Commit 07f2e13f by 刘鹏飞

创建订单增加下单时间判断

parent 86f76417
......@@ -67,6 +67,7 @@ public enum ResponseResult {
STORE_CLOSED_FOREVER("43017", "门店已关闭,请选择其他门店"),
STORE_CLOSED_THE_NIGHT("43018", "门店已打烊,请选择其他门店"),
STORE_DELIVERY_HOUR_ERROR("43019", "门店外卖时间错误"),
STORE_WILL_COLSE("43020", "门店即将打烊,不能下单"),
/**
* 购物车状态码
......
......@@ -28,6 +28,8 @@ import cn.freemud.interceptor.ServiceException;
import cn.freemud.manager.StoreTableNumberManager;
import cn.freemud.service.CouponService;
import cn.freemud.service.adapter.OrderCheckAdapter;
import cn.freemud.service.order.OrderRelationFactory;
import cn.freemud.service.order.OrderRelationService;
import cn.freemud.service.thirdparty.ShoppingCartClient;
import cn.freemud.service.thirdparty.StockClient;
import cn.freemud.utils.LogUtil;
......@@ -111,7 +113,8 @@ public class CheckOrder {
@Autowired
private CouponService couponService;
private static Gson gson = new Gson();
@Autowired
private OrderRelationFactory orderRelationFactory;
/**
* 下单会员相关校验
*/
......@@ -181,6 +184,11 @@ public class CheckOrder {
*/
public Integer checkOrderByOrderType(CreateOrderVo createOrderVo, AssortmentCustomerInfoVo userLoginInfoDto,
StoreResponse.BizVO storeResponseDto, ShoppingCartGoodsDto shoppingCartGoodsDto, String trackingNo) {
// 下单时间校验
OrderRelationService orderRelationService = orderRelationFactory.getCreateOrderTimeCheckService(createOrderVo.getPartnerId());
orderRelationService.createOrderTimeCheck(storeResponseDto, createOrderVo);
Integer pushOrderTime = 0;
//非到店或者外卖,类型错误
if (!(CreateOrderType.COLLECT_GOODS.getCode().equals(createOrderVo.getOrderType()) ||
......
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationFactory
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.order;
public interface OrderRelationFactory {
/**
* 获取创建订单的时间检查实现类
* @param partnerId
* @return
*/
OrderRelationService getCreateOrderTimeCheckService(String partnerId);
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationService
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.order;
import cn.freemud.entities.vo.CreateOrderVo;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
public interface OrderRelationService {
/**
* 创建订单的时间检查
* @param
*/
void createOrderTimeCheck(StoreResponse.BizVO storeResponseDto, CreateOrderVo createOrderVo);
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: CocoOrderRelationServiceImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.order.impl;
import cn.freemud.base.util.DateUtil;
import cn.freemud.entities.dto.order.BusinessDate;
import cn.freemud.entities.vo.CreateOrderVo;
import cn.freemud.enums.CreateOrderType;
import cn.freemud.enums.ResponseResult;
import cn.freemud.interceptor.ServiceException;
import cn.freemud.service.order.OrderRelationService;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import com.freemud.application.sdk.api.storecenter.service.StoreCenterService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service("cocoOrderRelationService")
public class CocoOrderRelationServiceImpl implements OrderRelationService {
//门店SDK
@Autowired
private StoreCenterService storeCenterService;
@Override
public void createOrderTimeCheck(StoreResponse.BizVO storeResponseDto, CreateOrderVo createOrderVo) {
// 只有外卖单才做下单时间判断
if (CreateOrderType.TAKE_OUT.getCode().equals(createOrderVo.getOrderType())){
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 = 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);
}
}
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);
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;
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: OrderRelationFactoryImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.order.impl;
import cn.freemud.service.order.OrderRelationFactory;
import cn.freemud.service.order.OrderRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class OrderRelationFactoryImpl implements OrderRelationFactory {
/**
* coco商户
*/
@Value("#{'${coco.partnerId}'.split(',')}")
private List<String> cocoPartnerId;
/**
* coco的订单相关
*/
@Autowired
@Qualifier("cocoOrderRelationService")
OrderRelationService cocoOrderRelationService;
/**
* 平台的订单相关
*/
@Autowired
@Qualifier("platformOrderRelationServiceImpl")
OrderRelationService PlatformOrderRelationServiceImpl;
@Override
public OrderRelationService getCreateOrderTimeCheckService(String partnerId) {
if(cocoPartnerId.contains(partnerId)){
return cocoOrderRelationService;
}else{
return PlatformOrderRelationServiceImpl;
}
}
}
/**
* All rights Reserved, Designed By www.freemud.cn
*
* @Title: PlatformOrderRelationServiceImpl
* @Description:
* @author: pengfei.liu
* @date: 2020/11/23
* @version V1.0
* @Copyright: 2020 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package cn.freemud.service.order.impl;
import cn.freemud.entities.vo.CreateOrderVo;
import cn.freemud.service.order.OrderRelationService;
import com.freemud.application.sdk.api.storecenter.response.StoreResponse;
import org.springframework.stereotype.Service;
@Service("platformOrderRelationServiceImpl")
public class PlatformOrderRelationServiceImpl implements OrderRelationService {
@Override
public void createOrderTimeCheck(StoreResponse.BizVO storeResponseDto, CreateOrderVo createOrderVo) {
}
}
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