Commit 5008d344 by 崔彦峰

feat(financial): 添加商户企业配置服务并优化企微消息发送

- 新增 MerchantCorpConfigService 用于管理商户企业配置
- 新增 MerchantCorpProperties 配置类支持商户企业属性配置
- 修改 QWManager 中的日志记录方式以包含请求参数信息
- 在 ThirdPartyNiBoBatchStrategy 中集成商户配置服务获取 agentId
- 移除默认 agentId 配置改为从商户配置中动态获取
1 parent 02675353
package cn.com.glsx.dj.financial.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import java.util.List;
@Data
@Component
@ConfigurationProperties(prefix = "merchant.corp.agent.config")
public class MerchantCorpProperties {
private List<MerchantCorpConfig> config;
@Data
public static class MerchantCorpConfig {
private Integer merchantId;
private String agentId;
private String corpId;
private String corpSecret;
}
}
...@@ -79,15 +79,15 @@ public class QWManager { ...@@ -79,15 +79,15 @@ public class QWManager {
@SetDefaultMerchantId @SetDefaultMerchantId
public SendWorkWechatMessageResponseDTO sendMessage( public SendWorkWechatMessageResponseDTO sendMessage(
SendWorkWechatMessageRequestDTO sendWorkWechatMessageRequestDTO) { SendWorkWechatMessageRequestDTO sendWorkWechatMessageRequestDTO) {
log.info("发送企微应用消息:{}", JSON.toJSONString(sendWorkWechatMessageRequestDTO)); log.info("发送企微应用消息request:{}", JSON.toJSONString(sendWorkWechatMessageRequestDTO));
SendWorkWechatMessageResponseDTO responseDTO=null; SendWorkWechatMessageResponseDTO responseDTO=null;
try { try {
String baseurl = environment.getProperty("wechant.base.path")+"wechat/message/sendMessage"; String baseurl = environment.getProperty("wechant.base.path")+"wechat/message/sendMessage";
responseDTO = HttpUtil.post(baseurl,JSONObject.parseObject(JSONObject.toJSONString(sendWorkWechatMessageRequestDTO)), SendWorkWechatMessageResponseDTO.class); responseDTO = HttpUtil.post(baseurl,JSONObject.parseObject(JSONObject.toJSONString(sendWorkWechatMessageRequestDTO)), SendWorkWechatMessageResponseDTO.class);
log.info("发送企微应用消息 ropResponse:{}", JSON.toJSONString(responseDTO)); log.info("发送企微应用消息request:{},ropResponse:{}",JSON.toJSONString(sendWorkWechatMessageRequestDTO), JSON.toJSONString(responseDTO));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.info("发送企微应用消息异常:", e); log.info("发送企微应用消息异常request:{}",JSON.toJSONString(sendWorkWechatMessageRequestDTO), e);
} }
return responseDTO; return responseDTO;
} }
......
package cn.com.glsx.dj.financial.service;
import cn.com.glsx.dj.financial.config.MerchantCorpProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
public class MerchantCorpConfigService {
@Autowired
private MerchantCorpProperties merchantCorpProperties;
// 内存缓存 Map,Key 为 merchantId
private Map<Integer, MerchantCorpProperties.MerchantCorpConfig> configMap;
/**
* 项目启动时,自动将 List 转换为 Map,方便快速查找
*/
@PostConstruct
public void init() {
if (merchantCorpProperties.getConfig() != null) {
configMap = merchantCorpProperties.getConfig().stream()
.collect(Collectors.toMap(
MerchantCorpProperties.MerchantCorpConfig::getMerchantId,
config -> config,
(key1, key2) -> key1 // 如果 merchantId 重复,保留第一个
));
}
}
/**
* 根据 merchantId 获取对应的完整配置
*/
public Optional<MerchantCorpProperties.MerchantCorpConfig> getConfigByMerchantId(Integer merchantId) {
if (configMap == null || merchantId == null) {
return Optional.empty();
}
return Optional.ofNullable(configMap.get(merchantId));
}
/**
* 便捷方法:直接根据 merchantId 获取 agentId
*/
public String getAgentIdByMerchantId(Integer merchantId) {
return getConfigByMerchantId(merchantId)
.map(MerchantCorpProperties.MerchantCorpConfig::getAgentId)
.orElseThrow(() -> new IllegalArgumentException("未找到该商户对应的配置: " + merchantId));
}
}
...@@ -52,6 +52,9 @@ public class ThirdPartyNiBoBatchStrategy implements ThirdPartyStrategy{ ...@@ -52,6 +52,9 @@ public class ThirdPartyNiBoBatchStrategy implements ThirdPartyStrategy{
@Autowired @Autowired
private ApprovalTemplateConfigMapper approvalTemplateConfigMapper; private ApprovalTemplateConfigMapper approvalTemplateConfigMapper;
@Autowired
private MerchantCorpConfigService merchantCorpConfigService;
@Override @Override
public Object buildRequestParams(ApprovalRecords approvalRecord,String custId, Integer custType) { public Object buildRequestParams(ApprovalRecords approvalRecord,String custId, Integer custType) {
int remarksLengthMax = 35; int remarksLengthMax = 35;
...@@ -182,6 +185,7 @@ public class ThirdPartyNiBoBatchStrategy implements ThirdPartyStrategy{ ...@@ -182,6 +185,7 @@ public class ThirdPartyNiBoBatchStrategy implements ThirdPartyStrategy{
public void callBack(CallbackData callbackData, ApprovalRecords approvalRecords) { public void callBack(CallbackData callbackData, ApprovalRecords approvalRecords) {
// 1.处理订单状态 // 1.处理订单状态
if (("0").equals(callbackData.getStatus())) { if (("0").equals(callbackData.getStatus())) {
String agentId = merchantCorpConfigService.getAgentIdByMerchantId(approvalRecords.getMerchantId());
approvalRecords.setThirdRequestStatus(QWApprovalOrderStatusEnum.CALLBACK_SUCCESS.getValue()); approvalRecords.setThirdRequestStatus(QWApprovalOrderStatusEnum.CALLBACK_SUCCESS.getValue());
// 2.发送企微通知 // 2.发送企微通知
...@@ -202,7 +206,8 @@ public class ThirdPartyNiBoBatchStrategy implements ThirdPartyStrategy{ ...@@ -202,7 +206,8 @@ public class ThirdPartyNiBoBatchStrategy implements ThirdPartyStrategy{
} }
sendMessageRequestDTO.setTextCard(workWechatTextCardMessageDTO); sendMessageRequestDTO.setTextCard(workWechatTextCardMessageDTO);
sendMessageRequestDTO.setAgentId(environment.getProperty("default.agentid")==null?"1000008":environment.getProperty("default.agentid")); // sendMessageRequestDTO.setAgentId(environment.getProperty("default.agentid")==null?"1000008":environment.getProperty("default.agentid"));
sendMessageRequestDTO.setAgentId(agentId);
Set<String> qwUserIdList = new HashSet<>(); Set<String> qwUserIdList = new HashSet<>();
qwUserIdList.add(approvalRecords.getApplyerUserid()); qwUserIdList.add(approvalRecords.getApplyerUserid());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!