fix
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package com.agileboot.common.core.enums.dictionary;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.agileboot.common.core.enums.DictionaryEnum;
|
||||
import com.agileboot.common.core.enums.common.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 本地一级缓存 使用Map
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
public class DictCache {
|
||||
|
||||
private static final Map<String, List<DictionaryData>> DICTIONARY_CACHE = MapUtil.newHashMap(128);
|
||||
|
||||
private DictCache() {
|
||||
}
|
||||
|
||||
static {
|
||||
initDictionaryCache();
|
||||
}
|
||||
|
||||
private static void initDictionaryCache() {
|
||||
// TODO 这个可以做成自动扫描
|
||||
loadInCache(BusinessTypeEnum.values());
|
||||
loadInCache(YesOrNoEnum.values());
|
||||
loadInCache(StatusEnum.values());
|
||||
loadInCache(GenderEnum.values());
|
||||
loadInCache(NoticeStatusEnum.values());
|
||||
loadInCache(NoticeTypeEnum.values());
|
||||
loadInCache(OperationStatusEnum.values());
|
||||
loadInCache(LoginStatusEnum.values());
|
||||
loadInCache(VisibleStatusEnum.values());
|
||||
loadInCache(UserStatusEnum.values());
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, List<DictionaryData>> dictionaryCache() {
|
||||
return DICTIONARY_CACHE;
|
||||
}
|
||||
|
||||
private static void loadInCache(DictionaryEnum[] dictionaryEnums) {
|
||||
DICTIONARY_CACHE.put(getDictionaryName(dictionaryEnums[0].getClass()), arrayToList(dictionaryEnums));
|
||||
}
|
||||
|
||||
|
||||
private static String getDictionaryName(Class<?> clazz) {
|
||||
Objects.requireNonNull(clazz);
|
||||
Dictionary annotation = clazz.getAnnotation(Dictionary.class);
|
||||
|
||||
Objects.requireNonNull(annotation);
|
||||
return annotation.name();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static List<DictionaryData> arrayToList(DictionaryEnum[] dictionaryEnums) {
|
||||
if(ArrayUtil.isEmpty(dictionaryEnums)) {
|
||||
return ListUtil.empty();
|
||||
}
|
||||
return Arrays.stream(dictionaryEnums).map(DictionaryData::new).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class PageQuery<T> implements Serializable {
|
||||
/**
|
||||
* 排序的方向desc或者asc
|
||||
*/
|
||||
protected String isAsc;
|
||||
protected String isAsc = "desc";
|
||||
|
||||
/**
|
||||
* 构建分页对象
|
||||
|
||||
@@ -48,9 +48,9 @@ public class MonitorController {
|
||||
* @return 分页处理后的在线用户信息
|
||||
*/
|
||||
@GetMapping("/onlineUsers")
|
||||
public R<PageR<OnlineUserVO>> onlineUsers(String ipAddress, String username) {
|
||||
public PageR<OnlineUserVO> onlineUsers(@RequestParam(name = "ipAddress", required = false) String ipAddress, @RequestParam(name = "username", required = false) String username) {
|
||||
List<OnlineUserVO> onlineUserList = sysMonitorService.getOnlineUserList(username, ipAddress);
|
||||
return R.ok(new PageR<>(onlineUserList));
|
||||
return new PageR<>(onlineUserList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface SysNoticeMapper extends BaseMapper<SysNotice> {
|
||||
*/
|
||||
@Select("SELECT n.* "
|
||||
+ "FROM sys_notice n "
|
||||
+ "LEFT JOIN sys_user u ON n.creator_id = u.user_id"
|
||||
+ "LEFT JOIN sys_user u ON n.create_by = u.user_id"
|
||||
+ " ${ew.customSqlSegment}")
|
||||
Page<SysNotice> getNoticeList(Page<SysNotice> page, @Param(Constants.WRAPPER) Wrapper<SysNotice> queryWrapper);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SysUserController {
|
||||
* 获取用户列表
|
||||
*/
|
||||
@GetMapping
|
||||
public PageR<UserInfo> userList(SearchUserDTO dto) {
|
||||
public PageR<UserInfo> userList(SearchUserQuery dto) {
|
||||
IPage<UserInfo> page = sysUserService.getUserList(dto);
|
||||
return new PageR<>(page);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class SysUserController {
|
||||
* 用户列表导出
|
||||
*/
|
||||
@GetMapping("/excel")
|
||||
public void exportUserByExcel(HttpServletResponse response, SearchUserDTO dto) {
|
||||
public void exportUserByExcel(HttpServletResponse response, SearchUserQuery dto) {
|
||||
IPage<UserInfo> page = sysUserService.getUserList(dto);
|
||||
CustomExcelUtil.writeToResponse(page.getRecords(), UserInfo.class, response);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
package com.agileboot.system.user.mapper;
|
||||
|
||||
import com.agileboot.system.user.entity.SysUser;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
|
||||
Page<SysUser> getUserListByRole(Page<Object> objectPage, LambdaQueryWrapper<?> queryWrapper);
|
||||
Page<SysUser> getUserListByRole(Page<SysUser> objectPage, LambdaQueryWrapper<?> queryWrapper);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
* @param page 页码对象
|
||||
* @param queryWrapper 查询对象
|
||||
* @return 用户信息集合信息
|
||||
*/
|
||||
@Select("SELECT u.*, d.dept_name, d.leader_name as dept_leader "
|
||||
+ "FROM sys_user u "
|
||||
+ " LEFT JOIN sys_dept d ON u.dept_id = d.dept_id "
|
||||
+ "${ew.customSqlSegment}")
|
||||
Page<SysUser> getUserList(Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> queryWrapper);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public interface ISysUserService {
|
||||
|
||||
boolean registerUserInfo(SysUser sysUser);
|
||||
|
||||
IPage<UserInfo> getUserList(SearchUserDTO dto);
|
||||
IPage<UserInfo> getUserList(SearchUserQuery dto);
|
||||
|
||||
void addUser(AddUserCommand command);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.agileboot.system.user.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.agileboot.common.core.constant.Constants;
|
||||
import com.agileboot.common.core.exception.BizException;
|
||||
import com.agileboot.common.core.exception.error.ErrorCode;
|
||||
@@ -12,6 +13,7 @@ import com.agileboot.system.user.entity.SysUser;
|
||||
import com.agileboot.system.user.mapper.SysUserMapper;
|
||||
import com.agileboot.system.user.service.ISysUserService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
@@ -68,8 +70,29 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
// --------------------------------------
|
||||
|
||||
@Override
|
||||
public IPage<UserInfo> getUserList(SearchUserDTO query) {
|
||||
return null;
|
||||
public IPage<UserInfo> getUserList(SearchUserQuery query) {
|
||||
|
||||
String username = query.getUsername();
|
||||
String phoneNumber = query.getPhoneNumber();
|
||||
Long userId = query.getUserId();
|
||||
Integer status = query.getStatus();
|
||||
Long deptId = query.getDeptId();
|
||||
|
||||
QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.like(StrUtil.isNotEmpty(username), "username", username)
|
||||
.like(StrUtil.isNotEmpty(phoneNumber), "u.phone_number", phoneNumber)
|
||||
.eq(userId != null, "u.user_id", userId)
|
||||
.eq(status != null, "u.status", status)
|
||||
.eq("u.deleted", 0)
|
||||
.and(deptId != null, o ->
|
||||
o.eq("u.dept_id", deptId)
|
||||
.or()
|
||||
.apply("u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE find_in_set(" + deptId
|
||||
+ ", ancestors))"));
|
||||
query.setOrderByColumn("u.create_time");
|
||||
Page<SysUser> userPage = baseMapper.getUserList(query.toPage(), queryWrapper);
|
||||
IPage<UserInfo> convert = userPage.convert(UserInfo::new);
|
||||
return convert;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.agileboot.auth.service.IAuthStrategy;
|
||||
import com.agileboot.auth.service.SysLoginService;
|
||||
import com.agileboot.common.core.constant.Constants;
|
||||
import com.agileboot.common.core.core.R;
|
||||
import com.agileboot.common.core.enums.dictionary.DictCache;
|
||||
import com.agileboot.common.core.utils.ValidatorUtils;
|
||||
import com.agileboot.common.satoken.pojo.LoginUser;
|
||||
import com.agileboot.common.satoken.utils.LoginHelper;
|
||||
@@ -82,6 +83,7 @@ public class AuthController {
|
||||
configVO.setIsCaptchaOn(Boolean.parseBoolean(property));
|
||||
configVO.setIsPhoneRegisterOn(Boolean.parseBoolean(SpringUtil.getProperty("security.register.phoneEnabled")));
|
||||
configVO.setClientId(SpringUtil.getProperty("security.clientId"));
|
||||
configVO.setDictionary(DictCache.dictionaryCache());
|
||||
return R.ok(configVO);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package com.agileboot.auth.pojo.vo;
|
||||
|
||||
import com.agileboot.common.core.enums.dictionary.DictionaryData;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ConfigVO {
|
||||
private Boolean isCaptchaOn;
|
||||
private Boolean isPhoneRegisterOn;
|
||||
private String clientId;
|
||||
private Map<String, List<DictionaryData>> dictionary;
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.agileboot.system.user.dto;
|
||||
|
||||
import com.agileboot.system.user.entity.SysUser;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 如果Entity的字段和复杂查询不匹配时 自定义类来接收
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchUserDTO extends SysUser {
|
||||
|
||||
private String deptName;
|
||||
private String deptLeader;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.agileboot.system.user.dto;
|
||||
|
||||
import com.agileboot.common.mybatis.core.page.PageQuery;
|
||||
import com.agileboot.system.user.entity.SysUser;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 当出现复用Query的情况,我们需要把泛型加到类本身,通过传入类型 来进行复用
|
||||
*
|
||||
* @author valarchie
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SearchUserQuery extends PageQuery<SysUser> {
|
||||
|
||||
protected Long userId;
|
||||
protected String username;
|
||||
protected Integer status;
|
||||
protected String phoneNumber;
|
||||
protected Long deptId;
|
||||
|
||||
|
||||
@Override
|
||||
public LambdaQueryWrapper<SysUser> toQueryWrapper() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class UserInfo {
|
||||
private String nickname;
|
||||
|
||||
@ExcelColumn(name = "用户类型")
|
||||
private Integer userType;
|
||||
private String userType;
|
||||
|
||||
@ExcelColumn(name = "邮件")
|
||||
private String email;
|
||||
|
||||
Reference in New Issue
Block a user