hsy
2026-08-28 a8e4132c3e2e9c3b3fcb0360901b35571b6464ea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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));
    }
}