1.整理pom文件

2.新增定时任务迁移
pull/22/head
rays 2021-07-08 10:23:30 +08:00
parent 7d39c2f1ce
commit d244e40b71
8 changed files with 226 additions and 38 deletions

View File

@ -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>

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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.
*
* GunsAPACHE 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;
/**
* classTimerAction
*/
private String actionClass;
/**
*
*/
private String cron;
/**
*
*/
private String params;
/**
* 1-2-
*/
private Integer jobStatus;
/**
*
*/
private String remark;
/**
* Y-N-
*/
private String delFlag;
}

View File

@ -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>

View File

@ -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>

View File

@ -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;

View File

@ -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>