소스 검색

新增 水肥机操作记录功能

zhaiyifei 8 달 전
부모
커밋
0a4233cb42

+ 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(), "设备离线无法操作");
+                }
             }
         }
 

+ 11 - 0
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  所有设备
@@ -459,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);
+    }
+
 }

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

@@ -386,13 +386,13 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         List<IotSfElementfactor> updateList = new ArrayList<>();
         for (IotSfElementfactorEditReqVo req : reqList) {
             if (StringUtils.isEmpty(req.getSfDisplayname())) {
-                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素名称不能为空");
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "名称不能为空");
             }
             if (StringUtils.isEmpty(req.getSfBid())) {
-                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素标识不能为空");
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "标识不能为空");
             }
             if(!factorMap.containsKey(req.getSfBid())){
-                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "要素不存在");
+                throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "配置不存在");
             }
 
             IotSfElementfactor iotSfElementfactor = new IotSfElementfactor();

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

@@ -439,16 +439,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 +485,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);
@@ -527,126 +527,6 @@ 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)) {
@@ -659,7 +539,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();
@@ -687,7 +567,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
             String sfParentBid = element.getSfParentBid();
 
             if(sfCodeSet.contains(sfCode)){
-                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素已存在,请勿重复添加");
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "已存在,请勿重复添加");
             }
             if (StringUtils.isEmpty(sfType)) {
                 throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "类型不能为空");
@@ -896,7 +776,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<>();
@@ -999,22 +879,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);
@@ -1207,7 +1071,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{
@@ -1218,11 +1089,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));