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.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.TChargingGunVO;
|
import com.ruoyi.chargingPile.api.vo.TChargingPileVO;
|
import com.ruoyi.chargingPile.domain.SiteMenu;
|
import com.ruoyi.chargingPile.mapper.TChargingPileMapper;
|
import com.ruoyi.chargingPile.service.IPartnerService;
|
import com.ruoyi.chargingPile.service.TChargingGunService;
|
import com.ruoyi.chargingPile.service.TChargingPileService;
|
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.security.utils.SecurityUtils;
|
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 org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Set;
|
import java.util.stream.Collectors;
|
|
/**
|
* <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;
|
|
|
|
|
/**
|
* 获取充电桩列表数据
|
* @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<Integer> data1 = roleSiteClient.getSiteIds(sysUser.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("设备编号已存在");
|
}
|
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>().eq(TChargingGun::getChargingPileId, Arrays.asList(ids)).eq(TChargingGun::getDelFlag, 0));
|
if(count > 0){
|
return AjaxResult.error("该充电桩有关联的接口数据,删除失败!");
|
}
|
for (Integer id : ids) {
|
TChargingPile chargingPile = this.getById(id);
|
chargingPile.setDelFlag(true);
|
this.updateById(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.setChargingPileId(setAccountingStrategy.getAccountingStrategyId());
|
}
|
chargingGunService.updateBatchById(list);
|
}
|
|
@Override
|
public List<TChargingPileVO> getChargingGunList(Integer siteId,Integer type) {
|
List<TChargingPileVO> chargingPileVOS = this.baseMapper.getChargingGunList(siteId);
|
List<TChargingGun> chargingGuns = chargingGunService.list(Wrappers.lambdaQuery(TChargingGun.class)
|
.eq(TChargingGun::getSiteId, siteId)
|
.eq(TChargingGun::getChargeMode, type));
|
// 查询充电枪信息
|
chargingPileVOS.forEach(item -> {
|
item.setChargingGunList(chargingGuns.stream().filter(gun -> gun.getChargingPileId().equals(item.getId())).collect(Collectors.toList()));
|
});
|
return chargingPileVOS;
|
}
|
}
|