feat(device): 实现新增设备接口

完善设备新增接口,增加SN唯一性校验、参数非空验证和默认状态设置。
This commit is contained in:
TongTongStudio
2026-08-09 13:43:43 +08:00
parent 927332ad5d
commit a0c1596d28
2 changed files with 33 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import com.youlai.boot.common.enums.ActionTypeEnum;
import com.youlai.boot.common.enums.LogModuleEnum;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.device.model.entity.SnDeviceInfo;
import com.youlai.boot.device.model.query.DeviceQuery;
import com.youlai.boot.device.model.vo.DeviceApkInfoVO;
import com.youlai.boot.device.model.vo.DeviceHardwareInfoVO;
@@ -28,6 +29,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -69,6 +72,16 @@ public class DeviceController {
return Result.success(detail);
}
@Operation(summary = "新增设备")
@PostMapping
public Result<Void> addDevice(@RequestBody SnDeviceInfo device) {
boolean success = deviceService.addSn(device);
if (!success) {
return Result.failed("设备SN已存在或参数非法新增失败");
}
return Result.success();
}
// ===================== 设备系统信息(分面板独立接口) =====================
@Operation(summary = "设备基本信息")

View File

@@ -181,12 +181,30 @@ public class DeviceServiceImpl extends ServiceImpl<DeviceMapper, SnDeviceInfo> i
@Override
public boolean addSn(SnDeviceInfo device) {
return false;
if (device == null || device.getSerialno() == null || device.getSerialno().isBlank()) {
return false;
}
// 校验 SN 唯一
long count = this.count(new LambdaQueryWrapper<SnDeviceInfo>()
.eq(SnDeviceInfo::getSerialno, device.getSerialno()));
if (count > 0) {
log.warn("新增设备失败SN 已存在: {}", device.getSerialno());
return false;
}
// 状态默认启用
if (device.getStatus() == null) {
device.setStatus(1);
}
boolean saved = this.save(device);
if (!saved) {
log.error("新增设备失败, sn: {}", device.getSerialno());
}
return saved;
}
@Override
public boolean deleteSn(String sn) {
return false;
return false;
}
private PushSendParam getSinglePushSendParam(String sn, String type, String title, String content) {