EquipmentCenterController.java
18.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package com.skua.modules.equipment.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.skua.common.constant.BusinessConstant;
import com.skua.core.api.vo.Result;
import com.skua.core.aspect.annotation.AutoLog;
import com.skua.core.context.BaseContextHandler;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.equipment.dto.ReportStatisticsDTO;
import com.skua.modules.equipment.service.IEquipmentAnalysisService;
import com.skua.modules.equipment.service.IProductionEquipmentService;
import com.skua.modules.equipment.vo.*;
import com.skua.modules.system.service.ISysDepartService;
import com.skua.tool.util.DateUtils;
import com.skua.tool.util.DigitalUtils;
import com.skua.tool.util.JSUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Api(tags = "设备中心")
@RestController
@RequestMapping("/web/equipment/equipmentCenter")
public class EquipmentCenterController {
@Autowired
private IProductionEquipmentService iProductionEquipmentService;
@Autowired
private ISysDepartService departService;
@Autowired
private IEquipmentAnalysisService equipmentAnalysisService;
@AutoLog(value = "设备中心-顶部总览")
@ApiOperation(value = "设备中心-顶部总览", notes = "设备中心-顶部总览")
@GetMapping(value = "/topOverview")
public Result<ProductionEquipmentVO> topOverview(ReportStatisticsDTO reportStatisticsDTO) {
Result<ProductionEquipmentVO> result = new Result<ProductionEquipmentVO>();
setDepartIds(reportStatisticsDTO);
ProductionEquipmentVO productionEquipmentVO = iProductionEquipmentService.getProductionEquipmentVO(reportStatisticsDTO);
result.setResult(productionEquipmentVO);
return result;
}
@AutoLog(value = "设备中心-设备统计")
@ApiOperation(value = "设备中心-设备统计", notes = "设备中心-设备统计")
@GetMapping(value = "/equipmentStatistics")
public Result<FaultStatisticsVO> equipmentStatistics(ReportStatisticsDTO reportStatisticsDTO) {
Result<FaultStatisticsVO> result = new Result<>();
setDepartIds(reportStatisticsDTO);
//取消时间参数
reportStatisticsDTO.setStartTime(null);
reportStatisticsDTO.setEndTime(null);
FaultStatisticsVO equipmentStatistics = iProductionEquipmentService.getEquipmentStatistics(reportStatisticsDTO);
result.setResult(equipmentStatistics);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-设备统计详情")
@ApiOperation(value = "设备中心-设备统计详情", notes = "设备中心-设备统计详情")
@GetMapping(value = "/equipmentStatisticsDetails")
public Result<IPage<EquipmentNewMaintenancePlanVO>> equipmentStatisticsDetails(ReportStatisticsDTO reportStatisticsDTO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Result<IPage<EquipmentNewMaintenancePlanVO>> result = new Result<IPage<EquipmentNewMaintenancePlanVO>>();
Page<EquipmentNewMaintenancePlanVO> pageList = new Page<EquipmentNewMaintenancePlanVO>(pageNo, pageSize);
setDepartIds(reportStatisticsDTO);
//取消时间参数
reportStatisticsDTO.setStartTime(null);
reportStatisticsDTO.setEndTime(null);
pageList = iProductionEquipmentService.getEquipmentStatisticsDetails(pageList, reportStatisticsDTO);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@AutoLog(value = "设备中心-设备统计详情(新)")
@ApiOperation(value = "设备中心-设备统计详情(新)", notes = "设备中心-设备统计详情(新)")
@GetMapping(value = "/equipmentStatisticsDetailsNew")
public Result<IPage<EquipmentStatisticsCountVO>> equipmentStatisticsDetailsNew(ReportStatisticsDTO reportStatisticsDTO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Result<IPage<EquipmentStatisticsCountVO>> result = new Result<IPage<EquipmentStatisticsCountVO>>();
Page<EquipmentStatisticsCountVO> page = new Page<EquipmentStatisticsCountVO>(pageNo, pageSize);
setDepartIds(reportStatisticsDTO);//设置departIds
// bug11036:暂时先隐藏,不然和设备台账统计不一致
reportStatisticsDTO.setStartTime(null);
reportStatisticsDTO.setEndTime(null);
IPage<EquipmentStatisticsCountVO> pageList =iProductionEquipmentService.getEquipmentStatisticsDetailsNew(page, reportStatisticsDTO);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@AutoLog(value = "设备中心-设备状态")
@ApiOperation(value = "设备中心-设备状态", notes = "设备中心-设备状态")
@GetMapping(value = "/equipmentState")
public Result<List<TOPTenVO>> equipmentState(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<TOPTenVO>> result = new Result<>();
setDepartIds(reportStatisticsDTO);
//取消时间参数
// reportStatisticsDTO.setStartTime(null);
// reportStatisticsDTO.setEndTime(null);
List<TOPTenVO> equipmentState = iProductionEquipmentService.getEquipmentState(reportStatisticsDTO);
result.setSuccess(true);
result.setResult(equipmentState);
return result;
}
@AutoLog(value = "设备中心-设备状态详情")
@ApiOperation(value = "设备中心-设备状态详情", notes = "设备中心-设备状态详情")
@GetMapping(value = "/equipmentStateDetails")
public Result<IPage<EquipmentNewMaintenancePlanVO>> equipmentStateDetails(ReportStatisticsDTO reportStatisticsDTO,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
Result<IPage<EquipmentNewMaintenancePlanVO>> result = new Result<IPage<EquipmentNewMaintenancePlanVO>>();
Page<EquipmentNewMaintenancePlanVO> pageList = new Page<EquipmentNewMaintenancePlanVO>(pageNo, pageSize);
setDepartIds(reportStatisticsDTO);
pageList = iProductionEquipmentService.getEquipmentStateDetailsNew(pageList, reportStatisticsDTO);
result.setSuccess(true);
result.setResult(pageList);
return result;
}
@AutoLog(value = "设备中心-设备完好率")
@ApiOperation(value = "设备中心-设备完好率", notes = "设备中心-设备完好率")
@GetMapping(value = "/equipmentIntactRate")
public Result<List<ContrastVO>> equipmentIntactRate(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<ContrastVO>> result = new Result<List<ContrastVO>>();
setDepartIds(reportStatisticsDTO);
// 当前时间
Date nowDate = new Date();
String nowDateStr = DateUtils.date2Str(nowDate, BusinessConstant.dateFormat);
Date startDate;
if (reportStatisticsDTO.getTimeUnit() == 6) {
startDate = DateUtils.someDate(nowDate, Calendar.MONTH, -6);
} else {
startDate = DateUtils.prevYear(nowDate);
}
String startTime = DateUtils.date2Str(startDate, BusinessConstant.dateFormat).substring(0, 7) + "-01" + BusinessConstant.startTimeSuffix;
int days = DateUtils.lengthOfSomeMonth(Integer.parseInt(nowDateStr.split("-")[0]), Integer.parseInt(nowDateStr.split("-")[1]));
String endTime = nowDateStr.substring(0, 7) + "-" + days + BusinessConstant.endTimeSuffix;
// 同比时间
String[] tbTimeArray = DateUtils.tbTime(startTime, endTime);
// departId删除''
String departId = Arrays.stream(reportStatisticsDTO.getDepartIds().split(",")).map(item -> item.replaceAll("'", "")).collect(Collectors.joining(","));
List<Map<String, Object>> entityList = equipmentAnalysisService.equipmentInTactRateByTime(new HashMap<String, Object>(){{
put("startTime", startTime);
put("endTime", endTime);
put("timeType", "month");
put("departId", departId);
}});
List<Map<String, Object>> entityListTb = equipmentAnalysisService.equipmentInTactRateByTime(new HashMap<String, Object>(){{
put("startTime", tbTimeArray[0]);
put("endTime", tbTimeArray[1]);
put("timeType", "month");
put("departId", departId);
}});
Map<String, String> tbTime2ValueMap = entityListTb.stream().collect(Collectors.toMap(item -> ConvertUtils.getString(item.get("time")).substring(0, 7), item -> DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0D) * 100, 2) + "%"));
// 封装结果集
List<ContrastVO> resMapList = new ArrayList<>();
for (Map<String, Object> item: entityList) {
ContrastVO map = new ContrastVO();
String yearMonth = ConvertUtils.getString(item.get("time")).substring(0, 7);
map.setMonth(yearMonth);
// 完好率
map.setRepairNum(DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0D) * 100, 2) + "%");
// 同比
String tbYearMonth = (Integer.parseInt(yearMonth.split("-")[0]) - 1) + "-" + yearMonth.split("-")[1];
map.setMaintainNum(tbTime2ValueMap.get(tbYearMonth));
resMapList.add(map);
}
result.setResult(resMapList);
// List<ContrastVO> equipmentIntactRate = iProductionEquipmentService.getEquipmentIntactRate(reportStatisticsDTO);
result.setSuccess(true);
// result.setResult(equipmentIntactRate);
return result;
}
@AutoLog(value = "设备中心-设备完好率详情")
@ApiOperation(value = "设备中心-设备完好率详情", notes = "设备中心-设备完好率详情")
@GetMapping(value = "/equipmentIntactRateDetails")
public Result<List<Map>> equipmentIntactRateDetails(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<Map>> result = new Result<List<Map>>();
setDepartIds(reportStatisticsDTO);
List<Map> equipmentIntactRateDetails = iProductionEquipmentService.getEquipmentIntactRateDetails(reportStatisticsDTO);
result.setResult(equipmentIntactRateDetails);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-设备完好率详情(新)")
@ApiOperation(value = "设备中心-设备完好率详情(新)", notes = "设备中心-设备完好率详情(新)")
@GetMapping(value = "/equipmentIntactRateDetailsNew")
public Result<List<Map>> equipmentIntactRateDetailsNew(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<Map>> result = new Result<List<Map>>();
setDepartIds(reportStatisticsDTO);
// List<Map> equipmentIntactRateDetails = iProductionEquipmentService.getEquipmentIntactRateDetailsNew(reportStatisticsDTO);
// result.setResult(equipmentIntactRateDetails);
// 请求参数
String startTime = reportStatisticsDTO.getStartTime();
String endTime = reportStatisticsDTO.getEndTime();
// endTime修改到本月月底
int days = DateUtils.lengthOfSomeMonth(Integer.parseInt(endTime.split("-")[0]), Integer.parseInt(endTime.split("-")[1]));
endTime = endTime.substring(0, 7) + "-" + days + BusinessConstant.endTimeSuffix;
String finalEndTime = endTime;
// 同比时间
String[] tbTimeArray = DateUtils.tbTime(startTime, endTime);
// departId删除''
String departId = Arrays.stream(reportStatisticsDTO.getDepartIds().split(",")).map(item -> item.replaceAll("'", "")).collect(Collectors.joining(","));
List<Map<String, Object>> entityList = equipmentAnalysisService.equipmentInTactRateByDepart(new HashMap<String, Object>(){{
put("startTime", startTime);
put("endTime", finalEndTime);
put("departId", departId);
}});
List<Map<String, Object>> entityListTb = equipmentAnalysisService.equipmentInTactRateByDepart(new HashMap<String, Object>(){{
put("startTime", tbTimeArray[0]);
put("endTime", tbTimeArray[1]);
put("departId", departId);
}});
Map<String, String> tbDepartId2intactRateMap = entityListTb.stream().collect(Collectors.toMap(item -> ConvertUtils.getString(item.get("departId")), item -> DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0D) * 100, 2)));
// 封装结果集
List<Map> resMapList = new ArrayList<>();
for (Map<String, Object> item : entityList) {
Map<String, Object> map = new HashMap<>();
map.put("depart_id", item.get("departId"));
map.put("depart_name", item.get("departName"));
map.put("intact", DigitalUtils.nPoint(ConvertUtils.getDouble(item.get("intactRate"), 0) * 100, 2));
map.put("percentage", tbDepartId2intactRateMap.get(ConvertUtils.getString(item.get("departId"))));
resMapList.add(map);
}
result.setSuccess(true);
result.setResult(resMapList);
return result;
}
@AutoLog(value = "设备中心-MTTR&MTBF")
@ApiOperation(value = "设备中心-MTTR&MTBF", notes = "设备中心-MTTR&MTBF")
@GetMapping(value = "/equipmentMF")
public Result<List<ContrastVO>> equipmentMF(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<ContrastVO>> result = new Result<List<ContrastVO>>();
setDepartIds(reportStatisticsDTO);
List<ContrastVO> equipmentMF = iProductionEquipmentService.getEquipmentMF(reportStatisticsDTO);
result.setResult(equipmentMF);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-MTTR&MTBF详情")
@ApiOperation(value = "设备中心-MTTR&MTBF详情", notes = "设备中心-MTTR&MTBF详情")
@GetMapping(value = "/equipmentMFDetails")
public Result<List<ContrastDetailVO>> equipmentMFDetails(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<ContrastDetailVO>> result = new Result<List<ContrastDetailVO>>();
setDepartIds(reportStatisticsDTO);
List<ContrastDetailVO> equipmentMFDetails = iProductionEquipmentService.getEquipmentMFDetailsNew(reportStatisticsDTO.getDepartIds(),reportStatisticsDTO.getStartTime(),reportStatisticsDTO.getEndTime());
result.setResult(equipmentMFDetails);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-维护完成率趋势")
@ApiOperation(value = "设备中心-维护完成率趋势", notes = "设备中心-维护完成率趋势")
@GetMapping(value = "/maintainCompleteRate")
public Result<List<ContrastVO>> maintainCompleteRate(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<ContrastVO>> result = new Result<List<ContrastVO>>();
setDepartIds(reportStatisticsDTO);
List<ContrastVO> maintainCompleteRate = iProductionEquipmentService.getMaintainCompleteRate(reportStatisticsDTO);
result.setResult(maintainCompleteRate);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-维护完成率趋势详情")
@ApiOperation(value = "设备中心-维护完成率趋势详情", notes = "设备中心-维护完成率趋势详情")
@GetMapping(value = "/maintainCompleteRateDetails")
public Result<List<Map>> maintainCompleteRateDetails(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<Map>> result = new Result<>();
setDepartIds(reportStatisticsDTO);
List<Map> maintainCompleteRateDetails = iProductionEquipmentService.getMaintainCompleteRateDetailsNew(reportStatisticsDTO);
result.setResult(maintainCompleteRateDetails);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-维护维修费用")
@ApiOperation(value = "设备中心-维护维修费用", notes = "设备中心-维护维修费用")
@GetMapping(value = "/maintainRepairCost")
public Result<List<ContrastVO>> maintainRepairCost(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<ContrastVO>> result = new Result<List<ContrastVO>>();
setDepartIds(reportStatisticsDTO);
List<ContrastVO> maintainCompleteRate = iProductionEquipmentService.getContrastCost(reportStatisticsDTO);
result.setResult(maintainCompleteRate);
result.setSuccess(true);
return result;
}
@AutoLog(value = "设备中心-维护维修费用详情")
@ApiOperation(value = "设备中心-维护维修费用详情", notes = "设备中心-维护维修费用详情")
@GetMapping(value = "/maintainRepairCostDetails")
public Result<List<Map>> maintainRepairCostDetails(ReportStatisticsDTO reportStatisticsDTO) {
Result<List<Map>> result = new Result<>();
setDepartIds(reportStatisticsDTO);
List<Map> contrastCostDetails = iProductionEquipmentService.getContrastCostDetails(reportStatisticsDTO);
result.setResult(contrastCostDetails);
result.setSuccess(true);
return result;
}
/***
* 设置查询条件的departIds属性
* @param reportStatisticsDTO
*/
private void setDepartIds(ReportStatisticsDTO reportStatisticsDTO){
String departIds = null;
if (StringUtils.isNotEmpty(reportStatisticsDTO.getFactoryId())) {
departIds = departService.getChildDepartId(reportStatisticsDTO.getFactoryId());
}else{
departIds = BaseContextHandler.getDeparts();
}
reportStatisticsDTO.setDepartIds(JSUtils.quoteEach(departIds,","));
}
}