feat: complete reverse engineering, standard Maven structure, detailed code annotations and IoT-M platform architecture

This commit is contained in:
rick committed 2026-11-16 14:35:53 +08:00
1 parent e8dc09fb3c
commit cd6a4c70e7
3045 files changed
+566733 -1

No files matched your search

@@ -0,0 +1,495 @@
package com.midm.model.device;
import com.google.common.base.Strings;
import com.midm.model.GeneralProfile;
import com.midm.model.battery.Battery;
import com.midm.model.file.OtaFile;
import com.midm.model.org.User;
import com.mitac.cell.db.DbObject;
import com.mitac.cell.utils.McJsonUtils;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import org.bson.Document;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
/**
* ======================================================================================
* 核心实体模型:受控终端设备档案 (Device Entity)
* ======================================================================================
*
* <p>【数据建模与 MongoDB 索引架构】
* 1. 业务地位:
* - 作为整个 MDM / IoT 系统的核心资产抽象,代表一台具体的受控智能硬件(PDA / 移动平板 / 车载终端)。
* 2. 【生产级复合索引设计】:
* - `{'profile.hardware_info.serial_no': 1}` (unique = true):
* 以出厂序列号构建唯一业务主键索引,杜绝重复设备接入,提供 O(1) 复杂度的极速检索。
* - `{'deviceGroup.$id': 1}`:
* 按部门/仓库/车辆编队等组织分组高效检索关联设备。
* - `{'owner.$id': 1, 'deviceGroup.$id': 1}`:
* 加速管理员按员工责任人与所属部门进行组合过滤统计。
* 3. 关联映射({@link DBRef}):
* - 关联所属企业员工 (User owner)、商业授权凭据 (DeviceLicense license)、组织分组 (DeviceGroup deviceGroup)。
* 4. 动态属性集(DbObject):
* - `profile`:静态硬件特征(IMEI、MAC、CPU型号、屏幕分辨率、出厂镜像版本);
* - `states`:动态运行快照(当前电量、实时网络类型、内存剩余空间、活跃IP);
* - `installedApps`:端侧已安装的应用清单快照(用于合规检测与版本审计)。
*
* @author MiDM Core Platform Team
*/
@org.springframework.data.mongodb.core.mapping.Document
@CompoundIndexes({@CompoundIndex(
def = "{'deviceGroup.$id':1}"
), @CompoundIndex(
def = "{'profile.hardware_info.serial_no':1}",
unique = true
), @CompoundIndex(
def = "{'owner.$id':1, 'deviceGroup.$id':1}"
)})
public class Device extends GeneralProfile {
/** 所属企业租户主键 UUID(实现多租户严格逻辑隔离) */
private UUID siteUuid;
/** 临时字段:前端传递的目标分组 UUID,不持久化到 MongoDB */
@Transient
private UUID groupUuid;
/** 临时字段:展示给前端的分组全路径(如 "总公司/华东大区/智能物流一号仓") */
@Transient
private String groupPath;
/** 临时字段:归属负责人主键 UUID */
@Transient
private UUID ownerUuid;
/** MongoDB 跨集合引用:设备领用人档案 */
@DBRef
private User owner;
/** MongoDB 跨集合引用:设备绑定的商业 License 授权凭据 */
@DBRef
private DeviceLicense license;
/** MongoDB 跨集合引用:所属层级组织分组 */
@DBRef
private DeviceGroup deviceGroup;
/** 临时字段:设备当前生效的策略清单缓存 */
@Transient
private List deviceProfiles;
/** 许可激活时间点索引 */
@Indexed
private Date licensed;
/** 许可到期时间点索引(用于定时扫描批量过期告警与自动续约) */
@Indexed
private Date licenseExpiry;
/** 临时字段:RSA 鉴权私钥字符串 */
@Transient
private String rsa;
/** 终端动态遥测快照数据字典(电池状态、网络、存储剩余空间等) */
protected DbObject states;
/** 首次入网注册时间戳 */
private Date enrolled;
/** 最近一次活跃心跳上报时间(Check-in,用于离线判定) */
private Date lastCheckedIn;
/** 最近一次 TCP / WebSocket 连接断开时间点 */
private Date lastDisconnected;
/** 终端已安装的应用程序包信息清单快照 */
private List installedApps;
public String getRsa() {
return this.rsa;
}
public void setRsa(String rsa) {
this.rsa = rsa;
}
public UUID getSiteUuid() {
return this.siteUuid;
}
public void setSiteUuid(UUID siteUuid) {
this.siteUuid = siteUuid;
}
public UUID getGroupUuid() {
return this.groupUuid;
}
public String getGroupPath() {
return this.groupPath;
}
public void setGroupPath(String groupPath) {
this.groupPath = groupPath;
}
public User getOwner() {
return this.owner;
}
public void setOwner(User owner) {
this.owner = owner;
if (owner != null) {
this.removeProfile("owner");
}
}
public UUID getOwnerUuid() {
return this.ownerUuid;
}
public void setOwnerUuid(UUID ownerUuid) {
this.ownerUuid = ownerUuid;
}
public boolean hasOwner() {
return this.getOwner() != null;
}
public String getOwnerInfo(String key, String defaultValue) {
if (this.owner == null) {
DbObject owner = this.getProfileCategory(new String[]{"owner"});
return (String)owner.get(key, defaultValue);
} else {
return key.equals("email") ? this.owner.getEmail() : (String)this.owner.getProfile(key, defaultValue);
}
}
public boolean isAssociated() {
return this.getDeviceGroup() != null;
}
public boolean canRegister() {
return !Strings.isNullOrEmpty(this.getSerialNo());
}
public DeviceGroup getDeviceGroup() {
return this.deviceGroup;
}
public void setDeviceGroup(DeviceGroup deviceGroup) {
if (deviceGroup != null && deviceGroup.getSiteUuid().equals(this.getSiteUuid())) {
this.deviceGroup = deviceGroup;
} else {
this.groupUuid = null;
this.deviceGroup = null;
}
}
public DbObject getStates() {
if (this.states == null) {
this.states = new DbObject();
}
return this.states;
}
public void setStates(DbObject states) {
this.states = states;
}
public String getState() {
return this.getStates().getString("state", "unknown");
}
public void setState(String state) {
this.setState("state", state);
}
public boolean isOnline() {
return this.getStates().getBoolean("isOnline", false);
}
public void setOnline(boolean online) {
this.setState("isOnline", online);
}
public boolean isBlocked() {
return this.getStates().containsKey("blocked");
}
public void setState(String key, Object value) {
this.getStates().append(key, value);
}
public void setClientVersion(int version) {
this.getStates().put("clientVersion", version);
}
public int getClientVersion() {
return this.getStates().getInteger("clientVersion", -1);
}
public Battery.BATTERY_CONDITION getBatteryCondition() {
return Battery.BATTERY_CONDITION.forValue(this.getStates().getInteger("batteryCondition", -1));
}
public boolean hasOldClient() {
return this.getClientVersion() < 0;
}
public Date getEnrolled() {
return this.enrolled;
}
public boolean isEnrolled() {
return this.enrolled != null;
}
public void setEnrolled(Date enrolled) {
this.enrolled = enrolled;
this.setState("enrolled");
this.setLicenseExpiry();
}
public boolean isRetired() {
return this.getState().equals("retired");
}
public Date getLastCheckedIn() {
return this.lastCheckedIn;
}
public void setLastCheckedIn() {
this.setLastCheckedIn(new Date());
}
public void setLastCheckedIn(Date lastCheckedIn) {
this.lastCheckedIn = lastCheckedIn;
}
public Date getLastDisconnected() {
return this.lastDisconnected;
}
public void setLastDisconnected() {
this.lastDisconnected = new Date();
}
public void setLastDisconnected(Date disconnected) {
this.lastDisconnected = disconnected;
}
public List getInstalledApps() {
return this.installedApps;
}
public void setInstalledApps(List installedApps) {
this.installedApps = installedApps;
}
public void setDeviceProfiles(List deviceProfiles) {
this.deviceProfiles = deviceProfiles;
}
public String getSerialNo() {
return (String)this.getCategoryProfile("hardware_info", "serial_no");
}
public void setSerialNo(String serialNo) {
this.setProfile("hardware_info", "serial_no", serialNo.trim());
}
public String getModelId() {
return (String)this.getCategoryProfile("hardware_info", "product_id");
}
public String getBuildNo() {
return this.getProfileCategory(new String[]{"software_info"}).getString("build_no");
}
public String getDisplayId() {
return this.getProfileCategory(new String[]{"software_info"}).getString("display_id");
}
public String getProductDisplayId() {
return this.getProfileCategory(new String[]{"software_info"}).getString("product_display_id");
}
public long getBuildDate() {
return this.getProfileCategory(new String[]{"software_info"}).getLong("build_date", -1L);
}
public int getSdkVersion() {
if (this.isEnrolled()) {
int version = this.getProfileCategory(new String[]{"software_info"}).getInteger("sdk_version", -1);
if (version < 0) {
String osVersion = this.getProfileCategory(new String[]{"software_info"}).getString("os_version");
if (!Strings.isNullOrEmpty(osVersion)) {
if (osVersion.startsWith("5.")) {
version = 22;
} else if (osVersion.startsWith("6.")) {
version = 23;
} else if (osVersion.startsWith("7.")) {
version = 25;
} else if (osVersion.startsWith("8.")) {
version = 27;
} else if (osVersion.equals("9")) {
version = 28;
}
}
}
return version;
} else {
return -1;
}
}
public String getCustomerId() {
return (String)this.getCategoryProfile("software_info", "customer_id");
}
public String getRegionImgVersion() {
return this.getProfile().getDbObject(new String[]{"software_info"}).getString("region_version");
}
public String getScriptVersion() {
return (String)this.getCategoryProfile("software_info", "script_version");
}
public long getRegionBuildDate() {
return this.getProfile().getDbObject(new String[]{"software_info"}).getLong("region_build_date");
}
public boolean isGmsAvailable() {
return this.getProfile().getDbObject(new String[]{"software_info"}).getBoolean("gms_available");
}
public String getSkuId() {
String skuId = (String)this.getCategoryProfile("hardware_info", "sku_id");
if (skuId == null) {
if (this.isGmsAvailable()) {
String buildNo = this.getBuildNo();
if (buildNo == null) {
buildNo = this.getDisplayId();
}
if (buildNo != null) {
skuId = buildNo.substring(0, buildNo.indexOf("."));
}
} else {
skuId = OtaFile.parseSkuId(this.getDisplayId());
}
if (skuId == null) {
skuId = OtaFile.parseSkuId(this.getProductDisplayId());
}
if (skuId == null) {
skuId = OtaFile.parseSkuId(this.getBuildNo());
}
if (skuId != null) {
this.setProfile("hardware_info", "sku_id", skuId);
}
}
return skuId;
}
public String getDeviceId() {
return (String)this.getCategoryProfile("hardware_info", "device_id");
}
public String getBuildFingerPrint() {
return (String)this.getCategoryProfile("software_info", "build_fingerprint");
}
public boolean isMobileConnected() {
String type = this.getProfileCategory(new String[]{"network", "active"}).getString("type");
return "MOBILE".equalsIgnoreCase(type);
}
public String getWifiMacAddr() {
return this.getProfileCategory(new String[]{"network", "wifi"}).getString("mac_address");
}
public DeviceLicense getLicense() {
return this.license;
}
public void setLicense(DeviceLicense license) {
this.license = license;
if (license != null) {
this.licensed = new Date();
this.setLicenseExpiry();
}
}
public Date getLicensed() {
return this.licensed;
}
public void setLicensed(Date licensed) {
this.licensed = licensed;
}
private void setLicenseExpiry() {
if (this.hasLicense()) {
if (!this.license.isActivated() && this.isEnrolled()) {
this.license.activate();
}
this.setLicenseExpiry(this.license.getExpiry());
}
}
public Date getLicenseExpiry() {
if (this.licenseExpiry == null && this.hasLicense()) {
this.licenseExpiry = this.license.getExpiry();
}
return this.licenseExpiry;
}
public boolean isLicenseExpired() {
return this.license != null && !this.license.isPerpetual() && this.license.isExpired();
}
public void setLicenseExpiry(Date expiry) {
this.licenseExpiry = expiry;
}
public boolean hasLicense() {
return this.license != null;
}
public boolean isTrial() {
return !this.hasLicense() || this.license.isTrial();
}
public void removeLicense() {
this.setLicense((DeviceLicense)null);
}
public String getPlan() {
return this.license.getPlan();
}
public void reset() {
this.setEnrolled((Date)null);
this.getStates().clear();
}
public Device clone() {
return (Device)McJsonUtils.clone(this);
}
}