it working

This commit is contained in:
DozorovaA.A 2023-06-13 15:05:57 +04:00
parent 3604cd3fe5
commit d00660090f
12 changed files with 84 additions and 57 deletions

Binary file not shown.

View File

@ -21,9 +21,7 @@ public class EmployeeDTO {
public String getFio() { return fio; }
public void setAppointment(Long appointment) {
this.appointmentId = appointment;
}
public void setAppointmentId(Long appointment) { this.appointmentId = appointment; }
public void setFio(String fio) {
this.fio = fio;

View File

@ -8,39 +8,39 @@ import java.util.Date;
public class RequestForCooperationDTO {
private Long id;
private Company nameCompany;
private Long nameCompany;
private String comment;
private Date createDate;
private Date approveDate;
private Boolean isActive;
private EmployeeDTO sotr;
private Long sotr;
private TypeOfRequestEnum type;
public RequestForCooperationDTO(RequestForCooperation request)
{
this.id = request.getId();
this.nameCompany = request.getName();
this.nameCompany = request.getName().getId();
this.comment = request.getComment();
this.approveDate = request.getApproveDate();
this.sotr = new EmployeeDTO(request.getWorker());
this.sotr = request.getWorker().getId();
this.createDate = request.getCreateDate();
this.isActive = request.getActive();
this.type = request.getType();
}
public RequestForCooperationDTO(){}
public long getId() { return this.id; }
public String getComment() { return comment; }
public Boolean getActive() { return isActive; }
public Company getNameCompany() { return nameCompany; }
public Long getNameCompany() { return nameCompany; }
public Date getApproveDate() { return approveDate; }
public Date getCreateDate() { return createDate; }
public EmployeeDTO getSotr() { return sotr; }
public Long getSotr() { return sotr; }
public TypeOfRequestEnum getType() {return type; }
@ -60,11 +60,11 @@ public class RequestForCooperationDTO {
this.createDate = createDate;
}
public void setNameCompany(Company nameCompany) {
public void setNameCompany(Long nameCompany) {
this.nameCompany = nameCompany;
}
public void setSotr(EmployeeDTO sotr) {
public void setSotr(Long sotr) {
this.sotr = sotr;
}

View File

@ -44,7 +44,7 @@ public class EmployeeMVCController {
@PostMapping("/create")
public String createWorker(@ModelAttribute EmployeeDTO employeeDTO, Model model) {
employeeService.addWorker(employeeDTO);
return "redirect:employee";
return "employee";
}
@PostMapping("/edit/{id}")
@ -52,7 +52,7 @@ public class EmployeeMVCController {
employeeService.updateReportWorker(id, employeeDTO);
// model.addAttribute("employees", employeeService.findAllWorkers());
// model.addAttribute("appointments", appointmentService.findAllAppointments());
return "redirect:employee";
return "/employee";
}
@PostMapping("/delete/{id}")

View File

@ -10,10 +10,12 @@ import com.example.demo.speaker.model.TypeOfRequestEnum;
import com.example.demo.speaker.service.CompanyService;
import com.example.demo.speaker.service.EmployeeService;
import com.example.demo.speaker.service.RequestForCooperationService;
import org.h2.store.Data;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@ -39,6 +41,7 @@ public class RequestMVCController {
@GetMapping
public String getRequests(Model model) {
model.addAttribute("requestDTO", new RequestForCooperationDTO());
model.addAttribute("requests", requestForCooperationService.findAllRequests()
.stream().map(RequestForCooperationDTO::new).toList());
model.addAttribute("types", types);
@ -49,27 +52,23 @@ public class RequestMVCController {
return "request";
}
@PostMapping("/add")
public String createRequest(@PathVariable Long nameCompany,
@PathVariable String comment,
@PathVariable Integer isActive,
@PathVariable Long sort,
@PathVariable Long type,
@PostMapping("/create")
public String createRequest(@ModelAttribute("requestDTO") RequestForCooperationDTO requestDTO,
Model model
){
requestDTO.setCreateDate(new Date());
requestDTO.setApproveDate(new Date());
//@RequestBody RequestForCooperationDTO requestDTO) {
var company = companyService.findCompany(nameCompany);
var emp = employeeService.findWorker(sort);
var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment);
requestForCooperationService.addRequest(new RequestForCooperationDTO(request));
return "redirect:request";
requestForCooperationService.addRequest(requestDTO);
return "request";
}
@PutMapping("/{id}")
public String updateRequest(@PathVariable Long id,
@ModelAttribute RequestForCooperationDTO request,
Model model) {
request.setApproveDate(new Date());
request.setCreateDate(requestForCooperationService.findRequest(id).getCreateDate());
requestForCooperationService.updateRequest(request);
return "redirect:request";
}

View File

@ -45,7 +45,7 @@ public class RequestForCooperationController {
//@RequestBody RequestForCooperationDTO requestDTO) {
var company = companyService.findCompany(nameCompany);
var emp = employeeService.findWorker(sort);
var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment);
var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment, emp);
return requestForCooperationService.addRequest(new RequestForCooperationDTO(request));
}

View File

@ -27,19 +27,20 @@ public class RequestForCooperation {
public RequestForCooperation() {
}
Random r = new Random();
public RequestForCooperation(Company name, Date createDate, TypeOfRequestEnum type, String text) {
public RequestForCooperation(Company name, Date createDate, TypeOfRequestEnum type, String text, Employee employee) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
this.id = r.nextLong();
this.sotr = employee;
}
public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text) {
public RequestForCooperation(Long id, Company name, Date createDate,
TypeOfRequestEnum type, String text) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
this.id = id;
}
public Company getName()

View File

@ -25,10 +25,13 @@ public class RequestForCooperationService {
@Transactional
public RequestForCooperation addRequest(RequestForCooperationDTO requestDTO) {
final RequestForCooperation request = new RequestForCooperation(requestDTO.getNameCompany(),
var company = companyService.findCompany(requestDTO.getNameCompany());
var empl = employeeService.findWorker(requestDTO.getSotr());
final RequestForCooperation request = new RequestForCooperation(company,
requestDTO.getCreateDate(),
requestDTO.getType(),
requestDTO.getComment());
requestDTO.getComment(),
empl);
requestForCooperationRepository.save(request);
return request;
}
@ -49,7 +52,7 @@ public class RequestForCooperationService {
final RequestForCooperation currentReport = findRequest(requestDTO.getId());
currentReport.setApproveDate(requestDTO.getApproveDate());
currentReport.setActive(requestDTO.getActive());
currentReport.setUser(employeeService.findWorker(requestDTO.getSotr().getId()));
currentReport.setUser(employeeService.findWorker(requestDTO.getSotr()));
requestForCooperationRepository.save(currentReport);
return currentReport;
}

View File

@ -13,7 +13,7 @@
<input type="text" class="form-control" id="name" th:field="${appointmentDTO.name}" required="true">
</div>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<button type="submit" class="btn btn-info">
<span >Добавить</span>
</button>
</div>
@ -34,12 +34,12 @@
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/appointment/edit/{id}(id=${appointment.id})}" th:object="${appointmentDTO}" th:method="post">
<input type="text" class="form-control" id="nameAppointment" th:field="${appointmentDTO.name}" th:placeholder="${appointment.name}" style="width: 60%; display: inline-block" >
<button class="btn btn-warning button-fixed button-sm"
<button class="btn btn-info"
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-danger button-fixed button-sm" style="display: inline-block"
<button type="button" class="btn btn-info" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${appointment.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->

View File

@ -12,7 +12,7 @@
<input type="text" class="form-control" id="legalAdressCompanyNew" th:field="*{legalAdressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="adressCompanyNew" th:field="*{adressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="contactEmailNew" th:field="*{contactEmail}" style="width: 15%; display: inline-block" >
<button class="btn btn-warning button-fixed button-sm"
<button class="btn btn-info"
type="submit" style="display: inline-block"> Создать
</button>
</form>
@ -35,12 +35,12 @@
<input type="text" class="form-control" id="legalAdressCompany" th:placeholder="${company.legalAdressCompany}" th:field="*{legalAdressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="adressCompany" th:placeholder="${company.adressCompany}" th:field="*{adressCompany}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="contactEmail" th:placeholder="${company.contactEmail}" th:field="*{contactEmail}" style="width: 15%; display: inline-block" >
<button class="btn btn-warning button-fixed button-sm"
<button class="btn btn-info"
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-danger button-fixed button-sm" style="display: inline-block"
<button type="button" class="btn btn-info" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${company.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->

View File

@ -12,7 +12,7 @@
<label for="name" class="form-label">Название</label>
<input type="text" class="form-control" id="name" th:field="${employeeDTO.fio}" required="true">
</div>
<select id="appointmentId" class="form-select" th:name="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
<select id="appointmentId" class="form-select" th:field="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
<option th:each="app: ${appointments}" th:value="${app.id}">
<span th:text="${app.name}"></span>
</option>
@ -41,7 +41,7 @@
<form th:action="@{/employee/edit/{id}(id=${employee.id})}" th:object="${employeeDTO}" th:method="post">
<input type="text" class="form-control" id="fio" th:field="${employeeDTO.fio}" th:placeholder="${employee.fio}" style="width: 30%; display: inline-block" >
<select id="appointment" class="form-select" th:name="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
<select id="appointment" class="form-select" th:field="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
<option th:each="app: ${appointments}" th:value="${app.id}" th:selected="${employee.appointmentId} == ${app.id}">
<span th:text="${app.name}"></span>
</option>
@ -52,7 +52,7 @@
</button>
<button type="button" class="btn btn-danger button-fixed button-sm" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${employee.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</i> Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->

View File

@ -6,6 +6,32 @@
</head>
<body>
<div layout:fragment="content">
<form th:action="@{/request/create}" th:object="${requestDTO}" th:method="post">
<select id="companyNew" class="form-select" th:name="company" th:field="${requestDTO.nameCompany}" style="width: 15%; display: inline-block">
<option th:each="value: ${companies}" th:value="${value.id}">
<span th:text="${value.getNameCompany()}"></span>
</option>
</select>
<!-- <input type="date" class="form-control" id="createDateNew" th:field="${requestDTO.createDate}" style="width: 15%; display: inline-block" >-->
<!-- <input type="date" class="form-control" id="approveDateNew" th:field="${requestDTO.approveDate}" style="width: 15%; display: inline-block" >-->
<input type="text" class="form-control" id="commentNew" th:field="${requestDTO.comment}" style="width: 15%; display: inline-block" >
<select id="employeeNew" class="form-select" th:field="${requestDTO.sotr}" th:name="employee" style="width: 30%; display: inline-block">
<option th:each="value: ${employees}" th:value="${value.id}">
<span th:text="${value.getFio()}"></span>
</option>
</select>
<select id="typesNew" class="form-select" th:name="type" th:field="${requestDTO.type}" style="width: 30%; display: inline-block">
<option th:each="value: ${types}" th:value="${value}">
<span th:text="${value}"></span>
</option>
</select>
<button class="btn btn-warning button-fixed button-sm"
type="submit" style="display: inline-block"> Изменить
</button>
</form>
<div class="table-responsive">
<table class="table">
<thead>
@ -19,24 +45,24 @@
<tr th:each="request, iterator: ${requests}">
<td th:text="${request.id}"/>
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/request/edit/{id}(id=*{id})}" th:object="${request}" th:method="post">
<select id="company" class="form-select" th:name="company" style="width: 15%; display: inline-block">
<option th:each="value: ${companies}" th:selected="${request.getNameCompany().getNameCompany()} == ${value.nameCompany}">
<form th:action="@{/request/edit/{id}(id=${request.id})}" th:object="${requestDTO}" th:method="post">
<select id="company" class="form-select" th:name="company" th:field="*{nameCompany}" style="width: 15%; display: inline-block">
<option th:each="value: ${companies}" th:value="${value.id}" th:selected="${request.getNameCompany()} == ${value.id}">
<span th:text="${value.getNameCompany()}"></span>
</option>
</select>
<input type="date" class="form-control" id="createDate" th:value="${request.getCreateDate()}" style="width: 15%; display: inline-block" >
<input type="date" class="form-control" id="approveDate" th:value="${request.getApproveDate()}" style="width: 15%; display: inline-block" >
<input type="text" class="form-control" id="comment" th:value="${request.getComment()}" style="width: 15%; display: inline-block" >
<!-- <input type="date" class="form-control" id="createDate" th:value="${request.createDate}" style="width: 15%; display: inline-block" readonly>-->
<!-- <input type="date" class="form-control" id="approveDate" th:value="${request.approveDate}" style="width: 15%; display: inline-block" readonly>-->
<input type="text" class="form-control" id="comment" th:placeholder="${request.comment}" th:field="${requestDTO.comment}" style="width: 15%; display: inline-block" >
<select id="employee" class="form-select" th:name="employee" style="width: 30%; display: inline-block">
<option th:each="value: ${employees}" th:selected="${request.getSotr().getFio()} == ${value.getFio()}">
<select id="employee" class="form-select" th:field="${requestDTO.sotr}" th:name="employee" style="width: 30%; display: inline-block">
<option th:each="value: ${employees}" th:value="${value.id}" th:selected="${request.getSotr()} == ${value.id}">
<span th:text="${value.getFio()}"></span>
</option>
</select>
<select id="types" class="form-select" th:name="type" style="width: 30%; display: inline-block">
<option th:each="value: ${types}" th:selected="${request.getType()} == ${value}">
<select id="types" class="form-select" th:field="${requestDTO.type}" th:name="type" style="width: 30%; display: inline-block">
<option th:each="value: ${types}" th:value="${value}" th:selected="${request.getType()} == ${value}">
<span th:text="${value}"></span>
</option>
</select>
@ -45,15 +71,15 @@
type="submit" style="display: inline-block"> Изменить
</button>
<button type="button" class="btn btn-danger button-fixed button-sm" style="display: inline-block"
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${employee.id}').click()|">
th:attr="onclick=|confirm('Удалить запись?') && document.getElementById('remove-${request.id}').click()|">
<i class="fa fa-trash" aria-hidden="true"></i> Удалить
</button>
</form></td>
<!--<td th:text="${appointment.name}" style="width: 60%"/>-->
<td style="width: 10%">
<form th:action="@{/employee/delete/{id}(id=${employee.id})}" method="post">
<button th:id="'remove-' + ${employee.id}" type="submit" style="display: none">
<form th:action="@{/request/delete/{id}(id=${request.id})}" method="post">
<button th:id="'remove-' + ${request.id}" type="submit" style="display: none">
Удалить
</button>
</form>