diff --git a/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RepairStaffRoleCacheResultDTO.java b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RepairStaffRoleCacheResultDTO.java new file mode 100644 index 0000000000..e24f490559 --- /dev/null +++ b/epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RepairStaffRoleCacheResultDTO.java @@ -0,0 +1,42 @@ +package com.epmet.dto.result; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author zxc + * @DateTime 2021/6/15 5:49 下午 + * @DESC + */ +@Data +public class RepairStaffRoleCacheResultDTO implements Serializable { + + private static final long serialVersionUID = 1220784037854283625L; + + /** + * 角色key + */ + private String roleKey; + + /** + * 角色value + */ + private String roleName; + + /** + * 组织ID + */ + private String orgId; + + /** + * 工作人员ID + */ + private String staffId; + + /** + * 客户ID + */ + private String customerId; + +} diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java index 411b6fee69..969eae7e66 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java @@ -199,7 +199,7 @@ public class StaffRoleController { */ @PostMapping("repairstaffrolecache") public Result repairStaffRoleCache(){ - + staffRoleService.repairStaffRoleCache(); return new Result(); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java index 25c8c2687f..da289c6308 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java @@ -144,4 +144,12 @@ public interface StaffRoleDao extends BaseDao { * @date 2021/6/15 3:51 下午 */ List getRolesByDB(@Param("userId")String userId); + + /** + * @Description 查询所有用户角色 + * @Param + * @author zxc + * @date 2021/6/15 5:54 下午 + */ + List selectAllUserRoles(); } diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java index 0fd2fcb101..b34f90d294 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java @@ -174,4 +174,12 @@ public interface StaffRoleService extends BaseService { * @date 2021/6/15 3:03 下午 */ CustomerAgencyUserRoleDTO getUserRoles(CustomerAgencyUserRoleFormDTO formDTO); + + /** + * @Description 补全缓存 工作人员角色 + * @Param + * @author zxc + * @date 2021/6/15 2:05 下午 + */ + void repairStaffRoleCache(); } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java index 578c577f17..0404a5ff0a 100644 --- a/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java +++ b/epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java @@ -236,4 +236,33 @@ public class StaffRoleServiceImpl extends BaseServiceImpl allRoles = baseDao.selectAllUserRoles(); + if (!CollectionUtils.isEmpty(allRoles)){ + // 根据 userId分组【staffId】 + Map> groupByStaff = allRoles.stream().collect(Collectors.groupingBy(RepairStaffRoleCacheResultDTO::getStaffId)); + groupByStaff.forEach((userId,list) -> { + CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO(); + String customerId = list.get(NumConstant.ZERO).getCustomerId(); + dto.setStaffId(list.get(NumConstant.ZERO).getStaffId()); + dto.setCustomerId(customerId); + dto.setAgencyId(list.get(NumConstant.ZERO).getOrgId()); + Map map = new HashMap(16); + list.forEach(l -> { + map.put(l.getRoleKey(), l.getRoleName()); + }); + dto.setRoles(map.toString()); + staffRoleRedis.setRole(customerId, userId, dto); + }); + } + } + } \ No newline at end of file diff --git a/epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml b/epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml index 437abfa4e3..1054b26a5e 100644 --- a/epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml +++ b/epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml @@ -220,4 +220,17 @@ WHERE sr.DEL_FLAG = 0 AND sr.STAFF_ID = #{userId} + + +