permission
This commit is contained in:
parent
3eae7d7672
commit
b7a25fb070
@ -5,10 +5,7 @@ import club.joylink.rtss.services.permission.PermissionDistributeService;
|
||||
import club.joylink.rtss.vo.AccountVO;
|
||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
import club.joylink.rtss.vo.permission.CreatePermissionDistributeReqVo;
|
||||
import club.joylink.rtss.vo.permission.CreatePermissionDistributeRspVo;
|
||||
import club.joylink.rtss.vo.permission.FindPermissionDistributeByPageReqVo;
|
||||
import club.joylink.rtss.vo.permission.PermissionDistributeRspVo;
|
||||
import club.joylink.rtss.vo.permission.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -52,10 +49,11 @@ public class AcPermissionDistributeController {
|
||||
*
|
||||
* @param pdId 权限分发id
|
||||
* @param receiver 权限领取者,当前登录用户
|
||||
* @return 返回生成的权限主体id
|
||||
*/
|
||||
@GetMapping("/{pdId}/get")
|
||||
public void userReceiveFromPermissionDistribute(@PathVariable("pdId") Long pdId, @RequestAttribute AccountVO receiver) {
|
||||
|
||||
public Long userReceiveFromPermissionDistribute(@PathVariable("pdId") Long pdId, @RequestAttribute AccountVO receiver) {
|
||||
return this.permissionDistributeService.subjectAcceptFromPermissionDistribute(pdId, PermissionSubjectTypeEnum.user, receiver.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,10 +61,12 @@ public class AcPermissionDistributeController {
|
||||
*
|
||||
* @param pdId 权限分发id
|
||||
* @param subjectType 主体类型,其值为(user,org),user-一般用户,org-组织
|
||||
* @return 返回生成的权限主体id
|
||||
*/
|
||||
@PostMapping("/{pdId}/to/{subjectType}/{subjectId}")
|
||||
public void permissionDistributeToSubject(@PathVariable("pdId") Long pdId, @PathVariable("subjectType") String subjectType, @PathVariable("subjectId") Long subjectId) {
|
||||
|
||||
public Long permissionDistributeToSubject(@PathVariable("pdId") Long pdId, @PathVariable("subjectType") String subjectType, @PathVariable("subjectId") Long subjectId) {
|
||||
final PermissionSubjectTypeEnum subjectTypeEnum = PermissionSubjectTypeEnum.valueOf(subjectType);
|
||||
return this.permissionDistributeService.subjectAcceptFromPermissionDistribute(pdId, subjectTypeEnum, subjectId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,12 +1,16 @@
|
||||
package club.joylink.rtss.services.permission;
|
||||
|
||||
import club.joylink.rtss.dao.OrgDAO;
|
||||
import club.joylink.rtss.dao.SysAccountDAO;
|
||||
import club.joylink.rtss.dao.permission.AcPermissionDAO;
|
||||
import club.joylink.rtss.dao.permission.PermissionSubjectDAO;
|
||||
import club.joylink.rtss.dao.permission.RtsPermissionDistributeDAO;
|
||||
import club.joylink.rtss.entity.Org;
|
||||
import club.joylink.rtss.entity.SysAccount;
|
||||
import club.joylink.rtss.entity.permission.Permission;
|
||||
import club.joylink.rtss.entity.permission.PermissionDistribute;
|
||||
import club.joylink.rtss.entity.permission.PermissionDistributeExample;
|
||||
import club.joylink.rtss.entity.permission.PermissionSubject;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.vo.AccountVO;
|
||||
import club.joylink.rtss.vo.client.PageVO;
|
||||
@ -23,6 +27,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -41,6 +46,8 @@ public class PermissionDistributeService {
|
||||
private AcPermissionDAO permissionDAO;
|
||||
@Autowired
|
||||
private SysAccountDAO sysAccountDAO;
|
||||
@Autowired
|
||||
private OrgDAO orgDAO;
|
||||
|
||||
/**
|
||||
* 创建权限分发
|
||||
@ -71,7 +78,7 @@ public class PermissionDistributeService {
|
||||
//
|
||||
this.permissionDistributeDAO.insertSelective(pd);
|
||||
//
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null!=pd.getId(),"permissionDistributeDAO insert 未生成id返回");
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != pd.getId(), "permissionDistributeDAO insert 未生成id返回");
|
||||
CreatePermissionDistributeRspVo rsp = new CreatePermissionDistributeRspVo();
|
||||
rsp.setPdId(pd.getId());
|
||||
rsp.setPermissionId(pd.getPermissionId());
|
||||
@ -126,10 +133,69 @@ public class PermissionDistributeService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void invalidatePermissionDistributeImmediately(Long pdId) {
|
||||
PermissionDistribute permissionDistribute = this.permissionDistributeDAO.selectByPrimaryKey(pdId);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permissionDistribute, String.format("权限分发[id=%s]不存在"));
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permissionDistribute, String.format("权限分发[id=%s]不存在", pdId));
|
||||
PermissionDistribute invalid = new PermissionDistribute();
|
||||
invalid.setId(pdId);
|
||||
invalid.setStatus(PermissionDistributeStatusEnum.InValid.getValue());
|
||||
this.permissionDistributeDAO.updateByPrimaryKeySelective(invalid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 主体从权限分发获取权限
|
||||
*
|
||||
* @return 返回权限主体id
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long subjectAcceptFromPermissionDistribute(Long pdId, PermissionSubjectTypeEnum subjectType, Long subjectId) {
|
||||
// 校验分发
|
||||
PermissionDistribute permissionDistribute = this.permissionDistributeDAO.selectByPrimaryKey(pdId);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permissionDistribute, String.format("权限分发[id=%s]不存在", pdId));
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(PermissionDistributeStatusEnum.Valid.equals(PermissionDistributeStatusEnum.getItem(permissionDistribute.getStatus())), String.format("权限分发[id=%s]已失效", pdId));
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(permissionDistribute.getRemains()>0,String.format("权限分发[id=%s]剩余权限数量不足", pdId));
|
||||
// 校验权限
|
||||
Permission permission = this.permissionDAO.selectByPrimaryKey(permissionDistribute.getPermissionId());
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permission, String.format("权限分发[id=%s]的权限不存在", pdId, permissionDistribute.getPermissionId()));
|
||||
// 校验主体
|
||||
Serializable subject = null;
|
||||
switch (subjectType) {
|
||||
case org: {
|
||||
subject = this.orgDAO.selectByPrimaryKey(subjectId);
|
||||
}
|
||||
;
|
||||
break;
|
||||
case user: {
|
||||
subject = this.sysAccountDAO.selectByPrimaryKey(subjectId);
|
||||
}
|
||||
;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != subject, String.format("权限分发[id=%s]的主体[type=%s id=%s]不存在", pdId, subjectType.name(), subjectId));
|
||||
//分发权限到主体
|
||||
PermissionSubject permissionSubject = new PermissionSubject();
|
||||
permissionSubject.setPermissionId(permissionDistribute.getPermissionId());
|
||||
permissionSubject.setSubjectType(subjectType.name());
|
||||
permissionSubject.setSubjectId(subjectId);
|
||||
permissionSubject.setAmount(permissionDistribute.getRemains());
|
||||
permissionSubject.setRemains(permissionSubject.getAmount());
|
||||
permissionSubject.setStatus(PermissionSubjectStatusEnum.Valid.name());
|
||||
permissionSubject.setForever(permissionDistribute.getForever());
|
||||
permissionSubject.setStartTime(permissionDistribute.getStartTime());
|
||||
permissionSubject.setEndTime(permissionDistribute.getEndTime());
|
||||
permissionSubject.setDistributeId(permissionDistribute.getId());
|
||||
permissionSubject.setCreateTime(LocalDateTime.now());
|
||||
this.permissionSubjectDAO.insertSelective(permissionSubject);
|
||||
final Long permissionSubjectId = permissionSubject.getId();
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permissionSubjectId, "permissionSubjectDAO insert 未返回id");
|
||||
// 从权限分发减掉已经分发的并修改权限分发状态
|
||||
PermissionDistribute updateDistribute = new PermissionDistribute();
|
||||
updateDistribute.setId(permissionDistribute.getId());
|
||||
updateDistribute.setRemains(permissionDistribute.getRemains()-permissionSubject.getAmount());
|
||||
if(updateDistribute.getRemains()<=0){
|
||||
updateDistribute.setStatus(PermissionDistributeStatusEnum.InValid.getValue());
|
||||
}
|
||||
this.permissionDistributeDAO.updateByPrimaryKeySelective(updateDistribute);
|
||||
//
|
||||
return permissionSubjectId;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
package club.joylink.rtss.vo.permission;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 权限主体状态,1-有效,2-无效
|
||||
*/
|
||||
public enum PermissionSubjectStatusEnum {
|
||||
Valid(1),
|
||||
InValid(2),
|
||||
;
|
||||
private Integer value;
|
||||
|
||||
private PermissionSubjectStatusEnum(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PermissionSubjectStatusEnum getItem(Integer value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@JsonValue
|
||||
public Integer getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
private static Map<Integer, PermissionSubjectStatusEnum> map = new HashMap<>();
|
||||
|
||||
static {
|
||||
for (PermissionSubjectStatusEnum t : values()) {
|
||||
map.put(t.value, t);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package club.joylink.rtss.vo.permission;
|
||||
|
||||
/**
|
||||
* 主体类型,其值为(user,org),user-一般用户,org-组织
|
||||
*/
|
||||
public enum PermissionSubjectTypeEnum {
|
||||
user,//用户
|
||||
org;//组织
|
||||
}
|
Loading…
Reference in New Issue
Block a user