فهرست منبع

新增 水肥机泵类要素接口

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

+ 25 - 3
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/controller/IotDeviceSfController.java

@@ -1,10 +1,13 @@
 package com.yunfeiyun.agmp.iotm.device.sf.controller;
 
+import cn.hutool.core.exceptions.ValidateException;
+import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
 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.IotSfElementfactorAddReqVo;
 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;
@@ -12,9 +15,8 @@ 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 org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
@@ -94,4 +96,24 @@ public class IotDeviceSfController extends BaseController {
         iotDeviceBaseFunReqVo.setParam(reqVo);
         return iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
     }
+
+    /**
+     * 新增泵类要素
+     * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     * @return 返回操作结果的表格数据信息
+     * @throws ValidateException 如果设备标识(devBid)无效,则抛出ValidateException异常
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @PostMapping("/pump/add")
+    public AjaxResult pumpAdd(@RequestBody IotSfElementfactorAddReqVo reqVo){
+        ValidateUtil.validateDevBid(reqVo.getDevBid());
+        IotDeviceBaseFunReqVo iotDeviceBaseFunReqVo = new IotDeviceBaseFunReqVo();
+        iotDeviceBaseFunReqVo.setDevBid(reqVo.getDevBid());
+        iotDeviceBaseFunReqVo.setMethodName("pumpAdd");
+        iotDeviceBaseFunReqVo.setParam(reqVo);
+        int status = iotDeviceCommonService.func(iotDeviceBaseFunReqVo);
+        return toAjax(status);
+    }
 }

+ 58 - 0
src/main/java/com/yunfeiyun/agmp/iotm/device/sf/domain/IotSfElementfactorAddReqVo.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 IotSfElementfactorAddReqVo 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<IotSfElementfactorAddReqVo> childrenList;
+
+}

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

@@ -2,23 +2,27 @@ 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.DateUtils;
+import com.yunfeiyun.agmp.common.utils.SecurityUtils;
 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.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.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.IIotSfElementfactorService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 /**
  * 水肥机通用服务
@@ -63,14 +67,8 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         if (findDevice == null) {
             throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "设备不存在");
         }
-        List<String> sfTypeList = new ArrayList<>();
-        sfTypeList.add(EnumSfElementType.WATER_SOURCE.getCode());
-        sfTypeList.add(EnumSfElementType.FERILIZER.getCode());
-        sfTypeList.add(EnumSfElementType.SUCTION.getCode());
-        sfTypeList.add(EnumSfElementType.MIXING.getCode());
-        reqVo.setSfTypeList(sfTypeList);
-
-        List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getAlreadyElementList(reqVo);
+
+        List<IotSfElementfactorAlreadyListResVo> resVoList = iotSfElementfactorService.getPumpAlreadyElementList(reqVo);
         if (resVoList != null && !resVoList.isEmpty()){
             rspData.setData(resVoList);
             rspData.setTotal(resVoList.size());
@@ -90,4 +88,89 @@ public class IIotSfCommService extends IotDeviceBaseServiceImpl implements IotDe
         // 由具体子类实现
         return null;
     }
+
+    private IotSfElementfactor makeIotSfElementfactor(IotSfElementfactorAddReqVo reqVo, String date){
+        String tid = SecurityUtils.getTid();
+        String userId = SecurityUtils.getUserId();
+
+        IotSfElementfactor elementfactor = new IotSfElementfactor();
+        String sfBid = elementfactor.getUUId();
+        BeanUtils.copyProperties(reqVo, elementfactor);
+        elementfactor.setSfBid(sfBid);
+        elementfactor.setTid(tid);
+        elementfactor.setSfCreatedDate(date);
+        elementfactor.setSfCreator(userId);
+        elementfactor.setSfModifieddate(date);
+        elementfactor.setSfModifier(userId);
+        return elementfactor;
+    }
+
+    /**
+     * 新增泵类要素
+     * 该接口用于添加新的泵类要素,接收相关参数并调用通用设备功能服务进行处理。
+     *
+     * @param reqVo 包含设备添加请求的参数,包括设备标识(devBid)等
+     */
+    public int pumpAdd(IotSfElementfactorAddReqVo 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(), "设备不存在");
+        }
+        String sfType = reqVo.getSfType();
+        String sfCode = reqVo.getSfCode();
+        // 肥料桶是虚拟的,不需要检测code重复问题
+        if(!Objects.equals(sfType, EnumSfElementType.FERTILIZER_BUCKET.getCode())){
+            if (StringUtils.isEmpty(sfCode)) {
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码不能为空");
+            }
+        }
+        String sfDisplayname = reqVo.getSfDisplayname();
+        if (StringUtils.isEmpty(sfType)) {
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素类型不能为空");
+        }
+
+        if (StringUtils.isEmpty(sfDisplayname)) {
+            throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素名称不能为空");
+        }
+
+        IotSfElementfactorListReqVo reqVo1 = new IotSfElementfactorListReqVo();
+        reqVo1.setDevBid(devBid);
+        List<IotSfElementfactor> elementList = iotSfElementfactorService.selectIotSfElementfactorListByPump(reqVo1);
+        Set<String> sfCodeSet = new HashSet<>();
+        for (IotSfElementfactor element : elementList) {
+            if(StringUtils.isNotEmpty(element.getSfCode())){
+                sfCodeSet.add(element.getSfCode());
+            }
+        }
+
+        String createDate = DateUtils.dateTimeNow();
+        List<IotSfElementfactor> sfElementfactorList = new ArrayList<>();
+
+        IotSfElementfactor elementfactor = makeIotSfElementfactor(reqVo, createDate);
+        sfElementfactorList.add(elementfactor);
+
+        List<IotSfElementfactorAddReqVo> childrenList = reqVo.getChildrenList();
+        if (childrenList!= null &&!childrenList.isEmpty()){
+            for (IotSfElementfactorAddReqVo child : childrenList) {
+                child.setDevBid(devBid);
+                IotSfElementfactor childElementfactor = makeIotSfElementfactor(child, createDate);
+                childElementfactor.setSfParentBid(elementfactor.getSfBid());
+                sfElementfactorList.add(childElementfactor);
+            }
+        }
+
+        for(IotSfElementfactor element : sfElementfactorList){
+            if(sfCodeSet.contains(element.getSfCode())){
+                throw new IotBizException(IotErrorCode.INVALID_DEVICE_ID.getCode(), "要素编码重复");
+            }
+        }
+
+        return iotSfElementfactorService.batchInsertIotSfElementfactor(sfElementfactorList);
+    }
+
 }

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

@@ -69,7 +69,7 @@ public class IotRunHaoSfServiceImpl extends IIotSfCommService {
 
         List<String> sfTypeList = new ArrayList<>();
         sfTypeList.add(EnumSfElementType.WATER_SOURCE.getCode());
-        sfTypeList.add(EnumSfElementType.FERILIZER.getCode());
+        sfTypeList.add(EnumSfElementType.FERTILIZER.getCode());
         sfTypeList.add(EnumSfElementType.SUCTION.getCode());
         sfTypeList.add(EnumSfElementType.MIXING.getCode());
         reqVo.setSfTypeList(sfTypeList);

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

@@ -19,4 +19,12 @@ public interface IotSfElementfactorMapper {
      */
     public List<IotSfElementfactor> selectIotSfElementfactorList(IotSfElementfactorListReqVo reqVo);
 
+    /**
+     * 批量插入水肥机要素
+     *
+     * @param factorList 水肥机要素列表
+     * @return 结果
+     */
+    public int batchInsertIotSfElementfactor(List<IotSfElementfactor> factorList);
+
 }

+ 33 - 1
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotSfElementfactorService.java

@@ -19,11 +19,43 @@ public interface IIotSfElementfactorService {
     public List<IotSfElementfactor> selectIotSfElementfactorList(IotSfElementfactorListReqVo reqVo);
 
     /**
+     * 查询泵类已配置原始要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public List<IotSfElementfactor> selectIotSfElementfactorListByPump(IotSfElementfactorListReqVo reqVo);
+
+    /**
+     * 批量插入水肥机要素
+     *
+     * @param factorList 水肥机要素列表
+     * @return 结果
+     */
+    public int batchInsertIotSfElementfactor(List<IotSfElementfactor> factorList);
+
+//    /**
+//     * 查询已配置要素列表
+//     * @param reqVo
+//     * @return
+//     */
+//
+//    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(IotSfElementfactorListReqVo reqVo);
+
+    /**
      * 查询已配置要素列表
      * @param reqVo
      * @return
      */
 
-    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(IotSfElementfactorListReqVo reqVo);
+    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList);
+
+    /**
+     * 查询泵类已配置要素列表
+     * @param reqVo
+     * @return
+     */
+
+    public List<IotSfElementfactorAlreadyListResVo> getPumpAlreadyElementList(IotSfElementfactorListReqVo reqVo);
 }
 

+ 74 - 5
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotSfElementfactorServiceImpl.java

@@ -2,6 +2,7 @@ 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.iot.common.enums.EnumSfElementType;
 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;
@@ -34,17 +35,55 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
         return iotSfElementfactorMapper.selectIotSfElementfactorList(reqVo);
     }
 
+
+    /**
+     * 批量插入水肥机要素
+     *
+     * @param factorList 水肥机要素列表
+     * @return 结果
+     */
+    @Override
+    public int batchInsertIotSfElementfactor(List<IotSfElementfactor> factorList) {
+        return iotSfElementfactorMapper.batchInsertIotSfElementfactor(factorList);
+    }
+
+//    /**
+//     * 查询已配置要素列表
+//     *
+//     * @param reqVo
+//     * @return
+//     */
+//    @Override
+//    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+//        List<IotSfElementfactor> elementfactorList = 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());
+//    }
+
     /**
      * 查询已配置要素列表
      *
-     * @param reqVo
-     * @return
+     * @param factorList@return
      */
     @Override
-    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
-        List<IotSfElementfactor> elementfactorList = iotSfElementfactorMapper.selectIotSfElementfactorList(reqVo);
+    public List<IotSfElementfactorAlreadyListResVo> getAlreadyElementList(List<IotSfElementfactor> factorList) {
         Map<String, IotSfElementfactorAlreadyListResVo> eleMap = new LinkedHashMap<>();
-        for (IotSfElementfactor elementfactor : elementfactorList) {
+        for (IotSfElementfactor elementfactor : factorList) {
             String sfBid = elementfactor.getSfBid();
             String sfParentBid = elementfactor.getSfParentBid();
 
@@ -61,4 +100,34 @@ public class IotSfElementfactorServiceImpl implements IIotSfElementfactorService
         }
         return new ArrayList<>(eleMap.values());
     }
+
+    /**
+     * 查询泵类已配置原始要素列表
+     *
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotSfElementfactor> selectIotSfElementfactorListByPump(IotSfElementfactorListReqVo reqVo) {
+        List<String> sfTypeList = new ArrayList<>();
+        sfTypeList.add(EnumSfElementType.WATER_SOURCE.getCode());
+        sfTypeList.add(EnumSfElementType.FERTILIZER.getCode());
+        sfTypeList.add(EnumSfElementType.SUCTION.getCode());
+        sfTypeList.add(EnumSfElementType.MIXING.getCode());
+        sfTypeList.add(EnumSfElementType.FERTILIZER_BUCKET.getCode());
+        reqVo.setSfTypeList(sfTypeList);
+        return selectIotSfElementfactorList(reqVo);
+    }
+
+    /**
+     * 查询泵类已配置要素列表
+     *
+     * @param reqVo
+     * @return
+     */
+    @Override
+    public List<IotSfElementfactorAlreadyListResVo> getPumpAlreadyElementList(IotSfElementfactorListReqVo reqVo) {
+        List<IotSfElementfactor> elementfactorList = selectIotSfElementfactorListByPump(reqVo);
+        return getAlreadyElementList(elementfactorList);
+    }
 }

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

@@ -32,4 +32,14 @@
         </where>
     </select>
 
+    <insert id="batchInsertIotSfElementfactor">
+        INSERT INTO IotSfElementfactor (id, sfBid, devBid, sfType, sfCode, sfName, sfDisplayname, sfParentBid, sfSequence,
+            tid, sfCreatedDate, sfCreator, sfModifieddate, sfModifier)
+        VALUES
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.id}, #{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})
+        </foreach>
+    </insert>
+
 </mapper>