package com.iailab.module.watch;
|
|
import com.iailab.common.utils.DateUtils;
|
import com.iailab.module.data.api.IFeignDataApi;
|
import com.iailab.module.data.dto.FeignResultDTO;
|
import com.iailab.module.data.dto.FeignWritePointValueDTO;
|
import lombok.extern.slf4j.Slf4j;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Component;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年06月05日
|
*/
|
@Slf4j
|
@Component
|
public class WatchDog {
|
|
private long failure_time = 1000 * 10;
|
|
@Resource
|
private IFeignDataApi feignDataApi;
|
|
public int writeWatchDogTime(String writePoint, String readPoint, String statusPoint, int lastHeat) {
|
try {
|
FeignWritePointValueDTO writeHeart = new FeignWritePointValueDTO();
|
writeHeart.setPointCode(writePoint);
|
writeHeart.setPointValue(DateUtils.format(new Date(), DateUtils.TIME2_PATTERN));
|
FeignResultDTO writeHeartResult = feignDataApi.setPointValue(writeHeart);
|
if (writeHeartResult.getCode() != 0) {
|
log.info("写入心跳值失败");
|
setStsStop(statusPoint);
|
return lastHeat;
|
}
|
List<String> pointNos = new ArrayList<>();
|
pointNos.add(readPoint);
|
Map<String, Object> readHeatValue = feignDataApi.getCurrentValue(pointNos);
|
Integer heartValue = new BigDecimal(readHeatValue.get(readPoint).toString()).intValue();
|
log.info("heartValue=" + heartValue);
|
if (lastHeat == heartValue) {
|
log.info("心跳值无变化");
|
setStsStop(statusPoint);
|
return lastHeat;
|
}
|
lastHeat = heartValue;
|
setStsNormal(statusPoint);
|
} catch (Exception ex) {
|
log.error("异常:控制器不能下发随机数;message:" + ex.getMessage());
|
ex.printStackTrace();
|
setStsStop(statusPoint);
|
|
}
|
return lastHeat;
|
}
|
|
public boolean isConnect(String pointNo) {
|
List<String> pointNos = new ArrayList<>();
|
pointNos.add(pointNo);
|
Map<String, Object> pointValue = feignDataApi.getCurrentValue(pointNos);
|
Integer value = new BigDecimal(pointValue.get(pointNo).toString()).intValue();
|
return WatchConstant.TX_STS_NORMAL.equals(value);
|
}
|
|
public boolean isUse(String pointNo) {
|
List<String> pointNos = new ArrayList<>();
|
pointNos.add(pointNo);
|
Map<String, Object> pointValue = feignDataApi.getCurrentValue(pointNos);
|
log.info("isUse=" + pointValue.get(pointNo).toString());
|
return WatchConstant.CONTROLLER_ON.equals(pointValue.get(pointNo).toString());
|
}
|
|
public void stopControllerSts(String controllerCode) {
|
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO();
|
writeSts.setPointCode(controllerCode);
|
writeSts.setPointValue(WatchConstant.CONTROLLER_OFF);
|
feignDataApi.setPointValue(writeSts);
|
}
|
|
public void startControllerSts(String controllerCode) {
|
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO();
|
writeSts.setPointCode(controllerCode);
|
writeSts.setPointValue(WatchConstant.CONTROLLER_ON);
|
feignDataApi.setPointValue(writeSts);
|
}
|
|
private void setStsStop(String statusPoint) {
|
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO();
|
writeSts.setPointCode(statusPoint);
|
writeSts.setPointValue(WatchConstant.TX_STS_STOP);
|
feignDataApi.setPointValue(writeSts);
|
}
|
|
private void setStsNormal(String statusPoint) {
|
FeignWritePointValueDTO writeSts = new FeignWritePointValueDTO();
|
writeSts.setPointCode(statusPoint);
|
writeSts.setPointValue(WatchConstant.TX_STS_NORMAL);
|
feignDataApi.setPointValue(writeSts);
|
}
|
|
}
|