|
@@ -1,9 +1,12 @@
|
|
|
package com.caimei.modules.archive.service;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.io.File;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import com.caimei.dfs.image.beens.ImageUploadInfo;
|
|
|
+import com.caimei.modules.archive.entity.CmOrderArchiveFile;
|
|
|
import com.caimei.modules.archive.entity.CmProductArchiveFile;
|
|
|
+import com.caimei.modules.archive.utils.OssArchiveUtil;
|
|
|
import com.caimei.modules.common.utils.UploadUtils;
|
|
|
import com.caimei.modules.sys.utils.UploadImageUtils;
|
|
|
import com.thinkgem.jeesite.common.config.Global;
|
|
@@ -16,6 +19,7 @@ import com.thinkgem.jeesite.common.persistence.Page;
|
|
|
import com.thinkgem.jeesite.common.service.CrudService;
|
|
|
import com.caimei.modules.archive.entity.CmProductArchiveContent;
|
|
|
import com.caimei.modules.archive.dao.CmProductArchiveContentDao;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
@@ -45,12 +49,12 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
@Transactional(readOnly = false)
|
|
|
public void save(CmProductArchiveContent cmProductArchiveContent) {
|
|
|
super.save(cmProductArchiveContent);
|
|
|
- cmProductArchiveContentDao.deleteFile(cmProductArchiveContent.getId());
|
|
|
if (1 == cmProductArchiveContent.getType()) {
|
|
|
+ cmProductArchiveContentDao.deleteFile(cmProductArchiveContent.getId());
|
|
|
//保存图片
|
|
|
- List<CmProductArchiveFile> imageList = cmProductArchiveContent.getImageList();
|
|
|
+ List<CmProductArchiveFile> imageList = cmProductArchiveContent.getFileList();
|
|
|
//上传图片
|
|
|
- imageList.forEach(image->{
|
|
|
+ imageList.forEach(image -> {
|
|
|
if (StringUtils.isNotEmpty(image.getOssUrl())) {
|
|
|
if (!image.getOssUrl().startsWith("http")) {
|
|
|
image.setOssUrl(getImageUrl(image.getOssUrl()));
|
|
@@ -59,6 +63,14 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
cmProductArchiveContentDao.insertFile(image);
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ // 更新文件的archiveContentId
|
|
|
+ Integer fileId = cmProductArchiveContent.getFileId();
|
|
|
+ Integer dbFileId = cmProductArchiveContentDao.getDbFileId(cmProductArchiveContent.getId());
|
|
|
+ if (null != fileId && !fileId.equals(dbFileId)) {
|
|
|
+ cmProductArchiveContentDao.deleteFile(cmProductArchiveContent.getId());
|
|
|
+ cmProductArchiveContentDao.updateFile(fileId, Integer.valueOf(cmProductArchiveContent.getId()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -94,4 +106,49 @@ public class CmProductArchiveContentService extends CrudService<CmProductArchive
|
|
|
}
|
|
|
return imageUrl;
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public Map<String, Object> upload(MultipartFile multipartFile, String fileName) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ String fileAllName = multipartFile.getOriginalFilename();
|
|
|
+ String fileType = fileAllName.substring(fileAllName.lastIndexOf(".") + 1);
|
|
|
+ String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
+ String filePath = uuid + "." + fileType;
|
|
|
+ String contentType = OssArchiveUtil.getContentType(fileAllName);
|
|
|
+ try {
|
|
|
+ //保存本地
|
|
|
+ File file = OssArchiveUtil.ossUpload(multipartFile);
|
|
|
+ logger.info("默认路径>>>" + file.getAbsolutePath());
|
|
|
+ //上传oss
|
|
|
+ String url = OssArchiveUtil.ossUpload(filePath, "archiveFile/", file, contentType);
|
|
|
+ //删除本地文件
|
|
|
+ OssArchiveUtil.deleteFile(file);
|
|
|
+ //保存关联关系
|
|
|
+ CmProductArchiveFile archiveFile = new CmProductArchiveFile();
|
|
|
+ archiveFile.setFileName(fileName);
|
|
|
+ archiveFile.setOssName(filePath);
|
|
|
+ archiveFile.setOssUrl(url);
|
|
|
+ archiveFile.setUploadTime(new Date());
|
|
|
+ cmProductArchiveContentDao.insertFile(archiveFile);
|
|
|
+ map.put("success", true);
|
|
|
+ map.put("msg", "操作成功");
|
|
|
+ map.put("archiveFile", archiveFile);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ map.put("success", false);
|
|
|
+ map.put("msg", "操作失败");
|
|
|
+ logger.info("上传异常!!!");
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /*@Transactional(readOnly = false)
|
|
|
+ public void deleteFile(Integer fileId) {
|
|
|
+ CmOrderArchiveFile archiveFile = cmOrderArchiveDao.getArchiveFileById(fileId);
|
|
|
+ if (archiveFile != null) {
|
|
|
+ //删除oss服务器上的文件
|
|
|
+ OssArchiveUtil.deleteSingleFile("archiveFile/", archiveFile.getOssName());
|
|
|
+ cmOrderArchiveDao.deleteArchiveFile(fileId);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
}
|