Эх сурвалжийг харах

[fix]
1、 将项目的启用禁用增加先需要进行设计项目日历价格的逻辑

chenchen 5 сар өмнө
parent
commit
b01891eb3b

+ 42 - 2
application-webadmin/src/main/java/com/tourism/webadmin/back/controller/ExtraController.java

@@ -2,6 +2,7 @@ package com.tourism.webadmin.back.controller;
 
 import ch.qos.logback.core.joran.sanity.Pair;
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import com.tourism.common.core.annotation.MyRequestBody;
 import com.tourism.common.core.constant.ErrorCodeEnum;
 import com.tourism.common.core.object.MyOrderParam;
 import com.tourism.common.core.object.MyRelationParam;
@@ -11,6 +12,7 @@ import com.tourism.common.core.util.MyModelUtil;
 import com.tourism.webadmin.app.website.dto.DatePriceSaveDto;
 import com.tourism.webadmin.app.website.vo.DateRangePriceVo;
 import com.tourism.webadmin.app.website.vo.DateRangesPriceVo;
+import com.tourism.webadmin.back.dto.TourismProjectDto;
 import com.tourism.webadmin.back.model.TourismDatePrice;
 import com.tourism.webadmin.back.model.TourismProject;
 import com.tourism.webadmin.back.service.TourismDatePriceService;
@@ -133,9 +135,18 @@ public class ExtraController {
     @SaCheckPermission("tourismProject.view")
     @PostMapping("/saveDatePrice")
     public ResponseResult<Void> saveDatePrice(@RequestBody DatePriceSaveDto datePriceSaveDto) {
-        //dateRangesPriceVoList为空的话,直接返回成功
+        //dateRangesPriceVoList为空的话,则删除全部的日历价格
         if(CollectionUtils.isEmpty(datePriceSaveDto.getDateRangesPriceVoList())){
-            return ResponseResult.success();
+            TourismProject tourismProject = tourismProjectService.getById(datePriceSaveDto.getProjectId());
+            if(tourismProject == null){
+                return ResponseResult.error(ErrorCodeEnum.DATA_SAVE_FAILED,"旅游项目不存在");
+                }else {
+                TourismDatePrice filter = new TourismDatePrice();
+                filter.setProjectId(datePriceSaveDto.getProjectId());
+                filter.setNowDate(MyDateUtil.truncateToDay(new Date()));
+                List<TourismDatePrice> tourismDatePriceList = tourismDatePriceService.getTourismDatePriceList(filter, "");
+                tourismDatePriceList.stream().map(TourismDatePrice::getId).forEach(tourismDatePriceService::remove);
+            }
         }
         //取旅游项目的价格,来对列表数据进行对比,如果列表数据低于旅游项目的价格,则进行提示
         TourismProject tourismProject = tourismProjectService.getById(datePriceSaveDto.getProjectId());
@@ -226,5 +237,34 @@ public class ExtraController {
         });
         return ResponseResult.success();
     }
+    /**
+     * 更新项目的状态(1.启用;0.禁用。)
+     *
+     * @param tourismProjectDto 旅游项目管理Dto对象。
+     * @return void。
+     */
+    @Transactional
+    @SaCheckPermission("tourismProject.update")
+    @PostMapping("/updateProjectState")
+    public ResponseResult<Void> updateProjectState(@MyRequestBody TourismProjectDto tourismProjectDto) {
+        TourismProject tourismProject = tourismProjectService.getById(tourismProjectDto.getId());
+        if (tourismProject == null) {
+            return ResponseResult.error(ErrorCodeEnum.PROJECT_NOT_EXIST);
+        }
+        if(tourismProjectDto.getEnable() == 1) {
+            //查看该项目是否设置日历;设置日历,则允许修改项目状态;若未设置日历,则不允许修改项目状态
+            TourismDatePrice tourismDatePrice = new TourismDatePrice();
+            tourismDatePrice.setProjectId(tourismProject.getId());
+            tourismDatePrice.setNowDate(new Date());
+            List<TourismDatePrice> listByFilter = tourismDatePriceService.getTourismDatePriceList(tourismDatePrice,"");
+            if (listByFilter.isEmpty()) {
+                return ResponseResult.error(ErrorCodeEnum.DATE_PRICE_NOTEXIST);
+            }
+        }
+        TourismProject originalTourismProject = MyModelUtil.copyTo(tourismProject, TourismProject.class);
+        tourismProject.setEnable(tourismProjectDto.getEnable());
+        tourismProjectService.update(tourismProject,originalTourismProject);
+        return ResponseResult.success();
+    }
 
 }

+ 3 - 1
common/common-core/src/main/java/com/tourism/common/core/constant/ErrorCodeEnum.java

@@ -71,7 +71,9 @@ public enum ErrorCodeEnum {
     MOBILE_EXIST("该手机号已被注册!"),
     PROJECT_ALREADY_BOOKING("该项目已被您预定,请选择其他项目!"),
     DATE_OVERLAP("日期重叠,请重新选择!"),
-    PRICE_ERROR("价格错误,请重新填写!");
+    PRICE_ERROR("价格错误,请重新填写!"),
+    PROJECT_NOT_EXIST("该项目不存在,请重新选择!"),
+    DATE_PRICE_NOTEXIST("请先编辑日历价格!");
     // 下面的枚举值为特定枚举值,即开发者可以根据自己的项目需求定义更多的非通用枚举值
 
     /**