add report

This commit is contained in:
DozorovaA.A 2023-06-13 19:46:18 +04:00
parent c96cf40dee
commit 353639c22f
6 changed files with 28 additions and 22 deletions

Binary file not shown.

View File

@ -15,7 +15,7 @@ import java.util.List;
public class EmployeeController {
private final EmployeeService employeeService;
private final RequestForCooperationService requestForCooperationService;
private final AppointmentService appointmentService;
private final AppointmentService appointmentService;
public EmployeeController(EmployeeService employeeService, RequestForCooperationService requestForCooperationService, AppointmentService appointmentService) {
@ -40,9 +40,11 @@ public class EmployeeController {
return new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee)));
}
@PutMapping("/{id}")
public EmployeeDTO updateWorker(@PathVariable Long id,@RequestBody EmployeeDTO employeeDTO) {
return new EmployeeDTO(employeeService.updateReportWorker(id, employeeDTO));
@PutMapping("/update")
public EmployeeDTO updateWorker(@RequestParam("id") Long id, @RequestParam("name") String name) {
var emp = employeeService.findWorker(id);
emp.setFio(name);
return new EmployeeDTO(employeeService.updateReportWorker(id, new EmployeeDTO(emp)));
}
@DeleteMapping("/{id}")
@ -51,15 +53,17 @@ public class EmployeeController {
}
@GetMapping("/id={id}")
public List<RequestForCooperation> getListOfReports(@PathVariable Long id) {
var employee = employeeService.findWorker(id);
return employeeService.findAllRequestsOfEmployee(employee);
public List<RequestForCooperation> getListOfReports(@PathVariable Long id) {
var employee = employeeService.findWorker(id);
return employeeService.findAllRequestsOfEmployee(employee);
}
@GetMapping("/postId={postId}")
public List<Employee> getListOfWorkers(@RequestParam("postId") Long id) {
final Appointment appointment = appointmentService.findAppointment(id);
return employeeService.findWorkerByPost(appointment);
@GetMapping("/postid={id}")
public List<Employee> getListOfWorkers(@PathVariable Long id) {
final Appointment appointment = appointmentService.findAppointment(id);
var res = employeeService.findWorkerByPost(appointment);
return res;
//return new ArrayList<Employee>();
}
}

View File

@ -7,6 +7,9 @@ import com.example.demo.speaker.service.EmployeeService;
import com.example.demo.speaker.service.RequestForCooperationService;
import org.springframework.web.bind.annotation.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@ -34,17 +37,15 @@ public class RequestForCooperationController {
}
@PostMapping("/add")
public RequestForCooperation createRequest(@PathVariable Long nameCompany,
@PathVariable String comment,
@PathVariable Integer isActive,
@PathVariable Long sort,
@PathVariable Long type
){
public RequestForCooperation createRequest(@RequestParam Long nameCompany,
@RequestParam String comment
) throws ParseException {
//@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 emp = employeeService.findWorker(1L);
DateFormat form = new SimpleDateFormat("yyyy-MM-dd");
var request = new RequestForCooperation(656656L, company, form.parse("2023-06-13"), TypeOfRequestEnum.DEVELOP, comment, emp);
return requestForCooperationService.addRequest(new RequestForCooperationDTO(request));
}

View File

@ -34,12 +34,13 @@ public class RequestForCooperation {
this.typeSotr = type;
this.id = r.nextLong();
}
public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text) {
public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text, Employee emp) {
this.nameCompany = name;
this.createDate = createDate;
this.comment = text;
this.typeSotr = type;
this.id = id;
this.sotr = emp;
}
public Company getName()

View File

@ -10,7 +10,7 @@ import org.springframework.data.repository.query.Param;
import java.util.List;
public interface IEmployeeRepository extends JpaRepository<Employee, Long> {
@Query("SELECT DISTINCT p.fio FROM Employee p where :appointment = p.appointment")
@Query("SELECT DISTINCT p FROM Employee p where :appointment = p.appointment")
List<Employee> getEmployeeByAppointment(@Param("appointment") Appointment appointment);
@Query("SELECT DISTINCT p FROM RequestForCooperation p where :employee = p.sotr")

View File

@ -35,7 +35,7 @@ private final IAppointmentRepository appointmentRepository;
@Transactional(readOnly = true)
public Appointment findAppointment(Long id) {
final Optional<Appointment> appointment = appointmentRepository.findById(id);
return appointment.orElseThrow(()->new AppointmentNotFoundException(id));
return appointment.get();
}
@Transactional(readOnly = true)