From d8e3e8a0e8f66ddc64974ff3e256ca9df1a58a8c Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期三, 20 五月 2026 14:07:37 +0800
Subject: [PATCH] 1.处理后台巡游打卡计划多个用户选择 2.处理对接发票字段新增 3.后台巡游打卡计划新增编辑功能

---
 xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpCruiseCheckInRuleServiceImpl.java |   65 ++++++++++++++++++++++++++++++--
 1 files changed, 60 insertions(+), 5 deletions(-)

diff --git a/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpCruiseCheckInRuleServiceImpl.java b/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpCruiseCheckInRuleServiceImpl.java
index 2a54996..6f18e7d 100644
--- a/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpCruiseCheckInRuleServiceImpl.java
+++ b/xp-robotaxi-maintenance-boot/src/main/java/com/xiaopeng/maintenance/service/impl/XpCruiseCheckInRuleServiceImpl.java
@@ -40,6 +40,7 @@
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
@@ -313,9 +314,7 @@
             throw new ServiceException("巡游打卡规则名称已存在");
         }
         // 校验同一运维人员是否已存在有效规则(未删除且非循环模式或时间在有效期内)
-        long count = this.count(new LambdaQueryWrapper<XpCruiseCheckInRule>()
-                .eq(XpCruiseCheckInRule::getOperationsUserId, dto.getRelationId())
-                .eq(XpCruiseCheckInRule::getDeleted, false));
+        long count = countByAnyOperationsUserId(dto.getRelationId(), null);
         if (count > 0) {
             throw new ServiceException("该运维人员已存在有效的巡游打卡规则");
         }
@@ -325,6 +324,36 @@
         xpCruiseCheckInRule.setDeleted(false);
         xpCruiseCheckInRule.setOperationsUserId(dto.getRelationId());
         this.save(xpCruiseCheckInRule);
+        dto.getPoints().forEach(s->{
+            s.setCruiseCheckInRuleId(xpCruiseCheckInRule.getId());
+        });
+        xpCruiseCheckInRuleLocationService.saveBatch(dto.getPoints());
+    }
+
+
+    /**
+     * 编辑巡游打卡规则
+     * @param dto
+     */
+    @Override
+    public void updateXpCruiseCheckInRule(XpCruiseCheckInRuleDto dto) {
+        XpCruiseCheckInRule one = this.getOne(new QueryWrapper<XpCruiseCheckInRule>().like("name", dto.getName()).ne("id", dto.getId()).eq("is_deleted", 0));
+        if(null != one){
+            throw new ServiceException("巡游打卡规则名称已存在");
+        }
+        // 校验同一运维人员是否已存在有效规则(未删除且非循环模式或时间在有效期内)
+        long count = countByAnyOperationsUserId(dto.getRelationId(), dto.getId());
+        if (count > 0) {
+            throw new ServiceException("该运维人员已存在有效的巡游打卡规则");
+        }
+
+        XpCruiseCheckInRule xpCruiseCheckInRule = new XpCruiseCheckInRule();
+        BeanUtils.copyProperties(dto, xpCruiseCheckInRule);
+        xpCruiseCheckInRule.setDeleted(false);
+        xpCruiseCheckInRule.setOperationsUserId(dto.getRelationId());
+        this.updateById(xpCruiseCheckInRule);
+        // 移除原来的id
+        xpCruiseCheckInRuleLocationService.remove(new LambdaQueryWrapper<XpCruiseCheckInRuleLocation>().eq(XpCruiseCheckInRuleLocation::getCruiseCheckInRuleId, xpCruiseCheckInRule.getId()));
         dto.getPoints().forEach(s->{
             s.setCruiseCheckInRuleId(xpCruiseCheckInRule.getId());
         });
@@ -353,10 +382,36 @@
 
         }).collect(Collectors.toList());
         info.setLocationList(collect);
-        XpOperationsUser xpOperationsUser = xpOperationsUserClient.queryById(byId.getOperationsUserId()).getData();
+        List<XpOperationsUser> xpOperationsUser = xpOperationsUserClient.queryByIds(byId.getOperationsUserId()).getData();
         if(null != xpOperationsUser){
-            info.setOperationsUser(xpOperationsUser.getNickName());
+            info.setOperationsUser(xpOperationsUser.stream().map(XpOperationsUser::getNickName).collect(Collectors.toList()));
         }
         return info;
     }
+
+    private long countByAnyOperationsUserId(String relationId, Integer excludeRuleId) {
+        if (StringUtils.isEmpty(relationId)) {
+            return 0;
+        }
+        List<String> relationIds = Arrays.stream(relationId.split(","))
+                .map(String::trim)
+                .filter(StringUtils::isNotEmpty)
+                .collect(Collectors.toList());
+        if (relationIds.isEmpty()) {
+            return 0;
+        }
+
+        LambdaQueryWrapper<XpCruiseCheckInRule> queryWrapper = new LambdaQueryWrapper<XpCruiseCheckInRule>()
+                .eq(XpCruiseCheckInRule::getDeleted, false)
+                .and(wrapper -> {
+                    wrapper.apply("find_in_set({0}, operations_user_id)", relationIds.get(0));
+                    for (int i = 1; i < relationIds.size(); i++) {
+                        wrapper.or().apply("find_in_set({0}, operations_user_id)", relationIds.get(i));
+                    }
+                });
+        if (excludeRuleId != null) {
+            queryWrapper.ne(XpCruiseCheckInRule::getId, excludeRuleId);
+        }
+        return this.count(queryWrapper);
+    }
 }

--
Gitblit v1.7.1