userService源代码

@Slf4j
@ Service("userService")
public class UserServiceImpl implements UserService{
@ Autowired
private FinTechDataProviderService finTechDataProviderService;
@ Autowired
private UserConfigMapper userConfigMapper;
@ Autowired
private UserDepartmentMapper userDepartmentMapper;
@ Autowired
private UserPermissionServiceImpl userPermissionService;
@ Autowired
private DepartmentServiceImpl departmentService;
@ Autowired
private IndexPatternMapper indexPatternMapper;
@ Autowired
private IndexPatternServiceImpl indexPattemService;
public ListgetUserByNameList( List< String>nameList){
if (CollectionUtils. isEmpty(nameList)){
return new ArrayList<>();
}
Example example = new Example(UserConfig. class);
Example. Criteria criteria = example. createCriteria();
for ( String name : nameList){
criteria. orEqualTo("userName", name);}
return userConfigMapper. selectByExample( example);
}
public UserConfig queryByUserName( String userName){
Example example= new Example(UserConfig. class);
example. createCriteria(). andEqualTo("userName",userName); return userConfigMapper. selectOneByExample( example);
)
@ Transactional(rollbackFor= Exception.class)
public void deleteUser( Long userId){
userConfigMapper. deleteByPrimaryKey(userId);
Example example = new Example(UserDepartment. class);
example. createCriteria(). andEqualTo("userId",userId);
userDepartmentMapper. deleteByExample( example);
return;
}
@ Override
public QueryUserGlobalQueryResponse
isGlobalQuery(QueryUserGlobalQueryRequest request){
String userName= request. getUserName();
QueryUserGlobalQueryResponse response = new
QueryUserGlobalQueryResponse();
if (StringUtils. isEmpty(userName)){
log. error("查询用户全局查询权限请求参数为空");
throw new TitanException("所传参数为空!");
}
UserConfig user= queryByUserName(userName);
if ( user== null){
RespUtils. setError(ErrorCodeEnum. USER_NOT_EXIST, response);
return response;
}
Boolean globalQueryFlag= user. getGlobalQuery();
if (globalQueryFlag && user. getQueryPermanentFlag() != null&&
user. getQueryEffectiveDate()!= null){
if (! user. getQueryPermanentFlag() &&
user. getQueryEffectiveDate(). before( new Date()))
globalQueryFlag= false;
}
response,setGlobalQueryFlag(globalQueryFlag);
response,setEffectiveDate( user. getQueryEffectiveDate());
response. setPermanentFlag( user. getQueryPermanentFlag());
RespUtils. setSuccess( response);
return response;
}
@ Override
public QueryUserIndexPatternResponse
queryIndexPatternByUserName(QueryUserIndexPatternRequest request){
String userName= request. getUserName();
QueryUserIndexPatternResponse response = new
QueryUserIndexPatternResponse();
if (StringUtils. isEmpty(userName)){
log. error("查询用户关联索引请求参数为空");
throw new TitanException("所传参数为空!");
}
UserConfig user= queryByUserName(userName);
if ( user== null) {
RespUtils. setError(ErrorCodeEnum. USER_NOT_EXIST, response);
return response;
}
response. setIndexPatternItemList(indexPatternService. getUserIndexPatternByUserName(userName));
RespUtils. setSuccess( response);
return response;
}
@ Override
public QueryIndicesNoPermissionResponse
queryIndicesNoPermission(QueryIndicesNoPermissionRequest request
String userName= request. getUserName();
QueryIndicesNoPermissionResponse response = new QueryIndicesNoPermissionResponse();
if (StringUtils. isEmpty(userName)){
log. error("查询用户关联索引请求参数为空");
throw new TitanException("所传参数为空!");
}
Example example = new Example(UserConfig. class);
example. createCriteria(). andEqualTo("userName",userName);
UserConfig userConfig = userConfigMapper. selectOneByExample( example);
List< String>userNameList = new ArrayList<>();
userNameList. add(userName);
QueryFinTechUserRequest userRequest= new QueryFinTechUserRequest();
userRequest. setUserNameList(userNameList);
UserInfoResponse userInfoResponse =
finTechDataProviderService. queryFinTechUserInfo(userRequest);
String departmentId= userInfoResponse. getUserList(). get(0). getOrgId();
Department department =
departmentService. getDepartmentById(departmentId);
if((userConfig!= null && userConfig. getGlobalQuery())||( department != null && department. getGlobalQuery())){
response. setErrMsg("用户是全查询用户, 无需申请临时权限! ");
return response;
}
PageHelper. startPage( request. getPageIndex(), request. getLimit());
PageInfo pageInfo = new
PageInfo<>(indexPatternMapper. queryIndicesNoPermission(userName,departmentId, req uest. getIndexName(), request. getSystemIdList(), request. getApplicationName()));
response. setTotal(pageInfo. getTotal());
List indexPatternItemList= new ArrayList<>();
pageInfo. getList(). forEach(indexPattern->{
IndexPatternItem indexPatternItem= new IndexPatternItem();
indexPatternItem. setId(indexPattern. getId());
indexPatternItem. setIndexPatternName(indexPattern. getIndexPattemName());
indexPatternItem. setApplicationName(indexPattern. getApplicationName());
indexPatternItem. setSystemId(indexPattern. getSystemId());
indexPatternItemList. add(indexPatternItem);
});
response. setIndicesList(indexPatternItemList);
response. setSuccess();
return response;
)
@ Transactional(rollbackFor= Exception.class)
@ Override
public AddUserPermissionResponse addUserPermission(AddUserPermissionRequest request){
String userName= request. getUserName();
AddUserPermissionResponse response= new AddUserPermissionResponse();
if (StringUtils. isEmpty(userName) II
CollectionUtils. isEmpty( request. getUserPermissionDTOList())){
log. error("新增用户关联索引请求参数为空");
throw new TitanException("所传参数为空!");
)
UserConfig user= queryByUserName(userName);
if( user== null) {
UserConfig userNew= new UserConfig();
userNew. setUserName(userName);
userNew. setCreateTime( new Date());
userNew. setGlobalQuery( false);
//新增设置默认管理员权限为 false
userNew. setAdministratorFlag( false);
//新增结束
userConfigMapper. insert(userNew);
} else if (isGlobalQuery( new
QueryUserGlobalQueryRequest( request. getUserName())). getGlobalQueryFlag()){
RespUtils. setError(ErrorCodeEnum. USER_ALREADY_GLOBAL_QUERY, response);
return response;
}
// List< Long> indexIdList =
indexPatternService. getIndexPatternIdByNameList(indexPatternNameList);
userPermissionService. addPermissionForUser( request. getUserName(),
request. getUserPermissionDTOList());
RespUtils. setSuccess( response);
return response;
}
@ Transactional(rollbackFor= Exception.class)
@ Override
public DelUserPermissionResponse
deleteUserPermission(DelUserPermissionRequest request){
String userName = request. getUserName();
List< String>indexPatternNameList= request. getIndexPatternNameList();
DelUserPermissionResponse response= new DelUserPermissionResponse();
if (StringUtils. isEmpty(userName) ll
CollectionUtils. isEmpty(indexPatternNameList)) {
log. error("删除用户关联索引请求参数为空");
throw new TitanException("所传参数为空!");
}
List< Long> indexIdList =
indexPatternService. getIndexPatternIdByNameList(indexPattemNameList);
userPermissionService. deleteUserPermissionForUser( request. getUserName(),
indexIdList);
RespUtils. setSuccess( response);
return response;
}
@ Transactional(rollbackFor = Exception.class)
@ Override
public ChangeUserGlobalQueryResponse
changeGlobalQuery(ChangeUserGlobalQueryRequest request){
String userName= request. getUserName();
Boolean globalQuery = request. getGlobalQuery();
if (StringUtils. isEmpty(userName) || globalQuery== null) {
log. error("修改用户全局查询标志请求参数为空");
throw new TitanException("所传参数为空!");
}
if ( request. getGlobalQuery()){
if ( request. getPermanentFlag() == null){
log. error("修改用户全局查询标志请求参数->永久有效期标志字段为空");
throw new TitanException("所传参数为空!");
} else if (! request. getPermanentFlag() && request. getEffectiveDate() == null){
log. error("修改用户全局查询标志请求参数->有效期字段为空");
throw new TitanException("所传参数为空!");
}
}
ChangeUserGlobalQueryResponse response = new
ChangeUserGlobalQueryResponse();
UserConfig user= queryByUserName(userName);
if ( user== null){
UserConfig userNew= new UserConfig();
userNew. setUserName(userName);
userNew. setCreateTime( new Date());
userNew. setUpdateTime( new Date());
userNew. setGlobalQuery( false);
//新增设置默认管理员权限为 false
userNew. setAdministratorFlag( false);
//新增结束
userConfigMapper. insert(userNew);
}
Boolean isGlobalQuery = isGlobalQuery( new
QueryUserGlobalQueryRequest(userName)). getGlobalQueryFlag();
if (isGlobalQuery && !globalQuery){
UserConfig updateUser= new UserConfig();
updateUser. setUserName( request. getUserName());
updateUser. setGlobalQuery( false);
updateUser. setUpdateTime( new Date());
userConfigMapper. updateByPrimaryKeySelective(updateUser);
} else if (!isGlobalQuery && globalQuery) {
UserConfig updateUser= new UserConfig();
updateUser. setUserName( request. getUserName());
updateUser. setGlobalQuery( true);
updateUser. setQueryEffectiveDate( request. getEffectiveDate());
updateUser. setQueryPermanentFlag( request. getPermanentFlag());
updateUser. setUpdateTime( new Date());
userConfigMapper. updateByPrimaryKeySelective(updateUser);
)
RespUtils. setSuccess( response);
return response;
)
public ListgetSpecialPermissionUser( String userName){
ListspecialPermissionUsers= new ArrayList<>();
Example example = new Example(UserConfig. class);
Example. Criteria criteria = example. createCriteria();
if(StringUtils. isNotBlank(userName)){
criteria. andLike("userName", "%"+userName+"%");
}
List userConfigList =
userConfigMapper. selectByExample( example);
if(userConfigList. isEmpty()){
return specialPermissionUsers;
}
List< String> userNameList = new ArrayList<>();
List< String>departmentIdList= new ArrayList<>();
userConfigList. forEach(userConfig - >{
userNameList. add(userConfig. getUserName());
});
QueryFinTechUserRequest userRequest = new QueryFinTechUserRequest();
userRequest. setUserNameList(userNameList);
UserInfoResponse userInfoResponse =
finTechDataProviderService. queryFinTechUserInfo(userRequest);
if( userInfoResponse. getUserList()== null){
userConfigList. forEach(userConfig→{
SpecialPermissionUser user= new SpecialPermissionUser();
user. setUserName(userConfig. getUserName());
if (userConfig. getGlobalQuery()){
user. setSpecialPermission("是");
} else{
user. setSpecialPermission("否");
}
if(userConfig. getIsOfficeAllowLogin()){
user. setIsOfficeAllowLogin("是");
} else{
user. setIsOfficeAllowLogin("否");
}
SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyy-MM-dd HH: mm: ss");
String s="9999-12-31 00:00:00";
Date effDate = userConfig. getQueryEffectiveDate();
if (effDate == null && (userConfig. getQueryPermanentFlag() == null||
userConfig. getQueryPermanentFlag() != true)) {
s="2020-01-01 00:00:00";
}
try{
if (effDate == null || userConfig. getQueryPermanentFlag()) {
effDate= dateFormat. parse(s);
}
} catch (ParseException e){
effDate= new Date();
log. error("查询全局查询团队异常",e);
)
user. setQueryEffectiveDate(effDate);
specialPermissionUsers. add( user);
});
return specialPermissionUsers;
}
userInfoResponse. getUserList(). forEach(userInfo->{
departmentIdList. add(userInfo. getOrgId());
});
QueryFinTechDeptRequest deptRequest= new QueryFinTechDeptRequest();
deptRequest. setDeptIdList(departmentIdList);
DeptInfoResponse deptInfoResponse
finTechDataProviderService. queryFinTechDeptInfo(deptRequest);
userConfigList. forEach(userConfig->{
userInfoResponse. getUserList(). forEach(userInfo->{
if (userConfig. getUserName(). equals(userInfo. getUserName())){
SpecialPermissionUser user= new SpecialPermissionUser();
user. setUserName(userInfo. getUserName());
user. setRealName(userInfo. getUserRealName());
if
(userConfig. getGlobalQuery()!= null&&userConfig. getGlobalQuery()) {
user. setSpecialPermission("是");
} else{
user. setSpecialPermission("否");
}
if(userConfig. getIsOfficeAllowLogin()){
user. setIsOfficeAllowLogin("是");
} else{
user. setIsOfficeAllowLogin("否");
}
deptInfoResponse. getDeptList(). forEach(deptInfo->{
if (userInfo. getOrgId(). equals(deptInfo. getOrgId())) {
user. setDepartmentName(deptInfo. getOrgName());
}
});
SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyy-MM-dd HH: mm: ss");
String s="9999-12-31 00:00:00";
Date effDate = userConfig. getQueryEffectiveDate();
if (effDate == null && (userConfig. getQueryPermanentFlag()
== null || userConfig. getQueryPermanentFlag() != true)){
s="2020-01-01 00:00:00";
}
try{
if (effDate == null || userConfig. getQueryPermanentFlag()) {
effDate= dateFormat. parse(s);
}
} catch (ParseException e){
effDate= new Date();
log. error("查询全局查询团队异常",e);
}
user. setQueryEffectiveDate(effDate);
specialPermissionUsers. add( user);
}
});
});
return specialPermissionUsers;
}
public int getUserCount() {
Example example = new Example(UserConfig. class);
return userConfigMapper. selectCountByExample( example);
}
public void editUserConfig( String userName, Boolean flag){ userConfigMapper. updateByUserName(userName, flag);}
public void addUserConfig( String userNameArrayStr, Boolean flag){ String[] userNameArray= userNameArrayStr. split(";");
for( String userName:userNameArray) {
if(StringUtils. isBlank(userName)){
continue;
}
Example example = new Example(UserConfig. class); example. createCriteria(). andEqualTo("userName", userName); int count = userConfigMapper. selectCountByExample( example); if ( count ==0){
UserConfig userConfig= new UserConfig();
userConfig. setAuditAllUserFlag( false);
userConfig. setAdministratorFlag( false);
userConfig. setCreateTime( new Date());
userConfig. setGlobalQuery( false);
userConfig. setIsOfficeAllowLogin( flag);
userConfig. setQueryEffectiveDate( new Date());
userConfig. setQueryPermanentFlag( false);
userConfig. setUpdateTime( new Date());
userConfig. setUserName(userName);
userConfigMapper. insert(userConfig);
} else{
userConfigMapper. updateByUserName(userName, flag);
}
}
}
}

posted @ 2024-11-17 11:40  一曲微茫  阅读(5)  评论(0编辑  收藏  举报