FileUtil.java 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.sooka.sponest.data.utils;
  2. import com.ruoyi.common.core.utils.StringUtils;
  3. import com.ruoyi.common.core.utils.file.FilePrefixUtils;
  4. import com.sooka.sponest.data.system.attach.domain.CenterdataTAttach;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. /**
  8. * 附件文件 保存前处理
  9. */
  10. public class FileUtil {
  11. private FileUtil() {
  12. throw new IllegalStateException("Utility class");
  13. }
  14. public static List<CenterdataTAttach> documentProcessing(String id, String attachId, List<String> fileUrlsList, List<String> fileNamesList, String source, String busindx) {
  15. List<CenterdataTAttach> list = new ArrayList<>();
  16. // 新增逻辑
  17. if (StringUtils.isBlank(id)) {
  18. for (int i = 0; i < fileUrlsList.size(); i++) {
  19. if (null == fileUrlsList.get(i)) {
  20. continue;
  21. }
  22. String fileUrl = fileUrlsList.get(i).replace(",", "");
  23. String fileName = fileNamesList.get(i).replace(",", "");
  24. CenterdataTAttach centerdataTAttach = new CenterdataTAttach();
  25. String filetype = FilePrefixUtils.getUrlSuffix(fileUrlsList.get(i));
  26. centerdataTAttach.setFileType(filetype);
  27. centerdataTAttach.setBusId(attachId);
  28. centerdataTAttach.setBusSource(source);
  29. centerdataTAttach.setAttachPath(fileUrl);
  30. centerdataTAttach.setBusIndx(busindx);
  31. centerdataTAttach.setFileName(fileName);
  32. attach(centerdataTAttach);
  33. list.add(centerdataTAttach);
  34. }
  35. } else {
  36. String fileUrl = "";
  37. for (int i = 0; i < fileUrlsList.size(); i++) {
  38. if (null == fileUrlsList.get(i)) {
  39. continue;
  40. }
  41. CenterdataTAttach centerdataTAttach = new CenterdataTAttach();
  42. centerdataTAttach.setBusId(attachId);
  43. if (fileUrlsList.get(i).indexOf("+") > -1 || fileUrlsList.get(i).indexOf("&&") > -1) {
  44. if (fileUrlsList.get(i).indexOf("+") > -1) {
  45. fileUrl = fileUrlsList.get(i).substring(0, fileUrlsList.get(i).indexOf("+"));
  46. } else {
  47. fileUrl = fileUrlsList.get(i);
  48. }
  49. String[] fileurls = fileUrl.split("&&");
  50. fileUrl = fileurls[1].substring(fileurls[1].indexOf("=") + 1) + "/" + fileurls[2].substring(fileurls[2].indexOf("=") + 1);
  51. } else {
  52. fileUrl = fileUrlsList.get(i);
  53. }
  54. String fileName = fileNamesList.get(i).replace(",", "");
  55. fileUrl = fileUrl.replace(",", "");
  56. String filetype = FilePrefixUtils.getUrlSuffix(fileUrlsList.get(i));
  57. centerdataTAttach.setFileType(filetype);
  58. centerdataTAttach.setBusSource(source);
  59. centerdataTAttach.setAttachPath(fileUrl);
  60. centerdataTAttach.setBusIndx(busindx);
  61. centerdataTAttach.setFileName(fileName);
  62. list.add(centerdataTAttach);
  63. }
  64. }
  65. return list;
  66. }
  67. public static void attach(CenterdataTAttach centerdataTAttach) {
  68. /*
  69. *ImageUpload返回是全路径,数据库保存不要ip和端口号
  70. */
  71. if (centerdataTAttach.getAttachPath().startsWith("http")) {
  72. String attachPath = centerdataTAttach.getAttachPath();
  73. if (centerdataTAttach.getAttachPath().contains("Download")) {
  74. int i1 = attachPath.indexOf("group=");
  75. attachPath = attachPath.replace("&&path=", "/");
  76. attachPath = attachPath.substring(i1 + 6);
  77. centerdataTAttach.setAttachPath(attachPath);
  78. } else {
  79. int i1 = attachPath.indexOf('/');
  80. int i2 = attachPath.indexOf('/', i1 + 1);
  81. int i3 = attachPath.indexOf('/', i2 + 1);
  82. centerdataTAttach.setAttachPath(centerdataTAttach.getAttachPath().substring(i3 + 1, attachPath.length()));
  83. }
  84. }
  85. }
  86. }