作者 yangfu

评论详情/列表

... ... @@ -12,6 +12,8 @@
|机会评论列表|完成|2019.11.21|/v1/chance/comments|
|我来评论|完成|2019.11.21|/v1/chance/iComment|
|我的评论|完成|2019.11.21|/v1/chance/iComments|
|评论详情-继续评论| |2019.11.21|/v1/chance/commentDetailsMulti|
|评论详情-不能评论| |2019.11.21|/v1/chance/commentDetailsSingle|
|我的点赞| |2019.11.|v1/chance/favorite|
|我的收藏| |2019.11.|v1/chance/favorite|
|消息中心|完成|2019.11.|v1/message/messageCenter|
... ...
... ... @@ -90,7 +90,8 @@ func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
if h.Uid == 0 {
h.Uid, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-uid"), 10, 64)
}
h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-companyid"), 10, 64)
h.CompanyId, _ = strconv.ParseInt(ctx.Input.Header("x-mmm-cid"), 10, 64)
log.Debug(common.AssertJson(h))
return h
}
... ... @@ -179,6 +180,7 @@ func CheckToken(ctx *context.Context) (result bool) {
if rsp.UserInfo != nil {
//设置附加数据
ctx.Request.Header.Add("x-mmm-uid", fmt.Sprintf("%v", rsp.UserInfo.UserId))
ctx.Request.Header.Add("x-mmm-cid", fmt.Sprintf("%v", rsp.UserInfo.CurrentCompanyId))
}
}
return
... ...
... ... @@ -72,6 +72,7 @@ func (this *ChanceController) Comments() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
request.SourceType = protocol.SourceType_Chance
msg = protocol.NewReturnResponse(chance.Comments(header, request))
}
... ... @@ -95,3 +96,45 @@ func (this *ChanceController) Favorite() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.Favorite(header, request))
}
//CommentDetailsSingle
//@router /commentDetailsSingle [post]
func (this *ChanceController) CommentDetailsSingle() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.CommentDetailsSingleRequest
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.CommentDetailsSingle(header, request))
}
//CommentDetailsMulti
//@router /commentDetailsMulti [post]
func (this *ChanceController) CommentDetailsMulti() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.CommentDetailsMultiRequest
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.CommentDetailsMulti(header, request))
}
... ...
... ... @@ -16,6 +16,7 @@ func (r *ChanceRepository) GetChanceById(id int64) (v *models.Chance, err error)
type IChanceFavoriteRepository interface {
GetChanceFavorites(userId, companyId int64, objectType, chanceType int, lastId int64, pageSize int) (v []*models.ChanceFavorite, total int, err error)
ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error)
}
var _ IChanceFavoriteRepository = (*ChanceFavoriteRepository)(nil)
... ... @@ -25,3 +26,6 @@ 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)
}
func (r *ChanceFavoriteRepository) ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) {
return models.ExitsChanceFavorite(userId, companyId, sourceId, objectType)
}
... ...
... ... @@ -3,13 +3,13 @@ package repository
import "opp/models"
type ICommendRepository interface {
GetCommends(companyId int, llastId int, pageSize int) (v []*models.Commend, total int, err error)
GetCommends(companyId int64, llastId int, pageSize int) (v []*models.Commend, total int, err error)
}
var _ ICommendRepository = (*CommendRepository)(nil)
type CommendRepository struct{}
func (r *CommendRepository) GetCommends(companyId int, lastId int, pageSize int) (v []*models.Commend, total int, err error) {
func (r *CommendRepository) GetCommends(companyId int64, lastId int, pageSize int) (v []*models.Commend, total int, err error) {
return models.GetCommends(companyId, lastId, pageSize)
}
... ...
... ... @@ -5,7 +5,7 @@ import "opp/models"
type ICommentRepository interface {
GetCommentById(id int64) (v *models.Comment, err error)
AddComment(m *models.Comment) (id int64, err error)
GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageSize int) (v []*models.Comment, total int, err error)
GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error)
}
var _ ICommentRepository = (*CommentRepository)(nil)
... ... @@ -20,6 +20,6 @@ func (r *CommentRepository) AddComment(m *models.Comment) (id int64, err error)
return models.AddComment(m)
}
func (r *CommentRepository) GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageSize int) (v []*models.Comment, total int, err error) {
func (r *CommentRepository) GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*models.Comment, total int, err error) {
return models.GetComments(userId, sourceType, sourceId, lastId, pageSize)
}
... ...
... ... @@ -15,6 +15,7 @@ var (
ChanceFavorite IChanceFavoriteRepository
Comment ICommentRepository
Message IMessageRepository
UserCompany IUserCompanyRepository
)
func init() {
... ... @@ -32,6 +33,7 @@ func InitRepository() {
Comment = &CommentRepository{}
Message = &MessageRepository{}
ChanceFavorite = &ChanceFavoriteRepository{}
UserCompany = &UserCompanyRepository{}
}
func InitRepositoryMock() {
... ...
... ... @@ -23,3 +23,15 @@ func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err er
func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) {
return models.UpdateUsersById(m)
}
type IUserCompanyRepository interface {
GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error)
}
var _ IUserCompanyRepository = (*UserCompanyRepository)(nil)
type UserCompanyRepository struct{}
func (r *UserCompanyRepository) GetUserCompanyByUserId(uid int64, companyId int64) (v *models.UserCompany, err error) {
return models.GetUserCompanyByUserId(uid, companyId)
}
... ...
... ... @@ -82,7 +82,7 @@ func DeleteChanceFavorite(id int64) (err error) {
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))
sql.Where(fmt.Sprintf("company_id=%d", companyId))
if chanceType > 0 {
sql.Where(fmt.Sprintf("chance_type=%d", chanceType))
}
... ... @@ -102,3 +102,13 @@ func GetChanceFavorites(userId, companyId int64, objectType, chanceType int, las
return
}
func ExitsChanceFavorite(userId, companyId int64, sourceId int64, objectType int) (exits bool, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite")
sql.Where(fmt.Sprintf("source_id=%d", sourceId)).
Where(fmt.Sprintf("user_id=%d", userId)).
Where(fmt.Sprintf("company_id=%d", companyId)).
Where(fmt.Sprintf("(object_type&%d)>0", objectType)).
Where(fmt.Sprintf("enable_status=1"))
return sql.QueryExists()
}
... ...
... ... @@ -12,10 +12,10 @@ import (
)
type Commend struct {
Id int64 `orm:"column(id);auto" description:"表彰编号"`
Id int64 `orm:"column(id);auto" description:"表彰编号"`
Content string `orm:"column(content);size(255)" description:"表彰内容"`
CommendAt time.Time `orm:"column(commend_at);type(timestamp)" description:"表彰时间"`
UserId int64 `orm:"column(user_id)" description:"表user.id 表彰用户id"`
UserId int64 `orm:"column(user_id)" description:"表user.id 表彰用户id"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"状态 1可见 2不可见"`
... ... @@ -156,14 +156,14 @@ func DeleteCommend(id int64) (err error) {
return
}
func GetCommends(companyId int,lastId int,pageSize int)(v []*Commend,total int, err error) {
sql :=mybeego.NewSqlExutor().Table("commend").Order("create_at desc")
sql.Where(fmt.Sprintf("company_id=%d",companyId))
if pageSize>0{
sql.Limit(0,pageSize)
func GetCommends(companyId int64, lastId int, pageSize int) (v []*Commend, total int, err error) {
sql := mybeego.NewSqlExutor().Table("commend").Order("create_at desc")
sql.Where(fmt.Sprintf("company_id=%d", companyId))
if pageSize > 0 {
sql.Limit(0, pageSize)
}
if lastId>0{
sql.Where(fmt.Sprintf("id>%d",lastId))
if lastId > 0 {
sql.Where(fmt.Sprintf("id>%d", lastId))
}
if total, err = sql.Querys(&v); err == nil {
return
... ...
... ... @@ -3,6 +3,7 @@ package models
import (
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
"reflect"
"strings"
... ... @@ -158,7 +159,7 @@ func DeleteComment(id int64) (err error) {
return
}
func GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageSize int) (v []*Comment, total int, err error) {
func GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*Comment, total int, err error) {
sql := mybeego.NewSqlExutor().Table("comment").Order("create_at desc")
if userId > 0 {
sql.Where(fmt.Sprintf("user_id=%d", userId))
... ... @@ -176,7 +177,11 @@ func GetComments(userId int64, sourceType int, sourceId int64, lastId int, pageS
sql.Where(fmt.Sprintf("id>%d", lastId))
}
if total, err = sql.Querys(&v); err == nil {
if total == 0 {
log.Debug(sql.Strings())
}
return
}
return
}
... ...
... ... @@ -11,13 +11,13 @@ import (
)
type Company struct {
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(40)"`
UserId int64 `orm:"column(user_id)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
Logo string `orm:"column(logo);size(255)"`
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(40)" description:"公司名称"`
Logo string `orm:"column(logo);size(255)" description:"公司log地址"`
AdminId int64 `orm:"column(admin_id)" description:"管理员用户id"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
}
func (t *Company) TableName() string {
... ...
... ... @@ -11,14 +11,20 @@ import (
)
type UserAuth struct {
Id int `orm:"column(id);auto"`
UserId int64 `orm:"column(user_id)" description:"表user.id "`
RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "`
RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp);auto_now_add" description:"refresh token 过期时间"`
AccessToken string `orm:"column(access_token);size(64)" description:"access_token "`
AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp);auto_now_add" description:"access token 过期时间"`
AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"`
AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp);auto_now_add" description:"auth_code过期时间"`
Id int `orm:"column(id);auto" description:"唯一编号"`
UserId int64 `orm:"column(user_id)" description:"表user.id "`
RefreshToken string `orm:"column(refresh_token);size(64)" description:"refresh token "`
RefreshTokenExp time.Time `orm:"column(refresh_token_exp);type(timestamp)" description:"refresh token 过期时间"`
AccessToken string `orm:"column(access_token);size(64)" description:"access_token "`
AccessTokenExp time.Time `orm:"column(access_token_exp);type(timestamp)" description:"access token 过期时间"`
AuthCode string `orm:"column(auth_code);size(64)" description:"auth_code"`
AuthCodeExp time.Time `orm:"column(auth_code_exp);type(timestamp)" description:"auth_code过期时间"`
DeviceType int8 `orm:"column(device_type)" description:"设备类型 0:ios 1:安卓 2:web "`
ClientId string `orm:"column(client_id);size(100)" description:"设备识别码 推送标识"`
DeviceToken string `orm:"column(device_token);size(100)" description:"设备识别码 推送标识"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
CurrentCompanyId int64 `orm:"column(current_company_id)" description:"当前登录的公司id "`
}
func (t *UserAuth) TableName() string {
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type UserCompany struct {
Id int `orm:"column(id);auto" description:"唯一标识"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
DepartmentId int `orm:"column(department_id)" description:"部门id"`
PositionId int `orm:"column(position_id)" description:"职位id"`
ChanceTotal int `orm:"column(chance_total)" description:"发表机会数"`
CommentTotal int `orm:"column(comment_total)" description:"发表评论总数"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
}
func (t *UserCompany) TableName() string {
return "user_company"
}
func init() {
orm.RegisterModel(new(UserCompany))
}
// AddUserCompany insert a new UserCompany into database and returns
// last inserted Id on success.
func AddUserCompany(m *UserCompany) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetUserCompanyById retrieves UserCompany by Id. Returns error if
// Id doesn't exist
func GetUserCompanyById(id int) (v *UserCompany, err error) {
o := orm.NewOrm()
v = &UserCompany{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateUserCompany updates UserCompany by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserCompanyById(m *UserCompany) (err error) {
o := orm.NewOrm()
v := UserCompany{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteUserCompany deletes UserCompany by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserCompany(id int) (err error) {
o := orm.NewOrm()
v := UserCompany{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserCompany{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
// GetUserAuthById retrieves UserAuth by Id. Returns error if
// Id doesn't exist
func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err error) {
o := orm.NewOrm()
sql := "select * from user_company where user_id=? and company_id=?" //
if err = o.Raw(sql, uid, companyId).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -11,14 +11,14 @@ import (
)
type User struct {
Id int64 `orm:"column(id);pk" description:"用户id"`
NickName string `orm:"column(nick_name);size(100)" description:"昵称"`
Phone string `orm:"column(phone);size(40)" description:"手机号码"`
Passwd string `orm:"column(passwd);size(128)" description:"密码"`
Icon string `orm:"column(icon);size(255)" description:"头像"`
CompanyId int `orm:"column(company_id)" description:"公司Id"`
DepartmentId int `orm:"column(department_id)" description:"部门id"`
PositionId int `orm:"column(position_id)" description:"职位id"`
Id int64 `orm:"column(id);pk" description:"用户id"`
NickName string `orm:"column(nick_name);size(100)" description:"昵称"`
Phone string `orm:"column(phone);size(40)" description:"手机号码"`
Passwd string `orm:"column(passwd);size(128)" description:"密码"`
Icon string `orm:"column(icon);size(255)" description:"头像"`
//CompanyId int `orm:"column(company_id)" description:"公司Id"`
//DepartmentId int `orm:"column(department_id)" description:"部门id"`
//PositionId int `orm:"column(position_id)" description:"职位id"`
CsAccount int64 `orm:"column(cs_account)" description:"客服有话说ID"`
IsKefu int8 `orm:"column(is_kefu)" description:"是否是客服 0:否 1:是"`
ImToken string `orm:"column(im_token);size(128)" description:"网易云token"`
... ...
... ... @@ -6,8 +6,9 @@ import "opp/models"
//用户基础聚合
type UserBaseInfoAggregation struct {
User *models.User
Company *models.Company
Department *models.Department
Position *models.Position
User *models.User
Company *models.Company
Department *models.Department
Position *models.Position
UserCompany *models.UserCompany
}
... ...
... ... @@ -20,8 +20,8 @@ type ICommentResponse struct {
/*IComments */
type ICommentsRequest struct {
LastId int `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type ICommentsResponse struct {
Comments []*IComments `json:"comments"`
... ... @@ -35,9 +35,10 @@ type IComments struct {
/*机会评论*/
type CommentsRequest struct {
LastId int `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
SourceId int64 `json:"id" valid:"Required"`
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
SourceId int64 `json:"id" valid:"Required"`
SourceType int
}
type CommentsResponse struct {
Total int `json:"total"`
... ... @@ -53,4 +54,24 @@ type Comments struct {
CommentTotal int `json:"commentTotal"`
ZanTotal int `json:"zanTotal"`
CreateTime int64 `json:"createTime"`
IsZan int `json:"is_zan"` //0:未点赞 1:点赞
}
/*CommentDetailsMulti */
type CommentDetailsMultiRequest struct {
SourceId int64 `json:"cid"`
LastId int64 `json:"commentLastId"`
PageSize int `json:"commentPageSize" valid:"Required"`
}
type CommentDetailsMultiResponse struct {
Comment *Comments `json:"comment"`
Comments []*Comments `json:"comments"`
}
/*CommentDetailsSingle */
type CommentDetailsSingleRequest struct {
Id int64 `json:"cid" valid:"Required"`
}
type CommentDetailsSingleResponse struct {
Comment *Comments `json:"comment"`
}
... ...
... ... @@ -49,6 +49,22 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsSingle",
Router: `/commentDetailsSingle`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Comments",
Router: `/comments`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -8,18 +8,21 @@ import (
"sync"
)
func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation, err error) {
func GetUserBaseInfoAggregation(uid int64, companyId int64) (v *protocol.UserBaseInfoAggregation, err error) {
v = &protocol.UserBaseInfoAggregation{}
var wg sync.WaitGroup
if v.User, err = repository.User.GetUsersById(uid); err != nil {
log.Error(err)
return
}
if v.UserCompany, err = repository.UserCompany.GetUserCompanyByUserId(uid, companyId); err != nil {
log.Error(err)
return
}
wg.Add(3)
go func() {
defer wg.Done()
if v.Company, err = repository.Company.GetCompanyById(int64(v.User.CompanyId)); err != nil {
if v.Company, err = repository.Company.GetCompanyById(int64(v.UserCompany.CompanyId)); err != nil {
log.Error(err)
return
}
... ... @@ -27,7 +30,7 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation,
go func() {
defer wg.Done()
if v.Department, err = repository.Department.GetDepartmentById(v.User.DepartmentId); err != nil {
if v.Department, err = repository.Department.GetDepartmentById(v.UserCompany.DepartmentId); err != nil {
log.Error(err)
return
}
... ... @@ -35,7 +38,7 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation,
go func() {
defer wg.Done()
if v.Position, err = repository.Position.GetPositionById(v.User.PositionId); err != nil {
if v.Position, err = repository.Position.GetPositionById(v.UserCompany.PositionId); err != nil {
log.Error(err)
return
}
... ... @@ -44,11 +47,11 @@ func GetUserBaseInfoAggregation(uid int64) (v *protocol.UserBaseInfoAggregation,
return
}
func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) {
func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err error) {
var (
agg *protocol.UserBaseInfoAggregation
)
if agg, err = GetUserBaseInfoAggregation(uid); err != nil {
if agg, err = GetUserBaseInfoAggregation(uid, companyId); err != nil {
return
}
v = &protocol.BaseUserInfo{
... ... @@ -60,7 +63,7 @@ func GetUserBaseInfo(uid int64) (v *protocol.BaseUserInfo, err error) {
return
}
func GetChance(chanceId int64) (v *protocol.Chance, err error) {
func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error) {
var (
c *models.Chance
baseUserInfo *protocol.BaseUserInfo
... ... @@ -69,7 +72,7 @@ func GetChance(chanceId int64) (v *protocol.Chance, err error) {
if c, err = repository.Chance.GetChanceById(chanceId); err != nil {
return
}
if baseUserInfo, err = GetUserBaseInfo(c.UserId); err != nil {
if baseUserInfo, err = GetUserBaseInfo(c.UserId, companyId); err != nil {
return
}
v = &protocol.Chance{
... ...
... ... @@ -33,7 +33,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest)
}
switch f.SourceType {
case protocol.SourceType_Chance:
chance, err = agg.GetChance(f.SourceId)
chance, err = agg.GetChance(f.SourceId, f.CompanyId)
if err != nil {
log.Error(err)
return
... ...
... ... @@ -18,6 +18,8 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
comment *models.Comment
baseUserInfo *protocol.BaseUserInfo
chance *models.Chance
updateTable interface{}
updateMap = make(map[string]interface{})
)
switch request.SourceType {
case protocol.SourceType_Chance:
... ... @@ -25,15 +27,19 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
log.Error(err)
return
}
updateTable = chance
updateMap["CommentTotal"] = chance.CommentTotal + 1
case protocol.SourceType_Comment:
if _, err = repository.Comment.GetCommentById(request.Id); err != nil {
if comment, err = repository.Comment.GetCommentById(request.Id); err != nil {
log.Error(err)
return
}
updateTable = comment
updateMap["CommentTotal"] = comment.CommentTotal + 1
default:
err = fmt.Errorf("unknow source_type:%v", request.SourceType)
}
comment = &models.Comment{
newComment := &models.Comment{
Id: idgen.Next(),
UserId: header.Uid,
SourceType: int8(request.SourceType),
... ... @@ -41,22 +47,21 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
CreateAt: time.Now(),
SourceId: request.Id,
}
if _, err = repository.Comment.AddComment(comment); err != nil {
if _, err = repository.Comment.AddComment(newComment); err != nil {
log.Error(err)
return
}
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid); err != nil {
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil {
log.Error(err)
return
}
if chance != nil {
//TODO:sql更新
utils.UpdateTableByMap(chance, map[string]interface{}{"CommentTotal": chance.CommentTotal + 1})
if updateTable != nil {
utils.UpdateTableByMap(updateTable, updateMap)
}
rsp = &protocol.ICommentResponse{
Id: comment.Id,
Content: comment.Content,
CreateTime: comment.CreateAt.Unix(),
Id: newComment.Id,
Content: newComment.Content,
CreateTime: newComment.CreateAt.Unix(),
Provider: baseUserInfo,
}
return
... ... @@ -76,7 +81,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques
rsp = &protocol.ICommentsResponse{
Total: total,
}
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid); err != nil {
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil {
log.Error(err)
return
}
... ... @@ -105,8 +110,9 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
comments []*models.Comment
baseUserInfo *protocol.BaseUserInfo
total int
exists bool
)
if comments, total, err = repository.Comment.GetComments(header.Uid, protocol.SourceType_Chance, request.SourceId, request.LastId, request.PageSize); err != nil {
if comments, total, err = repository.Comment.GetComments(header.Uid, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
log.Error(err)
return
}
... ... @@ -115,7 +121,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
}
for i := range comments {
comment := comments[i]
if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId); err != nil {
if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId, header.CompanyId); err != nil {
log.Error(err)
//return
}
... ... @@ -128,7 +134,63 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
}
if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.ObjectType_Zan); exists {
item.IsZan = 1
}
rsp.Comments = append(rsp.Comments, item)
}
return
}
//评论详情-不带地下评论
func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.CommentDetailsSingleRequest) (rsp *protocol.CommentDetailsSingleResponse, err error) {
var (
comment *models.Comment
baseUserInfo *protocol.BaseUserInfo
exists bool
)
rsp = &protocol.CommentDetailsSingleResponse{}
if comment, err = repository.Comment.GetCommentById(request.Id); err != nil {
log.Error(err)
return
}
if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId, header.CompanyId); err != nil {
log.Error(err)
//return
}
rsp.Comment = &protocol.Comments{
Id: comment.Id,
Provider: baseUserInfo,
Content: comment.Content,
CreateTime: comment.CreateAt.Unix(),
ViewTotal: comment.ViewTotal,
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
}
if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.ObjectType_Zan); exists {
rsp.Comment.IsZan = 1
}
return
}
//评论详情-带底下评论
func CommentDetailsMulti(header *protocol.RequestHeader, request *protocol.CommentDetailsMultiRequest) (rsp *protocol.CommentDetailsMultiResponse, err error) {
var (
commentDetailSingle *protocol.CommentDetailsSingleResponse
commentDetailMulti *protocol.CommentsResponse
)
rsp = &protocol.CommentDetailsMultiResponse{}
//LastId=0时(返回comment对象和comments列表),commentLastId>0(返回comments列表)
if request.LastId == 0 {
if commentDetailSingle, err = CommentDetailsSingle(header, &protocol.CommentDetailsSingleRequest{Id: request.SourceId}); err != nil {
return
}
rsp.Comment = commentDetailSingle.Comment
}
if commentDetailMulti, err = Comments(header, &protocol.CommentsRequest{LastId: request.LastId, SourceId: request.SourceId, PageSize: request.PageSize, SourceType: protocol.SourceType_Comment}); err != nil {
log.Error(err)
return
}
rsp.Comments = commentDetailMulti.Comments
return
}
... ...
... ... @@ -19,12 +19,12 @@ func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) (
if err != nil {
return
}
if commends, rsp.Total, err = repository.Commend.GetCommends(user.CompanyId, request.LastId, request.PageSize); err != nil {
if commends, rsp.Total, err = repository.Commend.GetCommends(header.CompanyId, request.LastId, request.PageSize); err != nil {
return
}
for i := 0; i < len(commends); i++ {
c := commends[i]
userBaseInfo, err = agg.GetUserBaseInfoAggregation(c.UserId)
userBaseInfo, err = agg.GetUserBaseInfoAggregation(c.UserId, header.CompanyId)
if err != nil {
continue
}
... ...