소스 검색

plc流程校验、图片上传

985653680@qq.com 11 달 전
부모
커밋
edd46649dd

+ 22 - 3
config.xml

@@ -7,7 +7,7 @@
             <weighbridge>
                 <enable>false</enable>
                 <port>4005</port>
-                <brand></brand>
+                <brand>3000</brand>
                 <minKg>5000</minKg>
             </weighbridge>
             <car>
@@ -52,13 +52,18 @@
     </sysConfig>
     <eventList>
         <event>
-            <name>WEIGHBRIDGE.READ</name>
+            <name>WEIGHBRIDGE.READY</name>
             <!--动作格式 模块.命令-->
             <actionList>
                 <action>LED.LED_SHOW_CONTENT(地磅初始化)</action>
                 <action>CENTER.TIMER_SLEEP(1500)</action>
                 <action>LED.LED_SHOW_CONTENT(即将称重,请停稳车辆)</action>
-                <action>CENTER.TIMER_SLEEP(3000)</action>
+            </actionList>
+        </event>
+        <event>
+            <name>WEIGHBRIDGE.READ</name>
+            <!--动作格式 模块.命令-->
+            <actionList>
                 <action>LED.LED_SHOW_CONTENT(地磅称重中)</action>
                 <action>WEIGHBRIDGE.START_READ</action>
                 <action>LED.LED_SHOW_CONTENT(${weight})</action>
@@ -117,5 +122,19 @@
                 <action>LED.LED_SHOW_CONTENT(地磅称重数据异常,请联系管理人员)</action>
             </actionList>
         </event>
+
+        <event>
+            <name>WEIGHBRIDGE.POSITION_ERROR</name>
+            <actionList>
+                <action>LED.LED_SHOW_CONTENT(车辆位置异常,请完全退出通道后再次进入通道)</action>
+            </actionList>
+        </event>
+        <!--识别车牌异常-->
+        <event>
+            <name>CAPTURE.CAPTURE_FAILED</name>
+            <actionList>
+                <action>LED.LED_SHOW_CONTENT(车牌获取异常,请退车并申请人工处理)</action>
+            </actionList>
+        </event>
     </eventList>
 </config>

+ 3 - 3
src/main/java/com/gzlh/background/client/BackgroundClientHandler.java

@@ -42,9 +42,9 @@ public class BackgroundClientHandler extends SimpleChannelInboundHandler<String>
     @Override
     protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
         System.out.println("Client received: " + msg);
-//        if (!"back message".equalsIgnoreCase(msg)){
-//            eventBus.startEvent(msg);
-//        }
+        if (!"back message".equalsIgnoreCase(msg)){
+            eventBus.startEvent(msg);
+        }
     }
 
 

+ 5 - 0
src/main/java/com/gzlh/bus/EventThread.java

@@ -57,6 +57,11 @@ public class EventThread implements Runnable{
             actionList.forEach(action -> {
                 String module = StrUtil.subBefore(action, ".", true);
                 String command = StrUtil.subAfter(action, ".", true);
+//                中断事件动作
+                if (DeviceCache.isInterrupt()){
+                    DeviceCache.setInterrupt(false);
+                    return;
+                }
                 if (StrUtil.equals(module, ModuleEnum.INFRARED_MODULE.getModuleEn())) {
                     //动作属于红外
                     redFactory.handler(redPropertiesConfig.getBrand()).handlerAction(command);

+ 22 - 0
src/main/java/com/gzlh/config/ResourcesConfig.java

@@ -0,0 +1,22 @@
+package com.gzlh.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class ResourcesConfig implements WebMvcConfigurer {
+
+
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+
+        /**
+         * 图片资源映射
+         * http://ip:端口/image/2d
+         */
+        registry.addResourceHandler("/files/**").addResourceLocations("file:"+SystemObject.filePropertiesConfig.getRootPath());
+    }
+
+}

+ 1 - 1
src/main/java/com/gzlh/config/hksdk/AlarmParseService.java

@@ -78,7 +78,7 @@ public class AlarmParseService {
             if (strItsPlateResult.struPicInfo.length > 0) {
                 HCNetSDK.NET_ITS_PICTURE_INFO net_its_picture_info = strItsPlateResult.struPicInfo[0];
                 if (net_its_picture_info.dwDataLen > 0) {
-                    String currDateFolder = new SimpleDateFormat("MM-dd").format(nowTime);
+                    String currDateFolder = new SimpleDateFormat("MMdd").format(nowTime);
                     String newName = DateUtil.format(nowTime, "yyyyMMddHHmm");
                     FileOutputStream fout;
                     try {

+ 9 - 9
src/main/java/com/gzlh/device/camera/controller/CameraController.java

@@ -8,6 +8,7 @@ import com.gzlh.device.camera.factory.CameraFactory;
 import com.gzlh.device.camera.properties.CameraPropertiesConfig;
 import com.gzlh.utils.FileUtils;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.web.ServerProperties;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -18,21 +19,19 @@ import org.w3c.dom.Element;
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.*;
 
 
 @RestController
 @RequestMapping("/camera")
 public class CameraController {
-    @Value("${file.root-path}")
-    private String path;
-    @Value("${application.channel-name}")
-    private String channel;
     @Resource
     private CameraFactory cameraFactory;
     @Resource
     private CameraPropertiesConfig cameraPropertiesConfig;
-
+    @Resource
+    private ServerProperties serverProperties;
 
     @PostMapping("/recv")
     public void recv(
@@ -40,7 +39,8 @@ public class CameraController {
 //            HttpServletRequest request
     ) throws IOException {
 //        String xmlStr = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
-
+        String path=SystemObject.filePropertiesConfig.getRootPath();
+        String channelCode=SystemObject.applicationConfig.getChannelCode();
         Map<String, Object> StringObjectMap = new HashMap<>();
         Document document = XmlUtil.parseXml(xmlStr);
         Element rootElement = XmlUtil.getRootElement(document);
@@ -62,15 +62,15 @@ public class CameraController {
         EventDataManager.cacheData("boxNoList",boxNoMap);
 
         Calendar calendar = Calendar.getInstance();
+        String ipAddr =InetAddress.getLocalHost().getHostAddress()+":"+String.valueOf(serverProperties.getPort());
 
-
-        String savePath=path+"/"+SystemObject.applicationConfig.getChannelCode()+"/"+ calendar.get(Calendar.YEAR)+(calendar.get(Calendar.MONTH)+1)+calendar.get(Calendar.DAY_OF_MONTH);
-
+        String savePath=path+"/"+channelCode+"/"+ calendar.get(Calendar.YEAR)+(calendar.get(Calendar.MONTH)+1)+calendar.get(Calendar.DAY_OF_MONTH);
         List<String> fList = new ArrayList();
         List<String> bList = new ArrayList();
         for (Map.Entry<String, Object> entry : conta.entrySet()) {
             if(entry.getKey().contains("PIC")&& !StringUtils.isEmpty((String) entry.getValue())){
                 String filePath = FileUtils.downLoad((String) entry.getValue(),savePath);
+                filePath=filePath.replace(path,ipAddr+"/files");
 //                String base64 = FileUtils.getBase64FromImg(filePath);
                 if (entry.getKey().contains("CONTA_F")){
                     fList.add(filePath);

+ 2 - 2
src/main/java/com/gzlh/device/capture/task/HandlerCarImage.java

@@ -31,8 +31,8 @@ public class HandlerCarImage extends Task {
 
     @Override
     public void run() {
-      String base64=  Base64.encode(new File(filePath));
-        EventDataManager.cacheData("carImg",base64);
+//      String base64=  Base64.encode(new File(filePath));
+        EventDataManager.cacheData("carImg",filePath);
         EventDataManager.cacheData("carNo",carNo);
         EventBus eventBus=SpringUtil.getBean(EventBus.class);
         //向总线发送抓拍到车牌事件

+ 17 - 2
src/main/java/com/gzlh/device/led/handler/impl/LedHandlerFengLiYuan.java

@@ -8,8 +8,10 @@ import com.gzlh.device.led.client.LedNettyConfig;
 import com.gzlh.device.led.handler.ILedHandler;
 import com.gzlh.device.led.utils.FengLiYuanPackUtils;
 import com.gzlh.device.led.utils.LedOptions;
+import com.gzlh.entity.ReqBO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 
@@ -35,14 +37,27 @@ public class LedHandlerFengLiYuan implements ILedHandler {
     @Override
     public void handlerAction(String action) {
         if (StrUtil.contains(action, LedAction.LED_SHOW_CONTENT)) {
+            ReqBO reqBO = null;
             //展示内容
             if (StrUtil.contains(action,"platNo")){
-                String carNo= EventDataManager.getCacheData().getCarNo();
+                String carNo="";
+                reqBO = EventDataManager.getCacheData();
+                if (reqBO!=null){
+                    if (!StringUtils.isEmpty(reqBO.getCarNo())) {
+                        carNo = reqBO.getCarNo();
+                    }
+                }
                 LedOptions ledOptions=new LedOptions();
                 ledOptions.setColor("05").setLine("02").setShowType("0B");
                 sendMsg(carNo,ledOptions);
             }else  if (StrUtil.contains(action,"weight")){
-                String weight= String.format("%.0f", EventDataManager.getCacheData().getWeight());
+                String weight ="";
+                reqBO = EventDataManager.getCacheData();
+                if (reqBO!=null){
+                    if (reqBO.getWeight()!=null) {
+                        weight= String.format("%.0f", EventDataManager.getCacheData().getWeight());
+                    }
+                }
                 LedOptions ledOptions=new LedOptions();
                 ledOptions.setColor("04").setLine("03").setShowType("0B");
                 sendMsg(weight,ledOptions);

+ 1 - 1
src/main/java/com/gzlh/device/plc/client/PlcClientHandler.java

@@ -31,8 +31,8 @@ public class PlcClientHandler extends SimpleChannelInboundHandler<String> {
         String result = Integer.toBinaryString(Integer.parseInt(msg.substring(6, 8),16));
 
         String oldPlcInfo = DeviceCache.getPlcStatus();
-        String newPlcInfo = String.format("%8s", result).replace(" ", "0");
 //        将plc的设备信息补到8存入缓存
+        String newPlcInfo = String.format("%8s", result).replace(" ", "0");
         DeviceCache.setPlcStatus(newPlcInfo);
 
 //        设备信息发生变化时进入

+ 17 - 5
src/main/java/com/gzlh/device/plc/service/PLCService.java

@@ -6,15 +6,24 @@ import com.gzlh.bus.EventConfig;
 import com.gzlh.bus.EventDataManager;
 import com.gzlh.config.ModuleEnum;
 import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.led.event.LedDefaultEvent;
 import com.gzlh.device.plc.event.PLCEvent;
 import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
 import com.gzlh.utils.DeviceCache;
+import org.springframework.util.StringUtils;
 
 import java.util.Date;
 
 public class PLCService {
     public void fRedTrigger(String plcInfo) throws InterruptedException {
         EventBus eventBus = SpringUtil.getBean(EventBus.class);
+
+        String carNo = EventDataManager.getCacheData().getCarNo();
+//        车牌采集失败
+        if (StringUtils.isEmpty(carNo)){
+            eventBus.startEvent(ModuleEnum.LED_MODULE.getModuleEn() + "." + LedDefaultEvent.READ);
+            return;
+        }
         //向总线发送抓拍到车牌事件
         SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
 //        将plc设备信息的字符串反转
@@ -30,15 +39,16 @@ public class PLCService {
             if (oldFRed.equals(newFRed)) {
                 Thread.sleep(2000);
             } else {
+                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READY);
                 bool = false;
             }
         }
-
-        String BRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
+//        Thread.sleep(5000);
+        String bRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
         String radar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
 
 //        车辆处于前后红外之间(外)
-        if (newFRed.equals("0") && BRed.equals("0")) {
+        if (newFRed.equals("0") && bRed.equals("0")) {
             Date fRedTime = DeviceCache.getTime(status.getFRedPoint());
             Date radarTime = DeviceCache.getTime(status.getRadarPoint());
 
@@ -46,6 +56,8 @@ public class PLCService {
             if (radarTime.before(fRedTime)) {
                 eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.READ);
             }
+        }else{
+            eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.POSITION_ERROR);
         }
     }
 
@@ -70,8 +82,8 @@ public class PLCService {
             }
         }
 
-        String BRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
-        String radar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
+//        String bRed = String.valueOf(newStatus.charAt(Integer.parseInt(status.getBRedPoint())));
+//        String radar = String.valueOf(newStatus.charAt(Integer.parseInt(status.getRadarPoint())));
 
 //        设置str为只有栏杆下到位的状态
         String str = "00000000";

+ 2 - 0
src/main/java/com/gzlh/device/weighbridge/event/WeighbridgeEvent.java

@@ -4,6 +4,8 @@ package com.gzlh.device.weighbridge.event;
  * 地磅内置事件
  */
 public interface WeighbridgeEvent {
+    String READY="READY";
     String READ="READ";
     String TIMEOUT="TIMEOUT";
+    String POSITION_ERROR="POSITION_ERROR";
 }

+ 29 - 8
src/main/java/com/gzlh/device/weighbridge/handler/impl/CommonWeighbridgeHandler.java

@@ -2,12 +2,18 @@ package com.gzlh.device.weighbridge.handler.impl;
 
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.extra.spring.SpringUtil;
+import com.gzlh.bus.EventConfig;
 import com.gzlh.bus.EventDataManager;
 import com.gzlh.config.ApplicationConfig;
 import com.gzlh.config.ModuleEnum;
 import com.gzlh.bus.EventBus;
+import com.gzlh.config.SystemObject;
+import com.gzlh.config.dto.SerialSetting;
+import com.gzlh.device.led.factory.LedFactory;
+import com.gzlh.device.led.utils.LedOptions;
 import com.gzlh.device.weighbridge.config.WeighbridgePropertiesConfig;
 import com.gzlh.device.weighbridge.event.WeighbridgeEvent;
+import com.gzlh.utils.DeviceCache;
 
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -52,19 +58,34 @@ public class CommonWeighbridgeHandler {
         @Override
         public void run() {
             int averaWeight = 0;
+            String deviceStatus= null;
+            SerialSetting.PlcDTO.StatusDTO status = EventConfig.serialSetting.getPlc().getStatus();
+
             while (time > 0) {
                 time = time - 1000;
                 averaWeight = WEIGHT_CACHE.stream().collect(Collectors.averagingInt(Integer::intValue)).intValue();
+                averaWeight = 12580;
+                deviceStatus = new StringBuffer(DeviceCache.getPlcStatus()).reverse().toString();
+                String fRed = String.valueOf(deviceStatus.charAt(Integer.parseInt(status.getFRedPoint())));
+                String bRed = String.valueOf(deviceStatus.charAt(Integer.parseInt(status.getBRedPoint())));
+                String radar = String.valueOf(deviceStatus.charAt(Integer.parseInt(status.getRadarPoint())));
+                if (fRed.equals("1")||bRed.equals("1")||radar.equals("1")){
+                    DeviceCache.setInterrupt(true);
+                    LedOptions options = new LedOptions().setLine("04").setColor("01").setShowType("00");
+                    SystemObject.ledFactory.handler(EventConfig.serialSetting.getLed().getBrand())
+                            .sendMsg("车辆位置异常或异常跟车,请完全退出通道后再次进入通道",options);
+                    break;
+                }
                 ThreadUtil.sleep(1000);
             }
-            EventBus eventBus = SpringUtil.getBean(EventBus.class);
-            WeighbridgePropertiesConfig weighbridgePropertiesConfig = SpringUtil.getBean(WeighbridgePropertiesConfig.class);
-            if (averaWeight == 0 || weighbridgePropertiesConfig.getMinKg() > averaWeight) {
-                //todo read timeout
-                //读取超时
-                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
-                return;
-            }
+//            EventBus eventBus = SpringUtil.getBean(EventBus.class);
+//            WeighbridgePropertiesConfig weighbridgePropertiesConfig = SpringUtil.getBean(WeighbridgePropertiesConfig.class);
+//            if (averaWeight == 0 || weighbridgePropertiesConfig.getMinKg() > averaWeight) {
+//                //todo read timeout
+//                //读取超时
+//                eventBus.startEvent(ModuleEnum.WEIGHBRIDGE_MODULE.getModuleEn() + "." + WeighbridgeEvent.TIMEOUT);
+//                return;
+//            }
             isStart=false;
             ApplicationConfig applicationConfig = SpringUtil.getBean(ApplicationConfig.class);
             //上传地磅数据

+ 8 - 0
src/main/java/com/gzlh/utils/DeviceCache.java

@@ -9,6 +9,8 @@ public class DeviceCache {
     private static Map<String,Object> map = new ConcurrentHashMap<String,Object>();
     private static Map<String, Date> plcTimeMap = new ConcurrentHashMap<String,Date>();
 
+    static boolean interrupt=false;
+
     static String plcStatus = null;
 
     public static void setPlcStatus(String status){
@@ -49,5 +51,11 @@ public class DeviceCache {
         return plcTimeMap;
     }
 
+    public static boolean isInterrupt() {
+        return interrupt;
+    }
 
+    public static void setInterrupt(boolean interrupt) {
+        DeviceCache.interrupt = interrupt;
+    }
 }

+ 1 - 0
src/main/java/com/gzlh/utils/FileUtils.java

@@ -3,6 +3,7 @@ package com.gzlh.utils;
 import org.springframework.beans.factory.annotation.Value;
 
 import java.io.*;
+import java.net.InetAddress;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.Arrays;