作者 yangfu

成果详情

1 [dev] 1 [dev]
2 #数据库相关 2 #数据库相关
3 mysql_user = "${MYSQL_USER||root}" 3 mysql_user = "${MYSQL_USER||root}"
4 -mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"  
5 -mysql_host = "${MYSQL_HOST||115.29.205.99}" 4 +mysql_password = "${MYSQL_PASSWORD||sutianxia2018}"
  5 +mysql_host = "${MYSQL_HOST||101.37.68.23}"
6 mysql_port = "${MYSQL_PORT||3306}" 6 mysql_port = "${MYSQL_PORT||3306}"
7 -mysql_db_name = "${MYSQL_DB_NAME||opportunity}" 7 +mysql_db_name = "${MYSQL_DB_NAME||opportunity_dev}"
8 8
9 #日志 9 #日志
10 log_level = "${LOG_LEVEL||debug}" 10 log_level = "${LOG_LEVEL||debug}"
@@ -27,7 +27,7 @@ type Achievement struct { @@ -27,7 +27,7 @@ type Achievement struct {
27 } 27 }
28 28
29 func (t *Achievement) TableName() string { 29 func (t *Achievement) TableName() string {
30 - return "new_achievement" 30 + return "achievement"
31 } 31 }
32 32
33 func init() { 33 func init() {
@@ -69,20 +69,20 @@ func UpdateAchievementById(m *Achievement) (err error) { @@ -69,20 +69,20 @@ func UpdateAchievementById(m *Achievement) (err error) {
69 func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId int, pageSize int, v interface{}) (total int, err error) { 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 70 var whereString bytes.Buffer
71 if departmentId > 0 { 71 if departmentId > 0 {
72 - 72 + whereString.WriteString(fmt.Sprintf(` and %v in (select department_id from user_department where user_company_id=achievement.user_company_id and enable_status=1) `, departmentId))
73 } 73 }
74 if uid > 0 { 74 if uid > 0 {
75 whereString.WriteString(fmt.Sprintf(` and user_company_id=%v `, uid)) 75 whereString.WriteString(fmt.Sprintf(` and user_company_id=%v `, uid))
76 } 76 }
77 sql := fmt.Sprintf(` 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 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 achievement
79 where company_id=%v and (%v=0 or id<%v) and (%v=0 or chance_type_id =%v) and status=1 %v 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 80 order by create_at desc
81 limit %v 81 limit %v
82 `, cid, lastId, lastId, chanceTypeId, chanceTypeId, whereString.String(), pageSize) 82 `, cid, lastId, lastId, chanceTypeId, chanceTypeId, whereString.String(), pageSize)
83 83
84 sqlCount := fmt.Sprintf(` 84 sqlCount := fmt.Sprintf(`
85 -select count(0) from new_achievement 85 +select count(0) from achievement
86 where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v 86 where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v
87 `, cid, chanceTypeId, chanceTypeId, whereString.String()) 87 `, cid, chanceTypeId, chanceTypeId, whereString.String())
88 88
@@ -100,7 +100,7 @@ where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v @@ -100,7 +100,7 @@ where company_id=%v and (%v=0 or chance_type_id =%v) and status=1 %v
100 //成果详情 100 //成果详情
101 func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) { 101 func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) {
102 o := orm.NewOrm() 102 o := orm.NewOrm()
103 - sql := "select * from new_achievement where id=?" 103 + sql := "select * from achievement where id=?"
104 if _, err = o.Raw(sql, id).QueryRows(v); err == nil { 104 if _, err = o.Raw(sql, id).QueryRows(v); err == nil {
105 return nil 105 return nil
106 } 106 }
@@ -15,7 +15,7 @@ type AchievementChance struct { @@ -15,7 +15,7 @@ type AchievementChance struct {
15 } 15 }
16 16
17 func (t *AchievementChance) TableName() string { 17 func (t *AchievementChance) TableName() string {
18 - return "new_achievement_chance" 18 + return "achievement_chance"
19 } 19 }
20 20
21 func init() { 21 func init() {
@@ -32,3 +32,19 @@ func GetAchievementChanceById(id int64) (v *AchievementChance, err error) { @@ -32,3 +32,19 @@ func GetAchievementChanceById(id int64) (v *AchievementChance, err error) {
32 } 32 }
33 return nil, err 33 return nil, err
34 } 34 }
  35 +
  36 +//查询成果提供者列表
  37 +func GetAchievementChances(achievementId int64, v interface{}) (err error) {
  38 + o := orm.NewOrm()
  39 + sql := `select a.*,b.images,speechs,videos
  40 +from (
  41 +select chance_id,b.user_id chance_user_id,approve_time create_at,source_content,enable_status,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,publish_status,status
  42 +from achievement_chance a inner join chance b on a.chance_id=b.id where achievement_id=? and b.review_status=3
  43 +) a left JOIN chance_data b on a.chance_id =b.chance_id
  44 +order by a.create_at desc
  45 +`
  46 + if _, err = o.Raw(sql, achievementId).QueryRows(v); err == nil {
  47 + return nil
  48 + }
  49 + return err
  50 +}
@@ -15,7 +15,7 @@ type AchievementProvider struct { @@ -15,7 +15,7 @@ type AchievementProvider struct {
15 } 15 }
16 16
17 func (t *AchievementProvider) TableName() string { 17 func (t *AchievementProvider) TableName() string {
18 - return "new_achievement_provider" 18 + return "achievement_provider"
19 } 19 }
20 20
21 func init() { 21 func init() {
@@ -36,7 +36,7 @@ func GetAchievementProviderById(id int64) (v *AchievementProvider, err error) { @@ -36,7 +36,7 @@ func GetAchievementProviderById(id int64) (v *AchievementProvider, err error) {
36 //查询成果提供者列表 36 //查询成果提供者列表
37 func GetAchievementProviders(achievementId int64) (v []*AchievementProvider, err error) { 37 func GetAchievementProviders(achievementId int64) (v []*AchievementProvider, err error) {
38 o := orm.NewOrm() 38 o := orm.NewOrm()
39 - sql := "select * from new_achievement_provider where achievement_id=?" 39 + sql := "select * from achievement_provider where achievement_id=?"
40 if _, err = o.Raw(sql, achievementId).QueryRows(&v); err == nil { 40 if _, err = o.Raw(sql, achievementId).QueryRows(&v); err == nil {
41 return v, nil 41 return v, nil
42 } 42 }
@@ -97,11 +97,11 @@ type AchievementDetailResponse struct { @@ -97,11 +97,11 @@ type AchievementDetailResponse struct {
97 Achievement AchievementItem `json:"achievement,omitempty"` //成果详情 97 Achievement AchievementItem `json:"achievement,omitempty"` //成果详情
98 StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数 98 StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数
99 //模板 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 //参与人 100 + ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
  101 + ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
  102 + Status int `json:"-"` //0:删除 1:开启 2:关闭
  103 + SourceChance []*CommonListItem `json:"sourceChance"` //机会来源
  104 + Participants []UserGraspInfo `json:"participants"` //参与人
105 } 105 }
106 106
107 type UserGraspInfo struct { 107 type UserGraspInfo struct {
@@ -109,3 +109,10 @@ type UserGraspInfo struct { @@ -109,3 +109,10 @@ type UserGraspInfo struct {
109 GraspScore float64 `json:"graspScore"` //把握分 109 GraspScore float64 `json:"graspScore"` //把握分
110 Type int `json:"type"` //1:把握人 2:提供者 110 Type int `json:"type"` //1:把握人 2:提供者
111 } 111 }
  112 +
  113 +type SourceChanceItemOrm struct {
  114 + CommChanceItemOrm
  115 +
  116 + TemplateId int `orm:"column(audit_template_id)"`
  117 + ChanceTypeId int `orm:"column(chance_type_id)"`
  118 +}
@@ -514,11 +514,11 @@ type CommonListItem struct { @@ -514,11 +514,11 @@ type CommonListItem struct {
514 CommentedData interface{} `json:"commentedData,omitempty"` 514 CommentedData interface{} `json:"commentedData,omitempty"`
515 SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论 515 SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论
516 516
517 - ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭  
518 - Status int `json:"-"` //1:开启 2:关闭  
519 - ReviewStatus int `json:"reviewStatus"` //审核状态 517 + ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
  518 + Status int `json:"-"` //1:开启 2:关闭
  519 + ReviewStatus int `json:"reviewStatus,omitempty"` //审核状态
520 520
521 - ChanceId int64 `json:"chanceId"` //机会编号 521 + ChanceId int64 `json:"chanceId,omitempty"` //机会编号
522 } 522 }
523 523
524 type MsgCommonListItem struct { 524 type MsgCommonListItem struct {
@@ -95,6 +95,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve @@ -95,6 +95,7 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
95 var ( 95 var (
96 items []protocol.CommAchievementItemOrm 96 items []protocol.CommAchievementItemOrm
97 participants []*models.AchievementProvider 97 participants []*models.AchievementProvider
  98 + chances []protocol.SourceChanceItemOrm
98 ) 99 )
99 if err = models.GetCommAchievementItemOrmId(request.Id, &items); err != nil { 100 if err = models.GetCommAchievementItemOrmId(request.Id, &items); err != nil {
100 log.Error(err) 101 log.Error(err)
@@ -145,7 +146,50 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve @@ -145,7 +146,50 @@ func AchievementDetail(header *protocol.RequestHeader, request *protocol.Achieve
145 //查看数量 146 //查看数量
146 utils.ExecuteSqlByRoll(true, agg.GetIncrementSql((&models.Achievement{}).TableName(), "view_total", 1, request.Id)) 147 utils.ExecuteSqlByRoll(true, agg.GetIncrementSql((&models.Achievement{}).TableName(), "view_total", 1, request.Id))
147 148
  149 + if err = models.GetAchievementChances(request.Id, &chances); err != nil {
  150 + log.Error(err)
  151 + return
  152 + }
  153 + for i := range chances {
  154 + chance := chances[i]
  155 + commItem := &protocol.CommonListItem{}
  156 + commItem.Chance, commItem.ChanceStatus = SetChanceItem(header, chance.CommChanceItemOrm)
  157 + //commItem.ChanceTemplate = getTemplate(chance.TemplateId)
  158 + //commItem.ChanceType = getChanceType(chance.ChanceTypeId)
  159 + commItem.ChanceId = chance.ChanceId
  160 + rsp.SourceChance = append(rsp.SourceChance, commItem)
  161 + }
  162 + agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.SourceChance)
148 return 163 return
149 } 164 }
150 165
151 -//func GetSourceChance(header ) 166 +//设置机会详情
  167 +func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceItemOrm) (item protocol.ChanceItem, chanceStatus int) {
  168 + var provider *protocol.BaseUserInfo
  169 + var err error
  170 + if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
  171 + chanceStatus = protocol.ChanceStatusDelete
  172 + log.Error(err)
  173 + return
  174 + }
  175 + if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
  176 + chanceStatus = protocol.ChanceStatusDelete
  177 + }
  178 + if chance.Status == models.ChanceStatusClose { //机会关闭
  179 + chanceStatus = protocol.ChanceStatusClose
  180 + return
  181 + }
  182 +
  183 + item = protocol.ChanceItem{
  184 + Id: chance.ChanceId,
  185 + Provider: provider,
  186 + CreateTime: chance.CreateTime.Unix() * 1000,
  187 + //PublicStatus: chance.PublishStatus,
  188 + }
  189 + jsonUnmarshal(chance.SourceContent, &item.FormList)
  190 + item.FormList = clearEmptyForm(item.FormList)
  191 + jsonUnmarshal(chance.Images, &item.Pictures)
  192 + jsonUnmarshal(chance.Voices, &item.Speechs)
  193 + jsonUnmarshal(chance.Videos, &item.Videos)
  194 + return item, chanceStatus
  195 +}