Prechádzať zdrojové kódy

[feat]
接口自测与调整

limeng 2 mesiacov pred
rodič
commit
08af6125ff

+ 19 - 1
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/WebsiteProjectGroupPurchaseController.java

@@ -65,7 +65,12 @@ public class WebsiteProjectGroupPurchaseController {
 //        dto.setSuccess(0);
         TourProjectGroupPurchase tourProjectGroupPurchaseFilter = MyModelUtil.copyTo(dto, TourProjectGroupPurchase.class);
         MyOrderParam myOrderParam = new MyOrderParam();
-        myOrderParam.add(new MyOrderParam.OrderInfo("showOrder",true,null));
+        // 如果项目id不为空,说明是项目详情中进行查询的,那么按照出发时间正序排序,如果不为空,则是列表页查询的,按照设定的排序规则进行排序
+        if(dto.getProjectId() != null) {
+            myOrderParam.add(new MyOrderParam.OrderInfo("travelStartTime",true,null));
+        }else {
+            myOrderParam.add(new MyOrderParam.OrderInfo("showOrder",true,null));
+        }
         String orderBy = MyOrderParam.buildOrderBy(myOrderParam, TourProjectGroupPurchase.class);
         List<TourProjectGroupPurchase> tourProjectGroupPurchaseList =
                 tourProjectGroupPurchaseService.getTourProjectGroupPurchaseListWithRelation(tourProjectGroupPurchaseFilter, orderBy);
@@ -100,6 +105,7 @@ public class WebsiteProjectGroupPurchaseController {
         tourismDatePrice.setProjectId(tourProjectGroupPurchase.getProjectId().toString());
         tourismDatePrice.setDepartureDate(tourProjectGroupPurchase.getTravelStartTime());
         TourismDatePrice oneTourismDatePrice = tourismDatePriceService.getOneTourismDatePrice(tourismDatePrice);
+        // 如果无法查到对应天的拼团价格,则直接展示拼团初始价格
         if (oneTourismDatePrice == null) {
             tourProjectGroupPurchaseVo.setOriginalPrice(BigDecimal.ZERO);
         }else {
@@ -118,6 +124,8 @@ public class WebsiteProjectGroupPurchaseController {
 
     /**
      * 查询拼团成功的用户信息,并展示头像、用户昵称和拼团成功的时间
+     * @param projectId
+     * @return
      */
     @SaIgnore
     @GetMapping("/queryGroupPurchaseUser")
@@ -127,4 +135,14 @@ public class WebsiteProjectGroupPurchaseController {
         List<TourGroupPurchaseUserVo> tourGroupPurchaseUserVoList = MyModelUtil.copyCollectionTo(tourUserList, TourGroupPurchaseUserVo.class);
         return ResponseResult.success(tourGroupPurchaseUserVoList);
     }
+    /**
+     * 根据projectId和出发开始截止时间,查询有拼团活动的日期
+     */
+    @SaIgnore
+    @GetMapping("/queryGroupPurchaseDate")
+    public ResponseResult<List<String>> queryGroupPurchaseDate(TourProjectGroupPurchaseDtoToWebDto dto) {
+        List<String> dateList = tourProjectGroupPurchaseService.queryUniqueGroupPurchaseDates(dto);
+        return ResponseResult.success(dateList);
+    }
+
 }

+ 4 - 0
application-webadmin/src/main/java/com/tourism/webadmin/app/website/dto/TourProjectGroupPurchaseDtoToWebDto.java

@@ -7,6 +7,8 @@ import com.tourism.webadmin.back.model.constant.Enable;
 import io.swagger.v3.oas.annotations.media.Schema;
 import jakarta.validation.constraints.NotNull;
 import lombok.Data;
+import org.checkerframework.checker.formatter.qual.Format;
+import org.springframework.format.annotation.DateTimeFormat;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -47,6 +49,7 @@ public class TourProjectGroupPurchaseDtoToWebDto {
      * NOTE: 可支持等于操作符的列表数据过滤。
      */
     @Schema(description = "出行开始时间。可支持等于操作符的列表数据过滤。")
+//    @DateTimeFormat(pattern = "yyyy-MM-dd")
     private Date travelStartTime;
 
     /**
@@ -54,6 +57,7 @@ public class TourProjectGroupPurchaseDtoToWebDto {
      * NOTE: 可支持等于操作符的列表数据过滤。
      */
     @Schema(description = "出行结束时间。可支持等于操作符的列表数据过滤。")
+//    @DateTimeFormat(pattern = "yyyy-MM-dd")
     private Date travelEndTime;
 
     /**

+ 8 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/TourProjectGroupPurchaseService.java

@@ -1,5 +1,6 @@
 package com.tourism.webadmin.back.service;
 
+import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
 import com.tourism.webadmin.back.model.*;
 import com.tourism.common.core.object.CallResult;
 import com.tourism.common.core.base.service.IBaseService;
@@ -82,4 +83,11 @@ public interface TourProjectGroupPurchaseService extends IBaseService<TourProjec
      * @return
      */
     List<TourProjectGroupPurchase> getLowestPriceGroupPurchase(List<Long> projectIds);
+
+    /**
+     * 查询项目有团购的日期
+     * @param projectId
+     * @return
+     */
+    List<String> queryUniqueGroupPurchaseDates(TourProjectGroupPurchaseDtoToWebDto dto);
 }

+ 33 - 0
application-webadmin/src/main/java/com/tourism/webadmin/back/service/impl/TourProjectGroupPurchaseServiceImpl.java

@@ -1,7 +1,9 @@
 package com.tourism.webadmin.back.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.tourism.webadmin.app.website.dto.TourProjectGroupPurchaseDtoToWebDto;
 import com.tourism.webadmin.back.service.*;
 import com.tourism.webadmin.back.dao.*;
 import com.tourism.webadmin.back.model.*;
@@ -18,7 +20,9 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 拼团设置主表数据操作服务类。
@@ -128,6 +132,35 @@ public class TourProjectGroupPurchaseServiceImpl extends BaseService<TourProject
         return tourProjectGroupPurchaseMapper.getLowestPriceGroupPurchaseList(projectIds, endTime);
     }
 
+    @Override
+    public List<String> queryUniqueGroupPurchaseDates(TourProjectGroupPurchaseDtoToWebDto dto) {
+        LambdaQueryWrapper<TourProjectGroupPurchase> queryWrapper = new LambdaQueryWrapper<>();
+
+        // 查询条件:根据 project_id 和 end_time 筛选
+        queryWrapper.eq(TourProjectGroupPurchase::getProjectId, dto.getProjectId())
+                .eq(TourProjectGroupPurchase::getState, 1)  // 只查启用状态的记录
+//                .ne(TourProjectGroupPurchase::getDataState, -1)  // 排除已删除的记录
+                .ge(TourProjectGroupPurchase::getEndTime, new Date())
+                .ge(dto.getTravelStartTimeStart() != null, TourProjectGroupPurchase::getTravelStartTime, dto.getTravelStartTimeStart())
+                .le(dto.getTravelStartTimeEnd() != null, TourProjectGroupPurchase::getTravelStartTime, dto.getTravelStartTimeEnd())
+                .orderBy(true, true, TourProjectGroupPurchase::getTravelStartTime); // 按照拼团结束时间筛选
+
+        // 查询出符合条件的出行开始时间
+        queryWrapper.select(TourProjectGroupPurchase::getTravelStartTime);
+
+        // 执行查询,获取符合条件的结果
+        List<TourProjectGroupPurchase> groupPurchases = tourProjectGroupPurchaseMapper.selectList(queryWrapper);
+
+        // 创建另一个 SimpleDateFormat 对象来格式化为新的格式
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+
+        // 返回去重后的出行开始时间,转为字符串形式
+        return groupPurchases.stream()
+                .map(item -> sdf.format(item.getTravelStartTime()))
+                .distinct()  // 去重
+                .collect(Collectors.toList());
+    }
+
     private TourProjectGroupPurchase buildDefaultValue(TourProjectGroupPurchase tourProjectGroupPurchase) {
         if (tourProjectGroupPurchase.getId() == null) {
             tourProjectGroupPurchase.setId(idGenerator.nextLongId());