|
|
@@ -0,0 +1,98 @@
|
|
|
+package com.fire.order.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import com.fire.order.request.OrderRequestContent;
|
|
|
+import com.fire.order.request.OrderRequestMsgBody;
|
|
|
+import com.fire.order.request.OrderRequestParam;
|
|
|
+import com.fire.order.response.OrderResp;
|
|
|
+import com.fire.order.response.OrderResponseDto;
|
|
|
+import com.fire.order.response.OrderResponseMsgBody;
|
|
|
+import com.fire.order.service.MakeOrderService;
|
|
|
+import com.fire.param.HeaderDto;
|
|
|
+import com.fire.utils.date.DateUtils;
|
|
|
+import com.fire.utils.string.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import static com.fire.dto.enums.Status.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 下单服务实现层
|
|
|
+ *
|
|
|
+ * @author ZJQ 2021年5月14日17:13:54
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MakeOrderServiceImpl implements MakeOrderService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下单方法
|
|
|
+ *
|
|
|
+ * @param orderRequestParam 下单参数
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public OrderResponseDto makeOrder(OrderRequestParam orderRequestParam) {
|
|
|
+ //初始化下单响应类
|
|
|
+ OrderResponseDto responseDto = new OrderResponseDto();
|
|
|
+ OrderResp orderResp = new OrderResp();
|
|
|
+ OrderResponseMsgBody msgBody = new OrderResponseMsgBody();
|
|
|
+ msgBody.setResp(orderResp);
|
|
|
+ responseDto.setMsgBody(msgBody);
|
|
|
+ //判断请求参数是否为空
|
|
|
+ if (null == orderRequestParam) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("请求参数为空");
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ HeaderDto header = orderRequestParam.getHeader();
|
|
|
+ //判断头信息是否为空
|
|
|
+ if (null == header) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("请求参数头信息为空");
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ responseDto.setHeader(header);
|
|
|
+ //校验时间戳
|
|
|
+ Long now = System.currentTimeMillis();
|
|
|
+ String orderTime = header.getTimestamp();
|
|
|
+ if (null == orderTime) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("时间戳为空");
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ Long orderT = DateUtils.String2Long(orderTime);
|
|
|
+ if (orderT == 0) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("时间戳格式错误");
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Math.abs(now - orderT) > 300000) {
|
|
|
+ orderResp.setRCode(OVER_TIME.status());
|
|
|
+ orderResp.setRMsg(OVER_TIME.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //校验消息体
|
|
|
+ OrderRequestMsgBody requestMsgBody = orderRequestParam.getMsgBody();
|
|
|
+ if (null == requestMsgBody) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("请求消息体为空");
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //参数正文校验
|
|
|
+ OrderRequestContent content = requestMsgBody.getContent();
|
|
|
+ if (null == content) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("请求参数正文为空");
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //手机号校验
|
|
|
+ String phoneNo = content.getUser();
|
|
|
+ if (!StringUtils.isMobile(phoneNo)) {
|
|
|
+ orderResp.setRCode(PHONE_NUM_ERROR.status());
|
|
|
+ orderResp.setRMsg(PHONE_NUM_ERROR.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|