Merge branch 'master' into god-mode

This commit is contained in:
徐涛
2022-09-06 16:08:45 +08:00
15 changed files with 157 additions and 126 deletions

View File

@@ -205,7 +205,7 @@ func (_ChargeService) ListPagedChargeRecord(keyword, beginDate, endDate string,
total int64
err error
)
if cachedTotal, _ := cache.RetreiveCount("charge_with_name", condition...); cachedTotal != -1 {
if cachedTotal, err := cache.RetreiveCount("charge_with_name", condition...); cachedTotal != -1 && err == nil {
total = cachedTotal
} else {
total, err = global.DBConn.

View File

@@ -45,7 +45,7 @@ func (_EndUserService) SearchEndUserRecord(reportId, keyword string, page int) (
total int64
err error
)
if cachedTotal, _ := cache.RetreiveCount("end_user_detail", conditions...); cachedTotal != -1 {
if cachedTotal, err := cache.RetreiveCount("end_user_detail", conditions...); cachedTotal != -1 && err == nil {
total = cachedTotal
} else {
total, err = global.DBConn.

View File

@@ -36,7 +36,7 @@ func (_Meter04kVService) ListMeterDetail(park, keyword string, page int) ([]mode
total int64
err error
)
if cachedTotal, _ := cache.RetreiveCount("meter_04kv", condition...); cachedTotal != -1 {
if cachedTotal, err := cache.RetreiveCount("meter_04kv", condition...); cachedTotal != -1 && err == nil {
total = cachedTotal
} else {
total, err = global.DBConn.Where(cond).NoAutoCondition().Count(new(model.Meter04KV))

View File

@@ -73,19 +73,29 @@ func (_ParkService) DeletePark(uid, pid string) error {
return nil
}
func (_ParkService) ListAllParkBelongsTo(uid string) ([]model.Park, error) {
if parks, _ := cache.RetreiveSearch[[]model.Park]("park", "belong", uid); parks != nil {
func (_ParkService) ListAllParkBelongsTo(uid, keyword string) ([]model.Park, error) {
if parks, _ := cache.RetreiveSearch[[]model.Park]("park", "belong", uid, keyword); parks != nil {
return *parks, nil
}
cond := builder.NewCond().And(builder.Eq{"user_id": uid})
if len(keyword) > 0 {
cond = cond.And(
builder.Like{"name", keyword}.
Or(builder.Like{"abbr", keyword}).
Or(builder.Like{"address", keyword}).
Or(builder.Like{"contact", keyword}).
Or(builder.Like{"phone", keyword}),
)
}
parks := make([]model.Park, 0)
err := global.DBConn.
Where(builder.Eq{"user_id": uid}).
Where(cond).
NoAutoCondition().
Find(&parks)
if err != nil {
return make([]model.Park, 0), err
}
cache.CacheSearch(parks, []string{"park"}, "park", "belong", uid)
cache.CacheSearch(parks, []string{"park"}, "park", "belong", uid, keyword)
return parks, nil
}

View File

@@ -299,7 +299,7 @@ func (_ReportService) CalculateSummaryAndFinishStep(reportId string) error {
}
defer tx.Close()
summary.CalculatePrices()
_, err = tx.ID(summary.ReportId).Cols("overall_price", "critical_price", "peak_price", "flat", "flat_fee", "flat_price", "valley_price").Update(summary)
_, err = tx.ID(summary.ReportId).Cols("overall_price", "critical_price", "peak_price", "flat", "flat_fee", "flat_price", "valley_price", "consumption_fee").Update(summary)
if err != nil {
tx.Rollback()
return err
@@ -461,7 +461,7 @@ func (_ReportService) SearchReport(requestUser, requestPark, requestKeyword stri
total int64
err error
)
if cachedTotal, _ := cache.RetreiveCount("join_report_for_withdraw", conditions...); cachedTotal != -1 {
if cachedTotal, err := cache.RetreiveCount("join_report_for_withdraw", conditions...); cachedTotal != -1 && err == nil {
total = cachedTotal
} else {
total, err := global.DBConn.

View File

@@ -14,7 +14,7 @@ type _StatisticsService struct{}
var StatisticsService _StatisticsService
func (_StatisticsService) EnabledEnterprises() (int64, error) {
if cachedCount, _ := cache.RetreiveCount("enabled_ent"); cachedCount != -1 {
if cachedCount, err := cache.RetreiveCount("enabled_ent"); cachedCount != -1 && err == nil {
return cachedCount, nil
}
c, err := global.DBConn.
@@ -28,7 +28,7 @@ func (_StatisticsService) EnabledEnterprises() (int64, error) {
}
func (_StatisticsService) EnabledParks(userIds ...string) (int64, error) {
if cachedParks, _ := cache.RetreiveCount("enabled_parks", userIds...); cachedParks != -1 {
if cachedParks, err := cache.RetreiveCount("enabled_parks", userIds...); cachedParks != -1 && err == nil {
return cachedParks, nil
}
cond := builder.NewCond().And(builder.Eq{"enabled": true})

View File

@@ -342,7 +342,7 @@ func (_UserService) ListUserDetail(keyword string, userType int, userState *bool
total int64
err error
)
if cacheCounts, _ := cache.RetreiveCount("join_user_detail", cacheConditions...); cacheCounts != -1 {
if cacheCounts, err := cache.RetreiveCount("join_user_detail", cacheConditions...); cacheCounts != -1 && err == nil {
total = cacheCounts
} else {
total, err = global.DBConn.

View File

@@ -85,7 +85,7 @@ func (_WithdrawService) FetchPagedWithdrawApplies(page int, keyword string) ([]m
total int64
err error
)
if cachedTotal, _ := cache.RetreiveCount("join_report_for_withdraw", conditions...); cachedTotal != -1 {
if cachedTotal, err := cache.RetreiveCount("join_report_for_withdraw", conditions...); cachedTotal != -1 && err == nil {
total = cachedTotal
} else {
total, err = global.DBConn.
@@ -134,7 +134,7 @@ func (_WithdrawService) AuditWithdraw(reportId string, granted bool) error {
}
func (_WithdrawService) AuditWaits() (int64, error) {
if cachedWaits, _ := cache.RetreiveCount("withdraw_waits"); cachedWaits != -1 {
if cachedWaits, err := cache.RetreiveCount("withdraw_waits"); cachedWaits != -1 && err == nil {
return cachedWaits, nil
}
cond := builder.NewCond()