|
@@ -2,18 +2,14 @@ package credit_balance
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
+ "github.com/suyuan32/simple-admin-common/utils/pointy"
|
|
|
"github.com/suyuan32/simple-admin-core/rpc/types/core"
|
|
|
"github.com/zeromicro/go-zero/core/errorx"
|
|
|
- "wechat-api/ent/creditbalance"
|
|
|
- "wechat-api/ent/predicate"
|
|
|
+ "github.com/zeromicro/go-zero/core/logx"
|
|
|
+ "wechat-api/database/dao/wechat/model"
|
|
|
"wechat-api/internal/svc"
|
|
|
"wechat-api/internal/types"
|
|
|
- "wechat-api/internal/utils/dberrorhandler"
|
|
|
-
|
|
|
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
|
|
|
-
|
|
|
- "github.com/suyuan32/simple-admin-common/utils/pointy"
|
|
|
- "github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
|
|
|
|
|
type GetCreditBalanceListLogic struct {
|
|
@@ -36,39 +32,88 @@ func (l *GetCreditBalanceListLogic) GetCreditBalanceList(req *types.CreditBalanc
|
|
|
return nil, errorx.NewInvalidArgumentError("权限不足")
|
|
|
}
|
|
|
|
|
|
- var predicates []predicate.CreditBalance
|
|
|
+ query := l.svcCtx.WechatDB.Find(&model.CreditBalance{})
|
|
|
if req.OrganizationId != nil && *req.OrganizationId > 0 {
|
|
|
- predicates = append(predicates, creditbalance.OrganizationID(*req.OrganizationId))
|
|
|
+ query = query.Where("organization_id = ?", *req.OrganizationId)
|
|
|
+ }
|
|
|
+ creditBalanceList := make([]model.CreditBalance, 0)
|
|
|
+ err := query.Order("created_at DESC").Find(&creditBalanceList).Error
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ l.Logger.Error(err)
|
|
|
+ return nil, errorx.NewInvalidArgumentError("查询列表失败")
|
|
|
}
|
|
|
- data, err := l.svcCtx.DB.CreditBalance.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
|
|
|
|
|
|
+ var count int64
|
|
|
+ err = query.Count(&count).Error
|
|
|
if err != nil {
|
|
|
- return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ l.Logger.Error(err)
|
|
|
+ return nil, errorx.NewInvalidArgumentError("查询个数失败")
|
|
|
}
|
|
|
|
|
|
resp := &types.CreditBalanceListResp{}
|
|
|
resp.Msg = errormsg.Success
|
|
|
- resp.Data.Total = data.PageDetails.Total
|
|
|
+ resp.Data.Total = uint64(count)
|
|
|
|
|
|
- for _, v := range data.List {
|
|
|
- departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: v.OrganizationID})
|
|
|
+ for _, v := range creditBalanceList {
|
|
|
+ departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: uint64(v.OrganizationID)})
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
+ status := int(v.Status)
|
|
|
+ id := uint64(v.ID)
|
|
|
+ balance, _ := v.Balance.Float64()
|
|
|
+ organizationId := uint64(v.OrganizationID)
|
|
|
resp.Data.Data = append(resp.Data.Data,
|
|
|
types.CreditBalanceInfo{
|
|
|
BaseIDInfo: types.BaseIDInfo{
|
|
|
- Id: &v.ID,
|
|
|
+ Id: &id,
|
|
|
CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
|
|
|
UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
|
|
|
},
|
|
|
- Status: &v.Status,
|
|
|
- Balance: &v.Balance,
|
|
|
- OrganizationId: &v.OrganizationID,
|
|
|
+ Status: &status,
|
|
|
+ Balance: &balance,
|
|
|
+ OrganizationId: &organizationId,
|
|
|
OrganizationName: departmentInfo.Name,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
return resp, nil
|
|
|
+
|
|
|
+ //var predicates []predicate.CreditBalance
|
|
|
+ //if req.OrganizationId != nil && *req.OrganizationId > 0 {
|
|
|
+ // predicates = append(predicates, creditbalance.OrganizationID(*req.OrganizationId))
|
|
|
+ //}
|
|
|
+ //data, err := l.svcCtx.DB.CreditBalance.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
|
|
|
+ //
|
|
|
+ //if err != nil {
|
|
|
+ // return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //resp := &types.CreditBalanceListResp{}
|
|
|
+ //resp.Msg = errormsg.Success
|
|
|
+ //resp.Data.Total = data.PageDetails.Total
|
|
|
+ //
|
|
|
+ //for _, v := range data.List {
|
|
|
+ // departmentInfo, err := l.svcCtx.CoreRpc.GetDepartmentById(l.ctx, &core.IDReq{Id: v.OrganizationID})
|
|
|
+ // if err != nil {
|
|
|
+ // return nil, err
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // resp.Data.Data = append(resp.Data.Data,
|
|
|
+ // types.CreditBalanceInfo{
|
|
|
+ // BaseIDInfo: types.BaseIDInfo{
|
|
|
+ // Id: &v.ID,
|
|
|
+ // CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
|
|
|
+ // UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
|
|
|
+ // },
|
|
|
+ // Status: &v.Status,
|
|
|
+ // Balance: &v.Balance,
|
|
|
+ // OrganizationId: &v.OrganizationID,
|
|
|
+ // OrganizationName: departmentInfo.Name,
|
|
|
+ // })
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //return resp, nil
|
|
|
}
|