fix: repair decompiled sources and add exhaustive documentation

- restore generic signatures, scoped variables and missing code from original bytecode
- remove decompiler artifacts and document classes, methods, fields and packages
- restore resources, add Batik/BouncyCastle dependencies and build/runtime docs
This commit is contained in:
rick committed 2026-11-16 17:28:23 +08:00
1 parent 9d7e42eda8
commit 10aa1829f5
346 files changed
+42404 -622

No files matched your search

@@ -10,34 +10,102 @@ import org.joda.time.DateTime;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
/**
* 【Java 类型】{@code GeneralProfile}
*
* 类职责:
* <ul>
* <li>提供该包内的可复用能力。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code profile}(DbObject):配置档案</li>
* <li>{@code settings}(DbObject):设置列表</li>
* <li>{@code created}(Date):创建时间</li>
* <li>{@code updated}(Date):最后更新时间</li>
* <li>{@code enabled}(Boolean):是否启用</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class GeneralProfile {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
protected UUID uuid;
/**
* 配置档案。
*/
protected DbObject profile;
/**
* 设置列表。
*/
protected DbObject settings;
/**
* 创建时间。
*/
protected Date created;
/**
* 最后更新时间;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
protected Date updated;
/**
* 是否启用。
*/
protected Boolean enabled;
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.generateId();
this.created = new Date();
this.updated = this.created;
}
/**
* 生成ID。
*/
public void generateId() {
this.uuid = UUID.randomUUID();
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code profile}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getProfile() {
if (this.profile == null) {
this.profile = new DbObject();
@@ -46,10 +114,21 @@ public class GeneralProfile {
return this.profile;
}
/**
* 设置 {@code profile}。
*
* @param profile 设备配置档案({@code DbObject})
*/
public void setProfile(DbObject profile) {
this.profile = profile;
}
/**
* 获取 {@code settings}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getSettings() {
if (this.settings == null) {
this.settings = new DbObject();
@@ -58,34 +137,72 @@ public class GeneralProfile {
return this.settings;
}
/**
* 设置 {@code settings}。
*
* @param settings 参数 {@code settings}({@code DbObject})
*/
public void setSettings(DbObject settings) {
this.settings = settings;
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 获取 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
public Date getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code Date})
*/
public void setUpdated(Date updated) {
this.updated = updated;
}
/**
* 设置Updated。
*
* 实现要点:主要调用:new Date。
*/
public void setUpdated() {
this.setUpdated(new Date());
}
/**
* 获取 {@code enabled}。
* @return 字段/派生属性 {@code enabled} 的值
*/
public boolean getEnabled() {
return this.enabled != null && this.enabled;
}
/**
* 判断 {@code ended}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字段/派生属性 {@code ended} 的值
*/
public boolean isEnded() {
if ("ends".equals(this.getProfile("endsOption"))) {
DateTime dateTime = McDateTimeUtils.parseDate((String)this.getProfile("ends"), "yyyy-MM-dd").plusDays(1);
@@ -95,18 +212,38 @@ public class GeneralProfile {
}
}
/**
* 设置 {@code enabled}。
*
* @param enabled 参数 {@code enabled}({@code Boolean})
*/
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Object getProfile(String key) {
return this.getProfile(key, (Object)null);
/**
* 获取配置档案。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code profile} 的值
*/
public <T> T getProfile(String key) {
return this.getProfile(key, (T)null);
}
public Object getProfile(String key, Object defaultValue) {
/**
* 获取配置档案。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 1 个条件分支、0 个循环。
*
* @param key 键/配置项({@code String})
* @param defaultValue 参数 {@code defaultValue}({@code T})
* @return 字段/派生属性 {@code profile} 的值
*/
public <T> T getProfile(String key, T defaultValue) {
if (this.getProfile().containsKey(key)) {
try {
return this.getProfile().get(key);
return (T)this.getProfile().get(key);
} catch (Exception var4) {
}
}
@@ -114,35 +251,96 @@ public class GeneralProfile {
return defaultValue;
}
/**
* 获取配置档案AsBoolean。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @param subCategory 参数 {@code subCategory}({@code String})
* @param item 参数 {@code item}({@code String})
* @param def 参数 {@code def}({@code boolean})
* @return 字段/派生属性 {@code profileAsBoolean} 的值
*/
public boolean getProfileAsBoolean(String category, String key, String subCategory, String item, boolean def) {
Boolean value = McBooleanUtils.isTrue(this.getProfile(category, key, subCategory, item));
return value == null ? def : value;
}
/**
* 获取配置档案。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @param subCategory 参数 {@code subCategory}({@code String})
* @param item 参数 {@code item}({@code String})
* @return 字段/派生属性 {@code profile} 的值
*/
public Object getProfile(String category, String key, String subCategory, String item) {
return this.getProfileCategory(category, key, subCategory).get(item);
}
/**
* 获取配置档案Category。
*
* @param categoryNames 参数 {@code categoryNames}({@code String[]})
* @return MongoDB 文档扩展对象
*/
public DbObject getProfileCategory(String... categoryNames) {
return this.getProfile().getDbObject(categoryNames);
}
/**
* 获取Category配置档案。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code categoryProfile} 的值
*/
public Object getCategoryProfile(String category, String key) {
return this.getProfileCategory(category) == null ? null : this.getProfileCategory(category).get(key);
}
/**
* 设置配置档案。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setProfile(String key, Object value) {
this.getProfile().put(key, value);
}
/**
* 设置配置档案。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setProfile(String category, String key, Object value) {
this.getProfileCategory(category).put(key, value);
}
/**
* 设置配置档案。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param subCategory 参数 {@code subCategory}({@code String})
* @param item 参数 {@code item}({@code String})
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setProfile(String category, String subCategory, String item, String key, Object value) {
this.getProfileCategory(category, subCategory, item).put(key, value);
}
/**
* 移除配置档案。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:remove。
*
* @param key 键/配置项({@code String})
*/
public void removeProfile(String key) {
if (this.profile != null) {
this.profile.remove(key);
@@ -150,47 +348,121 @@ public class GeneralProfile {
}
/**
* 获取设置。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code setting} 的值
*/
public Object getSetting(String key) {
return this.getSettings().get(key);
}
/**
* 获取设置AsString。
*
* @param key 键/配置项({@code String})
* @return 字符串结果
*/
public String getSettingAsString(String key) {
return this.getSettings().getString(key, (String)null);
}
/**
* 获取设置AsInt。
*
* @param key 键/配置项({@code String})
* @param def 参数 {@code def}({@code int})
* @return 数量/长度
*/
public int getSettingAsInt(String key, int def) {
return this.getSettings().getInteger(key, def);
}
/**
* 获取设置AsFloat。
*
* @param key 键/配置项({@code String})
* @param def 参数 {@code def}({@code float})
* @return 字段/派生属性 {@code settingAsFloat} 的值
*/
public float getSettingAsFloat(String key, float def) {
return this.getSettings().getFloat(key, def);
}
/**
* 获取设置AsBoolean。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code settingAsBoolean} 的值
*/
public boolean getSettingAsBoolean(String key) {
return this.getSettingAsBoolean(key, false);
}
/**
* 获取设置AsBoolean。
*
* @param key 键/配置项({@code String})
* @param def 参数 {@code def}({@code boolean})
* @return 字段/派生属性 {@code settingAsBoolean} 的值
*/
public boolean getSettingAsBoolean(String key, boolean def) {
return this.getSettings().containsKey(key) ? McBooleanUtils.isTrue(this.getSetting(key)) : def;
}
/**
* 获取设置AsBoolean。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @param def 参数 {@code def}({@code boolean})
* @return 字段/派生属性 {@code settingAsBoolean} 的值
*/
public boolean getSettingAsBoolean(String category, String key, boolean def) {
Boolean value = McBooleanUtils.isTrue(this.getSetting(category, key));
return value == null ? def : value;
}
/**
* 获取设置AsUUID。
*
* @param key 键/配置项({@code String})
* @return UUID
*/
public UUID getSettingAsUuid(String key) {
return this.getSettings().getUuid(key);
}
/**
* 获取设置列表Category。
*
* @param categoryNames 参数 {@code categoryNames}({@code String[]})
* @return MongoDB 文档扩展对象
*/
public DbObject getSettingsCategory(String... categoryNames) {
return this.getSettings().getDbObject(categoryNames);
}
/**
* 获取设置。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code setting} 的值
*/
public Object getSetting(String category, String key) {
return this.getSettingsCategory(category).get(key);
}
/**
* 设置设置。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param key 键/配置项({@code String})
* @param value 值({@code UUID})
*/
public void setSetting(String key, UUID value) {
if (value != null) {
this.getSettings().put(key, value.toString());
@@ -200,10 +472,25 @@ public class GeneralProfile {
}
/**
* 设置设置。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setSetting(String key, Object value) {
this.getSettings().put(key, value);
}
/**
* 设置设置。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:remove。
*
* @param categoryName 参数 {@code categoryName}({@code String})
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setSetting(String categoryName, String key, Object value) {
Document dbObject = this.getSettingsCategory(categoryName);
if (value != null) {
@@ -214,27 +501,53 @@ public class GeneralProfile {
}
/**
* 移除选项。
*
* @param key 键/配置项({@code String})
*/
public void removeOption(String key) {
this.getSettings().remove(key);
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
Object value = this.getProfile("name");
return value == null ? null : (String)value;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.setProfile("name", name);
}
/**
* 获取 {@code description}。
* @return 字符串结果
*/
public String getDescription() {
return (String)this.getProfile("desc");
}
/**
* 设置 {@code description}。
*
* @param desc 参数 {@code desc}({@code String})
*/
public void setDescription(String desc) {
this.setProfile("desc", desc);
}
/**
* 处理minify。
*/
public void minify() {
this.created = null;
}
@@ -1,25 +1,72 @@
package com.midm.model;
/**
* 【Java 类型】{@code GroupByResult}
*
* 类职责:
* <ul>
* <li>提供该包内的可复用能力。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code groups}(String[]):分组列表</li>
* <li>{@code count}(int):统计</li>
* </ul>
*
* 协作对象:{@code String[]}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class GroupByResult {
/**
* 分组列表。
*/
private String[] groups;
/**
* 统计。
*/
private int count;
/**
* 获取 {@code count}。
* @return 数量/长度
*/
public int getCount() {
return this.count;
}
/**
* 设置 {@code count}。
*
* @param count 参数 {@code count}({@code int})
*/
public void setCount(int count) {
this.count = count;
}
/**
* 获取 {@code group}。
* @return 字符串结果
*/
public String getGroup() {
return this.groups.length > 0 ? this.groups[0] : null;
}
/**
* 获取 {@code groups}。
* @return 字段/派生属性 {@code groups} 的值
*/
public String[] getGroups() {
return this.groups;
}
/**
* 设置 {@code groups}。
*
* @param groups 参数 {@code groups}({@code String[]})
*/
public void setGroups(String[] groups) {
this.groups = groups;
}
@@ -2,6 +2,22 @@ package com.midm.model;
import com.google.common.base.CharMatcher;
/**
* 【枚举常量】{@code IF_EXISTS_OPTION}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code option}(int):选项</li>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public enum IF_EXISTS_OPTION {
ignore(0),
skip(0),
@@ -11,12 +27,28 @@ public enum IF_EXISTS_OPTION {
modify(2),
remove(3);
/**
* 选项。
*/
public int option;
/**
* 构造 {@code IF_EXISTS_OPTION} 实例。
*
* @param option 参数 {@code option}({@code int})
*/
private IF_EXISTS_OPTION(int option) {
this.option = option;
}
/**
* 处理获取。
*
* 实现要点:包含异常捕获与降级/回滚分支。
*
* @param key 键/配置项({@code String})
* @return 处理结果
*/
public static IF_EXISTS_OPTION get(String key) {
try {
return valueOf(CharMatcher.whitespace().removeFrom(key).toLowerCase());
@@ -25,6 +57,12 @@ public enum IF_EXISTS_OPTION {
}
}
/**
* 获取选项。
*
* @param option 参数 {@code option}({@code String})
* @return 数量/长度
*/
public static int getOption(String option) {
return get(option).option;
}
@@ -12,61 +12,147 @@ import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code Battery}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code states}(DbObject):字段 states</li>
* <li>{@code deviceGroupPath}(String):设备分组路径</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndexes({@CompoundIndex(
def = "{'profile.hardware_info.batterySerial':1}",
unique = true
)})
public class Battery extends GeneralProfile {
/**
* 用户所属站点 UUID。
*/
private UUID siteUuid;
/**
* 字段 states。
*/
private DbObject states;
/**
* 设备分组路径;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private String deviceGroupPath;
/**
* 构造 {@code Battery} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public Battery() {
this.init();
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 获取 {@code batterySerial}。
* @return 字符串结果
*/
public String getBatterySerial() {
return (String)this.getCategoryProfile("hardware_info", "batterySerial");
}
/**
* 获取 {@code deviceSerial}。
* @return 字符串结果
*/
public String getDeviceSerial() {
return (String)this.getCategoryProfile("hardware_info", "deviceSerial");
}
/**
* 设置 {@code deviceSerial}。
*
* @param deviceSerial 参数 {@code deviceSerial}({@code String})
*/
public void setDeviceSerial(String deviceSerial) {
this.setProfile("hardware_info", "deviceSerial", deviceSerial.trim());
}
/**
* 获取 {@code model}。
* @return 字符串结果
*/
public String getModel() {
return (String)this.getCategoryProfile("hardware_info", "model");
}
/**
* 获取 {@code deviceId}。
* @return 字符串结果
*/
public String getDeviceId() {
return (String)this.getCategoryProfile("hardware_info", "device_id");
}
/**
* 设置 {@code registerState}。
*
* @param state 参数 {@code state}({@code String})
*/
public void setRegisterState(String state) {
this.getStates().put("state", state);
}
/**
* 获取 {@code registerState}。
* @return 字符串结果
*/
public String getRegisterState() {
return this.getStates().getString("state");
}
/**
* 获取 {@code batteryCondition}。
* @return 数量/长度
*/
public Integer getBatteryCondition() {
return this.getStates().getInteger("batteryCondition", -1);
}
/**
* 获取 {@code states}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getStates() {
if (this.states == null) {
this.states = new DbObject();
@@ -75,20 +161,42 @@ public class Battery extends GeneralProfile {
return this.states;
}
/**
* 获取 {@code deviceGroupPath}。
* @return 字符串结果
*/
public String getDeviceGroupPath() {
return this.deviceGroupPath;
}
/**
* 设置 {@code deviceGroupPath}。
*
* @param deviceGroupPath 参数 {@code deviceGroupPath}({@code String})
*/
public void setDeviceGroupPath(String deviceGroupPath) {
this.deviceGroupPath = deviceGroupPath;
}
/**
* 获取 {@code lastTemp}。
*
* 实现要点:主要调用:new TypeToken。
* @return 字段/派生属性 {@code lastTemp} 的值
*/
public ValueWithTime getLastTemp() {
List<ValueWithTime> dbTempList = (List)McJsonUtils.toObject(McJsonUtils.toJson(this.getStates().get("temperature")), (new TypeToken() {
}).getType());
return dbTempList.isEmpty() ? null : (ValueWithTime)dbTempList.get(0);
}
/**
* 设置 {@code lastTemp}。
*
* 实现要点:主要调用:new DbObject、new ArrayList。
*
* @param t 参数 {@code t}({@code ValueWithTime})
*/
public void setLastTemp(ValueWithTime t) {
DbObject obj = new DbObject();
obj.append("reportedAt", t.getReportedAt()).append("value", t.getValue());
@@ -97,22 +205,58 @@ public class Battery extends GeneralProfile {
this.getStates().put("temperature", list);
}
/**
* 【枚举常量】{@code BATTERY_CONDITION}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code value}(int):值</li>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public static enum BATTERY_CONDITION {
UNKNOWN(-1),
GOOD(0),
AVERAGE(1),
SERVICE_SOON(2);
/**
* 值。
*/
private int value;
/**
* 构造 {@code BATTERY_CONDITION} 实例。
*
* @param value 值({@code int})
*/
private BATTERY_CONDITION(int value) {
this.value = value;
}
/**
* 获取 {@code value}。
* @return 数量/长度
*/
public int getValue() {
return this.value;
}
/**
* 处理用于值。
*
* 实现要点:包含 1 个条件分支、1 个循环。
*
* @param value 值({@code int})
* @return 处理结果
*/
public static BATTERY_CONDITION forValue(int value) {
for(BATTERY_CONDITION e : values()) {
if (e.value == value) {
@@ -8,35 +8,108 @@ import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code BatteryLog}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code batterySerial}(String):电池序列</li>
* <li>{@code category}(String):字段 category</li>
* <li>{@code log}(String):日志</li>
* <li>{@code reportedAt}(Date):时间字段</li>
* <li>{@code states}(DbObject):字段 states</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndex(
def = "{batterySerial: 1, reportedAt: 1}"
)
public class BatteryLog {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid = UUID.randomUUID();
/**
* 电池序列;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private String batterySerial;
/**
* 字段 category;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private String category;
/**
* 日志。
*/
private String log;
/**
* 时间字段;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date reportedAt;
/**
* 字段 states。
*/
private DbObject states;
/**
* 时间字段。
*/
private Date recordedAt = new Date();
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 获取 {@code batterySerial}。
* @return 字符串结果
*/
public String getBatterySerial() {
return this.batterySerial;
}
/**
* 设置 {@code category}。
*
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public void setCategory(String category) {
this.category = category;
}
/**
* 获取 {@code states}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getStates() {
if (this.states == null) {
this.states = new DbObject();
@@ -45,6 +118,10 @@ public class BatteryLog {
return this.states;
}
/**
* 获取 {@code reportedAt}。
* @return 字段/派生属性 {@code reportedAt} 的值
*/
public Date getReportedAt() {
return this.reportedAt;
}
@@ -2,27 +2,74 @@ package com.midm.model.battery;
import java.util.Date;
/**
* 【领域模型】{@code ValueWithTime}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code reportedAt}(Date):时间字段</li>
* <li>{@code value}(double):值</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class ValueWithTime {
/**
* 时间字段。
*/
private Date reportedAt;
/**
* 值。
*/
private double value;
/**
* 构造 {@code ValueWithTime} 实例。
*
* @param reportedAt 参数 {@code reportedAt}({@code Date})
* @param value 值({@code double})
*/
public ValueWithTime(Date reportedAt, double value) {
this.reportedAt = reportedAt;
this.value = value;
}
/**
* 获取 {@code reportedAt}。
* @return 字段/派生属性 {@code reportedAt} 的值
*/
public Date getReportedAt() {
return this.reportedAt;
}
/**
* 设置 {@code reportedAt}。
*
* @param reportedAt 参数 {@code reportedAt}({@code Date})
*/
public void setReportedAt(Date reportedAt) {
this.reportedAt = reportedAt;
}
/**
* 获取 {@code value}。
* @return 字段/派生属性 {@code value} 的值
*/
public double getValue() {
return this.value;
}
/**
* 设置 {@code value}。
*
* @param value 值({@code double})
*/
public void setValue(double value) {
this.value = value;
}
@@ -0,0 +1,14 @@
/**
* 电池健康度(BMS)模型:电压、温度、循环次数、SOH 状态等遥测数据。
*
* <p>本包主要类型:
* <ul>
* <li>{@link Battery}</li>
* <li>{@link BatteryLog}</li>
* <li>{@link ValueWithTime}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.battery;
@@ -2,89 +2,222 @@ package com.midm.model.device;
import com.google.common.base.Strings;
/**
* 【领域模型】{@code AppInfo}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code packageName}(String):package名称</li>
* <li>{@code label}(String):字段 label</li>
* <li>{@code versionName}(String):版本名称</li>
* <li>{@code versionCode}(Integer):版本代码</li>
* <li>{@code minSdkVersion}(Integer):minSDK版本</li>
* <li>{@code appSize}(Long):应用数量</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class AppInfo {
/**
* package名称。
*/
private String packageName;
/**
* 字段 label。
*/
private String label;
/**
* 版本名称。
*/
private String versionName;
/**
* 版本代码。
*/
private Integer versionCode;
/**
* minSDK版本。
*/
private Integer minSdkVersion;
/**
* 应用数量。
*/
private Long appSize;
/**
* 数据数量。
*/
private Long dataSize;
/**
* 第一Installed。
*/
private Long firstInstalled;
/**
* 最后Updated。
*/
private Long lastUpdated;
/**
* 获取 {@code packageName}。
* @return 字符串结果
*/
public String getPackageName() {
return this.packageName;
}
/**
* 设置 {@code packageName}。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public void setPackageName(String packageName) {
this.packageName = packageName;
}
/**
* 获取 {@code label}。
* @return 字符串结果
*/
public String getLabel() {
return Strings.isNullOrEmpty(this.label) ? this.packageName : this.label;
}
/**
* 设置 {@code label}。
*
* @param label 参数 {@code label}({@code String})
*/
public void setLabel(String label) {
this.label = label;
}
/**
* 获取 {@code versionName}。
* @return 字符串结果
*/
public String getVersionName() {
return this.versionName;
}
/**
* 设置 {@code versionName}。
*
* @param versionName 参数 {@code versionName}({@code String})
*/
public void setVersionName(String versionName) {
this.versionName = versionName;
}
/**
* 获取 {@code versionCode}。
* @return 数量/长度
*/
public int getVersionCode() {
return this.versionCode;
}
/**
* 设置 {@code versionCode}。
*
* @param versionCode 参数 {@code versionCode}({@code int})
*/
public void setVersionCode(int versionCode) {
this.versionCode = versionCode;
}
/**
* 处理minSDK版本。
* @return 数量/长度
*/
public int minSdkVersion() {
return this.minSdkVersion;
}
/**
* 设置 {@code minSdkVersion}。
*
* @param version 参数 {@code version}({@code int})
*/
public void setMinSdkVersion(int version) {
this.minSdkVersion = version;
}
/**
* 获取 {@code appSize}。
* @return 数量/长度
*/
public long getAppSize() {
return this.appSize;
}
/**
* 设置 {@code appSize}。
*
* @param appSize 参数 {@code appSize}({@code long})
*/
public void setAppSize(long appSize) {
this.appSize = appSize;
}
/**
* 获取 {@code dataSize}。
* @return 数量/长度
*/
public long getDataSize() {
return this.dataSize;
}
/**
* 设置 {@code dataSize}。
*
* @param dataSize 参数 {@code dataSize}({@code long})
*/
public void setDataSize(long dataSize) {
this.dataSize = dataSize;
}
/**
* 获取 {@code firstInstalled}。
* @return 数量/长度
*/
public long getFirstInstalled() {
return this.firstInstalled;
}
/**
* 设置 {@code firstInstalled}。
*
* @param firstInstalled 参数 {@code firstInstalled}({@code long})
*/
public void setFirstInstalled(long firstInstalled) {
this.firstInstalled = firstInstalled;
}
/**
* 获取 {@code lastUpdated}。
* @return 数量/长度
*/
public long getLastUpdated() {
return this.lastUpdated;
}
/**
* 设置 {@code lastUpdated}。
*
* @param lastUpdated 参数 {@code lastUpdated}({@code long})
*/
public void setLastUpdated(long lastUpdated) {
this.lastUpdated = lastUpdated;
}
/**
* 返回对象的可读字符串表示。
* @return 字符串结果
*/
public String toString() {
return String.format("%s %s(%s)", this.label, this.versionName, this.packageName);
}
@@ -2,6 +2,21 @@ package com.midm.model.device;
import com.google.common.base.CharMatcher;
/**
* 【枚举常量】{@code DEVICE_PROPERTY}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public enum DEVICE_PROPERTY {
serialno,
serial_no,
@@ -41,6 +56,14 @@ public enum DEVICE_PROPERTY {
rsa,
unknown;
/**
* 处理获取。
*
* 实现要点:包含异常捕获与降级/回滚分支。
*
* @param key 键/配置项({@code String})
* @return 处理结果
*/
public static DEVICE_PROPERTY get(String key) {
try {
return valueOf(CharMatcher.whitespace().removeFrom(key).toLowerCase());
@@ -8,30 +8,98 @@ import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DataUsage}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code deviceUuid}(UUID):设备UUID</li>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code from}(Date):从</li>
* <li>{@code to}(Date):转换为</li>
* <li>{@code usage}(DbObject):用量</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndex(
def = "{deviceUuid: 1, siteUuid: 1}"
)
public class DataUsage {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 设备UUID。
*/
private UUID deviceUuid;
/**
* 用户所属站点 UUID。
*/
private UUID siteUuid;
/**
* 从;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date from;
/**
* 转换为;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date to;
/**
* 用量。
*/
private DbObject usage;
/**
* 时间字段;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed(expireAfterSeconds = 15552000)}。
*/
@Indexed(
expireAfterSeconds = 15552000
)
private Date recordedAt;
/**
* 构造 {@code DataUsage} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*
* 实现要点:主要调用:new Date。
*/
public DataUsage() {
this.uuid = UUID.randomUUID();
this.recordedAt = new Date();
}
/**
* 构造 {@code DataUsage} 实例。
*
* 实现要点:包含 5 个条件分支、0 个循环;主要调用:new Date、remove。
*
* @param device 设备({@code Device})
* @param report 参数 {@code report}({@code DbObject})
*/
public DataUsage(Device device, DbObject report) {
this();
this.setSiteUuid(device.getSiteUuid());
@@ -67,70 +135,152 @@ public class DataUsage {
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.deviceUuid;
}
/**
* 设置 {@code deviceUuid}。
*
* @param deviceUuid 设备 UUID({@code UUID})
*/
public void setDeviceUuid(UUID deviceUuid) {
this.deviceUuid = deviceUuid;
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code from}。
* @return 字段/派生属性 {@code from} 的值
*/
public Date getFrom() {
return this.from;
}
/**
* 设置 {@code from}。
*
* @param from 起始时间({@code Date})
*/
public void setFrom(Date from) {
this.from = from;
}
/**
* 获取 {@code to}。
* @return 字段/派生属性 {@code to} 的值
*/
public Date getTo() {
return this.to;
}
/**
* 设置 {@code to}。
*
* @param to 结束时间({@code Date})
*/
public void setTo(Date to) {
this.to = to;
}
/**
* 获取 {@code usage}。
* @return MongoDB 文档扩展对象
*/
public DbObject getUsage() {
return this.usage;
}
/**
* 获取用量。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @return 数量/长度
*/
public long getUsage(String category, String key) {
return this.getUsage().getDbObject(new String[]{category}).getLong(key, 0L);
}
/**
* 设置 {@code usage}。
*
* @param usage 参数 {@code usage}({@code DbObject})
*/
public void setUsage(DbObject usage) {
this.usage = usage;
}
/**
* 获取 {@code recordedAt}。
* @return 字段/派生属性 {@code recordedAt} 的值
*/
public Date getRecordedAt() {
return this.recordedAt;
}
/**
* 设置 {@code recordedAt}。
*
* @param recordedAt 参数 {@code recordedAt}({@code Date})
*/
public void setRecordedAt(Date recordedAt) {
this.recordedAt = recordedAt;
}
/**
* 判断是否LaterThan。
*
* @param usage 参数 {@code usage}({@code DataUsage})
* @return 字段/派生属性 {@code laterThan} 的值
*/
public boolean isLaterThan(DataUsage usage) {
return usage.getTo().getTime() < this.getFrom().getTime();
}
/**
* 判断是否Overlapped。
*
* @param usage 参数 {@code usage}({@code DataUsage})
* @return 字段/派生属性 {@code overlapped} 的值
*/
public boolean isOverlapped(DataUsage usage) {
return usage.getFrom().getTime() >= this.getTo().getTime() && usage.getTo().getTime() <= this.getTo().getTime();
}
+342 -5
View File
@@ -80,7 +80,7 @@ public class Device extends GeneralProfile {
/** 临时字段:设备当前生效的策略清单缓存 */
@Transient
private List deviceProfiles;
private List<Document> deviceProfiles;
/** 许可激活时间点索引 */
@Indexed
@@ -107,40 +107,82 @@ public class Device extends GeneralProfile {
private Date lastDisconnected;
/** 终端已安装的应用程序包信息清单快照 */
private List installedApps;
private List<AppInfo> installedApps;
/**
* 获取 {@code rsa}。
* @return 字符串结果
*/
public String getRsa() {
return this.rsa;
}
/**
* 设置 {@code rsa}。
*
* @param rsa 参数 {@code rsa}({@code String})
*/
public void setRsa(String rsa) {
this.rsa = rsa;
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code groupUuid}。
* @return UUID
*/
public UUID getGroupUuid() {
return this.groupUuid;
}
/**
* 获取 {@code groupPath}。
* @return 字符串结果
*/
public String getGroupPath() {
return this.groupPath;
}
/**
* 设置 {@code groupPath}。
*
* @param groupPath 参数 {@code groupPath}({@code String})
*/
public void setGroupPath(String groupPath) {
this.groupPath = groupPath;
}
/**
* 获取 {@code owner}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getOwner() {
return this.owner;
}
/**
* 设置 {@code owner}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param owner 参数 {@code owner}({@code User})
*/
public void setOwner(User owner) {
this.owner = owner;
if (owner != null) {
@@ -149,18 +191,40 @@ public class Device extends GeneralProfile {
}
/**
* 获取 {@code ownerUuid}。
* @return UUID
*/
public UUID getOwnerUuid() {
return this.ownerUuid;
}
/**
* 设置 {@code ownerUuid}。
*
* @param ownerUuid 所有者用户 UUID({@code UUID})
*/
public void setOwnerUuid(UUID ownerUuid) {
this.ownerUuid = ownerUuid;
}
/**
* 判断 {@code owner}。
* @return 字段/派生属性 {@code owner} 的值
*/
public boolean hasOwner() {
return this.getOwner() != null;
}
/**
* 获取所有者信息。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param key 键/配置项({@code String})
* @param defaultValue 参数 {@code defaultValue}({@code String})
* @return 字符串结果
*/
public String getOwnerInfo(String key, String defaultValue) {
if (this.owner == null) {
DbObject owner = this.getProfileCategory(new String[]{"owner"});
@@ -170,18 +234,37 @@ public class Device extends GeneralProfile {
}
}
/**
* 判断 {@code associated}。
* @return 字段/派生属性 {@code associated} 的值
*/
public boolean isAssociated() {
return this.getDeviceGroup() != null;
}
/**
* 判断 {@code register}。
* @return 字段/派生属性 {@code register} 的值
*/
public boolean canRegister() {
return !Strings.isNullOrEmpty(this.getSerialNo());
}
/**
* 获取 {@code deviceGroup}。
* @return 设备分组;未找到时返回 {@code null}
*/
public DeviceGroup getDeviceGroup() {
return this.deviceGroup;
}
/**
* 设置 {@code deviceGroup}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param deviceGroup 设备分组对象({@code DeviceGroup})
*/
public void setDeviceGroup(DeviceGroup deviceGroup) {
if (deviceGroup != null && deviceGroup.getSiteUuid().equals(this.getSiteUuid())) {
this.deviceGroup = deviceGroup;
@@ -192,6 +275,12 @@ public class Device extends GeneralProfile {
}
/**
* 获取 {@code states}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getStates() {
if (this.states == null) {
this.states = new DbObject();
@@ -200,132 +289,276 @@ public class Device extends GeneralProfile {
return this.states;
}
/**
* 设置 {@code states}。
*
* @param states 参数 {@code states}({@code DbObject})
*/
public void setStates(DbObject states) {
this.states = states;
}
/**
* 获取 {@code state}。
* @return 字符串结果
*/
public String getState() {
return this.getStates().getString("state", "unknown");
}
/**
* 设置 {@code state}。
*
* @param state 参数 {@code state}({@code String})
*/
public void setState(String state) {
this.setState("state", state);
}
/**
* 判断 {@code online}。
* @return 字段/派生属性 {@code online} 的值
*/
public boolean isOnline() {
return this.getStates().getBoolean("isOnline", false);
}
/**
* 设置 {@code online}。
*
* @param online 参数 {@code online}({@code boolean})
*/
public void setOnline(boolean online) {
this.setState("isOnline", online);
}
/**
* 判断 {@code blocked}。
* @return 字段/派生属性 {@code blocked} 的值
*/
public boolean isBlocked() {
return this.getStates().containsKey("blocked");
}
/**
* 设置状态。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setState(String key, Object value) {
this.getStates().append(key, value);
}
/**
* 设置 {@code clientVersion}。
*
* @param version 参数 {@code version}({@code int})
*/
public void setClientVersion(int version) {
this.getStates().put("clientVersion", version);
}
/**
* 获取 {@code clientVersion}。
* @return 数量/长度
*/
public int getClientVersion() {
return this.getStates().getInteger("clientVersion", -1);
}
/**
* 获取 {@code batteryCondition}。
* @return 字段/派生属性 {@code batteryCondition} 的值
*/
public Battery.BATTERY_CONDITION getBatteryCondition() {
return Battery.BATTERY_CONDITION.forValue(this.getStates().getInteger("batteryCondition", -1));
}
/**
* 判断 {@code oldClient}。
* @return 字段/派生属性 {@code oldClient} 的值
*/
public boolean hasOldClient() {
return this.getClientVersion() < 0;
}
/**
* 获取 {@code enrolled}。
* @return 字段/派生属性 {@code enrolled} 的值
*/
public Date getEnrolled() {
return this.enrolled;
}
/**
* 判断 {@code enrolled}。
* @return 字段/派生属性 {@code enrolled} 的值
*/
public boolean isEnrolled() {
return this.enrolled != null;
}
/**
* 设置 {@code enrolled}。
*
* @param enrolled 参数 {@code enrolled}({@code Date})
*/
public void setEnrolled(Date enrolled) {
this.enrolled = enrolled;
this.setState("enrolled");
this.setLicenseExpiry();
}
/**
* 判断 {@code retired}。
* @return 字段/派生属性 {@code retired} 的值
*/
public boolean isRetired() {
return this.getState().equals("retired");
}
/**
* 获取 {@code lastCheckedIn}。
* @return 字段/派生属性 {@code lastCheckedIn} 的值
*/
public Date getLastCheckedIn() {
return this.lastCheckedIn;
}
/**
* 设置最后Checked在。
*
* 实现要点:主要调用:new Date。
*/
public void setLastCheckedIn() {
this.setLastCheckedIn(new Date());
}
/**
* 设置 {@code lastCheckedIn}。
*
* @param lastCheckedIn 参数 {@code lastCheckedIn}({@code Date})
*/
public void setLastCheckedIn(Date lastCheckedIn) {
this.lastCheckedIn = lastCheckedIn;
}
/**
* 获取 {@code lastDisconnected}。
* @return 字段/派生属性 {@code lastDisconnected} 的值
*/
public Date getLastDisconnected() {
return this.lastDisconnected;
}
/**
* 设置最后Disconnected。
*
* 实现要点:主要调用:new Date。
*/
public void setLastDisconnected() {
this.lastDisconnected = new Date();
}
/**
* 设置 {@code lastDisconnected}。
*
* @param disconnected 参数 {@code disconnected}({@code Date})
*/
public void setLastDisconnected(Date disconnected) {
this.lastDisconnected = disconnected;
}
public List getInstalledApps() {
/**
* 获取 {@code installedApps}。
* @return 应用信息列表,可能为空
*/
public List<AppInfo> getInstalledApps() {
return this.installedApps;
}
public void setInstalledApps(List installedApps) {
/**
* 设置 {@code installedApps}。
*
* @param installedApps 参数 {@code installedApps}({@code List<AppInfo>})
*/
public void setInstalledApps(List<AppInfo> installedApps) {
this.installedApps = installedApps;
}
public void setDeviceProfiles(List deviceProfiles) {
/**
* 设置 {@code deviceProfiles}。
*
* @param deviceProfiles 参数 {@code deviceProfiles}({@code List<Document>})
*/
public void setDeviceProfiles(List<Document> deviceProfiles) {
this.deviceProfiles = deviceProfiles;
}
/**
* 获取 {@code serialNo}。
* @return 字符串结果
*/
public String getSerialNo() {
return (String)this.getCategoryProfile("hardware_info", "serial_no");
}
/**
* 设置 {@code serialNo}。
*
* @param serialNo 设备序列号({@code String})
*/
public void setSerialNo(String serialNo) {
this.setProfile("hardware_info", "serial_no", serialNo.trim());
}
/**
* 获取 {@code modelId}。
* @return 字符串结果
*/
public String getModelId() {
return (String)this.getCategoryProfile("hardware_info", "product_id");
}
/**
* 获取 {@code buildNo}。
* @return 字符串结果
*/
public String getBuildNo() {
return this.getProfileCategory(new String[]{"software_info"}).getString("build_no");
}
/**
* 获取 {@code displayId}。
* @return 字符串结果
*/
public String getDisplayId() {
return this.getProfileCategory(new String[]{"software_info"}).getString("display_id");
}
/**
* 获取 {@code productDisplayId}。
* @return 字符串结果
*/
public String getProductDisplayId() {
return this.getProfileCategory(new String[]{"software_info"}).getString("product_display_id");
}
/**
* 获取 {@code buildDate}。
* @return 数量/长度
*/
public long getBuildDate() {
return this.getProfileCategory(new String[]{"software_info"}).getLong("build_date", -1L);
}
/**
* 获取 {@code sdkVersion}。
*
* 实现要点:包含 8 个条件分支、0 个循环。
* @return 数量/长度
*/
public int getSdkVersion() {
if (this.isEnrolled()) {
int version = this.getProfileCategory(new String[]{"software_info"}).getInteger("sdk_version", -1);
@@ -352,26 +585,52 @@ public class Device extends GeneralProfile {
}
}
/**
* 获取 {@code customerId}。
* @return 字符串结果
*/
public String getCustomerId() {
return (String)this.getCategoryProfile("software_info", "customer_id");
}
/**
* 获取 {@code regionImgVersion}。
* @return 字符串结果
*/
public String getRegionImgVersion() {
return this.getProfile().getDbObject(new String[]{"software_info"}).getString("region_version");
}
/**
* 获取 {@code scriptVersion}。
* @return 字符串结果
*/
public String getScriptVersion() {
return (String)this.getCategoryProfile("software_info", "script_version");
}
/**
* 获取 {@code regionBuildDate}。
* @return 数量/长度
*/
public long getRegionBuildDate() {
return this.getProfile().getDbObject(new String[]{"software_info"}).getLong("region_build_date");
}
/**
* 判断 {@code gmsAvailable}。
* @return 字段/派生属性 {@code gmsAvailable} 的值
*/
public boolean isGmsAvailable() {
return this.getProfile().getDbObject(new String[]{"software_info"}).getBoolean("gms_available");
}
/**
* 获取 {@code skuId}。
*
* 实现要点:包含 7 个条件分支、0 个循环。
* @return 字符串结果
*/
public String getSkuId() {
String skuId = (String)this.getCategoryProfile("hardware_info", "sku_id");
if (skuId == null) {
@@ -404,27 +663,54 @@ public class Device extends GeneralProfile {
return skuId;
}
/**
* 获取 {@code deviceId}。
* @return 字符串结果
*/
public String getDeviceId() {
return (String)this.getCategoryProfile("hardware_info", "device_id");
}
/**
* 获取 {@code buildFingerPrint}。
* @return 字符串结果
*/
public String getBuildFingerPrint() {
return (String)this.getCategoryProfile("software_info", "build_fingerprint");
}
/**
* 判断 {@code mobileConnected}。
* @return 字段/派生属性 {@code mobileConnected} 的值
*/
public boolean isMobileConnected() {
String type = this.getProfileCategory(new String[]{"network", "active"}).getString("type");
return "MOBILE".equalsIgnoreCase(type);
}
/**
* 获取 {@code wifiMacAddr}。
* @return 字符串结果
*/
public String getWifiMacAddr() {
return this.getProfileCategory(new String[]{"network", "wifi"}).getString("mac_address");
}
/**
* 获取 {@code license}。
* @return 字段/派生属性 {@code license} 的值
*/
public DeviceLicense getLicense() {
return this.license;
}
/**
* 设置 {@code license}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new Date。
*
* @param license 参数 {@code license}({@code DeviceLicense})
*/
public void setLicense(DeviceLicense license) {
this.license = license;
if (license != null) {
@@ -434,14 +720,28 @@ public class Device extends GeneralProfile {
}
/**
* 获取 {@code licensed}。
* @return 字段/派生属性 {@code licensed} 的值
*/
public Date getLicensed() {
return this.licensed;
}
/**
* 设置 {@code licensed}。
*
* @param licensed 参数 {@code licensed}({@code Date})
*/
public void setLicensed(Date licensed) {
this.licensed = licensed;
}
/**
* 设置许可证Expiry。
*
* 实现要点:包含 2 个条件分支、0 个循环。
*/
private void setLicenseExpiry() {
if (this.hasLicense()) {
if (!this.license.isActivated() && this.isEnrolled()) {
@@ -452,6 +752,12 @@ public class Device extends GeneralProfile {
}
}
/**
* 获取 {@code licenseExpiry}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字段/派生属性 {@code licenseExpiry} 的值
*/
public Date getLicenseExpiry() {
if (this.licenseExpiry == null && this.hasLicense()) {
this.licenseExpiry = this.license.getExpiry();
@@ -460,35 +766,66 @@ public class Device extends GeneralProfile {
return this.licenseExpiry;
}
/**
* 判断 {@code licenseExpired}。
* @return 字段/派生属性 {@code licenseExpired} 的值
*/
public boolean isLicenseExpired() {
return this.license != null && !this.license.isPerpetual() && this.license.isExpired();
}
/**
* 设置 {@code licenseExpiry}。
*
* @param expiry 参数 {@code expiry}({@code Date})
*/
public void setLicenseExpiry(Date expiry) {
this.licenseExpiry = expiry;
}
/**
* 判断 {@code license}。
* @return 字段/派生属性 {@code license} 的值
*/
public boolean hasLicense() {
return this.license != null;
}
/**
* 判断 {@code trial}。
* @return 字段/派生属性 {@code trial} 的值
*/
public boolean isTrial() {
return !this.hasLicense() || this.license.isTrial();
}
/**
* 移除许可证。
*/
public void removeLicense() {
this.setLicense((DeviceLicense)null);
}
/**
* 获取 {@code plan}。
* @return 字符串结果
*/
public String getPlan() {
return this.license.getPlan();
}
/**
* 处理重置。
*/
public void reset() {
this.setEnrolled((Date)null);
this.getStates().clear();
}
/**
* 处理clone。
* @return 匹配的设备对象;未找到时返回 {@code null}
*/
public Device clone() {
return (Device)McJsonUtils.clone(this);
}
@@ -10,64 +10,167 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceApps}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code deviceUuid}(UUID):设备UUID</li>
* <li>{@code serialNo}(String):序列号</li>
* <li>{@code category}(String):字段 category</li>
* <li>{@code apps}(List<AppInfo>):应用列表</li>
* <li>{@code reported}(Date):时间字段</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class DeviceApps {
/**
* 设备UUID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID deviceUuid;
/**
* 序列号;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private String serialNo;
/**
* 字段 category。
*/
private String category = "installed";
private List apps;
/**
* 应用列表。
*/
private List<AppInfo> apps;
/**
* 时间字段。
*/
private Date reported = new Date();
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.deviceUuid;
}
/**
* 设置 {@code deviceUuid}。
*
* @param deviceUuid 设备 UUID({@code UUID})
*/
public void setDeviceUuid(UUID deviceUuid) {
this.deviceUuid = deviceUuid;
}
/**
* 获取 {@code serialNo}。
* @return 字符串结果
*/
public String getSerialNo() {
return this.serialNo;
}
/**
* 设置 {@code serialNo}。
*
* @param serialNo 设备序列号({@code String})
*/
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
/**
* 获取 {@code category}。
* @return 字符串结果
*/
public String getCategory() {
return this.category;
}
/**
* 设置 {@code category}。
*
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public void setCategory(String category) {
this.category = category;
}
public List getApps() {
/**
* 获取 {@code apps}。
* @return 应用信息列表,可能为空
*/
public List<AppInfo> getApps() {
return this.apps;
}
public void setApps(List apps) {
/**
* 设置 {@code apps}。
*
* @param apps 参数 {@code apps}({@code List<AppInfo>})
*/
public void setApps(List<AppInfo> apps) {
this.apps = apps;
}
/**
* 获取 {@code clientService}。
* @return 字段/派生属性 {@code clientService} 的值
*/
public AppInfo getClientService() {
return this.getApp("com.mitac.midm.client");
}
/**
* 设置 {@code clientService}。
*
* @param appInfo 参数 {@code appInfo}({@code AppInfo})
*/
public void setClientService(AppInfo appInfo) {
this.setApp(appInfo);
}
/**
* 获取 {@code systemService}。
* @return 字段/派生属性 {@code systemService} 的值
*/
public AppInfo getSystemService() {
return this.getApp("com.mitac.midm.system");
}
/**
* 设置 {@code systemService}。
*
* @param appInfo 参数 {@code appInfo}({@code AppInfo})
*/
public void setSystemService(AppInfo appInfo) {
this.setApp(appInfo);
}
/**
* 获取应用。
*
* 实现要点:包含 2 个条件分支、1 个循环。
*
* @param packageName 参数 {@code packageName}({@code String})
* @return 字段/派生属性 {@code app} 的值
*/
public AppInfo getApp(String packageName) {
if (this.apps != null) {
for(AppInfo app : this.apps) {
@@ -81,6 +184,13 @@ public class DeviceApps {
return null;
}
/**
* 设置 {@code app}。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new ArrayList。
*
* @param newApp 参数 {@code newApp}({@code AppInfo})
*/
public void setApp(AppInfo newApp) {
if (newApp != null && !Strings.isNullOrEmpty(newApp.getPackageName())) {
if (this.apps == null) {
@@ -91,6 +201,11 @@ public class DeviceApps {
}
}
/**
* 修复Abnormal。
*
* 实现要点:包含 2 个条件分支、1 个循环;主要调用:remove。
*/
public void fixAbnormal() {
Iterator<AppInfo> it = this.apps.iterator();
@@ -107,14 +222,34 @@ public class DeviceApps {
}
/**
* 获取 {@code reported}。
* @return 字段/派生属性 {@code reported} 的值
*/
public Date getReported() {
return this.reported;
}
/**
* 设置 {@code reported}。
*
* @param reported 参数 {@code reported}({@code Date})
*/
public void setReported(Date reported) {
this.reported = reported;
}
/**
* 判断是否应用Installed。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param deviceSdk 参数 {@code deviceSdk}({@code int})
* @param packageName 参数 {@code packageName}({@code String})
* @param versionCode 参数 {@code versionCode}({@code long})
* @param minSdk 参数 {@code minSdk}({@code int})
* @return 字段/派生属性 {@code appInstalled} 的值
*/
public boolean isAppInstalled(int deviceSdk, String packageName, long versionCode, int minSdk) {
if (minSdk != -1 && deviceSdk < minSdk) {
return true;
@@ -124,6 +259,14 @@ public class DeviceApps {
}
}
/**
* 比较当前对象与另一个对象是否相等。
*
* 实现要点:包含 4 个条件分支、1 个循环。
*
* @param obj 参数 {@code obj}({@code Object})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean equals(Object obj) {
List<AppInfo> newApps = null;
if (obj instanceof DeviceApps) {
@@ -6,23 +6,78 @@ import java.util.UUID;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceGroup}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code parentUuid}(UUID):父级UUID</li>
* <li>{@code order}(Integer):字段 order</li>
* <li>{@code deviceNumbers}(Integer):设备Numbers</li>
* <li>{@code children}(List<DeviceGroup>):子级</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class DeviceGroup extends GeneralProfile implements Comparable {
public class DeviceGroup extends GeneralProfile implements Comparable<Object> {
/**
* 用户所属站点 UUID。
*/
private UUID siteUuid;
/**
* 父级UUID。
*/
private UUID parentUuid;
/**
* 字段 order。
*/
private Integer order;
/**
* 设备Numbers;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Integer deviceNumbers;
private List children;
/**
* 子级。
*/
private List<DeviceGroup> children;
/**
* 构造 {@code DeviceGroup} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public DeviceGroup() {
this.deviceNumbers = 0;
}
/**
* 构造 {@code DeviceGroup} 实例。
*
* @param uuid 对象 UUID({@code UUID})
*/
public DeviceGroup(UUID uuid) {
this.uuid = uuid;
}
/**
* 构造 {@code DeviceGroup} 实例。
*
* @param siteUuid 站点 UUID({@code UUID})
* @param parentUuid 参数 {@code parentUuid}({@code UUID})
* @param name 参数 {@code name}({@code String})
*/
public DeviceGroup(UUID siteUuid, UUID parentUuid, String name) {
this.init();
this.siteUuid = siteUuid;
@@ -30,50 +85,109 @@ public class DeviceGroup extends GeneralProfile implements Comparable {
this.setName(name);
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code parentUuid}。
* @return UUID
*/
public UUID getParentUuid() {
return this.parentUuid;
}
/**
* 设置 {@code parentUuid}。
*
* @param parentUuid 参数 {@code parentUuid}({@code UUID})
*/
public void setParentUuid(UUID parentUuid) {
this.parentUuid = parentUuid;
}
/**
* 获取 {@code order}。
* @return 数量/长度
*/
public Integer getOrder() {
return this.order;
}
/**
* 设置 {@code order}。
*
* @param order 参数 {@code order}({@code Integer})
*/
public void setOrder(Integer order) {
this.order = order;
}
/**
* 获取 {@code deviceNumbers}。
* @return 数量/长度
*/
public Integer getDeviceNumbers() {
return this.deviceNumbers;
}
/**
* 设置 {@code deviceNumbers}。
*
* @param numbers 参数 {@code numbers}({@code Integer})
*/
public void setDeviceNumbers(Integer numbers) {
this.deviceNumbers = numbers == null ? 0 : numbers;
}
public List getChildren() {
/**
* 获取 {@code children}。
* @return 设备分组列表,可能为空
*/
public List<DeviceGroup> getChildren() {
return this.children;
}
public void setChildren(List children) {
/**
* 设置 {@code children}。
*
* @param children 参数 {@code children}({@code List<DeviceGroup>})
*/
public void setChildren(List<DeviceGroup> children) {
this.children = children;
}
/**
* 比较当前对象与另一个对象是否相等。
*
* @param uuid 对象 UUID({@code UUID})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean equals(UUID uuid) {
return this.uuid != null && this.uuid.equals(uuid);
}
/**
* 按业务字段比较两个对象的顺序。
*
* 实现要点:包含 3 个条件分支、0 个循环。
*
* @param target 参数 {@code target}({@code Object})
* @return 数量/长度
*/
public int compareTo(Object target) {
UUID targetUuid = null;
if (target instanceof UUID) {
@@ -6,19 +6,68 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceKey}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code deviceSerial}(String):设备序列</li>
* <li>{@code rsa}(String):RSA</li>
* <li>{@code created}(Date):创建时间</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class DeviceKey {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 设备序列;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private String deviceSerial;
/**
* RSA。
*/
private String rsa;
/**
* 创建时间。
*/
private Date created;
/**
* 构造 {@code DeviceKey} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public DeviceKey() {
this((String)null, (String)null);
}
/**
* 构造 {@code DeviceKey} 实例。
*
* 实现要点:主要调用:new Date。
*
* @param deviceSerial 参数 {@code deviceSerial}({@code String})
* @param rsa 参数 {@code rsa}({@code String})
*/
public DeviceKey(String deviceSerial, String rsa) {
this.uuid = UUID.randomUUID();
this.created = new Date();
@@ -26,22 +75,44 @@ public class DeviceKey {
this.rsa = rsa;
}
/**
* 获取 {@code deviceSerial}。
* @return 字符串结果
*/
public String getDeviceSerial() {
return this.deviceSerial;
}
/**
* 设置 {@code deviceSerial}。
*
* @param deviceSerial 参数 {@code deviceSerial}({@code String})
*/
public void setDeviceSerial(String deviceSerial) {
this.deviceSerial = deviceSerial;
}
/**
* 获取 {@code rsa}。
* @return 字符串结果
*/
public String getRsa() {
return this.rsa;
}
/**
* 设置 {@code rsa}。
*
* @param rsa 参数 {@code rsa}({@code String})
*/
public void setRsa(String rsa) {
this.rsa = rsa;
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
@@ -17,6 +17,31 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceLicense}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code deviceUuid}(UUID):设备UUID</li>
* <li>{@code deviceSerial}(String):设备序列</li>
* <li>{@code siteLicense}(SiteLicense):站点许可证</li>
* <li>{@code childSiteLicense}(SiteLicense):子站点许可证</li>
* <li>{@code site}(Site):站点</li>
* </ul>
*
* 协作对象:{@code SiteLicense、Site、LicenseModel}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndexes({@CompoundIndex(
def = "{'site.$id': 1}"
@@ -36,33 +61,107 @@ import org.springframework.data.mongodb.core.mapping.Document;
def = "{'childSite.$id': 1, 'site.$id': 1, 'expiry': 1}"
)})
public class DeviceLicense {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 设备UUID;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private UUID deviceUuid;
/**
* 设备序列;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private String deviceSerial;
/**
* 站点许可证;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private SiteLicense siteLicense;
/**
* 子站点许可证;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private SiteLicense childSiteLicense;
/**
* 站点;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private Site site;
/**
* 子站点;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private Site childSite;
/**
* 许可证模型;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private LicenseModel licenseModel;
/**
* 计划。
*/
private String plan;
/**
* 是否autoRenew。
*/
private boolean autoRenew;
/**
* renew转换为Same模型。
*/
private boolean renewToSameModel;
/**
* activation统计。
*/
private int activationCount;
/**
* 时间字段;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date activatedAt;
/**
* 时间字段;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date expiry;
private List reactivated;
/**
* 日期集合。
*/
private List<Date> reactivated;
/**
* 创建时间。
*/
private Date created;
/**
* 构造 {@code DeviceLicense} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*
* 实现要点:主要调用:new Date。
*/
public DeviceLicense() {
this.plan = "standard";
this.autoRenew = false;
@@ -71,44 +170,92 @@ public class DeviceLicense {
this.created = new Date();
}
/**
* 构造 {@code DeviceLicense} 实例。
*
* @param license 参数 {@code license}({@code SiteLicense})
*/
public DeviceLicense(SiteLicense license) {
this((Device)null, (SiteLicense)license);
}
/**
* 构造 {@code DeviceLicense} 实例。
*
* @param license 参数 {@code license}({@code SiteLicense})
* @param plan 参数 {@code plan}({@code String})
*/
public DeviceLicense(SiteLicense license, String plan) {
this((Device)null, (SiteLicense)license);
this.setPlan(plan);
}
/**
* 构造 {@code DeviceLicense} 实例。
*
* @param device 设备({@code Device})
*/
public DeviceLicense(Device device) {
this();
this.setDevice(device);
}
/**
* 构造 {@code DeviceLicense} 实例。
*
* @param device 设备({@code Device})
* @param license 参数 {@code license}({@code SiteLicense})
*/
public DeviceLicense(Device device, SiteLicense license) {
this();
this.setSiteLicense(license);
this.setDevice(device);
}
/**
* 构造 {@code DeviceLicense} 实例。
*
* @param device 设备({@code Device})
* @param licenseModel 参数 {@code licenseModel}({@code LicenseModel})
*/
public DeviceLicense(Device device, LicenseModel licenseModel) {
this();
this.setLicenseModel(licenseModel);
this.setDevice(device);
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code siteLicense}。
* @return 字段/派生属性 {@code siteLicense} 的值
*/
public SiteLicense getSiteLicense() {
return this.siteLicense;
}
/**
* 设置 {@code siteLicense}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param license 参数 {@code license}({@code SiteLicense})
*/
public void setSiteLicense(SiteLicense license) {
this.siteLicense = license;
if (license != null) {
@@ -120,22 +267,46 @@ public class DeviceLicense {
}
/**
* 获取 {@code childSiteLicense}。
* @return 字段/派生属性 {@code childSiteLicense} 的值
*/
public SiteLicense getChildSiteLicense() {
return this.childSiteLicense;
}
/**
* 设置 {@code childSiteLicense}。
*
* @param license 参数 {@code license}({@code SiteLicense})
*/
public void setChildSiteLicense(SiteLicense license) {
this.childSiteLicense = license;
}
/**
* 判断 {@code lite}。
* @return 字段/派生属性 {@code lite} 的值
*/
public boolean isLite() {
return this.site.isLite() || this.plan.equals("lite");
}
/**
* 获取 {@code site}。
* @return 站点对象;未找到时返回 {@code null}
*/
public Site getSite() {
return this.site;
}
/**
* 设置 {@code site}。
*
* 实现要点:包含 2 个条件分支、0 个循环。
*
* @param site 站点/企业({@code Site})
*/
public void setSite(Site site) {
if (site == null) {
this.site = this.childSite = null;
@@ -148,26 +319,56 @@ public class DeviceLicense {
}
/**
* 获取 {@code childSite}。
* @return 站点对象;未找到时返回 {@code null}
*/
public Site getChildSite() {
return this.childSite;
}
/**
* 设置 {@code childSite}。
*
* @param child 参数 {@code child}({@code Site})
*/
public void setChildSite(Site child) {
this.childSite = child;
}
/**
* 判断 {@code licenseModel}。
* @return 字段/派生属性 {@code licenseModel} 的值
*/
public boolean hasLicenseModel() {
return this.getLicenseModel() != null;
}
/**
* 获取 {@code licenseModel}。
* @return 字段/派生属性 {@code licenseModel} 的值
*/
public LicenseModel getLicenseModel() {
return this.licenseModel;
}
/**
* 设置 {@code licenseModel}。
*
* @param licenseModel 参数 {@code licenseModel}({@code LicenseModel})
*/
public void setLicenseModel(LicenseModel licenseModel) {
this.setLicenseModel(licenseModel, true);
}
/**
* 设置许可证模型。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new Date。
*
* @param licenseModel 参数 {@code licenseModel}({@code LicenseModel})
* @param setExpiry 参数 {@code setExpiry}({@code boolean})
*/
public void setLicenseModel(LicenseModel licenseModel, boolean setExpiry) {
this.licenseModel = licenseModel;
if (licenseModel != null && setExpiry) {
@@ -176,14 +377,31 @@ public class DeviceLicense {
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.deviceUuid;
}
/**
* 设置 {@code deviceUuid}。
*
* @param deviceUuid 设备 UUID({@code UUID})
*/
public void setDeviceUuid(UUID deviceUuid) {
this.deviceUuid = deviceUuid;
}
/**
* 设置 {@code device}。
*
* 实现要点:包含 8 个条件分支、0 个循环;主要调用:new Date。
*
* @param device 设备({@code Device})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean setDevice(Device device) {
if (this.isExceedActivationCount() && this.beforeExpiry()) {
return false;
@@ -222,42 +440,89 @@ public class DeviceLicense {
}
}
/**
* 获取 {@code deviceSerial}。
* @return 字符串结果
*/
public String getDeviceSerial() {
return this.deviceSerial;
}
/**
* 设置 {@code deviceSerial}。
*
* @param serialNo 设备序列号({@code String})
*/
public void setDeviceSerial(String serialNo) {
this.deviceSerial = serialNo;
}
/**
* 获取 {@code plan}。
* @return 字符串结果
*/
public String getPlan() {
return this.plan;
}
/**
* 设置 {@code plan}。
*
* @param plan 参数 {@code plan}({@code String})
*/
public void setPlan(String plan) {
this.plan = plan;
}
/**
* 判断 {@code autoRenew}。
* @return 字段/派生属性 {@code autoRenew} 的值
*/
public boolean isAutoRenew() {
return this.autoRenew;
}
/**
* 设置 {@code autoRenew}。
*
* @param autoRenew 参数 {@code autoRenew}({@code boolean})
*/
public void setAutoRenew(boolean autoRenew) {
this.autoRenew = autoRenew;
}
/**
* 判断 {@code renewToSameModel}。
* @return 字段/派生属性 {@code renewToSameModel} 的值
*/
public boolean isRenewToSameModel() {
return this.renewToSameModel;
}
/**
* 设置 {@code renewToSameModel}。
*
* @param renewToSameModel 参数 {@code renewToSameModel}({@code boolean})
*/
public void setRenewToSameModel(boolean renewToSameModel) {
this.renewToSameModel = renewToSameModel;
}
/**
* 获取 {@code activationCount}。
* @return 数量/长度
*/
public int getActivationCount() {
return this.activationCount;
}
/**
* 设置 {@code activationCount}。
*
* 实现要点:包含 2 个条件分支、0 个循环。
*
* @param count 参数 {@code count}({@code int})
*/
public void setActivationCount(int count) {
if (count < 0) {
count = 0;
@@ -270,6 +535,11 @@ public class DeviceLicense {
}
/**
* 重置Activation统计。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*/
public void resetActivationCount() {
if (this.isTrial()) {
this.setActivationCount(0);
@@ -280,22 +550,46 @@ public class DeviceLicense {
}
/**
* 处理exceedActivation统计。
*
* @param maxActivationCount 参数 {@code maxActivationCount}({@code int})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean exceedActivationCount(int maxActivationCount) {
return this.activationCount > maxActivationCount;
}
/**
* 判断 {@code active}。
* @return 字段/派生属性 {@code active} 的值
*/
public boolean isActive() {
return this.activatedAt == null;
}
/**
* 判断 {@code activated}。
* @return 字段/派生属性 {@code activated} 的值
*/
public boolean isActivated() {
return this.activatedAt != null;
}
/**
* 判断 {@code expired}。
* @return 字段/派生属性 {@code expired} 的值
*/
public boolean isExpired() {
return !this.beforeExpiry();
}
/**
* 判断 {@code extend}。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new DateTime。
* @return 字段/派生属性 {@code extend} 的值
*/
public boolean canExtend() {
if (!this.isPerpetual()) {
return false;
@@ -311,14 +605,32 @@ public class DeviceLicense {
}
}
/**
* 获取 {@code activatedAt}。
* @return 字段/派生属性 {@code activatedAt} 的值
*/
public Date getActivatedAt() {
return this.activatedAt;
}
/**
* 处理激活。
*
* 实现要点:主要调用:new Date。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public Boolean activate() {
return this.isActivated() ? true : this.setActivatedAt(new Date());
}
/**
* 设置 {@code activatedAt}。
*
* 实现要点:包含 4 个条件分支、0 个循环。
*
* @param activatedAt 参数 {@code activatedAt}({@code Date})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public Boolean setActivatedAt(Date activatedAt) {
if (!this.isActivated()) {
this.activatedAt = activatedAt;
@@ -339,71 +651,155 @@ public class DeviceLicense {
}
}
/**
* 处理重置。
*/
public void reset() {
this.setDevice((Device)null);
}
/**
* 获取 {@code expiry}。
* @return 字段/派生属性 {@code expiry} 的值
*/
public Date getExpiry() {
return this.expiry;
}
/**
* 处理beforeExpiry。
*
* 实现要点:主要调用:new Date。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean beforeExpiry() {
return this.expiry != null && this.expiry.after(new Date());
}
/**
* 设置 {@code expiry}。
*
* @param expiryDate 参数 {@code expiryDate}({@code Date})
*/
public void setExpiry(Date expiryDate) {
this.expiry = expiryDate;
}
/**
* 处理extendExpiryDays。
*
* 实现要点:主要调用:new DateTime。
*
* @param days 参数 {@code days}({@code int})
*/
public void extendExpiryDays(int days) {
this.setExpiry((new DateTime()).plusDays(days).toDate());
}
/**
* 处理过期。
*
* 实现要点:主要调用:new Date。
*/
public void expire() {
this.setExpiry(new Date());
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 判断 {@code perpetual}。
* @return 字段/派生属性 {@code perpetual} 的值
*/
public boolean isPerpetual() {
return this.licenseModel != null && this.licenseModel.isPerpetual();
}
/**
* 判断 {@code trial}。
* @return 字段/派生属性 {@code trial} 的值
*/
public boolean isTrial() {
return this.siteLicense == null || this.licenseModel == null || this.licenseModel.isTrial();
}
/**
* 判断 {@code exceedActivationCount}。
* @return 字段/派生属性 {@code exceedActivationCount} 的值
*/
public boolean isExceedActivationCount() {
int maxCount = this.licenseModel == null ? 2 : this.licenseModel.getMaxActivation();
return maxCount > 0 && maxCount <= this.activationCount;
}
/**
* 判断 {@code valid}。
*
* 实现要点:主要调用:new Date。
* @return 字段/派生属性 {@code valid} 的值
*/
public boolean isValid() {
return this.isPerpetual() ? true : (new Date()).before(this.expiry);
}
/**
* 判断是否Same许可证模型。
*
* @param licenseModelUuid 许可证型号 UUID({@code UUID})
* @return 字段/派生属性 {@code sameLicenseModel} 的值
*/
public boolean isSameLicenseModel(UUID licenseModelUuid) {
return this.licenseModel != null && this.licenseModel.getUuid().equals(licenseModelUuid);
}
/**
* 获取 {@code remainingDays}。
*
* 实现要点:主要调用:new Date、new DateTime。
* @return 数量/长度
*/
public int getRemainingDays() {
return this.expiry.before(new Date()) ? 0 : McDateTimeUtils.daysBetween(new DateTime(this.expiry), DateTime.now());
}
public List getReactivated() {
/**
* 获取 {@code reactivated}。
* @return 日期列表,可能为空
*/
public List<Date> getReactivated() {
return this.reactivated;
}
public void setReactivated(List reactivated) {
/**
* 设置 {@code reactivated}。
*
* @param reactivated 参数 {@code reactivated}({@code List<Date>})
*/
public void setReactivated(List<Date> reactivated) {
this.reactivated = reactivated;
}
/**
* 处理reactivate。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:new ArrayList、new DateTime。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean reactivate() {
if (this.isPerpetual()) {
if (this.reactivated == null) {
@@ -421,6 +817,10 @@ public class DeviceLicense {
return false;
}
/**
* 获取 {@code po}。
* @return 字符串结果
*/
public String getPo() {
return this.childSiteLicense != null ? this.childSiteLicense.getPo() : (this.siteLicense != null ? this.siteLicense.getPo() : null);
}
@@ -7,66 +7,172 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceNote}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code deviceUuid}(UUID):设备UUID</li>
* <li>{@code writerUuid}(UUID):writerUUID</li>
* <li>{@code writer}(User):字段 writer</li>
* <li>{@code note}(String):备注</li>
* <li>{@code registeredAt}(Date):时间字段</li>
* </ul>
*
* 协作对象:{@code User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class DeviceNote {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 设备UUID。
*/
private UUID deviceUuid;
/**
* writerUUID。
*/
private UUID writerUuid;
/**
* 字段 writer;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private User writer;
/**
* 备注。
*/
private String note;
/**
* 时间字段。
*/
private Date registeredAt;
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.setUuid(UUID.randomUUID());
this.setRegisteredAt(new Date());
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.deviceUuid;
}
/**
* 设置 {@code deviceUuid}。
*
* @param deviceUuid 设备 UUID({@code UUID})
*/
public void setDeviceUuid(UUID deviceUuid) {
this.deviceUuid = deviceUuid;
}
/**
* 获取 {@code writerUuid}。
* @return UUID
*/
public UUID getWriterUuid() {
return this.writerUuid;
}
/**
* 设置 {@code writerUuid}。
*
* @param writerUuid 参数 {@code writerUuid}({@code UUID})
*/
public void setWriterUuid(UUID writerUuid) {
this.writerUuid = writerUuid;
}
/**
* 获取 {@code writer}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getWriter() {
return this.writer;
}
/**
* 设置 {@code writer}。
*
* @param writer 参数 {@code writer}({@code User})
*/
public void setWriter(User writer) {
this.writer = writer;
}
/**
* 获取 {@code note}。
* @return 字符串结果
*/
public String getNote() {
return this.note;
}
/**
* 设置 {@code note}。
*
* @param note 参数 {@code note}({@code String})
*/
public void setNote(String note) {
this.note = note;
}
/**
* 获取 {@code registeredAt}。
* @return 字段/派生属性 {@code registeredAt} 的值
*/
public Date getRegisteredAt() {
return this.registeredAt;
}
/**
* 设置 {@code registeredAt}。
*
* @param registeredAt 参数 {@code registeredAt}({@code Date})
*/
public void setRegisteredAt(Date registeredAt) {
this.registeredAt = registeredAt;
}
@@ -16,61 +16,178 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceProfile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code deviceProfileGroup}(DeviceProfileGroup):设备配置档案分组</li>
* <li>{@code writerUuid}(UUID):writerUUID</li>
* <li>{@code isGlobal}(boolean):判断是否Global</li>
* <li>{@code status}(DbObject):状态</li>
* <li>{@code apps}(ProfileApps):应用列表</li>
* </ul>
*
* 协作对象:{@code DeviceProfileGroup、DbObject、ProfileApps、ProfileScope、User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndex(
def = "{'deviceProfileGroup.uuid': 1}"
)
public class DeviceProfile extends GeneralProfile {
/**
* 用户所属站点 UUID;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private UUID siteUuid;
/**
* 设备配置档案分组;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private DeviceProfileGroup deviceProfileGroup;
/**
* writerUUID。
*/
private UUID writerUuid;
/**
* 判断是否Global。
*/
private boolean isGlobal;
/**
* 状态。
*/
private DbObject status;
/**
* 应用列表。
*/
private ProfileApps apps;
private List otas;
/**
* UUID集合。
*/
private List<UUID> otas;
/**
* 文件列表。
*/
private DbObject files;
/**
* 范围。
*/
private ProfileScope scope;
private List sequence;
/**
* UUID集合。
*/
private List<UUID> sequence;
/**
* 字段 progress;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private DbObject progress;
/**
* 字段 reference;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private DbObject reference;
/**
* 分组UUID;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private UUID groupUuid;
/**
* 字段 writer;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private User writer;
/**
* need旧格式化;Gson 序列化控制;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Expose(serialize = false) @Transient}。
*/
@Expose(
serialize = false
)
@Transient
private boolean needOldFormat = false;
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 判断 {@code global}。
* @return 字段/派生属性 {@code global} 的值
*/
public boolean isGlobal() {
return this.isGlobal;
}
/**
* 设置 {@code isGlobal}。
*
* @param isGlobal 参数 {@code isGlobal}({@code boolean})
*/
public void setIsGlobal(boolean isGlobal) {
this.isGlobal = isGlobal;
}
/**
* 获取 {@code groupUuid}。
* @return UUID
*/
public UUID getGroupUuid() {
return this.groupUuid;
}
/**
* 设置 {@code groupUuid}。
*
* @param groupUuid 分组 UUID({@code UUID})
*/
public void setGroupUuid(UUID groupUuid) {
this.groupUuid = groupUuid;
}
/**
* 获取 {@code deviceProfileGroup}。
* @return 字段/派生属性 {@code deviceProfileGroup} 的值
*/
public DeviceProfileGroup getDeviceProfileGroup() {
return this.deviceProfileGroup;
}
/**
* 设置 {@code deviceProfileGroup}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param deviceProfileGroup 参数 {@code deviceProfileGroup}({@code DeviceProfileGroup})
*/
public void setDeviceProfileGroup(DeviceProfileGroup deviceProfileGroup) {
this.deviceProfileGroup = deviceProfileGroup;
if (deviceProfileGroup == null) {
@@ -79,7 +196,13 @@ public class DeviceProfile extends GeneralProfile {
}
public Set getFileUUids() {
/**
* 获取 {@code fileUUids}。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:new HashSet。
* @return UUID列表,可能为空
*/
public Set<UUID> getFileUUids() {
Set<UUID> pushUuids = new HashSet();
if (this.files != null && !this.files.isEmpty() && this.files.containsKey("push")) {
List<DbObject> pushes = this.files.getList("push", DbObject.class);
@@ -99,74 +222,153 @@ public class DeviceProfile extends GeneralProfile {
return pushUuids;
}
/**
* 应用Order。
* @return 字符串结果
*/
public String applyOrder() {
return this.getProfile().getString("applyOrder", "none");
}
public List getSequence() {
/**
* 获取 {@code sequence}。
* @return UUID列表,可能为空
*/
public List<UUID> getSequence() {
return this.sequence;
}
/**
* 判断 {@code sequence}。
* @return 字段/派生属性 {@code sequence} 的值
*/
public boolean hasSequence() {
return this.sequence != null && !this.sequence.isEmpty();
}
public void setSequence(List sequence) {
/**
* 设置 {@code sequence}。
*
* @param sequence 参数 {@code sequence}({@code List<UUID>})
*/
public void setSequence(List<UUID> sequence) {
this.sequence = sequence;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code writerUuid}。
* @return UUID
*/
public UUID getWriterUuid() {
return this.writerUuid;
}
/**
* 设置 {@code writerUuid}。
*
* @param writerUuid 参数 {@code writerUuid}({@code UUID})
*/
public void setWriterUuid(UUID writerUuid) {
this.writerUuid = writerUuid;
}
/**
* 获取 {@code status}。
* @return MongoDB 文档扩展对象
*/
public DbObject getStatus() {
return this.status;
}
/**
* 设置 {@code status}。
*
* @param status 状态({@code DbObject})
*/
public void setStatus(DbObject status) {
this.status = status;
}
/**
* 获取 {@code scope}。
* @return 字段/派生属性 {@code scope} 的值
*/
public ProfileScope getScope() {
return this.scope;
}
/**
* 判断 {@code scope}。
* @return 字段/派生属性 {@code scope} 的值
*/
public boolean hasScope() {
return this.scope != null && this.scope.hasScoped();
}
/**
* 判断 {@code scopeDeviceGroups}。
* @return 字段/派生属性 {@code scopeDeviceGroups} 的值
*/
public boolean hasScopeDeviceGroups() {
return this.scope != null && this.scope.getGroup() != null && !this.scope.getGroup().isEmpty();
}
public Set getScopedDeviceGroups() {
/**
* 获取 {@code scopedDeviceGroups}。
* @return UUID列表,可能为空
*/
public Set<UUID> getScopedDeviceGroups() {
return this.scope == null ? null : this.scope.getGroup();
}
public Set getScopedDevice() {
/**
* 获取 {@code scopedDevice}。
* @return String列表,可能为空
*/
public Set<String> getScopedDevice() {
return this.scope == null ? null : this.scope.getDevice();
}
/**
* 设置 {@code scope}。
*
* @param scope 参数 {@code scope}({@code ProfileScope})
*/
public void setScope(ProfileScope scope) {
this.scope = scope;
}
/**
* 获取 {@code writer}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getWriter() {
return this.writer;
}
/**
* 设置 {@code writer}。
*
* @param writer 参数 {@code writer}({@code User})
*/
public void setWriter(User writer) {
this.writer = writer;
}
/**
* 初始化应用列表。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*/
public void initApps() {
if (this.apps != null) {
this.apps.initInstallApp();
@@ -175,11 +377,21 @@ public class DeviceProfile extends GeneralProfile {
}
/**
* 获取 {@code apps}。
* @return 字段/派生属性 {@code apps} 的值
*/
public ProfileApps getApps() {
return this.apps;
}
public List getInstallApps() {
/**
* 获取 {@code installApps}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 配置档案Apps.Install应用列表,可能为空
*/
public List<ProfileApps.InstallApp> getInstallApps() {
if (this.apps == null) {
this.initApps();
}
@@ -187,7 +399,13 @@ public class DeviceProfile extends GeneralProfile {
return this.apps == null ? null : this.apps.getInstallApp();
}
public List getInstallUuids() {
/**
* 获取 {@code installUuids}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return UUID列表,可能为空
*/
public List<UUID> getInstallUuids() {
if (this.apps == null) {
this.initApps();
}
@@ -195,6 +413,14 @@ public class DeviceProfile extends GeneralProfile {
return this.apps != null ? this.apps.getInstallUuids() : null;
}
/**
* 获取Install应用。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param packageName 参数 {@code packageName}({@code String})
* @return 字段/派生属性 {@code installApp} 的值
*/
public ProfileApps.InstallApp getInstallApp(String packageName) {
if (this.apps == null) {
this.initApps();
@@ -203,18 +429,37 @@ public class DeviceProfile extends GeneralProfile {
return this.apps != null ? this.apps.getInstallApp(packageName) : null;
}
/**
* 设置 {@code apps}。
*
* @param apps 参数 {@code apps}({@code ProfileApps})
*/
public void setApps(ProfileApps apps) {
this.apps = apps;
}
/**
* 处理need旧格式化。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean needOldFormat() {
return this.needOldFormat;
}
/**
* 设置 {@code needOldFormat}。
*
* @param need 参数 {@code need}({@code boolean})
*/
public void setNeedOldFormat(boolean need) {
this.needOldFormat = need;
}
/**
* 设置转换为旧格式化。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*/
public void setToOldFormat() {
if (this.apps != null) {
this.apps.setToOldFormat();
@@ -222,50 +467,106 @@ public class DeviceProfile extends GeneralProfile {
}
public List getWhiteListPackages() {
/**
* 获取 {@code whiteListPackages}。
* @return String列表,可能为空
*/
public List<String> getWhiteListPackages() {
return this.apps != null ? this.apps.getPackageList(this.apps.getWhiteList()) : null;
}
public List getBlackListPackages() {
/**
* 获取 {@code blackListPackages}。
* @return String列表,可能为空
*/
public List<String> getBlackListPackages() {
return this.apps != null ? this.apps.getPackageList(this.apps.getWhiteList()) : null;
}
public List getOtas() {
/**
* 获取 {@code otas}。
* @return UUID列表,可能为空
*/
public List<UUID> getOtas() {
return this.otas;
}
public void setOtas(List otas) {
/**
* 设置 {@code otas}。
*
* @param otas 参数 {@code otas}({@code List<UUID>})
*/
public void setOtas(List<UUID> otas) {
this.otas = otas;
}
/**
* 检查构建日期。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean checkBuildDate() {
return this.getSettingAsBoolean("otas", "checkBuildDate", false);
}
/**
* 获取 {@code files}。
* @return MongoDB 文档扩展对象
*/
public DbObject getFiles() {
return this.files;
}
/**
* 设置 {@code files}。
*
* @param files 参数 {@code files}({@code DbObject})
*/
public void setFiles(DbObject files) {
this.files = files;
}
/**
* 获取 {@code progress}。
* @return MongoDB 文档扩展对象
*/
public DbObject getProgress() {
return this.progress;
}
/**
* 设置 {@code progress}。
*
* @param progress 参数 {@code progress}({@code DbObject})
*/
public void setProgress(DbObject progress) {
this.progress = progress;
}
/**
* 获取 {@code reference}。
* @return MongoDB 文档扩展对象
*/
public DbObject getReference() {
return this.reference;
}
/**
* 设置 {@code reference}。
*
* @param reference 参数 {@code reference}({@code DbObject})
*/
public void setReference(DbObject reference) {
this.reference = reference;
}
/**
* 设置Reference。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:remove、new DbObject。
*
* @param key 键/配置项({@code String})
* @param data 参数 {@code data}({@code Object})
*/
public void setReference(String key, Object data) {
if (data == null) {
if (this.reference != null) {
@@ -279,6 +580,11 @@ public class DeviceProfile extends GeneralProfile {
}
/**
* 处理unset日期时间设置列表。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:remove。
*/
public void unsetDateTimeSettings() {
DbObject settings = this.getSettingsCategory(new String[]{"system", "dateTime"});
if (settings != null) {
@@ -295,6 +601,11 @@ public class DeviceProfile extends GeneralProfile {
}
/**
* 转换Custom设置列表用于设备。
*
* 实现要点:包含 6 个条件分支、1 个循环;主要调用:new DbObject、remove。
*/
public void convertCustomSettingsForDevice() {
String[] categories = new String[]{"systemProperties", "globalSettings", "systemSettings", "secureSettings"};
@@ -327,14 +638,25 @@ public class DeviceProfile extends GeneralProfile {
}
/**
* 移除If号范围。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean removeIfNoScope() {
return this.getProfile().getBoolean("removeIfNoScope", false);
}
/**
* 处理unscopeIfApplied。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean unscopeIfApplied() {
return this.getProfile().getBoolean("unscopeIfApplied", false);
}
/**
* 处理minify。
*/
public void minify() {
super.minify();
this.deviceProfileGroup = null;
@@ -343,6 +665,10 @@ public class DeviceProfile extends GeneralProfile {
this.writer = null;
}
/**
* 处理clone。
* @return 设备配置档案;未找到时返回 {@code null}
*/
public DeviceProfile clone() {
return (DeviceProfile)McJsonUtils.clone(this);
}
@@ -6,52 +6,136 @@ import java.util.UUID;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceProfileGroup}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code parentUuid}(UUID):父级UUID</li>
* <li>{@code order}(Integer):字段 order</li>
* <li>{@code deviceProfileNumbers}(Long):设备配置档案Numbers</li>
* <li>{@code children}(List<DeviceProfileGroup>):子级</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class DeviceProfileGroup extends GeneralProfile {
/**
* 用户所属站点 UUID。
*/
private UUID siteUuid;
/**
* 父级UUID。
*/
private UUID parentUuid;
/**
* 字段 order。
*/
private Integer order;
/**
* 设备配置档案Numbers;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Long deviceProfileNumbers;
private List children;
/**
* 子级。
*/
private List<DeviceProfileGroup> children;
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code parentUuid}。
* @return UUID
*/
public UUID getParentUuid() {
return this.parentUuid;
}
/**
* 设置 {@code parentUuid}。
*
* @param parentUuid 参数 {@code parentUuid}({@code UUID})
*/
public void setParentUuid(UUID parentUuid) {
this.parentUuid = parentUuid;
}
/**
* 获取 {@code order}。
* @return 数量/长度
*/
public Integer getOrder() {
return this.order;
}
/**
* 设置 {@code order}。
*
* @param order 参数 {@code order}({@code Integer})
*/
public void setOrder(Integer order) {
this.order = order;
}
/**
* 获取 {@code deviceProfileNumbers}。
* @return 数量/长度
*/
public Long getDeviceProfileNumbers() {
return this.deviceProfileNumbers;
}
/**
* 设置 {@code deviceProfileNumbers}。
*
* @param numbers 参数 {@code numbers}({@code Long})
*/
public void setDeviceProfileNumbers(Long numbers) {
this.deviceProfileNumbers = numbers;
}
public List getChildren() {
/**
* 获取 {@code children}。
* @return 设备配置档案分组列表,可能为空
*/
public List<DeviceProfileGroup> getChildren() {
return this.children;
}
public void setChildren(List children) {
/**
* 设置 {@code children}。
*
* @param children 参数 {@code children}({@code List<DeviceProfileGroup>})
*/
public void setChildren(List<DeviceProfileGroup> children) {
this.children = children;
}
}
@@ -11,6 +11,31 @@ import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DeviceProfileState}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code STATE_IN_PROGRESS}(String):字段 STATE_IN_PROGRESS</li>
* <li>{@code STATE_DONE}(String):字段 STATE_DONE</li>
* <li>{@code STATE_UNKNWON}(String):字段 STATE_UNKNWON</li>
* <li>{@code scoped}(Scoped):字段 scoped</li>
* <li>{@code updated}(long):最后更新时间</li>
* <li>{@code state}(String):状态</li>
* </ul>
*
* 协作对象:{@code Scoped、DeviceReport}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndexes({@CompoundIndex(
def = "{'_id.deviceUuid': 1}"
@@ -18,103 +43,238 @@ import org.springframework.data.mongodb.core.mapping.Document;
def = "{'_id.profileUuid': 1}"
)})
public class DeviceProfileState {
/**
* 字段 STATE_IN_PROGRESS。
*/
public static final String STATE_IN_PROGRESS = "in_progress";
/**
* 字段 STATE_DONE。
*/
public static final String STATE_DONE = "done";
/**
* 字段 STATE_UNKNWON。
*/
public static final String STATE_UNKNWON = "unknown";
/**
* 字段 scoped;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private Scoped scoped;
/**
* 最后更新时间。
*/
private long updated = -1L;
/**
* 状态;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private String state = "unknown";
/**
* 应用第一状态。
*/
private String applyFirstState = "unknown";
/**
* 字段 applied;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private long applied;
/**
* 报表;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private DeviceReport report;
/**
* 构造 {@code DeviceProfileState} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public DeviceProfileState() {
}
/**
* 构造 {@code DeviceProfileState} 实例。
*
* 实现要点:主要调用:new Scoped、new Date。
*
* @param device 设备({@code Device})
* @param profile 设备配置档案({@code DeviceProfile})
*/
public DeviceProfileState(Device device, DeviceProfile profile) {
this.scoped = new Scoped(profile.getUuid(), device.getUuid());
this.updated = profile.getUpdated().getTime();
this.applied = (new Date()).getTime();
}
/**
* 构造 {@code DeviceProfileState} 实例。
*
* @param report 参数 {@code report}({@code DeviceReport})
*/
public DeviceProfileState(DeviceReport report) {
this.setReport(report);
}
/**
* 获取 {@code scoped}。
* @return 字段/派生属性 {@code scoped} 的值
*/
public Scoped getScoped() {
return this.scoped;
}
/**
* 设置 {@code scoped}。
*
* @param scoped 参数 {@code scoped}({@code Scoped})
*/
public void setScoped(Scoped scoped) {
this.scoped = scoped;
}
/**
* 获取 {@code profileUuid}。
* @return UUID
*/
public UUID getProfileUuid() {
return this.getScoped().getProfileUuid();
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.getScoped().getDeviceUuid();
}
/**
* 获取 {@code updated}。
* @return 数量/长度
*/
public long getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code long})
*/
public void setUpdated(long updated) {
this.updated = updated;
}
/**
* 获取 {@code state}。
* @return 字符串结果
*/
public String getState() {
return this.state;
}
/**
* 判断 {@code done}。
* @return 字段/派生属性 {@code done} 的值
*/
public boolean isDone() {
return this.state == null || this.state.equals("done");
}
/**
* 设置 {@code state}。
*
* @param state 参数 {@code state}({@code String})
*/
public void setState(String state) {
this.state = state;
}
/**
* 获取 {@code applyFirstState}。
* @return 字符串结果
*/
public String getApplyFirstState() {
return this.applyFirstState;
}
/**
* 判断 {@code applyFirstDone}。
* @return 字段/派生属性 {@code applyFirstDone} 的值
*/
public boolean isApplyFirstDone() {
return this.applyFirstState != null && this.applyFirstState.equals("done");
}
/**
* 设置 {@code applyFirstState}。
*
* @param applyFirstState 参数 {@code applyFirstState}({@code String})
*/
public void setApplyFirstState(String applyFirstState) {
this.applyFirstState = applyFirstState;
}
/**
* 获取 {@code applied}。
* @return 数量/长度
*/
public long getApplied() {
return this.applied;
}
/**
* 设置 {@code applied}。
*
* @param applied 参数 {@code applied}({@code long})
*/
public void setApplied(long applied) {
this.applied = applied;
this.setState("done");
}
/**
* 设置Applied。
*
* @param applied 参数 {@code applied}({@code long})
* @param state 参数 {@code state}({@code String})
*/
public void setApplied(long applied, String state) {
this.state = state;
this.applied = applied;
}
/**
* 设置Applied。
*
* 实现要点:主要调用:new Date。
*/
public void setApplied() {
this.applied = (new Date()).getTime();
}
/**
* 获取 {@code report}。
* @return 字段/派生属性 {@code report} 的值
*/
public DeviceReport getReport() {
return this.report;
}
/**
* 设置 {@code report}。
*
* 实现要点:主要调用:new Scoped。
*
* @param report 参数 {@code report}({@code DeviceReport})
*/
public void setReport(DeviceReport report) {
this.report = report;
DbObject profile = report.getProperties().getDbObject(new String[]{"deviceProfile"});
@@ -124,30 +284,81 @@ public class DeviceProfileState {
this.setState("done");
}
/**
* 【领域模型】{@code Scoped}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code profileUuid}(UUID):配置档案UUID</li>
* <li>{@code deviceUuid}(UUID):设备UUID</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public static class Scoped implements Serializable {
/**
* 配置档案UUID。
*/
private UUID profileUuid;
/**
* 设备UUID。
*/
private UUID deviceUuid;
/**
* 构造 {@code Scoped} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public Scoped() {
}
/**
* 构造 {@code Scoped} 实例。
*
* @param profileUuid 配置档案 UUID({@code UUID})
* @param deviceUuid 设备 UUID({@code UUID})
*/
public Scoped(UUID profileUuid, UUID deviceUuid) {
this.profileUuid = profileUuid;
this.deviceUuid = deviceUuid;
}
/**
* 获取 {@code profileUuid}。
* @return UUID
*/
public UUID getProfileUuid() {
return this.profileUuid;
}
/**
* 设置 {@code profileUuid}。
*
* @param profileUuid 配置档案 UUID({@code UUID})
*/
public void setProfileUuid(UUID profileUuid) {
this.profileUuid = profileUuid;
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.deviceUuid;
}
/**
* 设置 {@code deviceUuid}。
*
* @param deviceUuid 设备 UUID({@code UUID})
*/
public void setDeviceUuid(UUID deviceUuid) {
this.deviceUuid = deviceUuid;
}
@@ -53,43 +53,89 @@ public class DeviceReport {
/** 云端服务端持久化写入数据库的系统时间戳 */
private Date recordedAt;
/**
* 构造 {@code DeviceReport} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public DeviceReport() {
this.setRecordedAt();
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.setUuid(UUID.randomUUID());
this.setReportedAt(new Date());
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.deviceUuid;
}
/**
* 设置 {@code deviceUuid}。
*
* @param deviceUuid 设备 UUID({@code UUID})
*/
public void setDeviceUuid(UUID deviceUuid) {
this.deviceUuid = deviceUuid;
}
/**
* 获取 {@code serialNo}。
* @return 字符串结果
*/
public String getSerialNo() {
return this.serialNo;
}
/**
* 设置 {@code serialNo}。
*
* @param serialNo 设备序列号({@code String})
*/
public void setSerialNo(String serialNo) {
this.serialNo = serialNo;
}
/**
* 判断 {@code properties}。
* @return 字段/派生属性 {@code properties} 的值
*/
public boolean hasProperties() {
return this.properties != null && !this.properties.isEmpty();
}
/**
* 获取 {@code properties}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getProperties() {
if (this.properties == null) {
this.properties = new DbObject();
@@ -98,38 +144,82 @@ public class DeviceReport {
return this.properties;
}
/**
* 设置 {@code properties}。
*
* @param properties 参数 {@code properties}({@code DbObject})
*/
public void setProperties(DbObject properties) {
this.properties = properties;
}
/**
* 获取 {@code reportedAt}。
* @return 字段/派生属性 {@code reportedAt} 的值
*/
public Date getReportedAt() {
return this.reportedAt;
}
/**
* 设置 {@code reportedAt}。
*
* @param reportedAt 参数 {@code reportedAt}({@code Date})
*/
public void setReportedAt(Date reportedAt) {
this.reportedAt = reportedAt;
}
/**
* 获取 {@code recordedAt}。
* @return 字段/派生属性 {@code recordedAt} 的值
*/
public Date getRecordedAt() {
return this.recordedAt;
}
/**
* 设置 {@code recordedAt}。
*
* @param recordedAt 参数 {@code recordedAt}({@code Date})
*/
public void setRecordedAt(Date recordedAt) {
this.recordedAt = recordedAt;
}
/**
* 设置RecordedAt。
*
* 实现要点:主要调用:new Date。
*/
public void setRecordedAt() {
this.recordedAt = new Date();
}
/**
* 设置Property。
*
* @param key 键/配置项({@code String})
* @param val 参数 {@code val}({@code Object})
*/
public void setProperty(String key, Object val) {
this.getProperties().append(key, val);
}
/**
* 获取Property。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code property} 的值
*/
public Object getProperty(String key) {
return this.getProperties().get(key);
}
/**
* 返回对象的可读字符串表示。
* @return 字符串结果
*/
public String toString() {
return McJsonUtils.toJson(this);
}
@@ -15,45 +15,126 @@ import java.util.stream.Collectors;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Field;
/**
* 【领域模型】{@code ProfileApps}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code install}(List<?>):?集合</li>
* <li>{@code installApp}(List<InstallApp>):install应用</li>
* <li>{@code uninstall}(List<DbObject>):数据库Object集合</li>
* <li>{@code appWidget}(List<DbObject>):应用Widget</li>
* <li>{@code widget}(List<DbObject>):数据库Object集合</li>
* <li>{@code grantAll}(List<DbObject>):grant全部</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class ProfileApps {
private List install;
/**
* ?集合。
*/
private List<?> install;
/**
* install应用;不持久化到 MongoDB,仅运行时使用;Gson 序列化控制。
*
* 注解:{@code @Transient @Expose(serialize = false)}。
*/
@Transient
@Expose(
serialize = false
)
private List installApp;
private List uninstall;
private List<InstallApp> installApp;
/**
* 数据库Object集合。
*/
private List<DbObject> uninstall;
/**
* 应用Widget;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("add_appwidget") @Field("add_appwidget")}。
*/
@SerializedName("add_appwidget")
@Field("add_appwidget")
private List appWidget;
private List widget;
private List<DbObject> appWidget;
/**
* 数据库Object集合。
*/
private List<DbObject> widget;
/**
* grant全部;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("grant_all") @Field("grant_all")}。
*/
@SerializedName("grant_all")
@Field("grant_all")
private List grantAll;
private List disabled;
private List<DbObject> grantAll;
/**
* 数据库Object集合。
*/
private List<DbObject> disabled;
/**
* Wi-FiOnly;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("wifi_only") @Field("wifi_only")}。
*/
@SerializedName("wifi_only")
@Field("wifi_only")
private List wifiOnly;
private List<DbObject> wifiOnly;
/**
* white列出;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("white_list") @Field("white_list")}。
*/
@SerializedName("white_list")
@Field("white_list")
private List whiteList;
private List<DbObject> whiteList;
/**
* black列出;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("black_list") @Field("black_list")}。
*/
@SerializedName("black_list")
@Field("black_list")
private List blackList;
private List<DbObject> blackList;
public List getInstall() {
/**
* 获取 {@code install}。
* @return ?列表,可能为空
*/
public List<?> getInstall() {
return this.install;
}
public void setInstall(List install) {
/**
* 设置 {@code install}。
*
* @param install 参数 {@code install}({@code List<?>})
*/
public void setInstall(List<?> install) {
this.install = install;
}
/**
* 设置转换为旧格式化。
*/
public void setToOldFormat() {
this.install = this.getInstallUuids();
}
public List getInstallApp() {
/**
* 获取 {@code installApp}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return Install应用列表,可能为空
*/
public List<InstallApp> getInstallApp() {
if (this.installApp == null && this.install != null) {
this.initInstallApp();
}
@@ -61,10 +142,15 @@ public class ProfileApps {
return this.installApp;
}
/**
* 初始化Install应用。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new TypeToken。
*/
public void initInstallApp() {
if (this.install != null && !this.install.isEmpty()) {
if (this.install.get(0) instanceof InstallApp) {
this.installApp = this.install;
this.installApp = (List<InstallApp>)this.install;
} else {
this.installApp = (List)McJsonUtils.toObject(McJsonUtils.toJsonElement(this.install), (new TypeToken() {
}).getType());
@@ -74,15 +160,32 @@ public class ProfileApps {
}
public void setInstallApp(List installApp) {
/**
* 设置 {@code installApp}。
*
* @param installApp 参数 {@code installApp}({@code List<InstallApp>})
*/
public void setInstallApp(List<InstallApp> installApp) {
this.installApp = installApp;
}
/**
* 判断 {@code installApps}。
* @return 字段/派生属性 {@code installApps} 的值
*/
public boolean hasInstallApps() {
this.getInstallApp();
return this.installApp != null && !this.installApp.isEmpty();
}
/**
* 获取Install应用。
*
* 实现要点:包含 2 个条件分支、1 个循环。
*
* @param packageName 参数 {@code packageName}({@code String})
* @return 字段/派生属性 {@code installApp} 的值
*/
public InstallApp getInstallApp(String packageName) {
if (!this.hasInstallApps()) {
return null;
@@ -97,6 +200,14 @@ public class ProfileApps {
}
}
/**
* 移除Install应用。
*
* 实现要点:包含 2 个条件分支、1 个循环;主要调用:remove。
*
* @param appUuid 参数 {@code appUuid}({@code UUID})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean removeInstallApp(UUID appUuid) {
if (this.hasInstallApps()) {
Iterator<InstallApp> it = this.installApp.iterator();
@@ -112,83 +223,177 @@ public class ProfileApps {
return false;
}
public List getInstallUuids() {
/**
* 获取 {@code installUuids}。
* @return UUID列表,可能为空
*/
public List<UUID> getInstallUuids() {
return this.installApp != null ? (List)this.installApp.stream().map((app) -> app.getUuid()).collect(Collectors.toList()) : null;
}
public List getUninstall() {
/**
* 获取 {@code uninstall}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getUninstall() {
return this.toDbList(this.uninstall);
}
public void setUninstall(List uninstall) {
/**
* 设置 {@code uninstall}。
*
* @param uninstall 参数 {@code uninstall}({@code List<DbObject>})
*/
public void setUninstall(List<DbObject> uninstall) {
this.uninstall = uninstall;
}
public List getAppWidget() {
/**
* 获取 {@code appWidget}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getAppWidget() {
return this.appWidget;
}
public void setAppWidget(List addAppWidget) {
/**
* 设置 {@code appWidget}。
*
* @param addAppWidget 参数 {@code addAppWidget}({@code List<DbObject>})
*/
public void setAppWidget(List<DbObject> addAppWidget) {
this.appWidget = addAppWidget;
}
public List getWidget() {
/**
* 获取 {@code widget}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getWidget() {
return this.widget;
}
public void setWidget(List widget) {
/**
* 设置 {@code widget}。
*
* @param widget 参数 {@code widget}({@code List<DbObject>})
*/
public void setWidget(List<DbObject> widget) {
this.widget = widget;
}
public List getGrantAll() {
/**
* 获取 {@code grantAll}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getGrantAll() {
return this.toDbList(this.grantAll);
}
public void setGrantAll(List grantAll) {
/**
* 设置 {@code grantAll}。
*
* @param grantAll 参数 {@code grantAll}({@code List<DbObject>})
*/
public void setGrantAll(List<DbObject> grantAll) {
this.grantAll = grantAll;
}
public List getDisabled() {
/**
* 获取 {@code disabled}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getDisabled() {
return this.toDbList(this.disabled);
}
public void setDisabled(List disabled) {
/**
* 设置 {@code disabled}。
*
* @param disabled 参数 {@code disabled}({@code List<DbObject>})
*/
public void setDisabled(List<DbObject> disabled) {
this.disabled = disabled;
}
public List getWifiOnly() {
/**
* 获取 {@code wifiOnly}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getWifiOnly() {
return this.toDbList(this.wifiOnly);
}
public void setWifiOnly(List wifiOnly) {
/**
* 设置 {@code wifiOnly}。
*
* @param wifiOnly 参数 {@code wifiOnly}({@code List<DbObject>})
*/
public void setWifiOnly(List<DbObject> wifiOnly) {
this.wifiOnly = wifiOnly;
}
public List getWhiteList() {
/**
* 获取 {@code whiteList}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getWhiteList() {
return this.toDbList(this.whiteList);
}
public void setWhiteList(List whiteList) {
/**
* 设置 {@code whiteList}。
*
* @param whiteList 参数 {@code whiteList}({@code List<DbObject>})
*/
public void setWhiteList(List<DbObject> whiteList) {
this.whiteList = whiteList;
}
public List getBlackList() {
/**
* 获取 {@code blackList}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getBlackList() {
return this.toDbList(this.blackList);
}
public void setBlackList(List blackList) {
/**
* 设置 {@code blackList}。
*
* @param blackList 参数 {@code blackList}({@code List<DbObject>})
*/
public void setBlackList(List<DbObject> blackList) {
this.blackList = blackList;
}
public List getPackageList(List apps) {
/**
* 获取Package列出。
*
* @param apps 参数 {@code apps}({@code List<DbObject>})
* @return String列表,可能为空
*/
public List<String> getPackageList(List<DbObject> apps) {
return apps != null ? (List)apps.stream().map((app) -> app.getString("package")).collect(Collectors.toList()) : null;
}
/**
* 判断 {@code empty}。
* @return 字段/派生属性 {@code empty} 的值
*/
public boolean isEmpty() {
return (this.install == null || this.install.isEmpty()) && (this.uninstall == null || this.uninstall.isEmpty()) && (this.appWidget == null || this.appWidget.isEmpty()) && (this.widget == null || this.widget.isEmpty()) && (this.grantAll == null || this.grantAll.isEmpty()) && (this.disabled == null || this.disabled.isEmpty()) && (this.wifiOnly == null || this.wifiOnly.isEmpty()) && (this.whiteList == null || this.whiteList.isEmpty()) && (this.blackList == null || this.blackList.isEmpty());
}
private List toDbList(List list) {
/**
* 处理转换为数据库列出。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:new ArrayList、new DbObject。
*
* @param list 参数 {@code list}({@code List<?>})
* @return 数据库Object列表,可能为空
*/
private List<DbObject> toDbList(List<?> list) {
if (list != null && !list.isEmpty()) {
List<DbObject> dbList = new ArrayList();
list.forEach((item) -> {
@@ -205,78 +410,196 @@ public class ProfileApps {
}
}
/**
* 【领域模型】{@code InstallApp}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code packageName}(String):package名称</li>
* <li>{@code silentInstall}(Boolean):是否silentInstall</li>
* <li>{@code grantAll}(Boolean):grant全部</li>
* <li>{@code startsOnUpdate}(Boolean):starts处理更新</li>
* <li>{@code rebootsOnUpdate}(Boolean):reboots处理更新</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public static class InstallApp {
/**
* 对象唯一标识(MongoDB 主键)。
*/
private UUID uuid;
/**
* package名称。
*/
private String packageName;
/**
* 是否silentInstall;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("silent_install") @Field("silent_install")}。
*/
@SerializedName("silent_install")
@Field("silent_install")
private Boolean silentInstall = true;
/**
* grant全部;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("grant_all") @Field("grant_all")}。
*/
@SerializedName("grant_all")
@Field("grant_all")
private Boolean grantAll = false;
/**
* starts处理更新;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("starts_on_update") @Field("starts_on_update")}。
*/
@SerializedName("starts_on_update")
@Field("starts_on_update")
private Boolean startsOnUpdate = false;
/**
* reboots处理更新;通过 @Field 映射到 MongoDB 字段。
*
* 注解:{@code @SerializedName("reboots_on_update") @Field("reboots_on_update")}。
*/
@SerializedName("reboots_on_update")
@Field("reboots_on_update")
private Boolean rebootsOnUpdate = false;
/**
* 构造 {@code InstallApp} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public InstallApp() {
}
/**
* 构造 {@code InstallApp} 实例。
*
* @param appFile 参数 {@code appFile}({@code AppFile})
*/
public InstallApp(AppFile appFile) {
this.uuid = appFile.getFileUuid();
this.packageName = appFile.getPackageName();
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code packageName}。
* @return 字符串结果
*/
public String getPackageName() {
return this.packageName;
}
/**
* 设置 {@code packageName}。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public void setPackageName(String packageName) {
this.packageName = packageName;
}
/**
* 获取 {@code silentInstall}。
* @return 字段/派生属性 {@code silentInstall} 的值
*/
public Boolean getSilentInstall() {
return this.silentInstall;
}
/**
* 设置 {@code silentInstall}。
*
* @param silentInstall 参数 {@code silentInstall}({@code Boolean})
*/
public void setSilentInstall(Boolean silentInstall) {
this.silentInstall = silentInstall;
}
/**
* 获取 {@code grantAll}。
* @return 字段/派生属性 {@code grantAll} 的值
*/
public Boolean getGrantAll() {
return this.grantAll;
}
/**
* 设置 {@code grantAll}。
*
* @param grantAll 参数 {@code grantAll}({@code Boolean})
*/
public void setGrantAll(Boolean grantAll) {
this.grantAll = grantAll;
}
/**
* 获取 {@code startsOnUpdate}。
* @return 字段/派生属性 {@code startsOnUpdate} 的值
*/
public Boolean getStartsOnUpdate() {
return this.startsOnUpdate;
}
/**
* 设置 {@code startsOnUpdate}。
*
* @param startsOnUpdate 参数 {@code startsOnUpdate}({@code Boolean})
*/
public void setStartsOnUpdate(Boolean startsOnUpdate) {
this.startsOnUpdate = startsOnUpdate;
}
/**
* 获取 {@code rebootsOnUpdate}。
* @return 字段/派生属性 {@code rebootsOnUpdate} 的值
*/
public Boolean getRebootsOnUpdate() {
return this.rebootsOnUpdate;
}
/**
* 设置 {@code rebootsOnUpdate}。
*
* @param rebootsOnUpdate 参数 {@code rebootsOnUpdate}({@code Boolean})
*/
public void setRebootsOnUpdate(Boolean rebootsOnUpdate) {
this.rebootsOnUpdate = rebootsOnUpdate;
}
/**
* 比较当前对象与另一个对象是否相等。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param obj 参数 {@code obj}({@code Object})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean equals(Object obj) {
if (!(obj instanceof InstallApp)) {
return false;
@@ -4,19 +4,62 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
* 【领域模型】{@code ProfileScope}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code group}(Set<UUID>):分组</li>
* <li>{@code device}(Set<String>):设备</li>
* <li>{@code userGroup}(Set<String>):用户分组</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class ProfileScope {
Set group;
Set device;
Set userGroup;
/**
* 分组。
*/
Set<UUID> group;
/**
* 设备。
*/
Set<String> device;
/**
* 用户分组。
*/
Set<String> userGroup;
public Set getGroup() {
/**
* 获取 {@code group}。
* @return UUID列表,可能为空
*/
public Set<UUID> getGroup() {
return this.group;
}
public void setGroup(Set group) {
/**
* 设置 {@code group}。
*
* @param group 分组对象({@code Set<UUID>})
*/
public void setGroup(Set<UUID> group) {
this.group = group;
}
/**
* 添加分组。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new HashSet。
*
* @param groupUuid 分组 UUID({@code UUID})
*/
public void addGroup(UUID groupUuid) {
if (this.group == null) {
this.group = new HashSet();
@@ -25,6 +68,13 @@ public class ProfileScope {
}
/**
* 移除分组。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:remove。
*
* @param groupUuid 分组 UUID({@code UUID})
*/
public void removeGroup(UUID groupUuid) {
if (this.group != null) {
this.group.remove(groupUuid);
@@ -32,14 +82,30 @@ public class ProfileScope {
}
public Set getDevice() {
/**
* 获取 {@code device}。
* @return String列表,可能为空
*/
public Set<String> getDevice() {
return this.device;
}
public void setDevice(Set device) {
/**
* 设置 {@code device}。
*
* @param device 设备({@code Set<String>})
*/
public void setDevice(Set<String> device) {
this.device = device;
}
/**
* 添加设备。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new HashSet。
*
* @param serialNo 设备序列号({@code String})
*/
public void addDevice(String serialNo) {
if (this.device == null) {
this.device = new HashSet();
@@ -48,6 +114,13 @@ public class ProfileScope {
}
/**
* 移除设备。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:remove。
*
* @param serialNo 设备序列号({@code String})
*/
public void removeDevice(String serialNo) {
if (this.device != null) {
this.device.remove(serialNo);
@@ -55,14 +128,27 @@ public class ProfileScope {
}
public Set getUserGroup() {
/**
* 获取 {@code userGroup}。
* @return String列表,可能为空
*/
public Set<String> getUserGroup() {
return this.userGroup;
}
public void setUserGroup(Set userGroup) {
/**
* 设置 {@code userGroup}。
*
* @param userGroup 参数 {@code userGroup}({@code Set<String>})
*/
public void setUserGroup(Set<String> userGroup) {
this.userGroup = userGroup;
}
/**
* 判断 {@code scoped}。
* @return 字段/派生属性 {@code scoped} 的值
*/
public boolean hasScoped() {
return this.group != null && !this.group.isEmpty() || this.device != null && !this.device.isEmpty() || this.userGroup != null && !this.userGroup.isEmpty();
}
@@ -8,25 +8,92 @@ import java.util.TimerTask;
import java.util.UUID;
import org.joda.time.LocalDateTime;
/**
* 【领域模型】{@code ReconnectMonitor}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code BLOCKING_HOURS}(int):字段 BLOCKING_HOURS</li>
* <li>{@code RECONNECT_FOR}(int):字段 RECONNECT_FOR</li>
* <li>{@code device}(Device):设备</li>
* <li>{@code startedAt}(Date):时间字段</li>
* <li>{@code prevMins}(long):字段 prevMins</li>
* <li>{@code count}(int):统计</li>
* </ul>
*
* 协作对象:{@code Device、Timer、OnAbusedListener}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class ReconnectMonitor {
/**
* 字段 BLOCKING_HOURS。
*/
private static final int BLOCKING_HOURS = 12;
/**
* 字段 RECONNECT_FOR。
*/
private static final int RECONNECT_FOR = 10;
/**
* 设备。
*/
private Device device;
/**
* 时间字段。
*/
private Date startedAt;
/**
* 字段 prevMins。
*/
private long prevMins;
/**
* 统计。
*/
private int count;
/**
* 总数。
*/
private int total;
/**
* 时间字段。
*/
private Date blockedAt;
/**
* 时间字段。
*/
private Date unblockAt;
/**
* unblock定时器。
*/
private Timer unblockTimer;
/**
* 监听器。
*/
private OnAbusedListener listener;
/**
* 构造 {@code ReconnectMonitor} 实例。
*
* @param device 设备({@code Device})
* @param listener 参数 {@code listener}({@code OnAbusedListener})
*/
public ReconnectMonitor(Device device, OnAbusedListener listener) {
this.device = device;
this.listener = listener;
this.init();
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
private void init() {
this.startedAt = new Date();
this.blockedAt = null;
@@ -35,34 +102,67 @@ public class ReconnectMonitor {
this.total = this.count = 1;
}
/**
* 获取 {@code device}。
* @return 匹配的设备对象;未找到时返回 {@code null}
*/
public Device getDevice() {
return this.device;
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.device.getUuid();
}
/**
* 获取 {@code startedAt}。
* @return 字段/派生属性 {@code startedAt} 的值
*/
public Date getStartedAt() {
return this.startedAt;
}
/**
* 获取 {@code blockedAt}。
* @return 字段/派生属性 {@code blockedAt} 的值
*/
public Date getBlockedAt() {
return this.blockedAt;
}
/**
* 获取 {@code unblockAt}。
* @return 字段/派生属性 {@code unblockAt} 的值
*/
public Date getUnblockAt() {
return this.unblockAt;
}
/**
* 获取 {@code count}。
* @return 数量/长度
*/
public int getCount() {
return this.count;
}
/**
* 获取 {@code total}。
* @return 数量/长度
*/
public int getTotal() {
return this.total;
}
/**
* 处理connected。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:new Date。
*/
public void connected() {
long curMins = this.getCurMins();
long gap = curMins - this.prevMins;
@@ -82,16 +182,32 @@ public class ReconnectMonitor {
}
/**
* 判断 {@code blocked}。
* @return 字段/派生属性 {@code blocked} 的值
*/
public boolean isBlocked() {
return this.blockedAt != null;
}
/**
* 处理block。
*
* 实现要点:主要调用:new Date、new LocalDateTime。
*/
public void block() {
this.blockedAt = new Date();
this.unblockAt = (new LocalDateTime(this.blockedAt)).plusHours(12).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0).toDate();
this.startUnblockTimer();
}
/**
* 处理block。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new Date。
*
* @param device 设备({@code Device})
*/
public void block(Device device) {
if (device.isBlocked()) {
DbObject blockedState = device.getStates().getDbObject(new String[]{"blocked"});
@@ -108,10 +224,14 @@ public class ReconnectMonitor {
}
/**
* 启动Unblock定时器。
*
* 实现要点:主要调用:new Timer、new Date、schedule、new TimerTask。
*/
private void startUnblockTimer() {
this.stopUnblockTimer();
String var10003 = this.device.getUuid().toString();
this.unblockTimer = new Timer(var10003 + (new Date()).getTime());
this.unblockTimer = new Timer(this.device.getUuid().toString() + (new Date()).getTime());
this.unblockTimer.schedule(new TimerTask() {
public void run() {
ReconnectMonitor.this.unblock((User)null);
@@ -119,6 +239,11 @@ public class ReconnectMonitor {
}, this.unblockAt);
}
/**
* 停止Unblock定时器。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 1 个条件分支、0 个循环;主要调用:cancel。
*/
private void stopUnblockTimer() {
if (this.unblockTimer != null) {
try {
@@ -131,6 +256,13 @@ public class ReconnectMonitor {
}
/**
* 处理unblock。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param user 当前用户({@code User})
*/
public void unblock(User user) {
this.stopUnblockTimer();
this.startedAt = null;
@@ -144,6 +276,11 @@ public class ReconnectMonitor {
}
/**
* 处理处理Abused。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*/
private void onAbused() {
this.block();
if (this.listener != null) {
@@ -152,13 +289,40 @@ public class ReconnectMonitor {
}
/**
* 获取 {@code curMins}。
*
* 实现要点:主要调用:new Date。
* @return 数量/长度
*/
private long getCurMins() {
return (new Date()).getTime() / 60000L;
}
/**
* 【接口契约】{@code OnAbusedListener}
*
* 类职责:
* <ul>
* <li>定义调用方与实现方之间的契约,屏蔽具体实现。</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public interface OnAbusedListener {
/**
* 处理处理Abused。
*
* @param monitor 参数 {@code monitor}({@code ReconnectMonitor})
*/
void onAbused(ReconnectMonitor monitor);
/**
* 处理处理Unblocked。
*
* @param monitor 参数 {@code monitor}({@code ReconnectMonitor})
* @param user 当前用户({@code User})
*/
void onUnblocked(ReconnectMonitor monitor, User user);
}
}
@@ -0,0 +1,27 @@
/**
* 设备领域模型:设备档案、分组、策略、应用、License、遥测状态。
*
* <p>本包主要类型:
* <ul>
* <li>{@link AppInfo}</li>
* <li>{@link DEVICE_PROPERTY}</li>
* <li>{@link DataUsage}</li>
* <li>{@link Device}</li>
* <li>{@link DeviceApps}</li>
* <li>{@link DeviceGroup}</li>
* <li>{@link DeviceKey}</li>
* <li>{@link DeviceLicense}</li>
* <li>{@link DeviceNote}</li>
* <li>{@link DeviceProfile}</li>
* <li>{@link DeviceProfileGroup}</li>
* <li>{@link DeviceProfileState}</li>
* <li>{@link DeviceReport}</li>
* <li>{@link ProfileApps}</li>
* <li>{@link ProfileScope}</li>
* <li>{@link ReconnectMonitor}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.device;
+224 -2
View File
@@ -12,24 +12,76 @@ import net.dongliu.apk.parser.bean.ApkMeta;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code AppFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code appInfo}(DbObject):应用信息</li>
* <li>{@code updateOptions}(DbObject):更新选项列表</li>
* <li>{@code generateIcon}(boolean):生成Icon</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class AppFile extends BaseFile {
/**
* 应用信息。
*/
private DbObject appInfo;
/**
* 更新选项列表。
*/
private DbObject updateOptions;
/**
* 生成Icon;不持久化到 MongoDB,仅运行时使用;Gson 序列化控制。
*
* 注解:{@code @Transient @Expose(serialize = false)}。
*/
@Transient
@Expose(
serialize = false
)
private boolean generateIcon;
/**
* 构造 {@code AppFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public AppFile() {
this.generateIcon = true;
}
/**
* 构造 {@code AppFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public AppFile(User user, UUID fileUuid, McFile file) {
this(user, fileUuid, file, true);
}
/**
* 构造 {@code AppFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
* @param generateIcon 参数 {@code generateIcon}({@code boolean})
*/
public AppFile(User user, UUID fileUuid, McFile file, boolean generateIcon) {
super(user, fileUuid, file);
this.generateIcon = true;
@@ -37,14 +89,28 @@ public class AppFile extends BaseFile {
this.setAppInfo(file);
}
/**
* 判断 {@code apk}。
* @return 字段/派生属性 {@code apk} 的值
*/
public boolean isApk() {
return !Strings.isNullOrEmpty(this.getPackageName());
}
/**
* 判断 {@code systemPermission}。
* @return 字段/派生属性 {@code systemPermission} 的值
*/
public boolean hasSystemPermission() {
return "android.uid.system".equals(this.getSharedUserId());
}
/**
* 获取 {@code appInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getAppInfo() {
if (this.appInfo == null) {
this.appInfo = new DbObject();
@@ -53,14 +119,31 @@ public class AppFile extends BaseFile {
return this.appInfo;
}
/**
* 设置 {@code appInfo}。
*
* @param appInfo 参数 {@code appInfo}({@code DbObject})
*/
public void setAppInfo(DbObject appInfo) {
this.appInfo = appInfo;
}
/**
* 设置应用信息。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setAppInfo(String key, Object value) {
this.getAppInfo().append(key, value);
}
/**
* 获取 {@code updateOptions}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getUpdateOptions() {
if (this.updateOptions == null) {
this.updateOptions = new DbObject();
@@ -69,30 +152,65 @@ public class AppFile extends BaseFile {
return this.updateOptions;
}
/**
* 设置 {@code updateOptions}。
*
* @param updateOptions 参数 {@code updateOptions}({@code DbObject})
*/
public void setUpdateOptions(DbObject updateOptions) {
this.updateOptions = updateOptions;
}
/**
* 设置更新选项列表。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setUpdateOptions(String key, Object value) {
this.getUpdateOptions().append(key, value);
}
/**
* 判断 {@code mitacApp}。
* @return 字段/派生属性 {@code mitacApp} 的值
*/
public boolean isMitacApp() {
return this.getPackageName().toLowerCase().contains("mitac");
}
/**
* 获取 {@code packageName}。
* @return 字符串结果
*/
public String getPackageName() {
return this.getAppInfo().getString("packageName");
}
/**
* 设置 {@code packageName}。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public void setPackageName(String packageName) {
this.setAppInfo("packageName", packageName);
}
/**
* 获取 {@code sharedUserId}。
* @return 字符串结果
*/
public String getSharedUserId() {
return this.getAppInfo().getString("sharedUid");
}
/**
* 设置 {@code sharedUserId}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param sharedUid 参数 {@code sharedUid}({@code String})
*/
public void setSharedUserId(String sharedUid) {
if (!Strings.isNullOrEmpty(sharedUid)) {
this.setAppInfo("sharedUid", sharedUid);
@@ -100,42 +218,89 @@ public class AppFile extends BaseFile {
}
/**
* 获取 {@code label}。
* @return 字符串结果
*/
public String getLabel() {
return this.getAppInfo().getString("label");
}
/**
* 设置 {@code label}。
*
* @param label 参数 {@code label}({@code String})
*/
public void setLabel(String label) {
this.setAppInfo("label", label);
}
/**
* 获取 {@code iconName}。
* @return 字符串结果
*/
public String getIconName() {
return this.getAppInfo().getString("iconName");
}
/**
* 设置 {@code iconName}。
*
* @param iconName 参数 {@code iconName}({@code String})
*/
public void setIconName(String iconName) {
this.setAppInfo("iconName", iconName);
}
/**
* 获取 {@code versionCode}。
* @return 数量/长度
*/
public long getVersionCode() {
return this.getAppInfo().getLong("versionCode");
}
/**
* 设置 {@code versionCode}。
*
* @param versionCode 参数 {@code versionCode}({@code long})
*/
public void setVersionCode(long versionCode) {
this.setAppInfo("versionCode", versionCode);
}
/**
* 获取 {@code versionName}。
* @return 字符串结果
*/
public String getVersionName() {
return this.getAppInfo().getString("versionName");
}
/**
* 设置 {@code versionName}。
*
* @param versionName 参数 {@code versionName}({@code String})
*/
public void setVersionName(String versionName) {
this.setAppInfo("versionName", versionName);
}
/**
* 获取 {@code minSdkVersion}。
* @return 数量/长度
*/
public int getMinSdkVersion() {
return this.getAppInfo().getInteger("minSdkVersion", -1);
}
/**
* 设置 {@code minSdkVersion}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param minSdkVersion 参数 {@code minSdkVersion}({@code String})
*/
public void setMinSdkVersion(String minSdkVersion) {
if (!Strings.isNullOrEmpty(minSdkVersion)) {
this.setMinSdkVersion(Integer.parseInt(minSdkVersion));
@@ -143,14 +308,30 @@ public class AppFile extends BaseFile {
}
/**
* 设置 {@code minSdkVersion}。
*
* @param minSdkVersion 参数 {@code minSdkVersion}({@code int})
*/
public void setMinSdkVersion(int minSdkVersion) {
this.setAppInfo("minSdkVersion", minSdkVersion);
}
/**
* 获取 {@code maxSdkVersion}。
* @return 数量/长度
*/
public int getMaxSdkVersion() {
return this.getAppInfo().getInteger("maxSdkVersion", -1);
}
/**
* 设置 {@code maxSdkVersion}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param maxSdkVersion 参数 {@code maxSdkVersion}({@code String})
*/
public void setMaxSdkVersion(String maxSdkVersion) {
if (!Strings.isNullOrEmpty(maxSdkVersion)) {
this.setAppInfo("maxSdkVersion", Integer.parseInt(maxSdkVersion));
@@ -158,10 +339,21 @@ public class AppFile extends BaseFile {
}
/**
* 获取 {@code targetSdkVersion}。
* @return 数量/长度
*/
public int getTargetSdkVersion() {
return this.getAppInfo().getInteger("targetSdkVersion", -1);
}
/**
* 设置 {@code targetSdkVersion}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param targetSdkVersion 参数 {@code targetSdkVersion}({@code String})
*/
public void setTargetSdkVersion(String targetSdkVersion) {
if (Strings.isNullOrEmpty(targetSdkVersion)) {
this.getAppInfo().remove("targetSdkVersion");
@@ -171,18 +363,38 @@ public class AppFile extends BaseFile {
}
public List getUserPermission() {
/**
* 获取 {@code userPermission}。
* @return String列表,可能为空
*/
public List<String> getUserPermission() {
return this.getAppInfo().getList("userPermission", String.class);
}
public void setUserPermission(List userPermission) {
/**
* 设置 {@code userPermission}。
*
* @param userPermission 参数 {@code userPermission}({@code List<String>})
*/
public void setUserPermission(List<String> userPermission) {
this.setAppInfo("userPermission", userPermission);
}
/**
* 获取 {@code certMd5}。
* @return 字符串结果
*/
public String getCertMd5() {
return this.getAppInfo().getString("certMd5");
}
/**
* 设置 {@code certMd5}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param certMd5 参数 {@code certMd5}({@code String})
*/
public void setCertMd5(String certMd5) {
if (!Strings.isNullOrEmpty(certMd5)) {
this.setAppInfo("certMd5", certMd5);
@@ -190,6 +402,13 @@ public class AppFile extends BaseFile {
}
/**
* 设置 {@code appInfo}。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 2 个条件分支、0 个循环;主要调用:new McApkFile、close。
*
* @param file 文件({@code McFile})
*/
public void setAppInfo(McFile file) {
try {
McApkFile apkFile = new McApkFile(file);
@@ -220,6 +439,9 @@ public class AppFile extends BaseFile {
}
/**
* 处理minify。
*/
public void minify() {
super.minify();
this.setUserPermission((List)null);
+286 -2
View File
@@ -14,23 +14,90 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code BaseFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code fileUuid}(UUID):文件UUID</li>
* <li>{@code userUuid}(UUID):用户UUID</li>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code fileInfo}(DbObject):文件信息</li>
* <li>{@code extra}(DbObject):字段 extra</li>
* <li>{@code name}(String):名称</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class BaseFile {
/**
* 文件UUID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
protected UUID fileUuid;
/**
* 用户UUID。
*/
protected UUID userUuid;
/**
* 用户所属站点 UUID;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
protected UUID siteUuid;
/**
* 文件信息。
*/
protected DbObject fileInfo;
/**
* 字段 extra。
*/
protected DbObject extra;
/**
* 名称。
*/
protected String name;
/**
* 是否启用。
*/
protected boolean enabled = true;
/**
* 最后Updated。
*/
protected Date lastUpdated;
/**
* 时间字段。
*/
protected Date registeredAt;
/**
* 构造 {@code BaseFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public BaseFile() {
}
/**
* 构造 {@code BaseFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public BaseFile(User user, UUID fileUuid, McFile file) {
this.setUserUuid(user);
this.setFileUuid(fileUuid);
@@ -38,30 +105,64 @@ public class BaseFile {
this.initRegisteredAt();
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code fileUuid}。
* @return UUID
*/
public UUID getFileUuid() {
return this.fileUuid;
}
/**
* 设置 {@code fileUuid}。
*
* @param uid 参数 {@code uid}({@code UUID})
*/
public void setFileUuid(UUID uid) {
this.fileUuid = uid;
}
/**
* 获取 {@code userUuid}。
* @return UUID
*/
public UUID getUserUuid() {
return this.userUuid;
}
/**
* 设置 {@code userUuid}。
*
* @param uid 参数 {@code uid}({@code UUID})
*/
public void setUserUuid(UUID uid) {
this.userUuid = uid;
}
/**
* 设置 {@code userUuid}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param user 当前用户({@code User})
*/
public void setUserUuid(User user) {
if (user != null) {
this.userUuid = user.getUuid();
@@ -69,6 +170,12 @@ public class BaseFile {
}
/**
* 获取 {@code fileInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getFileInfo() {
if (this.fileInfo == null) {
this.fileInfo = new DbObject();
@@ -77,6 +184,14 @@ public class BaseFile {
return this.fileInfo;
}
/**
* 获取文件信息AsString。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
*
* @param key 键/配置项({@code String})
* @return 字符串结果
*/
public String getFileInfoAsString(String key) {
if (this.fileInfo == null) {
this.fileInfo = new DbObject();
@@ -85,14 +200,29 @@ public class BaseFile {
return this.fileInfo.getString(key);
}
/**
* 移除文件信息。
*/
public void removeFileInfo() {
this.fileInfo = null;
}
/**
* 设置 {@code fileInfo}。
*
* @param fileInfo 参数 {@code fileInfo}({@code DbObject})
*/
public void setFileInfo(DbObject fileInfo) {
this.fileInfo = fileInfo;
}
/**
* 设置 {@code fileInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:exists。
*
* @param file 文件({@code McFile})
*/
public void setFileInfo(McFile file) {
if (file.exists()) {
this.setLength(file.length());
@@ -102,15 +232,31 @@ public class BaseFile {
}
/**
* 获取 {@code extra}。
* @return MongoDB 文档扩展对象
*/
public DbObject getExtra() {
return this.extra;
}
/**
* 设置 {@code extra}。
*
* @param extra 参数 {@code extra}({@code DbObject})
*/
public void setExtra(DbObject extra) {
this.extra = extra;
}
public void setExtra(Map parameters) {
/**
* 设置 {@code extra}。
*
* 实现要点:包含 3 个条件分支、0 个循环;主要调用:new DbObject。
*
* @param parameters 参数 {@code parameters}({@code Map<String, String[]>})
*/
public void setExtra(Map<String, String[]> parameters) {
if (parameters != null) {
if (this.extra == null) {
this.extra = new DbObject();
@@ -119,7 +265,7 @@ public class BaseFile {
parameters.forEach((k, v) -> {
String key = (String) k;
String[] value = (String[]) v;
if (value != null && value.length > 0 && key.startsWith("extra.")) {
if (value.length > 0 && key.startsWith("extra.")) {
this.extra.put(key.substring(6), value.length == 1 ? value[0] : Arrays.asList(value));
}
@@ -128,30 +274,63 @@ public class BaseFile {
}
/**
* 获取 {@code enabled}。
* @return 字段/派生属性 {@code enabled} 的值
*/
public boolean getEnabled() {
return this.enabled;
}
/**
* 设置 {@code enabled}。
*
* @param enabled 参数 {@code enabled}({@code boolean})
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
return this.name;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 {@code fileName}。
* @return 字符串结果
*/
public String getFileName() {
return this.getFileInfo().getString("fileName");
}
/**
* 设置 {@code fileName}。
*
* @param fileName 文件名({@code String})
*/
public void setFileName(String fileName) {
this.setFileInfo("fileName", fileName);
}
/**
* 获取 {@code contentType}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new Tika。
* @return 字符串结果
*/
public String getContentType() {
String contentType = this.getFileInfo().getString("contentType");
if (Strings.isNullOrEmpty(contentType)) {
@@ -162,30 +341,64 @@ public class BaseFile {
return contentType;
}
/**
* 设置 {@code type}。
*
* @param contentType Content-Type({@code String})
*/
public void setType(String contentType) {
this.setFileInfo("contentType", contentType);
}
/**
* 获取 {@code length}。
* @return 数量/长度
*/
public long getLength() {
return this.getFileInfo().getLong("length");
}
/**
* 设置 {@code length}。
*
* @param length 参数 {@code length}({@code long})
*/
public void setLength(long length) {
this.setFileInfo("length", length);
}
/**
* 获取 {@code checksum}。
* @return 数量/长度
*/
public long getChecksum() {
return this.getFileInfo().getLong("checksum");
}
/**
* 设置 {@code checksum}。
*
* @param checksum 参数 {@code checksum}({@code long})
*/
public void setChecksum(long checksum) {
this.setFileInfo("checksum", checksum);
}
/**
* 获取 {@code lastModified}。
* @return 数量/长度
*/
public long getLastModified() {
return this.getFileInfo().getLong("lastModified");
}
/**
* 设置 {@code lastModified}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new Date。
*
* @param lastModified 参数 {@code lastModified}({@code long})
*/
public void setLastModified(long lastModified) {
if (lastModified <= 0L) {
lastModified = (new Date()).getTime();
@@ -194,25 +407,51 @@ public class BaseFile {
this.setFileInfo("lastModified", lastModified);
}
/**
* 设置文件信息。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setFileInfo(String key, Object value) {
this.getFileInfo().append(key, value);
}
/**
* 设置 {@code fileUrl}。
*
* @param url 参数 {@code url}({@code String})
*/
public void setFileUrl(String url) {
this.setFileInfo("fileUrl", url);
}
/**
* 获取 {@code urlExpiry}。
* @return 数量/长度
*/
public long getUrlExpiry() {
Date expiry = this.getFileInfo().getDate("urlExpiry");
return expiry == null ? -1L : expiry.getTime();
}
/**
* 设置 {@code cloudUrl}。
*
* @param url 参数 {@code url}({@code String})
*/
public void setCloudUrl(String url) {
this.setFileInfo("fileUrl", url);
Date expiry = LocalDateTime.now().plusDays(6).toDate();
this.setFileInfo("urlExpiry", expiry);
}
/**
* 判断 {@code fileUrl}。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new Date。
* @return 字段/派生属性 {@code fileUrl} 的值
*/
public boolean hasFileUrl() {
boolean hasUrl = this.getFileInfo().containsKey("fileUrl");
if (hasUrl && this.getFileInfo().containsKey("urlExpiry")) {
@@ -226,10 +465,20 @@ public class BaseFile {
return hasUrl;
}
/**
* 获取 {@code fileUrl}。
* @return 字符串结果
*/
public String getFileUrl() {
return this.getFileInfoAsString("fileUrl");
}
/**
* 判断 {@code iconUrl}。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new Date。
* @return 字段/派生属性 {@code iconUrl} 的值
*/
public boolean hasIconUrl() {
boolean hasUrl = this.getFileInfo().containsKey("iconUrl");
if (hasUrl && this.getFileInfo().containsKey("iconExpiry")) {
@@ -243,37 +492,72 @@ public class BaseFile {
return hasUrl;
}
/**
* 设置 {@code iconUrl}。
*
* @param url 参数 {@code url}({@code String})
*/
public void setIconUrl(String url) {
this.setFileInfo("iconUrl", url);
Date expiry = LocalDateTime.now().plusDays(6).toDate();
this.setFileInfo("iconExpiry", expiry);
}
/**
* 获取 {@code iconUrl}。
* @return 字符串结果
*/
public String getIconUrl() {
return this.getFileInfoAsString("iconUrl");
}
/**
* 获取 {@code lastUpdated}。
* @return 字段/派生属性 {@code lastUpdated} 的值
*/
public Date getLastUpdated() {
return this.lastUpdated;
}
/**
* 设置 {@code lastUpdated}。
*
* @param lastUpdated 参数 {@code lastUpdated}({@code Date})
*/
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
/**
* 获取 {@code registeredAt}。
* @return 字段/派生属性 {@code registeredAt} 的值
*/
public Date getRegisteredAt() {
return this.registeredAt;
}
/**
* 设置 {@code registeredAt}。
*
* @param registeredAt 参数 {@code registeredAt}({@code Date})
*/
public void setRegisteredAt(Date registeredAt) {
this.registeredAt = registeredAt;
}
/**
* 初始化RegisteredAt。
*
* 实现要点:主要调用:new Date。
*/
public void initRegisteredAt() {
this.setRegisteredAt(new Date());
this.setLastUpdated(this.getRegisteredAt());
}
/**
* 处理minify。
*/
public void minify() {
this.userUuid = null;
this.registeredAt = null;
@@ -1,80 +1,212 @@
package com.midm.model.file;
/**
* 【领域模型】{@code DeployOption}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code PROPERTY_DEFAULT}(String):字段 PROPERTY_DEFAULT</li>
* <li>{@code PROPERTY_FORCE_TO_DOWNLOAD}(String):字段 PROPERTY_FORCE_TO_DOWNLOAD</li>
* <li>{@code PROPERTY_FORCE_TO_INSTALL}(String):字段 PROPERTY_FORCE_TO_INSTALL</li>
* <li>{@code PROPERTY_SAVE_AS}(String):字段 PROPERTY_SAVE_AS</li>
* <li>{@code PROPERTY_KEEP_BACKUP}(String):字段 PROPERTY_KEEP_BACKUP</li>
* <li>{@code isDefault}(boolean):判断是否Default</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class DeployOption {
/**
* 字段 PROPERTY_DEFAULT。
*/
public static final String PROPERTY_DEFAULT = "default";
/**
* 字段 PROPERTY_FORCE_TO_DOWNLOAD。
*/
public static final String PROPERTY_FORCE_TO_DOWNLOAD = "force_to_download";
/**
* 字段 PROPERTY_FORCE_TO_INSTALL。
*/
public static final String PROPERTY_FORCE_TO_INSTALL = "force_to_install";
/**
* 字段 PROPERTY_SAVE_AS。
*/
public static final String PROPERTY_SAVE_AS = "save_as";
/**
* 字段 PROPERTY_KEEP_BACKUP。
*/
public static final String PROPERTY_KEEP_BACKUP = "keep_backgup";
/**
* 判断是否Default。
*/
private boolean isDefault;
/**
* uninstall第一。
*/
private boolean uninstallFirst;
/**
* keep数据。
*/
private boolean keepData;
/**
* force转换为下载。
*/
private boolean forceToDownload;
/**
* forece转换为Install。
*/
private boolean foreceToInstall;
/**
* 保存转换为。
*/
private String saveTo;
/**
* 是否keepBackup。
*/
private boolean keepBackup;
/**
* 判断是否用户Mode。
*/
private boolean isUserMode;
/**
* 获取 {@code isDefault}。
* @return 字段/派生属性 {@code isDefault} 的值
*/
public boolean getIsDefault() {
return this.isDefault;
}
/**
* 设置 {@code isDefault}。
*
* @param isDefault 参数 {@code isDefault}({@code boolean})
*/
public void setIsDefault(boolean isDefault) {
this.isDefault = isDefault;
}
/**
* 获取 {@code uninstallFirst}。
* @return 字段/派生属性 {@code uninstallFirst} 的值
*/
public boolean getUninstallFirst() {
return this.uninstallFirst;
}
/**
* 设置 {@code uninstallFirst}。
*
* @param uninstallFirst 参数 {@code uninstallFirst}({@code boolean})
*/
public void setUninstallFirst(boolean uninstallFirst) {
this.uninstallFirst = uninstallFirst;
}
/**
* 获取 {@code keepData}。
* @return 字段/派生属性 {@code keepData} 的值
*/
public boolean getKeepData() {
return this.keepData;
}
/**
* 设置 {@code keepData}。
*
* @param keepData 参数 {@code keepData}({@code boolean})
*/
public void setKeepData(boolean keepData) {
this.keepData = keepData;
}
/**
* 获取 {@code forceToDownload}。
* @return 字段/派生属性 {@code forceToDownload} 的值
*/
public boolean getForceToDownload() {
return this.forceToDownload;
}
/**
* 设置 {@code forceToDownload}。
*
* @param forceToDownload 参数 {@code forceToDownload}({@code boolean})
*/
public void setForceToDownload(boolean forceToDownload) {
this.forceToDownload = forceToDownload;
}
/**
* 获取 {@code foreceToInstall}。
* @return 字段/派生属性 {@code foreceToInstall} 的值
*/
public boolean getForeceToInstall() {
return this.foreceToInstall;
}
/**
* 设置 {@code foreceToInstall}。
*
* @param foreceToInstall 参数 {@code foreceToInstall}({@code boolean})
*/
public void setForeceToInstall(boolean foreceToInstall) {
this.foreceToInstall = foreceToInstall;
}
/**
* 获取 {@code saveTo}。
* @return 字符串结果
*/
public String getSaveTo() {
return this.saveTo;
}
/**
* 设置 {@code saveTo}。
*
* @param saveTo 参数 {@code saveTo}({@code String})
*/
public void setSaveTo(String saveTo) {
this.saveTo = saveTo;
}
/**
* 获取 {@code keepBackup}。
* @return 字段/派生属性 {@code keepBackup} 的值
*/
public boolean getKeepBackup() {
return this.keepBackup;
}
/**
* 设置 {@code keepBackup}。
*
* @param keepBackup 参数 {@code keepBackup}({@code boolean})
*/
public void setKeepBackup(boolean keepBackup) {
this.keepBackup = keepBackup;
}
/**
* 获取 {@code isUserMode}。
* @return 字段/派生属性 {@code isUserMode} 的值
*/
public boolean getIsUserMode() {
return this.isUserMode;
}
/**
* 设置 {@code isUserMode}。
*
* @param isUserMode 参数 {@code isUserMode}({@code boolean})
*/
public void setIsUserMode(boolean isUserMode) {
this.isUserMode = isUserMode;
}
@@ -1,5 +1,20 @@
package com.midm.model.file;
/**
* 【枚举常量】{@code FILE_TYPE}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public enum FILE_TYPE {
OTA,
REGION,
+437 -1
View File
@@ -45,6 +45,9 @@ import org.springframework.data.mongodb.core.mapping.Document;
public class OtaFile extends BaseFile implements Comparable<OtaFile> {
/** Android Recovery 固件升级脚本入口 */
private static final String ENTRY_META_INF = "META-INF/com/";
/**
* 字段 ENTRY_UPDATE_SCRIPT。
*/
private static final String ENTRY_UPDATE_SCRIPT = "META-INF/com/google/android/updater-script";
/** Android 操作系统属性字典路径(包含型号、Build版本、指纹等关键参数) */
@@ -55,19 +58,39 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
/** OTA 元数据配置文件(版本区间、差分基线版本等) */
private static final String ENTRY_METADATA = "META-INF/com/android/metadata";
/**
* 字段 ENTRY_UPDATE_INFO。
*/
private static final String ENTRY_UPDATE_INFO = "META-INF/com/android/update_info";
/** 解析固件包后提取的硬件规格与构建元数据字典 */
private DbObject otaInfo;
/**
* 构造 {@code OtaFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public OtaFile() {
}
/**
* 构造 {@code OtaFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public OtaFile(User user, UUID fileUuid, McFile file) {
super(user, fileUuid, file);
this.setOtaInfo(file);
}
/**
* 判断 {@code otaImage}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字段/派生属性 {@code otaImage} 的值
*/
public boolean isOtaImage() {
if (Strings.isNullOrEmpty(this.getProductId()) && Strings.isNullOrEmpty(this.getDeviceId())) {
return false;
@@ -76,6 +99,12 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
}
/**
* 获取 {@code otaInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getOtaInfo() {
if (this.otaInfo == null) {
this.otaInfo = new DbObject();
@@ -84,14 +113,32 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
return this.otaInfo;
}
/**
* 设置 {@code otaInfo}。
*
* @param otaInfo 参数 {@code otaInfo}({@code DbObject})
*/
public void setOtaInfo(DbObject otaInfo) {
this.otaInfo = otaInfo;
}
/**
* 设置OTA 固件信息。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setOtaInfo(String key, Object value) {
this.getOtaInfo().append(key, value);
}
/**
* 设置 {@code otaInfo}。
*
* 实现要点:包含异常捕获与降级/回滚分支;主要调用:new ZipFile。
*
* @param file 文件({@code McFile})
*/
public void setOtaInfo(McFile file) {
try {
this.retrieveBuildInfo(new ZipFile(file));
@@ -100,30 +147,61 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 获取 {@code type}。
* @return 字符串结果
*/
public String getType() {
return this.getOtaInfo().getString("type", "system");
}
/**
* 判断 {@code systemImage}。
* @return 字段/派生属性 {@code systemImage} 的值
*/
public boolean isSystemImage() {
return this.getType().equals("system");
}
/**
* 判断 {@code regionImage}。
* @return 字段/派生属性 {@code regionImage} 的值
*/
public boolean isRegionImage() {
return this.getType().equals("region");
}
/**
* 判断 {@code modemImage}。
* @return 字段/派生属性 {@code modemImage} 的值
*/
public boolean isModemImage() {
return this.getType().equals("modem");
}
/**
* 判断 {@code abUpdate}。
* @return 字段/派生属性 {@code abUpdate} 的值
*/
public boolean isAbUpdate() {
return this.getOtaInfo().getBoolean("abUpdate", false);
}
/**
* 判断 {@code partial}。
* @return 字段/派生属性 {@code partial} 的值
*/
public boolean isPartial() {
return this.getOtaInfo().containsKey("preBuild");
}
/**
* 设置 {@code type}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param type 类型({@code String})
*/
public void setType(String type) {
if (type.toLowerCase().equals("base")) {
type = "system";
@@ -132,67 +210,142 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
this.getOtaInfo().put("type", type);
}
/**
* 设置 {@code abUpdate}。
*
* @param abUpdate 参数 {@code abUpdate}({@code boolean})
*/
public void setAbUpdate(boolean abUpdate) {
this.getOtaInfo().put("abUpdate", abUpdate);
}
/**
* 获取 {@code buildDate}。
* @return 数量/长度
*/
public long getBuildDate() {
return this.getOtaInfo().getLong("buildDate", -1L);
}
/**
* 设置 {@code buildDate}。
*
* @param date 参数 {@code date}({@code long})
*/
public void setBuildDate(long date) {
this.setOtaInfo("buildDate", date);
}
/**
* 获取 {@code sdkLevel}。
* @return 数量/长度
*/
public int getSdkLevel() {
return this.getOtaInfo().getInteger("sdk", -1);
}
/**
* 设置 {@code sdkLevel}。
*
* @param level 参数 {@code level}({@code int})
*/
public void setSdkLevel(int level) {
this.setOtaInfo("sdk", level);
}
/**
* 获取 {@code postBuildDate}。
* @return 数量/长度
*/
public long getPostBuildDate() {
return this.getOtaInfo().getLong("postBuildDate", -1L);
}
/**
* 设置 {@code postBuildDate}。
*
* @param date 参数 {@code date}({@code long})
*/
public void setPostBuildDate(long date) {
this.setOtaInfo("postBuildDate", date);
}
/**
* 获取 {@code productId}。
* @return 字符串结果
*/
public String getProductId() {
return this.getOtaInfo().getString("productId");
}
/**
* 设置 {@code productId}。
*
* @param productId 参数 {@code productId}({@code String})
*/
public void setProductId(String productId) {
this.setOtaInfo("productId", productId);
}
/**
* 获取 {@code targetProduct}。
* @return 字符串结果
*/
public String getTargetProduct() {
return this.getOtaInfo().getString("targetProduct");
}
/**
* 设置 {@code targetProduct}。
*
* @param productId 参数 {@code productId}({@code String})
*/
public void setTargetProduct(String productId) {
this.setOtaInfo("targetProduct", productId);
}
/**
* 获取 {@code skuId}。
* @return 字符串结果
*/
public String getSkuId() {
return this.getOtaInfo().getString("skuId");
}
/**
* 设置 {@code skuId}。
*
* @param skuId 参数 {@code skuId}({@code String})
*/
public void setSkuId(String skuId) {
this.setOtaInfo("skuId", skuId);
}
/**
* 判断 {@code compatibleSkuIds}。
* @return 字段/派生属性 {@code compatibleSkuIds} 的值
*/
public boolean hasCompatibleSkuIds() {
List<String> ids = this.getOtaInfo().getList("compatibleSkuIds", String.class);
return ids != null && ids.size() > 0;
}
public List getCompatibleSkuIds() {
/**
* 获取 {@code compatibleSkuIds}。
* @return String列表,可能为空
*/
public List<String> getCompatibleSkuIds() {
return this.getOtaInfo().getList("compatibleSkuIds", String.class);
}
/**
* 判断是否CompatibleSkuID。
*
* 实现要点:包含 2 个条件分支、0 个循环。
*
* @param skuId 参数 {@code skuId}({@code String})
* @return 字段/派生属性 {@code compatibleSkuId} 的值
*/
public boolean isCompatibleSkuId(String skuId) {
if (Strings.isNullOrEmpty(skuId)) {
return false;
@@ -207,6 +360,13 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
}
/**
* 设置 {@code compatibleSkuIds}。
*
* 实现要点:包含 2 个条件分支、0 个循环。
*
* @param skuIds 参数 {@code skuIds}({@code String})
*/
public void setCompatibleSkuIds(String skuIds) {
if (!Strings.isNullOrEmpty(skuIds)) {
String[] ids = skuIds.split("\\s*,\\s*");
@@ -217,34 +377,74 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 获取 {@code deviceId}。
* @return 字符串结果
*/
public String getDeviceId() {
return this.getOtaInfo().getString("deviceId");
}
/**
* 设置 {@code deviceId}。
*
* @param deviceId 参数 {@code deviceId}({@code String})
*/
public void setDeviceId(String deviceId) {
this.setOtaInfo("deviceId", deviceId);
}
/**
* 获取 {@code displayId}。
* @return 字符串结果
*/
public String getDisplayId() {
return this.getOtaInfo().getString("displayId");
}
/**
* 设置 {@code displayId}。
*
* @param displayId 参数 {@code displayId}({@code String})
*/
public void setDisplayId(String displayId) {
this.setOtaInfo("displayId", displayId);
}
/**
* 设置 {@code productDisplayId}。
*
* @param displayId 参数 {@code displayId}({@code String})
*/
public void setProductDisplayId(String displayId) {
this.setOtaInfo("productDisplayId", displayId);
}
/**
* 获取 {@code preDisplayId}。
* @return 字符串结果
*/
public String getPreDisplayId() {
return this.getOtaInfo().getString("preDisplayId");
}
/**
* 设置 {@code preDisplayId}。
*
* @param displayId 参数 {@code displayId}({@code String})
*/
public void setPreDisplayId(String displayId) {
this.setOtaInfo("preDisplayId", displayId);
}
/**
* 解析SkuID。
*
* 实现要点:包含 3 个条件分支、0 个循环。
*
* @param displayId 参数 {@code displayId}({@code String})
* @return 字符串结果
*/
public static String parseSkuId(String displayId) {
if (displayId != null) {
int startIndex = displayId.indexOf(46);
@@ -262,142 +462,302 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
return null;
}
/**
* 获取 {@code brand}。
* @return 字符串结果
*/
public String getBrand() {
return this.getOtaInfo().getString("brand");
}
/**
* 设置 {@code brand}。
*
* @param brand 参数 {@code brand}({@code String})
*/
public void setBrand(String brand) {
this.setOtaInfo("brand", brand);
}
/**
* 获取 {@code customer}。
* @return 字符串结果
*/
public String getCustomer() {
return this.getOtaInfo().getString("customer");
}
/**
* 设置 {@code customer}。
*
* @param customer 参数 {@code customer}({@code String})
*/
public void setCustomer(String customer) {
this.setOtaInfo("customer", customer);
}
/**
* 获取 {@code customerId}。
* @return 字符串结果
*/
public String getCustomerId() {
return this.getOtaInfo().getString("customerId");
}
/**
* 设置 {@code customerId}。
*
* @param customerId 参数 {@code customerId}({@code String})
*/
public void setCustomerId(String customerId) {
this.setOtaInfo("customerId", customerId);
}
/**
* 获取 {@code partNo}。
* @return 字符串结果
*/
public String getPartNo() {
return this.getOtaInfo().getString("partNo");
}
/**
* 设置 {@code partNo}。
*
* @param partNo 参数 {@code partNo}({@code String})
*/
public void setPartNo(String partNo) {
this.setOtaInfo("partNo", partNo);
}
/**
* 获取 {@code osVersion}。
* @return 字符串结果
*/
public String getOsVersion() {
return this.getOtaInfo().getString("osVersion");
}
/**
* 设置 {@code osVersion}。
*
* @param version 参数 {@code version}({@code String})
*/
public void setOsVersion(String version) {
this.setOtaInfo("osVersion", version);
}
/**
* 获取 {@code scriptVersion}。
* @return 字符串结果
*/
public String getScriptVersion() {
return this.getOtaInfo().getString("scriptVersion");
}
/**
* 设置 {@code scriptVersion}。
*
* @param partNo 参数 {@code partNo}({@code String})
*/
public void setScriptVersion(String partNo) {
this.setOtaInfo("scriptVersion", partNo);
}
/**
* 获取 {@code releaseVersion}。
* @return 字符串结果
*/
public String getReleaseVersion() {
return this.getOtaInfo().getString("releaseVersion");
}
/**
* 设置 {@code releaseVersion}。
*
* @param partNo 参数 {@code partNo}({@code String})
*/
public void setReleaseVersion(String partNo) {
this.setOtaInfo("releaseVersion", partNo);
}
/**
* 获取 {@code marketName1}。
* @return 字符串结果
*/
public String getMarketName1() {
return this.getOtaInfo().getString("marketName1");
}
/**
* 设置 {@code marketName1}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setMarketName1(String name) {
this.setOtaInfo("marketName1", name);
}
/**
* 获取 {@code marketName2}。
* @return 字符串结果
*/
public String getMarketName2() {
return this.getOtaInfo().getString("marketName2");
}
/**
* 设置 {@code marketName2}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setMarketName2(String name) {
this.setOtaInfo("marketName2", name);
}
/**
* 获取 {@code securityPatchLevel}。
* @return 字符串结果
*/
public String getSecurityPatchLevel() {
return this.getOtaInfo().getString("securityPatch");
}
/**
* 设置 {@code securityPatchLevel}。
*
* @param level 参数 {@code level}({@code String})
*/
public void setSecurityPatchLevel(String level) {
this.setOtaInfo("securityPatch", level);
}
/**
* 获取 {@code buildType}。
* @return 字符串结果
*/
public String getBuildType() {
return this.getOtaInfo().getString("buildType");
}
/**
* 设置 {@code buildType}。
*
* @param buildType 参数 {@code buildType}({@code String})
*/
public void setBuildType(String buildType) {
this.setOtaInfo("buildType", buildType);
}
/**
* 获取 {@code buildTags}。
* @return 字符串结果
*/
public String getBuildTags() {
return this.getOtaInfo().getString("buildTags");
}
/**
* 设置 {@code buildTags}。
*
* @param buildTags 参数 {@code buildTags}({@code String})
*/
public void setBuildTags(String buildTags) {
this.setOtaInfo("buildTags", buildTags);
}
/**
* 获取 {@code preBuild}。
* @return 字符串结果
*/
public String getPreBuild() {
return this.getOtaInfo().getString("preBuild");
}
/**
* 设置 {@code preBuild}。
*
* @param value 值({@code String})
*/
public void setPreBuild(String value) {
this.setOtaInfo("preBuild", value);
}
/**
* 获取 {@code otaCertHash}。
* @return 字符串结果
*/
public String getOtaCertHash() {
return this.getOtaInfo().getString("otaCert");
}
/**
* 设置 {@code otaCertHash}。
*
* @param hash 参数 {@code hash}({@code String})
*/
public void setOtaCertHash(String hash) {
this.setOtaInfo("otaCert", hash);
}
/**
* 获取 {@code modemSku}。
* @return 字符串结果
*/
public String getModemSku() {
return this.getOtaInfo().getString("modemSku");
}
/**
* 设置 {@code modemSku}。
*
* @param hash 参数 {@code hash}({@code String})
*/
public void setModemSku(String hash) {
this.setOtaInfo("modemSku", hash);
}
/**
* 获取 {@code modemFirmwareVersion}。
* @return 字符串结果
*/
public String getModemFirmwareVersion() {
return this.getOtaInfo().getString("modemFirmwareVersion");
}
/**
* 设置 {@code modemFirmwareVersion}。
*
* @param hash 参数 {@code hash}({@code String})
*/
public void setModemFirmwareVersion(String hash) {
this.setOtaInfo("modemFirmwareVersion", hash);
}
/**
* 获取 {@code modemFirmwareLongVersion}。
* @return 字符串结果
*/
public String getModemFirmwareLongVersion() {
return this.getOtaInfo().getString("modemFirmwareLongVersion");
}
/**
* 设置 {@code modemFirmwareLongVersion}。
*
* @param hash 参数 {@code hash}({@code String})
*/
public void setModemFirmwareLongVersion(String hash) {
this.setOtaInfo("modemFirmwareLongVersion", hash);
}
/**
* 处理retrieve构建信息。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 13 个条件分支、2 个循环;主要调用:new ZipInputStream、close。
*
* @param zipFile 参数 {@code zipFile}({@code ZipFile})
*/
private void retrieveBuildInfo(ZipFile zipFile) {
try {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
@@ -475,6 +835,13 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 处理dispatchUpdaterScript。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 8 个条件分支、0 个循环。
*
* @param is 参数 {@code is}({@code InputStream})
*/
private void dispatchUpdaterScript(InputStream is) {
try {
String script = IOUtils.toString(is, "UTF-8");
@@ -520,6 +887,13 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 处理dispatchProp。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 0 个条件分支、1 个循环;主要调用:new Properties。
*
* @param input 参数 {@code input}({@code InputStream})
*/
private void dispatchProp(InputStream input) {
try {
Properties properties = new Properties();
@@ -534,6 +908,13 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 处理dispatchJSON。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 3 个条件分支、1 个循环。
*
* @param input 参数 {@code input}({@code InputStream})
*/
private void dispatchJson(InputStream input) {
if (input != null) {
JsonElement json = McJsonUtils.toJsonElement(input);
@@ -552,11 +933,26 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
}
/**
* 处理dispatchOTA 固件证书。
*
* 实现要点:主要调用:new McOtaCert。
*
* @param otaCertIs 参数 {@code otaCertIs}({@code InputStream})
*/
private void dispatchOtaCert(InputStream otaCertIs) {
McOtaCert otaCert = new McOtaCert(otaCertIs);
this.setOtaCertHash(otaCert.getBase64Hash());
}
/**
* 设置OTA 固件Property。
*
* 实现要点:包含 25 个条件分支、0 个循环。
*
* @param key 键/配置项({@code String})
* @param value 值({@code String})
*/
private void setOtaProperty(String key, String value) {
switch (key) {
case "ota-type":
@@ -660,6 +1056,7 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
break;
case "mitac-package-type":
this.setType(value);
break;
case "post-build-incremental":
default:
break;
@@ -711,10 +1108,21 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 获取 {@code postBuild}。
* @return 字符串结果
*/
public String getPostBuild() {
return this.getOtaInfo().getString("postBuild");
}
/**
* 处理dispatchPost构建。
*
* 实现要点:包含 4 个条件分支、0 个循环。
*
* @param text 参数 {@code text}({@code String})
*/
private void dispatchPostBuild(String text) {
this.setOtaInfo("postBuild", text);
String[] tags = text.split(":");
@@ -736,6 +1144,17 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
/**
* 处理subString。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param sb 参数 {@code sb}({@code String})
* @param key 键/配置项({@code String})
* @param prefix 参数 {@code prefix}({@code String})
* @param suffix 参数 {@code suffix}({@code String})
* @return 字符串结果
*/
private String subString(String sb, String key, String prefix, String suffix) {
int keyIndex = sb.indexOf(key);
if (keyIndex < 0) {
@@ -747,6 +1166,15 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
}
}
/**
* 处理最后SubString。
*
* @param sb 参数 {@code sb}({@code String})
* @param key 键/配置项({@code String})
* @param prefix 参数 {@code prefix}({@code String})
* @param suffix 参数 {@code suffix}({@code String})
* @return 字符串结果
*/
private String lastSubString(String sb, String key, String prefix, String suffix) {
int keyIndex = sb.indexOf(key);
int endIndex = sb.lastIndexOf(",", keyIndex);
@@ -754,6 +1182,14 @@ public class OtaFile extends BaseFile implements Comparable<OtaFile> {
return startIndex < endIndex ? sb.substring(startIndex, endIndex) : "";
}
/**
* 按业务字段比较两个对象的顺序。
*
* 实现要点:包含 6 个条件分支、0 个循环。
*
* @param other 参数 {@code other}({@code OtaFile})
* @return 数量/长度
*/
public int compareTo(OtaFile other) {
int result = this.getSkuId().compareTo(other.getSkuId());
if (result == 0) {
@@ -2,6 +2,23 @@ package com.midm.model.file;
import java.util.List;
/**
* 【枚举常量】{@code REPORT_ERROR}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code COLLECT_SSN}(List<REPORT_ERROR>):REPORT_ERROR集合</li>
* <li>{@code value}(int):值</li>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public enum REPORT_ERROR {
UNKNOWN(1000),
FILE_ERROR(1001),
@@ -14,17 +31,40 @@ public enum REPORT_ERROR {
FILE_ALREADY_EXISTS(1009),
FILE_MISMATCHED(2001);
public static final List COLLECT_SSN = List.of(UNKNOWN, FILE_ERROR, INSUFFICIENT_SPACE, DEVICE_NOT_FOUND, CANNOT_RESUME, FILE_ALREADY_EXISTS);
/**
* REPORT_ERROR集合。
*/
public static final List<REPORT_ERROR> COLLECT_SSN = List.of(UNKNOWN, FILE_ERROR, INSUFFICIENT_SPACE, DEVICE_NOT_FOUND, CANNOT_RESUME, FILE_ALREADY_EXISTS);
/**
* 值。
*/
private int value;
/**
* 构造 {@code REPORT_ERROR} 实例。
*
* @param value 值({@code int})
*/
private REPORT_ERROR(int value) {
this.value = value;
}
/**
* 获取 {@code value}。
* @return 数量/长度
*/
public int getValue() {
return this.value;
}
/**
* 处理从值。
*
* 实现要点:包含 1 个条件分支、1 个循环。
*
* @param value 值({@code int})
* @return 处理结果
*/
public static REPORT_ERROR fromValue(int value) {
for(REPORT_ERROR e : values()) {
if (e.getValue() == value) {
@@ -0,0 +1,17 @@
/**
* 文件领域模型:APK/OTA/报表/图片等文件元数据与上传结果。
*
* <p>本包主要类型:
* <ul>
* <li>{@link AppFile}</li>
* <li>{@link BaseFile}</li>
* <li>{@link DeployOption}</li>
* <li>{@link FILE_TYPE}</li>
* <li>{@link OtaFile}</li>
* <li>{@link REPORT_ERROR}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.file;
@@ -12,6 +12,31 @@ import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code MidmLog}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code forWhat}(UUID):用于What</li>
* <li>{@code category}(String):字段 category</li>
* <li>{@code log}(String):日志</li>
* <li>{@code reference}(DbObject):字段 reference</li>
* <li>{@code loggedAt}(Date):时间字段</li>
* </ul>
*
* 协作对象:{@code DbObject、User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
@CompoundIndexes({@CompoundIndex(
def = "{'category':1, 'loggedAt':1}"
@@ -21,21 +46,62 @@ import org.springframework.data.mongodb.core.mapping.Document;
def = "{'forWhat':1, 'log': 1}"
)})
public class MidmLog {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 用于What。
*/
private UUID forWhat;
/**
* 字段 category。
*/
private String category;
/**
* 日志。
*/
private String log;
/**
* 字段 reference。
*/
private DbObject reference;
/**
* 时间字段。
*/
private Date loggedAt;
/**
* 字段 logger;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private User logger;
/**
* 构造 {@code MidmLog} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*
* 实现要点:主要调用:new Date。
*/
public MidmLog() {
this.setUuid(UUID.randomUUID());
this.setLoggedAt(new Date());
}
/**
* 构造 {@code MidmLog} 实例。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param user 当前用户({@code User})
* @param forWhat 参数 {@code forWhat}({@code UUID})
* @param category 分类(app/ota/other/report 等)({@code String})
* @param log 参数 {@code log}({@code String})
*/
public MidmLog(User user, UUID forWhat, String category, String log) {
this();
if (user != null) {
@@ -47,38 +113,80 @@ public class MidmLog {
this.setLog(log);
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code forWhat}。
* @return UUID
*/
public UUID getForWhat() {
return this.forWhat;
}
/**
* 设置 {@code forWhat}。
*
* @param forWhat 参数 {@code forWhat}({@code UUID})
*/
public void setForWhat(UUID forWhat) {
this.forWhat = forWhat;
}
/**
* 获取 {@code category}。
* @return 字符串结果
*/
public String getCategory() {
return this.category;
}
/**
* 设置 {@code category}。
*
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public void setCategory(String category) {
this.category = category;
}
/**
* 获取 {@code log}。
* @return 字符串结果
*/
public String getLog() {
return this.log;
}
/**
* 设置 {@code log}。
*
* @param log 参数 {@code log}({@code String})
*/
public void setLog(String log) {
this.log = log;
}
/**
* 获取 {@code reference}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReference() {
if (this.reference == null) {
this.reference = new DbObject();
@@ -87,14 +195,32 @@ public class MidmLog {
return this.reference;
}
/**
* 判断 {@code reference}。
* @return 字段/派生属性 {@code reference} 的值
*/
public boolean hasReference() {
return this.reference != null && this.reference.size() > 0;
}
/**
* 设置 {@code reference}。
*
* @param reference 参数 {@code reference}({@code DbObject})
*/
public void setReference(DbObject reference) {
this.reference = reference;
}
/**
* 设置Reference。
*
* 实现要点:包含 3 个条件分支、0 个循环。
*
* @param agent 参数 {@code agent}({@code UserAgent})
* @param sessionId 参数 {@code sessionId}({@code String})
* @param remoteIp 参数 {@code remoteIp}({@code String})
*/
public void setReference(UserAgent agent, String sessionId, String remoteIp) {
if (agent != null) {
this.addReference("browser", agent.agentFamily());
@@ -112,30 +238,65 @@ public class MidmLog {
}
/**
* 添加Reference。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void addReference(String key, Object value) {
this.getReference().put(key, value);
}
/**
* 获取 {@code loggerUuid}。
* @return UUID
*/
public UUID getLoggerUuid() {
return this.logger != null ? this.logger.getUuid() : null;
}
/**
* 获取 {@code loggedAt}。
* @return 字段/派生属性 {@code loggedAt} 的值
*/
public Date getLoggedAt() {
return this.loggedAt;
}
/**
* 设置 {@code loggedAt}。
*
* @param loggedAt 参数 {@code loggedAt}({@code Date})
*/
public void setLoggedAt(Date loggedAt) {
this.loggedAt = loggedAt;
}
/**
* 设置 {@code loggedAt}。
*
* 实现要点:主要调用:new Date。
*
* @param loggedAt 参数 {@code loggedAt}({@code long})
*/
public void setLoggedAt(long loggedAt) {
this.loggedAt = new Date(loggedAt);
}
/**
* 获取 {@code logger}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getLogger() {
return this.logger;
}
/**
* 设置 {@code logger}。
*
* @param logger 参数 {@code logger}({@code User})
*/
public void setLogger(User logger) {
this.logger = logger;
}
@@ -0,0 +1,12 @@
/**
* 审计与操作日志模型。
*
* <p>本包主要类型:
* <ul>
* <li>{@link MidmLog}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.log;
@@ -1,5 +1,22 @@
package com.midm.model.message;
/**
* 【枚举常量】{@code MIDM_REQUEST}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code code}(int):代码</li>
* <li>{@code request}(String):请求</li>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public enum MIDM_REQUEST {
PING(99, "ping"),
CONNECT(100, "connect"),
@@ -21,22 +38,50 @@ public enum MIDM_REQUEST {
RTC(400, "rtc"),
UNKNOWN(-1, "");
/**
* 代码。
*/
private int code;
/**
* 请求。
*/
private String request;
/**
* 构造 {@code MIDM_REQUEST} 实例。
*
* @param code 状态码/业务码({@code int})
* @param request HTTP 请求({@code String})
*/
private MIDM_REQUEST(int code, String request) {
this.code = code;
this.request = request;
}
/**
* 获取 {@code code}。
* @return 数量/长度
*/
public int getCode() {
return this.code;
}
/**
* 获取 {@code request}。
* @return 字符串结果
*/
public String getRequest() {
return this.request;
}
/**
* 处理获取。
*
* 实现要点:包含 1 个条件分支、1 个循环。
*
* @param code 状态码/业务码({@code int})
* @return 处理结果
*/
public static MIDM_REQUEST get(int code) {
for(MIDM_REQUEST request : values()) {
if (request.code == code) {
@@ -47,6 +92,14 @@ public enum MIDM_REQUEST {
return UNKNOWN;
}
/**
* 处理获取。
*
* 实现要点:包含 1 个条件分支、1 个循环。
*
* @param requestText 参数 {@code requestText}({@code String})
* @return 处理结果
*/
public static MIDM_REQUEST get(String requestText) {
for(MIDM_REQUEST request : values()) {
if (request.getRequest().equalsIgnoreCase(requestText.trim())) {
@@ -14,121 +14,306 @@ import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.web.socket.BinaryMessage;
import org.springframework.web.socket.TextMessage;
/**
* 【MongoDB 文档实体】{@code MidmPacket}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code recieverUuid}(UUID):recieverUUID</li>
* <li>{@code queryUuid}(UUID):查询UUID</li>
* <li>{@code query}(MidmQuery):查询</li>
* <li>{@code feedback}(MidmResponse):反馈</li>
* <li>{@code readAt}(Date):读取At</li>
* </ul>
*
* 协作对象:{@code MidmQuery、MidmResponse}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class MidmPacket implements Serializable {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* recieverUUID。
*/
private UUID recieverUuid;
/**
* 查询UUID。
*/
private UUID queryUuid;
/**
* 查询;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private MidmQuery query;
/**
* 反馈。
*/
private MidmResponse feedback;
/**
* 读取At。
*/
private Date readAt;
/**
* 构造 {@code MidmPacket} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public MidmPacket() {
this.setUuid(UUID.randomUUID());
}
/**
* 构造 {@code MidmPacket} 实例。
*
* 实现要点:主要调用:new MidmQuery。
*
* @param code 状态码/业务码({@code int})
*/
public MidmPacket(int code) {
this.init();
this.setQuery(new MidmQuery(code));
}
/**
* 构造 {@code MidmPacket} 实例。
*
* @param request HTTP 请求({@code MIDM_REQUEST})
*/
public MidmPacket(MIDM_REQUEST request) {
this(request.getCode());
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*/
private void init() {
this.setUuid(UUID.randomUUID());
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code recieverUuid}。
* @return UUID
*/
public UUID getRecieverUuid() {
return this.recieverUuid;
}
/**
* 设置 {@code recieverUuid}。
*
* @param recieverUuid 参数 {@code recieverUuid}({@code UUID})
*/
public void setRecieverUuid(UUID recieverUuid) {
this.recieverUuid = recieverUuid;
}
/**
* 获取 {@code queryUuid}。
* @return UUID
*/
public UUID getQueryUuid() {
return this.queryUuid;
}
/**
* 设置 {@code queryUuid}。
*
* @param queryUuid 参数 {@code queryUuid}({@code UUID})
*/
public void setQueryUuid(UUID queryUuid) {
this.queryUuid = queryUuid;
}
/**
* 获取 {@code query}。
* @return 字段/派生属性 {@code query} 的值
*/
public MidmQuery getQuery() {
return this.query;
}
/**
* 设置 {@code query}。
*
* @param query 查询对象({@code MidmQuery})
*/
public void setQuery(MidmQuery query) {
this.query = query;
}
/**
* 获取Param。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code param} 的值
*/
public Object getParam(String key) {
return this.getQuery().getParam(key);
}
/**
* 设置Param。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setParam(String key, Object value) {
this.getQuery().setParam(key, value);
}
/**
* 获取 {@code feedback}。
* @return 字段/派生属性 {@code feedback} 的值
*/
public MidmResponse getFeedback() {
return this.feedback;
}
/**
* 设置 {@code feedback}。
*
* @param feedback 参数 {@code feedback}({@code MidmResponse})
*/
public void setFeedback(MidmResponse feedback) {
this.feedback = feedback;
}
/**
* 设置反馈。
*
* 实现要点:主要调用:new MidmResponse。
*
* @param code 状态码/业务码({@code int})
* @param message 消息内容({@code String})
*/
public void setFeedback(int code, String message) {
this.feedback = new MidmResponse(code, message);
}
/**
* 设置反馈。
*
* 实现要点:主要调用:new MidmResponse。
*
* @param code 状态码/业务码({@code int})
* @param message 消息内容({@code String})
* @param data 参数 {@code data}({@code Object})
*/
public void setFeedback(int code, String message, Object data) {
this.feedback = new MidmResponse(code, message, data);
}
/**
* 获取 {@code readAt}。
* @return 字段/派生属性 {@code readAt} 的值
*/
public Date getReadAt() {
return this.readAt;
}
/**
* 设置 {@code readAt}。
*
* @param readAt 参数 {@code readAt}({@code Date})
*/
public void setReadAt(Date readAt) {
this.readAt = readAt;
}
/**
* 处理转换为消息。
*
* 实现要点:主要调用:new TextMessage。
* @return 处理结果
*/
public TextMessage toMessage() {
return new TextMessage(this.toString());
}
/**
* 处理转换为Binary。
*
* 实现要点:主要调用:new BinaryMessage。
* @return 处理结果
*/
public BinaryMessage toBinary() {
byte[] bytes = McCompress.compress(this.toString());
return new BinaryMessage(bytes);
}
/**
* 返回对象的可读字符串表示。
* @return 字符串结果
*/
public String toString() {
return McJsonUtils.toJson(this);
}
/**
* 处理转换为报文。
*
* @param message 消息内容({@code TextMessage})
* @return 处理结果
*/
public static MidmPacket toPacket(TextMessage message) {
return (MidmPacket)McJsonUtils.toObject((String)message.getPayload(), MidmPacket.class);
}
/**
* 处理topacket。
*
* 实现要点:主要调用:new String。
*
* @param message 消息内容({@code BinaryMessage})
* @return 处理结果
*/
public static MidmPacket topacket(BinaryMessage message) {
ByteBuffer bytes = (ByteBuffer)message.getPayload();
byte[] decompressed = McDecompress.decompress(bytes.array());
return (MidmPacket)McJsonUtils.toObject(new String(decompressed, Charsets.UTF_8), MidmPacket.class);
}
/**
* 处理转换为报文。
*
* @param message 消息内容({@code String})
* @return 处理结果
*/
public static MidmPacket toPacket(String message) {
return (MidmPacket)McJsonUtils.toObject(message, MidmPacket.class);
}
@@ -5,54 +5,144 @@ import java.util.Date;
import java.util.UUID;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code MidmQuery}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code senderUuid}(UUID):senderUUID</li>
* <li>{@code code}(int):代码</li>
* <li>{@code query}(DbObject):查询</li>
* <li>{@code isInstant}(boolean):判断是否Instant</li>
* <li>{@code registeredAt}(Date):时间字段</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class MidmQuery {
/**
* 对象唯一标识(MongoDB 主键)。
*/
private UUID uuid;
/**
* senderUUID。
*/
private UUID senderUuid;
/**
* 代码。
*/
private int code;
/**
* 查询。
*/
private DbObject query;
/**
* 判断是否Instant。
*/
private boolean isInstant;
/**
* 时间字段。
*/
private Date registeredAt;
/**
* 构造 {@code MidmQuery} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public MidmQuery() {
this.init();
}
/**
* 构造 {@code MidmQuery} 实例。
*
* @param code 状态码/业务码({@code int})
*/
public MidmQuery(int code) {
this();
this.setCode(code);
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.setUuid(UUID.randomUUID());
this.isInstant = true;
this.setRegisteredAt(new Date());
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code senderUuid}。
* @return UUID
*/
public UUID getSenderUuid() {
return this.senderUuid;
}
/**
* 设置 {@code senderUuid}。
*
* @param senderUuid 参数 {@code senderUuid}({@code UUID})
*/
public void setSenderUuid(UUID senderUuid) {
this.senderUuid = senderUuid;
}
/**
* 获取 {@code code}。
* @return 数量/长度
*/
public int getCode() {
return this.code;
}
/**
* 设置 {@code code}。
*
* @param code 状态码/业务码({@code int})
*/
public void setCode(int code) {
this.code = code;
}
/**
* 获取 {@code query}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getQuery() {
if (this.query == null) {
this.query = new DbObject();
@@ -61,18 +151,38 @@ public class MidmQuery {
return this.query;
}
/**
* 设置 {@code query}。
*
* @param query 查询对象({@code DbObject})
*/
public void setQuery(DbObject query) {
this.query = query;
}
/**
* 获取 {@code request}。
* @return 字符串结果
*/
public String getRequest() {
return (String)this.getQuery().get("request");
}
/**
* 设置 {@code request}。
*
* @param request HTTP 请求({@code String})
*/
public void setRequest(String request) {
this.getQuery().put("request", request);
}
/**
* 获取 {@code params}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getParams() {
DbObject params = this.getQuery().getDbObject(new String[]{"params"});
if (params == null) {
@@ -83,30 +193,64 @@ public class MidmQuery {
return params;
}
/**
* 获取Param。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code param} 的值
*/
public Object getParam(String key) {
return this.getParams().get(key);
}
/**
* 获取 {@code command}。
* @return 字符串结果
*/
public String getCommand() {
return this.getParam("command").toString();
}
/**
* 设置Param。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setParam(String key, Object value) {
this.getParams().put(key, value);
}
/**
* 判断 {@code instant}。
* @return 字段/派生属性 {@code instant} 的值
*/
public boolean isInstant() {
return this.isInstant;
}
/**
* 设置 {@code instant}。
*
* @param isInstant 参数 {@code isInstant}({@code boolean})
*/
public void setInstant(boolean isInstant) {
this.isInstant = isInstant;
}
/**
* 获取 {@code registeredAt}。
* @return 字段/派生属性 {@code registeredAt} 的值
*/
public Date getRegisteredAt() {
return this.registeredAt;
}
/**
* 设置 {@code registeredAt}。
*
* @param registeredAt 参数 {@code registeredAt}({@code Date})
*/
public void setRegisteredAt(Date registeredAt) {
this.registeredAt = registeredAt;
}
@@ -8,163 +8,584 @@ import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.web.socket.TextMessage;
/**
* 【领域模型】{@code MidmResponse}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code MESSAGE_SUCCEED}(String):字段 MESSAGE_SUCCEED</li>
* <li>{@code MESSAGE_FAILED}(String):字段 MESSAGE_FAILED</li>
* <li>{@code CODE_SERVICE_CONNECTED}(int):字段 CODE_SERVICE_CONNECTED</li>
* <li>{@code CODE_SUCCEED}(int):字段 CODE_SUCCEED</li>
* <li>{@code CODE_CHECKEDIN}(int):字段 CODE_CHECKEDIN</li>
* <li>{@code CODE_ENROLLED}(int):字段 CODE_ENROLLED</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class MidmResponse {
/**
* 字段 MESSAGE_SUCCEED。
*/
public static final String MESSAGE_SUCCEED = "succeed";
/**
* 字段 MESSAGE_FAILED。
*/
public static final String MESSAGE_FAILED = "failed";
/**
* 字段 CODE_SERVICE_CONNECTED。
*/
public static final int CODE_SERVICE_CONNECTED = 100;
/**
* 字段 CODE_SUCCEED。
*/
public static final int CODE_SUCCEED = 200;
/**
* 字段 CODE_CHECKEDIN。
*/
public static final int CODE_CHECKEDIN = 110;
/**
* 字段 CODE_ENROLLED。
*/
public static final int CODE_ENROLLED = 111;
/**
* 字段 CODE_ENROLL_REJECTED。
*/
public static final int CODE_ENROLL_REJECTED = 112;
/**
* 字段 CODE_DEVICE_REGISTERD。
*/
public static final int CODE_DEVICE_REGISTERD = 113;
/**
* 字段 CODE_DEVICE_UPDATED。
*/
public static final int CODE_DEVICE_UPDATED = 114;
/**
* 字段 CODE_LICENSE_EXPIRED。
*/
public static final int CODE_LICENSE_EXPIRED = 115;
/**
* 字段 CODE_MESSAGE_NOTIFY。
*/
public static final int CODE_MESSAGE_NOTIFY = 116;
/**
* 字段 CODE_REPORT_READY。
*/
public static final int CODE_REPORT_READY = 117;
/**
* 字段 CODE_REPORT_GENERATE_FAIL。
*/
public static final int CODE_REPORT_GENERATE_FAIL = 118;
/**
* 字段 CODE_HOST_LICENSE_READY。
*/
public static final int CODE_HOST_LICENSE_READY = 119;
/**
* 字段 CODE_SITE_LICENSE_READY。
*/
public static final int CODE_SITE_LICENSE_READY = 109;
/**
* 字段 CODE_SITE_LICENSE_REQUESTED。
*/
public static final int CODE_SITE_LICENSE_REQUESTED = 108;
/**
* 字段 CODE_SITE_UPGRADE_REQUESTED。
*/
public static final int CODE_SITE_UPGRADE_REQUESTED = 107;
/**
* 字段 CODE_SITE_UPGRADE_SUCCESS。
*/
public static final int CODE_SITE_UPGRADE_SUCCESS = 106;
/**
* 字段 CODE_UPDATE_CIENT_APPS。
*/
public static final int CODE_UPDATE_CIENT_APPS = 121;
/**
* 字段 CODE_ONLINE_STATE_CHANGED。
*/
public static final int CODE_ONLINE_STATE_CHANGED = 211;
/**
* 字段 CODE_DEVICE_STATE_CHANGED。
*/
public static final int CODE_DEVICE_STATE_CHANGED = 300;
/**
* 字段 FEEDBACK_APP_LIST。
*/
public static final int FEEDBACK_APP_LIST = 120;
/**
* 字段 FEEDBACK_APP_INSTALLED。
*/
public static final int FEEDBACK_APP_INSTALLED = 121;
/**
* 字段 FEEDBACK_APP_UNINSTALLED。
*/
public static final int FEEDBACK_APP_UNINSTALLED = 122;
/**
* 字段 FEEDBACK_APP_ENABLE。
*/
public static final int FEEDBACK_APP_ENABLE = 123;
/**
* 字段 FEEDBACK_APP_DISABLE。
*/
public static final int FEEDBACK_APP_DISABLE = 124;
/**
* 字段 FEEDBACK_APP_SHOW。
*/
public static final int FEEDBACK_APP_SHOW = 125;
/**
* 字段 FEEDBACK_APP_HIDE。
*/
public static final int FEEDBACK_APP_HIDE = 126;
/**
* 字段 FEEDBACK_APP_INFO。
*/
public static final int FEEDBACK_APP_INFO = 127;
/**
* 字段 FEEDBACK_FILE_LIST。
*/
public static final int FEEDBACK_FILE_LIST = 130;
/**
* 字段 FEEDBACK_FILE_STORAGE。
*/
public static final int FEEDBACK_FILE_STORAGE = 131;
/**
* 字段 FEEDBACK_FILE_COPY。
*/
public static final int FEEDBACK_FILE_COPY = 132;
/**
* 字段 FEEDBACK_FILE_RENAME。
*/
public static final int FEEDBACK_FILE_RENAME = 133;
/**
* 字段 FEEDBACK_FILE_MOVE。
*/
public static final int FEEDBACK_FILE_MOVE = 134;
/**
* 字段 FEEDBACK_FILE_REMOVE。
*/
public static final int FEEDBACK_FILE_REMOVE = 135;
/**
* 字段 FEEDBACK_FILE_MKDIR。
*/
public static final int FEEDBACK_FILE_MKDIR = 136;
/**
* 字段 FEEDBACK_FILE_PUSH。
*/
public static final int FEEDBACK_FILE_PUSH = 137;
/**
* 字段 FEEDBACK_FILE_PULL。
*/
public static final int FEEDBACK_FILE_PULL = 138;
/**
* 字段 FEEDBACK_FILE_LOGCAT。
*/
public static final int FEEDBACK_FILE_LOGCAT = 139;
/**
* 字段 FEEDBACK_EXEC。
*/
public static final int FEEDBACK_EXEC = 140;
/**
* 字段 FEEDBACK_EXEC_LOGCAT。
*/
public static final int FEEDBACK_EXEC_LOGCAT = 141;
/**
* 字段 FEEDBACK_HARDWARE_INFO。
*/
public static final int FEEDBACK_HARDWARE_INFO = 170;
/**
* 字段 FEEDBACK_SOFTWARE_INFO。
*/
public static final int FEEDBACK_SOFTWARE_INFO = 180;
/**
* 字段 FEEDBACK_MEMORY_USAGE。
*/
public static final int FEEDBACK_MEMORY_USAGE = 190;
/**
* 字段 FEEDBACK_BATTERY_INFO。
*/
public static final int FEEDBACK_BATTERY_INFO = 191;
/**
* 字段 FEEDBACK_DATA_USAGE。
*/
public static final int FEEDBACK_DATA_USAGE = 192;
/**
* 字段 FEEDBACK_ACTIVE_NETWORK。
*/
public static final int FEEDBACK_ACTIVE_NETWORK = 193;
/**
* 字段 FEEDBACK_NETWORK。
*/
public static final int FEEDBACK_NETWORK = 194;
/**
* 字段 FEEDBACK_LOCATION。
*/
public static final int FEEDBACK_LOCATION = 198;
/**
* 字段 FEEDBACK_SCREEN_CAPTURED。
*/
public static final int FEEDBACK_SCREEN_CAPTURED = 199;
/**
* 字段 FEEDBACK_ONLINE_STATE。
*/
public static final int FEEDBACK_ONLINE_STATE = 211;
/**
* 字段 FEEDBACK_CAMERA_STATE。
*/
public static final int FEEDBACK_CAMERA_STATE = 212;
/**
* 字段 FEEDBACK_DEVICE_STATE。
*/
public static final int FEEDBACK_DEVICE_STATE = 300;
/**
* 字段 CODE_FAILED。
*/
public static final int CODE_FAILED = 400;
/**
* 字段 CODE_NOT_FOUND。
*/
public static final int CODE_NOT_FOUND = 404;
/**
* 字段 CODE_FAIL_USER_NOT_FOUND。
*/
public static final int CODE_FAIL_USER_NOT_FOUND = 410;
/**
* 字段 CODE_FAIL_WRONG_PASSWROD。
*/
public static final int CODE_FAIL_WRONG_PASSWROD = 411;
/**
* 字段 CODE_FAIL_USER_NOT_AVAILABLE。
*/
public static final int CODE_FAIL_USER_NOT_AVAILABLE = 412;
/**
* 字段 CODE_FAIL_INSUFFICIENT_INFO。
*/
public static final int CODE_FAIL_INSUFFICIENT_INFO = 413;
/**
* 字段 CODE_FAIL_USER_LOGGED_IN。
*/
public static final int CODE_FAIL_USER_LOGGED_IN = 414;
/**
* 字段 CODE_FAIL_NO_AUTH_INFO。
*/
public static final int CODE_FAIL_NO_AUTH_INFO = 415;
/**
* 字段 CODE_FAIL_REGISTERED_TO_OTHER。
*/
public static final int CODE_FAIL_REGISTERED_TO_OTHER = 416;
/**
* 字段 CODE_FAIL_VERSION_DUPLICATE。
*/
public static final int CODE_FAIL_VERSION_DUPLICATE = 417;
/**
* 字段 CODE_FAIL_USER_NOT_AGREED。
*/
public static final int CODE_FAIL_USER_NOT_AGREED = 418;
/**
* 字段 CODE_FAIL_SAME_NAME_NOT_ALLOW。
*/
public static final int CODE_FAIL_SAME_NAME_NOT_ALLOW = 419;
/**
* 字段 CODE_FAIL_HOST_EXPIRED。
*/
public static final int CODE_FAIL_HOST_EXPIRED = 420;
/**
* 字段 CODE_FAIL_HOST_EXCEED_DEVICE_LIMIT。
*/
public static final int CODE_FAIL_HOST_EXCEED_DEVICE_LIMIT = 421;
/**
* 字段 CODE_FAIL_INVALID。
*/
public static final int CODE_FAIL_INVALID = 422;
/**
* 字段 CODE_FAIL_EXISTING_USER。
*/
public static final int CODE_FAIL_EXISTING_USER = 423;
/**
* 字段 CODE_FAIL_EXCEED_LOGIN_FAILURE。
*/
public static final int CODE_FAIL_EXCEED_LOGIN_FAILURE = 424;
/**
* 字段 CODE_FAIL_API_ONLY_USER。
*/
public static final int CODE_FAIL_API_ONLY_USER = 425;
/**
* 字段 CODE_FAIL_SITE_NOT_FOUND。
*/
public static final int CODE_FAIL_SITE_NOT_FOUND = 450;
/**
* 字段 CODE_FAIL_NO_SITE_AVAILABLE。
*/
public static final int CODE_FAIL_NO_SITE_AVAILABLE = 451;
/**
* 字段 CODE_FAIL_SITE_NO_USER。
*/
public static final int CODE_FAIL_SITE_NO_USER = 452;
/**
* 字段 CODE_FAIL_SITE_USER_DISABLED。
*/
public static final int CODE_FAIL_SITE_USER_DISABLED = 453;
/**
* 字段 CODE_FAIL_SITE_SAME。
*/
public static final int CODE_FAIL_SITE_SAME = 455;
/**
* 字段 CODE_FAIL_DEVICE_NO_SERIAL。
*/
public static final int CODE_FAIL_DEVICE_NO_SERIAL = 461;
/**
* 字段 CODE_FAIL_DEVICE_NO_SITE。
*/
public static final int CODE_FAIL_DEVICE_NO_SITE = 462;
/**
* 字段 CODE_FAIL_NO_DEVICE_EXISTS。
*/
public static final int CODE_FAIL_NO_DEVICE_EXISTS = 463;
/**
* 字段 CODE_FAIL_DEVICE_NO_LICENSE。
*/
public static final int CODE_FAIL_DEVICE_NO_LICENSE = 464;
/**
* 字段 CODE_FAIL_CHILD_EXISTS。
*/
public static final int CODE_FAIL_CHILD_EXISTS = 466;
/**
* 字段 CODE_FAIL_DEVICE_EXISTS。
*/
public static final int CODE_FAIL_DEVICE_EXISTS = 467;
/**
* 字段 CODE_FAIL_LICENSE_EXPIRED。
*/
public static final int CODE_FAIL_LICENSE_EXPIRED = 115;
/**
* 字段 CODE_ERROR_NO_RECORD。
*/
public static final int CODE_ERROR_NO_RECORD = 421;
/**
* 字段 CODE_ERROR_TOKEN_NOT_DEFINED。
*/
public static final int CODE_ERROR_TOKEN_NOT_DEFINED = 461;
/**
* 字段 CODE_ERROR_EXPIRED_TOKEN。
*/
public static final int CODE_ERROR_EXPIRED_TOKEN = 462;
/**
* 字段 CODE_ERROR_INVALID_TOKEN。
*/
public static final int CODE_ERROR_INVALID_TOKEN = 463;
/**
* 字段 CODE_ERROR_URL_FORMAT。
*/
public static final int CODE_ERROR_URL_FORMAT = 431;
/**
* 字段 CODE_ERROR_IO_EXEPTION。
*/
public static final int CODE_ERROR_IO_EXEPTION = 432;
/**
* 字段 CODE_ERROR_NO_PERMISSION。
*/
public static final int CODE_ERROR_NO_PERMISSION = 433;
/**
* 字段 CODE_ERROR_INVALID_SYSTEM_IMAGE。
*/
public static final int CODE_ERROR_INVALID_SYSTEM_IMAGE = 441;
/**
* 字段 CODE_UNKOWN。
*/
public static final int CODE_UNKOWN = -1;
/**
* 字段 MESSAGE_NOT_ALLOWED。
*/
public static final String MESSAGE_NOT_ALLOWED = "Not allowed.";
/**
* 字段 MESSAGE_NOT_AUTHORIZED。
*/
public static final String MESSAGE_NOT_AUTHORIZED = "Not authorized.";
/**
* 字段 MESSAGE_NO_PERMISSION。
*/
public static final String MESSAGE_NO_PERMISSION = "No permission.";
/**
* 字段 MESSAGE_NO_USER_EXISTS。
*/
public static final String MESSAGE_NO_USER_EXISTS = "No user exists.";
/**
* 字段 MESSAGE_NO_SITE_AVAILABLE。
*/
public static final String MESSAGE_NO_SITE_AVAILABLE = "No site available.";
/**
* 字段 MESSAGE_NO_DEVICE_EXISTS。
*/
public static final String MESSAGE_NO_DEVICE_EXISTS = "No device exists.";
/**
* 字段 MESSAGE_NO_SERIAL_DEFINED。
*/
public static final String MESSAGE_NO_SERIAL_DEFINED = "No serial no. defined.";
/**
* 字段 MESSAGE_DEVICE_EXISTS。
*/
public static final String MESSAGE_DEVICE_EXISTS = "Existing device.";
/**
* 字段 MESSAGE_NO_GROUP_EXISTS。
*/
public static final String MESSAGE_NO_GROUP_EXISTS = "No group exists.";
/**
* 字段 MESSAGE_NO_GROUP。
*/
public static final String MESSAGE_NO_GROUP = "No group: ";
/**
* 字段 MESSAGE_NO_RECORDS。
*/
public static final String MESSAGE_NO_RECORDS = "No records.";
/**
* 字段 MESSAGE_NO_REPORTS。
*/
public static final String MESSAGE_NO_REPORTS = "No reports.";
/**
* 字段 MESSAGE_NO_LICENSE。
*/
public static final String MESSAGE_NO_LICENSE = "No license.";
/**
* 字段 MESSAGE_NO_LOCATIONS。
*/
public static final String MESSAGE_NO_LOCATIONS = "No locations.";
/**
* 字段 MESSAGE_NO_PROFILE_FOUND。
*/
public static final String MESSAGE_NO_PROFILE_FOUND = "No profile found.";
/**
* 字段 MESSAGE_NO_APP_FOUND。
*/
public static final String MESSAGE_NO_APP_FOUND = "No apps found.";
/**
* 字段 MESSAGE_NO_USER_LOGGED_IN。
*/
public static final String MESSAGE_NO_USER_LOGGED_IN = "No user logged in.";
/**
* 代码。
*/
private int code;
/**
* 消息。
*/
private String message;
/**
* 数据。
*/
private Object data;
/**
* 字段 reference。
*/
private Object reference;
/**
* 总数分页。
*/
private Integer totalPage;
/**
* 数量。
*/
private Long size;
/**
* 总数数量。
*/
private Long totalSize;
/**
* 构造 {@code MidmResponse} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public MidmResponse() {
}
/**
* 构造 {@code MidmResponse} 实例。
*
* @param code 状态码/业务码({@code int})
* @param msg 参数 {@code msg}({@code String})
*/
public MidmResponse(int code, String msg) {
this.setCode(code);
this.setMessage(msg);
}
/**
* 构造 {@code MidmResponse} 实例。
*
* @param code 状态码/业务码({@code int})
* @param msg 参数 {@code msg}({@code String})
* @param data 参数 {@code data}({@code Object})
*/
public MidmResponse(int code, String msg, Object data) {
this.setCode(code);
this.setMessage(msg);
this.setData(data);
}
/**
* 获取 {@code code}。
* @return 数量/长度
*/
public int getCode() {
return this.code;
}
/**
* 设置 {@code code}。
*
* @param code 状态码/业务码({@code int})
*/
public void setCode(int code) {
this.code = code;
}
/**
* 获取 {@code message}。
* @return 字符串结果
*/
public String getMessage() {
return this.message;
}
/**
* 设置 {@code message}。
*
* @param message 消息内容({@code String})
*/
public void setMessage(String message) {
this.message = message;
}
/**
* 获取 {@code data}。
* @return 字段/派生属性 {@code data} 的值
*/
public Object getData() {
return this.data;
}
/**
* 获取 {@code dataAsDbObject}。
*
* 实现要点:主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getDataAsDbObject() {
Object data = this.getData();
return data == null ? new DbObject() : new DbObject((Map)data);
}
/**
* 设置 {@code data}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
*
* @param data 参数 {@code data}({@code Object})
*/
public void setData(Object data) {
if (data instanceof UpdateResult) {
UpdateResult result = (UpdateResult)data;
@@ -175,56 +596,120 @@ public class MidmResponse {
}
/**
* 获取 {@code reference}。
* @return 字段/派生属性 {@code reference} 的值
*/
public Object getReference() {
return this.reference;
}
/**
* 获取 {@code refereceAsDbObject}。
*
* 实现要点:主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getRefereceAsDbObject() {
Object data = this.getReference();
return data == null ? new DbObject() : new DbObject((Map)data);
}
/**
* 设置 {@code reference}。
*
* @param reference 参数 {@code reference}({@code Object})
*/
public void setReference(Object reference) {
this.reference = reference;
}
/**
* 获取 {@code totalPage}。
* @return 数量/长度
*/
public int getTotalPage() {
return this.totalPage;
}
/**
* 设置 {@code totalPages}。
*
* @param totalPage 参数 {@code totalPage}({@code int})
*/
public void setTotalPages(int totalPage) {
this.totalPage = totalPage;
}
/**
* 获取 {@code size}。
* @return 数量/长度
*/
public long getSize() {
return this.size;
}
/**
* 设置 {@code size}。
*
* @param size 每页数量({@code long})
*/
public void setSize(long size) {
this.size = size;
}
/**
* 获取 {@code totalSize}。
* @return 数量/长度
*/
public long getTotalSize() {
return this.totalSize;
}
/**
* 设置 {@code totalSize}。
*
* @param totalSize 参数 {@code totalSize}({@code long})
*/
public void setTotalSize(long totalSize) {
this.totalSize = totalSize;
}
/**
* 返回对象的可读字符串表示。
* @return 字符串结果
*/
public String toString() {
return McJsonUtils.toJson(this);
}
/**
* 处理转换为Text消息。
*
* 实现要点:主要调用:new TextMessage。
* @return 处理结果
*/
public TextMessage toTextMessage() {
return new TextMessage(this.toString());
}
/**
* 获取 {@code succeedResponse}。
* @return 字符串结果
*/
public static String getSucceedResponse() {
return getResponse(200, "succeed");
}
public static String getSucceedResponse(List list) {
/**
* 获取Succeed响应。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new MidmResponse。
*
* @param list 参数 {@code list}({@code List<?>})
* @return 字符串结果
*/
public static String getSucceedResponse(List<?> list) {
MidmResponse response = new MidmResponse(200, "succeed");
if (list != null) {
response.setData(list);
@@ -234,7 +719,15 @@ public class MidmResponse {
return response.toString();
}
public static String getSucceedResponse(Page page) {
/**
* 获取Succeed响应。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new MidmResponse。
*
* @param page 页码(从 0 开始)({@code Page<?>})
* @return 字符串结果
*/
public static String getSucceedResponse(Page<?> page) {
MidmResponse response = new MidmResponse(200, "succeed");
if (page != null) {
response.setData(page.getContent());
@@ -246,22 +739,57 @@ public class MidmResponse {
return response.toString();
}
/**
* 获取Succeed响应。
*
* @param data 参数 {@code data}({@code Object})
* @return 字符串结果
*/
public static String getSucceedResponse(Object data) {
return getResponse(200, "succeed", data);
}
/**
* 获取 {@code failedResponse}。
* @return 字符串结果
*/
public static String getFailedResponse() {
return getResponse(400, "failed");
}
/**
* 获取响应。
*
* 实现要点:主要调用:new MidmResponse。
*
* @param code 状态码/业务码({@code int})
* @param msg 参数 {@code msg}({@code String})
* @return 字符串结果
*/
public static String getResponse(int code, String msg) {
return (new MidmResponse(code, msg)).toString();
}
/**
* 获取响应。
*
* 实现要点:主要调用:new MidmResponse。
*
* @param code 状态码/业务码({@code int})
* @param msg 参数 {@code msg}({@code String})
* @param data 参数 {@code data}({@code Object})
* @return 字符串结果
*/
public static String getResponse(int code, String msg, Object data) {
return (new MidmResponse(code, msg, data)).toString();
}
/**
* 获取响应。
*
* @param object 参数 {@code object}({@code Object})
* @return 字符串结果
*/
public static String getResponse(Object object) {
return McJsonUtils.toJson(object);
}
@@ -0,0 +1,15 @@
/**
* WebSocket 报文模型:请求、响应、反馈、参数与错误码。
*
* <p>本包主要类型:
* <ul>
* <li>{@link MIDM_REQUEST}</li>
* <li>{@link MidmPacket}</li>
* <li>{@link MidmQuery}</li>
* <li>{@link MidmResponse}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.message;
@@ -8,30 +8,113 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code MessageLog}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code message}(NewsMessage):消息</li>
* <li>{@code reader}(User):字段 reader</li>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code readDate}(Date):读取日期</li>
* <li>{@code isCheck}(boolean):判断是否检查</li>
* </ul>
*
* 协作对象:{@code NewsMessage、User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class MessageLog {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 消息;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private NewsMessage message;
/**
* 字段 reader;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private User reader;
/**
* 用户所属站点 UUID;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private UUID siteUuid;
/**
* 读取日期;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date readDate;
/**
* 判断是否检查;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private boolean isCheck;
/**
* 判断是否读取;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private boolean isRead;
/**
* 检查日期;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date checkDate;
/**
* 时间字段;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private Date notified;
/**
* 构造 {@code MessageLog} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public MessageLog() {
}
/**
* 构造 {@code MessageLog} 实例。
*
* 实现要点:主要调用:new Date。
*
* @param message 消息内容({@code NewsMessage})
* @param reader 参数 {@code reader}({@code User})
* @param siteUuid 站点 UUID({@code UUID})
*/
public MessageLog(NewsMessage message, User reader, UUID siteUuid) {
this.uuid = UUID.randomUUID();
this.message = message;
@@ -41,6 +124,15 @@ public class MessageLog {
this.notified = new Date();
}
/**
* 构造 {@code MessageLog} 实例。
*
* 实现要点:主要调用:new User、new Date。
*
* @param message 消息内容({@code NewsMessage})
* @param userUuid 用户 UUID({@code UUID})
* @param siteUuid 站点 UUID({@code UUID})
*/
public MessageLog(NewsMessage message, UUID userUuid, UUID siteUuid) {
this.uuid = UUID.randomUUID();
this.message = message;
@@ -50,74 +142,155 @@ public class MessageLog {
this.notified = new Date();
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code message}。
* @return 字段/派生属性 {@code message} 的值
*/
public NewsMessage getMessage() {
return this.message;
}
/**
* 设置 {@code message}。
*
* @param message 消息内容({@code NewsMessage})
*/
public void setMessage(NewsMessage message) {
this.message = message;
}
/**
* 获取 {@code reader}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getReader() {
return this.reader;
}
/**
* 设置 {@code reader}。
*
* @param reader 参数 {@code reader}({@code User})
*/
public void setReader(User reader) {
this.reader = reader;
}
/**
* 判断 {@code check}。
* @return 字段/派生属性 {@code check} 的值
*/
public boolean isCheck() {
return this.isCheck;
}
/**
* 设置 {@code check}。
*
* @param isCheck 参数 {@code isCheck}({@code boolean})
*/
public void setCheck(boolean isCheck) {
this.isCheck = isCheck;
}
/**
* 判断 {@code read}。
* @return 字段/派生属性 {@code read} 的值
*/
public boolean isRead() {
return this.isRead;
}
/**
* 设置 {@code read}。
*
* @param isRead 参数 {@code isRead}({@code boolean})
*/
public void setRead(boolean isRead) {
this.isRead = isRead;
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code notified}。
* @return 字段/派生属性 {@code notified} 的值
*/
public Date getNotified() {
return this.notified;
}
/**
* 设置 {@code notified}。
*
* @param notified 参数 {@code notified}({@code Date})
*/
public void setNotified(Date notified) {
this.notified = notified;
}
/**
* 获取 {@code readDate}。
* @return 字段/派生属性 {@code readDate} 的值
*/
public Date getReadDate() {
return this.readDate;
}
/**
* 设置 {@code readDate}。
*
* @param readDate 参数 {@code readDate}({@code Date})
*/
public void setReadDate(Date readDate) {
this.readDate = readDate;
}
/**
* 获取 {@code checkDate}。
* @return 字段/派生属性 {@code checkDate} 的值
*/
public Date getCheckDate() {
return this.checkDate;
}
/**
* 设置 {@code checkDate}。
*
* @param checkDate 参数 {@code checkDate}({@code Date})
*/
public void setCheckDate(Date checkDate) {
this.checkDate = checkDate;
}
@@ -18,37 +18,124 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.mail.internet.InternetAddress;
/**
* 【MongoDB 文档实体】{@code NewsMessage}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code writer}(User):字段 writer</li>
* <li>{@code category}(String):字段 category</li>
* <li>{@code forWhat}(String):用于What</li>
* <li>{@code reference}(DbObject):字段 reference</li>
* <li>{@code message}(DbObject):消息</li>
* </ul>
*
* 协作对象:{@code User、DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class NewsMessage {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 字段 writer;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private User writer;
/**
* 字段 category。
*/
private String category;
/**
* 用于What。
*/
private String forWhat;
/**
* 字段 reference。
*/
private DbObject reference;
/**
* 消息。
*/
private DbObject message;
/**
* 判断是否Unremovable。
*/
private Boolean isUnremovable;
/**
* 判断是否Enabled。
*/
private Boolean isEnabled;
/**
* 发送调度。
*/
private Date sendSchedule;
/**
* 时间字段。
*/
private Date expiry;
/**
* 发送Now;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private boolean sendNow;
/**
* 创建时间。
*/
private Date created;
/**
* 最后更新时间。
*/
private Date updated;
/**
* 构造 {@code NewsMessage} 实例。
*
* @param device 设备({@code Device})
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public NewsMessage(Device device, String category) {
this.init();
this.category = "device_" + category;
this.reference.put("uuid", device.getUuid());
}
/**
* 构造 {@code NewsMessage} 实例。
*
* @param device 设备({@code Device})
*/
public NewsMessage(Device device) {
this.init();
this.reference.put("uuid", device.getUuid());
}
/**
* 构造 {@code NewsMessage} 实例。
*
* @param packet WebSocket 报文({@code MidmPacket})
*/
public NewsMessage(MidmPacket packet) {
MidmQuery query = packet.getQuery();
this.setUuid(query.getUuid());
@@ -62,16 +149,31 @@ public class NewsMessage {
this.getReference().put("query", query.getQuery());
}
/**
* 构造 {@code NewsMessage} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public NewsMessage() {
this.init();
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.uuid = UUID.randomUUID();
this.created = new Date();
this.updated = this.created;
}
/**
* 获取 {@code message}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage() {
if (this.message == null) {
this.message = new DbObject();
@@ -80,17 +182,32 @@ public class NewsMessage {
return this.message;
}
/**
* 获取消息。
*
* @param locale 参数 {@code locale}({@code Locale})
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage(Locale locale) {
return this.getMessage(locale.toLanguageTag());
}
/**
* 获取消息。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 4 个条件分支、2 个循环;主要调用:new DbObject。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage(String languageTag) {
DbObject message = this.getMessage();
DbObject localedMessage = new DbObject();
if (message.get(languageTag) == null) {
message.put(languageTag, localedMessage);
} else if (message.get(languageTag) instanceof LinkedTreeMap) {
for(Map.Entry entry : ((LinkedTreeMap)message.get(languageTag)).entrySet()) {
for(Object entryObject : ((LinkedTreeMap)message.get(languageTag)).entrySet()) {
Map.Entry entry = (Map.Entry)entryObject;
localedMessage.append((String)entry.getKey(), entry.getValue());
}
@@ -109,83 +226,186 @@ public class NewsMessage {
return localedMessage;
}
/**
* 设置 {@code message}。
*
* @param message 消息内容({@code DbObject})
*/
public void setMessage(DbObject message) {
this.message = message;
}
/**
* 设置消息。
*
* @param title 参数 {@code title}({@code String})
* @param content 参数 {@code content}({@code String})
*/
public void setMessage(String title, String content) {
this.setTitle(title);
this.setContent(content);
}
/**
* 获取 {@code title}。
* @return 字符串结果
*/
public String getTitle() {
return this.getMessage("en-US").getString("title");
}
/**
* 获取 {@code summary}。
* @return 字符串结果
*/
public String getSummary() {
return this.getMessage().getString("summary");
}
/**
* 判断 {@code content}。
* @return 字段/派生属性 {@code content} 的值
*/
public boolean hasContent() {
return this.getMessage().containsKey("content");
}
/**
* 获取 {@code content}。
* @return 字符串结果
*/
public String getContent() {
return this.getMessage("en-US").getString("content");
}
/**
* 获取Title。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字符串结果
*/
public String getTitle(String locale) {
return this.getMessage(locale).getString("title");
}
/**
* 获取Summary。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字符串结果
*/
public String getSummary(String locale) {
return this.getMessage(locale).getString("summary");
}
/**
* 判断是否Content。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字段/派生属性 {@code content} 的值
*/
public boolean hasContent(String locale) {
return this.getMessage(locale).containsKey("content");
}
/**
* 获取Content。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字符串结果
*/
public String getContent(String locale) {
return this.getMessage(locale).getString("content");
}
public List getMailsTo() {
/**
* 获取 {@code mailsTo}。
* @return InternetAddress列表,可能为空
*/
public List<InternetAddress> getMailsTo() {
return McEmailUtils.parseMails(this.getMessage().getString("to"));
}
/**
* 设置消息。
*
* @param title 参数 {@code title}({@code String})
* @param content 参数 {@code content}({@code String})
* @param summary 参数 {@code summary}({@code String})
*/
public void setMessage(String title, String content, String summary) {
this.setMessage(Locale.US.toLanguageTag(), title, content, summary);
}
/**
* 设置消息。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @param title 参数 {@code title}({@code String})
* @param content 参数 {@code content}({@code String})
* @param summary 参数 {@code summary}({@code String})
*/
public void setMessage(String languageTag, String title, String content, String summary) {
this.setTitle(languageTag, title);
this.setContent(languageTag, content);
this.setSummary(languageTag, summary);
}
/**
* 设置 {@code title}。
*
* @param title 参数 {@code title}({@code String})
*/
public void setTitle(String title) {
this.setTitle(Locale.US.toLanguageTag(), title);
}
/**
* 设置 {@code content}。
*
* @param content 参数 {@code content}({@code String})
*/
public void setContent(String content) {
this.setContent(Locale.US.toLanguageTag(), content);
}
/**
* 设置 {@code summary}。
*
* @param summary 参数 {@code summary}({@code String})
*/
public void setSummary(String summary) {
this.setSummary(Locale.US.toLanguageTag(), summary);
}
/**
* 设置Title。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @param title 参数 {@code title}({@code String})
*/
public void setTitle(String languageTag, String title) {
DbObject message = this.getMessage(languageTag);
message.put("title", title);
}
/**
* 设置Content。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @param content 参数 {@code content}({@code String})
*/
public void setContent(String languageTag, String content) {
DbObject message = this.getMessage(languageTag);
message.put("content", content);
}
/**
* 获取 {@code reference}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReference() {
if (this.reference == null) {
this.reference = new DbObject();
@@ -194,111 +414,240 @@ public class NewsMessage {
return this.reference;
}
/**
* 设置 {@code reference}。
*
* @param reference 参数 {@code reference}({@code DbObject})
*/
public void setReference(DbObject reference) {
this.reference = reference;
}
/**
* 设置Summary。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @param summary 参数 {@code summary}({@code String})
*/
public void setSummary(String languageTag, String summary) {
DbObject message = this.getMessage(languageTag);
message.put("summary", summary);
}
/**
* 判断 {@code unremovable}。
* @return 字段/派生属性 {@code unremovable} 的值
*/
public Boolean isUnremovable() {
return this.isUnremovable;
}
/**
* 设置 {@code isUnremovable}。
*
* @param isUnremovable 参数 {@code isUnremovable}({@code Boolean})
*/
public void setIsUnremovable(Boolean isUnremovable) {
this.isUnremovable = isUnremovable;
}
/**
* 获取 {@code forWhat}。
* @return 字符串结果
*/
public String getForWhat() {
return this.forWhat;
}
/**
* 设置 {@code forWhat}。
*
* @param forWhat 参数 {@code forWhat}({@code String})
*/
public void setForWhat(String forWhat) {
this.forWhat = forWhat;
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code writer}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getWriter() {
return this.writer;
}
/**
* 设置 {@code writer}。
*
* @param writer 参数 {@code writer}({@code User})
*/
public void setWriter(User writer) {
this.writer = writer;
}
/**
* 获取 {@code category}。
* @return 字符串结果
*/
public String getCategory() {
return this.category;
}
/**
* 设置 {@code category}。
*
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public void setCategory(String category) {
this.category = category;
}
/**
* 获取 {@code sendSchedule}。
* @return 字段/派生属性 {@code sendSchedule} 的值
*/
public Date getSendSchedule() {
return this.sendSchedule;
}
/**
* 设置 {@code sendSchedule}。
*
* @param sendSchedule 参数 {@code sendSchedule}({@code Date})
*/
public void setSendSchedule(Date sendSchedule) {
this.sendSchedule = sendSchedule;
}
/**
* 发送Now。
*
* 实现要点:主要调用:new DateTime。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean sendNow() {
return this.sendNow || this.sendSchedule == null || McDateTimeUtils.isSameDate(new DateTime(this.sendSchedule), DateTime.now());
}
/**
* 获取 {@code expiry}。
* @return 字段/派生属性 {@code expiry} 的值
*/
public Date getExpiry() {
return this.expiry;
}
/**
* 设置 {@code expiry}。
*
* @param expiry 参数 {@code expiry}({@code Date})
*/
public void setExpiry(Date expiry) {
this.expiry = expiry;
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 获取 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
public Date getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code Date})
*/
public void setUpdated(Date updated) {
this.updated = updated;
}
/**
* 获取 {@code isUnremovable}。
* @return 字段/派生属性 {@code isUnremovable} 的值
*/
public Boolean getIsUnremovable() {
return this.isUnremovable;
}
/**
* 判断 {@code enabled}。
* @return 字段/派生属性 {@code enabled} 的值
*/
public Boolean isEnabled() {
return this.isEnabled;
}
/**
* 设置 {@code isEnabled}。
*
* @param isEnabled 参数 {@code isEnabled}({@code Boolean})
*/
public void setIsEnabled(Boolean isEnabled) {
this.isEnabled = isEnabled;
}
/**
* 判断 {@code sendNow}。
* @return 字段/派生属性 {@code sendNow} 的值
*/
public boolean isSendNow() {
return this.sendNow;
}
/**
* 设置 {@code sendNow}。
*
* @param sendNow 参数 {@code sendNow}({@code boolean})
*/
public void setSendNow(boolean sendNow) {
this.sendNow = sendNow;
}
/**
* 处理转换为日期String。
*
* 实现要点:主要调用:new DateTime。
*
* @param dateString 参数 {@code dateString}({@code String})
* @param format 参数 {@code format}({@code String})
* @return 字符串结果
*/
public String toDateString(String dateString, String format) {
DateTime dateTime = new DateTime(dateString);
return McDateTimeUtils.toString(dateTime, format);
@@ -0,0 +1,13 @@
/**
* 新闻/通知消息模型。
*
* <p>本包主要类型:
* <ul>
* <li>{@link MessageLog}</li>
* <li>{@link NewsMessage}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.news;
+373 -2
View File
@@ -13,30 +13,95 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code Site}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code MODEL_MIDM}(String):字段 MODEL_MIDM</li>
* <li>{@code MODEL_MUST}(String):字段 MODEL_MUST</li>
* <li>{@code reseller}(Site):字段 reseller</li>
* <li>{@code idName}(String):ID名称</li>
* <li>{@code latestVisit}(Date):最新Visit</li>
* <li>{@code report}(DbObject):报表</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class Site extends GeneralProfile {
/**
* 字段 MODEL_MIDM。
*/
public static final String MODEL_MIDM = "midm";
/**
* 字段 MODEL_MUST。
*/
public static final String MODEL_MUST = "must";
/**
* 字段 reseller;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private Site reseller;
/**
* ID名称;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed(unique = true)}。
*/
@Indexed(
unique = true
)
private String idName;
/**
* 最新Visit;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Date latestVisit;
/**
* 报表;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private DbObject report;
/**
* 构造 {@code Site} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public Site() {
this.setEnabled(false);
}
/**
* 构造 {@code Site} 实例。
*
* @param model 参数 {@code model}({@code String})
*/
public Site(String model) {
this();
this.setModel(model);
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new DbObject、new Date。
*/
public void init() {
this.setUuid(UUID.randomUUID());
DbObject notiSettings = new DbObject("sendEmail", true);
@@ -49,57 +114,115 @@ public class Site extends GeneralProfile {
this.setCreated(new Date());
}
/**
* 获取 {@code reseller}。
* @return 站点对象;未找到时返回 {@code null}
*/
public Site getReseller() {
return this.reseller;
}
/**
* 设置 {@code reseller}。
*
* @param reseller 参数 {@code reseller}({@code Site})
*/
public void setReseller(Site reseller) {
this.reseller = reseller;
}
/**
* 判断 {@code child}。
* @return 字段/派生属性 {@code child} 的值
*/
public boolean isChild() {
return this.reseller != null;
}
/**
* 判断 {@code customize}。
* @return 字段/派生属性 {@code customize} 的值
*/
public boolean canCustomize() {
return true;
}
/**
* 获取 {@code domainName}。
* @return 字段/派生属性 {@code domainName} 的值
*/
public Object getDomainName() {
return this.getSetting("domainName");
}
/**
* 获取 {@code idName}。
* @return 字符串结果
*/
public String getIdName() {
return this.idName;
}
/**
* 设置 {@code idName}。
*
* @param idName 参数 {@code idName}({@code String})
*/
public void setIdName(String idName) {
this.idName = idName;
}
/**
* 获取 {@code title}。
* @return 字符串结果
*/
public String getTitle() {
String siteName = (String)this.getSetting("theme", "siteName");
return Strings.isNullOrEmpty(siteName) ? this.getName() : siteName;
}
/**
* 判断 {@code logo}。
* @return 字段/派生属性 {@code logo} 的值
*/
public boolean hasLogo() {
return this.getSettingAsBoolean("theme", "logo", false);
}
/**
* 获取 {@code plan}。
* @return MongoDB 文档扩展对象
*/
public DbObject getPlan() {
return this.getProfileCategory(new String[]{"plan"});
}
/**
* 获取 {@code planName}。
* @return 字符串结果
*/
public String getPlanName() {
DbObject plan = this.getPlan();
return plan.getString("plan", "standard");
}
/**
* 获取 {@code showPlanName}。
* @return 字符串结果
*/
public String getShowPlanName() {
String planName = this.getPlanName();
return this.getShowPlanName(planName);
}
/**
* 获取Show计划名称。
*
* 实现要点:包含 3 个条件分支、0 个循环。
*
* @param planName 参数 {@code planName}({@code String})
* @return 字符串结果
*/
public String getShowPlanName(String planName) {
String name = "";
if (planName.equals("lite")) {
@@ -113,10 +236,22 @@ public class Site extends GeneralProfile {
return name;
}
/**
* 设置 {@code plan}。
*
* @param plan 参数 {@code plan}({@code DbObject})
*/
public void setPlan(DbObject plan) {
this.setProfile("plan", plan);
}
/**
* 设置 {@code plan}。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:remove。
*
* @param plan 参数 {@code plan}({@code String})
*/
public void setPlan(String plan) {
if (!Strings.isNullOrEmpty(plan)) {
this.setProfile("plan", "plan", plan);
@@ -129,64 +264,133 @@ public class Site extends GeneralProfile {
}
}
/**
* 获取 {@code upgradeStatus}。
* @return 字符串结果
*/
public String getUpgradeStatus() {
DbObject plan = this.getPlan();
return plan.getString("upgradeStatus");
}
/**
* 判断 {@code upgradeRequested}。
* @return 字段/派生属性 {@code upgradeRequested} 的值
*/
public boolean isUpgradeRequested() {
return "processing".equals(this.getUpgradeStatus());
}
/**
* 获取 {@code upgradeTargetPlan}。
* @return 字符串结果
*/
public String getUpgradeTargetPlan() {
DbObject plan = this.getPlan();
return plan.getString("targetPlan");
}
/**
* 获取 {@code model}。
* @return 字符串结果
*/
public String getModel() {
return (String)this.getProfile("model", "midm");
}
/**
* 设置 {@code model}。
*
* @param model 参数 {@code model}({@code String})
*/
public void setModel(String model) {
this.setProfile("model", model);
}
/**
* 获取 {@code phone}。
* @return 字符串结果
*/
public String getPhone() {
return (String)this.getProfile("phone");
}
/**
* 获取 {@code address}。
* @return 字符串结果
*/
public String getAddress() {
return (String)this.getProfile("address");
}
/**
* 获取 {@code country}。
*
* 实现要点:包含异常捕获与降级/回滚分支。
* @return 字符串结果
*/
public String getCountry() {
return (String)this.getProfile("country");
}
/**
* 判断 {@code reseller}。
* @return 字段/派生属性 {@code reseller} 的值
*/
public boolean isReseller() {
return (Boolean)this.getProfile("isReseller", false);
}
/**
* 设置 {@code isReseller}。
*
* @param isReseller 参数 {@code isReseller}({@code boolean})
*/
public void setIsReseller(boolean isReseller) {
this.setProfile("isReseller", isReseller);
}
/**
* 处理limitRegistered设备Only。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean limitRegisteredDeviceOnly() {
return this.getSettingAsBoolean("enrollment", "registeredOnly", false);
}
/**
* 获取 {@code latestVisit}。
* @return 字段/派生属性 {@code latestVisit} 的值
*/
public Date getLatestVisit() {
return this.latestVisit;
}
/**
* 设置 {@code latestVisit}。
*
* @param latestVisit 参数 {@code latestVisit}({@code Date})
*/
public void setLatestVisit(Date latestVisit) {
this.latestVisit = latestVisit;
}
/**
* 获取 {@code credential}。
* @return MongoDB 文档扩展对象
*/
public DbObject getCredential() {
return this.getSettings().getDbObject(new String[]{"credential"});
}
/**
* 判断是否CredentialMatched。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:new Date。
*
* @param credential 参数 {@code credential}({@code String})
* @return 字段/派生属性 {@code credentialMatched} 的值
*/
public boolean isCredentialMatched(String credential) {
if (Strings.isNullOrEmpty(credential)) {
return false;
@@ -202,6 +406,13 @@ public class Site extends GeneralProfile {
}
}
/**
* 设置 {@code credential}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
*
* @param credential 参数 {@code credential}({@code String})
*/
public void setCredential(String credential) {
if (!Strings.isNullOrEmpty(credential)) {
DbObject value = new DbObject("credential", credential);
@@ -213,11 +424,20 @@ public class Site extends GeneralProfile {
}
/**
* 处理renewCredential。
*/
public void renewCredential() {
String credential = McUuidUtils.toBase64String(UUID.randomUUID(), true);
this.setCredential(credential);
}
/**
* 获取 {@code settings}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getSettings() {
DbObject settings = super.getSettings();
if (settings.get("theme") == null) {
@@ -230,6 +450,12 @@ public class Site extends GeneralProfile {
return settings;
}
/**
* 获取 {@code report}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReport() {
if (this.report == null) {
this.report = new DbObject();
@@ -238,14 +464,33 @@ public class Site extends GeneralProfile {
return this.report;
}
/**
* 设置 {@code report}。
*
* @param report 参数 {@code report}({@code DbObject})
*/
public void setReport(DbObject report) {
this.report = report;
}
/**
* 添加报表。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void addReport(String key, Object value) {
this.getReport().put(key, value);
}
/**
* 比较当前对象与另一个对象是否相等。
*
* 实现要点:包含 3 个条件分支、0 个循环。
*
* @param obj 参数 {@code obj}({@code Object})
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean equals(Object obj) {
if (obj.hashCode() == this.hashCode()) {
return true;
@@ -260,63 +505,139 @@ public class Site extends GeneralProfile {
}
}
/**
* 判断 {@code lite}。
* @return 字段/派生属性 {@code lite} 的值
*/
public boolean isLite() {
return this.getPlanName().equals("lite");
}
/**
* 判断 {@code standard}。
* @return 字段/派生属性 {@code standard} 的值
*/
public boolean isStandard() {
return this.getPlanName().equals("standard");
}
/**
* 判断 {@code standardWithBatteryPro}。
* @return 字段/派生属性 {@code standardWithBatteryPro} 的值
*/
public boolean isStandardWithBatteryPro() {
return this.getPlanName().equals("standardWithBatteryPro");
}
/**
* 判断 {@code must}。
* @return 字段/派生属性 {@code must} 的值
*/
public boolean isMust() {
return this.getModel().equals("must");
}
/**
* 设置 {@code must}。
*
* @param isMust 参数 {@code isMust}({@code boolean})
*/
public void setMust(boolean isMust) {
this.setModel("must");
}
/**
* 判断是否FeatureAllowed。
*
* @param subCategory 参数 {@code subCategory}({@code String})
* @param item 参数 {@code item}({@code String})
* @return 字段/派生属性 {@code featureAllowed} 的值
*/
public boolean isFeatureAllowed(String subCategory, String item) {
return !this.isLite() ? true : this.getProfileAsBoolean("plan", "features", subCategory, item, false);
}
/**
* 获取 {@code notificationSettings}。
* @return MongoDB 文档扩展对象
*/
public DbObject getNotificationSettings() {
return this.getSettingsCategory(new String[]{"noti"});
}
/**
* 通知Via邮件。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean notifyViaMail() {
return this.getNotificationSettings().getBoolean("sendEmail", false);
}
/**
* 设置 {@code notifyViaMail}。
*
* @param viaMail 参数 {@code viaMail}({@code boolean})
*/
public void setNotifyViaMail(boolean viaMail) {
this.getNotificationSettings().put("sendEmail", viaMail);
}
/**
* 通知设备错误邮件。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean notifyDeviceErrorMail() {
return this.getNotificationSettings().getBoolean("sendDeviceErrorEmail", false);
}
/**
* 设置 {@code notifyDeviceErrorMail}。
*
* @param enable 参数 {@code enable}({@code boolean})
*/
public void setNotifyDeviceErrorMail(boolean enable) {
this.getNotificationSettings().put("sendDeviceErrorEmail", enable);
}
/**
* 通知电池Condition邮件。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean notifyBatteryConditionMail() {
return this.getNotificationSettings().getBoolean("sendBatteryConditionEmail", false);
}
/**
* 设置 {@code notifyBatteryConditionMail}。
*
* @param enable 参数 {@code enable}({@code boolean})
*/
public void setNotifyBatteryConditionMail(boolean enable) {
this.getNotificationSettings().put("sendBatteryConditionEmail", enable);
}
/**
* 设置Notification设置列表。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param forWhat 参数 {@code forWhat}({@code String})
* @param isEnabled 参数 {@code isEnabled}({@code boolean})
*/
public void setNotificationSettings(String category, String forWhat, boolean isEnabled) {
this.setNotificationSettings(category, forWhat, isEnabled, (Set)null);
}
public void setNotificationSettings(String category, String forWhat, boolean isEnabled, Set roles) {
/**
* 设置Notification设置列表。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:remove。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param forWhat 参数 {@code forWhat}({@code String})
* @param isEnabled 参数 {@code isEnabled}({@code boolean})
* @param roles 参数 {@code roles}({@code Set<String>})
*/
public void setNotificationSettings(String category, String forWhat, boolean isEnabled, Set<String> roles) {
DbObject settings = this.getSettingsCategory(new String[]{"noti", category, forWhat});
settings.put("isEnabled", isEnabled);
if (roles == null) {
@@ -327,20 +648,45 @@ public class Site extends GeneralProfile {
}
/**
* 设置Notification设置列表。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param forWhat 参数 {@code forWhat}({@code String})
* @param key 键/配置项({@code String})
* @param value 值({@code String})
*/
public void setNotificationSettings(String category, String forWhat, String key, String value) {
DbObject settings = this.getSettingsCategory(new String[]{"noti", category, forWhat});
settings.put(key, value);
}
/**
* 获取 {@code dataUsage}。
* @return 字符串结果
*/
public String getDataUsage() {
return this.getSettingsCategory(new String[]{"report"}).getString("dataUsage", "none");
}
/**
* 处理collect数据用量。
* @return 条件成立返回 {@code true},否则返回 {@code false}
*/
public boolean collectDataUsage() {
return !this.getDataUsage().equals("none");
}
public Set getMessageRoles(String category, String forWhat) {
/**
* 获取消息Roles。
*
* 实现要点:包含 2 个条件分支、0 个循环。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param forWhat 参数 {@code forWhat}({@code String})
* @return String列表,可能为空
*/
public Set<String> getMessageRoles(String category, String forWhat) {
DbObject settings = this.getSettingsCategory(new String[]{"noti", category, forWhat});
if (settings.getBoolean("enabled")) {
Object value = settings.get("roles");
@@ -355,28 +701,53 @@ public class Site extends GeneralProfile {
}
}
/**
* 判断 {@code timeZone}。
* @return 字段/派生属性 {@code timeZone} 的值
*/
public boolean hasTimeZone() {
return this.getSetting("general", "timeZone") != null;
}
/**
* 设置 {@code timeZone}。
*
* @param timeZone 参数 {@code timeZone}({@code TimeZone})
*/
public void setTimeZone(TimeZone timeZone) {
this.setSetting("general", "timeZone", timeZone.getID());
}
/**
* 获取 {@code timeZone}。
* @return 字段/派生属性 {@code timeZone} 的值
*/
public TimeZone getTimeZone() {
Object timeZone = this.getSetting("general", "timeZone");
return timeZone != null ? TimeZone.getTimeZone((String)timeZone) : TimeZone.getDefault();
}
/**
* 获取 {@code includeApps}。
* @return 字段/派生属性 {@code includeApps} 的值
*/
public String[] getIncludeApps() {
String installApps = this.getSettingsCategory(new String[]{"report"}).getString("installApps");
return Strings.isNullOrEmpty(installApps) ? null : installApps.split("[,;\\s]+");
}
/**
* 获取 {@code callbackSetting}。
* @return MongoDB 文档扩展对象
*/
public DbObject getCallbackSetting() {
return this.getSettingsCategory(new String[]{"callback"});
}
/**
* 返回对象的可读字符串表示。
* @return 字符串结果
*/
public String toString() {
return String.format("%s(%s):%s", this.getName(), this.getIdName(), this.getUuid());
}
@@ -7,69 +7,179 @@ import java.util.UUID;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code SiteFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code category}(String):字段 category</li>
* <li>{@code forWhat}(String):用于What</li>
* <li>{@code requested}(Date):时间字段</li>
* <li>{@code expiry}(Date):时间字段</li>
* <li>{@code siteName}(String):站点名称</li>
* <li>{@code requestedFrom}(User):requested从</li>
* </ul>
*
* 协作对象:{@code User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class SiteFile extends BaseFile {
/**
* 字段 category。
*/
private String category;
/**
* 用于What。
*/
private String forWhat;
/**
* 时间字段。
*/
private Date requested;
/**
* 时间字段。
*/
private Date expiry;
/**
* 站点名称。
*/
private String siteName;
/**
* requested从;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private User requestedFrom;
/**
* 构造 {@code SiteFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public SiteFile() {
}
/**
* 构造 {@code SiteFile} 实例。
*
* @param requestedFrom 参数 {@code requestedFrom}({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public SiteFile(User requestedFrom, UUID fileUuid, McFile file) {
this.setUserUuid(requestedFrom);
this.setFileUuid(fileUuid);
this.setFileInfo(file);
}
/**
* 获取 {@code category}。
* @return 字符串结果
*/
public String getCategory() {
return this.category;
}
/**
* 设置 {@code category}。
*
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public void setCategory(String category) {
this.category = category;
}
/**
* 获取 {@code requestedFrom}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getRequestedFrom() {
return this.requestedFrom;
}
/**
* 设置 {@code requestedFrom}。
*
* @param requestedFrom 参数 {@code requestedFrom}({@code User})
*/
public void setRequestedFrom(User requestedFrom) {
this.requestedFrom = requestedFrom;
}
/**
* 获取 {@code requested}。
* @return 字段/派生属性 {@code requested} 的值
*/
public Date getRequested() {
return this.requested;
}
/**
* 设置 {@code requested}。
*
* @param requested 参数 {@code requested}({@code Date})
*/
public void setRequested(Date requested) {
this.requested = requested;
}
/**
* 获取 {@code expiry}。
* @return 字段/派生属性 {@code expiry} 的值
*/
public Date getExpiry() {
return this.expiry;
}
/**
* 设置 {@code expiry}。
*
* @param expiry 参数 {@code expiry}({@code Date})
*/
public void setExpiry(Date expiry) {
this.expiry = expiry;
}
/**
* 获取 {@code siteName}。
* @return 字符串结果
*/
public String getSiteName() {
return this.siteName;
}
/**
* 设置 {@code siteName}。
*
* @param siteName 参数 {@code siteName}({@code String})
*/
public void setSiteName(String siteName) {
this.siteName = siteName;
}
/**
* 获取 {@code forWhat}。
* @return 字符串结果
*/
public String getForWhat() {
return this.forWhat;
}
/**
* 设置 {@code forWhat}。
*
* @param forWhat 参数 {@code forWhat}({@code String})
*/
public void setForWhat(String forWhat) {
this.forWhat = forWhat;
}
+195 -2
View File
@@ -9,17 +9,72 @@ import java.util.Set;
import java.util.UUID;
import org.springframework.data.mongodb.core.index.Indexed;
/**
* 【领域模型】{@code SiteInfo}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code roles}(Set<String>):String集合</li>
* <li>{@code groupUuid}(UUID):分组UUID</li>
* <li>{@code settings}(DbObject):设置列表</li>
* <li>{@code apiOnly}(Boolean):APIOnly</li>
* <li>{@code created}(Date):创建时间</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class SiteInfo {
/**
* 用户所属站点 UUID;建有索引,常用于查询条件。
*
* 注解:{@code @Indexed}。
*/
@Indexed
private UUID siteUuid;
private Set roles;
/**
* String集合。
*/
private Set<String> roles;
/**
* 分组UUID。
*/
private UUID groupUuid;
/**
* 设置列表。
*/
protected DbObject settings;
/**
* APIOnly。
*/
private Boolean apiOnly;
/**
* 创建时间。
*/
private Date created;
/**
* 最后更新时间。
*/
private Date updated;
/**
* 是否启用。
*/
private boolean enabled;
/**
* 构造 {@code SiteInfo} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*
* 实现要点:主要调用:new HashSet、new Date。
*/
public SiteInfo() {
this.setRoles(new HashSet());
this.setCreated(new Date());
@@ -27,20 +82,40 @@ public class SiteInfo {
this.setEnabled(false);
}
/**
* 构造 {@code SiteInfo} 实例。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public SiteInfo(UUID siteUuid) {
this();
this.setSiteUuid(siteUuid);
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
public Set getRoles() {
/**
* 获取 {@code roles}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new HashSet。
* @return String列表,可能为空
*/
public Set<String> getRoles() {
if (this.roles == null) {
this.roles = new HashSet();
}
@@ -48,10 +123,24 @@ public class SiteInfo {
return this.roles;
}
/**
* 判断是否Role。
*
* @param role 参数 {@code role}({@code String})
* @return 字段/派生属性 {@code role} 的值
*/
public boolean hasRole(String role) {
return this.isEnabled() && !this.getRoles().isEmpty() && this.getRoles().contains(role);
}
/**
* 判断是否Role。
*
* 实现要点:包含 2 个条件分支、1 个循环。
*
* @param roles 参数 {@code roles}({@code Collection<String>})
* @return 字段/派生属性 {@code role} 的值
*/
public boolean hasRole(Collection<String> roles) {
if (this.isEnabled() && !this.getRoles().isEmpty()) {
for(String role : roles) {
@@ -64,6 +153,13 @@ public class SiteInfo {
return false;
}
/**
* 添加Role。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param role 参数 {@code role}({@code String})
*/
public void addRole(String role) {
role = UserRole.toRole(role);
if (!Strings.isNullOrEmpty(role)) {
@@ -72,6 +168,13 @@ public class SiteInfo {
}
/**
* 设置 {@code roles}。
*
* 实现要点:包含 3 个条件分支、1 个循环。
*
* @param roles 参数 {@code roles}({@code Set<String>})
*/
public void setRoles(Set<String> roles) {
if (roles != null && !roles.isEmpty()) {
for(String role : roles) {
@@ -91,26 +194,53 @@ public class SiteInfo {
}
/**
* 清理Roles。
*/
public void clearRoles() {
this.getRoles().clear();
}
/**
* 获取 {@code groupUuid}。
* @return UUID
*/
public UUID getGroupUuid() {
return this.groupUuid;
}
/**
* 设置 {@code groupUuid}。
*
* @param groupUuid 分组 UUID({@code UUID})
*/
public void setGroupUuid(UUID groupUuid) {
this.groupUuid = groupUuid;
}
/**
* 判断 {@code apiOnly}。
* @return 字段/派生属性 {@code apiOnly} 的值
*/
public boolean isApiOnly() {
return this.apiOnly != null && this.apiOnly;
}
/**
* 设置 {@code apiOnly}。
*
* @param apiOnly 参数 {@code apiOnly}({@code boolean})
*/
public void setApiOnly(boolean apiOnly) {
this.apiOnly = apiOnly;
}
/**
* 获取 {@code settings}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getSettings() {
if (this.settings == null) {
this.settings = new DbObject();
@@ -119,50 +249,113 @@ public class SiteInfo {
return this.settings;
}
/**
* 设置 {@code settings}。
*
* @param settings 参数 {@code settings}({@code DbObject})
*/
public void setSettings(DbObject settings) {
this.settings = settings;
}
/**
* 设置设置。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setSetting(String key, Object value) {
this.getSettings().put(key, value);
}
/**
* 获取设置。
*
* @param key 键/配置项({@code String})
* @return 字段/派生属性 {@code setting} 的值
*/
public Object getSetting(String key) {
return this.getSettings().get(key);
}
/**
* 获取设置AsString。
*
* @param key 键/配置项({@code String})
* @return 字符串结果
*/
public String getSettingAsString(String key) {
return this.getSettings().getString(key, (String)null);
}
/**
* 获取分页设置。
*
* @param url 参数 {@code url}({@code String})
* @return MongoDB 文档扩展对象
*/
public DbObject getPageSetting(String url) {
return this.getSettings().getDbObject(new String[]{"page", url});
}
/**
* 设置分页设置。
*
* @param url 参数 {@code url}({@code String})
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setPageSetting(String url, String key, Object value) {
this.getPageSetting(url).put(key, value);
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 获取 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
public Date getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code Date})
*/
public void setUpdated(Date updated) {
this.updated = updated;
}
/**
* 判断 {@code enabled}。
* @return 字段/派生属性 {@code enabled} 的值
*/
public boolean isEnabled() {
return this.enabled;
}
/**
* 设置 {@code enabled}。
*
* @param enabled 参数 {@code enabled}({@code boolean})
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
@@ -12,28 +12,110 @@ import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code SiteLicense}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code site}(Site):站点</li>
* <li>{@code childSite}(Site):子站点</li>
* <li>{@code writer}(User):字段 writer</li>
* <li>{@code licenseModel}(LicenseModel):许可证模型</li>
* <li>{@code amount}(int):字段 amount</li>
* </ul>
*
* 协作对象:{@code Site、User、LicenseModel、DbObject、STATUS}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class SiteLicense {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 站点;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private Site site;
/**
* 子站点;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private Site childSite;
/**
* 字段 writer;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private User writer;
/**
* 许可证模型;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private LicenseModel licenseModel;
/**
* 字段 amount。
*/
private int amount;
/**
* 字段 reference。
*/
private DbObject reference;
/**
* 计划。
*/
private String plan;
/**
* 报表;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private DbObject report;
/**
* 状态。
*/
private STATUS status;
/**
* 是否启用。
*/
private boolean enabled;
/**
* 最后更新时间。
*/
private Date updated;
/**
* 创建时间。
*/
private Date created;
/**
* 构造 {@code SiteLicense} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*
* 实现要点:主要调用:new Date。
*/
public SiteLicense() {
this.plan = "standard";
this.status = SiteLicense.STATUS.UNKNOWN;
@@ -42,23 +124,48 @@ public class SiteLicense {
this.setCreated(new Date());
}
/**
* 构造 {@code SiteLicense} 实例。
*
* @param site 站点/企业({@code Site})
*/
public SiteLicense(Site site) {
this();
this.setSite(site);
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code site}。
* @return 站点对象;未找到时返回 {@code null}
*/
public Site getSite() {
return this.site;
}
/**
* 设置 {@code site}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param site 站点/企业({@code Site})
*/
public void setSite(Site site) {
if (site.isChild()) {
this.site = site.getReseller();
@@ -69,42 +176,88 @@ public class SiteLicense {
}
/**
* 获取 {@code childSite}。
* @return 站点对象;未找到时返回 {@code null}
*/
public Site getChildSite() {
return this.childSite;
}
/**
* 判断 {@code forChildSite}。
* @return 字段/派生属性 {@code forChildSite} 的值
*/
public boolean isForChildSite() {
return this.childSite != null;
}
/**
* 设置 {@code childSite}。
*
* @param reseller 参数 {@code reseller}({@code Site})
*/
public void setChildSite(Site reseller) {
this.childSite = reseller;
}
/**
* 获取 {@code writer}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getWriter() {
return this.writer;
}
/**
* 设置 {@code writer}。
*
* @param user 当前用户({@code User})
*/
public void setWriter(User user) {
this.writer = user;
}
/**
* 获取 {@code plan}。
* @return 字符串结果
*/
public String getPlan() {
return this.plan;
}
/**
* 设置 {@code plan}。
*
* @param plan 参数 {@code plan}({@code String})
*/
public void setPlan(String plan) {
this.plan = plan;
}
/**
* 判断 {@code lite}。
* @return 字段/派生属性 {@code lite} 的值
*/
public boolean isLite() {
return "lite".equals(this.getPlan());
}
/**
* 获取 {@code licenseModel}。
* @return 字段/派生属性 {@code licenseModel} 的值
*/
public LicenseModel getLicenseModel() {
return this.licenseModel;
}
/**
* 设置 {@code licenseModel}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param licenseModel 参数 {@code licenseModel}({@code LicenseModel})
*/
public void setLicenseModel(LicenseModel licenseModel) {
if (this.isUpdated() && !this.licenseModel.getUuid().equals(licenseModel.getUuid())) {
this.addNote("License model changed: " + licenseModel.getName());
@@ -113,18 +266,37 @@ public class SiteLicense {
this.licenseModel = licenseModel;
}
/**
* 获取 {@code type}。
* @return 字段/派生属性 {@code type} 的值
*/
public Character getType() {
return this.licenseModel.getType();
}
/**
* 获取 {@code period}。
* @return 数量/长度
*/
public Integer getPeriod() {
return this.licenseModel.getPeriod();
}
/**
* 获取 {@code amount}。
* @return 数量/长度
*/
public int getAmount() {
return this.amount;
}
/**
* 设置 {@code amount}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param amount 参数 {@code amount}({@code int})
*/
public void setAmount(int amount) {
if (this.isUpdated() && this.amount != amount) {
this.addNote("Amount changed: " + amount);
@@ -133,6 +305,12 @@ public class SiteLicense {
this.amount = amount;
}
/**
* 获取 {@code reference}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReference() {
if (this.reference == null) {
this.reference = new DbObject();
@@ -141,14 +319,30 @@ public class SiteLicense {
return this.reference;
}
/**
* 设置 {@code reference}。
*
* @param reference 参数 {@code reference}({@code DbObject})
*/
public void setReference(DbObject reference) {
this.reference = reference;
}
/**
* 获取 {@code po}。
* @return 字符串结果
*/
public String getPo() {
return this.getReference().getString("po", "");
}
/**
* 设置 {@code po}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param po 参数 {@code po}({@code String})
*/
public void setPo(String po) {
if (this.isUpdated() && !this.getPo().equals(po)) {
this.addNote(Strings.isNullOrEmpty(po) ? "PO has unset" : "PO changed: " + po);
@@ -157,18 +351,38 @@ public class SiteLicense {
this.getReference().put("po", po);
}
/**
* 获取 {@code desc}。
* @return 字符串结果
*/
public String getDesc() {
return this.getReference().getString("desc", "");
}
/**
* 设置 {@code desc}。
*
* @param desc 参数 {@code desc}({@code String})
*/
public void setDesc(String desc) {
this.getReference().put("desc", desc);
}
public List getNotes() {
/**
* 获取 {@code notes}。
* @return 数据库Object列表,可能为空
*/
public List<DbObject> getNotes() {
return this.getReference().getList("notes", DbObject.class);
}
/**
* 添加备注。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param status 状态({@code STATUS})
*/
public void addNote(STATUS status) {
if (this.isUpdated()) {
this.addNote("Status changed: " + status);
@@ -178,6 +392,13 @@ public class SiteLicense {
}
/**
* 添加备注。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject、new ArrayList。
*
* @param note 参数 {@code note}({@code String})
*/
public void addNote(String note) {
DbObject noteObj = new DbObject("name", this.writer.getName());
noteObj.append("email", this.writer.getEmail()).append("note", note).append("updated", this.updated);
@@ -190,39 +411,81 @@ public class SiteLicense {
notes.add(noteObj);
}
/**
* 获取 {@code enabled}。
* @return 字段/派生属性 {@code enabled} 的值
*/
public boolean getEnabled() {
return this.enabled;
}
/**
* 设置 {@code enabled}。
*
* @param enabled 参数 {@code enabled}({@code boolean})
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* 获取 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
public Date getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code Date})
*/
public void setUpdated(Date updated) {
this.updated = updated;
}
/**
* 判断 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
private boolean isUpdated() {
return !this.created.equals(this.updated);
}
/**
* 处理updated。
*
* 实现要点:主要调用:new Date。
*/
public void updated() {
this.updated = new Date();
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
this.updated = created;
}
/**
* 获取 {@code report}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReport() {
if (this.report == null) {
this.report = new DbObject();
@@ -231,31 +494,74 @@ public class SiteLicense {
return this.report;
}
/**
* 设置 {@code report}。
*
* @param report 参数 {@code report}({@code DbObject})
*/
public void setReport(DbObject report) {
this.report = report;
}
/**
* 设置报表。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setReport(String key, Object value) {
this.getReport().put(key, value);
}
/**
* 判断 {@code trial}。
* @return 字段/派生属性 {@code trial} 的值
*/
public boolean isTrial() {
return this.getLicenseModel().isTrial();
}
/**
* 判断 {@code perpetual}。
* @return 字段/派生属性 {@code perpetual} 的值
*/
public boolean isPerpetual() {
return this.getLicenseModel().isPerpetual();
}
/**
* 获取 {@code status}。
* @return 字段/派生属性 {@code status} 的值
*/
public STATUS getStatus() {
return this.status;
}
/**
* 设置 {@code status}。
*
* @param status 状态({@code STATUS})
*/
public void setStatus(STATUS status) {
this.addNote(status);
this.status = status;
}
/**
* 【枚举常量】{@code STATUS}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public static enum STATUS {
ORDERED,
PROCESSING,
@@ -5,42 +5,115 @@ import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code SitePlan}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code model}(String):模型</li>
* <li>{@code plan}(DbObject):计划</li>
* <li>{@code isReseller}(boolean):判断是否Reseller</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class SitePlan {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 模型。
*/
private String model = "midm";
/**
* 计划。
*/
private DbObject plan;
/**
* 判断是否Reseller。
*/
private boolean isReseller = false;
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code model}。
* @return 字符串结果
*/
public String getModel() {
return this.model;
}
/**
* 设置 {@code model}。
*
* @param model 参数 {@code model}({@code String})
*/
public void setModel(String model) {
this.model = model;
}
/**
* 获取 {@code plan}。
* @return MongoDB 文档扩展对象
*/
public DbObject getPlan() {
return this.plan;
}
/**
* 设置 {@code plan}。
*
* @param plan 参数 {@code plan}({@code DbObject})
*/
public void setPlan(DbObject plan) {
this.plan = plan;
}
/**
* 判断 {@code reseller}。
* @return 字段/派生属性 {@code reseller} 的值
*/
public boolean isReseller() {
return this.isReseller;
}
/**
* 设置 {@code reseller}。
*
* @param isReseller 参数 {@code isReseller}({@code boolean})
*/
public void setReseller(boolean isReseller) {
this.isReseller = isReseller;
}
@@ -5,87 +5,228 @@ import java.util.UUID;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code SiteRequest}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code name}(String):名称</li>
* <li>{@code email}(String):用户邮箱(登录名,建立索引)</li>
* <li>{@code company}(String):字段 company</li>
* <li>{@code title}(String):字段 title</li>
* <li>{@code phone}(String):字段 phone</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class SiteRequest {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 名称。
*/
private String name;
/**
* 用户邮箱(登录名,建立索引)。
*/
private String email;
/**
* 字段 company。
*/
private String company;
/**
* 字段 title。
*/
private String title;
/**
* 字段 phone。
*/
private String phone;
/**
* 字段 country。
*/
private String country;
/**
* 字段 industry。
*/
private String industry;
/**
* 时间字段。
*/
private Date requestedAt;
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
return this.name;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 {@code email}。
* @return 字符串结果
*/
public String getEmail() {
return this.email;
}
/**
* 设置 {@code email}。
*
* @param email 邮箱({@code String})
*/
public void setEmail(String email) {
this.email = email;
}
/**
* 获取 {@code company}。
* @return 字符串结果
*/
public String getCompany() {
return this.company;
}
/**
* 设置 {@code company}。
*
* @param company 参数 {@code company}({@code String})
*/
public void setCompany(String company) {
this.company = company;
}
/**
* 获取 {@code title}。
* @return 字符串结果
*/
public String getTitle() {
return this.title;
}
/**
* 设置 {@code title}。
*
* @param title 参数 {@code title}({@code String})
*/
public void setTitle(String title) {
this.title = title;
}
/**
* 获取 {@code phone}。
* @return 字符串结果
*/
public String getPhone() {
return this.phone;
}
/**
* 设置 {@code phone}。
*
* @param phone 参数 {@code phone}({@code String})
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
* 获取 {@code country}。
*
* 实现要点:包含异常捕获与降级/回滚分支。
* @return 字符串结果
*/
public String getCountry() {
return this.country;
}
/**
* 设置 {@code country}。
*
* 实现要点:包含异常捕获与降级/回滚分支。
*
* @param country 参数 {@code country}({@code String})
*/
public void setCountry(String country) {
this.country = country;
}
/**
* 获取 {@code industry}。
*
* 实现要点:包含异常捕获与降级/回滚分支。
* @return 字符串结果
*/
public String getIndustry() {
return this.industry;
}
/**
* 设置 {@code industry}。
*
* 实现要点:包含异常捕获与降级/回滚分支。
*
* @param industry 参数 {@code industry}({@code String})
*/
public void setIndustry(String industry) {
this.industry = industry;
}
/**
* 获取 {@code requestedAt}。
* @return 字段/派生属性 {@code requestedAt} 的值
*/
public Date getRequestedAt() {
return this.requestedAt;
}
/**
* 设置 {@code requestedAt}。
*
* @param requestedAt 参数 {@code requestedAt}({@code Date})
*/
public void setRequestedAt(Date requestedAt) {
this.requestedAt = requestedAt;
}
@@ -1,5 +1,20 @@
package com.midm.model.org;
/**
* 【枚举常量】{@code USER_PROPERTY}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public enum USER_PROPERTY {
email,
email_addr,
@@ -21,6 +36,14 @@ public enum USER_PROPERTY {
mobile_phone,
unknown;
/**
* 处理获取。
*
* 实现要点:包含异常捕获与降级/回滚分支。
*
* @param key 键/配置项({@code String})
* @return 处理结果
*/
public static USER_PROPERTY get(String key) {
try {
return valueOf(key.trim().toLowerCase());
File diff suppressed because it is too large. Load diff
@@ -3,11 +3,50 @@ package com.midm.model.org;
import java.util.Date;
import java.util.UUID;
/**
* 【领域模型】{@code UserAccess}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code sessionId}(String):会话ID</li>
* <li>{@code userUuid}(UUID):用户UUID</li>
* <li>{@code browser}(String):字段 browser</li>
* <li>{@code os}(String):操作系统</li>
* <li>{@code device}(String):设备</li>
* <li>{@code lastAccess}(Date):最后Access</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class UserAccess {
/**
* 会话ID。
*/
private String sessionId;
/**
* 用户UUID。
*/
private UUID userUuid;
/**
* 字段 browser。
*/
private String browser;
/**
* 操作系统。
*/
private String os;
/**
* 设备。
*/
private String device;
/**
* 最后Access。
*/
private Date lastAccess;
}
@@ -4,16 +4,62 @@ import com.midm.model.GeneralProfile;
import java.util.UUID;
import org.springframework.data.annotation.Transient;
/**
* 【领域模型】{@code UserGroup}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code siteUuid}(UUID):用户所属站点 UUID</li>
* <li>{@code parentUuid}(UUID):父级UUID</li>
* <li>{@code order}(Integer):字段 order</li>
* <li>{@code userNumbers}(Long):用户Numbers</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class UserGroup extends GeneralProfile {
/**
* 用户所属站点 UUID。
*/
private UUID siteUuid;
/**
* 父级UUID。
*/
private UUID parentUuid;
/**
* 字段 order。
*/
private Integer order;
/**
* 用户Numbers;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Long userNumbers;
/**
* 构造 {@code UserGroup} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public UserGroup() {
}
/**
* 构造 {@code UserGroup} 实例。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param siteUuid 站点 UUID({@code UUID})
* @param parentGroup 参数 {@code parentGroup}({@code UserGroup})
* @param name 参数 {@code name}({@code String})
*/
public UserGroup(UUID siteUuid, UserGroup parentGroup, String name) {
this.setSiteUuid(siteUuid);
if (parentGroup != null) {
@@ -23,34 +69,70 @@ public class UserGroup extends GeneralProfile {
this.setName(name);
}
/**
* 获取 {@code siteUuid}。
* @return UUID
*/
public UUID getSiteUuid() {
return this.siteUuid;
}
/**
* 设置 {@code siteUuid}。
*
* @param siteUuid 站点 UUID({@code UUID})
*/
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
/**
* 获取 {@code parentUuid}。
* @return UUID
*/
public UUID getParentUuid() {
return this.parentUuid;
}
/**
* 设置 {@code parentUuid}。
*
* @param parentUuid 参数 {@code parentUuid}({@code UUID})
*/
public void setParentUuid(UUID parentUuid) {
this.parentUuid = parentUuid;
}
/**
* 获取 {@code order}。
* @return 数量/长度
*/
public Integer getOrder() {
return this.order;
}
/**
* 设置 {@code order}。
*
* @param order 参数 {@code order}({@code Integer})
*/
public void setOrder(Integer order) {
this.order = order;
}
/**
* 获取 {@code userNumbers}。
* @return 数量/长度
*/
public Long getUserNumbers() {
return this.userNumbers;
}
/**
* 设置 {@code userNumbers}。
*
* @param numbers 参数 {@code numbers}({@code Long})
*/
public void setUserNumbers(Long numbers) {
this.userNumbers = numbers;
}
+104 -2
View File
@@ -5,28 +5,114 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.GrantedAuthority;
/**
* 【领域模型】{@code UserRole}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code ROLES}(String):字段 ROLES</li>
* <li>{@code SYSTEM_ROLES}(String):字段 SYSTEM_ROLES</li>
* <li>{@code ROLE_SUPER_USER}(String):字段 ROLE_SUPER_USER</li>
* <li>{@code ROLE_SUPERVISOR}(String):字段 ROLE_SUPERVISOR</li>
* <li>{@code ROLE_SYSTEM_ADMIN}(String):字段 ROLE_SYSTEM_ADMIN</li>
* <li>{@code ROLE_SITE_MANAGER}(String):字段 ROLE_SITE_MANAGER</li>
* </ul>
*
* 协作对象:{@code String[]}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class UserRole {
/**
* 字段 ROLES。
*/
public static final String ROLES = "roles";
/**
* 字段 SYSTEM_ROLES。
*/
public static final String SYSTEM_ROLES = "systemRoles";
/**
* 字段 ROLE_SUPER_USER。
*/
public static final String ROLE_SUPER_USER = "SUPER_USER";
/**
* 字段 ROLE_SUPERVISOR。
*/
public static final String ROLE_SUPERVISOR = "SUPERVISOR";
/**
* 字段 ROLE_SYSTEM_ADMIN。
*/
public static final String ROLE_SYSTEM_ADMIN = "SYSTEM_ADMIN";
/**
* 字段 ROLE_SITE_MANAGER。
*/
public static final String ROLE_SITE_MANAGER = "SITE_MANAGER";
/**
* 字段 ROLE_SALES。
*/
public static final String ROLE_SALES = "SALES";
/**
* 字段 ROLE_RESELLER。
*/
public static final String ROLE_RESELLER = "RESELLER";
/**
* 字段 ROLE_FINANCE。
*/
public static final String ROLE_FINANCE = "FINANCE";
/**
* 字段 ROLE_USER。
*/
public static final String ROLE_USER = "USER";
/**
* 字段 ROLE_USER_MANAGER。
*/
public static final String ROLE_USER_MANAGER = "USER_MANAGER";
/**
* 字段 ROLE_DEVICE_MANAGER。
*/
public static final String ROLE_DEVICE_MANAGER = "DEVICE_MANAGER";
/**
* 字段 ROLE_PROFILE_MANAGER。
*/
public static final String ROLE_PROFILE_MANAGER = "PROFILE_MANAGER";
/**
* 字段 ROLE_DEVIE_OWNER。
*/
public static final String ROLE_DEVIE_OWNER = "DEVICE_OWNER";
/**
* 字段 ROLE_GUEST。
*/
public static final String ROLE_GUEST = "ROLE_GUEST";
/**
* 字段 USER_MANAGE_ROLES。
*/
public static final String[] USER_MANAGE_ROLES = new String[]{"SUPERVISOR", "USER_MANAGER"};
/**
* 字段 DEVICE_MANAGE_ROLES。
*/
public static final String[] DEVICE_MANAGE_ROLES = new String[]{"SUPERVISOR", "DEVICE_MANAGER"};
/**
* 字段 PROFILE_MANAGE_ROLES。
*/
public static final String[] PROFILE_MANAGE_ROLES = new String[]{"SUPERVISOR", "PROFILE_MANAGER"};
public static List getAuthorities(final String role) {
/**
* 获取Authorities。
*
* 实现要点:主要调用:new ArrayList、new SimpleGrantedAuthority。
*
* @param role 参数 {@code role}({@code String})
* @return GrantedAuthority列表,可能为空
*/
public static List<GrantedAuthority> getAuthorities(final String role) {
return new ArrayList() {
{
this.add(new SimpleGrantedAuthority(role));
@@ -34,7 +120,15 @@ public class UserRole {
};
}
public static List getAuthorities(final Set roles) {
/**
* 获取Authorities。
*
* 实现要点:包含 1 个条件分支、1 个循环;主要调用:new ArrayList、new SimpleGrantedAuthority。
*
* @param roles 参数 {@code roles}({@code Set<String>})
* @return GrantedAuthority列表,可能为空
*/
public static List<GrantedAuthority> getAuthorities(final Set<String> roles) {
return new ArrayList() {
{
if (roles != null && !roles.isEmpty()) {
@@ -49,6 +143,14 @@ public class UserRole {
};
}
/**
* 处理转换为Role。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param role 参数 {@code role}({@code String})
* @return 字符串结果
*/
public static String toRole(String role) {
if (Strings.isNullOrEmpty(role)) {
return null;
+206 -2
View File
@@ -14,43 +14,135 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code UserToken}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code TOKEN_CONFIRMATION}(char):字段 TOKEN_CONFIRMATION</li>
* <li>{@code TOKEN_ACTIVATION}(char):字段 TOKEN_ACTIVATION</li>
* <li>{@code TOKEN_LOGIN}(char):字段 TOKEN_LOGIN</li>
* <li>{@code TOKEN_REMEMBER_LOGIN}(char):字段 TOKEN_REMEMBER_LOGIN</li>
* <li>{@code TOKEN_RESET_PASSWORD}(char):字段 TOKEN_RESET_PASSWORD</li>
* <li>{@code TOKEN_MFA_AUTH}(char):字段 TOKEN_MFA_AUTH</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class UserToken implements Serializable {
/**
* 字段 TOKEN_CONFIRMATION。
*/
public static final char TOKEN_CONFIRMATION = 'C';
/**
* 字段 TOKEN_ACTIVATION。
*/
public static final char TOKEN_ACTIVATION = 'A';
/**
* 字段 TOKEN_LOGIN。
*/
public static final char TOKEN_LOGIN = 'L';
/**
* 字段 TOKEN_REMEMBER_LOGIN。
*/
public static final char TOKEN_REMEMBER_LOGIN = 'R';
/**
* 字段 TOKEN_RESET_PASSWORD。
*/
public static final char TOKEN_RESET_PASSWORD = 'P';
/**
* 字段 TOKEN_MFA_AUTH。
*/
public static final char TOKEN_MFA_AUTH = 'M';
/**
* 字段 TOKEN_DEVICE_ACCESS。
*/
public static final char TOKEN_DEVICE_ACCESS = 'D';
/**
* 令牌UUID;MongoDB 主键;Gson 序列化控制。
*
* 注解:{@code @Id @Expose(serialize = false)}。
*/
@Id
@Expose(
serialize = false
)
private UUID tokenUuid;
/**
* access令牌;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private String accessToken;
/**
* 用户UUID;Gson 序列化控制。
*
* 注解:{@code @Expose(serialize = false)}。
*/
@Expose(
serialize = false
)
private UUID userUuid;
/**
* 令牌类型;Gson 序列化控制。
*
* 注解:{@code @Expose(serialize = false)}。
*/
@Expose(
serialize = false
)
private char tokenType;
/**
* 创建时间;Gson 序列化控制。
*
* 注解:{@code @Expose(serialize = false)}。
*/
@Expose(
serialize = false
)
private Date created;
/**
* 时间字段;Gson 序列化控制。
*
* 注解:{@code @Expose(serialize = false)}。
*/
@Expose(
serialize = false
)
private Date expired;
/**
* 字段 reference。
*/
private DbObject reference;
/**
* 构造 {@code UserToken} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public UserToken() {
}
/**
* 构造 {@code UserToken} 实例。
*
* 实现要点:主要调用:new Date、new DateTime。
*
* @param user 当前用户({@code User})
* @param tokenType 参数 {@code tokenType}({@code char})
* @param validPeriod 参数 {@code validPeriod}({@code long})
*/
public UserToken(User user, char tokenType, long validPeriod) {
this.tokenUuid = UUID.randomUUID();
this.userUuid = user.getUuid();
@@ -60,6 +152,11 @@ public class UserToken implements Serializable {
this.expired = date.plus(validPeriod).toDate();
}
/**
* 处理renew。
*
* 实现要点:主要调用:new Date、new DateTime。
*/
public void renew() {
this.tokenUuid = UUID.randomUUID();
this.encryptToken();
@@ -69,10 +166,19 @@ public class UserToken implements Serializable {
this.expired = date.plus(validPeriod).toDate();
}
/**
* 加密令牌。
*/
public void encryptToken() {
this.accessToken = McUuidUtils.toBase64String(this.tokenUuid);
}
/**
* 获取 {@code accessToken}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字符串结果
*/
public String getAccessToken() {
if (Strings.isNullOrEmpty(this.accessToken)) {
this.encryptToken();
@@ -81,38 +187,81 @@ public class UserToken implements Serializable {
return this.accessToken;
}
/**
* 获取 {@code tokenUuid}。
* @return UUID
*/
public UUID getTokenUuid() {
return this.tokenUuid;
}
/**
* 设置 {@code tokenUuid}。
*
* @param uid 参数 {@code uid}({@code UUID})
*/
public void setTokenUuid(UUID uid) {
this.tokenUuid = uid;
}
/**
* 获取 {@code userUuid}。
* @return UUID
*/
public UUID getUserUuid() {
return this.userUuid;
}
/**
* 设置 {@code userUuid}。
*
* @param userUuid 用户 UUID({@code UUID})
*/
public void setUserUuid(UUID userUuid) {
this.userUuid = userUuid;
}
/**
* 获取 {@code tokenType}。
* @return 字段/派生属性 {@code tokenType} 的值
*/
public char getTokenType() {
return this.tokenType;
}
/**
* 设置 {@code tokenType}。
*
* @param tokenType 参数 {@code tokenType}({@code char})
*/
public void setTokenType(char tokenType) {
this.tokenType = tokenType;
}
/**
* 获取Mfa令牌。
*
* @param length 参数 {@code length}({@code int})
* @return 字符串结果
*/
public String getMfaToken(int length) {
return this.getMfaToken().substring(0, length);
}
/**
* 获取 {@code mfaToken}。
* @return 字符串结果
*/
public String getMfaToken() {
return String.valueOf(this.tokenUuid.getMostSignificantBits() * this.tokenUuid.getLeastSignificantBits());
}
/**
* 获取 {@code reference}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReference() {
if (this.reference == null) {
this.reference = new DbObject();
@@ -121,10 +270,23 @@ public class UserToken implements Serializable {
return this.reference;
}
/**
* 设置 {@code reference}。
*
* @param reference 参数 {@code reference}({@code DbObject})
*/
public void setReference(DbObject reference) {
this.reference = reference;
}
/**
* 设置Reference。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setReference(String key, Object value) {
if (value == null) {
this.getReference().remove(key);
@@ -134,38 +296,80 @@ public class UserToken implements Serializable {
}
/**
* 获取 {@code deviceUuid}。
* @return UUID
*/
public UUID getDeviceUuid() {
return this.getReference().getUuid("deviceUuid");
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param registered 参数 {@code registered}({@code Date})
*/
public void setCreated(Date registered) {
this.created = registered;
}
/**
* 获取 {@code expired}。
* @return 字段/派生属性 {@code expired} 的值
*/
public Date getExpired() {
return this.expired;
}
/**
* 设置 {@code expired}。
*
* @param expired 参数 {@code expired}({@code Date})
*/
public void setExpired(Date expired) {
this.expired = expired;
}
/**
* 处理plusExpired。
*
* 实现要点:主要调用:new DateTime。
*
* @param time 参数 {@code time}({@code long})
*/
public void plusExpired(long time) {
DateTime expiredDate = new DateTime(this.getExpired());
expiredDate.plus(time);
}
/**
* 判断 {@code expired}。
*
* 实现要点:主要调用:new Date。
* @return 字段/派生属性 {@code expired} 的值
*/
public boolean isExpired() {
return this.getExpired().getTime() < (new Date()).getTime();
}
/**
* 处理转换为设备Access。
*
* 实现要点:主要调用:new DbObject。
*
* @param request HTTP 请求({@code HttpServletRequest})
* @return MongoDB 文档扩展对象
*/
public DbObject toDeviceAccess(HttpServletRequest request) {
String var10000 = McUrlUtils.getHostUrl(request);
String accessUrl = var10000 + "/device/" + McUuidUtils.toBase64String(this.tokenUuid, true);
String accessUrl = McUrlUtils.getHostUrl(request) + "/device/" + McUuidUtils.toBase64String(this.tokenUuid, true);
DbObject deviceAccess = new DbObject("accessUrl", accessUrl);
deviceAccess.append("expiry", this.getExpired());
return deviceAccess;
@@ -0,0 +1,23 @@
/**
* 组织架构模型:站点、用户、用户组、License、令牌。
*
* <p>本包主要类型:
* <ul>
* <li>{@link Site}</li>
* <li>{@link SiteFile}</li>
* <li>{@link SiteInfo}</li>
* <li>{@link SiteLicense}</li>
* <li>{@link SitePlan}</li>
* <li>{@link SiteRequest}</li>
* <li>{@link USER_PROPERTY}</li>
* <li>{@link User}</li>
* <li>{@link UserAccess}</li>
* <li>{@link UserGroup}</li>
* <li>{@link UserRole}</li>
* <li>{@link UserToken}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.org;
@@ -0,0 +1,14 @@
/**
* 领域模型根包:所有 MongoDB 文档/值对象的公共基类与通用模型。
*
* <p>本包主要类型:
* <ul>
* <li>{@link GeneralProfile}</li>
* <li>{@link GroupByResult}</li>
* <li>{@link IF_EXISTS_OPTION}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model;
@@ -5,79 +5,217 @@ import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code AppReleaseNote}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code noteId}(NoteId):备注ID</li>
* <li>{@code versionName}(String):版本名称</li>
* <li>{@code minSdkVersion}(int):minSDK版本</li>
* <li>{@code files}(List<StoreAppFile>):文件列表</li>
* </ul>
*
* 协作对象:{@code NoteId}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class AppReleaseNote extends ReleaseNote {
/**
* 备注ID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private NoteId noteId;
/**
* 版本名称。
*/
private String versionName;
/**
* minSDK版本。
*/
private int minSdkVersion;
private List files;
/**
* 文件列表。
*/
private List<StoreAppFile> files;
/**
* 构造 {@code AppReleaseNote} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public AppReleaseNote() {
}
/**
* 构造 {@code AppReleaseNote} 实例。
*
* 实现要点:主要调用:new NoteId。
*
* @param packageName 参数 {@code packageName}({@code String})
* @param versionCode 参数 {@code versionCode}({@code int})
* @param versionName 参数 {@code versionName}({@code String})
* @param minSdkVersion 参数 {@code minSdkVersion}({@code int})
*/
public AppReleaseNote(String packageName, int versionCode, String versionName, int minSdkVersion) {
this.noteId = new NoteId(packageName, versionCode);
this.versionName = versionName;
this.setMinSdkVersion(minSdkVersion);
}
/**
* 构造 {@code AppReleaseNote} 实例。
*
* @param appFile 参数 {@code appFile}({@code StoreAppFile})
*/
public AppReleaseNote(StoreAppFile appFile) {
this(appFile.getPackageName(), (int)appFile.getVersionCode(), appFile.getVersionName(), appFile.getMinSdkVersion());
}
/**
* 获取 {@code versionCode}。
* @return 数量/长度
*/
public int getVersionCode() {
return this.noteId.getVersionCode();
}
/**
* 获取 {@code versionName}。
* @return 字符串结果
*/
public String getVersionName() {
return this.versionName;
}
/**
* 设置 {@code versionName}。
*
* @param versionName 参数 {@code versionName}({@code String})
*/
public void setVersionName(String versionName) {
this.versionName = versionName;
}
public List getFiles() {
/**
* 获取 {@code files}。
* @return Store应用文件列表,可能为空
*/
public List<StoreAppFile> getFiles() {
return this.files;
}
public void setFiles(List files) {
/**
* 设置 {@code files}。
*
* @param files 参数 {@code files}({@code List<StoreAppFile>})
*/
public void setFiles(List<StoreAppFile> files) {
this.files = files;
}
/**
* 获取 {@code minSdkVersion}。
* @return 数量/长度
*/
public int getMinSdkVersion() {
return this.minSdkVersion;
}
/**
* 设置 {@code minSdkVersion}。
*
* @param minSdkVersion 参数 {@code minSdkVersion}({@code int})
*/
public void setMinSdkVersion(int minSdkVersion) {
this.minSdkVersion = minSdkVersion;
}
/**
* 【领域模型】{@code NoteId}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code packageName}(String):package名称</li>
* <li>{@code versionCode}(int):版本代码</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public static class NoteId implements Serializable {
/**
* package名称。
*/
private String packageName;
/**
* 版本代码。
*/
private int versionCode;
/**
* 构造 {@code NoteId} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public NoteId() {
}
/**
* 构造 {@code NoteId} 实例。
*
* @param packageName 参数 {@code packageName}({@code String})
* @param versionCode 参数 {@code versionCode}({@code int})
*/
public NoteId(String packageName, int versionCode) {
this.packageName = packageName;
this.versionCode = versionCode;
}
/**
* 获取 {@code appUuid}。
* @return 字符串结果
*/
public String getAppUuid() {
return this.packageName;
}
/**
* 设置 {@code appUuid}。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public void setAppUuid(String packageName) {
this.packageName = packageName;
}
/**
* 获取 {@code versionCode}。
* @return 数量/长度
*/
public int getVersionCode() {
return this.versionCode;
}
/**
* 设置 {@code versionCode}。
*
* @param versionCode 参数 {@code versionCode}({@code int})
*/
public void setVersionCode(int versionCode) {
this.versionCode = versionCode;
}
@@ -9,64 +9,168 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code KeyStore}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code id}(String):ID</li>
* <li>{@code description}(String):字段 description</li>
* <li>{@code alias}(String):字段 alias</li>
* <li>{@code keyPassword}(String):密钥Password</li>
* <li>{@code storePassword}(String):字段 storePassword</li>
* <li>{@code certMd5}(String):证书Md5</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class KeyStore {
/**
* ID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String id;
/**
* 字段 description。
*/
private String description;
/**
* 字段 alias。
*/
private String alias;
/**
* 密钥Password。
*/
private String keyPassword;
/**
* 字段 storePassword。
*/
private String storePassword;
/**
* 证书Md5。
*/
private String certMd5;
/**
* 获取 {@code id}。
* @return 字符串结果
*/
public String getId() {
return this.id;
}
/**
* 设置 {@code id}。
*
* @param id 参数 {@code id}({@code String})
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取 {@code description}。
* @return 字符串结果
*/
public String getDescription() {
return this.description;
}
/**
* 设置 {@code description}。
*
* @param description 参数 {@code description}({@code String})
*/
public void setDescription(String description) {
this.description = description;
}
/**
* 获取 {@code alias}。
* @return 字符串结果
*/
public String getAlias() {
return this.alias;
}
/**
* 设置 {@code alias}。
*
* @param alias 参数 {@code alias}({@code String})
*/
public void setAlias(String alias) {
this.alias = alias;
}
/**
* 获取 {@code keyPassword}。
* @return 字符串结果
*/
public String getKeyPassword() {
return this.keyPassword;
}
/**
* 设置 {@code keyPassword}。
*
* @param keyPassword 参数 {@code keyPassword}({@code String})
*/
public void setKeyPassword(String keyPassword) {
this.keyPassword = keyPassword;
}
/**
* 获取 {@code storePassword}。
* @return 字符串结果
*/
public String getStorePassword() {
return this.storePassword;
}
/**
* 设置 {@code storePassword}。
*
* @param storePassword 参数 {@code storePassword}({@code String})
*/
public void setStorePassword(String storePassword) {
this.storePassword = storePassword;
}
/**
* 获取 {@code certMd5}。
* @return 字符串结果
*/
public String getCertMd5() {
return this.certMd5;
}
/**
* 设置 {@code certMd5}。
*
* @param certMd5 参数 {@code certMd5}({@code String})
*/
public void setCertMd5(String certMd5) {
this.certMd5 = certMd5;
}
/**
* 设置 {@code certMd5}。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 1 个条件分支、0 个循环。
*
* @param storeFile 参数 {@code storeFile}({@code McFile})
*/
public void setCertMd5(McFile storeFile) {
try {
InputStream input = storeFile.getInputStream();
@@ -3,56 +3,162 @@ package com.midm.model.store;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code OtaReleaseNote}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code noteId}(NoteId):备注ID</li>
* <li>{@code displayId}(String):displayID</li>
* </ul>
*
* 协作对象:{@code NoteId}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class OtaReleaseNote extends ReleaseNote {
/**
* 备注ID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private NoteId noteId;
/**
* displayID。
*/
private String displayId;
/**
* 构造 {@code OtaReleaseNote} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public OtaReleaseNote() {
}
/**
* 构造 {@code OtaReleaseNote} 实例。
*
* 实现要点:主要调用:new NoteId。
*
* @param productId 参数 {@code productId}({@code String})
* @param buildDate 参数 {@code buildDate}({@code long})
*/
public OtaReleaseNote(String productId, long buildDate) {
this.noteId = new NoteId(productId, buildDate);
}
/**
* 构造 {@code OtaReleaseNote} 实例。
*
* @param otaFile 参数 {@code otaFile}({@code StoreOtaFile})
*/
public OtaReleaseNote(StoreOtaFile otaFile) {
this(otaFile.getProductId(), otaFile.getBuildDate());
this.setDisplayId(otaFile.getDisplayId());
}
/**
* 获取 {@code displayId}。
* @return 字符串结果
*/
public String getDisplayId() {
return this.displayId;
}
/**
* 设置 {@code displayId}。
*
* @param versionName 参数 {@code versionName}({@code String})
*/
public void setDisplayId(String versionName) {
this.displayId = versionName;
}
/**
* 【领域模型】{@code NoteId}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code productId}(String):productID</li>
* <li>{@code buildDate}(long):构建日期</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class NoteId {
/**
* productID。
*/
private String productId;
/**
* 构建日期。
*/
private long buildDate;
/**
* 构造 {@code NoteId} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public NoteId() {
}
/**
* 构造 {@code NoteId} 实例。
*
* @param productId 参数 {@code productId}({@code String})
* @param buildDate 参数 {@code buildDate}({@code long})
*/
public NoteId(String productId, long buildDate) {
this.productId = productId;
this.buildDate = buildDate;
}
/**
* 获取 {@code productId}。
* @return 字符串结果
*/
public String getProductId() {
return this.productId;
}
/**
* 设置 {@code productId}。
*
* @param productId 参数 {@code productId}({@code String})
*/
public void setProductId(String productId) {
this.productId = productId;
}
/**
* 获取 {@code buildDate}。
* @return 数量/长度
*/
public long getBuildDate() {
return this.buildDate;
}
/**
* 设置 {@code buildDate}。
*
* @param buildDate 参数 {@code buildDate}({@code long})
*/
public void setBuildDate(long buildDate) {
this.buildDate = buildDate;
}
@@ -2,48 +2,125 @@ package com.midm.model.store;
import java.util.Date;
/**
* 【领域模型】{@code ReleaseNote}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code note}(String[]):备注</li>
* <li>{@code noteNewFunction}(String[]):备注新Function</li>
* <li>{@code isFormal}(Boolean):判断是否Formal</li>
* <li>{@code releasedAt}(Date):时间字段</li>
* </ul>
*
* 协作对象:{@code String[]}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class ReleaseNote {
/**
* 备注。
*/
private String[] note;
/**
* 备注新Function。
*/
private String[] noteNewFunction;
/**
* 判断是否Formal。
*/
private Boolean isFormal;
/**
* 时间字段。
*/
private Date releasedAt = new Date();
/**
* 获取 {@code releasedAt}。
* @return 字段/派生属性 {@code releasedAt} 的值
*/
public Date getReleasedAt() {
return this.releasedAt;
}
/**
* 设置 {@code releasedAt}。
*
* @param releasedAt 参数 {@code releasedAt}({@code Date})
*/
public void setReleasedAt(Date releasedAt) {
this.releasedAt = releasedAt;
}
/**
* 判断 {@code note}。
* @return 字段/派生属性 {@code note} 的值
*/
public boolean hasNote() {
return this.note != null && this.note.length > 0;
}
/**
* 判断 {@code noteNewFunction}。
* @return 字段/派生属性 {@code noteNewFunction} 的值
*/
public boolean hasNoteNewFunction() {
return this.noteNewFunction != null && this.noteNewFunction.length > 0;
}
/**
* 获取 {@code note}。
* @return 字段/派生属性 {@code note} 的值
*/
public String[] getNote() {
return this.note;
}
/**
* 设置 {@code notes}。
*
* @param note 参数 {@code note}({@code String[]})
*/
public void setNotes(String[] note) {
this.note = note;
}
/**
* 获取 {@code noteNewFunction}。
* @return 字段/派生属性 {@code noteNewFunction} 的值
*/
public String[] getNoteNewFunction() {
return this.noteNewFunction;
}
/**
* 设置 {@code noteNewFunctions}。
*
* @param noteNewFunction 参数 {@code noteNewFunction}({@code String[]})
*/
public void setNoteNewFunctions(String[] noteNewFunction) {
this.noteNewFunction = noteNewFunction;
}
/**
* 判断 {@code formal}。
* @return 字段/派生属性 {@code formal} 的值
*/
public Boolean isFormal() {
return this.isFormal;
}
/**
* 设置 {@code isFormal}。
*
* @param isFormal 参数 {@code isFormal}({@code Boolean})
*/
public void setIsFormal(Boolean isFormal) {
this.isFormal = isFormal;
}
@@ -1,6 +1,7 @@
package com.midm.model.store;
import com.mitac.cell.db.DbObject;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -8,35 +9,103 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StoreApp}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code packageName}(String):package名称</li>
* <li>{@code isFormal}(Boolean):判断是否Formal</li>
* <li>{@code appInfo}(DbObject):应用信息</li>
* <li>{@code sdkVersions}(Set<Integer>):SDKVersions</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StoreApp extends StoreBase {
/**
* package名称;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String packageName;
/**
* 判断是否Formal。
*/
private Boolean isFormal;
/**
* 应用信息。
*/
private DbObject appInfo;
/**
* SDKVersions;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Set sdkVersions;
private Set<Integer> sdkVersions;
/**
* 构造 {@code StoreApp} 实例。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public StoreApp(String packageName) {
this.packageName = packageName;
}
/**
* 判断 {@code formal}。
* @return 字段/派生属性 {@code formal} 的值
*/
public Boolean isFormal() {
return this.isFormal;
}
/**
* 设置 {@code isFormal}。
*
* @param isFormal 参数 {@code isFormal}({@code Boolean})
*/
public void setIsFormal(Boolean isFormal) {
this.isFormal = isFormal;
}
/**
* 获取 {@code packageName}。
* @return 字符串结果
*/
public String getPackageName() {
return this.packageName;
}
/**
* 设置 {@code packageName}。
*
* @param packageName 参数 {@code packageName}({@code String})
*/
public void setPackageName(String packageName) {
this.packageName = packageName;
}
/**
* 获取 {@code appInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getAppInfo() {
if (this.appInfo == null) {
this.appInfo = new DbObject();
@@ -45,26 +114,53 @@ public class StoreApp extends StoreBase {
return this.appInfo;
}
/**
* 设置 {@code appInfo}。
*
* @param appInfo 参数 {@code appInfo}({@code DbObject})
*/
public void setAppInfo(DbObject appInfo) {
this.appInfo = appInfo;
}
/**
* 设置应用信息。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setAppInfo(String key, Object value) {
this.getAppInfo().append(key, value);
}
public Set getSdkVersions() {
/**
* 获取 {@code sdkVersions}。
* @return Integer列表,可能为空
*/
public Set<Integer> getSdkVersions() {
return this.sdkVersions;
}
public void setSdkVersions(Set sdkVersions) {
/**
* 设置 {@code sdkVersions}。
*
* @param sdkVersions 参数 {@code sdkVersions}({@code Set<Integer>})
*/
public void setSdkVersions(Set<Integer> sdkVersions) {
this.sdkVersions = sdkVersions;
}
public void setSdkVersions(List sdkVersions) {
/**
* 设置 {@code sdkVersions}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new HashSet。
*
* @param sdkVersions 参数 {@code sdkVersions}({@code List<?>})
*/
public void setSdkVersions(List<?> sdkVersions) {
if (sdkVersions != null) {
this.sdkVersions = new HashSet();
this.sdkVersions.addAll(sdkVersions);
this.sdkVersions.addAll((Collection)sdkVersions);
} else {
this.sdkVersions = null;
}
@@ -6,11 +6,35 @@ import com.mitac.cell.io.McFile;
import java.util.UUID;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StoreAppFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StoreAppFile extends AppFile {
/**
* 构造 {@code StoreAppFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public StoreAppFile() {
}
/**
* 构造 {@code StoreAppFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
* @param generateIcon 参数 {@code generateIcon}({@code boolean})
*/
public StoreAppFile(User user, UUID fileUuid, McFile file, boolean generateIcon) {
super(user, fileUuid, file, generateIcon);
}
@@ -4,18 +4,66 @@ import com.midm.constant.LocaleConst;
import com.mitac.cell.db.DbObject;
import java.util.Date;
/**
* 【领域模型】{@code StoreBase}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code title}(DbObject):字段 title</li>
* <li>{@code summary}(DbObject):字段 summary</li>
* <li>{@code desc}(DbObject):字段 desc</li>
* <li>{@code createdAt}(Date):时间字段</li>
* <li>{@code lastUpdated}(Date):最后Updated</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class StoreBase {
/**
* 字段 title。
*/
private DbObject title;
/**
* 字段 summary。
*/
private DbObject summary;
/**
* 字段 desc。
*/
private DbObject desc;
/**
* 时间字段。
*/
private Date createdAt = new Date();
/**
* 最后Updated。
*/
private Date lastUpdated = new Date();
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.createdAt = new Date();
this.lastUpdated = new Date();
}
/**
* 获取 {@code title}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getTitle() {
if (this.title == null) {
this.title = new DbObject();
@@ -24,18 +72,40 @@ public class StoreBase {
return this.title;
}
/**
* 设置 {@code title}。
*
* @param title 参数 {@code title}({@code DbObject})
*/
public void setTitle(DbObject title) {
this.title = title;
}
/**
* 设置Title。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setTitle(String key, Object value) {
this.getTitle().append(key, value);
}
/**
* 设置 {@code title}。
*
* @param title 参数 {@code title}({@code String})
*/
public void setTitle(String title) {
this.setTitle(LocaleConst.DEFAULT_LOCALE.toLanguageTag(), title);
}
/**
* 获取 {@code summary}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getSummary() {
if (this.summary == null) {
this.summary = new DbObject();
@@ -44,14 +114,31 @@ public class StoreBase {
return this.summary;
}
/**
* 设置 {@code summary}。
*
* @param summary 参数 {@code summary}({@code DbObject})
*/
public void setSummary(DbObject summary) {
this.summary = summary;
}
/**
* 设置Summary。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setSummary(String key, Object value) {
this.getSummary().append(key, value);
}
/**
* 获取 {@code desc}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getDesc() {
if (this.desc == null) {
this.desc = new DbObject();
@@ -60,26 +147,55 @@ public class StoreBase {
return this.desc;
}
/**
* 设置 {@code description}。
*
* @param desc 参数 {@code desc}({@code DbObject})
*/
public void setDescription(DbObject desc) {
this.desc = desc;
}
/**
* 设置Description。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setDescription(String key, Object value) {
this.getDesc().append(key, value);
}
/**
* 获取 {@code createdAt}。
* @return 字段/派生属性 {@code createdAt} 的值
*/
public Date getCreatedAt() {
return this.createdAt;
}
/**
* 设置 {@code createdAt}。
*
* @param createdAt 参数 {@code createdAt}({@code Date})
*/
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
/**
* 获取 {@code lastUpdated}。
* @return 字段/派生属性 {@code lastUpdated} 的值
*/
public Date getLastUpdated() {
return this.lastUpdated;
}
/**
* 设置 {@code lastUpdated}。
*
* @param lastUpdated 参数 {@code lastUpdated}({@code Date})
*/
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
@@ -5,66 +5,172 @@ import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StoreOta}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code productId}(String):productID</li>
* <li>{@code deviceId}(String):设备ID</li>
* <li>{@code otaInfo}(DbObject):OTA 固件信息</li>
* <li>{@code isFormal}(Boolean):判断是否Formal</li>
* <li>{@code createdAt}(Date):时间字段</li>
* <li>{@code lastUpdated}(Date):最后Updated</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StoreOta {
/**
* productID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String productId;
/**
* 设备ID。
*/
private String deviceId;
/**
* OTA 固件信息。
*/
private DbObject otaInfo;
/**
* 判断是否Formal。
*/
private Boolean isFormal;
/**
* 时间字段。
*/
private Date createdAt;
/**
* 最后Updated。
*/
private Date lastUpdated;
/**
* 构造 {@code StoreOta} 实例。
*
* 实现要点:主要调用:new Date。
*
* @param productId 参数 {@code productId}({@code String})
*/
public StoreOta(String productId) {
this.productId = productId;
this.createdAt = new Date();
this.lastUpdated = new Date();
}
/**
* 判断 {@code formal}。
* @return 字段/派生属性 {@code formal} 的值
*/
Boolean isFormal() {
return this.isFormal;
}
/**
* 设置 {@code isFormal}。
*
* @param isFormal 参数 {@code isFormal}({@code Boolean})
*/
public void setIsFormal(Boolean isFormal) {
this.isFormal = isFormal;
}
/**
* 获取 {@code productId}。
* @return 字符串结果
*/
public String getProductId() {
return this.productId;
}
/**
* 设置 {@code productId}。
*
* @param productId 参数 {@code productId}({@code String})
*/
public void setProductId(String productId) {
this.productId = productId;
}
/**
* 获取 {@code deviceId}。
* @return 字符串结果
*/
public String getDeviceId() {
return this.deviceId;
}
/**
* 设置 {@code deviceId}。
*
* @param deviceId 参数 {@code deviceId}({@code String})
*/
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
/**
* 获取 {@code createdAt}。
* @return 字段/派生属性 {@code createdAt} 的值
*/
public Date getCreatedAt() {
return this.createdAt;
}
/**
* 设置 {@code createdAt}。
*
* @param createdAt 参数 {@code createdAt}({@code Date})
*/
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
/**
* 获取 {@code lastUpdated}。
* @return 字段/派生属性 {@code lastUpdated} 的值
*/
public Date getLastUpdated() {
return this.lastUpdated;
}
/**
* 设置 {@code lastUpdated}。
*
* @param lastUpdated 参数 {@code lastUpdated}({@code Date})
*/
public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
}
/**
* 获取 {@code otaInfo}。
* @return MongoDB 文档扩展对象
*/
public DbObject getOtaInfo() {
return this.otaInfo;
}
/**
* 设置 {@code otaInfo}。
*
* @param otaInfo 参数 {@code otaInfo}({@code DbObject})
*/
public void setOtaInfo(DbObject otaInfo) {
this.otaInfo = otaInfo;
}
@@ -6,21 +6,64 @@ import com.mitac.cell.io.McFile;
import java.util.UUID;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StoreOtaFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code note}(String[]):备注</li>
* </ul>
*
* 协作对象:{@code String[]}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StoreOtaFile extends OtaFile {
/**
* 备注。
*/
private String[] note;
/**
* 构造 {@code StoreOtaFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public StoreOtaFile() {
}
/**
* 构造 {@code StoreOtaFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public StoreOtaFile(User user, UUID fileUuid, McFile file) {
super(user, fileUuid, file);
}
/**
* 获取 {@code note}。
* @return 字段/派生属性 {@code note} 的值
*/
public String[] getNote() {
return this.note;
}
/**
* 设置 {@code notes}。
*
* @param note 参数 {@code note}({@code String[]})
*/
public void setNotes(String[] note) {
this.note = note;
}
@@ -6,21 +6,62 @@ import com.mitac.cell.io.McFile;
import java.util.UUID;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StoreOtherFile}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code alias}(String):字段 alias</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StoreOtherFile extends BaseFile {
/**
* 字段 alias。
*/
private String alias;
/**
* 构造 {@code StoreOtherFile} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public StoreOtherFile() {
}
/**
* 构造 {@code StoreOtherFile} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public StoreOtherFile(User user, UUID fileUuid, McFile file) {
super(user, fileUuid, file);
}
/**
* 获取 {@code alias}。
* @return 字符串结果
*/
public String getAlias() {
return this.alias;
}
/**
* 设置 {@code alias}。
*
* @param alias 参数 {@code alias}({@code String})
*/
public void setAlias(String alias) {
this.alias = alias;
}
@@ -17,34 +17,100 @@ import java.util.zip.ZipEntry;
import org.joda.time.DateTime;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StoreWebApp}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code appInfo}(DbObject):应用信息</li>
* <li>{@code isFormal}(Boolean):判断是否Formal</li>
* <li>{@code releaseNote}(List<String>):release备注</li>
* <li>{@code releaseNoteNewFunction}(List<String>):release备注新Function</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StoreWebApp extends BaseFile {
/**
* 应用信息。
*/
private DbObject appInfo;
/**
* 判断是否Formal。
*/
private Boolean isFormal;
private List releaseNote;
private List releaseNoteNewFunction;
/**
* release备注。
*/
private List<String> releaseNote;
/**
* release备注新Function。
*/
private List<String> releaseNoteNewFunction;
/**
* 构造 {@code StoreWebApp} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public StoreWebApp() {
}
/**
* 构造 {@code StoreWebApp} 实例。
*
* @param user 当前用户({@code User})
* @param fileUuid 文件 UUID({@code UUID})
* @param file 文件({@code McFile})
*/
public StoreWebApp(User user, UUID fileUuid, McFile file) {
super(user, fileUuid, file);
this.setAppInfo((File)file);
}
/**
* 构造 {@code StoreWebApp} 实例。
*
* @param file 文件({@code McFile})
*/
public StoreWebApp(McFile file) {
super((User)null, (UUID)null, file);
this.setAppInfo((File)file);
}
/**
* 判断 {@code formal}。
* @return 字段/派生属性 {@code formal} 的值
*/
public boolean isFormal() {
return this.isFormal != null && this.isFormal;
}
/**
* 设置 {@code isFormal}。
*
* @param isFormal 参数 {@code isFormal}({@code boolean})
*/
public void setIsFormal(boolean isFormal) {
this.isFormal = isFormal;
}
/**
* 获取 {@code appInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getAppInfo() {
if (this.appInfo == null) {
this.appInfo = new DbObject();
@@ -53,10 +119,23 @@ public class StoreWebApp extends BaseFile {
return this.appInfo;
}
/**
* 设置 {@code appInfo}。
*
* @param appInfo 参数 {@code appInfo}({@code DbObject})
*/
public void setAppInfo(DbObject appInfo) {
this.appInfo = appInfo;
}
/**
* 设置应用信息。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public void setAppInfo(String key, Object value) {
if (!this.getAppInfo().containsKey(key)) {
this.getAppInfo().append(key, value);
@@ -64,6 +143,13 @@ public class StoreWebApp extends BaseFile {
}
/**
* 设置 {@code appInfo}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:parse。
*
* @param properties 参数 {@code properties}({@code Properties})
*/
public void setAppInfo(Properties properties) {
properties.forEach((key, value) -> {
String name = (String)key;
@@ -99,23 +185,45 @@ public class StoreWebApp extends BaseFile {
});
}
/**
* 获取 {@code groupId}。
* @return 字符串结果
*/
public String getGroupId() {
return this.getAppInfo().getString("groupId");
}
/**
* 获取 {@code artifactId}。
* @return 字符串结果
*/
public String getArtifactId() {
return this.getAppInfo().getString("artifactId");
}
/**
* 获取 {@code version}。
* @return 字符串结果
*/
public String getVersion() {
return this.getAppInfo().getString("version");
}
/**
* 获取 {@code buildTime}。
* @return 字段/派生属性 {@code buildTime} 的值
*/
public Date getBuildTime() {
return this.getAppInfo().getDate("buildTime");
}
public List getReleaseNote() {
/**
* 获取 {@code releaseNote}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new ArrayList。
* @return String列表,可能为空
*/
public List<String> getReleaseNote() {
if (this.releaseNote == null) {
this.releaseNote = new ArrayList();
}
@@ -123,15 +231,30 @@ public class StoreWebApp extends BaseFile {
return this.releaseNote;
}
public void setReleaseNote(List releaseNote) {
/**
* 设置 {@code releaseNote}。
*
* @param releaseNote 参数 {@code releaseNote}({@code List<String>})
*/
public void setReleaseNote(List<String> releaseNote) {
this.releaseNote = releaseNote;
}
/**
* 判断 {@code releaseNote}。
* @return 字段/派生属性 {@code releaseNote} 的值
*/
public boolean hasReleaseNote() {
return !this.getReleaseNote().isEmpty();
}
public List getReleaseNoteNewFunction() {
/**
* 获取 {@code releaseNoteNewFunction}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new ArrayList。
* @return String列表,可能为空
*/
public List<String> getReleaseNoteNewFunction() {
if (this.releaseNoteNewFunction == null) {
this.releaseNoteNewFunction = new ArrayList();
}
@@ -139,18 +262,37 @@ public class StoreWebApp extends BaseFile {
return this.releaseNoteNewFunction;
}
public void setReleaseNoteNewFunction(List releaseNoteNewFunction) {
/**
* 设置 {@code releaseNoteNewFunction}。
*
* @param releaseNoteNewFunction 参数 {@code releaseNoteNewFunction}({@code List<String>})
*/
public void setReleaseNoteNewFunction(List<String> releaseNoteNewFunction) {
this.releaseNoteNewFunction = releaseNoteNewFunction;
}
/**
* 判断 {@code releaseNoteNewFunction}。
* @return 字段/派生属性 {@code releaseNoteNewFunction} 的值
*/
public boolean hasReleaseNoteNewFunction() {
return !this.getReleaseNoteNewFunction().isEmpty();
}
/**
* 判断 {@code webApp}。
* @return 字段/派生属性 {@code webApp} 的值
*/
public boolean isWebApp() {
return !Strings.isNullOrEmpty(this.getGroupId()) && !Strings.isNullOrEmpty(this.getArtifactId());
}
/**
* 获取 {@code fileName}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字符串结果
*/
public String getFileName() {
String fileName = super.getFileName();
if (Strings.isNullOrEmpty(fileName)) {
@@ -160,6 +302,13 @@ public class StoreWebApp extends BaseFile {
return fileName;
}
/**
* 设置 {@code appInfo}。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 3 个条件分支、0 个循环;主要调用:new JarFile、new Properties、close。
*
* @param file 文件({@code File})
*/
private void setAppInfo(File file) {
try {
JarFile jarFile = new JarFile(file);
@@ -201,6 +350,15 @@ public class StoreWebApp extends BaseFile {
}
/**
* 查找ZipEntry。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 1 个条件分支、1 个循环。
*
* @param jarFile 参数 {@code jarFile}({@code JarFile})
* @param name 参数 {@code name}({@code String})
* @return 处理结果
*/
private ZipEntry findZipEntry(JarFile jarFile, String name) {
Enumeration<? extends ZipEntry> entries = jarFile.entries();
@@ -0,0 +1,22 @@
/**
* 应用商店模型:StoreApp、WebApp、ReleaseNote、OTA 发布信息。
*
* <p>本包主要类型:
* <ul>
* <li>{@link AppReleaseNote}</li>
* <li>{@link KeyStore}</li>
* <li>{@link OtaReleaseNote}</li>
* <li>{@link ReleaseNote}</li>
* <li>{@link StoreApp}</li>
* <li>{@link StoreAppFile}</li>
* <li>{@link StoreBase}</li>
* <li>{@link StoreOta}</li>
* <li>{@link StoreOtaFile}</li>
* <li>{@link StoreOtherFile}</li>
* <li>{@link StoreWebApp}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.store;
@@ -4,28 +4,77 @@ import java.util.Locale;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code AltLocale}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code locale}(String):语言区域</li>
* <li>{@code altLocale}(String):alt语言区域</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class AltLocale {
/**
* 语言区域;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String locale;
/**
* alt语言区域。
*/
private String altLocale;
/**
* 获取 {@code locale}。
* @return 字符串结果
*/
public String getLocale() {
return this.locale;
}
/**
* 设置 {@code locale}。
*
* @param locale 参数 {@code locale}({@code String})
*/
public void setLocale(String locale) {
this.locale = locale;
}
/**
* 获取 {@code altLocale}。
* @return 字符串结果
*/
public String getAltLocale() {
return this.altLocale;
}
/**
* 设置 {@code altLocale}。
*
* @param altLocale 参数 {@code altLocale}({@code String})
*/
public void setAltLocale(String altLocale) {
this.altLocale = altLocale;
}
/**
* 处理转换为语言区域。
* @return 处理结果
*/
public Locale toLocale() {
return Locale.forLanguageTag(this.getAltLocale());
}
@@ -6,21 +6,76 @@ import java.util.Locale;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code Category}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code id}(CategoryId):ID</li>
* <li>{@code order}(int):字段 order</li>
* <li>{@code profile}(DbObject):配置档案</li>
* <li>{@code features}(List<LicenseFeature>):许可证Feature集合</li>
* </ul>
*
* 协作对象:{@code CategoryId、DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class Category {
/**
* ID;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
public CategoryId id;
/**
* 字段 order。
*/
public int order;
/**
* 配置档案。
*/
public DbObject profile;
public List features;
/**
* 许可证Feature集合。
*/
public List<LicenseFeature> features;
/**
* 构造 {@code Category} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public Category() {
}
/**
* 构造 {@code Category} 实例。
*
* 实现要点:主要调用:new CategoryId。
*
* @param use 参数 {@code use}({@code String})
* @param categoryId 参数 {@code categoryId}({@code String})
*/
public Category(String use, String categoryId) {
this.id = new CategoryId(use, categoryId);
}
/**
* 获取 {@code id}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new CategoryId。
* @return 字段/派生属性 {@code id} 的值
*/
public CategoryId getId() {
if (this.id == null) {
this.id = new CategoryId();
@@ -29,46 +84,99 @@ public class Category {
return this.id;
}
/**
* 设置 {@code id}。
*
* @param id 参数 {@code id}({@code CategoryId})
*/
public void setId(CategoryId id) {
this.id = id;
}
/**
* 获取 {@code use}。
* @return 字符串结果
*/
public String getUse() {
return this.getId().getUse();
}
/**
* 设置 {@code use}。
*
* @param use 参数 {@code use}({@code String})
*/
public void setUse(String use) {
this.getId().setUse(use);
}
/**
* 获取 {@code categoryId}。
* @return 字符串结果
*/
public String getCategoryId() {
return this.getId().getId();
}
/**
* 设置 {@code categoryId}。
*
* @param id 参数 {@code id}({@code String})
*/
public void setCategoryId(String id) {
this.getId().setId(id);
}
/**
* 设置Category。
*
* @param use 参数 {@code use}({@code String})
* @param categoryId 参数 {@code categoryId}({@code String})
*/
public void setCategory(String use, String categoryId) {
this.getId().set(use, categoryId);
}
public List getFeatures() {
/**
* 获取 {@code features}。
* @return 许可证Feature列表,可能为空
*/
public List<LicenseFeature> getFeatures() {
return this.features;
}
public void setFeatures(List features) {
/**
* 设置 {@code features}。
*
* @param features 参数 {@code features}({@code List<LicenseFeature>})
*/
public void setFeatures(List<LicenseFeature> features) {
this.features = features;
}
/**
* 获取 {@code order}。
* @return 数量/长度
*/
public int getOrder() {
return this.order;
}
/**
* 设置 {@code order}。
*
* @param order 参数 {@code order}({@code int})
*/
public void setOrder(int order) {
this.order = order;
}
/**
* 获取 {@code profile}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getProfile() {
if (this.profile == null) {
this.profile = new DbObject();
@@ -77,10 +185,24 @@ public class Category {
return this.profile;
}
/**
* 设置 {@code profile}。
*
* @param profile 设备配置档案({@code DbObject})
*/
public void setProfile(DbObject profile) {
this.profile = profile;
}
/**
* 设置配置档案。
*
* 实现要点:主要调用:new DbObject。
*
* @param locale 参数 {@code locale}({@code Locale})
* @param name 参数 {@code name}({@code String})
* @param desc 参数 {@code desc}({@code String})
*/
public void setProfile(Locale locale, String name, String desc) {
DbObject profile = new DbObject();
profile.put("name", name);
@@ -88,6 +210,12 @@ public class Category {
this.getProfile().put(locale.toString(), profile);
}
/**
* 获取配置档案。
*
* @param locale 参数 {@code locale}({@code Locale})
* @return MongoDB 文档扩展对象
*/
public DbObject getProfile(Locale locale) {
return (DbObject)this.getProfile().get(locale.toString());
}
@@ -2,33 +2,90 @@ package com.midm.model.system;
import java.io.Serializable;
/**
* 【领域模型】{@code CategoryId}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code use}(String):字段 use</li>
* <li>{@code id}(String):ID</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class CategoryId implements Serializable {
/**
* 字段 use。
*/
private String use;
/**
* ID。
*/
private String id;
/**
* 构造 {@code CategoryId} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public CategoryId() {
}
/**
* 构造 {@code CategoryId} 实例。
*
* @param use 参数 {@code use}({@code String})
* @param id 参数 {@code id}({@code String})
*/
public CategoryId(String use, String id) {
this.set(use, id);
}
/**
* 获取 {@code use}。
* @return 字符串结果
*/
public String getUse() {
return this.use;
}
/**
* 设置 {@code use}。
*
* @param use 参数 {@code use}({@code String})
*/
public void setUse(String use) {
this.use = use;
}
/**
* 获取 {@code id}。
* @return 字符串结果
*/
public String getId() {
return this.id;
}
/**
* 设置 {@code id}。
*
* @param id 参数 {@code id}({@code String})
*/
public void setId(String id) {
this.id = id;
}
/**
* 处理设置。
*
* @param use 参数 {@code use}({@code String})
* @param id 参数 {@code id}({@code String})
*/
public void set(String use, String id) {
this.setUse(use);
this.setId(id);
@@ -3,51 +3,133 @@ package com.midm.model.system;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code DbTemplate}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code code}(String):代码</li>
* <li>{@code name}(String):名称</li>
* <li>{@code content}(String):字段 content</li>
* <li>{@code comment}(String):字段 comment</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class DbTemplate {
/**
* 代码;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String code;
/**
* 名称。
*/
private String name;
/**
* 字段 content。
*/
private String content;
/**
* 字段 comment。
*/
private String comment;
/**
* 构造 {@code DbTemplate} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public DbTemplate() {
}
/**
* 构造 {@code DbTemplate} 实例。
*
* @param code 状态码/业务码({@code String})
* @param name 参数 {@code name}({@code String})
* @param content 参数 {@code content}({@code String})
*/
public DbTemplate(String code, String name, String content) {
this.setCode(code);
this.setName(name);
this.setContent(content);
}
/**
* 获取 {@code code}。
* @return 字符串结果
*/
public String getCode() {
return this.code;
}
/**
* 设置 {@code code}。
*
* @param code 状态码/业务码({@code String})
*/
public void setCode(String code) {
this.code = code;
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
return this.name;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 {@code content}。
* @return 字符串结果
*/
public String getContent() {
return this.content;
}
/**
* 设置 {@code content}。
*
* @param content 参数 {@code content}({@code String})
*/
public void setContent(String content) {
this.content = content;
}
/**
* 获取 {@code comment}。
* @return 字符串结果
*/
public String getComment() {
return this.comment;
}
/**
* 设置 {@code comment}。
*
* @param comment 参数 {@code comment}({@code String})
*/
public void setComment(String comment) {
this.comment = comment;
}
@@ -5,35 +5,105 @@ import com.mitac.cell.db.DbObject;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code HelpMessage}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code code}(String):代码</li>
* <li>{@code message}(DbObject):消息</li>
* <li>{@code options}(DbObject):选项列表</li>
* <li>{@code comment}(String):字段 comment</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class HelpMessage {
/**
* 代码;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String code;
/**
* 消息。
*/
private DbObject message;
/**
* 选项列表。
*/
private DbObject options;
/**
* 字段 comment。
*/
private String comment;
/**
* 构造 {@code HelpMessage} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public HelpMessage() {
}
/**
* 构造 {@code HelpMessage} 实例。
*
* @param code 状态码/业务码({@code String})
*/
public HelpMessage(String code) {
this.setCode(code);
}
/**
* 构造 {@code HelpMessage} 实例。
*
* @param code 状态码/业务码({@code String})
* @param locale 参数 {@code locale}({@code String})
* @param title 参数 {@code title}({@code String})
* @param desc 参数 {@code desc}({@code String})
* @param comment 参数 {@code comment}({@code String})
*/
public HelpMessage(String code, String locale, String title, String desc, String comment) {
this.setCode(code);
this.setMessage(locale, title, desc);
this.setComment(comment);
}
/**
* 获取 {@code code}。
* @return 字符串结果
*/
public String getCode() {
return this.code;
}
/**
* 设置 {@code code}。
*
* @param code 状态码/业务码({@code String})
*/
public void setCode(String code) {
this.code = code;
}
/**
* 获取 {@code message}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage() {
if (this.message == null) {
this.message = new DbObject();
@@ -42,26 +112,64 @@ public class HelpMessage {
return this.message;
}
/**
* 设置 {@code messages}。
*
* @param messages 参数 {@code messages}({@code DbObject})
*/
public void setMessages(DbObject messages) {
this.message = messages;
}
/**
* 设置消息。
*
* 实现要点:主要调用:new DbObject。
*
* @param locale 参数 {@code locale}({@code String})
* @param title 参数 {@code title}({@code String})
* @param desc 参数 {@code desc}({@code String})
*/
public void setMessage(String locale, String title, String desc) {
this.getMessage().append(locale, (new DbObject("title", title)).append("desc", this.message));
}
/**
* 获取Title。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字符串结果
*/
public String getTitle(String locale) {
return this.getMessage(locale).getString("title");
}
/**
* 获取消息。
*
* @param locale 参数 {@code locale}({@code String})
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage(String locale) {
return this.getMessage().getDbObject(new String[]{Strings.isNullOrEmpty(locale) ? "en-US" : locale});
}
/**
* 获取Description。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字符串结果
*/
public String getDescription(String locale) {
return this.getMessage(locale).getString("desc");
}
/**
* 获取 {@code options}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getOptions() {
if (this.options == null) {
this.options = new DbObject();
@@ -70,6 +178,14 @@ public class HelpMessage {
return this.options;
}
/**
* 获取选项列表。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @return MongoDB 文档扩展对象
*/
public DbObject getOptions(String category) {
Object categoryObject = this.getOptions().get(category);
if (categoryObject == null) {
@@ -80,22 +196,49 @@ public class HelpMessage {
return (DbObject)categoryObject;
}
/**
* 设置 {@code options}。
*
* @param options 参数 {@code options}({@code DbObject})
*/
public void setOptions(DbObject options) {
this.options = options;
}
/**
* 设置选项列表。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param options 参数 {@code options}({@code DbObject})
*/
public void setOptions(String category, DbObject options) {
this.getOptions().put(category, options);
}
/**
* 设置选项列表。
*
* @param category 分类(app/ota/other/report 等)({@code String})
* @param key 键/配置项({@code String})
* @param desc 参数 {@code desc}({@code String})
*/
public void setOptions(String category, String key, String desc) {
this.getOptions(category).put(key, desc);
}
/**
* 获取 {@code comment}。
* @return 字符串结果
*/
public String getComment() {
return this.comment;
}
/**
* 设置 {@code comment}。
*
* @param comment 参数 {@code comment}({@code String})
*/
public void setComment(String comment) {
this.comment = comment;
}
@@ -20,45 +20,156 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code HostLicense}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code trialPeriod}(Integer):字段 trialPeriod</li>
* <li>{@code trialDeviceLimit}(Integer):trial设备Limit</li>
* <li>{@code trialSiteLimit}(Integer):trial站点Limit</li>
* <li>{@code hostId}(String):hostID</li>
* <li>{@code siteLimit}(Integer):站点Limit</li>
* <li>{@code deviceLimit}(Integer):设备Limit</li>
* </ul>
*
* 协作对象:{@code DbObject、McTextEncryptor}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class HostLicense {
/**
* 字段 trialPeriod。
*/
public static final Integer trialPeriod = 45;
/**
* trial设备Limit。
*/
private static final Integer trialDeviceLimit = -1;
/**
* trial站点Limit。
*/
private static final Integer trialSiteLimit = -1;
/**
* hostID;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private String hostId;
/**
* 站点Limit;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Integer siteLimit;
/**
* 设备Limit;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Integer deviceLimit;
/**
* valid从;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Long validFrom;
/**
* valid转换为;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Long validTo;
/**
* 判断是否Standalone;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private boolean isStandalone;
/**
* 判断是否Valid密钥;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Boolean isValidKey;
/**
* 系统哈希;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String systemHash;
/**
* 许可证密钥。
*/
private String licenseKey;
/**
* 字段 properties。
*/
private DbObject properties;
/**
* 判断是否Primary。
*/
private boolean isPrimary;
/**
* 字段 validated;Gson 序列化控制。
*
* 注解:{@code @Expose(serialize = false)}。
*/
@Expose(
serialize = false
)
private String validated;
/**
* 字段 validatedAt;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private Long validatedAt;
/**
* 字段 encryptor;不持久化到 MongoDB,仅运行时使用;Gson 序列化控制。
*
* 注解:{@code @Transient @Expose(serialize = false)}。
*/
@Transient
@Expose(
serialize = false
)
private McTextEncryptor encryptor;
/**
* 令牌Password。
*/
private static final String tokenPassword = "MiDM@MiTAC.com";
/**
* 令牌Salt。
*/
private static final String tokenSalt = "171891893b5cef2f";
/**
* 字段 sourceEncryptor。
*/
public static final McTextEncryptor sourceEncryptor = new McTextEncryptor("MiDM@MiTAC.com", "171891893b5cef2f");
/**
* 构造 {@code HostLicense} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public HostLicense() {
this.siteLimit = trialSiteLimit;
this.deviceLimit = trialDeviceLimit;
@@ -68,10 +179,23 @@ public class HostLicense {
this.isValidKey = false;
}
/**
* 构造 {@code HostLicense} 实例。
*
* @param hostId 参数 {@code hostId}({@code String})
* @param systemHash 参数 {@code systemHash}({@code String})
*/
public HostLicense(String hostId, String systemHash) {
this(hostId, systemHash, (String)null);
}
/**
* 构造 {@code HostLicense} 实例。
*
* @param hostId 参数 {@code hostId}({@code String})
* @param systemHash 参数 {@code systemHash}({@code String})
* @param licenseKey 参数 {@code licenseKey}({@code String})
*/
public HostLicense(String hostId, String systemHash, String licenseKey) {
this.siteLimit = trialSiteLimit;
this.deviceLimit = trialDeviceLimit;
@@ -85,23 +209,46 @@ public class HostLicense {
this.dispatch();
}
/**
* 获取 {@code systemHash}。
* @return 字符串结果
*/
public String getSystemHash() {
return this.systemHash;
}
/**
* 设置 {@code systemHash}。
*
* @param systemHash 参数 {@code systemHash}({@code String})
*/
public void setSystemHash(String systemHash) {
this.systemHash = systemHash;
}
/**
* 获取 {@code hostId}。
* @return 字符串结果
*/
public String getHostId() {
return this.hostId;
}
/**
* 设置 {@code hostId}。
*
* @param hostId 参数 {@code hostId}({@code String})
*/
public void setHostId(String hostId) {
this.hostId = hostId;
this.refreshEncryptor();
}
/**
* 刷新Encryptor。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 1 个条件分支、0 个循环;主要调用:new McTextEncryptor。
*/
private void refreshEncryptor() {
if (!Strings.isNullOrEmpty(this.hostId) && !Strings.isNullOrEmpty(this.systemHash)) {
try {
@@ -115,14 +262,29 @@ public class HostLicense {
}
/**
* 获取 {@code licenseKey}。
* @return 字符串结果
*/
public String getLicenseKey() {
return this.licenseKey;
}
/**
* 判断 {@code licenseKey}。
* @return 字段/派生属性 {@code licenseKey} 的值
*/
public boolean hasLicenseKey() {
return !Strings.isNullOrEmpty(this.licenseKey);
}
/**
* 设置 {@code licenseKey}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param licenseKey 参数 {@code licenseKey}({@code String})
*/
public void setLicenseKey(String licenseKey) {
this.licenseKey = licenseKey;
if (Strings.isNullOrEmpty(licenseKey)) {
@@ -134,50 +296,104 @@ public class HostLicense {
}
/**
* 判断 {@code validKey}。
* @return 字段/派生属性 {@code validKey} 的值
*/
public boolean isValidKey() {
return this.isValidKey;
}
/**
* 获取 {@code siteLimit}。
* @return 数量/长度
*/
public int getSiteLimit() {
return this.siteLimit;
}
/**
* 设置 {@code siteLimit}。
*
* @param siteLimit 参数 {@code siteLimit}({@code int})
*/
public void setSiteLimit(int siteLimit) {
this.siteLimit = siteLimit;
}
/**
* 获取 {@code deviceLimit}。
* @return 数量/长度
*/
public int getDeviceLimit() {
return this.deviceLimit;
}
/**
* 设置 {@code deviceLimit}。
*
* @param deviceLimit 参数 {@code deviceLimit}({@code int})
*/
public void setDeviceLimit(int deviceLimit) {
this.deviceLimit = deviceLimit;
}
/**
* 获取 {@code validFrom}。
* @return 数量/长度
*/
public Long getValidFrom() {
return this.validFrom;
}
/**
* 设置 {@code validFrom}。
*
* @param validFrom 参数 {@code validFrom}({@code Long})
*/
public void setValidFrom(Long validFrom) {
this.validFrom = validFrom;
}
/**
* 获取 {@code validTo}。
* @return 数量/长度
*/
public Long getValidTo() {
return this.validTo;
}
/**
* 设置 {@code validTo}。
*
* @param validTo 参数 {@code validTo}({@code Long})
*/
public void setValidTo(Long validTo) {
this.validTo = validTo;
}
/**
* 判断 {@code standalone}。
* @return 字段/派生属性 {@code standalone} 的值
*/
public boolean isStandalone() {
return this.isStandalone;
}
/**
* 设置 {@code isStandalone}。
*
* @param isStandalone 参数 {@code isStandalone}({@code boolean})
*/
public void setIsStandalone(boolean isStandalone) {
this.isStandalone = isStandalone;
}
/**
* 设置AsTrial。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new Date、new DateTime。
*/
public void setAsTrial() {
this.setIsStandalone(true);
this.setDeviceLimit(trialDeviceLimit);
@@ -188,18 +404,40 @@ public class HostLicense {
this.validTo = (new DateTime(this.validFrom)).plusDays(trialPeriod).getMillis();
}
/**
* 判断 {@code valid}。
* @return 字段/派生属性 {@code valid} 的值
*/
public boolean isValid() {
return !this.isExpired() && this.isValidated();
}
/**
* 判断 {@code validated}。
*
* 实现要点:主要调用:new DateTime。
* @return 字段/派生属性 {@code validated} 的值
*/
private boolean isValidated() {
return DateTime.now().isBefore((new DateTime(this.validatedDate())).plusDays(trialPeriod));
}
/**
* 判断 {@code expired}。
*
* 实现要点:主要调用:new DateTime。
* @return 字段/派生属性 {@code expired} 的值
*/
private boolean isExpired() {
return this.validTo != -1L && (new DateTime(this.validTo)).plusDays(1).isBeforeNow();
}
/**
* 获取 {@code properties}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getProperties() {
if (this.properties == null) {
this.properties = new DbObject();
@@ -208,14 +446,30 @@ public class HostLicense {
return this.properties;
}
/**
* 设置 {@code properties}。
*
* @param properties 参数 {@code properties}({@code DbObject})
*/
public void setProperties(DbObject properties) {
this.properties = properties;
}
/**
* 设置Property。
*
* @param key 键/配置项({@code String})
* @param value 值({@code String})
*/
public void setProperty(String key, String value) {
this.getProperties().append(key, value);
}
/**
* 处理dispatch。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*/
public void dispatch() {
if (!Strings.isNullOrEmpty(this.getLicenseKey())) {
this.dispatch(this.getLicenseKey());
@@ -224,6 +478,11 @@ public class HostLicense {
this.validatedDate();
}
/**
* 处理校验。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:encrypt、new Date。
*/
public void validate() {
this.setProperty("ip_addr", McNetUtils.getIpAddress());
this.setProperty("host_name", McNetUtils.hostName());
@@ -233,6 +492,12 @@ public class HostLicense {
}
/**
* 处理validated日期。
*
* 实现要点:包含 2 个条件分支、0 个循环;主要调用:decrypt。
* @return 数量/长度
*/
public Long validatedDate() {
this.validatedAt = null;
if (!Strings.isNullOrEmpty(this.validated)) {
@@ -245,14 +510,30 @@ public class HostLicense {
return this.validatedAt;
}
/**
* 判断 {@code primary}。
* @return 字段/派生属性 {@code primary} 的值
*/
public boolean isPrimary() {
return this.isPrimary;
}
/**
* 设置 {@code primary}。
*
* @param isPrimary 参数 {@code isPrimary}({@code boolean})
*/
public void setPrimary(boolean isPrimary) {
this.isPrimary = isPrimary;
}
/**
* 处理dispatch。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 3 个条件分支、0 个循环;主要调用:decrypt。
*
* @param encryptedLicense 参数 {@code encryptedLicense}({@code String})
*/
public void dispatch(String encryptedLicense) {
if (this.encryptor == null) {
this.refreshEncryptor();
@@ -279,6 +560,14 @@ public class HostLicense {
}
}
/**
* 生成系统哈希。
*
* 实现要点:包含异常捕获与降级/回滚分支;包含 2 个条件分支、1 个循环;主要调用:new McSystemInfo。
*
* @param systemHash 参数 {@code systemHash}({@code String})
* @return 字符串结果
*/
public static String generateSystemHash(String systemHash) {
if (!Strings.isNullOrEmpty(systemHash)) {
return systemHash;
@@ -306,20 +595,52 @@ public class HostLicense {
}
}
/**
* 处理加密。
*
* 实现要点:主要调用:encrypt。
*
* @param value 值({@code String})
* @return 字符串结果
*/
public static String encrypt(String value) {
return sourceEncryptor.encrypt(value);
}
/**
* 处理解密。
*
* 实现要点:主要调用:decrypt。
*
* @param value 值({@code String})
* @return 字符串结果
*/
public static String decrypt(String value) {
return sourceEncryptor.decrypt(value);
}
/**
* 生成许可证。
* @return 字符串结果
*/
public String generateLicense() {
String licenseKey = this.generateLicense(this.siteLimit, this.deviceLimit, this.validTo, false, this.isStandalone);
this.setLicenseKey(licenseKey);
return licenseKey;
}
/**
* 生成许可证。
*
* 实现要点:包含 7 个条件分支、0 个循环;主要调用:new JsonObject、encrypt。
*
* @param siteLimit 参数 {@code siteLimit}({@code Integer})
* @param deviceLimit 参数 {@code deviceLimit}({@code Integer})
* @param validTo 参数 {@code validTo}({@code Long})
* @param isLicenseServer 参数 {@code isLicenseServer}({@code Boolean})
* @param isStandalone 参数 {@code isStandalone}({@code Boolean})
* @return 字符串结果
*/
public String generateLicense(Integer siteLimit, Integer deviceLimit, Long validTo, Boolean isLicenseServer, Boolean isStandalone) {
if (this.encryptor == null) {
this.refreshEncryptor();
@@ -5,29 +5,86 @@ import java.util.Locale;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code LicenseFeature}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code code}(String):代码</li>
* <li>{@code categoryId}(CategoryId):categoryID</li>
* <li>{@code profile}(DbObject):配置档案</li>
* </ul>
*
* 协作对象:{@code CategoryId、DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class LicenseFeature {
/**
* 代码;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
String code;
/**
* categoryID。
*/
CategoryId categoryId;
/**
* 配置档案。
*/
DbObject profile;
/**
* 获取 {@code code}。
* @return 字符串结果
*/
public String getCode() {
return this.code;
}
/**
* 设置 {@code code}。
*
* @param code 状态码/业务码({@code String})
*/
public void setCode(String code) {
this.code = code;
}
/**
* 获取 {@code categoryId}。
* @return 字段/派生属性 {@code categoryId} 的值
*/
public CategoryId getCategoryId() {
return this.categoryId;
}
/**
* 设置 {@code categoryId}。
*
* @param categoryId 参数 {@code categoryId}({@code CategoryId})
*/
public void setCategoryId(CategoryId categoryId) {
this.categoryId = categoryId;
}
/**
* 获取 {@code profile}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getProfile() {
if (this.profile == null) {
this.profile = new DbObject();
@@ -36,10 +93,24 @@ public class LicenseFeature {
return this.profile;
}
/**
* 设置 {@code profile}。
*
* @param profile 设备配置档案({@code DbObject})
*/
public void setProfile(DbObject profile) {
this.profile = profile;
}
/**
* 设置配置档案。
*
* 实现要点:主要调用:new DbObject。
*
* @param locale 参数 {@code locale}({@code Locale})
* @param name 参数 {@code name}({@code String})
* @param desc 参数 {@code desc}({@code String})
*/
public void setProfile(Locale locale, String name, String desc) {
DbObject profile = new DbObject();
profile.put("name", name);
@@ -47,6 +118,12 @@ public class LicenseFeature {
this.getProfile().put(locale.toString(), profile);
}
/**
* 获取配置档案。
*
* @param locale 参数 {@code locale}({@code Locale})
* @return MongoDB 文档扩展对象
*/
public DbObject getProfile(Locale locale) {
return (DbObject)this.getProfile().get(locale.toString());
}
@@ -10,32 +10,127 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code LicenseModel}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code TYPE_TRIAL}(char):字段 TYPE_TRIAL</li>
* <li>{@code TYPE_PERPETUAL}(char):字段 TYPE_PERPETUAL</li>
* <li>{@code TYPE_YEARLY}(char):字段 TYPE_YEARLY</li>
* <li>{@code TYPE_MONTHLY}(char):字段 TYPE_MONTHLY</li>
* <li>{@code TYPE_DAILY}(char):字段 TYPE_DAILY</li>
* <li>{@code DEFAULT_TRIAL_DAYS}(int):字段 DEFAULT_TRIAL_DAYS</li>
* </ul>
*
* 协作对象:{@code DbObject、Character}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class LicenseModel {
/**
* 字段 TYPE_TRIAL。
*/
public static final char TYPE_TRIAL = 't';
/**
* 字段 TYPE_PERPETUAL。
*/
public static final char TYPE_PERPETUAL = 'p';
/**
* 字段 TYPE_YEARLY。
*/
public static final char TYPE_YEARLY = 'y';
/**
* 字段 TYPE_MONTHLY。
*/
public static final char TYPE_MONTHLY = 'm';
/**
* 字段 TYPE_DAILY。
*/
public static final char TYPE_DAILY = 'd';
/**
* 字段 DEFAULT_TRIAL_DAYS。
*/
public static final int DEFAULT_TRIAL_DAYS = 45;
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 名称。
*/
private String name;
/**
* ID名称。
*/
private String idName;
/**
* 配置档案。
*/
private DbObject profile;
/**
* 类型。
*/
private Character type;
/**
* 字段 period。
*/
private Integer period;
/**
* 字段 freshExpiry。
*/
private String freshExpiry;
/**
* 字段 activatedExpiry。
*/
private String activatedExpiry;
/**
* 字段 autoExtend。
*/
private String autoExtend;
/**
* 字段 maxActivation。
*/
private Integer maxActivation = 2;
/**
* 判断是否Formal。
*/
private boolean isFormal;
/**
* 报表;不持久化到 MongoDB,仅运行时使用。
*
* 注解:{@code @Transient}。
*/
@Transient
private DbObject report;
/**
* 构造 {@code LicenseModel} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public LicenseModel() {
}
/**
* 构造 {@code LicenseModel} 实例。
*
* @param name 参数 {@code name}({@code String})
* @param type 类型({@code Character})
* @param period 参数 {@code period}({@code Integer})
* @param maxActivation 参数 {@code maxActivation}({@code Integer})
*/
public LicenseModel(String name, Character type, Integer period, Integer maxActivation) {
this.initUuid();
this.name = name;
@@ -44,82 +139,171 @@ public class LicenseModel {
this.maxActivation = maxActivation;
}
/**
* 初始化UUID。
*/
public void initUuid() {
this.setUuid(UUID.randomUUID());
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
return this.name;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 {@code idName}。
* @return 字符串结果
*/
public String getIdName() {
return this.idName;
}
/**
* 设置 {@code idName}。
*
* @param idName 参数 {@code idName}({@code String})
*/
public void setIdName(String idName) {
this.idName = idName;
}
/**
* 获取 {@code period}。
* @return 数量/长度
*/
public Integer getPeriod() {
return this.period;
}
/**
* 设置 {@code period}。
*
* @param period 参数 {@code period}({@code int})
*/
public void setPeriod(int period) {
this.period = period;
}
/**
* 获取 {@code type}。
* @return 字段/派生属性 {@code type} 的值
*/
public Character getType() {
return this.type;
}
/**
* 设置 {@code type}。
*
* @param type 类型({@code char})
*/
public void setType(char type) {
this.type = type;
}
/**
* 判断 {@code trial}。
* @return 字段/派生属性 {@code trial} 的值
*/
public boolean isTrial() {
return this.getType() == 't';
}
/**
* 判断 {@code perpetual}。
* @return 字段/派生属性 {@code perpetual} 的值
*/
public boolean isPerpetual() {
return this.getType() == 'p';
}
/**
* 获取 {@code maxActivation}。
* @return 数量/长度
*/
public Integer getMaxActivation() {
return this.maxActivation;
}
/**
* 设置 {@code maxActivation}。
*
* @param maxCount 参数 {@code maxCount}({@code int})
*/
public void setMaxActivation(int maxCount) {
this.maxActivation = maxCount;
}
/**
* 获取 {@code profile}。
* @return MongoDB 文档扩展对象
*/
public DbObject getProfile() {
return this.profile;
}
/**
* 判断 {@code formal}。
* @return 字段/派生属性 {@code formal} 的值
*/
public boolean isFormal() {
return this.isFormal;
}
/**
* 设置 {@code formal}。
*
* @param isFormal 参数 {@code isFormal}({@code boolean})
*/
public void setFormal(boolean isFormal) {
this.isFormal = isFormal;
}
/**
* 设置 {@code profile}。
*
* @param profile 设备配置档案({@code DbObject})
*/
public void setProfile(DbObject profile) {
this.profile = profile;
}
/**
* 获取 {@code report}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getReport() {
if (this.report == null) {
this.report = new DbObject();
@@ -128,18 +312,41 @@ public class LicenseModel {
return this.report;
}
/**
* 获取报表AsLong。
*
* @param key 键/配置项({@code String})
* @return 数量/长度
*/
public long getReportAsLong(String key) {
return this.getReport().getLong(key);
}
/**
* 设置 {@code report}。
*
* @param report 参数 {@code report}({@code DbObject})
*/
public void setReport(DbObject report) {
this.report = report;
}
/**
* 设置报表。
*
* @param key 键/配置项({@code String})
* @param data 参数 {@code data}({@code Object})
*/
public void setReport(String key, Object data) {
this.getReport().put(key, data);
}
/**
* 获取 {@code freshExpiry}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字符串结果
*/
public String getFreshExpiry() {
if (Strings.isNullOrEmpty(this.freshExpiry)) {
switch (this.getType()) {
@@ -151,18 +358,28 @@ public class LicenseModel {
this.freshExpiry = "45d";
break;
default:
String var10001 = String.valueOf(this.period);
this.freshExpiry = var10001 + this.type;
this.freshExpiry = String.valueOf(this.period) + this.type;
}
}
return this.freshExpiry;
}
/**
* 设置 {@code freshExpiry}。
*
* @param expiry 参数 {@code expiry}({@code String})
*/
public void setFreshExpiry(String expiry) {
this.freshExpiry = expiry;
}
/**
* 获取 {@code activatedExpiry}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字符串结果
*/
public String getActivatedExpiry() {
if (Strings.isNullOrEmpty(this.activatedExpiry)) {
switch (this.getType()) {
@@ -173,18 +390,28 @@ public class LicenseModel {
this.activatedExpiry = "45d";
break;
default:
String var10001 = String.valueOf(this.period);
this.activatedExpiry = var10001 + this.type;
this.activatedExpiry = String.valueOf(this.period) + this.type;
}
}
return this.activatedExpiry;
}
/**
* 设置 {@code activatedExpiry}。
*
* @param expiry 参数 {@code expiry}({@code String})
*/
public void setActivatedExpiry(String expiry) {
this.activatedExpiry = expiry;
}
/**
* 获取 {@code autoExtend}。
*
* 实现要点:包含 1 个条件分支、0 个循环。
* @return 字符串结果
*/
public String getAutoExtend() {
if (this.isPerpetual()) {
this.autoExtend = "1y";
@@ -193,35 +420,106 @@ public class LicenseModel {
return this.autoExtend;
}
/**
* 设置 {@code autoExtend}。
*
* @param extend 参数 {@code extend}({@code String})
*/
public void setAutoExtend(String extend) {
this.autoExtend = extend;
}
/**
* 获取FreshExpiry。
*
* 实现要点:主要调用:new Period。
*
* @param from 起始时间({@code Date})
* @return 字段/派生属性 {@code freshExpiry} 的值
*/
public Date getFreshExpiry(Date from) {
return (new Period(this.getFreshExpiry())).from(from);
}
/**
* 获取ActivatedExpiry。
*
* 实现要点:主要调用:new Period。
*
* @param from 起始时间({@code Date})
* @return 字段/派生属性 {@code activatedExpiry} 的值
*/
public Date getActivatedExpiry(Date from) {
return (new Period(this.getActivatedExpiry())).from(from);
}
/**
* 获取NextExpiry。
*
* 实现要点:主要调用:new Period。
*
* @param from 起始时间({@code Date})
* @return 字段/派生属性 {@code nextExpiry} 的值
*/
public Date getNextExpiry(Date from) {
return (new Period(this.getAutoExtend())).from(from);
}
/**
* 处理defaultTrial。
*
* 实现要点:主要调用:new LicenseModel。
* @return 处理结果
*/
public static LicenseModel defaultTrial() {
return new LicenseModel("Trial", 't', 45, 45);
}
/**
* 【领域模型】{@code Period}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code period}(int):字段 period</li>
* <li>{@code unit}(char):字段 unit</li>
* </ul>
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public class Period {
/**
* 字段 period。
*/
private int period = 0;
/**
* 字段 unit。
*/
private char unit = 'd';
/**
* 构造 {@code Period} 实例。
*
* @param period 参数 {@code period}({@code int})
* @param unit 参数 {@code unit}({@code char})
*/
public Period(int period, char unit) {
this.period = period;
this.unit = unit;
}
/**
* 构造 {@code Period} 实例。
*
* 实现要点:包含 1 个条件分支、0 个循环。
*
* @param expireBy 参数 {@code expireBy}({@code String})
*/
public Period(String expireBy) {
if (!Strings.isNullOrEmpty(expireBy)) {
String[] tokens = expireBy.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
@@ -231,18 +529,40 @@ public class LicenseModel {
}
/**
* 获取 {@code period}。
* @return 数量/长度
*/
public int getPeriod() {
return this.period;
}
/**
* 获取 {@code unit}。
* @return 字段/派生属性 {@code unit} 的值
*/
public char getUnit() {
return this.unit;
}
/**
* 处理从Now。
*
* 实现要点:主要调用:new Date。
* @return 处理结果
*/
public Date fromNow() {
return this.from(new Date());
}
/**
* 处理从。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DateTime。
*
* @param date 参数 {@code date}({@code Date})
* @return 处理结果
*/
public Date from(Date date) {
if (this.period > 0) {
LocalDate localDate = (new DateTime(date)).plusDays(1).toLocalDate();
@@ -262,6 +582,10 @@ public class LicenseModel {
}
}
/**
* 返回对象的可读字符串表示。
* @return 字符串结果
*/
public String toString() {
return "" + this.period + this.unit;
}
@@ -9,66 +9,173 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code PolicyAgreement}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code writer}(User):字段 writer</li>
* <li>{@code category}(String):字段 category</li>
* <li>{@code version}(String):版本</li>
* <li>{@code message}(DbObject):消息</li>
* <li>{@code created}(Date):创建时间</li>
* </ul>
*
* 协作对象:{@code User、DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class PolicyAgreement {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 字段 writer;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private User writer;
/**
* 字段 category。
*/
private String category;
/**
* 版本。
*/
private String version;
/**
* 消息。
*/
private DbObject message;
/**
* 创建时间。
*/
private Date created;
/**
* 构造 {@code PolicyAgreement} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public PolicyAgreement() {
this.init();
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.uuid = UUID.randomUUID();
this.created = new Date();
}
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code writer}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getWriter() {
return this.writer;
}
/**
* 设置 {@code writer}。
*
* @param writer 参数 {@code writer}({@code User})
*/
public void setWriter(User writer) {
this.writer = writer;
}
/**
* 获取 {@code category}。
* @return 字符串结果
*/
public String getCategory() {
return this.category;
}
/**
* 设置 {@code category}。
*
* @param category 分类(app/ota/other/report 等)({@code String})
*/
public void setCategory(String category) {
this.category = category;
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 获取 {@code version}。
* @return 字符串结果
*/
public String getVersion() {
return this.version;
}
/**
* 设置 {@code version}。
*
* @param version 参数 {@code version}({@code String})
*/
public void setVersion(String version) {
this.version = version;
}
/**
* 获取 {@code message}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage() {
if (this.message == null) {
this.message = new DbObject();
@@ -77,19 +184,42 @@ public class PolicyAgreement {
return this.message;
}
/**
* 获取 {@code content}。
* @return 字符串结果
*/
public String getContent() {
return this.message.getString("content");
}
/**
* 设置 {@code content}。
*
* @param content 参数 {@code content}({@code String})
*/
public void setContent(String content) {
this.setContent(Locale.US.toLanguageTag(), content);
}
/**
* 设置Content。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @param content 参数 {@code content}({@code String})
*/
public void setContent(String languageTag, String content) {
DbObject message = this.getMessage(languageTag);
message.put("content", content);
}
/**
* 获取消息。
*
* 实现要点:主要调用:new DbObject。
*
* @param languageTag 参数 {@code languageTag}({@code String})
* @return MongoDB 文档扩展对象
*/
public DbObject getMessage(String languageTag) {
DbObject message = this.getMessage();
DbObject localedMessage = new DbObject();
@@ -4,25 +4,84 @@ import java.util.Locale;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code ResourceLocale}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code locale}(String):语言区域</li>
* <li>{@code name}(String):名称</li>
* <li>{@code order}(Integer):字段 order</li>
* <li>{@code enabled}(Boolean):是否启用</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class ResourceLocale {
/**
* 语言区域;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String locale;
/**
* 名称。
*/
private String name;
/**
* 字段 order。
*/
private Integer order;
/**
* 是否启用。
*/
private Boolean enabled;
/**
* 构造 {@code ResourceLocale} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public ResourceLocale() {
}
/**
* 构造 {@code ResourceLocale} 实例。
*
* @param locale 参数 {@code locale}({@code String})
* @param name 参数 {@code name}({@code String})
*/
public ResourceLocale(String locale, String name) {
this.init(locale, name, true);
}
/**
* 构造 {@code ResourceLocale} 实例。
*
* @param locale 参数 {@code locale}({@code String})
* @param name 参数 {@code name}({@code String})
* @param enabled 参数 {@code enabled}({@code boolean})
*/
public ResourceLocale(String locale, String name, boolean enabled) {
this.init(locale, name, enabled);
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* @param locale 参数 {@code locale}({@code String})
* @param name 参数 {@code name}({@code String})
* @param enabled 参数 {@code enabled}({@code boolean})
*/
public void init(String locale, String name, boolean enabled) {
this.setLocale(locale);
this.setName(name);
@@ -30,38 +89,78 @@ public class ResourceLocale {
this.setOrder(0);
}
/**
* 获取 {@code locale}。
* @return 字符串结果
*/
public String getLocale() {
return this.locale;
}
/**
* 设置 {@code locale}。
*
* @param locale 参数 {@code locale}({@code String})
*/
public void setLocale(String locale) {
this.locale = locale;
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
return this.name;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.name = name;
}
/**
* 判断 {@code enabled}。
* @return 字段/派生属性 {@code enabled} 的值
*/
public Boolean isEnabled() {
return this.enabled;
}
/**
* 设置 {@code enabled}。
*
* @param enabled 参数 {@code enabled}({@code Boolean})
*/
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
/**
* 获取 {@code order}。
* @return 数量/长度
*/
public Integer getOrder() {
return this.order;
}
/**
* 设置 {@code order}。
*
* @param order 参数 {@code order}({@code Integer})
*/
public void setOrder(Integer order) {
this.order = order;
}
/**
* 处理转换为语言区域。
* @return 处理结果
*/
public Locale toLocale() {
return Locale.forLanguageTag(this.getLocale());
}
@@ -5,34 +5,99 @@ import com.mitac.cell.utils.McStringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code ResourceMessage}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code code}(String):代码</li>
* <li>{@code messages}(DbObject):消息列表</li>
* <li>{@code comment}(String):字段 comment</li>
* </ul>
*
* 协作对象:{@code DbObject}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class ResourceMessage {
/**
* 代码;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String code;
/**
* 消息列表。
*/
private DbObject messages;
/**
* 字段 comment。
*/
private String comment;
/**
* 构造 {@code ResourceMessage} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public ResourceMessage() {
}
/**
* 构造 {@code ResourceMessage} 实例。
*
* @param code 状态码/业务码({@code String})
*/
public ResourceMessage(String code) {
this.setCode(code);
}
/**
* 构造 {@code ResourceMessage} 实例。
*
* @param code 状态码/业务码({@code String})
* @param locale 参数 {@code locale}({@code String})
* @param message 消息内容({@code String})
* @param comment 参数 {@code comment}({@code String})
*/
public ResourceMessage(String code, String locale, String message, String comment) {
this.setCode(code);
this.setMessage(locale, message);
this.setComment(comment);
}
/**
* 获取 {@code code}。
* @return 字符串结果
*/
public String getCode() {
return this.code;
}
/**
* 设置 {@code code}。
*
* @param code 状态码/业务码({@code String})
*/
public void setCode(String code) {
this.code = code;
}
/**
* 获取 {@code messages}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new DbObject。
* @return MongoDB 文档扩展对象
*/
public DbObject getMessages() {
if (this.messages == null) {
this.messages = new DbObject();
@@ -41,27 +106,59 @@ public class ResourceMessage {
return this.messages;
}
/**
* 设置 {@code messages}。
*
* @param messages 参数 {@code messages}({@code DbObject})
*/
public void setMessages(DbObject messages) {
this.messages = messages;
}
/**
* 设置消息。
*
* @param locale 参数 {@code locale}({@code String})
* @param message 消息内容({@code String})
*/
public void setMessage(String locale, String message) {
this.getMessages().append(locale, message);
}
/**
* 获取消息。
*
* @param locale 参数 {@code locale}({@code String})
* @return 字符串结果
*/
public String getMessage(String locale) {
String message = this.getMessages().getString(locale);
return McStringUtils.isNullOrEmpty(message) ? getDefaultMessage(this.code) : message;
}
/**
* 获取Default消息。
*
* @param code 状态码/业务码({@code String})
* @return 字符串结果
*/
public static String getDefaultMessage(String code) {
return "#" + code;
}
/**
* 获取 {@code comment}。
* @return 字符串结果
*/
public String getComment() {
return this.comment;
}
/**
* 设置 {@code comment}。
*
* @param comment 参数 {@code comment}({@code String})
*/
public void setComment(String comment) {
this.comment = comment;
}
@@ -11,30 +11,115 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code StandaloneLicense}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code uuid}(UUID):对象唯一标识(MongoDB 主键)</li>
* <li>{@code site}(Site):站点</li>
* <li>{@code writer}(User):字段 writer</li>
* <li>{@code hostId}(String):hostID</li>
* <li>{@code systemHash}(String):系统哈希</li>
* <li>{@code licenseType}(String):许可证类型</li>
* </ul>
*
* 协作对象:{@code Site、User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class StandaloneLicense {
/**
* 对象唯一标识(MongoDB 主键);MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private UUID uuid;
/**
* 站点;以 DBRef 引用其他文档。
*
* 注解:{@code @DBRef}。
*/
@DBRef
private Site site;
/**
* 字段 writer。
*/
private User writer;
/**
* hostID。
*/
private String hostId;
/**
* 系统哈希。
*/
private String systemHash;
/**
* 许可证类型。
*/
private String licenseType;
/**
* 许可证密钥。
*/
private String licenseKey;
/**
* 状态。
*/
private String status;
/**
* 设备Limit。
*/
private Integer deviceLimit;
/**
* valid转换为。
*/
private long validTo = -1L;
/**
* 字段 period。
*/
private Integer period;
/**
* 判断是否Standalone。
*/
private boolean isStandalone = true;
private List notes;
/**
* 备注集合。
*/
private List<Note> notes;
/**
* 最后更新时间。
*/
private Date updated;
/**
* 创建时间。
*/
protected Date created;
/**
* 获取 {@code uuid}。
* @return UUID
*/
public UUID getUuid() {
return this.uuid;
}
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*
* @param user 当前用户({@code User})
*/
public void init(User user) {
this.uuid = UUID.randomUUID();
this.writer = user;
@@ -42,91 +127,192 @@ public class StandaloneLicense {
this.updated = new Date();
}
/**
* 设置 {@code uuid}。
*
* @param uuid 对象 UUID({@code UUID})
*/
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
/**
* 获取 {@code hostId}。
* @return 字符串结果
*/
public String getHostId() {
return this.hostId;
}
/**
* 设置 {@code hostId}。
*
* @param hostId 参数 {@code hostId}({@code String})
*/
public void setHostId(String hostId) {
this.hostId = hostId;
}
/**
* 获取 {@code systemHash}。
* @return 字符串结果
*/
public String getSystemHash() {
return this.systemHash;
}
/**
* 设置 {@code systemHash}。
*
* @param systemHash 参数 {@code systemHash}({@code String})
*/
public void setSystemHash(String systemHash) {
this.systemHash = systemHash;
}
/**
* 获取 {@code licenseKey}。
* @return 字符串结果
*/
public String getLicenseKey() {
return this.licenseKey;
}
/**
* 设置 {@code licenseKey}。
*
* @param licenseKey 参数 {@code licenseKey}({@code String})
*/
public void setLicenseKey(String licenseKey) {
this.licenseKey = licenseKey;
}
/**
* 获取 {@code deviceLimit}。
* @return 数量/长度
*/
public Integer getDeviceLimit() {
return this.deviceLimit;
}
/**
* 设置 {@code deviceLimit}。
*
* @param deviceLimit 参数 {@code deviceLimit}({@code Integer})
*/
public void setDeviceLimit(Integer deviceLimit) {
this.deviceLimit = deviceLimit;
}
/**
* 获取 {@code validTo}。
* @return 数量/长度
*/
public long getValidTo() {
return this.validTo;
}
/**
* 设置 {@code validTo}。
*
* @param validTo 参数 {@code validTo}({@code long})
*/
public void setValidTo(long validTo) {
this.validTo = validTo;
}
/**
* 判断 {@code standalone}。
* @return 字段/派生属性 {@code standalone} 的值
*/
public boolean isStandalone() {
return this.isStandalone;
}
/**
* 设置 {@code standalone}。
*
* @param isStandalone 参数 {@code isStandalone}({@code boolean})
*/
public void setStandalone(boolean isStandalone) {
this.isStandalone = isStandalone;
}
/**
* 获取 {@code site}。
* @return 站点对象;未找到时返回 {@code null}
*/
public Site getSite() {
return this.site;
}
/**
* 设置 {@code site}。
*
* @param site 站点/企业({@code Site})
*/
public void setSite(Site site) {
this.site = site;
}
/**
* 获取 {@code licenseType}。
* @return 字符串结果
*/
public String getLicenseType() {
return this.licenseType;
}
/**
* 设置 {@code licenseType}。
*
* @param licenseType 参数 {@code licenseType}({@code String})
*/
public void setLicenseType(String licenseType) {
this.licenseType = licenseType;
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 获取 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
public Date getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code Date})
*/
public void setUpdated(Date updated) {
this.updated = updated;
}
public List getNotes() {
/**
* 获取 {@code notes}。
*
* 实现要点:包含 1 个条件分支、0 个循环;主要调用:new ArrayList。
* @return 备注列表,可能为空
*/
public List<Note> getNotes() {
if (this.notes == null) {
this.notes = new ArrayList();
}
@@ -134,30 +320,75 @@ public class StandaloneLicense {
return this.notes;
}
public void setNotes(List notes) {
/**
* 设置 {@code notes}。
*
* @param notes 参数 {@code notes}({@code List<Note>})
*/
public void setNotes(List<Note> notes) {
this.notes = notes;
}
/**
* 添加备注。
*
* 实现要点:主要调用:new Note。
*
* @param note 参数 {@code note}({@code String})
*/
public void addNote(String note) {
this.getNotes().add(new Note(this.writer, note));
}
/**
* 获取 {@code status}。
* @return 字符串结果
*/
public String getStatus() {
return this.status;
}
/**
* 设置 {@code status}。
*
* @param status 状态({@code String})
*/
public void setStatus(String status) {
this.status = status;
}
/**
* 获取 {@code period}。
* @return 数量/长度
*/
public Integer getPeriod() {
return this.period;
}
/**
* 设置 {@code period}。
*
* @param period 参数 {@code period}({@code Integer})
*/
public void setPeriod(Integer period) {
this.period = period;
}
/**
* 【枚举常量】{@code STATUS}
*
* 类职责:
* <ul>
* <li>用有限枚举值表达状态/类型,避免魔法字符串。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* </ul>
*
* 学习提示:注意枚举顺序、value 字段与 fromValue/get 静态方法的映射关系。
*/
public static enum STATUS {
REQUESTED,
PROCESSING,
@@ -168,6 +399,14 @@ public class StandaloneLicense {
RENEWED,
UNKNOWN;
/**
* 处理获取。
*
* 实现要点:包含异常捕获与降级/回滚分支。
*
* @param key 键/配置项({@code String})
* @return 处理结果
*/
public static STATUS get(String key) {
try {
return valueOf(CharMatcher.whitespace().removeFrom(key).toLowerCase());
@@ -177,40 +416,108 @@ public class StandaloneLicense {
}
}
/**
* 【领域模型】{@code Note}
*
* 类职责:
* <ul>
* <li>表达领域对象的数据结构、字段约束与派生属性。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code recordedBy}(User):recorded按</li>
* <li>{@code note}(String):备注</li>
* <li>{@code noted}(Date):时间字段</li>
* </ul>
*
* 协作对象:{@code User}。
*
* 学习提示:先看类注释和 public 方法,再结合调用方理解它在整体流程中的位置。
*/
public static class Note {
/**
* recorded按。
*/
private User recordedBy;
/**
* 备注。
*/
private String note;
/**
* 时间字段。
*/
private Date noted;
/**
* 构造 {@code Note} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public Note() {
}
/**
* 构造 {@code Note} 实例。
*
* 实现要点:主要调用:new Date。
*
* @param user 当前用户({@code User})
* @param note 参数 {@code note}({@code String})
*/
public Note(User user, String note) {
this.recordedBy = user;
this.note = note;
this.noted = new Date();
}
/**
* 获取 {@code recordedBy}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getRecordedBy() {
return this.recordedBy;
}
/**
* 设置 {@code recordedBy}。
*
* @param recordedBy 参数 {@code recordedBy}({@code User})
*/
public void setRecordedBy(User recordedBy) {
this.recordedBy = recordedBy;
}
/**
* 获取 {@code note}。
* @return 字符串结果
*/
public String getNote() {
return this.note;
}
/**
* 设置 {@code note}。
*
* @param note 参数 {@code note}({@code String})
*/
public void setNote(String note) {
this.note = note;
}
/**
* 获取 {@code noted}。
* @return 字段/派生属性 {@code noted} 的值
*/
public Date getNoted() {
return this.noted;
}
/**
* 设置 {@code noted}。
*
* @param noted 参数 {@code noted}({@code Date})
*/
public void setNoted(Date noted) {
this.noted = noted;
}
@@ -4,44 +4,111 @@ import com.mitac.cell.utils.McNumberUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code SystemSetting}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code key}(String):密钥</li>
* <li>{@code value}(String):值</li>
* </ul>
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class SystemSetting {
/**
* 密钥;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String key;
/**
* 值。
*/
private String value;
/**
* 构造 {@code SystemSetting} 实例。
* 使用默认字段值,后续通常由 Spring/Mongo 或调用方填充。
*/
public SystemSetting() {
}
/**
* 构造 {@code SystemSetting} 实例。
*
* @param key 键/配置项({@code String})
* @param value 值({@code Object})
*/
public SystemSetting(String key, Object value) {
this.setKey(key);
this.setValue(value != null ? String.valueOf(value) : null);
}
/**
* 获取 {@code key}。
* @return 字符串结果
*/
public String getKey() {
return this.key;
}
/**
* 设置 {@code key}。
*
* @param key 键/配置项({@code String})
*/
public void setKey(String key) {
this.key = key;
}
/**
* 获取 {@code value}。
* @return 字符串结果
*/
public String getValue() {
return this.value;
}
/**
* 设置 {@code value}。
*
* @param value 值({@code String})
*/
public void setValue(String value) {
this.value = value;
}
/**
* 获取 {@code asInteger}。
* @return 数量/长度
*/
public Integer getAsInteger() {
return McNumberUtils.toInt(this.getValue());
}
/**
* 获取 {@code asLong}。
* @return 数量/长度
*/
public Long getAsLong() {
return McNumberUtils.toLong(this.getValue());
}
/**
* 获取 {@code asBoolean}。
* @return 字段/派生属性 {@code asBoolean} 的值
*/
public Boolean getAsBoolean() {
return this.value.equalsIgnoreCase("true");
}
@@ -0,0 +1,24 @@
/**
* 系统设置模型:SystemSetting、LicenseModel、HostLicense、语言资源等。
*
* <p>本包主要类型:
* <ul>
* <li>{@link AltLocale}</li>
* <li>{@link Category}</li>
* <li>{@link CategoryId}</li>
* <li>{@link DbTemplate}</li>
* <li>{@link HelpMessage}</li>
* <li>{@link HostLicense}</li>
* <li>{@link LicenseFeature}</li>
* <li>{@link LicenseModel}</li>
* <li>{@link PolicyAgreement}</li>
* <li>{@link ResourceLocale}</li>
* <li>{@link ResourceMessage}</li>
* <li>{@link StandaloneLicense}</li>
* <li>{@link SystemSetting}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.system;
@@ -6,74 +6,190 @@ import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 【MongoDB 文档实体】{@code MailTemplate}
*
* 类职责:
* <ul>
* <li>作为 MongoDB 集合文档,承载该领域对象的持久化字段与索引。</li>
* <li>通过字段/依赖注入持有运行期状态,字段含义见下方“核心字段”。</li>
* </ul>
*
* 核心字段(按声明顺序):
* <ul>
* <li>{@code idName}(String):ID名称</li>
* <li>{@code name}(String):名称</li>
* <li>{@code description}(String):字段 description</li>
* <li>{@code template}(DbObject):模板</li>
* <li>{@code writer}(User):字段 writer</li>
* <li>{@code created}(Date):创建时间</li>
* </ul>
*
* 协作对象:{@code DbObject、User}。
*
* 持久化/框架标记:{@code @Document} 映射为 MongoDB 集合。
*
* 学习提示:先看字段与 @Field/@Indexed,再看对应 Service/Repository 如何构造查询条件。
*/
@Document
public class MailTemplate {
/**
* ID名称;MongoDB 主键。
*
* 注解:{@code @Id}。
*/
@Id
private String idName;
/**
* 名称。
*/
private String name;
/**
* 字段 description。
*/
private String description;
/**
* 模板。
*/
private DbObject template;
/**
* 字段 writer。
*/
private User writer;
/**
* 创建时间。
*/
private Date created;
/**
* 最后更新时间。
*/
private Date updated;
/**
* 初始化对象状态(补齐 UUID/时间戳/默认字段)。
*
* 实现要点:主要调用:new Date。
*/
public void init() {
this.created = new Date();
this.updated = new Date();
}
/**
* 获取 {@code idName}。
* @return 字符串结果
*/
public String getIdName() {
return this.idName;
}
/**
* 设置 {@code idName}。
*
* @param idName 参数 {@code idName}({@code String})
*/
public void setIdName(String idName) {
this.idName = idName;
}
/**
* 获取 {@code name}。
* @return 字符串结果
*/
public String getName() {
return this.name;
}
/**
* 设置 {@code name}。
*
* @param name 参数 {@code name}({@code String})
*/
public void setName(String name) {
this.name = name;
}
/**
* 获取 {@code description}。
* @return 字符串结果
*/
public String getDescription() {
return this.description;
}
/**
* 设置 {@code description}。
*
* @param description 参数 {@code description}({@code String})
*/
public void setDescription(String description) {
this.description = description;
}
/**
* 获取 {@code template}。
* @return MongoDB 文档扩展对象
*/
public DbObject getTemplate() {
return this.template;
}
/**
* 设置 {@code template}。
*
* @param template 参数 {@code template}({@code DbObject})
*/
public void setTemplate(DbObject template) {
this.template = template;
}
/**
* 获取 {@code writer}。
* @return 用户对象;未找到时返回 {@code null}
*/
public User getWriter() {
return this.writer;
}
/**
* 设置 {@code writer}。
*
* @param writer 参数 {@code writer}({@code User})
*/
public void setWriter(User writer) {
this.writer = writer;
}
/**
* 获取 {@code created}。
* @return 字段/派生属性 {@code created} 的值
*/
public Date getCreated() {
return this.created;
}
/**
* 设置 {@code created}。
*
* @param created 参数 {@code created}({@code Date})
*/
public void setCreated(Date created) {
this.created = created;
}
/**
* 获取 {@code updated}。
* @return 字段/派生属性 {@code updated} 的值
*/
public Date getUpdated() {
return this.updated;
}
/**
* 设置 {@code updated}。
*
* @param updated 参数 {@code updated}({@code Date})
*/
public void setUpdated(Date updated) {
this.updated = updated;
}
@@ -0,0 +1,12 @@
/**
* 邮件/消息模板模型。
*
* <p>本包主要类型:
* <ul>
* <li>{@link MailTemplate}</li>
* </ul>
*
* <p>阅读建议:结合本包内类的 Javadoc 与 {@code docs/CODE_WALKTHROUGH.md} 一起看,
* 先理解输入/输出,再跟踪 Service 与 MongoTemplate 的调用链。
*/
package com.midm.model.template;