diff --git a/storage_rs/docker-compose.yaml b/storage_rs/docker-compose.yaml
index 4c0d0f1..fb79a89 100644
--- a/storage_rs/docker-compose.yaml
+++ b/storage_rs/docker-compose.yaml
@@ -10,7 +10,10 @@ services:
- 82:8282
restart: unless-stopped
volumes:
- - ./uploads:${DATA}
+ - tech_storage_rs:${DATA}
+volumes:
+ tech_storage_rs:
+ external: true
networks:
default:
external:
diff --git a/storage_rs/pom.xml b/storage_rs/pom.xml
index 33ba70f..a51aa99 100644
--- a/storage_rs/pom.xml
+++ b/storage_rs/pom.xml
@@ -22,6 +22,16 @@
lombok
true
+
+ org.apache.poi
+ poi
+ 5.2.0
+
+
+ org.apache.poi
+ poi-ooxml
+ 5.2.0
+
org.springframework.boot
spring-boot-configuration-processor
diff --git a/storage_rs/src/main/java/ru/molokoin/storage_rs/controller/StorageController.java b/storage_rs/src/main/java/ru/molokoin/storage_rs/controller/StorageController.java
index c4b733a..1fc134b 100644
--- a/storage_rs/src/main/java/ru/molokoin/storage_rs/controller/StorageController.java
+++ b/storage_rs/src/main/java/ru/molokoin/storage_rs/controller/StorageController.java
@@ -5,11 +5,15 @@ import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import ru.molokoin.storage_rs.model.Document;
+import ru.molokoin.storage_rs.model.XlsxCell;
+import ru.molokoin.storage_rs.model.XlsxDocument;
import ru.molokoin.storage_rs.service.StorageServiceFace;
/**
@@ -20,6 +24,7 @@ import ru.molokoin.storage_rs.service.StorageServiceFace;
* файлов пользователя/сторонего сервиса
*/
@Controller
+@RequestMapping(path = "/", consumes = {"*/*"})
public class StorageController {
/**
* получаем в переменную root
@@ -37,15 +42,6 @@ public class StorageController {
this.storage = storage;
}
- /**
- * Отдаем пользователю страничку загрузки файлов на сервер
- * @return
- */
- @GetMapping("/upload")
- public String uploadFace(){
- return "upload";
- }
-
/**
* Загружаем файл пользователя и возвращаем список файлов на сервере
* @return
@@ -53,13 +49,47 @@ public class StorageController {
@PostMapping("/upload")
public String upload(@RequestParam("file") MultipartFile file){
storage.store(file);
- return "list";
+ return "redirect:/uploads";
}
+ /**
+ * Возвращаем пользователю список файлов с сервера
+ * @param model
+ * @return
+ */
@GetMapping("/uploads")
public String list(Model model){
model.addAttribute("documents", storage.list());
- return "list";
+ return "documents";
}
+ /**
+ * Удаление файла из хранилища
+ * @param name
+ * @return
+ */
+ @GetMapping("/delete/{name}")
+ public String delete(@PathVariable String name) {
+ storage.delete(name);
+ return "redirect:/uploads";
+ }
+
+ /**
+ * Удаление файла из хранилища
+ * @param name
+ * @return
+ */
+ @GetMapping("/view/{name}")
+ public String view(@PathVariable String name) {
+ Document doc = storage.find(name);
+ XlsxDocument xlsx = new XlsxDocument(doc);
+ for (List row : xlsx.getData().values()) {
+ for (XlsxCell xlsxCell : row) {
+ System.out.println(xlsxCell.getContent());
+ }
+ }
+ return "redirect:/uploads";
+ }
+
+
}
diff --git a/storage_rs/src/main/java/ru/molokoin/storage_rs/model/XlsxCell.java b/storage_rs/src/main/java/ru/molokoin/storage_rs/model/XlsxCell.java
new file mode 100644
index 0000000..23d799a
--- /dev/null
+++ b/storage_rs/src/main/java/ru/molokoin/storage_rs/model/XlsxCell.java
@@ -0,0 +1,104 @@
+package ru.molokoin.storage_rs.model;
+
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+
+@AllArgsConstructor
+@NoArgsConstructor
+public class XlsxCell {
+ private String content; //содержимое ячейки
+ private String textColor; //цвет шрифта
+ private String bgColor; // цвет заливки ячейки
+ private String textSize; //8-12-14-24 размеры шрифта
+ private int textWeight; //жирность: bold (900), normal(500),
+ private String type;// STRING, NUMERIC, BOOLEAN, FORMULA
+
+ public XlsxCell(String content){
+ this.content = content;
+ }
+
+ /**
+ * @return the content
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * @param content the content to set
+ */
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ /**
+ * @return the textColor
+ */
+ public String getTextColor() {
+ return textColor;
+ }
+
+ /**
+ * @param textColor the textColor to set
+ */
+ public void setTextColor(String textColor) {
+ this.textColor = textColor;
+ }
+
+ /**
+ * @return the bgColor
+ */
+ public String getBgColor() {
+ return bgColor;
+ }
+
+ /**
+ * @param bgColor the bgColor to set
+ */
+ public void setBgColor(String bgColor) {
+ this.bgColor = bgColor;
+ }
+
+ /**
+ * @return the textSize
+ */
+ public String getTextSize() {
+ return textSize;
+ }
+
+ /**
+ * @param textSize the textSize to set
+ */
+ public void setTextSize(String textSize) {
+ this.textSize = textSize;
+ }
+
+ /**
+ * @return the textWeight
+ */
+ public int getTextWeight() {
+ return textWeight;
+ }
+
+ /**
+ * @param textWeight the textWeight to set
+ */
+ public void setTextWeight(int textWeight) {
+ this.textWeight = textWeight;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+}
diff --git a/storage_rs/src/main/java/ru/molokoin/storage_rs/model/XlsxDocument.java b/storage_rs/src/main/java/ru/molokoin/storage_rs/model/XlsxDocument.java
new file mode 100644
index 0000000..3dcf4a0
--- /dev/null
+++ b/storage_rs/src/main/java/ru/molokoin/storage_rs/model/XlsxDocument.java
@@ -0,0 +1,137 @@
+package ru.molokoin.storage_rs.model;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@AllArgsConstructor
+@NoArgsConstructor
+public class XlsxDocument {
+ private Map> data;
+ private Document document;
+
+ public XlsxDocument(Document document){
+ this.document = document;
+ this.data = init(document);
+ }
+
+ private Map> init(Document document) {
+ FileInputStream file;
+ Workbook workbook;
+ try {
+ file = new FileInputStream(new File(document.getPath()));
+ workbook = new XSSFWorkbook(file);
+
+ Sheet sheet = workbook.getSheetAt(0);
+ data = new HashMap<>();
+ Integer i = 0;
+ for (Row row : sheet) {
+ List xlsxCells = null;
+ XlsxCell xlsxCell = null;
+ for (Cell cell : row) {
+ xlsxCells = new ArrayList<>();
+ switch (cell.getCellType()) {
+ case STRING: {
+ xlsxCell = new XlsxCell(cell.getStringCellValue() + "");
+ } break;
+ case NUMERIC: {
+ xlsxCell = new XlsxCell(cell.getNumericCellValue() + "");
+ } break;
+ case BOOLEAN: {
+ xlsxCell = new XlsxCell(cell.getBooleanCellValue() + "");
+ } break;
+ case FORMULA: {
+ xlsxCell = new XlsxCell(cell.getCellFormula() + "");
+ } break;
+ default:
+ }
+ xlsxCells.add(xlsxCell);
+ }
+ data.put(i, xlsxCells);
+ i++;
+ }
+ }catch (IOException e) {
+ System.out.println("Не читается файл: " + e.getMessage());
+ }
+ return data;
+ }
+
+ /**
+ * @return the data
+ */
+ public Map> getData() {
+ return data;
+ }
+
+ /**
+ * @param data the data to set
+ */
+ public void setData(Map> data) {
+ this.data = data;
+ }
+
+ /**
+ * @return the document
+ */
+ public Document getDocument() {
+ return document;
+ }
+
+ /**
+ * @param document the document to set
+ */
+ public void setDocument(Document document) {
+ this.document = document;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((data == null) ? 0 : data.hashCode());
+ result = prime * result + ((document == null) ? 0 : document.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ XlsxDocument other = (XlsxDocument) obj;
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
+ if (document == null) {
+ if (other.document != null)
+ return false;
+ } else if (!document.equals(other.document))
+ return false;
+ return true;
+ }
+
+
+
+
+
+
+}
diff --git a/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageService.java b/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageService.java
index e995d22..31143b1 100644
--- a/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageService.java
+++ b/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageService.java
@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import jakarta.annotation.PostConstruct;
+
import ru.molokoin.storage_rs.config.StorageConfiguration;
import ru.molokoin.storage_rs.model.Document;
@@ -69,7 +70,7 @@ public class StorageService implements StorageServiceFace{
for (String file : new ArrayList<>(Arrays.asList(files))) {
Document doc = new Document();
- doc.setPath(file);
+ doc.setPath(root() + "/" + file);
/**
* Извлекаем имя файла
@@ -82,13 +83,7 @@ public class StorageService implements StorageServiceFace{
* файлы, загруженные приложением ошибок вызывать не будут,
* только файлы перемещенные в том из операционной системы.
*/
- long size = 0;
- try {
- Path p = Paths.get(file);
- size = Files.size(p);
- } catch (IOException e) {
- System.out.println(e.getMessage() + " >>> Ошибка! не удалось определить размер файла!");
- }
+ long size = new File(doc.getPath()).length();
doc.setSize(size);
/**
@@ -103,6 +98,15 @@ public class StorageService implements StorageServiceFace{
return docs;
}
+ /**
+ * Найти документ по имени
+ */
+ public Document find(String name){
+ return list().stream().filter(doc -> name.equals(doc.getName()))
+ .findAny()
+ .orElse(null);
+ }
+
@Override
public void clear() {
// TODO Auto-generated method stub
@@ -115,10 +119,24 @@ public class StorageService implements StorageServiceFace{
throw new UnsupportedOperationException("Unimplemented method 'load'");
}
+ /**
+ * Удаление файла из хранилища
+ * - по имени файла
+ */
@Override
- public boolean delete(long id) {
- // TODO Auto-generated method stub
- throw new UnsupportedOperationException("Unimplemented method 'delete'");
+ public boolean delete(String name) {
+ Path path = Paths.get(find(name).getPath());
+ if (Files.exists(path)){
+ try {
+ Files.delete(path);
+ } catch (IOException e) {
+ System.out.println("Не удалось удалить файл " + name);
+ System.out.println(e.getMessage());
+ return false;
+ }
+ return true;
+ }
+ return true;
}
@Override
diff --git a/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageServiceFace.java b/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageServiceFace.java
index 17e84b8..9784dc2 100644
--- a/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageServiceFace.java
+++ b/storage_rs/src/main/java/ru/molokoin/storage_rs/service/StorageServiceFace.java
@@ -33,6 +33,13 @@ public interface StorageServiceFace {
*/
public List list();
+ /**
+ * Поиск документа из списка по имени
+ * @param name
+ * @return
+ */
+ public Document find(String name);
+
/**
* Удаление всех файлов, очистка хранилища
*/
@@ -50,7 +57,7 @@ public interface StorageServiceFace {
* @param id
* @return
*/
- public boolean delete(long id);
+ public boolean delete(String name);
/**
* Сохранение файла в хранилище
diff --git a/storage_rs/src/main/resources/templates/list.html b/storage_rs/src/main/resources/templates/documents.html
similarity index 72%
rename from storage_rs/src/main/resources/templates/list.html
rename to storage_rs/src/main/resources/templates/documents.html
index 3cd3162..cfe6e0f 100644
--- a/storage_rs/src/main/resources/templates/list.html
+++ b/storage_rs/src/main/resources/templates/documents.html
@@ -18,20 +18,21 @@ xmlns:th="http://www.thymeleaf.org">
Перечень файлов:
+
name |
path |
extension |
- size |
+ size(bytes) |
-
+
|
@@ -51,9 +52,14 @@ xmlns:th="http://www.thymeleaf.org">
-
+
+ |
+
+
|
diff --git a/storage_rs/src/main/resources/templates/upload.html b/storage_rs/src/main/resources/templates/upload.html
deleted file mode 100644
index c630c22..0000000
--- a/storage_rs/src/main/resources/templates/upload.html
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
- upload-page
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/storage_rs/src/main/resources/templates/view.html b/storage_rs/src/main/resources/templates/view.html
new file mode 100644
index 0000000..e69de29