Commit 7fb2bb35 by 周晓航

预定单 预约单 预定时间校验模式修改

Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent 86605b2c
......@@ -46,6 +46,7 @@ import cn.freemud.service.thirdparty.CustomerPropertyClient;
import cn.freemud.service.thirdparty.ShoppingCartClient;
import cn.freemud.service.thirdparty.StoreBaseApiClient;
import cn.freemud.utils.AppLogUtil;
import cn.freemud.utils.DateUtils;
import cn.freemud.utils.ResponseUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
......@@ -505,9 +506,10 @@ public class CheckOrder {
}
Date createOrder = DateUtil.addMinutes(new Date(), 10);
int diffDay = DateUtils.diffDay(new Date(), takeMealDateTime);
for (String todayTime : todayBusinessTimes) {
//每段营业时间校验
BusinessDate businessDate2 = this.getStoreBusinessDate(todayTime, true);
BusinessDate businessDate2 = this.getStoreBusinessDate(todayTime, diffDay);
if (createOrder.after(businessDate2.getEndDate())) {
throw new ServiceException(ResponseResult.STORE_SELF_ERROR_10);
}
......@@ -525,21 +527,6 @@ public class CheckOrder {
&& BizTypeEnum.ADVANCE_ORDER.getBizType().compareTo(bizType) == 0;
}
/**
* 获取门店营业时间
*
* @param storeResponseDto
* @param toDay true 今日,false 明天
* @return
*/
private BusinessDate getStoreBusinessDate(StoreResponseDto storeResponseDto, boolean toDay) {
List<String> todayBusinessTimes = storeCenterService.getTodayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHoursDay());
if (CollectionUtils.isEmpty(todayBusinessTimes)) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
BusinessDate businessDate = getStoreBusinessDate(todayBusinessTimes.get(todayBusinessTimes.size() - 1), toDay);
return businessDate;
}
public void checkOrderExpectTime(CreateOrderVo createOrderVo, StoreResponseDto storeResponseDto, Date takeMealDateTime) {
if (takeMealDateTime == null) {
......@@ -551,11 +538,12 @@ public class CheckOrder {
if (CollectionUtils.isEmpty(todayBusinessTimes)) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
BusinessDate businessDate = getStoreBusinessDate(todayBusinessTimes.get(todayBusinessTimes.size() - 1), true);
Date date = new Date();
int diffDay = DateUtils.diffDay(date, takeMealDateTime);
BusinessDate businessDate = getStoreBusinessDate(todayBusinessTimes.get(todayBusinessTimes.size() - 1), diffDay);
todayEndDate = businessDate.getEndDate();
//在当天营业时间内
boolean expectTimeInTodayBusinessTime = true;
Date date = new Date();
Date newDate = DateUtil.convert2Date(date, DateUtil.FORMAT_yyyyMMdd_date);
newDate = DateUtil.addDays(newDate, 1);
//隔天预约(在明日凌晨之后且在门店营业结束之后)
......@@ -566,7 +554,7 @@ public class CheckOrder {
boolean inTodayBusinessTime = true;
for (String todayTime : todayBusinessTimes) {
//每段营业时间校验
BusinessDate businessDate2 = getStoreBusinessDate(todayTime, true);
BusinessDate businessDate2 = getStoreBusinessDate(todayTime, diffDay);
if (takeMealDateTime.getTime() >= businessDate2.getStartDate().getTime()
&& takeMealDateTime.getTime() <= businessDate2.getEndDate().getTime()) {
inTodayBusinessTime = false;
......@@ -582,7 +570,7 @@ public class CheckOrder {
List<String> nextDayBusinessTimes = storeCenterService.getNextDayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHoursDay());
boolean inNextDayBusinessTime = true;
for (String nextDayTime : nextDayBusinessTimes) {
BusinessDate storeNextBusinessDate = getStoreBusinessDate(nextDayTime, false);
BusinessDate storeNextBusinessDate = getStoreBusinessDate(nextDayTime, diffDay);
if (takeMealDateTime.getTime() >= storeNextBusinessDate.getStartDate().getTime()
&& takeMealDateTime.getTime() <= storeNextBusinessDate.getEndDate().getTime()) {
inNextDayBusinessTime = false;
......@@ -671,7 +659,7 @@ public class CheckOrder {
if (CollectionUtils.isEmpty(todayBusinessTimes)) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
BusinessDate businessDate = getStoreBusinessDate(todayBusinessTimes.get(todayBusinessTimes.size() - 1), true);
BusinessDate businessDate = getStoreBusinessDate(todayBusinessTimes.get(todayBusinessTimes.size() - 1), 0);
todayEndDate = businessDate.getEndDate();
//隔天营业的预约时间处理 计算出预约时间在当前时间之前,预约时间加1天 newDate.before(todayEndDate)=隔天营业
......@@ -694,9 +682,6 @@ public class CheckOrder {
return takeMealDateTime;
}
public BusinessDate getStoreBusinessDate(String businessHoursDay, boolean today) {
return this.getStoreBusinessDate(businessHoursDay, today ? 0 : 1);
}
public ShoppingCartGoodsDto getShoppingCartGoodsDto(CreateOrderVo createOrderVo) {
// ShoppingCartInfoRequestVo.BuyMemberCard buyMemberCard = null;
......@@ -1403,7 +1388,7 @@ public class CheckOrder {
}
}
private BusinessDate getStoreBusinessDate(String businessHoursDay, int today) {
public BusinessDate getStoreBusinessDate(String businessHoursDay, int today) {
BusinessDate businessDate = new BusinessDate();
//设置营业开始和结束时间
String businessHourStr = businessHoursDay.replace("-", ",").replace("_", ",");
......@@ -1460,13 +1445,14 @@ public class CheckOrder {
private void getBusinessTimeByType1(String businessHoursDay, Date takeMealDateTime) {
String[] splitArr = businessHoursDay.split(";");
boolean isBusinessTime = false;
int diffDay = DateUtils.diffDay(new Date(), takeMealDateTime);
for (String businessHours : splitArr) {
if ("00: 00-00: 00".equals(businessHours)) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
// 获取营业时间
BusinessDate storeBusinessDate = getStoreBusinessDate(businessHours, true);
BusinessDate storeBusinessDate = getStoreBusinessDate(businessHours, diffDay);
// 检验 是否在营业时间 范围内
if (takeMealDateTime.after(storeBusinessDate.getStartDate()) && takeMealDateTime.before(storeBusinessDate.getEndDate())) {
// 在营业时间范围
......
......@@ -16,7 +16,6 @@ import cn.freemud.base.util.DateUtil;
import cn.freemud.entities.dto.StoreResponseDto;
import cn.freemud.entities.dto.order.BusinessDate;
import cn.freemud.entities.vo.CreateOrderBaseVo;
import cn.freemud.entities.vo.CreateOrderVo;
import cn.freemud.entities.vo.ProductVo;
import cn.freemud.entities.vo.QueryOrderResponseVo;
import cn.freemud.enums.CreateOrderType;
......@@ -28,7 +27,6 @@ import com.alibaba.fastjson.JSONObject;
import com.freemud.application.sdk.api.ordercenter.entities.v1.ProductBeanV1;
import com.freemud.application.sdk.api.ordercenter.entities.v1.ProductDiscountV1;
import com.freemud.application.sdk.api.ordercenter.response.orderInfo.OrderSendCouponResp;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import com.freemud.sdk.api.assortment.order.enums.OldOrderAccountType;
import com.freemud.sdk.api.assortment.order.request.order.OrderProductAddInfoDto;
......@@ -54,42 +52,6 @@ public class CocoOrderRelationServiceImpl implements OrderRelationService {
private CheckOrder checkOrder;
// @Override
public void createOrderTimeCheck(StoreResponseDto storeResponseDto, CreateOrderVo createOrderVo) {
// 只有外卖单才做下单时间判断
if (!CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType())){
return;
}
// 如果是明天的预约单,不做时间检查
// 设置预约时间
Date takeMealDateTime = checkOrder.getOrderExpectTime(createOrderVo.getTakeMealFlag(), createOrderVo.getTakeMealTime(), createOrderVo.getExpectTime(),
CreateOrderType.getByCode(createOrderVo.getOrderType()), storeResponseDto.getServiceTime(), storeResponseDto);
Date todayEnd = DateUtil.setEndDay(new Date());
if(takeMealDateTime != null && todayEnd.before(takeMealDateTime)){
return;
}
//获取门店当天营业时间
// coco只有一个营业时间,如果返回多个就报错
Date todayEndDate = null;
List<String> todayBusinessTimes = storeCenterService.getTodayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHoursDay());
if (CollectionUtils.isEmpty(todayBusinessTimes) || 1 < todayBusinessTimes.size() ) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
BusinessDate businessDate = checkOrder.getStoreBusinessDate(todayBusinessTimes.get(0), true);
todayEndDate = businessDate.getEndDate();
// 当前时间+15分钟 > 门店打烊时间,返回错误
Date nowAddDate = DateUtil.addMinutes(new Date(),15);
if(nowAddDate.after(todayEndDate)){
throw new ServiceException(ResponseResult.STORE_WILL_COLSE);
}
}
// @Override
public void createOrderTimeCheck(StoreResponseDto storeResponseDto, CreateOrderBaseVo createOrderVo) {
// 只有外卖单才做下单时间判断
if (!CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType())){
......@@ -114,7 +76,7 @@ public class CocoOrderRelationServiceImpl implements OrderRelationService {
if (CollectionUtils.isEmpty(todayBusinessTimes) || 1 < todayBusinessTimes.size() ) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
BusinessDate businessDate = checkOrder.getStoreBusinessDate(todayBusinessTimes.get(0), true);
BusinessDate businessDate = checkOrder.getStoreBusinessDate(todayBusinessTimes.get(0), 0);
todayEndDate = businessDate.getEndDate();
// 当前时间+15分钟 > 门店打烊时间,返回错误
......
......@@ -44,6 +44,8 @@ public class DateUtils {
}
}
public static int diffDay(Date before, Date after) {
return Integer.parseInt(String.valueOf((after.getTime() - before.getTime()) / 86400000L));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment