|
@@ -1,8 +1,10 @@
|
|
package com.platform.opc.servie;
|
|
package com.platform.opc.servie;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.platform.common.constant.UpmsRedisKeyConstants;
|
|
import com.platform.common.constant.UpmsRedisKeyConstants;
|
|
import com.platform.common.util.BeanUtils;
|
|
import com.platform.common.util.BeanUtils;
|
|
import com.platform.common.util.RedisUtils;
|
|
import com.platform.common.util.RedisUtils;
|
|
|
|
+import com.platform.common.util.StringUtils;
|
|
import com.platform.dao.entity.remote.RemoteOpc;
|
|
import com.platform.dao.entity.remote.RemoteOpc;
|
|
import com.platform.dao.mapper.remote.RemoteOpcMapper;
|
|
import com.platform.dao.mapper.remote.RemoteOpcMapper;
|
|
import com.platform.dao.mapper.upms.SysDictMapper;
|
|
import com.platform.dao.mapper.upms.SysDictMapper;
|
|
@@ -16,8 +18,10 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
import javax.annotation.PostConstruct;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -38,9 +42,11 @@ public class OpcTaskService {
|
|
public void getValue(){
|
|
public void getValue(){
|
|
log.info("开始定时任务");
|
|
log.info("开始定时任务");
|
|
List<OpcResult> resultList = OpcDAClient.getItemValuesList();
|
|
List<OpcResult> resultList = OpcDAClient.getItemValuesList();
|
|
- log.info("resultList数量:" + resultList.size());
|
|
|
|
- log.info("数据存入redis");
|
|
|
|
- RedisUtils.setList("opcList", resultList);
|
|
|
|
|
|
+ if(!CollectionUtils.isEmpty(resultList)){
|
|
|
|
+ log.info("resultList数量:" + resultList.size());
|
|
|
|
+ String str = JSON.toJSONString(resultList);
|
|
|
|
+ RedisUtils.setString("opcList", str);
|
|
|
|
+ }
|
|
log.info("结束定时任务");
|
|
log.info("结束定时任务");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -55,11 +61,15 @@ public class OpcTaskService {
|
|
@Scheduled(fixedDelay = 60000) //间隔60秒
|
|
@Scheduled(fixedDelay = 60000) //间隔60秒
|
|
public void saveValue(){
|
|
public void saveValue(){
|
|
log.info("开始读取redis");
|
|
log.info("开始读取redis");
|
|
- List<OpcResult> resultList = RedisUtils.getList("opcList", 0 , -1);
|
|
|
|
- log.info("resultList数量:" + resultList.size());
|
|
|
|
- /*for(OpcResult result: resultList){
|
|
|
|
- log.info("id: " + result.getId() + ", value: " + result.getValue() + ", time: " + result.getTime());
|
|
|
|
- }*/
|
|
|
|
|
|
+ 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());
|
|
|
|
+ }*/
|
|
|
|
+ }
|
|
log.info("结束读取redis");
|
|
log.info("结束读取redis");
|
|
}
|
|
}
|
|
}
|
|
}
|