Ver código fonte

新增液位发送接口,每天凌晨发送前一天数据

hfxc226 3 dias atrás
pai
commit
77ee1bd476

+ 3 - 1
platform-dao/src/main/java/com/platform/dao/enums/SysConfigEnum.java

@@ -65,7 +65,9 @@ public enum SysConfigEnum {
     PREPARATION_SPECIAL_DEPT_IDS("指定某些部门含默认审核主管和部门负责人"),
     TRANSFER_DEPT_IDS("需要转化的部门ID集合"),
     PREPARATION_SPECIAL_USER_IDS("指定账号ID为默认审核主管和部门负责人"),
-    PURCHASE_SYSTEM_URL_DEGREE("采购系统接收电量数据的接口");
+    PURCHASE_SYSTEM_URL_DEGREE("采购系统接收电量数据的接口"),
+    PURCHASE_DEGREE_NO("采购系统需要的电量数据的点位"),
+    PURCHASE_SYSTEM_URL_YEWEI("采购系统接收液位数据的接口");
     private final String typeName;
 
 }

+ 86 - 6
platform-rest/src/main/java/com/platform/rest/task/DegreeTask.java

@@ -1,23 +1,30 @@
 package com.platform.rest.task;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.platform.common.cache.ConfigCache;
+import com.platform.common.constant.RedisKeyConstants;
 import com.platform.common.exception.BusinessException;
 import com.platform.common.util.DateUtils;
 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.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.remote.RemotePositionService;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 import tk.mybatis.mapper.util.StringUtil;
 
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
 
 /**
  * @Description 电量数据发送给生产采购系统
@@ -32,9 +39,11 @@ public class DegreeTask {
 
     private final BigScreenSbInfoService bigScreenSbInfoService;
 
+    private final RemotePositionService sbPositionService;
+
     /**
      * 每天凌晨发送前天的数据
-     *
+     * <p>
      * http://192.168.16.226/api/ignores/produce/record/dian
      */
     public void generateDian() throws IOException {
@@ -47,13 +56,13 @@ public class DegreeTask {
 
         // 发送到采购系统
         String url = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.PURCHASE_SYSTEM_URL_DEGREE.name());
-        if(StringUtil.isEmpty(url)){
+        if (StringUtil.isEmpty(url)) {
             throw new BusinessException("请配置采购系统电量接收地址");
         }
         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<>();
         data.put("value", value);
         data.put("date", DateUtils.dateToString(date, DateUtils.PATTERN_YMD));
@@ -64,9 +73,80 @@ public class DegreeTask {
             e.printStackTrace();
         }
     }
+
     public static void main(String[] args) {
         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);
+    }
+
+    public static void setDegreeValue(String url, List<RemoteOpcVO> list) {
+
+        // 发送
+        List<Map<String, String>> dataList = new ArrayList<>();
+        LocalDate localDate = LocalDate.now().plusDays(-1);
+        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() throws IOException {
+
+
+        // 找到配置的点位数据,逗号分割,点位编号
+        String positions = ConfigCache.getLabelByValueAllowNull(SysConfigEnum.PURCHASE_DEGREE_NO.name());
+        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("请配置采购系统液位接收地址");
+            }
+        }
     }
 
+
 }