|
|
@@ -1,10 +1,8 @@
|
|
|
package com.kym.service.admin.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.alibaba.fastjson2.JSONReader;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.kym.common.enums.EnPlusApi;
|
|
|
import com.kym.common.utils.AESUtil;
|
|
|
import com.kym.entity.admin.Station;
|
|
|
@@ -16,6 +14,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -28,6 +27,7 @@ import java.util.List;
|
|
|
* @since 2023-08-12
|
|
|
*/
|
|
|
@Service
|
|
|
+@DS("db-admin")
|
|
|
public class StationServiceImpl extends ServiceImpl<StationMapper, Station> implements StationService {
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(StationServiceImpl.class);
|
|
|
@@ -45,13 +45,8 @@ public class StationServiceImpl extends ServiceImpl<StationMapper, Station> impl
|
|
|
}
|
|
|
""".formatted(pageNum, pageSize);
|
|
|
var response = enPlusService.enPlusPost(EnPlusApi.EN_PLUS_QUERY_STATION_INFO.getApi(), enPlusService.buildParams(param));
|
|
|
- // TODO: 2023-08-12 包装成自己的数据格式
|
|
|
var enStations = JSONObject.parseObject(AESUtil.decrypt(response.getData()));
|
|
|
-
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
-// var station = mapper.convertValue(enStations.get("StationInfos"), List<Station>.class);
|
|
|
- var stations = JSONArray.parseArray(enStations.get("StationInfos").toString(), Station.class);
|
|
|
- return stations;
|
|
|
+ return enStations.getJSONArray("StationInfos").toJavaList(Station.class);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -64,9 +59,8 @@ public class StationServiceImpl extends ServiceImpl<StationMapper, Station> impl
|
|
|
}
|
|
|
""".formatted(String.join("\",\"", ids));
|
|
|
var response = enPlusService.enPlusPost(EnPlusApi.EN_PLUS_QUERY_STATION_STATUS.getApi(), enPlusService.buildParams(param));
|
|
|
- // TODO: 2023-08-12 包装成自己的数据格式
|
|
|
var enStationStatus = JSONObject.parseObject(AESUtil.decrypt(response.getData()));
|
|
|
- return enStationStatus.getJSONArray("StationStatusInfos").toJavaList(StationStatusInfo.class, JSONReader.Feature.SupportArrayToBean);
|
|
|
+ return enStationStatus.getJSONArray("StationStatusInfos").toJavaList(StationStatusInfo.class);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -83,4 +77,13 @@ public class StationServiceImpl extends ServiceImpl<StationMapper, Station> impl
|
|
|
return JSONObject.parseObject(AESUtil.decrypt(response.getData()));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 拉取EN+充电站信息数据并更新本地服务器数据
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void pullEnStationInfos() {
|
|
|
+ saveOrUpdateBatch(queryStationInfo(1, 1000));
|
|
|
+ }
|
|
|
+
|
|
|
}
|