|
@@ -169,17 +169,26 @@ func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, com |
|
@@ -169,17 +169,26 @@ func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, com |
169
|
return
|
169
|
return
|
170
|
}
|
170
|
}
|
171
|
}
|
171
|
}
|
|
|
172
|
+ if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.Public, companyId, models.MsgTypeBulletin, sourceId); err != nil {
|
|
|
173
|
+ log.Error(err.Error())
|
|
|
174
|
+ orm.Rollback()
|
|
|
175
|
+ return
|
|
|
176
|
+ }
|
172
|
for i := range ids {
|
177
|
for i := range ids {
|
173
|
if _, ok := sended[ids[i]]; ok {
|
178
|
if _, ok := sended[ids[i]]; ok {
|
174
|
continue
|
179
|
continue
|
175
|
}
|
180
|
}
|
176
|
sended[ids[i]] = ids[i]
|
181
|
sended[ids[i]] = ids[i]
|
|
|
182
|
+ //这条消息不存在,插入一条消息
|
|
|
183
|
+ if _, e := models.GetUserMsgBy(ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId); e != nil && e == orm2.ErrNoRows {
|
177
|
msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
|
184
|
msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
|
178
|
if _, err = orm.Insert(msg); err != nil {
|
185
|
if _, err = orm.Insert(msg); err != nil {
|
|
|
186
|
+ orm.Rollback()
|
179
|
log.Error(err.Error())
|
187
|
log.Error(err.Error())
|
180
|
return
|
188
|
return
|
181
|
}
|
189
|
}
|
182
|
}
|
190
|
}
|
|
|
191
|
+ }
|
183
|
return
|
192
|
return
|
184
|
}
|
193
|
}
|
185
|
|
194
|
|
|
@@ -345,6 +354,17 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
@@ -345,6 +354,17 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
345
|
log.Error(err.Error())
|
354
|
log.Error(err.Error())
|
346
|
return
|
355
|
return
|
347
|
}
|
356
|
}
|
|
|
357
|
+ orm := orm2.NewOrm()
|
|
|
358
|
+ orm.Begin()
|
|
|
359
|
+
|
|
|
360
|
+ if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
361
|
+ if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
|
|
|
362
|
+ log.Error(err.Error())
|
|
|
363
|
+ orm.Rollback()
|
|
|
364
|
+ return
|
|
|
365
|
+ }
|
|
|
366
|
+ }
|
|
|
367
|
+
|
348
|
//update
|
368
|
//update
|
349
|
{
|
369
|
{
|
350
|
bulletin.Title = request.Title
|
370
|
bulletin.Title = request.Title
|
|
@@ -360,8 +380,10 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
@@ -360,8 +380,10 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
360
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
380
|
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
361
|
bulletin.Status = protocol.BulletinRelease
|
381
|
bulletin.Status = protocol.BulletinRelease
|
362
|
}
|
382
|
}
|
363
|
- if err = models.UpdateBulletinById(bulletin); err != nil {
|
383
|
+
|
|
|
384
|
+ if err = models.UpdateBulletinById(orm, bulletin); err != nil {
|
364
|
log.Error(err.Error())
|
385
|
log.Error(err.Error())
|
|
|
386
|
+ orm.Rollback()
|
365
|
return
|
387
|
return
|
366
|
}
|
388
|
}
|
367
|
}
|
389
|
}
|
|
@@ -371,6 +393,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
@@ -371,6 +393,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
371
|
validQuestion(&request.Question)
|
393
|
validQuestion(&request.Question)
|
372
|
if err != nil && err != orm2.ErrNoRows {
|
394
|
if err != nil && err != orm2.ErrNoRows {
|
373
|
log.Error(err.Error())
|
395
|
log.Error(err.Error())
|
|
|
396
|
+ orm.Rollback()
|
374
|
return
|
397
|
return
|
375
|
}
|
398
|
}
|
376
|
if err == nil {
|
399
|
if err == nil {
|
|
@@ -388,8 +411,9 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
@@ -388,8 +411,9 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
388
|
bulletinQuestion.Content = string(questionContent)
|
411
|
bulletinQuestion.Content = string(questionContent)
|
389
|
bulletinQuestion.Type = int8(request.Question.Type)
|
412
|
bulletinQuestion.Type = int8(request.Question.Type)
|
390
|
bulletinQuestion.UpdateAt = time.Now()
|
413
|
bulletinQuestion.UpdateAt = time.Now()
|
391
|
- if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
|
414
|
+ if err = models.UpdateBulletinQuestionById(orm, bulletinQuestion); err != nil {
|
392
|
log.Error(err.Error())
|
415
|
log.Error(err.Error())
|
|
|
416
|
+ orm.Rollback()
|
393
|
return
|
417
|
return
|
394
|
}
|
418
|
}
|
395
|
}
|
419
|
}
|
|
@@ -403,22 +427,16 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
|
@@ -403,22 +427,16 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r |
403
|
CreateAt: time.Now(),
|
427
|
CreateAt: time.Now(),
|
404
|
UpdateAt: time.Now(),
|
428
|
UpdateAt: time.Now(),
|
405
|
}
|
429
|
}
|
406
|
- _, err = models.AddBulletinQuestion(bulletinQuestion)
|
430
|
+ _, err = orm.Insert(bulletinQuestion)
|
407
|
if err != nil {
|
431
|
if err != nil {
|
|
|
432
|
+ orm.Rollback()
|
408
|
log.Error("添加问题失败:%s", err)
|
433
|
log.Error("添加问题失败:%s", err)
|
409
|
return
|
434
|
return
|
410
|
}
|
435
|
}
|
411
|
}
|
436
|
}
|
412
|
|
437
|
|
413
|
}
|
438
|
}
|
414
|
- orm := orm2.NewOrm()
|
|
|
415
|
- if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
|
|
|
416
|
- if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
|
|
|
417
|
- log.Error(err.Error())
|
|
|
418
|
- orm.Rollback()
|
|
|
419
|
- return
|
|
|
420
|
- }
|
|
|
421
|
- }
|
439
|
+ orm.Commit()
|
422
|
return
|
440
|
return
|
423
|
}
|
441
|
}
|
424
|
|
442
|
|
|
@@ -453,7 +471,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest) |
|
@@ -453,7 +471,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest) |
453
|
orm.Begin()
|
471
|
orm.Begin()
|
454
|
if request.CmdType == protocol.BulletinUnRelease { //下架
|
472
|
if request.CmdType == protocol.BulletinUnRelease { //下架
|
455
|
status = protocol.BulletinUnRelease
|
473
|
status = protocol.BulletinUnRelease
|
456
|
- if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteUserMsg, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
|
474
|
+ if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.NoPublic, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
|
457
|
log.Error(err.Error())
|
475
|
log.Error(err.Error())
|
458
|
orm.Rollback()
|
476
|
orm.Rollback()
|
459
|
return
|
477
|
return
|