Merge remote-tracking branch 'origin/master'

pull/58/head
shao1121353141 2023-09-25 23:03:53 +08:00
commit 438e3037a6
14 changed files with 100 additions and 102 deletions

View File

@ -1,5 +1,5 @@
/*
* eiam-portal - Employee Identity and Access Management
* 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
@ -20,11 +20,11 @@ package cn.topiam.employee.common.entity.app.query;
import java.io.Serial;
import java.io.Serializable;
import io.swagger.v3.oas.annotations.Parameter;
import org.springdoc.core.annotations.ParameterObject;
import lombok.Data;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
/**

View File

@ -18,6 +18,7 @@
package cn.topiam.employee.common.repository.account.impl;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
@ -105,7 +106,7 @@ public class UserGroupMemberRepositoryCustomizedImpl implements
String countSql = "SELECT count(*) FROM (" + sql + ") user_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
private final JdbcTemplate jdbcTemplate;

View File

@ -129,7 +129,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized {
String countSql = "SELECT count(*) FROM (" + sql + ") user_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**
@ -203,7 +203,7 @@ public class UserRepositoryCustomizedImpl implements UserRepositoryCustomized {
String countSql = "SELECT COUNT(*) FROM(" + sql + ") user_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**

View File

@ -19,12 +19,12 @@ package cn.topiam.employee.common.repository.app;
import java.util.List;
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.entity.app.query.AppQuery;
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
/**
* Repository Customized

View File

@ -133,7 +133,7 @@ public class AppAccessPolicyRepositoryCustomizedImpl implements
String countSql = "SELECT count(*) FROM (" + sql + ") app_access_policy_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**

View File

@ -18,6 +18,7 @@
package cn.topiam.employee.common.repository.app.impl;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
@ -106,7 +107,7 @@ public class AppAccountRepositoryCustomizedImpl implements AppAccountRepositoryC
String countSql = "SELECT count(*) FROM (" + sql + ") app_account_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**

View File

@ -18,6 +18,7 @@
package cn.topiam.employee.common.repository.app.impl;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
@ -77,7 +78,7 @@ public class AppGroupAssociationRepositoryCustomizedImpl implements
String countSql = "SELECT count(*) FROM (" + sql + ") app_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
private final JdbcTemplate jdbcTemplate;

View File

@ -18,6 +18,7 @@
package cn.topiam.employee.common.repository.app.impl;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -44,15 +45,38 @@ import lombok.AllArgsConstructor;
public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCustomized {
/**
*
*
*
* @param query {@link UserGroupMemberListQuery}
* @param pageable {@link Pageable}
* @return {@link Page}
*/
@SuppressWarnings("DuplicatedCode")
@Override
public Page<AppGroupPO> getAppGroupList(AppGroupQuery query, Pageable pageable) {
StringBuilder builder = getBaseAppGroupListSql(query);
String sql = getBaseAppGroupListSql(query).toString();
List<AppGroupPO> list = jdbcTemplate.query(
builder.append(" LIMIT ").append(pageable.getPageNumber() * pageable.getPageSize())
.append(",").append(pageable.getPageSize()).toString(),
new AppGroupPoMapper());
//@formatter:off
String countSql = "SELECT count(*) FROM (" + sql + ") app_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**
*
*
* @return {@link List}
*/
@Override
public List<AppGroupPO> getAppGroupList(AppGroupQuery query) {
return jdbcTemplate.query(getBaseAppGroupListSql(query).toString(), new AppGroupPoMapper());
}
private StringBuilder getBaseAppGroupListSql(AppGroupQuery query) {
//@formatter:off
StringBuilder builder = new StringBuilder("SELECT `group`.id_, `group`.name_, `group`.code_, `group`.type_, `group`.create_time, `group`.remark_, IFNULL( ass.app_count, 0) AS app_count FROM app_group `group` LEFT JOIN(SELECT aga.group_id, COUNT(*) AS `app_count` FROM app_group_association aga INNER JOIN app ON aga.app_id = app.id_ AND app.is_deleted = 0 GROUP BY aga.group_id ) ass ON `group`.id_ = ass.group_id WHERE is_deleted = '0'");
//分组名称
@ -69,43 +93,7 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto
}
builder.append(" ORDER BY `group`.create_time DESC");
//@formatter:on
String sql = builder.toString();
List<AppGroupPO> list = jdbcTemplate.query(
builder.append(" LIMIT ").append(pageable.getPageNumber() * pageable.getPageSize())
.append(",").append(pageable.getPageSize()).toString(),
new AppGroupPoMapper());
//@formatter:off
String countSql = "SELECT count(*) FROM (" + sql + ") app_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
}
/**
*
*
* @return {@link List}
*/
@Override
public List<AppGroupPO> getAppGroupList(AppGroupQuery query) {
//@formatter:off
StringBuilder builder = new StringBuilder("SELECT `group`.id_, `group`.name_, `group`.code_, `group`.type_, `group`.create_time, `group`.remark_, IFNULL( ass.app_count, 0) AS app_count FROM app_group `group` LEFT JOIN(SELECT aga.group_id, COUNT(*) AS `app_count` FROM app_group_association aga WHERE aga.is_deleted = '0' GROUP BY aga.group_id ) ass ON `group`.id_ = ass.group_id WHERE is_deleted = '0'");
//分组名称
if (StringUtils.isNoneBlank(query.getName())) {
builder.append(" AND `group`.name_ like '%").append(query.getName()).append("%'");
}
//分组编码
if (StringUtils.isNoneBlank(query.getCode())) {
builder.append(" AND `group`.code_ like '%").append(query.getCode()).append("%'");
}
//分组类型
if (ObjectUtils.isNotEmpty(query.getType())) {
builder.append(" AND `group`.type_ like '%").append(query.getType().getCode()).append("%'");
}
builder.append(" ORDER BY `group`.create_time DESC");
//@formatter:on
List<AppGroupPO> list = jdbcTemplate.query(builder.toString(), new AppGroupPoMapper());
return list;
return builder;
}
private final JdbcTemplate jdbcTemplate;

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
@ -37,12 +36,14 @@ 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.entity.app.query.AppQuery;
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
import cn.topiam.employee.common.repository.account.OrganizationMemberRepository;
import cn.topiam.employee.common.repository.account.UserGroupMemberRepository;
import cn.topiam.employee.common.repository.app.AppRepositoryCustomized;
import cn.topiam.employee.common.repository.app.impl.mapper.AppEntityMapper;
import lombok.AllArgsConstructor;
import static cn.topiam.employee.common.enums.app.AuthorizationType.ALL_ACCESS;
/**
* App Repository Customized
@ -58,8 +59,8 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
*
*
* @param userId {@link Long}
* @param query {@link query}
* @param pageable {@link String}
* @param query {@link GetAppListQuery}
* @param pageable {@link Pageable}
* @return {@link List}
*/
@Override
@ -77,18 +78,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
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')
""");
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()+"')");
//用户名
if (StringUtils.isNoneBlank(query.getName())) {
builder.append(" AND app.name_ like '%").append(query.getName()).append("%'");
@ -108,7 +98,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
//@formatter:on
Integer count = namedParameterJdbcTemplate.queryForObject(countSql, paramMap,
Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**
@ -118,6 +108,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
* @param pageable {@link Pageable}
* @return {@link List}
*/
@Override
public Page<AppEntity> getAppList(AppQuery appQuery, Pageable pageable) {
//@formatter:off
StringBuilder builder = new StringBuilder("SELECT DISTINCT app.* FROM app LEFT JOIN app_group_association `group` ON app.id_ = `group`.app_id WHERE app.is_deleted =0");
@ -145,7 +136,7 @@ public class AppRepositoryCustomizedImpl implements AppRepositoryCustomized {
String countSql = "SELECT count(*) FROM (" + sql + ") app_account_";
//@formatter:on
Integer count = jdbcTemplate.queryForObject(countSql, Integer.class);
return new PageImpl<>(list, pageable, count);
return new PageImpl<>(list, pageable, Objects.requireNonNull(count).longValue());
}
/**

View File

@ -49,7 +49,7 @@
"@ant-design/maps": "^1.0.7",
"@ant-design/pro-components": "^2.6.24",
"ahooks": "^3.7.8",
"antd": "^5.9.2",
"antd": "^5.9.3",
"antd-img-crop": "^4.13.0",
"antd-style": "^3.5.0",
"classnames": "^2.3.2",

View File

@ -25,11 +25,11 @@ import org.springframework.stereotype.Service;
import cn.topiam.employee.common.entity.app.AppEntity;
import cn.topiam.employee.common.entity.app.po.AppGroupPO;
import cn.topiam.employee.common.entity.app.query.AppGroupQuery;
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
import cn.topiam.employee.common.repository.app.AppGroupRepository;
import cn.topiam.employee.common.repository.app.AppRepository;
import cn.topiam.employee.portal.converter.AppConverter;
import cn.topiam.employee.portal.converter.AppGroupConverter;
import cn.topiam.employee.common.entity.app.query.GetAppListQuery;
import cn.topiam.employee.portal.pojo.result.AppGroupListResult;
import cn.topiam.employee.portal.pojo.result.GetAppListResult;
import cn.topiam.employee.portal.service.AppService;
@ -63,13 +63,12 @@ public class AppServiceImpl implements AppService {
/**
*
*
* @param appGroupQuery {@link AppGroupQuery}
* @param query {@link AppGroupQuery}
* @return {@link AppGroupListResult}
*/
@Override
public List<AppGroupListResult> getAppGroupList(AppGroupQuery appGroupQuery) {
//查询映射
List<AppGroupPO> list = appGroupRepository.getAppGroupList(appGroupQuery);
public List<AppGroupListResult> getAppGroupList(AppGroupQuery query) {
List<AppGroupPO> list = appGroupRepository.getAppGroupList(query);
return appGroupConverter.entityConvertToAppGroupListResult(list);
}

View File

@ -50,7 +50,7 @@
"@ant-design/maps": "^1.0.7",
"@ant-design/pro-components": "^2.6.24",
"ahooks": "^3.7.8",
"antd": "^5.9.2",
"antd": "^5.9.3",
"antd-img-crop": "^4.13.0",
"antd-style": "^3.5.0",
"classnames": "^2.3.2",

View File

@ -25,16 +25,17 @@ import {
} from '@ant-design/pro-components';
import { App, Avatar, Badge, Card, Typography } from 'antd';
import React, { useRef, useState } from 'react';
import { AppList, InitLoginType } from './data.d';
import { AppGroupList, AppList, InitLoginType } from './data.d';
import { getAppGroupList, queryAppList } from './service';
import { useIntl } from '@@/exports';
import useStyle from './style';
import classnames from 'classnames';
import { useAsyncEffect } from 'ahooks';
import { SpinProps } from 'antd/es/spin';
import { useIntl } from '@umijs/max';
const { Paragraph } = Typography;
const prefixCls = 'topiam-app-list';
const all = 'all';
const renderBadge = (count: number, active = false) => {
return (
<Badge
@ -57,8 +58,34 @@ const CardList = () => {
const { message } = App.useApp();
const actionRef = useRef<ActionType>();
const [searchParams, setSearchParams] = useState<Record<string, any>>();
const [appGroupList, setAppGroupList] = useState<AppGroupList[]>([]);
const [loading, setLoading] = useState<boolean | SpinProps | undefined>(false);
const [items, setItems] = useState<{ key: string; label: React.JSX.Element }[]>([]);
const getItems = () => {
let data: { key: string; label: React.JSX.Element }[] = [
{
key: all,
label: (
<span>
{intl.formatMessage({ id: 'pages.application.group_all' })}
{renderBadge(0, currentGroup === all)}
</span>
),
},
];
appGroupList.forEach((item) => {
data.push({
key: item.id,
label: (
<span>
{item.name}
{renderBadge(item.appCount, currentGroup === item.id)}
</span>
),
});
});
return data;
};
const initSso = (idpInitUrl: string) => {
const div = window.document.createElement('div');
@ -80,29 +107,11 @@ const CardList = () => {
setLoading(false);
});
if (success && result) {
let data: { key: string; label: React.JSX.Element }[] = [];
result.forEach((item) => {
data.push({
key: item.id,
label: (
<span>
{item.name}
{renderBadge(item.appCount, currentGroup === item.id)}
</span>
),
});
});
setItems(data);
// 如果有分组,取第一个分组
if (data.length > 0) {
setSearchParams({ groupId: data[0].key });
actionRef.current?.reload();
}
setAppGroupList(result);
setCurrentGroup(all);
// 手动请求
else {
actionRef.current?.reload();
}
}
}, []);
return (
@ -125,19 +134,26 @@ const CardList = () => {
}}
manualRequest
request={queryAppList}
pagination={{}}
toolbar={
items.length > 0
appGroupList?.length > 0
? {
menu: {
type: 'tab',
activeKey: currentGroup,
items: items,
items: getItems(),
onChange(key) {
if (key) {
setCurrentGroup(key);
if (key === all) {
setSearchParams((values) => {
return { ...values, groupId: undefined };
});
} else {
setSearchParams((values) => {
return { ...values, groupId: key };
});
}
actionRef.current?.reload();
}
},
@ -199,7 +215,7 @@ const CardList = () => {
return Promise.resolve();
}}
onReset={() => {
if (items.length > 0) {
if (currentGroup && currentGroup !== all) {
setSearchParams({ groupId: currentGroup });
} else {
setSearchParams({});

View File

@ -17,6 +17,7 @@
*/
export default {
'pages.application.search.name': '应用名称',
'pages.application.group_all': '全部',
'pages.application.tab.list': '应用列表',
'pages.application.tab.account': '应用账号',
'pages.application.init.warning': '仅允许应用发起',