Bläddra i källkod

新增 水肥机操作记录功能

zhaiyifei 8 månader sedan
förälder
incheckning
7b22d00058

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 37 - 9
src/main/java/com/yunfeiyun/agmp/iots/device/serviceImp/RunHaoSfDeviceImpl.java


+ 55 - 3
src/main/java/com/yunfeiyun/agmp/iots/service/impl/IotSfElementfactorServiceImpl.java

@@ -1,5 +1,6 @@
 package com.yunfeiyun.agmp.iots.service.impl;
 package com.yunfeiyun.agmp.iots.service.impl;
 
 
+import com.yunfeiyun.agmp.common.utils.StringUtils;
 import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
 import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
 import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 import com.yunfeiyun.agmp.iots.domain.IotSfElementfactorAlreadyListResVo;
 import com.yunfeiyun.agmp.iots.domain.IotSfElementfactorAlreadyListResVo;
@@ -98,6 +99,32 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
 //        return new ArrayList<>(eleMap.values());
 //        return new ArrayList<>(eleMap.values());
 //    }
 //    }
 
 
+//    /**
+//     * 查询已配置要素列表
+//     *
+//     * @param factorList@return
+//     */
+//    @Override
+//    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList) {
+//        Map<String, IotSfElementfactorAlreadyListResVo> eleMap = new LinkedHashMap<>();
+//        for (IotSfElementfactor elementfactor : factorList) {
+//            String sfBid = elementfactor.getSfBid();
+//            String sfParentBid = elementfactor.getSfParentBid();
+//
+//            IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
+//            BeanUtils.copyProperties(elementfactor, eleResVo);
+//
+//            IotSfElementfactorAlreadyListResVo parentInfo = eleMap.get(sfParentBid);
+//            if(parentInfo == null){
+//                eleResVo.setChildrenList(new ArrayList<>());
+//                eleMap.put(sfBid, eleResVo);
+//            }else{
+//                parentInfo.getChildrenList().add(eleResVo);
+//            }
+//        }
+//        return new ArrayList<>(eleMap.values());
+//    }
+
     /**
     /**
      * 查询已配置要素列表
      * 查询已配置要素列表
      *
      *
@@ -106,6 +133,13 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
     @Override
     @Override
     public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList) {
     public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList) {
         Map<String, IotSfElementfactorAlreadyListResVo> eleMap = new LinkedHashMap<>();
         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) {
         for (IotSfElementfactor elementfactor : factorList) {
             String sfBid = elementfactor.getSfBid();
             String sfBid = elementfactor.getSfBid();
             String sfParentBid = elementfactor.getSfParentBid();
             String sfParentBid = elementfactor.getSfParentBid();
@@ -113,12 +147,30 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
             IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
             IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
             BeanUtils.copyProperties(elementfactor, eleResVo);
             BeanUtils.copyProperties(elementfactor, eleResVo);
 
 
-            IotSfElementfactorAlreadyListResVo parentInfo = eleMap.get(sfParentBid);
-            if(parentInfo == null){
+            // 表示是一级元素,直接添加
+            if(StringUtils.isEmpty(sfParentBid) && !eleMap.containsKey(sfBid)){
                 eleResVo.setChildrenList(new ArrayList<>());
                 eleResVo.setChildrenList(new ArrayList<>());
                 eleMap.put(sfBid, eleResVo);
                 eleMap.put(sfBid, eleResVo);
             }else{
             }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());
         return new ArrayList<>(eleMap.values());

+ 38 - 6
src/main/resources/mapper/IotSfElementfactorMapper.xml

@@ -33,12 +33,44 @@
     </select>
     </select>
 
 
     <insert id="batchInsertIotSfElementfactor" parameterType="IotSfElementfactor">
     <insert id="batchInsertIotSfElementfactor" parameterType="IotSfElementfactor">
-        INSERT INTO IotSfElementfactor (id, sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
-            tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier)
-        VALUES
-        <foreach collection="list" item="item" index="index" separator=",">
-            (#{item.id}, #{item.sfBid}, #{item.devBid}, #{item.sfType}, #{item.sfCode}, #{item.sfName}, #{item.sfDisplayname}, #{item.sfParentBid}, #{item.sfSequence},
-            #{item.tid}, #{item.sfCreatedDate}, #{item.sfCreator}, #{item.sfModifieddate}, #{item.sfModifier})
+        <foreach collection="list" item="item" index="index" separator=";">
+            INSERT INTO IotSfElementfactor
+            <trim prefix="(" suffix=")" suffixOverrides=",">
+                <if test="item.sfBid!= null and item.sfBid!= ''">sfBid,</if>
+                <if test="item.devBid!= null and item.devBid!= ''">devBid,</if>
+                <if test="item.sfType!= null and item.sfType!= ''">sfType,</if>
+                <if test="item.sfCode!= null and item.sfCode!= ''">sfCode,</if>
+                <if test="item.sfName!= null and item.sfName!= ''">sfName,</if>
+                <if test="item.sfDisplayname!= null and item.sfDisplayname!= ''">sfDisplayname,</if>
+                <if test="item.sfParentBid!= null and item.sfParentBid!= ''">sfParentBid,</if>
+                <if test="item.sfSequence!= null">sfSequence,</if>
+                <if test="item.tid!= null and item.tid!= ''">tid,</if>
+                <if test="item.sfCreatedDate!= null and item.sfCreatedDate!= ''">sfCreatedDate,</if>
+                <if test="item.sfCreator!= null and item.sfCreator!= ''">sfCreator,</if>
+                <if test="item.sfModifieddate!= null and item.sfModifieddate!= ''">sfModifieddate,</if>
+                <if test="item.sfModifier!= null and item.sfModifier!= ''">sfModifier,</if>
+                <if test="item.sfLng!= null and item.sfLng!= ''">sfLng,</if>
+                <if test="item.sfLat!= null and item.sfLat!= ''">sfLat,</if>
+                <if test="item.sfAddress!= null and item.sfAddress!= ''">sfAddress,</if>
+            </trim>
+            <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
+                <if test="item.sfBid!= null and item.sfBid!= ''">#{item.sfBid},</if>
+                <if test="item.devBid!= null and item.devBid!= ''">#{item.devBid},</if>
+                <if test="item.sfType!= null and item.sfType!= ''">#{item.sfType},</if>
+                <if test="item.sfCode!= null and item.sfCode!= ''">#{item.sfCode},</if>
+                <if test="item.sfName!= null and item.sfName!= ''">#{item.sfName},</if>
+                <if test="item.sfDisplayname!= null and item.sfDisplayname!= ''">#{item.sfDisplayname},</if>
+                <if test="item.sfParentBid!= null and item.sfParentBid!= ''">#{item.sfParentBid},</if>
+                <if test="item.sfSequence!= null">#{item.sfSequence},</if>
+                <if test="item.tid!= null and item.tid!= ''">#{item.tid},</if>
+                <if test="item.sfCreatedDate!= null and item.sfCreatedDate!= ''">#{item.sfCreatedDate},</if>
+                <if test="item.sfCreator!= null and item.sfCreator!= ''">#{item.sfCreator},</if>
+                <if test="item.sfModifieddate!= null and item.sfModifieddate!= ''">#{item.sfModifieddate},</if>
+                <if test="item.sfModifier!= null and item.sfModifier!= ''">#{item.sfModifier},</if>
+                <if test="item.sfLng!= null and item.sfLng!= ''">#{item.sfLng},</if>
+                <if test="item.sfLat!= null and item.sfLat!= ''">#{item.sfLat},</if>
+                <if test="item.sfAddress!= null and item.sfAddress!= ''">#{item.sfAddress},</if>
+            </trim>
         </foreach>
         </foreach>
     </insert>
     </insert>