Quellcode durchsuchen

新增 获取水肥机状态信息接口

zhaiyifei vor 8 Monaten
Ursprung
Commit
d9a0d65016

+ 15 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/controller/IotDeviceSfController.java

@@ -196,4 +196,19 @@ public class IotDeviceSfController extends BaseController {
         return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
     }
 
+    /**
+     * 获取水肥机状态信息
+     * @param
+     * @return
+     */
+    @GetMapping("/status/{devBid}")
+    public TableDataInfo getStatus(@PathVariable String devBid){
+        ValidateUtil.validateDevBid(devBid);
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(devBid);
+        iotDeviceBaseFunReqVo.setMethodName("getStatus");
+        iotDeviceBaseFunReqVo.setParam(devBid);
+        return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+    }
+
 }

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

@@ -0,0 +1,61 @@
+package com.yunfeiyun.agmp.iotm.device.sf.domain;
+
+import com.yunfeiyun.agmp.iot.common.domain.IotBaseEntity;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 水肥机要素
+ */
+@Data
+public class IotSfElementfactorInfoVo extends IotBaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /** 自增主键 */
+    private Long id;
+
+    /** 业务标识 */
+    private String sfBid;
+
+    /** 设备编号 */
+    private String devBid;
+
+    /** 水肥要素类型 */
+    private String sfType;
+
+    /** 原始名称 */
+    private String sfName;
+
+    /** 显示名称 */
+    private String sfDisplayname;
+
+    /** 要素编码 */
+    private String sfCode;
+
+    /** 父类id */
+    private String sfParentBid;
+
+    /** 排序字段 默认0 */
+    private int sfSequence;
+
+    /** 租户ID */
+    private String tid;
+
+    /** 创建时间 */
+    private String sfCreatedDate;
+
+    /** 创建人 */
+    private String sfCreator;
+
+    /** 修改时间 */
+    private String sfModifieddate;
+    /** 修改人 */
+    private String sfModifier;
+
+    /** 值 */
+    private String value;
+
+    private List<IotSfElementfactorInfoVo> childrenList;
+
+}

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

@@ -271,4 +271,17 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         return rspData;
     }
 
+
+    /**
+     * 获取水肥机状态信息
+     *
+     * @param reqVo 请求对象,包含设备标识等信息
+     * @return TableDataInfo 包含响应码、消息、数据和总数
+     * @throws IotBizException 抛出业务异常,包含错误码和错误信息
+     */
+    public TableDataInfo getStatus(String devBid) {
+        // 由具体子类实现
+        return null;
+    }
+
 }

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

@@ -10,10 +10,12 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.ServiceNameConst;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotRunHaoSfdata;
 import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
+import com.yunfeiyun.agmp.iot.common.enums.EnumSfElementType;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 import com.yunfeiyun.agmp.iot.common.service.MongoService;
 import com.yunfeiyun.agmp.iot.common.util.dev.RunHaoSfElementUtil;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorInfoVo;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
 import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
@@ -41,6 +43,16 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
     @Autowired
     private MongoService mongoService;
 
+    private String getDataValue(JSONObject dataJson, String key){
+        String v = dataJson.getString(key);
+        if("true".equals(v)){
+            v = "1";
+        }else if("false".equals(v)){
+            v = "0";
+        }
+        return v;
+    }
+
     /**
      * 获取泵类未处理的元素列表
      * 该接口用于根据请求参数获取未处理的元素列表,并返回相关数据。
@@ -258,4 +270,89 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         rspData.setTotal(resultList.size());
         return rspData;
     }
+
+    /**
+     * 获取水肥机状态信息
+     *
+     * @param reqVo 请求对象,包含设备标识等信息
+     * @return TableDataInfo 包含响应码、消息、数据和总数
+     * @throws IotBizException 抛出业务异常,包含错误码和错误信息
+     */
+
+    @Override
+    public TableDataInfo getStatus(String devBid) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(ErrorCode.SUCCESS.getCode());
+        rspData.setMsg(ErrorCode.SUCCESS.getMessage());
+        rspData.setData(new ArrayList<>());
+        rspData.setTotal(0);
+
+        IotDevice findDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+        if (findDevice == null) {
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
+        }
+
+        HashMap<String, String> params = new HashMap<>();
+        params.put("devBid", devBid);
+
+        IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
+        if (iotRunHaoSfdata == null) {
+            return rspData;
+        }
+        IotSfElementfactorListReqVo reqVo = new IotSfElementfactorListReqVo();
+        reqVo.setDevBid(devBid);
+        List<IotSfElementfactor> resVoList = iotSfElementfactorService.selectIotSfElementfactorList(reqVo);
+
+        if (resVoList == null || resVoList.isEmpty()){
+            return rspData;
+        }
+        JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
+        Map<String, IotSfElementfactorInfoVo> eleMap = new LinkedHashMap<>();
+        for (IotSfElementfactor elementfactor : resVoList) {
+            String sfBid = elementfactor.getSfBid();
+            String sfParentBid = elementfactor.getSfParentBid();
+            String sfCode = elementfactor.getSfCode();
+            String value = getDataValue(dataJson, sfCode);
+
+            IotSfElementfactorInfoVo infoVo = new IotSfElementfactorInfoVo();
+            BeanUtils.copyProperties(elementfactor, infoVo);
+            infoVo.setValue(value);
+
+            IotSfElementfactorInfoVo parentInfo = eleMap.get(sfParentBid);
+            if(parentInfo == null){
+                infoVo.setChildrenList(new ArrayList<>());
+                eleMap.put(sfBid, infoVo);
+            }else{
+                parentInfo.getChildrenList().add(infoVo);
+                if(Objects.equals(infoVo.getSfType(), EnumSfElementType.SUCTION.getCode())){
+                    List<IotSfElementfactor> lsliList = RunHaoSfElementUtil.getLsLlFactor(sfCode);
+                    for(IotSfElementfactor lsli : lsliList){
+                        IotSfElementfactorInfoVo lsliVo = new IotSfElementfactorInfoVo();
+                        BeanUtils.copyProperties(lsli, lsliVo);
+                        String lv = getDataValue(dataJson, lsli.getSfCode());
+                        lsliVo.setValue(lv);
+                        parentInfo.getChildrenList().add(lsliVo);
+                    }
+                }
+
+            }
+        }
+
+        List<IotSfElementfactorInfoVo> resultList = new ArrayList<>(eleMap.values());
+        for(String key : dataJson.keySet()){
+            IotSfElementfactor elementFactor = RunHaoSfElementUtil.getSensorElementFactor(key);
+            if(elementFactor == null){
+                continue;
+            }
+            String value = dataJson.getString(key);
+            IotSfElementfactorInfoVo infoVo = new IotSfElementfactorInfoVo();
+            BeanUtils.copyProperties(elementFactor, infoVo);
+            infoVo.setValue(value);
+            resultList.add(infoVo);
+        }
+
+        rspData.setData(resultList);
+        rspData.setTotal(resultList.size());
+        return rspData;
+    }
 }