Przeglądaj źródła

新增 水肥机操作记录功能

zhaiyifei 8 miesięcy temu
rodzic
commit
1b19cace8b

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorAddReqVo.java

@@ -38,7 +38,7 @@ public class IotSfElementfactorAddReqVo extends IotBaseEntity {
     private String sfParentBid;
 
     /** 排序字段 默认0 */
-    private int sfSequence;
+    private Integer sfSequence;
 
     /** 租户ID */
     private String tid;

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorAlreadyListResVo.java

@@ -38,7 +38,7 @@ public class IotSfElementfactorAlreadyListResVo extends IotBaseEntity {
     private String sfParentBid;
 
     /** 排序字段 默认0 */
-    private int sfSequence;
+    private Integer sfSequence;
 
     /** 租户ID */
     private String tid;

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorEditReqVo.java

@@ -22,7 +22,7 @@ public class IotSfElementfactorEditReqVo extends IotBaseEntity {
     private String sfDisplayname;
 
     /** 排序字段 默认0 */
-    private int sfSequence;
+    private Integer sfSequence;
 
     /** 纬度 */
     private BigDecimal sfLat;

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorInfoVo.java

@@ -38,7 +38,7 @@ public class IotSfElementfactorInfoVo extends IotBaseEntity {
     private String sfParentBid;
 
     /** 排序字段 默认0 */
-    private int sfSequence;
+    private Integer sfSequence;
 
     /** 租户ID */
     private String tid;

+ 1 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorListReqVo.java

@@ -37,7 +37,7 @@ public class IotSfElementfactorListReqVo {
     private String sfParentBid;
 
     /** 排序字段 默认0 */
-    private int sfSequence;
+    private Integer sfSequence;
 
     /** 租户ID */
     private String tid;

+ 49 - 18
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/service/impl/IotRunHaoSfServiceImpl.java

@@ -283,31 +283,47 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         }
         JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
         Map<String, IotSfElementfactorInfoVo> eleMap = new LinkedHashMap<>();
+        Map<String, IotSfElementfactor> tempMap = new LinkedHashMap<>();
+
+        for (IotSfElementfactor elementfactor : resVoList) {
+            String sfBid = elementfactor.getSfBid();
+            tempMap.put(sfBid, elementfactor);
+        }
+
         for (IotSfElementfactor elementfactor : resVoList) {
             String sfBid = elementfactor.getSfBid();
-            String sfParentBid = elementfactor.getSfParentBid();
             String sfCode = elementfactor.getSfCode();
+            String sfParentBid = elementfactor.getSfParentBid();
             String value = getDataValue(dataJson, sfCode);
 
-            IotSfElementfactorInfoVo infoVo = new IotSfElementfactorInfoVo();
-            BeanUtils.copyProperties(elementfactor, infoVo);
-            infoVo.setValue(value);
+            IotSfElementfactorInfoVo eleResVo = new IotSfElementfactorInfoVo();
+            BeanUtils.copyProperties(elementfactor, eleResVo);
+            eleResVo.setValue(value);
 
-            IotSfElementfactorInfoVo parentInfo = eleMap.get(sfParentBid);
-            if(parentInfo == null){
-                infoVo.setChildrenList(new ArrayList<>());
-                eleMap.put(sfBid, infoVo);
+            // 表示是一级元素,直接添加
+            if(StringUtils.isEmpty(sfParentBid) && !eleMap.containsKey(sfBid)){
+                eleResVo.setChildrenList(new ArrayList<>());
+                eleMap.put(sfBid, eleResVo);
             }else{
-                parentInfo.getChildrenList().add(infoVo);
-                if(Objects.equals(infoVo.getSfType(), EnumSfElementType.SUCTION.getCode())){
-                    List<IotSfElementfactor> lsliList = RunHaoSfElementUtil.getLsLlFactor(sfCode);
-                    for(IotSfElementfactor lsli : lsliList){
-                        IotSfElementfactorInfoVo lsliVo = new IotSfElementfactorInfoVo();
-                        BeanUtils.copyProperties(lsli, lsliVo);
-                        String lv = getDataValue(dataJson, lsli.getSfCode());
-                        lsliVo.setValue(lv);
-                        parentInfo.getChildrenList().add(lsliVo);
+                // 表示不是一级元素,需要判断父元素是否已经存在
+                IotSfElementfactorInfoVo parentInfo = eleMap.get(sfParentBid);
+                // 如果父类已经添加,直接添加到父类的childrenList中
+                if(parentInfo != null){
+                    parentInfo.getChildrenList().add(eleResVo);
+                }else{
+                    // 如果父类没有添加,需要先添加父类,再添加当前元素
+                    IotSfElementfactor parentElement = tempMap.get(sfParentBid);
+                    // 如果父类不存在,直接跳过
+                    if(parentElement == null){
+                        continue;
                     }
+                    IotSfElementfactorInfoVo parentReq = new IotSfElementfactorInfoVo();
+                    BeanUtils.copyProperties(parentElement, parentReq);
+                    parentReq.setChildrenList(new ArrayList<>());
+                    parentReq.setValue(getDataValue(dataJson, parentReq.getSfCode()));
+
+                    parentReq.getChildrenList().add(eleResVo);
+                    eleMap.put(sfParentBid, parentReq);
                 }
             }
         }
@@ -744,6 +760,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         sfTypeMap.put(runMode, null);
 
         Map<EnumSfElementType, Integer> sfTypeValueMap = new HashMap<>();
+        Map<String, IotSfElementfactorInfoVo> elementfactorInfoVoMap = new HashMap<>();
         IotSfElementfactorAlreadyListResVo groupResVo = null;
 
         for(IotSfElementfactorInfoVo element : resultList){
@@ -776,11 +793,13 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
                     sfTypeValueMap.put(childType, sfTypeValueMap.getOrDefault(childType, 0) + Integer.parseInt(child.getValue()));
                     sfTypeMap.put(child.getSfCode(), childType);
+                    elementfactorInfoVoMap.put(child.getSfCode(), child);
                 }
             }
             if(typeSet.contains(elementType)){
                 sfTypeValueMap.put(elementType, sfTypeValueMap.getOrDefault(elementType, 0) + Integer.parseInt(element.getValue()));
                 sfTypeMap.put(element.getSfCode(), elementType);
+                elementfactorInfoVoMap.put(element.getSfCode(), element);
             }
         }
 
@@ -824,7 +843,17 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
                         throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"请先关闭水源泵");
                     }
                 }
-
+            }
+            if(elementfactorInfoVoMap.containsKey(key)){
+                IotSfElementfactorInfoVo elementfactorInfoVo = elementfactorInfoVoMap.get(key);
+                String oprecdName = elementfactorInfoVo.getSfDisplayname();
+                String oprecdContent = "关闭";
+                String oprecdStatus = "0";
+                if(Objects.equals(v, "1")){
+                    oprecdContent = "打开";
+                    oprecdStatus = "1";
+                }
+                iotSfIrrigationOprecordService.createIotSfIrrigationOprecord(devBid, oprecdName, oprecdContent, oprecdStatus);
             }
         }
 //
@@ -1076,6 +1105,8 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         String sfdataBid = runStatusData.getString("sfdataBid");
         iotSfIrrigationRecordService.createIotSfIrrigationRecordList(groupList, EnumIrrigationRecord.MODE_AUTO.getCode(), sfdataBid);
 
+        iotSfIrrigationOprecordService.createIotSfIrrigationOprecord(devBid, "自动灌溉", "启动", "1");
+
         IotSfConfigCmdReqVo cmdReqVo = new IotSfConfigCmdReqVo();
         cmdReqVo.setDevBid(devBid);
         cmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);

+ 29 - 3
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotSfElementfactorServiceImpl.java

@@ -1,6 +1,7 @@
 package com.yunfeiyun.agmp.iotm.web.service.impl;
 
 import com.yunfeiyun.agmp.common.utils.SecurityUtils;
+import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
 import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
@@ -116,6 +117,13 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
     @Override
     public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList) {
         Map<String, IotSfElementfactorAlreadyListResVo> eleMap = new LinkedHashMap<>();
+        Map<String, IotSfElementfactor> tempMap = new LinkedHashMap<>();
+
+        for (IotSfElementfactor elementfactor : factorList) {
+            String sfBid = elementfactor.getSfBid();
+            tempMap.put(sfBid, elementfactor);
+        }
+
         for (IotSfElementfactor elementfactor : factorList) {
             String sfBid = elementfactor.getSfBid();
             String sfParentBid = elementfactor.getSfParentBid();
@@ -123,12 +131,30 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
             IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
             BeanUtils.copyProperties(elementfactor, eleResVo);
 
-            IotSfElementfactorAlreadyListResVo parentInfo = eleMap.get(sfParentBid);
-            if(parentInfo == null){
+            // 表示是一级元素,直接添加
+            if(StringUtils.isEmpty(sfParentBid) && !eleMap.containsKey(sfBid)){
                 eleResVo.setChildrenList(new ArrayList<>());
                 eleMap.put(sfBid, eleResVo);
             }else{
-                parentInfo.getChildrenList().add(eleResVo);
+                // 表示不是一级元素,需要判断父元素是否已经存在
+                IotSfElementfactorAlreadyListResVo parentInfo = eleMap.get(sfParentBid);
+                // 如果父类已经添加,直接添加到父类的childrenList中
+                if(parentInfo != null){
+                    parentInfo.getChildrenList().add(eleResVo);
+                }else{
+                    // 如果父类没有添加,需要先添加父类,再添加当前元素
+                    IotSfElementfactor parentElement = tempMap.get(sfParentBid);
+                    // 如果父类不存在,直接跳过
+                    if(parentElement == null){
+                        continue;
+                    }
+                    IotSfElementfactorAlreadyListResVo parentReq = new IotSfElementfactorAlreadyListResVo();
+                    BeanUtils.copyProperties(parentElement, parentReq);
+                    parentReq.setChildrenList(new ArrayList<>());
+
+                    parentReq.getChildrenList().add(eleResVo);
+                    eleMap.put(sfParentBid, parentReq);
+                }
             }
         }
         return new ArrayList<>(eleMap.values());

+ 3 - 3
src/main/resources/mapper/IotSfElementfactorMapper.xml

@@ -8,10 +8,10 @@
         UPDATE IotSfElementfactor
         <set>
             <if test="sfDisplayname!= null and sfDisplayname!= ''">sfDisplayname = #{sfDisplayname},</if>
-            <if test="sfSequence!= null and sfSequence!= ''">sfSequence = #{sfSequence},</if>
+            <if test="sfSequence != null">sfSequence = #{sfSequence},</if>
             <if test="sfLng!= null and sfLng!= ''">sfLng = #{sfLng},</if>
             <if test="sfLat!= null and sfLat!= ''">sfLat = #{sfLat},</if>
-            <if test="sfAddress!= null and sfAddress!= ''">sfAddress = #{sfAddress},</if>
+            <if test="sfAddress != null and sfAddress!= ''">sfAddress = #{sfAddress},</if>
             <if test="sfModifieddate!= null and sfModifieddate!= ''">sfModifieddate = #{sfModifieddate},</if>
             <if test="sfModifier!= null and sfModifier!= ''">sfModifier = #{sfModifier},</if>
         </set>
@@ -44,7 +44,7 @@
                 </foreach>
             </if>
         </where>
-        ORDER BY sf.sfSequence DESC, sf.sfCreatedDate DESC, sf.sfDisplayname ASC
+        ORDER BY sf.sfSequence ASC, sf.sfModifieddate DESC
     </select>
 
     <select id="selectIotSfElementfactorBySfBid" resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor" parameterType="string">

+ 1 - 0
src/main/resources/mapper/IotSfIrrigationOprecordMapper.xml

@@ -42,5 +42,6 @@
             <if test="startTime!= null and startTime!= ''"> and oprcdCreateddate <![CDATA[ >= ]]> #{startTime}</if>
             <if test="endTime!= null and endTime!= ''"> and oprcdCreateddate <![CDATA[ <= ]]> #{endTime}</if>
         </where>
+        ORDER BY oprcdCreateddate DESC
     </select>
 </mapper>