|
@@ -7,8 +7,13 @@ import com.bizmatics.persistence.mapper.PatrolInspectionDeviceMapper;
|
|
|
import com.bizmatics.service.PatrolInspectionDeviceService;
|
|
|
import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import com.bizmatics.service.util.SecurityUtils;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
@@ -57,4 +62,31 @@ public class PatrolInspectionDeviceServiceImpl extends AbstractCrudService<Patro
|
|
|
return patrolInspectionDeviceList;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String pictureUpload(@NotNull MultipartFile file, HttpServletRequest request){
|
|
|
+ if (file.isEmpty()) {
|
|
|
+ System.out.println("文件为空空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String fileName = file.getOriginalFilename(); // 文件名
|
|
|
+ String suffixName = fileName.substring(fileName.lastIndexOf(".")); // 后缀名
|
|
|
+// String filePath = "D://temp-rainy//"; // 上传后的路径
|
|
|
+ fileName = UUID.randomUUID() + suffixName; // 新文件名
|
|
|
+
|
|
|
+ String destFileName = request.getServletContext().getRealPath("") + "uploaded" + File.separator+fileName;
|
|
|
+ File dest = new File(destFileName);
|
|
|
+// File dest = new File(filePath + fileName);
|
|
|
+ if (!dest.getParentFile().exists()) {
|
|
|
+ dest.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ file.transferTo(dest);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String filename = "/uploaded/" + fileName;
|
|
|
+ return filename;
|
|
|
+ }
|
|
|
+
|
|
|
}
|