Browse Source

1.新增:新增更新工作人员权限缓存接口

dev_shibei_match
wxz 5 years ago
parent
commit
34a0857083
  1. 39
      epmet-module/gov-access/gov-access-client/src/main/java/com/epmet/dto/form/StaffPermCacheFormDTO.java
  2. 43
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/controller/AccessController.java
  3. 12
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/AccessService.java
  4. 40
      epmet-module/gov-access/gov-access-server/src/main/java/com/epmet/service/impl/AccessServiceImpl.java

39
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<String> permissions;
}

43
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<String> permissions = staffPermCacheFormDTO.getPermissions();
accessService.updatePermissionCache(staffId, app, client, permissions);
return new Result();
}
}

12
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<String> permissions);
}

40
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<String> 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);
}
}
Loading…
Cancel
Save