修改分页检索核算报表一些细节,完成审核撤回报表功能

This commit is contained in:
2023-07-25 15:31:35 +08:00
parent 6fece99e00
commit d8a29e7d17
3 changed files with 134 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ import (
"electricity_bill_calc/logger"
"electricity_bill_calc/model"
"electricity_bill_calc/tools"
"electricity_bill_calc/types"
"fmt"
"github.com/doug-martin/goqu/v9"
"github.com/georgysavva/scany/v2/pgxscan"
@@ -22,17 +23,9 @@ var WithdrawRepository = &_WithdrawRepository{
ds: goqu.Dialect("postgres"),
}
/**
* @author: ZiHangQin
* 该方法用于分页查询核算报表
* @parampage
* @param: keyword
* @return[]object
* @returntotal
* @return: error
*/
//该方法用于分页查询核算报表
func (wd _WithdrawRepository) FindWithdraw(page uint, keyword *string) ([]model.Withdraw, int64, error) {
wd.log.Info("查询用户的充值记录。", zap.Stringp("keyword", keyword), zap.Int("page", int(page)))
wd.log.Info("查询核算报表", zap.Stringp("keyword", keyword), zap.Int("page", int(page)))
ctx, cancel := global.TimeoutContext()
defer cancel()
@@ -66,6 +59,8 @@ func (wd _WithdrawRepository) FindWithdraw(page uint, keyword *string) ([]model.
Where(goqu.I("withdraw").Eq(1)).
Join(goqu.T("park").As("p"), goqu.On(goqu.I("r.park_id").Eq(goqu.I("p.id")))).
Join(goqu.T("user_detail").As("ud"), goqu.On(goqu.I("p.user_id").Eq(goqu.I("ud.id")))).
Where(goqu.I("p.deleted_at").IsNull()).
Where(goqu.I("ud.deleted_at").IsNull()).
Select(
goqu.I("r.id").As("report_id"), goqu.I("r.last_withdraw_applied_at"), goqu.I("r.last_withdraw_audit_at"),
goqu.I("r.park_id").As("report_park_id"), goqu.I("r.period"), goqu.I("r.published"), goqu.I("r.published_at"), goqu.I("r.withdraw"),
@@ -99,7 +94,6 @@ func (wd _WithdrawRepository) FindWithdraw(page uint, keyword *string) ([]model.
countReportQuerySql, countReportQueryArgs, _ := countReportQuery.Prepared(true).ToSQL()
var (
reports []*model.ReportRes = make([]*model.ReportRes, 0)
total int64
@@ -122,9 +116,8 @@ func (wd _WithdrawRepository) FindWithdraw(page uint, keyword *string) ([]model.
return make([]model.Withdraw, 0), total, nil
}
fmt.Println(&reports)
var withdrawReses []model.Withdraw
//TODO: 2023.07.24对查询到的数据进行拼接
//TODO: 2023.07.24对查询到的数据进行拼接(完成)
for _, v := range reports {
Begin := v.Period.SafeLower().Format("2006-01-02")
End := v.Period.SafeUpper().Format("2006-01-02")
@@ -174,3 +167,75 @@ func (wd _WithdrawRepository) FindWithdraw(page uint, keyword *string) ([]model.
return withdrawReses, total, nil
}
//该方法用于审核同意报表撤回
func (wd _WithdrawRepository) ReviewTrueReportWithdraw( rid string) (bool, error) {
wd.log.Info("审核指定的报表", zap.String("rid", rid))
ctx, cancel := global.TimeoutContext()
defer cancel()
//update report set withdraw=$2,
//last_withdraw_audit_at=$3, published=false,
//published_at=null where id=$1
tx, err := global.DB.Begin(ctx)
if err != nil {
wd.log.Error("开启数据库事务失败", zap.Error(err))
}
updateQuerySql, updateArgs, _ := wd.ds.
Update(goqu.T("report")).
Set(goqu.Record{
"withdraw": 3,
"last_withdraw_audit_at": types.Now(),
"published": false,
"published_at": nil,
}).
Where(goqu.I("id").Eq(rid)).
Prepared(true).ToSQL()
rs, err := tx.Exec(ctx, updateQuerySql, updateArgs...)
if err != nil {
wd.log.Error("审核报表失败", zap.Error(err))
return false, err
}
err = tx.Commit(ctx)
if err != nil {
wd.log.Error("提交数据库事务失败", zap.Error(err))
return false, err
}
return rs.RowsAffected() > 0, nil
}
func (wd _WithdrawRepository) ReviewFalseReportWithdraw( rid string) (bool, error) {
wd.log.Info("审核指定的报表", zap.String("rid", rid))
ctx, cancel := global.TimeoutContext()
defer cancel()
tx, err := global.DB.Begin(ctx)
if err != nil {
wd.log.Error("开启数据库事务失败", zap.Error(err))
}
updateQuerySql, updateArgs, _ := wd.ds.
Update(goqu.T("report")).
Set(goqu.Record{
"withdraw": 2,
"last_withdraw_audit_at": types.Now(),
"published": false,
"published_at": nil,
}).
Where(goqu.I("id").Eq(rid)).
Prepared(true).ToSQL()
rs, err := tx.Exec(ctx, updateQuerySql, updateArgs...)
if err != nil {
wd.log.Error("审核报表失败", zap.Error(err))
return false, err
}
err = tx.Commit(ctx)
if err != nil {
wd.log.Error("提交数据库事务失败", zap.Error(err))
return false, err
}
return rs.RowsAffected() > 0, nil
}