|
@@ -1,23 +1,30 @@
|
|
package com.platform.rest.task;
|
|
package com.platform.rest.task;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.platform.common.cache.ConfigCache;
|
|
import com.platform.common.cache.ConfigCache;
|
|
|
|
+import com.platform.common.constant.RedisKeyConstants;
|
|
import com.platform.common.exception.BusinessException;
|
|
import com.platform.common.exception.BusinessException;
|
|
import com.platform.common.util.DateUtils;
|
|
import com.platform.common.util.DateUtils;
|
|
import com.platform.common.util.HttpUtil;
|
|
import com.platform.common.util.HttpUtil;
|
|
|
|
+import com.platform.common.util.RedisUtils;
|
|
|
|
+import com.platform.common.util.StringUtils;
|
|
import com.platform.dao.dto.remote.RemoteDegreeLogDTO;
|
|
import com.platform.dao.dto.remote.RemoteDegreeLogDTO;
|
|
import com.platform.dao.enums.SysConfigEnum;
|
|
import com.platform.dao.enums.SysConfigEnum;
|
|
|
|
+import com.platform.dao.vo.query.remote.RemoteOpcVO;
|
|
|
|
+import com.platform.dao.vo.remote.RemotePositionVO;
|
|
import com.platform.service.big.BigScreenSbInfoService;
|
|
import com.platform.service.big.BigScreenSbInfoService;
|
|
|
|
+import com.platform.service.remote.RemotePositionService;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
import tk.mybatis.mapper.util.StringUtil;
|
|
import tk.mybatis.mapper.util.StringUtil;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description 电量数据发送给生产采购系统
|
|
* @Description 电量数据发送给生产采购系统
|
|
@@ -26,15 +33,17 @@ import java.util.Map;
|
|
* @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
* @Version Copyright (c) 2020,北京乾元坤和科技有限公司 All rights reserved.
|
|
*/
|
|
*/
|
|
@Slf4j
|
|
@Slf4j
|
|
-@Component("dDegreeTask")
|
|
|
|
|
|
+@Component("degreeTask")
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class DegreeTask {
|
|
public class DegreeTask {
|
|
|
|
|
|
private final BigScreenSbInfoService bigScreenSbInfoService;
|
|
private final BigScreenSbInfoService bigScreenSbInfoService;
|
|
|
|
|
|
|
|
+ private final RemotePositionService sbPositionService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * 每天凌晨发送前天的数据
|
|
|
|
- *
|
|
|
|
|
|
+ * 每天凌晨1点发送前天的数据
|
|
|
|
+ * <p>
|
|
* http://192.168.16.226/api/ignores/produce/record/dian
|
|
* http://192.168.16.226/api/ignores/produce/record/dian
|
|
*/
|
|
*/
|
|
public void generateDian() throws IOException {
|
|
public void generateDian() throws IOException {
|
|
@@ -47,13 +56,13 @@ public class DegreeTask {
|
|
|
|
|
|
// 发送到采购系统
|
|
// 发送到采购系统
|
|
String url = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.PURCHASE_SYSTEM_URL_DEGREE.name());
|
|
String url = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.PURCHASE_SYSTEM_URL_DEGREE.name());
|
|
- if(StringUtil.isEmpty(url)){
|
|
|
|
|
|
+ if (StringUtil.isEmpty(url)) {
|
|
throw new BusinessException("请配置采购系统电量接收地址");
|
|
throw new BusinessException("请配置采购系统电量接收地址");
|
|
}
|
|
}
|
|
setValue(url, localDate, bigDecimal.toString());
|
|
setValue(url, localDate, bigDecimal.toString());
|
|
}
|
|
}
|
|
|
|
|
|
- public static void setValue(String url, LocalDate date, String value){
|
|
|
|
|
|
+ public static void setValue(String url, LocalDate date, String value) {
|
|
Map<String, String> data = new HashMap<>();
|
|
Map<String, String> data = new HashMap<>();
|
|
data.put("value", value);
|
|
data.put("value", value);
|
|
data.put("date", DateUtils.dateToString(date, DateUtils.PATTERN_YMD));
|
|
data.put("date", DateUtils.dateToString(date, DateUtils.PATTERN_YMD));
|
|
@@ -64,9 +73,86 @@ public class DegreeTask {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
String url = "http://localhost:5000/ignores/produce/record/dian";
|
|
String url = "http://localhost:5000/ignores/produce/record/dian";
|
|
- setValue(url, LocalDate.now(), "12562");
|
|
|
|
|
|
+ String url2 = "http://localhost:5000/ignores/produce/record/yewei";
|
|
|
|
+ //setValue(url, LocalDate.now(), "12562");
|
|
|
|
+ List<RemoteOpcVO> list = new ArrayList<>();
|
|
|
|
+ RemoteOpcVO remoteOpcVO = new RemoteOpcVO();
|
|
|
|
+ remoteOpcVO.setPositionNum("1");
|
|
|
|
+ remoteOpcVO.setResult(new BigDecimal(23));
|
|
|
|
+ list.add(remoteOpcVO);
|
|
|
|
+ setDegreeValue(url2, list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 液位,当天11:30开始
|
|
|
|
+ * @param url
|
|
|
|
+ * @param list
|
|
|
|
+ */
|
|
|
|
+ public static void setDegreeValue(String url, List<RemoteOpcVO> list) {
|
|
|
|
+
|
|
|
|
+ // 发送
|
|
|
|
+ List<Map<String, String>> dataList = new ArrayList<>();
|
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
|
+ for (RemoteOpcVO remoteOpcVO : list) {
|
|
|
|
+ Map<String, String> data = new HashMap<>();
|
|
|
|
+ data.put("no", remoteOpcVO.getPositionNum());
|
|
|
|
+ data.put("num", remoteOpcVO.getResult().toString());
|
|
|
|
+ data.put("date", DateUtils.dateToString(localDate, DateUtils.PATTERN_YMD));
|
|
|
|
+ dataList.add(data);
|
|
|
|
+ }
|
|
|
|
+ String requestJson = JSONObject.toJSONString(dataList);
|
|
|
|
+ log.info(requestJson);
|
|
|
|
+ try {
|
|
|
|
+ HttpUtil.post(url, requestJson);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 液位凌晨发送前天的数据,从redis里面获取,然后发送即可
|
|
|
|
+ * 1:
|
|
|
|
+ * <p>
|
|
|
|
+ * http://192.168.16.226/api/ignores/produce/record/yewei
|
|
|
|
+ */
|
|
|
|
+ public void generateYewei() {
|
|
|
|
+ // 找到配置的点位数据,逗号分割,点位编号
|
|
|
|
+ String positions = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.PURCHASE_DEGREE_NO.name());
|
|
|
|
+ if (StringUtils.isBlank(positions)) {
|
|
|
|
+ throw new BusinessException("请配置采集点位");
|
|
|
|
+ }
|
|
|
|
+ List<String> positionList = Arrays.asList(positions.split(","));
|
|
|
|
+ List<RemotePositionVO> remotePositionVOList = sbPositionService.selectVOList(null);
|
|
|
|
+
|
|
|
|
+ // 拿到点位
|
|
|
|
+ List<RemoteOpcVO> list = new ArrayList<>();
|
|
|
|
+ for (RemotePositionVO vo : remotePositionVOList) {
|
|
|
|
+ String jsonStr = RedisUtils.get(RedisKeyConstants.DCS_PREFIX + vo.getId());
|
|
|
|
+ // log.info("jsonStr: " + jsonStr);
|
|
|
|
+ if (StringUtils.isNotBlank(jsonStr)) {
|
|
|
|
+ List<RemoteOpcVO> resultList = JSON.parseArray(jsonStr, RemoteOpcVO.class);
|
|
|
|
+ for (RemoteOpcVO remoteOpcVO : resultList) {
|
|
|
|
+ for (String p : positionList) {
|
|
|
|
+ if (remoteOpcVO.getPositionNum().equals(p)) {
|
|
|
|
+ list.add(remoteOpcVO);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 发送到采购系统
|
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
|
+ String url = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.PURCHASE_SYSTEM_URL_YEWEI.name());
|
|
|
|
+ if (StringUtil.isEmpty(url)) {
|
|
|
|
+ throw new BusinessException("请配置采购系统液位接收地址");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
}
|
|
}
|