作者 yangfu

我把握的统计

@@ -76,3 +76,24 @@ func (this *AchievementController) AchievementDetail() { @@ -76,3 +76,24 @@ func (this *AchievementController) AchievementDetail() {
76 header := controllers.GetRequestHeader(this.Ctx) 76 header := controllers.GetRequestHeader(this.Ctx)
77 msg = protocol.NewReturnResponse(chance.AchievementDetail(header, request)) 77 msg = protocol.NewReturnResponse(chance.AchievementDetail(header, request))
78 } 78 }
  79 +
  80 +//MyGraspStatistic 我把握的统计(按一级分类类型)
  81 +// @router /myGraspStatistic [post]
  82 +func (this *AchievementController) MyGraspStatistic() {
  83 + var msg *protocol.ResponseMessage
  84 + defer func() {
  85 + this.Resp(msg)
  86 + }()
  87 + var request *protocol.MyGraspStatisticRequest
  88 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  89 + log.Error(err)
  90 + msg = protocol.BadRequestParam(1)
  91 + return
  92 + }
  93 + if b, m := this.Valid(request); !b {
  94 + msg = m
  95 + return
  96 + }
  97 + header := controllers.GetRequestHeader(this.Ctx)
  98 + msg = protocol.NewReturnResponse(chance.MyGraspStatistic(header, request))
  99 +}
@@ -110,3 +110,17 @@ func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) { @@ -110,3 +110,17 @@ func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) {
110 } 110 }
111 return err 111 return err
112 } 112 }
  113 +
  114 +//获取成果统计
  115 +func GetAchievementStatisticByChanceType(uid int64, v interface{}) (err error) {
  116 + o := orm.NewOrm()
  117 + sql := `select a.*,b.name from (
  118 + select chance_type_id,count(0) total from achievement where user_company_id =?
  119 + group by chance_type_id
  120 + )a inner join chance_type b on a.chance_type_id = b.id
  121 + order by sort_num`
  122 + if _, err = o.Raw(sql, uid).QueryRows(v); err == nil {
  123 + return nil
  124 + }
  125 + return err
  126 +}
@@ -125,3 +125,10 @@ type SourceChanceItemOrm struct { @@ -125,3 +125,10 @@ type SourceChanceItemOrm struct {
125 TemplateId int `orm:"column(audit_template_id)"` 125 TemplateId int `orm:"column(audit_template_id)"`
126 ChanceTypeId int `orm:"column(chance_type_id)"` 126 ChanceTypeId int `orm:"column(chance_type_id)"`
127 } 127 }
  128 +
  129 +/*MyGraspStatistic */
  130 +type MyGraspStatisticRequest struct {
  131 +}
  132 +type MyGraspStatisticResponse struct {
  133 + GraspStatistic interface{} `json:"list"`
  134 +}
@@ -31,6 +31,14 @@ func init() { @@ -31,6 +31,14 @@ func init() {
31 MethodParams: param.Make(), 31 MethodParams: param.Make(),
32 Params: nil}) 32 Params: nil})
33 33
  34 + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"],
  35 + beego.ControllerComments{
  36 + Method: "MyGraspStatistic",
  37 + Router: `/myGraspStatistic`,
  38 + AllowHTTPMethods: []string{"post"},
  39 + MethodParams: param.Make(),
  40 + Params: nil})
  41 +
34 beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], 42 beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
35 beego.ControllerComments{ 43 beego.ControllerComments{
36 Method: "AccessToken", 44 Method: "AccessToken",
@@ -191,3 +191,22 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve @@ -191,3 +191,22 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
191 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.SourceChance) 191 agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.SourceChance)
192 return 192 return
193 } 193 }
  194 +
  195 +//我把握的统计(按一级分类类型)
  196 +func MyGraspStatistic(header *protocol.RequestHeader, request *protocol.MyGraspStatisticRequest) (rsp *protocol.MyGraspStatisticResponse, err error) {
  197 + type StatisticItemOrm struct {
  198 + Id int `json:"id" orm:"column(chance_type_id)"` //类型
  199 + Name string `json:"name" orm:"column(name)"` //总数
  200 + Total int `json:"total" orm:"column(total)"`
  201 + }
  202 + var (
  203 + items []StatisticItemOrm
  204 + )
  205 + if err = models.GetAchievementStatisticByChanceType(header.UserId, &items); err != nil {
  206 + log.Error(err)
  207 + return
  208 + }
  209 + rsp = &protocol.MyGraspStatisticResponse{}
  210 + rsp.GraspStatistic = items
  211 + return
  212 +}