Sfoglia il codice sorgente

修复 同一个设备ID不允许绑定多个租户的问题

zhaiyifei 1 anno fa
parent
commit
0b0c9ec25b

+ 8 - 3
src/main/java/com/yunfeiyun/agmp/iotm/web/service/IIotDeviceService.java

@@ -3,15 +3,12 @@ package com.yunfeiyun.agmp.iotm.web.service;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.common.core.page.TableDataInfo;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
 import com.yunfeiyun.agmp.iot.common.domain.IotDeviceconn;
-import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseCtlReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceAddReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceAddReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceEditReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceEditReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceListReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceModifyReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.reqvo.IotDeviceModifyReqVo;
 import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
 import com.yunfeiyun.agmp.iotm.web.domain.resvo.IotDeviceListResVo;
 
 
-import com.yunfeiyun.agmp.iotm.device.common.domin.IotDeviceBaseListReqVo;
-
 import java.util.List;
 import java.util.List;
 
 
 /**
 /**
@@ -73,4 +70,12 @@ public interface IIotDeviceService {
 
 
     List<IotDeviceListResVo> selectIotDeviceListByType(IotDeviceListReqVo reqVo);
     List<IotDeviceListResVo> selectIotDeviceListByType(IotDeviceListReqVo reqVo);
 
 
+    /**
+     * 检查设备基础列表
+     *
+     * @param iotDevice 设备基础
+     * @return 设备基础集合
+     */
+    public List<IotDevice> checkIotDeviceList(IotDevice iotDevice);
+
 }
 }

+ 33 - 3
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotDeviceServiceImpl.java

@@ -27,6 +27,7 @@ import com.yunfeiyun.agmp.iotm.web.service.IIotDeviceconnService;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -63,6 +64,9 @@ public class IotDeviceServiceImpl implements IIotDeviceService
     @Autowired
     @Autowired
     private IotDeviceRefreshService iotDeviceRefreshService;
     private IotDeviceRefreshService iotDeviceRefreshService;
 
 
+    @Value("${runMode.dev:1}")
+    private String runMode;
+
     /**
     /**
      * 新增设备基础
      * 新增设备基础
      *
      *
@@ -111,7 +115,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService
         selectIotDevice.setFirmBid(firmBid);
         selectIotDevice.setFirmBid(firmBid);
         selectIotDevice.setDevtypeBid(devtypeBid);
         selectIotDevice.setDevtypeBid(devtypeBid);
 
 
-        List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice);
+        List<IotDevice> iotDeviceList = checkIotDeviceList(selectIotDevice);
         Set<String> devCodeSet = new HashSet<>();
         Set<String> devCodeSet = new HashSet<>();
         for (IotDevice iotDevice : iotDeviceList) {
         for (IotDevice iotDevice : iotDeviceList) {
             devCodeSet.add(iotDevice.getDevtypeBid() + iotDevice.getDevCode());
             devCodeSet.add(iotDevice.getDevtypeBid() + iotDevice.getDevCode());
@@ -200,7 +204,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService
         selectIotDevice.setDevCode(devCode);
         selectIotDevice.setDevCode(devCode);
         selectIotDevice.setDevtypeBid(newIotDeviceconn.getDevtypeBid());
         selectIotDevice.setDevtypeBid(newIotDeviceconn.getDevtypeBid());
 
 
-        List<IotDevice> iotDeviceList = selectIotDeviceList(selectIotDevice);
+        List<IotDevice> iotDeviceList = checkIotDeviceList(selectIotDevice);
         Set<String> devSet = new HashSet<>();
         Set<String> devSet = new HashSet<>();
         for (IotDevice item : iotDeviceList) {
         for (IotDevice item : iotDeviceList) {
             devSet.add(item.getFirmBid() + item.getDevtypeBid() + item.getDevCode());
             devSet.add(item.getFirmBid() + item.getDevtypeBid() + item.getDevCode());
@@ -278,7 +282,22 @@ public class IotDeviceServiceImpl implements IIotDeviceService
      */
      */
     @Override
     @Override
     public List<IotDevice> selectIotDeviceList(IotDevice iotDevice) {
     public List<IotDevice> selectIotDeviceList(IotDevice iotDevice) {
-        iotDevice.setTid(SecurityUtils.getTid());
+        return selectIotDeviceList(iotDevice, true);
+    }
+
+    /**
+     * 查询设备基础列表
+     *
+     * @param iotDevice 设备基础
+     * @return 设备基础
+     */
+    public List<IotDevice> selectIotDeviceList(IotDevice iotDevice, boolean isTid) {
+        // 生产环境
+        if("0".equals(runMode) && !isTid){
+            iotDevice.setTid(null);
+        }else{
+            iotDevice.setTid(SecurityUtils.getTid());
+        }
         return iotDeviceMapper.selectIotDeviceList(iotDevice);
         return iotDeviceMapper.selectIotDeviceList(iotDevice);
     }
     }
 
 
@@ -368,4 +387,15 @@ public class IotDeviceServiceImpl implements IIotDeviceService
         return iotDeviceMapper.selectIotDeviceListByType(reqVo);
         return iotDeviceMapper.selectIotDeviceListByType(reqVo);
     }
     }
 
 
+    /**
+     * 检查设备基础列表
+     *
+     * @param iotDevice 设备基础
+     * @return 设备基础集合
+     */
+    @Override
+    public List<IotDevice> checkIotDeviceList(IotDevice iotDevice) {
+        return selectIotDeviceList(iotDevice, false);
+    }
+
 }
 }

+ 5 - 0
src/main/resources/application-dev.yml

@@ -284,3 +284,8 @@ iot:
       #python 执行地址
       #python 执行地址
       pythonExePath: /root/.pyenv/versions/iotm_ai_venv2/bin/python
       pythonExePath: /root/.pyenv/versions/iotm_ai_venv2/bin/python
   warnVer: 3
   warnVer: 3
+
+runMode:
+    # 0: 生产环境
+    # 1: 测试环境
+  env: 1