删改单申请推送

This commit is contained in:
zhaoqing
2026-05-19 10:22:42 +08:00
parent 986808af9a
commit 95af50fe12
2 changed files with 139 additions and 0 deletions
@@ -1,5 +1,6 @@
package com.mhd.oms.application.service.businessDocumentOrder;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mhd.common.core.web.domain.AjaxResult;
@@ -31,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.json.JsonObject;
import java.io.IOException;
import java.util.*;
@@ -48,6 +50,9 @@ public class BusinessDocumentOrderApplicationService {
private static final String API_NAME_I = "saveBill_i";
private static final String API_NAME_E = "saveBill_e";
private static final String VERIFY = "tjPZMT9fwhZRnv+eTXKF75QXmXzCn7phPagmoUQsvsh2ZTWDjuRxHAgcP0GZENHP";
private static final String API_NAME = "billAppModify";
@Autowired
private BusinessDocumentOrderDomainService businessDocumentOrderDomainService;
@@ -297,4 +302,125 @@ public class BusinessDocumentOrderApplicationService {
}
public AjaxResult batchPushForReviseApply(BusinessDocumentOrderDTO businessDocumentOrderDTO) {
LoginUser loginUser = SecurityUtils.getLoginUser();
Long pushBy = loginUser != null ? loginUser.getUserid() : null;
//String pushByName = loginUser != null ? loginUser.getUsername() : null;
Long organizationId = loginUser != null ? loginUser.getUserPo().getOrganizationId() : null;
Long topOrganizationId = loginUser != null ? loginUser.getUserPo().getTopOrganizationId() : null;
String organizationName = loginUser != null ? loginUser.getUserPo().getOrganizationName() : null;
int successCount = 0;
int failCount = 0;
StringBuilder failMsg = new StringBuilder();
// 构建单个对象
Map<String, String> item = new HashMap<>();
item.put("erpBillNo", String.valueOf(businessDocumentOrderDTO.getId()));
item.put("operateType", String.valueOf(businessDocumentOrderDTO.getReviseApplyType()));
item.put("appMan", businessDocumentOrderDTO.getReviseApplyBy());
item.put("appMess", businessDocumentOrderDTO.getReviseApplyReason());
// 2. 记录日志
GwLog gwLog = new GwLog();
gwLog.setType("删改单申请");
gwLog.setBusinessId(Long.valueOf(businessDocumentOrderDTO.getId()));
gwLog.setRequestBody(JSONObject.toJSONString(item));
gwLog.setResponseBody("");
gwLog.setStatus(1);
gwLog.setSendTime(new Date());
gwLog.setOrganizationId(organizationId);
gwLog.setTopOrganizationId(topOrganizationId);
gwLog.setOrganizationName(organizationName);
gwLog.setCreateBy(pushBy);
gwLog.setCreateTime(new Date());
gwLog.setDelFlag(1);
gwLogMapper.insert(gwLog);
//updateReservationOrder(businessDocumentOrderDTO);
// 3. 调用推送接口
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(PUSH_API_URL);
StringEntity postingString = new StringEntity(JSONObject.toJSONString(item), "UTF-8");
httpPost.setEntity(postingString);
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("verify", VERIFY);
httpPost.setHeader("apiName", API_NAME);
CloseableHttpResponse response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
gwLog.setResponseBody(responseString);
if (response.getStatusLine().getStatusCode() == 200) {
JSONObject responseJson = JSONObject.parseObject(responseString);
JSONArray dataArray = responseJson.getJSONArray("data");
if(dataArray != null && dataArray.size()>0){
JSONObject dataObj = dataArray.getJSONObject(0);
if("1".equals(String.valueOf(responseJson.get("data.code")))){
gwLog.setStatus(2);
businessDocumentOrderDTO.setReviseApplyStatus(1);
updateReservationOrder(businessDocumentOrderDTO);
successCount++;
}else {
gwLog.setStatus(3);
gwLog.setErrorMsg(responseString);
failCount++;
failMsg.append("原始单证Id").append(businessDocumentOrderDTO.getId()).append("失败:");
}
}
} else {
gwLog.setStatus(3);
gwLog.setErrorMsg(responseString);
if (businessDocumentOrderDTO.getId() != null) {
businessDocumentOrderDTO.setReviseApplyStatus(2);
updateReservationOrder(businessDocumentOrderDTO);
}
failCount++;
failMsg.append("原始单证id:").append(businessDocumentOrderDTO.getId()).append("失败:");
}
gwLogMapper.updateById(gwLog);
response.close();
} catch (IOException e) {
gwLog.setStatus(3);
gwLog.setErrorMsg(e.getMessage());
gwLog.setResponseBody("请求异常:" + e.getMessage());
gwLogMapper.updateById(gwLog);
if (businessDocumentOrderDTO.getId() != null) {
businessDocumentOrderDTO.setReviseApplyStatus(2);
updateReservationOrder(businessDocumentOrderDTO);
}
failCount++;
failMsg.append("单证id:").append(businessDocumentOrderDTO.getId()).append("异常:").append(e.getMessage());
log.error("GW推送异常:单证id={} error={}", businessDocumentOrderDTO.getId(), e.getMessage());
}
String resultMsg = "推送完成:成功" + successCount + "条,失败" + failCount + "";
if (failCount > 0) {
resultMsg += "[" + failMsg.toString() + "]";
}
return AjaxResult.success(resultMsg);
}
private void updateReservationOrder(BusinessDocumentOrderDTO businessDocumentOrderDTO) {
try {
BusinessDocumentOrder businessDocumentOrder = new BusinessDocumentOrder();
BeanUtils.copyProperties(businessDocumentOrderDTO,businessDocumentOrder);
businessDocumentOrderMapper.updateById(businessDocumentOrder);
} catch (Exception e) {
log.error("删改单申请更新状态失败失败: id={}, error={}", businessDocumentOrderDTO.getId(), e.getMessage());
}
}
}
@@ -171,4 +171,17 @@ public class OriginalImportExportDocumentApi extends BaseController {
return resultList;
}
@ApiOperation("批量推送")
@PostMapping("/batchPushForReviseApply")
public AjaxResult batchPushForReviseApply(@RequestBody BusinessDocumentOrderDTO businessDocumentOrderDTO){
if(businessDocumentOrderDTO == null){
return AjaxResult.error("没有数据需要推送");
}
return businessDocumentOrderApplicationService.batchPushForReviseApply(businessDocumentOrderDTO);
}
}