diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java index d2b8ed1fb..e9518c713 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/WlhyServiceFeign.java @@ -546,4 +546,10 @@ public interface WlhyServiceFeign { @RequestParam(name="organizationId", required = false) String organizationId); + @ApiOperation("汇率-更新推送状态") + @PostMapping("/ntocc/tmsSettlementExchangeRate/updatePushStatus") + void updateExchangeRatePushStatus(@RequestParam("id") String id, + @RequestParam("pushStatus") Integer pushStatus, + @RequestParam("pushTime") String pushTime, + @RequestParam("pushBy") Long pushBy); } \ No newline at end of file diff --git a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWlhyFallbackFactory.java b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWlhyFallbackFactory.java index be28da5dd..430061dd5 100644 --- a/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWlhyFallbackFactory.java +++ b/mhd-api/mhd-api-system/src/main/java/com/mhd/system/api/factory/RemoteWlhyFallbackFactory.java @@ -555,6 +555,11 @@ public class RemoteWlhyFallbackFactory implements FallbackFactory queryList(Integer pageNo, Integer pageSize, String pushStatus, String organizationId) { return AjaxResult.error(cause.getMessage()); } + + @Override + public void updateExchangeRatePushStatus(String id, Integer pushStatus, String pushTime, Long pushBy) { + + } }; } } \ No newline at end of file diff --git a/mhd_oms/src/main/java/com/mhd/oms/application/service/exchangeRate/ExchangeRateApplicationService.java b/mhd_oms/src/main/java/com/mhd/oms/application/service/exchangeRate/ExchangeRateApplicationService.java index f9376ee76..81d5af512 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/application/service/exchangeRate/ExchangeRateApplicationService.java +++ b/mhd_oms/src/main/java/com/mhd/oms/application/service/exchangeRate/ExchangeRateApplicationService.java @@ -1,25 +1,43 @@ package com.mhd.oms.application.service.exchangeRate; +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSONObject; import com.mhd.common.core.web.domain.AjaxResult; import com.mhd.common.core.web.page.TableDataInfo; +import com.mhd.common.security.utils.SecurityUtils; +import com.mhd.oms.domain.gwLog.entity.GwLog; +import com.mhd.oms.domain.gwLog.repository.mapper.GwLogMapper; +import com.mhd.oms.interfaces.dto.exchangeRate.ExchangeRateDTO; import com.mhd.system.api.WlhyServiceFeign; +import com.mhd.system.api.model.LoginUser; import lombok.extern.slf4j.Slf4j; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.io.IOException; +import java.util.*; @Service @Slf4j public class ExchangeRateApplicationService { + private static final String PUSH_API_URL = "http://10.33.0.100/ktms-erp-api/transfer/pushData"; + private static final String API_NAME = "saveCurr"; + @Resource private WlhyServiceFeign wlhyServiceFeign; + @Resource + private GwLogMapper gwLogMapper; + public TableDataInfo queryExchangeRateList(Integer pageNum, Integer pageSize, String pushStatus, String organizationId) { try { log.info("查询汇率列表: pageNum={}, pageSize={}, pushStatus={}, organizationId={}", @@ -56,4 +74,107 @@ public class ExchangeRateApplicationService { tableDataInfo.setCode(200); return tableDataInfo; } + + + + + public AjaxResult batchPushExchangeRate(List exchangeRateDTOList) { + if (exchangeRateDTOList == null || exchangeRateDTOList.isEmpty()) { + return AjaxResult.error("没有数据需要推送"); + } + + LoginUser loginUser = SecurityUtils.getLoginUser(); + Long pushBy = loginUser != null ? loginUser.getUserid() : 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(); + + for (ExchangeRateDTO dto : exchangeRateDTOList) { + Map body = new HashMap<>(); + body.put("erpCurrCode", dto.getErpCurrCode()); + body.put("erpCurrName", dto.getErpCurrName()); + + GwLog gwLog = new GwLog(); + gwLog.setType("汇率管理"); + gwLog.setBusinessId(String.valueOf(dto.getId())); + gwLog.setRequestBody(JSONObject.toJSONString(body)); + 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); + + // 更新为推送中 + updateExchangeRatePushStatus(dto.getId(), 2, new Date(), pushBy); + + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(PUSH_API_URL); + StringEntity postingString = new StringEntity(JSONObject.toJSONString(body), "UTF-8"); + httpPost.setEntity(postingString); + httpPost.setHeader("Content-type", "application/json"); + httpPost.setHeader("apiName", API_NAME); + + try { + CloseableHttpResponse response = httpClient.execute(httpPost); + String responseString = EntityUtils.toString(response.getEntity()); + gwLog.setResponseBody(responseString); + + if (response.getStatusLine().getStatusCode() == 200) { + gwLog.setStatus(2); + updateExchangeRatePushStatus(dto.getId(), 3, new Date(), pushBy); + successCount++; + } else { + gwLog.setStatus(3); + gwLog.setErrorMsg(responseString); + updateExchangeRatePushStatus(dto.getId(), 4, new Date(), pushBy); + failCount++; + failMsg.append("erpCurrCode:").append(dto.getErpCurrCode()).append("失败;"); + } + gwLogMapper.updateById(gwLog); + response.close(); + } catch (IOException e) { + gwLog.setStatus(3); + gwLog.setErrorMsg(e.getMessage()); + gwLogMapper.updateById(gwLog); + updateExchangeRatePushStatus(dto.getId(), 4, new Date(), pushBy); + failCount++; + failMsg.append("erpCurrCode:").append(dto.getErpCurrCode()).append("异常:").append(e.getMessage()).append(";"); + log.error("汇率推送异常: id={}, error={}", dto.getId(), e.getMessage()); + } finally { + try { + httpClient.close(); + } catch (Exception e) { + log.error("关闭httpClient异常: {}", e.getMessage()); + } + } + } + + String resultMsg = "推送完成: 成功" + successCount + "条, 失败" + failCount + "条"; + if (failCount > 0) { + resultMsg += "[" + failMsg.toString() + "]"; + } + return AjaxResult.success(resultMsg); + } + + private void updateExchangeRatePushStatus(String id, Integer pushStatus, Date pushTime, Long pushBy) { + try { + String pushTimeStr = pushTime != null ? DateUtil.format(pushTime, "yyyy-MM-dd HH:mm:ss") : null; + wlhyServiceFeign.updateExchangeRatePushStatus(id, pushStatus, pushTimeStr, pushBy); + } catch (Exception e) { + log.error("更新汇率推送状态失败: id={}, error={}", id, e.getMessage()); + } + } + + + + } diff --git a/mhd_oms/src/main/java/com/mhd/oms/interfaces/dto/exchangeRate/ExchangeRateDTO.java b/mhd_oms/src/main/java/com/mhd/oms/interfaces/dto/exchangeRate/ExchangeRateDTO.java new file mode 100644 index 000000000..6d76960aa --- /dev/null +++ b/mhd_oms/src/main/java/com/mhd/oms/interfaces/dto/exchangeRate/ExchangeRateDTO.java @@ -0,0 +1,19 @@ +package com.mhd.oms.interfaces.dto.exchangeRate; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +@ApiModel(description = "汇率批量推送DTO") +public class ExchangeRateDTO { + + @ApiModelProperty(value = "汇率ID") + private String id; + + @ApiModelProperty(value = "币种编码(ERP编码)") + private String erpCurrCode; + + @ApiModelProperty(value = "币种名称(ERP名称)") + private String erpCurrName; +} diff --git a/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/exchangeRate/ExchangeRateApi.java b/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/exchangeRate/ExchangeRateApi.java index 825287645..8efc3f8da 100644 --- a/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/exchangeRate/ExchangeRateApi.java +++ b/mhd_oms/src/main/java/com/mhd/oms/interfaces/facade/exchangeRate/ExchangeRateApi.java @@ -1,8 +1,10 @@ package com.mhd.oms.interfaces.facade.exchangeRate; +import com.mhd.common.core.web.domain.AjaxResult; import com.mhd.common.core.web.page.TableDataInfo; import com.mhd.oms.application.service.exchangeRate.ExchangeRateApplicationService; +import com.mhd.oms.interfaces.dto.exchangeRate.ExchangeRateDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.GetMapping; @@ -13,6 +15,8 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.List; + import static com.mhd.common.core.utils.PageUtils.startPage; @@ -34,4 +38,12 @@ public class ExchangeRateApi { return exchangeRateApplicationService.queryExchangeRateList(pageNum, pageSize, pushStatus, organizationId); } + @ApiOperation("批量推送汇率") + @PostMapping("/batchPush") + public AjaxResult batchPush(@RequestBody List exchangeRateDTOList) { + return exchangeRateApplicationService.batchPushExchangeRate(exchangeRateDTOList); + } + + + }