|
@@ -1,28 +1,16 @@
|
|
package com.ydd.app.service.impl;
|
|
package com.ydd.app.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
-import com.alibaba.fastjson.parser.Feature;
|
|
|
|
import com.ydd.app.service.OpenApiNotifyService;
|
|
import com.ydd.app.service.OpenApiNotifyService;
|
|
import com.ydd.app.vo.StoreStatusNotifyVo;
|
|
import com.ydd.app.vo.StoreStatusNotifyVo;
|
|
-import com.ydd.common.enums.ResponseResultCodeEnum;
|
|
|
|
-import com.ydd.common.utils.http.HttpUtils;
|
|
|
|
-import com.ydd.common.utils.sign.SignatureUtil;
|
|
|
|
-import com.ydd.ecloud.core.utils.JsonMapper;
|
|
|
|
-import com.ydd.module.domain.AppInfo;
|
|
|
|
-import com.ydd.module.expection.CustomAppException;
|
|
|
|
-import com.ydd.module.service.IAppInfoService;
|
|
|
|
|
|
+import com.ydd.common.constant.RabbitConstant;
|
|
|
|
+import com.ydd.module.constants.AppConstant;
|
|
|
|
+import com.ydd.module.producer.RabbitSender;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
|
-import java.net.URLEncoder;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.HashSet;
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 通知接口
|
|
* 通知接口
|
|
@@ -34,41 +22,16 @@ import java.util.Set;
|
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
public class OpenApiNotifyServiceImpl implements OpenApiNotifyService {
|
|
public class OpenApiNotifyServiceImpl implements OpenApiNotifyService {
|
|
|
|
|
|
- private final IAppInfoService iAppInfoService;
|
|
|
|
|
|
+ private final RabbitSender rabbitSender;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String storeStatus(StoreStatusNotifyVo storeStatusNotifyVo) {
|
|
|
|
- storeStatusNotifyVo.setTimeStamp(System.currentTimeMillis());
|
|
|
|
- String json = JsonMapper.nonNullMapper().toJson(storeStatusNotifyVo);
|
|
|
|
- HashMap<String, String> signParam = JSON.parseObject(json, LinkedHashMap.class, Feature.OrderedField);
|
|
|
|
- Set<String> exclude = new HashSet<>();
|
|
|
|
- exclude.add("sign");
|
|
|
|
- AppInfo appInfo = iAppInfoService.getByAppId(storeStatusNotifyVo.getAppId());
|
|
|
|
- if (appInfo == null) {
|
|
|
|
- throw new CustomAppException("应用不存在");
|
|
|
|
|
|
+ public void storeStatus(StoreStatusNotifyVo storeStatusNotifyVo) {
|
|
|
|
+ List<Integer> durations = AppConstant.PUSH_INTERVAL_DURATION;
|
|
|
|
+ for (int i = 0; i < durations.size(); i++) {
|
|
|
|
+ // 记录推送次数, 超过规定总次数后做处理: 入库或者其他
|
|
|
|
+ storeStatusNotifyVo.setNotifyCount(i);
|
|
|
|
+ rabbitSender.sendDelay(storeStatusNotifyVo, RabbitConstant.QUEUE_DELAY_PUSH_STORE_STATUS_ROUTING_KEY, durations.get(i) * 1000);
|
|
}
|
|
}
|
|
- String sign = null;
|
|
|
|
- try {
|
|
|
|
- sign = SignatureUtil.getRequestMD5Sign(signParam, exclude, appInfo.getAppSecret());
|
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
|
- log.error("获取签名失败: {}", e.getMessage());
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- storeStatusNotifyVo.setSign(sign);
|
|
|
|
- String storeStatusNotifyVoStr = JSONObject.toJSONString(storeStatusNotifyVo);
|
|
|
|
- try {
|
|
|
|
- storeStatusNotifyVoStr = URLEncoder.encode(storeStatusNotifyVoStr,"utf-8");
|
|
|
|
- log.info("门店状态同步请求参数: {}", storeStatusNotifyVoStr);
|
|
|
|
- String resp = HttpUtils.sendPost(appInfo.getStoreStatusNotifyUrl(), storeStatusNotifyVoStr);
|
|
|
|
- log.info("门店状态同步返回结果: {}", resp);
|
|
|
|
- // 若未收到响应, 则继续推送
|
|
|
|
- if (!ResponseResultCodeEnum.SUCCESS.getMessage().equals(resp)) {
|
|
|
|
- // todo: 未收到响应开启重试机制
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("门店状态同步异常: {}", e.getMessage());
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- return null;
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|