12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package com.sooka.sponest.data.utils;
- import com.ruoyi.common.core.utils.StringUtils;
- import com.ruoyi.common.core.utils.file.FilePrefixUtils;
- import com.sooka.sponest.data.system.attach.domain.CenterdataTAttach;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * 附件文件 保存前处理
- */
- public class FileUtil {
- private FileUtil() {
- throw new IllegalStateException("Utility class");
- }
- public static List<CenterdataTAttach> documentProcessing(String id, String attachId, List<String> fileUrlsList, List<String> fileNamesList, String source, String busindx) {
- List<CenterdataTAttach> list = new ArrayList<>();
- // 新增逻辑
- if (StringUtils.isBlank(id)) {
- for (int i = 0; i < fileUrlsList.size(); i++) {
- if (null == fileUrlsList.get(i)) {
- continue;
- }
- String fileUrl = fileUrlsList.get(i).replace(",", "");
- String fileName = fileNamesList.get(i).replace(",", "");
- CenterdataTAttach centerdataTAttach = new CenterdataTAttach();
- String filetype = FilePrefixUtils.getUrlSuffix(fileUrlsList.get(i));
- centerdataTAttach.setFileType(filetype);
- centerdataTAttach.setBusId(attachId);
- centerdataTAttach.setBusSource(source);
- centerdataTAttach.setAttachPath(fileUrl);
- centerdataTAttach.setBusIndx(busindx);
- centerdataTAttach.setFileName(fileName);
- attach(centerdataTAttach);
- list.add(centerdataTAttach);
- }
- } else {
- String fileUrl = "";
- for (int i = 0; i < fileUrlsList.size(); i++) {
- if (null == fileUrlsList.get(i)) {
- continue;
- }
- CenterdataTAttach centerdataTAttach = new CenterdataTAttach();
- centerdataTAttach.setBusId(attachId);
- if (fileUrlsList.get(i).indexOf("+") > -1 || fileUrlsList.get(i).indexOf("&&") > -1) {
- if (fileUrlsList.get(i).indexOf("+") > -1) {
- fileUrl = fileUrlsList.get(i).substring(0, fileUrlsList.get(i).indexOf("+"));
- } else {
- fileUrl = fileUrlsList.get(i);
- }
- String[] fileurls = fileUrl.split("&&");
- fileUrl = fileurls[1].substring(fileurls[1].indexOf("=") + 1) + "/" + fileurls[2].substring(fileurls[2].indexOf("=") + 1);
- } else {
- fileUrl = fileUrlsList.get(i);
- }
- String fileName = fileNamesList.get(i).replace(",", "");
- fileUrl = fileUrl.replace(",", "");
- String filetype = FilePrefixUtils.getUrlSuffix(fileUrlsList.get(i));
- centerdataTAttach.setFileType(filetype);
- centerdataTAttach.setBusSource(source);
- centerdataTAttach.setAttachPath(fileUrl);
- centerdataTAttach.setBusIndx(busindx);
- centerdataTAttach.setFileName(fileName);
- list.add(centerdataTAttach);
- }
- }
- return list;
- }
- public static void attach(CenterdataTAttach centerdataTAttach) {
- /*
- *ImageUpload返回是全路径,数据库保存不要ip和端口号
- */
- if (centerdataTAttach.getAttachPath().startsWith("http")) {
- String attachPath = centerdataTAttach.getAttachPath();
- if (centerdataTAttach.getAttachPath().contains("Download")) {
- int i1 = attachPath.indexOf("group=");
- attachPath = attachPath.replace("&&path=", "/");
- attachPath = attachPath.substring(i1 + 6);
- centerdataTAttach.setAttachPath(attachPath);
- } else {
- int i1 = attachPath.indexOf('/');
- int i2 = attachPath.indexOf('/', i1 + 1);
- int i3 = attachPath.indexOf('/', i2 + 1);
- centerdataTAttach.setAttachPath(centerdataTAttach.getAttachPath().substring(i3 + 1, attachPath.length()));
- }
- }
- }
- }
|