From b4dadea685bea47174d7d531b1a7a0ae8b328ae4 Mon Sep 17 00:00:00 2001 From: chen-xin-zhi <3588068430@qq.com> Date: Wed, 12 Feb 2025 12:27:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB=E8=AE=A2=E5=8D=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../good/AppointmentDateController.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java b/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java index 359ee90..0948459 100644 --- a/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java +++ b/src/main/java/com/cultural/heritage/controller/good/AppointmentDateController.java @@ -19,6 +19,7 @@ import com.cultural.heritage.model.entity.AppointmentDate; import com.cultural.heritage.model.entity.Good; import com.cultural.heritage.model.entity.PendingServiceGood; import com.cultural.heritage.model.entity.TimePeriod; +import com.cultural.heritage.service.common.CommonService; import com.cultural.heritage.service.good.AppointmentDateService; import com.cultural.heritage.service.good.GoodService; import com.cultural.heritage.service.good.TimePeriodService; @@ -35,7 +36,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; @RestController @RequestMapping("/appointmentDate") @@ -58,10 +61,17 @@ public class AppointmentDateController { private PendingServiceGoodService pendingServiceGoodService; + @Resource private GoodService goodService; + + @Resource + private CommonService commonService; + + + /** * Web端管理员根据id删除预约日期 * @param commonRequest 预约日期id @@ -148,6 +158,12 @@ public class AppointmentDateController { updateWrapper.set("isAvailable", status); boolean update = appointmentDateService.update(updateWrapper); ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "预约日期状态修改失败"); + + // 批量更新服务类商品待处理记录 + UpdateWrapper goodUpdateWrapper = new UpdateWrapper<>(); + goodUpdateWrapper.eq("appointmentDateId", id).set("isAvailable", status); + boolean result = pendingServiceGoodService.update(goodUpdateWrapper); + ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品待处理记录批量更新失败"); return ResultUtils.success(true); } @@ -178,7 +194,7 @@ public class AppointmentDateController { boolean update = timePeriodService.updateById(timePeriod); ThrowUtils.throwIf(!update, ErrorCode.OPERATION_ERROR, "预约时间段人数修改失败"); - // 删除服务类商品待处理记录 + // 更新服务类商品待处理记录 UpdateWrapper updateWrapper = new UpdateWrapper<>(); updateWrapper.eq("timePeriodId", id); updateWrapper.set("minNumber", timePeriodSingleUpdateRequest.getMinNumber()); @@ -225,6 +241,7 @@ public class AppointmentDateController { pendingServiceGood.setPrice(good.getPrice()); pendingServiceGood.setTimePeriodId(timePeriod.getId()); pendingServiceGood.setReservationDate(appointmentDate.getSpecificDate()); + pendingServiceGood.setIsAvailable(appointmentDate.getIsAvailable()); boolean result = pendingServiceGoodService.save(pendingServiceGood); ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品待处理记录添加失败"); @@ -270,6 +287,15 @@ public class AppointmentDateController { Good good = goodService.getById(goodId); ThrowUtils.throwIf(good == null, ErrorCode.OPERATION_ERROR, "当前商品不存在"); + // 获取预约日期列表 + List appointmentDateList = commonService.getItemsByIds(timePeriodList, appointmentDateService, TimePeriod::getAppointmentDateId); + + // 封装map集合(键:预约日期id, 值:是否可预约) + Map map = new HashMap<>(); + for (AppointmentDate appDate : appointmentDateList) { + map.put(appDate.getId(), appDate.getIsAvailable()); + } + List pendingServiceGoodList = new ArrayList<>(); for (TimePeriod timePeriod : timePeriodList) { PendingServiceGood pendingServiceGood = new PendingServiceGood(); @@ -278,6 +304,7 @@ public class AppointmentDateController { pendingServiceGood.setPrice(good.getPrice()); pendingServiceGood.setAppointmentDateId(appointmentDate.getId()); pendingServiceGood.setReservationDate(appointmentDate.getSpecificDate()); + pendingServiceGood.setIsAvailable(map.get(appointmentDate.getId())); pendingServiceGood.setTimePeriodId(timePeriod.getId()); pendingServiceGood.setTimeSlot(timePeriod.getTimeSlot());