From ff19001f1f0f666d46b49cbaf7edbd004ca3b932 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 11 Jun 2019 22:09:30 +0400 Subject: [PATCH] fix grant doubling cause date comparison --- .../java/ru/ulstu/core/util/DateUtils.java | 2 +- .../ru/ulstu/deadline/model/Deadline.java | 2 +- .../repository/DeadlineRepository.java | 7 +++---- .../ru/ulstu/grant/service/GrantService.java | 5 +++-- .../db/changelog-20190605_000000-schema.xml | 6 ++++++ .../papers/fragments/paperStatusFragment.html | 20 +++++++++---------- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/java/ru/ulstu/core/util/DateUtils.java b/src/main/java/ru/ulstu/core/util/DateUtils.java index 3a38452..bbcc86b 100644 --- a/src/main/java/ru/ulstu/core/util/DateUtils.java +++ b/src/main/java/ru/ulstu/core/util/DateUtils.java @@ -16,7 +16,7 @@ public class DateUtils { public static Date clearTime(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); - calendar.set(Calendar.HOUR, 0); + calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 17287a8..d0564a0 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -20,7 +20,7 @@ public class Deadline extends BaseEntity { private String description; - @Temporal(value = TemporalType.TIMESTAMP) + @Temporal(value = TemporalType.DATE) @DateTimeFormat(pattern = "yyyy-MM-dd") private Date date; diff --git a/src/main/java/ru/ulstu/deadline/repository/DeadlineRepository.java b/src/main/java/ru/ulstu/deadline/repository/DeadlineRepository.java index 3f237e4..652f01d 100644 --- a/src/main/java/ru/ulstu/deadline/repository/DeadlineRepository.java +++ b/src/main/java/ru/ulstu/deadline/repository/DeadlineRepository.java @@ -3,14 +3,13 @@ package ru.ulstu.deadline.repository; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import ru.ulstu.deadline.model.Deadline; import java.util.Date; public interface DeadlineRepository extends JpaRepository { - @Query( - value = "SELECT date FROM Deadline d WHERE (d.grant_id = ?1) AND (d.date = ?2)", - nativeQuery = true) - Date findByGrantIdAndDate(Integer grantId, Date date); + @Query("SELECT d.date FROM Grant g JOIN g.deadlines d WHERE (g.id = :id) AND (d.date = :date)") + Date findByGrantIdAndDate(@Param("id") Integer grantId, @Param("date") Date date); } diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index ea0a454..112e119 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.Errors; +import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileDataDto; @@ -223,8 +224,8 @@ public class GrantService extends BaseService { } private boolean checkSameDeadline(GrantDto grantDto, Integer id) { - Date date = grantDto.getDeadlines().get(0).getDate(); //дата с сайта киас - Date foundGrantDate = deadlineService.findByGrantIdAndDate(id, date); + Date date = DateUtils.clearTime(grantDto.getDeadlines().get(0).getDate()); //дата с сайта киас + Date foundGrantDate = DateUtils.clearTime(deadlineService.findByGrantIdAndDate(id, date)); return foundGrantDate != null && foundGrantDate.compareTo(date) == 0; } diff --git a/src/main/resources/db/changelog-20190605_000000-schema.xml b/src/main/resources/db/changelog-20190605_000000-schema.xml index 2783660..3863268 100644 --- a/src/main/resources/db/changelog-20190605_000000-schema.xml +++ b/src/main/resources/db/changelog-20190605_000000-schema.xml @@ -26,4 +26,10 @@ newDataType="text" schemaName="public"/> + + + diff --git a/src/main/resources/templates/papers/fragments/paperStatusFragment.html b/src/main/resources/templates/papers/fragments/paperStatusFragment.html index a142722..7d9e479 100644 --- a/src/main/resources/templates/papers/fragments/paperStatusFragment.html +++ b/src/main/resources/templates/papers/fragments/paperStatusFragment.html @@ -5,34 +5,34 @@ - +
- +
- +
- +
- +
- +
- +
- +
-
- +
\ No newline at end of file