Commit b338ec89 by ping.wu

门店sdk升级,区间营业预约问题修改

parent 07fd1604
......@@ -93,7 +93,7 @@
<dependency>
<groupId>com.freemud.application.service.sdk</groupId>
<artifactId>storecenter-sdk</artifactId>
<version>2.10.5-SNAPSHOT</version>
<version>2.10.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cn.freemud</groupId>
......
......@@ -156,7 +156,10 @@ public class CheckOrder {
throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
}
StoreResponse.BizVO storeResponseDto = storeResponse.getBizVO();
checkOrderByStore(storeResponse.getBizVO());
// 校验门店是否停业 1 营业 2 停业 3 繁忙置休
if (storeResponseDto.getActiveFlag() == null || storeResponseDto.getActiveFlag() != 1) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
createOrderVo.setStoreName(storeResponseDto.getStoreName());
createOrderVo.setStoreAddress(storeResponseDto.getAddress());
createOrderVo.setThirdShopId(storeResponseDto.getThirdPartCode());
......@@ -174,8 +177,6 @@ public class CheckOrder {
CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType()))) {
throw new ServiceException(ResponseResult.PARAMETER_MISSING);
}
String takeMealTimes = createOrderVo.getTakeMealTime();
// TODO: 2020/6/16 门店校验处理
String takeMealFlag = createOrderVo.getTakeMealFlag();
//未营业无预约时间无法下单
......@@ -183,17 +184,17 @@ public class CheckOrder {
throw new ServiceException(ResponseResult.STORE_ITEM_CHECK_CLOSE);
}
String takeMealTimes = createOrderVo.getTakeMealTime();
//有预约时间
if(StringUtils.isNotBlank(takeMealTimes) || StringUtils.isNotBlank(createOrderVo.getExpectTime())){
// 设置预约时间
Date takeMealDateTime = getOrderExpectTime(takeMealFlag,takeMealTimes,createOrderVo.getExpectTime(),
CreateOrderType.getByCode(createOrderVo.getOrderType()),storeResponseDto.getServiceTime());
CreateOrderType.getByCode(createOrderVo.getOrderType()),storeResponseDto.getServiceTime(),storeResponseDto);
if(takeMealDateTime != null){
//校验预约时间
takeMealDateTime = checkOrderExpectTime(createOrderVo,storeResponseDto,takeMealDateTime);
checkOrderExpectTime(createOrderVo,storeResponseDto,takeMealDateTime);
//重新赋值为yyyy-MM-dd HH:mm:ss格式字符串时间
createOrderVo.setExpectTime(takeMealDateTime == null ? null : DateUtil.convert2String(takeMealDateTime, "yyyy-MM-dd HH:mm:ss"));
createOrderVo.setExpectTime(DateUtil.convert2String(takeMealDateTime, "yyyy-MM-dd HH:mm:ss"));
}
}
String appId = userLoginInfoDto.getWxAppId();
......@@ -239,50 +240,56 @@ public class CheckOrder {
return pushOrderTime;
}
public Date checkOrderExpectTime(CreateOrderVo createOrderVo,StoreResponse.BizVO storeResponseDto,Date takeMealDateTime){
public void checkOrderExpectTime(CreateOrderVo createOrderVo,StoreResponse.BizVO storeResponseDto,Date takeMealDateTime){
if(takeMealDateTime == null){
return takeMealDateTime;
return;
}
//获取门店当天营业时间
BusinessDate storeBusinessDate = getStoreBusinessDate(storeResponseDto.getBusinessHoursDay(), true);
Date endDate = storeBusinessDate.getEndDate();
Date startDate =storeBusinessDate.getStartDate();
storeResponseDto.setBusinessHoursDayStartTime(startDate);
storeResponseDto.setBusinessHoursDayEndTime(endDate);
Date todayEndDate =null;
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),true);
todayEndDate = businessDate.getEndDate();
//在当天营业时间内
boolean inTodayBusinessTime = true;
boolean expectTimeInTodayBusinessTime = true;
Date date = new Date();
Date newDate = DateUtil.convert2Date(date,DateUtil.FORMAT_yyyyMMdd_date);
newDate = DateUtil.addDays(newDate,1);
//隔天预约(在明日凌晨之后且在门店营业结束之后)
if(takeMealDateTime.after(newDate) && takeMealDateTime.after(endDate)){
if(takeMealDateTime.after(newDate) && takeMealDateTime.after(todayEndDate)){
expectTimeInTodayBusinessTime =false;
}
if(expectTimeInTodayBusinessTime){
boolean inTodayBusinessTime = true;
for (String todayTime : todayBusinessTimes){
//每段营业时间校验
BusinessDate businessDate2 = getStoreBusinessDate(todayTime,true);
if (takeMealDateTime.after(businessDate2.getStartDate()) && takeMealDateTime.before(businessDate2.getEndDate())) {
inTodayBusinessTime = false;
break;
}
}
if(inTodayBusinessTime){
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
}
}
//隔天预约
if(!expectTimeInTodayBusinessTime){
List<String> nextDayBusinessTimes = storeCenterService.getNextDayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHoursDay());
//当天营业时间结束 不校验预约时间
boolean inNextDayBusinessTime = true;
for (String nextDayTime : nextDayBusinessTimes){
BusinessDate storeNextBusinessDate = getStoreBusinessDate(nextDayTime,false);
if (takeMealDateTime.after(storeNextBusinessDate.getStartDate()) && takeMealDateTime.before(storeNextBusinessDate.getEndDate())) {
inNextDayBusinessTime = false;
break;
}
}
if(inNextDayBusinessTime){
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVALID);
}
}
//00:00-营业结束(隔天营业)
if(takeMealDateTime.after(newDate) && takeMealDateTime.before(endDate)){
return takeMealDateTime;
}
//当前时间刚过凌晨-营业结束(隔天营业)
if(takeMealDateTime.after(date) && takeMealDateTime.before(startDate)){
return takeMealDateTime;
}
//有预约时间,预约时间要在营业时间范围内
if (inTodayBusinessTime && (takeMealDateTime.before(storeResponseDto.getBusinessHoursDayStartTime())
|| takeMealDateTime.after(storeResponseDto.getBusinessHoursDayEndTime()))) {
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
}
if(CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType())){
String deliveryStr = storeResponseDto.getDeliveryHoursDay().replace("-", ",")
......@@ -306,22 +313,21 @@ public class CheckOrder {
throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY);
}
// 校验预约配送时间
if (inTodayBusinessTime && (takeMealDateTime.before(deliveryStartDate) || takeMealDateTime.after(deliveryEndDate))) {
if (expectTimeInTodayBusinessTime && (takeMealDateTime.before(deliveryStartDate) || takeMealDateTime.after(deliveryEndDate))) {
throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY);
}
Date nextDeliveryStartDate = DateUtil.addDays(deliveryStartDate,1);
Date nextDeliveryEndDate = DateUtil.addDays(deliveryEndDate,1);
// 隔日预约外卖校验预约配送时间
if (!inTodayBusinessTime && (takeMealDateTime.before(nextDeliveryStartDate) || takeMealDateTime.after(nextDeliveryEndDate))) {
if (!expectTimeInTodayBusinessTime && (takeMealDateTime.before(nextDeliveryStartDate) || takeMealDateTime.after(nextDeliveryEndDate))) {
throw new ServiceException(ResponseResult.ORDER_CREATE_TIME_NOT_DELIVERY);
}
}
return takeMealDateTime;
}
public Date getOrderExpectTime(String takeMealFlag,String takeMealTimes,String expectTime,
CreateOrderType createOrderType,Integer serviceTime){
CreateOrderType createOrderType,Integer serviceTime,StoreResponse.BizVO storeResponseDto){
Date takeMealDateTime = null;
//0=到店单我已到店、外卖单尽快送出
if (StringUtils.isNotBlank(takeMealFlag) && "0".equals(takeMealFlag)) {
......@@ -330,14 +336,27 @@ public class CheckOrder {
if (StringUtils.isBlank(takeMealTimes) && StringUtils.isBlank(expectTime)) {
return takeMealDateTime;
}
Date date = new Date();
if (StringUtils.isNotBlank(takeMealTimes)) {
StringBuffer takeMealTime = new StringBuffer("");
takeMealTime = takeMealTime.append(DateUtil.convert2String(date, "yyyy-MM-dd"))
.append(" ").append(takeMealTimes).append(":00");
takeMealDateTime = DateUtil.convert2Date(takeMealTime.toString(), "yyyy-MM-dd HH:mm:ss");
//隔天营业的预约时间处理 计算出预约时间在当前时间之前,预约时间加1天
if(takeMealDateTime != null && takeMealDateTime.before(date)){
Date newDate = DateUtil.convert2Date(date,DateUtil.FORMAT_yyyyMMdd_date);
newDate = DateUtil.addDays(newDate,1);
//获取门店当天营业结束时间
Date todayEndDate =null;
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),true);
todayEndDate = businessDate.getEndDate();
//隔天营业的预约时间处理 计算出预约时间在当前时间之前,预约时间加1天 newDate.before(todayEndDate)=隔天营业
if(takeMealDateTime != null && takeMealDateTime.before(date) && newDate.before(todayEndDate)){
takeMealDateTime = DateUtil.addDays(takeMealDateTime,1);
}
}
......@@ -649,36 +668,36 @@ public class CheckOrder {
if (storeResponseDto.getActiveFlag() == null || storeResponseDto.getActiveFlag() != 1) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
//设置营业开始和结束时间
String businessHourStr = storeResponseDto.getBusinessHoursDay().replace("-", ",").replace("_", ",");
String[] businessHours = businessHourStr.split(",");
if (businessHours.length != 2) {
throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
}
Date date = new Date();
String startDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[0] + ":00";
String endDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[1] + ":00";
Date startDateTime ;
Date endDateTime ;
startDateTime = DateUtil.convert2Date(startDateTimeStr, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS);
SimpleDateFormat hhmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
endDateTime = hhmmss.parse(endDateTimeStr);
} catch (ParseException e) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
//隔天营业时间处理
if(startDateTime.after(endDateTime)){
endDateTime = DateUtil.addDays(endDateTime,1);
}
storeResponseDto.setBusinessHoursDayStartTime(startDateTime);
storeResponseDto.setBusinessHoursDayEndTime(endDateTime);
// 校验门店是否打烊,打烊了则不让操作
if (storeResponseDto.getBusinessHoursDayStartTime() == null
|| storeResponseDto.getBusinessHoursDayEndTime() == null) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
// //设置营业开始和结束时间
// String businessHourStr = storeResponseDto.getBusinessHoursDay().replace("-", ",").replace("_", ",");
// String[] businessHours = businessHourStr.split(",");
// if (businessHours.length != 2) {
// throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
// }
// Date date = new Date();
// String startDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[0] + ":00";
// String endDateTimeStr = DateUtil.convert2String(date, DateUtil.FORMAT_YMD) + " " + businessHours[1] + ":00";
// Date startDateTime ;
// Date endDateTime ;
// startDateTime = DateUtil.convert2Date(startDateTimeStr, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS);
// SimpleDateFormat hhmmss = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// try {
// endDateTime = hhmmss.parse(endDateTimeStr);
// } catch (ParseException e) {
// throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
// }
// //隔天营业时间处理
// if(startDateTime.after(endDateTime)){
// endDateTime = DateUtil.addDays(endDateTime,1);
// }
// storeResponseDto.setBusinessHoursDayStartTime(startDateTime);
// storeResponseDto.setBusinessHoursDayEndTime(endDateTime);
//
// // 校验门店是否打烊,打烊了则不让操作
// if (storeResponseDto.getBusinessHoursDayStartTime() == null
// || storeResponseDto.getBusinessHoursDayEndTime() == null) {
// throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
// }
}
}
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