refactor: 调整 starter 内的 CommonUserService、ContainerPool 到 admin 项目

This commit is contained in:
2025-01-09 21:28:14 +08:00
parent ee46e47361
commit f1d0b491b1
6 changed files with 57 additions and 16 deletions

View File

@@ -23,7 +23,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import top.continew.starter.extension.crud.constant.ContainerPool; import top.continew.admin.common.constant.ContainerConstants;
import java.io.Serial; import java.io.Serial;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@@ -45,7 +45,7 @@ public class BaseDetailResp extends BaseResp {
*/ */
@JsonIgnore @JsonIgnore
@ConditionOnPropertyNotNull @ConditionOnPropertyNotNull
@Assemble(container = ContainerPool.USER_NICKNAME, props = @Mapping(ref = "updateUserString")) @Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "updateUserString"))
private Long updateUser; private Long updateUser;
/** /**

View File

@@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import top.continew.starter.extension.crud.constant.ContainerPool; import top.continew.admin.common.constant.ContainerConstants;
import java.io.Serial; import java.io.Serial;
import java.io.Serializable; import java.io.Serializable;
@@ -52,7 +52,7 @@ public class BaseResp implements Serializable {
* 创建人 * 创建人
*/ */
@JsonIgnore @JsonIgnore
@Assemble(container = ContainerPool.USER_NICKNAME, props = @Mapping(ref = "createUserString")) @Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "createUserString"))
private Long createUser; private Long createUser;
/** /**

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.base;
import cn.crane4j.annotation.ContainerMethod;
import cn.crane4j.annotation.MappingType;
import top.continew.admin.common.constant.ContainerConstants;
/**
* 公共用户业务接口
*
* @author Charles7c
* @since 2025/1/9 20:17
*/
public interface CommonUserService {
/**
* 根据 ID 查询昵称
*
* <p>
* 数据填充容器 {@link ContainerConstants#USER_NICKNAME}
* </p>
*
* @param id ID
* @return 昵称
*/
@ContainerMethod(namespace = ContainerConstants.USER_NICKNAME, type = MappingType.ORDER_OF_KEYS)
String getNicknameById(Long id);
}

View File

@@ -16,20 +16,18 @@
package top.continew.admin.common.constant; package top.continew.admin.common.constant;
import top.continew.starter.extension.crud.constant.ContainerPool;
/** /**
* 数据源容器相关常量Crane4j 数据填充组件使用) * 数据源容器相关常量Crane4j 数据填充组件使用)
* *
* @author Charles7c * @author Charles7c
* @since 2024/1/20 12:33 * @since 2024/1/20 12:33
*/ */
public class ContainerConstants extends ContainerPool { public class ContainerConstants {
/** /**
* 用户昵称 * 用户昵称
*/ */
public static final String USER_NICKNAME = ContainerPool.USER_NICKNAME; public static final String USER_NICKNAME = "UserNickname";
/** /**
* 用户角色 ID 列表 * 用户角色 ID 列表

View File

@@ -20,8 +20,8 @@ import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.extra.spring.SpringUtil; import cn.hutool.extra.spring.SpringUtil;
import top.continew.admin.common.base.CommonUserService;
import top.continew.starter.core.util.ExceptionUtils; import top.continew.starter.core.util.ExceptionUtils;
import top.continew.starter.extension.crud.service.CommonUserService;
/** /**
* 用户上下文 Holder * 用户上下文 Holder

View File

@@ -54,6 +54,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import top.continew.admin.auth.service.OnlineUserService; import top.continew.admin.auth.service.OnlineUserService;
import top.continew.admin.common.base.CommonUserService;
import top.continew.admin.common.constant.CacheConstants; import top.continew.admin.common.constant.CacheConstants;
import top.continew.admin.common.constant.SysConstants; import top.continew.admin.common.constant.SysConstants;
import top.continew.admin.common.context.UserContext; import top.continew.admin.common.context.UserContext;
@@ -82,7 +83,6 @@ import top.continew.starter.extension.crud.model.query.PageQuery;
import top.continew.starter.extension.crud.model.query.SortQuery; import top.continew.starter.extension.crud.model.query.SortQuery;
import top.continew.starter.extension.crud.model.resp.PageResp; import top.continew.starter.extension.crud.model.resp.PageResp;
import top.continew.starter.extension.crud.service.BaseServiceImpl; import top.continew.starter.extension.crud.service.BaseServiceImpl;
import top.continew.starter.extension.crud.service.CommonUserService;
import top.continew.starter.web.util.FileUploadUtils; import top.continew.starter.web.util.FileUploadUtils;
import java.io.IOException; import java.io.IOException;
@@ -209,6 +209,12 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
ids.forEach(onlineUserService::kickOut); ids.forEach(onlineUserService::kickOut);
} }
@Override
@Cached(key = "#id", name = CacheConstants.USER_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public String getNicknameById(Long id) {
return baseMapper.selectNicknameById(id);
}
@Override @Override
public void downloadImportTemplate(HttpServletResponse response) throws IOException { public void downloadImportTemplate(HttpServletResponse response) throws IOException {
try { try {
@@ -462,12 +468,6 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserRes
return baseMapper.lambdaQuery().in(UserDO::getDeptId, deptIds).count(); return baseMapper.lambdaQuery().in(UserDO::getDeptId, deptIds).count();
} }
@Override
@Cached(key = "#id", name = CacheConstants.USER_KEY_PREFIX, cacheType = CacheType.BOTH, syncLocal = true)
public String getNicknameById(Long id) {
return baseMapper.selectNicknameById(id);
}
@Override @Override
protected <E> List<E> list(UserQuery query, SortQuery sortQuery, Class<E> targetClass) { protected <E> List<E> list(UserQuery query, SortQuery sortQuery, Class<E> targetClass) {
QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query); QueryWrapper<UserDO> queryWrapper = this.buildQueryWrapper(query);