package com.ruoyi.chargingPile.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.account.api.feignClient.AppUserCarClient;
|
import com.ruoyi.account.api.model.TAppUserCar;
|
import com.ruoyi.chargingPile.api.dto.PageChargingPileListDTO;
|
import com.ruoyi.chargingPile.api.model.Site;
|
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.BatchSetAccountingStrategy;
|
import com.ruoyi.chargingPile.api.query.PageChargingPileList;
|
import com.ruoyi.chargingPile.api.vo.TChargingGunVO;
|
import com.ruoyi.chargingPile.api.vo.TChargingPileVO;
|
import com.ruoyi.chargingPile.domain.SiteMenu;
|
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.mapper.TChargingPileMapper;
|
import com.ruoyi.chargingPile.service.*;
|
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.common.core.web.page.PageInfo;
|
import com.ruoyi.common.redis.service.RedisService;
|
import com.ruoyi.common.security.utils.SecurityUtils;
|
import com.ruoyi.integration.api.feignClient.IntegrationClient;
|
import com.ruoyi.integration.api.feignClient.IotInterfaceClient;
|
import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient;
|
import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData;
|
import com.ruoyi.integration.api.vo.AddDevice;
|
import com.ruoyi.integration.api.vo.AddDeviceResp;
|
import com.ruoyi.integration.api.vo.DeleteDeviceResp;
|
import com.ruoyi.order.api.feignClient.ChargingOrderAccountingStrategyClient;
|
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
|
import com.ruoyi.order.api.model.TChargingOrder;
|
import com.ruoyi.other.api.feignClient.RoleSiteClient;
|
import com.ruoyi.other.api.feignClient.UserSiteClient;
|
import com.ruoyi.system.api.domain.SysUser;
|
import com.ruoyi.system.api.feignClient.SysUserClient;
|
import com.ruoyi.system.api.feignClient.SysUserRoleClient;
|
import com.ruoyi.system.api.model.SysUserRoleVo;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.math.MathContext;
|
import java.math.RoundingMode;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
import java.util.stream.Stream;
|
|
/**
|
* <p>
|
* 充电桩 服务实现类
|
* </p>
|
*
|
* @author xiaochen
|
* @since 2024-08-06
|
*/
|
@Service
|
public class TChargingPileServiceImpl extends ServiceImpl<TChargingPileMapper, TChargingPile> implements TChargingPileService {
|
|
@Resource
|
private TChargingGunService chargingGunService;
|
|
@Resource
|
private SysUserClient sysUserClient;
|
|
@Resource
|
private IPartnerService partnerService;
|
|
@Resource
|
private UserSiteClient userSiteClient;
|
|
@Resource
|
private RoleSiteClient roleSiteClient;
|
|
@Resource
|
private ISiteService siteService;
|
|
@Resource
|
private ChargingOrderAccountingStrategyClient chargingOrderAccountingStrategyClient;
|
|
@Resource
|
private ChargingOrderClient chargingOrderClient;
|
|
@Resource
|
private AppUserCarClient appUserCarClient;
|
|
@Resource
|
private UploadRealTimeMonitoringDataClient uploadRealTimeMonitoringDataClient;
|
|
@Resource
|
private SysUserRoleClient sysUserRoleClient;
|
|
@Resource
|
private IotInterfaceClient iotInterfaceClient;
|
|
@Resource
|
private RedisService redisService;
|
|
@Resource
|
private TFaultMessageService faultMessageService;
|
|
@Resource
|
private IntegrationClient integrationClient;
|
|
|
|
|
|
/**
|
* 获取充电桩列表数据
|
* @param page
|
* @return
|
*/
|
@Override
|
public PageInfo<PageChargingPileListDTO> pageChargingPileList(PageChargingPileList page) {
|
Set<Integer> siteIds = null;
|
//校验合作商权限
|
SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData();
|
Integer roleType = sysUser.getRoleType();
|
Integer objectId = sysUser.getObjectId();
|
//合作商
|
if(roleType == 2){
|
siteIds = partnerService.authSite(objectId, SiteMenu.CHARGING_PILE);
|
}else{
|
//非管理员需要根据角色和用户配置查询允许的站点数据
|
if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
|
List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
|
List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
|
List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
|
data.addAll(data1);
|
siteIds = new HashSet<>(data);
|
}
|
}
|
PageInfo<PageChargingPileListDTO> pageInfo = new PageInfo<>(page.getPageCurr(), page.getPageSize());
|
List<PageChargingPileListDTO> list = this.baseMapper.pageChargingPileList(pageInfo, page, siteIds);
|
for (PageChargingPileListDTO pageChargingPileListDTO : list) {
|
Integer siteId = pageChargingPileListDTO.getSiteId();
|
pageChargingPileListDTO.setAuthAddChargingGun(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_ADD_CHARGING_GUN));
|
pageChargingPileListDTO.setAuthDelete(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_DELETE));
|
pageChargingPileListDTO.setAuthQueryInfo(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_QUERY_INFO));
|
pageChargingPileListDTO.setAuthUpdate(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_PILE_UPDATE));
|
}
|
return pageInfo.setRecords(list);
|
}
|
|
|
/**
|
* 添加充电桩
|
* @param chargingPile
|
* @return
|
*/
|
@Override
|
public AjaxResult addChargingPile(TChargingPile chargingPile) {
|
AjaxResult ajaxResult = addChargingPileVerify(chargingPile);
|
if(ajaxResult.isError()){
|
return ajaxResult;
|
}
|
long count = this.count(new LambdaQueryWrapper<TChargingPile>().eq(TChargingPile::getCode, chargingPile.getCode())
|
.eq(TChargingPile::getDelFlag, 0));
|
if(count > 0){
|
return AjaxResult.error("设备编号已存在");
|
}
|
//调用华为Iot创建设备
|
AddDevice addDevice = new AddDevice();
|
addDevice.setProductId("66da68d21837002b28b34ec0");
|
addDevice.setNodeId(chargingPile.getCode());
|
addDevice.setDeviceName(chargingPile.getName());
|
addDevice.setDescription(chargingPile.getNumber().toString());
|
AddDeviceResp deviceResp = iotInterfaceClient.addDevice(addDevice).getData();
|
if(null != deviceResp){
|
int httpStatusCode = deviceResp.getHttpStatusCode();
|
if(httpStatusCode == 201){
|
chargingPile.setIotdDeviceId(deviceResp.getDeviceId());
|
this.save(chargingPile);
|
}
|
}
|
return AjaxResult.success();
|
}
|
|
|
/**
|
* 校验必填项
|
* @param chargingPile
|
* @return
|
*/
|
AjaxResult addChargingPileVerify(TChargingPile chargingPile){
|
if(StringUtils.isEmpty(chargingPile.getCode())){
|
return AjaxResult.error("设备编号不能为空");
|
}
|
if(StringUtils.isEmpty(chargingPile.getName())){
|
return AjaxResult.error("充电设备名称不能为空");
|
}
|
if(null == chargingPile.getNumber()){
|
return AjaxResult.error("桩号不能为空");
|
}
|
if(null == chargingPile.getType()){
|
return AjaxResult.error("设备类型不能为空");
|
}
|
if(null == chargingPile.getSiteId()){
|
return AjaxResult.error("归属电站不能为空");
|
}
|
if(null == chargingPile.getPartnerId()){
|
return AjaxResult.error("归属合作商不能为空");
|
}
|
if(null == chargingPile.getRatedPower()){
|
return AjaxResult.error("额定功率不能为空");
|
}
|
return AjaxResult.success();
|
}
|
|
|
/**
|
* 获取充电桩详情
|
* @param id 充电桩id
|
* @return
|
*/
|
@Override
|
public TChargingPile getChargingPile(Integer id) {
|
return this.baseMapper.getChargingPile(id);
|
}
|
|
|
/**
|
* 编辑充电桩
|
* @param chargingPile
|
* @return
|
*/
|
@Override
|
public AjaxResult editChargingPile(TChargingPile chargingPile) {
|
AjaxResult ajaxResult = addChargingPileVerify(chargingPile);
|
if(ajaxResult.isError()){
|
return ajaxResult;
|
}
|
TChargingPile one = this.getOne(new LambdaQueryWrapper<TChargingPile>().eq(TChargingPile::getCode, chargingPile.getCode())
|
.eq(TChargingPile::getDelFlag, 0));
|
if(null != one && !one.getId().equals(chargingPile.getId())){
|
return AjaxResult.error("设备编号已存在");
|
}
|
this.updateById(chargingPile);
|
return AjaxResult.success();
|
}
|
|
|
/**
|
* 删除充电桩
|
* @param ids
|
* @return
|
*/
|
@Override
|
public AjaxResult delChargingPile(Integer[] ids) {
|
//检查是否有关联数据
|
long count = chargingGunService.count(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getChargingPileId, Arrays.asList(ids))
|
.eq(TChargingGun::getDelFlag, 0));
|
if(count > 0){
|
return AjaxResult.error("该充电桩已添加接口,不可删除。");
|
}
|
for (Integer id : ids) {
|
TChargingPile chargingPile = this.getById(id);
|
//调用华为Iot删除设备
|
if(StringUtils.isNotEmpty(chargingPile.getIotdDeviceId())){
|
DeleteDeviceResp deviceResp = iotInterfaceClient.deleteDevice(chargingPile.getIotdDeviceId()).getData();
|
if(null != deviceResp && deviceResp.getHttpStatusCode() == 0){
|
this.removeById(chargingPile);
|
}
|
}
|
}
|
return AjaxResult.success();
|
}
|
|
/**
|
* 批量设置计费策略
|
* @param setAccountingStrategy
|
*/
|
@Override
|
public void batchSetAccountingStrategy(BatchSetAccountingStrategy setAccountingStrategy) {
|
List<Integer> id = setAccountingStrategy.getId();
|
List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getChargingPileId, id).eq(TChargingGun::getDelFlag, 0));
|
for (TChargingGun tChargingGun : list) {
|
tChargingGun.setAccountingStrategyId(setAccountingStrategy.getAccountingStrategyId());
|
}
|
chargingGunService.updateBatchById(list);
|
//下发硬件更新计费模板
|
for (TChargingPile chargingPile : this.listByIds(id)) {
|
integrationClient.setupBillingModel1(chargingPile.getCode());
|
}
|
|
}
|
|
@Override
|
public List<TChargingPileVO> getChargingGunList(Integer siteId,Integer type) {
|
List<TChargingPileVO> chargingPileVOS = this.baseMapper.getChargingGunList(siteId);
|
LambdaQueryWrapper<TChargingGun> wrapper = new LambdaQueryWrapper<>();
|
if(Objects.nonNull(type)){
|
wrapper.eq(TChargingGun::getChargeMode, type);
|
}
|
wrapper.eq(TChargingGun::getSiteId, siteId);
|
List<TChargingGun> chargingGuns = chargingGunService.list(wrapper);
|
// 查询充电枪信息
|
chargingPileVOS.forEach(item -> {
|
List<TChargingGun> chargingGunList = chargingGuns.stream().filter(gun -> gun.getChargingPileId().equals(item.getId())).collect(Collectors.toList());
|
for (TChargingGun chargingGun : chargingGunList) {
|
if(chargingGun.getStatus().equals(4)){
|
// 查询正在充电的单子的实时记录
|
TChargingOrder chargingOrder = chargingOrderClient.getOrderDetailByGunId(chargingGun.getId()).getData();
|
if(Objects.nonNull(chargingOrder)){
|
UploadRealTimeMonitoringData uploadRealTimeMonitoringData = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrder.getCode()).getData();
|
chargingGun.setSoc(uploadRealTimeMonitoringData.getSoc());
|
}else {
|
chargingGun.setSoc(100);
|
}
|
}
|
if(chargingGun.getStatus().equals(5)){
|
chargingGun.setSoc(100);
|
}
|
}
|
item.setChargingGunList(chargingGunList);
|
});
|
return chargingPileVOS;
|
}
|
|
|
/**
|
* 获取监控设备监控数据
|
* @param siteId
|
* @return
|
*/
|
@Override
|
public ChargeMonitoring chargeMonitoring(Integer siteId) {
|
//获取当前登录账户的站点权限数据
|
Set<Integer> siteIds = new HashSet<>();
|
if(0 == siteId){
|
SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData();
|
Integer roleType = sysUser.getRoleType();
|
Integer objectId = sysUser.getObjectId();
|
if(2 == roleType){
|
siteIds = partnerService.authSite(objectId, SiteMenu.SITE_LIST);
|
}else{
|
//非管理员需要根据角色和用户配置查询允许的站点数据
|
if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
|
List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
|
List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
|
List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
|
data.addAll(data1);
|
siteIds = new HashSet<>(data);
|
}else{
|
siteIds = null;
|
}
|
}
|
}else{
|
siteIds.add(siteId);
|
}
|
List<Site> sites = null;
|
if(null == siteIds){
|
sites = siteService.list(new LambdaQueryWrapper<Site>().eq(Site::getDelFlag, 0));
|
siteIds = sites.stream().map(Site::getId).collect(Collectors.toSet());
|
}else{
|
sites = siteService.listByIds(siteIds);
|
}
|
List<TChargingGun> total = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getSiteId, siteIds).eq(TChargingGun::getDelFlag, 0));
|
List<TChargingGun> charging = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getSiteId, siteIds).eq(TChargingGun::getStatus, 4).eq(TChargingGun::getDelFlag, 0));
|
BigDecimal ratedPower = total.stream().map(TChargingGun::getRatedPower).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal realTimePower = charging.stream().map(TChargingGun::getChargingPower).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
ChargeMonitoring chargeMonitoring = new ChargeMonitoring();
|
chargeMonitoring.setPhone(sites.size() == 1 ? sites.get(0).getPhone() : "");
|
chargeMonitoring.setAddress(sites.size() == 1 ? sites.get(0).getAddress() : "");
|
chargeMonitoring.setTerminalTotal(total.size());
|
chargeMonitoring.setCharging(charging.size());
|
chargeMonitoring.setNotCharged(total.size() - charging.size());
|
chargeMonitoring.setRatedPower(ratedPower.setScale(4, RoundingMode.HALF_EVEN));
|
chargeMonitoring.setRealTimePower(realTimePower.setScale(4, RoundingMode.HALF_EVEN));
|
if(ratedPower.equals(BigDecimal.ZERO)){
|
chargeMonitoring.setDemandPowerSatisfactionRate(BigDecimal.ZERO);
|
}else{
|
chargeMonitoring.setDemandPowerSatisfactionRate(realTimePower.divide(ratedPower, new MathContext(2, RoundingMode.HALF_EVEN))
|
.multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_EVEN));
|
}
|
|
List<String> dates = new ArrayList<>();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
for (int i = 6; i >= 0; i--) {
|
Calendar calendar = Calendar.getInstance();
|
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - i);
|
dates.add(sdf.format(calendar.getTime()));
|
}
|
List<List<Map<String, Object>>> value1 = chargingOrderAccountingStrategyClient.getTotalElectricQuantity(6, siteIds).getData();
|
Map<String, Object> chargeTrend = new HashMap<>();
|
chargeTrend.put("date", dates);
|
chargeTrend.put("value", value1);
|
chargeMonitoring.setChargeTrend(chargeTrend);
|
|
//每日利用率=当日充电度数/(总桩数量*桩总功率*24小时)
|
List<TChargingPile> list = this.list(new LambdaQueryWrapper<TChargingPile>().in(TChargingPile::getSiteId, siteIds).eq(TChargingPile::getDelFlag, 0));
|
BigDecimal v = list.stream().map(TChargingPile::getRatedPower).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(4, RoundingMode.HALF_EVEN);
|
List<Double> data = chargingOrderAccountingStrategyClient.getDailyChargingDegree(6, siteIds).getData();
|
List<Double> value2 = new ArrayList<>();
|
for (Double datum : data) {
|
if(list.size() == 0){
|
value2.add(0D);
|
}else{
|
Double datum1 = new BigDecimal(datum).divide(new BigDecimal(list.size()).multiply(v).multiply(new BigDecimal(24)), new MathContext(4, RoundingMode.HALF_EVEN)).multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue();
|
value2.add(datum1);
|
}
|
}
|
Map<String, Object> utilizationTrend = new HashMap<>();
|
utilizationTrend.put("date", dates);
|
utilizationTrend.put("value", value2);
|
chargeMonitoring.setUtilizationTrend(utilizationTrend);
|
return chargeMonitoring;
|
}
|
|
|
|
/**
|
* 获取充电枪各种状态汇总
|
* @param siteId 站点id
|
* @return
|
*/
|
@Override
|
public ChargingGunCountMonitoring getChargingGunCountMonitoring(Integer siteId) {
|
//获取当前登录账户的站点权限数据
|
Set<Integer> siteIds = new HashSet<>();
|
if(0 == siteId){
|
SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData();
|
Integer roleType = sysUser.getRoleType();
|
Integer objectId = sysUser.getObjectId();
|
if(2 == roleType){
|
siteIds = partnerService.authSite(objectId, SiteMenu.SITE_LIST);
|
}else{
|
//非管理员需要根据角色和用户配置查询允许的站点数据
|
if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
|
List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
|
List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
|
List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
|
data.addAll(data1);
|
siteIds = new HashSet<>(data);
|
}else{
|
List<Site> list = siteService.list(new LambdaQueryWrapper<Site>().eq(Site::getDelFlag, 0));
|
siteIds = list.stream().map(Site::getId).collect(Collectors.toSet());
|
}
|
}
|
}else{
|
siteIds.add(siteId);
|
}
|
List<TChargingGun> list = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().in(TChargingGun::getSiteId, siteIds).eq(TChargingGun::getDelFlag, 0));
|
//空闲
|
long leisure = list.stream().filter(s -> s.getStatus().equals(2)).count();
|
//已插枪
|
long loaded = list.stream().filter(s -> Arrays.asList(3, 5, 6).contains(s.getStatus())).count();
|
//充电中
|
long charging = list.stream().filter(s -> s.getStatus().equals(4)).count();
|
//离网
|
long offline = list.stream().filter(s -> s.getStatus().equals(1)).count();
|
//故障
|
long breakdown = list.stream().filter(s -> s.getStatus().equals(7)).count();
|
ChargingGunCountMonitoring chargingGunCountMonitoring = new ChargingGunCountMonitoring();
|
chargingGunCountMonitoring.setLeisure(leisure);
|
chargingGunCountMonitoring.setLoaded(loaded);
|
chargingGunCountMonitoring.setCharging(charging);
|
chargingGunCountMonitoring.setOffline(offline);
|
chargingGunCountMonitoring.setBreakdown(breakdown);
|
return chargingGunCountMonitoring;
|
}
|
|
/**
|
* 获取充电枪监控数据
|
* @param query
|
* @return
|
*/
|
@Override
|
public PageInfo<ChargingGunMonitoring> getChargingGunMonitoring(GetChargingGunMonitoring query) {
|
//获取当前登录账户的站点权限数据
|
Set<Integer> siteIds = new HashSet<>();
|
if(0 == query.getSiteId()){
|
SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData();
|
Integer roleType = sysUser.getRoleType();
|
Integer objectId = sysUser.getObjectId();
|
if(2 == roleType){
|
siteIds = partnerService.authSite(objectId, SiteMenu.SITE_LIST);
|
}else{
|
//非管理员需要根据角色和用户配置查询允许的站点数据
|
if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
|
List<Integer> data = userSiteClient.getSiteIds(sysUser.getUserId()).getData();
|
List<SysUserRoleVo> data2 = sysUserRoleClient.getRoleByUserId(sysUser.getUserId()).getData();
|
List<Integer> data1 = roleSiteClient.getSiteIds(data2.get(0).getRoleId()).getData();
|
data.addAll(data1);
|
siteIds = new HashSet<>(data);
|
}else{
|
List<Site> list = siteService.list(new LambdaQueryWrapper<Site>().eq(Site::getDelFlag, 0));
|
siteIds = list.stream().map(Site::getId).collect(Collectors.toSet());
|
}
|
}
|
}else{
|
siteIds.add(query.getSiteId());
|
}
|
|
if(null != query.getStatus() && 0 < query.getStatus().size()){
|
if(query.getStatus().contains(3)){
|
query.getStatus().add(5);
|
query.getStatus().add(6);
|
}
|
}
|
PageInfo<ChargingGunMonitoring> pageInfo = new PageInfo<>(query.getPageCurr(), query.getPageSize());
|
List<ChargingGunMonitoring> chargingGunMonitoring = this.baseMapper.getChargingGunMonitoring(pageInfo, siteIds, query);
|
for (ChargingGunMonitoring gunMonitoring : chargingGunMonitoring) {
|
Integer status = gunMonitoring.getStatus();
|
if(status == 5 || status == 6){
|
gunMonitoring.setStatus(3);
|
}
|
if(status == 4){
|
Integer id = gunMonitoring.getId();
|
TChargingOrder chargingOrder = chargingOrderClient.getOrderDetailByGunId(id).getData();
|
if(null != chargingOrder){
|
Long appUserCarId = chargingOrder.getAppUserCarId();
|
if(null != appUserCarId){
|
TAppUserCar tAppUserCar = appUserCarClient.getCarByIds(Arrays.asList(appUserCarId)).getData().get(0);
|
gunMonitoring.setLicensePlate(tAppUserCar.getLicensePlate());
|
}
|
|
UploadRealTimeMonitoringData data = uploadRealTimeMonitoringDataClient.chargingOrderInfo(chargingOrder.getCode()).getData();
|
gunMonitoring.setChargingRatio(BigDecimal.valueOf(data.getSoc()));
|
gunMonitoring.setElectricQuantity(data.getCharging_degree().toString());
|
gunMonitoring.setSoc(data.getSoc().toString());
|
gunMonitoring.setElectricCurrent(data.getOutput_current().toString());
|
gunMonitoring.setVoltage(data.getOutput_voltage().toString());
|
switch (data.getHardware_fault()){
|
case 1:
|
gunMonitoring.setFaultCause("急停按钮动作故障");
|
break;
|
case 2:
|
gunMonitoring.setFaultCause("无可用整流模块");
|
break;
|
case 3:
|
gunMonitoring.setFaultCause("出风口温度过高");
|
break;
|
case 4:
|
gunMonitoring.setFaultCause("交流防雷故障");
|
break;
|
case 5:
|
gunMonitoring.setFaultCause("交直流模块 DC20 通信中断");
|
break;
|
case 6:
|
gunMonitoring.setFaultCause("绝缘检测模块 FC08 通信中断");
|
break;
|
case 7:
|
gunMonitoring.setFaultCause("电度表通信中断");
|
break;
|
case 8:
|
gunMonitoring.setFaultCause("读卡器通信中断");
|
break;
|
case 9:
|
gunMonitoring.setFaultCause("RC10 通信中断");
|
break;
|
case 10:
|
gunMonitoring.setFaultCause("风扇调速板故障");
|
break;
|
case 11:
|
gunMonitoring.setFaultCause("直流熔断器故障");
|
break;
|
case 12:
|
gunMonitoring.setFaultCause("高压接触器故障");
|
break;
|
case 13:
|
gunMonitoring.setFaultCause("门打开");
|
break;
|
}
|
}
|
}
|
}
|
return pageInfo.setRecords(chargingGunMonitoring);
|
}
|
|
|
/**
|
* 定时任务修改充电桩状态
|
*/
|
@Override
|
public void updateStatus() {
|
List<TChargingPile> list = this.list(new LambdaQueryWrapper<TChargingPile>().eq(TChargingPile::getDelFlag, 0));
|
Map<String, Object> charging_pile_online = redisService.getCacheMap("charging_pile_online");
|
for (TChargingPile chargingPile : list) {
|
Long time = (Long) charging_pile_online.get(chargingPile.getCode());
|
if(null != time && System.currentTimeMillis() - time > 60000){
|
TChargingPile chargingPile1 = new TChargingPile();
|
chargingPile1.setId(chargingPile.getId());
|
chargingPile1.setStatus(2);
|
this.updateById(chargingPile1);
|
List<TChargingGun> list1 = chargingGunService.list(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, chargingPile.getId()));
|
for (TChargingGun chargingGun : list1) {
|
TChargingGun chargingGun1 = new TChargingGun();
|
chargingGun1.setId(chargingGun.getId());
|
chargingGun1.setStatus(1);
|
chargingGunService.updateById(chargingGun1);
|
}
|
|
//添加记录
|
TFaultMessage faultMessage = faultMessageService.getOne(new LambdaQueryWrapper<TFaultMessage>().eq(TFaultMessage::getChargingPileId, chargingPile.getId())
|
.eq(TFaultMessage::getStatus, 1).eq(TFaultMessage::getDelFlag, 0).isNull(TFaultMessage::getEndTime));
|
if(null == faultMessage){
|
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);
|
}
|
}
|
}
|
}
|
}
|