Commit f485969a authored by jiangpeng's avatar jiangpeng

dapp/vote:add vote status info

parent 5a906fb2
...@@ -68,15 +68,15 @@ func (v *vote) Query_GetVotes(in *vty.ReqStrings) (types.Message, error) { ...@@ -68,15 +68,15 @@ func (v *vote) Query_GetVotes(in *vty.ReqStrings) (types.Message, error) {
if in == nil { if in == nil {
return nil, types.ErrInvalidParam return nil, types.ErrInvalidParam
} }
infos := &vty.VoteInfos{VoteList: make([]*vty.VoteInfo, 0, len(in.GetItems()))} voteList := make([]*vty.VoteInfo, 0, len(in.GetItems()))
for _, id := range in.GetItems() { for _, id := range in.GetItems() {
info, err := v.getVote(id) info, err := v.getVote(id)
if err != nil { if err != nil {
return nil, err return nil, err
} }
infos.VoteList = append(infos.VoteList, info) voteList = append(voteList, info)
} }
return classifyVoteList(infos), nil return classifyVoteList(voteList), nil
} }
...@@ -163,13 +163,13 @@ func (v *vote) Query_ListVote(in *vty.ReqListVote) (types.Message, error) { ...@@ -163,13 +163,13 @@ func (v *vote) Query_ListVote(in *vty.ReqListVote) (types.Message, error) {
return nil, err return nil, err
} }
list := &vty.VoteInfos{VoteList: make([]*vty.VoteInfo, 0, len(rows))} list := make([]*vty.VoteInfo, 0, len(rows))
for _, row := range rows { for _, row := range rows {
info, ok := row.Data.(*vty.VoteInfo) info, ok := row.Data.(*vty.VoteInfo)
if !ok { if !ok {
return nil, types.ErrTypeAsset return nil, types.ErrTypeAsset
} }
list.VoteList = append(list.VoteList, info) list = append(list, info)
} }
return classifyVoteList(list), nil return classifyVoteList(list), nil
......
...@@ -7,8 +7,11 @@ import ( ...@@ -7,8 +7,11 @@ import (
) )
const ( const (
voteStatusNormal = iota voteStatusNormal = iota //非关闭常规状态
voteStatusClosed voteStatusPending //即将开始
voteStatusOngoing //正在进行
voteStatusFinished //已经结束
voteStatusClosed //已经关闭
) )
const ( const (
...@@ -88,22 +91,23 @@ func decodeCommitInfo(data []byte) *vty.CommitInfo { ...@@ -88,22 +91,23 @@ func decodeCommitInfo(data []byte) *vty.CommitInfo {
return info return info
} }
func classifyVoteList(infos *vty.VoteInfos) *vty.ReplyVoteList { func classifyVoteList(voteList []*vty.VoteInfo) *vty.ReplyVoteList {
reply := &vty.ReplyVoteList{} reply := &vty.ReplyVoteList{}
currentTime := types.Now().Unix() currentTime := types.Now().Unix()
for _, voteInfo := range infos.GetVoteList() { for _, voteInfo := range voteList {
if voteInfo.Status == voteStatusClosed { if voteInfo.Status == voteStatusClosed {
reply.ClosedList = append(reply.ClosedList, voteInfo) continue
} else if voteInfo.BeginTimestamp > currentTime { } else if voteInfo.BeginTimestamp > currentTime {
reply.PendingList = append(reply.PendingList, voteInfo) voteInfo.Status = voteStatusPending
} else if voteInfo.EndTimestamp > currentTime { } else if voteInfo.EndTimestamp > currentTime {
reply.OngoingList = append(reply.OngoingList, voteInfo) voteInfo.Status = voteStatusOngoing
} else { } else {
reply.FinishedList = append(reply.FinishedList, voteInfo) voteInfo.Status = voteStatusFinished
} }
} }
reply.CurrentTimestamp = currentTime reply.CurrentTimestamp = currentTime
reply.VoteList = voteList
return reply return reply
} }
...@@ -100,7 +100,7 @@ message VoteInfo { ...@@ -100,7 +100,7 @@ message VoteInfo {
int64 endTimestamp = 7; //投票结束时间戳 int64 endTimestamp = 7; //投票结束时间戳
repeated CommitInfo commitInfos = 8; //已投票的提交信息 repeated CommitInfo commitInfos = 8; //已投票的提交信息
string description = 9; //描述信息 string description = 9; //描述信息
uint32 status = 10; //状态,0正常,1关闭 uint32 status = 10; //状态,1即将开始,2正在进行,3已经结束,4已关闭
} }
message VoteInfos { message VoteInfos {
...@@ -134,9 +134,6 @@ message ReqListVote { ...@@ -134,9 +134,6 @@ message ReqListVote {
} }
message ReplyVoteList { message ReplyVoteList {
repeated VoteInfo pendingList = 1; //即将开始投票列表 repeated VoteInfo voteList = 1; //投票列表
repeated VoteInfo ongoingList = 2; //正在进行投票列表 int64 currentTimestamp = 2; //当前系统时间
repeated VoteInfo finishedList = 3; //已经完成投票列表
repeated VoteInfo closedList = 4; //已经关闭投票列表
int64 currentTimestamp = 5;
} }
...@@ -131,7 +131,7 @@ message VoteInfo { ...@@ -131,7 +131,7 @@ message VoteInfo {
int64 endTimestamp = 7; //投票结束时间戳 int64 endTimestamp = 7; //投票结束时间戳
repeated CommitInfo commitInfos = 8; //已投票的提交信息 repeated CommitInfo commitInfos = 8; //已投票的提交信息
string description = 9; //描述信息 string description = 9; //描述信息
uint32 status = 10; //状态,0正常,1关闭 uint32 status = 10; //状态,1即将开始,2正在进行,3已经结束,4已关闭
} }
//投票选项 //投票选项
...@@ -212,7 +212,7 @@ message VoteInfo { ...@@ -212,7 +212,7 @@ message VoteInfo {
int64 endTimestamp = 7; //投票结束时间戳 int64 endTimestamp = 7; //投票结束时间戳
repeated CommitInfo commitInfos = 8; //已投票的提交信息 repeated CommitInfo commitInfos = 8; //已投票的提交信息
string description = 9; //描述信息 string description = 9; //描述信息
uint32 status = 10; //状态,0正常,1关闭 uint32 status = 10; //状态,1即将开始,2正在进行,3已经结束,4已关闭
} }
``` ```
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment