longz
2026-08-07 81dfcef329bc07c69f286836df4df86f330dd46c
fix: 限制合作商大屏统计范围
1个文件已添加
3个文件已修改
117 ■■■■■ 已修改文件
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingGunController.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/TChargingPileService.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/test/java/com/ruoyi/chargingPile/controller/TChargingGunControllerTest.java 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingGunController.java
@@ -3,7 +3,6 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.chargingPile.api.dto.GetSiteListDTO;
import com.ruoyi.chargingPile.api.dto.TChargingGunDTO;
import com.ruoyi.chargingPile.api.model.Site;
import com.ruoyi.chargingPile.api.model.TChargingGun;
@@ -24,7 +23,6 @@
import com.ruoyi.common.log.enums.OperatorType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
import io.swagger.annotations.Api;
@@ -271,8 +269,6 @@
        }
        return name.replaceAll("[\\\\/:*?\\\"<>|]", "_");
    }
    @Resource
    private TokenService tokenService;
    /**
     * 设备状态统计
     */
@@ -281,16 +277,7 @@
    @PutMapping(value = "/gunStatusStatistics")
    public R<GunStatusStatisticsVO> gunStatusStatistics(
            @RequestParam(value = "siteId", required = false) Integer siteId) {
        List<Integer> siteIds = new ArrayList<>();
        Long userId = tokenService.getLoginUser().getUserid();
        //获取当前登录的siteIds
        PageInfo<GetSiteListDTO> siteList1 = siteService.getSiteList1(userId);
        for (GetSiteListDTO datum : siteList1.getRecords()) {
            siteIds.add(datum.getId());
        }
        if (siteId != null) {
            siteIds.removeIf(id -> !siteId.equals(id));
        }
        List<Integer> siteIds = chargingPileService.getGeneralScreenSiteIds(siteId);
        return R.ok(chargingGunService.gunStatusStatistics(siteIds));
    }
    
@@ -466,4 +453,3 @@
    }
}
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/TChargingPileService.java
@@ -101,9 +101,17 @@
     */
    ChargeMonitoring chargeMonitoring(Integer siteId);
    /** 智慧充电大屏监控数据,不按菜单权限过滤站点。 */
    /** 智慧充电大屏监控数据,按当前账号可见站点过滤。 */
    ChargeMonitoring chargeMonitoringForScreen(Integer siteId);
    /**
     * 获取智慧充电大屏允许统计的站点。
     *
     * @param siteId 选中的站点,未选择时统计全部可见站点
     * @return 当前账号有权查看的站点;无权限时返回 -1 空范围
     */
    List<Integer> getGeneralScreenSiteIds(Integer siteId);
    List<Site> getChargingMonitoringSiteList();
    
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/service/impl/TChargingPileServiceImpl.java
@@ -740,6 +740,14 @@
    }
    private Set<Integer> resolveChargingMonitoringSiteIds(Integer requestedSiteId) {
        return resolveAccessibleSiteIds(requestedSiteId, SiteMenu.CHARGING_FACILITY_MONITORING);
    }
    private Set<Integer> resolveGeneralScreenSiteIds(Integer requestedSiteId) {
        return resolveAccessibleSiteIds(requestedSiteId, SiteMenu.SITE_LIST);
    }
    private Set<Integer> resolveAccessibleSiteIds(Integer requestedSiteId, SiteMenu partnerSiteMenu) {
        Long userId = tokenService.getLoginUser().getUserid();
        Set<Integer> allowedSiteIds = new HashSet<>();
        if (SecurityUtils.isAdmin(userId)) {
@@ -756,7 +764,7 @@
        }
        if (Integer.valueOf(2).equals(sysUser.getRoleType())) {
            Set<Integer> partnerSiteIds = partnerService.authSite(
                    sysUser.getObjectId(), SiteMenu.CHARGING_FACILITY_MONITORING);
                    sysUser.getObjectId(), partnerSiteMenu);
            if (partnerSiteIds != null) {
                allowedSiteIds.addAll(partnerSiteIds);
            }
@@ -799,14 +807,12 @@
    @Override
    public ChargeMonitoring chargeMonitoringForScreen(Integer siteId) {
        Set<Integer> siteIds;
        if (siteId != null && siteId > 0) {
            siteIds = Collections.singleton(siteId);
        } else {
            siteIds = siteService.list(new LambdaQueryWrapper<Site>()
                    .eq(Site::getDelFlag, 0)).stream().map(Site::getId).collect(Collectors.toSet());
        return buildChargeMonitoring(resolveGeneralScreenSiteIds(siteId));
        }
        return buildChargeMonitoring(siteIds);
    @Override
    public List<Integer> getGeneralScreenSiteIds(Integer siteId) {
        return new ArrayList<>(resolveGeneralScreenSiteIds(siteId));
    }
    private ChargeMonitoring buildChargeMonitoring(Set<Integer> siteIds) {
ruoyi-service/ruoyi-chargingPile/src/test/java/com/ruoyi/chargingPile/controller/TChargingGunControllerTest.java
New file
@@ -0,0 +1,69 @@
package com.ruoyi.chargingPile.controller;
import com.ruoyi.chargingPile.api.vo.GunStatusStatisticsVO;
import com.ruoyi.chargingPile.service.TChargingGunService;
import com.ruoyi.chargingPile.service.TChargingPileService;
import com.ruoyi.common.core.domain.R;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class TChargingGunControllerTest {
    @Test
    void gunStatusStatisticsUsesAllVisibleGeneralScreenSites() {
        TChargingGunController controller = new TChargingGunController();
        TChargingPileService chargingPileService = mock(TChargingPileService.class);
        TChargingGunService chargingGunService = mock(TChargingGunService.class);
        GunStatusStatisticsVO expected = new GunStatusStatisticsVO();
        ReflectionTestUtils.setField(controller, "chargingPileService", chargingPileService);
        ReflectionTestUtils.setField(controller, "chargingGunService", chargingGunService);
        when(chargingPileService.getGeneralScreenSiteIds(null)).thenReturn(Arrays.asList(10, 20));
        when(chargingGunService.gunStatusStatistics(Arrays.asList(10, 20))).thenReturn(expected);
        R<GunStatusStatisticsVO> result = controller.gunStatusStatistics(null);
        assertSame(expected, result.getData());
        verify(chargingPileService).getGeneralScreenSiteIds(null);
        verify(chargingGunService).gunStatusStatistics(Arrays.asList(10, 20));
    }
    @Test
    void gunStatusStatisticsUsesTheGeneralScreenSiteScope() {
        TChargingGunController controller = new TChargingGunController();
        TChargingPileService chargingPileService = mock(TChargingPileService.class);
        TChargingGunService chargingGunService = mock(TChargingGunService.class);
        GunStatusStatisticsVO expected = new GunStatusStatisticsVO();
        ReflectionTestUtils.setField(controller, "chargingPileService", chargingPileService);
        ReflectionTestUtils.setField(controller, "chargingGunService", chargingGunService);
        when(chargingPileService.getGeneralScreenSiteIds(20)).thenReturn(Arrays.asList(20));
        when(chargingGunService.gunStatusStatistics(Arrays.asList(20))).thenReturn(expected);
        R<GunStatusStatisticsVO> result = controller.gunStatusStatistics(20);
        assertSame(expected, result.getData());
        verify(chargingPileService).getGeneralScreenSiteIds(20);
        verify(chargingGunService).gunStatusStatistics(Arrays.asList(20));
    }
    @Test
    void gunStatusStatisticsPassesTheEmptyScopeForAnUnauthorizedSite() {
        TChargingGunController controller = new TChargingGunController();
        TChargingPileService chargingPileService = mock(TChargingPileService.class);
        TChargingGunService chargingGunService = mock(TChargingGunService.class);
        ReflectionTestUtils.setField(controller, "chargingPileService", chargingPileService);
        ReflectionTestUtils.setField(controller, "chargingGunService", chargingGunService);
        when(chargingPileService.getGeneralScreenSiteIds(30)).thenReturn(Collections.singletonList(-1));
        controller.gunStatusStatistics(30);
        verify(chargingGunService).gunStatusStatistics(Collections.singletonList(-1));
    }
}