package com.stylefeng.guns.modular.system.util; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.stylefeng.guns.core.util.ToolUtil; import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample; import com.stylefeng.guns.modular.cloudPayment.example.BalanceAcctExample; import com.stylefeng.guns.modular.cloudPayment.example.MchApplicationExample; import com.stylefeng.guns.modular.cloudPayment.example.WithdrawalExample; import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq; import com.stylefeng.guns.modular.system.dao.TCompanyMapper; import com.stylefeng.guns.modular.system.model.TDriver; import com.stylefeng.guns.modular.system.model.TEnterpriseWithdrawal; import com.stylefeng.guns.modular.system.service.*; import com.unionpay.upyzt.exception.UpyztException; import com.unionpay.upyzt.resp.AllocationResp; import com.unionpay.upyzt.resp.BalanceAcctResp; import com.unionpay.upyzt.resp.MchApplicationResp; import com.unionpay.upyzt.resp.WithdrawalResp; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; /** * 定时任务工具类 */ @Component public class TaskUtil { @Autowired private ITLocationService locationService; @Autowired private PushMinistryOfTransportUtil pushMinistryOfTransportUtil; @Value("${pushMinistryOfTransport}") private boolean pushMinistryOfTransport; @Autowired private ITDriverService driverService; @Resource private ITCompanyService companyMapper; @Autowired private ITEnterpriseWithdrawalService tEnterpriseWithdrawalService; @Autowired private IDictService dictService; @Autowired private MapDispatchUtil mapDispatchUtil; /** * 每隔一分钟去处理的定时任务 */ @Scheduled(fixedRate = 1000 * 60) public void taskMinute() { try { List isAudit = tEnterpriseWithdrawalService.selectList(new EntityWrapper().eq("isAudit", 1)); for (TEnterpriseWithdrawal enterpriseWithdrawal : isAudit) { String mchApplicationId = enterpriseWithdrawal.getMchApplicationId(); MchApplicationResp mchApplicationResp = MchApplicationExample.retrieveById(mchApplicationId); enterpriseWithdrawal.setApplicationStatus(mchApplicationResp.getApplicationStatus()); if ("succeeded".equals(mchApplicationResp.getApplicationStatus())) { enterpriseWithdrawal.setMchId(mchApplicationResp.getMchId()); enterpriseWithdrawal.setBalanceAcctId(mchApplicationResp.getBalanceAcctId()); enterpriseWithdrawal.setSettleAcctId(mchApplicationResp.getSettleAcctId()); enterpriseWithdrawal.setRelAcctNo(mchApplicationResp.getRelAcctNo()); enterpriseWithdrawal.setIsAudit(2); } tEnterpriseWithdrawalService.updateById(enterpriseWithdrawal); } } catch (Exception e) { e.printStackTrace(); } } /** * 每天的凌晨执行的任务 */ @Scheduled(cron = "0 0 0 * * *") // @Scheduled(fixedRate = 1000 * 60) public void taskDay() { try { // companyMapper.aaa(); companyMapper.updateMoney(); // 分账业务 locationService.updateFence();//更新线上电子围栏 } catch (Exception e) { e.printStackTrace(); } } /** * 重置【输入提示】Key池 */ @Scheduled(cron = "0 0 0 * * *") public void resetInputtips() { try { dictService.updateByCode("gaode_inputtips_switch", "1");//重置【输入提示】Key池 System.out.println("重置【输入提示】Key池成功!"); } catch (Exception e) { System.out.println("重置【输入提示】Key池失败!Exception:" + e); } } /** * 更新地图使用量 */ @Scheduled(cron = "0 0/10 * * * *") public void updateDayBaseQuotaUsage() { System.out.println("updateDayBaseQuotaUsageBegin..."); try { System.out.println("开始更新高德地图接口使用量..."); mapDispatchUtil.updateGaoDeDayBaseQuotaUsageBatch(); System.out.println("开始更新腾讯地图接口使用量..."); mapDispatchUtil.updateTencentMapDayBaseQuotaUsageBatch(); } catch (Exception e) { System.out.println("updateDayBaseQuotaUsageException"); e.printStackTrace(); } System.out.println("updateDayBaseQuotaUsageEnd"); } @Scheduled(fixedRate = 1000 * 60) public void taskDayFenzhang() { try { companyMapper.taskDayFenzhang(); // 分账业务 } catch (Exception e) { e.printStackTrace(); } } @Scheduled(fixedRate = 1000 * 60) public void taskTixian() { try { /* WithdrawalResp withdrawalResp = WithdrawalExample.retrieveById("3708467427201980978"); System.out.println(withdrawalResp);*/ companyMapper.taskTixian(); } catch (Exception e) { e.printStackTrace(); } } /** * 每月第一天的1点执行的任务 */ @Scheduled(cron = "0 0 1 1 * *") public void taskMonth() { try { if (pushMinistryOfTransport) { List tDrivers = driverService.selectList(new EntityWrapper().eq("authState", 2).ne("flag", 3)); for (TDriver driver : tDrivers) { pushMinistryOfTransportUtil.baseInfoDriverStat(driver.getId()); } } } catch (Exception e) { e.printStackTrace(); } } }