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 { public class EmployeeController {
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final RequestForCooperationService requestForCooperationService; private final RequestForCooperationService requestForCooperationService;
private final AppointmentService appointmentService; private final AppointmentService appointmentService;
public EmployeeController(EmployeeService employeeService, RequestForCooperationService requestForCooperationService, 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))); return new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee)));
} }
@PutMapping("/{id}") @PutMapping("/update")
public EmployeeDTO updateWorker(@PathVariable Long id,@RequestBody EmployeeDTO employeeDTO) { public EmployeeDTO updateWorker(@RequestParam("id") Long id, @RequestParam("name") String name) {
return new EmployeeDTO(employeeService.updateReportWorker(id, employeeDTO)); var emp = employeeService.findWorker(id);
emp.setFio(name);
return new EmployeeDTO(employeeService.updateReportWorker(id, new EmployeeDTO(emp)));
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@ -51,15 +53,17 @@ public class EmployeeController {
} }
@GetMapping("/id={id}") @GetMapping("/id={id}")
public List<RequestForCooperation> getListOfReports(@PathVariable Long id) { public List<RequestForCooperation> getListOfReports(@PathVariable Long id) {
var employee = employeeService.findWorker(id); var employee = employeeService.findWorker(id);
return employeeService.findAllRequestsOfEmployee(employee); return employeeService.findAllRequestsOfEmployee(employee);
} }
@GetMapping("/postId={postId}") @GetMapping("/postid={id}")
public List<Employee> getListOfWorkers(@RequestParam("postId") Long id) { public List<Employee> getListOfWorkers(@PathVariable Long id) {
final Appointment appointment = appointmentService.findAppointment(id); final Appointment appointment = appointmentService.findAppointment(id);
return employeeService.findWorkerByPost(appointment); 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 com.example.demo.speaker.service.RequestForCooperationService;
import org.springframework.web.bind.annotation.*; 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.Date;
import java.util.List; import java.util.List;
@ -34,17 +37,15 @@ public class RequestForCooperationController {
} }
@PostMapping("/add") @PostMapping("/add")
public RequestForCooperation createRequest(@PathVariable Long nameCompany, public RequestForCooperation createRequest(@RequestParam Long nameCompany,
@PathVariable String comment, @RequestParam String comment
@PathVariable Integer isActive, ) throws ParseException {
@PathVariable Long sort,
@PathVariable Long type
){
//@RequestBody RequestForCooperationDTO requestDTO) { //@RequestBody RequestForCooperationDTO requestDTO) {
var company = companyService.findCompany(nameCompany); var company = companyService.findCompany(nameCompany);
var emp = employeeService.findWorker(sort); var emp = employeeService.findWorker(1L);
var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment); 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)); return requestForCooperationService.addRequest(new RequestForCooperationDTO(request));
} }

View File

@ -34,12 +34,13 @@ public class RequestForCooperation {
this.typeSotr = type; this.typeSotr = type;
this.id = r.nextLong(); 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.nameCompany = name;
this.createDate = createDate; this.createDate = createDate;
this.comment = text; this.comment = text;
this.typeSotr = type; this.typeSotr = type;
this.id = id; this.id = id;
this.sotr = emp;
} }
public Company getName() public Company getName()

View File

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

View File

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