Commit 9a591ece by 周晓航

重新开启门店营业时间校验规则

Signed-off-by: 周晓航 <xiaohang.zhou@freemud.com>
parent d6a31c19
......@@ -176,6 +176,7 @@ public enum ResponseResult {
STORE_SELF_ERROR("45069", "请选择截止营业时间大于45分钟下单",""),
COUPON_INVALID("45070", "券已锁定,请先支付或取消待支付订单",""),
ORDER_RECEIVE_ERR("45071", "确认收货失败,请稍后再试",""),
STORE_NO_OPEN("45072", "选择时间不在门店营业时间范围内",""),
/**
* 售后单
......
......@@ -113,7 +113,7 @@ public class CheckOrder {
private MemberPropertyService memberPropertyService;
@Autowired
private ShoppingCartClient shoppingCartClient;
// @Autowired
// @Autowired
// private OrderAdapter orderAdapter;
@Autowired
private StoreServiceImpl storeService;
......@@ -192,7 +192,7 @@ public class CheckOrder {
/**
* 查询门店信息新接口
*/
public SoreMixResponseDto getStoreInfoNew(String partnerId, String shopId,Boolean queryBusinessInfo) {
public SoreMixResponseDto getStoreInfoNew(String partnerId, String shopId, Boolean queryBusinessInfo) {
// 获取门店信息
StoreInfoRequestDto request = new StoreInfoRequestDto();
request.setPartnerId(partnerId);
......@@ -253,7 +253,7 @@ public class CheckOrder {
// 获取门店信息
SoreMixResponseDto storeInfoNew = getStoreInfoNew(partnerId, shopId, true);
BusinessInfoDto businessInfo =storeInfoNew.getBusinessInfo();
BusinessInfoDto businessInfo = storeInfoNew.getBusinessInfo();
return businessInfo;
}
......@@ -315,9 +315,9 @@ public class CheckOrder {
}
//扫桌码下单开关判断
businessInfoDto = this.queryBusinessInfoNew(createOrderVo);
if(businessInfoDto != null && businessInfoDto.getExpandFields() != null
if (businessInfoDto != null && businessInfoDto.getExpandFields() != null
&& ScanOrderSwitchEnum.TRUE.getCode().equals(businessInfoDto.getExpandFields().getScanOrderSwitch())
&& StringUtils.isBlank(createOrderVo.getTableNumber())){
&& StringUtils.isBlank(createOrderVo.getTableNumber())) {
throw new ServiceException(ResponseResult.ORDER_TABLE_BINDING_ERROR);
}
createOrderVo.setUserName(userLoginInfoDto.getNickName());
......@@ -328,13 +328,13 @@ public class CheckOrder {
// 设置预约时间
Date takeMealDateTime = getOrderExpectTime(takeMealFlag, takeMealTimes, createOrderVo.getExpectTime(),
CreateOrderType.getByCode(createOrderVo.getOrderType()), storeResponseDto.getServiceTime(), storeResponseDto);
AppLogUtil.infoLog("fisherman 校验门店时间数据 00", JSON.toJSONString(takeMealDateTime),takeMealTimes);
AppLogUtil.infoLog("fisherman 校验门店时间数据 00", JSON.toJSONString(takeMealDateTime), takeMealTimes);
if (takeMealDateTime != null && !isAdvanceOrder) {
//校验预约时间 -->
checkOrderExpectTime(createOrderVo, storeResponseDto, takeMealDateTime);
//重新赋值为yyyy-MM-dd HH:mm:ss格式字符串时间
createOrderVo.setExpectTime(DateUtil.convert2String(takeMealDateTime, DateUtil.FORMAT_YYYY_MM_DD_HHMMSS));
}else {
} else {
if (isAdvanceOrder) {
//fisherman-ka 预定单校验是否在预计开业时间范围内, 2. 校验 营业结束前十分钟,不允许下预约单(上面有代码,可以复用)
if (Objects.isNull(businessInfoDto)) {
......@@ -406,21 +406,22 @@ public class CheckOrder {
storeDeliveryInfoDto.setEnableTakeaway(true);
// 校验收货地址是否可配送 fisherman -> 获取门店预计送达时间
checkReceiveAddress(storeDeliveryInfoDto, createOrderVo,storeResponseDto.getStoreCode());
checkReceiveAddress(storeDeliveryInfoDto, createOrderVo, storeResponseDto.getStoreCode());
}
return pushOrderTime;
}
/**
* 预定单的 额外校验:
* 是否支持预定单 完成
* 预定单校验是否在预计开业时间范围内, ?
* 营业结束前十分钟,不允许下预约单(上面有代码,可以复用)
* 下面俩参数 在新的 /api/v2/organization/getStoreMix 可以一次性查出来 后续人员需要优化
* 预定单的 额外校验:
* 是否支持预定单 完成
* 预定单校验是否在预计开业时间范围内, ?
* 营业结束前十分钟,不允许下预约单(上面有代码,可以复用)
* 下面俩参数 在新的 /api/v2/organization/getStoreMix 可以一次性查出来 后续人员需要优化
*
* @param queryBusinessInfoNew
* @param storeResponseDto
*/
private void checkAdvanceOrderExpectTime(BusinessInfoDto queryBusinessInfoNew,StoreResponse.BizVO storeResponseDto, Date takeMealDateTime) {
private void checkAdvanceOrderExpectTime(BusinessInfoDto queryBusinessInfoNew, StoreResponse.BizVO storeResponseDto, Date takeMealDateTime) {
AppLogUtil.infoLog("fisherman 校验门店时间数据 01", JSON.toJSONString(storeResponseDto),
JSON.toJSONString(takeMealDateTime));
if (Objects.isNull(queryBusinessInfoNew)) {
......@@ -430,20 +431,9 @@ public class CheckOrder {
// 没开启 抛出异常
throw new ServiceException(ResponseResult.STORE_ITEM_NOT_ADVANCE);
}
// fisherman 预计 营业时间范围校验 begin
List<String> nextDayBusinessTime = storeCenterService.getNextDayBusinessTime(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHours());
if (CollectionUtils.isEmpty(nextDayBusinessTime)) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
for (String bussinessTime : nextDayBusinessTime) {
BusinessDate bussinessTime2 = this.getStoreBusinessDate(bussinessTime, true);
AppLogUtil.infoLog("fisherman 校验门店时间数据 02", JSON.toJSONString(bussinessTime2),takeMealDateTime);
// 取餐时间在营业时间前面, 或者在营业结束时间后面
boolean isTrue = takeMealDateTime.after(bussinessTime2.getStartDate()) && takeMealDateTime.before(bussinessTime2.getEndDate());
if (!isTrue) {
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
}
}
this.getBusinessTimeByType(Integer.parseInt(storeResponseDto.getBusinessType()), storeResponseDto.getBusinessHours(),takeMealDateTime);
//预计 营业时间范围校验 end
// 营业结束前校验 结束时间前十分钟可以下单 begin
......@@ -456,7 +446,7 @@ public class CheckOrder {
for (String todayTime : todayBusinessTimes) {
//每段营业时间校验
BusinessDate businessDate2 = this.getStoreBusinessDate(todayTime, true);
AppLogUtil.infoLog("fisherman 校验门店时间数据 03", JSON.toJSONString(businessDate2),null);
AppLogUtil.infoLog("fisherman 校验门店时间数据 03", JSON.toJSONString(businessDate2), null);
if (createOrder.after(businessDate2.getEndDate())) {
throw new ServiceException(ResponseResult.ORDER_TAKEMEALTIME_INVAILD);
}
......@@ -464,7 +454,8 @@ public class CheckOrder {
}
/**
* 是否是 预定单
* 是否是 预定单
*
* @param bizType=7 就是预定单
* @return true 预定单
*/
......@@ -643,43 +634,7 @@ public class CheckOrder {
}
public BusinessDate getStoreBusinessDate(String businessHoursDay, boolean today) {
BusinessDate businessDate = new BusinessDate();
//设置营业开始和结束时间
String businessHourStr = businessHoursDay.replace("-", ",").replace("_", ",");
String[] businessHours = businessHourStr.split(",");
if (businessHours.length != 2) {
throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
}
Date date = new Date();
if (!today) {
date = DateUtil.addDays(date, 1);
}
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);
//判断营业开始时间是24:00点
if (startDateTime == null) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
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);
}
// 校验门店是否打烊,打烊了则不让操作
if (startDateTime == null || endDateTime == null) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
businessDate.setStartDate(startDateTime);
businessDate.setEndDate(endDateTime);
return businessDate;
return this.getStoreBusinessDate(businessHoursDay, today ? 0 : 1);
}
public ShoppingCartGoodsDto getShoppingCartGoodsDto(CreateOrderVo createOrderVo) {
......@@ -729,7 +684,7 @@ public class CheckOrder {
// 如果批量使用优惠券或者商品券,校验 couponCode
List<ShoppingCartInfoRequestVo.couponCode> couponCodes = new ArrayList();
if (createOrderVo.getCouponCodes() != null && !createOrderVo.getCouponCodes().isEmpty()) {
createOrderVo.getCouponCodes().forEach(couponCode->{
createOrderVo.getCouponCodes().forEach(couponCode -> {
// 校验couponCode
GetCouponDetailResponseDto getCouponDetailResponseDto = couponService.getMemberCoupon(GetMemberCouponRequestVo.builder()
.partnerId(createOrderVo.getPartnerId())
......@@ -749,7 +704,7 @@ public class CheckOrder {
couponCodes.add(coupon);
});
if(StringUtils.isEmpty(shoppingCartInfoRequestVo.getCardCode())){
if (StringUtils.isEmpty(shoppingCartInfoRequestVo.getCardCode())) {
shoppingCartInfoRequestVo.setCardCode(createOrderVo.getCardCode());
}
}
......@@ -773,10 +728,10 @@ public class CheckOrder {
// 这个是专门的给coco使用的验证券的逻辑
if (ObjectUtils.equals(ResponseCodeConstant.COCO_RESPONSE_COUPON_ERR_STR, apportionResponse.getCode())) {
throw new ServiceException(ResponseResult.COCO_COUPON_VALIDATOR_FAIL,apportionResponse.getMessage());
throw new ServiceException(ResponseResult.COCO_COUPON_VALIDATOR_FAIL, apportionResponse.getMessage());
}
if (ObjectUtils.equals(ResponseCodeConstant.USER_HAVE_NO_COUPON, apportionResponse.getCode())) {
throw new ServiceException(ResponseResult.SHOPPING_CART_USER_HAVE_NO_COUPON,apportionResponse.getMessage());
throw new ServiceException(ResponseResult.SHOPPING_CART_USER_HAVE_NO_COUPON, apportionResponse.getMessage());
}
if (!ObjectUtils.equals(ResponseCodeConstant.RESPONSE_SUCCESS_STR, apportionResponse.getCode())) {
......@@ -822,34 +777,34 @@ public class CheckOrder {
private void checkCouonRedeemTime(List<GetCouponDetailResponseDto.ActiveRedeemTimeInterval> activeRedeemTimeIntervalList) {
boolean verificationPassed = false;
if (CollectionUtils.isNotEmpty(activeRedeemTimeIntervalList)){
for (GetCouponDetailResponseDto.ActiveRedeemTimeInterval dateLimit : activeRedeemTimeIntervalList){
if (CollectionUtils.isNotEmpty(activeRedeemTimeIntervalList)) {
for (GetCouponDetailResponseDto.ActiveRedeemTimeInterval dateLimit : activeRedeemTimeIntervalList) {
boolean dayCheck = true;
String weekday = dateLimit.getWeekday(); // 日期限制 0011100 周日开始,0表示不可用
if (StringUtils.isNotBlank(weekday)){ // 存在校验周几
if (StringUtils.isNotBlank(weekday)) { // 存在校验周几
char[] chars = weekday.toCharArray();
int dayOfWeek = LocalDate.now().getDayOfWeek().getValue(); // 从周一开始
if (dayOfWeek == 7){
if (dayOfWeek == 7) {
dayOfWeek = 0;
}
if (Integer.parseInt(String.valueOf(chars[dayOfWeek])) == 0){ //限制
if (Integer.parseInt(String.valueOf(chars[dayOfWeek])) == 0) { //限制
dayCheck = false;
}
}
boolean timeCheck = true;
String begintime = dateLimit.getBegintime(); // 开始时间 00:00:00
String endtime = dateLimit.getEndtime(); // 结束时间 12:59:59
if (StringUtils.isNotBlank(begintime) && StringUtils.isNotBlank(endtime)){ // 存在校验时段
if (StringUtils.isNotBlank(begintime) && StringUtils.isNotBlank(endtime)) { // 存在校验时段
String[] beginTimeArr = begintime.split(":");
String[] endTimeArr = endtime.split(":");
LocalTime beginLocalTime = LocalTime.of(Integer.valueOf(beginTimeArr[0]), Integer.valueOf(beginTimeArr[1]), Integer.valueOf(beginTimeArr[2]));
LocalTime endLocalTime = LocalTime.of(Integer.valueOf(endTimeArr[0]), Integer.valueOf(endTimeArr[1]), Integer.valueOf(endTimeArr[2]));
LocalTime now = LocalTime.now();
if (now.isBefore(beginLocalTime) || now.isAfter(endLocalTime)){
if (now.isBefore(beginLocalTime) || now.isAfter(endLocalTime)) {
timeCheck = false;
}
}
if (dayCheck && timeCheck){
if (dayCheck && timeCheck) {
verificationPassed = true;
break;
}
......@@ -857,7 +812,7 @@ public class CheckOrder {
} else {
verificationPassed = true;
}
if (!verificationPassed){
if (!verificationPassed) {
throw new ServiceException(ResponseResult.COUPON_DATETIME_INVAILD);
}
......@@ -1026,7 +981,7 @@ public class CheckOrder {
/**
* 校验收货地址是否可配送
*/
public void checkReceiveAddress(StoreDeliveryInfoDto storeDeliveryInfoDto, CreateOrderVo createOrderVo,String storeCode) {
public void checkReceiveAddress(StoreDeliveryInfoDto storeDeliveryInfoDto, CreateOrderVo createOrderVo, String storeCode) {
//校验收货地址是否可配送
String receiveId = createOrderVo.getReceiveId();
String trackingNo = LogThreadLocal.getTrackingNo();
......@@ -1069,10 +1024,11 @@ public class CheckOrder {
/**
* 获取 用户预计送达时间 距离
* @param userLat 用户纬度
* @param userLong 用户经度
* @param partnerId 商户号
* @param storeCode 门店号
*
* @param userLat 用户纬度
* @param userLong 用户经度
* @param partnerId 商户号
* @param storeCode 门店号
* @return
*/
private Date getEstimateDeliveryCompleteTime(String userLat,
......@@ -1091,15 +1047,15 @@ public class CheckOrder {
request.setPartnerId(partnerId);
request.setStoreCode(storeCode);
StoreCBaseResponse<StoreCBaseResponseDto> responseDto = storeBaseApiClient.queryDeliverDetail(request);
AppLogUtil.infoLog("fisherman 获取门店预计送达时间",request,responseDto);
AppLogUtil.infoLog("fisherman 获取门店预计送达时间", request, responseDto);
if (responseDto == null) {
throw new ServiceException(ResponseResult.SYSTEM_BUSINESS_ERROR);
}
if(!ResponseResult.SUCCESS.getCode().equals(responseDto.getCode()) || responseDto.getResult() == null){
if (!ResponseResult.SUCCESS.getCode().equals(responseDto.getCode()) || responseDto.getResult() == null) {
throw new ServiceException(ResponseResult.STORE_QUERYEXPECTARRIVETIME);
}
return responseDto.getResult().getExpectArriveTime();
return responseDto.getResult().getExpectArriveTime();
}
......@@ -1166,6 +1122,7 @@ public class CheckOrder {
/**
* 判断是否为拼单订单
*
* @param createOrderVo
* @return
*/
......@@ -1175,13 +1132,14 @@ public class CheckOrder {
/**
* 校验配送信息
* 这里可以获取用户的 预计送达时间
* 这里可以获取用户的 预计送达时间
*
* @param createOrderVo
* @param storeCode
* @param trackingNo
* @return
*/
public String checkDeliveryType(CreateOrderVo createOrderVo,String storeCode,String trackingNo) {
public String checkDeliveryType(CreateOrderVo createOrderVo, String storeCode, String trackingNo) {
String code = "";
QueryDeliveryRequest request = new QueryDeliveryRequest();
request.setStoreCode(storeCode);
......@@ -1200,4 +1158,116 @@ public class CheckOrder {
}
return code;
}
private void getBusinessTimeByType(Integer businessType, String businessHoursDay, Date takeMealDateTime) {
if (businessType == null) {
throw new ServiceException(ResponseResult.STORE_DATE_ERROR);
}
if (businessType.compareTo(1) == 0) {
this.getBusinessTimeByType1(businessHoursDay, takeMealDateTime);
} else if (businessType.compareTo(2) == 0) {
this.getBusinessTimeByType2(businessHoursDay, takeMealDateTime);
}
}
private void getBusinessTimeByType2(String businessHoursDay, Date takeMealDateTime) {
String[] splitArr = businessHoursDay.split(";");
// 取值
// 获取当前星期几, 0 表示 周日
int weekDay = DateUtil.getWeekDay(takeMealDateTime);
int index = weekDay - 1;
index = index < 0 ? splitArr.length - 1 : index;
// 数组里面取值 00-00 就是没设置
String businessHours = splitArr[index];
if ("00: 00-00: 00".equals(businessHours)) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
// 获取营业时间
int weekDay1 = this.getWeekDay(new Date(), takeMealDateTime);
BusinessDate storeBusinessDate = this.getStoreBusinessDate(businessHours, weekDay1);
// 检验 是否在营业时间 范围内
if (takeMealDateTime.before(storeBusinessDate.getStartDate()) || takeMealDateTime.after(storeBusinessDate.getEndDate())) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
}
private BusinessDate getStoreBusinessDate(String businessHoursDay, int today) {
BusinessDate businessDate = new BusinessDate();
//设置营业开始和结束时间
String businessHourStr = businessHoursDay.replace("-", ",").replace("_", ",");
String[] businessHours = businessHourStr.split(",");
if (businessHours.length != 2) {
throw new ServiceException(ResponseResult.STORE_NOT_FOUND);
}
Date date = DateUtil.addDays(new Date(), today);
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);
//判断营业开始时间是24:00点
if (startDateTime == null) {
throw new ServiceException(ResponseResult.STORE_BUSINESS_HOUR_ERROR);
}
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);
}
// 校验门店是否打烊,打烊了则不让操作
if (endDateTime == null) {
throw new ServiceException(ResponseResult.STORE_ITEM_STOP_BUSINESS);
}
businessDate.setStartDate(startDateTime);
businessDate.setEndDate(endDateTime);
return businessDate;
}
/**
* 获取 2个时间之间的天数
*
* @return
*/
private int getWeekDay(Date begin, Date end) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(end);
int endDay = calendar.get(Calendar.DAY_OF_YEAR);
Calendar calendar2 = Calendar.getInstance();
calendar2.setTime(begin);
int begDay = calendar2.get(Calendar.DAY_OF_YEAR);
return endDay - begDay;
}
private void getBusinessTimeByType1(String businessHoursDay, Date takeMealDateTime) {
String[] splitArr = businessHoursDay.split(";");
boolean isBusinessTime = false;
for (String businessHours : splitArr) {
if ("00: 00-00: 00".equals(businessHours)) {
// 不在营业时间范围
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
// 获取营业时间
BusinessDate storeBusinessDate = getStoreBusinessDate(businessHours, true);
// 检验 是否在营业时间 范围内
if (takeMealDateTime.after(storeBusinessDate.getStartDate()) && takeMealDateTime.before(storeBusinessDate.getEndDate())) {
// 在营业时间范围
isBusinessTime = true;
}
}
if (!isBusinessTime) {
throw new ServiceException(ResponseResult.STORE_NO_OPEN);
}
}
}
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