Browse Source

Merge remote-tracking branch 'origin/dev_grid_patrol' into develop

master
zxc 4 years ago
parent
commit
41b7f7630c
  1. 35
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/CustomerAgencyUserRoleDTO.java
  2. 30
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerAgencyUserRoleFormDTO.java
  3. 24
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RoleKeyValueResultDTO.java
  4. 9
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java
  5. 5
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java
  6. 25
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java
  7. 9
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/GovStaffRoleDao.java
  8. 8
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java
  9. 39
      epmet-user/epmet-user-server/src/main/java/com/epmet/redis/StaffRoleRedis.java
  10. 10
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java
  11. 52
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java
  12. 16
      epmet-user/epmet-user-server/src/main/resources/mapper/GovStaffRoleDao.xml
  13. 17
      epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml

35
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/CustomerAgencyUserRoleDTO.java

@ -0,0 +1,35 @@
package com.epmet.dto;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2021/6/15 10:00 上午
* @DESC
*/
@Data
public class CustomerAgencyUserRoleDTO implements Serializable {
/**
* 客户ID
*/
private String customerId;
/**
* 组织ID
*/
private String agencyId;
/**
* 工作人员ID
*/
private String staffId;
/**
* 角色
*/
private String roles;
}

30
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/CustomerAgencyUserRoleFormDTO.java

@ -0,0 +1,30 @@
package com.epmet.dto.form;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.List;
/**
* @Author zxc
* @DateTime 2021/6/15 2:54 下午
* @DESC
*/
@Data
public class CustomerAgencyUserRoleFormDTO implements Serializable {
private static final long serialVersionUID = -4880100913767612685L;
public interface CustomerAgencyUserRoleForm{}
@NotBlank(message = "客户ID不能为空",groups = CustomerAgencyUserRoleForm.class)
private String customerId;
/**
* 工作人员IDs
*/
@NotNull(message = "工作人员IDS不能为空",groups = CustomerAgencyUserRoleForm.class)
private List<String> staffIds;
}

24
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/result/RoleKeyValueResultDTO.java

@ -0,0 +1,24 @@
package com.epmet.dto.result;
import lombok.Data;
import java.io.Serializable;
/**
* @Author zxc
* @DateTime 2021/6/15 2:31 下午
* @DESC
*/
@Data
public class RoleKeyValueResultDTO implements Serializable {
private static final long serialVersionUID = 6511646803043360335L;
private String roleKey;
private String roleName;
private String orgId;
private String staffId;
}

9
epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java

@ -586,4 +586,13 @@ public interface EpmetUserOpenFeignClient {
*/
@PostMapping("/epmetuser/staffpatrol/patroltrack")
Result<List<PatrolTrackResultDTO>> patrolTrack(@RequestBody PatrolTrackFormDTO formDTO);
/**
* @Description 查询角色
* @Param formDTO
* @author zxc
* @date 2021/6/15 3:03 下午
*/
@PostMapping("/epmetuser/staffrole/getroles")
Result<List<CustomerAgencyUserRoleDTO>> getRoles(@RequestBody CustomerAgencyUserRoleFormDTO formDTO);
}

5
epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java

@ -404,4 +404,9 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "patrolTrack", formDTO);
}
@Override
public Result<List<CustomerAgencyUserRoleDTO>> getRoles(CustomerAgencyUserRoleFormDTO formDTO) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getRoles", formDTO);
}
}

25
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/StaffRoleController.java

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import com.epmet.commons.mybatis.entity.DataScope;
import com.epmet.commons.tools.utils.Result;
import com.epmet.commons.tools.validator.ValidatorUtils;
import com.epmet.dto.CustomerAgencyUserRoleDTO;
import com.epmet.dto.GovStaffRoleDTO;
import com.epmet.dto.StaffRoleDTO;
import com.epmet.dto.form.CommonUserFormDTO;
@ -189,4 +190,28 @@ public class StaffRoleController {
public Result<List<GridStaffResultDTO>> staffGridRole(@RequestBody List<GridStaffResultDTO> forms){
return new Result<List<GridStaffResultDTO>>().ok(staffRoleService.staffGridRole(forms));
}
/**
* @Description 补全缓存 工作人员角色
* @Param
* @author zxc
* @date 2021/6/15 2:05 下午
*/
@PostMapping("repairstaffrolecache")
public Result repairStaffRoleCache(){
return new Result();
}
/**
* @Description 查询角色
* @Param formDTO
* @author zxc
* @date 2021/6/15 3:03 下午
*/
@PostMapping("getroles")
public Result<List<CustomerAgencyUserRoleDTO>> getRoles(@RequestBody CustomerAgencyUserRoleFormDTO formDTO){
ValidatorUtils.validateEntity(formDTO, CustomerAgencyUserRoleFormDTO.CustomerAgencyUserRoleForm.class);
return new Result<List<CustomerAgencyUserRoleDTO>>().ok(staffRoleService.getRoles(formDTO));
}
}

9
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/GovStaffRoleDao.java

@ -21,6 +21,7 @@ import com.epmet.commons.mybatis.dao.BaseDao;
import com.epmet.dto.GovStaffRoleDTO;
import com.epmet.dto.result.GovStaffRoleResultDTO;
import com.epmet.dto.result.RoleInfoResultDTO;
import com.epmet.dto.result.RoleKeyValueResultDTO;
import com.epmet.dto.result.RoleResultDTO;
import com.epmet.entity.GovStaffRoleEntity;
import org.apache.ibatis.annotations.Mapper;
@ -79,4 +80,12 @@ public interface GovStaffRoleDao extends BaseDao<GovStaffRoleEntity> {
List<GovStaffRoleResultDTO> listRolesByRoleKey(@Param("roleKey") String roleKey);
Integer countRolesByCustomerId(@Param("customerId") String customerId);
/**
* @Description 查询role key name
* @Param roleIds
* @author zxc
* @date 2021/6/15 2:35 下午
*/
List<RoleKeyValueResultDTO> selectRoleKeyName(@Param("roleIds")List<String> roleIds);
}

8
epmet-user/epmet-user-server/src/main/java/com/epmet/dao/StaffRoleDao.java

@ -136,4 +136,12 @@ public interface StaffRoleDao extends BaseDao<StaffRoleEntity> {
* @date 2021/6/8 4:53 下午
*/
List<GridStaffResultDTO> staffGridRole(@Param("forms") List<GridStaffResultDTO> forms);
/**
* @Description 查询角色
* @Param userIds
* @author zxc
* @date 2021/6/15 3:51 下午
*/
List<RoleKeyValueResultDTO> getRolesByDB(@Param("userIds")List<String> userIds);
}

39
epmet-user/epmet-user-server/src/main/java/com/epmet/redis/StaffRoleRedis.java

@ -17,10 +17,17 @@
package com.epmet.redis;
import cn.hutool.core.bean.BeanUtil;
import com.epmet.commons.tools.redis.RedisUtils;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.dto.CustomerAgencyUserRoleDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Map;
import static com.epmet.commons.tools.redis.RedisUtils.NOT_EXPIRE;
/**
* 工作人员-角色关系表
*
@ -44,4 +51,36 @@ public class StaffRoleRedis {
return null;
}
/**
* @Description 查询工作人员的角色
* @Param customerId
* @Param userId
* @author zxc
* @date 2021/6/15 3:20 下午
*/
public CustomerAgencyUserRoleDTO getRole(String customerId, String userId){
String key = "epmet:staffrole:"+customerId+":"+userId;
Map<String, Object> roleMap = redisUtils.hGetAll(key);
boolean empty = roleMap.isEmpty();
if (!empty){
CustomerAgencyUserRoleDTO result = ConvertUtils.mapToEntity(roleMap, CustomerAgencyUserRoleDTO.class);
return result;
}
return null;
}
/**
* @Description 放入缓存角色
* @Param customerId
* @Param userId
* @Param dto
* @author zxc
* @date 2021/6/15 4:01 下午
*/
public void setRole(String customerId,String userId,CustomerAgencyUserRoleDTO dto){
String key = "epmet:staffrole:"+customerId+":"+userId;
Map<String, Object> map = BeanUtil.beanToMap(dto, false, true);
redisUtils.hMSet(key, map,NOT_EXPIRE);
}
}

10
epmet-user/epmet-user-server/src/main/java/com/epmet/service/StaffRoleService.java

@ -21,8 +21,10 @@ import com.epmet.commons.mybatis.entity.DataScope;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerAgencyUserRoleDTO;
import com.epmet.dto.StaffRoleDTO;
import com.epmet.dto.form.CommonUserFormDTO;
import com.epmet.dto.form.CustomerAgencyUserRoleFormDTO;
import com.epmet.dto.form.CustomerStaffRoleListFormDTO;
import com.epmet.dto.form.RolesUsersListFormDTO;
import com.epmet.dto.result.*;
@ -164,4 +166,12 @@ public interface StaffRoleService extends BaseService<StaffRoleEntity> {
* @date 2021/6/8 4:42 下午
*/
List<GridStaffResultDTO> staffGridRole(List<GridStaffResultDTO> forms);
/**
* @Description 查询角色
* @Param formDTO
* @author zxc
* @date 2021/6/15 3:03 下午
*/
List<CustomerAgencyUserRoleDTO> getRoles(CustomerAgencyUserRoleFormDTO formDTO);
}

52
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/StaffRoleServiceImpl.java

@ -28,8 +28,10 @@ import com.epmet.commons.tools.constant.FieldConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dao.GovStaffRoleTemplateDao;
import com.epmet.dao.StaffRoleDao;
import com.epmet.dto.CustomerAgencyUserRoleDTO;
import com.epmet.dto.StaffRoleDTO;
import com.epmet.dto.form.CommonUserFormDTO;
import com.epmet.dto.form.CustomerAgencyUserRoleFormDTO;
import com.epmet.dto.form.CustomerStaffRoleListFormDTO;
import com.epmet.dto.form.RolesUsersListFormDTO;
import com.epmet.dto.result.*;
@ -42,10 +44,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* 工作人员-角色关系表
@ -204,4 +204,48 @@ public class StaffRoleServiceImpl extends BaseServiceImpl<StaffRoleDao, StaffRol
return result;
}
/**
* @Description 查询角色
* @Param formDTO
* @author zxc
* @date 2021/6/15 3:03 下午
*/
@Override
public List<CustomerAgencyUserRoleDTO> getRoles(CustomerAgencyUserRoleFormDTO formDTO) {
List<CustomerAgencyUserRoleDTO> result = new ArrayList<>();
List<String> disUserIds = new ArrayList<>();
if (!CollectionUtils.isEmpty(formDTO.getStaffIds())){
List<String> staffIds = formDTO.getStaffIds();
String customerId = formDTO.getCustomerId();
staffIds.forEach(userId -> {
CustomerAgencyUserRoleDTO role = staffRoleRedis.getRole(customerId, userId);
if (null != role){
result.add(role);
}else {
disUserIds.add(userId);
}
});
if (!CollectionUtils.isEmpty(disUserIds)){
List<RoleKeyValueResultDTO> rolesByDB = baseDao.getRolesByDB(disUserIds);
if (!CollectionUtils.isEmpty(rolesByDB)){
Map<String, List<RoleKeyValueResultDTO>> groupByUserId = rolesByDB.stream().collect(Collectors.groupingBy(RoleKeyValueResultDTO::getStaffId));
groupByUserId.forEach((userId,list) -> {
CustomerAgencyUserRoleDTO dto = new CustomerAgencyUserRoleDTO();
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);
result.add(dto);
});
}
}
}
return result;
}
}

16
epmet-user/epmet-user-server/src/main/resources/mapper/GovStaffRoleDao.xml

@ -117,4 +117,20 @@
from gov_staff_role
where CUSTOMER_ID = #{customerId}
</select>
<!-- 查询role key 和 name -->
<select id="selectRoleKeyName" resultType="com.epmet.dto.result.RoleKeyValueResultDTO">
SELECT
ROLE_KEY,
ROLE_NAME
FROM
gov_staff_role
WHERE
DEL_FLAG = 0
AND (
<foreach collection="roleIds" item="roleId" separator=" OR ">
ID = #{roleId}
</foreach>
)
</select>
</mapper>

17
epmet-user/epmet-user-server/src/main/resources/mapper/StaffRoleDao.xml

@ -207,4 +207,21 @@
AND sr.STAFF_ID = #{s.staffId}
</foreach>
</select>
<!-- 查询角色 -->
<select id="getRolesByDB" resultType="com.epmet.dto.result.RoleKeyValueResultDTO">
SELECT
sr.ORG_ID,
gsr.ROLE_KEY,
gsr.ROLE_NAME,
sr.STAFF_ID
FROM staff_role sr
LEFT JOIN gov_staff_role gsr ON gsr.ID = sr.ROLE_ID AND gsr.DEL_FLAG = 0
WHERE sr.DEL_FLAG = 0
AND (
<foreach collection="userIds" item="userId" separator=" OR ">
sr.STAFF_ID = #{userId}
</foreach>
)
</select>
</mapper>

Loading…
Cancel
Save