TASK:数据迁移;
This commit is contained in:
@@ -10,8 +10,11 @@ import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.ResultEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.FileUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.LibraryCopyMapper;
|
||||
import com.ai.da.mapper.LibraryMapper;
|
||||
import com.ai.da.mapper.LibraryModelPointCopyMapper;
|
||||
import com.ai.da.mapper.SysFileMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.model.dto.*;
|
||||
@@ -30,15 +33,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.base.Function;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@@ -463,6 +477,121 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
libraryMapper.delete(qw);
|
||||
}
|
||||
|
||||
@Resource
|
||||
private LibraryCopyMapper libraryCopyMapper;
|
||||
@Resource
|
||||
private LibraryModelPointCopyMapper libraryModelPointCopyMapper;
|
||||
@Override
|
||||
public void moveLibraryDate() throws ParseException {
|
||||
QueryWrapper<LibraryCopy> qw = new QueryWrapper<>();
|
||||
// 定义日期格式
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// 定义日期字符串
|
||||
String dateString = "2023-09-01 00:00:00";
|
||||
qw.gt("create_date", dateFormat.parse(dateString));
|
||||
// 生产所有数据
|
||||
List<LibraryCopy> libraryList = libraryCopyMapper.selectList(qw);
|
||||
for (LibraryCopy libraryCopy : libraryList) {
|
||||
QueryWrapper<Library> one = new QueryWrapper<>();
|
||||
one.lambda().eq(Library::getAccountId, libraryCopy.getAccountId());
|
||||
one.lambda().eq(Library::getMd5, libraryCopy.getMd5());
|
||||
List<Library> libraryList1 = libraryMapper.selectList(one);
|
||||
if (CollectionUtil.isNotEmpty(libraryList1)) {
|
||||
continue;
|
||||
}
|
||||
String url = libraryCopy.getUrl();
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
continue;
|
||||
}
|
||||
if (url.contains("/download/")) {
|
||||
String[] downloads = url.split("/download/");
|
||||
if (downloads.length == 2) {
|
||||
String linux = downloads[1];
|
||||
String windows = linux.replaceAll("/", "\\\\");
|
||||
String path = "C:\\workspace\\fileData\\file\\" + windows;
|
||||
File file = FileUtil.getFile(path);
|
||||
if (file != null) {
|
||||
String name = file.getName();
|
||||
System.out.println(name);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(libraryCopy.getAccountId()).append("/").append(libraryCopy.getLevel1Type().toLowerCase()).append("/");
|
||||
if (libraryCopy.getLevel1Type().equals("Sketchboard") || libraryCopy.getLevel1Type().equals("Models")) {
|
||||
sb.append("female/");
|
||||
}
|
||||
if (!StringUtils.isEmpty(libraryCopy.getLevel2Type())) {
|
||||
sb.append(libraryCopy.getLevel2Type().toLowerCase()).append("/");
|
||||
}
|
||||
sb.append(name);
|
||||
String bucketName = users;
|
||||
boolean b = minioUtil.doesObjectExist(bucketName, sb.toString());
|
||||
if (!b) {
|
||||
FileItem a = getMultipartFile(file, file.getName());
|
||||
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
||||
String upload = minioUtil.upload(bucketName, sb.toString(), multipartFile, "");
|
||||
Library newInsert = CopyUtil.copyObject(libraryCopy, Library.class);
|
||||
newInsert.setId(null);
|
||||
if (libraryCopy.getLevel1Type().equals("Models")) {
|
||||
newInsert.setLevel2Type("Female");
|
||||
QueryWrapper<LibraryModelPointCopy> modelCopy = new QueryWrapper<>();
|
||||
modelCopy.lambda().eq(LibraryModelPointCopy::getLibraryId, libraryCopy.getId());
|
||||
LibraryModelPointCopy libraryModelPointCopy = libraryModelPointCopyMapper.selectOne(modelCopy);
|
||||
LibraryModelPoint libraryModelPoint = CopyUtil.copyObject(libraryModelPointCopy, LibraryModelPoint.class);
|
||||
libraryModelPoint.setModelType("Library");
|
||||
|
||||
upload = processMannequins(upload);
|
||||
newInsert.setUrl(upload);
|
||||
libraryMapper.insert(newInsert);
|
||||
|
||||
libraryModelPoint.setRelationId(newInsert.getId());
|
||||
libraryModelPoint.setId(null);
|
||||
libraryModelPointService.saveOrUpdate(libraryModelPoint);
|
||||
continue;
|
||||
}
|
||||
if (libraryCopy.getLevel1Type().equals("Sketchboard")) {
|
||||
newInsert.setLevel3Type("Female");
|
||||
}
|
||||
newInsert.setUrl(upload);
|
||||
libraryMapper.insert(newInsert);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static FileItem getMultipartFile(File file, String fieldName) {
|
||||
// 使用 DiskFileItemFactory 创建一个 FileItemFactory
|
||||
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
||||
|
||||
// 使用 FileItemFactory 创建一个 FileItem 对象
|
||||
String mimeType = getMimeType(file);
|
||||
FileItem item = factory.createItem(fieldName, mimeType, true, file.getName());
|
||||
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file);
|
||||
OutputStream os = item.getOutputStream()) {
|
||||
// 从文件中读取数据并写入 FileItem
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private static String getMimeType(File file) {
|
||||
try {
|
||||
return Files.probeContentType(file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void checkModel(String value, List<Long> modelIds, Integer deleteModelConfirm) {
|
||||
|
||||
Reference in New Issue
Block a user