作者 yangfu

排行榜修改

... ... @@ -117,3 +117,24 @@ func (this *RankController) ComputeRankScore() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(rank.ComputeRankScore(header, request))
}
//GetRankSortItems 获取排行榜评比项
//@router /getRankSortItems [post]
func (this *RankController) GetRankSortItems() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.GetRankSortItemsRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(rank.GetRankSortItems(header, request))
}
... ...
... ... @@ -83,3 +83,12 @@ func GetRankItemKeys(companyId int64, rankTypeId int) (v []string, name []string
}
return
}
func GetRankItems(companyId int64, rankTypeId int, v interface{}) (err error) {
sql := "select item_key,item_name from rank_item where company_id=? and rank_type_id=? order by sort_num"
o := orm.NewOrm()
if _, err = o.Raw(sql, companyId, rankTypeId).QueryRows(v); err != nil {
return
}
return
}
... ...
... ... @@ -20,11 +20,12 @@ const (
/*GetRankList 排行榜*/
type GetRankListRequest struct {
RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜)
RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门)
RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间)
PageIndex int `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页)
PageSize int `json:"pageSize" valid:"Required"` //每页数量
RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜)
RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门)
RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间)
SortItemKeys []string `json:"sortItemKeys" ` //排行项键值列表 valid:"Required"
PageIndex int `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页)
PageSize int `json:"pageSize" valid:"Required"` //每页数量
}
type GetRankListResponse struct {
SortItems []string `json:"sortItems"` //评比项
... ... @@ -84,3 +85,16 @@ type ComputeRankScoreRequest struct {
}
type ComputeRankScoreResponse struct {
}
/*GetRankSortItems */
type GetRankSortItemsRequest struct {
RankTypeId int `json:"rankTypeId" valid:"Required"`
}
type GetRankSortItemsResponse struct {
RankSortItems []RankSortItem `json:"rankSortItems"`
}
type RankSortItem struct {
ItemName string `json:"name" orm:"column(item_name)"`
ItemKey string `json:"key" orm:"column(item_key)"`
}
... ...
... ... @@ -489,6 +489,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankSortItems",
Router: `/getRankSortItems`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"],
beego.ControllerComments{
Method: "GetRankType",
Router: `/getRankTypes`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -25,9 +25,12 @@ func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRe
log.Error(err)
return
}
if itemKeys, itemNames, err = models.GetRankItemKeys(header.CompanyId, request.RankTypeId); err != nil && err != orm.ErrNoRows {
log.Error(err)
return
itemKeys = request.SortItemKeys
if len(itemKeys) == 0 {
if itemKeys, itemNames, err = models.GetRankItemKeys(header.CompanyId, request.RankTypeId); err != nil && err != orm.ErrNoRows {
log.Error(err)
return
}
}
rsp = &protocol.GetRankListResponse{
Self: make([]protocol.RankItem, 0),
... ... @@ -191,6 +194,28 @@ func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPer
return
}
//获取排行榜评比项
func GetRankSortItems(header *protocol.RequestHeader, request *protocol.GetRankSortItemsRequest) (rsp *protocol.GetRankSortItemsResponse, err error) {
var (
sortItems []protocol.RankSortItem
)
rsp = &protocol.GetRankSortItemsResponse{
RankSortItems: make([]protocol.RankSortItem, 0),
}
if err = models.GetRankItems(header.CompanyId, request.RankTypeId, &sortItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
if len(sortItems) > 0 {
rsp.RankSortItems = sortItems
}
return
}
//手动计算排行榜
func ComputeRankScore(header *protocol.RequestHeader, request *protocol.ComputeRankScoreRequest) (rsp *protocol.ComputeRankScoreResponse, err error) {
var ()
... ...