| | |
| | | try { |
| | | // 1. 检查已存在的无人机盒子 |
| | | List<ArdDroneInfo> existingDrones = getExistingDrones(boxSn); |
| | | // 1.1 新增时不能添加重复的 |
| | | checkDuplicateBox(existingDrones, boxSn); |
| | | // 2. 授权数量验证 |
| | | validateAuthorization(existingDrones.size(), boxSn.length); |
| | | // 3. 获取并组装新的无人机信息 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 检查是否有重复的盒子编码 |
| | | */ |
| | | private void checkDuplicateBox(List<ArdDroneInfo> existingDrone,String[] boxSn) { |
| | | Set<String> existingBoxSnSet = new HashSet<>(); |
| | | for (ArdDroneInfo droneInfo : existingDrone) { |
| | | existingBoxSnSet.add(droneInfo.getBoxSn()); |
| | | } |
| | | |
| | | // 检查是否有重复的盒子编码 |
| | | List<String> duplicateBoxSns = new ArrayList<>(); |
| | | for (String sn : boxSn) { |
| | | if (existingBoxSnSet.contains(sn)) { |
| | | duplicateBoxSns.add(sn); |
| | | } |
| | | } |
| | | |
| | | if (!duplicateBoxSns.isEmpty()) { |
| | | log.warn("存在重复的无人机盒子编码: {}", duplicateBoxSns); |
| | | throw new ServiceException("以下无人机盒子编码已存在: " + String.join(", ", duplicateBoxSns)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 验证授权数量 |
| | | */ |
| | | private void validateAuthorization(int existingCount, int newCount) { |