xuhy
2024-08-07 abcc4b90f2dfe74b668700631173a5b0b3e1496b
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.ruoyi.chargingPile.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.chargingPile.api.dto.TAccountingStrategyDTO;
import com.ruoyi.chargingPile.api.model.TAccountingStrategy;
import com.ruoyi.chargingPile.api.model.TAccountingStrategyDetail;
import com.ruoyi.chargingPile.api.model.TCarport;
import com.ruoyi.chargingPile.api.model.TVehicleRamp;
import com.ruoyi.chargingPile.api.query.TAccountingStrategyQuery;
import com.ruoyi.chargingPile.api.vo.TAccountingStrategyDetailVO;
import com.ruoyi.chargingPile.api.vo.TAccountingStrategyVO;
import com.ruoyi.chargingPile.service.TAccountingStrategyDetailService;
import com.ruoyi.chargingPile.service.TAccountingStrategyService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 * 计费策略 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-06
 */
@Api(tags = "计费策略")
@RestController
@RequestMapping("/t-accounting-strategy")
public class TAccountingStrategyController {
 
    private final TAccountingStrategyService accountingStrategyService;
    private final TAccountingStrategyDetailService accountingStrategyDetailService;
 
    @Autowired
    public TAccountingStrategyController(TAccountingStrategyService accountingStrategyService, TAccountingStrategyDetailService accountingStrategyDetailService) {
        this.accountingStrategyService = accountingStrategyService;
        this.accountingStrategyDetailService = accountingStrategyDetailService;
    }
    
    /**
     * 查询计费策略列表
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "查询计费策略分页列表")
    @PostMapping(value = "/pageList")
    public AjaxResult<PageInfo<TAccountingStrategyVO>> pageList(@RequestBody TAccountingStrategyQuery query) {
        return AjaxResult.ok(accountingStrategyService.pageList(query));
    }
 
    /**
     * 查询计费策略明细列表
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "查询计费策略明细列表")
    @GetMapping(value = "/queryAccountingStrategyDetailByStrategyId")
    public AjaxResult<List<TAccountingStrategyDetailVO>> queryAccountingStrategyDetailByStrategyId(@RequestParam Integer strategyId) {
        List<TAccountingStrategyDetailVO> list = accountingStrategyDetailService.queryAccountingStrategyDetailByStrategyId(strategyId);
        list.forEach(detail -> {
            detail.setTotalPrice(detail.getCostServiceCharge().add(detail.getElectrovalence()));
        });
        return AjaxResult.ok(list);
    }
 
    /**
     * 添加计费策略管理
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "添加计费策略")
    @PostMapping(value = "/add")
    public AjaxResult<Boolean> add(@RequestBody TAccountingStrategyDTO dto) {
        accountingStrategyService.save(dto);
        // 添加明细
        dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId()));
        // TODO 硬件 同步策略到充电桩
        return AjaxResult.ok(accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()));
    }
 
    /**
     * 修改计费策略
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "修改计费策略")
    @PostMapping(value = "/update")
    public AjaxResult<Boolean> update(@RequestBody TAccountingStrategyDTO dto) {
        // 删除计费策略明细信息
        accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class)
                .eq(TAccountingStrategyDetail::getAccountingStrategyId, dto.getId()));
        accountingStrategyService.updateById(dto);
        // 添加明细
        dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId()));
        // TODO 硬件 同步策略到充电桩
        return AjaxResult.ok(accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails()));
    }
 
    /**
     * 查看计费策略详情
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "查看计费策略详情")
    @GetMapping(value = "/getDetailById")
    public AjaxResult<TAccountingStrategy> getDetailById(@RequestParam Integer id) {
        return AjaxResult.ok(accountingStrategyService.getById(id));
    }
 
    /**
     * 删除计费策略
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "删除计费策略")
    @DeleteMapping(value = "/deleteById")
    public AjaxResult<Boolean> deleteById(@RequestParam Integer id) {
        // 刪除计费策略明细信息
        accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class)
                .eq(TAccountingStrategyDetail::getAccountingStrategyId, id));
        return AjaxResult.ok(accountingStrategyService.removeById(id));
    }
 
    /**
     * 批量删除计费策略
     */
    @ApiOperation(tags = {"后台-计费策略"},value = "批量删除计费策略")
    @DeleteMapping(value = "/deleteByIds")
    public AjaxResult<Boolean> deleteByIds(@RequestBody List<Integer> ids) {
        // 刪除计费策略明细信息
        accountingStrategyDetailService.remove(Wrappers.lambdaQuery(TAccountingStrategyDetail.class)
                .in(TAccountingStrategyDetail::getAccountingStrategyId, ids));
        return AjaxResult.ok(accountingStrategyService.removeByIds(ids));
    }
    
}