mirror of https://gitee.com/topiam/eiam
smallbun
1 year ago
committed by
Gitee
13 changed files with 255 additions and 75 deletions
@ -0,0 +1,38 @@
|
||||
/* |
||||
* 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.app.po; |
||||
|
||||
import cn.topiam.employee.common.entity.app.AppGroupEntity; |
||||
|
||||
import lombok.Data; |
||||
import lombok.EqualsAndHashCode; |
||||
|
||||
/** |
||||
* |
||||
* @author TopIAM |
||||
* Created by support@topiam.cn on 2022/12/13 23:45 |
||||
*/ |
||||
@Data |
||||
@EqualsAndHashCode(callSuper = true) |
||||
public class AppGroupPO extends AppGroupEntity { |
||||
|
||||
/** |
||||
* 应用数量 |
||||
*/ |
||||
private Integer appCount; |
||||
} |
@ -0,0 +1,41 @@
|
||||
/* |
||||
* 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.app; |
||||
|
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.Pageable; |
||||
|
||||
import cn.topiam.employee.common.entity.app.po.AppGroupPO; |
||||
import cn.topiam.employee.common.entity.app.query.AppGroupAssociationListQuery; |
||||
import cn.topiam.employee.common.entity.app.query.AppGroupQuery; |
||||
|
||||
/** |
||||
* @author TopIAM |
||||
* Created by support@topiam.cn on 2023/9/8 19:20 |
||||
*/ |
||||
public interface AppGroupRepositoryCustomized { |
||||
|
||||
/** |
||||
* 获取应用组应用列表 |
||||
* |
||||
* @param query {@link AppGroupAssociationListQuery} |
||||
* @param pageable {@link Pageable} |
||||
* @return {@link Page} |
||||
*/ |
||||
Page<AppGroupPO> getAppGroupList(AppGroupQuery query, Pageable pageable); |
||||
} |
@ -0,0 +1,94 @@
|
||||
/* |
||||
* 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.app.impl; |
||||
|
||||
import java.util.List; |
||||
|
||||
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.stereotype.Repository; |
||||
|
||||
import cn.topiam.employee.common.entity.account.query.UserGroupMemberListQuery; |
||||
import cn.topiam.employee.common.entity.app.po.AppGroupPO; |
||||
import cn.topiam.employee.common.entity.app.query.AppGroupQuery; |
||||
import cn.topiam.employee.common.repository.app.AppGroupRepositoryCustomized; |
||||
import cn.topiam.employee.common.repository.app.impl.mapper.AppGroupPoMapper; |
||||
|
||||
import lombok.AllArgsConstructor; |
||||
|
||||
/** |
||||
* @author TopIAM |
||||
* Created by support@topiam.cn on 2023/9/8 19:20 |
||||
*/ |
||||
@Repository |
||||
@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) { |
||||
//@formatter:off
|
||||
StringBuilder builder = new StringBuilder(""" |
||||
SELECT |
||||
`group`.id_, |
||||
`group`.name_, |
||||
`group`.code_, |
||||
`group`.create_time, |
||||
`group`.remark_, |
||||
IFNULL( ass.app_count, 0 ) AS app_count |
||||
FROM |
||||
app_group `group` |
||||
LEFT JOIN ( SELECT group_id, count(*) AS `app_count` FROM app_group_association GROUP BY 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("%'"); |
||||
} |
||||
|
||||
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); |
||||
} |
||||
|
||||
private final JdbcTemplate jdbcTemplate; |
||||
} |
@ -0,0 +1,57 @@
|
||||
/* |
||||
* 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.app.impl.mapper; |
||||
|
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.time.LocalDateTime; |
||||
|
||||
import org.springframework.jdbc.core.RowMapper; |
||||
|
||||
import cn.topiam.employee.common.entity.app.po.AppGroupPO; |
||||
|
||||
/** |
||||
* @author TopIAM |
||||
* Created by support@topiam.cn on 2022/2/13 22:25 |
||||
*/ |
||||
public class AppGroupPoMapper implements RowMapper<AppGroupPO> { |
||||
|
||||
/** |
||||
* 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) |
||||
*/ |
||||
@SuppressWarnings("DuplicatedCode") |
||||
@Override |
||||
public AppGroupPO mapRow(ResultSet rs, int rowNum) throws SQLException { |
||||
AppGroupPO appGroup = new AppGroupPO(); |
||||
appGroup.setId(rs.getLong("id_")); |
||||
appGroup.setCode(rs.getString("code_")); |
||||
appGroup.setName(rs.getString("name_")); |
||||
appGroup.setRemark(rs.getString("remark_")); |
||||
appGroup.setAppCount(rs.getInt("app_count")); |
||||
appGroup.setCreateTime(rs.getObject("create_time", LocalDateTime.class)); |
||||
return appGroup; |
||||
} |
||||
} |
Loading…
Reference in new issue