permission

This commit is contained in:
xzb 2022-10-19 13:55:13 +08:00
parent b7a25fb070
commit 7de63057a3
3 changed files with 132 additions and 10 deletions

View File

@ -70,14 +70,22 @@ public class AcPermissionDistributeController {
} }
/** /**
* 生成分发二维码(用户扫码可以领取权限) * 生成分发二维码
* *
* @param pdId 权限分发id * @param pdId 权限分发id
*/ */
@GetMapping(path = "/{pdId}/qrCode") @GetMapping(path = "/{pdId}/qrCode")
public String generateQrCode(@PathVariable("pdId") Long pdId, @RequestAttribute(value = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginInfo) { public String generateQrCode(@PathVariable("pdId") Long pdId, @RequestAttribute(value = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginInfo) {
return this.permissionDistributeService.generateQrCode(pdId,loginInfo);
}
/**
* 微信扫码获取权限分发相关信息
* @param code 用户编码
* @param id 权限分发id
*/
@GetMapping
public void findPermissionDistributeInfo(String code, Long id){
return null;
} }
} }

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.services.permission; package club.joylink.rtss.services.permission;
import club.joylink.rtss.controller.advice.AuthenticateInterceptor;
import club.joylink.rtss.dao.OrgDAO; import club.joylink.rtss.dao.OrgDAO;
import club.joylink.rtss.dao.SysAccountDAO; import club.joylink.rtss.dao.SysAccountDAO;
import club.joylink.rtss.dao.permission.AcPermissionDAO; import club.joylink.rtss.dao.permission.AcPermissionDAO;
@ -12,7 +13,11 @@ import club.joylink.rtss.entity.permission.PermissionDistribute;
import club.joylink.rtss.entity.permission.PermissionDistributeExample; import club.joylink.rtss.entity.permission.PermissionDistributeExample;
import club.joylink.rtss.entity.permission.PermissionSubject; import club.joylink.rtss.entity.permission.PermissionSubject;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.QRCodeManager;
import club.joylink.rtss.services.WxApiService;
import club.joylink.rtss.services.auth.IAuthenticateService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.permission.*; import club.joylink.rtss.vo.permission.*;
import club.joylink.rtss.vo.permission.convertor.PermissionDistributeConvertor; import club.joylink.rtss.vo.permission.convertor.PermissionDistributeConvertor;
@ -22,10 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
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.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -48,6 +50,10 @@ public class PermissionDistributeService {
private SysAccountDAO sysAccountDAO; private SysAccountDAO sysAccountDAO;
@Autowired @Autowired
private OrgDAO orgDAO; private OrgDAO orgDAO;
@Autowired
private QRCodeManager qrCodeManager;
@Autowired
private IAuthenticateService authenticateService;
/** /**
* 创建权限分发 * 创建权限分发
@ -151,10 +157,15 @@ public class PermissionDistributeService {
PermissionDistribute permissionDistribute = this.permissionDistributeDAO.selectByPrimaryKey(pdId); PermissionDistribute permissionDistribute = this.permissionDistributeDAO.selectByPrimaryKey(pdId);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permissionDistribute, String.format("权限分发[id=%s]不存在", 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(PermissionDistributeStatusEnum.Valid.equals(PermissionDistributeStatusEnum.getItem(permissionDistribute.getStatus())), String.format("权限分发[id=%s]已失效", pdId));
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(permissionDistribute.getRemains()>0,String.format("权限分发[id=%s]剩余权限数量不足", pdId)); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(permissionDistribute.getRemains() > 0, String.format("权限分发[id=%s]剩余权限数量不足", pdId));
final LocalDateTime now = LocalDateTime.now();
final LocalDateTime startTime = permissionDistribute.getStartTime();
final LocalDateTime endTime = permissionDistribute.getEndTime();
final boolean isForever = permissionDistribute.getForever();
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(isForever ? now.isAfter(startTime) : now.isAfter(startTime) && now.isBefore(endTime), String.format("当前时间不在权限分发[id=%s]有效时间内", pdId));
// 校验权限 // 校验权限
Permission permission = this.permissionDAO.selectByPrimaryKey(permissionDistribute.getPermissionId()); Permission permission = this.permissionDAO.selectByPrimaryKey(permissionDistribute.getPermissionId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permission, String.format("权限分发[id=%s]的权限不存在", pdId, permissionDistribute.getPermissionId())); BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permission, String.format("权限分发[id=%s]的权限[id=%s]不存在", pdId, permissionDistribute.getPermissionId()));
// 校验主体 // 校验主体
Serializable subject = null; Serializable subject = null;
switch (subjectType) { switch (subjectType) {
@ -190,12 +201,35 @@ public class PermissionDistributeService {
// 从权限分发减掉已经分发的并修改权限分发状态 // 从权限分发减掉已经分发的并修改权限分发状态
PermissionDistribute updateDistribute = new PermissionDistribute(); PermissionDistribute updateDistribute = new PermissionDistribute();
updateDistribute.setId(permissionDistribute.getId()); updateDistribute.setId(permissionDistribute.getId());
updateDistribute.setRemains(permissionDistribute.getRemains()-permissionSubject.getAmount()); updateDistribute.setRemains(permissionDistribute.getRemains() - permissionSubject.getAmount());
if(updateDistribute.getRemains()<=0){ if (updateDistribute.getRemains() <= 0) {
updateDistribute.setStatus(PermissionDistributeStatusEnum.InValid.getValue()); updateDistribute.setStatus(PermissionDistributeStatusEnum.InValid.getValue());
} }
this.permissionDistributeDAO.updateByPrimaryKeySelective(updateDistribute); this.permissionDistributeDAO.updateByPrimaryKeySelective(updateDistribute);
// //
return permissionSubjectId; return permissionSubjectId;
} }
/**
* 生成权限分发二维码
*
* @param pdId 权限分发id
*/
public String generateQrCode(Long pdId, LoginUserInfoVO loginInfo) {
return qrCodeManager.getDistributeCode(pdId, loginInfo.getProject());
}
/**
* 微信扫码获取权限分发相关信息
*
* @param code 用户编码
* @param id 权限分发id
*/
public void scanPermissionDistributeInfo(String code, Long id) {
AccountVO accountVO = this.authenticateService.getOrCreateUserByWmcode(WxApiService.MiniApp.JoyLink, code);
PermissionDistribute permissionDistribute = this.permissionDistributeDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permissionDistribute, String.format("权限分发[id=%s]不存在", id));
Permission permission = this.permissionDAO.selectByPrimaryKey(permissionDistribute.getPermissionId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(null != permission, String.format("权限分发[id=%s]的权限[id=%s]不存在", id, permissionDistribute.getPermissionId()));
}
} }

View File

@ -0,0 +1,80 @@
package club.joylink.rtss.vo.permission;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 扫码获取权限分发的响应
*/
@Data
public class ScanPermissionDistributeInfoRspVo {
/**
* 扫码用户的账号id
*/
private Long accountId;
/**
* 权限分发id
*/
private Long pdId;
/**
* 关联权限id
*/
private Long permissionId;
/**
* 分发来自subject id(rts_permission_subject)
*/
private Long sourceSubjectId;
/**
* 总数量
*/
private Integer amount;
/**
* 剩余数量
*/
private Integer remains;
/**
* 是否永久true/false
*/
private Boolean forever;
/**
* 权限分发状态
*/
private Integer status;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 修改时间
*/
private LocalDateTime updateTime;
/**
* 开始时间
*/
private LocalDateTime startTime;
/**
* 结束时间
*/
private LocalDateTime endTime;
/**
* 创建者id
*/
private Long creatorId;
/**
* 备注描述
*/
private String dsc;
}