Pārlūkot izejas kodu

私有化部署:激活设备接口+序列码sign激活

tangxiangan 1 gadu atpakaļ
vecāks
revīzija
422612a1a4

+ 9 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/constant/VppDeviceConstant.java

@@ -13,4 +13,13 @@ public interface VppDeviceConstant {
 
     String EXCEPTION_MSG_NO_TEAM = " User not manage any team!";
 
+    String EXCEPTION_MSG_INVALID_LICENSE_KEY = "invalid_license_key";
+
+    String EXCEPTION_MSG_LICENSE_NOT_MATCH_PRODUCT = "license_not_match_product";
+
+    String EXCEPTION_MSG_LICENSE_EXPIRED = "license_expired";
+
+    String EXCEPTION_MSG_MAX_DEVICE_NUM = "exceed_max_device_num";
+
+
 }

+ 3 - 3
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/controller/VppDeviceController.java

@@ -5,6 +5,7 @@ import cn.kdan.pdf.tech.core.constant.VppDeviceConstant;
 import cn.kdan.pdf.tech.core.enums.RoleEnum;
 import cn.kdan.pdf.tech.core.model.VppCompany;
 import cn.kdan.pdf.tech.core.params.VerifyParam;
+import cn.kdan.pdf.tech.core.pojo.vo.ActivationVO;
 import cn.kdan.pdf.tech.core.pojo.vo.VppDeviceVO;
 import cn.kdan.pdf.tech.core.service.VppCompanyService;
 import cn.kdan.pdf.tech.core.service.VppDeviceService;
@@ -109,9 +110,8 @@ public class VppDeviceController {
 
     @PreCheckRole(roles = {RoleEnum.TEAM_ADMIN,RoleEnum.SUPER_ADMIN})
     @PostMapping("/activation")
-    public ResultMap<Boolean> activation(@RequestBody VerifyParam verifyParam) {
-//        vppDeviceService.activation(verifyParam);
-        return new ResultMap<>(CommonConstant.SUCCESS, VppDeviceConstant.SUCCESS_ACTIVATION_SUCCESS,Boolean.TRUE);
+    public ResultMap<ActivationVO> activation(@RequestBody VerifyParam verifyParam) {
+        return new ResultMap<>(CommonConstant.SUCCESS, VppDeviceConstant.SUCCESS_ACTIVATION_SUCCESS,vppDeviceService.activation(verifyParam));
     }
 
 

+ 36 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/enums/PlatformEnum.java

@@ -0,0 +1,36 @@
+package cn.kdan.pdf.tech.core.enums;
+
+public enum PlatformEnum {
+    DMG(0,"DMG"),
+    AppleStore(1,"AppleStore"),
+    AppleStorePro(2,"AppleStorePro"),
+    EXE(3,"EXE"),
+    MicrosoftEXE(4,"MicrosoftEXE");
+
+    private Integer code;
+
+    private String value;
+
+    PlatformEnum(Integer code, String value) {
+        this.code = code;
+        this.value = value;
+    }
+
+
+    public static PlatformEnum getEnumByCode(String value) {
+        for (PlatformEnum type : PlatformEnum.values()) {
+            if (type.value().equals(value)) {
+                return type;
+            }
+        }
+        return DMG;
+    }
+
+    public Integer code() {
+        return code;
+    }
+
+    public String value() {
+        return value;
+    }
+}

+ 8 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/mapper/ext/ExtVppLicenseCodeMapper.java

@@ -2,6 +2,7 @@ package cn.kdan.pdf.tech.core.mapper.ext;
 
 import cn.kdan.pdf.tech.core.mapper.LicenseCodesMapper;
 import cn.kdan.pdf.tech.core.model.LicenseCodes;
+import cn.kdan.pdf.tech.core.pojo.vo.LicenseCodesVO;
 import cn.kdan.pdf.tech.core.pojo.vo.VppLicenseCodeVO;
 import org.apache.ibatis.annotations.Param;
 
@@ -28,6 +29,13 @@ public interface ExtVppLicenseCodeMapper extends LicenseCodesMapper {
 
     List<LicenseCodes> listBySubscriptionIds(@Param("subscriptionIds") List<String> subscriptionIds);
 
+    /**
+     * 私有化部署验证序列码用到
+     * @param cdkey cdkey
+     * @return LicenseCodesVO
+     */
+    List<LicenseCodesVO> listWithApp(@Param("cdkey") String cdkey);
+
 
     /**
      * 序列码列表

+ 19 - 7
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/model/LicenseCodes.java

@@ -34,9 +34,6 @@ public class LicenseCodes implements Serializable {
 
     private Date endUpAt;
 
-    /**
-     * 状态 0:退单 1:未授权 2:已授权 3:已激活 4:已取消授权 5:已过期
-     */
     private Integer validFlag;
 
     private Date assignedDate;
@@ -45,6 +42,8 @@ public class LicenseCodes implements Serializable {
 
     private Short isVpp;
 
+    private String sign;
+
     private static final long serialVersionUID = 1L;
 
     public String getId() {
@@ -242,9 +241,6 @@ public class LicenseCodes implements Serializable {
         this.endUpAt = endUpAt;
     }
 
-    /**
-     * 状态 0:退单 1:未授权 2:已授权 3:已激活 4:已取消授权 5:已过期 6:refunded 7:未激活 8:部分激活
-     */
     public Integer getValidFlag() {
         return validFlag;
     }
@@ -297,6 +293,19 @@ public class LicenseCodes implements Serializable {
         this.isVpp = isVpp;
     }
 
+    public String getSign() {
+        return sign;
+    }
+
+    public LicenseCodes withSign(String sign) {
+        this.setSign(sign);
+        return this;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
+
     @Override
     public boolean equals(Object that) {
         if (this == that) {
@@ -327,7 +336,8 @@ public class LicenseCodes implements Serializable {
             && (this.getValidFlag() == null ? other.getValidFlag() == null : this.getValidFlag().equals(other.getValidFlag()))
             && (this.getAssignedDate() == null ? other.getAssignedDate() == null : this.getAssignedDate().equals(other.getAssignedDate()))
             && (this.getActivatedDate() == null ? other.getActivatedDate() == null : this.getActivatedDate().equals(other.getActivatedDate()))
-            && (this.getIsVpp() == null ? other.getIsVpp() == null : this.getIsVpp().equals(other.getIsVpp()));
+            && (this.getIsVpp() == null ? other.getIsVpp() == null : this.getIsVpp().equals(other.getIsVpp()))
+            && (this.getSign() == null ? other.getSign() == null : this.getSign().equals(other.getSign()));
     }
 
     @Override
@@ -353,6 +363,7 @@ public class LicenseCodes implements Serializable {
         result = prime * result + ((getAssignedDate() == null) ? 0 : getAssignedDate().hashCode());
         result = prime * result + ((getActivatedDate() == null) ? 0 : getActivatedDate().hashCode());
         result = prime * result + ((getIsVpp() == null) ? 0 : getIsVpp().hashCode());
+        result = prime * result + ((getSign() == null) ? 0 : getSign().hashCode());
         return result;
     }
 
@@ -381,6 +392,7 @@ public class LicenseCodes implements Serializable {
         sb.append(", assignedDate=").append(assignedDate);
         sb.append(", activatedDate=").append(activatedDate);
         sb.append(", isVpp=").append(isVpp);
+        sb.append(", sign=").append(sign);
         sb.append(", serialVersionUID=").append(serialVersionUID);
         sb.append("]");
         return sb.toString();

+ 88 - 13
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/model/LicenseCodesExample.java

@@ -926,62 +926,62 @@ public class LicenseCodesExample {
         }
 
         public Criteria andTypeIsNull() {
-            addCriterion("type is null");
+            addCriterion("`type` is null");
             return (Criteria) this;
         }
 
         public Criteria andTypeIsNotNull() {
-            addCriterion("type is not null");
+            addCriterion("`type` is not null");
             return (Criteria) this;
         }
 
         public Criteria andTypeEqualTo(Short value) {
-            addCriterion("type =", value, "type");
+            addCriterion("`type` =", value, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeNotEqualTo(Short value) {
-            addCriterion("type <>", value, "type");
+            addCriterion("`type` <>", value, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeGreaterThan(Short value) {
-            addCriterion("type >", value, "type");
+            addCriterion("`type` >", value, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeGreaterThanOrEqualTo(Short value) {
-            addCriterion("type >=", value, "type");
+            addCriterion("`type` >=", value, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeLessThan(Short value) {
-            addCriterion("type <", value, "type");
+            addCriterion("`type` <", value, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeLessThanOrEqualTo(Short value) {
-            addCriterion("type <=", value, "type");
+            addCriterion("`type` <=", value, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeIn(List<Short> values) {
-            addCriterion("type in", values, "type");
+            addCriterion("`type` in", values, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeNotIn(List<Short> values) {
-            addCriterion("type not in", values, "type");
+            addCriterion("`type` not in", values, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeBetween(Short value1, Short value2) {
-            addCriterion("type between", value1, value2, "type");
+            addCriterion("`type` between", value1, value2, "type");
             return (Criteria) this;
         }
 
         public Criteria andTypeNotBetween(Short value1, Short value2) {
-            addCriterion("type not between", value1, value2, "type");
+            addCriterion("`type` not between", value1, value2, "type");
             return (Criteria) this;
         }
 
@@ -1285,6 +1285,76 @@ public class LicenseCodesExample {
             return (Criteria) this;
         }
 
+        public Criteria andSignIsNull() {
+            addCriterion("sign is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignIsNotNull() {
+            addCriterion("sign is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignEqualTo(String value) {
+            addCriterion("sign =", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignNotEqualTo(String value) {
+            addCriterion("sign <>", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignGreaterThan(String value) {
+            addCriterion("sign >", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignGreaterThanOrEqualTo(String value) {
+            addCriterion("sign >=", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignLessThan(String value) {
+            addCriterion("sign <", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignLessThanOrEqualTo(String value) {
+            addCriterion("sign <=", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignLike(String value) {
+            addCriterion("sign like", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignNotLike(String value) {
+            addCriterion("sign not like", value, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignIn(List<String> values) {
+            addCriterion("sign in", values, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignNotIn(List<String> values) {
+            addCriterion("sign not in", values, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignBetween(String value1, String value2) {
+            addCriterion("sign between", value1, value2, "sign");
+            return (Criteria) this;
+        }
+
+        public Criteria andSignNotBetween(String value1, String value2) {
+            addCriterion("sign not between", value1, value2, "sign");
+            return (Criteria) this;
+        }
+
         public Criteria andCdkeyLikeInsensitive(String value) {
             addCriterion("upper(cdkey) like", value.toUpperCase(), "cdkey");
             return (Criteria) this;
@@ -1304,6 +1374,11 @@ public class LicenseCodesExample {
             addCriterion("upper(company_id) like", value.toUpperCase(), "companyId");
             return (Criteria) this;
         }
+
+        public Criteria andSignLikeInsensitive(String value) {
+            addCriterion("upper(sign) like", value.toUpperCase(), "sign");
+            return (Criteria) this;
+        }
     }
 
     public static class Criteria extends GeneratedCriteria {
@@ -1397,4 +1472,4 @@ public class LicenseCodesExample {
             this(condition, value, secondValue, null);
         }
     }
-}
+}

+ 27 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/pojo/dto/VppPrivateDeployment.java

@@ -0,0 +1,27 @@
+package cn.kdan.pdf.tech.core.pojo.dto;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class VppPrivateDeployment {
+    private String subscriptionId;
+    private String cdkey;
+
+    private Short times;
+
+    private Integer productId;
+
+    private String teamId;
+
+    private String companyId;
+
+    private Short type;
+
+    private Integer validFlag;
+
+    private Short isVpp;
+
+    private Date endUpAt;
+}

+ 16 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/pojo/vo/DeviceResVO.java

@@ -22,6 +22,22 @@ public class DeviceResVO {
         private String name;
         private String code;
 
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getCode() {
+            return code;
+        }
+
+        public void setCode(String code) {
+            this.code = code;
+        }
+
         // Getter、Setter方法省略
     }
 }

+ 56 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/pojo/vo/LicenseCodesVO.java

@@ -0,0 +1,56 @@
+package cn.kdan.pdf.tech.core.pojo.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class LicenseCodesVO  {
+    private String id;
+
+    private String memberId;
+
+    private String subscriptionId;
+
+    private String cdkey;
+
+    private Short times;
+
+    private Short usedTimes;
+
+    private Date createdAt;
+
+    private Date updatedAt;
+
+    private Date lastRemindAt;
+
+    private Integer productId;
+
+    private String vppMemberId;
+
+    private String teamId;
+
+    private String companyId;
+
+    private Short type;
+
+    private Date endUpAt;
+
+    /**
+     * 状态 0:退单 1:未授权 2:已授权 3:已激活 4:已取消授权 5:已过期
+     */
+    private Integer validFlag;
+
+    private Date assignedDate;
+
+    private Date activatedDate;
+
+    private Short isVpp;
+
+    private String appCode;
+
+    private Integer appId;
+
+    private String sign;
+}

+ 9 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/VppDeviceService.java

@@ -1,6 +1,8 @@
 package cn.kdan.pdf.tech.core.service;
 
 import cn.kdan.pdf.tech.core.model.Devices;
+import cn.kdan.pdf.tech.core.params.VerifyParam;
+import cn.kdan.pdf.tech.core.pojo.vo.ActivationVO;
 import cn.kdan.pdf.tech.core.pojo.vo.VppDeviceVO;
 import com.github.pagehelper.PageInfo;
 
@@ -56,4 +58,11 @@ public interface VppDeviceService {
      * @return
      */
     List<Devices> getByCdKeyList(List<String> cdKeyList);
+
+    /**
+     * 设备激活
+     * @param verifyParam 激活参数
+     * @return ActivationVO
+     */
+    ActivationVO activation(VerifyParam verifyParam);
 }

+ 3 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/VppLicenseCodeService.java

@@ -1,6 +1,7 @@
 package cn.kdan.pdf.tech.core.service;
 
 import cn.kdan.pdf.tech.core.model.LicenseCodes;
+import cn.kdan.pdf.tech.core.pojo.vo.LicenseCodesVO;
 import cn.kdan.pdf.tech.core.pojo.vo.VppLicenseCodeVO;
 import com.github.pagehelper.PageInfo;
 import org.springframework.web.multipart.MultipartFile;
@@ -142,6 +143,8 @@ public interface VppLicenseCodeService {
     List<LicenseCodes> getBySubscriptionIds(List<String> subscriptionIds);
 
 
+    List<LicenseCodesVO> getWithInfo(String cdKey);
+
     LicenseCodes getByCdKey(String cdKey);
 
     /**

+ 122 - 6
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppDeviceServiceImpl.java

@@ -4,19 +4,24 @@ import cn.kdan.pdf.tech.core.constant.VppDeviceConstant;
 import cn.kdan.pdf.tech.core.enums.CaptchaActionEnum;
 import cn.kdan.pdf.tech.core.enums.DeviceStatusEnum;
 import cn.kdan.pdf.tech.core.enums.LicenseCodeStatusEnum;
+import cn.kdan.pdf.tech.core.enums.PlatformEnum;
 import cn.kdan.pdf.tech.core.mapper.ext.ExtVppDeviceMapper;
 import cn.kdan.pdf.tech.core.model.*;
-import cn.kdan.pdf.tech.core.pojo.vo.VppDeviceVO;
-import cn.kdan.pdf.tech.core.pojo.vo.VppRTeamMemberRoleVO;
+import cn.kdan.pdf.tech.core.params.VerifyParam;
+import cn.kdan.pdf.tech.core.pojo.dto.VppPrivateDeployment;
+import cn.kdan.pdf.tech.core.pojo.vo.*;
 import cn.kdan.pdf.tech.core.service.*;
 import cn.kdan.pdf.tech.core.utils.ThreadPoolSingleUtil;
+import com.alibaba.fastjson.JSON;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import constant.CommonConstant;
 import exception.BackendRuntimeException;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang.StringUtils;
 import org.omg.PortableInterceptor.ACTIVE;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -26,12 +31,11 @@ import org.springframework.util.ObjectUtils;
 //import cn.kdan.pdf.tech.core.utils.EmailUtils;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
+import static cn.hutool.core.bean.BeanUtil.copyProperties;
+
 
 /**
  * 用户与团队的关系类
@@ -178,4 +182,116 @@ public class VppDeviceServiceImpl implements VppDeviceService {
         devicesExample.createCriteria().andCdkeyIn(cdKeyList).andStatusEqualTo(1);
         return extVppDeviceMapper.selectByExample(devicesExample);
     }
+
+    @Override
+    public ActivationVO activation(VerifyParam verifyParam) {
+        ActivationVO activationVO = new ActivationVO();
+        // 查询序列码信息
+        List<LicenseCodesVO> licenseCodes = licenseCodeService.getWithInfo(verifyParam.getCdkey());
+        if (CollectionUtils.isEmpty(licenseCodes)) {
+            throw new BackendRuntimeException(VppDeviceConstant.EXCEPTION_MSG_INVALID_LICENSE_KEY);
+        }
+        LicenseCodesVO licenseCodesVO = licenseCodes.get(0);
+
+        //验证序列码是否合法
+        String sign = licenseCodesVO.getSign();
+        VppPrivateDeployment deployment = new VppPrivateDeployment();
+        BeanUtils.copyProperties(licenseCodesVO, deployment);
+        //将对象转化为json
+        String deploymentJson = JSON.toJSONString(deployment) + "vpp_private_deployment";
+        //对上述json进行MD5加密并且和sign对比
+        String signOriginal = DigestUtils.md5Hex(deploymentJson);
+        if (!signOriginal.equals(sign)) {
+            throw new BackendRuntimeException(VppDeviceConstant.EXCEPTION_MSG_INVALID_LICENSE_KEY);
+        }
+
+        // 定义设备状态集合,用于判断设备是否已激活
+        Set<Integer> activeStatuses = new HashSet<>();
+        activeStatuses.add(DeviceStatusEnum.UNACTIVATED.code());
+        activeStatuses.add(DeviceStatusEnum.ACTIVE.code());
+
+        // 查询设备是否已激活
+        DevicesExample devicesExample = new DevicesExample();
+        devicesExample.createCriteria()
+                .andUniqueSnEqualTo(verifyParam.getUniqueSn())
+                .andCdkeyEqualTo(verifyParam.getCdkey())
+                .andStatusIn(new ArrayList<>(activeStatuses));
+        List<Devices> list = extVppDeviceMapper.selectByExample(devicesExample);
+
+        if (!CollectionUtils.isEmpty(list)) {
+            // 设备已激活,返回设备信息
+            Devices devices = list.get(0);
+            DeviceResVO deviceResVO = new DeviceResVO();
+            deviceResVO.setStatus(Objects.requireNonNull(DeviceStatusEnum.getEnumByCode(devices.getStatus())).value());
+            Products products = productService.getById(licenseCodesVO.getProductId());
+            deviceResVO.setProductCode(products.getCode());
+            activationVO.setDevice(deviceResVO);
+            return activationVO;
+        }
+
+        // 验证序列码的应用程序代码和激活请求的应用程序代码是否一致
+        if (!Objects.equals(licenseCodesVO.getAppCode(), verifyParam.getAppCode())) {
+            throw new BackendRuntimeException(VppDeviceConstant.EXCEPTION_MSG_LICENSE_NOT_MATCH_PRODUCT);
+        }
+
+        // 验证序列码使用次数是否超过限制
+        if (licenseCodesVO.getUsedTimes() >= licenseCodesVO.getTimes()) {
+            throw new BackendRuntimeException(VppDeviceConstant.EXCEPTION_MSG_MAX_DEVICE_NUM);
+        }
+
+        // 验证序列码是否已过期
+        if (licenseCodesVO.getEndUpAt().before(new Date())) {
+            throw new BackendRuntimeException(VppDeviceConstant.EXCEPTION_MSG_LICENSE_EXPIRED);
+        }
+
+        // 验证序列码的有效标志
+        if (!licenseCodesVO.getValidFlag().equals(LicenseCodeStatusEnum.PARTIALLY_ACTIVATED.code())
+                && !licenseCodesVO.getValidFlag().equals(LicenseCodeStatusEnum.ASSIGNED.code())) {
+            throw new BackendRuntimeException(VppDeviceConstant.EXCEPTION_MSG_INVALID_LICENSE_KEY);
+        }
+
+        // 查询设备状态列表
+        DevicesExample devicesExample1 = new DevicesExample();
+        devicesExample1.createCriteria()
+                .andUniqueSnEqualTo(verifyParam.getUniqueSn())
+                .andAppIdEqualTo(licenseCodesVO.getAppId())
+                .andStatusIn(new ArrayList<>(activeStatuses));
+        List<Devices> statusDevicelist = extVppDeviceMapper.selectByExample(devicesExample1);
+
+        if (CollectionUtils.isEmpty(statusDevicelist)) {
+            // 新增设备
+            Devices devices = new Devices();
+            devices.setAppId(licenseCodesVO.getAppId());
+            devices.setEndUpAt(licenseCodesVO.getEndUpAt());
+            devices.setMemberId(licenseCodesVO.getMemberId());
+            PlatformEnum platformEnum = PlatformEnum.getEnumByCode(verifyParam.getPlatform());
+            devices.setPlatform(platformEnum.code());
+            devices.setSubscriptionId(licenseCodesVO.getSubscriptionId());
+            devices.setStatus(DeviceStatusEnum.ACTIVE.code());
+            devices.setCdkey(licenseCodesVO.getCdkey());
+            devices.setActivatedDate(new Date());
+            devices.setIsVpp(Short.valueOf("2"));
+            extVppDeviceMapper.insert(devices);
+        }
+
+        // 更新序列码的使用次数和有效标志
+        LicenseCodes updateCode = new LicenseCodes();
+        updateCode.setUsedTimes((short) (licenseCodesVO.getUsedTimes() + 1));
+        if (updateCode.getUsedTimes() < licenseCodesVO.getTimes()) {
+            updateCode.setValidFlag(LicenseCodeStatusEnum.PARTIALLY_ACTIVATED.code());
+        }
+        if (updateCode.getUsedTimes().equals(licenseCodesVO.getTimes())) {
+            updateCode.setValidFlag(LicenseCodeStatusEnum.ACTIVE.code());
+        }
+        licenseCodeService.updateByPrimaryKey(updateCode);
+
+        // 返回设备信息
+        DeviceResVO deviceResVO = activationVO.getDevice();
+        deviceResVO.setStatus(Objects.requireNonNull(DeviceStatusEnum.getEnumByCode(statusDevicelist.get(0).getStatus())).value());
+        Products products = productService.getById(licenseCodesVO.getProductId());
+        deviceResVO.setProductCode(products.getCode());
+        activationVO.setDevice(deviceResVO);
+        return activationVO;
+    }
+
 }

+ 6 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/service/impl/VppLicenseCodeServiceImpl.java

@@ -9,6 +9,7 @@ import cn.kdan.pdf.tech.core.enums.CaptchaActionEnum;
 import cn.kdan.pdf.tech.core.enums.LicenseCodeStatusEnum;
 import cn.kdan.pdf.tech.core.mapper.ext.ExtVppLicenseCodeMapper;
 import cn.kdan.pdf.tech.core.model.*;
+import cn.kdan.pdf.tech.core.pojo.vo.LicenseCodesVO;
 import cn.kdan.pdf.tech.core.pojo.vo.VppLicenseCodeVO;
 import cn.kdan.pdf.tech.core.pojo.vo.VppRTeamMemberRoleVO;
 import cn.kdan.pdf.tech.core.service.*;
@@ -571,6 +572,11 @@ public class VppLicenseCodeServiceImpl implements VppLicenseCodeService {
         return licenseCodeMapper.listBySubscriptionIds(subscriptionIds);
     }
 
+    @Override
+    public List<LicenseCodesVO> getWithInfo(String cdKey) {
+        return licenseCodeMapper.listWithApp(cdKey);
+    }
+
 
     @Override
     public LicenseCodes getByCdKey(String cdKey) {

+ 6 - 6
pdf-tech-core/src/main/resources/generatorConfig.xml

@@ -18,7 +18,7 @@
             <property name="suppressAllComments" value="true"/>
         </commentGenerator>
         <jdbcConnection driverClass="org.postgresql.Driver"
-                        connectionURL="jdbc:postgresql://139.196.224.157:5432/db_larger1"
+                        connectionURL="jdbc:postgresql://139.196.160.101:5433/db_larger1"
                         userId="postgres" password="hYG59287"
         >
             <property name="nullCatalogMeansCurrent" value="true"/>
@@ -62,11 +62,11 @@
             <columnOverride column="product_id" property="productId" javaType="java.lang.Integer" />
             <columnOverride column="valid_flag" property="validFlag" javaType="java.lang.Integer" />
         </table>
-        <table tableName="devices">
-            <columnOverride column="id" property="id" javaType="java.lang.String" />
-            <columnOverride column="subscription_id" property="subscriptionId" javaType="java.lang.String" />
-            <columnOverride column="member_id" property="memberId" javaType="java.lang.String" />
-        </table>
+<!--        <table tableName="devices">-->
+<!--            <columnOverride column="id" property="id" javaType="java.lang.String" />-->
+<!--            <columnOverride column="subscription_id" property="subscriptionId" javaType="java.lang.String" />-->
+<!--            <columnOverride column="member_id" property="memberId" javaType="java.lang.String" />-->
+<!--        </table>-->
 <!--        <table tableName="orders"/>-->
 <!--        <table tableName="vpp_r_team_member_role"/>-->
 <!--        <table tableName="vpp_company"/>-->

+ 58 - 43
pdf-tech-core/src/main/resources/sqlmap/LicenseCodesMapper.xml

@@ -21,6 +21,7 @@
     <result column="assigned_date" jdbcType="TIMESTAMP" property="assignedDate" />
     <result column="activated_date" jdbcType="TIMESTAMP" property="activatedDate" />
     <result column="is_vpp" jdbcType="SMALLINT" property="isVpp" />
+    <result column="sign" jdbcType="VARCHAR" property="sign" />
   </resultMap>
   <sql id="Example_Where_Clause">
     <where>
@@ -81,9 +82,9 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, member_id, subscription_id, cdkey, times, used_times, created_at, updated_at,
-    last_remind_at, product_id, vpp_member_id, team_id, company_id, type, end_up_at,
-    valid_flag, assigned_date, activated_date, is_vpp
+    id, member_id, subscription_id, cdkey, times, used_times, created_at, updated_at, 
+    last_remind_at, product_id, vpp_member_id, team_id, company_id, `type`, end_up_at, 
+    valid_flag, assigned_date, activated_date, is_vpp, sign
   </sql>
   <select id="selectByExample" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodesExample" resultMap="BaseResultMap">
     select
@@ -100,14 +101,14 @@
     </if>
   </select>
   <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
-    select
+    select 
     <include refid="Base_Column_List" />
     from license_codes
-    where id = #{id}::uuid
+    where id = #{id,jdbcType=OTHER}
   </select>
   <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
     delete from license_codes
-    where id = #{id}::uuid
+    where id = #{id,jdbcType=OTHER}
   </delete>
   <delete id="deleteByExample" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodesExample">
     delete from license_codes
@@ -116,20 +117,20 @@
     </if>
   </delete>
   <insert id="insert" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodes">
-    insert into license_codes (id, member_id, subscription_id,
-      cdkey, times, used_times,
-      created_at, updated_at, last_remind_at,
-      product_id, vpp_member_id, team_id,
-      company_id, type, end_up_at,
-      valid_flag, assigned_date, activated_date,
-      is_vpp)
-    values (#{id}::uuid, #{memberId}::uuid, #{subscriptionId}::uuid,
-      #{cdkey,jdbcType=VARCHAR}, #{times,jdbcType=SMALLINT}, #{usedTimes,jdbcType=SMALLINT},
-      #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{lastRemindAt,jdbcType=TIMESTAMP},
-      #{productId,jdbcType=INTEGER}, #{vppMemberId,jdbcType=VARCHAR}, #{teamId,jdbcType=VARCHAR},
-      #{companyId,jdbcType=VARCHAR}, #{type,jdbcType=SMALLINT}, #{endUpAt,jdbcType=TIMESTAMP},
-      #{validFlag,jdbcType=SMALLINT}, #{assignedDate,jdbcType=TIMESTAMP}, #{activatedDate,jdbcType=TIMESTAMP},
-      #{isVpp,jdbcType=SMALLINT})
+    insert into license_codes (id, member_id, subscription_id, 
+      cdkey, times, used_times, 
+      created_at, updated_at, last_remind_at, 
+      product_id, vpp_member_id, team_id, 
+      company_id, `type`, end_up_at, 
+      valid_flag, assigned_date, activated_date, 
+      is_vpp, sign)
+    values (#{id,jdbcType=OTHER}, #{memberId,jdbcType=OTHER}, #{subscriptionId,jdbcType=OTHER}, 
+      #{cdkey,jdbcType=VARCHAR}, #{times,jdbcType=SMALLINT}, #{usedTimes,jdbcType=SMALLINT}, 
+      #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{lastRemindAt,jdbcType=TIMESTAMP}, 
+      #{productId,jdbcType=INTEGER}, #{vppMemberId,jdbcType=VARCHAR}, #{teamId,jdbcType=VARCHAR}, 
+      #{companyId,jdbcType=VARCHAR}, #{type,jdbcType=SMALLINT}, #{endUpAt,jdbcType=TIMESTAMP}, 
+      #{validFlag,jdbcType=SMALLINT}, #{assignedDate,jdbcType=TIMESTAMP}, #{activatedDate,jdbcType=TIMESTAMP}, 
+      #{isVpp,jdbcType=SMALLINT}, #{sign,jdbcType=VARCHAR})
   </insert>
   <insert id="insertSelective" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodes">
     insert into license_codes
@@ -174,7 +175,7 @@
         company_id,
       </if>
       <if test="type != null">
-        type,
+        `type`,
       </if>
       <if test="endUpAt != null">
         end_up_at,
@@ -191,16 +192,19 @@
       <if test="isVpp != null">
         is_vpp,
       </if>
+      <if test="sign != null">
+        sign,
+      </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides=",">
       <if test="id != null">
-        #{id}::uuid,
+        #{id,jdbcType=OTHER},
       </if>
       <if test="memberId != null">
-        #{memberId}::uuid,
+        #{memberId,jdbcType=OTHER},
       </if>
       <if test="subscriptionId != null">
-        #{subscriptionId}::uuid,
+        #{subscriptionId,jdbcType=OTHER},
       </if>
       <if test="cdkey != null">
         #{cdkey,jdbcType=VARCHAR},
@@ -250,6 +254,9 @@
       <if test="isVpp != null">
         #{isVpp,jdbcType=SMALLINT},
       </if>
+      <if test="sign != null">
+        #{sign,jdbcType=VARCHAR},
+      </if>
     </trim>
   </insert>
   <select id="countByExample" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodesExample" resultType="java.lang.Long">
@@ -262,13 +269,13 @@
     update license_codes
     <set>
       <if test="row.id != null">
-        id = #{row.id}::uuid,
+        id = #{row.id,jdbcType=OTHER},
       </if>
       <if test="row.memberId != null">
-        member_id = #{row.memberId}::uuid,
+        member_id = #{row.memberId,jdbcType=OTHER},
       </if>
       <if test="row.subscriptionId != null">
-        subscription_id = #{row.subscriptionId}::uuid,
+        subscription_id = #{row.subscriptionId,jdbcType=OTHER},
       </if>
       <if test="row.cdkey != null">
         cdkey = #{row.cdkey,jdbcType=VARCHAR},
@@ -301,7 +308,7 @@
         company_id = #{row.companyId,jdbcType=VARCHAR},
       </if>
       <if test="row.type != null">
-        type = #{row.type,jdbcType=SMALLINT},
+        `type` = #{row.type,jdbcType=SMALLINT},
       </if>
       <if test="row.endUpAt != null">
         end_up_at = #{row.endUpAt,jdbcType=TIMESTAMP},
@@ -318,6 +325,9 @@
       <if test="row.isVpp != null">
         is_vpp = #{row.isVpp,jdbcType=SMALLINT},
       </if>
+      <if test="row.sign != null">
+        sign = #{row.sign,jdbcType=VARCHAR},
+      </if>
     </set>
     <if test="example != null">
       <include refid="Update_By_Example_Where_Clause" />
@@ -325,9 +335,9 @@
   </update>
   <update id="updateByExample" parameterType="map">
     update license_codes
-    set id = #{row.id}::uuid,
-      member_id = #{row.memberId}::uuid,
-      subscription_id = #{row.subscriptionId}::uuid,
+    set id = #{row.id,jdbcType=OTHER},
+      member_id = #{row.memberId,jdbcType=OTHER},
+      subscription_id = #{row.subscriptionId,jdbcType=OTHER},
       cdkey = #{row.cdkey,jdbcType=VARCHAR},
       times = #{row.times,jdbcType=SMALLINT},
       used_times = #{row.usedTimes,jdbcType=SMALLINT},
@@ -338,12 +348,13 @@
       vpp_member_id = #{row.vppMemberId,jdbcType=VARCHAR},
       team_id = #{row.teamId,jdbcType=VARCHAR},
       company_id = #{row.companyId,jdbcType=VARCHAR},
-      type = #{row.type,jdbcType=SMALLINT},
+      `type` = #{row.type,jdbcType=SMALLINT},
       end_up_at = #{row.endUpAt,jdbcType=TIMESTAMP},
       valid_flag = #{row.validFlag,jdbcType=SMALLINT},
       assigned_date = #{row.assignedDate,jdbcType=TIMESTAMP},
       activated_date = #{row.activatedDate,jdbcType=TIMESTAMP},
-      is_vpp = #{row.isVpp,jdbcType=SMALLINT}
+      is_vpp = #{row.isVpp,jdbcType=SMALLINT},
+      sign = #{row.sign,jdbcType=VARCHAR}
     <if test="example != null">
       <include refid="Update_By_Example_Where_Clause" />
     </if>
@@ -352,10 +363,10 @@
     update license_codes
     <set>
       <if test="memberId != null">
-        member_id = #{memberId}::uuid,
+        member_id = #{memberId,jdbcType=OTHER},
       </if>
       <if test="subscriptionId != null">
-        subscription_id = #{subscriptionId}::uuid,
+        subscription_id = #{subscriptionId,jdbcType=OTHER},
       </if>
       <if test="cdkey != null">
         cdkey = #{cdkey,jdbcType=VARCHAR},
@@ -388,7 +399,7 @@
         company_id = #{companyId,jdbcType=VARCHAR},
       </if>
       <if test="type != null">
-        type = #{type,jdbcType=SMALLINT},
+        `type` = #{type,jdbcType=SMALLINT},
       </if>
       <if test="endUpAt != null">
         end_up_at = #{endUpAt,jdbcType=TIMESTAMP},
@@ -405,13 +416,16 @@
       <if test="isVpp != null">
         is_vpp = #{isVpp,jdbcType=SMALLINT},
       </if>
+      <if test="sign != null">
+        sign = #{sign,jdbcType=VARCHAR},
+      </if>
     </set>
-    where id = #{id}::uuid
+    where id = #{id,jdbcType=OTHER}
   </update>
   <update id="updateByPrimaryKey" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodes">
     update license_codes
-    set member_id = #{memberId}::uuid,
-      subscription_id = #{subscriptionId}::uuid,
+    set member_id = #{memberId,jdbcType=OTHER},
+      subscription_id = #{subscriptionId,jdbcType=OTHER},
       cdkey = #{cdkey,jdbcType=VARCHAR},
       times = #{times,jdbcType=SMALLINT},
       used_times = #{usedTimes,jdbcType=SMALLINT},
@@ -422,13 +436,14 @@
       vpp_member_id = #{vppMemberId,jdbcType=VARCHAR},
       team_id = #{teamId,jdbcType=VARCHAR},
       company_id = #{companyId,jdbcType=VARCHAR},
-      type = #{type,jdbcType=SMALLINT},
+      `type` = #{type,jdbcType=SMALLINT},
       end_up_at = #{endUpAt,jdbcType=TIMESTAMP},
       valid_flag = #{validFlag,jdbcType=SMALLINT},
       assigned_date = #{assignedDate,jdbcType=TIMESTAMP},
       activated_date = #{activatedDate,jdbcType=TIMESTAMP},
-      is_vpp = #{isVpp,jdbcType=SMALLINT}
-    where id = #{id}::uuid
+      is_vpp = #{isVpp,jdbcType=SMALLINT},
+      sign = #{sign,jdbcType=VARCHAR}
+    where id = #{id,jdbcType=OTHER}
   </update>
   <select id="selectByExampleWithRowbounds" parameterType="cn.kdan.pdf.tech.core.model.LicenseCodesExample" resultMap="BaseResultMap">
     select
@@ -444,4 +459,4 @@
       order by ${orderByClause}
     </if>
   </select>
-</mapper>
+</mapper>

+ 34 - 1
pdf-tech-core/src/main/resources/sqlmap/ext/ExtVppLicenseCodeMapper.xml

@@ -34,7 +34,30 @@
         <result column="activated_date" jdbcType="TIMESTAMP" property="activatedDate" />
         <result column="is_vpp" jdbcType="SMALLINT" property="isVpp" />
     </resultMap>
-
+    <resultMap id="InfoResultMap" type="cn.kdan.pdf.tech.core.pojo.vo.LicenseCodesVO">
+        <id column="id" jdbcType="OTHER" property="id" />
+        <result column="member_id" jdbcType="OTHER" property="memberId" />
+        <result column="subscription_id" jdbcType="OTHER" property="subscriptionId" />
+        <result column="cdkey" jdbcType="VARCHAR" property="cdkey" />
+        <result column="times" jdbcType="SMALLINT" property="times" />
+        <result column="used_times" jdbcType="SMALLINT" property="usedTimes" />
+        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
+        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
+        <result column="last_remind_at" jdbcType="TIMESTAMP" property="lastRemindAt" />
+        <result column="product_id" jdbcType="INTEGER" property="productId" />
+        <result column="vpp_member_id" jdbcType="VARCHAR" property="vppMemberId" />
+        <result column="team_id" jdbcType="VARCHAR" property="teamId" />
+        <result column="company_id" jdbcType="VARCHAR" property="companyId" />
+        <result column="type" jdbcType="SMALLINT" property="type" />
+        <result column="end_up_at" jdbcType="TIMESTAMP" property="endUpAt" />
+        <result column="valid_flag" jdbcType="SMALLINT" property="validFlag" />
+        <result column="assigned_date" jdbcType="TIMESTAMP" property="assignedDate" />
+        <result column="activated_date" jdbcType="TIMESTAMP" property="activatedDate" />
+        <result column="is_vpp" jdbcType="SMALLINT" property="isVpp" />
+        <result column="app_code" jdbcType="VARCHAR" property="appCode" />
+        <result column="app_id" jdbcType="SMALLINT" property="appId" />
+        <result column="sign" jdbcType="VARCHAR" property="sign" />
+    </resultMap>
   <select id="listWithInfo" resultMap="BaseResultMap">
     select vlc.id,
            vlc.cdkey,
@@ -74,6 +97,16 @@
       order by vlc.updated_at desc
   </select>
 
+    <select id="listWithApp" resultMap="InfoResultMap">
+        select l.*,a.code app_code,a.id app_id from license_codes l
+                                   left join products p on l.product_id = p.id
+                                   left join apps a on p.app_id = a.id
+        where  l.valid_flag != '0'
+        <if test="cdkey != null and cdkey != ''">
+            and l.cdkey = #{cdkey}
+        </if>
+    </select>
+
     <select id="listWithInfoForReseller" resultMap="BaseResultMap">
         select vlc.id,
         vlc.cdkey,