正在显示
16 个修改的文件
包含
328 行增加
和
190 行删除
@@ -12,17 +12,16 @@ | @@ -12,17 +12,16 @@ | ||
12 | |机会评论列表|完成|2019.11.21|/v1/chance/comments| | 12 | |机会评论列表|完成|2019.11.21|/v1/chance/comments| |
13 | |我来评论|完成|2019.11.21|/v1/chance/iComment| | 13 | |我来评论|完成|2019.11.21|/v1/chance/iComment| |
14 | |我的评论|完成|2019.11.21|/v1/chance/iComments| | 14 | |我的评论|完成|2019.11.21|/v1/chance/iComments| |
15 | -|我的点赞| |2019.11.| | | ||
16 | -|我的收藏| |2019.11.| | | 15 | +|我的点赞| |2019.11.|v1/chance/favorite| |
16 | +|我的收藏| |2019.11.|v1/chance/favorite| | ||
17 | |消息中心|完成|2019.11.|v1/message/messageCenter| | 17 | |消息中心|完成|2019.11.|v1/message/messageCenter| |
18 | |标记已读|完成|2019.11.|v1/message/msgCenterRead| | 18 | |标记已读|完成|2019.11.|v1/message/msgCenterRead| |
19 | |标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead| | 19 | |标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead| |
20 | -|互动消息-点赞| |2019.11.| | | ||
21 | -|互动消息-评论| |2019.11.| | | 20 | +|互动消息-点赞| |2019.11.|v1/message/msgInteractive| |
21 | +|互动消息-评论| |2019.11.|v1/message/msgInteractive| | ||
22 | |我提交的机会| |2019.11.| | | 22 | |我提交的机会| |2019.11.| | |
23 | |我审核的机会| |2019.11.| | | 23 | |我审核的机会| |2019.11.| | |
24 | |待抓住机会列表| |2019.11. | | 24 | |待抓住机会列表| |2019.11. | |
25 | |机会池| |2019.11.| | | 25 | |机会池| |2019.11.| | |
26 | |提交机会| |2019.11.| | | 26 | |提交机会| |2019.11.| | |
27 | -|机会审核消息| |2019.11.| | | ||
28 | -|机会互动消息| |2019.11.| | | 27 | +|机会审核消息| |2019.11.|v1/message/msgInteractive| |
@@ -74,3 +74,24 @@ func (this *ChanceController) Comments() { | @@ -74,3 +74,24 @@ func (this *ChanceController) Comments() { | ||
74 | header := controllers.GetRequestHeader(this.Ctx) | 74 | header := controllers.GetRequestHeader(this.Ctx) |
75 | msg = protocol.NewReturnResponse(chance.Comments(header, request)) | 75 | msg = protocol.NewReturnResponse(chance.Comments(header, request)) |
76 | } | 76 | } |
77 | + | ||
78 | +//Favorite | ||
79 | +// @router /favorite [post] | ||
80 | +func (this *ChanceController) Favorite() { | ||
81 | + var msg *protocol.ResponseMessage | ||
82 | + defer func() { | ||
83 | + this.Resp(msg) | ||
84 | + }() | ||
85 | + var request *protocol.FavoriteRequest | ||
86 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
87 | + log.Error(err) | ||
88 | + msg = protocol.BadRequestParam(1) | ||
89 | + return | ||
90 | + } | ||
91 | + if b, m := this.Valid(request); !b { | ||
92 | + msg = m | ||
93 | + return | ||
94 | + } | ||
95 | + header := controllers.GetRequestHeader(this.Ctx) | ||
96 | + msg = protocol.NewReturnResponse(chance.Favorite(header, request)) | ||
97 | +} |
@@ -74,3 +74,24 @@ func (this *MessageController) MsgCenterAllRead() { | @@ -74,3 +74,24 @@ func (this *MessageController) MsgCenterAllRead() { | ||
74 | header := controllers.GetRequestHeader(this.Ctx) | 74 | header := controllers.GetRequestHeader(this.Ctx) |
75 | msg = protocol.NewReturnResponse(message.MsgCenterAllRead(header, request)) | 75 | msg = protocol.NewReturnResponse(message.MsgCenterAllRead(header, request)) |
76 | } | 76 | } |
77 | + | ||
78 | +//MsgInteractive | ||
79 | +// @router /msgInteractive [post] | ||
80 | +func (this *MessageController) MsgInteractive() { | ||
81 | + var msg *protocol.ResponseMessage | ||
82 | + defer func() { | ||
83 | + this.Resp(msg) | ||
84 | + }() | ||
85 | + var request *protocol.MsgInteractiveRequest | ||
86 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
87 | + log.Error(err) | ||
88 | + msg = protocol.BadRequestParam(1) | ||
89 | + return | ||
90 | + } | ||
91 | + if b, m := this.Valid(request); !b { | ||
92 | + msg = m | ||
93 | + return | ||
94 | + } | ||
95 | + header := controllers.GetRequestHeader(this.Ctx) | ||
96 | + msg = protocol.NewReturnResponse(message.MsgInteractive(header, request)) | ||
97 | +} |
@@ -8,6 +8,7 @@ require ( | @@ -8,6 +8,7 @@ require ( | ||
8 | github.com/gorilla/websocket v1.4.1 | 8 | github.com/gorilla/websocket v1.4.1 |
9 | github.com/klauspost/cpuid v1.2.1 // indirect | 9 | github.com/klauspost/cpuid v1.2.1 // indirect |
10 | github.com/prometheus/client_golang v1.1.0 | 10 | github.com/prometheus/client_golang v1.1.0 |
11 | + github.com/prometheus/common v0.6.0 | ||
11 | github.com/satori/go.uuid v1.2.0 | 12 | github.com/satori/go.uuid v1.2.0 |
12 | github.com/sony/sonyflake v1.0.0 | 13 | github.com/sony/sonyflake v1.0.0 |
13 | gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1 | 14 | gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1 |
@@ -13,3 +13,15 @@ type ChanceRepository struct{} | @@ -13,3 +13,15 @@ type ChanceRepository struct{} | ||
13 | func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) { | 13 | func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) { |
14 | return models.GetChanceById(id) | 14 | return models.GetChanceById(id) |
15 | } | 15 | } |
16 | + | ||
17 | +type IChanceFavoriteRepository interface { | ||
18 | + GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) | ||
19 | +} | ||
20 | + | ||
21 | +var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil) | ||
22 | + | ||
23 | +type ChanceFavoriteRepository struct{} | ||
24 | + | ||
25 | +func (r *ChanceFavoriteRepository) GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) { | ||
26 | + return models.GetChanceFavorites(userId, companyId, objectType, chanceType, lastId, pageSize) | ||
27 | +} |
@@ -5,6 +5,7 @@ import "opp/models" | @@ -5,6 +5,7 @@ import "opp/models" | ||
5 | type IMessageRepository interface { | 5 | type IMessageRepository interface { |
6 | GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) | 6 | GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) |
7 | UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) | 7 | UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) |
8 | + GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error) | ||
8 | } | 9 | } |
9 | 10 | ||
10 | var _ IMessageRepository = (*MessageRepository)(nil) | 11 | var _ IMessageRepository = (*MessageRepository)(nil) |
@@ -18,3 +19,7 @@ func (r *MessageRepository) GetUserMsgTotals(userId int64, companyId int64, msgT | @@ -18,3 +19,7 @@ func (r *MessageRepository) GetUserMsgTotals(userId int64, companyId int64, msgT | ||
18 | func (r *MessageRepository) UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { | 19 | func (r *MessageRepository) UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) { |
19 | return models.UpdateUserMsgSetRead(userId, companyId, msgType, msgId) | 20 | return models.UpdateUserMsgSetRead(userId, companyId, msgType, msgId) |
20 | } | 21 | } |
22 | + | ||
23 | +func (r *MessageRepository) GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error) { | ||
24 | + return models.GetUserMsgs(userId, companyId, msgType, sourceType, lastId, pageSize) | ||
25 | +} |
@@ -4,16 +4,17 @@ import "sync" | @@ -4,16 +4,17 @@ import "sync" | ||
4 | 4 | ||
5 | //全局 | 5 | //全局 |
6 | var ( | 6 | var ( |
7 | - once sync.Once | ||
8 | - User IUserRepository | ||
9 | - UserAuth IUserAuthRepository | ||
10 | - Commend ICommendRepository | ||
11 | - Company ICompanyRepository | ||
12 | - Department IDepartmentRepository | ||
13 | - Position IPositionRepository | ||
14 | - Chance IChanceRepository | ||
15 | - Comment ICommentRepository | ||
16 | - Message IMessageRepository | 7 | + once sync.Once |
8 | + User IUserRepository | ||
9 | + UserAuth IUserAuthRepository | ||
10 | + Commend ICommendRepository | ||
11 | + Company ICompanyRepository | ||
12 | + Department IDepartmentRepository | ||
13 | + Position IPositionRepository | ||
14 | + Chance IChanceRepository | ||
15 | + ChanceFavorite IChanceFavoriteRepository | ||
16 | + Comment ICommentRepository | ||
17 | + Message IMessageRepository | ||
17 | ) | 18 | ) |
18 | 19 | ||
19 | func init() { | 20 | func init() { |
@@ -30,6 +31,7 @@ func InitRepository() { | @@ -30,6 +31,7 @@ func InitRepository() { | ||
30 | Chance = &ChanceRepository{} | 31 | Chance = &ChanceRepository{} |
31 | Comment = &CommentRepository{} | 32 | Comment = &CommentRepository{} |
32 | Message = &MessageRepository{} | 33 | Message = &MessageRepository{} |
34 | + ChanceFavorite = &ChanceFavoriteRepository{} | ||
33 | } | 35 | } |
34 | 36 | ||
35 | func InitRepositoryMock() { | 37 | func InitRepositoryMock() { |
@@ -11,17 +11,18 @@ import ( | @@ -11,17 +11,18 @@ import ( | ||
11 | ) | 11 | ) |
12 | 12 | ||
13 | type Chance struct { | 13 | type Chance struct { |
14 | - Id int64 `orm:"column(id);pk" description:"id 主键"` | ||
15 | - UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"` | ||
16 | - DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"` | ||
17 | - ChanceTypeId int `orm:"column(chance_type_id)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "` | ||
18 | - Content string `orm:"column(content)" description:"内容"` | ||
19 | - CommentTotal int `orm:"column(comment_total)" description:"评论总数"` | ||
20 | - ZanTotal int `orm:"column(zan_total)" description:"点赞总数"` | ||
21 | - ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待审核 1:被退回 2:已通过 3:草稿箱"` | ||
22 | - EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "` | ||
23 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
24 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | 14 | + Id int64 `orm:"column(id);pk" description:"id 主键"` |
15 | + UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"` | ||
16 | + DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"` | ||
17 | + ChanceType int `orm:"column(chance_type)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "` | ||
18 | + Content string `orm:"column(content)" description:"内容"` | ||
19 | + ViewTotal int `orm:"column(view_total)" description:"浏览总数"` | ||
20 | + CommentTotal int `orm:"column(comment_total)" description:"评论总数"` | ||
21 | + ZanTotal int `orm:"column(zan_total)" description:"点赞总数"` | ||
22 | + ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待审核 1:被退回 2:已通过 3:草稿箱"` | ||
23 | + EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "` | ||
24 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
25 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
25 | } | 26 | } |
26 | 27 | ||
27 | func (t *Chance) TableName() string { | 28 | func (t *Chance) TableName() string { |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "errors" | ||
5 | "fmt" | 4 | "fmt" |
6 | - "reflect" | ||
7 | - "strings" | 5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
8 | "time" | 7 | "time" |
9 | 8 | ||
10 | "github.com/astaxie/beego/orm" | 9 | "github.com/astaxie/beego/orm" |
@@ -13,10 +12,11 @@ import ( | @@ -13,10 +12,11 @@ import ( | ||
13 | type ChanceFavorite struct { | 12 | type ChanceFavorite struct { |
14 | Id int64 `orm:"column(id);pk" description:"点赞编号"` | 13 | Id int64 `orm:"column(id);pk" description:"点赞编号"` |
15 | UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` | 14 | UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` |
15 | + CompanyId int64 `orm:"column(company_id)" description:"company.id 公司编号"` | ||
16 | ObjectType int `orm:"column(object_type)" description:"类型 1:点赞 2:收藏"` | 16 | ObjectType int `orm:"column(object_type)" description:"类型 1:点赞 2:收藏"` |
17 | SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"` | 17 | SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"` |
18 | SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"` | 18 | SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"` |
19 | - ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号 - 附加 "` | 19 | + ChanceType int `orm:"column(chance_type)" description:"机会类型编号 - 附加 "` |
20 | EnableStatus int `orm:"column(enable_status)" description:"1:有效 0:无效"` | 20 | EnableStatus int `orm:"column(enable_status)" description:"1:有效 0:无效"` |
21 | CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | 21 | CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` |
22 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp);null" description:"删除时间"` | 22 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp);null" description:"删除时间"` |
@@ -49,84 +49,6 @@ func GetChanceFavoriteById(id int64) (v *ChanceFavorite, err error) { | @@ -49,84 +49,6 @@ func GetChanceFavoriteById(id int64) (v *ChanceFavorite, err error) { | ||
49 | return nil, err | 49 | return nil, err |
50 | } | 50 | } |
51 | 51 | ||
52 | -// GetAllChanceFavorite retrieves all ChanceFavorite matches certain condition. Returns empty list if | ||
53 | -// no records exist | ||
54 | -func GetAllChanceFavorite(query map[string]string, fields []string, sortby []string, order []string, | ||
55 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
56 | - o := orm.NewOrm() | ||
57 | - qs := o.QueryTable(new(ChanceFavorite)) | ||
58 | - // query k=v | ||
59 | - for k, v := range query { | ||
60 | - // rewrite dot-notation to Object__Attribute | ||
61 | - k = strings.Replace(k, ".", "__", -1) | ||
62 | - if strings.Contains(k, "isnull") { | ||
63 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
64 | - } else { | ||
65 | - qs = qs.Filter(k, v) | ||
66 | - } | ||
67 | - } | ||
68 | - // order by: | ||
69 | - var sortFields []string | ||
70 | - if len(sortby) != 0 { | ||
71 | - if len(sortby) == len(order) { | ||
72 | - // 1) for each sort field, there is an associated order | ||
73 | - for i, v := range sortby { | ||
74 | - orderby := "" | ||
75 | - if order[i] == "desc" { | ||
76 | - orderby = "-" + v | ||
77 | - } else if order[i] == "asc" { | ||
78 | - orderby = v | ||
79 | - } else { | ||
80 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
81 | - } | ||
82 | - sortFields = append(sortFields, orderby) | ||
83 | - } | ||
84 | - qs = qs.OrderBy(sortFields...) | ||
85 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
86 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
87 | - for _, v := range sortby { | ||
88 | - orderby := "" | ||
89 | - if order[0] == "desc" { | ||
90 | - orderby = "-" + v | ||
91 | - } else if order[0] == "asc" { | ||
92 | - orderby = v | ||
93 | - } else { | ||
94 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
95 | - } | ||
96 | - sortFields = append(sortFields, orderby) | ||
97 | - } | ||
98 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
99 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
100 | - } | ||
101 | - } else { | ||
102 | - if len(order) != 0 { | ||
103 | - return nil, errors.New("Error: unused 'order' fields") | ||
104 | - } | ||
105 | - } | ||
106 | - | ||
107 | - var l []ChanceFavorite | ||
108 | - qs = qs.OrderBy(sortFields...) | ||
109 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
110 | - if len(fields) == 0 { | ||
111 | - for _, v := range l { | ||
112 | - ml = append(ml, v) | ||
113 | - } | ||
114 | - } else { | ||
115 | - // trim unused fields | ||
116 | - for _, v := range l { | ||
117 | - m := make(map[string]interface{}) | ||
118 | - val := reflect.ValueOf(v) | ||
119 | - for _, fname := range fields { | ||
120 | - m[fname] = val.FieldByName(fname).Interface() | ||
121 | - } | ||
122 | - ml = append(ml, m) | ||
123 | - } | ||
124 | - } | ||
125 | - return ml, nil | ||
126 | - } | ||
127 | - return nil, err | ||
128 | -} | ||
129 | - | ||
130 | // UpdateChanceFavorite updates ChanceFavorite by Id and returns error if | 52 | // UpdateChanceFavorite updates ChanceFavorite by Id and returns error if |
131 | // the record to be updated doesn't exist | 53 | // the record to be updated doesn't exist |
132 | func UpdateChanceFavoriteById(m *ChanceFavorite) (err error) { | 54 | func UpdateChanceFavoriteById(m *ChanceFavorite) (err error) { |
@@ -156,3 +78,27 @@ func DeleteChanceFavorite(id int64) (err error) { | @@ -156,3 +78,27 @@ func DeleteChanceFavorite(id int64) (err error) { | ||
156 | } | 78 | } |
157 | return | 79 | return |
158 | } | 80 | } |
81 | + | ||
82 | +func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) { | ||
83 | + sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc") | ||
84 | + sql.Where(fmt.Sprintf("user_id=%d", userId)) | ||
85 | + sql.Where(fmt.Sprintf("company_id=%d", userId)) | ||
86 | + if chanceType > 0 { | ||
87 | + sql.Where(fmt.Sprintf("chance_type=%d", chanceType)) | ||
88 | + } | ||
89 | + if objectType > 0 { | ||
90 | + sql.Where(fmt.Sprintf("object_type&%d>0", objectType)) | ||
91 | + } | ||
92 | + if pageSize > 0 { | ||
93 | + sql.Limit(0, pageSize) | ||
94 | + } | ||
95 | + if lastId > 0 { | ||
96 | + sql.Where(fmt.Sprintf("id>%d", lastId)) | ||
97 | + } | ||
98 | + if total, err = sql.Querys(&v); err == nil { | ||
99 | + return | ||
100 | + } | ||
101 | + log.Error(sql.Strings()) | ||
102 | + return | ||
103 | + | ||
104 | +} |
1 | package models | 1 | package models |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | - "errors" | ||
5 | "fmt" | 4 | "fmt" |
6 | - "reflect" | ||
7 | - "strings" | 5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" |
8 | "time" | 6 | "time" |
9 | 7 | ||
10 | "github.com/astaxie/beego/orm" | 8 | "github.com/astaxie/beego/orm" |
@@ -17,6 +15,7 @@ type UserMsg struct { | @@ -17,6 +15,7 @@ type UserMsg struct { | ||
17 | MsgType int `orm:"column(msg_type)" description:"消息类型 1.公司公告 2.表彰通知 4.互动消息 8.机会审核"` | 15 | MsgType int `orm:"column(msg_type)" description:"消息类型 1.公司公告 2.表彰通知 4.互动消息 8.机会审核"` |
18 | Message string `orm:"column(message)" description:"消息内容"` | 16 | Message string `orm:"column(message)" description:"消息内容"` |
19 | SourceId int64 `orm:"column(source_id)" description:"来源id (机会编号 /评论编号)"` | 17 | SourceId int64 `orm:"column(source_id)" description:"来源id (机会编号 /评论编号)"` |
18 | + SourceType int `orm:"column(source_type)"` | ||
20 | IsPublic int8 `orm:"column(is_public)" description:"1:公开 0:不公开"` | 19 | IsPublic int8 `orm:"column(is_public)" description:"1:公开 0:不公开"` |
21 | IsRead int8 `orm:"column(is_read)" description:"1:已读 0:未读"` | 20 | IsRead int8 `orm:"column(is_read)" description:"1:已读 0:未读"` |
22 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"` | 21 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"` |
@@ -49,84 +48,6 @@ func GetUserMsgById(id int64) (v *UserMsg, err error) { | @@ -49,84 +48,6 @@ func GetUserMsgById(id int64) (v *UserMsg, err error) { | ||
49 | return nil, err | 48 | return nil, err |
50 | } | 49 | } |
51 | 50 | ||
52 | -// GetAllUserMsg retrieves all UserMsg matches certain condition. Returns empty list if | ||
53 | -// no records exist | ||
54 | -func GetAllUserMsg(query map[string]string, fields []string, sortby []string, order []string, | ||
55 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
56 | - o := orm.NewOrm() | ||
57 | - qs := o.QueryTable(new(UserMsg)) | ||
58 | - // query k=v | ||
59 | - for k, v := range query { | ||
60 | - // rewrite dot-notation to Object__Attribute | ||
61 | - k = strings.Replace(k, ".", "__", -1) | ||
62 | - if strings.Contains(k, "isnull") { | ||
63 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
64 | - } else { | ||
65 | - qs = qs.Filter(k, v) | ||
66 | - } | ||
67 | - } | ||
68 | - // order by: | ||
69 | - var sortFields []string | ||
70 | - if len(sortby) != 0 { | ||
71 | - if len(sortby) == len(order) { | ||
72 | - // 1) for each sort field, there is an associated order | ||
73 | - for i, v := range sortby { | ||
74 | - orderby := "" | ||
75 | - if order[i] == "desc" { | ||
76 | - orderby = "-" + v | ||
77 | - } else if order[i] == "asc" { | ||
78 | - orderby = v | ||
79 | - } else { | ||
80 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
81 | - } | ||
82 | - sortFields = append(sortFields, orderby) | ||
83 | - } | ||
84 | - qs = qs.OrderBy(sortFields...) | ||
85 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
86 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
87 | - for _, v := range sortby { | ||
88 | - orderby := "" | ||
89 | - if order[0] == "desc" { | ||
90 | - orderby = "-" + v | ||
91 | - } else if order[0] == "asc" { | ||
92 | - orderby = v | ||
93 | - } else { | ||
94 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
95 | - } | ||
96 | - sortFields = append(sortFields, orderby) | ||
97 | - } | ||
98 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
99 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
100 | - } | ||
101 | - } else { | ||
102 | - if len(order) != 0 { | ||
103 | - return nil, errors.New("Error: unused 'order' fields") | ||
104 | - } | ||
105 | - } | ||
106 | - | ||
107 | - var l []UserMsg | ||
108 | - qs = qs.OrderBy(sortFields...) | ||
109 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
110 | - if len(fields) == 0 { | ||
111 | - for _, v := range l { | ||
112 | - ml = append(ml, v) | ||
113 | - } | ||
114 | - } else { | ||
115 | - // trim unused fields | ||
116 | - for _, v := range l { | ||
117 | - m := make(map[string]interface{}) | ||
118 | - val := reflect.ValueOf(v) | ||
119 | - for _, fname := range fields { | ||
120 | - m[fname] = val.FieldByName(fname).Interface() | ||
121 | - } | ||
122 | - ml = append(ml, m) | ||
123 | - } | ||
124 | - } | ||
125 | - return ml, nil | ||
126 | - } | ||
127 | - return nil, err | ||
128 | -} | ||
129 | - | ||
130 | // UpdateUserMsg updates UserMsg by Id and returns error if | 51 | // UpdateUserMsg updates UserMsg by Id and returns error if |
131 | // the record to be updated doesn't exist | 52 | // the record to be updated doesn't exist |
132 | func UpdateUserMsgById(m *UserMsg) (err error) { | 53 | func UpdateUserMsgById(m *UserMsg) (err error) { |
@@ -183,3 +104,25 @@ func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int6 | @@ -183,3 +104,25 @@ func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int6 | ||
183 | } | 104 | } |
184 | return | 105 | return |
185 | } | 106 | } |
107 | + | ||
108 | +func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId int64, pageSize int) (v []*UserMsg, total int, err error) { | ||
109 | + sql := mybeego.NewSqlExutor().Table("user_msg").Order("create_at desc") | ||
110 | + if lastId > 0 { | ||
111 | + sql.Where(fmt.Sprintf("id>%d", lastId)) | ||
112 | + } | ||
113 | + if msgType > 0 { | ||
114 | + sql.Where(fmt.Sprintf("msg_type=%d", msgType)) | ||
115 | + } | ||
116 | + sql.Where(fmt.Sprintf("receive_user_id=%d", userId)) | ||
117 | + sql.Where(fmt.Sprintf("company_id=%d", companyId)) | ||
118 | + if sourceType > 0 { | ||
119 | + sql.Where(fmt.Sprintf("source_type=%d", sourceType)) | ||
120 | + } | ||
121 | + if pageSize > 0 { | ||
122 | + sql.Limit(0, pageSize) | ||
123 | + } | ||
124 | + if total, err = sql.Querys(&v); err == nil { | ||
125 | + return | ||
126 | + } | ||
127 | + return | ||
128 | +} |
protocol/chance.go
0 → 100644
1 | +package protocol | ||
2 | + | ||
3 | +const ( | ||
4 | + ObjectType_Zan = 1 | ||
5 | + ObjectType_Collect = 2 | ||
6 | +) | ||
7 | + | ||
8 | +/*Favorite */ | ||
9 | +type FavoriteRequest struct { | ||
10 | + ObjectType int `json:"object_type" valid:"Required"` //收藏 点赞 | ||
11 | + ChanceType int `json:"chance_type" valid:"Required"` | ||
12 | + //TagId int `json:"tag_id"` //标签id | ||
13 | + LastId int64 `json:"lastId"` | ||
14 | + PageSize int `json:"pageSize" valid:"Required"` | ||
15 | +} | ||
16 | +type FavoriteResponse struct { | ||
17 | + Total int `json:"total"` | ||
18 | + Lists []*ChanceFavorite `json:"lists"` | ||
19 | +} | ||
20 | + | ||
21 | +type ChanceFavorite struct { | ||
22 | + Id int64 `json:"id"` | ||
23 | + Favorite interface{} `json:"favorite"` | ||
24 | +} | ||
25 | + | ||
26 | +type Chance struct { | ||
27 | + Id int64 `json:"id"` | ||
28 | + Provider *BaseUserInfo `json:"provider"` | ||
29 | + IsCollect bool `json:"is_collect"` | ||
30 | + IsZan bool `json:"is_zan"` | ||
31 | + Content string `json:"content"` | ||
32 | + ChanceType int `json:"chance_type"` | ||
33 | + | ||
34 | + //图片 | ||
35 | + //视频 | ||
36 | + //语音 | ||
37 | + | ||
38 | + ViewTotal int `json:"view_total"` | ||
39 | + CommentTotal int `json:"comment_total"` | ||
40 | + ZanTotal int `json:"zan_total"` | ||
41 | +} |
@@ -49,3 +49,24 @@ type MsgCenterAllReadRequest struct { | @@ -49,3 +49,24 @@ type MsgCenterAllReadRequest struct { | ||
49 | } | 49 | } |
50 | type MsgCenterAllReadResponse struct { | 50 | type MsgCenterAllReadResponse struct { |
51 | } | 51 | } |
52 | + | ||
53 | +/*互动消息*/ | ||
54 | +type MsgInteractiveRequest struct { | ||
55 | + LastId int64 `json:"lastId"` | ||
56 | + PageSize int `json:"pageSize" valid:"Required"` | ||
57 | + MsgType int `json:"msgType" valid:"Required"` | ||
58 | + SourceType int `json:"sourceType" valid:"Required"` | ||
59 | +} | ||
60 | +type MsgInteractiveResponse struct { | ||
61 | + Lists []*UserMsg `json:"lists"` | ||
62 | + Total int `json:"total"` | ||
63 | +} | ||
64 | + | ||
65 | +type UserMsg struct { | ||
66 | + Id int64 `json:"msgId"` | ||
67 | + SourceType int `json:"msgType"` | ||
68 | + Content string `json:"content"` | ||
69 | + CreateAt int64 `json:"msgTime"` | ||
70 | + IsRead int `json:"isRead"` | ||
71 | + //机会 //评论 | ||
72 | +} |
@@ -57,6 +57,14 @@ func init() { | @@ -57,6 +57,14 @@ func init() { | ||
57 | 57 | ||
58 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | 58 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], |
59 | beego.ControllerComments{ | 59 | beego.ControllerComments{ |
60 | + Method: "Favorite", | ||
61 | + Router: `/favorite`, | ||
62 | + AllowHTTPMethods: []string{"post"}, | ||
63 | + MethodParams: param.Make(), | ||
64 | + Params: nil}) | ||
65 | + | ||
66 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
67 | + beego.ControllerComments{ | ||
60 | Method: "IComment", | 68 | Method: "IComment", |
61 | Router: `/iComment`, | 69 | Router: `/iComment`, |
62 | AllowHTTPMethods: []string{"post"}, | 70 | AllowHTTPMethods: []string{"post"}, |
@@ -103,6 +111,14 @@ func init() { | @@ -103,6 +111,14 @@ func init() { | ||
103 | MethodParams: param.Make(), | 111 | MethodParams: param.Make(), |
104 | Params: nil}) | 112 | Params: nil}) |
105 | 113 | ||
114 | + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | ||
115 | + beego.ControllerComments{ | ||
116 | + Method: "MsgInteractive", | ||
117 | + Router: `/msgInteractive`, | ||
118 | + AllowHTTPMethods: []string{"post"}, | ||
119 | + MethodParams: param.Make(), | ||
120 | + Params: nil}) | ||
121 | + | ||
106 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], | 122 | beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"], |
107 | beego.ControllerComments{ | 123 | beego.ControllerComments{ |
108 | Method: "Image", | 124 | Method: "Image", |
@@ -3,6 +3,7 @@ package agg | @@ -3,6 +3,7 @@ package agg | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 4 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
5 | "opp/internal/repository" | 5 | "opp/internal/repository" |
6 | + "opp/models" | ||
6 | "opp/protocol" | 7 | "opp/protocol" |
7 | "sync" | 8 | "sync" |
8 | ) | 9 | ) |
@@ -58,3 +59,28 @@ func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) { | @@ -58,3 +59,28 @@ func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) { | ||
58 | } | 59 | } |
59 | return | 60 | return |
60 | } | 61 | } |
62 | + | ||
63 | +func GetChance(chanceId int64) (v *protocol.Chance, err error) { | ||
64 | + var ( | ||
65 | + c *models.Chance | ||
66 | + baseUserInfo *protocol.BaseUserInfo | ||
67 | + ) | ||
68 | + | ||
69 | + if c, err = repository.Chance.GetChanceById(chanceId); err != nil { | ||
70 | + return | ||
71 | + } | ||
72 | + if baseUserInfo, err = GetUserBaseInfo(c.UserId); err != nil { | ||
73 | + return | ||
74 | + } | ||
75 | + v = &protocol.Chance{ | ||
76 | + Id: c.Id, | ||
77 | + Provider: baseUserInfo, | ||
78 | + | ||
79 | + Content: c.Content, | ||
80 | + ChanceType: c.ChanceType, | ||
81 | + ViewTotal: c.ViewTotal, | ||
82 | + CommentTotal: c.CommentTotal, | ||
83 | + ZanTotal: c.ZanTotal, | ||
84 | + } | ||
85 | + return | ||
86 | +} |
services/chance/chance.go
0 → 100644
1 | +package chance | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/prometheus/common/log" | ||
5 | + "opp/internal/repository" | ||
6 | + "opp/models" | ||
7 | + "opp/protocol" | ||
8 | + "opp/services/agg" | ||
9 | +) | ||
10 | + | ||
11 | +func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) (rsp *protocol.FavoriteResponse, err error) { | ||
12 | + var ( | ||
13 | + favorites []*models.ChanceFavorite | ||
14 | + chance *protocol.Chance | ||
15 | + ) | ||
16 | + rsp = &protocol.FavoriteResponse{} | ||
17 | + favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites( | ||
18 | + header.Uid, | ||
19 | + header.CompanyId, | ||
20 | + request.ObjectType, | ||
21 | + request.ChanceType, | ||
22 | + request.LastId, | ||
23 | + request.PageSize) | ||
24 | + if err != nil { | ||
25 | + log.Error(err) | ||
26 | + return | ||
27 | + } | ||
28 | + rsp.Lists = make([]*protocol.ChanceFavorite, len(favorites)) | ||
29 | + for i := range favorites { | ||
30 | + f := favorites[i] | ||
31 | + item := &protocol.ChanceFavorite{ | ||
32 | + Id: f.Id, | ||
33 | + } | ||
34 | + switch f.SourceType { | ||
35 | + case protocol.SourceType_Chance: | ||
36 | + chance, err = agg.GetChance(f.SourceId) | ||
37 | + if err != nil { | ||
38 | + log.Error(err) | ||
39 | + return | ||
40 | + } | ||
41 | + chance.IsZan = (f.ObjectType & protocol.ObjectType_Zan) == protocol.ObjectType_Zan | ||
42 | + chance.IsCollect = (f.ObjectType & protocol.ObjectType_Collect) == protocol.ObjectType_Collect | ||
43 | + item.Favorite = chance | ||
44 | + case protocol.SourceType_Comment: | ||
45 | + } | ||
46 | + rsp.Lists[i] = item | ||
47 | + } | ||
48 | + return | ||
49 | +} |
@@ -3,6 +3,7 @@ package message | @@ -3,6 +3,7 @@ package message | ||
3 | import ( | 3 | import ( |
4 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 4 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
5 | "opp/internal/repository" | 5 | "opp/internal/repository" |
6 | + "opp/models" | ||
6 | "opp/protocol" | 7 | "opp/protocol" |
7 | ) | 8 | ) |
8 | 9 | ||
@@ -33,3 +34,36 @@ func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCente | @@ -33,3 +34,36 @@ func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCente | ||
33 | } | 34 | } |
34 | return | 35 | return |
35 | } | 36 | } |
37 | + | ||
38 | +//互动消息 | ||
39 | +func MsgInteractive(header *protocol.RequestHeader, request *protocol.MsgInteractiveRequest) (rsp *protocol.MsgInteractiveResponse, err error) { | ||
40 | + var ( | ||
41 | + userMsgs []*models.UserMsg | ||
42 | + ) | ||
43 | + rsp = &protocol.MsgInteractiveResponse{} | ||
44 | + userMsgs, rsp.Total, err = repository.Message.GetUserMsgs(header.Uid, header.CompanyId, request.MsgType, request.SourceType, request.LastId, request.PageSize) | ||
45 | + if err != nil { | ||
46 | + log.Error(err) | ||
47 | + return | ||
48 | + } | ||
49 | + if len(userMsgs) == 0 { | ||
50 | + return | ||
51 | + } | ||
52 | + rsp.Lists = make([]*protocol.UserMsg, len(userMsgs)) | ||
53 | + for i := range userMsgs { | ||
54 | + msg := userMsgs[i] | ||
55 | + userMsg := &protocol.UserMsg{ | ||
56 | + Id: msg.Id, | ||
57 | + Content: msg.Message, | ||
58 | + CreateAt: msg.CreateAt.Unix(), | ||
59 | + IsRead: int(msg.IsRead), | ||
60 | + SourceType: msg.SourceType, | ||
61 | + } | ||
62 | + switch msg.SourceType { | ||
63 | + case protocol.SourceType_Chance: | ||
64 | + case protocol.SourceType_Comment: | ||
65 | + } | ||
66 | + rsp.Lists[i] = userMsg | ||
67 | + } | ||
68 | + return | ||
69 | +} |
-
请 注册 或 登录 后发表评论