...
|
...
|
@@ -169,15 +169,24 @@ func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, com |
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.Public, companyId, models.MsgTypeBulletin, sourceId); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
for i := range ids {
|
|
|
if _, ok := sended[ids[i]]; ok {
|
|
|
continue
|
|
|
}
|
|
|
sended[ids[i]] = ids[i]
|
|
|
msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
|
|
|
if _, err = orm.Insert(msg); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
//这条消息不存在,插入一条消息
|
|
|
if _, e := models.GetUserMsgBy(ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId); e != nil && e == orm2.ErrNoRows {
|
|
|
msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
|
|
|
if _, err = orm.Insert(msg); err != nil {
|
|
|
orm.Rollback()
|
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return
|
...
|
...
|
@@ -345,6 +354,17 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
log.Error(err.Error())
|
|
|
return
|
|
|
}
|
|
|
orm := orm2.NewOrm()
|
|
|
orm.Begin()
|
|
|
|
|
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//update
|
|
|
{
|
|
|
bulletin.Title = request.Title
|
...
|
...
|
@@ -360,8 +380,10 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
bulletin.Status = protocol.BulletinRelease
|
|
|
}
|
|
|
if err = models.UpdateBulletinById(bulletin); err != nil {
|
|
|
|
|
|
if err = models.UpdateBulletinById(orm, bulletin); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -371,6 +393,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
validQuestion(&request.Question)
|
|
|
if err != nil && err != orm2.ErrNoRows {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if err == nil {
|
...
|
...
|
@@ -388,8 +411,9 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
bulletinQuestion.Content = string(questionContent)
|
|
|
bulletinQuestion.Type = int8(request.Question.Type)
|
|
|
bulletinQuestion.UpdateAt = time.Now()
|
|
|
if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
|
|
|
if err = models.UpdateBulletinQuestionById(orm, bulletinQuestion); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -403,22 +427,16 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
|
CreateAt: time.Now(),
|
|
|
UpdateAt: time.Now(),
|
|
|
}
|
|
|
_, err = models.AddBulletinQuestion(bulletinQuestion)
|
|
|
_, err = orm.Insert(bulletinQuestion)
|
|
|
if err != nil {
|
|
|
orm.Rollback()
|
|
|
log.Error("添加问题失败:%s", err)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
orm := orm2.NewOrm()
|
|
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -453,7 +471,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest) |
|
|
orm.Begin()
|
|
|
if request.CmdType == protocol.BulletinUnRelease { //下架
|
|
|
status = protocol.BulletinUnRelease
|
|
|
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteUserMsg, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
|
|
|
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.NoPublic, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
|
|
|
log.Error(err.Error())
|
|
|
orm.Rollback()
|
|
|
return
|
...
|
...
|
|