bugfix 运营端小程序接口权限控制优化

This commit is contained in:
Lemon
2026-08-11 16:01:02 +08:00
parent 33b48f2ad4
commit e91b530517
6 changed files with 201 additions and 69 deletions

View File

@@ -2,12 +2,18 @@ package com.jsowell.api.uniapp.business;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.AjaxResult;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.SecurityUtils;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.dto.business.QueryConnectorInfoDTO;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.service.PileConnectorInfoService;
import com.jsowell.pile.service.PileMerchantInfoService;
import com.jsowell.pile.service.PileStationInfoService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.ConnectorInfoVO;
@@ -19,8 +25,10 @@ import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 运营端小程序枪口信息相关controller
@@ -38,6 +46,36 @@ public class BusinessConnectorInfoController extends BaseController {
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
/**
* 鉴权返回stationIdList
*/
public List<String> getStationIdListByAuthorization() {
// 权限过滤
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return new ArrayList<>();
}
String deptId = authorizedMap.getDeptId();
if (CollectionUtils.isNotEmpty(authorizedMap.getStationDeptIds())) {
// 为站点管理员
return pileStationInfoService.getIdsByDeptId(deptId);
}else {
// 平台管理员或运营商管理员
// 根据部门id查询merchantId
PileMerchantInfo pileMerchantInfo = pileMerchantInfoService.queryInfoByDeptId(deptId);
if (pileMerchantInfo != null) {
// 根据merchantId查询stationIdList
return pileStationInfoService.getStationIdsByMerchantIds(Lists.newArrayList(String.valueOf(pileMerchantInfo.getId())));
}
}
return new ArrayList<>();
}
/**
* 获取枪口信息列表
* @param dto
@@ -47,11 +85,9 @@ public class BusinessConnectorInfoController extends BaseController {
public RestApiResponse<?> getBusinessConnectorInfoList(@RequestBody QueryConnectorInfoDTO dto) {
RestApiResponse<?> response = null;
try {
// 获取登录账号信息
LoginUserDetailVO loginUserDetail = UserUtils.getLoginUserDetail();
List<String> merchantIdList = loginUserDetail.getFirstMerchantIdList();
if (CollectionUtils.isEmpty(dto.getStationIds())) {
dto.setStationIds(pileStationInfoService.getStationIdsByMerchantIds(merchantIdList));
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIds(stationIdList);
}
PageResponse pageResponse = pileConnectorInfoService.getConnectorListByStationAndStatus(dto);
response = new RestApiResponse<>(ImmutableMap.of("pageResponse", pageResponse));

View File

@@ -2,12 +2,15 @@ package com.jsowell.api.uniapp.business;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.page.PageResponse;
import com.jsowell.common.enums.ykc.ReturnCodeEnum;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.google.common.collect.ImmutableMap;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.dto.IndexQueryDTO;
import com.jsowell.pile.dto.MerchantOrderReportDTO;
import com.jsowell.pile.dto.ParkingCouponRecordQueryDTO;
@@ -16,6 +19,9 @@ import com.jsowell.pile.dto.business.BusinessEfficiencyQueryDTO;
import com.jsowell.pile.dto.business.BusinessOperationAnalysisQueryDTO;
import com.jsowell.pile.dto.business.BusinessScaleQueryDTO;
import com.jsowell.pile.dto.business.BusinessWorkbenchSummaryQueryDTO;
import com.jsowell.pile.service.PileMerchantInfoService;
import com.jsowell.pile.service.PileStationInfoService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.uniapp.business.BusinessDailySettlementDetailVO;
import com.jsowell.pile.service.BusinessFinancialService;
import com.jsowell.pile.service.OrderBasicInfoService;
@@ -27,6 +33,7 @@ import com.jsowell.pile.vo.uniapp.business.BusinessScaleVO;
import com.jsowell.pile.vo.uniapp.business.BusinessWorkbenchSummaryVO;
import com.jsowell.pile.vo.web.MerchantOrderReportVO;
import com.jsowell.pile.vo.web.TimeDistributionVO;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
@@ -34,6 +41,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
/**
@@ -51,6 +59,38 @@ public class BusinessFinancialController extends BaseController {
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private PileStationInfoService pileStationInfoService;
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
/**
* 鉴权返回stationIdList
*/
public List<String> getStationIdListByAuthorization() {
// 权限过滤
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return new ArrayList<>();
}
String deptId = authorizedMap.getDeptId();
if (CollectionUtils.isNotEmpty(authorizedMap.getStationDeptIds())) {
// 为站点管理员
return pileStationInfoService.getIdsByDeptId(deptId);
}else {
// 平台管理员或运营商管理员
// 根据部门id查询merchantId
PileMerchantInfo pileMerchantInfo = pileMerchantInfoService.queryInfoByDeptId(deptId);
if (pileMerchantInfo != null) {
// 根据merchantId查询stationIdList
return pileStationInfoService.getStationIdsByMerchantIds(Lists.newArrayList(String.valueOf(pileMerchantInfo.getId())));
}
}
return new ArrayList<>();
}
/**
* 查询工作台首页汇总
*
@@ -62,6 +102,10 @@ public class BusinessFinancialController extends BaseController {
logger.info("查询工作台首页汇总 params:{}", JSONObject.toJSONString(dto));
RestApiResponse<?> response;
try {
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIdList(stationIdList);
}
BusinessWorkbenchSummaryVO result = businessFinancialService.getWorkbenchSummary(dto);
response = new RestApiResponse<>(result);
logger.info("查询工作台首页汇总成功 today:{}, stationCount:{}",
@@ -90,6 +134,10 @@ public class BusinessFinancialController extends BaseController {
if (dto == null) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIdList(stationIdList);
}
BusinessDailySettlementDetailVO result = businessFinancialService.getDailySettlementDetail(dto);
response = new RestApiResponse<>(result);
logger.info("查询结算日报详情成功 startTime:{}, endTime:{}",
@@ -177,6 +225,10 @@ public class BusinessFinancialController extends BaseController {
if (dto == null) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIdList(stationIdList);
}
BusinessOperationAnalysisVO result = businessFinancialService.getBusinessOperationAnalysis(dto);
response = new RestApiResponse<>(result);
logger.info("查询经营分析成功 startTime:{}, endTime:{}, selectedMetricCode:{}",
@@ -205,6 +257,10 @@ public class BusinessFinancialController extends BaseController {
if (dto == null) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIdList(stationIdList);
}
BusinessScaleVO result = businessFinancialService.getBusinessScale(dto);
response = new RestApiResponse<>(result);
logger.info("查询经营规模成功 startTime:{}, endTime:{}, selectedMetricCode:{}",
@@ -261,6 +317,10 @@ public class BusinessFinancialController extends BaseController {
if (dto == null) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIdList(stationIdList);
}
BusinessEfficiencyAnalysisVO result = businessFinancialService.getEfficiencyAnalysis(dto);
response = new RestApiResponse<>(result);
logger.info("查询效率分析成功 startTime:{}, endTime:{}",
@@ -289,6 +349,10 @@ public class BusinessFinancialController extends BaseController {
if (dto == null) {
throw new BusinessException(ReturnCodeEnum.CODE_PARAM_NOT_NULL_ERROR);
}
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIdList(stationIdList);
}
PageResponse pageResponse = businessFinancialService.getStationOrderRank(dto);
response = new RestApiResponse<>(ImmutableMap.of("pageResponse", pageResponse));
logger.info("查询场站订单排行成功 startTime:{}, endTime:{}, total:{}",

View File

@@ -2,15 +2,19 @@ package com.jsowell.api.uniapp.business;
import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.jsowell.common.core.controller.BaseController;
import com.jsowell.common.core.domain.vo.AuthorizedDeptVO;
import com.jsowell.common.core.page.TableDataInfo;
import com.jsowell.common.exception.BusinessException;
import com.jsowell.common.response.RestApiResponse;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.PileMerchantInfo;
import com.jsowell.pile.dto.QueryStationDTO;
import com.jsowell.pile.dto.business.StationBusinessAnalyzeInfoDTO;
import com.jsowell.pile.dto.business.StationStatisticsInfoDTO;
import com.jsowell.pile.service.OrderBasicInfoService;
import com.jsowell.pile.service.PileMerchantInfoService;
import com.jsowell.pile.service.PileStationInfoService;
import com.jsowell.pile.util.UserUtils;
import com.jsowell.pile.vo.base.LoginUserDetailVO;
@@ -22,6 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
@@ -40,6 +45,36 @@ public class BusinessStationInfoController extends BaseController {
@Autowired
private OrderBasicInfoService orderBasicInfoService;
@Autowired
private PileMerchantInfoService pileMerchantInfoService;
/**
* 鉴权返回stationIdList
*/
public List<String> getStationIdListByAuthorization() {
// 权限过滤
AuthorizedDeptVO authorizedMap = UserUtils.getAuthorizedMap();
if (authorizedMap == null) {
// 为空表示没有权限,返回空数组
return new ArrayList<>();
}
String deptId = authorizedMap.getDeptId();
if (CollectionUtils.isNotEmpty(authorizedMap.getStationDeptIds())) {
// 为站点管理员
return pileStationInfoService.getIdsByDeptId(deptId);
}else {
// 平台管理员或运营商管理员
// 根据部门id查询merchantId
PileMerchantInfo pileMerchantInfo = pileMerchantInfoService.queryInfoByDeptId(deptId);
if (pileMerchantInfo != null) {
// 根据merchantId查询stationIdList
return pileStationInfoService.getStationIdsByMerchantIds(Lists.newArrayList(String.valueOf(pileMerchantInfo.getId())));
}
}
return new ArrayList<>();
}
/**
@@ -68,10 +103,9 @@ public class BusinessStationInfoController extends BaseController {
try {
// List<StationStatisticsInfosVO> stationStatisticsInfos = pileStationInfoService.getStationStatisticsInfos(dto);
// 获取登录账号信息
LoginUserDetailVO loginUserDetail = UserUtils.getLoginUserDetail();
List<String> merchantIdList = loginUserDetail.getFirstMerchantIdList();
if (CollectionUtils.isEmpty(dto.getStationIds())) {
dto.setStationIds(pileStationInfoService.getStationIdsByMerchantIds(merchantIdList));
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIds(stationIdList);
}
StationStatisticsInfosVO info = pileStationInfoService.getStationStatisticsInfosV2(dto);
response = new RestApiResponse<>(ImmutableMap.of("stationStatisticsInfo", info));
@@ -94,10 +128,9 @@ public class BusinessStationInfoController extends BaseController {
RestApiResponse<?> response = null;
try {
// 获取登录账号信息
LoginUserDetailVO loginUserDetail = UserUtils.getLoginUserDetail();
List<String> merchantIdList = loginUserDetail.getFirstMerchantIdList();
if (CollectionUtils.isEmpty(dto.getStationIds())) {
dto.setStationIds(pileStationInfoService.getStationIdsByMerchantIds(merchantIdList));
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIds(stationIdList);
}
StationBusinessAnalyzeInfoVO vo = pileStationInfoService.getStationBusinessAnalyzeInfo(dto);
response = new RestApiResponse<>(ImmutableMap.of("stationBusinessAnalyzeInfoVO", vo));
@@ -161,11 +194,9 @@ public class BusinessStationInfoController extends BaseController {
public RestApiResponse<?> getStationOrderQuantityInfo(@RequestBody StationBusinessAnalyzeInfoDTO dto) {
RestApiResponse<?> response = null;
try {
// 获取登录账号信息
LoginUserDetailVO loginUserDetail = UserUtils.getLoginUserDetail();
List<String> merchantIdList = loginUserDetail.getFirstMerchantIdList();
if (CollectionUtils.isEmpty(dto.getStationIds())) {
dto.setStationIds(pileStationInfoService.getStationIdsByMerchantIds(merchantIdList));
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIds(stationIdList);
}
StationBusinessAnalyzeInfoVO vo = pileStationInfoService.getStationOrderQuantityInfo(dto);
response = new RestApiResponse<>(ImmutableMap.of("stationBusinessAnalyzeInfoVO", vo));
@@ -185,11 +216,9 @@ public class BusinessStationInfoController extends BaseController {
public RestApiResponse<?> getStationConnectorUsedInfo(@RequestBody StationBusinessAnalyzeInfoDTO dto) {
RestApiResponse<?> response = null;
try {
// 获取登录账号信息
LoginUserDetailVO loginUserDetail = UserUtils.getLoginUserDetail();
List<String> merchantIdList = loginUserDetail.getFirstMerchantIdList();
if (CollectionUtils.isEmpty(dto.getStationIds())) {
dto.setStationIds(pileStationInfoService.getStationIdsByMerchantIds(merchantIdList));
List<String> stationIdList = getStationIdListByAuthorization();
if (CollectionUtils.isNotEmpty(stationIdList)) {
dto.setStationIds(stationIdList);
}
StationBusinessAnalyzeInfoVO vo = pileStationInfoService.getStationConnectorUsedInfo(dto);
response = new RestApiResponse<>(ImmutableMap.of("stationBusinessAnalyzeInfoVO", vo));