forked from free-lancers/electricity_bill_calc_service
新增:完善withdraw的返回值
This commit is contained in:
184
repository/withdraw.go
Normal file
184
repository/withdraw.go
Normal file
@@ -0,0 +1,184 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"electricity_bill_calc/global"
|
||||
"electricity_bill_calc/logger"
|
||||
"electricity_bill_calc/model"
|
||||
"electricity_bill_calc/tools"
|
||||
"fmt"
|
||||
"github.com/doug-martin/goqu/v9"
|
||||
"github.com/georgysavva/scany/v2/pgxscan"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type _WithdrawRepository struct {
|
||||
log *zap.Logger
|
||||
ds goqu.DialectWrapper
|
||||
}
|
||||
|
||||
var WithdrawRepository = &_WithdrawRepository{
|
||||
log: logger.Named("Repository", "Withdraw"),
|
||||
ds: goqu.Dialect("postgres"),
|
||||
}
|
||||
|
||||
/**
|
||||
* @author: ZiHangQin
|
||||
* 该方法用于分页查询核算报表
|
||||
* @param:page
|
||||
* @param: keyword
|
||||
* @return:[]object
|
||||
* @return:total
|
||||
* @return: error
|
||||
*/
|
||||
func (wd _WithdrawRepository) FindWithdraw(page int, keyword *string) ([]model.Withdraw, int64, error) {
|
||||
wd.log.Info("查询用户的充值记录。", zap.Stringp("keyword", keyword), zap.Int("page", page))
|
||||
ctx, cancel := global.TimeoutContext()
|
||||
defer cancel()
|
||||
fmt.Println(ctx)
|
||||
//TODO: 2023-07-18此处进行用户的核算报表分页查询的sql语句拼接逻辑。
|
||||
//1、SELECT * FROM report WHERE `withdraw` = 1(获取到所有的状态为申请撤回中的报表数据)
|
||||
//
|
||||
//2、循环遍历1中获取的数据{
|
||||
//查询需要的字段"id": "string",
|
||||
// "parkId": "string",
|
||||
// "periodBegin": "string",
|
||||
// "periodEnd": "string",
|
||||
// "published": true,
|
||||
// "publishedAt": "string",
|
||||
// "withdraw": 0,
|
||||
// "lastWithdrawAppliedAt": "string",
|
||||
// "lastWithdrawAuditAt": "string",
|
||||
// "status": 0,
|
||||
// "message": "string"
|
||||
//----report简易核算报表信息获取完成
|
||||
//
|
||||
//3、SELECT * FROM park WHERE `id` = report.park_id(获取园区信息)
|
||||
//查询结果需要的字段 "id": "string",
|
||||
// "userId": "string",
|
||||
// "name": "string",
|
||||
// "tenement": "string",
|
||||
// "area": "string",
|
||||
// "capacity": "string",
|
||||
// "category": 0,
|
||||
// "meter04kvType": 0,
|
||||
// "region": "string",
|
||||
// "address": "string",
|
||||
// "contact": "string",
|
||||
// "phone": "string"
|
||||
//----park简易园区信息货物完成
|
||||
//
|
||||
//4、SELECT * FROM user_detail WHERE `id` = park.user_id(获取用户信息)
|
||||
//查询结果需要的字段 "id": "string",
|
||||
// "name": "string",
|
||||
// "contact": "string",
|
||||
// "phone": "string",
|
||||
// "region": "string",
|
||||
// "address": "string"
|
||||
//----user简易用户信息获取完成
|
||||
//}
|
||||
|
||||
reportQuery, reportQueryArgs, _ := wd.ds.
|
||||
From(goqu.T("report")).
|
||||
Where(goqu.I("withdraw").Eq(1)).
|
||||
Select("*").ToSQL()
|
||||
|
||||
reports := make([]model.Report, 0)
|
||||
|
||||
err := pgxscan.Select(ctx, global.DB, &reports, reportQuery, reportQueryArgs...)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return []model.Withdraw{}, 0, err
|
||||
}
|
||||
fmt.Println("数据库中读取的指定数据:", reports)
|
||||
|
||||
var withdrawReses []model.Withdraw
|
||||
|
||||
for _, v := range reports {
|
||||
lastWithdrawAppliedAtStr := tools.NullTime2PointerString(v.LastWithdrawAppliedAt)
|
||||
lastWithdrawAuditAtStr := tools.NullTime2PointerString(v.LastWithdrawAuditAt)
|
||||
publishAtStr := tools.NullTime2PointerString(v.PublishedAt)
|
||||
|
||||
Begin := v.Period.SafeLower().Format("2006-01-02")
|
||||
End := v.Period.SafeUpper().Format("2006-01-02")
|
||||
var withdrawRes model.Withdraw
|
||||
//构建简易报表信息
|
||||
simplifiedReport := model.SimplifiedReport{
|
||||
ID: v.ID,
|
||||
LastWithdrawAppliedAt: lastWithdrawAppliedAtStr,
|
||||
LastWithdrawAuditAt: lastWithdrawAuditAtStr,
|
||||
Message: nil,
|
||||
ParkID: v.ParkID,
|
||||
PeriodBegin: Begin,
|
||||
PeriodEnd: End,
|
||||
Published: v.Published,
|
||||
PublishedAt: publishAtStr,
|
||||
Status: 0.00,
|
||||
Withdraw: v.Withdraw,
|
||||
}
|
||||
|
||||
parkQuery, parkQueryArgs, _ := wd.ds.
|
||||
From(goqu.T("park")).
|
||||
Where(goqu.I("id").Eq(v.ParkID)).
|
||||
Select("*").ToSQL()
|
||||
|
||||
park := make([]model.Parks, 0)
|
||||
err := pgxscan.Select(ctx, global.DB, &park, parkQuery, parkQueryArgs...)
|
||||
fmt.Println("读到的园区数据:", park)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return []model.Withdraw{}, 0, err
|
||||
}
|
||||
|
||||
areaStr := tools.NullDecimalToString(park[0].Area)
|
||||
capacityStr := tools.NullDecimalToString(park[0].Capacity)
|
||||
TenementQuantityStr := tools.NullDecimalToString(park[0].TenementQuantity)
|
||||
//构建简易园区数据
|
||||
simplifiedPark := model.SimplifiedPark{
|
||||
Address: park[0].Address,
|
||||
Area: areaStr,
|
||||
Capacity: capacityStr,
|
||||
Category: park[0].Category,
|
||||
Contact: park[0].Contact,
|
||||
ID: park[0].Id,
|
||||
Meter04KvType: park[0].MeterType,
|
||||
Name: park[0].Name,
|
||||
Phone: park[0].Phone,
|
||||
Region: park[0].Region,
|
||||
Tenement: TenementQuantityStr,
|
||||
UserID: park[0].UserId,
|
||||
}
|
||||
|
||||
userQuery, userQueryArgs, _ := wd.ds.
|
||||
From(goqu.T("user_detail")).
|
||||
Where(goqu.I("id").Eq(park[0].UserId)).
|
||||
Select("*").ToSQL()
|
||||
|
||||
userInfo := make([]model.UserDetail, 0)
|
||||
|
||||
err = pgxscan.Select(ctx, global.DB, &userInfo, userQuery, userQueryArgs...)
|
||||
fmt.Println("读到的用户数据:", userInfo)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return []model.Withdraw{}, 0, err
|
||||
}
|
||||
|
||||
simplifiedUser := model.UserInfos{
|
||||
Address: userInfo[0].Address,
|
||||
Contact: userInfo[0].Contact,
|
||||
ID: userInfo[0].Id,
|
||||
Name: userInfo[0].Name,
|
||||
Phone: userInfo[0].Phone,
|
||||
Region: userInfo[0].Region,
|
||||
}
|
||||
|
||||
withdrawRes.Report = simplifiedReport
|
||||
withdrawRes.Park = simplifiedPark
|
||||
withdrawRes.User = simplifiedUser
|
||||
|
||||
withdrawReses = append(withdrawReses, withdrawRes)
|
||||
}
|
||||
|
||||
total := len(reports)
|
||||
|
||||
return withdrawReses, int64(total), nil
|
||||
}
|
Reference in New Issue
Block a user