Browse Source

看板同步、编辑同步事务优化、返回信息优化

qiangxuan 2 tháng trước cách đây
mục cha
commit
8805ffdc12

+ 14 - 5
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -493,13 +493,18 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 				old.setAmountTotal(originalAmountTotal);
 				JSONObject jsonObject = storageBillService.billetAutoTmpDataSyn(old);
 				log.info("钢坯装运单编辑,未知目的地数据同步结果:{}", jsonObject);
+				if (jsonObject.getBoolean("success")){
+					return Result.OK("装运单编辑成功!");
+				} else {
+					return Result.error("装运单编辑失败!");
+				}
 			} catch (Exception e) {
 				// 更新 typeConfigId 和 destination
 				old.setTypeConfigId(storageBill.getTypeConfigId());
 				old.setDestination(storageBill.getDestination());
 				storageBillService.updateById(old);
-				log.error("装运单同步发生异常,已更新目的地:", e);
-				return Result.OK("装运单同步异常,编辑目的地成功!");
+				log.info("装运单同步发生异常,已更新目的地:", e);
+				return Result.OK("装运单同步异常,编辑成功!");
 			}
 		} else {
 			log.info("{}{}", "B端编辑钢坯装运单", old.getLicensePlate() + "===" + storageBill.getLicensePlate());
@@ -518,7 +523,7 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 			storageBillService.updateById(storageBill);
 		}
 		operateLogService.add(old,storageBill,StorageBill.class);
-		return Result.OK("编辑成功!");
+		return Result.OK("装运单编辑成功!");
 	}
 	
 	/**
@@ -1745,14 +1750,18 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 				bill.setTypeConfigId(storageBill.getTypeConfigId());
 				JSONObject jsonObject = storageBillService.billetAutoTmpDataSynConfirm(bill);
 				log.info("{}{}", "看板确认目的地数据同步结果:", jsonObject);
-				return Result.OK("看板确认目的地成功!");
+				if (jsonObject.getBoolean("success")) {
+					return Result.OK("看板确认目的地成功!");
+				} else {
+					return Result.error("看板确认目的地失败!");
+				}
 			} catch (Exception e) {
 				// 更新typeConfigId和destination
 				bill.setTypeConfigId(storageBill.getTypeConfigId());
 				bill.setDestination(storageBill.getDestination());
 				storageBillService.getBaseMapper().updateById(bill);
 				log.error("B端监控看板确认目的地,同步发生异常", e.getMessage());
-				return Result.OK("看板确认目的地失败,系统已更新目的地信息!");
+				return Result.OK("看板确认目的地成功!");
 			}
 		}else {
 			log.info("{}{}", "看板确认目的地参数有误:", JSON.toJSON(storageBill));

+ 26 - 12
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/service/impl/StorageBillServiceImpl.java

@@ -2828,7 +2828,9 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                     if (jsonObject.containsKey("fail")) {
                         log.info("{}{}", "编辑装运单,未知目的地数据同步操作失败,事务回滚!", jsonObject);
                         result.put("fail", "编辑装运单,未知目的地数据同步操作失败!");
-                        throw new RuntimeException("编辑装运单,未知目的地数据同步操作失败!");
+                        // 手动回滚事务
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        return result;
                     }
                 }
                 List<String> billetNos = rollClubCommonHotChargeList.stream().map(RollClubCommon::getBilletNo).collect(Collectors.toList());
@@ -2900,7 +2902,9 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                     if (oConvertUtils.isEmpty(idExistBh)){
                         log.info("{}{}", "编辑装运单,钢坯热送单为空,堆垛数据同步失败:", JSON.toJSON(billetHotsend));
                         result.put("fail", "编辑装运单,钢坯热送单为空,堆垛数据同步操作失败!");
-                        throw new RuntimeException("编辑装运单,钢坯热送单为空,堆垛数据同步操作失败!");
+                        // 手动回滚事务
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        return result;
                     }
                     billetHotsend.setId(idExistBh.getId());
                     // 钢坯热送基础信息存在,但是钢坯信息不存在 直接返回
@@ -2932,7 +2936,9 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                 if (oConvertUtils.listIsEmpty(billetBasicInfoStackList)) {
                     log.info("编辑装运单,钢坯基础信息为空,堆垛数据同步失败!");
                     result.put("fail", "编辑装运单,钢坯基础信息为空,堆垛数据同步失败!");
-                    throw new RuntimeException("编辑装运单,钢坯基础信息为空,堆垛数据同步失败!");
+                    // 手动回滚事务
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return result;
                 }
                 //5 查询并批量更新钢坯基础信息 belongTable
                 billetBasicInfoStackList.forEach(x ->{
@@ -3017,9 +3023,11 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
             return result;
         } catch (Exception e) {
             // 记录异常日志
-            log.error("B端编辑装运单未知目的地明细同步发生异常", e);
-            // 抛出异常触发事务回滚
-            throw new RuntimeException(e);
+            log.error("编辑装运单未知目的地明细同步发生异常", e);
+            result.put("fail", "编辑装运单明细同步异常!");
+            // 手动回滚事务
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return result;
         }
     }
 
@@ -3031,13 +3039,12 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
         JSONObject result = new JSONObject();
         try {
             log.info("{}{}", "监控看板确认目的地,数据同步装运单信息:", JSON.toJSON(storageBill));
-
             // 根据装运单ID查询钢坯临时表 棒线数据同步、堆垛数据同步
             List<BilletAutoTmp> billetAutoTmpList = billetAutoTmpService.list(new LambdaQueryWrapper<BilletAutoTmp>()
                     .eq(BilletAutoTmp::getStorageBillId, storageBill.getId()));
             if (oConvertUtils.listIsEmpty(billetAutoTmpList)){
                 baseMapper.updateById(storageBill);
-                result.put("success", "更新目的地成功!");
+                result.put("success", "看板确认目的地成功!");
                 return result;
             }
 
@@ -3107,7 +3114,8 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                     if (jsonObject.containsKey("fail")) {
                         log.info("{}{}", "监控看板确认目的地,未知目的地数据同步操作失败,事务回滚!", jsonObject);
                         result.put("fail", "监控看板确认目的地,未知目的地数据同步操作失败!");
-                        throw new RuntimeException("监控看板确认目的地,未知目的地数据同步操作失败!");
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        return result;
                     }
                 }
                 List<String> billetNos = rollClubCommonHotChargeList.stream().map(RollClubCommon::getBilletNo).collect(Collectors.toList());
@@ -3180,7 +3188,8 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                     if (oConvertUtils.isEmpty(idExistBh)){
                         log.info("{}{}", "监控看板确认目的地,钢坯热送单为空,堆垛数据同步失败:", JSON.toJSON(billetHotsend));
                         result.put("fail", "监控看板确认目的地,钢坯热送单为空,堆垛数据同步操作失败!");
-                        throw new RuntimeException("监控看板确认目的地,钢坯热送单为空,堆垛数据同步操作失败!");
+                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                        return result;
                     }
                     billetHotsend.setId(idExistBh.getId());
                     // 钢坯热送基础信息存在,但是钢坯信息不存在 直接返回
@@ -3210,7 +3219,9 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
                         .in(BilletBasicInfo::getBilletNo, billetNosList);
                 billetBasicInfoStackList = billetBasicInfoService.list(queryWrapperls);
                 if (oConvertUtils.listIsEmpty(billetBasicInfoStackList)) {
+                    log.info("{}{}", "监控看板确认目的地,钢坯基础信息为空,堆垛数据同步失败:", billetNosList);
                     result.put("fail", "监控看板确认目的地,钢坯基础信息为空,堆垛数据同步失败!");
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     return result;
                 }
                 //5 查询并批量更新钢坯基础信息 belongTable
@@ -3297,8 +3308,11 @@ public class StorageBillServiceImpl extends ServiceImpl<StorageBillMapper, Stora
             return result;
         }catch (Exception e){
             // 记录异常日志
-            log.error("B端监控看板确认目的地,同步发生异常", e.getMessage());
-            throw new RuntimeException(e);
+            log.error("监控看板确认目的地,同步发生异常", e.getMessage());
+            result.put("fail", "编辑装运单明细同步异常!");
+            // 手动回滚事务
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+            return result;
         }
     }