From 77e5e0918131fa60a4fca8f075ab9ae6199cac54 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 16 八月 2024 15:27:06 +0800
Subject: [PATCH] 小程序登录
---
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 102 insertions(+), 4 deletions(-)
diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java
index 73709a5..e88f663 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingGunServiceImpl.java
@@ -1,20 +1,38 @@
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.TChargingGunDTO;
import com.ruoyi.chargingPile.api.model.TChargingGun;
import com.ruoyi.chargingPile.api.query.TChargingGunQuery;
+import com.ruoyi.chargingPile.api.vo.ChargingGunCountVO;
import com.ruoyi.chargingPile.api.vo.TChargingGunVO;
import com.ruoyi.chargingPile.api.vo.TMonitoringEquipmentVO;
+import com.ruoyi.chargingPile.domain.SiteMenu;
import com.ruoyi.chargingPile.mapper.TChargingGunMapper;
+import com.ruoyi.chargingPile.service.IPartnerService;
import com.ruoyi.chargingPile.service.TChargingGunService;
+import com.ruoyi.common.core.enums.status.ChargingGunModeEnum;
+import com.ruoyi.common.core.enums.status.ChargingGunStatusEnum;
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.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.Set;
/**
* <p>
@@ -26,11 +44,52 @@
*/
@Service
public class TChargingGunServiceImpl extends ServiceImpl<TChargingGunMapper, TChargingGun> implements TChargingGunService {
+
+ @Resource
+ private SysUserClient sysUserClient;
+
+ @Resource
+ private IPartnerService partnerService;
+
+ @Resource
+ private UserSiteClient userSiteClient;
+
+ @Resource
+ private RoleSiteClient roleSiteClient;
+
+
+
@Override
public PageInfo<TChargingGunVO> pageList(TChargingGunQuery query) {
+ 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_GUN);
+ }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<TChargingGunVO> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
- List<TChargingGunVO> list = this.baseMapper.pageList(query,pageInfo);
+ List<TChargingGunVO> list = this.baseMapper.pageList(query,pageInfo, siteIds);
+ for (TChargingGunVO tChargingGunVO : list) {
+ Integer siteId = tChargingGunVO.getSiteId();
+ tChargingGunVO.setAuthDelete(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_DELETE));
+ tChargingGunVO.setAuthDownloadQRCode(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_DOWNLOAD_QR_CODE));
+ tChargingGunVO.setAuthEndCharge(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_END_CHARGE));
+ tChargingGunVO.setAuthQueryInfo(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_QUERY_INFO));
+ tChargingGunVO.setAuthUpdate(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_UPDATE));
+ tChargingGunVO.setAuthViewRates(roleType == 1 ? true : partnerService.authMenu(objectId, siteId, SiteMenu.CHARGING_GUN_VIEW_RATES));
+ }
pageInfo.setRecords(list);
return pageInfo;
}
@@ -46,7 +105,8 @@
if(ajaxResult.isError()){
return ajaxResult;
}
- long count = this.count(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode()).eq(TChargingGun::getDelFlag, 0));
+ long count = this.count(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode())
+ .eq(TChargingGun::getDelFlag, 0));
if(count > 0){
return AjaxResult.error("接口编码已存在");
}
@@ -62,18 +122,56 @@
*/
@Override
public AjaxResult update(TChargingGunDTO dto) {
+ TChargingGun chargingGun = this.getById(dto.getId());
+ if(Arrays.asList(3,4,5,6).contains(chargingGun.getStatus())){
+ return AjaxResult.error("接口占用中,无法编辑!");
+ }
AjaxResult ajaxResult = addVerify(dto);
if(ajaxResult.isError()){
return ajaxResult;
}
- TChargingGun one = this.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode()).eq(TChargingGun::getDelFlag, 0));
+ TChargingGun one = this.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getCode, dto.getCode())
+ .eq(TChargingGun::getDelFlag, 0));
if(null != one && !dto.getId().equals(one.getId())){
return AjaxResult.error("接口编码已存在");
}
this.updateById(dto);
return AjaxResult.success();
}
-
+
+ @Override
+ public Map<String, ChargingGunCountVO> getChargingGunCount(Integer siteId) {
+ Map<String, ChargingGunCountVO> map = new HashMap<>(4);
+ // 查询全部充电枪
+ List<TChargingGun> list = this.list(Wrappers.lambdaQuery(TChargingGun.class).eq(TChargingGun::getSiteId, siteId));
+ int freeCount = 0;
+ // 超级充
+ ChargingGunCountVO superSufficient = getGunCount(ChargingGunModeEnum.SUPER_SUFFICIENT.getCode(), list);
+ freeCount += superSufficient.getFreeCount();
+ map.put("superSufficient", superSufficient);
+ // 快充
+ ChargingGunCountVO fastSufficient = getGunCount(ChargingGunModeEnum.FAST_SUFFICIENT.getCode(), list);
+ freeCount += fastSufficient.getFreeCount();
+ map.put("fastSufficient", fastSufficient);
+ // 慢充
+ ChargingGunCountVO slowSufficient = getGunCount(ChargingGunModeEnum.SLOW_SUFFICIENT.getCode(), list);
+ freeCount += slowSufficient.getFreeCount();
+ map.put("slowSufficient", slowSufficient);
+ ChargingGunCountVO chargingGunCountVO = new ChargingGunCountVO();
+ chargingGunCountVO.setTotalCount(list.size());
+ chargingGunCountVO.setFreeCount(freeCount);
+ map.put("totalSufficient", chargingGunCountVO);
+ return map;
+ }
+
+ private ChargingGunCountVO getGunCount(Integer chargeMode, List<TChargingGun> list){
+ ChargingGunCountVO chargingGunCountVO = new ChargingGunCountVO();
+ chargingGunCountVO.setTotalCount(list.stream().filter(tChargingGun -> tChargingGun.getChargeMode().equals(chargeMode)).collect(Collectors.toList()).size());
+ chargingGunCountVO.setFreeCount(list.stream().filter(tChargingGun -> tChargingGun.getChargeMode().equals(chargeMode)
+ && tChargingGun.getStatus()== ChargingGunStatusEnum.IDLE.getCode()).collect(Collectors.toList()).size());
+ return chargingGunCountVO;
+ }
+
/**
* 校验必填项
* @param dto
--
Gitblit v1.7.1