首先设置任务自动执行时间
//每日十点开始执行获取昨日账单任务
@Scheduled(cron = "0 0 10 * * ?")
public void task() throws Exception{
// 获取昨日日期
LocalDate today = LocalDate.now();
LocalDate yesterday = today.minusDays(1);
String taskDate = formatter.format(yesterday);
// 获取昨日微信支付账单
boolean taskStatus = this.wxpayBillsTask(task.getTaskID(), yesterday);
}
对多个公众号进行统一管理,一次性获取全部对账单
/*
* 获取昨日微信支付账单
* 1.查询微信公众号号配置
* 2.分别获取支付账单请求,并保存请求记录
* 3.解析微信返回账单数据,并保存到数据库
* 4.更新任务进程的微信商户账单采集状态
*/
protected boolean wxpayBillsTask(int taskID, LocalDate yesterday) throws Exception{
String bill_date = dateFormatter.format(yesterday);
String taskDate = formatter.format(yesterday);
logger.debug("wxpayBillsTask {}|{}", taskID, bill_date);
// 查询微信公众号配置信息
List<WeixinAccount> accounts = commonRepository.queryAllWeixinAccounts();
CollectLogs log = null;
Boolean bRet = false;
for (WeixinAccount account : accounts) {
if (StringUtils.isEmpty(account.getWeixinAppID()) || StringUtils.isEmpty(account.getWeixinMchID()