Explorar o código

新增 润浩水肥机对接

zhaiyifei hai 8 meses
pai
achega
ddac414644

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

@@ -0,0 +1,97 @@
+package com.yunfeiyun.agmp.iotm.device.sf.controller;
+
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
+import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
+import com.yunfeiyun.agmp.iotm.common.controller.BaseController;
+import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseFunReqVo;
+import com.yunfeiyun.agmp.iotm.device.common.service.IotDeviceCommonService;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
+import com.yunfeiyun.agmp.iotm.util.ValidateUtil;
+import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
+import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 水肥机设备
+ */
+
+@RestController
+@RequestMapping("/iot/device/sf")
+@Slf4j
+public class IotDeviceSfController extends BaseController {
+    @Autowired
+    private IIotDeviceService iIotDeviceService;
+
+    @Autowired
+    private IotDeviceCommonService iotDeviceCommonService;
+
+    /**
+     * 水肥设备列表
+     * /list  所有设备
+     * /rh/list 润浩设备
+     * @param reqVo
+     * @return
+     */
+    @GetMapping({"/list", "/rh/list"})
+    public TableDataInfo list(HttpServletRequest request, IotDeviceListReqVo reqVo) {
+        startPage();
+        String reqUri = request.getRequestURI();
+        String[] devTypeList = null;
+
+        if(reqUri.endsWith("/rh/list")){
+            devTypeList = new String[]{IotDeviceDictConst.TYPE_RUNHAO_SF};
+        }
+
+        List<IotDeviceListResVo> list = null;
+        if (devTypeList != null) {
+            reqVo.setDevtypeBidList(Arrays.asList(devTypeList));
+            list = iIotDeviceService.selectIotDeviceListByType(reqVo);
+        }
+        return getDataTable(list);
+    }
+
+    /**
+     * 获取已存在的元素列表
+     * 该接口用于根据请求参数获取已存在的元素列表,并返回相关数据。
+     *
+     * @param reqVo 请求参数,包含设备标识devBid等信息
+     * @return 返回TableDataInfo对象,包含元素列表数据
+     * @throws IllegalArgumentException 如果reqVo中的devBid为空,则抛出异常
+     */
+    @GetMapping("/ele/already/List")
+    public TableDataInfo getAlreadyElementList(IotSfElementfactorListReqVo reqVo){
+        ValidateUtil.validateDevBid(reqVo.getDevBid());
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("getAlreadyElementList");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+    }
+
+    /**
+     * 获取未处理的元素列表
+     * 该接口用于根据请求参数获取未处理的元素列表,并返回相关数据。
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等信息
+     * @return TableDataInfo 包含未处理的元素列表的数据封装对象
+     * @throws IllegalArgumentException 如果devBid为空,则抛出非法参数异常
+     */
+    @GetMapping("/ele/unalready/List")
+    public TableDataInfo getUnAlreadyElementList(IotSfElementfactorListReqVo reqVo){
+        ValidateUtil.validateDevBid(reqVo.getDevBid());
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("getUnAlreadyElementList");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+    }
+}

+ 58 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorAlreadyListResVo.java

@@ -0,0 +1,58 @@
+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 IotSfElementfactorAlreadyListResVo 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 List<IotSfElementfactorAlreadyListResVo> childrenList;
+
+}

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

@@ -0,0 +1,53 @@
+package com.yunfeiyun.agmp.iotm.device.sf.domain;
+
+import lombok.Data;
+
+/**
+ * 水肥机要素
+ */
+@Data
+public class IotSfElementfactorListReqVo {
+    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;
+
+}

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

@@ -0,0 +1,86 @@
+package com.yunfeiyun.agmp.iotm.device.sf.service;
+
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
+import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
+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.IotRunHaoSfdata;
+import com.yunfeiyun.agmp.iot.common.exception.IotBizException;
+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.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.IIotSfElementfactorService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 水肥机通用服务
+ */
+public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDeviceBaseService {
+
+    @Autowired
+    private IIotDeviceService iotDeviceService;
+
+    @Autowired
+    private IIotSfElementfactorService iotSfElementfactorService;
+
+
+    public Class getTableClass(String devtypeBid) {
+        Class tableClass = null;
+        if (devtypeBid.equals(IotDeviceDictConst.TYPE_RUNHAO_SF)) {
+            tableClass = IotRunHaoSfdata.class;
+        }
+        return tableClass;
+    }
+
+    /**
+     * 获取已存在的元素列表
+     *
+     * @param reqVo 请求对象,包含设备标识等信息
+     * @return TableDataInfo 包含响应码、消息、数据和总数
+     * @throws IotBizException 抛出业务异常,包含错误码和错误信息
+     */
+    public TableDataInfo getAlreadyElementList(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.getAlreadyElementList(reqVo);
+        if (resVoList != null && resVoList.size() > 0){
+            rspData.setData(resVoList);
+            rspData.setTotal(resVoList.size());
+        }
+        return rspData;
+    }
+
+    /**
+     * 获取未处理的元素列表
+     * 该接口用于根据请求参数获取未处理的元素列表,并返回相关数据。
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等信息
+     * @return TableDataInfo 包含未处理的元素列表的数据封装对象
+     * @throws IllegalArgumentException 如果devBid为空,则抛出非法参数异常
+     */
+    public TableDataInfo getUnAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        // 由具体子类实现
+        return null;
+    }
+}

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

@@ -0,0 +1,97 @@
+package com.yunfeiyun.agmp.iotm.device.sf.service.impl;
+
+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.StringUtils;
+import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
+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.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.IotSfElementfactorListReqVo;
+import com.yunfeiyun.agmp.iotm.device.sf.service.IIotSfCommService;
+import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * 润浩水肥机
+ */
+
+@Slf4j
+@Service(value = ServiceNameConst.SERVICE_RUNHAO_SF)
+public class IotRunHaoSfServiceImpl extends IIotSfCommService {
+    @Autowired
+    private IIotDeviceService iotDeviceService;
+
+    @Autowired
+    private IIotSfElementfactorService iotSfElementfactorService;
+
+    @Autowired
+    private MongoService mongoService;
+
+    /**
+     * 获取未处理的元素列表
+     * 该接口用于根据请求参数获取未处理的元素列表,并返回相关数据。
+     *
+     * @param reqVo 请求参数,包含设备标识(devBid)等信息
+     * @return TableDataInfo 包含未处理的元素列表的数据封装对象
+     * @throws IllegalArgumentException 如果devBid为空,则抛出非法参数异常
+     */
+    public TableDataInfo getUnAlreadyElementList(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<IotSfElementfactor> elementfactorList = iotSfElementfactorService.selectIotSfElementfactorList(reqVo);
+        Set<String> sfCodeSet = new java.util.HashSet<>();
+        for (IotSfElementfactor elementfactor : elementfactorList) {
+            sfCodeSet.add(elementfactor.getSfCode());
+        }
+
+        HashMap<String, String> params = new HashMap<>();
+        params.put("devBid", devBid);
+
+        IotRunHaoSfdata iotRunHaoSfdata = (IotRunHaoSfdata) mongoService.findOne(IotRunHaoSfdata.class, params, "sfdataCreatedDate", "desc");
+        List<IotSfElementfactor> resultList = new ArrayList<>();
+        if (iotRunHaoSfdata != null) {
+            JSONObject dataJson = iotRunHaoSfdata.getSfdataContent();
+            for (String key : dataJson.keySet()) {
+                if(sfCodeSet.contains(key)){
+                    continue;
+                }
+                IotSfElementfactor elementFactor = RunHaoSfElementUtil.getSfElementfactor(key);
+                if(elementFactor == null){
+                    continue;
+                }
+                resultList.add(elementFactor);
+            }
+        }
+        rspData.setData(resultList);
+        rspData.setTotal(resultList.size());
+        return rspData;
+    }
+}

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

@@ -0,0 +1,22 @@
+package com.yunfeiyun.agmp.iotm.web.mapper;
+
+import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
+
+import java.util.List;
+
+/**
+ * Mapper接口
+ *
+ */
+public interface IotSfElementfactorMapper {
+
+    /**
+     * 查询水肥机要素列表
+     *
+     * @param iotSfElementfactor 水肥机要素
+     * @return 水肥机要素集合
+     */
+    public List<IotSfElementfactor> selectIotSfElementfactorList(IotSfElementfactorListReqVo reqVo);
+
+}

+ 29 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotSfElementfactorService.java

@@ -0,0 +1,29 @@
+package com.yunfeiyun.agmp.iotm.web.service;
+
+import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
+
+import java.util.List;
+
+/**
+ * 水肥机要素Service
+ */
+public interface IIotSfElementfactorService {
+    /**
+     * 查询水肥机要素列表
+     *
+     * @param iotSfElementfactor 水肥机要素
+     * @return 水肥机要素集合
+     */
+    public List<IotSfElementfactor> selectIotSfElementfactorList(IotSfElementfactorListReqVo reqVo);
+
+    /**
+     * 查询已配置要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(IotSfElementfactorListReqVo reqVo);
+}
+

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

@@ -0,0 +1,61 @@
+package com.yunfeiyun.agmp.iotm.web.service.impl;
+
+import com.yunfeiyun.agmp.common.utils.SecurityUtils;
+import com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorAlreadyListResVo;
+import com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo;
+import com.yunfeiyun.agmp.iotm.web.mapper.IotSfElementfactorMapper;
+import com.yunfeiyun.agmp.iotm.web.service.IIotSfElementfactorService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService {
+    private IotSfElementfactorMapper iotSfElementfactorMapper;
+    /**
+     * 查询水肥机要素列表
+     *
+     * @param  水肥机要素
+     * @return 水肥机要素集合
+     */
+    @Override
+    public List<IotSfElementfactor> selectIotSfElementfactorList(IotSfElementfactorListReqVo reqVo) {
+        reqVo.setTid(SecurityUtils.getTid());
+        return iotSfElementfactorMapper.selectIotSfElementfactorList(reqVo);
+    }
+
+    /**
+     * 查询已配置要素列表
+     *
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        List<IotSfElementfactor> elementfactorList = iotSfElementfactorMapper.selectIotSfElementfactorList(reqVo);
+        Map<String, IotSfElementfactorAlreadyListResVo> eleMap = new LinkedHashMap<>();
+        for (IotSfElementfactor elementfactor : elementfactorList) {
+            String sfBid = elementfactor.getSfBid();
+            String sfParentBid = elementfactor.getSfParentBid();
+
+            IotSfElementfactorAlreadyListResVo eleResVo = new IotSfElementfactorAlreadyListResVo();
+            BeanUtils.copyProperties(elementfactor, eleResVo);
+
+            IotSfElementfactorAlreadyListResVo parentInfo = eleMap.get(sfParentBid);
+            if(parentInfo == null){
+                eleResVo.setChildrenList(new ArrayList<>());
+                eleMap.put(sfBid, eleResVo);
+            }else{
+                parentInfo.getChildrenList().add(eleResVo);
+            }
+        }
+        return new ArrayList<>(eleMap.values());
+    }
+}

+ 35 - 0
src/main/resources/mapper/IotSfElementfactorMapper.xml

@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.yunfeiyun.agmp.iotm.web.mapper.IotSfElementfactorMapper">
+
+    <select id="selectIotSfElementfactorList" parameterType="com.yunfeiyun.agmp.iotm.device.sf.domain.IotSfElementfactorListReqVo"
+            resultType="com.yunfeiyun.agmp.iot.common.domain.IotSfElementfactor" >
+        SELECT sf.id, sf.sfBid, sf.sfType, sf.sfCode, sf.sfName, sf.sfDisplayname, sf.sfParentBid, sf.sfSequence,
+            sf.tid, sf.sfCreatedDate, sf.sfCreator, sf.sfModifieddate, sf.sfModifier
+        FROM IotSfElementfactor AS sf
+        <where>
+            tid = #{tid}
+            <if test="sfBid!= null and sfBid!= ''"> and sf.sfBid = #{sfBid}</if>
+            <if test="sfType!= null and sfType!= ''"> and sf.sfType = #{sfType}</if>
+            <if test="sfCode!= null and sfCode!= ''"> and sf.sfCode = #{sfCode}</if>
+            <if test="sfName!= null and sfName!= ''"> and sf.sfName like concat('%', #{sfName}, '%')</if>
+            <if test="sfDisplayname!= null and sfDisplayname!= ''"> and sf.sfDisplayname like concat('%', #{sfDisplayname}, '%')</if>
+            <if test="sfParentBid!= null and sfParentBid!= ''"> and sf.sfParentBid = #{sfParentBid}</if>
+            <if test="sfSequence!= null and sfSequence!= ''"> and sf.sfSequence = #{sfSequence}</if>
+            <if test="tid!= null and tid!= ''"> and sf.tid = #{tid}</if>
+            <if test="sfCreatedDate!= null and sfCreatedDate!= ''"> and sf.sfCreatedDate = #{sfCreatedDate}</if>
+            <if test="sfCreator!= null and sfCreator!= ''"> and sf.sfCreator = #{sfCreator}</if>
+            <if test="sfModifieddate!= null and sfModifieddate!= ''"> and sf.sfModifieddate = #{sfModifieddate}</if>
+            <if test="sfModifier!= null and sfModifier!= ''"> and sf.sfModifier = #{sfModifier}</if>
+            <if test="sfTypeList != null and sfTypeList.size() > 0">
+                and sf.sfType in
+                <foreach collection="sfTypeList" item="item" index="index" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+    </select>
+
+</mapper>