package cn.exrick.xboot.your.schedulings; import cn.exrick.xboot.core.entity.User; import cn.exrick.xboot.core.service.UserService; import cn.exrick.xboot.your.entity.*; import cn.exrick.xboot.your.service.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.elasticsearch.cluster.ClusterState; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.IOException; import java.util.List; @Component public class StatisticScheduleImpl { @Autowired private IUserStatisticService iUserStatisticService; @Autowired private UserService userService; @Autowired private IDrivingRecordService iDrivingRecordService; @Autowired private IOrderTaskService iOrderTaskService; @Autowired private IAreaService iAreaService; @Autowired private ICustomerService iCustomerService; @Scheduled(cron="0 0 * * * ?")//每晚凌晨1点执行 public void execute() throws IOException { List all = userService.findAll(); for(User user:all){ Integer type2 = user.getType2(); if(type2!=null){ QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("user_id",user.getId()); UserStatistic one = iUserStatisticService.getOne(wrapper); if(one==null){ one = new UserStatistic(); } //司机 if(type2==0){ Integer max = iDrivingRecordService.maxByUserId(user.getId()); Integer min = iDrivingRecordService.minByUserId(user.getId()); one.setSafeDriving(max-min); one.setDriving(max-min); QueryWrapper wrapper2 = new QueryWrapper<>(); wrapper2.eq("user_id",user.getId()); int count = iDrivingRecordService.count(wrapper2); one.setOutCar(count); } //配送员 if(type2==1){ QueryWrapper wrapper2 = new QueryWrapper<>(); wrapper2.eq("user_id",user.getId()); int count = iOrderTaskService.count(wrapper2); wrapper2.ne("status",0); int count2 = iOrderTaskService.count(wrapper2); one.setSends(count); one.setSends2(count2); QueryWrapper wrapper3 = new QueryWrapper<>(); wrapper3.eq("user_id",user.getId()); Area area = iAreaService.getOne(wrapper3); QueryWrapper wrapper4 = new QueryWrapper<>(); wrapper4.eq("area_id",area.getId()); int count3 = iCustomerService.count(wrapper4); one.setService(count3); } iUserStatisticService.saveOrUpdate(one); } } } }