浏览代码

104模块

hfxc226 2 年之前
父节点
当前提交
0a3fbf332c

+ 1 - 0
platform-common/src/main/java/com/platform/common/yongyou/response/GetCurrentStock.java

@@ -12,6 +12,7 @@ import java.time.LocalDate;
  */
 @Data
 public class GetCurrentStock extends BaseResponse{
+    private Integer AutoId; ;// 仓库备件唯一id和sparestore id一样
     private Integer PartId; ;// ;//  partid 86
     private String cWhCode; ;// 仓库编码 "03"
     private String cWhName; ;// 仓库名称 "半成品库"

+ 18 - 0
platform-iec/src/main/java/com/platform/iec/IecApplication.java

@@ -2,6 +2,8 @@ package com.platform.iec;
 
 import com.platform.iec.master.MasterSysDataHandler;
 import com.ydl.iec.iec104.config.Iec104Config;
+import com.ydl.iec.iec104.core.Iec104ThreadLocal;
+import com.ydl.iec.iec104.core.ScheduledTaskPool;
 import com.ydl.iec.iec104.server.Iec104MasterFactory;
 import com.ydl.iec.util.Iec104Util;
 import lombok.extern.slf4j.Slf4j;
@@ -9,7 +11,10 @@ import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.core.annotation.Order;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
 
+import java.time.LocalDateTime;
 import java.util.TimeZone;
 
 /**
@@ -19,6 +24,7 @@ import java.util.TimeZone;
  * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
  */
 @SpringBootApplication
+@EnableScheduling
 @Order(1)
 @Slf4j
 public class IecApplication implements CommandLineRunner {
@@ -37,4 +43,16 @@ public class IecApplication implements CommandLineRunner {
         Iec104MasterFactory.createTcpClientMaster(Iec104Util.host, Iec104Util.port).setDataHandler(new MasterSysDataHandler()).setConfig(iec104Config).run();
         Thread.sleep(1000000);
     }
+
+    /**
+     * 每小时,五分钟
+     * {秒数} {分钟} {小时} {日期} {月份} {星期} {年份(可为空)}
+     */
+    @Scheduled(cron = "0 */1 * * * ?")
+   private void configureTasks() {
+        log.info("执行总召唤");
+        Iec104ThreadLocal.getScheduledTaskPool().sendStartFrame();
+        Iec104ThreadLocal.getScheduledTaskPool().sendGeneralCall();
+        log.info("执行总召唤,定时任务时间: " + LocalDateTime.now());
+    }
 }

+ 11 - 5
platform-iec/src/main/java/com/platform/iec/master/MasterSysDataHandler.java

@@ -8,8 +8,11 @@ import com.ydl.iec.iec104.server.handler.ChannelHandler;
 import com.ydl.iec.iec104.server.handler.DataHandler;
 import com.ydl.iec.util.ByteUtil;
 import com.ydl.iec.util.Iec104Util;
+import com.ydl.iec.util.MySqlUtil;
 import lombok.extern.slf4j.Slf4j;
 
+import java.time.LocalDateTime;
+
 
 @Slf4j
 public class MasterSysDataHandler implements DataHandler {
@@ -47,12 +50,9 @@ public class MasterSysDataHandler implements DataHandler {
 		log.info("判断是否有限定词:" + ruleDetail104.getQualifiersType());
 		log.info("判断是否有时标:" + ruleDetail104.isTimeScaleExit());
 		log.info("判断消息是否连续:" + ruleDetail104.isContinuous());
+
 		if(ruleDetail104.getMeasgLength()>0){
-			for (int i = 0; i<ruleDetail104.getMeasgLength();i++) {
-				MessageInfo messageInfo = ruleDetail104.getMessages().get(i);
-				log.info(i + "-消息地址:" + messageInfo.getMessageAddress());
-				log.info(i + "-数据:" + ByteUtil.byteArrayToHexString(messageInfo.getMessageInfos()));
-			}
+			MySqlUtil.dealMessage(ruleDetail104 );
 		}
 		try {
 			log.info("是否有消息元素:" + ruleDetail104.getQualifiersType().getValue());
@@ -74,6 +74,12 @@ public class MasterSysDataHandler implements DataHandler {
 		byte[] bytes = {1};
 		String strContent = ByteUtil.byteArrayToHexString(bytes);
 		System.out.println(strContent);
+
+		LocalDateTime time = LocalDateTime.now();
+		System.out.println(time.getYear());
+		System.out.println(time.getMonthValue());
+		System.out.println(time.getDayOfMonth());
+		System.out.println(time.getHour());
 	}
 
 }

+ 0 - 3
platform-iec/src/main/java/com/ydl/iec/iec104/core/Iec104ThreadLocal.java

@@ -26,9 +26,6 @@ public class Iec104ThreadLocal {
 	 */
 	private static ThreadLocal<Iec104Config> iec104ConfigThreadLocal = new ThreadLocal<>();
 
-
-
-
 	public static void setScheduledTaskPool(ScheduledTaskPool scheduledTaskPool) {
 		scheduledTaskPoolThreadLocal.set(scheduledTaskPool);
 	}

+ 6 - 2
platform-iec/src/main/java/com/ydl/iec/iec104/core/ScheduledTaskPool.java

@@ -6,6 +6,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter;
 import lombok.extern.slf4j.Slf4j;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Scheduled;
 
 
 /**
@@ -53,6 +54,10 @@ public class ScheduledTaskPool {
 	 */
 	private Thread generalCallTThread;
 
+	public Thread getGeneralCallTThread(){
+		return generalCallTThread;
+	}
+
 	public ScheduledTaskPool(ChannelHandlerContext ctx) {
 		this.ctx = ctx;
 	}
@@ -98,7 +103,6 @@ public class ScheduledTaskPool {
 			sendStatrStatus = false;
 		}
 	}
-
 	
 	/**
 	 * 
@@ -159,7 +163,7 @@ public class ScheduledTaskPool {
 						try {
 							LOGGER.info("发送总召唤指令");
 							ctx.channel().writeAndFlush(BasicInstruction104.getGeneralCallRuleDetail104());
-							Thread.sleep(1000 * 60 * 3);
+							Thread.sleep(1000 * 60 * 15);// 15分钟
 						} catch (Exception e) {
 							e.printStackTrace();
 						}

+ 87 - 34
platform-iec/src/main/java/com/ydl/iec/util/MySqlUtil.java

@@ -4,12 +4,18 @@ import com.platform.common.exception.BusinessException;
 import com.platform.common.exception.DeniedException;
 import com.platform.common.util.DateUtils;
 import com.platform.common.util.IdGeneratorUtils;
+import com.platform.common.util.SecurityUtils;
 import com.platform.common.util.StringUtils;
+import com.ydl.iec.iec104.message.MessageDetail;
+import com.ydl.iec.iec104.message.MessageInfo;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.util.CollectionUtils;
 
 import java.sql.*;
 import java.time.LocalDateTime;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Slf4j
@@ -56,23 +62,57 @@ public class MySqlUtil {
     }
 
     /**
-     * 更新遥测数据
-     * @param positionNum
-     * @param result
+     * 处理数据
+     *
+     * @param ruleDetail104
      */
-    public static void updateRemoteMeasureByPositionNum(Integer positionNum, String result) {
+    public static void dealMessage(MessageDetail ruleDetail104) {
+        LocalDateTime time = LocalDateTime.now();
+        int year = time.getYear();
+        int month = time.getMonthValue();
+        int day = time.getDayOfMonth();
+        int hour = time.getHour();
+        List<MessageInfo> addMessage = new ArrayList<>();
+        List<MessageInfo> updateMessage = new ArrayList<>();
+        for (int i = 0; i < ruleDetail104.getMeasgLength(); i++) {
+            MessageInfo messageInfo = ruleDetail104.getMessages().get(i);
+            if (messageInfo.getMessageAddress() >= remote_config_degree_min && messageInfo.getMessageAddress() <= remote_config_degree_max) {
+                addMessage.add(messageInfo);
+            } else if (messageInfo.getMessageAddress() >= remote_config_measure_min && messageInfo.getMessageAddress() <= remote_config_measure_max) {
+                updateMessage.add(messageInfo);
+            }
+        }
+        // 新增电度数据
+        if (!CollectionUtils.isEmpty(addMessage)) {
+            addBatch(addMessage, time, year, month, day, hour);
+        }
+        // 更新遥测数据
+        if (!CollectionUtils.isEmpty(addMessage)) {
+            updateBatch(updateMessage);
+        }
+    }
+
+    /**
+     * 更新遥测数据,批量更新
+     *
+     * @param list
+     */
+    public static void updateBatch(List<MessageInfo> list) {
         Statement stmt = null;
-        StringBuffer updateSql = new StringBuffer("update " + "t_remote_measure" + " set " +
-                "result='" + result +
-                "' where position_num=" + positionNum);
-        log.info("更新数据:" + updateSql);
         try {
             conn = getConnection();
             stmt = conn.createStatement();
+            for (int i = 0; i < list.size(); i++) {
+                MessageInfo messageInfo = list.get(i);
+                String updateSql = "update t_remote_measure set result='" + ByteUtil.byteArrayToHexString(messageInfo.getMessageInfos()) +
+                        "' where position_num = " + messageInfo.getMessageAddress();
+                stmt.addBatch(updateSql);
+            }
+
             // 获取总条数
-            int num = stmt.executeUpdate(updateSql.toString());
-            if (num != 1) {
-                throw new BusinessException("更新t_remote_measure失败,定位信息:" +positionNum );
+            int[] num = stmt.executeBatch();
+            if (num.length == 0) {
+                throw new BusinessException("批量更新t_remote_measure失败");
                 // 找不到定位数据,属于新增,则对应新增进入库,但是没有系数也不好处理
             }
             stmt.close();
@@ -94,31 +134,43 @@ public class MySqlUtil {
         }
     }
 
+
     /**
      * 记录电度数据-每一条新增保存
-     * @param positionNum
-     * @param result
+     *
+     * @param list
      * @param time
+     * @param year
+     * @param month
+     * @param day
+     * @param hour
      */
-    public static void addRemoteDegreeByPositionNum(Integer positionNum, String result, String time) {
+    public static void addBatch(List<MessageInfo> list, LocalDateTime time, Integer year, Integer month, Integer day, Integer hour) {
         Statement stmt = null;
         try {
-            if (StringUtils.isBlank(time)) {
-                time = DateUtils.dateToString(LocalDateTime.now(), DateUtils.PATTERN_YMD_HMS);
+            for (int i = 0; i < list.size(); i++) {
+                MessageInfo messageInfo = list.get(i);
+                StringBuffer sql = new StringBuffer();
+                sql.append("insert into " + " t_remote_degree_log " +
+                        " (id,position_num,year,month,day,hour,result,remark,created_time,created_user_id) values ");
+                sql.append("(");
+                sql.append("'" + IdGeneratorUtils.getObjectId() + "',");
+                sql.append("" + messageInfo.getMessageAddress() + ",");
+                sql.append("" + year + ",");
+                sql.append("" + month + ",");
+                sql.append("" + day + ",");
+                sql.append("" + hour + ",");
+                sql.append("'" + messageInfo + "',");
+                sql.append("'" + ByteUtil.byteArrayToHexString(messageInfo.getMessageInfos()) + "',");
+                sql.append("'" + DateUtils.dateToString(time, DateUtils.PATTERN_YMD_HMS) + "'");
+                sql.append("'" + 1 + "',");// 创建人
+                sql.append(")");
+                stmt.addBatch(sql.toString());
             }
-            StringBuffer sql = new StringBuffer();
-            sql.append("insert into " + " t_remote_degree_log " +
-                    " (id,position_num,result,created_time) values ");
-            sql.append("(");
-            sql.append("'" + IdGeneratorUtils.getObjectId() + "',");
-            sql.append("" + positionNum + ",");
-            sql.append("'" + result + "',");
-            sql.append("'" + time + "'");
-            sql.append(")");
-            log.info("----------" + sql.toString());
+
             conn = getConnection();
             stmt = conn.createStatement();
-            stmt.executeUpdate(sql.toString());
+            stmt.executeBatch();
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
@@ -134,17 +186,18 @@ public class MySqlUtil {
     /**
      * 查询遥测最高最低点位
      * 查询电度最高最低点位
+     *
      * @param type 1 遥测
      *             2 电度
      */
     public static Map<String, Integer> selectRemotePositionMap(int type) {
         Statement stmt = null;
         ResultSet rs = null;
-        Map<String, Integer> map= new HashMap<>();
-        if(type==1){
+        Map<String, Integer> map = new HashMap<>();
+        if (type == 1) {
             map.put("low", remote_config_measure_min);
             map.put("max", remote_config_measure_max);
-        }else{
+        } else {
             map.put("low", remote_config_degree_min);
             map.put("max", remote_config_degree_max);
         }
@@ -158,15 +211,15 @@ public class MySqlUtil {
             rs = stmt.executeQuery(sql.toString());
             rs.next();
             String content = rs.getString(1);
-            if(StringUtils.isBlank(content)){
+            if (StringUtils.isBlank(content)) {
                 log.error("点位最低最高未配置,将使用默认配置,请联系管理员配置,结构:遥测最低,遥测最高;电度最低,电度最高");
                 return map;
             }
             String[] arr = content.split(";");
-            if(type==1){
+            if (type == 1) {
                 map.put("min", Integer.valueOf(arr[0].split(",")[0]));
                 map.put("max", Integer.valueOf(arr[0].split(",")[1]));
-            }else{
+            } else {
                 map.put("min", Integer.valueOf(arr[1].split(",")[0]));
                 map.put("max", Integer.valueOf(arr[1].split(",")[1]));
             }
@@ -184,7 +237,7 @@ public class MySqlUtil {
         return map;
     }
 
-    public static void handler(){
+    public static void handler() {
 
     }
 }

+ 11 - 5
platform-rest/src/main/java/com/platform/rest/controller/yongyou/YongyouController.java

@@ -21,6 +21,7 @@ import com.platform.rest.log.annotation.SysLog;
 import com.platform.service.store.SparePickFormService;
 import com.platform.service.yongyou.YongyouService;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
@@ -36,6 +37,7 @@ import java.util.List;
  */
 @RestController
 @AllArgsConstructor
+@Slf4j
 @RequestMapping("/yongyou")
 public class YongyouController {
 
@@ -58,8 +60,8 @@ public class YongyouController {
      * 查询用友存量库存分页数据
      *
      * @param spareStoreDTO 备件查询条件DTO
-     * @param pageNum          当前页码
-     * @param pageSize         每页条数
+     * @param pageNum       当前页码
+     * @param pageSize      每页条数
      * @return R
      */
     @GetMapping("/spareStore/page")
@@ -76,10 +78,11 @@ public class YongyouController {
      */
     @SysLog("发起用友出库单")
     @PutMapping("/spare/pick/form/{id}")
-    public R addSparePickForm( @PathVariable("id") String id) {
+    public R addSparePickForm(@PathVariable("id") String id) {
         yongyouService.addOutForm(id);
         return new R<>();
     }
+
     /**
      * 用友回调领用出库单
      * 推送实际出库数量和状态
@@ -89,10 +92,12 @@ public class YongyouController {
      */
     @SysLog("用友回调领用出库单")
     @PostMapping("/spare/pick/form")
-    public R BackSparePickForm( String jsonStr) {
+    public R BackSparePickForm(String jsonStr) {
+        log.info("用友回调领用出库单:,返回数据:" + jsonStr);
         yongyouService.backOutForm(jsonStr);
         return new R<>();
     }
+
     /**
      * 发起用友退库单
      * 推送实际出库数量和状态
@@ -102,10 +107,11 @@ public class YongyouController {
      */
     @SysLog("发起用友退库单")
     @PutMapping("/spare/restore/form/{id}")
-    public R addSpareRestoreForm( @PathVariable("id") String id) {
+    public R addSpareRestoreForm(@PathVariable("id") String id) {
         yongyouService.addOutForm(id);
         return new R<>();
     }
+
     /**
      * 用友回调退库单
      * 推送实际退库数量和状态

+ 1 - 1
platform-service/src/main/java/com/platform/service/yongyou/impl/YongyouServiceImpl.java

@@ -142,7 +142,7 @@ public class YongyouServiceImpl implements YongyouService {
         List<SpareStoreVO> partInfoVOS = new ArrayList<>();
         for (GetCurrentStock stockResponse : stocks) {
             SpareStoreVO partInfoVO = new SpareStoreVO();
-            partInfoVO.setId(stockResponse.getPartId() + "");
+            partInfoVO.setId(stockResponse.getAutoId() + "");
             partInfoVO.setNo(stockResponse.getCInvCode());
             partInfoVO.setSpareId(stockResponse.getPartId() + "");
             partInfoVO.setSpareName(stockResponse.getCInvName());