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.ruoyi.system.service.ISysDictDataService;
import com.yanzhu.jh.project.domain.SurProjectUnitInfo;
import com.yanzhu.jh.project.service.ISurProjectUnitInfoService;
import com.yanzhu.jh.work.domain.WorkTrain;
import com.yanzhu.jh.work.service.IWorkTrainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @version : V1.0
 * @ClassName: ProjectTrainController
 * @Description: 专项培训||应急演练
 * @Auther: JiangYuQi
 * @Date: 2020/7/7 18:03
 */
@RestController
@RequestMapping("/wechat/projectTrain")
public class ProjectTrainController extends BaseController {

    @Autowired
    private ISysDictDataService sysDictDataService;

    @Autowired
    private IWorkTrainService workTrainService;

    @Autowired
    private ISurProjectUnitInfoService surProjectUnitInfoService;

    /**
     *  查询项目专项培训||应急演练列表
     * @param workTrain
     * @return
     */
    @GetMapping("/list")
    public AjaxResult list(WorkTrain workTrain){
        if(workTrain.getDeptId()==0){
            workTrain.setDeptId(null);
        }
        return success(workTrainService.selectWorkTrainList(workTrain));
    }

    /**
     * 查询专项培训||应急演练详情
     * @param id
     * @return
     */
    @GetMapping("/info")
    public AjaxResult info(Long id){
        return success(workTrainService.selectById(id));
    }

    /**
     * 新增专项培训
     * @param workTrain
     * @return
     */
    @PostMapping("/addTrain")
    @Log(title = "教育培训", businessType = BusinessType.INSERT)
    public AjaxResult addTrain(@RequestBody WorkTrain workTrain){
        return success(workTrainService.insertWorkTrain(workTrain));
    }

    /**
     * 新增应急演练
     * @param workTrain
     * @return
     */
    @PostMapping("/addEmergencyDrill")
    @Log(title = "应急演练", businessType = BusinessType.INSERT)
    public AjaxResult addEmergencyDrill(@RequestBody WorkTrain workTrain){
        return success(workTrainService.insertWorkTrain(workTrain));
    }

    /**
     * 删除专项培训
     */
    @Log(title = "教育培训", businessType = BusinessType.DELETE)
    @GetMapping("/removeTrain")
    public AjaxResult removeTrain(@RequestParam Long id)
    {
        return toAjax(workTrainService.deleteWorkTrainById(id));
    }

    /**
     * 删除应急演练
     */
    @Log(title = "应急演练", businessType = BusinessType.DELETE)
    @GetMapping("/removeEmergencyDrill")
    public AjaxResult removeEmergencyDrill(@RequestParam Long id)
    {
        return toAjax(workTrainService.deleteWorkTrainById(id));
    }

    /**
     * 查询项目部门列表
     */
    @GetMapping("/queryUnitList")
    public AjaxResult queryUnitList(SurProjectUnitInfo surProjectUnitInfo)
    {
        return success(surProjectUnitInfoService.selectSurProjectUnitInfoList(surProjectUnitInfo));
    }

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

    /**
     * 查询演训类型
     * @return
     */
    @GetMapping("/queryTrainDataType")
    public AjaxResult queryTrainDataType(){
        return success(DictUtils.getDictCache("work_train_data_type"));
    }
}
