Просмотр исходного кода

fix: allow device creation before site binding

Sheep 1 неделя назад
Родитель
Сommit
01394bbaee

+ 11 - 8
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/controller/AppDeviceController.java

@@ -87,18 +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("设备已存在!");
 		}
-		appDevice.setOrgCode(appSite.getOrgCode());
+		if (appDevice.getSiteId() != null && !appDevice.getSiteId().isEmpty()) {
+			AppSite appSite = appSiteMapper.selectById(appDevice.getSiteId());
+			if (appSite == null || appSite.getOrgCode() == null || appSite.getOrgCode().isEmpty()) {
+				return Result.error("设备所属场地不存在或未配置机构编码!");
+			}
+			appDevice.setOrgCode(appSite.getOrgCode());
+		} else {
+			// 管理端流程为先录入设备编码,再从列表绑定场地。
+			appDevice.setSiteId(null);
+			appDevice.setOrgCode(null);
+		}
 		if (!AppDeviceService.save(appDevice)) {
 			return Result.error("设备添加失败!");
 		}