From 7f288c7515fa04cf83fadc3506317d08fb099630 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期六, 10 八月 2024 11:44:53 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile

---
 ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
index 055590a..ea3e370 100644
--- a/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
+++ b/ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -1,12 +1,15 @@
 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;
@@ -16,12 +19,16 @@
 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.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 /**
@@ -44,6 +51,12 @@
 	@Resource
 	private IPartnerService partnerService;
 	
+	@Resource
+	private UserSiteClient userSiteClient;
+	
+	@Resource
+	private RoleSiteClient roleSiteClient;
+	
 	
 	
 	
@@ -54,7 +67,7 @@
 	 */
 	@Override
 	public PageInfo<PageChargingPileListDTO> pageChargingPileList(PageChargingPileList page) {
-		List<Integer> siteIds = null;
+		Set<Integer> siteIds = null;
 		//校验合作商权限
 		SysUser sysUser = sysUserClient.getSysUser(SecurityUtils.getUserId()).getData();
 		Integer roleType = sysUser.getRoleType();
@@ -62,6 +75,14 @@
 		//合作商
 		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);
@@ -192,4 +213,17 @@
 		}
 		chargingGunService.updateBatchById(list);
 	}
+
+	@Override
+	public List<TChargingPileVO> getChargingGunList(Integer siteId) {
+		List<TChargingPileVO> chargingPileVOS = this.baseMapper.getChargingGunList(siteId);
+		List<TChargingGun> chargingGuns = chargingGunService.list(Wrappers.lambdaQuery(TChargingGun.class)
+				.eq(TChargingGun::getSiteId, siteId));
+		// 查询充电枪信息
+		chargingPileVOS.forEach(item -> {
+			List<TChargingGun> gunList = chargingGuns.stream().filter(gun -> gun.getChargingPileId().equals(item.getId())).collect(Collectors.toList());
+			item.setChargingGunList(gunList);
+		});
+		return chargingPileVOS;
+	}
 }

--
Gitblit v1.7.1