|
@@ -0,0 +1,244 @@
|
|
|
+package com.fire.getorder.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.nacos.api.utils.StringUtils;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fire.dto.FlowAppInfo;
|
|
|
+import com.fire.dto.FlowOrderInfo;
|
|
|
+import com.fire.es.OrderEsDto;
|
|
|
+import com.fire.getorder.data.DataPool;
|
|
|
+import com.fire.getorder.request.GetOrderContent;
|
|
|
+import com.fire.getorder.request.GetOrderMsgBody;
|
|
|
+import com.fire.getorder.request.GetOrderParam;
|
|
|
+import com.fire.getorder.response.GetOrderResContent;
|
|
|
+import com.fire.getorder.response.GetOrderResp;
|
|
|
+import com.fire.getorder.response.GetOrderResponseDto;
|
|
|
+import com.fire.getorder.response.GetOrderResponseMsgBody;
|
|
|
+import com.fire.getorder.service.GetOrderService;
|
|
|
+import com.fire.param.HeaderDto;
|
|
|
+import com.fire.utils.date.DateUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
+import redis.clients.jedis.JedisCluster;
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+import static com.fire.dto.enums.Status.*;
|
|
|
+import static com.fire.dto.enums.Status.OVER_TIME;
|
|
|
+import static com.fire.dto.enums.ValidStatus.INVALID;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 客户查询定单状态
|
|
|
+ *
|
|
|
+ * @author QGC 2021年6月23日17:13:54
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class GetOrderServiceImpl implements GetOrderService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JedisCluster jedisCluster;
|
|
|
+
|
|
|
+ public String timeSwap(Date time,String format) {
|
|
|
+ //"yyyy-MM-dd hh:mm:ss"
|
|
|
+ DateFormat df = new SimpleDateFormat(format);
|
|
|
+ if (time==null){
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String s = df.format(time);
|
|
|
+ return s;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户查询定单状态
|
|
|
+ *
|
|
|
+ * @param getOrderParam 下单参数
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public GetOrderResponseDto getOrder(GetOrderParam getOrderParam) {
|
|
|
+ //初始化查询定单响应类
|
|
|
+ GetOrderResponseDto responseDto = new GetOrderResponseDto();
|
|
|
+ GetOrderResp orderResp = new GetOrderResp();
|
|
|
+ GetOrderResponseMsgBody msgBody = new GetOrderResponseMsgBody();
|
|
|
+ msgBody.setResp(orderResp);
|
|
|
+ responseDto.setMsgBody(msgBody);
|
|
|
+ //判断请求参数是否为空
|
|
|
+ if (null == getOrderParam) {
|
|
|
+ orderResp.setRCode(PARAM_LOSS.status());
|
|
|
+ orderResp.setRMsg(PARAM_LOSS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ HeaderDto header = getOrderParam.getHeader();
|
|
|
+// //判断头信息是否为空
|
|
|
+ if (null == header) {
|
|
|
+ orderResp.setRCode(PARAM_LOSS.status());
|
|
|
+ orderResp.setRMsg(PARAM_LOSS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ responseDto.setHeader(header);
|
|
|
+ //校验时间戳
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ String orderTime = header.getTimestamp();
|
|
|
+ if (null == orderTime) {
|
|
|
+ orderResp.setRCode(DATE_ERROR.status());
|
|
|
+ orderResp.setRMsg(DATE_ERROR.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ long orderT = DateUtils.String2Long(orderTime);
|
|
|
+ if (orderT == 0) {
|
|
|
+ orderResp.setRCode(DATE_ERROR.status());
|
|
|
+ orderResp.setRMsg(DATE_ERROR.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ if (Math.abs(now - orderT) > 300000) {
|
|
|
+ orderResp.setRCode(OVER_TIME.status());
|
|
|
+ orderResp.setRMsg(OVER_TIME.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //校验seqNo是否为空
|
|
|
+ String seqNo = header.getSeqNo();
|
|
|
+ if (StringUtils.isEmpty(seqNo)) {
|
|
|
+ orderResp.setRCode(PARAM_LOSS.status());
|
|
|
+ orderResp.setRMsg("seqNo" + PARAM_LOSS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //校验appId
|
|
|
+ String appId = header.getAppId();
|
|
|
+ if (StringUtils.isEmpty(appId)) {
|
|
|
+ orderResp.setRCode(APP_ID_LOSE.status());
|
|
|
+ orderResp.setRMsg(APP_ID_LOSE.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ //appId是否存在
|
|
|
+ FlowAppInfo flowAppInfo = DataPool.flowAppInfoMap.get(appId);
|
|
|
+ if (flowAppInfo == null) {
|
|
|
+ orderResp.setRCode(APP_ID_LOSE.status());
|
|
|
+ orderResp.setRMsg(APP_ID_LOSE.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //appId是否失效
|
|
|
+ if (INVALID.status().equals(flowAppInfo.getStatus())) {
|
|
|
+ orderResp.setRCode(APP_ID_LOSE.status());
|
|
|
+ orderResp.setRMsg(APP_ID_LOSE.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ String secretStr = header.getTimestamp() + seqNo + appId + flowAppInfo.getAppKey();
|
|
|
+ String secretKey = DigestUtils.md5DigestAsHex(secretStr.getBytes(StandardCharsets.UTF_8));
|
|
|
+ //secretKey校验
|
|
|
+ if (!secretKey.equals(header.getSecretKey())) {
|
|
|
+ orderResp.setRCode(SECRET_KEY_ERROR.status());
|
|
|
+ orderResp.setRMsg(SECRET_KEY_ERROR.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //校验消息体
|
|
|
+ GetOrderMsgBody requestMsgBody = getOrderParam.getMsgBody();
|
|
|
+ if (null == requestMsgBody) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("body" + PARAM_LOSS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //参数正文校验
|
|
|
+ GetOrderContent content = requestMsgBody.getContent();
|
|
|
+ if (null == content) {
|
|
|
+ orderResp.setRCode(FAILURE_SERVER.status());
|
|
|
+ orderResp.setRMsg("content" + PARAM_LOSS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ //orderId
|
|
|
+ String orderId = content.getOrderId();
|
|
|
+ //CP订单号
|
|
|
+ String extensionId = content.getExtensionId();
|
|
|
+ //sign校验
|
|
|
+ String signStr = header.getSecretKey() + orderId + extensionId;
|
|
|
+ String sign = DigestUtils.md5DigestAsHex(signStr.getBytes(StandardCharsets.UTF_8));
|
|
|
+ //sign校验
|
|
|
+ if (!sign.equals(content.getSign())) {
|
|
|
+ orderResp.setRCode(SIGN_FAIL.status());
|
|
|
+ orderResp.setRMsg(SIGN_FAIL.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(orderId) && StringUtils.isEmpty(extensionId)) {
|
|
|
+ orderResp.setRCode(ORDER_NOT_EXISTS.status());
|
|
|
+ orderResp.setRMsg(ORDER_NOT_EXISTS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ //判断extensionId不为空时查询orderId
|
|
|
+ if (!StringUtils.isBlank(extensionId)) {
|
|
|
+ Long customerId = flowAppInfo.getCustomerId();
|
|
|
+ String searchString = extensionId + "." + customerId;
|
|
|
+ //redis位置
|
|
|
+ int num = searchString.hashCode() % 10000;
|
|
|
+ String redisIndex = "{down.order." + num + "}";
|
|
|
+ //redis查询orderId
|
|
|
+ String resOrderId = jedisCluster.hget(redisIndex, redisIndex + searchString);
|
|
|
+ if (!StringUtils.isBlank(orderId)) {
|
|
|
+ if (!resOrderId.equals(orderId)) {
|
|
|
+ orderResp.setRCode(ORDER_NOT_EXISTS.status());
|
|
|
+ orderResp.setRMsg(ORDER_NOT_EXISTS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ orderId = resOrderId;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //查询订单详情
|
|
|
+ long temNum = 0L;
|
|
|
+ try {
|
|
|
+ temNum = Long.valueOf(orderId) / 10000000;
|
|
|
+ } catch(Exception e){
|
|
|
+ log.error(e.toString());
|
|
|
+ orderResp.setRCode(ORDER_NOT_EXISTS.status());
|
|
|
+ orderResp.setRMsg(ORDER_NOT_EXISTS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ String redisIndex = "order.info." + temNum;
|
|
|
+ String resString = jedisCluster.hget(redisIndex,orderId);
|
|
|
+ if (StringUtils.isEmpty(resString)) {
|
|
|
+ orderResp.setRCode(ORDER_NOT_EXISTS.status());
|
|
|
+ orderResp.setRMsg(ORDER_NOT_EXISTS.message());
|
|
|
+ return responseDto;
|
|
|
+ }else{
|
|
|
+ try {
|
|
|
+ ObjectMapper om = new ObjectMapper();
|
|
|
+ FlowOrderInfo flowOrderInfo = om.readValue(resString, FlowOrderInfo.class);
|
|
|
+ GetOrderResContent getOrderResContent = new GetOrderResContent();
|
|
|
+ getOrderResContent.setOrderId(flowOrderInfo.getOrderId().toString());
|
|
|
+ getOrderResContent.setOrderType(flowOrderInfo.getOrderType().toString());
|
|
|
+ getOrderResContent.setUser(flowOrderInfo.getPhoneNo());
|
|
|
+ getOrderResContent.setReqDate(timeSwap(flowOrderInfo.getApplyDate(),"yyyyMMdd"));
|
|
|
+ getOrderResContent.setPackageId(flowOrderInfo.getPackageId());
|
|
|
+ getOrderResContent.setStatus(flowOrderInfo.getStatus().toString());
|
|
|
+ getOrderResContent.setExtorder(flowOrderInfo.getExtorderId());
|
|
|
+ getOrderResContent.setMsg(flowOrderInfo.getGwErrorCode());
|
|
|
+ getOrderResContent.setPrice(flowOrderInfo.getFlowAmount().toString());
|
|
|
+ getOrderResContent.setCheckTime(timeSwap(flowOrderInfo.getApplyDate(),"yyyyMMddHHmmssSSS"));
|
|
|
+ getOrderResContent.setAttr1(flowOrderInfo.getAttr1());
|
|
|
+ getOrderResContent.setAttr2(flowOrderInfo.getAttr2());
|
|
|
+ getOrderResContent.setAttr3(flowOrderInfo.getAttr3());
|
|
|
+ msgBody.setContent(getOrderResContent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ orderResp.setRCode(ORDER_NOT_EXISTS.status());
|
|
|
+ orderResp.setRMsg(ORDER_NOT_EXISTS.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ orderResp.setRCode(SUCCESS_SERVER.status());
|
|
|
+ orderResp.setRMsg(SUCCESS_SERVER.message());
|
|
|
+ return responseDto;
|
|
|
+ }
|
|
|
+}
|