Bläddra i källkod

1、添加报税口数据报文解析功能

liweimin 4 veckor sedan
förälder
incheckning
c96e0e3dc5

+ 226 - 0
ruoyi-device/src/main/java/com/ruoyi/device/mqtt/domain/decoder/TaxDataUp.java

@@ -0,0 +1,226 @@
+package com.ruoyi.device.mqtt.domain.decoder;
+
+import com.ruoyi.device.mqtt.domain.BaseJsonBody;
+
+import java.math.BigDecimal;
+
+/**
+ * 报税口上行数据
+ *
+ * @author lwm
+ */
+public class TaxDataUp extends BaseJsonBody
+{
+    /** 接口号 */
+    private String interfaceNo;
+
+    /** 枪号 */
+    private Integer gunNo;
+
+    /** 是否启用新国标(1:启用,0:禁用) */
+    private Integer newNationalStandard;
+
+    /** 新国标报税口 */
+    private Integer newNationalStandardTaxNo;
+
+    /** 日期:年-月-日 */
+    private String queryDate;
+
+    /** 税控序列号 */
+    private String taxNo;
+
+    /** 厂家 */
+    private String manufacturer;
+
+    /** 枪个数 */
+    private Integer gunNumber;
+
+    /** 查询税控序列号执行结果 */
+    private String queryTaxResult;
+
+    /** 金额 */
+    private BigDecimal amount;
+
+    /** 油量 */
+    private BigDecimal volume;
+
+    /** 单价 */
+    private BigDecimal unitPrice;
+
+    /** 是否密文(1:是,0:否) */
+    private Integer encryption;
+
+    /** 总金额 */
+    private BigDecimal totalAmount;
+
+    /** 总油量 */
+    private BigDecimal totalVolume;
+
+    /** 查询累计数据执行结果 */
+    private String queryAccumulatedResult;
+
+    public TaxDataUp()
+    {
+        super();
+    }
+
+    public String getInterfaceNo()
+    {
+        return interfaceNo;
+    }
+
+    public void setInterfaceNo(String interfaceNo)
+    {
+        this.interfaceNo = interfaceNo;
+    }
+
+    public Integer getGunNo()
+    {
+        return gunNo;
+    }
+
+    public void setGunNo(Integer gunNo)
+    {
+        this.gunNo = gunNo;
+    }
+
+    public Integer getNewNationalStandard()
+    {
+        return newNationalStandard;
+    }
+
+    public void setNewNationalStandard(Integer newNationalStandard)
+    {
+        this.newNationalStandard = newNationalStandard;
+    }
+
+    public Integer getNewNationalStandardTaxNo()
+    {
+        return newNationalStandardTaxNo;
+    }
+
+    public void setNewNationalStandardTaxNo(Integer newNationalStandardTaxNo)
+    {
+        this.newNationalStandardTaxNo = newNationalStandardTaxNo;
+    }
+
+    public String getQueryDate()
+    {
+        return queryDate;
+    }
+
+    public void setQueryDate(String queryDate)
+    {
+        this.queryDate = queryDate;
+    }
+
+    public String getTaxNo()
+    {
+        return taxNo;
+    }
+
+    public void setTaxNo(String taxNo)
+    {
+        this.taxNo = taxNo;
+    }
+
+    public String getManufacturer()
+    {
+        return manufacturer;
+    }
+
+    public void setManufacturer(String manufacturer)
+    {
+        this.manufacturer = manufacturer;
+    }
+
+    public Integer getGunNumber()
+    {
+        return gunNumber;
+    }
+
+    public void setGunNumber(Integer gunNumber)
+    {
+        this.gunNumber = gunNumber;
+    }
+
+    public String getQueryTaxResult()
+    {
+        return queryTaxResult;
+    }
+
+    public void setQueryTaxResult(String queryTaxResult)
+    {
+        this.queryTaxResult = queryTaxResult;
+    }
+
+    public BigDecimal getAmount()
+    {
+        return amount;
+    }
+
+    public void setAmount(BigDecimal amount)
+    {
+        this.amount = amount;
+    }
+
+    public BigDecimal getVolume()
+    {
+        return volume;
+    }
+
+    public void setVolume(BigDecimal volume)
+    {
+        this.volume = volume;
+    }
+
+    public BigDecimal getUnitPrice()
+    {
+        return unitPrice;
+    }
+
+    public void setUnitPrice(BigDecimal unitPrice)
+    {
+        this.unitPrice = unitPrice;
+    }
+
+    public Integer getEncryption()
+    {
+        return encryption;
+    }
+
+    public void setEncryption(Integer encryption)
+    {
+        this.encryption = encryption;
+    }
+
+    public BigDecimal getTotalAmount()
+    {
+        return totalAmount;
+    }
+
+    public void setTotalAmount(BigDecimal totalAmount)
+    {
+        this.totalAmount = totalAmount;
+    }
+
+    public BigDecimal getTotalVolume()
+    {
+        return totalVolume;
+    }
+
+    public void setTotalVolume(BigDecimal totalVolume)
+    {
+        this.totalVolume = totalVolume;
+    }
+
+    public String getQueryAccumulatedResult()
+    {
+        return queryAccumulatedResult;
+    }
+
+    public void setQueryAccumulatedResult(String queryAccumulatedResult)
+    {
+        this.queryAccumulatedResult = queryAccumulatedResult;
+    }
+}

+ 1 - 0
ruoyi-device/src/main/java/com/ruoyi/device/mqtt/enums/CmdTypeEnum.java

@@ -11,6 +11,7 @@ public enum CmdTypeEnum
 {
     TSB_LOGIN("tsb:login", "tsb:login:up", "tsb:login:down", "调试宝登录"),
     TSB_PT("tsb:pt", "tsb:pt:up", "tsb:pt:down", "调试宝PT产测"),
+    COMMON_TAX("common:tax", "common:tax:up", "common:tax:down", "报税口数据"),
     ;
 
     private final String cmdType;

+ 11 - 4
ruoyi-device/src/main/java/com/ruoyi/device/mqtt/handler/decoder/json/JsonBodyDecoder.java

@@ -1,6 +1,7 @@
 package com.ruoyi.device.mqtt.handler.decoder.json;
 
 import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.device.mqtt.annotation.ConsumerHandler;
 import com.ruoyi.device.mqtt.domain.BaseJsonBody;
@@ -36,17 +37,17 @@ public class JsonBodyDecoder extends AbstractDecoder<BaseJsonBody>
         }
         byte[] bodyBytes = new byte[header.getMsgLength() - 2];
         body.readBytes(bodyBytes);
-        String bodyJson = new String(bodyBytes, StandardCharsets.UTF_8).trim();
+        String bodyStr = new String(bodyBytes, StandardCharsets.UTF_8).trim();
 
         // 2、解析报文体json
-        if (!JSON.isValidObject(bodyJson))
+        if (!JSON.isValidObject(bodyStr))
         {
             log.warn("报文体json格式化出错");
             return BaseJsonBody.fail(commonTopic.getDeviceType(), commonTopic.getDeviceSn(), "报文体json格式化出错");
         }
 
         // 3、json格式化为对象jsonBody
-        BaseJsonBody jsonBody = JSON.parseObject(bodyJson, BaseJsonBody.class);
+        BaseJsonBody jsonBody = JSON.parseObject(bodyStr, BaseJsonBody.class);
         if (jsonBody == null || StringUtils.isEmpty(jsonBody.getCmdType()))
         {
             log.warn("报文体缺少 cmdType");
@@ -67,10 +68,16 @@ public class JsonBodyDecoder extends AbstractDecoder<BaseJsonBody>
         if (StringUtils.isEmpty(jsonBody.getDeviceType()) && StringUtils.isNotEmpty(commonTopic.getDeviceType()))
         {
             jsonBody.setDeviceType(commonTopic.getDeviceType());
+            JSONObject jsonObject = JSON.parseObject(bodyStr);
+            jsonObject.put("deviceType", commonTopic.getDeviceType());
+            bodyStr = jsonObject.toJSONString();
         }
         if (jsonBody.getDeviceSn() == null && commonTopic.getDeviceSn() != null)
         {
             jsonBody.setDeviceSn(commonTopic.getDeviceSn());
+            JSONObject jsonObject = JSON.parseObject(bodyStr);
+            jsonObject.put("deviceSn", commonTopic.getDeviceSn());
+            bodyStr = jsonObject.toJSONString();
         }
 
         // 4、进行业务处理
@@ -84,6 +91,6 @@ public class JsonBodyDecoder extends AbstractDecoder<BaseJsonBody>
             log.warn("未注册 JSON 命令处理器 cmd={}", cmd);
             return BaseJsonBody.fail(jsonBody.getDeviceType(), jsonBody.getDeviceSn(), cmd.getCmdDownType(), "未实现的服务处理器");
         }
-        return handler.handle(commonTopic, header, bodyJson, cmd);
+        return handler.handle(commonTopic, header, bodyStr, cmd);
     }
 }

+ 36 - 0
ruoyi-device/src/main/java/com/ruoyi/device/mqtt/handler/decoder/json/service/TaxDataUpService.java

@@ -0,0 +1,36 @@
+package com.ruoyi.device.mqtt.handler.decoder.json.service;
+
+import com.alibaba.fastjson2.JSON;
+import com.ruoyi.device.mqtt.annotation.JsonCmdHandler;
+import com.ruoyi.device.mqtt.domain.BaseJsonBody;
+import com.ruoyi.device.mqtt.domain.decoder.TaxDataUp;
+import com.ruoyi.device.mqtt.enums.CmdTypeEnum;
+import com.ruoyi.device.mqtt.handler.decoder.json.IJsonCmdHandler;
+import com.ruoyi.device.mqtt.vo.CommonHeader;
+import com.ruoyi.device.mqtt.vo.CommonTopic;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 报税口上行数据
+ *
+ * @author lwm
+ */
+@JsonCmdHandler(cmdType = CmdTypeEnum.COMMON_TAX)
+public class TaxDataUpService implements IJsonCmdHandler
+{
+    private static final Logger log = LoggerFactory.getLogger(TaxDataUpService.class);
+
+    @Override
+    public BaseJsonBody handle(CommonTopic topic, CommonHeader header, String bodyJson, CmdTypeEnum cmd)
+    {
+        TaxDataUp taxDataUp = JSON.parseObject(bodyJson, TaxDataUp.class);
+        if (taxDataUp == null)
+        {
+            log.warn("报税口报文体解析失败");
+            return BaseJsonBody.fail(topic.getDeviceType(), topic.getDeviceSn(), cmd.getCmdDownType(), "报税口报文体解析失败");
+        }
+
+        return null;
+    }
+}