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

fix: bind door devices to site organization

Sheep 2 недель назад
Родитель
Сommit
825479667f

+ 8 - 1
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

@@ -1417,7 +1417,14 @@ public class OrderServiceImpl extends ServiceImpl<AppOrderMapper, AppOrder> impl
                     
                     // 使用解析到的日期范围更新门禁权限
                     if (earliestDate != null && latestDate != null) {
-                        for (AppDevice appDevice : appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery().eq(AppDevice::getOrgCode, appOrder.getOrgCode()))) {
+                        List<AppDevice> siteDevices = appDeviceMapper.selectList(Wrappers.<AppDevice>lambdaQuery()
+                                .eq(AppDevice::getSiteId, appOrderProInfo.getSiteId()));
+                        if (CollUtil.isEmpty(siteDevices)) {
+                            log.error("场地订单门禁下发失败:场地未配置设备,orderCode={}, siteId={}, orgCode={}",
+                                    appOrder.getOrderCode(), appOrderProInfo.getSiteId(), appOrder.getOrgCode());
+                            throw new JeecgBootException("场地未配置门禁设备,请联系管理员");
+                        }
+                        for (AppDevice appDevice : siteDevices) {
                             if (null != appDevice) {
                                 // 将LocalDate转换为Date类型,使用正午12:00避免时区问题
                                 Date startDate = Date.from(earliestDate.atTime(12, 0).atZone(ZoneId.systemDefault()).toInstant());

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

@@ -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("添加成功!");
 	}