更新了商品管理模块

This commit is contained in:
chen-xin-zhi 2024-12-06 09:18:28 +08:00
parent d93bb58d60
commit a451cc632e
29 changed files with 786 additions and 308 deletions

View File

@ -1,40 +0,0 @@
package com.cultural.heritage.config;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.constant.BookConstant;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.model.entity.BookingDate;
import com.cultural.heritage.service.book.BookingDateService;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.ArrayList;
import java.util.List;
@Configuration
public class BookingDateConfig {
@Resource
private BookingDateService bookingDateService;
// 写真预约日期初始化
@Bean
public Boolean initBookingDate() {
System.out.println("这是Config");
long count = bookingDateService.count();
List<BookingDate> bookingDateList = new ArrayList<>();
if (count == 0) {
for (int i = 0; i < 3; i ++ ) {
BookingDate bookingDateRent = bookingDateService.initBookingDate(BookConstant.RENT_CLOTHES, i);
BookingDate bookingDateOwn = bookingDateService.initBookingDate(BookConstant.OWN_CLOTHES, i);
bookingDateList.add(bookingDateRent);
bookingDateList.add(bookingDateOwn);
}
boolean result = bookingDateService.saveBatch(bookingDateList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
}
return true;
}
}

View File

@ -143,73 +143,6 @@ public class CouponController {
return ResultUtils.success(page);
}
//
// /**
// * 积分兑换优惠券
// * @param exchangeAddRequest 兑换记录添加请求体
// * @return 是否兑换成功
// */
// @PostMapping("/exchange")
// @Transactional(rollbackFor = Exception.class)
// @Operation(summary = "小程序端用户积分兑换优惠券", description = "参数:兑换记录添加请求体,权限:管理员(admin, boss)方法名pointsExchangeCoupon")
// public BaseResponse<Boolean> pointsExchangeCoupon(@RequestBody ExchangeAddRequest exchangeAddRequest, HttpServletRequest request) {
// if (exchangeAddRequest == null) {
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
// }
// // 更新用户积分
// User loginUser = userService.getLoginUser(request);
// Long userId = loginUser.getId();
// Integer requirePoints = exchangeAddRequest.getRequirePoints();
// Integer quantity = exchangeAddRequest.getQuantity();
// if (userId <= 0) {
// throw new BusinessException(ErrorCode.PARAMS_ERROR);
// }
// User user = userService.getById(userId);
// ThrowUtils.throwIf(user == null, ErrorCode.NOT_FOUND_ERROR);
// int residual = user.getPoints() - requirePoints * quantity;
// if (residual < 0) {
// throw new BusinessException(ErrorCode.OPERATION_ERROR, "积分不足");
// }
// user.setPoints(residual);
// boolean save = userService.updateById(user);
// ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR);
//
// // 更新优惠券的库存量
// Long couponId = exchangeAddRequest.getCouponId();
// Coupon coupon = couponService.getById(couponId);
// if (coupon.getTotalNum() - quantity < 0) {
// throw new BusinessException(ErrorCode.OPERATION_ERROR, "优惠券数量不足");
// }
// coupon.setResidueNum(coupon.getTotalNum() - quantity);
// boolean updateCoupon = couponService.updateById(coupon);
// ThrowUtils.throwIf(!updateCoupon, ErrorCode.OPERATION_ERROR);
//
// // 校验用户限领量是否已达到上限
// Integer currentNum = couponService.verifyIsReachTheUpperLimit(userId, couponId);
// int limitNum = 0;
// if (currentNum == null) {
// limitNum = quantity;
// } else {
// limitNum = currentNum + quantity;
// }
// if ( limitNum > coupon.getLimitNum()) {
// throw new BusinessException(ErrorCode.OPERATION_ERROR, "用户限领量已达到上限");
// }
// // 插入一条兑换记录
// Exchange exchange = new Exchange();
// BeanUtils.copyProperties(exchangeAddRequest, exchange);
// boolean result = exchangeService.save(exchange);
// ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
//
// // 给当前用户添加优惠券
// UserCoupon userCoupon = new UserCoupon();
// BeanUtils.copyProperties(exchangeAddRequest, userCoupon);
// boolean couponResult = userCouponService.save(userCoupon);
// ThrowUtils.throwIf(!couponResult, ErrorCode.OPERATION_ERROR);
// return ResultUtils.success(true, "兑换成功");
// }
/**
* 用户删除兑换记录

View File

@ -1,8 +1,8 @@
package com.cultural.heritage.controller.good;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cultural.heritage.annotation.AuthCheck;
import com.cultural.heritage.common.BaseResponse;
@ -19,33 +19,32 @@ import com.cultural.heritage.model.dto.good.GoodAddRequest;
import com.cultural.heritage.model.dto.good.GoodQueryRequest;
import com.cultural.heritage.model.dto.good.GoodUpdateRequest;
import com.cultural.heritage.model.dto.good.service.ServiceGoodAddRequest;
import com.cultural.heritage.model.dto.good.service.ServiceGoodQueryRequest;
import com.cultural.heritage.model.dto.good.service.ServiceGoodUpdateRequest;
import com.cultural.heritage.model.dto.timeperiod.TimePeriodAddRequest;
import com.cultural.heritage.model.entity.AppointmentDate;
import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.model.entity.TimePeriod;
import com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO;
import com.cultural.heritage.model.vo.appointment.AppointmentDateVO;
import com.cultural.heritage.model.vo.good.GoodPageVO;
import com.cultural.heritage.model.vo.good.ServiceGoodCardVO;
import com.cultural.heritage.model.vo.good.ServiceGoodVO;
import com.cultural.heritage.model.vo.timeperiod.TimePeriodVO;
import com.cultural.heritage.service.good.AppointmentDateService;
import com.cultural.heritage.service.good.GoodService;
import com.cultural.heritage.service.good.TimePeriodService;
import com.cultural.heritage.service.user.UserService;
import com.cultural.heritage.utils.AppointmentDateUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.*;
/**
@ -70,6 +69,11 @@ public class GoodController {
private AppointmentDateService appointmentDateService;
@Resource
private TimePeriodService timePeriodService;
/**
* Web端管理员添加常规类商品
* @param goodAddRequest 商品添加请求体
@ -100,6 +104,7 @@ public class GoodController {
* @return 是否添加成功
*/
@PostMapping("/add/service")
@Transactional(rollbackFor = Exception.class)
@Operation(summary = "Web端管理员添加服务类商品", description = "参数:服务类商品添加请求体,权限:管理员(admin, boss)方法名addServiceGood")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Boolean> addServiceGood(@RequestBody ServiceGoodAddRequest serviceGoodAddRequest) {
@ -108,32 +113,48 @@ public class GoodController {
}
// 向商品表插入服务类商品的基本信息
Good good = new Good();
good.setIsGoodType(0);
BeanUtils.copyProperties(serviceGoodAddRequest, good);
good.setType("服务类");
good.setIsGoodType(0);
good.setInventory(1);
good.setFestivalOrder(0);
// 校验
goodService.validGood(good, false);
boolean save = goodService.save(good);
ThrowUtils.throwIf(!save, ErrorCode.OPERATION_ERROR);
// 获取当天及未来三天的日期
List<String> dates = AppointmentDateUtil.getDates();
AtomicInteger idx = new AtomicInteger(0);
// 向预约日期表中批量插入服务类商品的预约信息
Long id = good.getId();
// 添加当前商品的预约日期
List<AppointmentDateAddRequest> appointmentDateAddRequestList = serviceGoodAddRequest.getAppointmentDateAddRequestList();
List<AppointmentDate> appointmentDates = appointmentDateAddRequestList.stream().map(appointmentDateAddRequest -> {
List<AppointmentDate> appointmentDateList = appointmentDateAddRequestList.stream().map(appointmentDateAddRequest -> {
AppointmentDate appointmentDate = new AppointmentDate();
BeanUtils.copyProperties(appointmentDateAddRequest, appointmentDate);
appointmentDate.setSpecificDate(dates.get(idx.getAndIncrement()));
appointmentDate.setGoodId(id);
appointmentDate.setGoodId(good.getId());
// 校验
appointmentDateService.validAppointmentDate(appointmentDate, false);
return appointmentDate;
}).toList();
boolean isSuccess = appointmentDateService.saveBatch(appointmentDates);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR);
boolean isSaveBatch = appointmentDateService.saveBatch(appointmentDateList);
ThrowUtils.throwIf(!isSaveBatch, ErrorCode.OPERATION_ERROR);
// 添加当前商品的预约时间段
List<TimePeriod> timePeriods = new ArrayList<>();
for (int i = 0; i < appointmentDateAddRequestList.size(); i++) {
AppointmentDate appointmentDate = appointmentDateList.get(i);
AppointmentDateAddRequest appointmentDateAddRequest = appointmentDateAddRequestList.get(i);
Long appointmentDateId = appointmentDate.getId();
List<TimePeriodAddRequest> timePeriodAddRequestList = appointmentDateAddRequest.getTimePeriodAddRequestList();
List<TimePeriod> timePeriodList = timePeriodAddRequestList.stream().map(timePeriodAddRequest -> {
TimePeriod timePeriod = new TimePeriod();
BeanUtils.copyProperties(timePeriodAddRequest, timePeriod);
timePeriod.setAppointmentDateId(appointmentDateId);
// 校验
timePeriodService.validTimePeriod(timePeriod, false);
return timePeriod;
}).toList();
timePeriods.addAll(timePeriodList);
}
boolean result = timePeriodService.saveBatch(timePeriods);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
@ -173,15 +194,24 @@ public class GoodController {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
Long id = deleteRequest.getId();
// 删除预约日期表中与该商品关联的记录
//删除预约时间段表中与该商品关联的记录
QueryWrapper<AppointmentDate> dateQueryWrapper = new QueryWrapper<>();
dateQueryWrapper.eq("goodId", id);
List<AppointmentDate> appointmentDateList = appointmentDateService.list(dateQueryWrapper);
List<Long> ids = appointmentDateList.stream().map(AppointmentDate::getId).toList();
QueryWrapper<TimePeriod> timePeriodQueryWrapper = new QueryWrapper<>();
timePeriodQueryWrapper.in("appointmentDateId", ids);
boolean remove = timePeriodService.remove(timePeriodQueryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
// 删除预约日期表中与该商品关联的记录
boolean isSuccess = appointmentDateService.remove(dateQueryWrapper);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
// 删除商品表中的服务类商品
boolean result = goodService.removeById(id);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "服务类商品删除失败");
return ResultUtils.success(true);
}
@ -202,9 +232,17 @@ public class GoodController {
if (CollectionUtils.isEmpty(ids)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
// 删除预约日期表中与该商品关联的记录
//删除预约时间段表中与该商品关联的记录
QueryWrapper<AppointmentDate> queryWrapper = new QueryWrapper<>();
queryWrapper.in("goodId", ids);
List<AppointmentDate> appointmentDateList = appointmentDateService.list(queryWrapper);
List<Long> appointmentDateIds = appointmentDateList.stream().map(AppointmentDate::getId).toList();
QueryWrapper<TimePeriod> timePeriodQueryWrapper = new QueryWrapper<>();
timePeriodQueryWrapper.in("appointmentDateId", appointmentDateIds);
boolean success = timePeriodService.remove(timePeriodQueryWrapper);
ThrowUtils.throwIf(!success, ErrorCode.OPERATION_ERROR, "服务类商品预约时间段删除失败");
// 删除预约日期表中与该商品关联的记录
boolean remove = appointmentDateService.remove(queryWrapper);
ThrowUtils.throwIf(!remove, ErrorCode.OPERATION_ERROR, "服务类商品预约日期删除失败");
@ -253,7 +291,7 @@ public class GoodController {
public BaseResponse<Page<GoodPageVO>> listGoodByPage(@RequestBody GoodQueryRequest goodQueryRequest) {
long current = goodQueryRequest.getCurrent();
long pageSize = goodQueryRequest.getPageSize();
QueryWrapper<Good> goodQueryWrapper = goodService.getGoodQueryWrapper(goodQueryRequest);
QueryWrapper<Good> goodQueryWrapper = goodService.getGoodQueryWrapper(goodQueryRequest, true);
Page<Good> page = goodService.page(new Page<>(current, pageSize), goodQueryWrapper);
List<Good> records = page.getRecords();
List<GoodPageVO> goodPageVOS = records.stream().map(good -> {
@ -316,57 +354,80 @@ public class GoodController {
/**
* Web端管理员分页查询服务类商品
* @param goodQueryRequest 商品查询请求体
* @param serviceGoodQueryRequest 服务类商品查询请求体
* @return 服务类商品列表
*/
@PostMapping("/service/list/page")
@Operation(summary = "Web端管理员分页查询服务类商品", description = "参数:商品查询请求体,权限:管理员(admin, boss)方法名listServiceGoodVOByPage")
@AuthCheck(mustRole = UserConstant.ADMIN_ROLE)
public BaseResponse<Page<ServiceGoodVO>> listServiceGoodVOByPage(@RequestBody GoodQueryRequest goodQueryRequest) {
if (goodQueryRequest == null) {
public BaseResponse<Page<ServiceGoodVO>> listServiceGoodVOByPage(@RequestBody ServiceGoodQueryRequest serviceGoodQueryRequest) {
if (serviceGoodQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR);
}
long current = goodQueryRequest.getCurrent();
long pageSize = goodQueryRequest.getPageSize();
QueryWrapper<Good> goodQueryWrapper = goodService.getGoodQueryWrapper(goodQueryRequest);
long current = serviceGoodQueryRequest.getCurrent();
long pageSize = serviceGoodQueryRequest.getPageSize();
GoodQueryRequest goodQueryRequest = new GoodQueryRequest();
BeanUtils.copyProperties(serviceGoodQueryRequest, goodQueryRequest);
goodQueryRequest.setFestivalOrder(0);
goodQueryRequest.setType("服务类");
QueryWrapper<Good> goodQueryWrapper = goodService.getGoodQueryWrapper(goodQueryRequest, true);
Page<Good> page = goodService.page(new Page<>(current, pageSize), goodQueryWrapper);
List<Good> records = page.getRecords();
// 获取当天及未来三天的日期
List<String> dates = AppointmentDateUtil.getDates();
// 用map集合存储服务类商品关联的预约日期
List<AppointmentDate> appointmentDateList = appointmentDateService.list();
List<AppointmentDateVO> appointmentDateVOS = appointmentDateList.stream().map(appointmentDate -> {
// 获取联表(预约日期表, 预约时间段表)查询结果
List<AppointmentDateTimePeriodVO> appointmentDateTimePeriodVOS = appointmentDateService.queryAppointmentDateDetail();
List<AppointmentDateVO> appointmentDateVOList = new ArrayList<>();
// 利用map集合封装预约日期和预约时间段
Map<Long, List<TimePeriodVO>> timeMap = new HashMap<>();
Map<Long, AppointmentDateVO> dateMap = new HashMap<>();
for (AppointmentDateTimePeriodVO appointmentDateTimePeriodVO : appointmentDateTimePeriodVOS) {
// 封装预约日期和预约时间段
AppointmentDateVO appointmentDateVO = new AppointmentDateVO();
BeanUtils.copyProperties(appointmentDate, appointmentDateVO);
return appointmentDateVO;
}).toList();
Map<Long, List<AppointmentDateVO>> map = new HashMap<>();
for (AppointmentDateVO appointmentDateVO : appointmentDateVOS) {
Long goodId = appointmentDateVO.getGoodId();
String specificDate = appointmentDateVO.getSpecificDate();
if (!dates.contains(specificDate)) continue;
List<AppointmentDateVO> dateVOList = map.get(goodId) != null ? map.get(goodId) : new ArrayList<>();
dateVOList.add(appointmentDateVO);
map.put(goodId, dateVOList);
TimePeriodVO timePeriodVO = new TimePeriodVO();
BeanUtils.copyProperties(appointmentDateTimePeriodVO, appointmentDateVO);
BeanUtils.copyProperties(appointmentDateTimePeriodVO, timePeriodVO);
Long timePeriodId = appointmentDateTimePeriodVO.getTimePeriodId();
timePeriodVO.setId(timePeriodId);
Long id = appointmentDateTimePeriodVO.getId();
List<TimePeriodVO> timePeriodVOList = timeMap.get(id);
if (timePeriodVOList == null) {
timePeriodVOList = new ArrayList<>();
// 用map集合存储预约日期
dateMap.put(id, appointmentDateVO);
}
timePeriodVOList.add(timePeriodVO);
timeMap.put(id, timePeriodVOList);
}
// 封装预约日期集合
Set<Long> dateIds = dateMap.keySet();
for (Long dateId : dateIds) {
AppointmentDateVO appointmentDateVO = dateMap.get(dateId);
List<TimePeriodVO> timePeriodVOList = timeMap.get(dateId);
appointmentDateVO.setTimePeriodVOList(timePeriodVOList);
appointmentDateVOList.add(appointmentDateVO);
}
List<ServiceGoodVO> serviceGoodVOList = records.stream().map(good -> {
List<ServiceGoodVO> serviceGoodVOList = new ArrayList<>();
for (Good good : records) {
ServiceGoodVO serviceGoodVO = new ServiceGoodVO();
BeanUtils.copyProperties(good, serviceGoodVO);
Long id = good.getId();
List<AppointmentDateVO> appointmentDateVOList = map.get(id);
serviceGoodVO.setAppointmentDateVOS(appointmentDateVOList);
return serviceGoodVO;
}).toList();
Long goodVOId = serviceGoodVO.getId();
List<AppointmentDateVO> dateVOList = appointmentDateVOList.stream()
.filter(appointmentDateVO -> Objects.equals(appointmentDateVO.getGoodId(), goodVOId)).toList();
serviceGoodVO.setAppointmentDateVOList(dateVOList);
serviceGoodVOList.add(serviceGoodVO);
}
Page<ServiceGoodVO> serviceGoodVOPage = new Page<>();
serviceGoodVOPage.setRecords(serviceGoodVOList);
serviceGoodVOPage.setCurrent(current);
serviceGoodVOPage.setPages(pageSize);
serviceGoodVOPage.setPages(page.getPages());
serviceGoodVOPage.setCurrent(page.getCurrent());
serviceGoodVOPage.setSize(page.getSize());
serviceGoodVOPage.setTotal(page.getTotal());
return ResultUtils.success(serviceGoodVOPage);
}
@ -389,22 +450,38 @@ public class GoodController {
ThrowUtils.throwIf(good == null, ErrorCode.NOT_FOUND_ERROR, "商品不存在");
ServiceGoodVO serviceGoodVO = new ServiceGoodVO();
BeanUtils.copyProperties(good, serviceGoodVO);
// 获取当天及未来三天的日期
List<String> dates = AppointmentDateUtil.getDates();
// 获取当前服务类商品关联的预约日期
QueryWrapper<AppointmentDate> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("goodId", id);
List<AppointmentDate> appointmentDateList = appointmentDateService.list(queryWrapper);
List<AppointmentDateVO> appointmentDateVOS = appointmentDateList.stream().map(appointmentDate -> {
Long goodVOId = serviceGoodVO.getId();
List<AppointmentDateTimePeriodVO> appointmentDateTimePeriodVOList = appointmentDateService.queryAppointmentDateDetailById(goodVOId);
List<AppointmentDateVO> appointmentDateVOList = new ArrayList<>();
// 封装预约日期和预约时间段
Map<Long, List<TimePeriodVO>> timeMap = new HashMap<>();
Map<Long, AppointmentDateVO> dateMap = new HashMap<>();
for (AppointmentDateTimePeriodVO appointmentDateTimePeriodVO : appointmentDateTimePeriodVOList) {
TimePeriodVO timePeriodVO = new TimePeriodVO();
AppointmentDateVO appointmentDateVO = new AppointmentDateVO();
BeanUtils.copyProperties(appointmentDate, appointmentDateVO);
return appointmentDateVO;
}).toList();
List<AppointmentDateVO> dateVOList = appointmentDateVOS.stream()
.filter(appointmentDateVO -> dates.contains(appointmentDateVO.getSpecificDate())).toList();
serviceGoodVO.setAppointmentDateVOS(dateVOList);
BeanUtils.copyProperties(appointmentDateTimePeriodVO, timePeriodVO);
BeanUtils.copyProperties(appointmentDateTimePeriodVO, appointmentDateVO);
Long timePeriodId = appointmentDateTimePeriodVO.getTimePeriodId();
timePeriodVO.setId(timePeriodId);
Long appId = appointmentDateTimePeriodVO.getId();
List<TimePeriodVO> timePeriodVOList = timeMap.get(appId);
if (timePeriodVOList == null) {
timePeriodVOList = new ArrayList<>();
dateMap.put(appId, appointmentDateVO);
}
timePeriodVOList.add(timePeriodVO);
timeMap.put(appId, timePeriodVOList);
}
Set<Long> dateIds = dateMap.keySet();
for (Long dateId : dateIds) {
AppointmentDateVO appointmentDateVO = dateMap.get(dateId);
List<TimePeriodVO> timePeriodVOList = timeMap.get(dateId);
appointmentDateVO.setTimePeriodVOList(timePeriodVOList);
appointmentDateVOList.add(appointmentDateVO);
}
serviceGoodVO.setAppointmentDateVOList(appointmentDateVOList);
return ResultUtils.success(serviceGoodVO);
}
@ -448,65 +525,31 @@ public class GoodController {
// 更新服务类商品的基本信息
Good good = new Good();
BeanUtils.copyProperties(serviceGoodUpdateRequest, good);
good.setType("服务类");
good.setIsGoodType(0);
good.setInventory(1);
good.setFestivalOrder(0);
// 校验
goodService.validGood(good, true);
boolean result = goodService.updateById(good);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "商品不存在");
// 获取当天及未来三天的日期
List<String> dates = AppointmentDateUtil.getDates();
AtomicInteger idx = new AtomicInteger(0);
// 封装预约日期实体类
List<AppointmentDateUpdateRequest> appointmentDateUpdateRequestList = serviceGoodUpdateRequest.getAppointmentDateUpdateRequestList();
List<AppointmentDate> appointmentDateList = appointmentDateUpdateRequestList.stream().map(appointmentDateUpdateRequest -> {
AppointmentDate appointmentDate = new AppointmentDate();
BeanUtils.copyProperties(appointmentDateUpdateRequest, appointmentDate);
appointmentDate.setSpecificDate(dates.get(idx.getAndIncrement()));
appointmentDate.setGoodId(good.getId());
// 校验
appointmentDateService.validAppointmentDate(appointmentDate, true);
return appointmentDate;
}).toList();
// 更新当前服务类商品的预约日期
boolean isSuccess = appointmentDateService.updateBatchById(appointmentDateList);
ThrowUtils.throwIf(!isSuccess, ErrorCode.OPERATION_ERROR);
return ResultUtils.success(true);
}
/**
* (服务类商品)初始化未来一天的预约日期
*/
// @Scheduled(cron = "*/5 * * * * ?")
// 每天00:00-00:00调用
@Scheduled(cron = "0 0 0 * * ?")
@PostMapping("/service/init")
@Operation(summary = "(服务类商品)初始化未来一天的预约日期", description = "参数权限自动调用方法名initServiceGoodBookingDate")
@Transactional(rollbackFor = Exception.class)
public void initServiceGoodBookingDate() {
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("isGoodType", 0);
List<Good> goodList = goodService.list(queryWrapper);
List<AppointmentDate> appointmentDateList = new ArrayList<>();
goodList.forEach(good -> {
AppointmentDate appointmentDate = new AppointmentDate();
appointmentDate.setGoodId(good.getId());
appointmentDate.setSpecificDate(DateUtil.formatDate(DateUtil.offsetDay(DateUtil.date(), 3)));
appointmentDate.setTimeSlot("00:00-00:00");
appointmentDate.setIsAvailable(0);
appointmentDate.setNumberRange("(0,0)");
appointmentDateList.add(appointmentDate);
});
boolean result = appointmentDateService.saveBatch(appointmentDateList);
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "初始化失败");
}

View File

@ -2,6 +2,20 @@ package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.AppointmentDate;
import com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO;
import java.util.List;
public interface AppointmentDateMapper extends BaseMapper<AppointmentDate> {
/**
* (多表联查)查询所有商品的预约情况
*/
List<AppointmentDateTimePeriodVO> queryAppointmentDateDetail();
/**
* (多表联查)根据id查询商品的预约情况
*/
List<AppointmentDateTimePeriodVO> queryAppointmentDateDetailById(Long goodId);
}

View File

@ -0,0 +1,7 @@
package com.cultural.heritage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cultural.heritage.model.entity.TimePeriod;
public interface TimePeriodMapper extends BaseMapper<TimePeriod> {
}

View File

@ -1,29 +1,25 @@
package com.cultural.heritage.model.dto.appointment;
import com.cultural.heritage.model.dto.timeperiod.TimePeriodAddRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "预约日期请求体", requiredProperties = {"timeSlot", "isAvailable", "minNumber", "maxNumber"})
@Schema(description = "预约日期请求体", requiredProperties = {
"timeSlot", "isAvailable", "minNumber", "maxNumber", "timePeriodAddRequestList"
})
public class AppointmentDateAddRequest implements Serializable {
// /**
// * 预约具体日期
// */
// @Schema(description = "预约具体日期", example = "2024-11-09")
// private String specificDate;
/**
* 预约时间
* 具体预约时间
*/
@Schema(description = "预约时间段", example = "9:00-11:00;12:00-14:00")
private String timeSlot;
@Schema(description = "具体预约时间", example = "2024-12-04")
private String specificDate;
/**
* 是否可预约
@ -31,13 +27,10 @@ public class AppointmentDateAddRequest implements Serializable {
@Schema(description = "是否可预约", example = "1")
private Integer isAvailable;
/**
* 预约人数范围
* 预约时间段列表
*/
@Schema(description = "预约人数范围", example = "(3,5);(4,6)")
private String numberRange;
private List<TimePeriodAddRequest> timePeriodAddRequestList;
@Serial

View File

@ -1,12 +1,16 @@
package com.cultural.heritage.model.dto.appointment;
import com.cultural.heritage.model.dto.timeperiod.TimePeriodUpdateRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
@Schema(description = "预约日期更新请求体", requiredProperties = {"id", "specificDate",
"isAvailable", "timePeriodUpdateRequestList"})
public class AppointmentDateUpdateRequest implements Serializable {
/**
@ -16,18 +20,11 @@ public class AppointmentDateUpdateRequest implements Serializable {
private Long id;
// /**
// * 预约具体日期
// */
// @Schema(description = "预约具体日期", example = "2024-11-09")
// private String specificDate;
/**
* 预约时间段
* 预约具体日期
*/
@Schema(description = "预约时间段", example = "9:00-11:00;12:00-14:00")
private String timeSlot;
@Schema(description = "预约具体日期", example = "2024-11-09")
private String specificDate;
/**
@ -38,10 +35,11 @@ public class AppointmentDateUpdateRequest implements Serializable {
/**
* 预约人数范围
* 预约时间段
*/
@Schema(description = "预约人数范围", example = "(3,5);(4,6)")
private String numberRange;
@Schema(description = "预约时间段")
private List<TimePeriodUpdateRequest> timePeriodUpdateRequestList;
@Serial

View File

@ -1,23 +1,66 @@
package com.cultural.heritage.model.dto.good.service;
import com.cultural.heritage.model.dto.appointment.AppointmentDateAddRequest;
import com.cultural.heritage.model.dto.good.GoodAddRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
@Schema(description = "服务类商品添加请求体", requiredProperties = {"appointmentDateAddRequestList"})
public class ServiceGoodAddRequest extends GoodAddRequest implements Serializable {
@Schema(description = "服务类商品添加请求体", requiredProperties = {"name", "price", "goodImg", "intro", "introDetail",
"detailImg", "label", "appointmentDateAddRequestList"})
public class ServiceGoodAddRequest implements Serializable {
/**
* 商品名
*/
@Schema(description = "商品名", example = "非遗香囊")
private String name;
/**
* 商品价格
*/
@Schema(description = "商品价格", example = "20.00")
private BigDecimal price;
/**
* 商品图片
*/
@Schema(description = "商品图片", example = "https://xxx/xxx.jpg")
private String goodImg;
/**
* 商品简介
*/
@Schema(description = "商品简介", example = "传承千年文化,守护健康美好")
private String intro;
/**
* 商品详情简介
*/
@Schema(description = "商品详情简介", example = "精选药材:选用艾草、菖蒲、苍术、白芷等十多种纯天然中草药,科学配比,香气宜人,具有驱蚊、防疫、安神等多种功效。端午香囊,传承千年文化,守护健康美好。在这个端午节,让我们共同感受传统文化的魅力,为生活增添一抹色彩!")
private String introDetail;
/**
* 商品详情图片
*/
@Schema(description = "商品详情图片", example = "https://xxx/xxx.jpg")
private String detailImg;
/**
* 商品标签
*/
@Schema(description = "商品标签", example = "亲情;送礼;材料包")
private String label;
/**
* 未来几天的预约详情
*/
@Schema(description = "未来几天的预约详情")
@Schema(description = "未来的预约时间表")
private List<AppointmentDateAddRequest> appointmentDateAddRequestList;

View File

@ -0,0 +1,36 @@
package com.cultural.heritage.model.dto.good.service;
import com.cultural.heritage.common.PageRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serial;
import java.io.Serializable;
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(description = "服务类商品查询请求体", requiredProperties = {"id", "name", "isShelves"})
public class ServiceGoodQueryRequest extends PageRequest implements Serializable {
/**
* id
*/
@Schema(description = "商品id(id > 0)", example = "17")
private Long id;
/**
* 商品名
*/
@Schema(description = "商品名", example = "非遗香囊")
private String name;
/**
* 是否上架
*/
@Schema(description = "是否上架(1:上架;0:下架)", example = "1")
private Integer isShelves;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,22 +1,72 @@
package com.cultural.heritage.model.dto.good.service;
import com.cultural.heritage.model.dto.appointment.AppointmentDateUpdateRequest;
import com.cultural.heritage.model.dto.good.GoodUpdateRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
@Schema(description = "服务类商品更新请求体", requiredProperties = {"appointmentDateUpdateRequestList"})
public class ServiceGoodUpdateRequest extends GoodUpdateRequest implements Serializable {
@Schema(description = "服务类商品更新请求体", requiredProperties = {"id", "name", "price", "goodImg", "intro", "introDetail",
"detailImg", "label", "appointmentDateUpdateRequestList"})
public class ServiceGoodUpdateRequest implements Serializable {
/**
* 未来几天的预约详情
* 商品id
*/
@Schema(description = "未来几天的预约详情")
@Schema(description = "商品id(id > 0)", example = "286")
private Long id;
/**
* 商品名
*/
@Schema(description = "商品名", example = "非遗香囊")
private String name;
/**
* 商品价格
*/
@Schema(description = "商品价格", example = "20.00")
private BigDecimal price;
/**
* 商品图片
*/
@Schema(description = "商品图片", example = "https://xxx/xxx.jpg")
private String goodImg;
/**
* 商品简介
*/
@Schema(description = "商品简介", example = "传承千年文化,守护健康美好")
private String intro;
/**
* 商品详情简介
*/
@Schema(description = "商品详情简介", example = "精选药材:选用艾草、菖蒲、苍术、白芷等十多种纯天然中草药,科学配比,香气宜人,具有驱蚊、防疫、安神等多种功效。端午香囊,传承千年文化,守护健康美好。在这个端午节,让我们共同感受传统文化的魅力,为生活增添一抹色彩!")
private String introDetail;
/**
* 商品详情图片
*/
@Schema(description = "商品详情图片", example = "https://xxx/xxx.jpg")
private String detailImg;
/**
* 商品标签
*/
@Schema(description = "商品标签", example = "亲情;送礼;材料包")
private String label;
/**
* 未来几天的预约时间表
*/
@Schema(description = "未来的预约时间表")
private List<AppointmentDateUpdateRequest> appointmentDateUpdateRequestList;

View File

@ -0,0 +1,39 @@
package com.cultural.heritage.model.dto.timeperiod;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
@Schema(description = "预约时间段添加请求体", requiredProperties = {
"timeSlot", "minNumber", "maxNumber"
})
public class TimePeriodAddRequest implements Serializable {
/**
* 时间段
*/
@Schema(description = "时间段", example = "08:00-10:00")
private String timeSlot;
/**
* 最小预约人数
*/
@Schema(description = "最小预约人数", example = "3")
private Integer minNumber;
/**
* 最大预约人数
*/
@Schema(description = "最大预约人数", example = "10")
private Integer maxNumber;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,44 @@
package com.cultural.heritage.model.dto.timeperiod;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
@Schema(description = "预约时间段更新请求体", requiredProperties = {"id", "timeSlot",
"minNumber", "maxNumber"})
public class TimePeriodUpdateRequest implements Serializable {
/**
* 预约时间段id
*/
@Schema(description = "预约时间段id(id > 0)", example = "10")
private Long id;
/**
* 时间段
*/
@Schema(description = "时间段", example = "08:00-10:00")
private String timeSlot;
/**
* 最小预约人数
*/
@Schema(description = "最小预约人数", example = "3")
private Integer minNumber;
/**
* 最大预约人数
*/
@Schema(description = "最大预约人数", example = "10")
private Integer maxNumber;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -31,24 +31,12 @@ public class AppointmentDate implements Serializable {
private String specificDate;
/**
* 预约时间段
*/
private String timeSlot;
/**
* 是否可预约
*/
private Integer isAvailable;
/**
* 预约人数范围
*/
private String numberRange;
/**
* 商品id
*/

View File

@ -0,0 +1,67 @@
package com.cultural.heritage.model.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
/**
* 服务类商品预约时间段表
* @TableName time_period
*/
@Data
@TableName("time_period")
public class TimePeriod implements Serializable {
/**
* 预约时间段id
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 时间段
*/
private String timeSlot;
/**
* 最小预约人数
*/
private Integer minNumber;
/**
* 最大预约人数
*/
private Integer maxNumber;
/**
* 预约日期id
*/
private Long appointmentDateId;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 是否删除
*/
private Integer isDelete;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,54 @@
package com.cultural.heritage.model.vo.appointment;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class AppointmentDateTimePeriodVO implements Serializable {
/**
* 预约日期id
*/
private Long id;
/**
* 预约具体日期
*/
private String specificDate;
/**
* 是否可预约
*/
private Integer isAvailable;
/**
* 商品id
*/
private Long goodId;
/**
* 预约时间段id
*/
private Long timePeriodId;
/**
* 预约时间段
*/
private String timeSlot;
/**
* 最小预约人数
*/
private Integer minNumber;
/**
* 最大预约人数
*/
private Integer maxNumber;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -1,9 +1,11 @@
package com.cultural.heritage.model.vo.appointment;
import com.cultural.heritage.model.vo.timeperiod.TimePeriodVO;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.util.List;
@Data
public class AppointmentDateVO implements Serializable {
@ -21,29 +23,24 @@ public class AppointmentDateVO implements Serializable {
private String specificDate;
/**
* 预约时间段
*/
private String timeSlot;
/**
* 是否可预约
*/
private Integer isAvailable;
/**
* 预约人数范围
*/
private String numberRange;
/**
* 商品id
*/
private Long goodId;
/**
* 预约时间段
*/
private List<TimePeriodVO> timePeriodVOList;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -6,17 +6,64 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@Data
public class ServiceGoodVO extends GoodPageVO implements Serializable {
public class ServiceGoodVO implements Serializable {
/**
* 商品编号
*/
private Long id;
/**
* 商品名
*/
private String name;
/**
* 商品价格
*/
private BigDecimal price;
/**
* 商品图片
*/
private String goodImg;
/**
* 商品简介
*/
private String intro;
/**
* 商品详情简介
*/
private String introDetail;
/**
* 商品详情图片
*/
private String detailImg;
/**
* 商品标签
*/
private String label;
/**
* 未来几天的预约详情
* 是否上架
*/
@Schema(description = "未来几天的预约详情")
private List<AppointmentDateVO> appointmentDateVOS;
private Integer isShelves;
/**
* 未来几天的预约时间表
*/
@Schema(description = "未来几天的预约时间表")
private List<AppointmentDateVO> appointmentDateVOList;
@Serial

View File

@ -0,0 +1,35 @@
package com.cultural.heritage.model.vo.timeperiod;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
@Data
public class TimePeriodVO implements Serializable {
/**
* 预约时间段id
*/
private Long id;
/**
* 时间段
*/
private String timeSlot;
/**
* 最小预约人数
*/
private Integer minNumber;
/**
* 最大预约人数
*/
private Integer maxNumber;
@Serial
private static final long serialVersionUID = 1L;
}

View File

@ -2,6 +2,9 @@ package com.cultural.heritage.service.good;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.AppointmentDate;
import com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO;
import java.util.List;
public interface AppointmentDateService extends IService<AppointmentDate> {
@ -9,4 +12,16 @@ public interface AppointmentDateService extends IService<AppointmentDate> {
* 校验
*/
void validAppointmentDate(AppointmentDate appointmentDate, boolean update);
/**
* (多表联查)查询所有商品的预约情况
*/
List<AppointmentDateTimePeriodVO> queryAppointmentDateDetail();
/**
* (多表联查)根据id查询商品的预约情况
*/
List<AppointmentDateTimePeriodVO> queryAppointmentDateDetailById(Long goodId);
}

View File

@ -12,7 +12,7 @@ public interface GoodService extends IService<Good> {
/**
* 获取查询条件
*/
QueryWrapper<Good> getGoodQueryWrapper(GoodQueryRequest goodQueryRequest);
QueryWrapper<Good> getGoodQueryWrapper(GoodQueryRequest goodQueryRequest, boolean isServiceGood);
/**

View File

@ -0,0 +1,13 @@
package com.cultural.heritage.service.good;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cultural.heritage.model.entity.TimePeriod;
public interface TimePeriodService extends IService<TimePeriod> {
/**
* 校验
*/
void validTimePeriod(TimePeriod timePeriod, boolean update);
}

View File

@ -3,10 +3,9 @@ package com.cultural.heritage.service.good.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.exception.ThrowUtils;
import com.cultural.heritage.mapper.AppointmentDateMapper;
import com.cultural.heritage.model.entity.AppointmentDate;
import com.cultural.heritage.model.entity.Good;
import com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO;
import com.cultural.heritage.service.good.AppointmentDateService;
import com.cultural.heritage.service.good.GoodService;
import jakarta.annotation.Resource;
@ -14,6 +13,8 @@ import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class AppointmentDateServiceImpl extends ServiceImpl<AppointmentDateMapper, AppointmentDate> implements AppointmentDateService {
@ -22,6 +23,10 @@ public class AppointmentDateServiceImpl extends ServiceImpl<AppointmentDateMappe
private GoodService goodService;
@Resource
private AppointmentDateMapper appointmentDateMapper;
/**
* 校验
*/
@ -29,10 +34,8 @@ public class AppointmentDateServiceImpl extends ServiceImpl<AppointmentDateMappe
public void validAppointmentDate(AppointmentDate appointmentDate, boolean update) {
Long id = appointmentDate.getId();
String specificDate = appointmentDate.getSpecificDate();
String timeSlot = appointmentDate.getTimeSlot();
Integer isAvailable = appointmentDate.getIsAvailable();
Long goodId = appointmentDate.getGoodId();
String numberRange = appointmentDate.getNumberRange();
if (update) {
if (id == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "参数id错误");
@ -44,11 +47,29 @@ public class AppointmentDateServiceImpl extends ServiceImpl<AppointmentDateMappe
if (ObjectUtils.isEmpty(goodId)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "商品id参数为null");
}
Good good = goodService.getById(goodId);
ThrowUtils.throwIf(good == null, ErrorCode.SYSTEM_ERROR, "商品不存在");
if (StringUtils.isAnyBlank(specificDate, timeSlot, numberRange)) {
if (StringUtils.isBlank(specificDate)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空");
}
}
/**
* (多表联查)查询所有商品的预约情况
*/
@Override
public List<AppointmentDateTimePeriodVO> queryAppointmentDateDetail() {
return appointmentDateMapper.queryAppointmentDateDetail();
}
/**
* (多表联查)根据id查询商品的预约情况
*/
@Override
public List<AppointmentDateTimePeriodVO> queryAppointmentDateDetailById(Long goodId) {
return appointmentDateMapper.queryAppointmentDateDetailById(goodId);
}
}

View File

@ -26,7 +26,7 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
* 商品查询条件
*/
@Override
public QueryWrapper<Good> getGoodQueryWrapper(GoodQueryRequest goodQueryRequest) {
public QueryWrapper<Good> getGoodQueryWrapper(GoodQueryRequest goodQueryRequest, boolean isServiceGood) {
if (goodQueryRequest == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
}
@ -41,9 +41,14 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
QueryWrapper<Good> queryWrapper = new QueryWrapper<>();
queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
queryWrapper.like(StringUtils.isNotBlank(name), "name", name);
queryWrapper.like(StringUtils.isNotBlank(type), "type", type);
queryWrapper.eq(ObjectUtils.isNotEmpty(festivalOrder), "festivalOrder", festivalOrder);
int isGoodType = 0;
if (!isServiceGood){
isGoodType = 1;
queryWrapper.like(StringUtils.isNotBlank(type), "type", type);
queryWrapper.eq(ObjectUtils.isNotEmpty(festivalOrder), "festivalOrder", festivalOrder);
}
queryWrapper.eq(ObjectUtils.isNotEmpty(isShelves), "isShelves", isShelves);
queryWrapper.eq(ObjectUtils.isNotEmpty(isGoodType), "isGoodType", isGoodType);
queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC),
sortField);
return queryWrapper;
@ -78,7 +83,7 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
String introDetail = good.getIntroDetail();
String detailImg = good.getDetailImg();
String label = good.getLabel();
// Integer inventory = good.getInventory();
Integer inventory = good.getInventory();
Integer festivalOrder = good.getFestivalOrder();
BigDecimal price = good.getPrice();
@ -90,9 +95,9 @@ public class GoodServiceImpl extends ServiceImpl<GoodMapper, Good> implements Go
if (StringUtils.isAnyBlank(type, goodImg, intro, introDetail, detailImg, label, name)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空");
}
// if (ObjectUtils.isEmpty(inventory) || inventory < 1) {
// throw new BusinessException(ErrorCode.PARAMS_ERROR, "库存量不能小于1");
// }
if (ObjectUtils.isEmpty(inventory) || inventory < 1) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "库存量不能小于1");
}
if (ObjectUtils.isEmpty(festivalOrder) || festivalOrder < 0) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "节日参数错误");
}

View File

@ -0,0 +1,40 @@
package com.cultural.heritage.service.good.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cultural.heritage.common.ErrorCode;
import com.cultural.heritage.exception.BusinessException;
import com.cultural.heritage.mapper.TimePeriodMapper;
import com.cultural.heritage.model.entity.TimePeriod;
import com.cultural.heritage.service.good.TimePeriodService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@Service
public class TimePeriodServiceImpl extends ServiceImpl<TimePeriodMapper, TimePeriod> implements TimePeriodService {
@Override
public void validTimePeriod(TimePeriod timePeriod, boolean update) {
Long id = timePeriod.getId();
Integer minNumber = timePeriod.getMinNumber();
Integer maxNumber = timePeriod.getMaxNumber();
String timeSlot = timePeriod.getTimeSlot();
Long appointmentDateId = timePeriod.getAppointmentDateId();
if (update) {
if (id == null) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "预约日期id参数错误");
}
}
if (ObjectUtils.anyNull(minNumber, maxNumber, appointmentDateId)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "存在参数为空");
}
if (minNumber > maxNumber) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "最小预约人数不能超过最大预约人数");
}
if (StringUtils.isBlank(timeSlot)) {
throw new BusinessException(ErrorCode.PARAMS_ERROR, "时间段参数为空");
}
}
}

View File

@ -3,5 +3,16 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cultural.heritage.mapper.AppointmentDateMapper">
<select id="queryAppointmentDateDetail" resultType="com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO">
select a.id, a.specificDate, a.isAvailable, a.goodId, t.id timePeriodId, t.timeSlot, t.minNumber, t.maxNumber
from appointment_date a, time_period t
where a.id = t.appointmentDateId and a.isDelete = 0 and t.isDelete = 0
</select>
<select id="queryAppointmentDateDetailById" resultType="com.cultural.heritage.model.vo.appointment.AppointmentDateTimePeriodVO">
select a.id, a.specificDate, a.isAvailable, goodId, t.id timePeriodId, t.timeSlot, t.minNumber, t.maxNumber
from appointment_date a, time_period t
where a.id = t.appointmentDateId and a.isDelete = 0 and t.isDelete = 0 and a.goodId = #{goodId}
</select>
</mapper>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cultural.heritage.mapper.TimePeriodMapper">
</mapper>

View File

@ -0,0 +1,6 @@
package com.cultural.heritage.test;
public class A {
public Long num = 10L;
}

View File

@ -0,0 +1,5 @@
package com.cultural.heritage.test;
public class B {
public Long num = 10L;
}

View File

@ -1,8 +1,5 @@
package com.cultural.heritage.test;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
public class Test {
public static void main(String[] args) {
// Date date = new Date();
@ -29,15 +26,25 @@ public class Test {
// Integer quantity = 10;
// BigDecimal bigDecimal = BigDecimal.valueOf(quantity);
// System.out.println(bigDecimal);
DateTime date = DateUtil.date();
System.out.println(date);
String formatDate = DateUtil.formatDate(date);
System.out.println(formatDate);
// DateTime date = DateUtil.date();
// System.out.println(date);
// String formatDate = DateUtil.formatDate(date);
// System.out.println(formatDate);
// String str = "2024-11-21 22:43:33";
// DateTime parse = DateUtil.parse(str);
// System.out.println(parse);
// Map<Long, Good> map = new HashMap<>();
// System.out.println(map.get(5));
// List<Long> ids = new ArrayList<>();
// Long number = 1L;
// ids.add(1L);
// System.out.println(ids.get(0) == number);
// System.out.println(Objects.equals(new A().num, new B().num));
}
}