|
@ -2,11 +2,12 @@ package vote_record |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
"fmt" |
|
|
"github.com/gogf/gf/v2/frame/g" |
|
|
"github.com/gogf/gf/v2/frame/g" |
|
|
v1 "practice_ArticleVote_Go/api/vote_record/v1" |
|
|
v1 "practice_ArticleVote_Go/api/vote_record/v1" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func (l *VoteRecordLogic) GetVoteDetail(ctx context.Context, req *v1.GetVoteDetailReq) (res []*v1.GetVoteDetailRes, err error) { |
|
|
|
|
|
|
|
|
func (l *VoteRecordLogic) GetVoteDetail(ctx context.Context, req *v1.GetVoteDetailReq) (res *v1.GetVoteDetailListRes, err error) { |
|
|
//query := `
|
|
|
//query := `
|
|
|
// SELECT
|
|
|
// SELECT
|
|
|
// u.username,
|
|
|
// u.username,
|
|
@ -79,17 +80,23 @@ func (l *VoteRecordLogic) GetVoteDetail(ctx context.Context, req *v1.GetVoteDeta |
|
|
query += " AND u.account LIKE ?" |
|
|
query += " AND u.account LIKE ?" |
|
|
conditions = append(conditions, "%"+req.Account+"%") |
|
|
conditions = append(conditions, "%"+req.Account+"%") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
query += " ORDER BY uv.create_time DESC " |
|
|
|
|
|
query += " LIMIT ?, ? " |
|
|
|
|
|
|
|
|
countQuery := "SELECT COUNT(*) AS cnt FROM ( " + query + " ) AS subquery" |
|
|
|
|
|
var cntResult struct{ Cnt int } |
|
|
|
|
|
err = g.DB().Ctx(ctx).Raw(countQuery, conditions...).Scan(&cntResult) |
|
|
|
|
|
fmt.Println(cntResult.Cnt) |
|
|
|
|
|
res = &v1.GetVoteDetailListRes{ |
|
|
|
|
|
TotalCount: cntResult.Cnt, |
|
|
|
|
|
} |
|
|
|
|
|
query += " ORDER BY uv.create_time DESC LIMIT ?, ?" |
|
|
offset := (req.Page - 1) * req.Size |
|
|
offset := (req.Page - 1) * req.Size |
|
|
conditions = append(conditions, offset, req.Size) |
|
|
conditions = append(conditions, offset, req.Size) |
|
|
|
|
|
|
|
|
|
|
|
var voteList []*v1.GetVoteDetailRes |
|
|
err = g.DB().Ctx(ctx). |
|
|
err = g.DB().Ctx(ctx). |
|
|
Raw(query, conditions...). |
|
|
Raw(query, conditions...). |
|
|
Scan(&res) |
|
|
|
|
|
|
|
|
Scan(&voteList) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|
|
|
res.VoteList = voteList |
|
|
return res, nil |
|
|
return res, nil |
|
|
} |
|
|
} |