作者 yangfu

我把握的统计

... ... @@ -76,3 +76,24 @@ func (this *AchievementController) AchievementDetail() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.AchievementDetail(header, request))
}
//MyGraspStatistic 我把握的统计(按一级分类类型)
// @router /myGraspStatistic [post]
func (this *AchievementController) MyGraspStatistic() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MyGraspStatisticRequest
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(chance.MyGraspStatistic(header, request))
}
... ...
... ... @@ -110,3 +110,17 @@ func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) {
}
return err
}
//获取成果统计
func GetAchievementStatisticByChanceType(uid int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `select a.*,b.name from (
select chance_type_id,count(0) total from achievement where user_company_id =?
group by chance_type_id
)a inner join chance_type b on a.chance_type_id = b.id
order by sort_num`
if _, err = o.Raw(sql, uid).QueryRows(v); err == nil {
return nil
}
return err
}
... ...
... ... @@ -125,3 +125,10 @@ type SourceChanceItemOrm struct {
TemplateId int `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
}
/*MyGraspStatistic */
type MyGraspStatisticRequest struct {
}
type MyGraspStatisticResponse struct {
GraspStatistic interface{} `json:"list"`
}
... ...
... ... @@ -31,6 +31,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"],
beego.ControllerComments{
Method: "MyGraspStatistic",
Router: `/myGraspStatistic`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
beego.ControllerComments{
Method: "AccessToken",
... ...
... ... @@ -191,3 +191,22 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.SourceChance)
return
}
//我把握的统计(按一级分类类型)
func MyGraspStatistic(header *protocol.RequestHeader, request *protocol.MyGraspStatisticRequest) (rsp *protocol.MyGraspStatisticResponse, err error) {
type StatisticItemOrm struct {
Id int `json:"id" orm:"column(chance_type_id)"` //类型
Name string `json:"name" orm:"column(name)"` //总数
Total int `json:"total" orm:"column(total)"`
}
var (
items []StatisticItemOrm
)
if err = models.GetAchievementStatisticByChanceType(header.UserId, &items); err != nil {
log.Error(err)
return
}
rsp = &protocol.MyGraspStatisticResponse{}
rsp.GraspStatistic = items
return
}
... ...