|
|
@@ -87,11 +87,21 @@ public class AppDeviceController extends JeecgController<AppDevice, IAppDeviceSe
|
|
|
@PostMapping(value = "/add")
|
|
|
@Transactional
|
|
|
public Result<String> add(@RequestBody AppDevice appDevice) {
|
|
|
+ if (appDevice.getSiteId() == null || appDevice.getSiteId().isEmpty()) {
|
|
|
+ return Result.error("请选择设备所属场地!");
|
|
|
+ }
|
|
|
+ AppSite appSite = appSiteMapper.selectById(appDevice.getSiteId());
|
|
|
+ if (appSite == null || appSite.getOrgCode() == null || appSite.getOrgCode().isEmpty()) {
|
|
|
+ return Result.error("设备所属场地不存在或未配置机构编码!");
|
|
|
+ }
|
|
|
if (AppDeviceService.getOne(Wrappers.<AppDevice>lambdaQuery()
|
|
|
.eq(AppDevice::getDeviceSerial, appDevice.getDeviceSerial())) != null) {
|
|
|
return Result.error("设备已存在!");
|
|
|
}
|
|
|
- AppDeviceService.save(appDevice);
|
|
|
+ appDevice.setOrgCode(appSite.getOrgCode());
|
|
|
+ if (!AppDeviceService.save(appDevice)) {
|
|
|
+ return Result.error("设备添加失败!");
|
|
|
+ }
|
|
|
return Result.OK("添加成功!");
|
|
|
}
|
|
|
|