|
@@ -31,14 +31,14 @@ func NewFollowupCommentService(ctx context.Context) (svc *followupCommentService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 跟进记录留言信息列表
|
|
// 跟进记录留言信息列表
|
|
|
-func (s *followupCommentService) GetList(req *model.SearchPlatFollowupCommentReq) (total int, followupCommentList []*model.PlatFollowupComment, err error) {
|
|
|
|
|
|
|
+func (s *followupCommentService) GetList(req *model.SearchPlatFollowupCommentReq) (total int, followupCommentList []*model.FollowupCommentEx, err error) {
|
|
|
followupCommentModel := s.Dao.M
|
|
followupCommentModel := s.Dao.M
|
|
|
|
|
|
|
|
if req.FollowId != "" {
|
|
if req.FollowId != "" {
|
|
|
- followupCommentModel = followupCommentModel.Where("follow_id", req.FollowId)
|
|
|
|
|
|
|
+ followupCommentModel = followupCommentModel.Where("plat_followup_comment.follow_id", req.FollowId)
|
|
|
}
|
|
}
|
|
|
if req.Pid != "" {
|
|
if req.Pid != "" {
|
|
|
- followupCommentModel = followupCommentModel.Where("pid", req.Pid)
|
|
|
|
|
|
|
+ followupCommentModel = followupCommentModel.Where("plat_followup_comment.pid", req.Pid)
|
|
|
}
|
|
}
|
|
|
total, err = followupCommentModel.Count()
|
|
total, err = followupCommentModel.Count()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -47,11 +47,122 @@ func (s *followupCommentService) GetList(req *model.SearchPlatFollowupCommentReq
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = followupCommentModel.Order("created_time DESC").Scan(&followupCommentList)
|
|
|
|
|
|
|
+ err = followupCommentModel.Order("plat_followup_comment.created_time DESC").Scan(&followupCommentList)
|
|
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = myerrors.DbError("获取数据失败。")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取回复数据
|
|
|
|
|
+ var replyComments []*model.FollowupCommentEx
|
|
|
|
|
+ err = followupCommentModel.InnerJoin("plat_followup_comment b", "b.pid=plat_followup_comment.id").Fields("b.*").Order("b.id ASC").Scan(&replyComments)
|
|
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = myerrors.DbError("获取数据失败。")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ commentMap := make(map[int]*model.FollowupCommentEx)
|
|
|
|
|
+ for index, comment := range followupCommentList {
|
|
|
|
|
+ commentMap[comment.Id] = followupCommentList[index]
|
|
|
|
|
+ }
|
|
|
|
|
+ // 构造回复数据
|
|
|
|
|
+ for _, comment := range replyComments {
|
|
|
|
|
+ if commentMap[comment.Pid].ReplyComments == nil {
|
|
|
|
|
+ commentMap[comment.Pid].ReplyComments = make([]*model.FollowupCommentEx, 0)
|
|
|
|
|
+ }
|
|
|
|
|
+ commentMap[comment.Pid].ReplyComments = append(commentMap[comment.Pid].ReplyComments, comment)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// NeedReplyList 本人需要回复的评论列表
|
|
|
|
|
+func (s *followupCommentService) NeedReplyList(req *model.SearchNeedReplyCommentsReq) (total int, followupCommentList []*model.PlatFollowupComment, err error) {
|
|
|
|
|
+ followupModel := s.FollowupDao.As("a").M.InnerJoin(plat.PlatFollowupComment.Table+" b", "a.id=b.follow_id").LeftJoin(plat.PlatFollowupComment.Table+" reply", "b.id=reply.pid")
|
|
|
|
|
+ // 本人创建的评论
|
|
|
|
|
+ followupModel = followupModel.Where("a."+s.Dao.C.CreatedBy, s.GetCxtUserId())
|
|
|
|
|
+ // 第一级的 未回复的 评论
|
|
|
|
|
+ followupModel = followupModel.Where("(b.pid=0 OR b.pid IS NULL) AND reply.id IS NULL")
|
|
|
|
|
+ // 分组去重
|
|
|
|
|
+ followupModel = followupModel.Group("b.id")
|
|
|
|
|
+
|
|
|
|
|
+ total, err = followupModel.Count()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = myerrors.DbError("获取总行数失败。")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ err = followupModel.Order("b.created_time ASC").Fields("b.*").Scan(&followupCommentList)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 添加信息
|
|
|
|
|
|
|
+// NeedReplyCount 本人需要回复的评论数量
|
|
|
|
|
+func (s *followupCommentService) NeedReplyCount(req *model.SearchNeedReplyCommentsReq) (total int, err error) {
|
|
|
|
|
+ followupModel := s.FollowupDao.As("a").M.InnerJoin(plat.PlatFollowupComment.Table+" b", "a.id=b.follow_id").LeftJoin(plat.PlatFollowupComment.Table+" reply", "b.id=reply.pid")
|
|
|
|
|
+ // 本人创建的评论
|
|
|
|
|
+ followupModel = followupModel.Where("a."+s.Dao.C.CreatedBy, s.GetCxtUserId())
|
|
|
|
|
+ // 第一级的 未回复的 评论
|
|
|
|
|
+ followupModel = followupModel.Where("(b.pid=0 OR b.pid IS NULL) AND reply.id IS NULL")
|
|
|
|
|
+ // 分组去重
|
|
|
|
|
+ followupModel = followupModel.Group("b.id")
|
|
|
|
|
+
|
|
|
|
|
+ total, err = followupModel.Count()
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = myerrors.DbError("获取总行数失败。")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// LatestComments 获取最新50条数据
|
|
|
|
|
+func (s *followupCommentService) LatestComments(req *model.SearchPlatFollowupCommentReq) (total int, followupCommentList []*model.FollowupCommentEx2, err error) {
|
|
|
|
|
+ // 默认50条数据
|
|
|
|
|
+ if req.PageSize == 0 {
|
|
|
|
|
+ req.PageSize = 50
|
|
|
|
|
+ }
|
|
|
|
|
+ if req.PageNum == 0 {
|
|
|
|
|
+ req.PageNum = 1
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ followupCommentModel := s.Dao.M.InnerJoin("plat_followup c", "plat_followup_comment.follow_id=c.id")
|
|
|
|
|
+ // 只查询第一层评论
|
|
|
|
|
+ followupCommentModel = followupCommentModel.Where("plat_followup_comment.pid=0 OR plat_followup_comment.pid IS NULL")
|
|
|
|
|
+
|
|
|
|
|
+ err = followupCommentModel.Order("plat_followup_comment.created_time DESC").Page(req.GetPage()).Fields("plat_followup_comment.*,c.target_type,c.target_name").Scan(&followupCommentList)
|
|
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = myerrors.DbError("获取数据失败。")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // 获取回复数据
|
|
|
|
|
+ var replyComments []*model.FollowupCommentEx2
|
|
|
|
|
+ err = followupCommentModel.InnerJoin("plat_followup_comment b", "b.pid=plat_followup_comment.id").Fields("b.*,c.target_type,c.target_name").Order("b.id ASC").Scan(&replyComments)
|
|
|
|
|
+ if err != nil && err != sql.ErrNoRows {
|
|
|
|
|
+ g.Log().Error(err)
|
|
|
|
|
+ err = myerrors.DbError("获取数据失败。")
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ commentMap := make(map[int]*model.FollowupCommentEx2)
|
|
|
|
|
+ for index, comment := range followupCommentList {
|
|
|
|
|
+ commentMap[comment.Id] = followupCommentList[index]
|
|
|
|
|
+ }
|
|
|
|
|
+ // 构造回复数据
|
|
|
|
|
+ for _, comment := range replyComments {
|
|
|
|
|
+ if commentMap[comment.Pid].ReplyComments == nil {
|
|
|
|
|
+ commentMap[comment.Pid].ReplyComments = make([]*model.FollowupCommentEx2, 0)
|
|
|
|
|
+ }
|
|
|
|
|
+ commentMap[comment.Pid].ReplyComments = append(commentMap[comment.Pid].ReplyComments, comment)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 添加评论
|
|
|
func (s *followupCommentService) Create(req *model.AddPlatFollowupCommentReq) (err error) {
|
|
func (s *followupCommentService) Create(req *model.AddPlatFollowupCommentReq) (err error) {
|
|
|
followup, err := s.FollowupDao.WherePri(req.FollowId).One()
|
|
followup, err := s.FollowupDao.WherePri(req.FollowId).One()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -97,3 +208,21 @@ func (s *followupCommentService) Create(req *model.AddPlatFollowupCommentReq) (e
|
|
|
|
|
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// Reply 回复评论
|
|
|
|
|
+func (s *followupCommentService) Reply(req *model.AddPlatFollowupCommentReq) (err error) {
|
|
|
|
|
+ platFollowupComment := new(model.PlatFollowupComment)
|
|
|
|
|
+ if err = gconv.Struct(req, platFollowupComment); err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ // 填充创建信息
|
|
|
|
|
+ service.SetCreatedInfo(platFollowupComment, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
|
|
+ // 填充更新信息
|
|
|
|
|
+ //service.SetUpdatedInfo(platFollowupComment, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
|
|
+ _, err = s.Dao.Insert(platFollowupComment)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return
|
|
|
|
|
+}
|