优化代码

pull/63/MERGE
awenes 2023-10-01 22:06:36 +08:00
parent 04f165a450
commit d19448d113
17 changed files with 29 additions and 953 deletions

View File

@ -1,227 +0,0 @@
/*
* eiam-common - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.common.entity.account;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.Setting;
import cn.topiam.employee.common.entity.account.po.OrganizationPO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import jakarta.persistence.Column;
import static org.springframework.data.elasticsearch.annotations.DateFormat.date;
import static org.springframework.data.elasticsearch.annotations.DateFormat.date_hour_minute_second_millis;
/**
* elasticsearch
*
* @author TopIAM
* Created by support@topiam.cn on 2023/4/12 23:22
*/
@Data
@Builder
@EqualsAndHashCode
@Document(indexName = "#{@userIndexName.getIndexName()}")
@Setting(replicas = 0)
public class UserElasticSearchEntity implements Serializable {
/**
* userId
*/
@Id
@Field(type = FieldType.Keyword, name = "id")
private String id;
/**
*
*/
@Field(type = FieldType.Keyword, name = "username")
private String username;
/**
*
*/
@Field(type = FieldType.Keyword, name = "email")
private String email;
/**
*
*/
@Field(type = FieldType.Keyword, name = "phone")
private String phone;
/**
*
*/
@Field(type = FieldType.Keyword, name = "phoneAreaCode")
private String phoneAreaCode;
/**
*
*/
@Field(type = FieldType.Keyword, name = "fullName")
private String fullName;
/**
*
*/
@Field(type = FieldType.Keyword, name = "nickName")
private String nickName;
/**
* URL
*/
@Field(type = FieldType.Keyword, name = "avatar")
private String avatar;
/**
* ENABLE: DISABLE: LOCKING:
*/
@Field(type = FieldType.Keyword, name = "status")
private String status;
/**
*
*/
@Field(type = FieldType.Keyword, name = "dataOrigin")
private String dataOrigin;
/**
* ID
*/
@Field(type = FieldType.Keyword, name = "identitySourceId")
private Long identitySourceId;
/**
*
*/
@Field(type = FieldType.Keyword, name = "emailVerified")
private Boolean emailVerified;
/**
*
*/
@Field(type = FieldType.Keyword, name = "phoneVerified")
private Boolean phoneVerified;
/**
*
*/
@Field(type = FieldType.Keyword, name = "authTotal")
private Long authTotal;
/**
* IP
*/
@Field(type = FieldType.Keyword, name = "lastAuthIp")
private String lastAuthIp;
/**
*
*/
@Field(type = FieldType.Date, name = "lastAuthTime", format = date_hour_minute_second_millis)
private LocalDateTime lastAuthTime;
/**
*
*/
@Column(name = "expand_")
private String expand;
/**
* ID
*/
@Column(name = "external_id")
private String externalId;
/**
*
*/
@Field(type = FieldType.Date, name = "expireDate", format = date)
private LocalDate expireDate;
/**
*
*/
@Field(type = FieldType.Date, name = "lastUpdatePasswordTime", format = date_hour_minute_second_millis)
private LocalDateTime lastUpdatePasswordTime;
// ----------------------------------用户详情----------------------------------
/**
*
*/
@Field(type = FieldType.Keyword, name = "idType")
private String idType;
/**
*
*/
@Field(type = FieldType.Keyword, name = "idCard")
private String idCard;
/**
*
*/
@Field(type = FieldType.Text, name = "website")
private String website;
/**u
*
*/
@Field(type = FieldType.Keyword, name = "address")
private String address;
/**
*
*/
@Field(type = FieldType.Object, name = "organizations")
private List<OrganizationPO> organizations;
/**
*
*/
@Field(type = FieldType.Object, name = "userGroups")
private List<UserGroup> userGroups;
@Data
@AllArgsConstructor
public static class UserGroup {
/**
* id
*/
@Field(type = FieldType.Keyword, name = "id")
private String id;
/**
*
*/
@Field(type = FieldType.Keyword, name = "name")
private String name;
}
}

View File

@ -1,71 +0,0 @@
/*
* eiam-common - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.common.entity.account.po;
import java.io.Serial;
import java.util.Map;
import java.util.Set;
import cn.topiam.employee.common.entity.account.UserEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* PO
*
* @author TopIAM
* Created by support@topiam.cn on 2022/2/10 22:46
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class UserEsPO extends UserEntity {
@Serial
private static final long serialVersionUID = 2330202241972458786L;
/**
*
*/
private String idType;
/**
*
*/
private String idCard;
/**
*
*/
private String website;
/**
*
*/
private String address;
/**
* id
*/
private Set<String> organizationIds;
/**
*
*/
private Map<String, String> userGroups;
}

View File

@ -30,7 +30,7 @@ import lombok.EqualsAndHashCode;
*/ */
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
public class UserIdpBindPo extends UserIdpBindEntity { public class UserIdpBindPO extends UserIdpBindEntity {
/** /**
* *

View File

@ -1,35 +0,0 @@
/*
* eiam-common - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.common.repository.account;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
import cn.topiam.employee.common.entity.account.UserElasticSearchEntity;
/**
* repository
*
* @author TopIAM
* Created by support@topiam.cn on 2021/9/11 22:32
*/
@Repository
public interface UserElasticSearchRepository extends
ElasticsearchRepository<UserElasticSearchEntity, String> {
}

View File

@ -19,7 +19,7 @@ package cn.topiam.employee.common.repository.account;
import java.util.Optional; import java.util.Optional;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
import cn.topiam.employee.support.repository.page.domain.Page; import cn.topiam.employee.support.repository.page.domain.Page;
/** /**
@ -37,7 +37,7 @@ public interface UserIdpRepositoryCustomized {
* @param openId {@link String} * @param openId {@link String}
* @return {@link Optional} * @return {@link Optional}
*/ */
Optional<UserIdpBindPo> findByIdpIdAndOpenId(String idpId, String openId); Optional<UserIdpBindPO> findByIdpIdAndOpenId(String idpId, String openId);
/** /**
* IDuserId * IDuserId
@ -46,7 +46,7 @@ public interface UserIdpRepositoryCustomized {
* @param userId {@link String} * @param userId {@link String}
* @return {@link Optional} * @return {@link Optional}
*/ */
Optional<UserIdpBindPo> findByIdpIdAndUserId(String idpId, Long userId); Optional<UserIdpBindPO> findByIdpIdAndUserId(String idpId, Long userId);
/** /**
* *
@ -54,5 +54,5 @@ public interface UserIdpRepositoryCustomized {
* @param userId {@link Long} * @param userId {@link Long}
* @return {@link Page} * @return {@link Page}
*/ */
Iterable<UserIdpBindPo> getUserIdpBindList(Long userId); Iterable<UserIdpBindPO> getUserIdpBindList(Long userId);
} }

View File

@ -21,17 +21,12 @@ import java.util.List;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import cn.topiam.employee.common.entity.account.UserElasticSearchEntity;
import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.entity.account.UserEntity;
import cn.topiam.employee.common.entity.account.po.UserEsPO;
import cn.topiam.employee.common.entity.account.po.UserPO; import cn.topiam.employee.common.entity.account.po.UserPO;
import cn.topiam.employee.common.entity.account.query.UserListNotInGroupQuery; import cn.topiam.employee.common.entity.account.query.UserListNotInGroupQuery;
import cn.topiam.employee.common.entity.account.query.UserListQuery; import cn.topiam.employee.common.entity.account.query.UserListQuery;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
/** /**
* User Repository Customized * User Repository Customized
* *
@ -107,29 +102,4 @@ public interface UserRepositoryCustomized {
*/ */
void batchUpdate(List<UserEntity> list); void batchUpdate(List<UserEntity> list);
/**
*
*
* @param idList {@link List}
* @return {@link List}
*/
List<UserEsPO> getUserList(List<String> idList);
/**
* es
*
* @param userIndex {@link IndexCoordinates}
* @return {@link List}
*/
List<UserElasticSearchEntity> getAllUserElasticSearchEntity(IndexCoordinates userIndex);
/**
* es
*
* @param userIndex {@link IndexCoordinates}
* @param queryBuilder {@link Query}
* @return {@link List}
*/
List<UserElasticSearchEntity> getAllUserElasticSearchEntity(IndexCoordinates userIndex,
Query queryBuilder);
} }

View File

@ -26,7 +26,7 @@ import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
import cn.topiam.employee.common.repository.account.UserIdpRepositoryCustomized; import cn.topiam.employee.common.repository.account.UserIdpRepositoryCustomized;
import cn.topiam.employee.common.repository.account.impl.mapper.UserIdpBindPoMapper; import cn.topiam.employee.common.repository.account.impl.mapper.UserIdpBindPoMapper;
import cn.topiam.employee.support.repository.page.domain.Page; import cn.topiam.employee.support.repository.page.domain.Page;
@ -53,7 +53,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi
* @return {@link Optional} * @return {@link Optional}
*/ */
@Override @Override
public Optional<UserIdpBindPo> findByIdpIdAndOpenId(String idpId, String openId) { public Optional<UserIdpBindPO> findByIdpIdAndOpenId(String idpId, String openId) {
//@formatter:off //@formatter:off
StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' ");
//身份提供商ID //身份提供商ID
@ -67,7 +67,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi
//@formatter:on //@formatter:on
String sql = builder.toString(); String sql = builder.toString();
try { try {
UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, UserIdpBindPO userIdpBindPo = jdbcTemplate.queryForObject(sql,
new UserIdpBindPoMapper()); new UserIdpBindPoMapper());
return Optional.ofNullable(userIdpBindPo); return Optional.ofNullable(userIdpBindPo);
} catch (EmptyResultDataAccessException e) { } catch (EmptyResultDataAccessException e) {
@ -83,7 +83,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi
* @return {@link Optional} * @return {@link Optional}
*/ */
@Override @Override
public Optional<UserIdpBindPo> findByIdpIdAndUserId(String idpId, Long userId) { public Optional<UserIdpBindPO> findByIdpIdAndUserId(String idpId, Long userId) {
//@formatter:off //@formatter:off
StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); StringBuilder builder = new StringBuilder("SELECT uidp.*,`user`.username_,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN `user` ON uidp.user_id = `user`.id_ AND `user`.is_deleted = '0' LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' ");
//身份提供商ID //身份提供商ID
@ -97,7 +97,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi
//@formatter:on //@formatter:on
String sql = builder.toString(); String sql = builder.toString();
try { try {
UserIdpBindPo userIdpBindPo = jdbcTemplate.queryForObject(sql, UserIdpBindPO userIdpBindPo = jdbcTemplate.queryForObject(sql,
new UserIdpBindPoMapper()); new UserIdpBindPoMapper());
return Optional.ofNullable(userIdpBindPo); return Optional.ofNullable(userIdpBindPo);
} catch (EmptyResultDataAccessException e) { } catch (EmptyResultDataAccessException e) {
@ -112,7 +112,7 @@ public class UserIdpRepositoryCustomizedImpl implements UserIdpRepositoryCustomi
* @return {@link Page} * @return {@link Page}
*/ */
@Override @Override
public Iterable<UserIdpBindPo> getUserIdpBindList(Long userId) { public Iterable<UserIdpBindPO> getUserIdpBindList(Long userId) {
//@formatter:off //@formatter:off
StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' "); StringBuilder builder = new StringBuilder("SELECT uidp.*,idp.name_ as idp_name FROM user_idp_bind uidp LEFT JOIN identity_provider idp ON uidp.idp_id = idp.id_ AND idp.is_deleted = '0' WHERE uidp.is_deleted = '0' ");
//用户ID //用户ID

View File

@ -21,7 +21,6 @@ import java.sql.Date;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -31,34 +30,21 @@ import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate; import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.client.elc.NativeQuery;
import org.springframework.data.elasticsearch.client.elc.NativeQueryBuilder;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHitsIterator;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.jdbc.core.BatchPreparedStatementSetter; import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import cn.topiam.employee.common.entity.account.UserElasticSearchEntity;
import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.entity.account.UserEntity;
import cn.topiam.employee.common.entity.account.po.UserEsPO;
import cn.topiam.employee.common.entity.account.po.UserPO; import cn.topiam.employee.common.entity.account.po.UserPO;
import cn.topiam.employee.common.entity.account.query.UserListNotInGroupQuery; import cn.topiam.employee.common.entity.account.query.UserListNotInGroupQuery;
import cn.topiam.employee.common.entity.account.query.UserListQuery; import cn.topiam.employee.common.entity.account.query.UserListQuery;
import cn.topiam.employee.common.repository.account.UserRepositoryCustomized; import cn.topiam.employee.common.repository.account.UserRepositoryCustomized;
import cn.topiam.employee.common.repository.account.impl.mapper.UserEntityMapper; import cn.topiam.employee.common.repository.account.impl.mapper.UserEntityMapper;
import cn.topiam.employee.common.repository.account.impl.mapper.UserEsMapper;
import cn.topiam.employee.common.repository.account.impl.mapper.UserPoMapper; import cn.topiam.employee.common.repository.account.impl.mapper.UserPoMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import static cn.topiam.employee.common.constant.AccountConstants.USER_CACHE_NAME; import static cn.topiam.employee.common.constant.AccountConstants.USER_CACHE_NAME;
/** /**
@ -362,120 +348,6 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized {
//@formatter:on //@formatter:on
} }
@Override
public List<UserEsPO> getUserList(List<String> idList) {
//@formatter:off
String whereUserId = "";
if (!CollectionUtils.isEmpty(idList)) {
if (idList.size() > 1) {
whereUserId = "AND `user`.id_ IN ('%s')".formatted(String.join("','", idList));
}
else {
whereUserId = "AND `user`.id_ = '%s'".formatted(idList.get(0));
}
}
String sql = """
SELECT
`user`.id_,
`user`.username_,
`user`.email_,
`user`.phone_,
`user`.phone_area_code,
`user`.full_name,
`user`.nick_name,
`user`.avatar_,
`user`.status_,
`user`.data_origin,
`user`.email_verified,
`user`.phone_verified,
`user`.auth_total,
`user`.last_auth_ip,
`user`.last_auth_time,
`user`.expand_,
`user`.external_id,
`user`.expire_date,
`user`.create_by,
`user`.create_time,
`user`.update_by,
`user`.update_time,
`user`.remark_,
`user`.identity_source_id,
`user`.last_update_password_time,
`user_detail`.id_type,
`user_detail`.id_card,
`user_detail`.website_,
`user_detail`.address_,
GROUP_CONCAT( DISTINCT `organization_member`.org_id SEPARATOR ',' ) AS organization_ids,
CONCAT( '{', GROUP_CONCAT( DISTINCT CONCAT( '"', user_group.id_, '": "', user_group.name_, '"' ) SEPARATOR ',' ), '}' ) AS user_groups
FROM
`user`
LEFT JOIN `user_detail` ON `user`.id_ = user_detail.user_id
AND user_detail.is_deleted = '0'
LEFT JOIN `organization_member` ON `user`.id_ = organization_member.user_id
AND organization_member.is_deleted = '0'
LEFT JOIN `user_group_member` ON `user`.id_ = user_group_member.user_id
AND user_group_member.is_deleted = '0'
LEFT JOIN `user_group` ON `user_group`.id_ = user_group_member.group_id
AND user_group.is_deleted = '0'
WHERE
`user`.is_deleted = 0 %s
GROUP BY
`user`.id_,
`user`.username_,
`user`.email_,
`user`.phone_,
`user`.phone_area_code,
`user`.full_name,
`user`.nick_name,
`user`.avatar_,
`user`.status_,
`user`.data_origin,
`user`.email_verified,
`user`.phone_verified,
`user`.auth_total,
`user`.last_auth_ip,
`user`.last_auth_time,
`user`.expand_,
`user`.external_id,
`user`.expire_date,
`user`.create_by,
`user`.create_time,
`user`.update_by,
`user`.update_time,
`user`.remark_,
`user`.identity_source_id,
`user`.last_update_password_time
""".formatted(whereUserId);
//@formatter:on
return jdbcTemplate.query(sql, new UserEsMapper());
}
@Override
public List<UserElasticSearchEntity> getAllUserElasticSearchEntity(IndexCoordinates userIndex) {
return getAllUserElasticSearchEntity(userIndex,
QueryBuilders.matchAll().build()._toQuery());
}
@Override
public List<UserElasticSearchEntity> getAllUserElasticSearchEntity(IndexCoordinates userIndex,
Query query) {
if (!elasticsearchTemplate.indexOps(userIndex).exists()) {
return null;
}
NativeQuery searchQuery = new NativeQueryBuilder().withQuery(query)
// 设置每页数据量
.withPageable(PageRequest.of(0, 2000)).build();
List<UserElasticSearchEntity> userElasticSearchEntityList = new ArrayList<>();
SearchHitsIterator<UserElasticSearchEntity> searchScrollHits = elasticsearchTemplate
.searchForStream(searchQuery, UserElasticSearchEntity.class, userIndex);
while (searchScrollHits.hasNext()) {
SearchHit<UserElasticSearchEntity> next = searchScrollHits.next();
userElasticSearchEntityList.add(next.getContent());
}
return userElasticSearchEntityList;
}
/** /**
* JdbcTemplate * JdbcTemplate
*/ */

View File

@ -1,111 +0,0 @@
/*
* eiam-common - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.common.repository.account.impl.mapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.NonNull;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import cn.topiam.employee.common.entity.account.po.UserEsPO;
import cn.topiam.employee.common.enums.DataOrigin;
import cn.topiam.employee.common.enums.UserStatus;
import lombok.extern.slf4j.Slf4j;
/**
* @author TopIAM
* Created by support@topiam.cn on 2023/5/30 22:25
*/
@Slf4j
public class UserEsMapper implements RowMapper<UserEsPO> {
/**
* Implementations must implement this method to map each row of data
* in the ResultSet. This method should not call {@code next()} on
* the ResultSet; it is only supposed to map values of the current row.
*
* @param rs the ResultSet to map (pre-initialized for the current row)
* @param rowNum the number of the current row
* @return the result object for the current row (may be {@code null})
* @throws SQLException if an SQLException is encountered getting
* column values (that is, there's no need to catch SQLException)
*/
@Override
public UserEsPO mapRow(@NonNull ResultSet rs, int rowNum) throws SQLException {
//@formatter:off
UserEsPO user = new UserEsPO();
user.setId(rs.getLong("id_"));
user.setUsername(rs.getString("username_"));
user.setEmail(rs.getString("email_"));
user.setPhone(rs.getString("phone_"));
user.setPhoneAreaCode(rs.getString("phone_area_code"));
user.setFullName(rs.getString("full_name"));
user.setNickName(rs.getString("nick_name"));
user.setAvatar(rs.getString("avatar_"));
user.setStatus(UserStatus.getStatus(rs.getString("status_")));
user.setDataOrigin(DataOrigin.getType(rs.getString("data_origin")));
user.setEmailVerified(rs.getBoolean("email_verified"));
user.setAuthTotal(rs.getLong("auth_total"));
user.setLastAuthIp(rs.getString("last_auth_ip"));
user.setLastAuthTime(ObjectUtils.isNotEmpty(rs.getTimestamp("last_auth_time")) ? rs.getTimestamp("last_auth_time").toLocalDateTime() : null);
user.setExpand(rs.getString("expand_"));
user.setExternalId(rs.getString("external_id"));
user.setIdentitySourceId(rs.getLong("identity_source_id"));
user.setExpireDate(ObjectUtils.isNotEmpty(rs.getTimestamp("expire_date")) ? rs.getDate("expire_date").toLocalDate() : null);
user.setLastAuthTime(ObjectUtils.isNotEmpty(rs.getTimestamp("last_auth_time")) ? rs.getTimestamp("last_auth_time").toLocalDateTime() : null);
user.setCreateBy(rs.getString("create_by"));
user.setCreateTime(ObjectUtils.isNotEmpty(rs.getTimestamp("create_time")) ? rs.getTimestamp("create_time").toLocalDateTime() : null);
user.setUpdateBy(rs.getString("update_by"));
user.setUpdateTime(ObjectUtils.isNotEmpty(rs.getTimestamp("update_time")) ? rs.getTimestamp("update_time").toLocalDateTime() : null);
user.setRemark(rs.getString("remark_"));
user.setLastUpdatePasswordTime(ObjectUtils.isNotEmpty(rs.getTimestamp("last_update_password_time")) ? rs.getTimestamp("last_update_password_time").toLocalDateTime() : null);
// 额外数据
user.setIdType(rs.getString("id_type"));
user.setIdCard(rs.getString("id_card"));
user.setWebsite(rs.getString("website_"));
user.setAddress(rs.getString("address_"));
String organizationIds = rs.getString("organization_ids");
if (StringUtils.isNotBlank(organizationIds)) {
user.setOrganizationIds(Set.of((organizationIds.split(","))));
}
ObjectMapper objectMapper = new ObjectMapper();
String userGroups = rs.getString("user_groups");
if (StringUtils.isNotBlank(userGroups)) {
Map<String, String> userGroupMap;
try {
userGroupMap = objectMapper.readValue(userGroups, new TypeReference<>() {
});
} catch (JsonProcessingException e) {
log.error("解析用户组字段json异常:[{}]", e.getMessage());
throw new RuntimeException(e);
}
user.setUserGroups(userGroupMap);
}
return user;
//@formatter:on
}
}

View File

@ -24,14 +24,14 @@ import org.apache.commons.lang3.ObjectUtils;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
/** /**
* @author TopIAM * @author TopIAM
* Created by support@topiam.cn on 2022/2/13 22:25 * Created by support@topiam.cn on 2022/2/13 22:25
*/ */
@SuppressWarnings("DuplicatedCode") @SuppressWarnings("DuplicatedCode")
public class UserIdpBindPoMapper implements RowMapper<UserIdpBindPo> { public class UserIdpBindPoMapper implements RowMapper<UserIdpBindPO> {
/** /**
* Implementations must implement this method to map each row of data * Implementations must implement this method to map each row of data
* in the ResultSet. This method should not call {@code next()} on * in the ResultSet. This method should not call {@code next()} on
@ -44,9 +44,9 @@ public class UserIdpBindPoMapper implements RowMapper<UserIdpBindPo> {
* column values (that is, there's no need to catch SQLException) * column values (that is, there's no need to catch SQLException)
*/ */
@Override @Override
public UserIdpBindPo mapRow(@NonNull ResultSet rs, int rowNum) throws SQLException { public UserIdpBindPO mapRow(@NonNull ResultSet rs, int rowNum) throws SQLException {
//@formatter:off //@formatter:off
UserIdpBindPo userIdpBindPo = new UserIdpBindPo(); UserIdpBindPO userIdpBindPo = new UserIdpBindPO();
userIdpBindPo.setId(rs.getLong("id_")); userIdpBindPo.setId(rs.getLong("id_"));
userIdpBindPo.setUserId(rs.getLong("user_id")); userIdpBindPo.setUserId(rs.getLong("user_id"));
userIdpBindPo.setOpenId(rs.getString("open_id")); userIdpBindPo.setOpenId(rs.getString("open_id"));

View File

@ -22,7 +22,7 @@ import java.util.List;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
import cn.topiam.employee.console.pojo.result.app.UserIdpBindListResult; import cn.topiam.employee.console.pojo.result.app.UserIdpBindListResult;
import cn.topiam.employee.support.repository.page.domain.Page; import cn.topiam.employee.support.repository.page.domain.Page;
@ -41,9 +41,9 @@ public interface UserIdpBindConverter {
* @param page {@link Page} * @param page {@link Page}
* @return {@link Page} * @return {@link Page}
*/ */
default List<UserIdpBindListResult> userIdpBindEntityConvertToUserIdpBindListResult(Iterable<UserIdpBindPo> page) { default List<UserIdpBindListResult> userIdpBindEntityConvertToUserIdpBindListResult(Iterable<UserIdpBindPO> page) {
List<UserIdpBindListResult> list = new ArrayList<>(); List<UserIdpBindListResult> list = new ArrayList<>();
for (UserIdpBindPo entity : page) { for (UserIdpBindPO entity : page) {
list.add(entityConvertToAppAccountResult(entity)); list.add(entityConvertToAppAccountResult(entity));
} }
return list; return list;
@ -52,8 +52,8 @@ public interface UserIdpBindConverter {
/** /**
* *
* *
* @param userIdpBindPo {@link UserIdpBindPo} * @param userIdpBindPo {@link UserIdpBindPO}
* @return {@link UserIdpBindListResult} * @return {@link UserIdpBindListResult}
*/ */
UserIdpBindListResult entityConvertToAppAccountResult(UserIdpBindPo userIdpBindPo); UserIdpBindListResult entityConvertToAppAccountResult(UserIdpBindPO userIdpBindPo);
} }

View File

@ -1,202 +0,0 @@
/*
* eiam-core - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.core.mq;
import java.io.IOException;
import java.util.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import com.rabbitmq.client.Channel;
import cn.topiam.employee.common.entity.account.UserElasticSearchEntity;
import cn.topiam.employee.common.entity.account.po.UserEsPO;
import cn.topiam.employee.common.repository.account.OrganizationRepository;
import cn.topiam.employee.common.repository.account.UserElasticSearchRepository;
import cn.topiam.employee.common.repository.account.UserRepository;
import lombok.extern.slf4j.Slf4j;
import static cn.topiam.employee.core.mq.AbstractMessagePublisher.USER_DELETE;
import static cn.topiam.employee.core.mq.AbstractMessagePublisher.USER_SAVE;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/5/30 23:12
*/
@Slf4j
@Component
public class UserMessageListener extends AbstractMessageListener {
/**
*
*
* @param message {@link Message}
* @param channel {@link Channel}
* @param body {@link String}
* @param headers {@link Map}
*/
@Override
@RabbitListener(queues = { USER_SAVE, USER_DELETE }, ackMode = "MANUAL")
@RabbitHandler()
public void onMessage(Message message, Channel channel, @Payload String body,
@Headers Map<String, Object> headers) throws IOException {
super.onMessage(message, channel, body, headers);
log.info("异步接收ES用户信息入参: [{}]", message);
syncUser(message, channel, body);
}
/**
*
*
* @param message {@link Message}
* @param channel {@link Channel}
* @param body {@link String}
*/
private void syncUser(Message message, Channel channel, String body) {
try {
// 处理消息逻辑
String queueName = message.getMessageProperties().getConsumerQueue();
if (!StringUtils.hasText(body)) {
log.warn("接收用户消息内容为空:[{}]", message.getMessageProperties().getDeliveryTag());
return;
}
log.info("接收用户消息:[{}]", body);
List<String> idList = Arrays.asList(body.split(","));
if (queueName.equals(USER_SAVE)) {
List<UserEsPO> userList = userRepository.getUserList(idList);
List<UserElasticSearchEntity> userElasticSearchEntity = getUserElasticSearchEntity(
userList, organizationRepository);
userElasticSearchRepository.saveAll(userElasticSearchEntity);
} else if (queueName.equals(USER_DELETE)) {
userElasticSearchRepository.deleteAllById(idList);
}
log.info("同步用户数据成功:[{}]", message.getMessageProperties().getDeliveryTag());
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
} catch (Exception e) {
log.error("处理用户数据失败出现异常: MessageProperties: [{}], 用户ID:[{}], Error:[{}]",
message.getMessageProperties(), body, e.getMessage(), e);
try {
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
} catch (IOException exception) {
log.error("接收用户消息退回出现异常: MessageProperties: [{}], 用户ID:[{}], Error:[{}]",
message.getMessageProperties(), body, e.getMessage(), e);
}
}
}
/**
* es
*
* @param userList {@link List}
* @param organizationRepository {@link OrganizationRepository}
* @return {@link List}
*/
@NotNull
public static List<UserElasticSearchEntity> getUserElasticSearchEntity(List<UserEsPO> userList,
OrganizationRepository organizationRepository) {
List<UserElasticSearchEntity> userElasticSearchEntityList = new ArrayList<>();
userList.forEach(user -> {
UserElasticSearchEntity entity = UserElasticSearchEntity.builder().build();
entity.setId(user.getId().toString());
entity.setUsername(user.getUsername());
entity.setEmail(user.getEmail());
entity.setPhone(user.getPhone());
entity.setPhoneAreaCode(user.getPhoneAreaCode());
entity.setFullName(user.getFullName());
entity.setNickName(user.getNickName());
entity.setAvatar(user.getAvatar());
if (Objects.nonNull(user.getStatus())) {
entity.setStatus(user.getStatus().getCode());
}
if (Objects.nonNull(user.getDataOrigin())) {
entity.setDataOrigin(user.getDataOrigin().getCode());
}
entity.setIdentitySourceId(user.getIdentitySourceId());
entity.setEmailVerified(user.getEmailVerified());
entity.setPhoneVerified(user.getPhoneVerified());
entity.setAuthTotal(user.getAuthTotal());
entity.setLastAuthIp(user.getLastAuthIp());
if (Objects.nonNull(user.getLastUpdatePasswordTime())) {
entity.setLastUpdatePasswordTime(user.getLastUpdatePasswordTime());
}
if (Objects.nonNull(user.getLastAuthTime())) {
entity.setLastAuthTime(user.getLastAuthTime());
}
entity.setExpand(user.getExpand());
entity.setExternalId(user.getExternalId());
if (Objects.nonNull(user.getExpireDate())) {
entity.setExpireDate(user.getExpireDate());
}
// 用户详情
entity.setIdType(user.getIdType());
entity.setIdCard(user.getIdCard());
entity.setWebsite(user.getWebsite());
entity.setAddress(user.getAddress());
// 组织列表
if (!CollectionUtils.isEmpty(user.getOrganizationIds())) {
entity.setOrganizations(organizationRepository
.getOrganizationList(new ArrayList<>(user.getOrganizationIds())));
}
// 用户组
List<UserElasticSearchEntity.UserGroup> userGroups = new ArrayList<>();
if (!CollectionUtils.isEmpty(user.getUserGroups())) {
userGroups.addAll(user.getUserGroups().entrySet().stream()
.map(group -> new UserElasticSearchEntity.UserGroup(group.getKey(),
group.getValue()))
.toList());
}
entity.setUserGroups(userGroups);
userElasticSearchEntityList.add(entity);
});
return userElasticSearchEntityList;
}
/**
* UserElasticSearchRepository
*/
private final UserElasticSearchRepository userElasticSearchRepository;
/**
* UserRepository
*/
private final UserRepository userRepository;
/**
* OrganizationRepository
*/
private final OrganizationRepository organizationRepository;
public UserMessageListener(UserElasticSearchRepository userElasticSearchRepository,
UserRepository userRepository,
OrganizationRepository organizationRepository) {
this.userElasticSearchRepository = userElasticSearchRepository;
this.userRepository = userRepository;
this.organizationRepository = organizationRepository;
}
}

View File

@ -1,85 +0,0 @@
/*
* eiam-core - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.core.mq;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.AsyncRabbitTemplate;
import org.springframework.amqp.rabbit.RabbitConverterFuture;
import org.springframework.stereotype.Component;
import cn.topiam.employee.support.constant.EiamConstants;
import lombok.extern.slf4j.Slf4j;
import jakarta.annotation.PostConstruct;
/**
* MQ
*
* @author TopIAM
* Created by support@topiam.cn on 2023/5/30 23:12
*/
@Slf4j
@Component
public class UserMessagePublisher extends AbstractMessagePublisher {
@PostConstruct
public void init() {
TopicExchange topicExchange = new TopicExchange(USER);
Queue saveQueue = new Queue(USER_SAVE, true);
Queue deleteQueue = new Queue(USER_DELETE, true);
amqpAdmin.declareExchange(topicExchange);
amqpAdmin.declareQueue(saveQueue);
amqpAdmin.declareQueue(deleteQueue);
amqpAdmin.declareBinding(BindingBuilder.bind(saveQueue).to(topicExchange).with(USER_SAVE));
amqpAdmin
.declareBinding(BindingBuilder.bind(deleteQueue).to(topicExchange).with(USER_DELETE));
}
/**
*
*
* @param asyncRabbitTemplate {@link AsyncRabbitTemplate}
* @param amqpAdmin {@link AmqpAdmin}
*/
public UserMessagePublisher(AsyncRabbitTemplate asyncRabbitTemplate, AmqpAdmin amqpAdmin) {
super(asyncRabbitTemplate, amqpAdmin);
}
/**
*
*
* @param tag {@link UserMessageTag} SAVE/DELETE
* @param userIds {@link String} id
*/
public void sendUserChangeMessage(UserMessageTag tag, String userIds) {
log.info("发送[{}]用户消息, 用户ID:[{}]", tag.name(), userIds);
String routingKey = USER + EiamConstants.POINT + tag.name().toLowerCase();
RabbitConverterFuture<Object> future = sendMessage(USER, routingKey, userIds);
future.whenComplete((result, ex) -> {
if (ex == null) {
log.info("发送[{}]用户消息成功, 用户ID:[{}],处理结果为:[{}]", tag.name(), userIds, result);
} else {
log.info("发送[{}]用户消息异常用户ID:[{}],失败原因:[{}] ", tag.name(), userIds, ex);
}
});
}
}

View File

@ -1,35 +0,0 @@
/*
* eiam-core - Employee Identity and Access Management
* Copyright © 2022-Present Jinan Yuanchuang Network Technology Co., Ltd. (support@topiam.cn)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cn.topiam.employee.core.mq;
/**
*
*
* @author TopIAM
* Created by support@topiam.cn on 2023/5/30 23:12
*/
public enum UserMessageTag {
/**
*
*/
DELETE,
/**
*
*/
SAVE
}

View File

@ -31,7 +31,7 @@ import cn.topiam.employee.authentication.common.authentication.IdpUserDetails;
import cn.topiam.employee.common.entity.account.UserDetailEntity; import cn.topiam.employee.common.entity.account.UserDetailEntity;
import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.entity.account.UserEntity;
import cn.topiam.employee.common.entity.account.UserIdpBindEntity; import cn.topiam.employee.common.entity.account.UserIdpBindEntity;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
import cn.topiam.employee.common.entity.authn.IdentityProviderEntity; import cn.topiam.employee.common.entity.authn.IdentityProviderEntity;
import cn.topiam.employee.portal.pojo.request.UpdateUserInfoRequest; import cn.topiam.employee.portal.pojo.request.UpdateUserInfoRequest;
import cn.topiam.employee.portal.pojo.result.BoundIdpListResult; import cn.topiam.employee.portal.pojo.result.BoundIdpListResult;
@ -124,11 +124,11 @@ public interface AccountConverter {
* entityresult * entityresult
* *
* @param identityProviderList {@link List<IdentityProviderEntity>} * @param identityProviderList {@link List<IdentityProviderEntity>}
* @param userIdpBindList {@link Iterable<UserIdpBindPo>} * @param userIdpBindList {@link Iterable< UserIdpBindPO >}
* @return {@link List< BoundIdpListResult >} * @return {@link List< BoundIdpListResult >}
*/ */
default List<BoundIdpListResult> entityConverterToBoundIdpListResult(List<IdentityProviderEntity> identityProviderList, default List<BoundIdpListResult> entityConverterToBoundIdpListResult(List<IdentityProviderEntity> identityProviderList,
Iterable<UserIdpBindPo> userIdpBindList) { Iterable<UserIdpBindPO> userIdpBindList) {
List<BoundIdpListResult> boundIdpListResultList = new ArrayList<>(); List<BoundIdpListResult> boundIdpListResultList = new ArrayList<>();
for (IdentityProviderEntity identityProviderEntity : identityProviderList) { for (IdentityProviderEntity identityProviderEntity : identityProviderList) {
BoundIdpListResult boundIdpListResult = new BoundIdpListResult(); BoundIdpListResult boundIdpListResult = new BoundIdpListResult();
@ -138,7 +138,7 @@ public interface AccountConverter {
boundIdpListResult.setType(identityProviderEntity.getType()); boundIdpListResult.setType(identityProviderEntity.getType());
boundIdpListResult.setCategory(identityProviderEntity.getCategory()); boundIdpListResult.setCategory(identityProviderEntity.getCategory());
boundIdpListResult.setBound(false); boundIdpListResult.setBound(false);
for (UserIdpBindPo userIdpBindPo : userIdpBindList) { for (UserIdpBindPO userIdpBindPo : userIdpBindList) {
if (userIdpBindPo.getIdpId() if (userIdpBindPo.getIdpId()
.equals(String.valueOf(identityProviderEntity.getId()))) { .equals(String.valueOf(identityProviderEntity.getId()))) {
boundIdpListResult.setBound(true); boundIdpListResult.setBound(true);

View File

@ -40,7 +40,7 @@ import cn.topiam.employee.audit.context.AuditContext;
import cn.topiam.employee.audit.entity.Target; import cn.topiam.employee.audit.entity.Target;
import cn.topiam.employee.common.entity.account.UserDetailEntity; import cn.topiam.employee.common.entity.account.UserDetailEntity;
import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.entity.account.UserEntity;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
import cn.topiam.employee.common.entity.authn.IdentityProviderEntity; import cn.topiam.employee.common.entity.authn.IdentityProviderEntity;
import cn.topiam.employee.common.enums.MailType; import cn.topiam.employee.common.enums.MailType;
import cn.topiam.employee.common.enums.MessageNoticeChannel; import cn.topiam.employee.common.enums.MessageNoticeChannel;
@ -353,7 +353,7 @@ public class AccountServiceImpl implements AccountService {
List<IdentityProviderEntity> identityProviderList = identityProviderRepository List<IdentityProviderEntity> identityProviderList = identityProviderRepository
.findByEnabledIsTrueAndDisplayedIsTrue(); .findByEnabledIsTrueAndDisplayedIsTrue();
// 获取已绑定idp // 获取已绑定idp
Iterable<UserIdpBindPo> userIdpBindList = userIdpRepository Iterable<UserIdpBindPO> userIdpBindList = userIdpRepository
.getUserIdpBindList(Long.valueOf(SecurityUtils.getCurrentUserId())); .getUserIdpBindList(Long.valueOf(SecurityUtils.getCurrentUserId()));
return accountConverter.entityConverterToBoundIdpListResult(identityProviderList, return accountConverter.entityConverterToBoundIdpListResult(identityProviderList,
userIdpBindList); userIdpBindList);

View File

@ -28,7 +28,7 @@ import cn.topiam.employee.authentication.common.authentication.IdpUserDetails;
import cn.topiam.employee.authentication.common.service.UserIdpService; import cn.topiam.employee.authentication.common.service.UserIdpService;
import cn.topiam.employee.common.entity.account.UserEntity; import cn.topiam.employee.common.entity.account.UserEntity;
import cn.topiam.employee.common.entity.account.UserIdpBindEntity; import cn.topiam.employee.common.entity.account.UserIdpBindEntity;
import cn.topiam.employee.common.entity.account.po.UserIdpBindPo; import cn.topiam.employee.common.entity.account.po.UserIdpBindPO;
import cn.topiam.employee.common.entity.authn.IdentityProviderEntity; import cn.topiam.employee.common.entity.authn.IdentityProviderEntity;
import cn.topiam.employee.common.repository.account.UserIdpRepository; import cn.topiam.employee.common.repository.account.UserIdpRepository;
import cn.topiam.employee.common.repository.account.UserRepository; import cn.topiam.employee.common.repository.account.UserRepository;
@ -68,7 +68,7 @@ public class UserIdpServiceImpl implements UserIdpService {
if (!source.get().getEnabled()) { if (!source.get().getEnabled()) {
throw new TopIamException("认证源已禁用"); throw new TopIamException("认证源已禁用");
} }
Optional<UserIdpBindPo> authnBind = userIdpRepository.findByIdpIdAndOpenId(providerId, Optional<UserIdpBindPO> authnBind = userIdpRepository.findByIdpIdAndOpenId(providerId,
openId); openId);
return authnBind.isPresent(); return authnBind.isPresent();
} }
@ -119,7 +119,7 @@ public class UserIdpServiceImpl implements UserIdpService {
} }
private UserEntity getUser(String openId, String providerId) { private UserEntity getUser(String openId, String providerId) {
Optional<UserIdpBindPo> bindEntity = userIdpRepository.findByIdpIdAndOpenId(providerId, Optional<UserIdpBindPO> bindEntity = userIdpRepository.findByIdpIdAndOpenId(providerId,
openId); openId);
if (bindEntity.isEmpty()) { if (bindEntity.isEmpty()) {
throw new NullPointerException("用户未绑定"); throw new NullPointerException("用户未绑定");