数据库事务提交
continuous-integration/drone/push Build is passing Details

master
YXY 12 months ago
parent 8ed72cc65a
commit 67d9259e4f

@ -22,6 +22,9 @@ import com.ruoyi.quartz.domain.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -57,6 +60,11 @@ public abstract class SyncAccountsJobAbstract {
private LarkRobotHelper larkRobotHelper; private LarkRobotHelper larkRobotHelper;
@Autowired @Autowired
private CJTCreateLarkTableJob cjtCreateLarkTableJob; private CJTCreateLarkTableJob cjtCreateLarkTableJob;
@Autowired
DataSourceTransactionManager dataSourceTransactionManager;
@Autowired
TransactionDefinition transactionDefinition;
@Value("${lark.robot.group}") @Value("${lark.robot.group}")
private String ROBOT_GROUP; private String ROBOT_GROUP;
@Value("${sync.flag}") @Value("${sync.flag}")
@ -354,6 +362,7 @@ public abstract class SyncAccountsJobAbstract {
List<List<String>> rows = new ArrayList<>(); List<List<String>> rows = new ArrayList<>();
do { do {
try { try {
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
//初始化数据 //初始化数据
if (cjtRequestBody == null) { if (cjtRequestBody == null) {
cjtRequestBody = new CJTRequestBody(page, PAGE_SIZE, getQueryFields(), getQueryCondition(context)); cjtRequestBody = new CJTRequestBody(page, PAGE_SIZE, getQueryFields(), getQueryCondition(context));
@ -377,6 +386,7 @@ public abstract class SyncAccountsJobAbstract {
throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey)); throw new RuntimeException(String.format("存在同步失败的记录 %s", errorKey));
} }
} }
dataSourceTransactionManager.commit(transactionStatus);
} catch (Exception e) { } catch (Exception e) {
log.error("{} exception", this.getClassName(), e); log.error("{} exception", this.getClassName(), e);
errorMessage = buildErrorBody(cjtRequest, e.getMessage()); errorMessage = buildErrorBody(cjtRequest, e.getMessage());

Loading…
Cancel
Save