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) {
if in == nil {
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() {
info, err := v.getVote(id)
if err != nil {
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) {
return nil, err
}
list := &vty.VoteInfos{VoteList: make([]*vty.VoteInfo, 0, len(rows))}
list := make([]*vty.VoteInfo, 0, len(rows))
for _, row := range rows {
info, ok := row.Data.(*vty.VoteInfo)
if !ok {
return nil, types.ErrTypeAsset
}
list.VoteList = append(list.VoteList, info)
list = append(list, info)
}
return classifyVoteList(list), nil
......
......@@ -7,8 +7,11 @@ import (
)
const (
voteStatusNormal = iota
voteStatusClosed
voteStatusNormal = iota //非关闭常规状态
voteStatusPending //即将开始
voteStatusOngoing //正在进行
voteStatusFinished //已经结束
voteStatusClosed //已经关闭
)
const (
......@@ -88,22 +91,23 @@ func decodeCommitInfo(data []byte) *vty.CommitInfo {
return info
}
func classifyVoteList(infos *vty.VoteInfos) *vty.ReplyVoteList {
func classifyVoteList(voteList []*vty.VoteInfo) *vty.ReplyVoteList {
reply := &vty.ReplyVoteList{}
currentTime := types.Now().Unix()
for _, voteInfo := range infos.GetVoteList() {
for _, voteInfo := range voteList {
if voteInfo.Status == voteStatusClosed {
reply.ClosedList = append(reply.ClosedList, voteInfo)
continue
} else if voteInfo.BeginTimestamp > currentTime {
reply.PendingList = append(reply.PendingList, voteInfo)
voteInfo.Status = voteStatusPending
} else if voteInfo.EndTimestamp > currentTime {
reply.OngoingList = append(reply.OngoingList, voteInfo)
voteInfo.Status = voteStatusOngoing
} else {
reply.FinishedList = append(reply.FinishedList, voteInfo)
voteInfo.Status = voteStatusFinished
}
}
reply.CurrentTimestamp = currentTime
reply.VoteList = voteList
return reply
}
......@@ -100,7 +100,7 @@ message VoteInfo {
int64 endTimestamp = 7; //投票结束时间戳
repeated CommitInfo commitInfos = 8; //已投票的提交信息
string description = 9; //描述信息
uint32 status = 10; //状态,0正常,1关闭
uint32 status = 10; //状态,1即将开始,2正在进行,3已经结束,4已关闭
}
message VoteInfos {
......@@ -134,9 +134,6 @@ message ReqListVote {
}
message ReplyVoteList {
repeated VoteInfo pendingList = 1; //即将开始投票列表
repeated VoteInfo ongoingList = 2; //正在进行投票列表
repeated VoteInfo finishedList = 3; //已经完成投票列表
repeated VoteInfo closedList = 4; //已经关闭投票列表
int64 currentTimestamp = 5;
repeated VoteInfo voteList = 1; //投票列表
int64 currentTimestamp = 2; //当前系统时间
}
......@@ -131,7 +131,7 @@ message VoteInfo {
int64 endTimestamp = 7; //投票结束时间戳
repeated CommitInfo commitInfos = 8; //已投票的提交信息
string description = 9; //描述信息
uint32 status = 10; //状态,0正常,1关闭
uint32 status = 10; //状态,1即将开始,2正在进行,3已经结束,4已关闭
}
//投票选项
......@@ -212,7 +212,7 @@ message VoteInfo {
int64 endTimestamp = 7; //投票结束时间戳
repeated CommitInfo commitInfos = 8; //已投票的提交信息
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