#101 project deadlines on timeline
This commit is contained in:
parent
eceb8ec528
commit
eb30d07d10
@ -9,6 +9,7 @@ import ru.ulstu.grant.repository.GrantRepository;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
import ru.ulstu.project.repository.ProjectRepository;
|
||||
import ru.ulstu.timeline.service.EventService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
@ -28,17 +29,20 @@ public class ProjectService {
|
||||
private final DeadlineService deadlineService;
|
||||
private final GrantRepository grantRepository;
|
||||
private final FileService fileService;
|
||||
private final EventService eventService;
|
||||
private final UserService userService;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository,
|
||||
DeadlineService deadlineService,
|
||||
GrantRepository grantRepository,
|
||||
FileService fileService,
|
||||
EventService eventService,
|
||||
UserService userService) {
|
||||
this.projectRepository = projectRepository;
|
||||
this.deadlineService = deadlineService;
|
||||
this.grantRepository = grantRepository;
|
||||
this.fileService = fileService;
|
||||
this.eventService = eventService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@ -64,6 +68,7 @@ public class ProjectService {
|
||||
public Project create(ProjectDto projectDto) throws IOException {
|
||||
Project newProject = copyFromDto(new Project(), projectDto);
|
||||
newProject = projectRepository.save(newProject);
|
||||
eventService.createFromProject(newProject);
|
||||
return newProject;
|
||||
}
|
||||
|
||||
@ -74,6 +79,7 @@ public class ProjectService {
|
||||
fileService.deleteFile(project.getApplication());
|
||||
}
|
||||
projectRepository.save(copyFromDto(project, projectDto));
|
||||
eventService.updateProjectDeadlines(project);
|
||||
return project;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.students.model.Task;
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
@ -88,6 +89,10 @@ public class Event extends BaseEntity {
|
||||
@JoinColumn(name = "grant_id")
|
||||
private Grant grant;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "project_id")
|
||||
private Project project;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "task_id")
|
||||
private Task task;
|
||||
@ -196,6 +201,14 @@ public class Event extends BaseEntity {
|
||||
this.grant = grant;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
public void setProject(Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
public Task getTask() {
|
||||
return task;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank;
|
||||
import ru.ulstu.conference.model.ConferenceDto;
|
||||
import ru.ulstu.grant.model.GrantDto;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
import ru.ulstu.students.model.TaskDto;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
|
||||
@ -30,6 +31,7 @@ public class EventDto {
|
||||
private PaperDto paperDto;
|
||||
private ConferenceDto conferenceDto;
|
||||
private GrantDto grantDto;
|
||||
private ProjectDto projectDto;
|
||||
private TaskDto taskDto;
|
||||
|
||||
@JsonCreator
|
||||
@ -45,6 +47,7 @@ public class EventDto {
|
||||
@JsonProperty("recipients") List<UserDto> recipients,
|
||||
@JsonProperty("conferenceDto") ConferenceDto conferenceDto,
|
||||
@JsonProperty("grantDto") GrantDto grantDto,
|
||||
@JsonProperty("projectDto") ProjectDto projectDto,
|
||||
@JsonProperty("taskDto") TaskDto taskDto) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
@ -58,6 +61,7 @@ public class EventDto {
|
||||
this.paperDto = paperDto;
|
||||
this.conferenceDto = conferenceDto;
|
||||
this.grantDto = grantDto;
|
||||
this.projectDto = projectDto;
|
||||
this.taskDto = taskDto;
|
||||
}
|
||||
|
||||
@ -80,6 +84,9 @@ public class EventDto {
|
||||
if (grantDto != null) {
|
||||
this.grantDto = new GrantDto(event.getGrant());
|
||||
}
|
||||
if (projectDto != null) {
|
||||
this.projectDto = new ProjectDto(event.getProject());
|
||||
}
|
||||
if (taskDto != null) {
|
||||
this.taskDto = new TaskDto(event.getTask());
|
||||
}
|
||||
@ -145,6 +152,14 @@ public class EventDto {
|
||||
this.grantDto = grantDto;
|
||||
}
|
||||
|
||||
public ProjectDto getProjectDto() {
|
||||
return projectDto;
|
||||
}
|
||||
|
||||
public void setProjectDto(ProjectDto projectDto) {
|
||||
this.projectDto = projectDto;
|
||||
}
|
||||
|
||||
public TaskDto getTaskDto() {
|
||||
return taskDto;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.students.model.Task;
|
||||
import ru.ulstu.timeline.model.Event;
|
||||
|
||||
@ -23,5 +24,7 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
|
||||
|
||||
List<Event> findAllByGrant(Grant grant);
|
||||
|
||||
List<Event> findAllByProject(Project project);
|
||||
|
||||
List<Event> findAllByTask(Task task);
|
||||
}
|
||||
|
@ -8,11 +8,13 @@ import ru.ulstu.conference.model.Conference;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.grant.model.Grant;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.students.model.Task;
|
||||
import ru.ulstu.timeline.model.Event;
|
||||
import ru.ulstu.timeline.model.EventDto;
|
||||
import ru.ulstu.timeline.model.Timeline;
|
||||
import ru.ulstu.timeline.repository.EventRepository;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.model.UserDto;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
@ -205,6 +207,38 @@ public class EventService {
|
||||
createFromGrant(grant);
|
||||
}
|
||||
|
||||
public void createFromProject(Project newProject) {
|
||||
List<Timeline> timelines = timelineService.findAll();
|
||||
Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0);
|
||||
|
||||
for (Deadline deadline : newProject.getDeadlines()
|
||||
.stream()
|
||||
.filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date()))
|
||||
.collect(Collectors.toList())) {
|
||||
Event newEvent = new Event();
|
||||
newEvent.setTitle("Дедлайн проекта");
|
||||
newEvent.setStatus(Event.EventStatus.NEW);
|
||||
newEvent.setExecuteDate(deadline.getDate());
|
||||
newEvent.setCreateDate(new Date());
|
||||
newEvent.setUpdateDate(new Date());
|
||||
newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' проекта '" + newProject.getTitle() + "'");
|
||||
if (newProject.getExecutors() != null) {
|
||||
newEvent.setRecipients(new ArrayList(newProject.getExecutors()));
|
||||
}
|
||||
newEvent.getRecipients().add((User) newProject.getExecutors());
|
||||
newEvent.setProject(newProject);
|
||||
eventRepository.save(newEvent);
|
||||
|
||||
timeline.getEvents().add(newEvent);
|
||||
timelineService.save(timeline);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProjectDeadlines(Project project) {
|
||||
eventRepository.delete(eventRepository.findAllByProject(project));
|
||||
createFromProject(project);
|
||||
}
|
||||
|
||||
public void removeConferencesEvent(Conference conference) {
|
||||
List<Event> eventList = eventRepository.findAllByConference(conference);
|
||||
eventList.forEach(event -> eventRepository.delete(event.getId()));
|
||||
|
Loading…
Reference in New Issue
Block a user