Explorar o código

新增 水肥机操作记录功能

zhaiyifei hai 8 meses
pai
achega
5e59c2a93b

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

@@ -351,10 +351,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 +374,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 +392,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 +411,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());

+ 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;
+
 }

+ 56 - 41
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/service/IIotSfCommService.java

@@ -13,6 +13,7 @@ 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;
@@ -20,14 +21,16 @@ 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;
 
 /**
  * 水肥机通用服务
@@ -347,36 +350,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 +463,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 +472,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 +484,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 +494,9 @@ 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);
     }
 
 }

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

@@ -527,6 +527,126 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
      *
      * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
      */
+//    public int elementBatchAdd(IotSfElementfactorBatchAddReqVo reqVo) {
+//        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<IotSfElementfactorAddReqVo> elementList = reqVo.getElementList();
+//        if(elementList == null || elementList.isEmpty()){
+//            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "元素列表不能为空");
+//        }
+//
+//        IotSfElementfactorListReqVo reqVo1 = new IotSfElementfactorListReqVo();
+//        reqVo1.setDevBid(devBid);
+//        List<IotSfElementfactor> dataList = iotSfElementfactorService.selectIotSfElementfactorList(reqVo1);
+//        Set<String> sfCodeSet = new HashSet<>();
+//        Map<String, IotSfElementfactor> elementMap = new HashMap<>();
+//        for (IotSfElementfactor element : dataList) {
+//            if(StringUtils.isNotEmpty(element.getSfCode())){
+//                sfCodeSet.add(element.getSfCode());
+//                elementMap.put(element.getSfBid(), element);
+//            }
+//        }
+//
+//        String createDate = DateUtils.dateTimeNow();
+//        List<IotSfElementfactor> sfElementfactorList = new ArrayList<>();
+//        Set<String> sfCodeAlreadySet = new HashSet<>();
+//        List<IotSfElementfactorAddReqVo> valveList = new ArrayList<>();
+//        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();
+//            String sfCode = element.getSfCode();
+//            String sfDisplayname = element.getSfDisplayname();
+//            String sfParentBid = element.getSfParentBid();
+//            if(sfCodeSet.contains(sfCode) || sfCodeAlreadySet.contains(sfCode)){
+//                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
+//            }
+//            if (StringUtils.isEmpty(sfType)) {
+//                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
+//            }
+//            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())){
+//                if(StringUtils.isEmpty(sfParentBid)){
+//                    throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "灌区标识不能为空");
+//                }
+//                parentElement = elementMap.get(sfParentBid);
+//                if(parentElement == null || !Objects.equals(parentElement.getSfType(), EnumSfElementType.GROUP.getCode())){
+//                    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);
+//                    }
+//                }
+//            }
+//
+//            sfElementfactorList.add(elementfactor);
+//
+//            sfCodeAlreadySet.add(sfCode);
+//        }
+//
+//        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){
+//            IotSfElementfactorAddReqVo groupReqVo = new IotSfElementfactorAddReqVo();
+//            BeanUtils.copyProperties(parentElement, groupReqVo);
+//
+//            groupReqVo.setChildrenList(valveList);
+//
+//            sendGroupConfig(groupReqVo, findDevice);
+//        }
+//
+//        return status;
+//    }
+
     public int elementBatchAdd(IotSfElementfactorBatchAddReqVo reqVo) {
         String devBid = reqVo.getDevBid();
         if (StringUtils.isEmpty(devBid)) {
@@ -555,26 +675,19 @@ 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)){
-                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
+
+            if(sfCodeSet.contains(sfCode)){
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素已存在,请勿重复添加");
             }
             if (StringUtils.isEmpty(sfType)) {
                 throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
@@ -582,9 +695,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 +702,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 +794,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 +838,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
             sendConfigCmd(configCmdReqVo);
         }
-
-        return status;
+        return iotSfElementfactorService.deleteIotSfElementfactorBySfBid(sfBid);
     }
 
     @Override

+ 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);
+
 }

+ 16 - 0
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
@@ -116,5 +124,13 @@ public interface IIotSfElementfactorService {
      */
 
     public List<IotSfElementfactorAlreadyListResVo> getValveAlreadyElementList(IotSfElementfactorListReqVo reqVo);
+
+    /**
+     * 查询已配置要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public IotSfElementfactorAlreadyListResVo getAlreadyElementByBid(String sfBid);
 }
 

+ 25 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotSfElementfactorServiceImpl.java

@@ -71,6 +71,16 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
     }
 
     /**
+     * 更新水肥机要素
+     *
+     * @param elementfactorList@return 结果
+     */
+    @Override
+    public int batchUpdateIotSfElementfactor(List<IotSfElementfactor> elementfactorList) {
+        return iotSfElementfactorMapper.batchUpdateIotSfElementfactor(elementfactorList);
+    }
+
+    /**
      * 删除水肥机要素
      *
      * @param sfBid 水肥机要素ID
@@ -246,4 +256,19 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
         List<IotSfElementfactor> elementfactorList = selectIotSfElementfactorListByValve(reqVo);
         return getAlreadyElementList(elementfactorList);
     }
+
+    /**
+     * 查询已配置要素列表
+     *
+     * @param sfBid@return
+     */
+    @Override
+    public IotSfElementfactorAlreadyListResVo getAlreadyElementByBid(String sfBid) {
+        List<IotSfElementfactor> elementfactorList = iotSfElementfactorMapper.getAlreadyElementByBid(sfBid);
+        List<IotSfElementfactorAlreadyListResVo> alreadyElementList = getAlreadyElementList(elementfactorList);
+        if(alreadyElementList != null && !alreadyElementList.isEmpty()){
+            return alreadyElementList.get(0);
+        }
+        return null;
+    }
 }

+ 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>