| | |
| | | package com.ruoyi.tms.service.impl; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | |
| | | /** |
| | | * 应收账单Service业务层处理 |
| | |
| | | executor.execute(() -> pushToExternalSystem(tmsArBill, tmsReceivableFees)); |
| | | } |
| | | |
| | | @Override |
| | | public void cancelPushToExternalSystem(Integer id) { |
| | | TmsArBill tmsArBill = tmsArBillMapper.selectTmsArBillById(id); |
| | | if (tmsArBill == null) { |
| | | throw new RuntimeException("应收账单不存在"); |
| | | } |
| | | |
| | | // 异步推送作废请求 |
| | | AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); |
| | | executor.execute(() -> pushCancelToExternalSystem(tmsArBill)); |
| | | } |
| | | |
| | | /** |
| | | * 向外部系统推送应收数据作废 |
| | | * @param tmsArBill 应收账单 |
| | | */ |
| | | @Async |
| | | protected void pushCancelToExternalSystem(TmsArBill tmsArBill) { |
| | | java.util.Map<String, Object> requestBody = new java.util.HashMap<>(); |
| | | try { |
| | | ; |
| | | |
| | | // 构建请求体 |
| | | String apiUrl = url+"/cancelBill"; |
| | | |
| | | // 构建请求体,只需要sourceSystemId |
| | | requestBody.put("sourceSystemId", tmsArBill.getSourceSystemId()); |
| | | |
| | | // 设置HTTP头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(requestBody), headers); |
| | | |
| | | // 发送API请求 |
| | | ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class); |
| | | logger.info("推送应收数据作废到外部系统成功,响应: {}", response.getBody()); |
| | | |
| | | // 更新推送状态为成功 |
| | | |
| | | tmsArBill.setStatus(3); // 设置账单状态为作废 |
| | | |
| | | tmsArBillMapper.updateTmsArBill(tmsArBill); |
| | | |
| | | // 重置关联的应收费用状态为待确认 |
| | | tmsReceivableFeeMapper.update(new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<TmsReceivableFee>() |
| | | .set(TmsReceivableFee::getStatus, 0) |
| | | .set(TmsReceivableFee::getBillRelationId, null) |
| | | .set(TmsReceivableFee::getBillRelationNo, null) |
| | | .eq(TmsReceivableFee::getBillRelationId, tmsArBill.getId()) |
| | | ); |
| | | logger.info("重置应收费用状态成功,账单ID: {}", tmsArBill.getId()); |
| | | } catch (Exception e) { |
| | | logger.error("推送应收数据作废到外部系统失败,账单ID: {}, 客户: {}", |
| | | tmsArBill.getId(), tmsArBill.getCustomerName(), e); |
| | | logger.debug("推送失败的请求数据: {}", JSON.toJSONString(requestBody)); |
| | | |
| | | // 更新推送状态为失败 |
| | | tmsArBill.setPushStatus(3); |
| | | tmsArBill.setPushTime(DateUtils.getNowDate()); |
| | | tmsArBillMapper.updateTmsArBill(tmsArBill); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 更新推送状态 |
| | | * |
| | |
| | | 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) { |
| | | tmsArBill.setSourceSystemId(Integer.parseInt(sourceSystemId)); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("解析外部系统响应失败: {}", e.getMessage()); |
| | | } |
| | | // 更新推送状态为成功 |
| | | tmsArBill.setPushStatus(2); |
| | | tmsArBill.setPushTime(DateUtils.getNowDate()); |