@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 List
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<>(indexPatternMapper. queryIndicesNoPermission(userName,departmentId, req uest. getIndexName(), request. getSystemIdList(), request. getApplicationName()));
response. setTotal(pageInfo. getTotal());
List
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 List
List
Example example = new Example(UserConfig. class);
Example. Criteria criteria = example. createCriteria();
if(StringUtils. isNotBlank(userName)){
criteria. andLike("userName", "%"+userName+"%");
}
List
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);
}
}
}
}
userService原始碼
相關文章
- 原始碼原始碼原始碼樹品原始碼原始碼
- UserService 新增使用者關聯索引 addUserPermission 分析索引
- UserService 修改使用者查詢許可權 changeGlobalQuery分析
- UserService 刪除使用者查詢許可權 deleteUserPermission分析delete
- UserService 查詢使用者查詢許可權 isGlobalQuery分析
- Spring原始碼分析——搭建spring原始碼Spring原始碼
- ReactNative原始碼解析-初識原始碼React原始碼
- Retrofit原始碼分析三 原始碼分析原始碼
- 程式包 applets.user.service.UserService 不存在-2022新專案APP
- 【JDK原始碼分析系列】ArrayBlockingQueue原始碼分析JDK原始碼BloC
- Flutter 原始碼系列:DropdownButton 原始碼淺析Flutter原始碼
- 【原始碼閱讀】AndPermission原始碼閱讀原始碼
- 【Tomcat 原始碼系列】原始碼構建 TomcatTomcat原始碼
- 集合原始碼分析[2]-AbstractList 原始碼分析原始碼
- 集合原始碼分析[3]-ArrayList 原始碼分析原始碼
- 原始碼|jdk原始碼之HashMap分析(一)原始碼JDKHashMap
- 原始碼|jdk原始碼之HashMap分析(二)原始碼JDKHashMap
- 集合原始碼分析[1]-Collection 原始碼分析原始碼
- Android 原始碼分析之 AsyncTask 原始碼分析Android原始碼
- Guava 原始碼分析之 EventBus 原始碼分析Guava原始碼
- Java集合原始碼剖析——ArrayList原始碼剖析Java原始碼
- 5.2 spring5原始碼--spring AOP原始碼分析三---切面原始碼分析Spring原始碼
- 原始碼補碼反碼原始碼
- Java容器原始碼學習--ArrayList原始碼分析Java原始碼
- ElementUI 原始碼簡析——原始碼結構篇UI原始碼
- Axios 原始碼解讀 —— 原始碼實現篇iOS原始碼
- 【Redis原始碼】Redis 6 ACL原始碼詳解Redis原始碼
- 【原始碼SOLO】Retrofit2原始碼解析(一)原始碼
- Vue原始碼探究-原始碼檔案組織Vue原始碼
- 死磕 jdk原始碼之HashMap原始碼分析JDK原始碼HashMap
- Spring原始碼之IOC(一)BeanDefinition原始碼解析Spring原始碼Bean
- 以太坊原始碼分析(36)ethdb原始碼分析原始碼
- 以太坊原始碼分析(38)event原始碼分析原始碼
- 以太坊原始碼分析(41)hashimoto原始碼分析原始碼
- 以太坊原始碼分析(43)node原始碼分析原始碼
- 以太坊原始碼分析(51)rpc原始碼分析原始碼RPC
- 以太坊原始碼分析(52)trie原始碼分析原始碼
- vuex 原始碼:原始碼系列解讀總結Vue原始碼