Bläddra i källkod

Merge branch 'develop' of com_yunfei_saas/agmp_iotm into master

yf_zn 8 månader sedan
förälder
incheckning
e37566a25a

+ 12 - 8
src/main/java/com/yunfeiyun/agmp/iotm/device/common/service/impl/IotDeviceRefreshServiceImpl.java

@@ -2,6 +2,7 @@ package com.yunfeiyun.agmp.iotm.device.common.service.impl;
 
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.enums.IotDeviceStatusTypeEnum;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
@@ -36,14 +37,17 @@ public class IotDeviceRefreshServiceImpl implements IotDeviceRefreshService {
         if (findDevice == null) {
             throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在" + devBid);
         }
-        String devStatus = findDevice.getDevStatus();
-        String devCreateddate = findDevice.getDevCreateddate();
-        Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
-        Date nowDate = DateUtils.getNowDate();
-        long diffTime = nowDate.getTime() - createdDate.getTime();
-        if(diffTime > 10 * 1000){
-            if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
-                throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
+
+        if(!Objects.equals(findDevice.getDevtypeBid(), IotDeviceDictConst.TYPE_RUNHAO_SF)){
+            String devStatus = findDevice.getDevStatus();
+            String devCreateddate = findDevice.getDevCreateddate();
+            Date createdDate = DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, devCreateddate);
+            Date nowDate = DateUtils.getNowDate();
+            long diffTime = nowDate.getTime() - createdDate.getTime();
+            if(diffTime > 10 * 1000){
+                if (!Objects.equals(devStatus, IotDeviceStatusTypeEnum.ONLINE.getCode()) && !Objects.equals(devStatus, IotDeviceStatusTypeEnum.WAIT_ACTIVATE.getCode())) {
+                    throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备离线无法操作");
+                }
             }
         }
 

+ 16 - 1
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/controller/IotDeviceSfController.java

@@ -15,6 +15,7 @@ import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
+import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceRefreshService;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.*;
 import com.yunfeiyun.agmp.iotm.util.ValidateUtil;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
@@ -26,6 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
 import java.util.List;
@@ -47,6 +49,9 @@ public class IotDeviceSfController extends BaseController {
     @Autowired
     private IIotSfElementfactorService iotSfElementfactorService;
 
+    @Resource
+    private IotDeviceRefreshService iotDeviceRefreshService;
+
     /**
      * 水肥设备列表
      * /list  所有设备
@@ -351,10 +356,11 @@ public class IotDeviceSfController extends BaseController {
     }
 
     /**
-     * 获取润浩全局灌区参数
+     * 编辑润浩全局灌区参数
      * @param
      * @return
      */
+    @Transactional(rollbackFor = Exception.class)
     @PostMapping("/rh/group/param/global/edit")
     public AjaxResult getGroupParamByGlobal(@RequestBody IotSfGroupParamEditReqVo reqVo){
         String devBid = reqVo.getDevBid();
@@ -373,6 +379,7 @@ public class IotDeviceSfController extends BaseController {
      * @param
      * @return
      */
+    @Transactional(rollbackFor = Exception.class)
     @PostMapping("/auto/start")
     public AjaxResult autoStart(@RequestBody IotSfConfigCmdReqVo reqVo){
         String devBid = reqVo.getDevBid();
@@ -390,6 +397,7 @@ public class IotDeviceSfController extends BaseController {
      * @param
      * @return
      */
+    @Transactional(rollbackFor = Exception.class)
     @PostMapping("/auto/stop")
     public AjaxResult autoStop(@RequestBody IotSfConfigCmdReqVo reqVo){
         String devBid = reqVo.getDevBid();
@@ -408,6 +416,7 @@ public class IotDeviceSfController extends BaseController {
      * @return
      * @throws Exception
      */
+    @Transactional(rollbackFor = Exception.class)
     @PostMapping("/devctl")
     public AjaxResult devControl(@RequestBody IotSfConfigCmdReqVo reqVo) {
         log.info("【{}】【水肥机】【下发水肥机设备控制指令】客户id {}", LogCore.getSeq(), getCustomerId());
@@ -455,4 +464,10 @@ public class IotDeviceSfController extends BaseController {
         return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
     }
 
+    @GetMapping("/refresh/{devBid}")
+    public AjaxResult refresh(@PathVariable("devBid") String devBid) {
+        String result = iotDeviceRefreshService.refresh(devBid);
+        return new AjaxResult(ErrorCode.SUCCESS.getCode(), result, null);
+    }
+
 }

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

@@ -4,6 +4,7 @@ import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
 import lombok.Data;
 
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * 水肥机要素
@@ -18,6 +19,8 @@ public class IotSfElementfactorEditReqVo extends IotBaseEntity {
     /** 设备编号 */
     private String devBid;
 
+    private String sfType;
+
     /** 显示名称 */
     private String sfDisplayname;
 
@@ -32,4 +35,6 @@ public class IotSfElementfactorEditReqVo extends IotBaseEntity {
     /** 地址 */
     private String sfAddress;
 
+    private List<IotSfElementfactorEditReqVo> childrenList;
+
 }

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

@@ -63,4 +63,6 @@ public class IotSfElementfactorListReqVo {
 
     private List<String> sfTypeList;
 
+    private List<String> sfBidList;
+
 }

+ 87 - 74
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/service/IIotSfCommService.java

@@ -13,21 +13,25 @@ import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
 import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
 import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.domain.*;
+import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.model.cmd.CmdGroupModel;
 import com.yunfeiyun.agmp.iot.common.util.dev.RunHaoSfElementUtil;
+import com.yunfeiyun.agmp.iotm.device.common.domin.DeviceRefreshDto;
 import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceDataListReqVo;
 import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceBaseService;
 import com.yunfeiyun.agmp.iotm.device.common.service.impl.IotDeviceBaseServiceImpl;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.*;
+import com.yunfeiyun.agmp.iotm.util.MyPageUtil;
 import com.yunfeiyun.agmp.iotm.web.service.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+
+import static com.yunfeiyun.agmp.common.utils.PageUtils.startPage;
 
 /**
  * 水肥机通用服务
@@ -230,39 +234,6 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
     }
 
     /**
-     * 获取灌区设备已存在的元素列表
-     *
-     * @param reqVo 请求对象,包含设备标识等信息
-     * @return TableDataInfo 包含响应码、消息、数据和总数
-     * @throws IotBizException 抛出业务异常,包含错误码和错误信息
-     */
-    public TableDataInfo getValveAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
-        TableDataInfo rspData = new TableDataInfo();
-        rspData.setCode(ErrorCode.SUCCESS.getCode());
-        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
-        rspData.setData(new ArrayList<>());
-        rspData.setTotal(0);
-
-        String devBid = reqVo.getDevBid();
-        if (StringUtils.isEmpty(devBid)) {
-            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
-        }
-
-        IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
-        if (findDevice == null) {
-            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
-        }
-
-        List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getValveAlreadyElementList(reqVo);
-        if (resVoList != null && !resVoList.isEmpty()){
-            rspData.setData(resVoList);
-            rspData.setTotal(resVoList.size());
-        }
-        return rspData;
-    }
-
-
-    /**
      * 获取水肥机状态信息
      *
      * @param devBid 请求对象,包含设备标识等信息
@@ -291,6 +262,9 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
             throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
         }
         IotDeviceconfig iotDeviceconfig = iIotDeviceconfigService.selectIotDeviceConfigByDevBid(devBid);
+        if(iotDeviceconfig == null){
+            throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"配置信息不存在,请检查设备");
+        }
         return JSONObject.parseObject(iotDeviceconfig.getDevcfgContext());
     }
 
@@ -347,36 +321,65 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
      */
     public int elementEdit(IotSfElementfactorEditReqVo reqVo) {
         String devBid = reqVo.getDevBid();
-        String sfBid = reqVo.getSfBid();
-        String sfDisplayname = reqVo.getSfDisplayname();
 
         if (StringUtils.isEmpty(devBid)) {
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
         }
-        if (StringUtils.isEmpty(sfDisplayname)) {
-            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素名称不能为空");
-        }
+
         IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(reqVo.getDevBid());
         if (iotDevice == null) {
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
         }
-        if (StringUtils.isEmpty(sfBid)) {
-            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素标识不能为空");
+
+        List<String> sfBidLit = new ArrayList<>();
+        List<IotSfElementfactorEditReqVo> reqList = new ArrayList<>();
+        reqList.add(reqVo);
+        sfBidLit.add(reqVo.getSfBid());
+        if(Objects.equals(reqVo.getSfType(), EnumSfElementType.FERTILIZER_BUCKET.getCode())){
+            List<IotSfElementfactorEditReqVo> childrenList = reqVo.getChildrenList();
+            if (childrenList!= null &&!childrenList.isEmpty()) {
+                for(IotSfElementfactorEditReqVo child : childrenList) {
+                    reqList.add(child);
+                    sfBidLit.add(child.getSfBid());
+                }
+            }
+        }
+        IotSfElementfactorListReqVo selectReqVo = new IotSfElementfactorListReqVo();
+        selectReqVo.setSfBidList(sfBidLit);
+        selectReqVo.setDevBid(devBid);
+        List<IotSfElementfactor> factorList = iotSfElementfactorService.selectIotSfElementfactorList(selectReqVo);
+        Map<String, IotSfElementfactor> factorMap = new HashMap<>();
+        for (IotSfElementfactor factor : factorList) {
+            factorMap.put(factor.getSfBid(), factor);
         }
 
-        IotSfElementfactor iotSfElementfactor = iotSfElementfactorService.selectIotSfElementfactorBySfBid(sfBid);
-        if (iotSfElementfactor == null) {
-            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素不存在");
+        String sfModifieddate = DateUtils.dateTimeNow();
+        List<IotSfElementfactor> updateList = new ArrayList<>();
+        for (IotSfElementfactorEditReqVo req : reqList) {
+            if (StringUtils.isEmpty(req.getSfDisplayname())) {
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "名称不能为空");
+            }
+            if (StringUtils.isEmpty(req.getSfBid())) {
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "标识不能为空");
+            }
+            if(!factorMap.containsKey(req.getSfBid())){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "配置不存在");
+            }
+
+            IotSfElementfactor iotSfElementfactor = new IotSfElementfactor();
+            iotSfElementfactor.setSfBid(req.getSfBid());
+            iotSfElementfactor.setSfDisplayname(req.getSfDisplayname());
+            iotSfElementfactor.setSfAddress(req.getSfAddress());
+            iotSfElementfactor.setSfLat(req.getSfLat());
+            iotSfElementfactor.setSfLng(req.getSfLng());
+            iotSfElementfactor.setSfSequence(req.getSfSequence());
+            iotSfElementfactor.setSfModifieddate(sfModifieddate);
+            iotSfElementfactor.setSfModifier(SecurityUtils.getUserId());
+
+            updateList.add(iotSfElementfactor);
         }
 
-        iotSfElementfactor.setSfDisplayname(sfDisplayname);
-        iotSfElementfactor.setSfAddress(reqVo.getSfAddress());
-        iotSfElementfactor.setSfLat(reqVo.getSfLat());
-        iotSfElementfactor.setSfLng(reqVo.getSfLng());
-        iotSfElementfactor.setSfSequence(reqVo.getSfSequence());
-        iotSfElementfactor.setSfModifieddate(DateUtils.dateTimeNow());
-        iotSfElementfactor.setSfModifier(SecurityUtils.getUserId());
-        return iotSfElementfactorService.updateIotSfElementfactor(iotSfElementfactor);
+        return iotSfElementfactorService.batchUpdateIotSfElementfactor(updateList);
     }
 
     /**
@@ -431,12 +434,6 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
      * @param reqVo
      */
     public TableDataInfo getRecordList(IotSfIrrigationRecordListReqVo reqVo) {
-        TableDataInfo rspData = new TableDataInfo();
-        rspData.setCode(ErrorCode.SUCCESS.getCode());
-        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
-        rspData.setData(new ArrayList<>());
-        rspData.setTotal(0);
-
         String devBid = reqVo.getDevBid();
         if (StringUtils.isEmpty(devBid)) {
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备标识不能为空");
@@ -446,12 +443,9 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
         }
 
+        startPage();
         List<IotSfIrrigationRecord> recordList = iIotSfIrrigationRecordService.selectIrrigationRecordList(reqVo);
-        if (recordList != null && !recordList.isEmpty()){
-            rspData.setData(recordList);
-            rspData.setTotal(recordList.size());
-        }
-        return rspData;
+        return MyPageUtil.getDataTable(recordList);
     }
 
     /**
@@ -461,11 +455,6 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
      * @param reqVo
      */
     public TableDataInfo getOpRecordList(IotSfIrrigationOprecordListReqVo reqVo) {
-        TableDataInfo rspData = new TableDataInfo();
-        rspData.setCode(ErrorCode.SUCCESS.getCode());
-        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
-        rspData.setData(new ArrayList<>());
-        rspData.setTotal(0);
 
         String devBid = reqVo.getDevBid();
         if (StringUtils.isEmpty(devBid)) {
@@ -476,12 +465,36 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
         }
 
+        startPage();
         List<IotSfIrrigationOprecord> recordList = iIotSfIrrigationOprecordService.selectIrrigationOprecordList(reqVo);
-        if (recordList != null && !recordList.isEmpty()){
-            rspData.setData(recordList);
-            rspData.setTotal(recordList.size());
-        }
-        return rspData;
+        return MyPageUtil.getDataTable(recordList);
     }
 
+    public void refresh(DeviceRefreshDto reqVo) {
+        IotDevice findDevice = reqVo.getIotDevice();
+        String devBid = findDevice.getDevBid();
+        log.info("创建【“刷新”指令集任务】,设备类型:{}", findDevice.getDevtypeName());
+        JSONObject ext = new JSONObject();
+        ext.put("type", "data");
+        JSONObject payload = new JSONObject();
+        payload.put("cmd", "read");
+        payload.put("ext", ext);
+        IotDeviceconfig iotDeviceconfig = new IotDeviceconfig();
+        iotDeviceconfig.setTid(findDevice.getTid());
+        iotDeviceconfig.setDevBid(devBid);
+        iotDeviceconfig.setDevcfgContext(JSONUtils.toJSONString(payload));
+
+        CmdGroupModel cmdGroupModel = iIotDeviceconfigService.createRefreshCmd(iotDeviceconfig);
+
+        // 构建日志需要用的内容
+        cmdGroupModel.setRequestId(IdUtils.fastUUID());
+        cmdGroupModel.setDevCode(findDevice.getDevCode());
+        cmdGroupModel.setCtBiztype("3");
+        cmdGroupModel.setCtDevtype(findDevice.getDevtypeBid());
+        cmdGroupModel.setCtBiztitle(findDevice.getDevtypeName() + ":" + findDevice.getDevCode());
+        cmdGroupModel.setCtParam("设备id:"+devBid);
+        iIotCmdtaskService.handInternalCmd(cmdGroupModel);
+        String taskUuid = cmdGroupModel.getTaskUuid();
+        log.info("【“刷新”指令集任务】创建成功,taskUuid:{}", taskUuid);
+    }
 }

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

@@ -364,10 +364,11 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         params.put("devBid", devBid);
 
         IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
-        JSONObject dataJson = new JSONObject();
-        if (iotRunHaoSfdata != null) {
-            dataJson = iotRunHaoSfdata.getSfdataContent();
+        if(iotRunHaoSfdata == null){
+            return new JSONObject();
         }
+        JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
+
         String[] keys = new String[]{"Num-dqqf", "Num-ggsj", "Num-fqs", "Num-lgjg", "Num-lgcs", "Btn-yjqd", "Btn-zdsd"};
         String[] feiKeys = new String[]{"Num-fsjA", "Num-fsjB", "Num-fsjC", "Num-fsjD"};
         JSONObject runStatus = new JSONObject();
@@ -439,16 +440,16 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         // 肥料桶是虚拟的,不需要检测code重复问题
         if(!Objects.equals(sfType, EnumSfElementType.FERTILIZER_BUCKET.getCode())){
             if (StringUtils.isEmpty(sfCode)) {
-                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码不能为空");
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "编码不能为空");
             }
         }
         String sfDisplayname = reqVo.getSfDisplayname();
         if (StringUtils.isEmpty(sfType)) {
-            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素类型不能为空");
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
         }
 
         if (StringUtils.isEmpty(sfDisplayname)) {
-            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素名称不能为空");
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "名称不能为空");
         }
         List<IotSfElementfactorAddReqVo> childrenList = reqVo.getChildrenList();
         if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
@@ -485,7 +486,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
         for(IotSfElementfactor element : sfElementfactorList){
             if(sfCodeSet.contains(element.getSfCode())){
-                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码重复");
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "编码重复");
             }
         }
         int status = iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
@@ -539,7 +540,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         }
         List<IotSfElementfactorAddReqVo> elementList = reqVo.getElementList();
         if(elementList == null || elementList.isEmpty()){
-            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "元素列表不能为空");
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "列表不能为空");
         }
 
         IotSfElementfactorListReqVo reqVo1 = new IotSfElementfactorListReqVo();
@@ -555,25 +556,18 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         }
 
         String createDate = DateUtils.dateTimeNow();
+        Set<String> sfTypeSet = new HashSet<>();
+
         List<IotSfElementfactor> sfElementfactorList = new ArrayList<>();
-        Set<String> sfCodeAlreadySet = new HashSet<>();
-        List<IotSfElementfactorAddReqVo> valveList = new ArrayList<>();
+        String sfType = null;
         IotSfElementfactor parentElement = null;
-
-        Map<String, List<String>> groupValveMap = new HashMap<>();
-        Map<String, String> params = new HashMap<>();
-        params.put("devBid", devBid);
-        IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
-        if(iotRunHaoSfdata != null && iotRunHaoSfdata.getSfdataContent() !=null ){
-            groupValveMap = getGroupValveMap(iotRunHaoSfdata.getSfdataContent());
-        }
-        Set<String> sfTypeSet = new HashSet<>();
-        for(IotSfElementfactorAddReqVo element : elementList) {
-            String sfType = element.getSfType();
+        for(IotSfElementfactorAddReqVo element : elementList){
             String sfCode = element.getSfCode();
+            sfType = element.getSfType();
             String sfDisplayname = element.getSfDisplayname();
             String sfParentBid = element.getSfParentBid();
-            if(sfCodeSet.contains(sfCode) || sfCodeAlreadySet.contains(sfCode)){
+
+            if(sfCodeSet.contains(sfCode)){
                 throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
             }
             if (StringUtils.isEmpty(sfType)) {
@@ -582,9 +576,6 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
             if (StringUtils.isEmpty(sfDisplayname)) {
                 throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "名称不能为空");
             }
-
-            sfTypeSet.add(sfType);
-
             IotSfElementfactor elementfactor = makeIotSfElementfactor(element, createDate);
 
             if(Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
@@ -592,62 +583,84 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
                     throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "灌区标识不能为空");
                 }
                 parentElement = elementMap.get(sfParentBid);
-                if(parentElement == null || !Objects.equals(parentElement.getSfType(), EnumSfElementType.GROUP.getCode())){
+                if(parentElement == null){
                     throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "灌区不存在");
                 }
-                valveList.add(element);
-
-            }else if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
-                List<String> valveCodeList = groupValveMap.get(sfCode);
-                if(valveCodeList!= null &&!valveCodeList.isEmpty()){
-                    for(String valveCode : valveCodeList){
-                        IotSfElementfactor valvefactor = RunHaoSfElementUtil.getValveElementFactor(valveCode);
-                        if(valvefactor == null){
-                            continue;
-                        }
-                        valvefactor.setSfParentBid(element.getSfBid());
-                        valvefactor.setTid(element.getTid());
-                        valvefactor.setDevBid(devBid);
-                        valvefactor.setSfCreatedDate(createDate);
-                        valvefactor.setSfCreator(SecurityUtils.getUserId());
-                        valvefactor.setSfModifieddate(createDate);
-                        valvefactor.setSfModifier(SecurityUtils.getUserId());
-
-                        sfElementfactorList.add(valvefactor);
-                    }
-                }
+                elementfactor.setSfParentBid(sfParentBid);
             }
-
             sfElementfactorList.add(elementfactor);
-
-            sfCodeAlreadySet.add(sfCode);
+            sfTypeSet.add(sfType);
         }
 
         if(sfTypeSet.size() > 1){
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "批量新增一次只能操作一种类型");
         }
 
-        if(parentElement != null){
-            iotSfElementfactorService.deleteIotSfElementfactorBySfBid(parentElement.getSfBid());
-        }
         int status = 0;
         if(!sfElementfactorList.isEmpty()){
             status = iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
         }
-        // 下发 灌区和阀的关联配置命令
-        if(parentElement != null){
+        if(parentElement != null && Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
             IotSfElementfactorAddReqVo groupReqVo = new IotSfElementfactorAddReqVo();
             BeanUtils.copyProperties(parentElement, groupReqVo);
-
-            groupReqVo.setChildrenList(valveList);
+            groupReqVo.setChildrenList(elementList);
 
             sendGroupConfig(groupReqVo, findDevice);
         }
-
         return status;
     }
 
 
+//    /**
+//     * 删除元素
+//     *
+//     * @param reqVo 请求对象,包含了要删除的元素信息
+//     * @return 返回删除结果,返回值为0表示删除成功,非0表示删除失败
+//     */
+//    @Override
+//    public int elementDelete(IotSfElementfactor reqVo) {
+//        String sfBid = reqVo.getSfBid();
+//        String sfType = reqVo.getSfType();
+//        String devBid = reqVo.getDevBid();
+//        String sfCode = reqVo.getSfCode();
+//        IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+//
+//        int status = iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
+//        Map<String, String> payload = new HashMap<>();
+//        if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
+//            IotSfElementfactorListReqVo selectReqVo = new IotSfElementfactorListReqVo();
+//            selectReqVo.setDevBid(devBid);
+//            List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getGroupAlreadyElementList(selectReqVo);
+//            IotSfElementfactorAlreadyListResVo alreadyResVo = resVoList.get(0);
+//            List<IotSfElementfactorAlreadyListResVo> childrenList = alreadyResVo.getChildrenList();
+//
+//            if(childrenList != null && !childrenList.isEmpty()){
+//                for(IotSfElementfactorAlreadyListResVo child : childrenList){
+//                    String childSfCode = child.getSfCode();
+//                    int valveIndex = Integer.parseInt(childSfCode.replace("Btn-fa", ""));
+//                    String key = "Btn-fx" + String.format("%02d", valveIndex);
+//                    payload.put(key, "0");
+//                }
+//            }
+//
+//        }else if(Objects.equals(sfType, EnumSfElementType.SOLENOID_VALVE.getCode())){
+//            int valveIndex = Integer.parseInt(sfCode.replace("Btn-fa", ""));
+//            String key = "Btn-fx" + String.format("%02d", valveIndex);
+//            payload.put(key, "0");
+//        }
+//        if(!payload.isEmpty()){
+//            IotSfConfigCmdReqVo configCmdReqVo = new IotSfConfigCmdReqVo();
+//            configCmdReqVo.setDevBid(devBid);
+//            configCmdReqVo.setCmd(CmdDef.RunHaoSfCmdDef.CMD_CONFIG);
+//            configCmdReqVo.setIotDevice(findDevice);
+//            configCmdReqVo.setData(JSONObject.from(payload));
+//
+//            sendConfigCmd(configCmdReqVo);
+//        }
+//
+//        return status;
+//    }
+
     /**
      * 删除元素
      *
@@ -662,13 +675,25 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         String sfCode = reqVo.getSfCode();
         IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
 
-        int status = iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
         Map<String, String> payload = new HashMap<>();
         if(Objects.equals(sfType, EnumSfElementType.GROUP.getCode())){
+
             IotSfElementfactorListReqVo selectReqVo = new IotSfElementfactorListReqVo();
             selectReqVo.setDevBid(devBid);
             List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getGroupAlreadyElementList(selectReqVo);
-            IotSfElementfactorAlreadyListResVo alreadyResVo = resVoList.get(0);
+            if(resVoList == null || resVoList.isEmpty()){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"灌区不存在");
+            }
+            IotSfElementfactorAlreadyListResVo alreadyResVo = null;
+            for(IotSfElementfactorAlreadyListResVo resVo : resVoList){
+                if(Objects.equals(resVo.getSfBid(), sfBid)){
+                    alreadyResVo = resVo;
+                    break;
+                }
+            }
+            if(alreadyResVo == null){
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"灌区不存在");
+            }
             List<IotSfElementfactorAlreadyListResVo> childrenList = alreadyResVo.getChildrenList();
 
             if(childrenList != null && !childrenList.isEmpty()){
@@ -694,8 +719,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
             sendConfigCmd(configCmdReqVo);
         }
-
-        return status;
+        return iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
     }
 
     @Override
@@ -753,7 +777,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         TableDataInfo tableDataInfo = getStatus(devBid);
         List<IotSfElementfactorInfoVo> resultList = (List<IotSfElementfactorInfoVo>) tableDataInfo.getData();
         if(resultList == null || resultList.isEmpty()){
-            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"未配置要素");
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"未配置");
         }
 
         Map<String, EnumSfElementType> sfTypeMap = new HashMap<>();
@@ -856,22 +880,6 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
                 iotSfIrrigationOprecordService.createIotSfIrrigationOprecord(devBid, oprecdName, oprecdContent, oprecdStatus);
             }
         }
-//
-//        if(groupResVo != null){
-//            String v = "0";
-//            for(IotSfElementfactorAlreadyListResVo child : groupResVo.getChildrenList()){
-//                String key = child.getSfCode();
-//                v = devConfig.getString(key);
-//            }
-//
-//            if(Objects.equals(v, "1")){
-//                String sfdataBid = runStatusData.getString("sfdataBid");
-//                List<IotSfElementfactorAlreadyListResVo> groupList = new ArrayList<>();
-//                groupList.add(groupResVo);
-//                iotSfIrrigationRecordService.createIotSfIrrigationRecordList(groupList, EnumIrrigationRecord.MODE_MANUAL.getCode(), sfdataBid);
-//            }
-//        }
-
 
         // 切换到自动模式,先重置状态
         String value = devConfig.getString(runMode);
@@ -1064,7 +1072,14 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
             if(elementfactor.getChildrenList() == null || elementfactor.getChildrenList().isEmpty()){
                 throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "灌区未配置阀,无法开始灌溉");
             }
+            // 打开灌区
             sendJson.put(sfCode, "1");
+            // 打开灌区下发阀
+            List<IotSfElementfactorAlreadyListResVo> childrenList = elementfactor.getChildrenList();
+            for(IotSfElementfactorAlreadyListResVo child : childrenList){
+                String childSfCode = child.getSfCode();
+                sendJson.put(childSfCode, "1");
+            }
             groupList.add(elementfactor);
             if("0".equals(dqqf) && sfCode.startsWith("Btn-qx")){
                 try{
@@ -1075,11 +1090,25 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
             }
         }
 
-        sendJson.put("Num-dqqf", dqqf);
-
         if(sendJson.isEmpty()){
             throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "请先选择灌区");
         }
+        IotSfElementfactorListReqVo pumpVo = new IotSfElementfactorListReqVo();
+        pumpVo.setDevBid(devBid);
+        pumpVo.setTid(SecurityUtils.getTid());
+        List<IotSfElementfactor> sfElementfactorList = iotSfElementfactorService.selectIotSfElementfactorListByPump(pumpVo);
+        if(sfElementfactorList != null &&!sfElementfactorList.isEmpty()){
+            for(IotSfElementfactor vo : sfElementfactorList){
+                String sfCode = vo.getSfCode();
+                String sfType = vo.getSfType();
+                if(Objects.equals(sfType, EnumSfElementType.FERTILIZER_BUCKET.getCode())){
+                    continue;
+                }
+                sendJson.put(sfCode, "1");
+            }
+        }
+
+        sendJson.put("Num-dqqf", dqqf);
         String[] keys = new String[]{"Btn-dsdl", "Num-lgcs", "Num-lgjg"};
         for(String key : keys){
             sendJson.put(key, data.getString(key));

+ 18 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotSfElementfactorMapper.java

@@ -52,4 +52,22 @@ public interface IotSfElementfactorMapper {
      */
     public int updateIotSfElementfactor(IotSfElementfactor elementfactor);
 
+
+    /**
+     * 查询已配置要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public List<IotSfElementfactor> getAlreadyElementByBid(String sfBid);
+
+
+    /**
+     * 更新水肥机要素
+     *
+     * @param elementfactor 水肥机要素
+     * @return 结果
+     */
+    public int batchUpdateIotSfElementfactor(List<IotSfElementfactor> elementfactorList);
+
 }

+ 8 - 7
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotSfElementfactorService.java

@@ -70,6 +70,14 @@ public interface IIotSfElementfactorService {
     public int updateIotSfElementfactor(IotSfElementfactor elementfactor);
 
     /**
+     * 更新水肥机要素
+     *
+     * @param elementfactor 水肥机要素
+     * @return 结果
+     */
+    public int batchUpdateIotSfElementfactor(List<IotSfElementfactor> elementfactorList);
+
+    /**
      * 删除水肥机要素
      *
      * @param sfBid 水肥机要素ID
@@ -109,12 +117,5 @@ public interface IIotSfElementfactorService {
 
     public List<IotSfElementfactorAlreadyListResVo> getGroupAlreadyElementList(IotSfElementfactorListReqVo reqVo);
 
-    /**
-     * 查询电磁阀已配置要素列表
-     * @param reqVo
-     * @return
-     */
-
-    public List<IotSfElementfactorAlreadyListResVo> getValveAlreadyElementList(IotSfElementfactorListReqVo reqVo);
 }
 

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

@@ -13,10 +13,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 
 @Slf4j
@@ -71,6 +68,16 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
     }
 
     /**
+     * 更新水肥机要素
+     *
+     * @param elementfactorList@return 结果
+     */
+    @Override
+    public int batchUpdateIotSfElementfactor(List<IotSfElementfactor> elementfactorList) {
+        return iotSfElementfactorMapper.batchUpdateIotSfElementfactor(elementfactorList);
+    }
+
+    /**
      * 删除水肥机要素
      *
      * @param sfBid 水肥机要素ID
@@ -116,48 +123,33 @@ 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);
-        }
 
+        Map<String, IotSfElementfactorAlreadyListResVo> resultMap = new LinkedHashMap<>();
         for (IotSfElementfactor elementfactor : factorList) {
             String sfBid = elementfactor.getSfBid();
             String sfParentBid = elementfactor.getSfParentBid();
-
             IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
             BeanUtils.copyProperties(elementfactor, eleResVo);
-
-            // 表示是一级元素,直接添加
-            if(StringUtils.isEmpty(sfParentBid) && !eleMap.containsKey(sfBid)){
+            if(StringUtils.isEmpty(sfParentBid)){
                 eleResVo.setChildrenList(new ArrayList<>());
-                eleMap.put(sfBid, eleResVo);
-            }else{
-                // 表示不是一级元素,需要判断父元素是否已经存在
-                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);
-                }
+                resultMap.put(sfBid, eleResVo);
+            }
+        }
+
+        for (IotSfElementfactor elementfactor : factorList) {
+            String sfParentBid = elementfactor.getSfParentBid();
+            if(StringUtils.isEmpty(sfParentBid)){
+                continue;
             }
+            IotSfElementfactorAlreadyListResVo parentInfo = resultMap.get(sfParentBid);
+            if(parentInfo == null){
+                continue;
+            }
+            IotSfElementfactorAlreadyListResVo childResVo = new IotSfElementfactorAlreadyListResVo();
+            BeanUtils.copyProperties(elementfactor, childResVo);
+            parentInfo.getChildrenList().add(childResVo);
         }
-        return new ArrayList<>(eleMap.values());
+        return new ArrayList<>(resultMap.values());
     }
 
     /**
@@ -234,16 +226,4 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
         List<IotSfElementfactor> elementfactorList = selectIotSfElementfactorList(reqVo);
         return getAlreadyElementList(elementfactorList);
     }
-
-    /**
-     * 查询电磁阀已配置要素列表
-     *
-     * @param reqVo
-     * @return
-     */
-    @Override
-    public List<IotSfElementfactorAlreadyListResVo> getValveAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
-        List<IotSfElementfactor> elementfactorList = selectIotSfElementfactorListByValve(reqVo);
-        return getAlreadyElementList(elementfactorList);
-    }
 }

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

@@ -17,6 +17,21 @@
         </set>
         WHERE sfBid = #{sfBid}
     </update>
+    <update id="batchUpdateIotSfElementfactor" parameterType="IotSfElementfactor">
+        <foreach collection="list" item="item" index="index" separator=";">
+            UPDATE IotSfElementfactor
+            <set>
+                <if test="item.sfDisplayname!= null and item.sfDisplayname!= ''">sfDisplayname = #{item.sfDisplayname},</if>
+                <if test="item.sfSequence!= null">sfSequence = #{item.sfSequence},</if>
+                <if test="item.sfLng!= null and item.sfLng!= ''">sfLng = #{item.sfLng},</if>
+                <if test="item.sfLat!= null and item.sfLat!= ''">sfLat = #{item.sfLat},</if>
+                <if test="item.sfAddress!= null and item.sfAddress!= ''">sfAddress = #{item.sfAddress},</if>
+                <if test="item.sfModifieddate!= null and item.sfModifieddate!= ''">sfModifieddate = #{item.sfModifieddate},</if>
+                <if test="item.sfModifier!= null and item.sfModifier!= ''">sfModifier = #{item.sfModifier},</if>
+            </set>
+            WHERE sfBid = #{item.sfBid}
+        </foreach>
+    </update>
 
     <select id="selectIotSfElementfactorList" parameterType="com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo"
             resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor" >
@@ -43,6 +58,12 @@
                     #{item}
                 </foreach>
             </if>
+            <if test="sfBidList != null and sfBidList.size() > 0">
+                and sf.sfBid in
+                <foreach collection="sfBidList" item="item" index="index" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
         </where>
         ORDER BY sf.sfSequence ASC, sf.sfModifieddate DESC
     </select>
@@ -53,14 +74,53 @@
         FROM IotSfElementfactor AS sf
         where sf.sfBid = #{sfBid}
     </select>
+    <select id="getAlreadyElementByBid" parameterType="string"
+            resultType="IotSfElementfactor">
+        SELECT sf.id, sf.sfBid, sf.devBid, sf.sfType, sf.sfCode, sf.sfName, sf.sfDisplayname, sf.sfParentBid, sf.sfSequence,
+        sf.tid, sf.sfCreatedDate, sf.sfCreator, sf.sfModifieddate, sf.sfModifier, sf.sfLng, sf.sfLat, sf.sfAddress
+        FROM IotSfElementfactor AS sf
+        where sf.sfBid = #{sfBid} or sf.sfParentBid = #{sfBid}
+    </select>
 
     <insert id="batchInsertIotSfElementfactor" parameterType="IotSfElementfactor">
-        INSERT INTO IotSfElementfactor (sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
-            tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier, sfLng, sfLat, sfAddress)
-        VALUES
-        <foreach collection="list" item="item" index="index" separator=",">
-            (#{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}, #{item.sfLng}, #{item.sfLat}, #{item.sfAddress})
+        <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>
     </insert>