作者 yangfu

增加功能 我的收藏,我的赞

... ... @@ -12,17 +12,16 @@
|机会评论列表|完成|2019.11.21|/v1/chance/comments|
|我来评论|完成|2019.11.21|/v1/chance/iComment|
|我的评论|完成|2019.11.21|/v1/chance/iComments|
|我的点赞| |2019.11.| |
|我的收藏| |2019.11.| |
|我的点赞| |2019.11.|v1/chance/favorite|
|我的收藏| |2019.11.|v1/chance/favorite|
|消息中心|完成|2019.11.|v1/message/messageCenter|
|标记已读|完成|2019.11.|v1/message/msgCenterRead|
|标记全部已读|完成|2019.11.|v1/message/msgCenterAllRead|
|互动消息-点赞| |2019.11.| |
|互动消息-评论| |2019.11.| |
|互动消息-点赞| |2019.11.|v1/message/msgInteractive|
|互动消息-评论| |2019.11.|v1/message/msgInteractive|
|我提交的机会| |2019.11.| |
|我审核的机会| |2019.11.| |
|待抓住机会列表| |2019.11. |
|机会池| |2019.11.| |
|提交机会| |2019.11.| |
|机会审核消息| |2019.11.| |
|机会互动消息| |2019.11.| |
|机会审核消息| |2019.11.|v1/message/msgInteractive|
... ...
... ... @@ -74,3 +74,24 @@ func (this *ChanceController) Comments() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.Comments(header, request))
}
//Favorite
// @router /favorite [post]
func (this *ChanceController) Favorite() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.FavoriteRequest
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.Favorite(header, request))
}
... ...
... ... @@ -74,3 +74,24 @@ func (this *MessageController) MsgCenterAllRead() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(message.MsgCenterAllRead(header, request))
}
//MsgInteractive
// @router /msgInteractive [post]
func (this *MessageController) MsgInteractive() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MsgInteractiveRequest
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(message.MsgInteractive(header, request))
}
... ...
... ... @@ -8,6 +8,7 @@ require (
github.com/gorilla/websocket v1.4.1
github.com/klauspost/cpuid v1.2.1 // indirect
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/common v0.6.0
github.com/satori/go.uuid v1.2.0
github.com/sony/sonyflake v1.0.0
gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
... ...
... ... @@ -13,3 +13,15 @@ type ChanceRepository struct{}
func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error) {
return models.GetChanceById(id)
}
type IChanceFavoriteRepository interface {
GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error)
}
var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil)
type ChanceFavoriteRepository struct{}
func (r *ChanceFavoriteRepository) GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error) {
return models.GetChanceFavorites(userId, companyId, objectType, chanceType, lastId, pageSize)
}
... ...
... ... @@ -5,6 +5,7 @@ import "opp/models"
type IMessageRepository interface {
GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error)
UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error)
GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error)
}
var _ IMessageRepository = (*MessageRepository)(nil)
... ... @@ -18,3 +19,7 @@ func (r *MessageRepository) GetUserMsgTotals(userId int64, companyId int64, msgT
func (r *MessageRepository) UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int64) (err error) {
return models.UpdateUserMsgSetRead(userId, companyId, msgType, msgId)
}
func (r *MessageRepository) GetUserMsgs(userId, companyId int64, msgType, sourceType int, lastId int64, pageSize int) (v []*models.UserMsg, total int, err error) {
return models.GetUserMsgs(userId, companyId, msgType, sourceType, lastId, pageSize)
}
... ...
... ... @@ -12,6 +12,7 @@ var (
Department IDepartmentRepository
Position IPositionRepository
Chance IChanceRepository
ChanceFavorite IChanceFavoriteRepository
Comment ICommentRepository
Message IMessageRepository
)
... ... @@ -30,6 +31,7 @@ func InitRepository() {
Chance = &ChanceRepository{}
Comment = &CommentRepository{}
Message = &MessageRepository{}
ChanceFavorite = &ChanceFavoriteRepository{}
}
func InitRepositoryMock() {
... ...
... ... @@ -14,8 +14,9 @@ type Chance struct {
Id int64 `orm:"column(id);pk" description:"id 主键"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"`
DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "`
ChanceType int `orm:"column(chance_type)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "`
Content string `orm:"column(content)" description:"内容"`
ViewTotal int `orm:"column(view_total)" description:"浏览总数"`
CommentTotal int `orm:"column(comment_total)" description:"评论总数"`
ZanTotal int `orm:"column(zan_total)" description:"点赞总数"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待审核 1:被退回 2:已通过 3:草稿箱"`
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -13,10 +12,11 @@ import (
type ChanceFavorite struct {
Id int64 `orm:"column(id);pk" description:"点赞编号"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
CompanyId int64 `orm:"column(company_id)" description:"company.id 公司编号"`
ObjectType int `orm:"column(object_type)" description:"类型 1:点赞 2:收藏"`
SourceType int `orm:"column(source_type)" description:"来源类型 1:机会 2:评论"`
SourceId int64 `orm:"column(source_id)" description:"来源id 机会编号/评论编号"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号 - 附加 "`
ChanceType int `orm:"column(chance_type)" description:"机会类型编号 - 附加 "`
EnableStatus int `orm:"column(enable_status)" description:"1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp);null" description:"删除时间"`
... ... @@ -49,84 +49,6 @@ func GetChanceFavoriteById(id int64) (v *ChanceFavorite, err error) {
return nil, err
}
// GetAllChanceFavorite retrieves all ChanceFavorite matches certain condition. Returns empty list if
// no records exist
func GetAllChanceFavorite(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(ChanceFavorite))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []ChanceFavorite
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateChanceFavorite updates ChanceFavorite by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceFavoriteById(m *ChanceFavorite) (err error) {
... ... @@ -156,3 +78,27 @@ func DeleteChanceFavorite(id int64) (err error) {
}
return
}
func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc")
sql.Where(fmt.Sprintf("user_id=%d", userId))
sql.Where(fmt.Sprintf("company_id=%d", userId))
if chanceType > 0 {
sql.Where(fmt.Sprintf("chance_type=%d", chanceType))
}
if objectType > 0 {
sql.Where(fmt.Sprintf("object_type&%d>0", objectType))
}
if pageSize > 0 {
sql.Limit(0, pageSize)
}
if lastId > 0 {
sql.Where(fmt.Sprintf("id>%d", lastId))
}
if total, err = sql.Querys(&v); err == nil {
return
}
log.Error(sql.Strings())
return
}
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -17,6 +15,7 @@ type UserMsg struct {
MsgType int `orm:"column(msg_type)" description:"消息类型 1.公司公告 2.表彰通知 4.互动消息 8.机会审核"`
Message string `orm:"column(message)" description:"消息内容"`
SourceId int64 `orm:"column(source_id)" description:"来源id (机会编号 /评论编号)"`
SourceType int `orm:"column(source_type)"`
IsPublic int8 `orm:"column(is_public)" description:"1:公开 0:不公开"`
IsRead int8 `orm:"column(is_read)" description:"1:已读 0:未读"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"`
... ... @@ -49,84 +48,6 @@ func GetUserMsgById(id int64) (v *UserMsg, err error) {
return nil, err
}
// GetAllUserMsg retrieves all UserMsg matches certain condition. Returns empty list if
// no records exist
func GetAllUserMsg(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(UserMsg))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []UserMsg
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateUserMsg updates UserMsg by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserMsgById(m *UserMsg) (err error) {
... ... @@ -183,3 +104,25 @@ func UpdateUserMsgSetRead(userId int64, companyId int64, msgType int, msgId int6
}
return
}
func GetUserMsgs(userId, companyId int64, msgType int, sourceType int, lastId int64, pageSize int) (v []*UserMsg, total int, err error) {
sql := mybeego.NewSqlExutor().Table("user_msg").Order("create_at desc")
if lastId > 0 {
sql.Where(fmt.Sprintf("id>%d", lastId))
}
if msgType > 0 {
sql.Where(fmt.Sprintf("msg_type=%d", msgType))
}
sql.Where(fmt.Sprintf("receive_user_id=%d", userId))
sql.Where(fmt.Sprintf("company_id=%d", companyId))
if sourceType > 0 {
sql.Where(fmt.Sprintf("source_type=%d", sourceType))
}
if pageSize > 0 {
sql.Limit(0, pageSize)
}
if total, err = sql.Querys(&v); err == nil {
return
}
return
}
... ...
package protocol
const (
ObjectType_Zan = 1
ObjectType_Collect = 2
)
/*Favorite */
type FavoriteRequest struct {
ObjectType int `json:"object_type" valid:"Required"` //收藏 点赞
ChanceType int `json:"chance_type" valid:"Required"`
//TagId int `json:"tag_id"` //标签id
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type FavoriteResponse struct {
Total int `json:"total"`
Lists []*ChanceFavorite `json:"lists"`
}
type ChanceFavorite struct {
Id int64 `json:"id"`
Favorite interface{} `json:"favorite"`
}
type Chance struct {
Id int64 `json:"id"`
Provider *BaseUserInfo `json:"provider"`
IsCollect bool `json:"is_collect"`
IsZan bool `json:"is_zan"`
Content string `json:"content"`
ChanceType int `json:"chance_type"`
//图片
//视频
//语音
ViewTotal int `json:"view_total"`
CommentTotal int `json:"comment_total"`
ZanTotal int `json:"zan_total"`
}
... ...
... ... @@ -49,3 +49,24 @@ type MsgCenterAllReadRequest struct {
}
type MsgCenterAllReadResponse struct {
}
/*互动消息*/
type MsgInteractiveRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
MsgType int `json:"msgType" valid:"Required"`
SourceType int `json:"sourceType" valid:"Required"`
}
type MsgInteractiveResponse struct {
Lists []*UserMsg `json:"lists"`
Total int `json:"total"`
}
type UserMsg struct {
Id int64 `json:"msgId"`
SourceType int `json:"msgType"`
Content string `json:"content"`
CreateAt int64 `json:"msgTime"`
IsRead int `json:"isRead"`
//机会 //评论
}
... ...
... ... @@ -57,6 +57,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Favorite",
Router: `/favorite`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "IComment",
Router: `/iComment`,
AllowHTTPMethods: []string{"post"},
... ... @@ -103,6 +111,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"],
beego.ControllerComments{
Method: "MsgInteractive",
Router: `/msgInteractive`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Image",
... ...
... ... @@ -3,6 +3,7 @@ package agg
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/models"
"opp/protocol"
"sync"
)
... ... @@ -58,3 +59,28 @@ func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) {
}
return
}
func GetChance(chanceId int64) (v *protocol.Chance, err error) {
var (
c *models.Chance
baseUserInfo *protocol.BaseUserInfo
)
if c, err = repository.Chance.GetChanceById(chanceId); err != nil {
return
}
if baseUserInfo, err = GetUserBaseInfo(c.UserId); err != nil {
return
}
v = &protocol.Chance{
Id: c.Id,
Provider: baseUserInfo,
Content: c.Content,
ChanceType: c.ChanceType,
ViewTotal: c.ViewTotal,
CommentTotal: c.CommentTotal,
ZanTotal: c.ZanTotal,
}
return
}
... ...
package chance
import (
"github.com/prometheus/common/log"
"opp/internal/repository"
"opp/models"
"opp/protocol"
"opp/services/agg"
)
func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) (rsp *protocol.FavoriteResponse, err error) {
var (
favorites []*models.ChanceFavorite
chance *protocol.Chance
)
rsp = &protocol.FavoriteResponse{}
favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites(
header.Uid,
header.CompanyId,
request.ObjectType,
request.ChanceType,
request.LastId,
request.PageSize)
if err != nil {
log.Error(err)
return
}
rsp.Lists = make([]*protocol.ChanceFavorite, len(favorites))
for i := range favorites {
f := favorites[i]
item := &protocol.ChanceFavorite{
Id: f.Id,
}
switch f.SourceType {
case protocol.SourceType_Chance:
chance, err = agg.GetChance(f.SourceId)
if err != nil {
log.Error(err)
return
}
chance.IsZan = (f.ObjectType & protocol.ObjectType_Zan) == protocol.ObjectType_Zan
chance.IsCollect = (f.ObjectType & protocol.ObjectType_Collect) == protocol.ObjectType_Collect
item.Favorite = chance
case protocol.SourceType_Comment:
}
rsp.Lists[i] = item
}
return
}
... ...
... ... @@ -3,6 +3,7 @@ package message
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/models"
"opp/protocol"
)
... ... @@ -33,3 +34,36 @@ func MsgCenterAllRead(header *protocol.RequestHeader, request *protocol.MsgCente
}
return
}
//互动消息
func MsgInteractive(header *protocol.RequestHeader, request *protocol.MsgInteractiveRequest) (rsp *protocol.MsgInteractiveResponse, err error) {
var (
userMsgs []*models.UserMsg
)
rsp = &protocol.MsgInteractiveResponse{}
userMsgs, rsp.Total, err = repository.Message.GetUserMsgs(header.Uid, header.CompanyId, request.MsgType, request.SourceType, request.LastId, request.PageSize)
if err != nil {
log.Error(err)
return
}
if len(userMsgs) == 0 {
return
}
rsp.Lists = make([]*protocol.UserMsg, len(userMsgs))
for i := range userMsgs {
msg := userMsgs[i]
userMsg := &protocol.UserMsg{
Id: msg.Id,
Content: msg.Message,
CreateAt: msg.CreateAt.Unix(),
IsRead: int(msg.IsRead),
SourceType: msg.SourceType,
}
switch msg.SourceType {
case protocol.SourceType_Chance:
case protocol.SourceType_Comment:
}
rsp.Lists[i] = userMsg
}
return
}
... ...