feat(device): 添加设备策略信息管理功能
新增设备策略信息表 sys_sn_device_policy 及对应实体、Mapper、Converter、VO、Req 模型,并在设备端、家属端、管理端分别提供策略查询、全量更新和单独开关设置接口。同时修正设备菜单按钮权限命名(add/edit → create/update),并调整删除设备与解绑接口的权限和返回值。
This commit is contained in:
@@ -5,13 +5,19 @@ import com.youlai.boot.client.model.entity.ClientUser;
|
||||
import com.youlai.boot.client.service.ClientUserService;
|
||||
import com.youlai.boot.common.exception.BusinessException;
|
||||
import com.youlai.boot.common.result.Result;
|
||||
import com.youlai.boot.device.converter.DevicePolicyConverter;
|
||||
import com.youlai.boot.device.model.entity.SnDeviceInfo;
|
||||
import com.youlai.boot.device.model.entity.SnDevicePolicy;
|
||||
import com.youlai.boot.device.model.req.DevicePolicyReq;
|
||||
import com.youlai.boot.device.model.req.DevicePolicyToggleReq;
|
||||
import com.youlai.boot.device.model.vo.DeviceApkInfoVO;
|
||||
import com.youlai.boot.device.model.vo.DeviceBriefVO;
|
||||
import com.youlai.boot.device.model.vo.DeviceLocationVO;
|
||||
import com.youlai.boot.device.model.vo.DevicePolicyVO;
|
||||
import com.youlai.boot.device.model.vo.DeviceSystemInfoVO;
|
||||
import com.youlai.boot.device.model.vo.ScreenshotVO;
|
||||
import com.youlai.boot.device.service.ApkInstallService;
|
||||
import com.youlai.boot.device.service.DevicePolicyService;
|
||||
import com.youlai.boot.device.service.DeviceService;
|
||||
import com.youlai.boot.device.service.LocationService;
|
||||
import com.youlai.boot.device.service.ScreenshotService;
|
||||
@@ -26,6 +32,8 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -53,6 +61,8 @@ public class ClientController {
|
||||
private final LocationService locationService;
|
||||
private final ApkInstallService apkInstallService;
|
||||
private final ScreenshotService screenshotService;
|
||||
private final DevicePolicyService devicePolicyService;
|
||||
private final DevicePolicyConverter devicePolicyConverter;
|
||||
|
||||
/**
|
||||
* 校验当前登录的 client 用户是否绑定了传入的设备 SN。
|
||||
@@ -286,4 +296,106 @@ public class ClientController {
|
||||
return Result.failed("解绑设备失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ===================== 设备策略信息(家属端) =====================
|
||||
|
||||
@Operation(summary = "获取已绑定设备策略信息", description = "SN 合法且无记录时自动新建默认策略(默认全开)")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@GetMapping("/policy")
|
||||
public Result<DevicePolicyVO> getPolicy(
|
||||
@Parameter(description = "设备序列号") @RequestParam("sn") String sn
|
||||
) {
|
||||
try {
|
||||
checkBound(sn);
|
||||
SnDevicePolicy policy = devicePolicyService.getOrInitBySn(sn);
|
||||
if (policy == null) {
|
||||
return Result.failed("设备SN不合法或不存在");
|
||||
}
|
||||
return Result.success(devicePolicyConverter.toVo(policy));
|
||||
} catch (BusinessException be) {
|
||||
return Result.failed(be.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("getPolicy error, sn: {}", sn, e);
|
||||
return Result.failed("获取策略信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "全量设置已绑定设备策略信息", description = "SN 合法且无记录时新建,存在时更新(空字段保持原值)")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@PutMapping("/policy")
|
||||
public Result<?> updatePolicy(
|
||||
@Parameter(description = "设备序列号") @RequestParam("sn") String sn,
|
||||
@RequestBody DevicePolicyReq req
|
||||
) {
|
||||
try {
|
||||
checkBound(sn);
|
||||
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不合法或参数异常)");
|
||||
}
|
||||
// 全量保存后推送策略状态到对应设备
|
||||
devicePolicyService.pushPolicyToDevice(sn);
|
||||
return Result.success();
|
||||
} catch (BusinessException be) {
|
||||
return Result.failed(be.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("updatePolicy error, sn: {}", sn, e);
|
||||
return Result.failed("保存策略信息失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "单独设置已绑定设备策略开关", description = "通过 field 指定策略字段,value 设置 0/1")
|
||||
@PreAuthorize("isAuthenticated()")
|
||||
@PutMapping("/policy/toggle")
|
||||
public Result<?> togglePolicy(
|
||||
@Parameter(description = "设备序列号") @RequestParam("sn") String sn,
|
||||
@RequestBody DevicePolicyToggleReq req
|
||||
) {
|
||||
try {
|
||||
checkBound(sn);
|
||||
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不合法或字段不支持)");
|
||||
}
|
||||
// 单独保存后推送策略状态到对应设备
|
||||
devicePolicyService.pushPolicyToDevice(sn);
|
||||
return Result.success();
|
||||
} catch (BusinessException be) {
|
||||
return Result.failed(be.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("togglePolicy 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