package com.yanzhu.jh.project.controller;

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

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.SysRoleEnum;
import com.ruoyi.system.service.ISysDeptService;
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.yanzhu.jh.project.domain.SurProjectWorkSpecial;
import com.yanzhu.jh.project.service.ISurProjectWorkSpecialService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目特种人员Controller
 * 
 * @author JiangYuQi
 * @date 2023-08-09
 */
@RestController
@RequestMapping("/project/surProjectSpecial")
public class SurProjectWorkSpecialController extends BaseController
{
    @Autowired
    private ISurProjectWorkSpecialService surProjectWorkSpecialService;

    @Autowired
    private ISysDeptService sysDeptService;

    /**
     * 查询项目特种人员列表
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurProjectWorkSpecial surProjectWorkSpecial)
    {
        startPage();
        surProjectWorkSpecial.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectWorkSpecial.getNowRole())){
            surProjectWorkSpecial.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectWorkSpecial.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectWorkSpecial.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectWorkSpecial> list = surProjectWorkSpecialService.selectSurProjectWorkSpecialList(surProjectWorkSpecial);
        return getDataTable(list);
    }

    /**
     * 查询项目特种人员数量统计
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:list')")
    @GetMapping("/findWorkSpecialCount")
    public AjaxResult findWorkSpecialCount(SurProjectWorkSpecial surProjectWorkSpecial)
    {
        surProjectWorkSpecial.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectWorkSpecial.getNowRole())){
            surProjectWorkSpecial.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectWorkSpecial.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectWorkSpecial.setNowUser(Convert.toStr(getUserId()));
        return success(surProjectWorkSpecialService.findWorkSpecialCount(surProjectWorkSpecial));
    }

    /**
     * 导出项目特种人员列表
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:export')")
    @Log(title = "项目特种人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurProjectWorkSpecial surProjectWorkSpecial)
    {
        surProjectWorkSpecial.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectWorkSpecial.getNowRole())){
            surProjectWorkSpecial.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectWorkSpecial.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectWorkSpecial.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectWorkSpecial> list = surProjectWorkSpecialService.selectSurProjectWorkSpecialList(surProjectWorkSpecial);
        ExcelUtil<SurProjectWorkSpecial> util = new ExcelUtil<SurProjectWorkSpecial>(SurProjectWorkSpecial.class);
        util.exportExcel(response, list, "项目特种人员数据");
    }

    /**
     * 获取项目特种人员详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surProjectWorkSpecialService.selectSurProjectWorkSpecialById(id));
    }

    /**
     * 新增项目特种人员
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:add')")
    @Log(title = "项目特种人员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurProjectWorkSpecial surProjectWorkSpecial)
    {
        return toAjax(surProjectWorkSpecialService.insertSurProjectWorkSpecial(surProjectWorkSpecial));
    }

    /**
     * 修改项目特种人员
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:edit')")
    @Log(title = "项目特种人员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurProjectWorkSpecial surProjectWorkSpecial)
    {
        return toAjax(surProjectWorkSpecialService.updateSurProjectWorkSpecial(surProjectWorkSpecial));
    }

    /**
     * 删除项目特种人员
     */
    @PreAuthorize("@ss.hasPermi('project:surProjectSpecial:remove')")
    @Log(title = "项目特种人员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surProjectWorkSpecialService.deleteSurProjectWorkSpecialByIds(ids));
    }
}
