| | |
| | | import cn.exrick.xboot.core.common.utils.ResultUtil; |
| | | import cn.exrick.xboot.core.common.vo.PageVo; |
| | | import cn.exrick.xboot.core.common.vo.Result; |
| | | import cn.exrick.xboot.core.entity.User; |
| | | import cn.exrick.xboot.your.entity.Car; |
| | | import cn.exrick.xboot.your.entity.UserStatistic; |
| | | import cn.exrick.xboot.your.service.ICarService; |
| | | import cn.exrick.xboot.your.service.IUserStatisticService; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | @Autowired |
| | | private IUserStatisticService iUserStatisticService; |
| | | |
| | | @Autowired |
| | | private ICarService iCarService; |
| | | |
| | | @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) |
| | | @ApiOperation(value = "通过id获取") |
| | | public Result<UserStatistic> get(@PathVariable String id) { |
| | |
| | | return new ResultUtil<UserStatistic>().setData(userStatistic); |
| | | } |
| | | |
| | | @RequestMapping(value = "/getAllByUserId", method = RequestMethod.GET) |
| | | @ApiOperation(value = "通过用户id获取统计信息") |
| | | public Result<UserStatistic> getStatisticByUserId(String userId,int type) { |
| | | UserStatistic userStatistic0 = getById(userId); |
| | | String otherId = getOtherIdFromCar(userId,type); |
| | | UserStatistic userStatistic1 = getById(otherId); |
| | | if(type==0){//驾驶员 |
| | | userStatistic0.setSends(userStatistic1.getSends()); |
| | | userStatistic0.setService(userStatistic1.getService()); |
| | | userStatistic0.setSends2(userStatistic1.getSends2()); |
| | | userStatistic0.setAbnormalOpen(userStatistic1.getAbnormalOpen()); |
| | | userStatistic0.setLikesRate(userStatistic1.getLikesRate()); |
| | | }else{//配送员 |
| | | userStatistic0.setSafeDriving(userStatistic1.getSafeDriving()); |
| | | userStatistic0.setOutCar(userStatistic1.getOutCar()); |
| | | userStatistic0.setDriving(userStatistic1.getDriving()); |
| | | userStatistic0.setFatigueDriving(userStatistic1.getFatigueDriving()); |
| | | userStatistic0.setSmoking(userStatistic1.getSmoking()); |
| | | userStatistic0.setNoBelt(userStatistic1.getNoBelt()); |
| | | userStatistic0.setLikes(userStatistic1.getLikes()); |
| | | } |
| | | return new ResultUtil<UserStatistic>().setData(userStatistic0); |
| | | } |
| | | |
| | | public UserStatistic getById(String userId){ |
| | | QueryWrapper<UserStatistic> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("user_id",userId); |
| | | UserStatistic userStatistic = iUserStatisticService.getOne(wrapper); |
| | | if(userStatistic==null){ |
| | | userStatistic = new UserStatistic(); |
| | | } |
| | | return userStatistic; |
| | | } |
| | | |
| | | public String getOtherIdFromCar(String userId,int type){ |
| | | QueryWrapper<Car> wrapper = new QueryWrapper<>(); |
| | | if(type==0){ |
| | | wrapper.eq("user_id",userId); |
| | | Car myCar = iCarService.getOne(wrapper); |
| | | if(myCar!=null){ |
| | | return myCar.getFollowUserId(); |
| | | } |
| | | }else if(type==1){ |
| | | wrapper.eq("follow_user_id",userId); |
| | | Car myCar = iCarService.getOne(wrapper); |
| | | if(myCar!=null){ |
| | | return myCar.getUserId(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @RequestMapping(value = "/getAll", method = RequestMethod.GET) |
| | | @ApiOperation(value = "获取全部数据") |
| | | public Result<List<UserStatistic>> getAll() { |