【V3.5.0】1、【新增】轻量级定时任务 SmartJob;2、【新增】站内信;3、【新增】个人中心;4、【新增】岗位管理;5、【优化】部门员工管理

This commit is contained in:
zhuoda 2024-07-16 23:41:50 +08:00
parent 201b6a5018
commit 4a4d7115ef
7 changed files with 90 additions and 36 deletions

View File

@ -26,7 +26,8 @@ public class RoleEmployeeManager extends ServiceImpl<RoleEmployeeDao, RoleEmploy
* *
*/ */
@Transactional(rollbackFor = Throwable.class) @Transactional(rollbackFor = Throwable.class)
public void saveRoleEmployee(List<RoleEmployeeEntity> roleEmployeeList) { public void saveRoleEmployee(Long roleId, List<RoleEmployeeEntity> roleEmployeeList) {
this.getBaseMapper().deleteByRoleId(roleId);
if (CollectionUtils.isNotEmpty(roleEmployeeList)) { if (CollectionUtils.isNotEmpty(roleEmployeeList)) {
this.saveBatch(roleEmployeeList); this.saveBatch(roleEmployeeList);
} }

View File

@ -110,7 +110,6 @@ public class RoleEmployeeService {
* 批量添加角色的成员员工 * 批量添加角色的成员员工
* *
*/ */
@Transactional(rollbackFor = Throwable.class)
public ResponseDTO<String> batchAddRoleEmployee(RoleEmployeeUpdateForm roleEmployeeUpdateForm) { public ResponseDTO<String> batchAddRoleEmployee(RoleEmployeeUpdateForm roleEmployeeUpdateForm) {
Long roleId = roleEmployeeUpdateForm.getRoleId(); Long roleId = roleEmployeeUpdateForm.getRoleId();
List<Long> employeeIdList = roleEmployeeUpdateForm.getEmployeeIdList(); List<Long> employeeIdList = roleEmployeeUpdateForm.getEmployeeIdList();
@ -121,10 +120,8 @@ public class RoleEmployeeService {
.map(employeeId -> new RoleEmployeeEntity(roleId, employeeId)) .map(employeeId -> new RoleEmployeeEntity(roleId, employeeId))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
// 防重删除此次角色员工数据
roleEmployeeDao.batchDeleteEmployeeRole(roleId, employeeIdList);
// 保存数据 // 保存数据
roleEmployeeManager.saveRoleEmployee(roleEmployeeList); roleEmployeeManager.saveRoleEmployee(roleId, roleEmployeeList);
return ResponseDTO.ok(); return ResponseDTO.ok();
} }

View File

@ -88,8 +88,11 @@ public class SmartJobExecutor implements Runnable {
* @param executorName * @param executorName
*/ */
public SmartJobLogEntity execute(String executorName) { public SmartJobLogEntity execute(String executorName) {
// 执行计时 // 保存执行记录
LocalDateTime startTime = LocalDateTime.now(); LocalDateTime startTime = LocalDateTime.now();
Long logId = this.saveLogBeforeExecute(jobEntity, executorName, startTime);
// 执行计时
StopWatch stopWatch = new StopWatch(); StopWatch stopWatch = new StopWatch();
stopWatch.start(); stopWatch.start();
@ -107,33 +110,49 @@ public class SmartJobExecutor implements Runnable {
log.error("==== SmartJob ==== execute err:", t); log.error("==== SmartJob ==== execute err:", t);
} }
// 保存执行记录 // 更新执行记录
SmartJobLogEntity logEntity = new SmartJobLogEntity();
logEntity.setLogId(logId);
logEntity.setSuccessFlag(successFlag);
long totalTimeMillis = stopWatch.getTotalTimeMillis();
logEntity.setExecuteTimeMillis(totalTimeMillis);
logEntity.setExecuteEndTime(startTime.plus(totalTimeMillis, ChronoUnit.MILLIS));
logEntity.setExecuteResult(executeResult);
jobRepository.getJobLogDao().updateById(logEntity);
return logEntity;
}
/**
* 执行前 保存执行记录
*
* @param jobEntity
* @param executorName
* @param executeTime
* @return 返回执行记录id
*/
private Long saveLogBeforeExecute(SmartJobEntity jobEntity,
String executorName,
LocalDateTime executeTime) {
Integer jobId = jobEntity.getJobId(); Integer jobId = jobEntity.getJobId();
// 保存执行记录
SmartJobLogEntity logEntity = new SmartJobLogEntity(); SmartJobLogEntity logEntity = new SmartJobLogEntity();
logEntity.setJobId(jobId); logEntity.setJobId(jobId);
logEntity.setJobName(jobEntity.getJobName()); logEntity.setJobName(jobEntity.getJobName());
logEntity.setParam(jobEntity.getParam()); logEntity.setParam(jobEntity.getParam());
logEntity.setSuccessFlag(successFlag); logEntity.setSuccessFlag(true);
// 执行开始 结束时间 // 执行开始时间
logEntity.setExecuteStartTime(startTime); logEntity.setExecuteStartTime(executeTime);
long totalTimeMillis = stopWatch.getTotalTimeMillis(); logEntity.setCreateName(executorName);
logEntity.setExecuteTimeMillis(totalTimeMillis);
logEntity.setExecuteEndTime(startTime.plus(totalTimeMillis, ChronoUnit.MILLIS));
// 执行结果
logEntity.setExecuteResult(executeResult);
logEntity.setIp(SmartIpUtil.getLocalFirstIp()); logEntity.setIp(SmartIpUtil.getLocalFirstIp());
logEntity.setProcessId(SmartJobUtil.getProcessId()); logEntity.setProcessId(SmartJobUtil.getProcessId());
logEntity.setProgramPath(SmartJobUtil.getProgramPath()); logEntity.setProgramPath(SmartJobUtil.getProgramPath());
logEntity.setCreateName(executorName);
// 更新上次执行 // 更新最后执行时间
SmartJobEntity updateJobEntity = new SmartJobEntity(); SmartJobEntity updateJobEntity = new SmartJobEntity();
updateJobEntity.setJobId(jobId); updateJobEntity.setJobId(jobId);
updateJobEntity.setLastExecuteTime(startTime); updateJobEntity.setLastExecuteTime(executeTime);
// 持久化数据
jobRepository.saveLog(logEntity, updateJobEntity); jobRepository.saveLog(logEntity, updateJobEntity);
return logEntity; return logEntity.getLogId();
} }
/** /**

View File

@ -25,6 +25,10 @@ public class SmartJobRepository {
return jobDao; return jobDao;
} }
public SmartJobLogDao getJobLogDao() {
return jobLogDao;
}
/** /**
* 保存执行记录 * 保存执行记录
* *
@ -38,5 +42,4 @@ public class SmartJobRepository {
jobEntity.setLastExecuteLogId(logEntity.getLogId()); jobEntity.setLastExecuteLogId(logEntity.getLogId());
jobDao.updateById(jobEntity); jobDao.updateById(jobEntity);
} }
} }

View File

@ -0,0 +1,34 @@
package net.lab1024.sa.base.module.support.redis;
import net.lab1024.sa.base.common.util.SmartStringUtil;
import org.redisson.config.Config;
import org.redisson.spring.starter.RedissonAutoConfigurationCustomizer;
import org.springframework.stereotype.Component;
/**
*
* redission对于password 为空处理有问题重新设置下
*
* @Author 1024创新实验室-主任:卓大
* @Date 2024/7/16 01:04:18
* @Wechat zhuoda1024
* @Email lab1024@163.com
* @Copyright <a href="https://1024lab.net">1024创新实验室</a> Since 2012
*/
@Component
public class RedissonPasswordConfigurationCustomizer implements RedissonAutoConfigurationCustomizer {
@Override
public void customize(Config configuration) {
if (configuration.isSingleConfig() && SmartStringUtil.isEmpty(configuration.useSingleServer().getPassword())) {
configuration.useSingleServer().setPassword(null);
}
if (configuration.isClusterConfig() && SmartStringUtil.isEmpty(configuration.useClusterServers().getPassword())) {
configuration.useClusterServers().setPassword(null);
}
if (configuration.isSentinelConfig() && SmartStringUtil.isEmpty(configuration.useSentinelServers().getPassword())) {
configuration.useSentinelServers().setPassword(null);
}
}
}

View File

@ -1,20 +1,20 @@
spring: spring:
# 数据库连接信息 # 数据库连接信息
datasource: datasource:
url: jdbc:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai url: jdbc:p6spy:mysql://127.0.0.1:3306/smart_admin_v3?autoReconnect=true&useServerPreparedStmts=false&rewriteBatchedStatements=true&characterEncoding=UTF-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai
username: root username: root
password: Zhuoda#1024lab password: Zhuoda1024lab
initial-size: 5 initial-size: 2
min-idle: 5 min-idle: 2
max-active: 20 max-active: 10
max-wait: 60000 max-wait: 60000
time-between-eviction-runs-millis: 60000 time-between-eviction-runs-millis: 60000
min-evictable-idle-time-millis: 300000 min-evictable-idle-time-millis: 300000
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.p6spy.engine.spy.P6SpyDriver
filters: stat filters: stat
druid: druid:
username: druid username: druid
password: 1024lab password: 1024
login: login:
enabled: false enabled: false
method: method:
@ -29,9 +29,9 @@ spring:
timeout: 10000ms timeout: 10000ms
lettuce: lettuce:
pool: pool:
max-active: 50 max-active: 5
min-idle: 5 min-idle: 1
max-idle: 5 max-idle: 3
max-wait: 30000ms max-wait: 30000ms
# 上传文件大小配置 # 上传文件大小配置
@ -74,9 +74,9 @@ file:
upload-path: /home/smart_admin_v3/upload/ #文件上传目录 upload-path: /home/smart_admin_v3/upload/ #文件上传目录
url-prefix: url-prefix:
cloud: cloud:
region: oss-cn-qingdao region: oss-cn-hangzhou
endpoint: oss-cn-qingdao.aliyuncs.com endpoint: oss-cn-hangzhou.aliyuncs.com
bucket-name: common bucket-name: 1024lab-smart-admin
access-key: access-key:
secret-key: secret-key:
url-prefix: https://${file.storage.cloud.bucket-name}.${file.storage.cloud.endpoint}/ url-prefix: https://${file.storage.cloud.bucket-name}.${file.storage.cloud.endpoint}/

View File

@ -1245,7 +1245,7 @@ INSERT INTO `t_smart_job` VALUES (2, '示例任务2', 'net.lab1024.sa.base.modul
-- ---------------------------- -- ----------------------------
DROP TABLE IF EXISTS `t_smart_job_log`; DROP TABLE IF EXISTS `t_smart_job_log`;
CREATE TABLE `t_smart_job_log` ( CREATE TABLE `t_smart_job_log` (
`log_id` int(0) NOT NULL AUTO_INCREMENT, `log_id` bigint(0) NOT NULL AUTO_INCREMENT,
`job_id` int(0) NOT NULL COMMENT '任务id', `job_id` int(0) NOT NULL COMMENT '任务id',
`job_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务名称', `job_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '任务名称',
`param` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '执行参数', `param` varchar(2000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '执行参数',