work with employee
This commit is contained in:
parent
2b8514b8e2
commit
4686c2a973
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -19,4 +19,8 @@ public class AppointmentDTO {
|
|||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String nameAppointment){
|
||||||
|
this.name = nameAppointment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,21 @@ public class CompanyDTO {
|
|||||||
|
|
||||||
public String getLegalAdressCompany() { return legalAdressCompany; }
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,18 +5,27 @@ import com.example.demo.speaker.model.Employee;
|
|||||||
public class EmployeeDTO {
|
public class EmployeeDTO {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String fio;
|
private String fio;
|
||||||
private AppointmentDTO appointment;
|
private Long appointmentId;
|
||||||
|
|
||||||
public EmployeeDTO(Employee employee)
|
public EmployeeDTO(Employee employee)
|
||||||
{
|
{
|
||||||
this.id = employee.getId();
|
this.id = employee.getId();
|
||||||
this.fio = employee.getFio();
|
this.fio = employee.getFio();
|
||||||
this.appointment = new AppointmentDTO(employee.getPost());
|
this.appointmentId = employee.getPost().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EmployeeDTO(){}
|
||||||
public Long getId() { return id; }
|
public Long getId() { return id; }
|
||||||
|
|
||||||
public AppointmentDTO getAppointment() { return appointment; }
|
public Long getAppointmentId() { return appointmentId; }
|
||||||
|
|
||||||
public String getFio() { return fio; }
|
public String getFio() { return fio; }
|
||||||
|
|
||||||
|
public void setAppointment(Long appointment) {
|
||||||
|
this.appointmentId = appointment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFio(String fio) {
|
||||||
|
this.fio = fio;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,4 +43,32 @@ public class RequestForCooperationDTO {
|
|||||||
public EmployeeDTO getSotr() { return sotr; }
|
public EmployeeDTO getSotr() { return sotr; }
|
||||||
|
|
||||||
public TypeOfRequestEnum getType() {return type; }
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,21 +36,22 @@ public class EmployeeMVCController {
|
|||||||
.toList());
|
.toList());
|
||||||
model.addAttribute("appointments",
|
model.addAttribute("appointments",
|
||||||
appointmentService.findAllAppointments().stream().map(AppointmentDTO::new).toList());
|
appointmentService.findAllAppointments().stream().map(AppointmentDTO::new).toList());
|
||||||
|
model.addAttribute("employeeDTO", new EmployeeDTO());
|
||||||
|
|
||||||
return "employee";
|
return "employee";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public String createWorker(@RequestParam("name") String name, @RequestParam("appointmentId") Long appointmentId, Model model) {
|
public String createWorker(@ModelAttribute EmployeeDTO employeeDTO, Model model) {
|
||||||
var Employee = new Employee(name, appointmentService.findAppointment(appointmentId));
|
employeeService.addWorker(employeeDTO);
|
||||||
model.addAttribute("employee",new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee))));
|
|
||||||
return "redirect:employee";
|
return "redirect:employee";
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/edit/{id}")
|
@PostMapping("/edit/{id}")
|
||||||
public String updateWorker(@PathVariable Long id,@ModelAttribute("employee") EmployeeDTO employee, Model model) {
|
public String updateWorker(@PathVariable Long id,@ModelAttribute("employeeDTO") EmployeeDTO employeeDTO, Model model) {
|
||||||
employeeService.updateReportWorker(id, employee);
|
employeeService.updateReportWorker(id, employeeDTO);
|
||||||
model.addAttribute("employees", employeeService.findAllWorkers());
|
// model.addAttribute("employees", employeeService.findAllWorkers());
|
||||||
model.addAttribute("appointments", appointmentService.findAllAppointments());
|
// model.addAttribute("appointments", appointmentService.findAllAppointments());
|
||||||
return "redirect:employee";
|
return "redirect:employee";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import java.util.Random;
|
|||||||
public class Employee {
|
public class Employee {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String fio;
|
private String fio;
|
||||||
|
@ -23,7 +23,7 @@ private final AppointmentService appointmentService;
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public Employee addWorker(EmployeeDTO employee) {
|
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);
|
Employee employeeNew = new Employee(employee.getFio(), appontment);
|
||||||
employeeRepository.save(employeeNew);
|
employeeRepository.save(employeeNew);
|
||||||
return employeeNew;
|
return employeeNew;
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
<tr th:each="appointment, iterator: ${appointments}">
|
<tr th:each="appointment, iterator: ${appointments}">
|
||||||
<td th:text="${appointment.id}"/>
|
<td th:text="${appointment.id}"/>
|
||||||
<td ><!--<td th:text="${appointment.name}"/>-->
|
<td ><!--<td th:text="${appointment.name}"/>-->
|
||||||
<form th:action="@{/appointment/edit/{id}(id=*{id})}" th:object="${appointmentDTO}" th:method="post">
|
<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:value="${appointment.name}" style="width: 60%; display: inline-block" >
|
<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-warning button-fixed button-sm"
|
||||||
type="submit" style="display: inline-block"> Изменить
|
type="submit" style="display: inline-block"> Изменить
|
||||||
</button>
|
</button>
|
||||||
|
@ -6,25 +6,44 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div layout:fragment="content">
|
<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">
|
<div class="table-responsive">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">ID</th>
|
<th scope="col">ID</th>
|
||||||
<th scope="col">Имя</th>
|
<th scope="col">Сотрудник</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="employee, iterator: ${employees}">
|
<tr th:each="employee, iterator: ${employees}">
|
||||||
<td th:text="${employee.id}"/>
|
<td th:text="${employee.id}"/>
|
||||||
<td ><!--<td th:text="${appointment.name}"/>-->
|
<td >
|
||||||
<form th:action="@{/employee/edit/{id}(id=*{id})}" th:object="${employee}" th:method="post">
|
<form th:action="@{/employee/edit/{id}(id=${employee.id})}" th:object="${employeeDTO}" th:method="post">
|
||||||
<input type="text" class="form-control" id="fio" th:value="*{fio}" style="width: 30%; display: inline-block" >
|
<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">
|
<select id="appointment" class="form-select" th:name="${employeeDTO.appointmentId}" style="width: 30%; display: inline-block">
|
||||||
<option th:each="value: ${appointments}" th:selected="${employee.appointment.name} == ${value.name}">
|
<option th:each="app: ${appointments}" th:value="${app.id}" th:selected="${employee.appointmentId} == ${app.id}">
|
||||||
<span th:text="${value.name}"></span>
|
<span th:text="${app.name}"></span>
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user