Просмотр исходного кода

扩展core-solar中AppControl模型,增加自定义控制参数字段

Signed-off-by: luoshi <luoshi@qmth.com.cn>
luoshi 1 год назад
Родитель
Сommit
c7e7c7a5c1

+ 32 - 0
core-solar/src/main/java/com/qmth/boot/core/solar/model/AppControl.java

@@ -1,10 +1,15 @@
 package com.qmth.boot.core.solar.model;
 package com.qmth.boot.core.solar.model;
 
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+
 import java.io.Serializable;
 import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
 
 
 /**
 /**
  * 应用部署控制参数
  * 应用部署控制参数
  */
  */
+@JsonIgnoreProperties(ignoreUnknown = true)
 public class AppControl implements Serializable {
 public class AppControl implements Serializable {
 
 
     private static final long serialVersionUID = -3748275799910491373L;
     private static final long serialVersionUID = -3748275799910491373L;
@@ -15,6 +20,9 @@ public class AppControl implements Serializable {
     //最大在线人数
     //最大在线人数
     private Integer maxOnlineUserCount;
     private Integer maxOnlineUserCount;
 
 
+    //自定义控制参数
+    private Map<String, Object> custom = new HashMap<>();
+
     /**
     /**
      * 判断是否已过期
      * 判断是否已过期
      *
      *
@@ -49,4 +57,28 @@ public class AppControl implements Serializable {
     public void setMaxOnlineUserCount(Integer maxOnlineUserCount) {
     public void setMaxOnlineUserCount(Integer maxOnlineUserCount) {
         this.maxOnlineUserCount = maxOnlineUserCount;
         this.maxOnlineUserCount = maxOnlineUserCount;
     }
     }
+
+    public Map<String, Object> getCustom() {
+        return custom;
+    }
+
+    public void setCustom(Map<String, Object> custom) {
+        this.custom = custom;
+    }
+
+    /**
+     * 读取自定义参数
+     *
+     * @param key
+     * @param <T>
+     * @return 自定进行类型转换,参数不存在或类型不匹配都返回null
+     */
+    public <T> T getCustomParam(String key) {
+        Object value = custom != null ? custom.get(key) : null;
+        try {
+            return value != null ? (T) value : null;
+        } catch (Exception e) {
+            return null;
+        }
+    }
 }
 }

+ 6 - 3
core-solar/src/test/java/com/qmth/boot/test/solar/AppLicenseUtilTest.java

@@ -7,7 +7,6 @@ import com.qmth.boot.tools.crypto.RSA;
 import com.qmth.boot.tools.device.DeviceInfo;
 import com.qmth.boot.tools.device.DeviceInfo;
 import com.qmth.boot.tools.models.ByteArray;
 import com.qmth.boot.tools.models.ByteArray;
 import org.junit.Assert;
 import org.junit.Assert;
-import org.junit.Test;
 
 
 import java.io.File;
 import java.io.File;
 
 
@@ -20,12 +19,16 @@ public class AppLicenseUtilTest {
                 .toFile(new File("/Users/luoshi/Downloads/solar/device-test.info"));
                 .toFile(new File("/Users/luoshi/Downloads/solar/device-test.info"));
     }
     }
 
 
-    @Test
+    //@Test
     public void testParseAppInfo() throws JsonProcessingException {
     public void testParseAppInfo() throws JsonProcessingException {
-        String content = "{\"id\":26,\"name\":\"本地部署\",\"code\":\"markingcloud\",\"control\":{\"expireTime\":33239779200000,\"maxOnlineUserCount\":10},\"orgs\":[]}";
+        //
+        String content = "{\"id\":26,\"name\":\"本地部署\",\"code\":\"markingcloud\",\"control\":{\"expireTime\":33239779200000,\"maxOnlineUserCount\":10, \"custom\":{\"extendKey\":true}},\"orgs\":[]}";
+        //String content = "{\"id\":26,\"name\":\"本地部署\",\"code\":\"markingcloud\",\"control\":{\"expireTime\":33239779200000,\"maxOnlineUserCount\":10},\"orgs\":[]}";
         ObjectMapper mapper = new ObjectMapper();
         ObjectMapper mapper = new ObjectMapper();
         AppLicense license = mapper.readValue(content, AppLicense.class);
         AppLicense license = mapper.readValue(content, AppLicense.class);
         Assert.assertNotNull(license);
         Assert.assertNotNull(license);
         Assert.assertEquals(26, (long) license.getId());
         Assert.assertEquals(26, (long) license.getId());
+        Assert.assertTrue(license.getControl().exceedOnlineUserCount(20));
+        //Assert.assertNotNull(license.getControl().getCustomParam("extendKey"));
     }
     }
 }
 }