53 lines
1.9 KiB
Java
53 lines
1.9 KiB
Java
package com.waterquality.projectmanagement.service;
|
|
|
|
import com.waterquality.projectmanagement.dto.plan.InspectionPlanCreateDTO;
|
|
import com.waterquality.projectmanagement.dto.plan.InspectionPlanVO;
|
|
import com.waterquality.projectmanagement.entity.employee.Employee;
|
|
import com.waterquality.projectmanagement.entity.plan.InspectionPlan;
|
|
import com.waterquality.projectmanagement.repository.InspectionPlanRepository;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
|
|
// InspectionPlanService.java
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class InspectionPlanService {
|
|
|
|
private final InspectionPlanRepository planRepository;
|
|
private final EmployeeService employeeService;
|
|
|
|
@Transactional
|
|
public InspectionPlanVO createPlan(InspectionPlanCreateDTO dto) {
|
|
Employee employee = employeeService.getEmployeeById(dto.getEmployeeId());
|
|
|
|
InspectionPlan plan = new InspectionPlan();
|
|
plan.setEmployee(employee);
|
|
plan.setArea(dto.getArea());
|
|
plan.setPlannedTime(dto.getPlannedTime());
|
|
|
|
InspectionPlan saved = planRepository.save(plan);
|
|
return convertToVO(saved);
|
|
}
|
|
|
|
public List<InspectionPlanVO> getPlansByEmployee(Integer employeeId) {
|
|
return planRepository.findByEmployeeEmployeeId(employeeId)
|
|
.stream()
|
|
.map(this::convertToVO)
|
|
.collect(Collectors.toList());
|
|
}
|
|
|
|
private InspectionPlanVO convertToVO(InspectionPlan plan) {
|
|
InspectionPlanVO vo = new InspectionPlanVO();
|
|
vo.setPlanId(plan.getPlanId());
|
|
vo.setEmployeeId(plan.getEmployee().getEmployeeId());
|
|
vo.setArea(plan.getArea());
|
|
vo.setPlannedTime(plan.getPlannedTime());
|
|
vo.setStatus(plan.getStatus());
|
|
vo.setCreatedAt(plan.getCreatedAt());
|
|
return vo;
|
|
}
|
|
} |