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.dto.PageChargingPileListDTO;
|
import com.ruoyi.chargingPile.api.model.TChargingGun;
|
import com.ruoyi.chargingPile.api.model.TChargingPile;
|
import com.ruoyi.chargingPile.api.query.BatchSetAccountingStrategy;
|
import com.ruoyi.chargingPile.api.query.PageChargingPileList;
|
import com.ruoyi.chargingPile.api.vo.UpdateChargingPileStatusVo;
|
import com.ruoyi.chargingPile.service.TChargingGunService;
|
import com.ruoyi.chargingPile.service.TChargingPileService;
|
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.common.log.annotation.Log;
|
import com.ruoyi.common.log.enums.BusinessType;
|
import com.ruoyi.common.log.enums.OperatorType;
|
import com.ruoyi.common.security.annotation.Logical;
|
import com.ruoyi.common.security.service.TokenService;
|
import com.ruoyi.system.api.domain.SysUser;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* <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;
|
private final TokenService tokenService;
|
|
@Resource
|
private RedisTemplate redisTemplate;
|
|
@Autowired
|
public TChargingPileController(TChargingPileService chargingPileService, TChargingGunService chargingGunService, TokenService tokenService) {
|
this.chargingPileService = chargingPileService;
|
this.chargingGunService = chargingGunService;
|
this.tokenService = tokenService;
|
}
|
|
/**
|
* 查询充电桩列表
|
*/
|
@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){
|
SysUser sysUser = tokenService.getLoginUser().getSysUser();
|
PageInfo<PageChargingPileListDTO> list = chargingPileService.pageChargingPileList(page,sysUser);
|
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();
|
}
|
|
|
/**
|
* 根据id获取充电桩信息
|
* @param id
|
* @return
|
*/
|
@ResponseBody
|
@PostMapping("/getChargingPileById/{id}")
|
public R<TChargingPile> getChargingPileById(@PathVariable("id") Integer id){
|
TChargingPile chargingPile = chargingPileService.getById(id);
|
return R.ok(chargingPile);
|
}
|
|
|
/**
|
* 更新充电桩状态
|
*/
|
@ResponseBody
|
@PostMapping("/updateChargingPileStatus")
|
public void updateChargingPileStatus(@RequestBody UpdateChargingPileStatusVo vo){
|
String pile_code = vo.getPile_code();
|
String gun_code = vo.getGun_code();
|
//0:正常,1:故障,2=插枪
|
Integer status = vo.getStatus();
|
Long time = (Long) redisTemplate.opsForHash().get("charging_gun_online", (pile_code + gun_code));
|
//小于1分钟才处理数据,防止频繁查询数据
|
if(null != time && (System.currentTimeMillis() - time) < 30000){
|
return;
|
}
|
TChargingGun tChargingGun = chargingGunService.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getFullNumber, (pile_code + gun_code)).eq(TChargingGun::getDelFlag, 0));
|
if(null != tChargingGun){
|
redisTemplate.opsForHash().put("charging_gun_online", tChargingGun.getFullNumber(), System.currentTimeMillis());
|
|
TChargingPile chargingPile = chargingPileService.getById(tChargingGun.getChargingPileId());
|
//枪处于离线或者故障,返回状态为正常,则修改其状态
|
if(0 == status && tChargingGun.getStatus() != 2){
|
TChargingGun tChargingGun1 = new TChargingGun();
|
tChargingGun1.setId(tChargingGun.getId());
|
tChargingGun1.setStatus(2);
|
chargingGunService.updateById(tChargingGun1);
|
|
if(chargingPile.getStatus() != 1){
|
TChargingPile chargingPile1 = new TChargingPile();
|
chargingPile1.setId(chargingPile.getId());
|
chargingPile1.setStatus(1);
|
chargingPileService.updateById(chargingPile1);
|
}
|
}
|
//枪处于正常,返回状态为故障,则修改其状态
|
if(1 == status && tChargingGun.getStatus() != 1 && tChargingGun.getStatus() != 7){
|
TChargingGun tChargingGun1 = new TChargingGun();
|
tChargingGun1.setId(tChargingGun.getId());
|
tChargingGun1.setStatus(7);
|
chargingGunService.updateById(tChargingGun1);
|
|
//桩处于正常,桩所属的枪都处于非正常,修改桩状态为异常
|
List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, chargingPile.getId()).eq(TChargingGun::getDelFlag, 0));
|
int size = list.stream().filter(s -> s.getStatus() == 1 || s.getStatus() == 7).collect(Collectors.toList()).size();
|
if(chargingPile.getStatus() == 1 && list.size() == size){
|
TChargingPile chargingPile1 = new TChargingPile();
|
chargingPile1.setId(chargingPile.getId());
|
chargingPile1.setStatus(3);
|
chargingPileService.updateById(chargingPile1);
|
}
|
}
|
if(2 == status){
|
}
|
}
|
}
|
}
|