|
@@ -39,6 +39,7 @@ import java.util.stream.Collectors;
|
|
|
@EnableAsync
|
|
|
public class OpcTaskService {
|
|
|
|
|
|
+ private final RemoteOpcMapper remoteOpcMapper;
|
|
|
private final RemoteOpcLogMapper remoteOpcLogMapper;
|
|
|
|
|
|
/**
|
|
@@ -51,10 +52,19 @@ public class OpcTaskService {
|
|
|
log.info("开始定时任务");
|
|
|
List<OpcResult> resultList = OpcDAClient.getItemValuesList();
|
|
|
if (!CollectionUtils.isEmpty(resultList)) {
|
|
|
- log.info("resultList数量:" + resultList.size());
|
|
|
- String str = JSON.toJSONString(resultList);
|
|
|
- //log.info("str: " + str);
|
|
|
- RedisUtils.setString("opcList", str);
|
|
|
+ //log.info("resultList数量:" + resultList.size());
|
|
|
+ RedisUtils.setString("opcList", JSON.toJSONString(resultList));
|
|
|
+ // 更新数据库实时数据
|
|
|
+ List<RemoteOpc> remoteOpcList = new ArrayList<>();
|
|
|
+ LocalDateTime localDateTime = LocalDateTime.now();
|
|
|
+ for (OpcResult result : resultList) {
|
|
|
+ RemoteOpc remoteOpc = new RemoteOpc();
|
|
|
+ remoteOpc.setResult(result.getValue());
|
|
|
+ remoteOpc.setPositionNum(result.getId());
|
|
|
+ remoteOpc.setUpdateTime(localDateTime);
|
|
|
+ remoteOpcList.add(remoteOpc);
|
|
|
+ }
|
|
|
+ remoteOpcMapper.updateBatch(remoteOpcList);
|
|
|
}
|
|
|
log.info("结束定时任务");
|
|
|
}
|
|
@@ -72,9 +82,7 @@ public class OpcTaskService {
|
|
|
log.info("开始读取redis");
|
|
|
String jsonStr = RedisUtils.getString("opcList");
|
|
|
if (StringUtils.isNotBlank(jsonStr)) {
|
|
|
- log.info("jsonStr2:" + jsonStr);
|
|
|
List<OpcResult> resultList = JSON.parseArray(jsonStr, OpcResult.class);
|
|
|
- log.info("resultList数量:" + resultList.size());
|
|
|
/*for(OpcResult result: resultList){
|
|
|
log.info("id: " + result.getId() + ", value: " + result.getValue() + ", time: " + result.getTime());
|
|
|
}*/
|