ProcessStatisticsController.java 7.9 KB
package com.skua.modules.process.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.context.SpringContextUtils;
import com.skua.modules.equipment.entity.EquipmentMaintainTask;
import com.skua.modules.equipment.service.IEquipmentMaintainTaskService;
import com.skua.modules.flow.core.utils.TaskUtil;
import com.skua.modules.flow.utils.Func;
import com.skua.modules.inspection.entity.InspectionUserWorkingGroup;
import com.skua.modules.inspection.service.IInspectionTaskService;
import com.skua.modules.inspection.service.IInspectionUserWorkingGroupService;
import com.skua.modules.process.vo.ProcessStatisticsVO;
import com.skua.modules.quartz.util.BaseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.flowable.task.api.TaskQuery;
import org.flowable.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Api(tags="测试流程")
@RestController("testProcessController")
@RequestMapping("/web/process")
public class ProcessStatisticsController {

    // 注入TaskService
    @Autowired
    private TaskService taskService;
    @Autowired
    private IEquipmentMaintainTaskService equipMaintainExecuteService;
    @Autowired
    private IInspectionTaskService inspectionTaskService;
    @Autowired
    private IInspectionUserWorkingGroupService inspectionUserWorkingGroupService;

    /*            问题上报流程	problemReport
            设备维修流程	EquipmentRepair
            设备缺陷管理	EquipmentDefectManagement
            事故事件流程	EmergencyRiskEvent
            生产任务流程	productive_task
            数据报警工单	productAlarmProcess
            安全隐患流程	AjhRectification
            考核评价流程	dataAssessmentSocreMaster
            危险作业流程	DangerousOperationManage*/
    @AutoLog(value = "测试流程"  )
    @ApiOperation(value="测试流程-统计", notes="测试流程-统计")
    @GetMapping(value = "/statistics")
    public Result<List<ProcessStatisticsVO>> statistics() {
        Result<List<ProcessStatisticsVO>> result = new Result<List<ProcessStatisticsVO>>();
        List<ProcessStatisticsVO>  processStatisticsList = new ArrayList<>();
        String taskUser = TaskUtil.getTaskUser();
        String taskGroup = TaskUtil.getCandidateGroup();
        List<String> userGroupList = Func.toStrList(taskGroup);
        try {
            //巡检任务、维修任务、保养任务、危险作业、事故事件、安全隐患、、药剂入库
            // 、、、、、药剂入库
            String process_key = "AjhRectification";
            processStatisticsList.add( queryProcessStatistics("安全隐患",  process_key,taskUser,taskGroup) ) ;
            process_key = "problemReport";
            processStatisticsList.add(  queryProcessStatistics("问题上报",  process_key,taskUser,taskGroup)) ;
            process_key = "EmergencyRiskEvent";
            processStatisticsList.add( queryProcessStatistics("事故事件",  process_key,taskUser,taskGroup) ) ;
            process_key = "DangerousOperationManage";
            processStatisticsList.add( queryProcessStatistics("危险作业",  process_key,taskUser,taskGroup) ) ;
            process_key = "EquipmentRepair";
            processStatisticsList.add( queryProcessStatistics("维修任务",  process_key,taskUser,taskGroup)) ;

            Integer todoCount = 0;
            QueryWrapper equipmentMaintainTaskQueryWrapper = new QueryWrapper<EquipmentMaintainTask>();
            equipmentMaintainTaskQueryWrapper.eq("maintainer_id", taskUser);
            equipmentMaintainTaskQueryWrapper.eq("results_enforcement", 1);
            todoCount = equipMaintainExecuteService.count(equipmentMaintainTaskQueryWrapper);
            ProcessStatisticsVO   maintainerProcessStatisticsVO =   new ProcessStatisticsVO("保养任务" ,""  , "0", todoCount.toString() );
            processStatisticsList.add(  maintainerProcessStatisticsVO );
            //巡检
            //得到巡检任务
            //得到进行中的任务
            //获取用户所在的班组
            Integer xunjian_count = 0;
            String userId = BaseContextHandler.getUserId();
            QueryWrapper<InspectionUserWorkingGroup> inspectionUserWorkingGroupQueryWrapper = new QueryWrapper<>();
            inspectionUserWorkingGroupQueryWrapper.eq("user_id", userId);
            List<InspectionUserWorkingGroup> inspectionUserWorkingGroupList = inspectionUserWorkingGroupService.list(inspectionUserWorkingGroupQueryWrapper);

            List<String> inspectionWorkingGroupIdList = new ArrayList<>();
            for (InspectionUserWorkingGroup inspectionUserWorkingGroup : inspectionUserWorkingGroupList) {
                inspectionWorkingGroupIdList.add(inspectionUserWorkingGroup.getInspectionWorkingGroupId());
            }
            if (inspectionWorkingGroupIdList.size() > 0) {
                QueryWrapper queryWrapper = new QueryWrapper();
                queryWrapper.eq("task_state", "1");
                queryWrapper.in("inspection_working_group_id", inspectionWorkingGroupIdList);
                xunjian_count = inspectionTaskService.count(queryWrapper);
            } else {
                xunjian_count = 0;
            }
            ProcessStatisticsVO   xunjianProcessStatisticsVO =   new ProcessStatisticsVO("巡检任务" ,""  , "0",xunjian_count.toString() );

            processStatisticsList.add(  xunjianProcessStatisticsVO );

            //药剂入库
            String userRoleIds = BaseContextHandler.getRoles();
            String roleIds = BaseUtil.quoteEach(userRoleIds,",");

            Integer materialINCount = 0;
            JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
            StringBuffer sql  = new StringBuffer("   select count(1) from sys_role_permission   rp  ,sys_config c ");
            sql.append("   where rp.permission_id = c.config_value  and c.config_id = 'MaterialIN_ID' and rp.role_id in ("+roleIds+") "  );
            Integer  authFlag =    masterDB.queryForObject(sql.toString(),Integer.class);
            if(authFlag.intValue() > 0){
                String sql2 = "select count(1) from erp_material_in where confirm_status =2 and audit_status>0 and audit_status<3";
                materialINCount =    masterDB.queryForObject(sql2,Integer.class);
            }

            ProcessStatisticsVO   materialINProcessStatisticsVO =   new ProcessStatisticsVO("药剂入库" ,""  , "0",materialINCount.toString() );
            processStatisticsList.add(  materialINProcessStatisticsVO );

            result.setResult( processStatisticsList );
            result.success("获取统计数据");
        } catch (Exception e) {
            log.error(e.getMessage(),e);
            result.error500("操作失败");
        }
        return result;
    }

    /***
     * @param process_key
     * @return
     */
    private ProcessStatisticsVO   queryProcessStatistics(String  processName,String process_key,String taskUser , String taskGroup){
        TaskQuery taskQuery = taskService.createTaskQuery();
        taskQuery.processDefinitionKey( process_key );
        Long todoCount = taskQuery.taskAssignee(taskUser).count();//代办人数
        Long claimCount = taskQuery.taskCandidateGroupIn(  Func.toStrList(taskGroup) ).count() ;//todoCount
        return  new ProcessStatisticsVO(processName ,process_key  , todoCount.toString(), claimCount.toString() );
    }
}