Преглед изворни кода

分账增加分布式事务

liuj пре 6 месеци
родитељ
комит
6008ef95c4

+ 27 - 5
src/main/java/com/sunxung/factoring/service/ledger/impl/LedgerManagementServiceImpl.java

@@ -75,13 +75,14 @@ import com.sunxung.factoring.service.sys.DictionaryService;
 import com.sunxung.factoring.service.sys.UserService;
 import com.sunxung.factoring.service.sys.flowable.FlowableService;
 import com.sunxung.factoring.service.tradingPlatform.PlatformService;
+import io.seata.core.context.RootContext;
+import io.seata.spring.annotation.GlobalTransactional;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.PropertySource;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.client.RestTemplate;
@@ -335,6 +336,7 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
     }
 
     @Override
+    @GlobalTransactional(rollbackFor = Exception.class)
     @Transactional(rollbackFor = Exception.class)
     public void addApproval(LedgerApprovalInfo ledgerApprovalInfo) {
         if (ledgerApprovalInfo == null || ledgerApprovalInfo.getLedgerAccountBasicInfoId() == null) {
@@ -382,7 +384,13 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                 //调用sop变更收放款计划接口
                 List<LedgerPlanFactoringAssign> planFactoringAssignList = planFactoringAssignService.findByBasicInfoId(ledgerAccountBasicInfo.getId());
                 if (CollectionUtil.isNotEmpty(planFactoringAssignList)) {
-                    ResponseEntity<String> responseEntity = restTemplate.postForEntity(planInfoAddUrl, planFactoringAssignList, String.class);
+                    HttpHeaders headers = new HttpHeaders();
+                    headers.setContentType(MediaType.APPLICATION_JSON);
+                    headers.set("Accept", "application/json");
+                    headers.set(RootContext.KEY_XID, RootContext.getXID());
+
+                    HttpEntity<String> entity = new HttpEntity<>(JSONUtil.toJsonStr(planFactoringAssignList), headers);
+                    ResponseEntity<String> responseEntity = restTemplate.postForEntity(planInfoAddUrl, entity, String.class);
                     ResponseJson responseJson = JSONUtil.toBean(responseEntity.getBody(), ResponseJson.class);
                     if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || !responseJson.isSuccess()) {
                         throw new BusinessException(CodeUtil.FAIL, "分账失败--变更sop收放款计划失败:" + responseJson.getMsg());
@@ -667,7 +675,14 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
             throw new BusinessException(CodeUtil.FAIL, "获取不到项目对应的贸易平台");
         }
         oaOtherPaymentTradeVo.setOaCompanyEntityStr(platform.getPlatformName());
-        ResponseEntity<String> responseEntity = restTemplate.postForEntity(startOaPaymentProcessUrl, oaOtherPaymentTradeVo, String.class);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        headers.set("Accept", "application/json");
+        headers.set(RootContext.KEY_XID, RootContext.getXID());
+
+        HttpEntity<String> entity = new HttpEntity<>(JSONUtil.toJsonStr(oaOtherPaymentTradeVo), headers);
+        ResponseEntity<String> responseEntity = restTemplate.postForEntity(startOaPaymentProcessUrl, entity, String.class);
         ResponseJson responseJson = JSONUtil.toBean(responseEntity.getBody(), ResponseJson.class);
         if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || !responseJson.isSuccess()) {
             throw new BusinessException(CodeUtil.FAIL, "开启OA申请-归还保理融资款失败:" + responseJson.getMsg().toString());
@@ -771,7 +786,14 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
             planFactoringList.add(planFactoring);
         }
         billingRecordBasic.setPlanFactoringList(planFactoringList);
-        ResponseEntity<String> responseEntity = restTemplate.postForEntity(billingRecordBasicAddUrl, billingRecordBasic, String.class);
+
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        headers.set("Accept", "application/json");
+        headers.set(RootContext.KEY_XID, RootContext.getXID());
+
+        HttpEntity<String> entity = new HttpEntity<>(JSONUtil.toJsonStr(billingRecordBasic), headers);
+        ResponseEntity<String> responseEntity = restTemplate.postForEntity(billingRecordBasicAddUrl, entity, String.class);
         ResponseJson responseJson = JSONUtil.toBean(responseEntity.getBody(), ResponseJson.class);
         if (responseEntity.getStatusCode().value() != HttpStatus.OK.value() || !responseJson.isSuccess()) {
             throw new BusinessException(CodeUtil.FAIL, "数据同步到sop失败:" + responseJson.getMsg().toString());