Commit c7d0dcca by 林永健

feat(integral): 添加定时任务批量更新提现记录平台方信息

1 parent 24e6ca39
package cn.com.glsx.scrm.shopmall.job;
import cn.com.glsx.framework.core.util.DateUtils;
import cn.com.glsx.scrm.shopmall.service.integral.IntegralTransferOutService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.oreframework.boot.autoconfigure.elasticjob.annotation.ElasticJobConf;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
@Slf4j
@ElasticJobConf(name = "IntegralTransferOutAppendRealityMerchantJob", cron = "0 0 23 21 1 ? 2026", description = "更新提现记录的平台方信息", overwrite = true)
public class IntegralTransferOutAppendRealityMerchantJob implements SimpleJob {
@Autowired
private IntegralTransferOutService integralTransferOutService;
@Override
public void execute(ShardingContext shardingContext) {
log.info("IntegralTransferOutAppendRealityMerchantJob start at {}", DateUtils.formatDate(new Date(), DateUtils.DEFAULT_DATE_FORMAT4));
integralTransferOutService.refreshOrderRealityMerchantInfo();
log.info("IntegralTransferOutAppendRealityMerchantJob end at {}", DateUtils.formatDate(new Date(), DateUtils.DEFAULT_DATE_FORMAT4));
}
}
...@@ -1687,4 +1687,75 @@ public class IntegralTransferOutService { ...@@ -1687,4 +1687,75 @@ public class IntegralTransferOutService {
return IntegralTransferSignStatusEnum.FAIL.getValue(); return IntegralTransferSignStatusEnum.FAIL.getValue();
} }
} }
public void refreshOrderRealityMerchantInfo() {
int pageNum = 1;
int pageSize = 200;
int totalProcessed = 0;
boolean hasMoreData = true;
int lastId = 0;
log.info("开始批量轮询并更新平台方信息,每页数量:{}", pageSize);
while (hasMoreData) {
try {
Example example = new Example(IntegralTransferOut.class);
example.selectProperties("id", "merchantId", "deletedFlag", "realityMerchantId", "realityMerchantName");
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("deletedFlag", "N")
.andGreaterThan("id", lastId)
.andIsNull("realityMerchantId")
.andIsNull("realityMerchantName");
example.setOrderByClause("id ASC");
PageHelper.startPage(1, pageSize, false);
List<IntegralTransferOut> orderList = integralTransferOutMapper.selectByExample(example);
if (CollectionUtils.isEmpty(orderList)) {
log.info("第{}页没有需要处理的数据,停止轮询", pageNum);
hasMoreData = false;
break;
}
log.info("第{}页查询到{}条需要处理的数据", pageNum, orderList.size());
int processedCount = 0;
// 更新 lastId,准备下一批查询
lastId = orderList.get(orderList.size() - 1).getId();
try {
// 追加平台方信息
appendRealityMerchantInfo(orderList);
// 批量更新数据库
for (IntegralTransferOut order : orderList) {
if (StringUtils.isNotBlank(order.getRealityMerchantId()) ||
StringUtils.isNotBlank(order.getRealityMerchantName())) {
// 只更新那些确实有平台方信息的数据
try {
integralTransferOutMapper.updateRealityMerchant(order);
processedCount++;
totalProcessed++;
} catch (Exception e) {
log.error("更新积分转账出账单失败,ID:{},错误:{}", order.getId(), e.getMessage(), e);
}
}
}
} catch (Exception e) {
log.error("第{}页处理批次数据时发生异常,错误:{}", pageNum, e.getMessage(), e);
}
// 避免过于频繁的操作,可选的延迟
try {
Thread.sleep(50); // 暂停50毫秒,避免过于频繁的数据库操作
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
log.warn("线程被中断,停止处理");
return;
}
log.info("第{}页处理完成,已处理{}条数据,累计处理{}条", pageNum, processedCount, totalProcessed);
pageNum++;
} catch (Exception e) {
log.error("轮询处理第{}页数据时发生异常:{}", pageNum, e.getMessage(), e);
hasMoreData = false; // 发生异常时停止处理
}
}
log.info("批量轮询并更新平台方信息完成,总共处理了{}条数据", totalProcessed);
}
} }
...@@ -11,10 +11,12 @@ import cn.com.glsx.scrm.shopmall.enums.integral.IntegralModeEnum; ...@@ -11,10 +11,12 @@ import cn.com.glsx.scrm.shopmall.enums.integral.IntegralModeEnum;
import cn.com.glsx.scrm.shopmall.enums.integral.IntegralTransferOutChannelEnum; import cn.com.glsx.scrm.shopmall.enums.integral.IntegralTransferOutChannelEnum;
import cn.com.glsx.scrm.shopmall.handler.platformPayment.PlatformPaymentNotifyHandler; import cn.com.glsx.scrm.shopmall.handler.platformPayment.PlatformPaymentNotifyHandler;
import cn.com.glsx.scrm.shopmall.handler.platformPayment.PlatformPaymentNotifyHandlerRegister; import cn.com.glsx.scrm.shopmall.handler.platformPayment.PlatformPaymentNotifyHandlerRegister;
import cn.com.glsx.scrm.shopmall.mapper.IntegralTransferOutMapper;
import cn.com.glsx.scrm.shopmall.model.IntegralTransferOut; import cn.com.glsx.scrm.shopmall.model.IntegralTransferOut;
import cn.com.glsx.scrm.shopmall.rabbitmq.consumer.ConsumerListener; import cn.com.glsx.scrm.shopmall.rabbitmq.consumer.ConsumerListener;
import cn.com.glsx.scrm.shopmall.service.BaseServiceTest; import cn.com.glsx.scrm.shopmall.service.BaseServiceTest;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
...@@ -31,6 +33,8 @@ public class IntegralTransferOutServiceTest extends BaseServiceTest { ...@@ -31,6 +33,8 @@ public class IntegralTransferOutServiceTest extends BaseServiceTest {
@Autowired @Autowired
private IntegralTransferOutService integralTransferOutService; private IntegralTransferOutService integralTransferOutService;
@Autowired @Autowired
private IntegralTransferOutMapper integralTransferOutMapper;
@Autowired
private PlatformPaymentNotifyHandlerRegister register; private PlatformPaymentNotifyHandlerRegister register;
@Autowired @Autowired
private ShenBianYunApiService shenBianYunApiService; private ShenBianYunApiService shenBianYunApiService;
...@@ -138,6 +142,18 @@ public class IntegralTransferOutServiceTest extends BaseServiceTest { ...@@ -138,6 +142,18 @@ public class IntegralTransferOutServiceTest extends BaseServiceTest {
} }
@Test @Test
public void appendRealityMerchantInfo(){
List<IntegralTransferOut> orders = integralTransferOutService.listByIds(Lists.newArrayList(180,181,182,183,184,185,186,187,188));
// List<IntegralTransferOut> orders = integralTransferOutService.listByIds(Lists.newArrayList(7514,7515,7516,7517,7518,7519));
integralTransferOutService.appendRealityMerchantInfo(orders);
}
@Test
public void refreshOrderRealityMerchantInfo(){
integralTransferOutService.refreshOrderRealityMerchantInfo();
}
@Test
public void testTransferOutImport() throws Exception{ public void testTransferOutImport() throws Exception{
// 读取 Excel 文件内容 // 读取 Excel 文件内容
Path path = Paths.get("D:\\data\\excel\\提现导入模版.xlsx"); Path path = Paths.get("D:\\data\\excel\\提现导入模版.xlsx");
...@@ -210,6 +226,39 @@ public class IntegralTransferOutServiceTest extends BaseServiceTest { ...@@ -210,6 +226,39 @@ public class IntegralTransferOutServiceTest extends BaseServiceTest {
} }
@Test @Test
public void handleSignFailData() {
List<IntegralTransferOut> orders = integralTransferOutService.listByIds(Lists.newArrayList(185, 186));
orders.stream().forEach(o -> {
o.setStatus("8");
o.setCustomerName("260110-"+o.getCustomerName());
o.setChannel("XINXIANGYUN");
});
integralTransferOutService.handleSignFailData(orders);
}
@Test
public void pushMessage() {
// List<IntegralTransferOut> orders = integralTransferOutService.listByIds(Lists.newArrayList(184));
List<IntegralTransferOut> orders = Lists.newArrayList(
integralTransferOutMapper.selectByPrimaryKey(1336),
integralTransferOutMapper.selectByPrimaryKey(1336),
integralTransferOutMapper.selectByPrimaryKey(1336),
integralTransferOutMapper.selectByPrimaryKey(1340),
integralTransferOutMapper.selectByPrimaryKey(1341),
integralTransferOutMapper.selectByPrimaryKey(1342),
integralTransferOutMapper.selectByPrimaryKey(1341),
integralTransferOutMapper.selectByPrimaryKey(1351),
integralTransferOutMapper.selectByPrimaryKey(1351)
);
orders.stream().forEach(o -> {
o.setStatus("8");
o.setCustomerName("260110-"+o.getCustomerName());
o.setChannel("XINXIANGYUN");
});
integralTransferOutService.queueBatchPay(orders, "XINXIANGYUN");
}
@Test
public void receiveMessage() { public void receiveMessage() {
// IntegralTransferOutQueueModel model = new IntegralTransferOutQueueModel(); // IntegralTransferOutQueueModel model = new IntegralTransferOutQueueModel();
// model.setChannel("XINXIANGYUN"); // model.setChannel("XINXIANGYUN");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!