xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/OrderDetailController.java
@@ -41,9 +41,11 @@ @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "获取全部数据") public Result<List<OrderDetail>> getAll() { public Result<List<OrderDetail>> getAll(String orderId) { List<OrderDetail> list = iOrderDetailService.list(); QueryWrapper<OrderDetail> wrapper = new QueryWrapper<>(); wrapper.eq("order_id",orderId); List<OrderDetail> list = iOrderDetailService.list(wrapper); return new ResultUtil<List<OrderDetail>>().setData(list); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/mapper/DrivingRecordMapper.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import cn.exrick.xboot.your.entity.DrivingRecord; import org.apache.ibatis.annotations.Select; import java.util.List; @@ -11,4 +12,9 @@ */ public interface DrivingRecordMapper extends BaseMapper<DrivingRecord> { @Select("select max(mileage) from t_driving_record where user_id=#{userId}") Integer maxByUserId(String userId); @Select("select min(mileage) from t_driving_record where user_id=#{userId}") Integer minByUserId(String userId); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/CarScheduleImpl.java
New file @@ -0,0 +1,14 @@ package cn.exrick.xboot.your.schedulings; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.io.IOException; @Component public class CarScheduleImpl { @Scheduled(cron="0 0 * * * ?")//每小时执行一次 public void execute() throws IOException { } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticScheduleImpl.java
New file @@ -0,0 +1,89 @@ 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(); } //司机 if(type2==0){ Integer max = iDrivingRecordService.maxByUserId(user.getId()); Integer min = iDrivingRecordService.minByUserId(user.getId()); 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); one.setSends(count); one.setSends2(count2); QueryWrapper<Area> wrapper3 = new QueryWrapper<>(); wrapper3.eq("user_id",user.getId()); Area area = iAreaService.getOne(wrapper3); QueryWrapper<Customer> wrapper4 = new QueryWrapper<>(); wrapper4.eq("area_id",area.getId()); int count3 = iCustomerService.count(wrapper4); one.setService(count3); } iUserStatisticService.saveOrUpdate(one); } } } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/service/IDrivingRecordService.java
@@ -11,4 +11,7 @@ */ public interface IDrivingRecordService extends IService<DrivingRecord> { Integer maxByUserId(String id); Integer minByUserId(String id); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/serviceimpl/IDrivingRecordServiceImpl.java
@@ -23,4 +23,14 @@ @Autowired private DrivingRecordMapper drivingRecordMapper; @Override public Integer maxByUserId(String userId) { return drivingRecordMapper.maxByUserId(userId); } @Override public Integer minByUserId(String userId) { return drivingRecordMapper.minByUserId(userId); } }