作者 yangfu

我把握的成果,机会成果,成果详情

  1 +package v1
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  7 + "opp/controllers"
  8 + "opp/protocol"
  9 + "opp/services/chance"
  10 +)
  11 +
  12 +//成果
  13 +type AchievementController struct {
  14 + controllers.BaseController
  15 +}
  16 +
  17 +//AchievementPool 成果池
  18 +// @router /achievementPool [post]
  19 +func (this *AchievementController) AchievementPool() {
  20 + var msg *protocol.ResponseMessage
  21 + defer func() {
  22 + this.Resp(msg)
  23 + }()
  24 + var request *protocol.AchievementPoolRequest
  25 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  26 + log.Error(err)
  27 + msg = protocol.BadRequestParam(1)
  28 + return
  29 + }
  30 + if b, m := this.Valid(request); !b {
  31 + msg = m
  32 + return
  33 + }
  34 + header := controllers.GetRequestHeader(this.Ctx)
  35 + msg = protocol.NewReturnResponse(chance.AchievementPool(header, request))
  36 +}
  37 +
  38 +//MyGrasp 我把握的
  39 +// @router /myGrasp [post]
  40 +func (this *AchievementController) MyGrasp() {
  41 + var msg *protocol.ResponseMessage
  42 + defer func() {
  43 + this.Resp(msg)
  44 + }()
  45 + var request *protocol.MyGraspRequest
  46 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  47 + log.Error(err)
  48 + msg = protocol.BadRequestParam(1)
  49 + return
  50 + }
  51 + if b, m := this.Valid(request); !b {
  52 + msg = m
  53 + return
  54 + }
  55 + header := controllers.GetRequestHeader(this.Ctx)
  56 + msg = protocol.NewReturnResponse(chance.MyGrasp(header, request))
  57 +}
  58 +
  59 +//AchievementDetail 成果详情
  60 +// @router /achievementDetail [post]
  61 +func (this *AchievementController) AchievementDetail() {
  62 + var msg *protocol.ResponseMessage
  63 + defer func() {
  64 + this.Resp(msg)
  65 + }()
  66 + var request *protocol.AchievementDetailRequest
  67 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  68 + log.Error(err)
  69 + msg = protocol.BadRequestParam(1)
  70 + return
  71 + }
  72 + if b, m := this.Valid(request); !b {
  73 + msg = m
  74 + return
  75 + }
  76 + header := controllers.GetRequestHeader(this.Ctx)
  77 + msg = protocol.NewReturnResponse(chance.AchievementDetail(header, request))
  78 +}
  1 +package models
  2 +
  3 +import (
  4 + "bytes"
  5 + "fmt"
  6 + "opp/internal/utils"
  7 + "time"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type Achievement struct {
  13 + Id int64 `orm:"column(id);pk" description:"id 主键"`
  14 + CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"`
  15 + UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"`
  16 + ChanceTypeId int `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "`
  17 + AuditTemplateId int `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"`
  18 + SourceContent string `orm:"column(source_content);null" description:"成果详情文本"`
  19 + GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"`
  20 + UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"`
  21 + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
  22 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  23 + ViewTotal int `orm:"column(view_total);null" description:"查看总数"`
  24 + CommentTotal int `orm:"column(comment_total);null" description:"评论总数"`
  25 + ZanTotal int `orm:"column(zan_total);null" description:"点赞总数"`
  26 + Status int8 `orm:"column(status);null" description:"机会状态 1:开启 2:关闭 0:删除"`
  27 +}
  28 +
  29 +func (t *Achievement) TableName() string {
  30 + return "new_achievement"
  31 +}
  32 +
  33 +func init() {
  34 + orm.RegisterModel(new(Achievement))
  35 +}
  36 +
  37 +// GetAchievementById retrieves Achievement by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetAchievementById(id int64) (v *Achievement, err error) {
  40 + o := orm.NewOrm()
  41 + v = &Achievement{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// UpdateAchievement updates Achievement by Id and returns error if
  49 +// the record to be updated doesn't exist
  50 +func UpdateAchievementById(m *Achievement) (err error) {
  51 + o := orm.NewOrm()
  52 + v := Achievement{Id: m.Id}
  53 + // ascertain id exists in the database
  54 + if err = o.Read(&v); err == nil {
  55 + var num int64
  56 + if num, err = o.Update(m); err == nil {
  57 + fmt.Println("Number of records updated in database:", num)
  58 + }
  59 + }
  60 + return
  61 +}
  62 +
  63 +//成果列表
  64 +//@uid 成果把握人
  65 +//@cid 公司编号
  66 +//@lastId 最后编号
  67 +//@chanceTypeId 机会一级分类编号
  68 +//@departmentId 部门编号
  69 +func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId int, pageSize int, v interface{}) (total int, err error) {
  70 + var whereString bytes.Buffer
  71 + if departmentId > 0 {
  72 +
  73 + }
  74 + if uid > 0 {
  75 + whereString.WriteString(fmt.Sprintf(` and user_company_id=%v `, uid))
  76 + }
  77 + sql := fmt.Sprintf(`
  78 +select id,user_company_id,create_at,source_content,audit_template_id,chance_type_id,grasp_score,user_grasp_score,comment_total,zan_total,view_total,images from new_achievement
  79 +where company_id=%v and (%v=0 or id<%v) and (%v=0 or chance_type_id =%v) and status=1 %v
  80 +order by create_at desc
  81 +limit %v
  82 +`, cid, lastId, lastId, chanceTypeId, chanceTypeId, whereString.String(), pageSize)
  83 +
  84 + sqlCount := fmt.Sprintf(`
  85 +select count(0) from new_achievement
  86 +where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v
  87 +`, cid, chanceTypeId, chanceTypeId, whereString.String())
  88 +
  89 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  90 + return
  91 + }
  92 + if v != nil {
  93 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  94 + return
  95 + }
  96 + }
  97 + return
  98 +}
  99 +
  100 +//成果详情
  101 +func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) {
  102 + o := orm.NewOrm()
  103 + sql := "select * from new_achievement where id=?"
  104 + if _, err = o.Raw(sql, id).QueryRows(v); err == nil {
  105 + return nil
  106 + }
  107 + return err
  108 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "github.com/astaxie/beego/orm"
  7 +)
  8 +
  9 +type AchievementChance struct {
  10 + Id int64 `orm:"column(id);pk"`
  11 + AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"`
  12 + ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"`
  13 + ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"`
  14 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  15 +}
  16 +
  17 +func (t *AchievementChance) TableName() string {
  18 + return "new_achievement_chance"
  19 +}
  20 +
  21 +func init() {
  22 + orm.RegisterModel(new(AchievementChance))
  23 +}
  24 +
  25 +// GetAchievementChanceById retrieves AchievementChance by Id. Returns error if
  26 +// Id doesn't exist
  27 +func GetAchievementChanceById(id int64) (v *AchievementChance, err error) {
  28 + o := orm.NewOrm()
  29 + v = &AchievementChance{Id: id}
  30 + if err = o.Read(v); err == nil {
  31 + return v, nil
  32 + }
  33 + return nil, err
  34 +}
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "github.com/astaxie/beego/orm"
  7 +)
  8 +
  9 +type AchievementProvider struct {
  10 + Id int64 `orm:"column(id);pk" description:"主键id"`
  11 + AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"`
  12 + UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"`
  13 + UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"`
  14 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
  15 +}
  16 +
  17 +func (t *AchievementProvider) TableName() string {
  18 + return "new_achievement_provider"
  19 +}
  20 +
  21 +func init() {
  22 + orm.RegisterModel(new(AchievementProvider))
  23 +}
  24 +
  25 +// GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if
  26 +// Id doesn't exist
  27 +func GetAchievementProviderById(id int64) (v *AchievementProvider, err error) {
  28 + o := orm.NewOrm()
  29 + v = &AchievementProvider{Id: id}
  30 + if err = o.Read(v); err == nil {
  31 + return v, nil
  32 + }
  33 + return nil, err
  34 +}
  35 +
  36 +//查询成果提供者列表
  37 +func GetAchievementProviders(achievementId int64) (v []*AchievementProvider, err error) {
  38 + o := orm.NewOrm()
  39 + sql := "select * from new_achievement_provider where achievement_id=?"
  40 + if _, err = o.Raw(sql, achievementId).QueryRows(&v); err == nil {
  41 + return v, nil
  42 + }
  43 + return nil, err
  44 +}
  1 +package protocol
  2 +
  3 +import "time"
  4 +
  5 +const (
  6 + Grasper = 1 //把握人
  7 + Provider = 2 //提供者
  8 +)
  9 +
  10 +//成果项
  11 +type AchievementItem struct {
  12 + Id int64 `json:"id"`
  13 + CreateTime int64 `json:"createTime"`
  14 + Provider *BaseUserInfo `json:"provider"`
  15 + Content string `json:"content"`
  16 + Pictures []Picture `json:"pictures"`
  17 + GraspScore float64 `json:"graspScore"` //把握分
  18 +}
  19 +
  20 +//机会列表 通用项
  21 +type AchievementCommonListItem struct {
  22 + Achievement AchievementItem `json:"achievement,omitempty"` //成果详情
  23 + StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData
  24 + //我审核的-通过
  25 + Score interface{} `json:"score,omitempty"`
  26 + //模板
  27 + ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
  28 + ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
  29 +
  30 + Message interface{} `json:"message,omitempty"` //消息
  31 + CommentData interface{} `json:"commentData,omitempty"` //评论
  32 + CollectData interface{} `json:"collectData,omitempty"` //收藏数据
  33 + ThumbUpData interface{} `json:"thumbUpData,omitempty"` //点赞数据
  34 + //我评论的 评论数据
  35 + CommentedData interface{} `json:"commentedData,omitempty"`
  36 +
  37 + SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论
  38 + Status int `json:"-"` //0:删除 1:开启 2:关闭
  39 +}
  40 +
  41 +/*AchievementPool 成果池*/
  42 +type AchievementPoolRequest struct {
  43 + UserId int64 `json:"userId"`
  44 + LastId int64 `json:"lastId"`
  45 + PageSize int `json:"pageSize" valid:"Required"`
  46 + ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会
  47 + DepartmentId int `json:"departmentId"`
  48 +}
  49 +type AchievementPoolResponse struct {
  50 + List []*AchievementCommonListItem `json:"list"`
  51 + Total int `json:"total"`
  52 +}
  53 +
  54 +//通用 机会orm对象
  55 +type CommAchievementItemOrm struct {
  56 + AchievementItemOrm
  57 + StaticDataOrm
  58 +}
  59 +type AchievementItemOrm struct {
  60 + AchievementId int64 `orm:"column(id)"`
  61 + UserId int64 `orm:"column(user_company_id)"`
  62 + CreateTime time.Time `orm:"column(create_at)"`
  63 + SourceContent string `orm:"column(source_content)"`
  64 + Images string `orm:"column(images)"`
  65 + GraspScore float64 `orm:"column(grasp_score)"`
  66 + UserGraspScore float64 `orm:"column(user_grasp_score)"`
  67 +
  68 + TemplateId int `orm:"column(audit_template_id)"`
  69 + ChanceTypeId int `orm:"column(chance_type_id)"`
  70 + Status int `orm:"column(status)"`
  71 +}
  72 +
  73 +type StaticDataOrm struct {
  74 + CommentTotal int `orm:"column(comment_total)"`
  75 + ZanTotal int `orm:"column(zan_total)"`
  76 + ViewTotal int `orm:"column(view_total)"`
  77 +}
  78 +
  79 +//机会池收藏列表项
  80 +//type AchievementsOrm struct {
  81 +// CommAchievementItemOrm
  82 +//}
  83 +
  84 +/*MyGrasp 我把握的*/
  85 +type MyGraspRequest struct {
  86 + AchievementPoolRequest
  87 +}
  88 +type MyGraspResponse struct {
  89 + AchievementPoolResponse
  90 +}
  91 +
  92 +/*AchievementDetail 成果详情*/
  93 +type AchievementDetailRequest struct {
  94 + Id int64 `json:"id" valid:"Required"`
  95 +}
  96 +type AchievementDetailResponse struct {
  97 + Achievement AchievementItem `json:"achievement,omitempty"` //成果详情
  98 + StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数
  99 + //模板
  100 + ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
  101 + ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
  102 + Status int `json:"-"` //0:删除 1:开启 2:关闭
  103 + SourceChance []ChanceItem `json:"sourceChance"` //机会来源
  104 + Participants []UserGraspInfo //参与人
  105 +}
  106 +
  107 +type UserGraspInfo struct {
  108 + Provider *BaseUserInfo `json:"provider"`
  109 + GraspScore float64 `json:"graspScore"` //把握分
  110 + Type int `json:"type"` //1:把握人 2:提供者
  111 +}
1 package protocol 1 package protocol
2 2
3 const ( 3 const (
4 - SourceTypeChance = 1  
5 - SourceTypeComment = 2  
6 - SourceTypeBulletin = 3 4 + SourceTypeChance = 1 //机会
  5 + SourceTypeComment = 2 //机会评论
  6 + SourceTypeBulletin = 3
  7 + SourceTypeAchievement = 4 //成果
  8 + SourceTypeAchievementComment = 5 //成果评论
7 ) 9 )
8 10
9 /*IComment */ 11 /*IComment */
@@ -37,6 +37,7 @@ const ( @@ -37,6 +37,7 @@ const (
37 MyAuditChanceWait //我审核的机会-待我审批 37 MyAuditChanceWait //我审核的机会-待我审批
38 MyAuditChancePass //我审核的机会-已通过 38 MyAuditChancePass //我审核的机会-已通过
39 MyAuditChanceReturn //我审核的机会-已退回 39 MyAuditChanceReturn //我审核的机会-已退回
  40 + MyGraspAchievement //我把握的成果
40 ) 41 )
41 42
42 var MapStaticName map[int64]string 43 var MapStaticName map[int64]string
@@ -7,6 +7,30 @@ import ( @@ -7,6 +7,30 @@ import (
7 7
8 func init() { 8 func init() {
9 9
  10 + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"],
  11 + beego.ControllerComments{
  12 + Method: "AchievementDetail",
  13 + Router: `/achievementDetail`,
  14 + AllowHTTPMethods: []string{"post"},
  15 + MethodParams: param.Make(),
  16 + Params: nil})
  17 +
  18 + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"],
  19 + beego.ControllerComments{
  20 + Method: "AchievementPool",
  21 + Router: `/achievementPool`,
  22 + AllowHTTPMethods: []string{"post"},
  23 + MethodParams: param.Make(),
  24 + Params: nil})
  25 +
  26 + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"],
  27 + beego.ControllerComments{
  28 + Method: "MyGrasp",
  29 + Router: `/myGrasp`,
  30 + AllowHTTPMethods: []string{"post"},
  31 + MethodParams: param.Make(),
  32 + Params: nil})
  33 +
10 beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], 34 beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"],
11 beego.ControllerComments{ 35 beego.ControllerComments{
12 Method: "AccessToken", 36 Method: "AccessToken",
@@ -24,6 +24,7 @@ func init() { @@ -24,6 +24,7 @@ func init() {
24 beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})), 24 beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})),
25 beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})), 25 beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})),
26 beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})), 26 beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})),
  27 + beego.NSNamespace("achievement", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AchievementController{})),
27 ) 28 )
28 beego.AddNamespace(nsV1) 29 beego.AddNamespace(nsV1)
29 30
@@ -195,6 +195,21 @@ func GetChanceMarkData(userId, companyId int64, sourceId int64) (flag int, err e @@ -195,6 +195,21 @@ func GetChanceMarkData(userId, companyId int64, sourceId int64) (flag int, err e
195 return v.MarkFlag, nil 195 return v.MarkFlag, nil
196 } 196 }
197 197
  198 +//获取机会标记数据 点赞 / 收藏
  199 +func GetMarkData(userId, companyId int64, sourceId int64, sourceType int) (flag int, err error) {
  200 + var (
  201 + v *models.ChanceFavorite
  202 + )
  203 + if v, err = models.GetChanceFavorite(userId, companyId, sourceId, sourceType); err != nil {
  204 + if err == orm.ErrNoRows {
  205 + //log.Error(userId, companyId, sourceId, err)
  206 + return 0, nil
  207 + }
  208 + return
  209 + }
  210 + return v.MarkFlag, nil
  211 +}
  212 +
198 //构建统计sql语句 213 //构建统计sql语句
199 func GetIncrementSql(table string, column string, incre int, id int64) *utils.SqlData { 214 func GetIncrementSql(table string, column string, incre int, id int64) *utils.SqlData {
200 var sql *bytes.Buffer 215 var sql *bytes.Buffer
@@ -45,3 +45,17 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8) @@ -45,3 +45,17 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8)
45 } 45 }
46 return 46 return
47 } 47 }
  48 +
  49 +//我把握的统计
  50 +func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) {
  51 + var ()
  52 + if total, err = models.GetAchievementAll(header.UserId, header.CompanyId, 0, 0, 0, 0, nil); err != nil {
  53 + if err == orm.ErrNoRows {
  54 + err = nil
  55 + return
  56 + }
  57 + log.Error(err)
  58 + return
  59 + }
  60 + return
  61 +}
  1 +package chance
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/orm"
  5 + "opp/internal/utils"
  6 + "opp/models"
  7 + "opp/protocol"
  8 + "opp/services/agg"
  9 +
  10 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  11 +)
  12 +
  13 +//成果池
  14 +func AchievementPool(header *protocol.RequestHeader, request *protocol.AchievementPoolRequest) (rsp *protocol.AchievementPoolResponse, err error) {
  15 + var (
  16 + ormItems []protocol.CommAchievementItemOrm
  17 + total int
  18 + )
  19 + rsp = &protocol.AchievementPoolResponse{}
  20 + rsp.List = make([]*protocol.AchievementCommonListItem, 0)
  21 + if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.DepartmentId, request.PageSize, &ormItems); err != nil {
  22 + if err == orm.ErrNoRows {
  23 + err = nil
  24 + return
  25 + }
  26 + log.Error(err)
  27 + return
  28 + }
  29 + rsp.Total = total
  30 + for i := range ormItems {
  31 + item := ormItems[i]
  32 + rspItem := &protocol.AchievementCommonListItem{
  33 + Achievement: GetAchievementItem(header, item),
  34 + StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId),
  35 + ChanceTemplate: getTemplate(item.TemplateId),
  36 + ChanceType: getChanceType(item.ChanceTypeId),
  37 + }
  38 + rsp.List = append(rsp.List, rspItem)
  39 + }
  40 + return
  41 +}
  42 +
  43 +//获取成果项
  44 +func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchievementItemOrm) (item protocol.AchievementItem) {
  45 + var (
  46 + provider *protocol.BaseUserInfo
  47 + err error
  48 + )
  49 + if from.UserId > 0 {
  50 + if provider, err = agg.GetUserBaseInfo(from.UserId, header.CompanyId); err != nil {
  51 + log.Error(err)
  52 + return
  53 + } else {
  54 + item = protocol.AchievementItem{
  55 + Id: from.AchievementId,
  56 + Provider: provider,
  57 + CreateTime: from.CreateTime.Unix() * 1000,
  58 + Content: from.SourceContent,
  59 + GraspScore: from.GraspScore,
  60 + }
  61 + jsonUnmarshal(from.Images, &item.Pictures)
  62 + }
  63 + }
  64 + return
  65 +}
  66 +
  67 +//获取统计数据
  68 +func GetStatisticData(header *protocol.RequestHeader, from protocol.StaticDataOrm, sourceId int64) (chanceData protocol.ChanceData) {
  69 + chanceData = protocol.ChanceData{
  70 + ThumbsUpTotal: from.ZanTotal,
  71 + CommentTotal: from.CommentTotal,
  72 + PageViewTotal: from.ViewTotal,
  73 + }
  74 + chanceData.IsThumbsUp, chanceData.IsCollect, _ = getMarkFlag(header, sourceId, protocol.SourceTypeAchievement)
  75 + return
  76 +}
  77 +
  78 +//我把握的
  79 +func MyGrasp(header *protocol.RequestHeader, request *protocol.MyGraspRequest) (rsp *protocol.MyGraspResponse, err error) {
  80 + var (
  81 + achievementPool *protocol.AchievementPoolResponse
  82 + )
  83 + request.UserId = header.UserId
  84 + if achievementPool, err = AchievementPool(header, &request.AchievementPoolRequest); err != nil {
  85 + log.Error(err)
  86 + return
  87 + }
  88 + rsp = &protocol.MyGraspResponse{}
  89 + rsp.AchievementPoolResponse = *achievementPool
  90 + return
  91 +}
  92 +
  93 +//成果详情
  94 +func AchievementDetail(header *protocol.RequestHeader, request *protocol.AchievementDetailRequest) (rsp *protocol.AchievementDetailResponse, err error) {
  95 + var (
  96 + items []protocol.CommAchievementItemOrm
  97 + participants []*models.AchievementProvider
  98 + )
  99 + if err = models.GetCommAchievementItemOrmId(request.Id, &items); err != nil {
  100 + log.Error(err)
  101 + return
  102 + }
  103 + if len(items) == 0 {
  104 + err = protocol.NewErrWithMessage(1)
  105 + log.Error("items not empty", request.Id)
  106 + return
  107 + }
  108 + item := items[0]
  109 + if item.Status != 1 {
  110 + //错误 成果删除或关闭
  111 + }
  112 + rsp = &protocol.AchievementDetailResponse{}
  113 + {
  114 + rsp.Achievement = GetAchievementItem(header, item)
  115 + rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId)
  116 + rsp.ChanceTemplate = getTemplate(item.TemplateId)
  117 + rsp.ChanceType = getChanceType(item.ChanceTypeId)
  118 + }
  119 +
  120 + if participants, err = models.GetAchievementProviders(request.Id); err != nil && err != orm.ErrNoRows {
  121 + log.Error(err)
  122 + return
  123 + }
  124 + newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo {
  125 + return protocol.UserGraspInfo{
  126 + Provider: user,
  127 + GraspScore: score,
  128 + Type: t,
  129 + }
  130 + }
  131 + addParticipants := func(item protocol.UserGraspInfo) {
  132 + rsp.Participants = append(rsp.Participants, item)
  133 + }
  134 + addParticipants(newParticipant(rsp.Achievement.Provider, item.UserGraspScore, protocol.Grasper))
  135 + for i := range participants {
  136 + p := participants[i]
  137 + if provider, e := agg.GetUserBaseInfo(p.UserCompanyId, header.CompanyId); e != nil {
  138 + log.Error(e)
  139 + return
  140 + } else {
  141 + addParticipants(newParticipant(provider, p.UserGraspScore, protocol.Provider))
  142 + }
  143 + }
  144 +
  145 + //查看数量
  146 + utils.ExecuteSqlByRoll(true, agg.GetIncrementSql((&models.Achievement{}).TableName(), "view_total", 1, request.Id))
  147 +
  148 + return
  149 +}
@@ -1792,6 +1792,18 @@ func getChanceMarkFlag(header *protocol.RequestHeader, chanceId int64) (isThumbs @@ -1792,6 +1792,18 @@ func getChanceMarkFlag(header *protocol.RequestHeader, chanceId int64) (isThumbs
1792 return 1792 return
1793 } 1793 }
1794 1794
  1795 +//获取机会点赞/收藏状态
  1796 +func getMarkFlag(header *protocol.RequestHeader, sourceId int64, sourceType int) (isThumbsUp, isCollect bool, err error) {
  1797 + var flag int
  1798 + if flag, err = agg.GetMarkData(header.UserId, header.CompanyId, sourceId, sourceType); err != nil {
  1799 + log.Error(err)
  1800 + return
  1801 + }
  1802 + isThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan
  1803 + isCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect
  1804 + return
  1805 +}
  1806 +
1795 //获取模板 1807 //获取模板
1796 func getTemplate(templateId int) protocol.NameItem { 1808 func getTemplate(templateId int) protocol.NameItem {
1797 if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil { 1809 if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil {
@@ -370,70 +370,78 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis @@ -370,70 +370,78 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis
370 rsp = &protocol.UserStatisticsResponse{} 370 rsp = &protocol.UserStatisticsResponse{}
371 //buf :=bytes.NewBuffer(nil) 371 //buf :=bytes.NewBuffer(nil)
372 //buf.WriteString(fmt.Sprintf("用户中心-统计信息 user:%v type_total:%v \n",header.UserId,request.TypeTotal)) 372 //buf.WriteString(fmt.Sprintf("用户中心-统计信息 user:%v type_total:%v \n",header.UserId,request.TypeTotal))
373 - for flag = 1; flag <= (protocol.MyAuditChanceReturn); flag = flag << 1 { 373 + for flag = 1; flag <= (protocol.MyGraspAchievement); flag = flag << 1 {
374 total = 0 374 total = 0
375 - switch flag {  
376 - case protocol.CollectStatic: //收藏  
377 - if total, err = models.GetChanceCollect(header.UserId, 0, 0, nil); err != nil {  
378 - log.Error(err)  
379 - }  
380 - break  
381 - case protocol.ZanStatic: //点赞  
382 - if total, err = models.GetChanceThumbUp(header.UserId, 0, 0, nil); err != nil {  
383 - log.Error(err)  
384 - }  
385 - break  
386 - case protocol.CommentStatic: //评论  
387 - if total, err = models.GetChanceComment(header.UserId, 0, 0, nil); err != nil {  
388 - log.Error(err)  
389 - }  
390 - break  
391 - case protocol.MyCommitChance:  
392 - if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging, protocol.ReviewStatusReturn, protocol.ReviewStatusPass); err != nil {  
393 - log.Error(err)  
394 - }  
395 - break  
396 - case protocol.MyCommitChanceWait:  
397 - if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging); err != nil {  
398 - log.Error(err)  
399 - }  
400 - break  
401 - case protocol.MyCommitChancePass:  
402 - if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusPass); err != nil {  
403 - log.Error(err)  
404 - }  
405 - break  
406 - case protocol.MyCommitChanceReturn:  
407 - if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusReturn); err != nil {  
408 - log.Error(err)  
409 - }  
410 - break  
411 - case protocol.MyAuditChance:  
412 - var total1, total2 int  
413 - if total1, err = agg.MyApproveStatic(header, protocol.ReviewStatusReturn, protocol.ReviewStatusPass); err != nil {  
414 - log.Error(err)  
415 - }  
416 - if total2, err = agg.MyApproveEnableStatic(header, protocol.ReviewStatusAuditging); err != nil {  
417 - log.Error(err)  
418 - }  
419 - total = total1 + total2  
420 - break  
421 - case protocol.MyAuditChanceWait:  
422 - if total, err = agg.MyApproveEnableStatic(header, protocol.ReviewStatusAuditging); err != nil {  
423 - log.Error(err)  
424 - }  
425 - break  
426 - case protocol.MyAuditChancePass:  
427 - if total, err = agg.MyApproveStatic(header, protocol.ReviewStatusPass); err != nil {  
428 - log.Error(err)  
429 - }  
430 - break  
431 - case protocol.MyAuditChanceReturn:  
432 - if total, err = agg.MyApproveStatic(header, protocol.ReviewStatusReturn); err != nil {  
433 - log.Error(err) 375 + if flag&request.TypeTotal > 0 {
  376 + switch flag {
  377 + case protocol.CollectStatic: //收藏
  378 + if total, err = models.GetChanceCollect(header.UserId, 0, 0, nil); err != nil {
  379 + log.Error(err)
  380 + }
  381 + break
  382 + case protocol.ZanStatic: //点赞
  383 + if total, err = models.GetChanceThumbUp(header.UserId, 0, 0, nil); err != nil {
  384 + log.Error(err)
  385 + }
  386 + break
  387 + case protocol.CommentStatic: //评论
  388 + if total, err = models.GetChanceComment(header.UserId, 0, 0, nil); err != nil {
  389 + log.Error(err)
  390 + }
  391 + break
  392 + case protocol.MyCommitChance:
  393 + if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging, protocol.ReviewStatusReturn, protocol.ReviewStatusPass); err != nil {
  394 + log.Error(err)
  395 + }
  396 + break
  397 + case protocol.MyCommitChanceWait:
  398 + if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusAuditging); err != nil {
  399 + log.Error(err)
  400 + }
  401 + break
  402 + case protocol.MyCommitChancePass:
  403 + if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusPass); err != nil {
  404 + log.Error(err)
  405 + }
  406 + break
  407 + case protocol.MyCommitChanceReturn:
  408 + if total, err = agg.MyChanceStatic(header, protocol.ReviewStatusReturn); err != nil {
  409 + log.Error(err)
  410 + }
  411 + break
  412 + case protocol.MyAuditChance:
  413 + var total1, total2 int
  414 + if total1, err = agg.MyApproveStatic(header, protocol.ReviewStatusReturn, protocol.ReviewStatusPass); err != nil {
  415 + log.Error(err)
  416 + }
  417 + if total2, err = agg.MyApproveEnableStatic(header, protocol.ReviewStatusAuditging); err != nil {
  418 + log.Error(err)
  419 + }
  420 + total = total1 + total2
  421 + break
  422 + case protocol.MyAuditChanceWait:
  423 + if total, err = agg.MyApproveEnableStatic(header, protocol.ReviewStatusAuditging); err != nil {
  424 + log.Error(err)
  425 + }
  426 + break
  427 + case protocol.MyAuditChancePass:
  428 + if total, err = agg.MyApproveStatic(header, protocol.ReviewStatusPass); err != nil {
  429 + log.Error(err)
  430 + }
  431 + break
  432 + case protocol.MyAuditChanceReturn:
  433 + if total, err = agg.MyApproveStatic(header, protocol.ReviewStatusReturn); err != nil {
  434 + log.Error(err)
  435 + }
  436 + break
  437 + case protocol.MyGraspAchievement:
  438 + if total, err = agg.MyGraspStatic(header); err != nil {
  439 + log.Error(err)
  440 + }
  441 + break
  442 + default:
  443 + break
434 } 444 }
435 - break  
436 -  
437 } 445 }
438 if flag&request.TypeTotal > 0 { 446 if flag&request.TypeTotal > 0 {
439 rsp.Totals = append(rsp.Totals, protocol.TypeTotalItem{ 447 rsp.Totals = append(rsp.Totals, protocol.TypeTotalItem{