EquipHealthLevelJob.java
8.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
package com.skua.modules.equipment.quartz;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.DateUtils;
import com.skua.core.util.DoubleOperaUtils;
import com.skua.modules.equipment.entity.EquipmentInfo;
import com.skua.modules.equipment.service.IEquipmentInfoService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @program: skboot
* @description: 设备健康度定时任务
* @author: zhanglei
* @create: 2025/03/08 16:05:05
*/
@Slf4j
@Component
public class EquipHealthLevelJob implements Job {
@Autowired
private IEquipmentInfoService equipmentInfoService;
private static final String qz_screen_type = "71";//权重标识
private static final String status_screen_type = "70";//状态标识
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("设备健康度更新任务开始");
//获取当前时间 yyyy-MM-dd
String today = DateUtils.formatDate(new Date(), "yyyy-MM-dd");
Map<String,Double> qzMap = initQzMap();
Map<String,String> statusValueMap = initStatusMap();
//workingLife 使用年限、originalValue 购置价格、installDate 安装日期
List<EquipmentInfo> list = equipmentInfoService.getEquipmentList();
for (EquipmentInfo equipmentInfo : list){
if(ConvertUtils.isEmpty(equipmentInfo.getWorkingLife())||
ConvertUtils.isEmpty(equipmentInfo.getOriginalValue())||
ConvertUtils.isEmpty(equipmentInfo.getInstallDate())){
equipmentInfo.setEquipmentHealthLevel("");
equipmentInfo.setEquipmentHealthStatus("wfjs");
}else{
double performanceScore = 100.00;//性能得分
double faultScore = 100.00;//故障得分
double maintainScore = 100.00;//维护得分
double useYearScore = 100.00;//使用年限得分
//性能分数
if(ConvertUtils.isNotEmpty(equipmentInfo.getPerformanceScore())){
performanceScore = Double.valueOf(equipmentInfo.getPerformanceScore());
}
performanceScore = DoubleOperaUtils.bigDecimalRound(qzMap.get("xnzb")/100.00 * performanceScore,2);
//故障分数
faultScore = getFaultScore(equipmentInfo.getGzCount(),qzMap.get("gzl")/100.00);
//维护分数
maintainScore = getMaintainScore(equipmentInfo.getMaintenanceCost(), equipmentInfo.getOriginalValue(),qzMap.get("whcb")/100.00);
//使用年限分数
useYearScore = getUseYearScore(equipmentInfo.getWorkingLife(),equipmentInfo.getInstallDate(),today,qzMap.get("synx")/100.00);
//计算总分
double score = DoubleOperaUtils.bigDecimalRound(performanceScore + faultScore + maintainScore + useYearScore,2);
equipmentInfo.setEquipmentHealthLevel(String.valueOf(score));
//判断score在statusValueMap的key值的哪个区间,返回对应的value
String statusValue = getEquipmentHealthStatus(score,statusValueMap);
equipmentInfo.setEquipmentHealthStatus(statusValue);
}
equipmentInfoService.updateById(equipmentInfo);
}
}
private String getEquipmentHealthStatus(double score,Map<String,String> statusValueMap) {
String statusValue = "";
for (Map.Entry<String, String> entry : statusValueMap.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (score >= Double.valueOf(key.split("-")[0]) && score <= Double.valueOf(key.split("-")[1])) {
statusValue = value.split("-")[0];
break;
}
}
return statusValue;
}
//初始化权重
private Map<String,Double> initQzMap() {
Map<String,Double> qzMap = new HashMap<>();
qzMap.put("xnzb",40.00);//性能指标
qzMap.put("gzl",20.00);//故障率
qzMap.put("whcb",20.00);//维护成本
qzMap.put("synx",20.00);//使用年限
//获取权重及分值信息
List<Map<String,Object>> weightList = equipmentInfoService.getScreenList(qz_screen_type);
for (Map<String,Object> map : weightList){
if("xnzb".equals(map.get("code"))){
qzMap.put("xnzb",Double.valueOf(map.get("value").toString()));
}
if("gzl".equals(map.get("code"))){
qzMap.put("gzl",Double.valueOf(map.get("value").toString()));
}
if("whcb".equals(map.get("code"))){
qzMap.put("whcb",Double.valueOf(map.get("value").toString()));
}
if("synx".equals(map.get("code"))){
qzMap.put("synx",Double.valueOf(map.get("value").toString()));
}
}
return qzMap;
}
//初始化状态字典
private Map<String,String> initStatusMap() {
Map<String,String> statusValueMap = new HashMap<>();
statusValueMap.put("90-100","wdyx-稳定运行");//稳定运行
statusValueMap.put("60-90","qwth-轻微退化");//轻微退化
statusValueMap.put("40-60","mxxj-明显下降");//明显下降
statusValueMap.put("0-40","jjbf-接近报废");//接近报废
List<Map<String,Object>> statusList = equipmentInfoService.getScreenList(status_screen_type);
for (Map<String,Object> map : statusList){
if("wdyx".equals(map.get("code"))){
statusValueMap.put(map.get("value").toString(),"wdyx-"+map.get("name").toString());//稳定运行
}
if("qwth".equals(map.get("code"))){
statusValueMap.put(map.get("value").toString(),"qwth-"+map.get("name").toString());//轻微退化
}
if("mxxj".equals(map.get("code"))){
statusValueMap.put(map.get("value").toString(),"mxxj-"+map.get("name").toString());//明显下降
}
if("jjbf".equals(map.get("code"))){
statusValueMap.put(map.get("value").toString(),"jjbf-"+map.get("name").toString());//接近报废
}
}
return statusValueMap;
}
/**
* 计算故障评分
* @param gzCount 设备信息
* @param qz 权重因子
* @return 返回计算得到的故障评分
*/
private double getFaultScore(String gzCount, double qz) {
double score = 100.00;
if(Double.valueOf(gzCount) >= 4){
score = 0.00;
}else{
score = 100 - 100*Double.valueOf(gzCount)/4;
}
return DoubleOperaUtils.bigDecimalRound(qz * score,2);
}
/**
* 计算维护得分
* @param maintenanceCost 设备维护费用
* @param originalValue 购置金额
* @param qz 权重
* @return 返回计算得到的维护得分
*/
private double getMaintainScore(String maintenanceCost, String originalValue, double qz) {
double score = 100.00;
if(ConvertUtils.isNotEmpty(originalValue)){
double gzfy = Double.valueOf(originalValue);
double whfy = Double.valueOf(maintenanceCost);
score = 100*(gzfy-whfy)/gzfy;
}
return DoubleOperaUtils.bigDecimalRound(qz * score,2);
}
/**
* 计算使用寿命得分
* @param workingLife 使用年限
* @param installDate 安装日期
* @param today 当前日期
* @param qz 权重因子
* @return 返回使用寿命得分,固定为100分的20%
*/
private double getUseYearScore(String workingLife, String installDate, String today, double qz) {
double score = 100.00;
if(ConvertUtils.isNotEmpty(installDate)){
if(ConvertUtils.isNotEmpty(workingLife)){
double sjsy = Double.valueOf(DateUtils.dayDiff(installDate,today));
double sm = 365*Double.valueOf(workingLife);
score = 100 * (sm-sjsy)/sm;
}
}
return DoubleOperaUtils.bigDecimalRound(qz * score,2);
}
}