mirror of https://gitee.com/stylefeng/roses
新增数据迁移模块
parent
374ae979a5
commit
9b34342509
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-s-message</artifactId>
|
||||
<version>7.0.4</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>migration-api</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!--auth模块的api-->
|
||||
<!--记录日志时候,有可能需要记录当前登录用户id-->
|
||||
<!--如果不要记录当前登录用户id时就不用本模块,所以optional=true-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>auth-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,54 @@
|
|||
package cn.stylefeng.roses.kernel.migration.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.migration.api.enums.MigrationAggregationTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.migration.api.pojo.MigrationInfo;
|
||||
|
||||
/**
|
||||
* 接入迁移模块Api
|
||||
* <p>
|
||||
* 1.所有需要接入迁移模块的业务,只需要实现本类即可
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:17
|
||||
*/
|
||||
public interface AccessMigrationApi {
|
||||
|
||||
/**
|
||||
* 获取应用名称
|
||||
*
|
||||
* @return {@link java.lang.String}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 17:15
|
||||
**/
|
||||
String getAppName();
|
||||
|
||||
/**
|
||||
* 获取模块名称
|
||||
*
|
||||
* @return {@link java.lang.String}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 17:15
|
||||
**/
|
||||
String getModuleName();
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @return {@link MigrationInfo}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:20
|
||||
**/
|
||||
MigrationInfo exportData();
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param type 导入类型-参考{@link MigrationAggregationTypeEnum} 枚举
|
||||
* @param data 导出的数据
|
||||
* @return {@link boolean}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:23
|
||||
**/
|
||||
boolean importData(String type, MigrationInfo data);
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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.migration.api.constants;
|
||||
|
||||
/**
|
||||
* migration 模块常量
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:04
|
||||
*/
|
||||
public interface MigrationConstants {
|
||||
|
||||
/**
|
||||
* migration模块的名称
|
||||
*/
|
||||
String MIGRATION_MODULE_NAME = "kernel-d-migration";
|
||||
|
||||
/**
|
||||
* 异常枚举的步进值
|
||||
*/
|
||||
String MIGRATION_EXCEPTION_STEP_CODE = "32";
|
||||
|
||||
/**
|
||||
* 名称分隔符
|
||||
*/
|
||||
String NAME_SEPARATOR = "#";
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package cn.stylefeng.roses.kernel.migration.api.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 迁移类型枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:25
|
||||
*/
|
||||
@Getter
|
||||
public enum MigrationAggregationTypeEnum {
|
||||
|
||||
/**
|
||||
* 全量迁移
|
||||
*/
|
||||
MIGRATION_FULL("FULL", "全量迁移"),
|
||||
|
||||
/**
|
||||
* 增量迁移
|
||||
*/
|
||||
MIGRATION_INCREMENTAL("INCREMENTAL", "增量迁移");
|
||||
|
||||
private final String code;
|
||||
|
||||
private final String name;
|
||||
|
||||
MigrationAggregationTypeEnum(String code, String name) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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.migration.api.exception;
|
||||
|
||||
import cn.stylefeng.roses.kernel.migration.api.constants.MigrationConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
|
||||
|
||||
/**
|
||||
* migration模块异常
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:07
|
||||
*/
|
||||
public class MigrationException extends ServiceException {
|
||||
|
||||
public MigrationException(AbstractExceptionEnum exception) {
|
||||
super(MigrationConstants.MIGRATION_MODULE_NAME, exception);
|
||||
}
|
||||
|
||||
public MigrationException(String errorCode, String userTip) {
|
||||
super(MigrationConstants.MIGRATION_MODULE_NAME, errorCode, userTip);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.migration.api.exception.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.migration.api.constants.MigrationConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Migration模块相关异常枚举
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:09
|
||||
*/
|
||||
@Getter
|
||||
public enum MigrationExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* Migration操作异常
|
||||
*/
|
||||
MIGRATION_ERROR(RuleConstants.THIRD_ERROR_TYPE_CODE + MigrationConstants.MIGRATION_EXCEPTION_STEP_CODE + "01", "操作异常,具体信息为:{}");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
MigrationExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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.migration.api.expander;
|
||||
|
||||
/**
|
||||
* Migration权限相关配置快速获取
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 15:11
|
||||
*/
|
||||
public class MigrationConfigExpander {
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package cn.stylefeng.roses.kernel.migration.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 数据迁移聚合类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:10
|
||||
*/
|
||||
@Data
|
||||
public class MigrationAggregationPOJO extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 应用和模块名称列表
|
||||
*/
|
||||
@NotNull(message = "模块名称不能为空", groups = {export.class, restore.class})
|
||||
private List<String> appAndModuleNameList;
|
||||
|
||||
/**
|
||||
* 数据集
|
||||
*/
|
||||
@NotNull(message = "数据集不能为空", groups = {restore.class})
|
||||
private Map<String, MigrationInfo> data;
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*/
|
||||
public @interface export {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复
|
||||
*/
|
||||
public @interface restore {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package cn.stylefeng.roses.kernel.migration.api.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 迁移数据信息
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:30
|
||||
*/
|
||||
@Data
|
||||
public class MigrationInfo {
|
||||
|
||||
/**
|
||||
* 版本
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 数据
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-s-message</artifactId>
|
||||
<version>7.0.4</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>migration-business-web</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--资源api模块-->
|
||||
<!--用在资源控制器,资源扫描上-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>scanner-api</artifactId>
|
||||
<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>
|
||||
<artifactId>migration-sdk-data-aggregation</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--web模块-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,84 @@
|
|||
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;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestPart;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据迁移控制器
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 17:35
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "数据迁移控制器")
|
||||
public class MigrationController {
|
||||
|
||||
@Autowired
|
||||
private MigrationService migrationService;
|
||||
|
||||
/**
|
||||
* 获取所有可备份数据列表
|
||||
*
|
||||
* @return {@link ResponseData}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 17:37
|
||||
**/
|
||||
@GetResource(name = "获取所有可备份数据列表", path = "/dataMigration/getAllMigrationList")
|
||||
public ResponseData getAllMigrationList() {
|
||||
List<MigrationRequest> migrationRequestList = migrationService.getAllMigrationList();
|
||||
return new SuccessResponseData(migrationRequestList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份指定数据列表
|
||||
*
|
||||
* @return {@link cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData}
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 11:11
|
||||
**/
|
||||
@GetResource(name = "备份指定数据列表", path = "/dataMigration/migrationSelectData")
|
||||
public ResponseData migrationSelectData(@Validated(MigrationAggregationPOJO.export.class) MigrationAggregationPOJO migrationAggregationPOJO) {
|
||||
List<String> res = new ArrayList<>();
|
||||
for (String s : migrationAggregationPOJO.getAppAndModuleNameList()) {
|
||||
try {
|
||||
String decode = URLDecoder.decode(s, "UTF-8");
|
||||
res.add(decode);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
migrationAggregationPOJO.setAppAndModuleNameList(res);
|
||||
String migrationSelectDataStr = migrationService.migrationSelectData(migrationAggregationPOJO);
|
||||
return new SuccessResponseData(migrationSelectDataStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复备份数据
|
||||
*
|
||||
* @return {@link ResponseData}
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 11:11
|
||||
**/
|
||||
@PostResource(name = "恢复备份数据", path = "/dataMigration/restoreData")
|
||||
public ResponseData restoreData(@RequestPart("file") MultipartFile file,String type) {
|
||||
migrationService.restoreData(file,type);
|
||||
return new SuccessResponseData();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.stylefeng.roses.kernel.migration.web.pojo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 迁移数据请求对象
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 9:15
|
||||
*/
|
||||
@Data
|
||||
public class MigrationRequest {
|
||||
|
||||
/**
|
||||
* 应用名称
|
||||
*/
|
||||
private String appName;
|
||||
|
||||
/**
|
||||
* 模块列表
|
||||
*/
|
||||
private List<String> moduleNames;
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package cn.stylefeng.roses.kernel.migration.web.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.migration.api.pojo.MigrationAggregationPOJO;
|
||||
import cn.stylefeng.roses.kernel.migration.web.pojo.MigrationRequest;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 迁移服务接口
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 9:34
|
||||
*/
|
||||
public interface MigrationService {
|
||||
|
||||
/**
|
||||
* 获取所有可备份数据列表
|
||||
*
|
||||
* @return {@link List< MigrationRequest>}
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 9:36
|
||||
**/
|
||||
List<MigrationRequest> getAllMigrationList();
|
||||
|
||||
/**
|
||||
* 备份指定数据列表
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 9:37
|
||||
**/
|
||||
String migrationSelectData(MigrationAggregationPOJO migrationAggregationPOJO);
|
||||
|
||||
/**
|
||||
* 恢复备份数据
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 11:14
|
||||
**/
|
||||
void restoreData(MultipartFile file,String type);
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package cn.stylefeng.roses.kernel.migration.web.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.stylefeng.roses.kernel.migration.aggregation.scheduling.SchedulingCenter;
|
||||
import cn.stylefeng.roses.kernel.migration.api.constants.MigrationConstants;
|
||||
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;
|
||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 迁移服务实现类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 9:34
|
||||
*/
|
||||
@Service
|
||||
public class MigrationServiceImpl implements MigrationService {
|
||||
|
||||
@Override
|
||||
public List<MigrationRequest> getAllMigrationList() {
|
||||
// 结构:应用-模块列表
|
||||
Map<String, MigrationRequest> migrationRequestList = new HashMap<>();
|
||||
|
||||
// 获取所有应用和模块的名称列表
|
||||
List<String> allMigrationInfo = SchedulingCenter.getAllMigrationInfo();
|
||||
|
||||
// 应用,模块映射关系
|
||||
for (String migration : allMigrationInfo) {
|
||||
|
||||
// 分割应用名称和模块名称
|
||||
String[] appAndModuleName = migration.split(MigrationConstants.NAME_SEPARATOR);
|
||||
|
||||
// 获取应用名称
|
||||
String appName = appAndModuleName[0];
|
||||
|
||||
// 获取模块名称
|
||||
String moduleName = appAndModuleName[1];
|
||||
|
||||
// 查找该应用
|
||||
MigrationRequest migrationRequest = migrationRequestList.get(appName);
|
||||
if (ObjectUtil.isEmpty(migrationRequest)) {
|
||||
migrationRequest = new MigrationRequest();
|
||||
migrationRequest.setAppName(appName);
|
||||
migrationRequestList.put(appName, migrationRequest);
|
||||
}
|
||||
|
||||
// 该应用是否有模块
|
||||
List<String> moduleNames = migrationRequest.getModuleNames();
|
||||
if (ObjectUtil.isEmpty(moduleNames)) {
|
||||
moduleNames = new ArrayList<>();
|
||||
migrationRequest.setModuleNames(moduleNames);
|
||||
}
|
||||
|
||||
moduleNames.add(moduleName);
|
||||
}
|
||||
return new ArrayList<>(migrationRequestList.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String migrationSelectData(MigrationAggregationPOJO migrationAggregationPOJO) {
|
||||
// 执行导出逻辑
|
||||
SchedulingCenter.exportData(migrationAggregationPOJO);
|
||||
|
||||
// 转换为Json字符串
|
||||
return JSON.toJSONString(migrationAggregationPOJO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreData(MultipartFile file,String type) {
|
||||
String jsonStr = null;
|
||||
try {
|
||||
// 转换文件为String类型
|
||||
jsonStr = new String(file.getBytes(), StandardCharsets.UTF_8);
|
||||
|
||||
// 把字符串转为java对象
|
||||
MigrationAggregationPOJO migrationAggregationPOJO = JSON.parseObject(jsonStr, MigrationAggregationPOJO.class);
|
||||
|
||||
// 交给调度中心去调度
|
||||
SchedulingCenter.importData(migrationAggregationPOJO,type);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-s-message</artifactId>
|
||||
<version>7.0.4</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>migration-sdk-data-aggregation</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!--migration模块的api-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>migration-api</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,122 @@
|
|||
package cn.stylefeng.roses.kernel.migration.aggregation.scheduling;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.migration.api.AccessMigrationApi;
|
||||
import cn.stylefeng.roses.kernel.migration.api.constants.MigrationConstants;
|
||||
import cn.stylefeng.roses.kernel.migration.api.pojo.MigrationAggregationPOJO;
|
||||
import cn.stylefeng.roses.kernel.migration.api.pojo.MigrationInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 调度中心
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:01
|
||||
*/
|
||||
public class SchedulingCenter {
|
||||
|
||||
/**
|
||||
* 迁移数据接入集合
|
||||
*/
|
||||
private static final ConcurrentHashMap<String, AccessMigrationApi> migrationCollection = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 接入一个迁移类
|
||||
*
|
||||
* @param accessMigrationApi 迁移接口
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 17:21
|
||||
**/
|
||||
public static void addMigration(AccessMigrationApi accessMigrationApi) {
|
||||
|
||||
// 拼接key值
|
||||
String appAndModuleNameItem = accessMigrationApi.getAppName() + MigrationConstants.NAME_SEPARATOR + accessMigrationApi.getModuleName();
|
||||
|
||||
// 存储迁移类
|
||||
migrationCollection.put(appAndModuleNameItem, accessMigrationApi);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据
|
||||
*
|
||||
* @param migrationAggregationPOJO 导入的数据
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:10
|
||||
**/
|
||||
public static void importData(MigrationAggregationPOJO migrationAggregationPOJO, String type) {
|
||||
|
||||
// 所有导入数据集合
|
||||
Map<String, MigrationInfo> migrationInfoMap = migrationAggregationPOJO.getData();
|
||||
|
||||
// 找到每个应用的处理程序,调用相关方法
|
||||
for (String appAndModuleName : migrationAggregationPOJO.getAppAndModuleNameList()) {
|
||||
AccessMigrationApi accessMigrationApi = migrationCollection.get(appAndModuleName);
|
||||
if (ObjectUtil.isNotEmpty(accessMigrationApi)) {
|
||||
|
||||
// 找到数据
|
||||
MigrationInfo migrationInfo = migrationInfoMap.get(appAndModuleName);
|
||||
|
||||
// 发送给实现类处理
|
||||
try {
|
||||
accessMigrationApi.importData(type, migrationInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @param migrationAggregationPOJO 导出要求
|
||||
* @return {@link MigrationAggregationPOJO}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:11
|
||||
**/
|
||||
public static MigrationAggregationPOJO exportData(MigrationAggregationPOJO migrationAggregationPOJO) {
|
||||
Map<String, MigrationInfo> data = migrationAggregationPOJO.getData();
|
||||
if (ObjectUtil.isEmpty(data)) {
|
||||
data = new HashMap<>();
|
||||
migrationAggregationPOJO.setData(data);
|
||||
}
|
||||
|
||||
// 导出所有指定项
|
||||
for (String appAndModuleName : migrationAggregationPOJO.getAppAndModuleNameList()) {
|
||||
// 查找对应的实现类
|
||||
AccessMigrationApi accessMigrationApi = migrationCollection.get(appAndModuleName);
|
||||
if (ObjectUtil.isNotEmpty(accessMigrationApi)) {
|
||||
// 执行导出
|
||||
try {
|
||||
// 获取数据
|
||||
MigrationInfo migrationInfo = accessMigrationApi.exportData();
|
||||
|
||||
// 放入返回结果中
|
||||
data.put(appAndModuleName, migrationInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
data.put(appAndModuleName, new MigrationInfo());
|
||||
}
|
||||
}
|
||||
|
||||
return migrationAggregationPOJO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有迁移数据列表
|
||||
*
|
||||
* @return {@link java.util.List<MigrationInfo>}
|
||||
* @author majianguo
|
||||
* @date 2021/7/6 16:13
|
||||
**/
|
||||
public static List<String> getAllMigrationInfo() {
|
||||
return new ArrayList<>(migrationCollection.keySet());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-s-message</artifactId>
|
||||
<version>7.0.4</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>migration-spring-boot-starter</artifactId>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--migration模块的SDK-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>migration-sdk-data-aggregation</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--migration模块的业务-->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>migration-business-web</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,33 @@
|
|||
package cn.stylefeng.roses.kernel.migration.starter.spring;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.migration.aggregation.scheduling.SchedulingCenter;
|
||||
import cn.stylefeng.roses.kernel.migration.api.AccessMigrationApi;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Spring boot启动完成的回调
|
||||
* <p>
|
||||
* 用于扫描所有的迁移实现类
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2021/7/7 9:49
|
||||
*/
|
||||
@Component
|
||||
public class MigrationApplicationRunnerImpl implements ApplicationRunner {
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
|
||||
// 获取所有的实现类
|
||||
Map<String, AccessMigrationApi> accessMigrationApiMap = SpringUtil.getBeansOfType(AccessMigrationApi.class);
|
||||
for (AccessMigrationApi accessMigrationApi : accessMigrationApiMap.values()) {
|
||||
// 加入调度中心
|
||||
SchedulingCenter.addMigration(accessMigrationApi);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.0.4</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>kernel-s-migration</artifactId>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>migration-api</module>
|
||||
<module>migration-sdk-data-aggregation</module>
|
||||
<module>migration-business-web</module>
|
||||
<module>migration-spring-boot-starter</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!-- 开发规则 -->
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-a-rule</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
Loading…
Reference in New Issue