package com.yanzhu.jh.bigscreen.web.controller;

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.core.text.Convert;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.yanzhu.jh.project.domain.SurProjectDeptWroks;
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.*;

import java.util.List;

/**
 * 培训演训Conller
 */
@RestController
@RequestMapping("/bgscreen/workTrain")
public class BgWorkTrainController extends BaseController {

    @Autowired
    IWorkTrainService workTrainService;

    /**
     * 根据类型查询培训演训
     * @param trainType
     * @return
     */
    @GetMapping("/getWorkTrainList")
    public TableDataInfo getWorkTrainList(String trainType,String deptId,String projectId){
        WorkTrain workTrain = new WorkTrain();
        workTrain.setTrainType(trainType);
        if(deptId!=null && !"0".equals(deptId)){
            workTrain.setNowDept(deptId);
        }else{
            if (SecurityUtils.isUserB()) {
                workTrain.setPrjIds(getProjectIds());
            }
        }
        if(projectId!=null && !"0".equals(projectId)){
            workTrain.setProjectId(Convert.toLong(projectId));
        }
        return getDataTable(workTrainService.selectBgscreenWorkTrainListv2(workTrain));
    }

    /**
     * 大屏教训培训，应急演练图标数据查询
     * @return
     */
    @GetMapping("/getGroupByDataType")
    public AjaxResult getGroupByDataType(String deptId, String projectId){
        WorkTrain workTrain = new WorkTrain();
        if(deptId!=null && !"0".equals(deptId)){
            workTrain.setNowDept(deptId);
        }else{
            if (SecurityUtils.isUserB()) {
                workTrain.setPrjIds(getProjectIds());
            }
        }
        if(projectId!=null && !"0".equals(projectId)){
            workTrain.setProjectId(Convert.toLong(projectId));
        }
        return AjaxResult.success(workTrainService.getGroupByDataType(workTrain));
    }

    @PostMapping("/queryWorkTrainList")
    public TableDataInfo queryWorkTrainList(@RequestBody WorkTrain where){
        Long deptId= where.getDeptId();
        if(deptId!=null && deptId>0){
            where.setNowDept(""+deptId);
        }else{
            if (SecurityUtils.isUserB()) {
                where.setPrjIds(getProjectIds());
            }
        }
        startPage();
        List<WorkTrain> list=workTrainService.queryWorkTrainList(where);
        return getDataTable(list);
    }

}
