package com.hx.medical.task; import com.hx.common.BaseController; import com.hx.medical.model.TimerMovieQuery; import com.hx.medical.model.TimerMovieRefund; import com.hx.medical.service.TimerMovieQueryService; import com.hx.medical.service.TimerMovieRefundService; import com.hx.mybatisTool.SqlSentence; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 电影订单退款 * @date 2021-07-15 * @author JiaHe.Chen */ @Component public class TimerMovieRefundTask extends BaseController { @Resource private TimerMovieRefundService timerMovieRefundService; /**每隔一分钟执行一次 * 订单状态处理 * @throws InterruptedException */ @Scheduled(cron = "0 */1 * * * ?") public void sendRedExecute() { //执行成功或者失败都保存一条日志 SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); values.put("type",TimerMovieQuery.TYPE_MOVICE_ORDER); sqlSentence.sqlSentence("SELECT * FROM timer_movie_refund WHERE type = #{m.type}",values); List timerMovieRefundLsit = timerMovieRefundService.selectList(sqlSentence); for(TimerMovieRefund timerMovieRefund:timerMovieRefundLsit){ //先删除,没有删除到就跳过 if(timerMovieRefundService.deleteOne(timerMovieRefund.getId()) != 1){ continue; } try{ timerMovieRefundService.refundHandle(timerMovieRefund); }catch (Exception e){ //错误保存 timerMovieRefundService.refundHandleFail(timerMovieRefund,e.getMessage()); } } } }