| | |
| | | import com.ruoyi.tms.mapper.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.core.task.AsyncTaskExecutor; |
| | | import org.springframework.core.task.SimpleAsyncTaskExecutor; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.HttpMethod; |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.annotation.DataSource; |
| | |
| | | tmsApBill.setSettledAmount(BigDecimal.ZERO); |
| | | tmsApBill.setInvoiceStatus(0); |
| | | tmsApBill.setStatus(0); |
| | | tmsApBill.setPushStatus(0); // 初始推送状态:未推送 |
| | | tmsApBill.setCreateBy(SecurityUtils.getUsername()); |
| | | tmsApBillMapper.insertTmsApBill(tmsApBill); |
| | | |
| | |
| | | } |
| | | |
| | | //向外部系统推送数据 |
| | | pushPayableToExternalSystem(tmsApBill, tmsPayableFeeList); |
| | | |
| | | AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); |
| | | executor.execute(() -> pushPayableToExternalSystem(tmsApBill, tmsPayableFeeList)); |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | // 发送API请求 |
| | | ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class); |
| | | logger.info("推送应付数据到外部系统成功,响应: {}", response.getBody()); |
| | | |
| | | |
| | | // 解析响应,获取sourceSystemId |
| | | try { |
| | | JSONObject result = JSONObject.parseObject(response.getBody()); |
| | | String sourceSystemId = result.getString("sourceSystemId"); |
| | | if (sourceSystemId != null) { |
| | | tmsApBill.setSourceSystemId(Integer.parseInt(sourceSystemId)); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("解析外部系统响应失败: {}", e.getMessage()); |
| | | } |
| | | // 更新推送状态为成功 |
| | | tmsApBill.setPushStatus(2); |
| | | tmsApBill.setPushTime(DateUtils.getNowDate()); |
| | | tmsApBillMapper.updateTmsApBill(tmsApBill); |
| | | } catch (Exception e) { |
| | | logger.error("推送应付数据到外部系统失败,账单ID: {}, 供应商: {}", |
| | | tmsApBill.getId(), tmsApBill.getServiceProviderName(), e); |
| | | logger.debug("推送失败的请求数据: {}", JSON.toJSONString(requestBody)); |
| | | // 推送失败不影响主流程,记录日志即可 |
| | | |
| | | // 更新推送状态为失败 |
| | | tmsApBill.setPushStatus(3); |
| | | tmsApBill.setPushTime(DateUtils.getNowDate()); |
| | | tmsApBillMapper.updateTmsApBill(tmsApBill); |
| | | } |
| | | } |
| | | |