feat(device): 添加设备策略信息管理功能
新增设备策略信息表 sys_sn_device_policy 及对应实体、Mapper、Converter、VO、Req 模型,并在设备端、家属端、管理端分别提供策略查询、全量更新和单独开关设置接口。同时修正设备菜单按钮权限命名(add/edit → create/update),并调整删除设备与解绑接口的权限和返回值。
This commit is contained in:
@@ -22,8 +22,13 @@ import com.youlai.boot.device.model.req.SnSecurityInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnOtherInfoReq;
|
||||
import com.youlai.boot.device.model.req.SnLocationReq;
|
||||
import com.youlai.boot.device.model.entity.SnLocation;
|
||||
import com.youlai.boot.device.model.entity.SnDevicePolicy;
|
||||
import com.youlai.boot.device.model.entity.SnScreenshot;
|
||||
import com.youlai.boot.device.model.req.DevicePolicyReq;
|
||||
import com.youlai.boot.device.model.req.DevicePolicyToggleReq;
|
||||
import com.youlai.boot.device.model.vo.DeveloperOptionsVO;
|
||||
import com.youlai.boot.device.model.vo.DevicePolicyVO;
|
||||
import com.youlai.boot.device.converter.DevicePolicyConverter;
|
||||
import com.youlai.boot.device.service.*;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -68,6 +73,8 @@ public class MobileController {
|
||||
private final NetworkInfoService networkInfoService;
|
||||
private final SecurityInfoService securityInfoService;
|
||||
private final OtherInfoService otherInfoService;
|
||||
private final DevicePolicyService devicePolicyService;
|
||||
private final DevicePolicyConverter devicePolicyConverter;
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(MobileController.class);
|
||||
|
||||
@@ -565,4 +572,100 @@ public class MobileController {
|
||||
return Result.failed("上传应用图标失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== 设备策略信息(设备端) =====================
|
||||
|
||||
@Operation(summary = "获取设备策略信息", description = "SN 合法且无记录时自动新建默认策略(默认全开)")
|
||||
@GetMapping("/get_device_policy")
|
||||
public Result<DevicePolicyVO> getDevicePolicy(
|
||||
@RequestHeader(value = "X-Device-SN") String sn
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
SnDevicePolicy policy = devicePolicyService.getOrInitBySn(sn);
|
||||
if (policy == null) {
|
||||
return Result.failed("设备SN不合法或不存在");
|
||||
}
|
||||
return Result.success(devicePolicyConverter.toVo(policy));
|
||||
} catch (Exception e) {
|
||||
logger.error("getDevicePolicy error, sn: {}", sn, e);
|
||||
return Result.failed("获取设备策略失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "上传/全量设置设备策略信息", description = "SN 合法且无记录时新建,存在时更新(空字段保持原值)")
|
||||
@PostMapping("/update_device_policy")
|
||||
public Result<Void> updateDevicePolicy(
|
||||
@RequestHeader(value = "X-Device-SN") String sn,
|
||||
@RequestBody DevicePolicyReq req
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
if (req == null) {
|
||||
return Result.failed("策略信息不能为空");
|
||||
}
|
||||
SnDevicePolicy policy = new SnDevicePolicy();
|
||||
policy.setSerialno(sn);
|
||||
copyPolicy(req, policy);
|
||||
boolean success = devicePolicyService.saveOrUpdateBySn(sn, policy);
|
||||
if (!success) {
|
||||
return Result.failed("保存设备策略失败(设备SN不合法或参数异常)");
|
||||
}
|
||||
logger.info("设备策略上传成功, sn: {}", sn);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
logger.error("updateDevicePolicy error, sn: {}", sn, e);
|
||||
return Result.failed("上传设备策略失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "单独设置设备策略开关", description = "通过 field 指定策略字段,value 设置 0/1")
|
||||
@PostMapping("/update_device_policy_toggle")
|
||||
public Result<Void> toggleDevicePolicy(
|
||||
@RequestHeader(value = "X-Device-SN") String sn,
|
||||
@RequestBody DevicePolicyToggleReq req
|
||||
) {
|
||||
try {
|
||||
if (sn == null || sn.trim().isEmpty()) {
|
||||
return Result.failed("设备序列号不能为空");
|
||||
}
|
||||
if (req == null || req.getField() == null || req.getValue() == null) {
|
||||
return Result.failed("field 与 value 不能为空");
|
||||
}
|
||||
boolean success = devicePolicyService.updateSingleBySn(sn, req.getField(), req.getValue());
|
||||
if (!success) {
|
||||
return Result.failed("设置设备策略失败(设备SN不合法或字段不支持)");
|
||||
}
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
logger.error("toggleDevicePolicy error, sn: {}", sn, e);
|
||||
return Result.failed("设置设备策略失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void copyPolicy(DevicePolicyReq src, SnDevicePolicy target) {
|
||||
target.setUsbData(src.getUsbData());
|
||||
target.setTimeSetting(src.getTimeSetting());
|
||||
target.setStorageCard(src.getStorageCard());
|
||||
target.setFactoryReset(src.getFactoryReset());
|
||||
target.setWifiHotspot(src.getWifiHotspot());
|
||||
target.setBluetoothSwitch(src.getBluetoothSwitch());
|
||||
target.setWallpaper(src.getWallpaper());
|
||||
target.setNotificationBar(src.getNotificationBar());
|
||||
target.setStatusBarPullDown(src.getStatusBarPullDown());
|
||||
target.setSystemNavBarShow(src.getSystemNavBarShow());
|
||||
target.setSystemNavBarSetting(src.getSystemNavBarSetting());
|
||||
target.setNavBarOptions(src.getNavBarOptions());
|
||||
target.setBluetoothFunction(src.getBluetoothFunction());
|
||||
target.setOtaUpgrade(src.getOtaUpgrade());
|
||||
target.setAppInstall(src.getAppInstall());
|
||||
target.setAutoRotate(src.getAutoRotate());
|
||||
target.setAutoBrightness(src.getAutoBrightness());
|
||||
target.setEyeProtection(src.getEyeProtection());
|
||||
target.setDarkMode(src.getDarkMode());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user