jiangping
2023-12-12 037c144cd417410deb8137c6f3fd271a34691742
server/platform/src/main/java/com/doumee/task/ScheduleTool.java
@@ -1,16 +1,21 @@
package com.doumee.task;
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.constants.Constants;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.DateUtil;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.core.wx.WxPayProperties;
import com.doumee.dao.business.model.Goodsorder;
import com.doumee.service.business.GoodsorderService;
import com.doumee.service.business.MemberRidesService;
import com.doumee.service.business.SitesService;
import com.doumee.service.business.WxBillService;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.service.business.*;
import com.doumee.service.system.SystemDictDataService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.util.ThreadContext;
import org.apache.shiro.web.mgt.DefaultWebSecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@@ -19,6 +24,7 @@
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
 * 定时任务
@@ -31,10 +37,13 @@
@Slf4j
public class ScheduleTool {
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
    @Autowired
    private RefundService refundService;
    @Autowired
    private SystemDictDataService systemDictDataService;
    @Autowired
    private WxBillService wxBillService;
@@ -51,8 +60,7 @@
    /**
     * @throws Exception
     */
    @Scheduled(cron = "0 0 11 * * ? ")
    public void syncStudent() throws Exception {
    public void getWxBill() throws Exception {
        //前一天的數據
        Date ydate = DateUtil.addDaysToDate(new Date(), -1);
        wxBillService.getWxBill(ydate);
@@ -94,4 +102,44 @@
        log.info("=====================结束 站点车辆满架率预警=======================");
    }
    @Autowired
    private WxPayProperties wxPayProperties;
    /**
     * 更新微信 ACCESS_TOKEN
     */
    @Scheduled(fixedDelay = 1000L * 60L * 90L)
    public void updAccessToken(){
        DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
        ThreadContext.bind(manager);
        String appId = wxPayProperties.getAppId();
        String appSecret = wxPayProperties.getAppSecret();
        if(wxPayProperties.getExistsSub() ==1){
            //如果是服务商支付,取子商户信息
             appId = StringUtils.trimToNull(wxPayProperties.getSubMchId());
            appSecret =StringUtils.trimToNull(wxPayProperties.getSubAppSecret());
        }
        //生成微信token
        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret;
        String response = HttpsUtil.doGet(url,null);
        JSONObject json = JSONObject.parseObject(response);
        SystemDictData systemDictData = systemDictDataBiz.queryByCode(Constants.MINI_PROGRAMME,Constants.ACCESS_TOKEN);
        if(!Objects.isNull(systemDictData)){
            systemDictData.setCode(json.getString("access_token"));
            systemDictData.setUpdateTime(new Date());
            systemDictDataService.updateById(systemDictData);
        }
    }
    /**
     * 更新微信 ACCESS_TOKEN
     */
    @Scheduled(fixedDelay = 1000L * 60L )
    public void autoCancelRefunOrder(){
        log.info("=====================开始 自動取消未推送退款状态的退款单状态=======================");
        refundService.autoCancelRefunOrder();;
        log.info("=====================结束 自動取消未推送退款状态的退款单状态=======================");
    }
}