huanglc 4 тижнів тому
батько
коміт
d1d400096b

+ 184 - 73
bpm-core/src/main/java/com/srm/bpm/logic/service/impl/BillLogicImpl.java

@@ -109,7 +109,12 @@ import com.srm.common.data.exception.RbException;
109 109
 import com.srm.common.util.bean.BeanUtil;
110 110
 import com.srm.common.util.datetime.DateTimeUtil;
111 111
 
112
+import org.activiti.engine.RuntimeService;
113
+import org.activiti.engine.TaskService;
112 114
 import org.activiti.engine.runtime.ProcessInstance;
115
+import org.activiti.engine.runtime.ProcessInstanceQuery;
116
+import org.activiti.engine.task.Task;
117
+import org.activiti.engine.task.TaskQuery;
113 118
 import org.apache.commons.codec.binary.StringUtils;
114 119
 import org.apache.commons.lang3.tuple.Pair;
115 120
 import org.apache.commons.lang3.tuple.Triple;
@@ -136,6 +141,7 @@ import cn.hutool.core.util.RandomUtil;
136 141
 import cn.hutool.core.util.StrUtil;
137 142
 import lombok.RequiredArgsConstructor;
138 143
 import lombok.extern.slf4j.Slf4j;
144
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
139 145
 import org.springframework.transaction.support.TransactionSynchronizationAdapter;
140 146
 import org.springframework.transaction.support.TransactionSynchronizationManager;
141 147
 import org.springframework.transaction.support.TransactionTemplate;
@@ -176,6 +182,8 @@ public class BillLogicImpl implements BillLogic {
176 182
     private final FlowMsgLogic flowMsgLogic;
177 183
     private final BillTitleLogic billTitleLogic;
178 184
     private final SerialNumberLogic serialNumberLogic;
185
+    private final RuntimeService runtimeService;
186
+    private final TaskService taskService;
179 187
     private final FormValidationService formValidationService;
180 188
     private final FormSettingService formSettingService;
181 189
     private final CallBackLogic callBackLogic;
@@ -750,6 +758,20 @@ public class BillLogicImpl implements BillLogic {
750 758
                                                 nextApprover, actionParam.getFormData(),
751 759
                                                 billTask.getTaskNodeKey(), billTask.getTaskId());
752 760
 
761
+                                        // 检查流程是否已结束,如果结束则在当前事务中调用 complete()
762
+                                        // 通过 Spring 代理调用确保 @Transactional 生效,加入当前事务
763
+                                        if (isProcessEnded(billId)) {
764
+                                            log.debug("流程已结束,在当前事务中调用 complete()。billId: {}", billId);
765
+                                            // 重新查询最新的 bill 对象,确保使用最新状态
766
+                                            ToaBillEntity latestBill = billService.getById(billId);
767
+                                            if (latestBill != null) {
768
+                                                BillLogic billLogicProxy = SpringContextHolder.getBean(BillLogic.class);
769
+                                                billLogicProxy.complete(latestBill, BillAction.agree.name());
770
+                                            } else {
771
+                                                log.warn("流程已结束,但无法查询到审批单。billId: {}", billId);
772
+                                            }
773
+                                        }
774
+
753 775
                                     } else {
754 776
                                         this.billTaskService.agreeTask(billTask, userCode,
755 777
                                                 actionParam);
@@ -895,41 +917,130 @@ public class BillLogicImpl implements BillLogic {
895 917
     /**
896 918
      * 结束并设置完成审批单
897 919
      *
898
-     * @param bill 审批单ID
920
+     * 事务管理:
921
+     * - 使用 @Transactional(rollbackFor = Exception.class),默认传播行为为 PROPAGATION_REQUIRED
922
+     * - 当从 agreeFlow() 等已有事务的方法调用时(通过 Spring 代理),会自动加入现有事务
923
+     * - 当从 ProcessBillListener 等无事务的方法调用时,会创建新事务
924
+     * - 如果 callBack() 失败抛出异常,整个事务(包括 bill_task 和 toa_bill 的更新)都会回滚
925
+     *
926
+     * 调用场景:
927
+     * 1. 从 agreeFlow() 调用:在 agreeFlow() 完成 Activiti 任务后,检查流程是否结束,如果结束则通过 Spring 代理调用此方法,确保在同一事务中
928
+     * 2. 从 ProcessBillListener 调用:在 Activiti 流程结束时,通过监听器调用此方法,会在新事务中执行
929
+     *
930
+     * 幂等性保证:
931
+     * - 方法内部会检查审批单状态,如果已经完成(COMPLETE),则直接返回,避免重复处理
932
+     *
933
+     * @param bill 审批单实体(注意:方法内部会重新查询最新的审批单数据,确保使用最新状态)
934
+     * @param action 操作类型(agree 或 refuse)
899 935
      */
900 936
     @Override
901 937
     @Transactional(rollbackFor = Exception.class)
902 938
     public void complete(ToaBillEntity bill, String action) {
939
+        // 重新查询最新的bill数据,确保使用最新状态
940
+        final ToaBillEntity latestBill = billService.getById(bill.getId());
941
+        if (latestBill == null) {
942
+            log.error("审批单不存在,无法完成流程。billId: {}", bill.getId());
943
+            throw new RbException(BillCode.BILL_NOT_FOUND);
944
+        }
945
+
946
+        // 检查是否已经完成,避免重复处理
947
+        if (latestBill.getStatus() == BillStatus.COMPLETE.getStatus()) {
948
+            log.debug("审批单已完成,无需再次处理。billId: {}", bill.getId());
949
+            return;
950
+        }
951
+
952
+        // 更新审批单状态
903 953
         final int dateline = DateTimeUtil.unixTime();
904
-        bill.setCompletionTime(dateline);
905
-        bill.setStatus(BillStatus.COMPLETE.getStatus());
906
-        bill.setArchivedTime(dateline);
907
-        TimerTask businessTask = new TimerTask() {
908
-            @Override
909
-            public void run() {
910
-                billService.upldate(bill);
911
-                log.info("查询到的审批单数据:{}", bill);
912
-                if (action.equals(BillAction.refuse.name())) {
913
-                    callBackLogic.callBack(bill.getProcessId(), bill.getId(),
914
-                            BillTaskStatus.REFUSE.getStatus());
915
-                } else {
916
-                    BillTaskEntity a = new BillTaskEntity();
917
-                    a.setBillId(bill.getId());
918
-                    a.setUserCode(bill.getSender());
919
-                    a.setNodeStatus(BillTaskStatus.COMPLATE.getStatus());//这里应该是16,但是这么多年一直都是错的,数据库里审批通过的也是2(同意)
920
-                    a.setNodeName(bill.getTitle());
921
-                    a.setOpinion("通过");
922
-                    flowMsgLogic.sendMsg(Lists.newArrayList(a));
923
-                    callBackLogic.callBack(bill.getProcessId(), bill.getId(), BillStatus.COMPLETE.getStatus());//这里是16,但是回调函数接收的却是8
954
+        latestBill.setCompletionTime(dateline);
955
+        latestBill.setStatus(BillStatus.COMPLETE.getStatus());
956
+        latestBill.setArchivedTime(dateline);
957
+        billService.upldate(latestBill);
958
+        log.info("审批单完成,已更新状态:{}", latestBill);
959
+
960
+        // 执行回调(如果失败,会抛出异常导致整个事务回滚)
961
+        if (action.equals(BillAction.refuse.name())) {
962
+            callBackLogic.callBack(latestBill.getProcessId(), latestBill.getId(),
963
+                    BillTaskStatus.REFUSE.getStatus());
964
+        } else {
965
+            BillTaskEntity a = new BillTaskEntity();
966
+            a.setBillId(latestBill.getId());
967
+            a.setUserCode(latestBill.getSender());
968
+            a.setNodeStatus(BillTaskStatus.COMPLATE.getStatus());//这里应该是16,但是这么多年一直都是错的,数据库里审批通过的也是2(同意)
969
+            a.setNodeName(latestBill.getTitle());
970
+            a.setOpinion("通过");
971
+            flowMsgLogic.sendMsg(Lists.newArrayList(a));
972
+            callBackLogic.callBack(latestBill.getProcessId(), latestBill.getId(), BillStatus.COMPLETE.getStatus());//这里是16,但是回调函数接收的却是8
973
+        }
974
+    }
975
+
976
+    /**
977
+     * 检查流程是否已结束
978
+     * 
979
+     * 通过检查以下条件判断流程是否结束:
980
+     * 1. 是否有活动的 Activiti 流程实例
981
+     * 2. 是否有活动的 Activiti 任务
982
+     * 3. 是否还有待审批的 bill_task(状态为 APPROVAL)
983
+     * 
984
+     * 如果以上都没有,说明流程已结束
985
+     *
986
+     * @param billId 审批单ID
987
+     * @return true 如果流程已结束,false 否则
988
+     */
989
+    private boolean isProcessEnded(long billId) {
990
+        try {
991
+            // 1. 检查是否有活动的 Activiti 流程实例
992
+            String businessKey = String.valueOf(billId);
993
+            ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery()
994
+                    .processInstanceBusinessKey(businessKey)
995
+                    .active();
996
+            List<ProcessInstance> activeProcessInstances = processInstanceQuery.list();
997
+            
998
+            if (CollectionUtil.isNotEmpty(activeProcessInstances)) {
999
+                // 有活动的流程实例,检查是否有活动的任务
1000
+                for (ProcessInstance processInstance : activeProcessInstances) {
1001
+                    TaskQuery taskQuery = taskService.createTaskQuery()
1002
+                            .processInstanceId(processInstance.getId())
1003
+                            .active();
1004
+                    List<Task> activeTasks = taskQuery.list();
1005
+                    if (CollectionUtil.isNotEmpty(activeTasks)) {
1006
+                        // 有活动的任务,流程未结束
1007
+                        log.debug("流程未结束:存在活动的 Activiti 任务。billId: {}, processInstanceId: {}, taskCount: {}", 
1008
+                                billId, processInstance.getId(), activeTasks.size());
1009
+                        return false;
1010
+                    }
924 1011
                 }
925 1012
             }
926
-        };
927
-        CallBackThreadPoolManager.me().executeLog(businessTask);
1013
+            
1014
+            // 2. 检查是否还有待审批的 bill_task(状态为 APPROVAL)
1015
+            List<BillTaskEntity> pendingTasks = billTaskService.list(
1016
+                    Wrappers.lambdaQuery(BillTaskEntity.class)
1017
+                            .eq(BillTaskEntity::getBillId, billId)
1018
+                            .eq(BillTaskEntity::getNodeStatus, BillTaskStatus.APPROVAL.getStatus())
1019
+                            .eq(BillTaskEntity::getIsDeleted, 0)
1020
+            );
1021
+            
1022
+            if (CollectionUtil.isNotEmpty(pendingTasks)) {
1023
+                // 有待审批的任务,流程未结束
1024
+                log.debug("流程未结束:存在待审批的 bill_task。billId: {}, pendingTaskCount: {}", 
1025
+                        billId, pendingTasks.size());
1026
+                return false;
1027
+            }
1028
+            
1029
+            // 所有检查都通过,流程已结束
1030
+            log.debug("流程已结束。billId: {}", billId);
1031
+            return true;
1032
+        } catch (Exception e) {
1033
+            // 检查过程中出现异常,保守处理:认为流程未结束,避免误判
1034
+            log.error("检查流程是否结束时发生异常。billId: {}, error: {}", billId, e.getMessage(), e);
1035
+            return false;
1036
+        }
1037
+    }
1038
+
928 1039
 
929 1040
 /*        try {
930 1041
             log.info("查询到的审批单数据:{}", bill);
931 1042
             billService.upldate(bill);
932
-            
1043
+
933 1044
             if (action.equals(BillAction.refuse.name())) {
934 1045
                 callBackLogic.callBack(bill.getProcessId(), bill.getId(), BillTaskStatus.REFUSE.getStatus());
935 1046
             } else {
@@ -943,12 +1054,12 @@ public class BillLogicImpl implements BillLogic {
943 1054
                 callBackLogic.callBack(bill.getProcessId(), bill.getId(), BillTaskStatus.COMPLATE.getStatus());
944 1055
             }
945 1056
         } catch (Exception e) {
946
-            log.error("流程完成失败: billId={}, action={}, error={}", 
1057
+            log.error("流程完成失败: billId={}, action={}, error={}",
947 1058
                       bill.getId(), action, e.getMessage(), e);
948 1059
             throw new RbException("流程完成失败:" + e.getMessage());
949 1060
         }*/
950 1061
 
951
-    }
1062
+
952 1063
     /*@Override
953 1064
     @Transactional(rollbackFor = Exception.class)
954 1065
     public void complete(ToaBillEntity bill, String action) {
@@ -1038,7 +1149,7 @@ public class BillLogicImpl implements BillLogic {
1038 1149
      * @return 审批历史记录
1039 1150
      */
1040 1151
     @Override
1041
-    public List<BillApprovalHistoryVO> findBillApprovalHistory(long billId) {
1152
+    public List<BillApprovalHistoryVO> findBillApprovalHistory ( long billId){
1042 1153
         final ToaBillEntity bill = billService.getById(billId);
1043 1154
         if (bill == null) {
1044 1155
             throw new RbException(BillCode.BILL_NOT_FOUND);
@@ -1096,7 +1207,7 @@ public class BillLogicImpl implements BillLogic {
1096 1207
      * @param actionParam 审批操作参数
1097 1208
      */
1098 1209
     @Override
1099
-    public void recallFlow(BillActionParamDTO actionParam) {
1210
+    public void recallFlow (BillActionParamDTO actionParam){
1100 1211
         final long billId = actionParam.getBillId();
1101 1212
         final String taskId = actionParam.getTaskId();
1102 1213
         final String opinion = actionParam.getOpinion();
@@ -1111,9 +1222,9 @@ public class BillLogicImpl implements BillLogic {
1111 1222
         billBpmnLogic.recall(bill, taskId, opinion, userCode);
1112 1223
     }
1113 1224
 
1114
-    private void refuseApproval(
1225
+    private void refuseApproval (
1115 1226
             String taskId, String opinion, ToaBillEntity bill, String userCode, BillTaskEntity task
1116
-    ) {
1227
+    ){
1117 1228
         final Optional<ProcessNodeExtendEntity> nodeExtendOpt;
1118 1229
         final Long processId = bill.getProcessId();
1119 1230
         final String taskNodeKey = task.getTaskNodeKey();
@@ -1156,7 +1267,7 @@ public class BillLogicImpl implements BillLogic {
1156 1267
     }
1157 1268
 
1158 1269
     @Override
1159
-    public boolean agreeIsGoOn(BillTaskEntity billTask) {
1270
+    public boolean agreeIsGoOn (BillTaskEntity billTask){
1160 1271
         final Long id = billTask.getId();
1161 1272
         final String taskId = billTask.getTaskId();
1162 1273
         final Long billId = billTask.getBillId();
@@ -1202,7 +1313,7 @@ public class BillLogicImpl implements BillLogic {
1202 1313
         return false;
1203 1314
     }
1204 1315
 
1205
-    private Page<BillItemVO> toItemVOList(Page page, List<BillItemPO> billDatas, String userCode) {
1316
+    private Page<BillItemVO> toItemVOList (Page page, List < BillItemPO > billDatas, String userCode){
1206 1317
         Page<BillItemVO> resultPage = new Page<>(page.getCurrent(), page.getSize());
1207 1318
         resultPage.setTotal(page.getTotal());
1208 1319
         if (CollectionUtil.isNotEmpty(billDatas)) {
@@ -1230,10 +1341,10 @@ public class BillLogicImpl implements BillLogic {
1230 1341
         return resultPage;
1231 1342
     }
1232 1343
 
1233
-    private ToaBillEntity createBill(
1344
+    private ToaBillEntity createBill (
1234 1345
             ProcessDetailPO processDetail, BillStatus billStatus, BillDataContext billDataValue,
1235 1346
             UserInfoDTO userInfoDTO
1236
-    ) {
1347
+    ){
1237 1348
         ToaBillEntity bill = new ToaBillEntity();
1238 1349
         bill.setId(billDataValue.getId());
1239 1350
         bill.setProcessId(processDetail.getId());
@@ -1283,9 +1394,9 @@ public class BillLogicImpl implements BillLogic {
1283 1394
      * @return 解析后的表单数据
1284 1395
      */
1285 1396
     @Override
1286
-    public BillDataContext resolveFormData(
1287
-            long billId, ProcessDetailPO processDetail, Map<String, Object> formDataMap
1288
-    ) {
1397
+    public BillDataContext resolveFormData (
1398
+            long billId, ProcessDetailPO processDetail, Map < String, Object > formDataMap
1399
+    ){
1289 1400
 
1290 1401
         long processId = processDetail.getId();
1291 1402
 
@@ -1401,7 +1512,7 @@ public class BillLogicImpl implements BillLogic {
1401 1512
      */
1402 1513
     @Override
1403 1514
     @Transactional(rollbackFor = Exception.class)
1404
-    public void endorse(BillActionParamDTO actionParam) {
1515
+    public void endorse (BillActionParamDTO actionParam){
1405 1516
         final String endorseApprover = actionParam.getEndorseApprover();
1406 1517
         final String opinion = actionParam.getOpinion();
1407 1518
         final String taskId = actionParam.getTaskId();
@@ -1466,7 +1577,7 @@ public class BillLogicImpl implements BillLogic {
1466 1577
      */
1467 1578
     @Override
1468 1579
     @Transactional(rollbackFor = Exception.class)
1469
-    public void repulseFlow(BillActionParamDTO actionParam) {
1580
+    public void repulseFlow (BillActionParamDTO actionParam){
1470 1581
         final String opinion = actionParam.getOpinion();
1471 1582
         final String taskId = actionParam.getTaskId();
1472 1583
         final long billId = actionParam.getBillId();
@@ -1559,9 +1670,9 @@ public class BillLogicImpl implements BillLogic {
1559 1670
      * @param turnUser 移交用户
1560 1671
      */
1561 1672
     @Override
1562
-    public void turnUser(
1673
+    public void turnUser (
1563 1674
             long billId, String taskId, String turnUser, String userCode, String opinion
1564
-    ) {
1675
+    ){
1565 1676
         List<BillTaskEntity> billTaskEntities =
1566 1677
                 billTaskService.findApprovingByBillAndTaskId(billId, taskId);
1567 1678
         Set<String> collect = billTaskEntities.stream()
@@ -1625,7 +1736,7 @@ public class BillLogicImpl implements BillLogic {
1625 1736
      * @param opinion       转办意见
1626 1737
      */
1627 1738
     @Override
1628
-    public void transferUser(long billId, String taskId, String transferUser, String userCode, String opinion) {
1739
+    public void transferUser ( long billId, String taskId, String transferUser, String userCode, String opinion){
1629 1740
         // 查找当前用户的任务(只查找状态为APPROVAL的任务)
1630 1741
         final Optional<BillTaskEntity> taskOpt = billBpmnLogic
1631 1742
                 .findTaskBybillAndEmployeeAndTaskId(billId, taskId, userCode);
@@ -1663,7 +1774,7 @@ public class BillLogicImpl implements BillLogic {
1663 1774
             }
1664 1775
 
1665 1776
             //
1666
-            BillTaskEntity transferTask = new  BillTaskEntity();
1777
+            BillTaskEntity transferTask = new BillTaskEntity();
1667 1778
 
1668 1779
             transferTask.setBillId(billId);
1669 1780
             transferTask.setUserCode(targetUser);
@@ -1711,25 +1822,25 @@ public class BillLogicImpl implements BillLogic {
1711 1822
 
1712 1823
         //链接OA统一待办审批
1713 1824
         BillItemVO billItemVO = new BillItemVO();
1714
-        OfsTodoDataWebServicePortType_OfsTodoDataWebServiceHttpPort_Client o1 = new  OfsTodoDataWebServicePortType_OfsTodoDataWebServiceHttpPort_Client();
1825
+        OfsTodoDataWebServicePortType_OfsTodoDataWebServiceHttpPort_Client o1 = new OfsTodoDataWebServicePortType_OfsTodoDataWebServiceHttpPort_Client();
1715 1826
         billItemVO.setId(billId);
1716 1827
         //给已转发的发送已办
1717 1828
         billItemVO.setStatus(14);
1718 1829
         billItemVO.setTaskid(taskId);
1719 1830
         List<ReceiveRequestInfoByJsonDto> requestInfoByJsonDtos2 = this.findrequestInfo(billItemVO);
1720
-        String token =this.getToken4();
1721
-        for (ReceiveRequestInfoByJsonDto requestInfoByJsonDto:requestInfoByJsonDtos2){
1722
-            String requestdata =o1.getRequestData(requestInfoByJsonDto,"2");
1723
-            o1.ofsTodoDatabyEten(requestdata,token);
1831
+        String token = this.getToken4();
1832
+        for (ReceiveRequestInfoByJsonDto requestInfoByJsonDto : requestInfoByJsonDtos2) {
1833
+            String requestdata = o1.getRequestData(requestInfoByJsonDto, "2");
1834
+            o1.ofsTodoDatabyEten(requestdata, token);
1724 1835
         }
1725 1836
 
1726 1837
         //给审批中的发送待办
1727 1838
         billItemVO.setStatus(1);
1728 1839
         billItemVO.setTaskid(taskId);
1729 1840
         List<ReceiveRequestInfoByJsonDto> requestInfoByJsonDtos1 = this.findrequestInfo(billItemVO);
1730
-        for (ReceiveRequestInfoByJsonDto requestInfoByJsonDto:requestInfoByJsonDtos1){
1731
-            String requestdata =o1.getRequestData(requestInfoByJsonDto,"0");
1732
-            o1.ofsTodoDatabyEten(requestdata,token);
1841
+        for (ReceiveRequestInfoByJsonDto requestInfoByJsonDto : requestInfoByJsonDtos1) {
1842
+            String requestdata = o1.getRequestData(requestInfoByJsonDto, "0");
1843
+            o1.ofsTodoDatabyEten(requestdata, token);
1733 1844
         }
1734 1845
     }
1735 1846
 
@@ -1740,7 +1851,7 @@ public class BillLogicImpl implements BillLogic {
1740 1851
      * @return 审批单数据信息
1741 1852
      */
1742 1853
     @Override
1743
-    public BillDetailVO<List<FormFieldVO>> createByApp(long processId) {
1854
+    public BillDetailVO<List<FormFieldVO>> createByApp ( long processId){
1744 1855
         ProcessDetailDTO process = checkProcess(processId);
1745 1856
         final List<FormFieldVO> fieldVOS =
1746 1857
                 formBasicConvert.FormFieldPOToVO(formFieldService.findVoByProcessId(processId));
@@ -1777,9 +1888,9 @@ public class BillLogicImpl implements BillLogic {
1777 1888
      * @return 验证结果
1778 1889
      */
1779 1890
     @Override
1780
-    public ValidationResultDTO validation(
1891
+    public ValidationResultDTO validation (
1781 1892
             long processId, long billId, String formDataJson, String userCode
1782
-    ) {
1893
+    ){
1783 1894
         final Map<String, Object> dataMap =
1784 1895
                 JSON.parseObject(formDataJson, FastJsonType.MAP_OBJECT_TR);
1785 1896
         final BillDataContext billDataValue;
@@ -1798,7 +1909,7 @@ public class BillLogicImpl implements BillLogic {
1798 1909
      * @return 节点条件
1799 1910
      */
1800 1911
     @Override
1801
-    public List<String> getNodeCondition(long processId, long billId, String taskId) {
1912
+    public List<String> getNodeCondition ( long processId, long billId, String taskId){
1802 1913
         final List<BillTaskEntity> list = billTaskService.list(
1803 1914
                 Wrappers.lambdaQuery(BillTaskEntity.class)
1804 1915
                         .eq(BillTaskEntity::getBillId, billId)
@@ -1839,7 +1950,7 @@ public class BillLogicImpl implements BillLogic {
1839 1950
      * @return 待我审批数量
1840 1951
      */
1841 1952
     @Override
1842
-    public String findTodoSize() {
1953
+    public String findTodoSize () {
1843 1954
         List<Integer> statusList =
1844 1955
                 Lists.newArrayList(BillStatus.APPROVAL.getStatus(), BillStatus.REFUSE.getStatus());
1845 1956
         final String userCode = loginUserHolder.getUserCode();
@@ -1848,18 +1959,18 @@ public class BillLogicImpl implements BillLogic {
1848 1959
     }
1849 1960
 
1850 1961
     @Override
1851
-    public Pair<List<BillItemVO>, Long> findAllByQuery(
1962
+    public Pair<List<BillItemVO>, Long> findAllByQuery (
1852 1963
             Integer pageNo, Integer pageSize, DraftBillQuery query
1853
-    ) {
1964
+    ){
1854 1965
         Page page = new Page(pageNo, pageSize);
1855 1966
         final List<BillItemPO> billDatas = this.billService.findAllByQuery(page, query);
1856 1967
         final Page<BillItemVO> billItemVOPage = toItemVOList(page, billDatas, null);
1857 1968
         return Pair.of(billItemVOPage.getRecords(), billItemVOPage.getTotal());
1858 1969
     }
1859 1970
 
1860
-    private ValidationResultDTO validataionWithResult(
1971
+    private ValidationResultDTO validataionWithResult (
1861 1972
             BillDataContext billDataValue, String userCode, BillValidationLogic validationService
1862
-    ) {
1973
+    ){
1863 1974
 
1864 1975
         if (null != validationService) {
1865 1976
             return validationService.validation(billDataValue, userCode);
@@ -1871,7 +1982,7 @@ public class BillLogicImpl implements BillLogic {
1871 1982
         }
1872 1983
     }
1873 1984
 
1874
-    private BillValidationLogic getValidationService(long processId) {
1985
+    private BillValidationLogic getValidationService ( long processId){
1875 1986
         FormValidationEntity formValidation = formValidationService.findByProcessId(processId);
1876 1987
         if (null == formValidation) {
1877 1988
             return null;
@@ -1881,9 +1992,9 @@ public class BillLogicImpl implements BillLogic {
1881 1992
     }
1882 1993
 
1883 1994
     @Transactional(readOnly = true, rollbackFor = Exception.class)
1884
-    public BillDataContext resolveFormDataByValidation(
1885
-            long billId, ProcessDetailPO processDetail, Map<String, Object> formDataMap
1886
-    ) {
1995
+    public BillDataContext resolveFormDataByValidation (
1996
+            long billId, ProcessDetailPO processDetail, Map < String, Object > formDataMap
1997
+    ){
1887 1998
         long processId = processDetail.getId();
1888 1999
 
1889 2000
         final List<FormFieldPO> formFieldVOS = this.formFieldService.findVoByProcessId(processId);
@@ -1978,7 +2089,7 @@ public class BillLogicImpl implements BillLogic {
1978 2089
      * @param bill 审批单
1979 2090
      * @return 审批信息
1980 2091
      */
1981
-    private List<BillOpinionVO> billOpinions(ToaBillEntity bill) {
2092
+    private List<BillOpinionVO> billOpinions (ToaBillEntity bill){
1982 2093
         long processId = MoreObjects.firstNonNull(bill.getProcessId(), 0L);
1983 2094
         final List<BillOpinionVO> opinionVOS = Lists.newArrayList();
1984 2095
         final List<ProcessNodeExtendEntity> taskNodes =
@@ -1997,13 +2108,13 @@ public class BillLogicImpl implements BillLogic {
1997 2108
         return opinionVOS;
1998 2109
     }
1999 2110
 
2000
-    private <T> BillDetailVO.BillDetailVOBuilder<T> billDetailBuilder(
2111
+    private <T > BillDetailVO.BillDetailVOBuilder < T > billDetailBuilder(
2001 2112
             BillDataJsonEntity billDataJson, ToaBillEntity bill
2002 2113
     ) {
2003 2114
         return billDetailBuilder(billDataJson, bill, StringPool.EMPTY);
2004 2115
     }
2005 2116
 
2006
-    private <T> BillDetailVO.BillDetailVOBuilder<T> billDetailBuilder(
2117
+    private <T > BillDetailVO.BillDetailVOBuilder < T > billDetailBuilder(
2007 2118
             BillDataJsonEntity billDataJson, ToaBillEntity bill, String page
2008 2119
     ) {
2009 2120
         long billId = bill.getId();
@@ -2126,7 +2237,7 @@ public class BillLogicImpl implements BillLogic {
2126 2237
      * @param processId 业务流程ID
2127 2238
      * @return 业务流程信息,如果状态或者业务流程不存在,则抛出异常
2128 2239
      */
2129
-    private ProcessDetailDTO checkProcess(long processId) {
2240
+    private ProcessDetailDTO checkProcess ( long processId){
2130 2241
         final ProcessDetailPO process = this.processService.findDetailById(processId);
2131 2242
         if (process == null) {
2132 2243
             throw new RbException(StringPool.EMPTY, ProcessCode.BILL_SAVE_PROCESS_NIL);
@@ -2145,9 +2256,9 @@ public class BillLogicImpl implements BillLogic {
2145 2256
      * @param title   审批标题
2146 2257
      * @return 封装后的表单字段信息
2147 2258
      */
2148
-    private Map<String, Object> bizFormData(
2259
+    private Map<String, Object> bizFormData (
2149 2260
             ProcessDetailDTO process, UserInfoDTO userInfoDTO, String title
2150
-    ) {
2261
+    ){
2151 2262
         final long processId = process.getId();
2152 2263
         final long processCodeId = Objects.isNull(process.getCodeId()) ? 0 : process.getCodeId();
2153 2264
         final List<FormFieldEntity> bizFields =
@@ -2203,7 +2314,7 @@ public class BillLogicImpl implements BillLogic {
2203 2314
     }
2204 2315
 
2205 2316
     @Override
2206
-    public List<ProcessTypeVO> findTodoCateSize() {
2317
+    public List<ProcessTypeVO> findTodoCateSize () {
2207 2318
         LambdaQueryWrapper<ProcessTypeEntity> wrapper =
2208 2319
                 Wrappers.lambdaQuery(ProcessTypeEntity.class);
2209 2320
 
@@ -2242,12 +2353,12 @@ public class BillLogicImpl implements BillLogic {
2242 2353
     }
2243 2354
 
2244 2355
     @Override
2245
-    public List<ReceiveRequestInfoByJsonDto> findrequestInfo(BillItemVO billItemVO) {
2356
+    public List<ReceiveRequestInfoByJsonDto> findrequestInfo (BillItemVO billItemVO){
2246 2357
         return billService.findrequestInfo(billItemVO);
2247 2358
     }
2248 2359
 
2249 2360
     @Override
2250
-    public String getToken4() {
2361
+    public String getToken4 () {
2251 2362
         return billService.getToken4();
2252 2363
     }
2253 2364
 }

+ 6 - 0
bpm-server/src/main/java/com/srm/bpmserver/logic/impl/CallBackLogicImpl.java

@@ -11,6 +11,7 @@ import com.srm.common.data.rest.R;
11 11
 import org.springframework.http.HttpStatus;
12 12
 import org.springframework.http.ResponseEntity;
13 13
 import org.springframework.stereotype.Service;
14
+import org.springframework.transaction.annotation.Transactional;
14 15
 
15 16
 import lombok.RequiredArgsConstructor;
16 17
 import lombok.extern.slf4j.Slf4j;
@@ -31,12 +32,17 @@ public class CallBackLogicImpl implements CallBackLogic {
31 32
 
32 33
     /**
33 34
      * 回调
35
+     * 
36
+     * 使用 @Transactional(propagation = PROPAGATION_REQUIRED) 确保:
37
+     * - 如果已有活动事务,会加入现有事务(如从 agreeFlow() -> complete() -> callBack())
38
+     * - 如果没有活动事务,会创建新事务(如独立调用时)
34 39
      *
35 40
      * @param processId 流程id
36 41
      * @param billId    审批单id
37 42
      * @param status    状态
38 43
      */
39 44
     @Override
45
+    @Transactional(rollbackFor = Exception.class)
40 46
     public void callBack(Long processId, Long billId, Integer status) {
41 47
         log.info("触发了回调:{},{},{}", processId, billId, status);
42 48
         JSONObject data = new JSONObject();

+ 6 - 6
bpm-server/src/main/resources/application.yml

@@ -49,15 +49,15 @@ spring:
49 49
     druid:
50 50
       #MySQL
51 51
       driver-class-name: com.mysql.jdbc.Driver
52
-#      url: jdbc:mysql://172.16.0.48:3306/jqh_srm_9000?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8
53
-#      username: root
54
-#      password: jqh_srm_2022
52
+      url: jdbc:mysql://172.16.0.48:3306/jqh_srm_9000?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8
53
+      username: root
54
+      password: jqh_srm_2022
55 55
 #      url: jdbc:mysql://172.16.0.71:3306/jqh_srm_9001?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8
56 56
 #      username: root
57 57
 #      password: jqh_srm_123123
58
-      url: jdbc:mysql://172.16.0.66:3306/jqh_srm_9000?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8
59
-      username: root
60
-      password: jqh_srm_2022
58
+#      url: jdbc:mysql://172.16.0.66:3306/jqh_srm_9000?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=GMT%2B8
59
+#      username: root
60
+#      password: jqh_srm_2022
61 61
       initial-size: 10
62 62
       max-active: 20
63 63
       min-idle: 2