提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.watch; |
H |
2 |
|
|
3 |
import com.iailab.common.utils.DateUtils; |
|
4 |
import com.iailab.module.data.api.IFeignDataApi; |
|
5 |
import com.iailab.module.data.dto.FeignResultDTO; |
|
6 |
import com.iailab.module.data.dto.FeignWritePointValueDTO; |
|
7 |
import lombok.extern.slf4j.Slf4j; |
|
8 |
import javax.annotation.Resource; |
|
9 |
import org.springframework.stereotype.Component; |
|
10 |
|
|
11 |
import java.math.BigDecimal; |
|
12 |
import java.util.ArrayList; |
|
13 |
import java.util.Date; |
|
14 |
import java.util.List; |
|
15 |
import java.util.Map; |
|
16 |
|
|
17 |
/** |
|
18 |
* @author PanZhibao |
|
19 |
* @Description |
|
20 |
* @createTime 2024年06月05日 |
|
21 |
*/ |
|
22 |
@Slf4j |
|
23 |
@Component |
|
24 |
public class WatchDog { |
|
25 |
|
|
26 |
private long failure_time = 1000 * 10; |
|
27 |
|
|
28 |
@Resource |
|
29 |
private IFeignDataApi feignDataApi; |
|
30 |
|
|
31 |
public int writeWatchDogTime(String writePoint, String readPoint, String statusPoint, int lastHeat) { |
|
32 |
try { |
|
33 |
FeignWritePointValueDTO writeHeart = new FeignWritePointValueDTO(); |
|
34 |
writeHeart.setPointCode(writePoint); |
|
35 |
writeHeart.setPointValue(DateUtils.format(new Date(), DateUtils.TIME2_PATTERN)); |
|
36 |
FeignResultDTO writeHeartResult = feignDataApi.setPointValue(writeHeart); |
|
37 |
if (writeHeartResult.getCode() != 0) { |
|
38 |
log.info("写入心跳值失败"); |
|
39 |
setStsStop(statusPoint); |
|
40 |
return lastHeat; |
|
41 |
} |
|
42 |
List<String> pointNos = new ArrayList<>(); |
|
43 |
pointNos.add(readPoint); |
|
44 |
Map<String, Object> readHeatValue = feignDataApi.getCurrentValue(pointNos); |
|
45 |
Integer heartValue = new BigDecimal(readHeatValue.get(readPoint).toString()).intValue(); |
|
46 |
log.info("heartValue=" + heartValue); |
|
47 |
if (lastHeat == heartValue) { |
|
48 |
log.info("心跳值无变化"); |
|
49 |
setStsStop(statusPoint); |
|
50 |
return lastHeat; |
|
51 |
} |
|
52 |
lastHeat = heartValue; |
|
53 |
setStsNormal(statusPoint); |
|
54 |
} catch (Exception ex) { |
|
55 |
log.error("异常:控制器不能下发随机数;message:" + ex.getMessage()); |
|
56 |
ex.printStackTrace(); |
|
57 |
setStsStop(statusPoint); |
|
58 |
|
|
59 |
} |
|
60 |
return lastHeat; |
|
61 |
} |
|
62 |
|
|
63 |
public boolean isConnect(String pointNo) { |
|
64 |
List<String> pointNos = new ArrayList<>(); |
|
65 |
pointNos.add(pointNo); |
|
66 |
Map<String, Object> pointValue = feignDataApi.getCurrentValue(pointNos); |
|
67 |
Integer value = new BigDecimal(pointValue.get(pointNo).toString()).intValue(); |
|
68 |
return WatchConstant.TX_STS_NORMAL.equals(value); |
|
69 |
} |
|
70 |
|
|
71 |
public boolean isUse(String pointNo) { |
|
72 |
List<String> pointNos = new ArrayList<>(); |
|
73 |
pointNos.add(pointNo); |
|
74 |
Map<String, Object> pointValue = feignDataApi.getCurrentValue(pointNos); |
|
75 |
log.info("isUse=" + pointValue.get(pointNo).toString()); |
|
76 |
return WatchConstant.CONTROLLER_ON.equals(pointValue.get(pointNo).toString()); |
|
77 |
} |
|
78 |
|
|
79 |
public void stopControllerSts(String controllerCode) { |
|
80 |
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO(); |
|
81 |
writeSts.setPointCode(controllerCode); |
|
82 |
writeSts.setPointValue(WatchConstant.CONTROLLER_OFF); |
|
83 |
feignDataApi.setPointValue(writeSts); |
|
84 |
} |
|
85 |
|
|
86 |
public void startControllerSts(String controllerCode) { |
|
87 |
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO(); |
|
88 |
writeSts.setPointCode(controllerCode); |
|
89 |
writeSts.setPointValue(WatchConstant.CONTROLLER_ON); |
|
90 |
feignDataApi.setPointValue(writeSts); |
|
91 |
} |
|
92 |
|
|
93 |
private void setStsStop(String statusPoint) { |
|
94 |
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO(); |
|
95 |
writeSts.setPointCode(statusPoint); |
|
96 |
writeSts.setPointValue(WatchConstant.TX_STS_STOP); |
|
97 |
feignDataApi.setPointValue(writeSts); |
|
98 |
} |
|
99 |
|
|
100 |
private void setStsNormal(String statusPoint) { |
|
101 |
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO(); |
|
102 |
writeSts.setPointCode(statusPoint); |
|
103 |
writeSts.setPointValue(WatchConstant.TX_STS_NORMAL); |
|
104 |
feignDataApi.setPointValue(writeSts); |
|
105 |
} |
|
106 |
|
|
107 |
} |