فهرست منبع

新增 获取润浩水肥机运行状态信息

zhaiyifei 8 ماه پیش
والد
کامیت
475dcb799a

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

@@ -1,6 +1,7 @@
 package com.yunfeiyun.agmp.iotm.device.sf.controller;
 
 import cn.hutool.core.exceptions.ValidateException;
+import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.utils.StringUtils;
@@ -9,6 +10,7 @@ import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
 import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
 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.sf.domain.IotSfElementfactorAddReqVo;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
@@ -211,4 +213,52 @@ public class IotDeviceSfController extends BaseController {
         return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
     }
 
+    /**
+     * 设备详情信息
+     * @param
+     * @return
+     */
+    @GetMapping("/info/{devBid}")
+    public AjaxResult info(@PathVariable("devBid") String devBid) {
+        ValidateUtil.validateDevBid(devBid);
+
+        IotDeviceListReqVo reqVo = new IotDeviceListReqVo();
+        reqVo.setDevBid(devBid);
+        List<IotDeviceListResVo> resVoList = iIotDeviceService.selectIotDeviceListByType(reqVo);
+        if(resVoList == null || resVoList.isEmpty()){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(), "设备不存在");
+        }
+        IotDeviceListResVo resVo = resVoList.get(0);
+        return AjaxResult.success(resVo);
+    }
+
+    @GetMapping("/config/info/{devBid}")
+    public AjaxResult configInfo(@PathVariable("devBid") String devBid){
+        IotDeviceDataListReqVo reqVo = new IotDeviceDataListReqVo();
+        reqVo.setDevBid(devBid);
+
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("configInfo");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        JSONObject jsonObject = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        return AjaxResult.success(jsonObject);
+    }
+
+    /**
+     * 获取水肥机状态信息
+     * @param
+     * @return
+     */
+    @GetMapping("/rh/run/status/{devBid}")
+    public AjaxResult getRunStatus(@PathVariable String devBid){
+        ValidateUtil.validateDevBid(devBid);
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(devBid);
+        iotDeviceBaseFunReqVo.setMethodName("getRunStatus");
+        iotDeviceBaseFunReqVo.setParam(devBid);
+        JSONObject jsonObject = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        return AjaxResult.success(jsonObject);
+    }
+
 }

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

@@ -1,6 +1,7 @@
 package com.yunfeiyun.agmp.iotm.device.sf.service;
 
 import cn.hutool.core.exceptions.ValidateException;
+import com.alibaba.fastjson2.JSONObject;
 import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
@@ -9,20 +10,24 @@ import com.yunfeiyun.agmp.common.utils.StringUtils;
 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.domain.IotDeviceconfig;
 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.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.IotSfElementfactorAddReqVo;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
 import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
 import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconfigService;
 import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import javax.annotation.Resource;
 import java.util.*;
 
 /**
@@ -36,6 +41,9 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
     @Autowired
     private IIotSfElementfactorService iotSfElementfactorService;
 
+    @Resource
+    private IIotDeviceconfigService iIotDeviceconfigService;
+
 
     public Class getTableClass(String devtypeBid) {
         Class tableClass = null;
@@ -284,4 +292,36 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         return null;
     }
 
+    /**
+     * 根据设备请求获取配置信息
+     *
+     * @param reqVo 设备数据列表请求对象
+     * @return 配置信息对象
+     * @throws IotBizException 如果设备ID为空或设备不存在,则抛出异常
+     */
+    public JSONObject configInfo(IotDeviceDataListReqVo reqVo){
+        String devBid = reqVo.getDevBid();
+        if(StringUtils.isEmpty(devBid)){
+            throw new IotBizException(IotErrorCode.PARAM_INVALID.getCode(),"参数不能为空");
+        }
+        IotDevice iotDevice = iotDeviceService.selectIotDeviceByDevBid(devBid);
+        if(iotDevice == null){
+            throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(),"设备不存在");
+        }
+        IotDeviceconfig iotDeviceconfig = iIotDeviceconfigService.selectIotDeviceConfigByDevBid(devBid);
+        return JSONObject.parseObject(iotDeviceconfig.getDevcfgContext());
+    }
+
+    /**
+     * 获取水肥机运行状态信息
+     *
+     * @param devBid 请求对象,包含设备标识等信息
+     * @return TableDataInfo 包含响应码、消息、数据和总数
+     * @throws IotBizException 抛出业务异常,包含错误码和错误信息
+     */
+    public JSONObject getRunStatus(String devBid) {
+        // 由具体子类实现
+        return null;
+    }
+
 }

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

@@ -366,4 +366,55 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
         rspData.setTotal(resultList.size());
         return rspData;
     }
+
+    /**
+     * 获取水肥机运行状态信息
+     *
+     * @param devBid 请求对象,包含设备标识等信息
+     * @return TableDataInfo 包含响应码、消息、数据和总数
+     * @throws IotBizException 抛出业务异常,包含错误码和错误信息
+     */
+    @Override
+    public JSONObject getRunStatus(String devBid) {
+        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");
+        JSONObject dataJson = new JSONObject();
+        if (iotRunHaoSfdata != null) {
+            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();
+        for (String key : keys) {
+            String value = "0";
+            try {
+                value = dataJson.getString(key);
+                if("true".equals(value)){
+                    value = "1";
+                }else if("false".equals(value)){
+                    value = "0";
+                }
+                value = String.valueOf((int)Math.floor(Double.parseDouble(value)));
+            } catch (Exception e) {
+                continue;
+            }
+            runStatus.put(key, value);
+        }
+        for (String key : feiKeys) {
+            if(dataJson.containsKey(key)){
+                try{
+                    String value = String.valueOf((int)Math.floor(Double.parseDouble(dataJson.getString(key))));
+                    runStatus.put(key, value);
+                }catch (Exception e){}
+            }
+        }
+        return runStatus;
+    }
 }