| | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.google.common.collect.ImmutableMap; |
| | | import com.xiaopeng.api.dto.account.GetUserCouponDto; |
| | | import com.xiaopeng.api.dto.account.UseUserCouponDto; |
| | | import com.xiaopeng.api.dto.account.UserResourcesDto; |
| | | import com.xiaopeng.api.dto.automaticPilot.PushOrderDto; |
| | | import com.xiaopeng.api.dto.operation.LonLatDto; |
| | | import com.xiaopeng.api.dto.order.GetOrderNumDto; |
| | |
| | | import com.xiaopeng.api.dto.statistics.OrderStatisticsDTO; |
| | | import com.xiaopeng.api.dto.statistics.StatisticsQueryDTO; |
| | | import com.xiaopeng.api.dto.vehicleConvoy.BaseVehicleUserDto; |
| | | import com.xiaopeng.api.feignClient.account.UserResourcesClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserClient; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; |
| | | import com.xiaopeng.api.feignClient.automaticPilot.OrderMissionClient; |
| | |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleet; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpVehicle; |
| | | import com.xiaopeng.api.vo.OrderType; |
| | | import com.xiaopeng.api.vo.account.GetUserListByUidsVo; |
| | | import com.xiaopeng.api.vo.account.UserCouponVo; |
| | | import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.OrderOperationType; |
| | | import com.xiaopeng.api.vo.operation.RouteVo; |
| | |
| | | import com.xiaopeng.api.vo.vehicleConvoy.AddTaxiPassengerVo; |
| | | import com.xiaopeng.api.vo.vehicleConvoy.CancelTaxiPassengerVo; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.constant.HttpStatus; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.enums.OrderStatusEnum; |
| | | import com.xiaopeng.common.core.enums.PushMessageTypeEnum; |
| | |
| | | @RequiredArgsConstructor(onConstructor_ = @Lazy) |
| | | public class XpOrderServiceImpl extends ServiceImpl<XpOrderMapper, XpOrder> implements IXpOrderService { |
| | | |
| | | private final XpAppUserClient xpAppUserClient; |
| | | private final UserResourcesClient userResourcesClient; |
| | | private final XpPointClient xpPointClient; |
| | | private final XpVehicleClient xpVehicleClient; |
| | | private final XpAppUserCouponClient xpAppUserCouponClient; |
| | |
| | | } |
| | | |
| | | // 4. 批量查询关联数据 |
| | | Map<Long, XpAppUser> userMap = batchGetUsers(userIds); |
| | | JSONObject jsonObject = batchGetUsers(userIds); |
| | | Map<Long, XpVehicle> vehicleMap = batchGetVehicles(vehicleIds); |
| | | Map<Long, XpFleet> fleetMap = batchGetFleets(fleetIds); |
| | | |
| | | // 5. 组装 VO |
| | | List<XpOrderPageVO> voList = pageResult.getRecords().stream() |
| | | .map(order -> convertToPageVO(order, userMap, vehicleMap, fleetMap)) |
| | | .map(order -> convertToPageVO(order, jsonObject, vehicleMap, fleetMap)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 6. 返回分页结果 |
| | |
| | | |
| | | // 3. 获取用户信息 |
| | | if (Objects.nonNull(order.getAppUserId())) { |
| | | Map<Long, XpAppUser> userMap = batchGetUsers(Collections.singleton(order.getAppUserId())); |
| | | XpAppUser user = userMap.get(order.getAppUserId()); |
| | | if (Objects.nonNull(user)) { |
| | | vo.setNickName(user.getNickName()); |
| | | vo.setPhoneNumber(user.getPhoneNumber()); |
| | | JSONObject jsonObject = batchGetUsers(Collections.singleton(order.getAppUserId())); |
| | | JSONObject userInfo = jsonObject.getJSONObject(order.getAppUserId().toString()); |
| | | if (Objects.nonNull(userInfo)) { |
| | | vo.setNickName(userInfo.getString("nickName")); |
| | | vo.setPhoneNumber(userInfo.getString("mobile")); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | // 4. 批量查询关联数据 |
| | | Map<Long, XpAppUser> userMap = batchGetUsers(userIds); |
| | | JSONObject jsonObject = batchGetUsers(userIds); |
| | | Map<Long, XpVehicle> vehicleMap = batchGetVehicles(vehicleIds); |
| | | Map<Long, XpFleet> fleetMap = batchGetFleets(fleetIds); |
| | | |
| | | // 5. 组装 VO |
| | | return orderList.stream() |
| | | .map(order -> convertToPageVO(order, userMap, vehicleMap, fleetMap)) |
| | | .map(order -> convertToPageVO(order, jsonObject, vehicleMap, fleetMap)) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 批量获取用户信息 |
| | | */ |
| | | private Map<Long, XpAppUser> batchGetUsers(Set<Long> userIds) { |
| | | private JSONObject batchGetUsers(Set<Long> userIds) { |
| | | if (CollectionUtils.isEmpty(userIds)) { |
| | | return new HashMap<>(); |
| | | return new JSONObject(); |
| | | } |
| | | try { |
| | | R<List<XpAppUser>> result = xpAppUserClient.listByIds(new ArrayList<>(userIds)); |
| | | if (Objects.nonNull(result) && Objects.nonNull(result.getData())) { |
| | | return result.getData().stream() |
| | | .collect(Collectors.toMap(XpAppUser::getId, Function.identity(), (a, b) -> a)); |
| | | GetUserListByUidsVo getUserListByUidsVo = new GetUserListByUidsVo(); |
| | | getUserListByUidsVo.setUids(new ArrayList<>(userIds)); |
| | | getUserListByUidsVo.setGetPreCarOwner(Boolean.TRUE); |
| | | UserResourcesDto userListByUids = userResourcesClient.getUserListByUids(getUserListByUidsVo); |
| | | if (userListByUids.getCode().equals(HttpStatus.SUCCESS)) { |
| | | return JSONObject.parseObject(userListByUids.getData().toString()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("批量获取用户信息失败: {}", e.getMessage()); |
| | | } |
| | | return new HashMap<>(); |
| | | return new JSONObject(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 转换为分页列表 VO |
| | | */ |
| | | private XpOrderPageVO convertToPageVO(XpOrder order, |
| | | Map<Long, XpAppUser> userMap, |
| | | JSONObject jsonObject, |
| | | Map<Long, XpVehicle> vehicleMap, |
| | | Map<Long, XpFleet> fleetMap) { |
| | | XpOrderPageVO vo = new XpOrderPageVO(); |
| | |
| | | vo.setStatus(order.getStatus()); |
| | | |
| | | // 用户信息 |
| | | if (Objects.nonNull(order.getAppUserId()) && userMap.containsKey(order.getAppUserId())) { |
| | | XpAppUser user = userMap.get(order.getAppUserId()); |
| | | vo.setNickName(user.getNickName()); |
| | | vo.setPhoneNumber(user.getPhoneNumber()); |
| | | if (Objects.nonNull(order.getAppUserId()) && jsonObject.containsKey(order.getAppUserId().toString())) { |
| | | JSONObject userInfo = jsonObject.getJSONObject(order.getAppUserId().toString()); |
| | | vo.setNickName(userInfo.getString("nickName")); |
| | | vo.setPhoneNumber(userInfo.getString("mobile")); |
| | | } |
| | | |
| | | // 车辆信息 |