transactionModel

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpenseAccumulate

func ExpenseAccumulate(
	tradeTime time.Time, accountId uint, userId uint, categoryId uint, amount int, count int, tx *gorm.DB,
) error

func IncomeAccumulate

func IncomeAccumulate(
	tradeTime time.Time, accountId uint, userId uint, categoryId uint, amount int, count int, tx *gorm.DB,
) error

Types

type CategoryAmountRank

type CategoryAmountRank struct {
	CategoryId uint
	global.AmountCount
}

CategoryAmountRank StatisticDao.GetCategoryAmountRank查询结果

type CategoryAmountRankCondition

type CategoryAmountRankCondition struct {
	Account   accountModel.Account
	StartTime time.Time
	EndTime   time.Time
}

CategoryAmountRankCondition StatisticDao.GetCategoryAmountRank查询条件

func (*CategoryAmountRankCondition) Local

func (c *CategoryAmountRankCondition) Local()

type Condition

Condition 交易记录查询条件 用于交易记录和统计的查询

type DayStatistic

type DayStatistic struct {
	global.AmountCount
	Date time.Time
}

DayStatistic StatisticDao.GetDayStatisticByCondition 方法返回

type ExpenseAccountStatistic

type ExpenseAccountStatistic struct {
	Statistic
	AccountId uint `gorm:"primaryKey"`
}

func (*ExpenseAccountStatistic) Accumulate

func (e *ExpenseAccountStatistic) Accumulate(
	tradeTime time.Time, accountId uint, amount int, count int, tx *gorm.DB,
) error

func (*ExpenseAccountStatistic) TableName

func (i *ExpenseAccountStatistic) TableName() string

type ExpenseAccountUserStatistic

type ExpenseAccountUserStatistic struct {
	Statistic
	AccountId  uint `gorm:"primaryKey"`
	UserId     uint `gorm:"primaryKey"`
	CategoryId uint `gorm:"primaryKey"`
}

func (*ExpenseAccountUserStatistic) Accumulate

func (e *ExpenseAccountUserStatistic) Accumulate(
	tradeTime time.Time, accountId uint, userId uint, categoryId uint, amount int, count int, tx *gorm.DB,
) error

func (*ExpenseAccountUserStatistic) TableName

func (i *ExpenseAccountUserStatistic) TableName() string

type ExpenseCategoryStatistic

type ExpenseCategoryStatistic struct {
	Statistic
	CategoryId uint `gorm:"primaryKey"`
	AccountId  uint //冗余字段
}

func (*ExpenseCategoryStatistic) Accumulate

func (e *ExpenseCategoryStatistic) Accumulate(
	tradeTime time.Time, accountId uint, categoryId uint, amount int, count int, tx *gorm.DB,
) error

func (*ExpenseCategoryStatistic) TableName

func (e *ExpenseCategoryStatistic) TableName() string

type ExtensionCondition

type ExtensionCondition struct {
	MinAmount, MaxAmount *int
}

ExtensionCondition 拓展查询条件 多是无索引条件

func (*ExtensionCondition) IsSet

func (ec *ExtensionCondition) IsSet() bool

type ForeignKeyCondition

type ForeignKeyCondition struct {
	AccountId   uint
	UserIds     *[]uint
	CategoryIds *[]uint
}

ForeignKeyCondition 交易外键查询条件 用于交易记录和统计的查询

func (*ForeignKeyCondition) GetStatisticTableName

func (f *ForeignKeyCondition) GetStatisticTableName(ie constant.IncomeExpense) string

GetStatisticTableName 根据查询条件返回合适的查询表格 gorm的Model方法视乎有问题 只会在第一次执行Model时更新查询的表格 故返回表名而不是模型

type IncomeAccountStatistic

type IncomeAccountStatistic struct {
	Statistic
	AccountId uint `gorm:"primaryKey"`
}

func (*IncomeAccountStatistic) Accumulate

func (i *IncomeAccountStatistic) Accumulate(
	tradeTime time.Time, accountId uint, amount int, count int, tx *gorm.DB,
) error

func (*IncomeAccountStatistic) TableName

func (i *IncomeAccountStatistic) TableName() string

type IncomeAccountUserStatistic

type IncomeAccountUserStatistic struct {
	Statistic
	AccountId  uint `gorm:"primaryKey"`
	UserId     uint `gorm:"primaryKey"`
	CategoryId uint `gorm:"primaryKey"`
}

func (*IncomeAccountUserStatistic) Accumulate

func (i *IncomeAccountUserStatistic) Accumulate(
	tradeTime time.Time, accountId uint, userId uint, categoryId uint, amount int, count int, tx *gorm.DB,
) error

func (*IncomeAccountUserStatistic) TableName

func (i *IncomeAccountUserStatistic) TableName() string

type IncomeCategoryStatistic

type IncomeCategoryStatistic struct {
	CategoryId uint `gorm:"primaryKey"`
	AccountId  uint //冗余字段
	Statistic
}

func (*IncomeCategoryStatistic) Accumulate

func (i *IncomeCategoryStatistic) Accumulate(
	tradeTime time.Time, accountId uint, categoryId uint, amount int, count int, tx *gorm.DB,
) error

func (*IncomeCategoryStatistic) TableName

func (i *IncomeCategoryStatistic) TableName() string

type Info

type Info struct {
	UserId, AccountId, CategoryId uint
	IncomeExpense                 constant.IncomeExpense
	Amount                        int
	Remark                        string
	TradeTime                     time.Time `gorm:"type:TIMESTAMP"`
}

func (*Info) Check

func (i *Info) Check(db *gorm.DB) error

func (*Info) GetAccount

func (t *Info) GetAccount(db ...*gorm.DB) (account accountModel.Account, err error)

func (*Info) GetCategory

func (t *Info) GetCategory(db ...*gorm.DB) (category categoryModel.Category, err error)

func (*Info) GetStatisticData

func (t *Info) GetStatisticData(isAdd bool) StatisticData

func (*Info) GetUser

func (t *Info) GetUser(selects ...interface{}) (user userModel.User, err error)

type Mapping

type Mapping struct {
	ID               uint `gorm:"primarykey"`
	MainId           uint `gorm:"not null;uniqueIndex:idx_mapping,priority:1"`
	MainAccountId    uint `gorm:"not null;"`
	RelatedId        uint `gorm:"not null;"`
	RelatedAccountId uint `gorm:"not null;uniqueIndex:idx_mapping,priority:2"`
	// 上次引起同步的交易更新时间,用来避免错误重试导致旧同步覆盖新同步
	LastSyncedTransUpdateTime time.Time `gorm:"not null;comment:'上次引起同步的交易更新时间'"`
	gorm.Model
}

Mapping MainId - RelatedId unique MainId - RelatedAccountId unique

func (*Mapping) CanSyncTrans

func (m *Mapping) CanSyncTrans(transaction Transaction) bool

func (*Mapping) ForShare

func (m *Mapping) ForShare(tx *gorm.DB) error

func (*Mapping) OnSyncSuccess

func (m *Mapping) OnSyncSuccess(db *gorm.DB, transaction Transaction) error

func (*Mapping) TableName

func (m *Mapping) TableName() string

type RecordType

type RecordType int8
const (
	RecordTypeOfManual RecordType = iota
	RecordTypeOfTiming
	RecordTypeOfSync
	RecordTypeOfImport
)

type Statistic

type Statistic struct {
	Date   time.Time `gorm:"primaryKey;type:TIMESTAMP"`
	Amount int
	Count  int
	commonModel.BaseModel
}

func (*Statistic) GetDate

func (s *Statistic) GetDate(t time.Time) time.Time

func (*Statistic) GetUpdatesValue

func (s *Statistic) GetUpdatesValue(amount, count int) map[string]interface{}

type StatisticCondition

type StatisticCondition struct {
	ForeignKeyCondition
	StartTime time.Time
	EndTime   time.Time
	// contains filtered or unexported fields
}

StatisticCondition 交易的统计查询条件

func (*StatisticCondition) CheckAvailability

func (s *StatisticCondition) CheckAvailability() bool

type StatisticConditionBuilder

type StatisticConditionBuilder struct {
	// contains filtered or unexported fields
}

StatisticConditionBuilder 是用于构建 StatisticCondition 的构建器

func NewStatisticConditionBuilder

func NewStatisticConditionBuilder(accountId uint) *StatisticConditionBuilder

NewStatisticConditionBuilder 返回一个新的 StatisticConditionBuilder 实例

func (*StatisticConditionBuilder) Build

Build 构建 StatisticCondition 实例

func (*StatisticConditionBuilder) WithCategoryIds

func (b *StatisticConditionBuilder) WithCategoryIds(Ids []uint) *StatisticConditionBuilder

WithCategoryIds 设置交易类型ids

func (*StatisticConditionBuilder) WithDate

func (b *StatisticConditionBuilder) WithDate(startTime, endTime time.Time) *StatisticConditionBuilder

WithDate 设置时间范围

func (*StatisticConditionBuilder) WithUserIds

WithUserIds 设置用户ids

type StatisticDao

type StatisticDao struct {
	// contains filtered or unexported fields
}

func NewStatisticDao

func NewStatisticDao(db ...*gorm.DB) *StatisticDao

func (*StatisticDao) GetAmountCountByCondition

func (s *StatisticDao) GetAmountCountByCondition(condition StatisticCondition, ie constant.IncomeExpense) (
	result global.AmountCount, err error,
)

func (*StatisticDao) GetCategoryAmountRank

func (s *StatisticDao) GetCategoryAmountRank(
	ie constant.IncomeExpense, condition CategoryAmountRankCondition, limit *int,
) (result []CategoryAmountRank, err error)

func (*StatisticDao) GetDayStatisticByCondition

func (s *StatisticDao) GetDayStatisticByCondition(
	ie constant.IncomeExpense, condition StatisticCondition,
) (result []DayStatistic, err error)

func (*StatisticDao) GetIeStatisticByCondition

func (s *StatisticDao) GetIeStatisticByCondition(ie *constant.IncomeExpense, condition StatisticCondition) (
	result global.IEStatistic, err error,
)

GetIeStatisticByCondition 查询收支统计 返回 global.IEStatistic

func (*StatisticDao) GetTotalByCondition

func (s *StatisticDao) GetTotalByCondition(
	ie constant.IncomeExpense, condition StatisticCondition,
) (result global.AmountCount, err error)

type StatisticData

type StatisticData struct {
	AccountId     uint
	UserId        uint
	IncomeExpense constant.IncomeExpense
	CategoryId    uint
	TradeTime     time.Time
	Amount        int
	Count         int
	Location      string
}

type TimeCondition

type TimeCondition struct {
	TradeStartTime *time.Time
	TradeEndTime   *time.Time
}

TimeCondition 交易表时间查询条件

func NewTimeCondition

func NewTimeCondition() *TimeCondition

func (*TimeCondition) SetTradeTimes

func (tc *TimeCondition) SetTradeTimes(startTime, endTime time.Time)

type Timing

type Timing struct {
	ID         uint `gorm:"primarykey"`
	AccountId  uint `gorm:"index"`
	UserId     uint
	TransInfo  Info       `gorm:"not null;type:json;serializer:json"`
	Type       TimingType `gorm:"not null;type:char(16)"`
	OffsetDays int        `gorm:"not null;"`
	NextTime   time.Time  `gorm:"not null;"`
	Close      bool
	gorm.Model
}

func (*Timing) ForUpdate

func (t *Timing) ForUpdate(tx *gorm.DB) error

func (*Timing) MakeExecTask

func (t *Timing) MakeExecTask(db *gorm.DB) (TimingExec, error)

func (*Timing) Open

func (t *Timing) Open(tx *gorm.DB) error

func (*Timing) TableName

func (t *Timing) TableName() string

func (*Timing) UpdateNextTime

func (t *Timing) UpdateNextTime(db *gorm.DB) error

type TimingExec

type TimingExec struct {
	ID            uint             `gorm:"primarykey"`
	Status        TimingExecStatus `gorm:"default:0"`
	ConfigId      uint             `gorm:"index;not null"`
	FailCause     string           `gorm:"default:'';not null"`
	TransInfo     Info             `gorm:"not null;type:json;serializer:json"`
	TransactionId uint
	ExecTime      sql.NullTime
	gorm.Model
}

func (*TimingExec) ExecFail

func (t *TimingExec) ExecFail(execErr error, db *gorm.DB) error

func (*TimingExec) ExecSuccess

func (t *TimingExec) ExecSuccess(trans Transaction, db *gorm.DB) error

func (*TimingExec) GetConfig

func (t *TimingExec) GetConfig(db *gorm.DB) (Timing, error)

func (*TimingExec) TableName

func (t *TimingExec) TableName() string

type TimingExecStatus

type TimingExecStatus int8
const (
	TimingExecWait TimingExecStatus = iota * 3
	TimingExecFail
	TimingExecSuccess
)

type TimingType

type TimingType string
const (
	Once           TimingType = "once"
	EveryDay       TimingType = "everyDay"
	EveryWeek      TimingType = "everyWeek"
	EveryMonth     TimingType = "everyMonth"
	LastDayOfMonth TimingType = "lastDayOfMonth"
)

type Transaction

type Transaction struct {
	ID         uint `gorm:"primarykey"`
	RecordType RecordType
	Info
	CreatedAt time.Time      `gorm:"type:TIMESTAMP"`
	UpdatedAt time.Time      `gorm:"type:TIMESTAMP"`
	DeletedAt gorm.DeletedAt `gorm:"index;type:TIMESTAMP"`
	commonModel.BaseModel
}

func (*Transaction) Exits

func (t *Transaction) Exits(query interface{}, args ...interface{}) (bool, error)

func (*Transaction) ForShare

func (t *Transaction) ForShare(tx *gorm.DB) error

func (*Transaction) ForUpdate

func (t *Transaction) ForUpdate(tx *gorm.DB) error

func (*Transaction) SelectById

func (t *Transaction) SelectById(id uint) error

func (*Transaction) SyncDataClone

func (t *Transaction) SyncDataClone() Transaction

type TransactionDao

type TransactionDao struct {
	// contains filtered or unexported fields
}

func NewDao

func NewDao(db ...*gorm.DB) *TransactionDao

func (*TransactionDao) Create

func (t *TransactionDao) Create(info Info, recordType RecordType) (result Transaction, err error)

func (*TransactionDao) GetAmountRank

func (t *TransactionDao) GetAmountRank(
	accountId uint, ie constant.IncomeExpense, timeCond TimeCondition,
) (result []Transaction, err error)

func (*TransactionDao) GetIeStatisticByCondition

func (t *TransactionDao) GetIeStatisticByCondition(
	ie *constant.IncomeExpense, condition StatisticCondition, extCond *ExtensionCondition,
) (result global.IEStatistic, err error)

func (*TransactionDao) GetListByCondition

func (t *TransactionDao) GetListByCondition(condition Condition, offset int, limit int) (
	result []Transaction, err error,
)

func (*TransactionDao) SelectAllTimingAndProcess

func (t *TransactionDao) SelectAllTimingAndProcess(startTime time.Time, process func(timing Timing) error) (err error)

func (*TransactionDao) SelectById

func (t *TransactionDao) SelectById(id uint, forUpdate bool) (result Transaction, err error)

func (*TransactionDao) SelectMappingByTrans

func (t *TransactionDao) SelectMappingByTrans(trans, syncTrans Transaction) (mapping Mapping, err error)

func (*TransactionDao) SelectTimingById

func (t *TransactionDao) SelectTimingById(id uint) (result Timing, err error)

func (*TransactionDao) SelectTimingListByUserId

func (t *TransactionDao) SelectTimingListByUserId(accountId uint, offset int, limit int) (result []Timing, err error)

func (*TransactionDao) SelectWaitTimingExec

func (t *TransactionDao) SelectWaitTimingExec(startId uint, limit int) ([]TimingExec, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL