| | |
| | | package com.ard.tianyu.service.impl; |
| | | |
| | | import com.ard.common.utils.DateUtils; |
| | | import com.ard.tianyu.domain.entity.UavBox; |
| | | import com.ard.tianyu.domain.entity.UavBoxEntity; |
| | | import com.ard.tianyu.domain.receiver.BoxInfoReceiver; |
| | | import com.ard.tianyu.mapper.UavBoxMapper; |
| | | import com.ard.tianyu.service.ITyService; |
| | |
| | | * @return 无人机盒子 |
| | | */ |
| | | @Override |
| | | public UavBox selectUavBoxById(Long id) { |
| | | public UavBoxEntity selectUavBoxById(Long id) { |
| | | return uavBoxMapper.selectUavBoxById(id); |
| | | } |
| | | |
| | | /** |
| | | * 查询无人机盒子列表 |
| | | * |
| | | * @param uavBox 无人机盒子 |
| | | * @param uavBoxEntity 无人机盒子 |
| | | * @return 无人机盒子 |
| | | */ |
| | | @Override |
| | | public List<UavBox> selectUavBoxList(UavBox uavBox) { |
| | | return uavBoxMapper.selectUavBoxList(uavBox); |
| | | public List<UavBoxEntity> selectUavBoxList(UavBoxEntity uavBoxEntity) { |
| | | return uavBoxMapper.selectUavBoxList(uavBoxEntity); |
| | | } |
| | | |
| | | /** |
| | | * 新增无人机盒子 |
| | | * |
| | | * @param uavBox 无人机盒子 |
| | | * @param uavBoxEntity 无人机盒子 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int insertUavBox(UavBox uavBox) { |
| | | uavBox.setCreateTime(DateUtils.getNowDate()); |
| | | return uavBoxMapper.insertUavBox(uavBox); |
| | | public int insertUavBox(UavBoxEntity uavBoxEntity) { |
| | | uavBoxEntity.setCreateTime(DateUtils.getNowDate()); |
| | | return uavBoxMapper.insertUavBox(uavBoxEntity); |
| | | } |
| | | |
| | | /** |
| | | * 修改无人机盒子 |
| | | * |
| | | * @param uavBox 无人机盒子 |
| | | * @param uavBoxEntity 无人机盒子 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int updateUavBox(UavBox uavBox) { |
| | | uavBox.setUpdateTime(DateUtils.getNowDate()); |
| | | return uavBoxMapper.updateUavBox(uavBox); |
| | | public int updateUavBox(UavBoxEntity uavBoxEntity) { |
| | | uavBoxEntity.setUpdateTime(DateUtils.getNowDate()); |
| | | return uavBoxMapper.updateUavBox(uavBoxEntity); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void syncBoxInfo() { |
| | | List<UavBox> uavBoxeList = selectUavBoxList(new UavBox()); |
| | | List<UavBoxEntity> uavBoxeListEntity = selectUavBoxList(new UavBoxEntity()); |
| | | // 将本地列表转换为Map,方便快速查找 |
| | | Map<String, UavBox> localUavBoxMap = uavBoxeList.stream() |
| | | .collect(Collectors.toMap(UavBox::getBoxSn, drone -> drone)); |
| | | Map<String, UavBoxEntity> localUavBoxMap = uavBoxeListEntity.stream() |
| | | .collect(Collectors.toMap(UavBoxEntity::getBoxSn, drone -> drone)); |
| | | //遍历接口最新获取的无人机盒子信息 |
| | | tyService.getBoxList().forEach(remoteUavBox -> { |
| | | UavBox localUavBox = localUavBoxMap.get(remoteUavBox.getBoxSn()); |
| | | if (localUavBox != null) { |
| | | if (!localUavBox.isSameAs(remoteUavBox)) { |
| | | UavBoxEntity localUavBoxEntity = localUavBoxMap.get(remoteUavBox.getBoxSn()); |
| | | if (localUavBoxEntity != null) { |
| | | if (!localUavBoxEntity.isSameAs(remoteUavBox)) { |
| | | // 修改无人机(只更新变化的属性) |
| | | updateChangedAttributes(localUavBox, remoteUavBox); |
| | | updateUavBox(localUavBox); |
| | | updateChangedAttributes(localUavBoxEntity, remoteUavBox); |
| | | updateUavBox(localUavBoxEntity); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 更新变化的属性 |
| | | private void updateChangedAttributes(UavBox localBoxInfo, BoxInfoReceiver remoteUavBox) { |
| | | private void updateChangedAttributes(UavBoxEntity localBoxInfo, BoxInfoReceiver remoteUavBox) { |
| | | if (!Objects.equals(localBoxInfo.getBoxName(), remoteUavBox.getBoxName())) { |
| | | localBoxInfo.setBoxName(remoteUavBox.getBoxName()); |
| | | } |