|
|
@@ -0,0 +1,50 @@
|
|
|
+package com.ydtech.modules.order.service.impl;
|
|
|
+
|
|
|
+import com.ydtech.core.page.HttpResult;
|
|
|
+import com.ydtech.exception.SystemException;
|
|
|
+import com.ydtech.modules.order.service.OrderTaskImageService;
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wenks
|
|
|
+ * @version 0.0.2
|
|
|
+ * @description 操作文件
|
|
|
+ * @date 2023/4/17 9:51
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class OrderTaskImageServiceImpl implements OrderTaskImageService {
|
|
|
+
|
|
|
+ @Value("${upload.file.path}")
|
|
|
+ private String uploadPathFile;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult uploadFile(MultipartFile multipartFile, String type) throws IOException {
|
|
|
+ File folder = new File(uploadPathFile + type);
|
|
|
+
|
|
|
+ // 路劲不存在创建目录
|
|
|
+ if (!folder.isDirectory()) {
|
|
|
+ folder.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ String oldName = multipartFile.getOriginalFilename();
|
|
|
+ String newName = UUID.randomUUID() +
|
|
|
+ oldName.substring(oldName.lastIndexOf("."));
|
|
|
+ try {
|
|
|
+ multipartFile.transferTo(new File(folder, newName));
|
|
|
+ return HttpResult.ok("/upload/" + type + "/" + newName);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ throw new SystemException("上传失败");
|
|
|
+ }
|
|
|
+}
|