diff --git a/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java new file mode 100644 index 0000000000..b800d6bc1a --- /dev/null +++ b/epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java @@ -0,0 +1,39 @@ +package com.epmet.dto.form; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.util.List; + +@Data +public class StaffPermCacheFormDTO { + + /** + * 更新权限缓存分组 + */ + public interface UpdatePermissionCache {} + + /** + * 工作人员 id + */ + @NotBlank(message = "工作人员ID不能为空", groups = {UpdatePermissionCache.class}) + private String staffId; + + /** + * 登录头信息app + */ + @NotBlank(message = "登录头信息app不能为空", groups = {UpdatePermissionCache.class}) + private String app; + + /** + * 登录头信息client + */ + @NotBlank(message = "登录头信息client不能为空", groups = {UpdatePermissionCache.class}) + private String client; + + /** + * 权限列表 + */ + private List permissions; + +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java new file mode 100644 index 0000000000..0f7eaf4920 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java @@ -0,0 +1,43 @@ +package com.epmet.controller; + +import com.epmet.commons.tools.utils.Result; +import com.epmet.commons.tools.validator.ValidatorUtils; +import com.epmet.dto.form.StaffPermCacheFormDTO; +import com.epmet.service.AccessService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 权限相关Api + * @Author wxz + * @Description + * @Date 2020/4/23 17:54 + **/ +@RestController +@RequestMapping("access") +public class AccessController { + + @Autowired + private AccessService accessService; + + /** + * 更新工作人员权限缓存 + * @param staffPermCacheFormDTO + * @return + */ + @PostMapping("updatepermissioncache") + public Result updatePermissionCache(@RequestBody StaffPermCacheFormDTO staffPermCacheFormDTO) { + ValidatorUtils.validateEntity(staffPermCacheFormDTO, StaffPermCacheFormDTO.UpdatePermissionCache.class); + String staffId = staffPermCacheFormDTO.getStaffId(); + String app = staffPermCacheFormDTO.getApp(); + String client = staffPermCacheFormDTO.getClient(); + List permissions = staffPermCacheFormDTO.getPermissions(); + accessService.updatePermissionCache(staffId, app, client, permissions); + return new Result(); + } +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java new file mode 100644 index 0000000000..cbf51355d1 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java @@ -0,0 +1,12 @@ +package com.epmet.service; + +import java.util.List; + +public interface AccessService { + /** + * 更新权限缓存 + * @param staffId + * @param permissions + */ + void updatePermissionCache(String staffId, String app, String client, List permissions); +} diff --git a/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java new file mode 100644 index 0000000000..e391283e94 --- /dev/null +++ b/epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java @@ -0,0 +1,40 @@ +package com.epmet.service.impl; + +import com.epmet.commons.tools.security.dto.GovTokenDto; +import com.epmet.commons.tools.utils.CpUserDetailRedis; +import com.epmet.service.AccessService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class AccessServiceImpl implements AccessService { + + private static Logger logger = LoggerFactory.getLogger(AccessServiceImpl.class); + + @Autowired + private CpUserDetailRedis cpUserDetailRedis; + + /** + * 更新权限缓存 + * @param staffId + * @param permissions + */ + @Override + public void updatePermissionCache(String staffId, String app, String client, List permissions) { + GovTokenDto govTokenDto = cpUserDetailRedis.get(app, client, staffId, GovTokenDto.class); + if (govTokenDto == null) { + logger.warn("更新[{}]用户缓存:Redis中不存在该用户TokenDto缓存信息", staffId); + return ; + } + govTokenDto.setPermissions(permissions); + + // 将新的TokenDto更新到redis中 + long expire = cpUserDetailRedis.getExpire(app, client, staffId); + cpUserDetailRedis.set(govTokenDto, expire); + logger.warn("更新[{}]用户缓存成功。", staffId); + } +}