|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.sqx.common.constant.RedisKey;
|
|
import com.sqx.common.constant.RedisKey;
|
|
|
|
|
+import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.common.utils.DateUtils;
|
|
import com.sqx.common.utils.DateUtils;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
import com.sqx.modules.app.entity.UserEntity;
|
|
import com.sqx.modules.app.entity.UserEntity;
|
|
@@ -34,6 +35,7 @@ import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
+import org.springframework.transaction.TransactionDefinition;
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
|
|
|
|
|
@@ -81,35 +83,35 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
public void generatePlatformBill(LocalDate date, boolean cover) {
|
|
public void generatePlatformBill(LocalDate date, boolean cover) {
|
|
|
RLock lock = redissonClient.getLock(RedisKey.PLATFORM_BILL_LOCK);
|
|
RLock lock = redissonClient.getLock(RedisKey.PLATFORM_BILL_LOCK);
|
|
|
lock.lock();
|
|
lock.lock();
|
|
|
- TransactionStatus status = null;
|
|
|
|
|
try {
|
|
try {
|
|
|
- // 开启编程式事务
|
|
|
|
|
- status = transactionManager.getTransaction(new DefaultTransactionDefinition());
|
|
|
|
|
-
|
|
|
|
|
// 判断有无当天数据,然后根据策略觉得是否执行覆盖数据还是直接退出
|
|
// 判断有无当天数据,然后根据策略觉得是否执行覆盖数据还是直接退出
|
|
|
LambdaQueryWrapper<PlatformBill> wrapper = Wrappers.lambdaQuery();
|
|
LambdaQueryWrapper<PlatformBill> wrapper = Wrappers.lambdaQuery();
|
|
|
wrapper.eq(PlatformBill::getDayId, date);
|
|
wrapper.eq(PlatformBill::getDayId, date);
|
|
|
if (count(wrapper) > 0) {
|
|
if (count(wrapper) > 0) {
|
|
|
- if (cover) {
|
|
|
|
|
- // 删除旧数据
|
|
|
|
|
- remove(wrapper);
|
|
|
|
|
- } else {
|
|
|
|
|
|
|
+ if (!cover) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 生成账单数据
|
|
|
Collection<PlatformBill> platformBills = doGeneratePlatformBill(date);
|
|
Collection<PlatformBill> platformBills = doGeneratePlatformBill(date);
|
|
|
|
|
|
|
|
- // 保存最终结果
|
|
|
|
|
- saveBatch(platformBills);
|
|
|
|
|
-
|
|
|
|
|
- transactionManager.commit(status);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- if (ObjectUtil.isNotNull(status)) {
|
|
|
|
|
|
|
+ // 开启编程式事务,保存账单数据
|
|
|
|
|
+ DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
|
|
|
|
|
+ definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
|
|
|
|
+ definition.setTimeout(30); // 超时时间30秒
|
|
|
|
|
+ TransactionStatus status = transactionManager.getTransaction(definition);
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 删除旧数据
|
|
|
|
|
+ if (cover) remove(wrapper);
|
|
|
|
|
+ // 保存最终结果
|
|
|
|
|
+ saveBatch(platformBills);
|
|
|
|
|
+
|
|
|
|
|
+ transactionManager.commit(status);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
transactionManager.rollback(status);
|
|
transactionManager.rollback(status);
|
|
|
|
|
+ throw new SqxException("账单数据保存失败", e);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
} finally {
|
|
} finally {
|
|
|
lock.unlock();
|
|
lock.unlock();
|
|
|
}
|
|
}
|