|
|
@@ -5,17 +5,23 @@ 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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.kym.common.annotation.DynamicCache;
|
|
|
import com.kym.common.cache.PlatformCache;
|
|
|
import com.kym.common.exception.BusinessException;
|
|
|
import com.kym.common.utils.CommUtil;
|
|
|
+import com.kym.common.utils.GeodsyDistanceUtils;
|
|
|
import com.kym.common.utils.PlatformAesUtil;
|
|
|
import com.kym.common.utils.PlatformConvertUtil;
|
|
|
import com.kym.entity.admin.*;
|
|
|
import com.kym.entity.admin.queryParams.StationQueryParam;
|
|
|
+import com.kym.entity.admin.vo.DetailStationVo;
|
|
|
import com.kym.entity.admin.vo.LocalStationVo;
|
|
|
+import com.kym.entity.admin.vo.SimpleStationVo;
|
|
|
import com.kym.entity.admin.vo.StationVo;
|
|
|
+import com.kym.entity.common.PageBean;
|
|
|
import com.kym.entity.platform.PlatformStationStatsInfo;
|
|
|
import com.kym.entity.platform.PlatformStationStatusInfo;
|
|
|
import com.kym.entity.platform.response.PlatformResponse;
|
|
|
@@ -137,26 +143,128 @@ public class StationServiceImpl extends MyBaseServiceImpl<StationMapper, Station
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取缓存的 站点ID:桩信息 映射
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@DynamicCache(timeout = 15 * 60 * 1000L)
|
|
|
@Override
|
|
|
- public Map<String, List<EquipmentInfo>> getCachedEquipmentMap() {
|
|
|
- return equipmentInfoService.list().stream().collect(Collectors.groupingBy(EquipmentInfo::getStationId));
|
|
|
+ public Map<String, List<EquipmentInfo>> getCachedEquipmentMap(String... stationId) {
|
|
|
+ var list = equipmentInfoService.lambdaQuery().eq(CommUtil.isNotEmptyAndNull(stationId), EquipmentInfo::getStationId, stationId[0]).list();
|
|
|
+ return list.stream().collect(Collectors.groupingBy(EquipmentInfo::getStationId));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取缓存的 桩ID:枪信息 映射
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@DynamicCache(timeout = 15 * 60 * 1000L)
|
|
|
@Override
|
|
|
- public Map<String, List<ConnectorInfo>> getCachedConnectorMap() {
|
|
|
+ public Map<String, List<ConnectorInfo>> getCachedStationConnectorMap(String... stationId) {
|
|
|
+ var list = connectorInfoService.lambdaQuery().eq(CommUtil.isNotEmptyAndNull(stationId), ConnectorInfo::getStationId, stationId[0]).list();
|
|
|
+ return list.stream().collect(Collectors.groupingBy(ConnectorInfo::getStationId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取缓存的 桩ID:枪信息 映射
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @DynamicCache(timeout = 15 * 60 * 1000L)
|
|
|
+ @Override
|
|
|
+ public Map<String, List<ConnectorInfo>> getCachedStationConnectorMap() {
|
|
|
return connectorInfoService.list().stream().collect(Collectors.groupingBy(ConnectorInfo::getEquipmentId));
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * APP首页地图接口,传入经纬度,按照距离由远到近返回站点列表
|
|
|
+ *
|
|
|
+ * @param params
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DynamicCache
|
|
|
+ public PageBean<SimpleStationVo> listStationForApp(StationQueryParam params) {
|
|
|
+ PageHelper.startPage(params.getPageNum(), params.getPageSize());
|
|
|
+ // 站点列表
|
|
|
+ LambdaQueryWrapper<Station> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.select(Station::getStationId, Station::getStationName, Station::getAddress, Station::getLocation,
|
|
|
+ Station::getStationStatus, Station::getParkingNum, Station::getElectricityFee, Station::getServiceFee, Station::getParkFee);
|
|
|
+ var stationVoList = new ArrayList<SimpleStationVo>();
|
|
|
+ var stationList = list(queryWrapper);
|
|
|
+ for (var station : stationList) {
|
|
|
+ var simpleStationVo = new SimpleStationVo();
|
|
|
+ BeanUtils.copyProperties(station, simpleStationVo);
|
|
|
+ // 计算距离,单位m
|
|
|
+ simpleStationVo.setDistance(GeodsyDistanceUtils.getDistance(
|
|
|
+ station.getLocation().getDoubleValue("stationLng"),
|
|
|
+ station.getLocation().getDoubleValue("stationLat"),
|
|
|
+ params.getLongitude(),
|
|
|
+ params.getLatitude(),
|
|
|
+ 2));
|
|
|
+ stationVoList.add(simpleStationVo);
|
|
|
+ }
|
|
|
+ // 按照距离由近到远排序
|
|
|
+ stationVoList.sort(Comparator.comparing(SimpleStationVo::getDistance));
|
|
|
+
|
|
|
+ // 计算站点空闲数量
|
|
|
+ var stationIds = stationVoList.stream().map(SimpleStationVo::getStationId).toList();
|
|
|
+ var stationConnectorCountMap = connectorInfoService.lambdaQuery()
|
|
|
+ .in(ConnectorInfo::getStationId, stationIds)
|
|
|
+ .eq(ConnectorInfo::getStatus, EquipmentInfo.SERVICE_STATUS_空闲)
|
|
|
+ .list()
|
|
|
+ .stream().collect(Collectors.groupingBy(ConnectorInfo::getStationId, Collectors.counting()));
|
|
|
+
|
|
|
+ // 填充站点空闲数量
|
|
|
+ stationVoList.forEach(stationVo -> stationVo.setAvailableParkingNum(stationConnectorCountMap.getOrDefault(stationVo.getStationId(), 0L).intValue()));
|
|
|
+
|
|
|
+ // 查询正在进行中的活动和各站点正在进行中的活动 (限充值优惠和优惠券领取活动) todo 性能待优化
|
|
|
+ var rechargeRightsActivityList = activityService.lambdaQuery().eq(Activity::getStatus, Activity.STATUS_进行中).eq(Activity::getDiscountType, Activity.DISCOUNT_TYPE_服务费折扣权益).list();
|
|
|
+ var couponActivityList = activityService.getAvailableCouponActivities();
|
|
|
+ var activityList = Stream.concat(rechargeRightsActivityList.stream(), couponActivityList.stream()).toList();
|
|
|
+
|
|
|
+ if (CommUtil.isNotEmptyAndNull(activityList)) {
|
|
|
+ var station2ActivityListMap = activityStationService.lambdaQuery().eq(ActivityStation::getStatus, Activity.STATUS_进行中).list()
|
|
|
+ .stream().collect(Collectors.groupingBy(ActivityStation::getStationId));
|
|
|
+ var station2ActivityList = new HashMap<String, List<Activity>>();
|
|
|
+ station2ActivityListMap.forEach((k, v) -> station2ActivityList.put(k,
|
|
|
+ v.stream().map(item -> activityList.stream().filter(activity -> activity.getId().equals(item.getActivityId())).findFirst().orElse(null)).toList()));
|
|
|
+ stationVoList.forEach(vo -> vo.setActivityList(station2ActivityList.get(vo.getStationId())));
|
|
|
+ }
|
|
|
+
|
|
|
+ return new PageBean<>(stationVoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 站点详情
|
|
|
+ *
|
|
|
+ * @param stationId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public DetailStationVo stationInfo(String stationId) {
|
|
|
+ var station = lambdaQuery().eq(Station::getStationId, stationId).oneOpt();
|
|
|
+ return station.map(s -> {
|
|
|
+ var vo = new DetailStationVo();
|
|
|
+ BeanUtils.copyProperties(s, vo);
|
|
|
+ // 填充桩信息
|
|
|
+ vo.setConnectInfoList(getCachedStationConnectorMap(s.getStationId()).get(s.getStationId()));
|
|
|
+ return vo;
|
|
|
+ }).orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Deprecated
|
|
|
@Override
|
|
|
@DynamicCache
|
|
|
public List<LocalStationVo> queryLocalStationInfo(int pageNum, int pageSize) {
|
|
|
StationService proxy = (StationService) AopContext.currentProxy();
|
|
|
var stationList = list();
|
|
|
+ // 获取桩号等映射信息缓存
|
|
|
var equipmentInfoMap = proxy.getCachedEquipmentMap();
|
|
|
- var connectorInfoMap = proxy.getCachedConnectorMap();
|
|
|
+ var connectorInfoMap = proxy.getCachedStationConnectorMap();
|
|
|
|
|
|
var stationVoList = new ArrayList<LocalStationVo>();
|
|
|
for (var station : stationList) {
|