esoe
2 months ago
45 changed files with 1278 additions and 344 deletions
@ -0,0 +1,46 @@
@@ -0,0 +1,46 @@
|
||||
package ru.mlokoin.gates.model.education; |
||||
|
||||
/** |
||||
* Список заголовков таблицы |
||||
* добавить поле, для хранения типа данных столбца |
||||
*/ |
||||
public enum Headers { |
||||
|
||||
ORGANIZATION_TYPE(0, "Тип организации"), |
||||
ORGANIZATION_NAME_FULL(1, "ПСК"), |
||||
STUDENT_DIRECTION(2, "Структурное подразделение"), |
||||
STUDENT_FULL_NAME(3, "ФИО обучающегося"), |
||||
STUDENT_PROFESSION(4, "Профессия"), |
||||
COURSE_PLACE(5, "Место проведения обучения"), |
||||
PROGRAM_NAME(6, "Программа обучения"), |
||||
COURSE_START_DATE(7, "Дата начала обучения"), |
||||
PROGRAM_LENGHT(8, "Продолжительность программы"), |
||||
COURSE_PROTOCOL_DATE(9, "Дата протокола"), |
||||
STUDENT_CATEGORY(10, "Категория обучаемых"), |
||||
PROGRAMM_STADY_DIRECTION(11, "Направление обучения"), |
||||
CRETAREA_NAME_SHORT(12, "Критерий"), |
||||
COURSE_PROTOCOL_NUMBER(13, "Номер протокола"), |
||||
EDUCATION_SERTIFICATE_NUMBER(14, "Номер удостоверения"), |
||||
PROGRAM_PRICE(15, "Стоимость обучения"), |
||||
EDUCATIONS_ONES(16, "Единички"), |
||||
COURSE_REPORT_PERIOD(17, "Отчетный период"), |
||||
TEACHER_FULL_NAME(18, "Преподаватель"), |
||||
BUILDING_NAME_SHORT(19, "Объект"); |
||||
|
||||
|
||||
private Headers(int column, String title) { |
||||
this.column = column; |
||||
this.title = title; |
||||
} |
||||
|
||||
public int column() { |
||||
return column; |
||||
} |
||||
|
||||
public String title() { |
||||
return title; |
||||
} |
||||
|
||||
private int column; |
||||
private String title; |
||||
} |
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>cretareas-list-from-base</title> |
||||
<!-- Скрипт обработки thymeleaf компонентов --> |
||||
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||
<!-- скрипт просмотра *.MD документов --> |
||||
<!-- <script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> --> |
||||
</head> |
||||
<body> |
||||
<header></header> |
||||
<main> |
||||
<div class="main-wraper"> |
||||
|
||||
<form th:action="@{/program-cretareas/save/{id}(id=${id})}" |
||||
th:method="post" |
||||
th:object="${programCretareaWraper}"> |
||||
|
||||
<h2>Критерии, извлеченные из БД: <span th:text="*{getList().size()}"></span></h2> |
||||
|
||||
<table rules="all"> |
||||
<thead> |
||||
<th> |
||||
<span>№</span> |
||||
</th> |
||||
<th> |
||||
<span>КРАТКО</span> |
||||
</th> |
||||
<th> |
||||
<span>ПОЛНО</span> |
||||
</th> |
||||
<!-- <th> |
||||
<span>ОТПРАВИТЬ</span> |
||||
</th> --> |
||||
</thead> |
||||
<tbody> |
||||
<tr th:each="cretarea, cretareaStat : *{getList()}" > |
||||
<td> |
||||
<span th:text="${cretareaStat.index + 1}"></span> |
||||
</td> |
||||
<td> |
||||
<input type="text" th:field="*{list[__${cretareaStat.index}__].nameShort}"/> |
||||
</td> |
||||
<td> |
||||
<input type="text" th:field="*{list[__${cretareaStat.index}__].name}"/> |
||||
</td> |
||||
<td> |
||||
<input type="submit" value="обновить"/> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
<!-- <input type="submit" value="POST-ALL"/> --> |
||||
</form> |
||||
</div> |
||||
</main> |
||||
</body> |
||||
</html> |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
<!DOCTYPE HTML> |
||||
<html xmlns="http://www.w3.org/1999/xhtml" |
||||
xmlns:th="http://www.thymeleaf.org"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title>cretareas-list-from-xlsx</title> |
||||
<!-- Скрипт обработки thymeleaf компонентов --> |
||||
<script src="https://cdn.jsdelivr.net/npm/@webcomponents/webcomponentsjs@2/webcomponents-loader.min.js"></script> |
||||
<!-- скрипт просмотра *.MD документов --> |
||||
<!-- <script type="module" src="https://cdn.jsdelivr.net/gh/zerodevx/zero-md@1/src/zero-md.min.js"></script> --> |
||||
</head> |
||||
<body> |
||||
<header></header> |
||||
<main> |
||||
<div class="main-wraper"> |
||||
|
||||
<form th:action="@{/program-cretareas/save/{id}(id=${id})}" |
||||
th:method="post" |
||||
th:object="${programCretareaWraper}"> |
||||
|
||||
<h2>Критерии, извлеченные из XLSX: <span th:text="*{getList().size()}"></span></h2> |
||||
|
||||
<table rules="all"> |
||||
<thead> |
||||
<th> |
||||
<span>№</span> |
||||
</th> |
||||
<th> |
||||
<span>КРАТКО</span> |
||||
</th> |
||||
<!-- <th> |
||||
<span>ПОЛНО</span> |
||||
</th> --> |
||||
<!-- <th> |
||||
<span>ОТПРАВИТЬ</span> |
||||
</th> --> |
||||
</thead> |
||||
<tbody> |
||||
<tr th:each="cretarea, cretareaStat : *{getList()}" > |
||||
<td> |
||||
<span th:text="${cretareaStat.index + 1}"></span> |
||||
</td> |
||||
<td> |
||||
<input type="text" th:field="*{list[__${cretareaStat.index}__].nameShort}"/> |
||||
</td> |
||||
<!-- <td> |
||||
<input type="text" th:field="*{list[__${cretareaStat.index}__].name}"/> |
||||
</td> --> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
<!-- <input type="submit" value="POST-ALL"/> --> |
||||
</form> |
||||
</div> |
||||
</main> |
||||
</body> |
||||
</html> |
@ -1,77 +0,0 @@
@@ -1,77 +0,0 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
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.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Building; |
||||
import ru.molokoin.resourceserviceapi.repositories.BuildingFace; |
||||
|
||||
@RestController |
||||
@RequestMapping(path = "/", consumes = {"*/*"}) |
||||
public class BuildingController { |
||||
@Autowired |
||||
private BuildingFace repo; |
||||
|
||||
/** |
||||
* Получение перечня объектов строительства |
||||
* @return |
||||
*/ |
||||
@GetMapping("/building/list") |
||||
public ResponseEntity<List<Building>> getBuildings(){ |
||||
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Получение сведений по объекту строительства |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@GetMapping("/building/{id}") |
||||
public ResponseEntity<?> getBuildingByID(@PathVariable Integer id){ |
||||
return new ResponseEntity<>(repo.findBuildingById(id), HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Создание запис о новом объекте строительства |
||||
* @param building |
||||
* @return |
||||
*/ |
||||
@PostMapping(path = "/building/create", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> saveBuilding(@RequestBody Building building) { |
||||
repo.save(building); |
||||
return new ResponseEntity<>(building, HttpStatus.CREATED); |
||||
} |
||||
|
||||
@PostMapping(path = "/building/update/{id}", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> updateBuilding(@PathVariable Integer id, @RequestBody Building building) { |
||||
Building b = repo.findBuildingById(id); |
||||
b.setName_full(building.getName_full()); |
||||
b.setName_short(building.getName_short()); |
||||
b.setCode_full(building.getCode_full()); |
||||
b.setCode_short(building.getCode_short()); |
||||
repo.save(b); |
||||
return new ResponseEntity<>(repo.findBuildingById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
@DeleteMapping("/building/delete/{id}") |
||||
public ResponseEntity<String> deleteBuilding(@PathVariable Long id){ |
||||
Building b = repo.findBuildingById(id); |
||||
repo.delete(b); |
||||
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); |
||||
} |
||||
} |
@ -1,65 +0,0 @@
@@ -1,65 +0,0 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
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.PutMapping; |
||||
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.ProgramCretarea; |
||||
import ru.molokoin.resourceserviceapi.repositories.ProgramCretareaRepositoryFace; |
||||
|
||||
@RestController |
||||
@RequestMapping(path = "/", consumes = {"*/*"}) |
||||
public class ProgramCretareaController { |
||||
@Autowired |
||||
private ProgramCretareaRepositoryFace repo; |
||||
|
||||
@GetMapping("/cretarea/list") |
||||
public ResponseEntity<List<ProgramCretarea>> getTeachers(){ |
||||
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); |
||||
} |
||||
|
||||
@GetMapping("/cretarea/{id}") |
||||
public ResponseEntity<?> getTeacherByID(@PathVariable Integer id){ |
||||
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.OK); |
||||
} |
||||
|
||||
@PostMapping(path = "/cretarea/create", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> saveTeacher(@RequestBody ProgramCretarea cretarea) { |
||||
repo.save(cretarea); |
||||
return new ResponseEntity<>(cretarea, HttpStatus.CREATED); |
||||
} |
||||
|
||||
@PutMapping(path = "/cretarea/update/{id}", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> updateCretarea(@PathVariable Integer id, @RequestBody ProgramCretarea cretarea) { |
||||
ProgramCretarea pc = repo.findCretareaById(id); |
||||
pc.setName(cretarea.getName()); |
||||
pc.setName_short(cretarea.getName_short()); |
||||
repo.save(pc); |
||||
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
@DeleteMapping("/cretarea/delete/{id}") |
||||
public ResponseEntity<String> deleteCretarea(@PathVariable Long id){ |
||||
ProgramCretarea pc = repo.findCretareaById(id); |
||||
System.out.println(pc.toString()); |
||||
repo.delete(pc); |
||||
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,187 @@
@@ -0,0 +1,187 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers.api; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.PageImpl; |
||||
import org.springframework.data.domain.PageRequest; |
||||
import org.springframework.data.domain.Pageable; |
||||
import org.springframework.data.domain.Sort; |
||||
import org.springframework.data.mapping.PropertyReferenceException; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
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.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Building; |
||||
import ru.molokoin.resourceserviceapi.repositories.BuildingRepository; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
|
||||
|
||||
@RestController |
||||
@RequestMapping(path = "/building", consumes = {"*/*"}) |
||||
public class BuildingController { |
||||
@Autowired |
||||
private BuildingRepository repo; |
||||
|
||||
public BuildingController(BuildingRepository repo) { |
||||
this.repo = repo; |
||||
} |
||||
|
||||
@GetMapping("/pages") |
||||
public Page<Building> page(@RequestParam(name = "page", required = false) Integer pageNo, |
||||
@RequestParam(name = "size", required = false) Long pageSize, |
||||
@RequestParam(name = "sortBy", required = false) String sortBy) { |
||||
if (pageNo == null || pageNo < 0) pageNo = 0; |
||||
if (pageSize == null || pageSize < 0) pageSize = repo.count(); |
||||
if (sortBy == null) sortBy = "id"; |
||||
|
||||
Sort sort = Sort.by(sortBy); |
||||
Pageable pageable = PageRequest.of(pageNo, pageSize == null ? null : Math.toIntExact(pageSize), sort); |
||||
try{ |
||||
return repo.findAll(pageable); |
||||
}catch(PropertyReferenceException e){ |
||||
sortBy = "id"; |
||||
sort = Sort.by(sortBy); |
||||
pageable = PageRequest.of(pageNo, pageSize == null ? null : Math.toIntExact(pageSize), sort); |
||||
return repo.findAll(pageable); |
||||
} |
||||
} |
||||
|
||||
@GetMapping("/count") |
||||
public ResponseEntity<Long> getСretareasCount(){ |
||||
return new ResponseEntity<>(repo.count(), HttpStatus.OK); |
||||
} |
||||
|
||||
@GetMapping("") |
||||
public ResponseEntity<?> building(@RequestParam(name="id", required = false) Long id, |
||||
@RequestParam(name="nameShort", required = false) String nameShort){ |
||||
boolean exists = false; |
||||
if(id != null && repo.existsById(id)){ |
||||
return new ResponseEntity<>(repo.findById(id), HttpStatus.OK); |
||||
} |
||||
if (nameShort != null && repo.existsByNameShort(nameShort)){ |
||||
return new ResponseEntity<>(repo.findByNameShort(nameShort), HttpStatus.OK); |
||||
} |
||||
return new ResponseEntity<>(exists, HttpStatus.OK); |
||||
} |
||||
|
||||
@GetMapping("/exists") |
||||
public ResponseEntity<Boolean> exists(@RequestBody Building building){ |
||||
return new ResponseEntity<>(repo.existsByNameShort(building.getNameShort()), HttpStatus.OK); |
||||
} |
||||
|
||||
@GetMapping("/absent") |
||||
public Page<Building> absent(@RequestBody List<Building> buildings) { |
||||
List<Building> absent = new ArrayList<>(); |
||||
//проверяем наличие объекта строительства в базе
|
||||
for (Building building : buildings) { |
||||
if (!repo.existsByNameShort(building.getNameShort())) { |
||||
//если не найден - добавляем в список
|
||||
absent.add(building); |
||||
} |
||||
} |
||||
//сортируем краткие наименования по алфавиту
|
||||
absent.sort(Comparator.comparing(Building::getNameShort)); |
||||
|
||||
//подготавливаем страницу для ответа
|
||||
Page<Building> absentPage = new PageImpl<>(absent); |
||||
return absentPage; |
||||
} |
||||
|
||||
/** |
||||
* Создание записи о новом объекте строительства |
||||
* @param building |
||||
* @return |
||||
*/ |
||||
@PostMapping(path = "/create", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> saveBuilding(@RequestBody Building building) { |
||||
repo.save(building); |
||||
return new ResponseEntity<>(building, HttpStatus.CREATED); |
||||
} |
||||
|
||||
@PostMapping(path = "/update/{id}", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> updateBuilding(@PathVariable Integer id, @RequestBody Building building) { |
||||
Building b = repo.findById(id); |
||||
b.setNameFull(building.getNameFull()); |
||||
b.setNameShort(building.getNameShort()); |
||||
b.setCodeFull(building.getCodeFull()); |
||||
b.setCodeShort(building.getCodeShort()); |
||||
repo.save(b); |
||||
return new ResponseEntity<>(repo.findById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
@PostMapping(path = "/update", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> update(@RequestParam(name="id", required = true) Integer id, |
||||
@RequestBody Building building) { |
||||
Building b = repo.findById(id); |
||||
b.setNameFull(building.getNameFull()); |
||||
b.setNameShort(building.getNameShort()); |
||||
b.setCodeFull(building.getCodeFull()); |
||||
b.setCodeShort(building.getCodeShort()); |
||||
repo.save(b); |
||||
return new ResponseEntity<>(repo.findById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
|
||||
@DeleteMapping("/delete/{id}") |
||||
public ResponseEntity<Boolean> deleteBuilding(@PathVariable Long id){ |
||||
Boolean success = false; |
||||
if (id != null && id > 0) { |
||||
repo.deleteById(id); |
||||
} |
||||
success = true; |
||||
return new ResponseEntity<>(success, HttpStatus.OK); |
||||
} |
||||
|
||||
@DeleteMapping("/delete") |
||||
public ResponseEntity<Boolean> delete(@RequestParam(name="id", required = true) Long id){ |
||||
Boolean success = false; |
||||
Building pc = repo.findById(id).get(); |
||||
try{ |
||||
repo.delete(pc); |
||||
success = true; |
||||
} catch(Exception e){ |
||||
System.out.println("Error: " + e.getMessage()); |
||||
success = false; |
||||
} |
||||
return new ResponseEntity<>(success, HttpStatus.OK); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * Получение перечня объектов строительства
|
||||
// * @return
|
||||
// */
|
||||
// @GetMapping("/list")
|
||||
// public ResponseEntity<List<Building>> getBuildings(){
|
||||
// return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Получение сведений по объекту строительства
|
||||
// * @param id
|
||||
// * @return
|
||||
// */
|
||||
// @GetMapping("/{id}")
|
||||
// public ResponseEntity<?> getBuildingByID(@PathVariable Integer id){
|
||||
// return new ResponseEntity<>(repo.findBuildingById(id), HttpStatus.OK);
|
||||
// }
|
||||
} |
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers; |
||||
package ru.molokoin.resourceserviceapi.controllers.api; |
||||
|
||||
import org.springframework.stereotype.Controller; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
@ -0,0 +1,250 @@
@@ -0,0 +1,250 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers.api; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Comparator; |
||||
import java.util.List; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.dao.EmptyResultDataAccessException; |
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.PageImpl; |
||||
import org.springframework.data.domain.PageRequest; |
||||
import org.springframework.data.domain.Pageable; |
||||
import org.springframework.data.domain.Sort; |
||||
import org.springframework.data.mapping.PropertyReferenceException; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
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.PutMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RequestParam; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.ProgramCretarea; |
||||
import ru.molokoin.resourceserviceapi.repositories.ProgramCretareaRepository; |
||||
|
||||
@RestController |
||||
@RequestMapping(path = "/cretarea", consumes = {"*/*"}) |
||||
public class ProgramCretareaController { |
||||
@Autowired |
||||
private final ProgramCretareaRepository repo; |
||||
|
||||
public ProgramCretareaController(ProgramCretareaRepository repo) { |
||||
this.repo = repo; |
||||
} |
||||
|
||||
/** |
||||
* Получение списка критериев постранично (предпочтительно) |
||||
* первая страница - 0 |
||||
* размер страницы по умолчанию - количество критериев в базе |
||||
* сортировка по умолчанию - id |
||||
* |
||||
* Если в запросе указано неприменимое поле sortBy - вполняется сортировка по умолчанию |
||||
* |
||||
* @param pageNo |
||||
* @param pageSize |
||||
* @param sortBy |
||||
* @return Page<ProgramCretarea> |
||||
*/ |
||||
@GetMapping("/pages") |
||||
public Page<ProgramCretarea> |
||||
page(@RequestParam(name = "page", required = false) Integer pageNo, |
||||
@RequestParam(name = "size", required = false) Long pageSize, |
||||
@RequestParam(name = "sortBy", required = false) String sortBy){ |
||||
|
||||
|
||||
if (pageNo == null || pageNo < 0) pageNo = 0; |
||||
if (pageSize == null || pageSize < 0) pageSize = repo.count(); |
||||
if (sortBy == null) sortBy = "id"; |
||||
|
||||
Sort sort = Sort.by(sortBy); |
||||
Pageable pageable = PageRequest.of(pageNo, pageSize == null ? null : Math.toIntExact(pageSize), sort); |
||||
try{ |
||||
return repo.findAll(pageable); |
||||
}catch(PropertyReferenceException e){ |
||||
sortBy = "id"; |
||||
sort = Sort.by(sortBy); |
||||
pageable = PageRequest.of(pageNo, pageSize == null ? null : Math.toIntExact(pageSize), sort); |
||||
return repo.findAll(pageable); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Получение количества критериев в базе |
||||
* - можно получить из объекта Page getСretareasPage() |
||||
* @return |
||||
*/ |
||||
@GetMapping("/count") |
||||
public ResponseEntity<Long> getСretareasCount(){ |
||||
return new ResponseEntity<>(repo.count(), HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Получение объекта |
||||
* - по id (приоритетный параметр) |
||||
* - по nameShort (проверяет при отсутствии id в запросе) |
||||
* |
||||
* При вызове запроса нужно быть готовым получить либо булевый ответ, либо объект Критерия |
||||
* Метод может быть использован для проверки наличия Критерия в базе |
||||
* |
||||
* @param id |
||||
* @param nameShort |
||||
* @return false |
||||
* - В случае указания отсутствующих/не верных параметров |
||||
* - в случае отсутствия параметров |
||||
*/ |
||||
@GetMapping("") |
||||
public ResponseEntity<?> cretarea(@RequestParam(name="id", required = false) Long id, @RequestParam(name="nameShort", required = false) String nameShort){ |
||||
boolean exists = false; |
||||
if(id != null && repo.existsById(id)){ |
||||
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.OK); |
||||
} |
||||
if (nameShort != null && repo.existsByNameShort(nameShort)){ |
||||
return new ResponseEntity<>(repo.findCretareaByNameShort(nameShort), HttpStatus.OK); |
||||
} |
||||
return new ResponseEntity<>(exists, HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Проверка наличия критерия в базе |
||||
* |
||||
* @param cretarea |
||||
* @return true если критерий в базе найден, иначе false |
||||
*/ |
||||
@GetMapping("/exists") |
||||
public ResponseEntity<Boolean> exists(@RequestBody ProgramCretarea cretarea){ |
||||
return new ResponseEntity<>(repo.existsByNameShort(cretarea.getNameShort()), HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Получение списка отсутствующих в базе критериев |
||||
* @param cretareas |
||||
* @return |
||||
*/ |
||||
@GetMapping("/absent") |
||||
public Page<ProgramCretarea> absent(@RequestBody List<ProgramCretarea> cretareas) { |
||||
List<ProgramCretarea> absent = new ArrayList<>(); |
||||
//проверяем наличие критериев в базе
|
||||
for (ProgramCretarea cretarea : cretareas) { |
||||
if (!repo.existsByNameShort(cretarea.getNameShort())) { |
||||
//если не найден - добавляем в список
|
||||
absent.add(cretarea); |
||||
} |
||||
} |
||||
//сортируем краткие наименования по алфавиту
|
||||
absent.sort(Comparator.comparing(ProgramCretarea::getNameShort)); |
||||
|
||||
//gподготавливаем страницу для ответа
|
||||
Page<ProgramCretarea> absentPage = new PageImpl<>(absent); |
||||
return absentPage; |
||||
} |
||||
|
||||
/** |
||||
* Сохранение Критерия в базе |
||||
* @param cretarea |
||||
* @return |
||||
*/ |
||||
@PostMapping(path = "/create", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> save(@RequestBody ProgramCretarea cretarea) { |
||||
repo.save(cretarea); |
||||
return new ResponseEntity<>(cretarea, HttpStatus.CREATED); |
||||
} |
||||
|
||||
/** |
||||
* Обновление Критерия |
||||
* @param id |
||||
* @param cretarea |
||||
* @return |
||||
*/ |
||||
@PutMapping(path = "/update/{id}", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> updateCretarea(@PathVariable Integer id, @RequestBody ProgramCretarea cretarea) { |
||||
ProgramCretarea pc = repo.findCretareaById(id); |
||||
pc.setName(cretarea.getName()); |
||||
pc.setNameShort(cretarea.getNameShort()); |
||||
repo.save(pc); |
||||
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
/** |
||||
* Обновление Критерия - с параметрами |
||||
* @param id |
||||
* @param cretarea |
||||
* @return обновленный критерий |
||||
*/ |
||||
@PutMapping(path = "/update", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> update(@RequestParam(name="id", required = true) Integer id, @RequestBody ProgramCretarea cretarea) { |
||||
ProgramCretarea pc = repo.findCretareaById(id); |
||||
pc.setName(cretarea.getName()); |
||||
pc.setNameShort(cretarea.getNameShort()); |
||||
repo.save(pc); |
||||
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
/** |
||||
* Удаление Критерия |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@DeleteMapping("/delete/{id}") |
||||
public ResponseEntity<Boolean> deleteCretarea(@PathVariable Long id){ |
||||
Boolean success = false; |
||||
if (id != null && id > 0) { |
||||
repo.deleteById(id); |
||||
} |
||||
success = true; |
||||
return new ResponseEntity<>(success, HttpStatus.OK); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Удаление Критерия - с параметрами |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@DeleteMapping("/delete") |
||||
public ResponseEntity<Boolean> delete(@RequestParam(name="id", required = true) Long id){ |
||||
Boolean success = false; |
||||
ProgramCretarea pc = repo.findCretareaById(id); |
||||
try{ |
||||
repo.delete(pc); |
||||
success = true; |
||||
} catch(Exception e){ |
||||
System.out.println("Error: " + e.getMessage()); |
||||
success = false; |
||||
} |
||||
return new ResponseEntity<>(success, HttpStatus.OK); |
||||
} |
||||
|
||||
// /**
|
||||
// * Получение объекта по ID (параметр в адресе)
|
||||
// * @param id
|
||||
// * @return
|
||||
// */
|
||||
// @GetMapping("/{id}")
|
||||
// public ResponseEntity<?> getCretareaByID(@PathVariable Integer id){
|
||||
// return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.OK);
|
||||
// }
|
||||
|
||||
/** |
||||
* Получение общего списка критериев (не рекомендуется) |
||||
* @return List<ProgramCretarea> |
||||
*/ |
||||
// @GetMapping("/list")
|
||||
// public ResponseEntity<List<ProgramCretarea>> getСretareas(){
|
||||
// return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
} |
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers; |
||||
package ru.molokoin.resourceserviceapi.controllers.api; |
||||
|
||||
import java.util.List; |
||||
|
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
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.Building; |
||||
|
||||
@Repository |
||||
public interface BuildingFace extends ListCrudRepository<Building, Long>{ |
||||
List<Building> findAll(); |
||||
Building findBuildingById(long id); |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
package ru.molokoin.resourceserviceapi.repositories; |
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Building; |
||||
|
||||
@Repository |
||||
public interface BuildingRepository extends JpaRepository<Building, Long>{ |
||||
Building findById(long id); |
||||
Building findByNameShort(String nameShort); |
||||
Boolean existsByNameShort(String nameShort); |
||||
} |
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
package ru.molokoin.resourceserviceapi.repositories; |
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.ProgramCretarea; |
||||
|
||||
@Repository |
||||
public interface ProgramCretareaRepository extends JpaRepository<ProgramCretarea, Long>{ |
||||
ProgramCretarea findCretareaById(long id); |
||||
ProgramCretarea findCretareaByNameShort(String nameShort); |
||||
Boolean existsByNameShort(String nameShort); |
||||
} |
@ -1,14 +0,0 @@
@@ -1,14 +0,0 @@
|
||||
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.ProgramCretarea; |
||||
|
||||
@Repository |
||||
public interface ProgramCretareaRepositoryFace extends ListCrudRepository<ProgramCretarea, Long>{ |
||||
List<ProgramCretarea> findAll(); |
||||
ProgramCretarea findCretareaById(long id); |
||||
} |
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
package ru.molokoin.resourceserviceapi.services; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.Pageable; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Building; |
||||
import ru.molokoin.resourceserviceapi.repositories.BuildingRepository; |
||||
|
||||
public class BuildingService { |
||||
private final BuildingRepository repo; |
||||
|
||||
public BuildingService(BuildingRepository repo) { |
||||
this.repo = repo; |
||||
} |
||||
|
||||
public Page<Building> findAll(Pageable pageable) { |
||||
return repo.findAll(pageable); |
||||
} |
||||
|
||||
public List<Building> findAll() { |
||||
return repo.findAll(); |
||||
} |
||||
|
||||
public Building findById(long id) { |
||||
return repo.findById(id); |
||||
} |
||||
|
||||
public Building findByNameShort(String nameShort) { |
||||
return repo.findByNameShort(nameShort); |
||||
} |
||||
|
||||
public Boolean existsByNameShort(String nameShort) { |
||||
return repo.existsByNameShort(nameShort); |
||||
} |
||||
} |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
package ru.molokoin.resourceserviceapi.services; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.Pageable; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.ProgramCretarea; |
||||
import ru.molokoin.resourceserviceapi.repositories.ProgramCretareaRepository; |
||||
|
||||
public class ProgramCretareaService { |
||||
private final ProgramCretareaRepository repo; |
||||
|
||||
public ProgramCretareaService(ProgramCretareaRepository repo) { |
||||
this.repo = repo; |
||||
} |
||||
|
||||
public Page<ProgramCretarea> findAll(Pageable pageable) { |
||||
return repo.findAll(pageable); |
||||
} |
||||
|
||||
public List<ProgramCretarea> findAll() { |
||||
return repo.findAll(); |
||||
} |
||||
|
||||
public ProgramCretarea findCretareaById(int id) { |
||||
return repo.findCretareaById(id); |
||||
} |
||||
|
||||
public ProgramCretarea findCretareaByMameShort(String nameShort) { |
||||
return repo.findCretareaByNameShort(nameShort); |
||||
} |
||||
|
||||
public Boolean existsByNameShort(String nameShort) { |
||||
return repo.existsByNameShort(nameShort); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue