diff --git a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java index 628095b3..7c8a25b1 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/controller/ResourceController.java @@ -23,12 +23,17 @@ import io.renren.modules.resource.videoPreview.AbstractVideoPreviewService; import io.renren.modules.resource.videoPreview.VideoPreviewFactory; import io.renren.modules.security.user.SecurityUser; import io.renren.modules.security.user.UserDetail; +import io.renren.modules.sys.dao.SysDeptDao; import io.renren.modules.sys.dao.SysUserDao; import io.renren.modules.sys.dto.SysDeptDTO; +import io.renren.modules.sys.dto.SysRoleDTO; import io.renren.modules.sys.dto.SysUserDTO; +import io.renren.modules.sys.entity.SysDeptEntity; import io.renren.modules.sys.entity.SysUserEntity; import io.renren.modules.sys.enums.SuperAdminEnum; import io.renren.modules.sys.service.SysDeptService; +import io.renren.modules.sys.service.SysRoleService; +import io.renren.modules.sys.service.SysRoleUserService; import io.renren.modules.sys.service.SysUserService; import io.swagger.annotations.*; import org.apache.commons.lang.StringUtils; @@ -85,6 +90,17 @@ public class ResourceController { @Value("${resource.path}") private String uploadPath; + @Value("${big_date.assignee_role_name}") + private String roleName0; // 具备审批的角色名称(普通) + + @Value("${big_date.assignee_district_role_name}") + private String roleName1; // 具备审批的角色名称(区县) + @Value("${big_date.assignee_city_role_name}") + private String roleName2; // 具备审批的角色名称(市区) + + @Value("${big_date.assignee_meet_role_id}") + private String defaultAssigneeRoleId; // 会客厅审核人角色 + @Autowired private ResourceService resourceService; @@ -99,6 +115,14 @@ public class ResourceController { @Autowired private SysUserService sysUserService; + @Autowired + private SysRoleService sysRoleService; + @Autowired + private SysRoleUserService sysRoleUserService; + + @Autowired + private SysDeptDao sysDeptDao; + @Resource(name = "${hisense.gateway.name}") private ApiGateway apiGateway; @@ -126,6 +150,74 @@ public class ResourceController { @ApiImplicitParam(name = "region", value = "是否过滤只出用户区域内部门", paramType = "query", dataType = "String") }) public Result> page(@ApiIgnore @RequestParam Map params) { + // 2022.12.16 后台过滤只出所属区域资源 + Boolean region = params.containsKey("region") ? (Boolean) params.get("region") : false; // 是否需要过滤只出用户所属区域资源 + while (region) { + List deptIds = new ArrayList<>(); + UserDetail user = SecurityUser.getUser(); // 当前用户 + if (SuperAdminEnum.YES.value() != user.getSuperAdmin()) { // 非超级管理员 + Optional userDTOOptional = Optional.ofNullable(sysUserService.get(user.getId())); + if (userDTOOptional.isPresent()) { + SysRoleDTO roleDTO0 = sysRoleService.getByName(roleName0); // 部门审核员 + SysRoleDTO roleDTO1 = sysRoleService.getByName(roleName1); // 区管理员 + SysRoleDTO roleDTO2 = sysRoleService.getByName(roleName2); // 市管理员 + List useIds0 = sysRoleUserService.getUserIdListByRoleId(roleDTO0.getId()); // 部门审核员列表 + List useIds1 = sysRoleUserService.getUserIdListByRoleId(roleDTO1.getId()); // 区管理员 + List useIds02 = sysRoleUserService.getUserIdListByRoleId(roleDTO2.getId()); // 市管理员 + List useIds = sysRoleUserService.getUserIdListByRoleId(Long.parseLong(defaultAssigneeRoleId)); // 运维管理员 + + if (useIds.contains(user.getId())) { // 为运维管理员时 + logger.info("运维管理员出所有资源"); + break; + } + if (useIds02.contains(user.getId())) { // 为市管理员 + logger.info("市管理员"); + break; + } + + SysDeptEntity sysDeptEntity = null; + if (userDTOOptional.get().getDeptId() != null) { + sysDeptEntity = sysDeptDao.getById(userDTOOptional.get().getDeptId()); + } + + if (sysDeptEntity == null || sysDeptEntity.getDistrict() == null) { + logger.info("该用户部门信息异常" + user.toString()); + break; + } + + if (useIds1.contains(user.getId())) { // 区管理员 + logger.info("区管理员"); + SysDeptEntity finalSysDeptEntity = sysDeptEntity; + List deptId = sysDeptDao.getIdFromDistrict(sysDeptEntity.getDistrict()); + List temp = new ArrayList() { + { + add(finalSysDeptEntity.getId()); + if (!deptId.isEmpty()) { + addAll(deptId); + } + } + }; + deptIds.addAll(temp); + params.put("deptIds", deptIds.stream().distinct().collect(Collectors.toList())); + break; + } + if (useIds0.contains(user.getId())) { // 部门审核员 + logger.info("部门审核员"); + SysDeptEntity finalSysDeptEntity1 = sysDeptEntity; + List temp = new ArrayList() { + { + add(finalSysDeptEntity1.getId()); + } + }; + deptIds.addAll(temp); + params.put("deptIds", deptIds.stream().distinct().collect(Collectors.toList())); + break; + } + } + + } + } + PageData page = resourceService.page(params); page.getList().forEach(item -> { item.setInfoList(resourceService.selectAttrsByResourceId(item.getId())); diff --git a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java index 317e336e..8903de57 100644 --- a/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/resource/service/impl/ResourceServiceImpl.java @@ -62,6 +62,7 @@ import io.renren.modules.sys.entity.SysDeptEntity; import io.renren.modules.sys.enums.SuperAdminEnum; import io.renren.modules.sys.service.SysDeptService; import io.renren.modules.sys.service.SysRoleService; +import io.renren.modules.sys.service.SysRoleUserService; import io.renren.modules.sys.service.SysUserService; import lombok.SneakyThrows; import okhttp3.*; @@ -270,6 +271,8 @@ public class ResourceServiceImpl extends CrudServiceImpl deptIds = new ArrayList<>(); + try { + deptIds = (List) params.get("deptIds"); + } catch (Exception ex) { + logger.error("", ex); + } + wrapper.in(deptIds.isEmpty(), "dept_id", deptIds); + } + break; default: break; } @@ -517,20 +530,77 @@ public class ResourceServiceImpl extends CrudServiceImpl userDTOOptional = Optional.ofNullable(sysUserService.get(user.getId())); - SysRoleDTO roleDTO0 = sysRoleService.getByName(roleName0); - SysRoleDTO roleDTO1 = sysRoleService.getByName(roleName1); - SysRoleDTO roleDTO2 = sysRoleService.getByName(roleName2); - userDTOOptional.ifPresent(userDto -> { - if (userDto.getDeptId() != null) { - SysDeptEntity sysDeptEntity = sysDeptDao.getById(userDto.getDeptId()); + if (userDTOOptional.isPresent()) { + SysRoleDTO roleDTO0 = sysRoleService.getByName(roleName0); // 部门审核员 + SysRoleDTO roleDTO1 = sysRoleService.getByName(roleName1); // 区管理员 + SysRoleDTO roleDTO2 = sysRoleService.getByName(roleName2); // 市管理员 + List useIds0 = sysRoleUserService.getUserIdListByRoleId(roleDTO0.getId()); // 部门审核员列表 + List useIds1 = sysRoleUserService.getUserIdListByRoleId(roleDTO1.getId()); // 区管理员 + List useIds02 = sysRoleUserService.getUserIdListByRoleId(roleDTO2.getId()); // 市管理员 + List useIds = sysRoleUserService.getUserIdListByRoleId(Long.parseLong(defaultAssigneeRoleId)); // 运维管理员 + + if (useIds.contains(user.getId())) { // 为运维管理员时 + logger.info("运维管理员出所有资源"); + break; } - }); + if (useIds02.contains(user.getId())) { // 为市管理员 + logger.info("市管理员"); + break; + } + + SysDeptEntity sysDeptEntity = null; + if (userDTOOptional.get().getDeptId() != null) { + sysDeptEntity = sysDeptDao.getById(userDTOOptional.get().getDeptId()); + } + + if (sysDeptEntity == null || sysDeptEntity.getDistrict() == null) { + logger.info("该用户部门信息异常" + user.toString()); + break; + } + + if (useIds1.contains(user.getId())) { // 区管理员 + logger.info("区管理员"); + SysDeptEntity finalSysDeptEntity = sysDeptEntity; + List deptId = sysDeptDao.getIdFromDistrict(sysDeptEntity.getDistrict()); + List temp = new ArrayList() { + { + add(finalSysDeptEntity.getId()); + if (!deptId.isEmpty()) { + addAll(deptId); + } + } + }; + if (!resourceDTO.getDeptIds().isEmpty()) { + temp.addAll(resourceDTO.getDeptIds()); + } + resourceDTO.setDeptIds(temp.stream().distinct().collect(Collectors.toList())); + break; + } + if (useIds0.contains(user.getId())) { // 部门审核员 + logger.info("部门审核员"); + if (userDTOOptional.get().getDeptId() != null) { + SysDeptEntity finalSysDeptEntity = sysDeptEntity; + List temp = new ArrayList() { + { + add(finalSysDeptEntity.getId()); + } + }; + if (!resourceDTO.getDeptIds().isEmpty()) { + temp.addAll(resourceDTO.getDeptIds()); + } + resourceDTO.setDeptIds(temp.stream().distinct().collect(Collectors.toList())); // 只出自己部门 + } + break; + } + } + } } + Boolean nonChinese = jsonObject.containsKey("nonChinese") ? jsonObject.getBoolean("nonChinese") : Boolean.FALSE; // 不传默认为中文走全文索引 //默认按上架时间降序排列 String orderField; diff --git a/renren-admin/src/main/java/io/renren/modules/security/user/UserDetail.java b/renren-admin/src/main/java/io/renren/modules/security/user/UserDetail.java index 5a372c9d..ccb6d7ca 100644 --- a/renren-admin/src/main/java/io/renren/modules/security/user/UserDetail.java +++ b/renren-admin/src/main/java/io/renren/modules/security/user/UserDetail.java @@ -28,4 +28,21 @@ public class UserDetail implements Serializable { */ private List deptIdList; + @Override + public String toString() { + return "UserDetail{" + + "id=" + id + + ", username='" + username + '\'' + + ", realName='" + realName + '\'' + + ", headUrl='" + headUrl + '\'' + + ", gender=" + gender + + ", email='" + email + '\'' + + ", mobile='" + mobile + '\'' + + ", deptId=" + deptId + + ", password='" + password + '\'' + + ", status=" + status + + ", superAdmin=" + superAdmin + + ", deptIdList=" + deptIdList + + '}'; + } } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java index 424e5bb7..91b41add 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/dao/SysDeptDao.java @@ -44,4 +44,6 @@ public interface SysDeptDao extends BaseDao { Map selectUCSDeptByLCDeptName(@Param("deptName") String deptName); + List getIdFromDistrict(@Param("district") Long district); + } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java index 3646cd25..803c94a1 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java @@ -34,4 +34,12 @@ public interface SysDeptService extends BaseService { SysDeptDTO getByName(String name); + /** + * 查询该区域内部门id + * + * @param district + * @return + */ + List getIdFromDistrict(Long district); + } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java index 2d098c84..f32819dc 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java @@ -51,7 +51,7 @@ public class SysDeptServiceImpl extends BaseServiceImpl entityList = baseDao.getList(params); List dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class); List result = dtoList.stream().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList()); - return new PageData( TreeUtils.build(result), dtoList.size()); + return new PageData(TreeUtils.build(result), dtoList.size()); } @Override @@ -147,6 +147,17 @@ public class SysDeptServiceImpl extends BaseServiceImpl getIdFromDistrict(Long district) { + return baseDao.getIdFromDistrict(district); + } + /** * 获取所有上级部门ID diff --git a/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml b/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml index e470d778..2654b4f9 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml @@ -43,8 +43,13 @@ + + + \ No newline at end of file