package com.ruoyi.web.project.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.enums.BusinessType;
import com.ruoyi.common.utils.DictUtils;
import com.yanzhu.jh.project.domain.SurProjectWorkSpecial;
import com.yanzhu.jh.project.service.ISurProjectWorkSpecialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version : V1.0
 * @ClassName: ProjectSpecialController
 * @Description: 项目特种人员
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectSpecial")
public class ProjectSpecialController extends BaseController {

    @Autowired
    private ISurProjectWorkSpecialService surProjectWorkSpecialService;

    /**
     *  查询项目特种人员列表
     * @param surProjectWorkSpecial
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SurProjectWorkSpecial surProjectWorkSpecial){
        if(surProjectWorkSpecial.getDeptId()==0){
            surProjectWorkSpecial.setDeptId(null);
        }
        return success(surProjectWorkSpecialService.selectSurProjectWorkSpecialList(surProjectWorkSpecial));
    }

    /**
     * 查询特种人员详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(surProjectWorkSpecialService.selectSurProjectWorkSpecialById(id));
    }

    /**
     * 新增特种人员
     * @param surProjectWorkSpecial
     * @return
     */
    @PostMapping("/add")
    @Log(title = "特种人员", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SurProjectWorkSpecial surProjectWorkSpecial){
        return success(surProjectWorkSpecialService.insertSurProjectWorkSpecial(surProjectWorkSpecial));
    }

    /**
     * 删除特种人员
     */
    @Log(title = "特种人员", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam Long id)
    {
        return toAjax(surProjectWorkSpecialService.deleteSurProjectWorkSpecialById(id));
    }

    /**
     * 查询特种人员类型
     * @return
     */
    @GetMapping("/querySpecialType")
    public AjaxResult querySpecialType(){
        return success(DictUtils.getDictCache("project_special_type"));
    }

    /**
     * 根据项目分组查询统计特种人员
     * @param projectId
     * @return
     */
    @GetMapping("/selectGroupCountByProjectId")
    public AjaxResult selectGroupCountByProjectId(Long projectId){
        return success(surProjectWorkSpecialService.findGroupCountByProjectId(projectId));
    }
}
