| | |
| | | package com.ruoyi.device.camera.service.impl; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private SysDeptMapper sysDeptMapper; |
| | | @Resource |
| | | private RedisCache redisCache; |
| | | @Autowired |
| | | @Resource |
| | | private ISysDeptService deptService; |
| | | @Resource |
| | | private ArdChannelMapper ardChannelMapper; |
| | | @Resource |
| | | private IVtduService vtduService; |
| | | @Autowired |
| | | @Resource |
| | | protected Validator validator; |
| | | |
| | | @PostConstruct |
| | |
| | | } |
| | | |
| | | public List findOptions(ArdCameras ardCameras) { |
| | | List<ArdCameras> options = ardCamerasMapper.findOptions(ardCameras); |
| | | //List<ArdCameras> options = ardCamerasMapper.findOptions(ardCameras); |
| | | List<Long> subDeptIdList = sysDeptMapper.selectDeptIdBySub(SecurityUtils.getDeptId());//下属及本权限 |
| | | List<Long> ownDeptIdList= sysDeptMapper.selectRoleDeptIdByUsersId(SecurityUtils.getUserId());//自定义权限 |
| | | HashSet<Long> deptIdSet = new HashSet();//去重 |
| | | deptIdSet.addAll(subDeptIdList); |
| | | deptIdSet.addAll(ownDeptIdList); |
| | | List<Long> deptIdList = new ArrayList(); |
| | | deptIdList.addAll(deptIdSet);//符合条件的全部权限 |
| | | List<ArdCameras> options = ardCamerasMapper.findTowerCamerasBySubAndOwnDeptIds(deptIdList); |
| | | for (ArdCameras camera : |
| | | options) { |
| | | ArdChannel ardChannel = new ArdChannel(); |
| | |
| | | SysDept sysDept = sysDeptMapper.selectDeptById(deptId); |
| | | Map<String, Object> map = fetchChildDepartments(sysDept, disabled); |
| | | return map; |
| | | } |
| | | |
| | | @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 |
| | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 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); |
| | | Map<String, Object> map1 = fetchChildDepartments(ownDeptIdList,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); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> getCamerasByDeptId(Long deptId) { |
| | | List<Map<String, Object>> result = ardCamerasMapper.getCamerasByDeptId(deptId); |
| | | public List<Map<String, Object>> getCamerasByDeptId(Long deptId,String userId) { |
| | | List<Long> deptIdList = new ArrayList(); |
| | | deptIdList.add(deptId); |
| | | deptIdList = getOwnAndChildrenDeptIdList(deptIdList,new ArrayList());//递归查询下属部门主键 |
| | | //List<Map<String, Object>> result = ardCamerasMapper.getCamerasByDeptId(deptId,userId); |
| | | List<Map<String, Object>> result = ardCamerasMapper.getCamerasByDeptId(deptIdList,userId); |
| | | return result; |
| | | } |
| | | |
| | | public List<Long> getOwnAndChildrenDeptIdList(List<Long> deptIdList,List<Long> deptIdListr){ |
| | | deptIdListr.addAll(deptIdList); |
| | | List<Long> result = sysDeptMapper.getChildrenDeptIdList(deptIdList); |
| | | if(result.size() != 0){ |
| | | deptIdListr.addAll(result); |
| | | result = getOwnAndChildrenDeptIdList(result,deptIdListr); |
| | | } |
| | | deptIdListr = deptIdListr.stream().distinct().collect(Collectors.toList()); |
| | | return deptIdListr; |
| | | } |
| | | |
| | | @Override |
| | | public Boolean getCameraOperationByCameraId(String id, String userId) { |
| | | Boolean result = ardCamerasMapper.getCameraOperationByCameraId(id,userId); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> getChannelByCameraId(String id) { |
| | | List<Map<String,Object>> result = ardCamerasMapper.getChannelByCameraId(id); |
| | | Map<String,Object> resultMap = new HashMap(); |
| | | if(result.size() == 1){ |
| | | resultMap.put("chanNo", result.get(0).get("chan_no")); |
| | | return resultMap; |
| | | }else{ |
| | | String configValue = (String) result.get(0).get("config_value"); |
| | | String beginTime = configValue.split("-")[0]; |
| | | String endTime = configValue.split("-")[1]; |
| | | Date now = new Date(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String nowDay = sdf.format(now); |
| | | try{ |
| | | Long beginDate = sdf.parse(nowDay).getTime() |
| | | + Integer.parseInt(beginTime.split(":")[0]) * 60 * 60 *1000 |
| | | + Integer.parseInt(beginTime.split(":")[1]) * 60 *1000; |
| | | Long endDate = sdf.parse(nowDay).getTime() |
| | | + Integer.parseInt(endTime.split(":")[0]) * 60 * 60 *1000 |
| | | + Integer.parseInt(endTime.split(":")[1]) * 60 *1000; |
| | | if(now.getTime() >= beginDate && now.getTime() <= endDate){ |
| | | result = result.stream().filter(map -> ((Integer)map.get("chan_no")) == 1).collect(Collectors.toList()); |
| | | resultMap.put("chanNo", result.get(0).get("chan_no")); |
| | | return resultMap; |
| | | }else{ |
| | | result = result.stream().filter(map -> ((Integer)map.get("chan_no")) == 2).collect(Collectors.toList()); |
| | | resultMap.put("chanNo", result.get(0).get("chan_no")); |
| | | return resultMap; |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return resultMap; |
| | | } |
| | | } |
| | | } |
| | | } |