xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/AddOilController.java
@@ -99,11 +99,11 @@ addOilList.add(new AddOil()); }); return new ResultUtil<List<AddOil>>().setData(addOilList); } @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "获取全部数据") public Result<List<AddOil>> getAll() { xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarController.java
@@ -24,8 +24,11 @@ import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author zhangzeli @@ -101,6 +104,27 @@ } return new ResultUtil<List<CarVo>>().setData(carVos); } @RequestMapping(value = "/getInfo", method = RequestMethod.GET) @ApiOperation(value = "通过车辆id获取") public Result<List<Car>> getInfo(String beginTime,String endTime) { QueryWrapper<Car> wrapper = new QueryWrapper<>(); wrapper.ge(beginTime!=null && beginTime!="","a.add_date",beginTime); wrapper.le(endTime!=null && endTime!="","a.add_date",endTime); wrapper.groupBy("car_no"); List<Car> list2 = iCarService.getCarInfo2(wrapper); List<Car> list = iCarService.getCarInfo(); for (Car car:list2){ for (Car car1:list){ if (car.getId().equals(car1.getId())){ car1.setAmount(car.getAmount()); car1.setMileage(car.getMileage()); car1.setMoney(car.getMoney()); continue; } } } return new ResultUtil<List<Car>>().setData(list); } @RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "分页获取") xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/entity/Car.java
@@ -83,4 +83,29 @@ @TableField(exist = false) private String areaName; @Transient @TableField(exist = false) private double mileage; @Transient @TableField(exist = false) private double money; @Transient @TableField(exist = false) private double amount; @Transient @TableField(exist = false) private double allMileage; @Transient @TableField(exist = false) private double allMoney; @Transient @TableField(exist = false) private double allAmount; } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/mapper/CarMapper.java
@@ -28,4 +28,19 @@ @Select("SELECT c.*,u.nickname,a.`name` AS area_name FROM t_car c LEFT JOIN t_user AS u ON c.user_id=u.id LEFT JOIN t_area AS a ON a.user_id=u.id") List<Car> getAll2(); @Select("SELECT\n" + "\tc.*,(SUM(amount)) AS allAmount,SUM(money) AS allMoney,(MAX(mileage)) AS allMileage\n" + "FROM\n" + "\tt_car c\n" + "LEFT JOIN t_add_oil a ON c.id = a.car_id GROUP BY car_no\n") List<Car> getCarInfo(); @Select("SELECT\n" + "\tc.*,(MAX(amount)-MIN(amount)) AS amount,SUM(money) AS money,(MAX(mileage)-MIN(mileage)) AS mileage\n" + "FROM\n" + "\tt_car c\n" + "LEFT JOIN t_add_oil a ON c.id = a.car_id ${ew.customSqlSegment}") List<Car> getCarInfo2(@Param(Constants.WRAPPER) QueryWrapper<Car> wrapper); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/service/ICarService.java
@@ -18,4 +18,8 @@ IPage<Car> page2(Page initMpPage, QueryWrapper<Car> wrapper); List<Car> getAll2(); List<Car> getCarInfo(); List<Car> getCarInfo2(QueryWrapper<Car> wrapper); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/serviceimpl/ICarServiceImpl.java
@@ -37,4 +37,12 @@ public List<Car> getAll2() { return carMapper.getAll2(); } public List<Car> getCarInfo(){ return carMapper.getCarInfo(); } public List<Car> getCarInfo2(QueryWrapper<Car> wrapper){ return carMapper.getCarInfo2(wrapper); } }