ProcessStatisticsController.java
9.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package com.skua.modules.process.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.business.service.FlowBusinessService;
import com.skua.modules.flow.core.entity.BladeFlow;
import com.skua.modules.flow.core.utils.TaskUtil;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
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 {
@Autowired
private FlowBusinessService flowBusinessService;
@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();*/
String userId = BaseContextHandler.getUserId();
IPage<BladeFlow> page = new Page<BladeFlow>();
page.setCurrent(1);
page.setSize(10000);
BladeFlow bladeFlow = new BladeFlow();
try {
//巡检任务、维修任务、保养任务、危险作业、事故事件、安全隐患、、药剂入库
// 、、、、、药剂入库
String process_key = "AjhRectification";
processStatisticsList.add( queryProcessStatistics("安全隐患", process_key,page,bladeFlow) ) ;
process_key = "problemReport";
processStatisticsList.add( queryProcessStatistics("问题上报", process_key,page,bladeFlow)) ;
process_key = "EmergencyRiskEvent";
processStatisticsList.add( queryProcessStatistics("事故事件", process_key,page,bladeFlow) ) ;
process_key = "DangerousOperationManage";
processStatisticsList.add( queryProcessStatistics("危险作业", process_key,page,bladeFlow) ) ;
process_key = "EquipmentRepair";
processStatisticsList.add( queryProcessStatistics("维修任务", process_key,page,bladeFlow)) ;
Integer baoyangTodoCount = 0;
QueryWrapper equipmentMaintainTaskQueryWrapper = new QueryWrapper<EquipmentMaintainTask>();
equipmentMaintainTaskQueryWrapper.eq("maintainer_id", userId);
//equipmentMaintainTaskQueryWrapper.eq("results_enforcement", 1);
baoyangTodoCount = equipMaintainExecuteService.count(equipmentMaintainTaskQueryWrapper);
ProcessStatisticsVO maintainerProcessStatisticsVO = new ProcessStatisticsVO("保养任务" ,"" , "0", baoyangTodoCount.toString() );
processStatisticsList.add( maintainerProcessStatisticsVO );
//巡检
//得到巡检任务
//得到进行中的任务
//获取用户所在的班组
Integer xunjian_count = 0;
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;
}
//得到当前未开始的
String moduleType = "1";
List<JSONObject> inspectionTaskByUserIdList = inspectionTaskService.getInspectionTaskByUserId(userId, moduleType);
ProcessStatisticsVO xunjianProcessStatisticsVO = new ProcessStatisticsVO("巡检任务" ,"" , "0", inspectionTaskByUserIdList.size()+"" );
processStatisticsList.add( xunjianProcessStatisticsVO );
//药剂入库
String userRoleIds = BaseContextHandler.getRoles();
String roleIds = BaseUtil.quoteEach(userRoleIds,",");
JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
Integer materialINCount = 0;
Integer authFlag = 0;
//如果为管理员,则跳过权限
if ("1".equals(BaseContextHandler.get("userType"))) {
authFlag = 1;
}else{
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+") " );
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 and apply_time >= '"+BaseUtil.getLastYearDate()+"' and apply_time<='"+BaseUtil.getCurrentDate()+"' ";
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() );
}*/
private ProcessStatisticsVO queryProcessStatistics(String processName, String process_key, IPage<BladeFlow> page,BladeFlow bladeFlow){
// String repairProcessDefinitionKey = "equipServicewx";
bladeFlow.setProcessDefinitionKey(process_key);
long repairClaimCount = flowBusinessService.selectClaimPage(page, bladeFlow).getTotal();
long repairToDoCount = flowBusinessService.selectTodoPage(page, bladeFlow).getTotal();
// long repairDoneCount = flowBusinessService.selectDonePage(page, bladeFlow).getTotal();
return new ProcessStatisticsVO(processName ,process_key , repairToDoCount+"", repairClaimCount+"" );
}
}