作者 yangfu

排行榜修改

@@ -117,3 +117,24 @@ func (this *RankController) ComputeRankScore() { @@ -117,3 +117,24 @@ func (this *RankController) ComputeRankScore() {
117 header := controllers.GetRequestHeader(this.Ctx) 117 header := controllers.GetRequestHeader(this.Ctx)
118 msg = protocol.NewReturnResponse(rank.ComputeRankScore(header, request)) 118 msg = protocol.NewReturnResponse(rank.ComputeRankScore(header, request))
119 } 119 }
  120 +
  121 +//GetRankSortItems 获取排行榜评比项
  122 +//@router /getRankSortItems [post]
  123 +func (this *RankController) GetRankSortItems() {
  124 + var msg *protocol.ResponseMessage
  125 + defer func() {
  126 + this.Resp(msg)
  127 + }()
  128 + var request *protocol.GetRankSortItemsRequest
  129 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  130 + log.Error(err)
  131 + msg = protocol.BadRequestParam(1)
  132 + return
  133 + }
  134 + if b, m := this.Valid(request); !b {
  135 + msg = m
  136 + return
  137 + }
  138 + header := controllers.GetRequestHeader(this.Ctx)
  139 + msg = protocol.NewReturnResponse(rank.GetRankSortItems(header, request))
  140 +}
@@ -83,3 +83,12 @@ func GetRankItemKeys(companyId int64, rankTypeId int) (v []string, name []string @@ -83,3 +83,12 @@ func GetRankItemKeys(companyId int64, rankTypeId int) (v []string, name []string
83 } 83 }
84 return 84 return
85 } 85 }
  86 +
  87 +func GetRankItems(companyId int64, rankTypeId int, v interface{}) (err error) {
  88 + sql := "select item_key,item_name from rank_item where company_id=? and rank_type_id=? order by sort_num"
  89 + o := orm.NewOrm()
  90 + if _, err = o.Raw(sql, companyId, rankTypeId).QueryRows(v); err != nil {
  91 + return
  92 + }
  93 + return
  94 +}
@@ -20,11 +20,12 @@ const ( @@ -20,11 +20,12 @@ const (
20 20
21 /*GetRankList 排行榜*/ 21 /*GetRankList 排行榜*/
22 type GetRankListRequest struct { 22 type GetRankListRequest struct {
23 - RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜)  
24 - RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门)  
25 - RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间)  
26 - PageIndex int `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页)  
27 - PageSize int `json:"pageSize" valid:"Required"` //每页数量 23 + RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜)
  24 + RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门)
  25 + RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间)
  26 + SortItemKeys []string `json:"sortItemKeys" ` //排行项键值列表 valid:"Required"
  27 + PageIndex int `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页)
  28 + PageSize int `json:"pageSize" valid:"Required"` //每页数量
28 } 29 }
29 type GetRankListResponse struct { 30 type GetRankListResponse struct {
30 SortItems []string `json:"sortItems"` //评比项 31 SortItems []string `json:"sortItems"` //评比项
@@ -84,3 +85,16 @@ type ComputeRankScoreRequest struct { @@ -84,3 +85,16 @@ type ComputeRankScoreRequest struct {
84 } 85 }
85 type ComputeRankScoreResponse struct { 86 type ComputeRankScoreResponse struct {
86 } 87 }
  88 +
  89 +/*GetRankSortItems */
  90 +type GetRankSortItemsRequest struct {
  91 + RankTypeId int `json:"rankTypeId" valid:"Required"`
  92 +}
  93 +type GetRankSortItemsResponse struct {
  94 + RankSortItems []RankSortItem `json:"rankSortItems"`
  95 +}
  96 +
  97 +type RankSortItem struct {
  98 + ItemName string `json:"name" orm:"column(item_name)"`
  99 + ItemKey string `json:"key" orm:"column(item_key)"`
  100 +}
@@ -489,6 +489,14 @@ func init() { @@ -489,6 +489,14 @@ func init() {
489 489
490 beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], 490 beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
491 beego.ControllerComments{ 491 beego.ControllerComments{
  492 + Method: "GetRankSortItems",
  493 + Router: `/getRankSortItems`,
  494 + AllowHTTPMethods: []string{"post"},
  495 + MethodParams: param.Make(),
  496 + Params: nil})
  497 +
  498 + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
  499 + beego.ControllerComments{
492 Method: "GetRankType", 500 Method: "GetRankType",
493 Router: `/getRankTypes`, 501 Router: `/getRankTypes`,
494 AllowHTTPMethods: []string{"post"}, 502 AllowHTTPMethods: []string{"post"},
@@ -25,9 +25,12 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe @@ -25,9 +25,12 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe
25 log.Error(err) 25 log.Error(err)
26 return 26 return
27 } 27 }
28 - if itemKeys, itemNames, err = models.GetRankItemKeys(header.CompanyId, request.RankTypeId); err != nil && err != orm.ErrNoRows {  
29 - log.Error(err)  
30 - return 28 + itemKeys = request.SortItemKeys
  29 + if len(itemKeys) == 0 {
  30 + if itemKeys, itemNames, err = models.GetRankItemKeys(header.CompanyId, request.RankTypeId); err != nil && err != orm.ErrNoRows {
  31 + log.Error(err)
  32 + return
  33 + }
31 } 34 }
32 rsp = &protocol.GetRankListResponse{ 35 rsp = &protocol.GetRankListResponse{
33 Self: make([]protocol.RankItem, 0), 36 Self: make([]protocol.RankItem, 0),
@@ -191,6 +194,28 @@ func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPer @@ -191,6 +194,28 @@ func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPer
191 return 194 return
192 } 195 }
193 196
  197 +//获取排行榜评比项
  198 +func GetRankSortItems(header *protocol.RequestHeader, request *protocol.GetRankSortItemsRequest) (rsp *protocol.GetRankSortItemsResponse, err error) {
  199 + var (
  200 + sortItems []protocol.RankSortItem
  201 + )
  202 + rsp = &protocol.GetRankSortItemsResponse{
  203 + RankSortItems: make([]protocol.RankSortItem, 0),
  204 + }
  205 + if err = models.GetRankItems(header.CompanyId, request.RankTypeId, &sortItems); err != nil {
  206 + if err == orm.ErrNoRows {
  207 + err = nil
  208 + return
  209 + }
  210 + log.Error(err)
  211 + return
  212 + }
  213 + if len(sortItems) > 0 {
  214 + rsp.RankSortItems = sortItems
  215 + }
  216 + return
  217 +}
  218 +
194 //手动计算排行榜 219 //手动计算排行榜
195 func ComputeRankScore(header *protocol.RequestHeader, request *protocol.ComputeRankScoreRequest) (rsp *protocol.ComputeRankScoreResponse, err error) { 220 func ComputeRankScore(header *protocol.RequestHeader, request *protocol.ComputeRankScoreRequest) (rsp *protocol.ComputeRankScoreResponse, err error) {
196 var () 221 var ()