jiazx0107@163.com
2023-11-18 41cd6c8db40bceb08290828ae0d4fc5caeea7147
调整车牌识别配置
已重命名2个文件
已删除1个文件
已修改10个文件
已添加1个文件
316 ■■■■ 文件已修改
src/main/java/com/fzzy/gateway/GatewayRunner.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/data/BaseReqData.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/entity/GateWayParam.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/ApiInitService.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayDevice.js 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/sdkhk/HKUtils.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/protocol/sdkhk/HkGatewaySyncLprImpl.java 66 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/fzzy/gateway/GatewayRunner.java
@@ -40,6 +40,8 @@
        //更新设备缓存
        apiInitService.updateDeviceCache();
        //初始化车牌识别
        apiInitService.initAllLpr();
    }
}
src/main/java/com/fzzy/gateway/api/GatewaySyncLprService.java
@@ -2,6 +2,7 @@
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.hx2023.data.*;
/**
@@ -22,6 +23,14 @@
     *
     * @return
     */
    public LprData syncLpr(BaseReqData reqData);
    public BaseResp syncLpr(BaseReqData reqData);
    /**
     * è½¦ç‰Œè¯†åˆ«èŽ·å–
     *
     * @return
     */
    public BaseResp initLpr(BaseReqData reqData);
}
src/main/java/com/fzzy/gateway/controller/GatewayDeviceController.java
ÎļþÃû´Ó src/main/java/com/fzzy/gateway/controller/GatewayDeviceTestController.java ÐÞ¸Ä
@@ -1,25 +1,15 @@
package com.fzzy.gateway.controller;
import com.alibaba.fastjson2.JSONObject;
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.api.utils.DateUtil;
import com.fzzy.async.fzzy40.Fzzy40CommonService;
import com.fzzy.async.fzzy40.entity.Fz40Grain;
import com.fzzy.gateway.GatewayUtils;
import com.fzzy.gateway.api.GatewayDeviceReportService;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.entity.GateWayTestParam;
import com.fzzy.gateway.entity.GateWayParam;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.hx2023.data.*;
import com.fzzy.gateway.service.GatewayDeviceService;
import com.fzzy.mqtt.MqttGatewayService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -36,8 +26,8 @@
 */
@Slf4j
@Controller
@RequestMapping("/gateway/test")
public class GatewayDeviceTestController {
@RequestMapping("/gateway")
public class GatewayDeviceController {
    @Resource
    private GatewayDeviceService gatewayDeviceService;
@@ -52,9 +42,9 @@
     * @param param
     * @return
     */
    @PostMapping("/deviceTest")
    @PostMapping("/test/deviceTest")
    public @ResponseBody
    String deviceTest(@RequestBody GateWayTestParam param) throws Exception {
    String deviceTest(@RequestBody GateWayParam param) throws Exception {
        if (StringUtils.isEmpty(param.getBizType())) {
            return "ERROR:没有获取到业务类型,执行失败";
@@ -79,7 +69,39 @@
        return "SUCCESS";
    }
    private String testGrain(GateWayTestParam param) {
    /**
     * åˆå§‹åŒ–车牌识别
     *
     * @param param
     * @return
     */
    @PostMapping("/control/init-lpr")
    public @ResponseBody
    String initLpr(@RequestBody GateWayParam param) throws Exception {
        List<GatewayDevice> list = gatewayDeviceService.listAll();
        if (null == list || list.isEmpty()) {
            return "ERROR:没有获取到设备信息";
        }
        BaseReqData reqData;
        int i = 1;
        for (GatewayDevice device : list) {
            if (!GatewayDeviceType.TYPE_02.getCode().equals(device.getType())) {
                continue;
            }
            reqData = new BaseReqData(device);
            reqData.setIndex(i);
            gatewayRemoteManager.getSyncLprService(device.getSyncProtocol()).initLpr(reqData);
            i++;
        }
        return "SUCCESS";
    }
    private String testGrain(GateWayParam param) {
        String deviceId = param.getDeviceId();
        GatewayDevice device = GatewayUtils.getCacheByDeviceId(deviceId);
@@ -116,7 +138,7 @@
     * @param param
     * @return
     */
    public String ajaxTestKafkaGrain(GateWayTestParam param) throws Exception {
    public String ajaxTestKafkaGrain(GateWayParam param) throws Exception {
        List<GatewayDevice> list = gatewayDeviceService.listAll();
        if (null == list || list.isEmpty()) {
            return "ERROR:为获取到系统中设备配置,取消执行";
@@ -148,10 +170,9 @@
     * @param param
     * @return
     */
    public String ajaxTestWeight(GateWayTestParam param) throws Exception {
    public String ajaxTestWeight(GateWayParam param) throws Exception {
        double weight = param.getWeight();
        String deviceId = param.getDeviceId();
        List<GatewayDevice> list = gatewayDeviceService.listAll();
        if (list == null || list.size() <= 0) {
@@ -189,7 +210,7 @@
     *
     * @return
     */
    public String ajaxTestLpr(GateWayTestParam param) throws Exception {
    public String ajaxTestLpr(GateWayParam param) throws Exception {
        String carNumber = param.getCarNumber();
src/main/java/com/fzzy/gateway/data/BaseReqData.java
@@ -31,4 +31,23 @@
    private Date dayTime;
    private String data;
    private int index = 1;
    public BaseReqData() {
    }
    public BaseReqData(GatewayDevice device) {
        this.device = device;
        this.productId = device.getProductId();
        this.deviceId = device.getDeviceId();
        this.deviceName = device.getDeviceName();
    }
    public BaseReqData(String productId, String deviceId, String deviceName, GatewayDevice device) {
        this.productId = productId;
        this.deviceId = deviceId;
        this.deviceName = deviceName;
        this.device = device;
    }
}
src/main/java/com/fzzy/gateway/entity/GateWayParam.java
ÎļþÃû´Ó src/main/java/com/fzzy/gateway/entity/GateWayTestParam.java ÐÞ¸Ä
@@ -6,7 +6,7 @@
import java.util.Date;
@Data
public class GateWayTestParam {
public class GateWayParam {
    @PropertyDef(label = "开始时间")
    private Date start;
    @PropertyDef(label = "截止时间")
src/main/java/com/fzzy/gateway/entity/GatewayDevice.java
@@ -101,10 +101,13 @@
    @PropertyDef(label = "组织编码")
    private String orgId;
    @Column(name = "POSITION_", length = 40)
    @PropertyDef(label = "位置")
    private String position;
    @Column(name = "REMARK_", length = 200)
    @PropertyDef(label = "备注", description = "备注信息")
    private String remark;
    @Column(name = "CABLE_RULE_", length = 20)
    @PropertyDef(label = "布线规则", description = "平方仓表示层行列,筒仓表示每圈的列数")
src/main/java/com/fzzy/gateway/hx2023/service/ApiInitService.java
@@ -1,9 +1,12 @@
package com.fzzy.gateway.hx2023.service;
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.data.GatewayDeviceType;
import com.fzzy.gateway.api.GatewayRemoteManager;
import com.fzzy.gateway.api.GatewayRemoteService;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.entity.GatewayConf;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.service.GatewayConfService;
@@ -52,4 +55,26 @@
    public void updateDeviceCache() {
        deviceService.flushCache();
    }
    public void initAllLpr() {
        List<GatewayDevice> list = deviceService.listAll();
        if (null == list || list.isEmpty()) {
            return;
        }
        BaseReqData reqData;
        int i = 1;
        for (GatewayDevice device : list) {
            if (!GatewayDeviceType.TYPE_02.getCode().equals(device.getType())) {
                continue;
            }
            reqData = new BaseReqData(device);
            reqData.setIndex(i);
            gatewayRemoteManager.getSyncLprService(device.getSyncProtocol()).initLpr(reqData);
            i++;
        }
    }
}
src/main/java/com/fzzy/gateway/hx2023/service/DeviceReportServiceImpl.java
@@ -7,6 +7,7 @@
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.hx2023.data.LprData;
import com.fzzy.gateway.hx2023.data.WebSocketPacket;
import com.fzzy.gateway.hx2023.data.WebSocketPacketHeader;
import com.fzzy.gateway.hx2023.data.WeightInfo;
@@ -94,6 +95,29 @@
        String topic = ScConstant.TOPIC_MESSAGE_REPORT;
        topic = topic.replace("${productId}", reqData.getProductId()).replace("${deviceId}", reqData.getDeviceId());
        GatewayDevice device = reqData.getDevice();
        if (null == reqData.getData()) {
            WebSocketPacket packet = new WebSocketPacket();
            WebSocketPacketHeader header = new WebSocketPacketHeader();
            header.setDeviceName(reqData.getDeviceName());
            header.setProductId(reqData.getProductId());
            packet.setHeaders(header);
            packet.setMessageType(ScConstant.MESSAGE_TYPE_REPORT_PROPERTY);
            packet.setDeviceId(reqData.getDeviceId());
            packet.setMessageId(System.currentTimeMillis() + "");
            //设置信息主体
            LprData lpr = new LprData();
            lpr.setDeviceId(reqData.getDeviceId());
            lpr.setCarNumber(reqData.getCarNumber());
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("carNumber", reqData.getCarNumber());
            jsonObject.put("position", device.getPosition());
            packet.setProperties(jsonObject);
            packet.setTimestamp(System.currentTimeMillis());
        }
        publishService.publishMqttWithTopic(reqData.getData(), topic);
        log.info("----------------------------推送MQTT车牌识别信息---------------------------");
src/main/java/com/fzzy/gateway/hx2023/service/HkGatewaySyncLprImpl.java
ÎļþÒÑɾ³ý
src/main/java/com/fzzy/gateway/hx2023/service/ScGatewayTestServiceImpl.java
@@ -235,6 +235,8 @@
    public BaseResp testLpr(BaseReqData reqData) {
        GatewayDevice device = reqData.getDevice();
        WebSocketPacket packet = new WebSocketPacket();
        WebSocketPacketHeader header = new WebSocketPacketHeader();
        header.setDeviceName(reqData.getDeviceName());
@@ -250,7 +252,7 @@
        lpr.setCarNumber(reqData.getCarNumber());
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("carNumber", reqData.getCarNumber());
        jsonObject.put("position", "big");
        jsonObject.put("position", device.getPosition());
        packet.setProperties(jsonObject);
        packet.setTimestamp(System.currentTimeMillis());
src/main/java/com/fzzy/gateway/view/GatewayDevice.js
@@ -15,4 +15,23 @@
             $alert(result);
        }
    })
}
/**
*
* @param param
*/
initLpr= function(param){
   $.ajax({
       type:"POST",
       contentType:"application/json;charset=UTF-8",
       url:"/gateway/control/initLpr",
       data:JSON.stringify(param),
       success:function(result){
            $alert(result);
       },
       error:function(result){
            $alert(result);
       }
   })
}
src/main/java/com/fzzy/gateway/view/GatewayDevice.view.xml
@@ -112,6 +112,10 @@
        <Property></Property>
        <Property name="label">筒仓层规则</Property>
      </PropertyDef>
      <PropertyDef name="position">
        <Property/>
        <Property name="label">位置</Property>
      </PropertyDef>
    </DataType>
    <DataType name="dtParam" parent="Map">
      <PropertyDef name="start">
@@ -232,6 +236,18 @@
        <ClientEvent name="onClick">view.get(&quot;#dialogLpr&quot;).show();&#xD;
</ClientEvent>
        <Property name="caption">车牌识别调试</Property>
        <Property name="iconClass">fa fa-wrench</Property>
        <Property name="exClassName">toolbar-button-push</Property>
      </ToolBarButton>
      <Separator/>
      <ToolBarButton>
        <ClientEvent name="onClick">var data = view.get(&quot;#dsMain.data:#&quot;);&#xD;
var param = {&#xD;
    deviceId:data.get(&quot;deviceId&quot;),&#xD;
    bizType:&quot;initLpr&quot;&#xD;
}&#xD;
initLpr(param);</ClientEvent>
        <Property name="caption">车牌识别初始化</Property>
        <Property name="iconClass">fa fa-wrench</Property>
        <Property name="exClassName">toolbar-button-push</Property>
      </ToolBarButton>
@@ -382,6 +398,11 @@
              <Property name="property">httpUrl</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement layoutConstraint="colSpan:2">
              <Property name="name">position</Property>
              <Property name="property">position</Property>
              <Editor/>
            </AutoFormElement>
            <AutoFormElement layoutConstraint="colSpan:3">
              <Property name="name">remark</Property>
              <Property name="property">remark</Property>
src/main/java/com/fzzy/protocol/sdkhk/HKUtils.java
@@ -8,11 +8,18 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * å·¥å…·ç±»
 */
@Component
public class HKUtils {
    /**
     * è®¾å¤‡æ˜¯å¦åœ¨çº¿ï¼Œkey = deviceId,value = Y、N
     */
    public static Map<String, String> contextOnlineMap = new HashMap<>();
    //验证是否为历史数据 10分钟
@@ -82,4 +89,22 @@
        }
        return base;
    }
    public static String getStatus(String deviceId) {
        String status = contextOnlineMap.get(deviceId);
        if (null == status) {
            status = "N";
            contextOnlineMap.put(deviceId, status);
        }
        return status;
    }
    public static void updateStatus(String deviceId, String status) {
        contextOnlineMap.put(deviceId, status);
    }
}
src/main/java/com/fzzy/protocol/sdkhk/HkGatewaySyncLprImpl.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,66 @@
package com.fzzy.protocol.sdkhk;
import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.gateway.api.GatewaySyncLprService;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.protocol.sdkhk.lpr.AlarmLpr;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
 * ç½‘关与设备之间的通讯-海康SDK
 */
@Slf4j
@Component
public class HkGatewaySyncLprImpl implements GatewaySyncLprService {
    private AlarmLpr alarmLpr = new AlarmLpr();
    @Override
    public String getLprProtocol() {
        return GatewayDeviceProtocol.DEVICE_LPR_SDK_HK.getCode();
    }
    @Override
    public BaseResp syncLpr(BaseReqData reqData) {
        return new BaseResp(500, "系统不支持手动触发获取");
    }
    @Override
    public BaseResp initLpr(BaseReqData reqData) {
        try {
            String msg = alarmLpr.initSdk();
            log.info("--------初始化HK-SDK-------{}", msg);
            Thread.sleep(500);
            GatewayDevice device = reqData.getDevice();
            //如果已经上线先离线
            String status = HKUtils.getStatus(reqData.getDeviceId());
            if ("Y".equals(status)) {
                alarmLpr.logout(reqData.getIndex(), device.getIp(), device.getPort());
                Thread.sleep(500);
            }
            //重新登陆
            msg = alarmLpr.login(reqData.getIndex(), device.getIp(), device.getPort(), device.getUserName(), device.getPassword());
            if (HKUtils.RESULT_SUCCESS.equals(msg)) {
                HKUtils.updateStatus(device.getDeviceId(), "Y");
            }
        } catch (Exception e) {
            log.error("----------------初始化车牌识别执行识别失败----------------------{}", e);
        }
        return new BaseResp();
    }
}