work with employee

This commit is contained in:
DozorovaA.A 2023-06-13 11:31:07 +04:00
parent 2b8514b8e2
commit 4686c2a973
10 changed files with 99 additions and 21 deletions

Binary file not shown.

View File

@ -19,4 +19,8 @@ public class AppointmentDTO {
public String getName() {
return name;
}
public void setName(String nameAppointment){
this.name = nameAppointment;
}
}

View File

@ -39,4 +39,21 @@ public class CompanyDTO {
public String getLegalAdressCompany() { return legalAdressCompany; }
public void setNameCompany(String name)
{
this.nameCompany = name;
}
public void setAdressCompany(String adressCompany) {
this.adressCompany = adressCompany;
}
public void setContactEmail(String contactEmail) {
this.contactEmail = contactEmail;
}
public void setLegalAdressCompany(String legalAdressCompany) {
this.legalAdressCompany = legalAdressCompany;
}
}

View File

@ -5,18 +5,27 @@ import com.example.demo.speaker.model.Employee;
public class EmployeeDTO {
private Long id;
private String fio;
private AppointmentDTO appointment;
private Long appointmentId;
public EmployeeDTO(Employee employee)
{
this.id = employee.getId();
this.fio = employee.getFio();
this.appointment = new AppointmentDTO(employee.getPost());
this.appointmentId = employee.getPost().getId();
}
public EmployeeDTO(){}
public Long getId() { return id; }
public AppointmentDTO getAppointment() { return appointment; }
public Long getAppointmentId() { return appointmentId; }
public String getFio() { return fio; }
public void setAppointment(Long appointment) {
this.appointmentId = appointment;
}
public void setFio(String fio) {
this.fio = fio;
}
}

View File

@ -43,4 +43,32 @@ public class RequestForCooperationDTO {
public EmployeeDTO getSotr() { return sotr; }
public TypeOfRequestEnum getType() {return type; }
public void setActive(Boolean active) {
isActive = active;
}
public void setApproveDate(Date approveDate) {
this.approveDate = approveDate;
}
public void setComment(String comment) {
this.comment = comment;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public void setNameCompany(Company nameCompany) {
this.nameCompany = nameCompany;
}
public void setSotr(EmployeeDTO sotr) {
this.sotr = sotr;
}
public void setType(TypeOfRequestEnum type) {
this.type = type;
}
}

View File

@ -36,21 +36,22 @@ public class EmployeeMVCController {
.toList());
model.addAttribute("appointments",
appointmentService.findAllAppointments().stream().map(AppointmentDTO::new).toList());
model.addAttribute("employeeDTO", new EmployeeDTO());
return "employee";
}
@PostMapping("/create")
public String createWorker(@RequestParam("name") String name, @RequestParam("appointmentId") Long appointmentId, Model model) {
var Employee = new Employee(name, appointmentService.findAppointment(appointmentId));
model.addAttribute("employee",new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee))));
public String createWorker(@ModelAttribute EmployeeDTO employeeDTO, Model model) {
employeeService.addWorker(employeeDTO);
return "redirect:employee";
}
@PostMapping("/edit/{id}")
public String updateWorker(@PathVariable Long id,@ModelAttribute("employee") EmployeeDTO employee, Model model) {
employeeService.updateReportWorker(id, employee);
model.addAttribute("employees", employeeService.findAllWorkers());
model.addAttribute("appointments", appointmentService.findAllAppointments());
public String updateWorker(@PathVariable Long id,@ModelAttribute("employeeDTO") EmployeeDTO employeeDTO, Model model) {
employeeService.updateReportWorker(id, employeeDTO);
// model.addAttribute("employees", employeeService.findAllWorkers());
// model.addAttribute("appointments", appointmentService.findAllAppointments());
return "redirect:employee";
}

View File

@ -10,7 +10,7 @@ import java.util.Random;
public class Employee {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false)
private String fio;

View File

@ -23,7 +23,7 @@ private final AppointmentService appointmentService;
@Transactional
public Employee addWorker(EmployeeDTO employee) {
var appontment = appointmentService.findAppointment(employee.getAppointment().getId());
var appontment = appointmentService.findAppointment(employee.getAppointmentId());
Employee employeeNew = new Employee(employee.getFio(), appontment);
employeeRepository.save(employeeNew);
return employeeNew;

View File

@ -32,8 +32,8 @@
<tr th:each="appointment, iterator: ${appointments}">
<td th:text="${appointment.id}"/>
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/appointment/edit/{id}(id=*{id})}" th:object="${appointmentDTO}" th:method="post">
<input type="text" class="form-control" id="nameAppointment" th:field="${appointmentDTO.name}" th:value="${appointment.name}" style="width: 60%; display: inline-block" >
<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"
type="submit" style="display: inline-block"> Изменить
</button>

View File

@ -6,25 +6,44 @@
</head>
<body>
<div layout:fragment="content">
<div>
<form action="#" th:action="@{/employee/create}" th:object="${employeeDTO}" method="post">
<div class="mb-3">
<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">
<option th:each="app: ${appointments}" th:value="${app.id}">
<span th:text="${app.name}"></span>
</option>
</select>
<div class="mb-3">
<button type="submit" class="btn btn-primary button-fixed">
<span >Добавить</span>
</button>
</div>
</form>
</div>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Имя</th>
<th scope="col">Сотрудник</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<tr th:each="employee, iterator: ${employees}">
<td th:text="${employee.id}"/>
<td ><!--<td th:text="${appointment.name}"/>-->
<form th:action="@{/employee/edit/{id}(id=*{id})}" th:object="${employee}" th:method="post">
<input type="text" class="form-control" id="fio" th:value="*{fio}" style="width: 30%; display: inline-block" >
<td >
<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="appointment" style="width: 30%; display: inline-block">
<option th:each="value: ${appointments}" th:selected="${employee.appointment.name} == ${value.name}">
<span th:text="${value.name}"></span>
<select id="appointment" class="form-select" th:name="${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>
</select>