|
@@ -17,6 +17,7 @@ import com.persagy.dmp.common.constant.CommonConstant;
|
|
|
import com.persagy.dmp.common.constant.ResponseCode;
|
|
|
import com.persagy.dmp.common.exception.BusinessException;
|
|
|
import com.persagy.dmp.file.context.OldFileAppContext;
|
|
|
+import com.persagy.dmp.file.dao.FileMapper;
|
|
|
import com.persagy.dmp.file.service.CompatibleOldFileService;
|
|
|
import com.persagy.dmp.file.service.FileMigrateService;
|
|
|
import lombok.Data;
|
|
@@ -40,6 +41,8 @@ import java.util.Set;
|
|
|
public class ImageUrlToImageUrlServiceImpl implements FileMigrateService {
|
|
|
|
|
|
private final CompatibleOldFileService compatibleOldFileService;
|
|
|
+ private final FileMapper fileMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void migrateFiles(Map<String, Object> requestMap) {
|
|
@@ -51,6 +54,10 @@ public class ImageUrlToImageUrlServiceImpl implements FileMigrateService {
|
|
|
final String toSecret = MapUtil.getStr(requestMap, "toSecret");
|
|
|
final Set<String> fileKeys = MapUtil.get(requestMap, "keys", new TypeReference<Set<String>>() {});
|
|
|
final boolean deleteOldFileFlag = MapUtil.getBool(requestMap, "deleteOldFileFlag",false);
|
|
|
+ final boolean physicalMigrateFlag = MapUtil.getBool(requestMap, "physicalMigrateFlag",false);
|
|
|
+ final Set<String> extractInfos = MapUtil.get(requestMap, "extractInfos",new TypeReference<Set<String>>() {});
|
|
|
+ final Set<String> groupCodes = MapUtil.get(requestMap, "groupCodes",new TypeReference<Set<String>>() {});
|
|
|
+ final String schema = MapUtil.getStr(requestMap, "schema");
|
|
|
if(StrUtil.isBlank(fromImageServiceUrl)
|
|
|
|| StrUtil.isBlank(fromSystemId)
|
|
|
|| StrUtil.isBlank(toImageServiceUrl)
|
|
@@ -63,33 +70,38 @@ public class ImageUrlToImageUrlServiceImpl implements FileMigrateService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- ThreadUtil.execute(() -> startMigrate(fromImageServiceUrl,fromSystemId,fromSecret,toImageServiceUrl,toSystemId,toSecret,deleteOldFileFlag,fileKeys));
|
|
|
+ ThreadUtil.execute(() -> startMigrate(fromImageServiceUrl,fromSystemId,fromSecret,toImageServiceUrl,toSystemId,
|
|
|
+ toSecret,deleteOldFileFlag,fileKeys,physicalMigrateFlag,extractInfos,groupCodes,schema));
|
|
|
}
|
|
|
|
|
|
|
|
|
* Description: 启动数据迁移
|
|
|
- * @param fromImageServiceUrl: 来源文件的地址
|
|
|
- * @param fromSystemId:来源文件的用户id
|
|
|
- * @param fromSecret:来源文件的用户密码
|
|
|
- * @param toImageServiceUrl:去向文件的地址
|
|
|
- * @param toSystemId:去向文件的用户id
|
|
|
- * @param toSecret:去向文件的用户密码
|
|
|
- * @param deleteOldFileFlag:是否删除旧文件的标记
|
|
|
- * @param fileKeys:是否只迁移部分文件key列表
|
|
|
- * @return : void
|
|
|
+ * @param fromImageServiceUrl : 来源文件的地址
|
|
|
+ * @param fromSystemId :来源文件的用户id
|
|
|
+ * @param fromSecret :来源文件的用户密码
|
|
|
+ * @param toImageServiceUrl :去向文件的地址
|
|
|
+ * @param toSystemId :去向文件的用户id
|
|
|
+ * @param toSecret :去向文件的用户密码
|
|
|
+ * @param deleteOldFileFlag :是否删除旧文件的标记
|
|
|
+ * @param fileKeys :是否只迁移部分文件key列表
|
|
|
+ * @param physicalMigrateFlag: 只迁移物理世界文件标记
|
|
|
+ * @param extractInfos:额外拥有图片key的信息点
|
|
|
+ * @param groupCodes: 集团编码
|
|
|
* @author : lijie
|
|
|
* @date :2021/9/9 23:31
|
|
|
* Update By lijie 2021/9/9 23:31
|
|
|
*/
|
|
|
private void startMigrate(String fromImageServiceUrl, String fromSystemId, String fromSecret, String toImageServiceUrl,
|
|
|
- String toSystemId, String toSecret, boolean deleteOldFileFlag, Set<String> fileKeys){
|
|
|
+ String toSystemId, String toSecret, Boolean deleteOldFileFlag, Set<String> fileKeys,
|
|
|
+ Boolean physicalMigrateFlag, Set<String> extractInfos, Set<String> groupCodes,String schema){
|
|
|
final Map<String,String> uriMap = MapUtil.of("/common/images_list","/common/image_get");
|
|
|
uriMap.put("/common/files_list","/common/file_get");
|
|
|
final String urlFormat = "{}{}?systemId={}";
|
|
|
for (String listSubUrl : uriMap.keySet()) {
|
|
|
String requestListUrl = StrUtil.format(urlFormat,fromImageServiceUrl,listSubUrl,fromSystemId);
|
|
|
transferFile(requestListUrl,null,fromImageServiceUrl,fromSystemId,fromSecret,deleteOldFileFlag,
|
|
|
- fileKeys,uriMap.get(listSubUrl),toImageServiceUrl,toSystemId,toSecret);
|
|
|
+ fileKeys,uriMap.get(listSubUrl),toImageServiceUrl,toSystemId,toSecret,physicalMigrateFlag,
|
|
|
+ extractInfos,groupCodes,schema);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -101,9 +113,29 @@ public class ImageUrlToImageUrlServiceImpl implements FileMigrateService {
|
|
|
*/
|
|
|
private void transferFile(String requestListUrl,String fromKey,String fromImageServiceUrl, String fromSystemId,
|
|
|
String fromSecret, Boolean deleteOldFileFlag,Set<String> destFileKeys, String getUrl,
|
|
|
- String toImageServiceUrl,String toSystemId,String toSecret) {
|
|
|
+ String toImageServiceUrl,String toSystemId,String toSecret,
|
|
|
+ Boolean physicalMigrateFlag, Set<String> extractInfos, Set<String> groupCodes,String schema) {
|
|
|
final int pageSize = 1000;
|
|
|
JSONObject param = new JSONObject();
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(destFileKeys) && physicalMigrateFlag
|
|
|
+ && CollUtil.isNotEmpty(groupCodes)
|
|
|
+ && StrUtil.isNotBlank(schema)){
|
|
|
+ for (String groupCode : groupCodes) {
|
|
|
+ String fileKey = fileMapper.queryFileKeysByInfos(schema,groupCode.toLowerCase(),extractInfos);
|
|
|
+ if (StrUtil.isBlank(fileKey)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> fileKeys = JSONArray.parseArray(fileKey, String.class);
|
|
|
+ if (CollUtil.isEmpty(fileKeys)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ transferFileInternal(CollUtil.newHashSet(fileKeys),fromImageServiceUrl,fromSystemId,fromSecret,deleteOldFileFlag,getUrl,
|
|
|
+ toImageServiceUrl,toSystemId,toSecret);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
if (CollUtil.isNotEmpty(destFileKeys)){
|
|
|
|
|
@@ -139,7 +171,8 @@ public class ImageUrlToImageUrlServiceImpl implements FileMigrateService {
|
|
|
return;
|
|
|
}
|
|
|
transferFile(requestListUrl,fileKeys.get(fileKeys.size() - 1),fromImageServiceUrl,fromSystemId,fromSecret,
|
|
|
- deleteOldFileFlag,destFileKeys,getUrl,toImageServiceUrl,toSystemId,toSecret);
|
|
|
+ deleteOldFileFlag,destFileKeys,getUrl,toImageServiceUrl,toSystemId,toSecret,physicalMigrateFlag,
|
|
|
+ extractInfos,groupCodes,schema);
|
|
|
}
|
|
|
|
|
|
* Description: 根据key列表迁移文件
|