add hs-office-coopshares entity+repository
This commit is contained in:
@ -0,0 +1,73 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
|
||||
import com.vladmihalcea.hibernate.type.basic.PostgreSQLEnumType;
|
||||
import lombok.*;
|
||||
import net.hostsharing.hsadminng.Stringify;
|
||||
import net.hostsharing.hsadminng.Stringifyable;
|
||||
import net.hostsharing.hsadminng.errors.DisplayName;
|
||||
import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.annotations.TypeDef;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.UUID;
|
||||
|
||||
import static net.hostsharing.hsadminng.Stringify.stringify;
|
||||
|
||||
@Entity
|
||||
@Table(name = "hs_office_coopsharestransaction_rv")
|
||||
@TypeDef(
|
||||
name = "pgsql_enum",
|
||||
typeClass = PostgreSQLEnumType.class
|
||||
)
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@DisplayName("CoopShareTransaction")
|
||||
public class HsOfficeCoopSharesTransactionEntity implements Stringifyable {
|
||||
|
||||
private static Stringify<HsOfficeCoopSharesTransactionEntity> stringify = stringify(HsOfficeCoopSharesTransactionEntity.class)
|
||||
.withProp(e -> e.getMembership().getMemberNumber())
|
||||
.withProp(HsOfficeCoopSharesTransactionEntity::getValueDate)
|
||||
.withProp(HsOfficeCoopSharesTransactionEntity::getTransactionType)
|
||||
.withProp(HsOfficeCoopSharesTransactionEntity::getShareCount)
|
||||
.withProp(HsOfficeCoopSharesTransactionEntity::getReference)
|
||||
.withSeparator(", ")
|
||||
.quotedValues(false);
|
||||
|
||||
private @Id UUID uuid;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "membershipuuid")
|
||||
private HsOfficeMembershipEntity membership;
|
||||
|
||||
@Column(name = "transactiontype")
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Type( type = "pgsql_enum" )
|
||||
private HsOfficeCoopSharesTransactionType transactionType;
|
||||
|
||||
@Column(name = "valuedate")
|
||||
private LocalDate valueDate;
|
||||
|
||||
@Column(name = "sharecount")
|
||||
private int shareCount;
|
||||
|
||||
@Column(name = "reference")
|
||||
private String reference;
|
||||
|
||||
@Column(name = "comment")
|
||||
private String comment;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return stringify.apply(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toShortString() {
|
||||
return "%s%+d".formatted(membership.getMemberNumber(), shareCount);
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.Repository;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface HsOfficeCoopSharesTransactionRepository extends Repository<HsOfficeCoopSharesTransactionEntity, UUID> {
|
||||
|
||||
Optional<HsOfficeCoopSharesTransactionEntity> findByUuid(UUID id);
|
||||
|
||||
@Query("""
|
||||
SELECT st FROM HsOfficeCoopSharesTransactionEntity st
|
||||
WHERE (:memberNumber IS NULL OR st.membership.memberNumber = :memberNumber)
|
||||
AND (:fromValueDate IS NULL OR (st.valueDate >= :fromValueDate))
|
||||
AND (:toValueDate IS NULL OR (st.valueDate <= :toValueDate))
|
||||
ORDER BY st.membership.memberNumber, st.valueDate
|
||||
""")
|
||||
List<HsOfficeCoopSharesTransactionEntity> findCoopSharesTransactionByOptionalMembershipUuidAndDateRange(
|
||||
Integer memberNumber, LocalDate fromValueDate, LocalDate toValueDate);
|
||||
|
||||
HsOfficeCoopSharesTransactionEntity save(final HsOfficeCoopSharesTransactionEntity entity);
|
||||
|
||||
long count();
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package net.hostsharing.hsadminng.hs.office.coopshares;
|
||||
|
||||
public enum HsOfficeCoopSharesTransactionType {
|
||||
ADJUSTMENT, SUBSCRIPTION, CANCELLATION;
|
||||
}
|
Reference in New Issue
Block a user