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<User> all = userService.findAll();
|
for(User user:all){
|
Integer type2 = user.getType2();
|
if(type2!=null){
|
QueryWrapper<UserStatistic> wrapper = new QueryWrapper<>();
|
wrapper.eq("user_id",user.getId());
|
UserStatistic one = iUserStatisticService.getOne(wrapper);
|
if(one==null){
|
one = new UserStatistic();
|
one.setUserId(user.getId());
|
}
|
//司机
|
if(type2==0){
|
Integer max = iDrivingRecordService.maxByUserId(user.getId());
|
Integer min = iDrivingRecordService.minByUserId(user.getId());
|
if(max==null||min==null){
|
one.setSafeDriving(0);
|
one.setDriving(0);
|
}else{
|
one.setSafeDriving(max-min);
|
one.setDriving(max-min);
|
}
|
|
QueryWrapper<DrivingRecord> wrapper2 = new QueryWrapper<>();
|
wrapper2.eq("user_id",user.getId());
|
int count = iDrivingRecordService.count(wrapper2);
|
one.setOutCar(count);
|
|
}
|
//配送员
|
if(type2==1){
|
QueryWrapper<OrderTask> wrapper2 = new QueryWrapper<>();
|
wrapper2.eq("user_id",user.getId());
|
int count = iOrderTaskService.count(wrapper2);
|
wrapper2.ne("status",0);
|
int count2 = iOrderTaskService.count(wrapper2);
|
wrapper2.ne("level",0);
|
wrapper2.gt("level",2);
|
int count5 = iOrderTaskService.count(wrapper2);
|
if(count2==0){
|
one.setLikesRate(0);
|
}else{
|
int rate = (count5/count2)*100;
|
one.setLikesRate(rate);
|
}
|
|
one.setSends(count);
|
one.setSends2(count2);
|
|
QueryWrapper<Area> wrapper3 = new QueryWrapper<>();
|
wrapper3.eq("user_id",user.getId());
|
Area area = iAreaService.getOne(wrapper3);
|
|
if(area!=null){
|
QueryWrapper<Customer> wrapper4 = new QueryWrapper<>();
|
wrapper4.eq("area_id",area.getId());
|
int count3 = iCustomerService.count(wrapper4);
|
one.setService(count3);
|
}
|
}
|
|
iUserStatisticService.saveOrUpdate(one);
|
}
|
|
}
|
|
}
|
}
|