feat:门店人员更新
This commit is contained in:
@@ -8,6 +8,7 @@ import com.aliyun.openservices.ons.api.bean.Subscription;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.enums.RocketMqGroupEnum;
|
||||
import com.cool.store.mq.RocketMqConfig;
|
||||
import com.cool.store.mq.consumer.listener.StoreUserUpdateListener;
|
||||
import com.cool.store.mq.consumer.listener.XfsgTrainingPersonSyncListener;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -32,6 +33,8 @@ public class ConsumerClient {
|
||||
// private FeiShuEventListener feiShuEventListener;
|
||||
@Resource
|
||||
private XfsgTrainingPersonSyncListener xfsgTrainingPersonSyncListener;
|
||||
@Resource
|
||||
private StoreUserUpdateListener storeUserUpdateListener;
|
||||
|
||||
/**
|
||||
* 获取通用配置
|
||||
@@ -85,4 +88,17 @@ public class ConsumerClient {
|
||||
// }
|
||||
|
||||
|
||||
@Bean(initMethod = "start", destroyMethod = "shutdown")
|
||||
public ConsumerBean test() {
|
||||
RocketMqGroupEnum groupEnum = RocketMqGroupEnum.STORE_USER_UPDATE;
|
||||
ConsumerBean consumerBean = new ConsumerBean();
|
||||
//配置文件
|
||||
Properties properties = getCommonProperties(groupEnum);
|
||||
consumerBean.setProperties(properties);
|
||||
Map<Subscription, MessageListener> commonSubscriptionTable = getCommonSubscriptionTable(groupEnum, storeUserUpdateListener);
|
||||
//订阅多个topic如上面设置
|
||||
consumerBean.setSubscriptionTable(commonSubscriptionTable);
|
||||
return consumerBean;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.cool.store.mq.consumer.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.openservices.ons.api.Action;
|
||||
import com.aliyun.openservices.ons.api.ConsumeContext;
|
||||
import com.aliyun.openservices.ons.api.Message;
|
||||
import com.aliyun.openservices.ons.api.MessageListener;
|
||||
import com.cool.store.constants.CommonConstants;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
import com.cool.store.dto.store.StoreUserUpdateDTO;
|
||||
import com.cool.store.service.PushService;
|
||||
import com.cool.store.service.StoreService;
|
||||
import com.cool.store.service.ThirdFoodService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/9/25 14:49
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class StoreUserUpdateListener implements MessageListener {
|
||||
|
||||
@Autowired
|
||||
public RedisUtilPool redisUtilPool;
|
||||
@Autowired
|
||||
StoreService storeService;
|
||||
@Autowired
|
||||
ThirdFoodService thirdFoodService;
|
||||
|
||||
@Override
|
||||
public Action consume(Message message, ConsumeContext context) {
|
||||
String text = new String(message.getBody());
|
||||
if(StringUtils.isBlank(text)){
|
||||
log.info("消息体为空,tag:{},messageId:{}",message.getTag(),message.getMsgID());
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
String lockKey = "StoreUserUpdateListener:" + message.getMsgID();
|
||||
boolean lock = redisUtilPool.setNxExpire(lockKey, message.getMsgID(), CommonConstants.NORMAL_LOCK_TIMES);
|
||||
if(lock){
|
||||
try {
|
||||
List<StoreUserPositionDTO> storeUser = storeService.getStoreUser(Arrays.asList(text));
|
||||
if (CollectionUtils.isNotEmpty(storeUser)){
|
||||
//转换 否则验签不通过
|
||||
List<StoreUserUpdateDTO> storeUserUpdateDTOS = JSONObject.parseArray(JSONObject.toJSONString(storeUser), StoreUserUpdateDTO.class);
|
||||
thirdFoodService.pushStoreUser(storeUserUpdateDTOS);
|
||||
}
|
||||
}catch (Exception e){
|
||||
log.error("StoreUserUpdateListener consume error",e);
|
||||
return Action.ReconsumeLater;
|
||||
}finally {
|
||||
redisUtilPool.delKey(lockKey);
|
||||
}
|
||||
log.info("消费成功,tag:{},messageId:{},reqBody={}",message.getTag(),message.getMsgID(),text);
|
||||
return Action.CommitMessage;
|
||||
}
|
||||
return Action.ReconsumeLater;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,11 @@ package com.cool.store.service;
|
||||
|
||||
import com.cool.store.dto.FoodTokenDTO;
|
||||
import com.cool.store.dto.GetAccessTokenDTO;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
import com.cool.store.dto.store.StoreUserUpdateDTO;
|
||||
import com.cool.store.response.caipin.StoreUserResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 正新菜品市场api对接-埃林哲-对接人徐哲
|
||||
@@ -19,4 +24,11 @@ public interface ThirdFoodService {
|
||||
*/
|
||||
String getFoodToken(FoodTokenDTO dto);
|
||||
|
||||
/**
|
||||
* 推送门店人员信息
|
||||
* @param storeUserUpdateDTOList
|
||||
* @return
|
||||
*/
|
||||
StoreUserResponse pushStoreUser(List<StoreUserUpdateDTO> storeUserUpdateDTOList);
|
||||
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ public class StoreServiceImpl implements StoreService {
|
||||
storeUserPositionDTO.setStoreId(x.getStoreId());
|
||||
storeUserPositionDTO.setStoreName(x.getStoreName());
|
||||
storeUserPositionDTO.setShopCode(x.getStoreNum());
|
||||
storeUserPositionDTO.setStoreCode(x.getStoreNum());
|
||||
List<StoreUserDTO> userList = Lists.newArrayList();
|
||||
for (String userId : storeUserDTOMap.keySet()) {
|
||||
List<StoreUserDTO> singleUserDTOList = storeUserDTOMap.get(userId);
|
||||
|
||||
@@ -4,11 +4,15 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.dto.FoodTokenDTO;
|
||||
import com.cool.store.dto.GetAccessTokenDTO;
|
||||
import com.cool.store.dto.store.StoreUserPositionDTO;
|
||||
import com.cool.store.dto.store.StoreUserUpdateDTO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.exception.ServiceException;
|
||||
import com.cool.store.response.caipin.StoreUserResponse;
|
||||
import com.cool.store.response.oppty.OpportunityApiResponse;
|
||||
import com.cool.store.service.ThirdFoodService;
|
||||
import com.cool.store.utils.SignatureUtils;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -21,6 +25,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -45,10 +50,16 @@ public class ThirdFoodServiceImpl implements ThirdFoodService {
|
||||
@Override
|
||||
public String getFoodToken(FoodTokenDTO dto) {
|
||||
// 1. 发送POST请求
|
||||
String url = apiUrl + "/interface/v1/user/getToken";
|
||||
String url = "/v1/user/getToken";
|
||||
return executeApiCall(url, dto, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StoreUserResponse pushStoreUser(List<StoreUserUpdateDTO> dto) {
|
||||
String url = "/v1/store/updateStoreUser";
|
||||
return executeApiCall(url, dto, StoreUserResponse.class);
|
||||
}
|
||||
|
||||
|
||||
private <T> T executeApiCall(String url, Object requestBody, Class<T> responseType) {
|
||||
// 1. 打印请求前日志
|
||||
@@ -62,7 +73,7 @@ public class ThirdFoodServiceImpl implements ThirdFoodService {
|
||||
String responseBody = response.body().string();
|
||||
|
||||
// 3. 打印响应日志
|
||||
logResponse(url, response.code(), responseBody);
|
||||
logResponse(apiUrl+ url, response.code(), responseBody);
|
||||
|
||||
if (!response.isSuccessful()) {
|
||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR,
|
||||
@@ -94,20 +105,24 @@ public class ThirdFoodServiceImpl implements ThirdFoodService {
|
||||
String random = RandomUtil.randomString(20);
|
||||
|
||||
String signString = null;
|
||||
String reqBody = null;
|
||||
try {
|
||||
signString = SignatureUtils.sign("POST","/v1/user/getToken", objectMapper.writeValueAsString(requestBody),timestamp,random);
|
||||
reqBody = objectMapper.writeValueAsString(requestBody);
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
signString = SignatureUtils.sign("POST",url, reqBody,timestamp,random);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_SIGN_ERROR,"加密失败");
|
||||
}
|
||||
|
||||
log.info("签名生成 - 签名结果: {}", signString);
|
||||
|
||||
RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json"),
|
||||
JSONObject.toJSONString(requestBody)
|
||||
);
|
||||
RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json"), reqBody);
|
||||
|
||||
return new Request.Builder()
|
||||
.url(url)
|
||||
.url(apiUrl + url)
|
||||
.post(body)
|
||||
.addHeader("X-ZhengXin-Sign", signString)
|
||||
.addHeader("X-ZhengXin-SignTime", timestamp)
|
||||
|
||||
Reference in New Issue
Block a user