package com.ruoyi.vehicle.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
import com.ruoyi.vehicle.pojo.VehicleCost;
|
import com.ruoyi.vehicle.service.VehicleCostService;
|
import com.ruoyi.vehicle.mapper.VehicleCostMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.util.StringUtils;
|
|
@RestController
|
@RequestMapping("/vehicle/cost")
|
public class VehicleCostController {
|
@Autowired
|
private VehicleCostService vehicleCostService;
|
|
@Autowired
|
private VehicleCostMapper vehicleCostMapper;
|
|
@GetMapping("/listPage")
|
public AjaxResult listPage(Page<VehicleCost> page, VehicleCost query) {
|
LambdaQueryWrapper<VehicleCost> wrapper = new LambdaQueryWrapper<>();
|
if (query.getVehicleId() != null) {
|
wrapper.eq(VehicleCost::getVehicleId, query.getVehicleId());
|
}
|
if (StringUtils.hasText(query.getCostType())) {
|
wrapper.eq(VehicleCost::getCostType, query.getCostType());
|
}
|
wrapper.orderByDesc(VehicleCost::getCostDate);
|
IPage<VehicleCost> pageInfo = vehicleCostService.page(page, wrapper);
|
return AjaxResult.success(pageInfo);
|
}
|
|
@GetMapping("/summaryByMonth")
|
public AjaxResult summaryByMonth() {
|
return AjaxResult.success(vehicleCostMapper.summaryByMonth());
|
}
|
|
@GetMapping("/summaryByVehicle")
|
public AjaxResult summaryByVehicle() {
|
return AjaxResult.success(vehicleCostMapper.summaryByVehicle());
|
}
|
|
@PostMapping
|
public AjaxResult add(@RequestBody VehicleCost entity) {
|
return AjaxResult.success(vehicleCostService.save(entity));
|
}
|
|
@PutMapping
|
public AjaxResult edit(@RequestBody VehicleCost entity) {
|
return AjaxResult.success(vehicleCostService.updateById(entity));
|
}
|
|
@DeleteMapping("/{id}")
|
public AjaxResult remove(@PathVariable Long id) {
|
return AjaxResult.success(vehicleCostService.removeById(id));
|
}
|
}
|