package com.org.web.person.controller;

import com.org.system.annotation.Log;
import com.org.system.controller.BaseController;
import com.org.system.enums.BusinessType;
import com.org.utils.AjaxResult;
import com.org.utils.core.IdParams;
import com.org.utils.page.TableDataInfo;
import com.org.web.person.domain.BcPersonSupport;
import com.org.web.person.service.BcPersonSupportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/person/support")
public class BcPersonSupportController extends BaseController {

	@Autowired
	BcPersonSupportService supportService;

	/**
	 * 新增
	 */
	@PostMapping("/addOrUpdate")
	@PreAuthorize("@ss.hasPermi('person:support:add')")
	@Log(title = "供养人员新增/编辑", businessType = BusinessType.INSERT)
	public AjaxResult add(@Validated @RequestBody BcPersonSupport params) {
		log.info("BcPersonSupportController - add params:{}", params);

		return AjaxResult.success(supportService.executeSaveOrUpdate(params));
	}

	/**
	 * 删除
	 */
	@PostMapping("/del")
	@PreAuthorize("@ss.hasPermi('person:support:del')")
	@Log(title = "供养人员删除", businessType = BusinessType.DELETE)
	public AjaxResult del(@Validated @RequestBody IdParams params) {
		log.info("BcPersonSupportController - del params:{}", params);

		return AjaxResult.success(supportService.del(params.getId()));
	}

	/**
	 * 详情
	 */
	@PostMapping("/detail")
	@PreAuthorize("@ss.hasAnyPermi('person:support:detail')")
	@Log(title = "供养人员详情", businessType = BusinessType.SELECT)
	public AjaxResult detail(@Validated @RequestBody IdParams params) {
		log.info("BcPersonSupportController - detail params:{}", params);

		return AjaxResult.success(supportService.get(params.getId()));
	}

	/**
	 * 列表查询
	 */
	@GetMapping("/list")
	@PreAuthorize("@ss.hasAnyPermi('person:support:list')")
	@Log(title = "供养人员列表查询", businessType = BusinessType.SELECT)
	public TableDataInfo list(BcPersonSupport params) {
		log.info("BcPersonSupportController - list params:{}", params);

		startPage();

		List<BcPersonSupport> list = supportService.queryList(params);

		TableDataInfo dataTable = getDataTable(list);

		return dataTable;
	}


}
