Merge remote-tracking branch 'origin/dev' into warm-flow-future

# Conflicts:
#	ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/DeptService.java
#	ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/PostService.java
#	ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/RoleService.java
#	ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/service/UserService.java
#	ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java
#	ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java
This commit is contained in:
疯狂的狮子Li 2024-12-12 23:35:15 +08:00
commit 86212f4818
12 changed files with 211 additions and 39 deletions

View File

@ -14,18 +14,6 @@ import java.util.concurrent.*;
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Threads {
/**
* sleep等待,单位为毫秒
*/
public static void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
return;
}
}
/**
* 停止线程池
* 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.

View File

@ -43,7 +43,13 @@ public class MailProperties {
private String pass;
/**
* 发送方遵循RFC-822标准
* 发送方遵循RFC-822标准<br>
* 发件人可以是以下形式
*
* <pre>
* 1. user@xxx.xx
* 2. name &lt;user@xxx.xx&gt;
* </pre>
*/
private String from;

View File

@ -0,0 +1,165 @@
package org.dromara.common.redis.utils;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.redisson.api.RIdGenerator;
import org.redisson.api.RedissonClient;
import java.time.Duration;
/**
* 发号器工具类
*
* @author 秋辞未寒
* @date 2024-12-10
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class SequenceUtils {
/**
* 默认初始值
*/
public static final Long DEFAULT_INIT_VALUE = 1L;
/**
* 默认步长
*/
public static final Long DEFAULT_STEP_VALUE = 1L;
/**
* 默认过期时间-
*/
public static final Duration DEFAULT_EXPIRE_TIME_DAY = Duration.ofDays(1);
/**
* 默认过期时间-分钟
*/
public static final Duration DEFAULT_EXPIRE_TIME_MINUTE = Duration.ofMinutes(1);
/**
* 获取Redisson客户端实例
*/
private static final RedissonClient REDISSON_CLIENT = SpringUtils.getBean(RedissonClient.class);
/**
* 获取ID生成器
*
* @param key 业务key
* @param expireTime 过期时间
* @param initValue ID初始值
* @param stepValue ID步长
* @return ID生成器
*/
private static RIdGenerator getIdGenerator(String key, Duration expireTime, Long initValue, Long stepValue) {
if (initValue == null || initValue <= 0) {
initValue = DEFAULT_INIT_VALUE;
}
if (stepValue == null || stepValue <= 0) {
stepValue = DEFAULT_STEP_VALUE;
}
RIdGenerator idGenerator = REDISSON_CLIENT.getIdGenerator(key);
// 设置过期时间
idGenerator.expire(expireTime);
// 设置初始值和步长
idGenerator.tryInit(initValue, stepValue);
return idGenerator;
}
/**
* 获取指定业务key的唯一id
*
* @param key 业务key
* @param expireTime 过期时间
* @param initValue ID初始值
* @param stepValue ID步长
* @return 唯一id
*/
public static long nextId(String key, Duration expireTime, Long initValue, Long stepValue) {
return getIdGenerator(key, expireTime, initValue, stepValue).nextId();
}
/**
* 获取指定业务key的唯一id字符串
*
* @param key 业务key
* @param expireTime 过期时间
* @param initValue ID初始值
* @param stepValue ID步长
* @return 唯一id
*/
public static String nextIdStr(String key, Duration expireTime, Long initValue, Long stepValue) {
return String.valueOf(nextId(key, expireTime, initValue, stepValue));
}
/**
* 获取指定业务key的唯一id (ID初始值=1,ID步长=1)
*
* @param key 业务key
* @param expireTime 过期时间
* @return 唯一id
*/
public static long nextId(String key, Duration expireTime) {
return getIdGenerator(key, expireTime, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE).nextId();
}
/**
* 获取指定业务key的唯一id字符串 (ID初始值=1,ID步长=1)
*
* @param key 业务key
* @param expireTime 过期时间
* @return 唯一id
*/
public static String nextIdStr(String key, Duration expireTime) {
return String.valueOf(nextId(key, expireTime));
}
/**
* 获取 yyyyMMdd 开头的唯一id
*
* @return 唯一id
*/
public static String nextIdDate() {
return nextIdDate("");
}
/**
* 获取 prefix + yyyyMMdd 开头的唯一id
*
* @param prefix 业务前缀
* @return 唯一id
*/
public static String nextIdDate(String prefix) {
// 前缀+日期 构建 prefixKey
String prefixKey = StringUtils.format("{}{}", StringUtils.blankToDefault(prefix, ""), DateUtil.format(DateUtil.date(), DatePattern.PURE_DATE_FORMATTER));
// 获取下一个id
long nextId = getIdGenerator(prefixKey, DEFAULT_EXPIRE_TIME_DAY, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE).nextId();
// 返回完整id
return StringUtils.format("{}{}", prefixKey, nextId);
}
/**
* 获取 yyyyMMddHHmmss 开头的唯一id
*
* @return 唯一id
*/
public static String nextIdDateTime() {
return nextIdDateTime("");
}
/**
* 获取 prefix + yyyyMMddHHmmss 开头的唯一id
*
* @param prefix 业务前缀
* @return 唯一id
*/
public static String nextIdDateTime(String prefix) {
// 前缀+日期时间 构建 prefixKey
String prefixKey = StringUtils.format("{}{}", StringUtils.blankToDefault(prefix, ""), DateUtil.format(DateUtil.date(), DatePattern.PURE_DATETIME_FORMATTER));
// 获取下一个id
long nextId = getIdGenerator(prefixKey, DEFAULT_EXPIRE_TIME_MINUTE, DEFAULT_INIT_VALUE, DEFAULT_STEP_VALUE).nextId();
// 返回完整id
return StringUtils.format("{}{}", prefixKey, nextId);
}
}

View File

@ -1,5 +1,6 @@
package org.dromara.demo.controller;
import cn.hutool.core.thread.ThreadUtil;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.domain.R;
import org.dromara.common.redis.utils.RedisUtils;
@ -83,11 +84,7 @@ public class RedisCacheController {
RedisUtils.setCacheObject(key, value);
boolean flag = RedisUtils.expire(key, Duration.ofSeconds(10));
System.out.println("***********" + flag);
try {
Thread.sleep(11 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ThreadUtil.sleep(11 * 1000);
Object obj = RedisUtils.getCacheObject(key);
return R.ok(value.equals(obj));
}

View File

@ -1,5 +1,6 @@
package org.dromara.demo.controller;
import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.lock.LockInfo;
import com.baomidou.lock.LockTemplate;
import com.baomidou.lock.annotation.Lock4j;
@ -33,13 +34,9 @@ public class RedisLockController {
@Lock4j(keys = {"#key"})
@GetMapping("/testLock4j")
public R<String> testLock4j(String key, String value) {
System.out.println("start:" + key + ",time:" + LocalTime.now().toString());
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("end :" + key + ",time:" + LocalTime.now().toString());
System.out.println("start:" + key + ",time:" + LocalTime.now());
ThreadUtil.sleep(10000);
System.out.println("end :" + key + ",time:" + LocalTime.now());
return R.ok("操作成功", value);
}
@ -54,11 +51,7 @@ public class RedisLockController {
}
// 获取锁成功处理业务
try {
try {
Thread.sleep(8000);
} catch (InterruptedException e) {
//
}
ThreadUtil.sleep(8000);
System.out.println("执行简单方法1 , 当前线程:" + Thread.currentThread().getName());
} finally {
//释放锁

View File

@ -97,7 +97,7 @@ public class SysClientController extends BaseController {
@Log(title = "客户端管理", businessType = BusinessType.UPDATE)
@PutMapping("/changeStatus")
public R<Void> changeStatus(@RequestBody SysClientBo bo) {
return toAjax(sysClientService.updateUserStatus(bo.getClientId(), bo.getStatus()));
return toAjax(sysClientService.updateClientStatus(bo.getClientId(), bo.getStatus()));
}
/**

View File

@ -218,7 +218,7 @@ public class SysUserController extends BaseController {
@GetMapping("/optionselect")
public R<List<SysUserVo>> optionselect(@RequestParam(required = false) Long[] userIds,
@RequestParam(required = false) Long deptId) {
return R.ok(userService.selectUserByIds(userIds == null ? null : List.of(userIds), deptId));
return R.ok(userService.selectUserByIds(ArrayUtil.isEmpty(userIds) ? null : List.of(userIds), deptId));
}
/**

View File

@ -50,7 +50,7 @@ public interface ISysClientService {
/**
* 修改状态
*/
int updateUserStatus(String clientId, String status);
int updateClientStatus(String clientId, String status);
/**
* 校验并批量删除客户端管理信息

View File

@ -123,7 +123,7 @@ public class SysClientServiceImpl implements ISysClientService {
*/
@CacheEvict(cacheNames = CacheNames.SYS_CLIENT, key = "#clientId")
@Override
public int updateUserStatus(String clientId, String status) {
public int updateClientStatus(String clientId, String status) {
return baseMapper.update(null,
new LambdaUpdateWrapper<SysClient>()
.set(SysClient::getStatus, status)

View File

@ -116,7 +116,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
.setName(dept.getDeptName())
.setWeight(dept.getOrderNum())
.putExtra("disabled", SystemConstants.DISABLE.equals(dept.getStatus())));
Tree<Long> tree = trees.stream().filter(it -> it.getId().longValue() == d.getDeptId()).findFirst().get();
Tree<Long> tree = StreamUtils.findFirst(trees, it -> it.getId().longValue() == d.getDeptId());
treeList.add(tree);
}
}
@ -425,4 +425,29 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return baseMapper.deleteById(deptId);
}
/**
* 根据部门ID查询部门负责人
*
* @param deptId 部门ID用于指定需要查询的部门
* @return 返回该部门的负责人ID
*/
@Override
public Long selectDeptLeaderById(Long deptId) {
SysDeptVo vo = SpringUtils.getAopProxy(this).selectDeptById(deptId);
return vo.getLeader();
}
/**
* 查询部门
*
* @return 部门列表
*/
@Override
public List<DeptDTO> selectDeptsByList() {
List<SysDeptVo> list = baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptId, SysDept::getDeptName, SysDept::getParentId)
.eq(SysDept::getStatus, SystemConstants.NORMAL));
return BeanUtil.copyToList(list, DeptDTO.class);
}
}

View File

@ -118,8 +118,7 @@ public class SysLogininforServiceImpl implements ISysLogininforService {
.between(params.get("beginTime") != null && params.get("endTime") != null,
SysLogininfor::getLoginTime, params.get("beginTime"), params.get("endTime"));
if (StringUtils.isBlank(pageQuery.getOrderByColumn())) {
pageQuery.setOrderByColumn("info_id");
pageQuery.setIsAsc("desc");
lqw.orderByDesc(SysLogininfor::getInfoId);
}
Page<SysLogininforVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(page);

View File

@ -53,8 +53,7 @@ public class SysOperLogServiceImpl implements ISysOperLogService {
public TableDataInfo<SysOperLogVo> selectPageOperLogList(SysOperLogBo operLog, PageQuery pageQuery) {
LambdaQueryWrapper<SysOperLog> lqw = buildQueryWrapper(operLog);
if (StringUtils.isBlank(pageQuery.getOrderByColumn())) {
pageQuery.setOrderByColumn("oper_id");
pageQuery.setIsAsc("desc");
lqw.orderByDesc(SysOperLog::getOperId);
}
Page<SysOperLogVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw);
return TableDataInfo.build(page);