no message

main
HUOJIN\92525 2025-09-05 10:53:17 +08:00
parent 094efb7c43
commit 2190d3f353
2 changed files with 134 additions and 56 deletions

View File

@ -12,6 +12,7 @@ import com.youchain.businessdata.service.LesService;
import com.youchain.businessdata.service.dto.LesDto; import com.youchain.businessdata.service.dto.LesDto;
import com.youchain.businessdata.service.dto.LesQueryCriteria; import com.youchain.businessdata.service.dto.LesQueryCriteria;
import com.youchain.businessdata.service.mapstruct.LesMapper; import com.youchain.businessdata.service.mapstruct.LesMapper;
import com.youchain.config.SignConfig;
import com.youchain.exception.BadRequestException; import com.youchain.exception.BadRequestException;
import com.youchain.modules.system.domain.Dict; import com.youchain.modules.system.domain.Dict;
import com.youchain.modules.system.domain.DictDetail; import com.youchain.modules.system.domain.DictDetail;
@ -174,49 +175,106 @@ public class LesServiceImpl implements LesService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void lesCallBack(Les les) { public void lesCallBack(Les les) {
//接口开关是否启动
try {
// 生成请求参数
String json = this.lesCallBackJson(les.getDstPositionCode(), les.getTaskCode());
log.info("LES回传参数: {}", json);
// 检查接口开关
if (!isInterfaceEnabled()) {
// 更新LES状态
updateLesStatus(les, null, json);
return;
}
// 获取签名配置
SignConfig signConfig = getSignConfig();
// 发送请求并处理响应
String result = sendLesRequest(signConfig, json);
validateLesResponse(result);
// 更新LES状态
updateLesStatus(les, result, json);
} catch (Exception e) {
log.error("LES回传失败", e);
throw new BadRequestException("LES回传失败:" + e.getMessage());
}
}
/**
*
*/
private boolean isInterfaceEnabled() {
Dict dict = dictRepository.findDictByName("OPEN"); Dict dict = dictRepository.findDictByName("OPEN");
String resultJson = ""; return dict != null;
String json = ""; }
if (dict != null) {
/**
*
*/
private SignConfig getSignConfig() {
Dict signeDict = dictRepository.findDictByName("signe"); Dict signeDict = dictRepository.findDictByName("signe");
if (signeDict == null) { if (signeDict == null) {
throw new BadRequestException("signe签名未配置"); throw new BadRequestException("signe签名未配置");
} }
DictDetail dictDetail = dictDetailRepository.findDictDetailByLabel(signeDict.getId(), signeDict.getDescription());
DictDetail dictDetail = dictDetailRepository.findDictDetailByLabel(
signeDict.getId(), signeDict.getDescription());
String value = dictDetail.getValue(); String value = dictDetail.getValue();
JSONObject jsonObject = JSONObject.parseObject(value); JSONObject jsonObject = JSONObject.parseObject(value);
if (jsonObject == null) { if (jsonObject == null) {
throw new BadRequestException("signe签名格式错误"); throw new BadRequestException("signe签名格式错误");
} }
String host = jsonObject.getString("host");
String path = jsonObject.getString("path"); return SignConfig.builder()
String appId = jsonObject.getString("appId"); .host(jsonObject.getString("host"))
String appSecret = jsonObject.getString("appSecret"); .path(jsonObject.getString("path"))
.appId(jsonObject.getString("appId"))
.appSecret(jsonObject.getString("appSecret"))
.build();
}
/**
* LES
*/
private String sendLesRequest(SignConfig config, String json) {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000); String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
//jsonBody参数 // 生成签名
json = this.lesCallBackJson(les.getDstPositionCode(), les.getTaskCode()); String sign = SignerUtils.generateSign(
log.info("LES回传参数: {}", json); config.getHost(), config.getPath(), config.getAppId(),
timestamp, json, config.getAppSecret());
//生成签名;
String sign = SignerUtils.generateSign(host, path, appId, timestamp, json, appSecret);
log.info("生成的签名: {}", sign); log.info("生成的签名: {}", sign);
//请求url // 构建请求URL
String url = SignerUtils.buildFullUrl(host, path, appId, timestamp, sign); String url = SignerUtils.buildFullUrl(
log.info("回传LES请求路径: {}", url); config.getHost(), config.getPath(), config.getAppId(), timestamp, sign);
log.info("LES请求路径: {}", url);
//返回结果 // 发送请求
resultJson = HttpPostUtil.sendPostReq(url, json); String result = HttpPostUtil.sendPostReq(url, json);
log.info("LES返回报文{}", resultJson); log.info("LES返回报文{}", result);
Map<String, String> result = parseResponse(resultJson);
if (result == null) { return result;
if (StringUtils.isEmpty(resultJson)) { }
/**
* LES
*/
private void validateLesResponse(String result) {
if (StringUtils.isEmpty(result)) {
throw new BadRequestException("LES返回信息:LES回传接口调用失败!"); throw new BadRequestException("LES返回信息:LES回传接口调用失败!");
} }
JSONObject resulObject = JSON.parseObject(resultJson); //解析XML格式
Map<String, String> resultMap = parseResponse(result);
if (resultMap == null) {
//解析JSON格式
JSONObject resulObject = JSON.parseObject(result);
if (resulObject == null) { if (resulObject == null) {
throw new BadRequestException("LES返回信息:LES回传接口返回为空!"); throw new BadRequestException("LES返回信息:LES回传接口返回为空!");
} }
@ -227,16 +285,20 @@ public class LesServiceImpl implements LesService {
throw new BadRequestException("LES返回消息:" + displayMsg); throw new BadRequestException("LES返回消息:" + displayMsg);
} }
} else { } else {
String resultCode = result.get("resultCode"); String resultCode = resultMap.get("resultCode");
String displayMsg = result.get("displayMsg"); String displayMsg = resultMap.get("displayMsg");
if (!"success".equals(resultCode)) { if (!"success".equals(resultCode)) {
throw new BadRequestException("LES返回消息:" + displayMsg); throw new BadRequestException("LES返回消息:" + displayMsg);
} }
} }
} }
/**
* LES
*/
private void updateLesStatus(Les les, String result, String json) {
les.setStatus(BizStatus.CLOSE); les.setStatus(BizStatus.CLOSE);
les.setRepMessage(resultJson); les.setRepMessage(result);
les.setReqMessage(json); les.setReqMessage(json);
les.setReturnTime(new Timestamp(System.currentTimeMillis())); les.setReturnTime(new Timestamp(System.currentTimeMillis()));
lesRepository.save(les); lesRepository.save(les);

View File

@ -0,0 +1,16 @@
package com.youchain.config;
import lombok.Builder;
import lombok.Data;
/**
*
*/
@Data
@Builder
public class SignConfig {
private String host;
private String path;
private String appId;
private String appSecret;
}