获取用户应用数量

pull/59/head
shao1121353141 1 year ago
parent 074e8e7882
commit 14f8cd24fb

@ -17,15 +17,25 @@
*/
package cn.topiam.employee.common.repository.app.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import cn.topiam.employee.common.entity.account.OrganizationMemberEntity;
import cn.topiam.employee.common.entity.account.UserGroupMemberEntity;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.repository.account.OrganizationMemberRepository;
import cn.topiam.employee.common.repository.account.UserGroupMemberRepository;
import cn.topiam.employee.common.repository.app.impl.mapper.AppEntityMapper;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import cn.topiam.employee.common.entity.account.query.UserGroupMemberListQuery;
@ -36,6 +46,8 @@ import cn.topiam.employee.common.repository.app.impl.mapper.AppGroupPoMapper;
import lombok.AllArgsConstructor;
import static cn.topiam.employee.common.enums.app.AuthorizationType.ALL_ACCESS;
/**
* @author TopIAM
* Created by support@topiam.cn on 2023/9/8 19:20
@ -117,8 +129,46 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto
*/
@Override
public Long getAppCount(String groupId, Long userId) {
return null;
//@formatter:on
List<Object> paramList = Lists.newArrayList();
//当前用户加入的用户组Id
List<Long> groupIdList = userGroupMemberRepository.findByUserId(userId).stream()
.map(UserGroupMemberEntity::getGroupId).toList();
//当前用户加入的组织id
List<String> orgId = organizationMemberRepository.findAllByUserId(userId).stream()
.map(OrganizationMemberEntity::getOrgId).toList();
paramList.addAll(groupIdList);
paramList.addAll(orgId);
paramList.add(userId);
Map<String, Object> paramMap = new HashMap<>(16);
paramMap.put("subjectIds", paramList);
//@formatter:off
StringBuilder builder = new StringBuilder("SELECT DISTINCT app.* FROM app LEFT JOIN app_access_policy app_acce ON app.id_ = app_acce.app_id AND app_acce.is_deleted = '0' LEFT JOIN app_group_association ass ON app.id_ = ass.app_id AND ass.is_deleted = '0' WHERE app.is_enabled = 1 AND app.is_deleted = '0' AND (app_acce.subject_id IN (:subjectIds) OR app.authorization_type = '"+ALL_ACCESS.getCode()+"')");
builder.append(" AND ass.group_id = ").append(groupId);
return namedParameterJdbcTemplate.queryForObject(builder.toString(), paramMap,
Long.class);
//@formatter:off
}
/**
* JdbcTemplate
*/
private final JdbcTemplate jdbcTemplate;
/**
* NamedParameterJdbcTemplate
*/
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
/**
* UserGroupMemberRepository
*/
private final UserGroupMemberRepository userGroupMemberRepository;
/**
* OrganizationMemberRepository
*/
private final OrganizationMemberRepository organizationMemberRepository;
}

Loading…
Cancel
Save