|
@@ -6,10 +6,9 @@ import (
|
|
|
"hongze/hongze_yb/global"
|
|
|
reqComment "hongze/hongze_yb/models/request/comment"
|
|
|
"hongze/hongze_yb/models/response"
|
|
|
- report "hongze/hongze_yb/models/tables/rddp/report"
|
|
|
- "hongze/hongze_yb/models/tables/rddp/report_chapter"
|
|
|
"hongze/hongze_yb/models/tables/wx_user"
|
|
|
"hongze/hongze_yb/models/tables/yb_comment"
|
|
|
+ "hongze/hongze_yb/services"
|
|
|
"hongze/hongze_yb/services/user"
|
|
|
"hongze/hongze_yb/services/wx_app"
|
|
|
"hongze/hongze_yb/utils"
|
|
@@ -33,52 +32,35 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
|
|
|
err = errors.New("请输入留言内容")
|
|
|
return
|
|
|
}
|
|
|
- if req.ReportId <= 0 && req.ReportChapterId <= 0 {
|
|
|
- err = errors.New("请输入报告ID")
|
|
|
- return
|
|
|
- }
|
|
|
+ reportId := req.ReportId
|
|
|
+ reportChapterId := req.ReportChapterId
|
|
|
+
|
|
|
if req.SourceAgent == 0 {
|
|
|
err = errors.New("请输入留言来源")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- //todo 校验权限
|
|
|
- // 校验报告是否存在
|
|
|
- reportInfo, err := report.GetByReportId(req.ReportId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询报告出错")
|
|
|
- return
|
|
|
- }
|
|
|
- if reportInfo.Id <=0 {
|
|
|
- err = errors.New("报告不存在")
|
|
|
+ if req.ReportChapterId <=0 && req.ReportId <=0 && req.OldReportId <=0 && req.OldReportChapterId <=0{
|
|
|
+ err = errors.New("请输入报告ID")
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if (reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报") && req.ReportChapterId <=0 {
|
|
|
- err = errors.New("请输入报告章节ID")
|
|
|
+ // todo 判断是否有留言权限
|
|
|
+ err, errMsg = services.CheckSimpleCompanyProduct(user)
|
|
|
+ if err != nil {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if req.ReportChapterId > 0 {
|
|
|
- reportChapterInfo, tErr := report_chapter.GetTypeIdById(req.ReportChapterId)
|
|
|
- if tErr != nil {
|
|
|
- errMsg = tErr.Error()
|
|
|
- err = errors.New("查询章节失败")
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if reportChapterInfo.ReportChapterId == 0 {
|
|
|
- err = errors.New("章节不存在或者未发布")
|
|
|
+ //处理老报告, 转化成新报告ID
|
|
|
+ if req.ReportChapterId <=0 && req.ReportId <=0 && (req.OldReportId >0 || req.OldReportChapterId > 0) {
|
|
|
+ reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(req.OldReportId), uint64(req.OldReportChapterId))
|
|
|
+ if err != nil {
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
- if reportChapterInfo.ReportId != req.ReportId {
|
|
|
- err = errors.New("章节ID和报告ID不匹配")
|
|
|
+ } else {
|
|
|
+ // 判断报告ID是否正确
|
|
|
+ err, errMsg = services.CheckReportExistByReportIdReportChapterId(reportId, reportChapterId)
|
|
|
+ if err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
// 敏感词过滤
|
|
|
checkResult, err := wx_app.MsgSecCheck(user.OpenID, req.Content)
|
|
|
if err != nil {
|
|
@@ -95,14 +77,16 @@ func Comment(user user.UserInfo, req reqComment.ReqComment) (ret response.RespCo
|
|
|
commentInfo := &yb_comment.YbComment{
|
|
|
UserId: user.UserID,
|
|
|
Content: req.Content,
|
|
|
- ReportId: req.ReportId,
|
|
|
- ReportChapterId: req.ReportChapterId,
|
|
|
+ ReportId: reportId,
|
|
|
+ ReportChapterId: reportChapterId,
|
|
|
IsShowName: req.IsShowName,
|
|
|
SourceAgent: req.SourceAgent,
|
|
|
Type: 1,
|
|
|
Enabled: 1,
|
|
|
CreateTime: now,
|
|
|
ModifyTime: now,
|
|
|
+ OldReportId: req.OldReportId,
|
|
|
+ OldReportChapterId: req.OldReportChapterId,
|
|
|
}
|
|
|
err = commentInfo.Create()
|
|
|
if err != nil {
|
|
@@ -158,7 +142,7 @@ func Delete(user user.UserInfo, req *reqComment.ReqDel) (err error) {
|
|
|
}
|
|
|
|
|
|
// List 查询精选留言列表或我的留言列表
|
|
|
-func List(user user.UserInfo, reportId, reportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
|
|
|
+func List(user user.UserInfo, reportId, reportChapterId, oldReportId, oldReportChapterId int, hotFlag bool, pageIndex, pageSize int) (ret response.RespCommentList, err error) {
|
|
|
var errMsg string
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
@@ -166,31 +150,68 @@ func List(user user.UserInfo, reportId, reportChapterId int, hotFlag bool, page
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
+ if reportId <=0 && reportChapterId <=0 && oldReportId <=0 && oldReportChapterId <=0{
|
|
|
+ err = errors.New("请输入报告ID")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理老报告, 转化成新报告ID
|
|
|
+ if reportId <=0 && reportChapterId <=0 && (oldReportId >0 || oldReportChapterId > 0) {
|
|
|
+ reportId, reportChapterId, err, errMsg = services.GetReportIdReportChapterIdByOldReportId(uint64(oldReportId), uint64(oldReportChapterId))
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
offset := (pageIndex -1)*pageSize
|
|
|
var commentList []*yb_comment.YbComment
|
|
|
var total int64
|
|
|
//查询精选留言
|
|
|
if hotFlag {
|
|
|
- commentList, err = yb_comment.GetHotListByReportId(reportId, reportChapterId, offset, pageSize)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言列表出错")
|
|
|
- return
|
|
|
- }
|
|
|
- total, err = yb_comment.GetHostListTotalByReportId(reportId, reportChapterId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言总数出错")
|
|
|
- return
|
|
|
+ if reportId > 0 {
|
|
|
+ commentList, err = yb_comment.GetHotListByReportId(reportId, reportChapterId, offset, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err = yb_comment.GetHotListTotalByReportId(reportId, reportChapterId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言总数出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ commentList, err = yb_comment.GetHotListByOldReportId(oldReportId, oldReportChapterId, offset, pageSize)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ total, err = yb_comment.GetHotListTotalByOldReportId(oldReportId, oldReportChapterId,)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言总数出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
//查询个人留言
|
|
|
- commentList, err = yb_comment.GetListByUserIdReportId(user.UserID, reportId, reportChapterId)
|
|
|
- if err != nil {
|
|
|
- errMsg = err.Error()
|
|
|
- err = errors.New("查询精选留言列表出错")
|
|
|
- return
|
|
|
+ if reportId > 0{
|
|
|
+ commentList, err = yb_comment.GetListByUserIdReportId(user.UserID, reportId, reportChapterId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ commentList, err = yb_comment.GetListByUserIdOldReportId(user.UserID, oldReportId, oldReportChapterId)
|
|
|
+ if err != nil {
|
|
|
+ errMsg = err.Error()
|
|
|
+ err = errors.New("查询精选留言列表出错")
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
var commentIds []uint64
|