Documentation ¶
Index ¶
- func ExpenseAccumulate(tradeTime time.Time, accountId uint, userId uint, categoryId uint, amount int, ...) error
- func IncomeAccumulate(tradeTime time.Time, accountId uint, userId uint, categoryId uint, amount int, ...) error
- type CategoryAmountRank
- type CategoryAmountRankCondition
- type Condition
- type DayStatistic
- type ExpenseAccountStatistic
- type ExpenseAccountUserStatistic
- type ExpenseCategoryStatistic
- type ExtensionCondition
- type ForeignKeyCondition
- type IncomeAccountStatistic
- type IncomeAccountUserStatistic
- type IncomeCategoryStatistic
- type Info
- func (i *Info) Check(db *gorm.DB) error
- func (t *Info) GetAccount(db ...*gorm.DB) (account accountModel.Account, err error)
- func (t *Info) GetCategory(db ...*gorm.DB) (category categoryModel.Category, err error)
- func (t *Info) GetStatisticData(isAdd bool) StatisticData
- func (t *Info) GetUser(selects ...interface{}) (user userModel.User, err error)
- type Mapping
- type RecordType
- type Statistic
- type StatisticCondition
- type StatisticConditionBuilder
- func (b *StatisticConditionBuilder) Build() *StatisticCondition
- func (b *StatisticConditionBuilder) WithCategoryIds(Ids []uint) *StatisticConditionBuilder
- func (b *StatisticConditionBuilder) WithDate(startTime, endTime time.Time) *StatisticConditionBuilder
- func (b *StatisticConditionBuilder) WithUserIds(Ids []uint) *StatisticConditionBuilder
- type StatisticDao
- func (s *StatisticDao) GetAmountCountByCondition(condition StatisticCondition, ie constant.IncomeExpense) (result global.AmountCount, err error)
- func (s *StatisticDao) GetCategoryAmountRank(ie constant.IncomeExpense, condition CategoryAmountRankCondition, limit *int) (result []CategoryAmountRank, err error)
- func (s *StatisticDao) GetDayStatisticByCondition(ie constant.IncomeExpense, condition StatisticCondition) (result []DayStatistic, err error)
- func (s *StatisticDao) GetIeStatisticByCondition(ie *constant.IncomeExpense, condition StatisticCondition) (result global.IEStatistic, err error)
- func (s *StatisticDao) GetTotalByCondition(ie constant.IncomeExpense, condition StatisticCondition) (result global.AmountCount, err error)
- type StatisticData
- type TimeCondition
- type Timing
- type TimingExec
- type TimingExecStatus
- type TimingType
- type Transaction
- type TransactionDao
- func (t *TransactionDao) Create(info Info, recordType RecordType) (result Transaction, err error)
- func (t *TransactionDao) GetAmountRank(accountId uint, ie constant.IncomeExpense, timeCond TimeCondition) (result []Transaction, err error)
- func (t *TransactionDao) GetIeStatisticByCondition(ie *constant.IncomeExpense, condition StatisticCondition, ...) (result global.IEStatistic, err error)
- func (t *TransactionDao) GetListByCondition(condition Condition, offset int, limit int) (result []Transaction, err error)
- func (t *TransactionDao) SelectAllTimingAndProcess(startTime time.Time, process func(timing Timing) error) (err error)
- func (t *TransactionDao) SelectById(id uint, forUpdate bool) (result Transaction, err error)
- func (t *TransactionDao) SelectMappingByTrans(trans, syncTrans Transaction) (mapping Mapping, err error)
- func (t *TransactionDao) SelectTimingById(id uint) (result Timing, err error)
- func (t *TransactionDao) SelectTimingListByUserId(accountId uint, offset int, limit int) (result []Timing, err error)
- func (t *TransactionDao) SelectWaitTimingExec(startId uint, limit int) ([]TimingExec, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExpenseAccumulate ¶
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 ¶
type Condition struct { IncomeExpense *constant.IncomeExpense ForeignKeyCondition TimeCondition ExtensionCondition }
Condition 交易记录查询条件 用于交易记录和统计的查询
type DayStatistic ¶
type DayStatistic struct { global.AmountCount Date time.Time }
DayStatistic StatisticDao.GetDayStatisticByCondition 方法返回
type ExpenseAccountStatistic ¶
func (*ExpenseAccountStatistic) Accumulate ¶
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 (*ExpenseAccountUserStatistic) TableName ¶
func (i *ExpenseAccountUserStatistic) TableName() string
type ExpenseCategoryStatistic ¶
type ExpenseCategoryStatistic struct { Statistic CategoryId uint `gorm:"primaryKey"` AccountId uint //冗余字段 }
func (*ExpenseCategoryStatistic) Accumulate ¶
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 ¶
ForeignKeyCondition 交易外键查询条件 用于交易记录和统计的查询
func (*ForeignKeyCondition) GetStatisticTableName ¶
func (f *ForeignKeyCondition) GetStatisticTableName(ie constant.IncomeExpense) string
GetStatisticTableName 根据查询条件返回合适的查询表格 gorm的Model方法视乎有问题 只会在第一次执行Model时更新查询的表格 故返回表名而不是模型
type IncomeAccountStatistic ¶
func (*IncomeAccountStatistic) Accumulate ¶
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 (*IncomeAccountUserStatistic) TableName ¶
func (i *IncomeAccountUserStatistic) TableName() string
type IncomeCategoryStatistic ¶
type IncomeCategoryStatistic struct { CategoryId uint `gorm:"primaryKey"` AccountId uint //冗余字段 Statistic }
func (*IncomeCategoryStatistic) Accumulate ¶
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) GetAccount ¶
func (*Info) GetCategory ¶
func (*Info) GetStatisticData ¶
func (t *Info) GetStatisticData(isAdd bool) StatisticData
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) OnSyncSuccess ¶
func (m *Mapping) OnSyncSuccess(db *gorm.DB, transaction Transaction) error
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) GetUpdatesValue ¶
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 ¶
func (b *StatisticConditionBuilder) Build() *StatisticCondition
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 ¶
func (b *StatisticConditionBuilder) WithUserIds(Ids []uint) *StatisticConditionBuilder
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 TimeCondition ¶
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) MakeExecTask ¶
func (t *Timing) MakeExecTask(db *gorm.DB) (TimingExec, 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) ExecSuccess ¶
func (t *TimingExec) ExecSuccess(trans Transaction, db *gorm.DB) 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) 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 (*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 (*TransactionDao) SelectWaitTimingExec ¶
func (t *TransactionDao) SelectWaitTimingExec(startId uint, limit int) ([]TimingExec, error)