新增事务方案修复掉线问题导致的重复消费

This commit is contained in:
liyj 2025-11-04 11:42:08 +08:00
parent 4b13a8c0d3
commit 03a475d1c9
2 changed files with 15 additions and 24 deletions

View File

@ -550,7 +550,7 @@ public class SxDataDao extends BaseDao{
int[] remainingCounts = ps.executeBatch();
//todo 新增流水
updateStoreSaleFlow(dataBaseInfo,rmSaleflowList,tRmPayflowList);
updateStoreSaleFlow(conn,rmSaleflowList,tRmPayflowList);
List<String> consumIds=productQuantityConsumptionDtoList
.stream()
@ -566,7 +566,7 @@ public class SxDataDao extends BaseDao{
if (!HttpUtils.SUCCESSCODE.equals(code)) {
throw new Exception("服务器异常");
}
log.info("剩余批次更新数: {}", Arrays.toString(remainingCounts));
log.info("库存更新剩余批次更新数: {}", Arrays.toString(remainingCounts));
conn.commit(); // 最终提交事务
log.info("批量更新完成,总记录数: {}" , count);
//baseUpdateImBrancStock(dataBaseInfo);
@ -754,18 +754,18 @@ public class SxDataDao extends BaseDao{
/**
* 批量新增销售流水
* @param dataBaseInfo
* @param conn
* @param rmSaleflowList
*/
public void updateStoreSaleFlow(DataBaseInfo dataBaseInfo,List<RmSaleflow> rmSaleflowList,List<TRmPayflow> payflowList){
public void updateStoreSaleFlow(Connection conn,List<RmSaleflow> rmSaleflowList,List<TRmPayflow> payflowList){
if(CollectionUtil.isEmpty(rmSaleflowList)){
log.info("销售流水记录为空");
return;
}
Connection conn =getConnection(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),
dataBaseInfo.getPassword(), dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName());
try {
conn.setAutoCommit(false); // 关闭自动提交开启事务
// Connection conn =getConnection(dataBaseInfo.getIp(),dataBaseInfo.getUserName(),
// dataBaseInfo.getPassword(), dataBaseInfo.getDbPort(),dataBaseInfo.getDataBaseName());
//try {
//conn.setAutoCommit(false); // 关闭自动提交开启事务
String sql = "INSERT INTO t_rm_saleflow (" +
"flow_id, flow_no, branch_no, item_no, source_price, sale_price, " +
"sale_qnty, sale_money, sell_way, oper_id, sale_man, counter_no, " +
@ -892,27 +892,18 @@ public class SxDataDao extends BaseDao{
int[] remainingCounts2 = ps2.executeBatch();
log.info("销售流水记录剩余批次更新数: {}", Arrays.toString(remainingCounts));
log.info("支付流水记录剩余批次更新数: {}", Arrays.toString(remainingCounts2));
conn.commit(); // 最终提交事务
//conn.commit(); // 最终提交事务
log.info("销售-支付-流水记录批量更新完成,总记录数: {}" , count);
//baseUpdateImBrancStock(dataBaseInfo);
} catch (Exception e) {
conn.rollback(); // 出错时回滚整个事务
// conn.rollback(); // 出错时回滚整个事务
log.info("销售支付流水记录业务失败:: {}", e.getMessage());
throw new RuntimeException("销售支付流水记录业务失败:: {}"+e.getMessage());
}
} catch (SQLException e) {
log.info("sql失败: {}", e.getMessage());
throw new RuntimeException("sql失败: {}"+e.getMessage());
}finally {
if(conn!=null){
try {
conn.close();
} catch (SQLException e) {
log.info("最后sql失败: {}", e.getMessage());
throw new RuntimeException("sql关闭失败: {}"+e.getMessage());
}
}
}
// } catch (SQLException e) {
// log.info("sql失败: {}", e.getMessage());
// throw new RuntimeException("sql失败: {}"+e.getMessage());
// }
}
/**

View File

@ -397,7 +397,7 @@ public class SxDataServiceImp extends SxDataAbstService implements SxDataService
+"&syncType="+DicEnum.MUAL_1.getCode()
+"&refreshDateStr="+refreshDate,
JSONUtil.parseArray(folders));
log.info("商品分类总共有{}条数据,同步完成{}条",total,syncCount);
log.info("商品总共有{}条数据,同步完成{}条",total,syncCount);
String code= HttpUtils.postData(restTemplate,remoteIp+HttpUtils.URL_SYNC_GOODS_READ
+"?appKey="+commentModel.getAppKey()
+"&sign="+commentModel.getAppId()