Explorar el Código

私有化部署:更新接口

tangxiangan hace 1 año
padre
commit
7640d2306e

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

@@ -115,7 +115,7 @@ public class VppDeviceController {
 
     @PostMapping("/verify")
     public ResultMap<ActivationVO> verify(@RequestBody VerifyParam verifyParam) {
-        return new ResultMap<>(CommonConstant.SUCCESS, VppDeviceConstant.SUCCESS_ACTIVATION_SUCCESS,vppDeviceService.verify(verifyParam));
+        return new ResultMap<>(CommonConstant.SUCCESS, CommonConstant.CODE_SUCCESS,vppDeviceService.verify(verifyParam));
     }
 
 }

+ 4 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/params/DeviceParam.java

@@ -1,5 +1,6 @@
 package cn.kdan.pdf.tech.core.params;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -10,10 +11,13 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 @NoArgsConstructor
 public class DeviceParam {
+    @JsonProperty("unique_sn")
     private String uniqueSn;
+    @JsonProperty("app_version")
     private String appVersion;
     private String platform;
     private String language;
+    @JsonProperty("time_zone")
     private String timeZone;
     private String os;
     private String model;

+ 2 - 0
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/params/SubscriptionParam.java

@@ -1,5 +1,6 @@
 package cn.kdan.pdf.tech.core.params;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
 import lombok.Data;
@@ -10,6 +11,7 @@ import lombok.NoArgsConstructor;
 @AllArgsConstructor
 @NoArgsConstructor
 public class SubscriptionParam {
+    @JsonProperty("app_code")
     private String appCode;
     private String cdkey;
 }

+ 19 - 11
pdf-tech-core/src/main/java/cn/kdan/pdf/tech/core/pojo/dto/VppPrivateDeployment.java

@@ -1,27 +1,35 @@
 package cn.kdan.pdf.tech.core.pojo.dto;
 
+import com.alibaba.fastjson.annotation.JSONField;
 import lombok.Data;
-
+import java.text.SimpleDateFormat;
 import java.util.Date;
 
 @Data
 public class VppPrivateDeployment {
+    @JSONField(name = "subscription_id")
     private String subscriptionId;
     private String cdkey;
 
     private Short times;
 
+    @JSONField(name = "product_id")
     private Integer productId;
 
-    private String teamId;
-
-    private String companyId;
-
-    private Short type;
-
-    private Integer validFlag;
-
-    private Short isVpp;
-
+    @JSONField(name = "end_up_at")
     private Date endUpAt;
+
+    // 省略 getter 和 setter 方法
+
+    public String toJSON() {
+        String pattern = "yyyy-MM-dd HH:mm:ss";
+        String dateStr = new SimpleDateFormat(pattern).format(endUpAt);
+        return "{" +
+                "\"subscription_id\":\"" + subscriptionId + '\"' +
+                ",\"cdkey\":\"" + cdkey + '\"' +
+                ",\"times\":" + times +
+                ",\"product_id\":" + productId +
+                ",\"end_up_at\":\"" + dateStr + '\"' +
+                '}';
+    }
 }

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

@@ -14,6 +14,7 @@ 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.alibaba.fastjson.serializer.SerializerFeature;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import constant.CommonConstant;
@@ -183,6 +184,7 @@ public class VppDeviceServiceImpl implements VppDeviceService {
         return extVppDeviceMapper.selectByExample(devicesExample);
     }
 
+    @Transactional
     @Override
     public ActivationVO activation(VerifyParam verifyParam) {
         ActivationVO activationVO = new ActivationVO();
@@ -197,8 +199,7 @@ public class VppDeviceServiceImpl implements VppDeviceService {
         String sign = licenseCodesVO.getSign();
         VppPrivateDeployment deployment = new VppPrivateDeployment();
         BeanUtils.copyProperties(licenseCodesVO, deployment);
-        //将对象转化为json
-        String deploymentJson = JSON.toJSONString(deployment) + "vpp_private_deployment";
+        String deploymentJson =  deployment.toJSON() + "vpp_private_deployment";
         //对上述json进行MD5加密并且和sign对比
         String signOriginal = DigestUtils.md5Hex(deploymentJson);
         if (!signOriginal.equals(sign)) {
@@ -257,10 +258,10 @@ public class VppDeviceServiceImpl implements VppDeviceService {
                 .andAppIdEqualTo(licenseCodesVO.getAppId())
                 .andStatusIn(new ArrayList<>(activeStatuses));
         List<Devices> statusDevicelist = extVppDeviceMapper.selectByExample(devicesExample1);
-
+        Devices devices = new Devices();
         if (CollectionUtils.isEmpty(statusDevicelist)) {
             // 新增设备
-            Devices devices = new Devices();
+            devices.setId(UUID.randomUUID().toString());
             devices.setAppId(licenseCodesVO.getAppId());
             devices.setEndUpAt(licenseCodesVO.getEndUpAt());
             devices.setMemberId(licenseCodesVO.getMemberId());
@@ -269,9 +270,14 @@ public class VppDeviceServiceImpl implements VppDeviceService {
             devices.setSubscriptionId(licenseCodesVO.getSubscriptionId());
             devices.setStatus(DeviceStatusEnum.ACTIVE.code());
             devices.setCdkey(licenseCodesVO.getCdkey());
+            devices.setUniqueSn(verifyParam.getDevice().getUniqueSn());
             devices.setActivatedDate(new Date());
             devices.setIsVpp(Short.valueOf("2"));
+            devices.setCreatedAt(new Date());
+            devices.setUpdatedAt(new Date());
             extVppDeviceMapper.insert(devices);
+        }else {
+            devices = statusDevicelist.get(0);
         }
 
         // 更新序列码的使用次数和有效标志
@@ -286,8 +292,8 @@ public class VppDeviceServiceImpl implements VppDeviceService {
         licenseCodeService.updateByPrimaryKey(updateCode);
 
         // 返回设备信息
-        DeviceResVO deviceResVO = activationVO.getDevice();
-        deviceResVO.setStatus(Objects.requireNonNull(DeviceStatusEnum.getEnumByCode(statusDevicelist.get(0).getStatus())).value());
+        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);
@@ -304,6 +310,7 @@ public class VppDeviceServiceImpl implements VppDeviceService {
         extVppDeviceMapper.updateByExampleSelective(devices,devicesExample);
     }
 
+    @Transactional
     @Override
     public ActivationVO verify(VerifyParam verifyParam) {
         // 查询设备是否已激活
@@ -317,6 +324,7 @@ public class VppDeviceServiceImpl implements VppDeviceService {
             devices.setAppVersion(verifyParam.getDevice().getAppVersion());
             devices.setId(list.get(0).getId());
             extVppDeviceMapper.updateByPrimaryKeySelective(devices);
+            devices = list.get(0);
         }else{
             // 新增设备
             AppsExample example = new AppsExample();
@@ -325,6 +333,7 @@ public class VppDeviceServiceImpl implements VppDeviceService {
             if (!CollectionUtils.isEmpty(apps)) {
                 devices.setAppId(apps.get(0).getId());
             }
+            devices.setId(UUID.randomUUID().toString());
             devices.setAppVersion(verifyParam.getDevice().getAppVersion());
             devices.setModel(verifyParam.getDevice().getModel());
             devices.setOs(verifyParam.getDevice().getOs());
@@ -334,6 +343,8 @@ public class VppDeviceServiceImpl implements VppDeviceService {
             devices.setPlatform(platformEnum.code());
             devices.setStatus(DeviceStatusEnum.UNACTIVATED.code());
             devices.setIsVpp(Short.valueOf("2"));
+            devices.setCreatedAt(new Date());
+            devices.setUpdatedAt(new Date());
             extVppDeviceMapper.insert(devices);
         }
         deviceResVO.setStatus(Objects.requireNonNull(DeviceStatusEnum.getEnumByCode(devices.getStatus())).value());

+ 12 - 12
pdf-tech-core/src/main/resources/sqlmap/AppsMapper.xml

@@ -69,7 +69,7 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, `name`, code, created_at, updated_at, latest_version_id, max_trail_days
+    id, name, code, created_at, updated_at, latest_version_id, max_trail_days
   </sql>
   <select id="selectByExample" parameterType="cn.kdan.pdf.tech.core.model.AppsExample" resultMap="BaseResultMap">
     select
@@ -86,7 +86,7 @@
     </if>
   </select>
   <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
-    select 
+    select
     <include refid="Base_Column_List" />
     from apps
     where id = #{id,jdbcType=BIGINT}
@@ -102,11 +102,11 @@
     </if>
   </delete>
   <insert id="insert" parameterType="cn.kdan.pdf.tech.core.model.Apps">
-    insert into apps (id, `name`, code, 
-      created_at, updated_at, latest_version_id, 
+    insert into apps (id, name, code,
+      created_at, updated_at, latest_version_id,
       max_trail_days)
-    values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, 
-      #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{latestVersionId,jdbcType=INTEGER}, 
+    values (#{id,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR},
+      #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{latestVersionId,jdbcType=INTEGER},
       #{maxTrailDays,jdbcType=DOUBLE})
   </insert>
   <insert id="insertSelective" parameterType="cn.kdan.pdf.tech.core.model.Apps">
@@ -116,7 +116,7 @@
         id,
       </if>
       <if test="name != null">
-        `name`,
+        name,
       </if>
       <if test="code != null">
         code,
@@ -171,7 +171,7 @@
         id = #{row.id,jdbcType=BIGINT},
       </if>
       <if test="row.name != null">
-        `name` = #{row.name,jdbcType=VARCHAR},
+        name = #{row.name,jdbcType=VARCHAR},
       </if>
       <if test="row.code != null">
         code = #{row.code,jdbcType=VARCHAR},
@@ -196,7 +196,7 @@
   <update id="updateByExample" parameterType="map">
     update apps
     set id = #{row.id,jdbcType=BIGINT},
-      `name` = #{row.name,jdbcType=VARCHAR},
+      name = #{row.name,jdbcType=VARCHAR},
       code = #{row.code,jdbcType=VARCHAR},
       created_at = #{row.createdAt,jdbcType=TIMESTAMP},
       updated_at = #{row.updatedAt,jdbcType=TIMESTAMP},
@@ -210,7 +210,7 @@
     update apps
     <set>
       <if test="name != null">
-        `name` = #{name,jdbcType=VARCHAR},
+        name = #{name,jdbcType=VARCHAR},
       </if>
       <if test="code != null">
         code = #{code,jdbcType=VARCHAR},
@@ -232,7 +232,7 @@
   </update>
   <update id="updateByPrimaryKey" parameterType="cn.kdan.pdf.tech.core.model.Apps">
     update apps
-    set `name` = #{name,jdbcType=VARCHAR},
+    set name = #{name,jdbcType=VARCHAR},
       code = #{code,jdbcType=VARCHAR},
       created_at = #{createdAt,jdbcType=TIMESTAMP},
       updated_at = #{updatedAt,jdbcType=TIMESTAMP},
@@ -254,4 +254,4 @@
       order by ${orderByClause}
     </if>
   </select>
-</mapper>
+</mapper>