From cef410f571a2960e979ca9383d9c8dd01ecc862c Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期一, 28 十月 2024 14:44:31 +0800
Subject: [PATCH] 2024-10-28 常用取水口单独建表,按照使用时间和使用次数排序

---
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java               |   29 ++++
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoPr/PrCommonIntakes.java           |   62 ++++++++++
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrCommonIntakesMapper.xml                     |  110 ++++++++++++++++++
 pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrCommonIntakesMapper.java      |   36 ++++++
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java |    5 
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java |    4 
 pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java   |   28 ++--
 pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml                            |   38 +++---
 8 files changed, 280 insertions(+), 32 deletions(-)

diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
index 17081dc..7cc909c 100644
--- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/command/ComSupport.java
@@ -11,9 +11,11 @@
 import com.dy.pipIrrGlobal.command.enums.LastOperateENUM;
 import com.dy.pipIrrGlobal.command.result.CommandResultCode;
 import com.dy.pipIrrGlobal.daoBa.BaSettingsMapper;
+import com.dy.pipIrrGlobal.daoPr.PrCommonIntakesMapper;
 import com.dy.pipIrrGlobal.daoPr.PrControllerMapper;
 import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper;
 import com.dy.pipIrrGlobal.daoSe.SeVirtualCardMapper;
+import com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes;
 import com.dy.pipIrrGlobal.pojoPr.PrController;
 import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory;
 import com.dy.pipIrrGlobal.pojoSe.SeVirtualCard;
@@ -78,6 +80,9 @@
 
     @Autowired
     private SeVirtualCardMapper seVirtualCardMapper;
+
+    @Autowired
+    private PrCommonIntakesMapper prCommonIntakesMapper;
 
     public static ComSupport comSupport;
 
@@ -279,6 +284,9 @@
         rmCommandHistoryMapper.insert(rmCommandHistory);
         comId = rmCommandHistory.getComId();
 
+        // 娣诲姞甯哥敤鍙栨按鍙f垨鏇存柊浣跨敤淇℃伅
+        addCommonIntake(operator, intakeId);
+
         /**
          * 澶勭悊鍥炶皟
          * feature鍑嗗灏辩华鍚庡彂閫佸懡浠�
@@ -357,4 +365,25 @@
         return response_CallBack;
 
     }
+
+    /**
+     * 娣诲姞甯哥敤鍙栨按鍙f垨鏇存柊浣跨敤淇℃伅
+     * @param intakeId
+     * @return
+     */
+    public Integer addCommonIntake(Long operatorId, Long intakeId) {
+        PrCommonIntakes commonIntake = prCommonIntakesMapper.selectByOperatorAndIntake(operatorId, intakeId);
+        if(commonIntake == null) {
+            commonIntake = new PrCommonIntakes();
+            commonIntake.setOperatorId(operatorId);
+            commonIntake.setIntakeId(intakeId);
+            commonIntake.setLastUsedTime(new Date());
+            commonIntake.setUsageCount(1);
+            return prCommonIntakesMapper.insert(commonIntake);
+        }
+
+        commonIntake.setLastUsedTime(new Date());
+        commonIntake.setUsageCount(commonIntake.getUsageCount() + 1);
+        return prCommonIntakesMapper.updateByPrimaryKeySelective(commonIntake);
+    }
 }
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrCommonIntakesMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrCommonIntakesMapper.java
new file mode 100644
index 0000000..01fb5d1
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoPr/PrCommonIntakesMapper.java
@@ -0,0 +1,36 @@
+package com.dy.pipIrrGlobal.daoPr;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-10-28 14:11
+ * @LastEditTime 2024-10-28 14:11
+ * @Description
+ */
+
+@Mapper
+public interface PrCommonIntakesMapper extends BaseMapper<PrCommonIntakes> {
+    int deleteByPrimaryKey(Long id);
+
+    int insert(PrCommonIntakes record);
+
+    int insertSelective(PrCommonIntakes record);
+
+    PrCommonIntakes selectByPrimaryKey(Long id);
+
+    int updateByPrimaryKeySelective(PrCommonIntakes record);
+
+    int updateByPrimaryKey(PrCommonIntakes record);
+
+    /**
+     * 鏍规嵁鎿嶄綔鍛業D銆佸彇姘村彛ID鑾峰彇甯哥敤鍙栨按鍙e璞�
+     * @param operatorId
+     * @param intakeId
+     * @return
+     */
+    PrCommonIntakes selectByOperatorAndIntake(@Param("operatorId") Long operatorId, @Param("intakeId")Long intakeId);
+}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoPr/PrCommonIntakes.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoPr/PrCommonIntakes.java
new file mode 100644
index 0000000..a59dfca
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/pojoPr/PrCommonIntakes.java
@@ -0,0 +1,62 @@
+package com.dy.pipIrrGlobal.pojoPr;
+
+/**
+ * @author ZhuBaoMin
+ * @date 2024-10-28 14:11
+ * @LastEditTime 2024-10-28 14:11
+ * @Description 甯哥敤鍙栨按鍙e疄浣撶被
+ */
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.alibaba.fastjson2.writer.ObjectWriterImplToString;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.dy.common.po.BaseEntity;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import jakarta.validation.constraints.NotNull;
+import lombok.*;
+
+import java.util.Date;
+
+@TableName(value="pr_common_intakes", autoResultMap = true)
+@Data
+@Builder
+@ToString
+@NoArgsConstructor
+@AllArgsConstructor
+public class PrCommonIntakes implements BaseEntity {
+    public static final long serialVersionUID = 202410281133001L;
+
+    /**
+     * 涓婚敭
+     */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    @TableId(type = IdType.INPUT)
+    private Long id;
+
+    /**
+     * 鎿嶄綔浜篒D
+     */
+    @JSONField(serializeUsing= ObjectWriterImplToString.class)
+    @NotNull(message = "鍙栨按鍙g紪鍙蜂笉鑳戒负绌�")
+    private Long operatorId;
+
+    /**
+     * 鍙栨按鍙D
+     */
+    @NotNull(message = "鍙栨按鍙g紪鍙蜂笉鑳戒负绌�")
+    private Long intakeId;
+
+    /**
+     * 鏈�鍚庝竴娆′娇鐢ㄦ椂闂�
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date lastUsedTime;
+
+    /**
+     * 浣跨敤娆℃暟
+     */
+    private Integer usageCount;
+
+}
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrCommonIntakesMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrCommonIntakesMapper.xml
new file mode 100644
index 0000000..14055c5
--- /dev/null
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrCommonIntakesMapper.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.dy.pipIrrGlobal.daoPr.PrCommonIntakesMapper">
+  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes">
+    <!--@mbg.generated-->
+    <!--@Table pr_common_intakes-->
+    <id column="id" jdbcType="BIGINT" property="id" />
+    <result column="operator_id" jdbcType="BIGINT" property="operatorId" />
+    <result column="intake_id" jdbcType="BIGINT" property="intakeId" />
+    <result column="last_used_time" jdbcType="TIMESTAMP" property="lastUsedTime" />
+    <result column="usage_count" jdbcType="INTEGER" property="usageCount" />
+  </resultMap>
+  <sql id="Base_Column_List">
+    <!--@mbg.generated-->
+    id, operator_id, intake_id, last_used_time, usage_count
+  </sql>
+  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
+    <!--@mbg.generated-->
+    select 
+    <include refid="Base_Column_List" />
+    from pr_common_intakes
+    where id = #{id,jdbcType=BIGINT}
+  </select>
+  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
+    <!--@mbg.generated-->
+    delete from pr_common_intakes
+    where id = #{id,jdbcType=BIGINT}
+  </delete>
+  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes">
+    <!--@mbg.generated-->
+    insert into pr_common_intakes (id, operator_id, intake_id, 
+      last_used_time, usage_count)
+    values (#{id,jdbcType=BIGINT}, #{operatorId,jdbcType=BIGINT}, #{intakeId,jdbcType=BIGINT}, 
+      #{lastUsedTime,jdbcType=TIMESTAMP}, #{usageCount,jdbcType=INTEGER})
+  </insert>
+  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes">
+    <!--@mbg.generated-->
+    insert into pr_common_intakes
+    <trim prefix="(" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        id,
+      </if>
+      <if test="operatorId != null">
+        operator_id,
+      </if>
+      <if test="intakeId != null">
+        intake_id,
+      </if>
+      <if test="lastUsedTime != null">
+        last_used_time,
+      </if>
+      <if test="usageCount != null">
+        usage_count,
+      </if>
+    </trim>
+    <trim prefix="values (" suffix=")" suffixOverrides=",">
+      <if test="id != null">
+        #{id,jdbcType=BIGINT},
+      </if>
+      <if test="operatorId != null">
+        #{operatorId,jdbcType=BIGINT},
+      </if>
+      <if test="intakeId != null">
+        #{intakeId,jdbcType=BIGINT},
+      </if>
+      <if test="lastUsedTime != null">
+        #{lastUsedTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="usageCount != null">
+        #{usageCount,jdbcType=INTEGER},
+      </if>
+    </trim>
+  </insert>
+  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes">
+    <!--@mbg.generated-->
+    update pr_common_intakes
+    <set>
+      <if test="operatorId != null">
+        operator_id = #{operatorId,jdbcType=BIGINT},
+      </if>
+      <if test="intakeId != null">
+        intake_id = #{intakeId,jdbcType=BIGINT},
+      </if>
+      <if test="lastUsedTime != null">
+        last_used_time = #{lastUsedTime,jdbcType=TIMESTAMP},
+      </if>
+      <if test="usageCount != null">
+        usage_count = #{usageCount,jdbcType=INTEGER},
+      </if>
+    </set>
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes">
+    <!--@mbg.generated-->
+    update pr_common_intakes
+    set operator_id = #{operatorId,jdbcType=BIGINT},
+      intake_id = #{intakeId,jdbcType=BIGINT},
+      last_used_time = #{lastUsedTime,jdbcType=TIMESTAMP},
+      usage_count = #{usageCount,jdbcType=INTEGER}
+    where id = #{id,jdbcType=BIGINT}
+  </update>
+
+  <!--鏍规嵁鎿嶄綔鍛業D銆佸彇姘村彛ID鑾峰彇甯哥敤鍙栨按鍙e璞�-->
+  <select id="selectByOperatorAndIntake" resultType="com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes">
+    SELECT *
+    FROM pr_common_intakes
+    WHERE operator_id = #{operatorId} AND intake_id = #{intakeId}
+    LIMIT 1
+  </select>
+</mapper>
\ No newline at end of file
diff --git a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
index 9bce76d..6fcfe5d 100644
--- a/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
+++ b/pipIrr-platform/pipIrr-global/src/main/resources/mapper/PrIntakeMapper.xml
@@ -276,7 +276,7 @@
                 AND cont.protocol = #{protocol}
             </if>
             <if test = "bindNumber != null and bindNumber > 0">
-                AND (SELECT COUNT(*) FROM pr_intake_controller WHERE intakeId = ge.id AND operateType = 1) = ${bindNumber}
+                AND (SELECT COUNT(*) FROM pr_intake_controller WHERE intakeId = ge.id AND operateType = 1) = #{bindNumber}
             </if>
         </where>
     </select>
@@ -357,7 +357,7 @@
                 AND cont.protocol = #{protocol}
             </if>
             <if test = "bindNumber != null and bindNumber > 0">
-                AND (SELECT COUNT(*) FROM pr_intake_controller WHERE intakeId = ge.id AND operateType = 1) = ${bindNumber}
+                AND (SELECT COUNT(*) FROM pr_intake_controller WHERE intakeId = ge.id AND operateType = 1) = #{bindNumber}
             </if>
         </where>
         ORDER BY ge.operateDt DESC
@@ -660,26 +660,28 @@
 
     <!--鏍规嵁鎿嶄綔鍛樿幏鍙栧父鐢ㄥ彇姘村彛-->
     <select id="getUsedIntakes" resultType="com.dy.pipIrrGlobal.voPr.VoOnLineIntake">
-        SELECT DISTINCT con.intakeId,
-        con.rtuAddr,
-        inta.name AS intakeNum,
-        rtus.isOnLine
-        FROM pr_controller con
-        INNER JOIN pr_intake inta ON con.intakeId = inta.id
-        INNER JOIN rm_command_history com ON con.rtuAddr = com.rtu_addr
-        INNER JOIN JSON_TABLE(
-        <!--'[{"rtuAddr":"37142501020100215","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
-        #{onLineMap},
-        '$[*]' COLUMNS (
-        rtuAddr VARCHAR(20) PATH '$.rtuAddr',
-        isOnLine BOOLEAN PATH '$.isOnLine'
-        )
-        ) rtus ON con.rtuAddr = rtus.rtuAddr
+        SELECT
+            com.intake_id AS intakeId,
+            con.rtuAddr,
+            inta.name AS intakeNum,
+            rtus.isOnLine
+        FROM pr_common_intakes com
+            INNER JOIN pr_intake inta ON inta.id = com.intake_id
+            INNER JOIN pr_controller con ON con.intakeId = com.intake_id
+            INNER JOIN JSON_TABLE(
+                <!--'[{"rtuAddr":"620201000030","isOnLine":true},{"rtuAddr":"4000004","isOnLine":true},{"rtuAddr":"dy20240325","isOnLine":false}]',-->
+                #{onLineMap},
+                '$[*]' COLUMNS (
+                    rtuAddr VARCHAR(20) PATH '$.rtuAddr',
+                    isOnLine BOOLEAN PATH '$.isOnLine'
+                )
+            ) rtus ON con.rtuAddr = rtus.rtuAddr
         <where>
             <if test="operator != null">
-                com.operator = #{operator}
+                com.operator_id = #{operator}
             </if>
         </where>
+        ORDER BY com.last_used_time DESC,com.usage_count DESC
     </select>
 
     <!--鍙栨按鍙e悕绉版崲鍙栨按鍙D锛屾壂鐮佸紑闃�浣跨敤-->
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
index 6118669..47772f7 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/command/CommandSv.java
@@ -50,7 +50,8 @@
     private final PrIntakeVcMapper prIntakeVcMapper;
     private final SeClientCardMapper seClientCardMapper;
     private final RmIrrigateProfileMapper rmIrrigateProfileMapper;
-    private RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper;
+    private final RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper;
+    //private final PrCommonIntakesMapper prCommonIntakesMapper;
 
     /**
      * pro_mw锛氬睘鎬�
@@ -64,6 +65,7 @@
     public CommandSv(RmCommandHistoryMapper rmCommandHistoryMapper,RmOpenCloseValveLastMapper rmOpenCloseValveLastMapper, SeVirtualCardMapper seVirtualCardMapper, PrIntakeMapper prIntakeMapper, PrWaterPriceMapper prWaterPriceMapper, PrIntakeVcMapper prIntakeVcMapper, SeClientCardMapper seClientCardMapper, RmIrrigateProfileMapper rmIrrigateProfileMapper, Environment env) {
         this.rmCommandHistoryMapper = rmCommandHistoryMapper;
         this.rmOpenCloseValveLastMapper = rmOpenCloseValveLastMapper;
+        //this.prCommonIntakesMapper = prCommonIntakesMapper;
         this.seVirtualCardMapper = seVirtualCardMapper;
         this.prIntakeMapper = prIntakeMapper;
         this.prWaterPriceMapper = prWaterPriceMapper;
@@ -195,5 +197,4 @@
         rsVo.obj = rmIrrigateProfileMapper.getIrrPro(type);
         return rsVo ;
     }
-
 }
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java
index 569914e..8aaf0a0 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeCtrl.java
@@ -69,6 +69,10 @@
      */
     @GetMapping(path = "used_intakes")
     public BaseResponse<List<VoOnLineIntake>> getUsedIntakes(Long operator) {
+        if(operator == null || operator <= 0) {
+            return BaseResponseUtils.buildErrorMsg("鎿嶄綔鍛樹笉鑳戒负绌�");
+        }
+
         try {
             List<VoOnLineIntake> res = intakeSv.getUsedIntakes(operator);
             return BaseResponseUtils.buildSuccess(res);
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java
index d3a59e3..2f4884a 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/intake/IntakeSv.java
@@ -78,14 +78,16 @@
         JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com));
         if(response != null && response.getString("code").equals("0001")) {
             JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap");
-            HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class);
 
             JSONArray jsonArray = new JSONArray();
-            for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
-                JSONObject jsonObject = new JSONObject();
-                jsonObject.put("rtuAddr", entry.getKey());
-                jsonObject.put("isOnLine", entry.getValue());
-                jsonArray.add(jsonObject);
+            if(attachment != null) {
+                HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class);
+                for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("rtuAddr", entry.getKey());
+                    jsonObject.put("isOnLine", entry.getValue());
+                    jsonArray.add(jsonObject);
+                }
             }
 
             qo.setOnLineMap(jsonArray.toJSONString());
@@ -116,14 +118,16 @@
         JSONObject response = (JSONObject) JSON.toJSON(sendCom2Mw(com));
         if(response != null && response.getString("code").equals("0001")) {
             JSONObject attachment = response.getJSONObject("content").getJSONObject("attachment").getJSONObject("onLineMap");
-            HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class);
 
             JSONArray jsonArray = new JSONArray();
-            for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
-                JSONObject jsonObject = new JSONObject();
-                jsonObject.put("rtuAddr", entry.getKey());
-                jsonObject.put("isOnLine", entry.getValue());
-                jsonArray.add(jsonObject);
+            if(attachment != null) {
+                HashMap<String, Boolean> onLineMap = JSON.parseObject(attachment.toJSONString(), HashMap.class);
+                for (Map.Entry<String, Boolean> entry : onLineMap.entrySet()) {
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("rtuAddr", entry.getKey());
+                    jsonObject.put("isOnLine", entry.getValue());
+                    jsonArray.add(jsonObject);
+                }
             }
 
             qo.setOnLineMap(jsonArray.toJSONString());

--
Gitblit v1.8.0