#93 users activity by date
parent
ea0b8fbaad
commit
ed7707c4d8
@ -0,0 +1,80 @@
|
|||||||
|
package ru.ulstu.user.model;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.EnumType;
|
||||||
|
import javax.persistence.Enumerated;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.ManyToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "activity")
|
||||||
|
public class Activity extends BaseEntity {
|
||||||
|
|
||||||
|
public enum ActivityState {
|
||||||
|
TOOK_IN_WORK("Взято в работу"),
|
||||||
|
COMPLETED("Выполнено");
|
||||||
|
|
||||||
|
private String statusName;
|
||||||
|
|
||||||
|
ActivityState(String statusName) {
|
||||||
|
this.statusName = statusName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatusName() {
|
||||||
|
return this.statusName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ManyToOne()
|
||||||
|
@JoinColumn(name = "user_id")
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
@Enumerated(value = EnumType.STRING)
|
||||||
|
@Column(name = "state")
|
||||||
|
private ActivityState activityState;
|
||||||
|
|
||||||
|
public Activity(User user, ActivityState activityState) {
|
||||||
|
this.user = user;
|
||||||
|
this.date = new Date();
|
||||||
|
this.activityState = activityState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Activity() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActivityState getActivityState() {
|
||||||
|
return activityState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivityState(ActivityState activityState) {
|
||||||
|
this.activityState = activityState;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package ru.ulstu.user.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.user.model.Activity;
|
||||||
|
//
|
||||||
|
//import java.util.Date;
|
||||||
|
//import java.util.List;
|
||||||
|
//
|
||||||
|
//public interface ActivityRepository extends JpaRepository<Activity, Integer> {
|
||||||
|
//
|
||||||
|
// @Query("SELECT a FROM Activity a WHERE (:userId IS NULL OR a.user.id = :userId) " +
|
||||||
|
// "AND (CAST(:dateFrom AS date) IS NULL OR :dateFrom < a.date) " +
|
||||||
|
// "AND (CAST(:dateTo AS date) IS NULL OR :dateTo > a.date)")
|
||||||
|
// List<Activity> getByUserAndDateInterval(@Param("userId") Integer userId,
|
||||||
|
// @Param("dateFrom") Date dateFrom,
|
||||||
|
// @Param("dateTo") Date dateTo);
|
||||||
|
//}
|
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||||
|
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
<changeSet author="arefyev" id="20190603_000000-3">
|
||||||
|
<createTable tableName="activity">
|
||||||
|
<column name="id" type="integer"/>
|
||||||
|
<column name="user_id" type="integer"/>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
<column name="date" type="timestamp"/>
|
||||||
|
<column name="state" type="varchar(255)"/>
|
||||||
|
</createTable>
|
||||||
|
<addForeignKeyConstraint baseTableName="activity" baseColumnNames="user_id"
|
||||||
|
constraintName="fk_activity_user" referencedTableName="users"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
Loading…
Reference in New Issue