From 908e6d98a51ee5d0f219180625140012b845b8c1 Mon Sep 17 00:00:00 2001
From: 野心家 <1051256694@qq.com>
Date: 星期四, 25 五月 2023 09:04:13 +0800
Subject: [PATCH] 消防,BUG

---
 src/main/java/com/zy/core/netty/handle/PackageServerHandler.java |  103 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 101 insertions(+), 2 deletions(-)

diff --git a/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java b/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java
index d91b1f1..faa5fdd 100644
--- a/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java
+++ b/src/main/java/com/zy/core/netty/handle/PackageServerHandler.java
@@ -1,13 +1,28 @@
 package com.zy.core.netty.handle;
 
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
+import com.core.common.DateUtils;
+import com.core.common.SpringUtils;
+import com.zy.asrs.entity.FireLog;
+import com.zy.asrs.entity.LocMast;
+import com.zy.asrs.service.FireLogService;
+import com.zy.asrs.service.LocMastService;
+import com.zy.asrs.service.impl.MainServiceImpl;
+import com.zy.asrs.utils.Utils;
 import com.zy.core.netty.AbstractInboundHandler;
 import com.zy.core.netty.cache.ChannelCache;
+import com.zy.core.netty.constant.Constant;
+import com.zy.core.netty.constant.FireDataType;
 import com.zy.core.netty.domain.ChPackage;
+import com.zy.core.netty.domain.fire.Fire_3030;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+
+import java.util.Date;
 
 /**
  * 鍥芥爣涓氬姟澶勭悊handler
@@ -18,10 +33,62 @@
 @ChannelHandler.Sharable
 public class PackageServerHandler extends AbstractInboundHandler<ChPackage> {
 
-
+    @Autowired
+    private MainServiceImpl mainService;
+    //娑堥槻蹇冭烦锛岀伀璀�
     @Override
     protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) {
-        log.info("{}", pac.getBytes().length);
+        FireDataType dataType = FireDataType.get(pac.getBytes()[1], pac.getBytes()[2]);
+        Fire_3030 fire3030 = new Fire_3030().readFromBytes(pac.getBytes());
+        switch (dataType) {
+            case HEARTBEAT:
+                ChannelCache.setChannel(String.valueOf(fire3030.getNo()), ctx.channel());
+                Constant.errorMap.remove(fire3030.getNo());
+                LocMastService locMastService2 = SpringUtils.getBean(LocMastService.class);
+                break;
+            case FIRE_ALARM:
+                //娑堥槻IO鐐圭紪鍙�
+//                String fireNo = fire3030.getNo().toString() + fire3030.getLoop().toString() + fire3030.getPartNo().toString();
+                String fireNo =fire3030.getPartNo().toString();  //0100201 瀵瑰簲  30 31   0200201 瀵瑰簲 34 35
+                int count=Integer.valueOf(fireNo)/2+Integer.valueOf(fireNo)%2;
+                fireNo=""+count;
+//                String fireTime = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay()
+//                        + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds();
+                Date dt = new Date();
+                LocMastService locMastService = SpringUtils.getBean(LocMastService.class);
+                if(null != locMastService){
+                    //鎶ヨ淇″彿鏇存柊鍒板簱瀛樹富妗� fire_status瀛楁
+                    LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("fire_no",fireNo));
+                    if(null != locMast){
+                        if(locMast.getFireStatus() != 1) {
+                            locMast.setFireStatus(1);
+                            locMast.setModiTime(new Date());
+                            locMastService.update(locMast, new EntityWrapper<LocMast>().eq("fire_no", fireNo));
+                        }
+
+                        //鎻掑叆鎶ヨ鏃ュ織璁板綍锛屽悓涓�搴撲綅鍚屼竴鎶ヨ鍙彃鍏ヤ竴娆�
+                        FireLogService fireLogService = SpringUtils.getBean(FireLogService.class);
+                        if(null != fireLogService){
+                            String ymd = "20" + fire3030.getYear() + "" + fire3030.getMonth() + "" + fire3030.getDay();
+                            FireLog one = fireLogService.selectOne(new EntityWrapper<FireLog>()
+                                    .eq("ymd",ymd)
+                                    .eq("fire_no",fireNo));
+                            if(null == one) {
+                                FireLog fireLog = new FireLog();
+                                fireLog.setYmd(ymd);
+                                fireLog.setFireNo(fireNo);
+                                fireLog.setFireTime(dt);
+                                fireLog.setLocNo(locMast.getLocNo());
+                                fireLog.setCreateTime(new Date());
+                                fireLogService.insert(fireLog);
+                            }
+                        }
+                    }
+                }
+                break;
+            default:
+                break;
+        }
         return true;
     }
 
@@ -37,4 +104,36 @@
         }
         channel.writeAndFlush(chPackage);
     }
+
+    /**************************************** 娴嬭瘯涓撶敤 *****************************************/
+    public static void main(String[] args){
+        byte[] rfidBytes = new byte[]{(byte)0xA0, 0x13, 0x01, (byte)0x8A, (byte)0xB6, 0x30, 0x00,
+                0x38, 0x30, 0x33, 0x34, 0x35, 0x36, 0x37, (byte)0x38, 0x28, (byte)0xC3, (byte)0x81, 0x2D, (byte)0xB0, 0x2F };
+        if(rfidBytes.length > 15) {
+            byte[] dataBytes = new byte[8];
+            dataBytes[0] = rfidBytes[7];
+            dataBytes[1] = rfidBytes[8];
+            dataBytes[2] = rfidBytes[9];
+            dataBytes[3] = rfidBytes[10];
+            dataBytes[4] = rfidBytes[11];
+            dataBytes[5] = rfidBytes[12];
+            dataBytes[6] = rfidBytes[13];
+            dataBytes[7] = rfidBytes[14];
+            String str = new String(dataBytes);
+            String barcode = new String(rfidBytes,7,8);
+            System.out.println(str);
+        }
+
+        String aa= "ILY0127 0001";
+        byte[] byteAa = aa.getBytes();
+
+        byte[] bytes = new byte[]{(byte)0x82, 0x38, 0x30, 0x32, 0x34, 0x30, 0x38, 0x39, 0x3B, 0x30, 0x31, 0x31, 0x31,
+                                    0x30, 0x33, 0x30, 0x38, 0x31, 0x30, 0x30, 0x34, 0x30, 0x38, 0x38, 0x30, (byte)0x83};
+        Fire_3030 fire3030 = new Fire_3030().readFromBytes(bytes);
+        String now = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay()
+                + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds();
+        //娑堥槻IO鐐圭紪鍙�
+        String fireNo = fire3030.getNo().toString() + fire3030.getLoop().toString() + fire3030.getPartNo().toString();
+        System.out.println(fireNo);
+    }
 }

--
Gitblit v1.9.1