package com.hx.medical.task; import com.hx.common.BaseController; import com.hx.medical.config.GlobalExceptionHandler; import com.hx.medical.model.TimerServiceScore; import com.hx.medical.model.TimerShopScore; import com.hx.medical.service.TimerServiceScoreService; import com.hx.medical.service.TimerShopScoreService; import com.hx.mybatisTool.SqlSentence; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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-04-25 * @author JiaHe.Chen */ @Component public class ServiceScoreTask extends BaseController { //log4j日志 private static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class.getName()); @Resource private TimerServiceScoreService timerServiceScoreService; /**5秒钟执行1次 * 积分变化处理 * @throws InterruptedException */ @Scheduled(fixedRate = 5000) public void sendRedExecute() { //执行成功或者失败都保存一条日志 SqlSentence sqlSentence = new SqlSentence(); Map values = new HashMap<>(); sqlSentence.sqlSentence("SELECT * FROM timer_service_score",new HashMap<>()); List timerServiceScoreList = timerServiceScoreService.selectList(sqlSentence); for(TimerServiceScore timerServiceScore:timerServiceScoreList){ //先删除,没有删除到就跳过 if(timerServiceScoreService.deleteOne(timerServiceScore.getId()) != 1){ continue; } try{ timerServiceScoreService.scoreHandel(timerServiceScore); }catch (Exception e){ //错误保存 logger.error("店铺统计评分报错:",e); } } } }