@@ -29,6 +29,7 @@ import java.util.stream.Collectors;
/**
* describe:
*
* @author wxp
* @date 2020/11/11
*/
@@ -59,35 +60,35 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
@Override
public List < UserAuthMappingDO > listUserAuthMappingByUserId ( String userId ) {
if ( StringUtils . isBlank ( userId ) ) {
if ( StringUtils . isBlank ( userId ) ) {
return Lists . newArrayList ( ) ;
}
return userAuthMappingMapper . listUserAuthMappingByUserId ( userId ) ;
}
@Override
public List < String > getAuthRegionIdAndSubRegionIdByUserId ( String userId ) {
public List < String > getAuthRegionIdAndSubRegionIdByUserId ( String userId ) {
List < UserAuthMappingDO > userAuthMapping = listUserAuthMappingByUserId ( userId ) ;
if ( CollectionUtils . isEmpty ( userAuthMapping ) ) {
if ( CollectionUtils . isEmpty ( userAuthMapping ) ) {
return Lists . newArrayList ( ) ;
}
List < String > regionIds = userAuthMapping . stream ( ) . map ( UserAuthMappingDO : : getMappingId ) . collect ( Collectors . toList ( ) ) ;
List < String > subRegionIds = regionMapper . getSubRegionIdsByRegionIds ( regionIds ) ;
if ( CollectionUtils . isNotEmpty ( subRegionIds ) ) {
if ( CollectionUtils . isNotEmpty ( subRegionIds ) ) {
regionIds . addAll ( subRegionIds ) ;
}
return regionIds ;
}
@Override
public List < String > getAuthStoreIdAndSubRegionIdByUserId ( String userId ) {
public List < String > getAuthStoreIdAndSubRegionIdByUserId ( String userId ) {
List < UserAuthMappingDO > userAuthMapping = listUserAuthMappingByUserId ( userId ) ;
if ( CollectionUtils . isEmpty ( userAuthMapping ) ) {
if ( CollectionUtils . isEmpty ( userAuthMapping ) ) {
return Lists . newArrayList ( ) ;
}
List < String > regionIds = userAuthMapping . stream ( ) . map ( UserAuthMappingDO : : getMappingId ) . collect ( Collectors . toList ( ) ) ;
List < String > subRegionIds = regionMapper . getStoreIdsByRegionIds ( regionIds ) ;
if ( CollectionUtils . isNotEmpty ( subRegionIds ) ) {
if ( CollectionUtils . isNotEmpty ( subRegionIds ) ) {
regionIds . addAll ( subRegionIds ) ;
}
return regionIds ;
@@ -95,6 +96,7 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
/**
* 提供 根据职位 意向区域 查 对应人的接口 同时返回人名字
*
* @param userRoleEnum
* @param wantShopAreaId
* @return
@@ -102,31 +104,31 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
@Override
public EnterpriseUserDO getUserByRoleEnumAndWantShopAreaId ( UserRoleEnum userRoleEnum , Long wantShopAreaId ) {
log . info ( " getUserByRoleEnumAndAreaId: {}, wantShopAreaId: {} " , userRoleEnum , wantShopAreaId ) ;
if ( Objects . isNull ( userRoleEnum ) | | Objects . isNull ( wantShopAreaId ) ) {
if ( Objects . isNull ( userRoleEnum ) | | Objects . isNull ( wantShopAreaId ) ) {
return null ;
}
String investmentManagerKey = redisConstantUtil . getInvestmentManagerKey ( wantShopAreaId , userRoleEnum . getCode ( ) ) ;
String suitableUserId = redisUtilPool . rpopStr ( investmentManagerKey ) ;
if ( StringUtils . isNotBlank ( suitableUserId ) ) {
if ( StringUtils . isNotBlank ( suitableUserId ) ) {
EnterpriseUserDO userDO = enterpriseUserDAO . getUserInfoById ( suitableUserId ) ;
return userDO ;
}
Long warRegionId = regionAreaConfigDao . getByWantShopAreaId ( wantShopAreaId ) ;
if ( warRegionId = = null ) {
if ( warRegionId = = null ) {
return fillDefaultUser ( userRoleEnum ) ;
}
// 查找有战区权限的人
List < String > authWarRegionUserIdList = authWarRegionUser ( warRegionId ) ;
if ( CollectionUtils . isEmpty ( authWarRegionUserIdList ) ) {
if ( CollectionUtils . isEmpty ( authWarRegionUserIdList ) ) {
return fillDefaultUser ( userRoleEnum ) ;
}
Long roleId = userRoleEnum . getCode ( ) ;
List < String > hasRoleUserIdList = sysRoleMapper . getPositionUserIds ( Collections . singletonList ( String . valueOf ( roleId ) ) ) ;
if ( CollectionUtils . isEmpty ( hasRoleUserIdList ) ) {
if ( CollectionUtils . isEmpty ( hasRoleUserIdList ) ) {
return fillDefaultUser ( userRoleEnum ) ;
}
authWarRegionUserIdList . retainAll ( hasRoleUserIdList ) ;
if ( CollectionUtils . isEmpty ( authWarRegionUserIdList ) ) {
if ( CollectionUtils . isEmpty ( authWarRegionUserIdList ) ) {
return fillDefaultUser ( userRoleEnum ) ;
}
authWarRegionUserIdList = authWarRegionUserIdList . stream ( )
@@ -140,6 +142,7 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
/**
* 获取有区域权限和职位 的人
*
* @param userRoleEnum
* @param regionId
* @return
@@ -148,37 +151,60 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
public EnterpriseUserDO getUserByRoleEnumAndRegionId ( UserRoleEnum userRoleEnum , Long regionId ) {
// 查找有区域权限的人
List < String > authRegionUserIdList = authWarRegionUser ( regionId ) ;
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
return null ;
}
Long roleId = userRoleEnum . getCode ( ) ;
List < String > hasRoleUserIdList = sysRoleMapper . getPositionUserIds ( Collections . singletonList ( String . valueOf ( roleId ) ) ) ;
if ( CollectionUtils . isEmpty ( hasRoleUserIdList ) ) {
if ( CollectionUtils . isEmpty ( hasRoleUserIdList ) ) {
return null ;
}
authRegionUserIdList . retainAll ( hasRoleUserIdList ) ;
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
return null ;
}
if ( CollectionUtils . isNotEmpty ( authRegionUserIdList ) ) {
if ( CollectionUtils . isNotEmpty ( authRegionUserIdList ) ) {
EnterpriseUserDO userDO = enterpriseUserDAO . getUserInfoById ( authRegionUserIdList . get ( 0 ) ) ;
return userDO ;
}
return null ;
}
@Override
public List < EnterpriseUserDO > getUserByRoleEnumAndRegionIdList ( UserRoleEnum userRoleEnum , Long regionId ) {
// 查找有区域权限的人
List < String > authRegionUserIdList = authWarRegionUser ( regionId ) ;
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
return null ;
}
Long roleId = userRoleEnum . getCode ( ) ;
List < String > hasRoleUserIdList = sysRoleMapper . getPositionUserIds ( Collections . singletonList ( String . valueOf ( roleId ) ) ) ;
if ( CollectionUtils . isEmpty ( hasRoleUserIdList ) ) {
return null ;
}
authRegionUserIdList . retainAll ( hasRoleUserIdList ) ;
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
return null ;
}
if ( CollectionUtils . isNotEmpty ( authRegionUserIdList ) ) {
return enterpriseUserDAO . getUserInfoByUserIds ( authRegionUserIdList ) ;
}
return null ;
}
private EnterpriseUserDO fillDefaultUser ( UserRoleEnum userRoleEnum ) {
// 如果找不到招商专员,则分配给默认的招商经理
if ( UserRoleEnum . INVESTMENT_COMMISSIONER . equals ( userRoleEnum ) ) {
if ( UserRoleEnum . INVESTMENT_COMMISSIONER . equals ( userRoleEnum ) ) {
EnterpriseUserDO defaultUser = enterpriseUserDAO . getUserInfoByJobnumber ( CommonConstants . DEAULT_INVESTMENT_JOBNUMBER ) ;
if ( defaultUser = = null ) {
if ( defaultUser = = null ) {
defaultUser = enterpriseUserDAO . getUserInfoById ( CommonConstants . DEAULT_INVESTMENT_JOBNUMBER ) ;
}
return defaultUser ;
} else if ( UserRoleEnum . SELECT_SITE_COMMISSIONER . equals ( userRoleEnum ) ) {
} else if ( UserRoleEnum . SELECT_SITE_COMMISSIONER . equals ( userRoleEnum ) ) {
// 如果找不到选址专员,则分配给默认的选址经理
EnterpriseUserDO defaultUser = enterpriseUserDAO . getUserInfoByJobnumber ( CommonConstants . DEAULT_SELECT_SITE_MANAGER ) ;
if ( defaultUser = = null ) {
if ( defaultUser = = null ) {
defaultUser = enterpriseUserDAO . getUserInfoById ( CommonConstants . DEAULT_SELECT_SITE_MANAGER ) ;
}
return defaultUser ;
@@ -188,27 +214,28 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
@Override
public Map < String , List < String > > getUserIdByRoleIdAndRegionId ( List < String > roleIds , Long regionId ) {
if ( CollectionUtils . isEmpty ( roleIds ) | | Objects . isNull ( regionId ) ) {
if ( CollectionUtils . isEmpty ( roleIds ) | | Objects . isNull ( regionId ) ) {
return Maps . newHashMap ( ) ;
}
RegionDO regionDO = regionMapper . getByRegionId ( regionId ) ;
if ( regionDO = = null ) {
if ( regionDO = = null ) {
throw new ServiceException ( ErrorCodeEnum . REGION_NOT_EXIST ) ;
}
// 查找有区域权限的人
List < String > authRegionUserIdList = authWarRegionUser ( regionId ) ;
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
if ( CollectionUtils . isEmpty ( authRegionUserIdList ) ) {
return Maps . newHashMap ( ) ;
}
List < Long > roleIdList = roleIds . stream ( ) . map ( a - > Long . valueOf ( a ) ) . collect ( Collectors . toList ( ) ) ;
List < EnterpriseUserRole > enterpriseUserRoleList = sysRoleMapper . getUserIdListByRoleIdList ( roleIdList ) ;
enterpriseUserRoleList = ListUtils . emptyIfNull ( enterpriseUserRoleList ) . stream ( ) . filter ( o - > authRegionUserIdList . contains ( o . getUserId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
Map < String , List < String > > enterpriseUserRoleMap = ListUtils . emptyIfNull ( enterpriseUserRoleList ) . stream ( ) . collect ( Collectors . groupingBy ( EnterpriseUserRole : : getRoleId , Collectors . mapping ( k - > k . getUserId ( ) , Collectors . toList ( ) ) ) ) ;
Map < String , List < String > > enterpriseUserRoleMap = ListUtils . emptyIfNull ( enterpriseUserRoleList ) . stream ( ) . collect ( Collectors . groupingBy ( EnterpriseUserRole : : getRoleId , Collectors . mapping ( k - > k . getUserId ( ) , Collectors . toList ( ) ) ) ) ;
return enterpriseUserRoleMap ;
}
/**
* 根据 人 查 这个人管辖区域 对应的意向区域省市code 团队线索
*
* @param userId
* @return
*/
@@ -241,22 +268,22 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
// 查找有战区权限的人
public List < String > authWarRegionUser ( Long warRegionId ) {
List < String > result = new ArrayList < > ( ) ;
if ( Objects . isNull ( warRegionId ) ) {
if ( Objects . isNull ( warRegionId ) ) {
return result ;
}
RegionDO regionDO = regionMapper . getByRegionId ( warRegionId ) ;
if ( regionDO = = null ) {
if ( regionDO = = null ) {
throw new ServiceException ( ErrorCodeEnum . REGION_NOT_EXIST ) ;
}
//将拥有管理员角色、角色属性为全企业数据的人查询出来
List < SysRoleVO > roleUserByRoleId = sysRoleMapper . getRoleUserByRoleEnum ( Role . MASTER . getRoleEnum ( ) , null ) ;
List < SysRoleVO > roleUserByRoleAuth = sysRoleMapper . getRoleUserByRoleAuth ( AuthRoleEnum . ALL . getCode ( ) , null ) ;
//组合出拥有所有门店信息的人
List < String > allWarRegionUserIdList = getAllWarRegionAuthUserIdList ( roleUserByRoleId , roleUserByRoleAuth ) ;
List < String > allWarRegionUserIdList = getAllWarRegionAuthUserIdList ( roleUserByRoleId , roleUserByRoleAuth ) ;
//查询出有门店权限配置的的人员
// 1.将门店区域切分出门店所属于的区域ID
// 2.将配置了区域的人 查询出来
List < String > fullAreaIdList = StrUtil . splitTrim ( regionDO . getRegionPath ( ) , " / " ) ;
List < String > fullAreaIdList = StrUtil . splitTrim ( regionDO . getRegionPath ( ) , " / " ) ;
List < String > lastAreaIdList = Collections . singletonList ( String . valueOf ( regionDO . getId ( ) ) ) ;
//除不包含子区域的可视化范围的区域配置。
List < UserAuthMappingDO > regionUserAuthMappingList =
@@ -264,13 +291,13 @@ public class UserAuthMappingServiceImpl implements UserAuthMappingService {
//不包含子区域的的直属连接门店的区域下的配置(会重复一些选择了上面数据)
List < UserAuthMappingDO > notIncludeRegionUserAuthMappingList =
userAuthMappingMapper . listUserAuthMappingByAuth ( UserAuthMappingTypeEnum . REGION . getCode ( ) , lastAreaIdList , null , null ) ;
List < String > authWarRegionUserIdList = mapAuthStoreUserDTO ( regionUserAuthMappingList , allWarRegionUserIdList , notIncludeRegionUserAuthMappingList ) ;
List < String > authWarRegionUserIdList = mapAuthStoreUserDTO ( regionUserAuthMappingList , allWarRegionUserIdList , notIncludeRegionUserAuthMappingList ) ;
return authWarRegionUserIdList ;
}
private List < String > getAllWarRegionAuthUserIdList ( List < SysRoleVO > roleUserByRoleId , List < SysRoleVO > roleUserByRoleAuth ) {
List < String > allUserIdList = new ArrayList < > ( ) ;
List < String > allUserIdList = new ArrayList < > ( ) ;
List < String > masterUserList = ListUtils . emptyIfNull ( roleUserByRoleId ) . stream ( )
. map ( SysRoleVO : : getEnterpriseDOs )
. flatMap ( Collection : : stream )