fix grant doubling cause date comparison

This commit is contained in:
Anton Romanov 2019-06-11 22:09:30 +04:00
parent 2012a58fc2
commit ff19001f1f
6 changed files with 24 additions and 18 deletions

View File

@ -16,7 +16,7 @@ public class DateUtils {
public static Date clearTime(Date date) { public static Date clearTime(Date date) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(date); calendar.setTime(date);
calendar.set(Calendar.HOUR, 0); calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0); calendar.set(Calendar.MILLISECOND, 0);

View File

@ -20,7 +20,7 @@ public class Deadline extends BaseEntity {
private String description; private String description;
@Temporal(value = TemporalType.TIMESTAMP) @Temporal(value = TemporalType.DATE)
@DateTimeFormat(pattern = "yyyy-MM-dd") @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date date; private Date date;

View File

@ -3,14 +3,13 @@ package ru.ulstu.deadline.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import java.util.Date; import java.util.Date;
public interface DeadlineRepository extends JpaRepository<Deadline, Integer> { public interface DeadlineRepository extends JpaRepository<Deadline, Integer> {
@Query( @Query("SELECT d.date FROM Grant g JOIN g.deadlines d WHERE (g.id = :id) AND (d.date = :date)")
value = "SELECT date FROM Deadline d WHERE (d.grant_id = ?1) AND (d.date = ?2)", Date findByGrantIdAndDate(@Param("id") Integer grantId, @Param("date") Date date);
nativeQuery = true)
Date findByGrantIdAndDate(Integer grantId, Date date);
} }

View File

@ -6,6 +6,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;
import ru.ulstu.core.util.DateUtils;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileDataDto; import ru.ulstu.file.model.FileDataDto;
@ -223,8 +224,8 @@ public class GrantService extends BaseService {
} }
private boolean checkSameDeadline(GrantDto grantDto, Integer id) { private boolean checkSameDeadline(GrantDto grantDto, Integer id) {
Date date = grantDto.getDeadlines().get(0).getDate(); //дата с сайта киас Date date = DateUtils.clearTime(grantDto.getDeadlines().get(0).getDate()); //дата с сайта киас
Date foundGrantDate = deadlineService.findByGrantIdAndDate(id, date); Date foundGrantDate = DateUtils.clearTime(deadlineService.findByGrantIdAndDate(id, date));
return foundGrantDate != null && foundGrantDate.compareTo(date) == 0; return foundGrantDate != null && foundGrantDate.compareTo(date) == 0;
} }

View File

@ -26,4 +26,10 @@
newDataType="text" newDataType="text"
schemaName="public"/> schemaName="public"/>
</changeSet> </changeSet>
<changeSet author="orion" id="20190525_000000-5">
<modifyDataType tableName="deadline"
columnName="date"
newDataType="date"
schemaName="public"/>
</changeSet>
</databaseChangeLog> </databaseChangeLog>

View File

@ -5,34 +5,34 @@
</head> </head>
<body> <body>
<span th:fragment="paperStatus (paperStatus, title, small)" class="fa-stack fa-1x"> <span th:fragment="paperStatus (paperStatus, title, small)" class="fa-stack fa-1x">
<th:block th:switch="${paperStatus.name()}"> <th:block th:switch="${paperStatus.name()}" >
<div th:case="'ATTENTION'"> <div th:case="'ATTENTION'">
<i class="fa fa-circle text-warning" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-warning" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'DRAFT'"> <div th:case="'DRAFT'">
<i class="fa fa-circle fa-stack-2x text-draft" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-draft" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'ON_PREPARATION'"> <div th:case="'ON_PREPARATION'">
<i class="fa fa-circle fa-stack-2x text-primary" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-primary" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'ON_REVIEW'"> <div th:case="'ON_REVIEW'">
<i class="fa fa-circle fa-stack-2x text-review" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-review" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'COMPLETED'"> <div th:case="'COMPLETED'">
<i class="fa fa-circle fa-stack-2x text-success" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-success" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'FAILED'"> <div th:case="'FAILED'">
<i class="fa fa-circle fa-stack-2x text-failed" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-failed" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'ACCEPTED'"> <div th:case="'ACCEPTED'">
<i class="fa fa-circle fa-stack-2x text-accepted" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> <i class="fa fa-circle text-accepted" th:classappend="${small} ? fa-stack-1x : fa-stack-2x" th:title="${title}"></i>
</div> </div>
<div th:case="'NOT_ACCEPTED'"> <div th:case="'NOT_ACCEPTED'">
<i class="fa fa-circle fa-stack-2x text-not-accepted" <i class="fa fa-circle text-not-accepted"
th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i> th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div> </div>
</th:block> </th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse" th:title="${title}"></i> <i th:if="not ${small}" class="fa fa-file-text-o fa-stack-1x fa-inverse" th:title="${title}"></i>
</span> </span>
</body> </body>
</html> </html>