package com.ruoyi.web.controller.residentInfo;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.domain.entity.ResidentInfo;
import com.ruoyi.system.service.IResidentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 居住人员信息，存储居住人员的详细信息Controller
 *
 * @author boman
 * @date 2025-02-20
 */
@RestController
@RequestMapping("/wuYe/residentInfo")
public class ResidentInfoController extends BaseController {
    @Autowired
    private IResidentInfoService residentInfoService;

    /**
     * 查询居住人员信息，存储居住人员的详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResidentInfo residentInfo) {
        startPage();
        List<ResidentInfo> list = residentInfoService.selectResidentInfoList(residentInfo);
        return getDataTable(list);
    }

    /**
     * 查询居住人员党员信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:count')")
    @GetMapping("/count")
    public AjaxResult count(ResidentInfo residentInfo) {
        return residentInfoService.selectCount(residentInfo);

    }

    /**
     * 导出居住人员信息，存储居住人员的详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:export')")
    @Log(title = "居住人员信息，存储居住人员的详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResidentInfo residentInfo) {
        List<ResidentInfo> list = residentInfoService.selectResidentInfoList(residentInfo);
        ExcelUtil<ResidentInfo> util = new ExcelUtil<ResidentInfo>(ResidentInfo.class);
        util.exportExcel(response, list, "居住人员信息，存储居住人员的详细信息数据");
    }

    /**
     * 获取居住人员信息，存储居住人员的详细信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:query')")
    @GetMapping(value = "/{residentId}")
    public AjaxResult getInfo(@PathVariable("residentId") Long residentId) {
        return success(residentInfoService.selectResidentInfoByResidentId(residentId));
    }

    /**
     * 新增居住人员信息，存储居住人员的详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:add')")
    @Log(title = "居住人员信息，存储居住人员的详细信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResidentInfo residentInfo) {
        return residentInfoService.insertResidentInfo(residentInfo);
    }

    /**
     * 修改居住人员信息，存储居住人员的详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:edit')")
    @Log(title = "居住人员信息，存储居住人员的详细信息", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ResidentInfo residentInfo) {
        return toAjax(residentInfoService.updateResidentInfo(residentInfo));
    }

    /**
     * 删除居住人员信息，存储居住人员的详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuYe:residentInfo:remove')")
    @Log(title = "居住人员信息，存储居住人员的详细信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{residentIds}")
    public AjaxResult remove(@PathVariable Long[] residentIds) {
        return toAjax(residentInfoService.deleteResidentInfoByResidentIds(residentIds));
    }
}
