|
|
package message
|
|
|
|
|
|
import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/astaxie/beego"
|
|
|
"github.com/astaxie/beego/orm"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
"opp/internal/repository"
|
|
|
"opp/internal/utils"
|
|
|
"opp/models"
|
|
|
"opp/protocol"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) {
|
...
|
...
|
@@ -71,9 +78,240 @@ func MsgInteractive(header *protocol.RequestHeader, request *protocol.MsgInterac |
|
|
//未读公告列表
|
|
|
func Announcements(header *protocol.RequestHeader, request *protocol.AnnouncementsRequest) (rsp *protocol.AnnouncementsResponse, err error) {
|
|
|
var (
|
|
|
//userMsg []*models.UserMsg
|
|
|
userMsg []*models.UserMsg
|
|
|
bulletin *models.Bulletin
|
|
|
)
|
|
|
//if err = utils.ExecuteQueryAll(&userMsg,models.SqlUserMsgUnRead,header.CompanyId,header.)
|
|
|
rsp = &protocol.AnnouncementsResponse{}
|
|
|
if err = utils.ExecuteQueryAll(&userMsg, models.SqlUserMsgsUnRead, header.CompanyId, header.UserId, models.MsgTypeBulletin); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(userMsg); i++ {
|
|
|
msg := userMsg[i]
|
|
|
if bulletin, err = models.GetBulletinById(int(msg.SourceId)); err != nil {
|
|
|
if orm.ErrNoRows == err {
|
|
|
err = nil
|
|
|
continue
|
|
|
}
|
|
|
log.Error(msg.SourceId, err)
|
|
|
continue
|
|
|
}
|
|
|
item := protocol.Announcement{
|
|
|
Id: bulletin.Id,
|
|
|
Type: int(bulletin.Type),
|
|
|
Title: bulletin.Title,
|
|
|
Control: int(bulletin.AllowClose),
|
|
|
//link:'https://web-open.fjmaimaimai.com/#/ability/announcement?id='+announcementCfgData[i].id+'&uid='+param.uid
|
|
|
Link: fmt.Sprintf("%v#/ability/announcement?id=%v&uid=%v", beego.AppConfig.String("h5_host"), bulletin.Id, msg.ReceiveUserId),
|
|
|
}
|
|
|
item.Cover = protocol.Cover{
|
|
|
Path: bulletin.Cover,
|
|
|
H: bulletin.H,
|
|
|
W: bulletin.W,
|
|
|
}
|
|
|
rsp.Lists = append(rsp.Lists, item)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//公告已读
|
|
|
func AnnouncementRead(header *protocol.RequestHeader, request *protocol.AnnouncementReadRequest) (rsp *protocol.AnnouncementReadResponse, err error) {
|
|
|
var (
|
|
|
bulletin *models.Bulletin
|
|
|
userMsg *models.UserMsg
|
|
|
)
|
|
|
if bulletin, err = models.GetBulletinById(request.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(2060)
|
|
|
return
|
|
|
}
|
|
|
if int64(bulletin.CompanyId) != header.CompanyId {
|
|
|
err = protocol.NewErrWithMessage(2060)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsgUnRead, bulletin.Id, header.CompanyId, header.UserId, models.MsgTypeBulletin); err != nil {
|
|
|
//if err==orm.ErrNoRows{
|
|
|
// err=nil
|
|
|
// return
|
|
|
//}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if userMsg.IsRead == 1 {
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMap(userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.AnnouncementReadResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//消息中心-公司公告
|
|
|
func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompanyNoticeRequest) (rsp *protocol.MsgCompanyNoticeResponse, err error) {
|
|
|
type MsgBulletin struct {
|
|
|
Id int `orm:"column(id)"`
|
|
|
Title string `orm:"column(title)"`
|
|
|
UpdateTime int64 `orm:"column(update_at)"`
|
|
|
IsRead int8 `orm:"column(is_read)"`
|
|
|
}
|
|
|
var (
|
|
|
msgBulletins []*MsgBulletin
|
|
|
total int
|
|
|
)
|
|
|
if total, err = models.GetUserMsgsBulletin(header.UserId, header.CompanyId, models.MsgTypeBulletin, request.LastId, request.PageSize, &msgBulletins); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.MsgCompanyNoticeResponse{}
|
|
|
rsp.Total = total
|
|
|
for i := range msgBulletins {
|
|
|
tmp := msgBulletins[i]
|
|
|
rsp.Lists = append(rsp.Lists, protocol.UserMsg{
|
|
|
Id: int64(tmp.Id),
|
|
|
SourceType: models.MsgTypeBulletin,
|
|
|
Content: tmp.Title,
|
|
|
CreateAt: tmp.UpdateTime,
|
|
|
IsRead: int(tmp.IsRead),
|
|
|
})
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//H5公告详情
|
|
|
func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) {
|
|
|
var (
|
|
|
bulletin *models.Bulletin
|
|
|
question *models.BulletinQuestion
|
|
|
userMsg *models.UserMsg
|
|
|
bulletinAnswer *models.BulletinQuestionAnswer
|
|
|
setRead bool = false
|
|
|
answer *protocol.Answer
|
|
|
)
|
|
|
if bulletin, err = models.GetBulletinById(request.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
err = protocol.NewErrWithMessage(2060)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsg, request.Id, request.Uid, models.MsgTypeBulletin); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(2060)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.AnnouncementResponse{}
|
|
|
rsp.Announcement = protocol.H5Announcement{
|
|
|
Id: bulletin.Id,
|
|
|
Title: bulletin.Title,
|
|
|
Content: bulletin.Content,
|
|
|
Control: int(bulletin.AllowClose),
|
|
|
IsRead: int(userMsg.IsRead),
|
|
|
}
|
|
|
if bulletin.QuestionSwitch == 1 {
|
|
|
if question, err = models.GetBulletinQuestionByBulletinId(bulletin.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp.Announcement.Vote = protocol.Question{
|
|
|
Id: question.Id,
|
|
|
Type: int(question.Type),
|
|
|
Title: question.Title,
|
|
|
}
|
|
|
if err = json.Unmarshal([]byte(question.Content), &rsp.Announcement.Vote.Content); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取回答详情数据
|
|
|
if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
|
|
|
if len(bulletinAnswer.Answer) != 0 {
|
|
|
if err = json.Unmarshal([]byte(bulletinAnswer.Answer), &answer); err != nil {
|
|
|
log.Error(err)
|
|
|
} else {
|
|
|
rsp.Announcement.EditContent = answer.EditContent
|
|
|
rsp.Announcement.VoteResults = answer.VoteResults
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
if userMsg.IsRead == 0 { //判断是否可以置为 已读
|
|
|
if bulletin.AllowClose == 2 && bulletin != nil && bulletin.Id != 0 {
|
|
|
setRead = true
|
|
|
}
|
|
|
}
|
|
|
if setRead {
|
|
|
if err = utils.UpdateTableByMap(userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//H5完成公告操作
|
|
|
func H5AnnouncementSubmit(header *protocol.RequestHeader, request *protocol.AnnouncementSubmitRequest) (rsp *protocol.AnnouncementSubmitResponse, err error) {
|
|
|
var (
|
|
|
bulletin *models.Bulletin
|
|
|
userMsg *models.UserMsg
|
|
|
bulletinAnswer *models.BulletinQuestionAnswer
|
|
|
)
|
|
|
if bulletin, err = models.GetBulletinById(request.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(2060)
|
|
|
return
|
|
|
}
|
|
|
if err = utils.ExecuteQueryOne(&userMsg, models.SqlUserMsg, request.Id, request.Uid, models.MsgTypeBulletin); err != nil {
|
|
|
log.Error(err)
|
|
|
err = protocol.NewErrWithMessage(2060)
|
|
|
return
|
|
|
}
|
|
|
//获取回答详情数据
|
|
|
if bulletinAnswer, err = models.GetBulletinQuestionAnswerBy(request.Id, int64(request.Uid)); err == nil {
|
|
|
bulletinAnswer.Answer = common.AssertJson(protocol.Answer{
|
|
|
EditContent: request.EditContent,
|
|
|
VoteResults: request.VoteResults,
|
|
|
})
|
|
|
bulletinAnswer.UpdateAt = time.Now()
|
|
|
if err = models.UpdateBulletinQuestionAnswerById(bulletinAnswer); err != nil {
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
{
|
|
|
bulletinAnswer = &models.BulletinQuestionAnswer{
|
|
|
Answer: common.AssertJson(&protocol.Answer{
|
|
|
VoteResults: request.VoteResults,
|
|
|
EditContent: request.EditContent,
|
|
|
}),
|
|
|
BulletinId: bulletin.Id,
|
|
|
BulletinQuestionId: request.VoteId,
|
|
|
Uid: request.Uid,
|
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
}
|
|
|
if _, err = orm.Insert(bulletinAnswer); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
{
|
|
|
if userMsg.IsRead != 1 {
|
|
|
if err = utils.UpdateTableByMapWithOrmer(orm, userMsg, map[string]interface{}{"IsRead": int8(1)}); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.AnnouncementSubmitResponse{}
|
|
|
return
|
|
|
} |
...
|
...
|
|