Browse Source

修改用户时候,更新角色的缓存信息bug修复

master
wxz 5 years ago
parent
commit
d5afc43c74
  1. 20
      epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java
  2. 12
      epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/GovStaffRoleFormDTO.java
  3. 14
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/EpmetUserOpenFeignClient.java
  4. 11
      epmet-user/epmet-user-client/src/main/java/com/epmet/feign/fallback/EpmetUserOpenFeignClientFallback.java
  5. 27
      epmet-user/epmet-user-server/src/main/java/com/epmet/controller/GovStaffRoleController.java
  6. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/dao/GovStaffRoleDao.java
  7. 4
      epmet-user/epmet-user-server/src/main/java/com/epmet/feign/AuthFeignClient.java
  8. 2
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/GovStaffRoleService.java
  9. 5
      epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/GovStaffRoleServiceImpl.java
  10. 9
      epmet-user/epmet-user-server/src/main/resources/mapper/GovStaffRoleDao.xml

20
epmet-auth/src/main/java/com/epmet/service/impl/GovLoginServiceImpl.java

@ -22,6 +22,7 @@ import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.feign.EpmetMessageOpenFeignClient;
import com.epmet.feign.EpmetUserFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.GovOrgFeignClient;
import com.epmet.jwt.JwtTokenProperties;
import com.epmet.jwt.JwtTokenUtils;
@ -62,6 +63,8 @@ public class GovLoginServiceImpl implements GovLoginService {
private GovOrgFeignClient govOrgFeignClient;
@Autowired
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient;
@Autowired
private EpmetUserOpenFeignClient userOpenFeignClient;
/**
* @param formDTO
@ -297,7 +300,22 @@ public class GovLoginServiceImpl implements GovLoginService {
if (userDetails == null) {
return;
}
List<GovTokenDto.Role> roles = queryGovStaffRoles(staffId, orgId);
GovStaffRoleFormDTO form = new GovStaffRoleFormDTO();
form.setRoleIdList(roleIds);
Result<List<GovStaffRoleResultDTO>> result = userOpenFeignClient.getByIds(form);
if (!result.success()) {
throw new RenException("更新缓存中的角色列表失败:" + result.getInternalMsg());
}
List<GovTokenDto.Role> roles = result.getData().stream().map(roleDto -> {
GovTokenDto.Role role = new GovTokenDto.Role();
role.setRoleName(roleDto.getRoleName());
role.setRoleKey(roleDto.getRoleKey());
role.setId(roleDto.getRoleId());
return role;
}).collect(Collectors.toList());
userDetails.setRoleList(roles);
cpUserDetailRedis.set(userDetails, jwtTokenProperties.getExpire());
}

12
epmet-user/epmet-user-client/src/main/java/com/epmet/dto/form/GovStaffRoleFormDTO.java

@ -0,0 +1,12 @@
package com.epmet.dto.form;
import lombok.Data;
import java.util.List;
@Data
public class GovStaffRoleFormDTO {
private List<String> roleIdList;
}

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

@ -4,12 +4,10 @@ import com.epmet.commons.tools.constant.ServiceConstant;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerStaffDTO;
import com.epmet.dto.form.CustomerStaffRoleListFormDTO;
import com.epmet.dto.form.GovStaffRoleFormDTO;
import com.epmet.dto.form.LoginUserDetailsFormDTO;
import com.epmet.dto.form.TagCustomerFormDTO;
import com.epmet.dto.result.CustomerStaffRoleListResultDTO;
import com.epmet.dto.result.CustomerStaffRoleResultDTO;
import com.epmet.dto.result.LoginUserDetailsResultDTO;
import com.epmet.dto.result.TagCustomerResultDTO;
import com.epmet.dto.result.*;
import com.epmet.feign.fallback.EpmetUserOpenFeignClientFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
@ -24,6 +22,7 @@ import java.util.List;
* @author yinzuomei@elink-cn.com
* @date 2020/6/4 13:09
*/
//@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserOpenFeignClientFallback.class, url = "localhost:8087")
@FeignClient(name = ServiceConstant.EPMET_USER_SERVER, fallback = EpmetUserOpenFeignClientFallback.class)
public interface EpmetUserOpenFeignClient {
@ -72,4 +71,11 @@ public interface EpmetUserOpenFeignClient {
@PostMapping("/epmetuser/user/getcustomeridbyuserid")
Result<TagCustomerResultDTO> getCustomerIdByUserId(@RequestBody TagCustomerFormDTO formDTO);
/**
* 根据角色id列表批量查询角色信息
* @param form
* @return
*/
@PostMapping("/epmetuser/govstaffrole/getbyids")
Result<List<GovStaffRoleResultDTO>> getByIds(@RequestBody GovStaffRoleFormDTO form);
}

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

@ -5,12 +5,10 @@ import com.epmet.commons.tools.utils.ModuleUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.CustomerStaffDTO;
import com.epmet.dto.form.CustomerStaffRoleListFormDTO;
import com.epmet.dto.form.GovStaffRoleFormDTO;
import com.epmet.dto.form.LoginUserDetailsFormDTO;
import com.epmet.dto.form.TagCustomerFormDTO;
import com.epmet.dto.result.CustomerStaffRoleListResultDTO;
import com.epmet.dto.result.CustomerStaffRoleResultDTO;
import com.epmet.dto.result.LoginUserDetailsResultDTO;
import com.epmet.dto.result.TagCustomerResultDTO;
import com.epmet.dto.result.*;
import com.epmet.feign.EpmetUserOpenFeignClient;
import org.springframework.stereotype.Component;
@ -50,4 +48,9 @@ public class EpmetUserOpenFeignClientFallback implements EpmetUserOpenFeignClien
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getCustomerIdByUserId", formDTO);
}
@Override
public Result<List<GovStaffRoleResultDTO>> getByIds(GovStaffRoleFormDTO form) {
return ModuleUtils.feignConError(ServiceConstant.EPMET_USER_SERVER, "getById", form);
}
}

27
epmet-user/epmet-user-server/src/main/java/com/epmet/controller/GovStaffRoleController.java

@ -1,17 +1,20 @@
package com.epmet.controller;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.commons.tools.utils.Result;
import com.epmet.dto.RoleDTO;
import com.epmet.dto.form.GovStaffRoleFormDTO;
import com.epmet.dto.result.GovStaffRoleResultDTO;
import com.epmet.dto.result.GovStaffRoleTemplateDTO;
import com.epmet.entity.GovStaffRoleEntity;
import com.epmet.service.GovStaffRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@RequestMapping("govstaffrole")
@RestController
@ -40,4 +43,20 @@ public class GovStaffRoleController {
List<GovStaffRoleTemplateDTO> roleTemplates = govStaffRoleService.listRoleTemplates();
return new Result().ok(roleTemplates);
}
/**
* 使用id列表查询角色列表
* @param form
* @return
*/
@PostMapping("getbyids")
public Result<List<GovStaffRoleResultDTO>> getByIds(@RequestBody GovStaffRoleFormDTO form) {
List<GovStaffRoleResultDTO> roleDTOS = new ArrayList<>();
List<String> roleIdList = form.getRoleIdList();
if (!CollectionUtils.isEmpty(roleIdList)) {
roleDTOS = roleIdList.stream().map(roleId -> govStaffRoleService.getDTOById(roleId)).collect(Collectors.toList());
}
return new Result<List<GovStaffRoleResultDTO>>().ok(roleDTOS);
}
}

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

@ -59,4 +59,6 @@ public interface GovStaffRoleDao extends BaseDao<GovStaffRoleEntity> {
GovStaffRoleDTO getRoleByCustomerIdAndRoleKey(@Param("customerId") String customerId, @Param("roleKey") String roleKey);
List<GovStaffRoleResultDTO> listRolesByCustomer(@Param("customerId") String customerId);
GovStaffRoleResultDTO getDTOById(@Param("roleId") String roleId);
}

4
epmet-user/epmet-user-server/src/main/java/com/epmet/feign/AuthFeignClient.java

@ -8,8 +8,8 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(name = ServiceConstant.EPMET_AUTH_SERVER, fallback = AuthFeignClientCallback.class, url = "localhost:8081")
//@FeignClient(name = ServiceConstant.EPMET_AUTH_SERVER, fallback = AuthFeignClientCallback.class)
//@FeignClient(name = ServiceConstant.EPMET_AUTH_SERVER, fallback = AuthFeignClientCallback.class, url = "localhost:8081")
@FeignClient(name = ServiceConstant.EPMET_AUTH_SERVER, fallback = AuthFeignClientCallback.class)
public interface AuthFeignClient {
/**

2
epmet-user/epmet-user-server/src/main/java/com/epmet/service/GovStaffRoleService.java

@ -125,4 +125,6 @@ public interface GovStaffRoleService extends BaseService<GovStaffRoleEntity> {
List<GovStaffRoleResultDTO> listRolesByCustomer(String customerId);
List<GovStaffRoleTemplateDTO> listRoleTemplates();
GovStaffRoleResultDTO getDTOById(String roleId);
}

5
epmet-user/epmet-user-server/src/main/java/com/epmet/service/impl/GovStaffRoleServiceImpl.java

@ -176,4 +176,9 @@ public class GovStaffRoleServiceImpl extends BaseServiceImpl<GovStaffRoleDao, Go
public List<GovStaffRoleTemplateDTO> listRoleTemplates() {
return govStaffRoleTemplateDao.listValidateRoles();
}
@Override
public GovStaffRoleResultDTO getDTOById(String roleId) {
return govStaffRoleDao.getDTOById(roleId);
}
}

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

@ -59,4 +59,13 @@
FROM gov_staff_role r
WHERE r.CUSTOMER_ID = #{customerId}
</select>
<select id="getDTOById" resultType="com.epmet.dto.result.GovStaffRoleResultDTO">
SELECT gsr.ID AS roleId,
gsr.ROLE_KEY AS roleKey,
gsr.ROLE_NAME AS roleName,
gsr.CUSTOMER_ID AS customerId,
gsr.ORG_TYPE AS orgType
FROM gov_staff_role gsr WHERE ID = #{roleId}
</select>
</mapper>
Loading…
Cancel
Save