浏览代码

Merge remote-tracking branch 'origin/develop' into develop

tangxiangan 2 年之前
父节点
当前提交
83f2d7e959

+ 6 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/constant/VppLicenseCodeConstant.java

@@ -9,5 +9,11 @@ public interface VppLicenseCodeConstant {
 
     String SUCCESS_MSG_ASSIGN = " Assign Success!";
 
+    String CANCEL_ASSIGN = " Cancel Success!";
+
     String PARAMETER_ERROR = "Parameter error";
+
+    String INSUFFICIENT_PERMISSIONS = "Insufficient permissions";
+
+    String LICENSE_STATUS_ERROR = "License status error";
 }

+ 3 - 1
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/constant/VppMemberConstant.java

@@ -28,7 +28,9 @@ public interface VppMemberConstant {
 
     String PASSWORD_UPDATE_SUCCESS = "Password updated successfully";
 
-    String MEMBEU_HAS_JOINED = "Member has joined a non-default team";
+    String MEMBEU_HAS_JOINED = "The Member has joined another team.";
+
+    String MEMBEU_HAS_ADMIN = "The member is already an admin of this team.";
 
     String FILE_ERROR = "File Error";
 

+ 2 - 2
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/controller/VppLicenseCodeController.java

@@ -136,13 +136,13 @@ public class VppLicenseCodeController {
     @PostMapping("/cancelLicenceAssign")
     public ResultMap<Boolean> cancelLicenceAssign(@RequestParam String licenceId) {
         vppLicenseCodeService.cancelLicenceAssign(licenceId);
-        return new ResultMap<>(CommonConstant.SUCCESS, VppLicenseCodeConstant.SUCCESS_MSG_ASSIGN, Boolean.TRUE);
+        return new ResultMap<>(CommonConstant.SUCCESS, VppLicenseCodeConstant.CANCEL_ASSIGN, Boolean.TRUE);
     }
 
     @PreCheckRole(roles = {RoleEnum.TEAM_ADMIN,RoleEnum.SUPER_ADMIN})
     @PostMapping("/cancelLicenceAssignBatch")
     public ResultMap<String> cancelLicenceAssignBatch(@RequestParam("file") MultipartFile file) {
-        return new ResultMap<>(CommonConstant.SUCCESS, VppLicenseCodeConstant.SUCCESS_MSG_ASSIGN, vppLicenseCodeService.cancelLicenceAssignBatch(file));
+        return new ResultMap<>(CommonConstant.SUCCESS, VppLicenseCodeConstant.CANCEL_ASSIGN, vppLicenseCodeService.cancelLicenceAssignBatch(file));
     }
 
     /**

+ 12 - 7
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/enums/CaptchaActionEnum.java

@@ -63,11 +63,11 @@ public enum CaptchaActionEnum {
             "<span style=\"font-size:16px;\">To get started, sign in to </span></span><span style=\"font-size:16px;color:#0000FF;\"><a href=\"%s\" target=\"_blank\">PDF Tech Console</a></span><span style=\"font-size:10pt;\"><span style=\"font-size:16px;\">. </span><br />\n" +
             "</span></span>"),
     //邀请普通用户加入团队
-    JOIN_TEAM_FOR_MEMBER("4", "团队邀请", "%s has invited you to join your team for PDF Tech products", "<span style=\"font-size:14px;\">Dear&nbsp;</span><span style=\"color:#337FE5;font-size:14px;\">%s</span><span style=\"font-size:14px;\">,</span><br />\n" +
-            "<span style=\"font-size:14px;\"> The&nbsp;admin&nbsp;of&nbsp;<span style=\"color:#337FE5;\">%s</span>&nbsp;and&nbsp;your&nbsp;team&nbsp;are&nbsp;waiting&nbsp;for&nbsp;you&nbsp;to&nbsp;join&nbsp;your&nbsp;team&nbsp;to&nbsp;access&nbsp;<span style=\"color:#E53333;\">PDF&nbsp;Tech&nbsp;products</span>.</span><br />\n" +
-            "<span style=\"font-size:14px;\"> Work&nbsp;with&nbsp;them&nbsp;on&nbsp;your&nbsp;organization.</span><br />\n" +
-            "<span style=\"font-size:14px;\"> <span style=\"color:#337FE5;\"><a href=\"%s\" target=\"_blank\">Click&nbsp;here&nbsp;to&nbsp;join&nbsp;now</a></span><span>!&nbsp;(The&nbsp;link&nbsp;expires&nbsp;in&nbsp;<span style=\"color:#E53333;\">72&nbsp;hours</span>)</span></span><br />\n" +
-            "<span style=\"font-size:14px;\"> After&nbsp;you&nbsp;click&nbsp;to&nbsp;agree&nbsp;to&nbsp;join&nbsp;the&nbsp;organization,&nbsp;you&nbsp;can&nbsp;wait&nbsp;for&nbsp;the&nbsp;administrator&nbsp;to&nbsp;assign&nbsp;you&nbsp;a&nbsp;license&nbsp;or&nbsp;actively&nbsp;contact&nbsp;your&nbsp;enterprise&nbsp;administrator&nbsp;to&nbsp;assign&nbsp;you&nbsp;a&nbsp;license.</span>"),
+    JOIN_TEAM_FOR_MEMBER("4", "团队邀请", "%s has invited you to join your team for PDF Tech products", "<span style=\"font-size:16px;\">Dear&nbsp;</span><span style=\"color:#337FE5;font-size:16px;\">%s</span><span style=\"font-size:16px;\">,</span><br />\n" +
+            "<span style=\"font-size:16px;\"> The&nbsp;admin&nbsp;of&nbsp;<span style=\"color:#337FE5;\">%s</span>&nbsp;and&nbsp;your&nbsp;team&nbsp;are&nbsp;waiting&nbsp;for&nbsp;you&nbsp;to&nbsp;join&nbsp;your&nbsp;team&nbsp;to&nbsp;access&nbsp;<span style=\"color:#E53333;\">PDF&nbsp;Tech&nbsp;products</span>.</span><br />\n" +
+            "<span style=\"font-size:16px;\"> Work&nbsp;with&nbsp;them&nbsp;on&nbsp;your&nbsp;organization.</span><br />\n" +
+            "<span style=\"font-size:16px;\"> <span style=\"color:#337FE5;\"><a href=\"%s\" target=\"_blank\">Click&nbsp;here&nbsp;to&nbsp;join&nbsp;now</a></span><span>!&nbsp;(The&nbsp;link&nbsp;expires&nbsp;in&nbsp;<span style=\"color:#E53333;\">72&nbsp;hours</span>)</span></span><br />\n" +
+            "<span style=\"font-size:16px;\"> After&nbsp;you&nbsp;click&nbsp;to&nbsp;agree&nbsp;to&nbsp;join&nbsp;the&nbsp;organization,&nbsp;you&nbsp;can&nbsp;wait&nbsp;for&nbsp;the&nbsp;administrator&nbsp;to&nbsp;assign&nbsp;you&nbsp;a&nbsp;license&nbsp;or&nbsp;actively&nbsp;contact&nbsp;your&nbsp;enterprise&nbsp;administrator&nbsp;to&nbsp;assign&nbsp;you&nbsp;a&nbsp;license.</span>"),
 
     //取消设备授权 被授权邮箱 设备型号 产品名称 产品名称  设备型号 超管邮箱
     CANCEL_DEVICE_ASSIGN("6", "取消设备授权通知", "Your organization's administrator has unbound device from your PDF Tech account", "<p>\n" +
@@ -77,7 +77,7 @@ public enum CaptchaActionEnum {
             "<span style=\"font-size:16px;\"></span><br />\n" +
             "</span></span> \n" +
             "</p>"),
-    ASSIGN_LICENSE_CODE("5", "账号被授权", "Your organization administrator has updated your PDF Technologies licenses", "<p>\n" +
+    ASSIGN_LICENSE_CODE("5", "账号被授权", "Your organization administrator has updated your PDF Tech licenses", "<p>\n" +
             "\t<span style=\"font-size:16px;font-family:Arial;\"><span style=\"font-size:16px;font-family:Arial;\"><span style=\"font-size:10pt;font-family:Arial;\"><span style=\"font-size:16px;\">Dear </span><span style=\"font-size:16px;color:#0000FF;\">%s</span><span style=\"font-size:10pt;\"><span style=\"font-size:16px;\">,</span><br />\n" +
             "<span style=\"font-size:16px;\">Your PDF Technologies licenses have been updated by your organization's administrator.</span><br />\n" +
             "<span style=\"font-size:16px;\">Currently, you have licenses for the product(s) below:</span><br />\n" +
@@ -102,7 +102,12 @@ public enum CaptchaActionEnum {
             "</p>"+
             "<p>\n" +
             "%s" +
-            "</p>\n" );
+            "</p>\n" ),
+    //取消序列码授权(被授权邮箱,产品名称,产品名称,管理员邮箱)
+    CANCEL_LICENSE_ASSIGN("7", "取消序列码授权通知", "Your organization's administrator has revoked your PDF Tech licenses",
+            "<span style=\"font-size:10pt;font-family:Arial;\"><span style=\"font-size:16px;\">Dear </span><span style=\"font-size:16px;color:#0000FF;\">%s</span><span style=\"font-size:10pt;\"><span style=\"font-size:16px;\">,</span><br />\n" +
+                    "<span style=\"font-size:16px;\"> Your licenses for </span></span><span style=\"font-size:16px;color:#0000FF;\">%s</span><span style=\"font-size:16px;\"> have been revoked by your organization's administrator. </span><span style=\"font-size:16px;color:#0000FF;\">%s</span><span style=\"font-size:10pt;\"><span style=\"font-size:16px;\"> will be automatically deactivated.</span><br />\n" +
+                    "<span style=\"font-size:16px;\"> If you have any questions, please contact your organization's administrator (</span></span><span style=\"font-size:16px;color:#0000FF;\">%s</span><span style=\"font-size:16px;\">).</span></span>"),;
 
     private final String value;
     private final String action;

+ 2 - 1
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/ProductServiceImpl.java

@@ -54,7 +54,8 @@ public class ProductServiceImpl implements ProductService {
     public Products getByName(String productName) {
         ProductsExample productsExample = new ProductsExample();
         productsExample.createCriteria().andNameEqualTo(productName);
-        return productMapper.selectByExample(productsExample).get(0);
+        List<Products> products = productMapper.selectByExample(productsExample);
+        return CollectionUtils.isEmpty(products) ? null : products.get(0);
     }
 
     @Override

+ 2 - 2
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppDashboardServiceImpl.java

@@ -140,9 +140,9 @@ public class VppDashboardServiceImpl implements VppDashboardService {
             long between = DateUtil.between(licenseCodes.getEndUpAt(), DateUtil.date(), DateUnit.DAY);
             int validPeriod = (int) DateUtil.between(licenseCodes.getEndUpAt(), licenseCodes.getCreatedAt(), DateUnit.DAY);
             validPeriod = validPeriod / 30;
-            dashboardOverviewProductVO.setValidPeriod(validPeriod + "months");
+            dashboardOverviewProductVO.setValidPeriod(String.valueOf(validPeriod));
             dashboardOverviewProductVO.setExpireDate(licenseCodes.getEndUpAt().toString());
-            dashboardOverviewProductVO.setTimeLeft(between + "days");
+            dashboardOverviewProductVO.setTimeLeft(String.valueOf(between));
         }
     }
 

+ 41 - 15
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppLicenseCodeServiceImpl.java

@@ -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());

+ 14 - 3
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppRTeamMemberRoleServiceImpl.java

@@ -116,15 +116,26 @@ public class VppRTeamMemberRoleServiceImpl implements VppRTeamMemberRoleService
         VppMember user = vppMemberService.getCurrentUser();
         VppMember byAccount = vppMemberService.getByAccount(dto.getMemberEmail());
         VppTeam vppTeam = vppTeamService.getById(dto.getTeamId());
-        // 如果成员存在
+        // 如果成员存在,校验数据
         if (null != byAccount) {
-            // 校验数据,查询用户是否已存在在团队中
+            // 判断是否存在于其他公司
+            if (!byAccount.getCompanyId().equals(user.getCompanyId())) {
+                throw new BackendRuntimeException(VppMemberConstant.MEMBEU_HAS_JOINED);
+            }
+            // 查询用户是否已存在其他团队中
             VppRTeamMemberRoleExample example = new VppRTeamMemberRoleExample();
-            example.createCriteria().andMemberIdEqualTo(byAccount.getId()).andRoleIdLike("3");
+            example.createCriteria().andMemberIdEqualTo(byAccount.getId()).andTeamIdNotEqualTo(dto.getTeamId()).andRoleIdLike("3");
             List<VppRTeamMemberRole> vppRTeamMemberRoles = vppRTeamMemberRoleMapper.selectByExample(example);
             if (!CollectionUtils.isEmpty(vppRTeamMemberRoles)) {
                 throw new BackendRuntimeException(VppMemberConstant.MEMBEU_HAS_JOINED);
             }
+            // 查询是否为本团队管理员
+            VppRTeamMemberRoleExample example1 = new VppRTeamMemberRoleExample();
+            example1.createCriteria().andMemberIdEqualTo(byAccount.getId()).andTeamIdEqualTo(dto.getTeamId()).andRoleIdLike("2");
+            List<VppRTeamMemberRole> vppRTeamMemberRoles1 = vppRTeamMemberRoleMapper.selectByExample(example);
+            if (!CollectionUtils.isEmpty(vppRTeamMemberRoles1)) {
+                throw new BackendRuntimeException(VppMemberConstant.MEMBEU_HAS_ADMIN);
+            }
         }
 
         // 发送邮件