feat(equipment): 添加设备健康度定时更新功能
- 新增设备健康度和健康状态字段 - 实现设备列表查询和屏幕列表查询接口 - 添加设备健康度定时更新任务 - 优化设备信息查询 SQL
正在显示
7 个修改的文件
包含
248 行增加
和
6 行删除
... | @@ -332,6 +332,8 @@ public class EquipmentController { | ... | @@ -332,6 +332,8 @@ public class EquipmentController { |
332 | } | 332 | } |
333 | queryWrapper.eq(flag, "EquipmentInfo_isSpecial", isSpecial) | 333 | queryWrapper.eq(flag, "EquipmentInfo_isSpecial", isSpecial) |
334 | .groupBy("EquipmentInfo_equipmentStatus");//EquipmentInfo_isSpecial | 334 | .groupBy("EquipmentInfo_equipmentStatus");//EquipmentInfo_isSpecial |
335 | sql = sql.replace("EquipmentInfo.maintenance_cost as EquipmentInfo_maintenanceCost,", "") | ||
336 | .replace("EquipmentInfo.gz_count as EquipmentInfo_gzCount,", ""); | ||
335 | List<Map<String, Object>> countMapList = iCommonSqlService.queryWrapperForList(sql, queryWrapper); | 337 | List<Map<String, Object>> countMapList = iCommonSqlService.queryWrapperForList(sql, queryWrapper); |
336 | for (Map<String, Object> item : countMapList) { | 338 | for (Map<String, Object> item : countMapList) { |
337 | String key = "" + item.get("EquipmentInfo_equipmentStatus"); | 339 | String key = "" + item.get("EquipmentInfo_equipmentStatus"); | ... | ... |
1 | package com.skua.modules.equipment.entity; | 1 | package com.skua.modules.equipment.entity; |
2 | 2 | ||
3 | import com.baomidou.mybatisplus.annotation.IdType; | 3 | import com.baomidou.mybatisplus.annotation.IdType; |
4 | import com.baomidou.mybatisplus.annotation.TableField; | ||
4 | import com.baomidou.mybatisplus.annotation.TableId; | 5 | import com.baomidou.mybatisplus.annotation.TableId; |
5 | import com.baomidou.mybatisplus.annotation.TableName; | 6 | import com.baomidou.mybatisplus.annotation.TableName; |
6 | import com.fasterxml.jackson.annotation.JsonFormat; | 7 | import com.fasterxml.jackson.annotation.JsonFormat; |
... | @@ -276,11 +277,22 @@ public class EquipmentInfo { | ... | @@ -276,11 +277,22 @@ public class EquipmentInfo { |
276 | 277 | ||
277 | @ApiModelProperty(value = "性能分数") | 278 | @ApiModelProperty(value = "性能分数") |
278 | private String performanceScore; | 279 | private String performanceScore; |
280 | |||
279 | @ApiModelProperty(value = "设备健康度") | 281 | @ApiModelProperty(value = "设备健康度") |
280 | private String equipmentHealthLevel; | 282 | private String equipmentHealthLevel; |
283 | |||
281 | @ApiModelProperty(value = "设备健康状态") | 284 | @ApiModelProperty(value = "设备健康状态") |
285 | @Dict(dicCode = "equipment_health_status") | ||
282 | private String equipmentHealthStatus; | 286 | private String equipmentHealthStatus; |
283 | 287 | ||
288 | //维护费用 | ||
289 | @TableField(exist = false) | ||
290 | private String maintenanceCost; | ||
291 | |||
292 | //维修次数 | ||
293 | @TableField(exist = false) | ||
294 | private String gzCount; | ||
295 | |||
284 | //检测机构 | 296 | //检测机构 |
285 | @ApiModelProperty(value = "检测机构") | 297 | @ApiModelProperty(value = "检测机构") |
286 | private String testingDepart; | 298 | private String testingDepart; | ... | ... |
1 | package com.skua.modules.equipment.mapper; | 1 | package com.skua.modules.equipment.mapper; |
2 | 2 | ||
3 | import java.util.List; | 3 | import java.util.List; |
4 | import java.util.Map; | ||
4 | 5 | ||
5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; | 6 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
6 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 7 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
7 | import com.skua.modules.equipment.entity.EquipmentInfo; | 8 | import com.skua.modules.equipment.entity.EquipmentInfo; |
8 | import com.skua.modules.equipment.vo.EquipmentInfoForMonitorVO; | 9 | import com.skua.modules.equipment.vo.EquipmentInfoForMonitorVO; |
10 | import io.lettuce.core.dynamic.annotation.Param; | ||
9 | 11 | ||
10 | /** | 12 | /** |
11 | * 设备信息 | 13 | * 设备信息 |
... | @@ -24,4 +26,9 @@ public interface EquipmentInfoMapper extends BaseMapper<EquipmentInfo> { | ... | @@ -24,4 +26,9 @@ public interface EquipmentInfoMapper extends BaseMapper<EquipmentInfo> { |
24 | List<EquipmentInfoForMonitorVO> queryCustomPageList(Page<EquipmentInfoForMonitorVO> pageList, EquipmentInfoForMonitorVO equipmentInfoForMonitorVO); | 26 | List<EquipmentInfoForMonitorVO> queryCustomPageList(Page<EquipmentInfoForMonitorVO> pageList, EquipmentInfoForMonitorVO equipmentInfoForMonitorVO); |
25 | 27 | ||
26 | void clearDigitaltwins(); | 28 | void clearDigitaltwins(); |
29 | |||
30 | List<EquipmentInfo> getEquipmentList(); | ||
31 | |||
32 | List<Map<String, Object>> getScreenList(@Param("screenType") String screenType); | ||
33 | |||
27 | } | 34 | } | ... | ... |
... | @@ -28,4 +28,24 @@ | ... | @@ -28,4 +28,24 @@ |
28 | <update id="clearDigitaltwins"> | 28 | <update id="clearDigitaltwins"> |
29 | update equipment_info set digital_twins_struct_code = '' | 29 | update equipment_info set digital_twins_struct_code = '' |
30 | </update> | 30 | </update> |
31 | <select id="getEquipmentList" resultType="com.skua.modules.equipment.entity.EquipmentInfo"> | ||
32 | SELECT | ||
33 | ifnull( t.maintenance_cost, 0 ) maintenance_cost, | ||
34 | ifnull( r.id_count, 0 ) gz_count, | ||
35 | e.* | ||
36 | FROM | ||
37 | equipment_info e | ||
38 | LEFT JOIN ( SELECT SUM( maintenance_cost ) AS maintenance_cost, equipment_id FROM equipment_maintain_task GROUP BY equipment_id ) t ON e.id = t.equipment_id | ||
39 | LEFT JOIN ( SELECT count( id ) id_count, info_id FROM equipment_repair GROUP BY info_id ) r ON e.id = r.info_id | ||
40 | </select> | ||
41 | <select id="getScreenList" resultType="java.util.HashMap"> | ||
42 | SELECT | ||
43 | context_code AS code, | ||
44 | context_title AS value, | ||
45 | context_name AS name | ||
46 | FROM | ||
47 | screen_user_context | ||
48 | WHERE | ||
49 | screen_type = #{screenType} | ||
50 | </select> | ||
31 | </mapper> | 51 | </mapper> | ... | ... |
sk-module-equipment/src/main/java/com/skua/modules/equipment/quartz/EquipHealthLevelJob.java
0 → 100644
1 | package com.skua.modules.equipment.quartz; | ||
2 | |||
3 | import com.skua.core.util.ConvertUtils; | ||
4 | import com.skua.core.util.DateUtils; | ||
5 | import com.skua.core.util.DoubleOperaUtils; | ||
6 | import com.skua.modules.equipment.entity.EquipmentInfo; | ||
7 | import com.skua.modules.equipment.service.IEquipmentInfoService; | ||
8 | import lombok.extern.slf4j.Slf4j; | ||
9 | import org.quartz.Job; | ||
10 | import org.quartz.JobExecutionContext; | ||
11 | import org.quartz.JobExecutionException; | ||
12 | import org.springframework.beans.factory.annotation.Autowired; | ||
13 | import org.springframework.stereotype.Component; | ||
14 | |||
15 | import java.util.Date; | ||
16 | import java.util.HashMap; | ||
17 | import java.util.List; | ||
18 | import java.util.Map; | ||
19 | |||
20 | /** | ||
21 | * @program: skboot | ||
22 | * @description: 设备健康度定时任务 | ||
23 | * @author: zhanglei | ||
24 | * @create: 2025/03/08 16:05:05 | ||
25 | */ | ||
26 | @Slf4j | ||
27 | @Component | ||
28 | public class EquipHealthLevelJob implements Job { | ||
29 | |||
30 | @Autowired | ||
31 | private IEquipmentInfoService equipmentInfoService; | ||
32 | |||
33 | private static final String qz_screen_type = "71";//权重标识 | ||
34 | private static final String status_screen_type = "70";//状态标识 | ||
35 | |||
36 | @Override | ||
37 | public void execute(JobExecutionContext context) throws JobExecutionException { | ||
38 | log.info("设备健康度更新任务开始"); | ||
39 | //获取当前时间 yyyy-MM-dd | ||
40 | String today = DateUtils.formatDate(new Date(), "yyyy-MM-dd"); | ||
41 | Map<String,Double> qzMap = initQzMap(); | ||
42 | Map<String,String> statusValueMap = initStatusMap(); | ||
43 | //workingLife 使用年限、originalValue 购置价格、installDate 安装日期 | ||
44 | List<EquipmentInfo> list = equipmentInfoService.getEquipmentList(); | ||
45 | for (EquipmentInfo equipmentInfo : list){ | ||
46 | double performanceScore = 100.00;//性能得分 | ||
47 | double faultScore = 100.00;//故障得分 | ||
48 | double maintainScore = 100.00;//维护得分 | ||
49 | double useYearScore = 100.00;//使用年限得分 | ||
50 | //性能分数 | ||
51 | if(ConvertUtils.isNotEmpty(equipmentInfo.getPerformanceScore())){ | ||
52 | performanceScore = Double.valueOf(equipmentInfo.getPerformanceScore()); | ||
53 | } | ||
54 | performanceScore = DoubleOperaUtils.bigDecimalRound(qzMap.get("xnzb")/100.00 * performanceScore,2); | ||
55 | //故障分数 | ||
56 | faultScore = getFaultScore(equipmentInfo.getGzCount(),qzMap.get("gzl")/100.00); | ||
57 | //维护分数 | ||
58 | maintainScore = getMaintainScore(equipmentInfo.getMaintenanceCost(), equipmentInfo.getOriginalValue(),qzMap.get("whcb")/100.00); | ||
59 | //使用年限分数 | ||
60 | useYearScore = getUseYearScore(equipmentInfo.getWorkingLife(),equipmentInfo.getInstallDate(),today,qzMap.get("synx")/100.00); | ||
61 | //计算总分 | ||
62 | double score = performanceScore + faultScore + maintainScore + useYearScore; | ||
63 | equipmentInfo.setEquipmentHealthLevel(String.valueOf(score)); | ||
64 | |||
65 | //判断score在statusValueMap的key值的哪个区间,返回对应的value | ||
66 | String statusValue = getEquipmentHealthStatus(score,statusValueMap); | ||
67 | |||
68 | equipmentInfo.setEquipmentHealthStatus(statusValue); | ||
69 | equipmentInfoService.updateById(equipmentInfo); | ||
70 | } | ||
71 | |||
72 | } | ||
73 | |||
74 | private String getEquipmentHealthStatus(double score,Map<String,String> statusValueMap) { | ||
75 | String statusValue = ""; | ||
76 | for (Map.Entry<String, String> entry : statusValueMap.entrySet()) { | ||
77 | String key = entry.getKey(); | ||
78 | String value = entry.getValue(); | ||
79 | if (score >= Double.valueOf(key.split("-")[0]) && score <= Double.valueOf(key.split("-")[1])) { | ||
80 | statusValue = value.split("-")[0]; | ||
81 | break; | ||
82 | } | ||
83 | } | ||
84 | return statusValue; | ||
85 | } | ||
86 | |||
87 | //初始化权重 | ||
88 | private Map<String,Double> initQzMap() { | ||
89 | Map<String,Double> qzMap = new HashMap<>(); | ||
90 | qzMap.put("xnzb",40.00);//性能指标 | ||
91 | qzMap.put("gzl",20.00);//故障率 | ||
92 | qzMap.put("whcb",20.00);//维护成本 | ||
93 | qzMap.put("synx",20.00);//使用年限 | ||
94 | //获取权重及分值信息 | ||
95 | List<Map<String,Object>> weightList = equipmentInfoService.getScreenList(qz_screen_type); | ||
96 | for (Map<String,Object> map : weightList){ | ||
97 | if("xnzb".equals(map.get("code"))){ | ||
98 | qzMap.put("xnzb",Double.valueOf(map.get("value").toString())); | ||
99 | } | ||
100 | if("gzl".equals(map.get("code"))){ | ||
101 | qzMap.put("gzl",Double.valueOf(map.get("value").toString())); | ||
102 | } | ||
103 | if("whcb".equals(map.get("code"))){ | ||
104 | qzMap.put("whcb",Double.valueOf(map.get("value").toString())); | ||
105 | } | ||
106 | if("synx".equals(map.get("code"))){ | ||
107 | qzMap.put("synx",Double.valueOf(map.get("value").toString())); | ||
108 | } | ||
109 | } | ||
110 | return qzMap; | ||
111 | } | ||
112 | |||
113 | //初始化状态字典 | ||
114 | private Map<String,String> initStatusMap() { | ||
115 | Map<String,String> statusValueMap = new HashMap<>(); | ||
116 | statusValueMap.put("90-100","wdyx-稳定运行");//稳定运行 | ||
117 | statusValueMap.put("60-90","qwth-轻微退化");//轻微退化 | ||
118 | statusValueMap.put("40-60","mxxj-明显下降");//明显下降 | ||
119 | statusValueMap.put("0-40","jjbf-接近报废");//接近报废 | ||
120 | List<Map<String,Object>> statusList = equipmentInfoService.getScreenList(status_screen_type); | ||
121 | for (Map<String,Object> map : statusList){ | ||
122 | if("wdyx".equals(map.get("code"))){ | ||
123 | statusValueMap.put(map.get("value").toString(),"wdyx-"+map.get("name").toString());//稳定运行 | ||
124 | } | ||
125 | if("qwth".equals(map.get("code"))){ | ||
126 | statusValueMap.put(map.get("value").toString(),"qwth-"+map.get("name").toString());//轻微退化 | ||
127 | } | ||
128 | if("mxxj".equals(map.get("code"))){ | ||
129 | statusValueMap.put(map.get("value").toString(),"mxxj-"+map.get("name").toString());//明显下降 | ||
130 | } | ||
131 | if("jjbf".equals(map.get("code"))){ | ||
132 | statusValueMap.put(map.get("value").toString(),"jjbf-"+map.get("name").toString());//接近报废 | ||
133 | } | ||
134 | } | ||
135 | return statusValueMap; | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * 计算故障评分 | ||
140 | * @param gzCount 设备信息 | ||
141 | * @param qz 权重因子 | ||
142 | * @return 返回计算得到的故障评分 | ||
143 | */ | ||
144 | private double getFaultScore(String gzCount, double qz) { | ||
145 | double score = 100.00; | ||
146 | if(Double.valueOf(gzCount) >= 4){ | ||
147 | score = 0.00; | ||
148 | }else{ | ||
149 | score = 100 - 100*Double.valueOf(gzCount)/4; | ||
150 | } | ||
151 | return DoubleOperaUtils.bigDecimalRound(qz * score,2); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * 计算维护得分 | ||
156 | * @param maintenanceCost 设备维护费用 | ||
157 | * @param originalValue 购置金额 | ||
158 | * @param qz 权重 | ||
159 | * @return 返回计算得到的维护得分 | ||
160 | */ | ||
161 | private double getMaintainScore(String maintenanceCost, String originalValue, double qz) { | ||
162 | double score = 100.00; | ||
163 | if(ConvertUtils.isNotEmpty(originalValue)){ | ||
164 | double gzfy = Double.valueOf(originalValue); | ||
165 | double whfy = Double.valueOf(maintenanceCost); | ||
166 | score = 100*(gzfy-whfy)/gzfy; | ||
167 | } | ||
168 | return DoubleOperaUtils.bigDecimalRound(qz * score,2); | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * 计算使用寿命得分 | ||
173 | * @param workingLife 使用年限 | ||
174 | * @param installDate 安装日期 | ||
175 | * @param today 当前日期 | ||
176 | * @param qz 权重因子 | ||
177 | * @return 返回使用寿命得分,固定为100分的20% | ||
178 | */ | ||
179 | private double getUseYearScore(String workingLife, String installDate, String today, double qz) { | ||
180 | double score = 100.00; | ||
181 | if(ConvertUtils.isNotEmpty(installDate)){ | ||
182 | if(ConvertUtils.isNotEmpty(workingLife)){ | ||
183 | double sjsy = Double.valueOf(DateUtils.dayDiff(installDate,today)); | ||
184 | double sm = 365*Double.valueOf(workingLife); | ||
185 | score = 100 * (sm-sjsy)/sm; | ||
186 | } | ||
187 | } | ||
188 | return DoubleOperaUtils.bigDecimalRound(qz * score,2); | ||
189 | } | ||
190 | |||
191 | } |
... | @@ -87,4 +87,9 @@ public interface IEquipmentInfoService extends IService<EquipmentInfo> { | ... | @@ -87,4 +87,9 @@ public interface IEquipmentInfoService extends IService<EquipmentInfo> { |
87 | String reCreateQrCode(String id); | 87 | String reCreateQrCode(String id); |
88 | 88 | ||
89 | void batchConfigDigitaltwins(JSONObject jsonObject); | 89 | void batchConfigDigitaltwins(JSONObject jsonObject); |
90 | |||
91 | List<EquipmentInfo> getEquipmentList(); | ||
92 | |||
93 | List<Map<String, Object>> getScreenList(String screenType); | ||
94 | |||
90 | } | 95 | } | ... | ... |
... | @@ -3,11 +3,7 @@ package com.skua.modules.equipment.service.impl; | ... | @@ -3,11 +3,7 @@ package com.skua.modules.equipment.service.impl; |
3 | import java.io.File; | 3 | import java.io.File; |
4 | import java.io.IOException; | 4 | import java.io.IOException; |
5 | import java.io.InputStream; | 5 | import java.io.InputStream; |
6 | import java.util.ArrayList; | 6 | import java.util.*; |
7 | import java.util.HashMap; | ||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | import java.util.Set; | ||
11 | 7 | ||
12 | import cn.hutool.json.JSONObject; | 8 | import cn.hutool.json.JSONObject; |
13 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 9 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
... | @@ -79,7 +75,6 @@ public class EquipmentInfoServiceImpl extends ServiceImpl<EquipmentInfoMapper, E | ... | @@ -79,7 +75,6 @@ public class EquipmentInfoServiceImpl extends ServiceImpl<EquipmentInfoMapper, E |
79 | @Autowired | 75 | @Autowired |
80 | private IEquipmentAssetService equipmentAssetService; | 76 | private IEquipmentAssetService equipmentAssetService; |
81 | 77 | ||
82 | |||
83 | @Override | 78 | @Override |
84 | public void addData(Result<EquipmentVO> result, EquipmentDTO equipmentDTO) throws Exception { | 79 | public void addData(Result<EquipmentVO> result, EquipmentDTO equipmentDTO) throws Exception { |
85 | 80 | ||
... | @@ -360,4 +355,14 @@ public class EquipmentInfoServiceImpl extends ServiceImpl<EquipmentInfoMapper, E | ... | @@ -360,4 +355,14 @@ public class EquipmentInfoServiceImpl extends ServiceImpl<EquipmentInfoMapper, E |
360 | } | 355 | } |
361 | } | 356 | } |
362 | 357 | ||
358 | @Override | ||
359 | public List<EquipmentInfo> getEquipmentList() { | ||
360 | return equipmentInfoMapper.getEquipmentList(); | ||
361 | } | ||
362 | |||
363 | @Override | ||
364 | public List<Map<String, Object>> getScreenList(String screenType) { | ||
365 | return equipmentInfoMapper.getScreenList(screenType); | ||
366 | } | ||
367 | |||
363 | } | 368 | } | ... | ... |
-
请 注册 或 登录 后发表评论