Browse Source

селект пост

master
esoe 3 months ago
parent
commit
d98b9d1f89
  1. 34
      gates/src/main/java/ru/mlokoin/gates/controller/v1/GatesController.java
  2. 23
      gates/src/main/java/ru/mlokoin/gates/model/fs/Post.java
  3. 16
      gates/src/main/java/ru/mlokoin/gates/repository/Storage.java
  4. 114
      gates/src/main/resources/templates/documents.html
  5. 103
      gates/src/main/resources/templates/storage.html
  6. 18
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StorageController.java
  7. 32
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Post.java
  8. 13
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/PostFace.java
  9. 2
      storage-rs/src/main/resources/static/content/md/hello.md

34
gates/src/main/java/ru/mlokoin/gates/controller/v1/GatesController.java

@ -3,6 +3,7 @@ package ru.mlokoin.gates.controller.v1; @@ -3,6 +3,7 @@ package ru.mlokoin.gates.controller.v1;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@ -13,6 +14,7 @@ import org.springframework.http.client.MultipartBodyBuilder; @@ -13,6 +14,7 @@ import org.springframework.http.client.MultipartBodyBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.reactive.function.BodyInserters;
@ -20,6 +22,7 @@ import org.springframework.web.reactive.function.client.WebClient; @@ -20,6 +22,7 @@ import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import ru.mlokoin.gates.model.fs.Document;
import ru.mlokoin.gates.model.fs.Post;
import ru.mlokoin.gates.model.fs.xlsx.XlsxDocument;
import ru.mlokoin.gates.repository.Storage;
import ru.mlokoin.gates.teh.fs.MpFile;
@ -51,6 +54,12 @@ public class GatesController { @@ -51,6 +54,12 @@ public class GatesController {
public String documentList(Model model) {
List<Document> docs = storage.getDocumentList();
model.addAttribute("documents", docs);
List<Post> posts = storage.getPostList();
model.addAttribute("posts", posts);
Post post = new Post();
model.addAttribute("newPost", post);
return "documents";
}
@ -214,8 +223,11 @@ public class GatesController { @@ -214,8 +223,11 @@ public class GatesController {
* @return
*/
@PostMapping("/document/upload")
public String upload(@RequestParam("file") MultipartFile file) {
public String upload(@RequestParam("file") MultipartFile file, Model model, @ModelAttribute("post") Post post) {
// System.out.println("Тип документа: " + type);
System.out.println("Тип документа: " + post.getType());
Document doc = new Document();
doc.setName(file.getOriginalFilename());
doc.setSize(file.getSize());
@ -235,6 +247,18 @@ public class GatesController { @@ -235,6 +247,18 @@ public class GatesController {
.timeout(Duration.ofSeconds(1))
.block();
post.setDocument(doc);
post = client.post()
.uri("http://resource-service-api:8181/post/create")
.body(Mono.just(post), Post.class)
.retrieve()
.bodyToMono(new ParameterizedTypeReference <Post>(){})
.timeout(Duration.ofSeconds(1))
.block();
System.out.println("Пакет передан в ресурсный сервис ...");
System.out.println("Пакет: " + post.toString());
// Добавление файла в файловое хранилище
MultipartBodyBuilder builder = new MultipartBodyBuilder();
Boolean ok;
@ -249,6 +273,7 @@ public class GatesController { @@ -249,6 +273,7 @@ public class GatesController {
.bodyToMono(new ParameterizedTypeReference <Boolean>(){})
.block();
System.out.println("Файл добавлен в хранилище: " + ok);
System.out.println("ID: " + doc.getId());
System.out.println(doc.toString());
@ -276,6 +301,11 @@ public class GatesController { @@ -276,6 +301,11 @@ public class GatesController {
return "view-xlsx";
}
// @GetMapping("/document/view-xlsx/{id}/{part}")
// public String viewPart(Model model, @PathVariable String id, @PathVariable String part) {
// }
/**
* Публикация "Реестра обученных"
* - просмотр

23
gates/src/main/java/ru/mlokoin/gates/model/fs/Post.java

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
package ru.mlokoin.gates.model.fs;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Post implements Serializable {
private long id;
private String type;//тип документа (реестр/ списочный состав/ прочее)
private Document document;
public Post(String type, Document document) {
this.type = type;
this.document = document;
}
}

16
gates/src/main/java/ru/mlokoin/gates/repository/Storage.java

@ -20,6 +20,7 @@ import ru.mlokoin.gates.model.course.Course; @@ -20,6 +20,7 @@ import ru.mlokoin.gates.model.course.Course;
import ru.mlokoin.gates.model.cretarea.ProgramCretarea;
import ru.mlokoin.gates.model.education.EducatonEntry;
import ru.mlokoin.gates.model.fs.Document;
import ru.mlokoin.gates.model.fs.Post;
import ru.mlokoin.gates.model.fs.xlsx.XlsxCell;
import ru.mlokoin.gates.model.fs.xlsx.XlsxDocument;
import ru.mlokoin.gates.model.organization.Organization;
@ -37,6 +38,7 @@ import ru.mlokoin.gates.teh.strings.Stringer; @@ -37,6 +38,7 @@ import ru.mlokoin.gates.teh.strings.Stringer;
public class Storage {
private String storageLink = "http://storage-rs:8282/api/document/content/";
private String storageListLink = "http://resource-service-api:8181/storage-entry/list";
private String postLink = "http://resource-service-api:8181/post/list";
private String programsLink = "http://resource-service-api:8181/program/list";
private String buildingsLink = "http://resource-service-api:8181/building/list";
private String coursesLink = "http://resource-service-api:8181/course/list";
@ -63,6 +65,20 @@ public class Storage { @@ -63,6 +65,20 @@ public class Storage {
.block();
}
/**
* Получение списка постов, размещенных в ресурсном сервисе
* @param id
* @return
*/
public List<Post> getPostList() {
System.out.println("Получение списка постов, размещенных в ресурсном сервисе ...");
return client.method(HttpMethod.GET)
.uri(postLink)
.retrieve()
.bodyToMono(new ParameterizedTypeReference <List<Post>>(){})
.block();
}
/**
* Получение всего содержимого xlsx-файла из файлового хранилища
* по id документа в хранилище

114
gates/src/main/resources/templates/documents.html

@ -26,64 +26,70 @@ xmlns:th="http://www.thymeleaf.org"> @@ -26,64 +26,70 @@ xmlns:th="http://www.thymeleaf.org">
-->
<h2>Добавление пакетов:</h2>
<form method="post" th:action="@{/document/upload}" enctype="multipart/form-data">
<div>
<form th:method="post" th:action="@{/document/upload}" enctype="multipart/form-data" th:object="${newPost}">
<!-- <div> -->
<select th:field="${newPost.type}">
<option value="" disabled selected>--Выберите вид загружаемого документа--</option>
<option value="Реестр обученных">Реестр обученных</option>
<option value="Прочее ...">Прочее ...</option>
</select>
<input type="file" name="file">
</div>
<button type="submit">Upload File</button>
<!-- </div> -->
<button type="submit">Загрузить пакет</button>
</form>
<h2>Перечень файлов:</h2>
<form th:action="@{/documents}" method="get"></form>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<!-- <th>path</th> -->
<th>extension</th>
<th>size(bytes)</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr th:each="doc: ${documents}">
<td>
<input type="text" id="id" name="id" th:value="${doc.id}" readonly />
</td>
<td>
<input type="text" id="name" name="name" th:value="${doc.name}" readonly />
</td>
<!-- <td>
<input type="text" id="path" name="path" th:value="${doc.path}" readonly />
</td> -->
<td>
<input type="text" id="extension" name="extension" th:value="${doc.extension}" readonly />
</td>
<td>
<input type="text" id="size" name="size" th:value="${doc.size}" readonly />
</td>
<table>
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>extension</th>
<th>size(bytes)</th>
<th>
<td>
<form th:action="@{/document/delete/{id}(id=${doc.id})}" th:method="get">
<!-- <input type="headen" th:field="${doc.name}" name="docName"> -->
<input type="submit" value="X"/>
</form>
</td>
<td>
<form th:action="@{/document/view-xlsx/{id}(id=${doc.id})}" th:method="get">
<input type="submit" value="VIEW"/>
</form>
</td>
<!-- <td>
<form th:action="@{/export-as-educations/{name}(name=${doc.name})}" th:method="get">
<input type="submit" value="EXPORT-AS-EDUCATIONS"/>
</form>
</td> -->
</tr>
</tbody>
</table>
</th>
</tr>
</thead>
<tbody>
<tr th:each="post: ${posts}">
<td>
<input type="text" id="type" name="type" th:value="${post.type}" readonly />
</td>
<td>
<input type="text" id="id" name="id" th:value="${post.document.id}" readonly />
</td>
<td>
<input type="text" id="name" name="name" th:value="${post.document.name}" readonly />
</td>
<!-- <td>
<input type="text" id="path" name="path" th:value="${doc.path}" readonly />
</td> -->
<td>
<input type="text" id="extension" name="extension" th:value="${post.document.extension}" readonly />
</td>
<td>
<input type="text" id="size" name="size" th:value="${post.document.size}" readonly />
</td>
<td>
<form th:action="@{/document/delete/{id}(id=${post.document.id})}" th:method="get">
<!-- <input type="headen" th:field="${doc.name}" name="docName"> -->
<input type="submit" value="X"/>
</form>
</td>
<td>
<form th:action="@{/document/view-xlsx/{id}(id=${post.document.id})}" th:method="get">
<input type="submit" value="VIEW"/>
</form>
</td>
<!-- <td>
<form th:action="@{/export-as-educations/{name}(name=${doc.name})}" th:method="get">
<input type="submit" value="EXPORT-AS-EDUCATIONS"/>
</form>
</td> -->
</tr>
</tbody>
</table>
</div>
</main>

103
gates/src/main/resources/templates/storage.html

@ -30,60 +30,59 @@ xmlns:th="http://www.thymeleaf.org"> @@ -30,60 +30,59 @@ xmlns:th="http://www.thymeleaf.org">
<h2>Перечень файлов:</h2>
<form th:action="@{/storage}" method="get"></form>
<form method="post" th:action="@{/storage/upload}" enctype="multipart/form-data">
<div>
<input type="file" name="file">
</div>
<button type="submit">Upload File</button>
</form>
<table>
<thead>
<tr>
<th>name</th>
<th>path</th>
<th>extension</th>
<th>size(bytes)</th>
<th>
</th>
</tr>
</thead>
<tbody>
<tr th:each="doc: ${documents}">
<td>
<input type="text" id="name" name="name" th:value="${doc.name}" readonly />
</td>
<td>
<input type="text" id="path" name="path" th:value="${doc.path}" readonly />
</td>
<td>
<input type="text" id="extension" name="extension" th:value="${doc.extension}" readonly />
</td>
<td>
<input type="text" id="size" name="size" th:value="${doc.size}" readonly />
</td>
<td>
<form th:action="@{/storage/delete/{name}(name=${doc.name})}" th:method="get">
<!-- <input type="headen" th:field="${doc.name}" name="docName"> -->
<input type="submit" value="X"/>
</form>
</td>
<!-- <td>
<form th:action="@{/view/{name}(name=${doc.name})}" th:method="get">
<input type="submit" value="VIEW"/>
</form>
</td> -->
<!-- <td>
<form th:action="@{/export-as-educations/{name}(name=${doc.name})}" th:method="get">
<input type="submit" value="EXPORT-AS-EDUCATIONS"/>
</form>
</td> -->
<form method="post" th:action="@{/storage/upload}" enctype="multipart/form-data">
<div>
<input type="file" name="file">
</div>
<button type="submit">Upload File</button>
</form>
<table>
<thead>
<tr>
<th>name</th>
<th>path</th>
<th>extension</th>
<th>size(bytes)</th>
<th>DEL</th>
<th>SHOW</th>
</tr>
</thead>
<tbody>
<tr th:each="doc: ${documents}">
<td>
<input type="text" id="name" name="name" th:value="${doc.name}" readonly />
</td>
<td>
<input type="text" id="path" name="path" th:value="${doc.path}" readonly />
</td>
<td>
<input type="text" id="extension" name="extension" th:value="${doc.extension}" readonly />
</td>
<td>
<input type="text" id="size" name="size" th:value="${doc.size}" readonly />
</td>
<td>
<form th:action="@{/storage/delete/{name}(name=${doc.name})}" th:method="get">
<!-- <input type="headen" th:field="${doc.name}" name="docName"> -->
<input type="submit" value="X"/>
</form>
</td>
<!-- <td>
<form th:action="@{/view/{name}(name=${doc.name})}" th:method="get">
<input type="submit" value="VIEW"/>
</form>
</td> -->
<!-- <td>
<form th:action="@{/export-as-educations/{name}(name=${doc.name})}" th:method="get">
<input type="submit" value="EXPORT-AS-EDUCATIONS"/>
</form>
</td> -->
</tr>
</tbody>
</table>
</tr>
</tbody>
</table>
</div>
</main>

18
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/StorageController.java

@ -15,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestBody; @@ -15,7 +15,9 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.molokoin.resourceserviceapi.entities.Post;
import ru.molokoin.resourceserviceapi.entities.StorageEntry;
import ru.molokoin.resourceserviceapi.repositories.PostFace;
import ru.molokoin.resourceserviceapi.repositories.StorageEntryFace;
/**
@ -27,11 +29,19 @@ public class StorageController { @@ -27,11 +29,19 @@ public class StorageController {
@Autowired
private StorageEntryFace repo;
@Autowired
private PostFace postRepo;
@GetMapping("/storage-entry/list")
public ResponseEntity<List<StorageEntry>> getStorageEntries(){
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
}
@GetMapping("/post/list")
public ResponseEntity<List<Post>> getPostList(){
return new ResponseEntity<>(postRepo.findAll(), HttpStatus.OK);
}
@GetMapping("/storage-entry/{id}")
public ResponseEntity<?> getStorageEntryByID(@PathVariable Integer id){
return new ResponseEntity<>(repo.findStorageEntryById(id), HttpStatus.OK);
@ -45,6 +55,14 @@ public class StorageController { @@ -45,6 +55,14 @@ public class StorageController {
return new ResponseEntity<>(storageEntry, HttpStatus.CREATED);
}
@PostMapping(path = "/post/create",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> savePost(@RequestBody Post post) {
postRepo.save(post);
return new ResponseEntity<>(post, HttpStatus.CREATED);
}
@PutMapping(path = "/storage-entry/update/{id}",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE)

32
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Post.java

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
package ru.molokoin.resourceserviceapi.entities;
import java.io.Serializable;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToOne;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Data
public class Post implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
private String type;//тип документа (реестр/ списочный состав/ прочее)
@OneToOne(fetch = FetchType.EAGER, optional = false)
@OnDelete(action = OnDeleteAction.CASCADE)
private StorageEntry document;
}

13
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/PostFace.java

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
package ru.molokoin.resourceserviceapi.repositories;
import java.util.List;
import org.springframework.data.repository.ListCrudRepository;
import org.springframework.stereotype.Repository;
import ru.molokoin.resourceserviceapi.entities.Post;
@Repository
public interface PostFace extends ListCrudRepository<Post, Long>{
List<Post> findAll();
}

2
storage-rs/src/main/resources/static/content/md/hello.md

@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
table_pack:
- id
- наименование пакета
- тип пакета(наименование загружаемой формы, для выбора последующего алгоритма обработки)
- тип пакета (наименование загружаемой формы, для выбора последующего алгоритма обработки)
# API
## [GET domain:port/api/list-uploads](http://localhost:82/api/list-uploads)

Loading…
Cancel
Save