无关风月
2024-08-10 7f288c7515fa04cf83fadc3506317d08fb099630
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.ruoyi.chargingPile.controller;
 
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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 com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.log.enums.OperatorType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
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;
 
    @Resource
    private TokenService tokenService;
 
    @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.getElectrovalence().add(detail.getElectrovalence()));
        });
        return AjaxResult.ok(list);
    }
 
    /**
     * 添加计费策略管理
     */
    @Log(title = "添加计费策略", businessType = BusinessType.INSERT,operatorType = OperatorType.MANAGE)
    @ApiOperation(tags = {"后台-计费策略", "管理后台-站点管理"},value = "添加计费策略")
    @PostMapping(value = "/add")
    public AjaxResult<Integer> add(@RequestBody TAccountingStrategyDTO dto) {
        accountingStrategyService.save(dto);
        // 添加明细
        dto.getAccountingStrategyDetails().forEach(detail -> detail.setAccountingStrategyId(dto.getId()));
        accountingStrategyDetailService.saveBatch(dto.getAccountingStrategyDetails());
        // TODO 硬件 同步策略到充电桩
        return AjaxResult.ok(dto.getId());
    }
 
    /**
     * 修改计费策略
     */
    @Log(title = "修改计费策略", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE)
    @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));
    }
 
    /**
     * 删除计费策略
     */
    @Log(title = "删除计费策略", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    @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));
    }
 
    /**
     * 批量删除计费策略
     */
    @Log(title = "批量删除计费策略", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    @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));
    }
    
    
    @ApiOperation(tags = {"管理后台-站点管理"},value = "获取平台添加的计费策略")
    @DeleteMapping(value = "/getPlatformAccountingStrategy")
    public AjaxResult<List<TAccountingStrategyVO>> getPlatformAccountingStrategy(){
        List<TAccountingStrategyVO> list = accountingStrategyService.getPlatformAccountingStrategy();
        return AjaxResult.success(list);
    }
 
 
 
    @ApiOperation(tags = {"后台-申请表单-计费模板审核"},value = "查询计费审核分页列表")
    @PostMapping(value = "/auth/pageList")
    public AjaxResult authPageList(@RequestBody TAccountingStrategyQuery query) {
        Long userid = tokenService.getLoginUser().getUserid();
        Page<TAccountingStrategy> page = accountingStrategyService.lambdaQuery()
                .in(TAccountingStrategy::getFirstUserId, userid)
                .or().in(TAccountingStrategy::getTwoUserId, userid)
                .page(Page.of(query.getPageCurr(), query.getPageSize()));
 
        List<TAccountingStrategy> records = page.getRecords();
        for (TAccountingStrategy record : records) {
            if (record.getAuditStatus()==2){
                if (record.getFirstUserId().equals(userid)){
                    record.setAuditStatus(3);
                }
 
            }
 
        }
 
 
        return AjaxResult.ok(accountingStrategyService.pageList(query));
    }
 
}