forked from free-lancers/electricity_bill_calc_service
refactor(time):彻底重构time类型。
This commit is contained in:
@@ -8,10 +8,8 @@ import (
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/tools"
|
||||
"electricity_bill_calc/tools/time"
|
||||
"electricity_bill_calc/types"
|
||||
"fmt"
|
||||
st "time"
|
||||
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
_ "github.com/doug-martin/goqu/v9/dialect/postgres"
|
||||
@@ -33,13 +31,13 @@ var ChargeRepository = &_ChargeRepository{
|
||||
}
|
||||
|
||||
// 分页查询用户的充值记录
|
||||
func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *st.Time, keyword *string) ([]*model.UserChargeDetail, int64, error) {
|
||||
cr.log.Info("查询用户的充值记录。", zap.Timep("beginTime", beginTime), zap.Timep("endTime", endTime), zap.Stringp("keyword", keyword), zap.Uint("page", page))
|
||||
func (cr _ChargeRepository) FindCharges(page uint, beginTime, endTime *types.Date, keyword *string) ([]*model.UserChargeDetail, int64, error) {
|
||||
cr.log.Info("查询用户的充值记录。", logger.DateFieldp("beginTime", beginTime), logger.DateFieldp("endTime", endTime), zap.Stringp("keyword", keyword), zap.Uint("page", page))
|
||||
cacheConditions := []string{
|
||||
fmt.Sprintf("%d", page),
|
||||
tools.DefaultTo(keyword, ""),
|
||||
tools.CondFn(func(t *st.Time) bool { return t != nil }, beginTime, beginTime.Format("2006-01-02"), "UNDEF"),
|
||||
tools.CondFn(func(t *st.Time) bool { return t != nil }, endTime, endTime.Format("2006-01-02"), "UNDEF"),
|
||||
tools.CondFn(func(t *types.Date) bool { return t != nil }, beginTime, beginTime.Format("2006-01-02"), "UNDEF"),
|
||||
tools.CondFn(func(t *types.Date) bool { return t != nil }, endTime, endTime.Format("2006-01-02"), "UNDEF"),
|
||||
}
|
||||
if charges, total, err := cache.RetrievePagedSearch[[]*model.UserChargeDetail]("charges", cacheConditions...); err == nil {
|
||||
cr.log.Info("从缓存中获取用户的充值记录成功。", zap.Int("count", len(*charges)), zap.Int64("total", total))
|
||||
@@ -115,7 +113,7 @@ func (cr _ChargeRepository) CreateChargeRecord(tx pgx.Tx, ctx context.Context, u
|
||||
createQuery, createArgs, _ := cr.ds.
|
||||
Insert(goqu.T("user_charge")).
|
||||
Cols("user_id", "fee", "discount", "amount", "charge_to", "created_at").
|
||||
Vals(goqu.Vals{uid, fee, discount, amount, chargeTo, time.Now()}).
|
||||
Vals(goqu.Vals{uid, fee, discount, amount, chargeTo, types.Now()}).
|
||||
Prepared(true).ToSQL()
|
||||
|
||||
rs, err := tx.Exec(ctx, createQuery, createArgs...)
|
||||
@@ -130,7 +128,7 @@ func (cr _ChargeRepository) CreateChargeRecord(tx pgx.Tx, ctx context.Context, u
|
||||
func (cr _ChargeRepository) CancelCharge(tx pgx.Tx, ctx context.Context, uid string, seq int64) (bool, error) {
|
||||
updateQuerySql, updateArgs, _ := cr.ds.
|
||||
Update(goqu.T("user_charge")).
|
||||
Set(goqu.Record{"cancelled": true, "cancelled_at": time.Now()}).
|
||||
Set(goqu.Record{"cancelled": true, "cancelled_at": types.Now()}).
|
||||
Where(goqu.I("user_id").Eq(uid), goqu.I("seq").Eq(seq)).
|
||||
Prepared(true).ToSQL()
|
||||
|
||||
|
Reference in New Issue
Block a user