|
|
@@ -28,8 +28,10 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.yc.ship.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
import static com.yc.ship.framework.common.pojo.CommonResult.success;
|
|
|
@@ -103,6 +105,18 @@ public class VoyageController {
|
|
|
PageResult<VoyageDO> pageResult = voyageService.getVoyagePage(pageReqVO);
|
|
|
PageResult<VoyageRespVO> page = BeanUtils.toBean(pageResult, VoyageRespVO.class);
|
|
|
List<VoyageRespVO> list = page.getList();
|
|
|
+
|
|
|
+ // 批量查询预定人数
|
|
|
+ List<Long> voyageIds = CollectionUtils.convertList(list, VoyageRespVO::getId);
|
|
|
+ Map<Long, Integer> bookingCountMap = new HashMap<>();;
|
|
|
+ if (!voyageIds.isEmpty()) {
|
|
|
+ bookingCountMap = voyageService.countBatchByVoyageIds(voyageIds).stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ countMap -> (Long) countMap.get("voyageId"),
|
|
|
+ countMap -> countMap.get("count") != null ? ((Number) countMap.get("count")).intValue() : 0
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
List<Long> shipIds = CollectionUtils.convertList(list, VoyageRespVO::getShipId);
|
|
|
List<ResourceShipDO> shipList = shipService.getList(shipIds);
|
|
|
Map<Long, ResourceShipDO> shipDoMap = CollectionUtils.convertMap(shipList, ResourceShipDO::getId);
|
|
|
@@ -110,9 +124,13 @@ public class VoyageController {
|
|
|
List<Long> routeIds = CollectionUtils.convertList(list, VoyageRespVO::getRouteId);
|
|
|
List<ResourceRouteDO> routeList = routeService.getList(routeIds);
|
|
|
Map<Long, ResourceRouteDO> routeDoMap = CollectionUtils.convertMap(routeList, ResourceRouteDO::getId);
|
|
|
+ Map<Long, Integer> finalBookingCountMap = bookingCountMap;
|
|
|
list.forEach(item -> {
|
|
|
MapUtils.findAndThen(shipDoMap, item.getShipId(), shipDO -> item.setShipName(shipDO.getName()));
|
|
|
MapUtils.findAndThen(routeDoMap, item.getRouteId(), routeDO -> item.setRouteName(routeDO.getName()));
|
|
|
+
|
|
|
+ // 从批量查询的 Map 中获取预定人数
|
|
|
+ item.setBookingCount(finalBookingCountMap.getOrDefault(item.getId(), 0));
|
|
|
});
|
|
|
return success(page);
|
|
|
}
|