|
@@ -244,10 +244,25 @@ public class VppLicenseCodeServiceImpl implements VppLicenseCodeService {
|
|
|
|
|
|
@Override
|
|
|
public void cancelLicenceAssign(String licenceId) {
|
|
|
+ // 获取当前登录用户
|
|
|
+ VppMember user = vppMemberService.getCurrentUser();
|
|
|
LicenseCodes vppLicenseCode = licenseCodeMapper.selectByPrimaryKey(licenceId);
|
|
|
if (null == vppLicenseCode) {
|
|
|
- throw new BackendRuntimeException(VppLicenseCodeConstant.PARAMETER_ERROR);
|
|
|
+ throw new BackendRuntimeException(AuthConstant.EXCEPTION_MSG_TOKEN_IS_INVALID);
|
|
|
}
|
|
|
+ // 验证是否为本公司序列码
|
|
|
+ if (!vppLicenseCode.getCompanyId().equals(user.getCompanyId())) {
|
|
|
+ throw new BackendRuntimeException(VppLicenseCodeConstant.INSUFFICIENT_PERMISSIONS);
|
|
|
+ }
|
|
|
+ if (vppLicenseCode.getValidFlag() != 2 && vppLicenseCode.getValidFlag() != 3) {
|
|
|
+ throw new BackendRuntimeException(VppLicenseCodeConstant.LICENSE_STATUS_ERROR);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(vppLicenseCode.getVppMemberId()) || null == vppLicenseCode.getProductId()) {
|
|
|
+ throw new BackendRuntimeException(VppLicenseCodeConstant.LICENSE_STATUS_ERROR);
|
|
|
+ }
|
|
|
+ // 获取被授权人和产品信息
|
|
|
+ VppMember vppMember = vppMemberService.getById(vppLicenseCode.getVppMemberId());
|
|
|
+ Products products = productService.getById(vppLicenseCode.getProductId());
|
|
|
vppLicenseCode.setMemberId(null);
|
|
|
vppLicenseCode.setVppMemberId(null);
|
|
|
vppLicenseCode.setValidFlag(4);
|
|
@@ -256,6 +271,9 @@ public class VppLicenseCodeServiceImpl implements VppLicenseCodeService {
|
|
|
licenseCodeMapper.updateByPrimaryKey(vppLicenseCode);
|
|
|
// 解绑激活设备
|
|
|
vppDeviceService.unBindByMemberId(null, Collections.singletonList(vppLicenseCode.getCdkey()));
|
|
|
+ // 发送邮件
|
|
|
+ String text = String.format(CaptchaActionEnum.CANCEL_LICENSE_ASSIGN.text(), vppMember.getEmail(), products.getName(), products.getName(), user.getEmail()) + CommonConstant.signHtml;
|
|
|
+ emailUtils.sendMail(CaptchaActionEnum.CANCEL_LICENSE_ASSIGN.subject(), text, Collections.singletonList(vppMember.getEmail()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -284,7 +302,7 @@ public class VppLicenseCodeServiceImpl implements VppLicenseCodeService {
|
|
|
continue;
|
|
|
}
|
|
|
// 查询产品
|
|
|
- Products product = productService.getByName(productName);
|
|
|
+ Products product = productService.getByName(productName.trim());
|
|
|
if (null == product) {
|
|
|
continue;
|
|
|
}
|
|
@@ -293,7 +311,7 @@ public class VppLicenseCodeServiceImpl implements VppLicenseCodeService {
|
|
|
continue;
|
|
|
}
|
|
|
// 查询用户,验证用户是否为本公司
|
|
|
- VppMember vppMember = vppMemberService.getByAccount(email);
|
|
|
+ VppMember vppMember = vppMemberService.getByAccount(email.trim());
|
|
|
if (null == vppMember || !vppMember.getCompanyId().equals(user.getCompanyId())) {
|
|
|
continue;
|
|
|
}
|
|
@@ -304,20 +322,28 @@ public class VppLicenseCodeServiceImpl implements VppLicenseCodeService {
|
|
|
if (CollectionUtils.isEmpty(vppLicenseCodeList)) {
|
|
|
continue;
|
|
|
}
|
|
|
- LicenseCodes vppLicenseCode = vppLicenseCodeList.stream().filter(c -> c.getValidFlag() != 0 &&
|
|
|
- (null == c.getEndUpAt() || c.getEndUpAt().compareTo(new Date()) > 0)).findFirst().orElse(null);
|
|
|
- if (null == vppLicenseCode) {
|
|
|
+ List<LicenseCodes> collect = vppLicenseCodeList.stream().filter(c -> c.getValidFlag() != 0 &&
|
|
|
+ (null == c.getEndUpAt() || c.getEndUpAt().compareTo(new Date()) > 0)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(collect)) {
|
|
|
continue;
|
|
|
}
|
|
|
- vppLicenseCode.setMemberId(null);
|
|
|
- vppLicenseCode.setVppMemberId(null);
|
|
|
- vppLicenseCode.setUsedTimes(Short.valueOf("0"));
|
|
|
- vppLicenseCode.setValidFlag(4);
|
|
|
- vppLicenseCode.setUpdatedAt(new Date());
|
|
|
- licenseCodeMapper.updateByPrimaryKey(vppLicenseCode);
|
|
|
- // 解绑激活设备
|
|
|
- vppDeviceService.unBindByMemberId(null, Collections.singletonList(vppLicenseCode.getCdkey()));
|
|
|
- count++;
|
|
|
+ for (LicenseCodes vppLicenseCode : collect) {
|
|
|
+ if (null == vppLicenseCode) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ vppLicenseCode.setMemberId(null);
|
|
|
+ vppLicenseCode.setVppMemberId(null);
|
|
|
+ vppLicenseCode.setUsedTimes(Short.valueOf("0"));
|
|
|
+ vppLicenseCode.setValidFlag(4);
|
|
|
+ vppLicenseCode.setUpdatedAt(new Date());
|
|
|
+ licenseCodeMapper.updateByPrimaryKey(vppLicenseCode);
|
|
|
+ // 解绑激活设备
|
|
|
+ vppDeviceService.unBindByMemberId(null, Collections.singletonList(vppLicenseCode.getCdkey()));
|
|
|
+ // 发送邮件
|
|
|
+ String text = String.format(CaptchaActionEnum.CANCEL_LICENSE_ASSIGN.text(), vppMember.getEmail(), product.getName(), product.getName(), user.getEmail()) + CommonConstant.signHtml;
|
|
|
+ emailUtils.sendMail(CaptchaActionEnum.CANCEL_LICENSE_ASSIGN.subject(), text, Collections.singletonList(vppMember.getEmail()));
|
|
|
+ count++;
|
|
|
+ }
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
log.error("批量取消授权码读取数据失败,{}", e.getMessage());
|