@ -39,6 +39,7 @@ import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.OperCrmFeignClient ;
import com.epmet.redis.CustomerAgencyRedis ;
import com.epmet.service.CustomerAgencyService ;
import com.epmet.util.ModuleConstant ;
import org.apache.commons.lang3.StringUtils ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
@ -46,6 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import java.lang.reflect.Field ;
import java.util.* ;
import java.util.concurrent.atomic.AtomicBoolean ;
import java.util.stream.Collectors ;
@ -834,4 +836,109 @@ public class CustomerAgencyServiceImpl extends BaseServiceImpl<CustomerAgencyDao
}
/ * *
* @Description 查询工作人员的信息 , 多客户 / 单客户 , epmet - plugin , 对外开放调用
* @param result
* @return
* @author wangc
* @date 2020 . 08 . 17 09 : 29
* * /
@Override
public ExtStaffInfoResultDTO staffInfoExt ( ExtStaffInfoResultDTO result ) {
//1.查找对应的所属关系,通过最近一次登陆的网格,通过网格查找对应的机关和客户
ExtStaffInfoResultDTO orgInfo =
baseDao . selectAgencyAndGridInfoExt ( result . getGridId ( ) ) ;
mergeObject ( orgInfo , result ) ;
//2.查找客户名称
CustomerDTO customerParam = new CustomerDTO ( ) ;
customerParam . setId ( result . getCustomerId ( ) ) ;
Result < CustomerDTO > customerResult =
operCrmFeignClient . getCustomerInfo ( customerParam ) ;
if ( customerResult . success ( ) & & null ! = customerResult . getData ( ) ) {
result . setCustomerName ( customerResult . getData ( ) . getCustomerName ( ) ) ;
}
checkFieldAndSetDefault ( result ) ;
result . setAdminFlag ( NumConstant . ZERO_STR ) ;
if ( null ! = result . getRoleList ( ) & & ! result . getRoleList ( ) . isEmpty ( ) ) {
result . getRoleList ( ) . forEach ( o - > {
if ( StringUtils . equals ( "root_manager" , o . getRoleKey ( ) ) ) {
result . setAdminFlag ( NumConstant . ONE_STR ) ;
}
} ) ;
}
return result ;
}
/ * *
* @Description 根据staffId , 查询当前这个用户的数据权限
* @param staffId
* @return
* @author wangc
* @date 2020 . 08 . 17 17 : 30
* * /
@Override
public ExtStaffPermissionResultDTO staffPermissionExt ( String staffId ) {
//1.通过staffId去user服务查询最近一次登陆的agencyId
Result < String > agency =
epmetUserOpenFeignClient . latestAgency ( staffId ) ;
if ( agency . success ( ) & & StringUtils . isNotBlank ( agency . getData ( ) ) ) {
//2.根据此agencyId查询数据权限
ExtStaffPermissionResultDTO res = baseDao . selectAgencyById ( agency . getData ( ) ) ;
return res ;
} else {
logger . error ( "com.epmet.service.impl.CustomerAgencyServiceImpl.staffPermissionExt,没有找到工作人员最近一次登陆的Agency信息,用户Id:{}" , staffId ) ;
ExtStaffPermissionResultDTO emptyResult = new ExtStaffPermissionResultDTO ( ) ;
checkFieldAndSetDefault ( emptyResult ) ;
return emptyResult ;
}
}
public < T > void mergeObject ( T origin , T destination ) {
if ( origin = = null | | destination = = null )
return ;
if ( ! origin . getClass ( ) . equals ( destination . getClass ( ) ) )
return ;
Field [ ] fields = origin . getClass ( ) . getDeclaredFields ( ) ;
for ( int i = 0 ; i < fields . length ; i + + ) {
try {
fields [ i ] . setAccessible ( true ) ;
Object value = fields [ i ] . get ( origin ) ;
if ( null ! = value ) {
fields [ i ] . set ( destination , value ) ;
}
fields [ i ] . setAccessible ( false ) ;
} catch ( Exception e ) {
}
}
}
public < T > void checkFieldAndSetDefault ( T origin ) {
if ( origin = = null )
return ;
Field [ ] fields = origin . getClass ( ) . getDeclaredFields ( ) ;
for ( int i = 0 ; i < fields . length ; i + + ) {
try {
fields [ i ] . setAccessible ( true ) ;
Object value = fields [ i ] . get ( origin ) ;
if ( null = = value & & value . getClass ( ) . getName ( ) . equals ( "java.lang.String" ) ) {
fields [ i ] . set ( origin , ModuleConstant . EMPTY_STR ) ;
}
fields [ i ] . setAccessible ( false ) ;
} catch ( Exception e ) {
}
}
}
}