package com.ruoyi.web.controller.care;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataScope;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.care.domain.CarePersons;
import com.ruoyi.care.service.ICarePersonsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 特困人员Controller
 * 
 * @author qy
 * @date 2024-11-25
 */
@RestController
@RequestMapping("/care/persons")
public class CarePersonsController extends BaseController
{
    @Autowired
    private ICarePersonsService carePersonsService;

    /**
     * 查询特困人员列表
     */
    @PreAuthorize("@ss.hasPermi('care:persons:list')")
    @DataScope(deptAlias = "u", userAlias = "u")
    @GetMapping("/list")
    public TableDataInfo list(CarePersons carePersons)
    {
        startPage();
        List<CarePersons> list = carePersonsService.selectCarePersonsList(carePersons);
        return getDataTable(list);
    }

    /**
     * 导出特困人员列表
     */
    @PreAuthorize("@ss.hasPermi('care:persons:export')")
    @Log(title = "特困人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarePersons carePersons)
    {
        List<CarePersons> list = carePersonsService.selectCarePersonsList(carePersons);
        ExcelUtil<CarePersons> util = new ExcelUtil<CarePersons>(CarePersons.class);
        util.exportExcel(response, list, "特困人员数据");
    }

    /**
     * 获取特困人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('care:persons:query')")
    @GetMapping(value = "/{personId}")
    public AjaxResult getInfo(@PathVariable("personId") Long personId)
    {
        return success(carePersonsService.selectCarePersonsByPersonId(personId));
    }

    /**
     * 新增特困人员
     */
    @PreAuthorize("@ss.hasPermi('care:persons:add')")
    @Log(title = "特困人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarePersons carePersons)
    {
        carePersons.setCreateBy(getUserId().toString());
        return toAjax(carePersonsService.insertCarePersons(carePersons));
    }

    /**
     * 修改特困人员
     */
    @PreAuthorize("@ss.hasPermi('care:persons:edit')")
    @Log(title = "特困人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarePersons carePersons)
    {
        carePersons.setUpdateBy(getUserId().toString());
        return toAjax(carePersonsService.updateCarePersons(carePersons));
    }

    /**
     * 删除特困人员
     */
    @PreAuthorize("@ss.hasPermi('care:persons:remove')")
    @Log(title = "特困人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{personIds}")
    public AjaxResult remove(@PathVariable Long[] personIds)
    {
        return toAjax(carePersonsService.deleteCarePersonsByPersonIds(personIds));
    }

    /**
     * 查询所有特困人员列表
     */
    @GetMapping("/listAll")
    @PreAuthorize("@ss.hasPermi('care:persons:listAll')")
    @DataScope(deptAlias = "u", userAlias = "u")
    public List<CarePersons> listAll(CarePersons carePersons)
    {
        List<CarePersons> list = carePersonsService.selectCarePersonsList(carePersons);
        return list;
    }
}
