-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce StatisticValue entity and repository
Added StatisticValue entity to track statistics, including required DDL. Updated StatisticService to handle statistics for created, updated, and deleted time reports. Implemented methods to update or save statistics and ensure persistence in database.
- Loading branch information
1 parent
880dc7f
commit d429bb7
Showing
5 changed files
with
277 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,68 @@ | ||
package org.tb.favorites.domain; | ||
|
||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Lob; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.domain.Persistable; | ||
|
||
@Builder | ||
@Data | ||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
public class Favorite { | ||
@NoArgsConstructor | ||
public class Favorite implements Persistable<Long> { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Setter(PRIVATE) | ||
private Long id; | ||
|
||
private Long employeeId; | ||
|
||
private Long employeeorderId; | ||
|
||
private Integer hours; | ||
|
||
private Integer minutes; | ||
|
||
@Lob | ||
@Column(columnDefinition = "text") | ||
private String comment; | ||
|
||
@Override | ||
public boolean isNew() { | ||
return id == null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if(id == null) return false; | ||
Favorite that = (Favorite) o; | ||
return Objects.equals(id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
if(id == null) return 0; | ||
return Objects.hash(id); | ||
} | ||
|
||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/org/tb/statistic/domain/StatisticValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package org.tb.statistic.domain; | ||
|
||
import static jakarta.persistence.AccessType.FIELD; | ||
import static lombok.AccessLevel.PRIVATE; | ||
|
||
import jakarta.persistence.Access; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Index; | ||
import jakarta.persistence.Table; | ||
import java.time.Duration; | ||
import java.util.Objects; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import org.springframework.data.domain.Persistable; | ||
|
||
@Entity | ||
@Access(FIELD) | ||
@Table(name = "statistic_value", indexes = { | ||
@Index(name = "idx_main", columnList = "category, key, object_id") | ||
}) | ||
@NoArgsConstructor(access = PRIVATE) | ||
public class StatisticValue implements Persistable<Long> { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Getter | ||
private Long id; | ||
|
||
@Getter | ||
private String category; | ||
|
||
@Column(name = "`key`") | ||
@Getter | ||
private String key; | ||
|
||
@Getter | ||
@Column(name = "object_id") | ||
private long objectId; | ||
|
||
@Setter | ||
private long value; | ||
|
||
@Column(length = 4000) | ||
@Getter | ||
@Setter | ||
private String comment; | ||
|
||
public StatisticValue(String category, String key, long objectId, Duration value, String comment) { | ||
this.category = category; | ||
this.key = key; | ||
this.objectId = objectId; | ||
this.comment = comment; | ||
this.value = value.toMinutes(); | ||
} | ||
|
||
public Duration getAsDuration() { | ||
return Duration.ofMinutes(value); | ||
} | ||
|
||
public void setValue(Duration value) { | ||
this.value = value.toMinutes(); | ||
} | ||
|
||
@Override | ||
public boolean isNew() { | ||
return id == null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
if (id == null) { | ||
return false; | ||
} | ||
StatisticValue that = (StatisticValue) o; | ||
return Objects.equals(id, that.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
if (id == null) { | ||
return 0; | ||
} | ||
return Objects.hash(id); | ||
} | ||
|
||
} | ||
|
||
// Corresponding DDL: | ||
|
||
/* | ||
CREATE TABLE statistic_value ( | ||
id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
category VARCHAR(255), | ||
key VARCHAR(255), | ||
object_id BIGINT, | ||
value BIGINT, | ||
comment VARCHAR(4000), | ||
INDEX idx_main (category, key, object_id) | ||
); | ||
*/ |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/tb/statistic/persistence/StatisticValueRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.tb.statistic.persistence; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
import org.tb.statistic.domain.StatisticValue; | ||
|
||
@Repository | ||
public interface StatisticValueRepository extends CrudRepository<StatisticValue, Long> { | ||
|
||
Optional<StatisticValue> findByCategoryAndKeyAndObjectId(String category, String key, long objectId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.