From e0c23133df3f7034ab49205e26bd9cd07df3462e Mon Sep 17 00:00:00 2001 From: wang-hao-jie <1550036656@qq.com> Date: 星期四, 25 十一月 2021 13:44:23 +0800 Subject: [PATCH] 违章记录 --- xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java | 70 +++++++++++++++++++++++++++++++++-- 1 files changed, 66 insertions(+), 4 deletions(-) diff --git a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java index 6737958..e261f9d 100644 --- a/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java +++ b/xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java @@ -4,8 +4,14 @@ 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.your.entity.AddOil; import cn.exrick.xboot.your.entity.Car; +import cn.exrick.xboot.your.entity.DrivingRecord; +import cn.exrick.xboot.your.entity.Suggest; +import cn.exrick.xboot.your.service.IAddOilService; import cn.exrick.xboot.your.service.ICarService; +import cn.exrick.xboot.your.service.IDrivingRecordService; +import cn.exrick.xboot.your.vo.CarVo; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -18,6 +24,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; /** @@ -32,6 +39,10 @@ @Autowired private ICarService iCarService; + @Autowired + private IAddOilService iAddOilService; + @Autowired + private IDrivingRecordService iDrivingRecordService; @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) @ApiOperation(value = "閫氳繃id鑾峰彇") @@ -41,12 +52,54 @@ return new ResultUtil<Car>().setData(car); } - @RequestMapping(value = "/getAll", method = RequestMethod.GET) + @RequestMapping(value = "/getAllCar", method = RequestMethod.GET) @ApiOperation(value = "鑾峰彇鍏ㄩ儴鏁版嵁") - public Result<List<Car>> getAll() { + public Result<List<Car>> getAllCar() { List<Car> list = iCarService.list(); return new ResultUtil<List<Car>>().setData(list); + } + + @RequestMapping(value = "/getAll", method = RequestMethod.GET) + @ApiOperation(value = "鑾峰彇鍏ㄩ儴鏁版嵁") + public Result<List<CarVo>> getAll(String beginTime,String endTime) { + List<CarVo> carVos = new ArrayList<>(); + List<Car> list = iCarService.getAll2(); + for (Car car:list){ + CarVo carVo = new CarVo(); + //鍔犳补淇℃伅 + QueryWrapper<AddOil> queryWrapper = new QueryWrapper<>(); + queryWrapper.select("sum(money) as money,sum(amount) as amount").eq("car_id", car.getId()); + + + //浠庡彂杞︽椂闂磋椹堕噷绋嬪垽鏂垵濮嬮噷绋� + QueryWrapper<DrivingRecord> wrapper = new QueryWrapper<>(); + wrapper.select("min(mileage) as beginMileage,max(mileage) as endMileage").eq("car_id",car.getId()); + + wrapper.ge(beginTime!=null && beginTime!="","out_time",beginTime); + queryWrapper.ge(beginTime!=null && beginTime!="","add_date",beginTime); + + wrapper.le(endTime!=null && endTime!="","in_time",endTime); + queryWrapper.le(endTime!=null && endTime!="","add_date",beginTime); + + DrivingRecord drivingRecord = iDrivingRecordService.getOne(wrapper); + + AddOil addOil = iAddOilService.getOne(queryWrapper); + + if (addOil!=null){ + carVo.setMoney(addOil.getMoney()); + carVo.setOilWear(addOil.getAmount()); + } + + if (drivingRecord!=null) { + carVo.setBeginMileage(drivingRecord.getBeginMileage()); + carVo.setEndMileage(drivingRecord.getEndMileage()); + } + + carVo.setCar(car); + carVos.add(carVo); + } + return new ResultUtil<List<CarVo>>().setData(carVos); } @RequestMapping(value = "/getByPage", method = RequestMethod.GET) @@ -54,9 +107,9 @@ public Result<IPage<Car>> getByPage(String carNo,PageVo page) { QueryWrapper<Car> wrapper = new QueryWrapper<>(); if(!StrUtil.isEmpty(carNo)){ - wrapper.like("car_no","%"+carNo+"%"); + wrapper.like("a.car_no","%"+carNo+"%"); } - IPage<Car> data = iCarService.page(PageUtil.initMpPage(page),wrapper); + IPage<Car> data = iCarService.page2(PageUtil.initMpPage(page),wrapper); return new ResultUtil<IPage<Car>>().setData(data); } @@ -70,6 +123,15 @@ return new ResultUtil<Car>().setErrorMsg("鎿嶄綔澶辫触"); } + @RequestMapping(value = "/bindCar", method = RequestMethod.POST) + @ApiOperation(value = "缁戝畾杞﹁締浜哄憳") + public Result<Car> bindCar(String carId,String userId) { + Car car = iCarService.getById(carId); + car.setUserId(userId); + iCarService.saveOrUpdate(car); + return ResultUtil.success("缁戝畾鎴愬姛"); + } + @RequestMapping(value = "/delByIds", method = RequestMethod.POST) @ApiOperation(value = "鎵归噺閫氳繃id鍒犻櫎") public Result<Object> delAllByIds(@RequestParam String[] ids) { -- Gitblit v1.9.1