Jelajahi Sumber

航次管理-增加预定人数

jinch 1 Minggu lalu
induk
melakukan
b44a09d036

+ 18 - 0
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/controller/admin/voyage/VoyageController.java

@@ -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);
     }

+ 6 - 0
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/controller/admin/voyage/vo/VoyageRespVO.java

@@ -148,4 +148,10 @@ public class VoyageRespVO {
     private Integer direction;
 
     private Integer isLock;
+
+    /**
+     * 预定人数
+     */
+    @Schema(description = "预定人数")
+    private Integer bookingCount;
 }

+ 8 - 0
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/dal/mysql/voyage/VoyageMapper.java

@@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Param;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 航次管理 Mapper
@@ -104,4 +105,11 @@ public interface VoyageMapper extends BaseMapperX<VoyageDO> {
      * @return
      */
     List<AppVoyageDayRespVO> selectVoyageListByShipIdAndDate(@Param("shipId") Long shipId, @Param("date") String date);
+
+    /**
+     * 批量统计航次的预定人数
+     * @param voyageIds
+     * @return Map<voyageId, count>
+     */
+    List<Map<String, Object>> countBatchByVoyageIds(@Param("voyageIds") List<Long> voyageIds);
 }

+ 9 - 0
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/service/voyage/VoyageService.java

@@ -4,8 +4,10 @@ import com.yc.ship.framework.common.pojo.PageResult;
 import com.yc.ship.module.product.controller.admin.voyage.vo.*;
 import com.yc.ship.module.product.controller.app.voyage.vo.AppVoyageDayRespVO;
 import com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO;
+import org.apache.ibatis.annotations.Param;
 
 import javax.validation.Valid;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -96,4 +98,11 @@ public interface VoyageService {
     List<AppVoyageDayRespVO> getVoyageListByShipIdAndDate(Long shipId, String date);
 
     void updateLockVoyage(String id);
+
+    /**
+     * 统计航次的预定人数
+     * @param voyageIds
+     * @return
+     */
+    List<Map<String, Object>> countBatchByVoyageIds(@Param("voyageId") List<Long> voyageIds);
 }

+ 5 - 0
ship-module-product/ship-module-product-biz/src/main/java/com/yc/ship/module/product/service/voyage/VoyageServiceImpl.java

@@ -446,4 +446,9 @@ public class VoyageServiceImpl implements VoyageService {
         log.info("航次: {}, {}完成 ...", id, (voyageDO.getIsLock().intValue() == 0 ? "解锁" : "锁定"));
     }
 
+    @Override
+    public List<Map<String, Object>> countBatchByVoyageIds(List<Long> voyageIds) {
+        return voyageMapper.countBatchByVoyageIds(voyageIds);
+    }
+
 }

+ 15 - 0
ship-module-product/ship-module-product-biz/src/main/resources/mapper/voyage/VoyageMapper.xml

@@ -55,4 +55,19 @@
          and w.shelf_status = 1
         order by w.start_time asc
     </select>
+
+
+    <select id="countBatchByVoyageIds" resultType="java.util.HashMap">
+        select b.voyage_id voyageId, count(tv.id) as count
+        from trade_visitor tv
+        join trade_order b on tv.order_id = b.id and b.deleted = 0
+        where b.voyage_id in
+        <foreach collection="voyageIds" item="voyageId" open="(" separator="," close=")">
+            #{voyageId}
+        </foreach>
+        and tv.deleted = 0
+        and b.order_status = 6
+        group by b.voyage_id
+    </select>
+
 </mapper>

TEMPAT SAMPAH
ship-module-trade/ship-module-trade-biz/src/main/resources/templates/tourist_template_agent.xlsx


TEMPAT SAMPAH
ship-module-trade/ship-module-trade-biz/src/main/resources/templates/tourist_template_operator.xlsx