| | |
| | | package com.ruoyi.chargingPile.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.mapper.TChargingPileMapper; |
| | | 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 org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @Service |
| | | public class TChargingPileServiceImpl extends ServiceImpl<TChargingPileMapper, TChargingPile> implements TChargingPileService { |
| | | |
| | | |
| | | @Resource |
| | | private TChargingGunService chargingGunService; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取充电桩列表数据 |
| | | * @param page |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageInfo<PageChargingPileListDTO> pageChargingPileList(PageChargingPileList page) { |
| | | PageInfo<PageChargingPileListDTO> pageInfo = new PageInfo<>(page.getPageCurr(), page.getPageSize()); |
| | | List<PageChargingPileListDTO> list = this.baseMapper.pageChargingPileList(pageInfo, page); |
| | | 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 id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult delChargingPile(Integer id) { |
| | | //检查是否有关联数据 |
| | | //接口 |
| | | long count = chargingGunService.count(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getChargingPileId, id).eq(TChargingGun::getDelFlag, 0)); |
| | | if(count > 0){ |
| | | return AjaxResult.error("该充电桩有关联的接口数据,删除失败!"); |
| | | } |
| | | 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); |
| | | } |
| | | } |