| | |
| | | package com.ruoyi.account.service; |
| | | |
| | | import com.ruoyi.chargingPile.api.domain.SiteMenu; |
| | | import com.ruoyi.chargingPile.api.feignClient.PartnerClient; |
| | | import com.ruoyi.chargingPile.api.dto.GetSiteListDTO; |
| | | import com.ruoyi.chargingPile.api.feignClient.SiteClient; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Collection; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | |
| | | private static final Integer PARTNER_ROLE_TYPE = 2; |
| | | private static final Long IMPOSSIBLE_USER_ID = -1L; |
| | | private static final String PARTNER_READ_ONLY_MESSAGE = "合作商账号仅支持查看用户信息"; |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | @Resource |
| | | private PartnerClient partnerClient; |
| | | private SiteClient siteClient; |
| | | @Resource |
| | | private ChargingOrderClient chargingOrderClient; |
| | | |
| | |
| | | if (!isPartner(sysUser)) { |
| | | return null; |
| | | } |
| | | if (sysUser.getObjectId() == null) { |
| | | if (sysUser.getObjectId() == null || sysUser.getUserId() == null) { |
| | | return impossibleUserIds(); |
| | | } |
| | | R<Set<Integer>> siteResult = partnerClient.authSite(sysUser.getObjectId(), SiteMenu.SITE_LIST.getValue()); |
| | | R<List<GetSiteListDTO>> siteResult = siteClient.getSiteListByUserId(sysUser.getUserId()); |
| | | if (siteResult == null || !R.isSuccess(siteResult) || siteResult.getData() == null) { |
| | | return impossibleUserIds(); |
| | | } |
| | | List<Integer> siteIds = siteResult.getData().stream() |
| | | .filter(Objects::nonNull) |
| | | .map(GetSiteListDTO::getId) |
| | | .filter(Objects::nonNull) |
| | | .filter(siteId -> siteId > 0) |
| | | .distinct() |
| | |
| | | return userIds.isEmpty() ? impossibleUserIds() : userIds; |
| | | } |
| | | |
| | | public boolean isCurrentPartner() { |
| | | return isPartner(getCurrentSysUser()); |
| | | } |
| | | |
| | | public void assertUserVisible(Long userId) { |
| | | List<Long> visibleUserIds = getVisibleUserIdsForCurrentPartner(); |
| | | if (visibleUserIds != null && (userId == null || !visibleUserIds.contains(userId))) { |
| | |
| | | } |
| | | } |
| | | |
| | | public void assertWritable() { |
| | | if (isCurrentPartner()) { |
| | | throw new ServiceException(PARTNER_READ_ONLY_MESSAGE); |
| | | public void assertUsersVisible(Collection<Long> userIds) { |
| | | List<Long> visibleUserIds = getVisibleUserIdsForCurrentPartner(); |
| | | if (visibleUserIds == null) { |
| | | return; |
| | | } |
| | | if (userIds == null || userIds.isEmpty()) { |
| | | throw new ServiceException("无权操作所选用户"); |
| | | } |
| | | for (Long userId : userIds) { |
| | | if (userId == null || !visibleUserIds.contains(userId)) { |
| | | throw new ServiceException("无权操作所选用户"); |
| | | } |
| | | } |
| | | } |
| | | |