dcs 6 月之前
父节点
当前提交
5c0ce0e25f

+ 23 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/operate/controller/OperateFlowDataController.java

@@ -1,6 +1,8 @@
 package com.bosshand.virgo.api.operate.controller;
 
 import com.bosshand.virgo.api.operate.model.OperateFlowData;
+import com.bosshand.virgo.api.operate.service.OperateDeviceLevelService;
+import com.bosshand.virgo.api.operate.service.OperateDeviceService;
 import com.bosshand.virgo.api.operate.service.OperateFlowDataService;
 import com.bosshand.virgo.api.service.ProjectItemTargetRoomService;
 import com.bosshand.virgo.core.response.Response;
@@ -9,6 +11,7 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -24,6 +27,12 @@ public class OperateFlowDataController {
     @Autowired
     ProjectItemTargetRoomService projectItemTargetRoomService;
 
+    @Autowired
+    OperateDeviceService operateDeviceService;
+
+    @Autowired
+    OperateDeviceLevelService operateDeviceLevelService;
+
     @ApiOperation(value = "详情", notes = "详情")
     @RequestMapping(value = "/{id}", method = RequestMethod.GET)
     public Response get(@PathVariable long id) {
@@ -50,6 +59,20 @@ public class OperateFlowDataController {
     @ApiOperation(value = "分页查询", notes = "分页查询")
     @RequestMapping(value = "/{currPage}/{pageSize}", method = RequestMethod.POST)
     public Response getList(@RequestBody OperateFlowData operateFlowData, @PathVariable int currPage, @PathVariable int pageSize) {
+        // 根据目录id获取下面是所有设备id
+        long deviceLevelId = operateFlowData.getDeviceLevelId();
+        if (deviceLevelId != 0) {
+            List<Long> levelIds = new ArrayList<>();
+            operateDeviceLevelService.getLevel(levelIds, deviceLevelId);
+            List<Long> deviceIds = operateDeviceService.getDeviceLevelIds(levelIds);
+            if (deviceIds.size() > 0) {
+                operateFlowData.setDeviceIds(deviceIds);
+            } else {
+                deviceIds.add(-1L);
+                operateFlowData.setDeviceIds(deviceIds);
+            }
+        }
+
         List<OperateFlowData> list = operateFlowDataService.getListLimit(operateFlowData, currPage, pageSize);
         if (list.size() > 0) {
             for (OperateFlowData of : list) {

+ 1 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/operate/dao/OperateDeviceDao.java

@@ -23,4 +23,5 @@ public interface OperateDeviceDao {
 
     public List<OperateDevice> limit(@Param("od") OperateDevice od, @Param("currIndex") int currIndex, @Param("pageSize") int pageSize);
 
+    List<OperateDevice> getDeviceLevelIds(List<Long> list);
 }

+ 24 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/operate/model/OperateFlowData.java

@@ -3,6 +3,7 @@ package com.bosshand.virgo.api.operate.model;
 import com.fasterxml.jackson.annotation.JsonFormat;
 
 import java.util.Date;
+import java.util.List;
 
 /**
  * 审核流程数据
@@ -27,8 +28,15 @@ public class OperateFlowData {
 
     private String projectItemTargetRoomName;
 
+    /**
+     * 设备目录id
+     */
+    private long deviceLevelId;
+
     private long deviceId;
 
+    private List<Long> deviceIds;
+
     /**
      * DTO-设备信息
      */
@@ -133,6 +141,14 @@ public class OperateFlowData {
         this.projectItemTargetRoomName = projectItemTargetRoomName;
     }
 
+    public long getDeviceLevelId() {
+        return deviceLevelId;
+    }
+
+    public void setDeviceLevelId(long deviceLevelId) {
+        this.deviceLevelId = deviceLevelId;
+    }
+
     public long getDeviceId() {
         return deviceId;
     }
@@ -141,6 +157,14 @@ public class OperateFlowData {
         this.deviceId = deviceId;
     }
 
+    public List<Long> getDeviceIds() {
+        return deviceIds;
+    }
+
+    public void setDeviceIds(List<Long> deviceIds) {
+        this.deviceIds = deviceIds;
+    }
+
     public OperateDevice getOperateDevice() {
         return operateDevice;
     }

+ 18 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/operate/service/OperateDeviceLevelService.java

@@ -118,4 +118,22 @@ public class OperateDeviceLevelService {
         return list;
     }
 
+    /**
+     * 获取目录ids
+     */
+    public void getLevel(List<Long> levelIds, long deviceLevelId) {
+        OperateDeviceLevel operateDeviceLevel = this.get(deviceLevelId);
+        getLevel(levelIds, operateDeviceLevel);
+    }
+
+    private void getLevel(List<Long> levelIds, OperateDeviceLevel operateDeviceLevel) {
+        levelIds.add(operateDeviceLevel.getId());
+        List<OperateDeviceLevel> children = operateDeviceLevel.getChildren();
+        if (children.size() > 0) {
+            for (OperateDeviceLevel level : children) {
+                getLevel(levelIds, level);
+            }
+        }
+    }
+
 }

+ 10 - 0
virgo.api/src/main/java/com/bosshand/virgo/api/operate/service/OperateDeviceService.java

@@ -128,4 +128,14 @@ public class OperateDeviceService {
         return map;
     }
 
+    /**
+     * 获取目录ids下的设备id
+     */
+    public List<Long> getDeviceLevelIds(List<Long> deviceLevelIds) {
+        List<Long> ids = new ArrayList<>();
+        List<OperateDevice> list = operateDeviceDao.getDeviceLevelIds(deviceLevelIds);
+        list.forEach(ls -> ids.add(ls.getId()));
+        return ids;
+    }
+
 }

+ 17 - 0
virgo.api/src/main/resources/mapper/OperateDeviceMapper.xml

@@ -131,4 +131,21 @@
         DELETE FROM operate_device where id = #{id}
     </delete>
 
+    <select id="getDeviceLevelIds" resultMap="OperateDeviceResult">
+        SELECT id FROM operate_device
+        <choose>
+            <when test="list.size > 0">
+                where operateDeviceLevelId in (
+                <foreach collection="list" item="item" index="index" separator=",">
+                    #{item}
+                </foreach>
+                )
+            </when>
+            <otherwise>
+                where 1=0
+            </otherwise>
+        </choose>
+    </select>
+
+
 </mapper>

+ 14 - 0
virgo.api/src/main/resources/mapper/OperateFlowDataMapper.xml

@@ -85,6 +85,13 @@
             <if test="ofd.deviceId != 0">
                 and a.deviceId = #{ofd.deviceId}
             </if>
+            <if test="ofd.deviceIds != null">
+                and deviceId in (
+                <foreach collection="ofd.deviceIds" item="item" index="index" separator=",">
+                    #{item}
+                </foreach>
+                )
+            </if>
             <if test="ofd.projectFlowId != 0">
                 and a.projectFlowId = #{ofd.projectFlowId}
             </if>
@@ -126,6 +133,13 @@
             <if test="ofd.deviceId != 0">
                 and deviceId = #{ofd.deviceId}
             </if>
+            <if test="ofd.deviceIds != null">
+                and deviceId in (
+                <foreach collection="ofd.deviceIds" item="item" index="index" separator=",">
+                    #{item}
+                </foreach>
+                )
+            </if>
             <if test="ofd.projectFlowId != 0">
                 and projectFlowId = #{ofd.projectFlowId}
             </if>