Pu Zhibing
2024-10-24 d2230c638cc57b7dc4fa4570e79cbc93107926b0
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package com.ruoyi.chargingPile.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.model.TChargingPile;
import com.ruoyi.chargingPile.api.model.TFaultMessage;
import com.ruoyi.chargingPile.api.query.TChargingGunQuery;
import com.ruoyi.chargingPile.api.vo.TChargingGunVO;
import com.ruoyi.chargingPile.dto.ChargeMonitoring;
import com.ruoyi.chargingPile.dto.ChargingGunCountMonitoring;
import com.ruoyi.chargingPile.dto.ChargingGunMonitoring;
import com.ruoyi.chargingPile.dto.GetChargingGunMonitoring;
import com.ruoyi.chargingPile.service.*;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.chargingPile.api.dto.PageChargingPileListDTO;
import com.ruoyi.chargingPile.api.model.TChargingPile;
import com.ruoyi.chargingPile.api.query.BatchSetAccountingStrategy;
import com.ruoyi.chargingPile.service.TChargingPileService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.chargingPile.api.query.PageChargingPileList;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.log.enums.OperatorType;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.other.api.domain.TVip;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 充电桩 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-06
 */
@Api(tags = "充电桩")
@RestController
@RequestMapping("/t-charging-pile")
public class TChargingPileController {
 
    private final TChargingPileService chargingPileService;
    private final TChargingGunService chargingGunService;
    
    @Resource
    private RedisService redisService;
    
    @Resource
    private TFaultMessageService faultMessageService;
 
 
    @Autowired
    public TChargingPileController(TChargingPileService chargingPileService, TChargingGunService chargingGunService) {
        this.chargingPileService = chargingPileService;
        this.chargingGunService = chargingGunService;
    }
 
    /**
     * 查询充电桩列表
     */
    @ApiOperation(tags = {"小程序-充电桩"},value = "通过站点id查询充电桩列表")
    @GetMapping(value = "/list")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "siteId", value = "站点id")
    })
    public AjaxResult<List<TChargingPile>> list(@RequestParam("siteId") Integer siteId) {
        return AjaxResult.ok(chargingPileService.list(Wrappers.lambdaQuery(TChargingPile.class)
                .eq(TChargingPile::getSiteId,siteId)));
    }
    /**
     * 查询充电桩列表
     */
    @ApiOperation(tags = {"通过充电桩id 查询充电枪列表"},value = "通过充电桩id 查询充电枪列表")
    @PostMapping(value = "/pileList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pileId", value = "充电桩id")
    })
    public AjaxResult<List<TChargingGun>> pileList(@RequestParam("pileId") Integer pileId) {
        return AjaxResult.ok(chargingGunService.list(Wrappers.lambdaQuery(TChargingGun.class)
                .eq(TChargingGun::getChargingPileId,pileId)));
    }
    /**
     * 管理后台-通过站点id获取充电桩列表 不分页
     */
    @ApiOperation(value = "管理后台-通过站点id获取充电桩列表 不分页")
    @PostMapping(value = "/getChargingPileBySiteId")
    public R<List<TChargingPile>> getChargingPileBySiteId(@RequestParam("siteId") Integer siteId) {
        return R.ok(chargingPileService.list(Wrappers.lambdaQuery(TChargingPile.class)
                .eq(TChargingPile::getSiteId,siteId)));
    }
 
    @PostMapping(value = "/getChargingPileBySiteIds")
    public R<List<TChargingPile>> getChargingPileBySiteIds(@RequestParam("siteIds") List<Integer> siteIds) {
        return R.ok(chargingPileService.list(Wrappers.lambdaQuery(TChargingPile.class)
                .in(!siteIds.isEmpty(),TChargingPile::getSiteId,siteIds)));
    }
    
    @ResponseBody
    @GetMapping("/pageChargingPileList")
    @ApiOperation(value = "获取充电桩列表数据", tags = {"管理后台-充电桩信息"})
    public AjaxResult<PageInfo<PageChargingPileListDTO>> pageChargingPileList(PageChargingPileList page){
        PageInfo<PageChargingPileListDTO> list = chargingPileService.pageChargingPileList(page);
        return AjaxResult.success(list);
    }
    
    @ResponseBody
    @Log(title = "【充电桩信息】添加充电桩数据", businessType = BusinessType.INSERT,operatorType = OperatorType.MANAGE)
    @PostMapping("/addChargingPile")
    @ApiOperation(value = "添加充电桩数据", tags = {"管理后台-充电桩信息"})
    public AjaxResult addChargingPile(@RequestBody TChargingPile chargingPile){
        return chargingPileService.addChargingPile(chargingPile);
    }
    
    
    @ResponseBody
    @GetMapping("/getChargingPile/{id}")
    @ApiOperation(value = "获取充电桩详情数据", tags = {"管理后台-充电桩信息"})
    public AjaxResult<TChargingPile> getChargingPile(@PathVariable Integer id){
        TChargingPile chargingPile = chargingPileService.getChargingPile(id);
        return AjaxResult.success(chargingPile);
    }
    
    
    @ResponseBody
    @Log(title = "【充电桩信息】编辑充电桩数据", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE)
    @PostMapping("/editChargingPile")
    @ApiOperation(value = "编辑充电桩数据", tags = {"管理后台-充电桩信息"})
    public AjaxResult editChargingPile(@RequestBody TChargingPile chargingPile){
        return chargingPileService.editChargingPile(chargingPile);
    }
    
    
    
    @ResponseBody
    @DeleteMapping("/delChargingPile")
    @Log(title = "【充电桩信息】删除充电桩", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    @ApiOperation(value = "删除充电桩", tags = {"管理后台-充电桩信息"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "充电桩id", name = "id", dataTypeClass = Integer.class, required = true)
    })
    public AjaxResult delChargingPile(@RequestParam("id") Integer[] id){
        return chargingPileService.delChargingPile(id);
    }
    
    
    @ResponseBody
    @Log(title = "【充电桩信息】批量设置计费策略", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE)
    @PostMapping("/batchSetAccountingStrategy")
    @ApiOperation(value = "批量设置计费策略", tags = {"管理后台-充电桩信息"})
    public AjaxResult batchSetAccountingStrategy(@RequestBody BatchSetAccountingStrategy setAccountingStrategy){
        chargingPileService.batchSetAccountingStrategy(setAccountingStrategy);
        return AjaxResult.success();
    }
    
    
    @ResponseBody
    @GetMapping("/chargeMonitoring/{siteId}")
    @ApiOperation(value = "获取充电设施监控数据", tags = {"管理后台-充电设备监控"})
    public AjaxResult<ChargeMonitoring> chargeMonitoring(@PathVariable Integer siteId){
        ChargeMonitoring chargeMonitoring = chargingPileService.chargeMonitoring(siteId);
        return AjaxResult.success(chargeMonitoring);
    }
 
 
    @ResponseBody
    @GetMapping("/getChargingGunCountMonitoring/{siteId}")
    @ApiOperation(value = "获取充电枪各种状态汇总监控数据", tags = {"管理后台-充电设备监控"})
    public AjaxResult<ChargingGunCountMonitoring> getChargingGunCountMonitoring(@PathVariable Integer siteId){
        ChargingGunCountMonitoring chargingGunCountMonitoring = chargingPileService.getChargingGunCountMonitoring(siteId);
        return AjaxResult.success(chargingGunCountMonitoring);
    }
    
    
    @ResponseBody
    @GetMapping("/getChargingGunMonitoring")
    @ApiOperation(value = "获取充电枪监控数据", tags = {"管理后台-充电设备监控"})
    public AjaxResult<PageInfo<ChargingGunMonitoring>> getChargingGunMonitoring(GetChargingGunMonitoring query){
        PageInfo<ChargingGunMonitoring> chargingGunMonitoring = chargingPileService.getChargingGunMonitoring(query);
        return AjaxResult.success(chargingGunMonitoring);
    }
    
    
    /**
     * 根据id获取充电桩信息
     * @param id
     * @return
     */
    @ResponseBody
    @PostMapping("/getChargingPileById/{id}")
    public R<TChargingPile> getChargingPileById(@PathVariable Integer id){
        TChargingPile chargingPile = chargingPileService.getById(id);
        return R.ok(chargingPile);
    }
    
    
    /**
     * 更新充电桩状态
     * @param code
     * @param status
     */
    @ResponseBody
    @PostMapping("/updateChargingPileStatus")
    public void updateChargingPileStatus(@RequestParam("code") String code, @RequestParam("status") Integer status){
        TChargingPile chargingPile = chargingPileService.getOne(new LambdaQueryWrapper<TChargingPile>()
                .eq(TChargingPile::getCode, code).eq(TChargingPile::getDelFlag, 0));
        if(null != chargingPile){
            if(chargingPile.getStatus() == 1){
                TFaultMessage faultMessage = new TFaultMessage();
                faultMessage.setSiteId(chargingPile.getSiteId());
                faultMessage.setChargingPileId(chargingPile.getId());
                faultMessage.setStatus(1);
                faultMessage.setDownTime(LocalDateTime.now());
                faultMessage.setCreateTime(LocalDateTime.now());
                faultMessage.setDelFlag(false);
                faultMessage.setContent("设备离线");
                faultMessageService.save(faultMessage);
                
                chargingPile.setStatus(0 == status ? 1 : 3);
                chargingPileService.updateById(chargingPile);
            }
            if(chargingPile.getStatus() != 1 && 0 == status){
                TFaultMessage one = faultMessageService.getOne(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingPileId, chargingPile.getId()).isNull(TFaultMessage::getEndTime));
                if(null != one){
                    one.setEndTime(LocalDateTime.now());
                    faultMessageService.updateById(one);
                }
            }
            if(0 == status){
                redisService.getCacheMap("charging_pile_online").put(code, System.currentTimeMillis());
            }
        }
    }
}