优化

pull/47/MERGE
smallbun 2023-09-11 12:08:46 +08:00
parent d1273a57d0
commit ff76fbaaa8
1 changed files with 1 additions and 17 deletions

View File

@ -54,35 +54,19 @@ public class AppGroupRepositoryCustomizedImpl implements AppGroupRepositoryCusto
@Override @Override
public Page<AppGroupPO> getAppGroupList(AppGroupQuery query, Pageable pageable) { public Page<AppGroupPO> getAppGroupList(AppGroupQuery query, Pageable pageable) {
//@formatter:off //@formatter:off
StringBuilder builder = new StringBuilder(""" 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'");
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 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())) { if (StringUtils.isNoneBlank(query.getName())) {
builder.append(" AND `group`.name_ like '%").append(query.getName()).append("%'"); builder.append(" AND `group`.name_ like '%").append(query.getName()).append("%'");
} }
//分组编码 //分组编码
if (StringUtils.isNoneBlank(query.getCode())) { if (StringUtils.isNoneBlank(query.getCode())) {
builder.append(" AND `group`.code_ like '%").append(query.getCode()).append("%'"); builder.append(" AND `group`.code_ like '%").append(query.getCode()).append("%'");
} }
//分组类型 //分组类型
if (ObjectUtils.isNotEmpty(query.getType())) { if (ObjectUtils.isNotEmpty(query.getType())) {
builder.append(" AND `group`.type_ like '%").append(query.getType().getCode()).append("%'"); builder.append(" AND `group`.type_ like '%").append(query.getType().getCode()).append("%'");
} }
builder.append(" ORDER BY `group`.create_time DESC"); builder.append(" ORDER BY `group`.create_time DESC");
//@formatter:on //@formatter:on
String sql = builder.toString(); String sql = builder.toString();