package com.ruoyi.szxc.controller;

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.szxc.domain.SzxcDyManage;
import com.ruoyi.szxc.service.ISzxcDyManageService;
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 hs
 * @date 2024-03-22
 */
@RestController
@RequestMapping("/szxc/dymanage")
public class SzxcDyManageController extends BaseController
{
    @Autowired
    private ISzxcDyManageService szxcDyManageService;

    /**
     * 查询党员管理列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:dymanage:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcDyManage szxcDyManage)
    {
        startPage();
        List<SzxcDyManage> list = szxcDyManageService.selectSzxcDyManageList(szxcDyManage);
        return getDataTable(list);
    }

    /**
     * 导出党员管理列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:dymanage:export')")
    @Log(title = "党员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcDyManage szxcDyManage)
    {
        List<SzxcDyManage> list = szxcDyManageService.selectSzxcDyManageList(szxcDyManage);
        ExcelUtil<SzxcDyManage> util = new ExcelUtil<SzxcDyManage>(SzxcDyManage.class);
        util.exportExcel(response, list, "党员管理数据");
    }

    /**
     * 获取党员管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:dymanage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcDyManageService.selectSzxcDyManageById(id));
    }

    /**
     * 新增党员管理
     */
    @PreAuthorize("@ss.hasPermi('szxc:dymanage:add')")
    @Log(title = "党员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcDyManage szxcDyManage)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcDyManage.getDeptId()==null){
            szxcDyManage.setDeptId(getDeptId());
        }
        szxcDyManage.setUserId(getUserId());
        return toAjax(szxcDyManageService.insertSzxcDyManage(szxcDyManage));
    }

    /**
     * 修改党员管理
     */
    @PreAuthorize("@ss.hasPermi('szxc:dymanage:edit')")
    @Log(title = "党员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcDyManage szxcDyManage)
    {
        return toAjax(szxcDyManageService.updateSzxcDyManage(szxcDyManage));
    }

    /**
     * 删除党员管理
     */
    @PreAuthorize("@ss.hasPermi('szxc:dymanage:remove')")
    @Log(title = "党员管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcDyManageService.deleteSzxcDyManageByIds(ids));
    }
}
