|
|
@@ -4,7 +4,7 @@ import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
-import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.kym.common.annotation.DynamicCache;
|
|
|
import com.kym.common.enums.EnPlusApi;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
|
@@ -20,6 +20,7 @@ import com.kym.entity.enplus.EnEquipmentInfo;
|
|
|
import com.kym.entity.enplus.EnStationStatsInfo;
|
|
|
import com.kym.entity.enplus.EnStationStatusInfo;
|
|
|
import com.kym.mapper.admin.StationMapper;
|
|
|
+import com.kym.service.MyBaseServiceImpl;
|
|
|
import com.kym.service.admin.ConnectorInfoService;
|
|
|
import com.kym.service.admin.EquipmentInfoService;
|
|
|
import com.kym.service.admin.EquipmentRelationService;
|
|
|
@@ -49,7 +50,7 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@DS("db-admin")
|
|
|
@Slf4j
|
|
|
-public class StationServiceImpl extends MPJBaseServiceImpl<StationMapper, Station> implements StationService {
|
|
|
+public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station> implements StationService {
|
|
|
|
|
|
private final EnPlusService enPlusService;
|
|
|
private final EquipmentInfoService equipmentInfoService;
|
|
|
@@ -146,60 +147,59 @@ public class StationServiceImpl extends MPJBaseServiceImpl<StationMapper, Statio
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void pullEnStationInfos() {
|
|
|
- var stationVoList = queryStationInfo(1, 1000);
|
|
|
- var stationList = new ArrayList<Station>();
|
|
|
+ public void pullEnStationInfos(String stationId) {
|
|
|
+ // 指定的站点信息
|
|
|
+ var stationVo = queryStationInfo(1, 1000).stream().filter(vo -> stationId.equals(vo.getStationId())).findFirst().orElse(null);
|
|
|
+
|
|
|
+ var station = new Station();
|
|
|
var equipmentList = new ArrayList<EquipmentInfo>();
|
|
|
var connectorList = new ArrayList<ConnectorInfo>();
|
|
|
- stationVoList.forEach(vo -> {
|
|
|
- if (!vo.getEquipmentInfos().isEmpty()) {
|
|
|
- vo.getEquipmentInfos().forEach(item -> {
|
|
|
- // 桩体
|
|
|
- var equipment = new EquipmentInfo()
|
|
|
- .setStationId(vo.getStationId())
|
|
|
- .setShortId(item.getShortId())
|
|
|
- .setPower(item.getConnectorInfos().get(0).getPower());
|
|
|
- BeanUtils.copyProperties(item, equipment);
|
|
|
- equipmentList.add(equipment);
|
|
|
- // 枪
|
|
|
- var connectorInfos = item.getConnectorInfos();
|
|
|
- if (!CommUtil.isEmptyOrNull(connectorInfos)) {
|
|
|
- connectorInfos.forEach(connector -> {
|
|
|
- var connectorInfo = new ConnectorInfo();
|
|
|
- BeanUtils.copyProperties(connector, connectorInfo);
|
|
|
- connectorList.add(connectorInfo);
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- equipmentList.sort(Comparator.comparing(EquipmentInfo::getShortId));
|
|
|
- }
|
|
|
- var station = new Station();
|
|
|
- BeanUtils.copyProperties(vo, station);
|
|
|
- stationList.add(station);
|
|
|
- });
|
|
|
- // 查询已存在的站点,只更新新增的站点和设备
|
|
|
- var stations = list().stream().map(Station::getStationId).toList();
|
|
|
- var equipments = equipmentInfoService.list().stream().map(EquipmentInfo::getEquipmentId).toList();
|
|
|
- var connectors = connectorInfoService.list().stream().map(ConnectorInfo::getConnectorId).toList();
|
|
|
|
|
|
- // 新增的数据
|
|
|
- var newStations = stationList.stream().filter(station -> !stations.contains(station.getStationId())).toList();
|
|
|
- var newEquipmentInfos = equipmentList.stream().filter(equipmentInfo -> !equipments.contains(equipmentInfo.getEquipmentId())).toList();
|
|
|
- var newConnectors = connectorList.stream().filter(connector -> !connectors.contains(connector.getConnectorId())).toList();
|
|
|
+ // 组装数据
|
|
|
+ assert stationVo != null;
|
|
|
+ if (!stationVo.getEquipmentInfos().isEmpty()) {
|
|
|
+ stationVo.getEquipmentInfos().forEach(item -> {
|
|
|
+ // 桩体
|
|
|
+ var equipment = new EquipmentInfo()
|
|
|
+ .setStationId(stationVo.getStationId())
|
|
|
+ .setShortId(item.getShortId())
|
|
|
+ .setPower(item.getConnectorInfos().get(0).getPower());
|
|
|
+ BeanUtils.copyProperties(item, equipment);
|
|
|
+ equipmentList.add(equipment);
|
|
|
+ // 枪
|
|
|
+ var connectorInfos = item.getConnectorInfos();
|
|
|
+ if (!CommUtil.isEmptyOrNull(connectorInfos)) {
|
|
|
+ connectorInfos.forEach(connector -> {
|
|
|
+ var connectorInfo = new ConnectorInfo();
|
|
|
+ BeanUtils.copyProperties(connector, connectorInfo);
|
|
|
+ connectorList.add(connectorInfo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ equipmentList.sort(Comparator.comparing(EquipmentInfo::getShortId));
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(stationVo, station);
|
|
|
+
|
|
|
+ // 更新站点信息
|
|
|
+ updateByQueryWrapper(station, s -> new QueryWrapper<Station>().eq("station_id", station.getStationId()));
|
|
|
+
|
|
|
+ // 更新设备信息
|
|
|
+ equipmentInfoService.updateBatchByQueryWrapper(equipmentList, equipmentInfo ->
|
|
|
+ new QueryWrapper<EquipmentInfo>().eq("equipment_id", equipmentInfo.getEquipmentId()));
|
|
|
+
|
|
|
+ // 更新枪信息
|
|
|
+ connectorInfoService.updateBatchByQueryWrapper(connectorList, connectorInfo ->
|
|
|
+ new QueryWrapper<ConnectorInfo>().eq("connector_id", connectorInfo.getConnectorId()));
|
|
|
|
|
|
// 将充电站相关数据写入KymCache
|
|
|
// 手动切换数据源
|
|
|
DynamicDataSourceContextHolder.push("db-admin");
|
|
|
- KymCache.INSTANCE.putStationId2Name(newStations.stream().collect(Collectors.toMap(Station::getStationId, Station::getStationName)));
|
|
|
-// KymCache.INSTANCE.putConnectorId2ParkingNo(newEquipmentInfos.stream().collect(Collectors.toMap(equipmentInfo -> equipmentInfo.getEquipmentId().concat("1"), EquipmentInfo::getParkingNo?)));
|
|
|
+ KymCache.INSTANCE.putStationId2Name(Map.of(stationVo.getStationId(), stationVo.getStationName()));
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
|
|
|
- // 新数据写入数据库
|
|
|
- saveBatch(newStations);
|
|
|
- equipmentInfoService.saveBatch(newEquipmentInfos);
|
|
|
- connectorInfoService.saveBatch(newConnectors);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void modifyStation(Station station) {
|