From 1f71a273c29432665a93507211e9168e51ac4d3f Mon Sep 17 00:00:00 2001
From: zhangnaisong <2434969829@qq.com>
Date: 星期三, 29 五月 2024 13:59:10 +0800
Subject: [PATCH] 光电查询加入自定义权限修改提交

---
 ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml                        |   19 ++++++
 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java                  |    4 +
 ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java    |    3 
 ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java         |    1 
 ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java |   99 +++++++++++++++++++++++++++++++++
 5 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
index 2b7d10e..ba8493e 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
@@ -218,7 +218,8 @@
     @GetMapping("/getDeptAndCameraWithCheckBox")
     @ApiOperation("鑾峰彇閮ㄩ棬鍜岀浉鏈�(寮�鍚閫夋)")
     public AjaxResult getDeptAndCameraWithCheckBox() {
-        Map deptAndCamera = ardCamerasService.getChildDeptAndCamera(false);
+        //Map deptAndCamera = ardCamerasService.getChildDeptAndCamera(false);
+        List<Map<String, Object>> deptAndCamera = ardCamerasService.getChildDeptAndCameraOwn(false);
         return AjaxResult.success(deptAndCamera);
     }
 
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
index 860d96d..c522cd1 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
@@ -107,6 +107,7 @@
      * @淇敼浜哄拰鍏跺畠淇℃伅
      */
     public Map getChildDeptAndCamera(Boolean disabled);
+    public List<Map<String, Object>> getChildDeptAndCameraOwn(Boolean disabled);
     public List<DeptAndCamerasDto> getChildDeptAndCamera();
 
     public TreeMap getNearCamerasBycoordinate(CameraCmd cmd);
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
index d35b60d..622ed8a 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -320,6 +320,28 @@
     }
 
     @Override
+    public List<Map<String, Object>> getChildDeptAndCameraOwn(Boolean disabled) {
+        Long deptId = SecurityUtils.getDeptId();
+        SysDept sysDept = sysDeptMapper.selectDeptById(deptId);
+        List<Long> ownDeptIdList = sysDeptMapper.selectRoleDeptIdByUsersId(SecurityUtils.getUserId());//鑷畾涔夋潈闄愪富閿煡璇�
+        ownDeptIdList.remove(SecurityUtils.getDeptId());//鑻ヨ嚜瀹氫箟鏉冮檺鍖呭惈鏈骇鏉冮檺锛屽垯绉婚櫎
+        Map<String, Object> map = fetchChildDepartments(sysDept, disabled, ownDeptIdList);//鏌ヨ鏈潈闄愬強涓嬪睘鏉冮檺璁惧骞跺湪鑷畾涔夋潈闄愪腑绉婚櫎涓嬪睘閮ㄩ棬涓婚敭
+        Set<Long> pIdSet = new HashSet();//鑷畾涔夋潈闄愪富閿殑鏈�璇ユ潈闄�
+        for(Long deptIdn : ownDeptIdList){
+            List<SysDept> pSysDeptList = sysDeptMapper.getParentsDeptListByDeptId(deptIdn);
+            pIdSet.add(pSysDeptList.get(pSysDeptList.size() - 1).getDeptId());//鑾峰彇
+        }
+        List<Map<String, Object>> result = new ArrayList();
+        result.add(map);
+        for(Long pId : pIdSet){
+            SysDept pSysDept = sysDeptMapper.selectDeptById(pId);
+            Map<String, Object> mapO = fetchChildDepartments(ownDeptIdList, pSysDept, disabled);
+            result.add(mapO);
+        }
+        return result;
+    }
+
+    @Override
     public List<DeptAndCamerasDto> getChildDeptAndCamera() {
         List<SysDept> depts = deptService.selectDeptList(new SysDept());
         return fetchChildDepartments(depts);
@@ -367,6 +389,83 @@
     }
 
     /**
+    * zns
+    *
+    * */
+    public Map<String, Object> fetchChildDepartments(SysDept sysDept, Boolean disabled, List<Long> ownDeptIdList) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("name", sysDept.getDeptName());
+        map.put("deptId", sysDept.getDeptId());
+        map.put("disabled", disabled);
+        List<SysDept> sysDepts = sysDeptMapper.selectNextChildrenDeptById(sysDept.getDeptId());
+        for(SysDept sysDeptC : sysDepts){//鑻ヨ嚜瀹氫箟鏉冮檺鍖呭惈涓嬬骇鏉冮檺锛屽垯绉婚櫎
+            if(ownDeptIdList.contains(sysDeptC.getDeptId())){
+                ownDeptIdList.remove(sysDeptC.getDeptId());
+            }
+        }
+        List<ArdCameras> ardCameras = ardCamerasMapper.selectArdCamerasByDeptId(sysDept.getDeptId());
+        List<Object> childList = new ArrayList<>();
+        for (SysDept childDept : sysDepts) {
+            Map<String, Object> childMap = new HashMap<>();
+            childMap.put("name", childDept.getDeptName());
+            childMap.put("deptId", childDept.getDeptId());
+            childMap.put("disabled", disabled);
+            Map<String, Object> map1 = fetchChildDepartments(childDept, disabled);
+            childMap.putAll(map1);
+            childList.add(childMap);
+        }
+        if (ardCameras.size() > 0) {
+            for (ArdCameras camera : ardCameras) {
+                ArdChannel ardChannel = new ArdChannel();
+                ardChannel.setDeviceId(camera.getId());
+                List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel);
+                if (ardChannels != null) {
+                    ardChannels.stream().sorted();
+                    camera.setChannelList(ardChannels);
+                }
+                Map<String, Object> cameraMap = ArdTool.convertEntityToMap(camera);
+                childList.add(cameraMap);
+            }
+        }
+        map.put("children", childList);
+        return map;
+    }
+
+    public Map<String, Object> fetchChildDepartments(List<Long> ownDeptIdList, SysDept sysDept, Boolean disabled) {
+        Map<String, Object> map = new HashMap<>();
+        map.put("name", sysDept.getDeptName());
+        map.put("deptId", sysDept.getDeptId());
+        map.put("disabled", disabled);
+        List<SysDept> sysDepts = sysDeptMapper.selectNextChildrenDeptByIdAndInList(sysDept.getDeptId(),ownDeptIdList);
+        List<ArdCameras> ardCameras = ardCamerasMapper.selectArdCamerasByDeptId(sysDept.getDeptId());
+        List<Object> childList = new ArrayList<>();
+        for (SysDept childDept : sysDepts) {
+            Map<String, Object> childMap = new HashMap<>();
+            childMap.put("name", childDept.getDeptName());
+            childMap.put("deptId", childDept.getDeptId());
+            childMap.put("disabled", disabled);
+            Map<String, Object> map1 = fetchChildDepartments(childDept, disabled);
+            childMap.putAll(map1);
+            childList.add(childMap);
+        }
+        if (ardCameras.size() > 0) {
+            for (ArdCameras camera : ardCameras) {
+                ArdChannel ardChannel = new ArdChannel();
+                ardChannel.setDeviceId(camera.getId());
+                List<ArdChannel> ardChannels = ardChannelMapper.selectArdChannelList(ardChannel);
+                if (ardChannels != null) {
+                    ardChannels.stream().sorted();
+                    camera.setChannelList(ardChannels);
+                }
+                Map<String, Object> cameraMap = ArdTool.convertEntityToMap(camera);
+                childList.add(cameraMap);
+            }
+        }
+        map.put("children", childList);
+        return map;
+    }
+
+    /**
      * 鑾峰彇鎵�鏈夐儴闂ㄥ強閮ㄩ棬涓嬬殑鐩告満
      * 鍒樿嫃涔�
      * 2024/3/4 14:45:03
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
index f918968..558d9ce 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
@@ -130,4 +130,8 @@
     public List<Long> selectDeptIdBySub(Long deptId);
 
     public List<Long> selectRoleDeptIdByUsersId(String usersId);
+
+    public List<SysDept> getParentsDeptListByDeptId(Long deptId);
+
+    public List<SysDept> selectNextChildrenDeptByIdAndInList(@Param("deptId")Long deptId,@Param("deptIdList")List<Long> deptIdList);
 }
diff --git a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index 13e09aa..94aa515 100644
--- a/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -179,6 +179,23 @@
 		select srd.dept_id from sys_user su
 		inner join sys_user_role sur on su.user_id = sur.user_id
 		inner join sys_role_dept srd on sur.role_id = srd.role_id
-		where su.user_id = #{usersId}
+		where su.user_id = #{usersId} order by srd.dept_id
+	</select>
+
+	<select id="getParentsDeptListByDeptId" resultMap="SysDeptResult" parameterType="java.lang.Long">
+		with recursive rsd as (
+			select * from sys_dept sd where sd.dept_id = #{deptId}
+			union
+			select psd.* from sys_dept psd inner join rsd on rsd.parent_id = psd.dept_id
+		)
+		select * from rsd
+	</select>
+
+	<select id="selectNextChildrenDeptByIdAndInList" resultMap="SysDeptResult">
+		select * from sys_dept where parent_id=#{deptId} and del_flag='0'
+		and dept_id in
+		<foreach collection="deptIdList" item="deptId" separator="," index="index" open="(" close=")">
+			#{deptId}
+		</foreach>
 	</select>
 </mapper> 
\ No newline at end of file

--
Gitblit v1.9.3