ard-work/src/main/java/com/ruoyi/device/camera/controller/ArdCamerasController.java
@@ -8,6 +8,7 @@ import com.ruoyi.device.hiksdk.service.impl.HikClientServiceImpl; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.service.ISysDeptService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; @@ -160,5 +161,11 @@ } return options; } @GetMapping("/getDeptAndCamera") @ApiOperation("è·åé¨é¨åç¸æº") public AjaxResult getDeptAndCamera() { Map deptAndCamera = ardCamerasService.getChildDeptAndCamera(); return AjaxResult.success(deptAndCamera); } } ard-work/src/main/java/com/ruoyi/device/camera/mapper/ArdCamerasMapper.java
@@ -3,6 +3,7 @@ import java.util.List; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.device.camera.domain.ArdCameras; /** @@ -67,4 +68,12 @@ */ public int deleteArdCamerasByIds(String[] ids); public List findOptions(ArdCameras ardCameras); /** * æ ¹æ®é¨é¨IDæ¥è¯¢æè½½çç¸æº * * @param deptId é¨é¨ID * @return é¨é¨å表 */ public List<ArdCameras> selectArdCamerasByDeptId(Long deptId); } ard-work/src/main/java/com/ruoyi/device/camera/service/IArdCamerasService.java
@@ -1,6 +1,8 @@ package com.ruoyi.device.camera.service; import java.util.HashMap; import java.util.List; import java.util.Map; import com.ruoyi.device.camera.domain.ArdCameras; @@ -67,4 +69,13 @@ public int deleteArdCamerasById(String id); public List findOptions(ArdCameras ardCameras); /** * @æè¿° è·åæ¬é¨é¨ä»¥ä¸çææç¸æºåé¨é¨ * @åæ° [] * @è¿åå¼ java.util.Map * @å建人 åèä¹ * @å建æ¶é´ 2023/6/2 10:58 * @ä¿®æ¹äººåå ¶å®ä¿¡æ¯ */ public Map getChildDeptAndCamera(); } ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -1,13 +1,23 @@ package com.ruoyi.device.camera.service.impl; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.common.utils.tools.ArdTool; import com.ruoyi.device.camera.domain.ArdCameras; import com.ruoyi.device.camera.mapper.ArdCamerasMapper; import com.ruoyi.device.camera.service.IArdCamerasService; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.system.mapper.SysDeptMapper; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -22,6 +32,8 @@ public class ArdCamerasServiceImpl implements IArdCamerasService { @Resource private ArdCamerasMapper ardCamerasMapper; @Resource private SysDeptMapper sysDeptMapper; /** * æ¥è¯¢ç¸æºè®¾å¤ @@ -108,4 +120,58 @@ public List findOptions(ArdCameras ardCameras) { return ardCamerasMapper.findOptions(ardCameras); } /** * @æè¿° è·åæ¬é¨é¨ä»¥ä¸çææç¸æºåé¨é¨ * @åæ° [] * @è¿åå¼ java.util.Map * @å建人 åèä¹ * @å建æ¶é´ 2023/6/2 10:58 * @ä¿®æ¹äººåå ¶å®ä¿¡æ¯ */ @Override public Map getChildDeptAndCamera() { Long deptId = SecurityUtils.getDeptId(); SysDept sysDept = sysDeptMapper.selectDeptById(deptId); Map<String, Object> map = fetchChildDepartments(sysDept); return map; } /** * @æè¿° é彿¥è¯¢ * @åæ° [sysDept] * @è¿åå¼ java.util.Map<java.lang.String,java.lang.Object> * @å建人 åèä¹ * @å建æ¶é´ 2023/6/2 14:38 * @ä¿®æ¹äººåå ¶å®ä¿¡æ¯ */ public Map<String, Object> fetchChildDepartments(SysDept sysDept) { Map<String, Object> map = new HashMap<>(); map.put("name", sysDept.getDeptName()); map.put("deptId", sysDept.getDeptId()); map.put("disabled", true); List<SysDept> sysDepts = sysDeptMapper.selectNextChildrenDeptById(sysDept.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", true); Map<String, Object> map1 = fetchChildDepartments(childDept); childMap.putAll(map1); childList.add(childMap); } if (ardCameras.size() > 0) { for (ArdCameras camera : ardCameras) { Map<String, Object> cameraMap = ArdTool.convertEntityToMap(camera); childList.add(cameraMap); } } map.put("children", childList); return map; } } ard-work/src/main/resources/mapper/device/ArdCamerasMapper.xml
@@ -239,7 +239,6 @@ </foreach> </delete> <select id="findOptions" parameterType="String" resultMap="ArdCamerasResult"> <include refid="selectArdCamerasVo"/> <where> @@ -247,4 +246,9 @@ <if test="name != null and name != ''">and c.name like '%'||#{name}||'%'</if> </where> </select> <select id="selectArdCamerasByDeptId" parameterType="Long" resultMap="ArdCamerasResult"> select * from ard_cameras where dept_id = #{deptId} </select> </mapper> ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java
@@ -55,6 +55,17 @@ /** åé¨é¨ */ private List<SysDept> children = new ArrayList<SysDept>(); private boolean disabled; public boolean isDisabled() { return disabled; } public void setDisabled(boolean disabled) { this.disabled = disabled; } public Long getDeptId() { return deptId; ruoyi-common/src/main/java/com/ruoyi/common/utils/tools/ArdTool.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,38 @@ package com.ruoyi.common.utils.tools; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; /** * @Description: å·¥å ·æ¹æ³ * @ClassName: ArdTool * @Author: åèä¹ * @Date: 2023å¹´06æ02æ¥14:37 * @Version: 1.0 **/ public class ArdTool { /** * @æè¿° å®ä½å¯¹è±¡è½¬Map * @åæ° [entity] * @è¿åå¼ java.util.Map<java.lang.String,java.lang.Object> * @å建人 åèä¹ * @å建æ¶é´ 2023/6/2 14:35 * @ä¿®æ¹äººåå ¶å®ä¿¡æ¯ */ public static Map<String, Object> convertEntityToMap(Object entity) { Map<String, Object> map = new HashMap<>(); Field[] fields = entity.getClass().getDeclaredFields(); for (Field field : fields) { field.setAccessible(true); try { Object value = field.get(entity); map.put(field.getName(), value); } catch (IllegalAccessException e) { e.printStackTrace(); } } return map; } } ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysDeptMapper.java
@@ -43,6 +43,13 @@ * @return é¨é¨å表 */ public List<SysDept> selectChildrenDeptById(Long deptId); /** * æ ¹æ®IDæ¥è¯¢ä¸çº§åé¨é¨ * * @param deptId é¨é¨ID * @return é¨é¨å表 */ public List<SysDept> selectNextChildrenDeptById(Long deptId); /** * æ ¹æ®IDæ¥è¯¢ææåé¨é¨ï¼æ£å¸¸ç¶æï¼ ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDeptService.java
@@ -1,6 +1,8 @@ package com.ruoyi.system.service; import java.util.List; import java.util.Map; import com.ruoyi.common.core.domain.TreeSelect; import com.ruoyi.common.core.domain.entity.SysDept; @@ -121,4 +123,5 @@ * @return ç»æ */ public int deleteDeptById(Long deptId); } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -1,10 +1,7 @@ package com.ruoyi.system.service.impl; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.*; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.UserConstants; @@ -21,6 +18,8 @@ import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysDeptService; import javax.annotation.Resource; /** * é¨é¨ç®¡ç æå¡å®ç° * @@ -29,10 +28,10 @@ @Service public class SysDeptServiceImpl implements ISysDeptService { @Autowired @Resource private SysDeptMapper deptMapper; @Autowired @Resource private SysRoleMapper roleMapper; /** @@ -335,4 +334,6 @@ { return getChildList(list, t).size() > 0; } } ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -77,7 +77,9 @@ <select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult"> select * from sys_dept where cast(#{deptId} as varchar) = any(string_to_array(ancestors,',')) </select> <select id="selectNextChildrenDeptById" parameterType="Long" resultMap="SysDeptResult"> select * from sys_dept where parent_id=#{deptId} and del_flag='0' </select> <select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int"> select count(*) from sys_dept where status = '0' and del_flag = '0' and cast(#{deptId} as varchar) = any(string_to_array(ancestors,',')) </select>