23 changed files with 167 additions and 48 deletions
-
19api/vote_record/v1/vote_record.go
-
1api/vote_record/vote_record.go
-
2hack/config.yaml
-
2internal/cmd/cmd.go
-
12internal/controller/vote_record/vote_record_v1_get_export_file.go
-
2internal/dao/internal/article.go
-
8internal/dao/internal/user.go
-
4internal/dao/internal/vote_poll.go
-
10internal/dao/internal/vote_record.go
-
64internal/logic/vote_record/get_export_file.go
-
10internal/logic/vote_record/get_index.go
-
6internal/logic/vote_record/get_vote.go
-
8internal/logic/vote_record/get_vote_detail.go
-
2internal/model/do/article.go
-
7internal/model/do/user.go
-
2internal/model/do/vote_poll.go
-
8internal/model/do/vote_record.go
-
2internal/model/entity/article.go
-
15internal/model/entity/user.go
-
2internal/model/entity/vote_poll.go
-
14internal/model/entity/vote_record.go
-
1internal/service/vote_record.go
-
10manifest/config/config.yaml
@ -0,0 +1,12 @@ |
|||||
|
package vote_record |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"practice_ArticleVote_Go/internal/service" |
||||
|
|
||||
|
"practice_ArticleVote_Go/api/vote_record/v1" |
||||
|
) |
||||
|
|
||||
|
func (c *ControllerV1) GetExportFile(ctx context.Context, req *v1.GetExportFileReq) (res *v1.GetExportFileRes, err error) { |
||||
|
return service.NewVoteRecordService().ExportVoteDetail(ctx, req) |
||||
|
} |
@ -0,0 +1,64 @@ |
|||||
|
package vote_record |
||||
|
|
||||
|
import ( |
||||
|
"context" |
||||
|
"github.com/gogf/gf/v2/frame/g" |
||||
|
v1 "practice_ArticleVote_Go/api/vote_record/v1" |
||||
|
) |
||||
|
|
||||
|
func (l *VoteRecordLogic) ExportVoteDetail(ctx context.Context, req *v1.GetExportFileReq) (res *v1.GetExportFileRes, err error) { |
||||
|
query := ` |
||||
|
SELECT |
||||
|
u.username, |
||||
|
u.account, |
||||
|
u.area, |
||||
|
uv.option_contents, |
||||
|
uv.create_time |
||||
|
FROM ( |
||||
|
SELECT |
||||
|
vr.user_id, |
||||
|
vr.vote_index, |
||||
|
DATE(vr.create_time) AS vote_date, |
||||
|
MAX(vr.create_time) AS create_time, |
||||
|
GROUP_CONCAT(o.option_content ORDER BY o.id SEPARATOR ',') AS option_contents |
||||
|
FROM vote_record vr |
||||
|
JOIN vote_option o |
||||
|
ON vr.option_id = o.id |
||||
|
WHERE vr.vote_id = ? |
||||
|
GROUP BY vr.user_id, vr.vote_index, vote_date |
||||
|
) AS uv |
||||
|
JOIN user u ON u.id = uv.user_id |
||||
|
WHERE 1=1 |
||||
|
` |
||||
|
|
||||
|
conditions := []interface{}{req.VoteId} |
||||
|
|
||||
|
if req.OptionContent != "" { |
||||
|
query += " AND uv.option_contents LIKE ?" |
||||
|
conditions = append(conditions, "%"+req.OptionContent+"%") |
||||
|
} |
||||
|
if req.Username != "" { |
||||
|
query += " AND u.username LIKE ?" |
||||
|
conditions = append(conditions, "%"+req.Username+"%") |
||||
|
} |
||||
|
if req.Account != "" { |
||||
|
query += " AND u.account LIKE ?" |
||||
|
conditions = append(conditions, "%"+req.Account+"%") |
||||
|
} |
||||
|
if req.Area != "" { |
||||
|
query += " AND u.area LIKE ?" |
||||
|
conditions = append(conditions, "%"+req.Area+"%") |
||||
|
} |
||||
|
query += " ORDER BY uv.create_time DESC " |
||||
|
var voteList []*v1.GetVoteDetailRes |
||||
|
err = g.DB().Ctx(ctx). |
||||
|
Raw(query, conditions...). |
||||
|
Scan(&voteList) |
||||
|
if err != nil { |
||||
|
return nil, err |
||||
|
} |
||||
|
res = &v1.GetExportFileRes{ |
||||
|
VoteList: voteList, |
||||
|
} |
||||
|
return res, err |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue