| | |
| | | * @return 成功插入的记录数 |
| | | */ |
| | | @Override |
| | | public int insertArdDroneLs(String[] boxSn, Long deptId) { |
| | | public int insertArdDroneLs(String[] boxSn,Long deptId,String serverId) { |
| | | // 参数校验 |
| | | if (boxSn == null || boxSn.length == 0) { |
| | | log.warn("传入的盒子编码为空"); |
| | |
| | | try { |
| | | // 1. 检查已存在的无人机盒子 |
| | | List<ArdDroneInfo> existingDrones = getExistingDrones(boxSn); |
| | | // 1.1 新增时不能添加重复的 |
| | | // 1.1 新增时不能添加重复的boxSn |
| | | checkDuplicateBox(existingDrones, boxSn); |
| | | // 2. 授权数量验证 |
| | | validateAuthorization(existingDrones.size(), boxSn.length); |
| | | // 3. 获取并组装新的无人机信息 |
| | | List<ArdDroneInfo> newDrones = assembleNewDrones(boxSn, deptId); |
| | | List<ArdDroneInfo> newDrones = assembleNewDrones(boxSn,deptId,serverId); |
| | | // 4. 批量插入 |
| | | return batchInsertDrones(newDrones); |
| | | } catch (Exception e) { |
| | |
| | | /** |
| | | * 组装新的无人机信息 |
| | | */ |
| | | private List<ArdDroneInfo> assembleNewDrones(String[] boxSn, Long deptId) { |
| | | private List<ArdDroneInfo> assembleNewDrones(String[] boxSn,Long deptId,String serverId) { |
| | | List<BoxInfoReceiver> allBoxes = tyService.getBoxList(); |
| | | Set<String> targetBoxSnSet = new HashSet<>(Arrays.asList(boxSn)); |
| | | return allBoxes.stream() |
| | | .filter(box -> targetBoxSnSet.contains(box.getBoxSn())) |
| | | .map(box -> createDroneInfo(box, deptId)) |
| | | .map(box -> createDroneInfo(box, deptId, serverId)) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | /** |
| | | * 创建无人机信息对象 |
| | | */ |
| | | private ArdDroneInfo createDroneInfo(BoxInfoReceiver box, Long deptId) { |
| | | private ArdDroneInfo createDroneInfo(BoxInfoReceiver box, Long deptId ,String serverId) { |
| | | ArdDroneInfo drone = new ArdDroneInfo(); |
| | | drone.setId(IdUtils.simpleUUID()); |
| | | drone.setBoxSn(box.getBoxSn()); |
| | |
| | | drone.setVideoPort(box.getVideoPort()); |
| | | drone.setLastTaskId(box.getLastTaskId()); |
| | | drone.setDeptId(deptId); |
| | | |
| | | // 设置创建信息和更新信息 |
| | | setCreateAndUpdateInfo(drone); |
| | | |
| | | drone.setCreateTime(new Date()); |
| | | drone.setUpdateTime(new Date()); |
| | | drone.setServerId(serverId); |
| | | drone.setBoxVersion(box.getBoxVersion()); |
| | | return drone; |
| | | } |
| | | |
| | | /** |
| | | * 设置创建和更新信息 |
| | | */ |
| | | private void setCreateAndUpdateInfo(ArdDroneInfo drone) { |
| | | Date currentTime = new Date(); |
| | | drone.setCreateTime(currentTime); |
| | | drone.setUpdateTime(currentTime); |
| | | } |
| | | |
| | | /** |
| | | * 批量插入无人机信息 |