mirror of https://gitee.com/stylefeng/roses
parent
7d39c2f1ce
commit
d244e40b71
|
@ -64,6 +64,13 @@
|
|||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--迁移模块的sdk-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>migration-sdk-data-aggregation</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--web模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
|
|
@ -0,0 +1,109 @@
|
|||
package cn.stylefeng.roses.kernel.timer.modular.migration;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.migration.api.AccessMigrationApi;
|
||||
import cn.stylefeng.roses.kernel.migration.api.enums.MigrationAggregationTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.migration.api.pojo.MigrationInfo;
|
||||
import cn.stylefeng.roses.kernel.timer.api.enums.TimerJobStatusEnum;
|
||||
import cn.stylefeng.roses.kernel.timer.modular.entity.SysTimers;
|
||||
import cn.stylefeng.roses.kernel.timer.modular.migration.pojo.TimerMigrationInfo;
|
||||
import cn.stylefeng.roses.kernel.timer.modular.migration.pojo.v1.SysTimersMigration;
|
||||
import cn.stylefeng.roses.kernel.timer.modular.param.SysTimersParam;
|
||||
import cn.stylefeng.roses.kernel.timer.modular.service.SysTimersService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 定时任务迁移接入实现
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/8 9:24
|
||||
*/
|
||||
@Component
|
||||
public class TimerMigrationImpl implements AccessMigrationApi {
|
||||
|
||||
@Autowired
|
||||
private SysTimersService sysTimersService;
|
||||
|
||||
@Override
|
||||
public String getAppName() {
|
||||
return "系统应用";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModuleName() {
|
||||
return "定时任务";
|
||||
}
|
||||
|
||||
@Override
|
||||
public MigrationInfo exportData() {
|
||||
MigrationInfo migrationInfo = new MigrationInfo();
|
||||
migrationInfo.setVersion("v1");
|
||||
|
||||
// 聚合对象
|
||||
TimerMigrationInfo timerMigrationInfo = new TimerMigrationInfo();
|
||||
migrationInfo.setData(timerMigrationInfo);
|
||||
|
||||
// 填充数据
|
||||
List<SysTimers> sysTimers = sysTimersService.list();
|
||||
List<SysTimersMigration> sysTimersMigrations;
|
||||
if (ObjectUtil.isNotEmpty(sysTimers)) {
|
||||
sysTimersMigrations = sysTimers.stream().map(item -> BeanUtil.toBean(item, SysTimersMigration.class)).collect(Collectors.toList());
|
||||
} else {
|
||||
sysTimersMigrations = new ArrayList<>();
|
||||
}
|
||||
timerMigrationInfo.setSysTimersMigrationList(sysTimersMigrations);
|
||||
|
||||
return migrationInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importData(String type, MigrationInfo data) {
|
||||
TimerMigrationInfo timerMigrationInfo = JSONObject.toJavaObject((JSONObject)data.getData(), TimerMigrationInfo.class);
|
||||
|
||||
if (MigrationAggregationTypeEnum.MIGRATION_INCREMENTAL.getCode().equals(type)) {
|
||||
// 查询配置信息
|
||||
List<SysTimersMigration> sysTimersMigrationList = timerMigrationInfo.getSysTimersMigrationList();
|
||||
if (ObjectUtil.isNotEmpty(sysTimersMigrationList)) {
|
||||
Set<Long> ids = sysTimersMigrationList.stream().map(SysTimersMigration::getTimerId).collect(Collectors.toSet());
|
||||
|
||||
// 组装查询条件
|
||||
LambdaQueryWrapper<SysTimers> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.select(SysTimers::getTimerId);
|
||||
lambdaQueryWrapper.in(SysTimers::getTimerId, ids);
|
||||
List<SysTimers> dbList = sysTimersService.list(lambdaQueryWrapper);
|
||||
|
||||
// 移除已存在项
|
||||
for (SysTimers db : dbList) {
|
||||
sysTimersMigrationList.removeIf(item -> item.getTimerId().equals(db.getTimerId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 入库
|
||||
List<SysTimersMigration> sysTimersMigrationList = timerMigrationInfo.getSysTimersMigrationList();
|
||||
if (ObjectUtil.isNotEmpty(sysTimersMigrationList)) {
|
||||
List<SysTimers> sysTimers = sysTimersMigrationList.stream().map(item -> BeanUtil.toBean(item, SysTimers.class)).collect(Collectors.toList());
|
||||
sysTimersService.saveOrUpdateBatch(sysTimers);
|
||||
|
||||
// 启动任务
|
||||
for (SysTimers sysTimer : sysTimers) {
|
||||
SysTimersParam sysTimersParam = BeanUtil.toBean(sysTimer, SysTimersParam.class);
|
||||
if (TimerJobStatusEnum.RUNNING.getCode().equals(sysTimer.getJobStatus())) {
|
||||
sysTimersService.start(sysTimersParam);
|
||||
} else {
|
||||
sysTimersService.stop(sysTimersParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package cn.stylefeng.roses.kernel.timer.modular.migration.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.timer.modular.migration.pojo.v1.SysTimersMigration;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 定时任务迁移信息
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/8 9:13
|
||||
*/
|
||||
@Data
|
||||
public class TimerMigrationInfo {
|
||||
|
||||
/**
|
||||
* 定时任务列表
|
||||
*/
|
||||
private List<SysTimersMigration> sysTimersMigrationList;
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.timer.modular.migration.pojo.v1;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 定时任务
|
||||
*
|
||||
* @author stylefeng
|
||||
* @date 2020/6/30 18:26
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysTimersMigration extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 定时器id
|
||||
*/
|
||||
private Long timerId;
|
||||
|
||||
/**
|
||||
* 任务名称
|
||||
*/
|
||||
private String timerName;
|
||||
|
||||
/**
|
||||
* 执行任务的class的类名(实现了TimerAction接口的类的全称)
|
||||
*/
|
||||
private String actionClass;
|
||||
|
||||
/**
|
||||
* 定时任务表达式
|
||||
*/
|
||||
private String cron;
|
||||
|
||||
/**
|
||||
* 参数
|
||||
*/
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 状态:1-运行,2-停止
|
||||
*/
|
||||
private Integer jobStatus;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 是否删除:Y-被删除,N-未删除
|
||||
*/
|
||||
private String delFlag;
|
||||
|
||||
}
|
|
@ -16,15 +16,15 @@
|
|||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!--auth模块的api-->
|
||||
<!--记录日志时候,有可能需要记录当前登录用户id-->
|
||||
<!--如果不要记录当前登录用户id时就不用本模块,所以optional=true-->
|
||||
|
||||
<!--参数校验模块-->
|
||||
<!--用在控制器,参数校验-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>auth-api</artifactId>
|
||||
<artifactId>validator-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -25,30 +25,6 @@
|
|||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--参数校验模块-->
|
||||
<!--用在控制器,参数校验-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>validator-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--数据库sdk-->
|
||||
<!--数据库初始化-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>db-sdk-init</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--数据库sdk-->
|
||||
<!--数据库dao框架-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>db-sdk-mp</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--数据迁移sdk-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package cn.stylefeng.roses.kernel.migration.web.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.migration.aggregation.scheduling.SchedulingCenter;
|
||||
import cn.stylefeng.roses.kernel.migration.api.pojo.MigrationAggregationPOJO;
|
||||
import cn.stylefeng.roses.kernel.migration.web.pojo.MigrationRequest;
|
||||
import cn.stylefeng.roses.kernel.migration.web.service.MigrationService;
|
||||
|
|
|
@ -16,14 +16,7 @@
|
|||
|
||||
<dependencies>
|
||||
|
||||
<!--migration模块的SDK-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>migration-sdk-data-aggregation</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--migration模块的业务-->
|
||||
<!--migration的业务模块-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>migration-business-web</artifactId>
|
||||
|
|
Loading…
Reference in New Issue