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.yanzhu.jh.project.domain.SurProjectDeptWroks;
import com.yanzhu.jh.project.service.ISurProjectDeptWroksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version : V1.0
 * @ClassName: ProjectDeptWroksController
 * @Description: 在岗人员
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectDeptWroks")
public class ProjectDeptWroksController extends BaseController {

    @Autowired
    private ISurProjectDeptWroksService surProjectDeptWroksService;

    /**
     *  查询项目在岗人员列表
     * @param surProjectDeptWroks
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(SurProjectDeptWroks surProjectDeptWroks){
        if(surProjectDeptWroks.getDeptId()==0){
            surProjectDeptWroks.setDeptId(null);
        }
        return success(surProjectDeptWroksService.selectSurProjectDeptWroksList(surProjectDeptWroks));
    }

    /**
     * 查询在岗人员详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(surProjectDeptWroksService.selectSurProjectDeptWroksById(id));
    }

    /**
     * 新增在岗人员
     * @param surProjectDeptWroks
     * @return
     */
    @PostMapping("/add")
    @Log(title = "在岗人员", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SurProjectDeptWroks surProjectDeptWroks){
        return success(surProjectDeptWroksService.deleteInsertProjectDeptWroks(surProjectDeptWroks));
    }

    /**
     * 删除在岗人员
     */
    @Log(title = "在岗人员", businessType = BusinessType.DELETE)
    @GetMapping("/remove")
    public AjaxResult remove(@RequestParam Long id)
    {
        return toAjax(surProjectDeptWroksService.deleteSurProjectDeptWroksById(id));
    }
    
    /**
     * 根据项目分组查询统计
     * @param projectId
     * @return
     */
    @GetMapping("/findSumByProjectId")
    public AjaxResult findSumByProjectId(Long projectId){
        return success(surProjectDeptWroksService.findSumByProjectId(projectId));
    }

}
