正在显示
2 个修改的文件
包含
30 行增加
和
0 行删除
@@ -61,6 +61,7 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ | @@ -61,6 +61,7 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ | ||
61 | log.Error("BulletinRelease:question.content not empty.", uid) | 61 | log.Error("BulletinRelease:question.content not empty.", uid) |
62 | return | 62 | return |
63 | } | 63 | } |
64 | + validQuestion(&request.Question) | ||
64 | if questionContent, err = json.Marshal(request.Question.Content); err != nil { | 65 | if questionContent, err = json.Marshal(request.Question.Content); err != nil { |
65 | log.Error(err.Error()) | 66 | log.Error(err.Error()) |
66 | return | 67 | return |
@@ -97,6 +98,19 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ | @@ -97,6 +98,19 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ | ||
97 | return | 98 | return |
98 | } | 99 | } |
99 | 100 | ||
101 | +//检查序号 | ||
102 | +func validQuestion(question *protocol.Question) { | ||
103 | + var id = 1 | ||
104 | + for i := range question.Content { | ||
105 | + //option :=question.Content[i] | ||
106 | + if question.Content[i].Id == -1 { | ||
107 | + continue | ||
108 | + } | ||
109 | + question.Content[i].Id = id | ||
110 | + id++ | ||
111 | + } | ||
112 | +} | ||
113 | + | ||
100 | func getBulletinReceiverIds(orm orm2.Ormer, receivers []protocol.VisibleObject, companyId int64, sourceId int64, message string) (ids []int64, err error) { | 114 | func getBulletinReceiverIds(orm orm2.Ormer, receivers []protocol.VisibleObject, companyId int64, sourceId int64, message string) (ids []int64, err error) { |
101 | var ( | 115 | var ( |
102 | //ids []int64 | 116 | //ids []int64 |
@@ -354,6 +368,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r | @@ -354,6 +368,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r | ||
354 | 368 | ||
355 | if bulletin.QuestionSwitch == 1 { | 369 | if bulletin.QuestionSwitch == 1 { |
356 | bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id) | 370 | bulletinQuestion, err = models.GetBulletinQuestionByBulletinId(bulletin.Id) |
371 | + validQuestion(&request.Question) | ||
357 | if err != nil && err != orm2.ErrNoRows { | 372 | if err != nil && err != orm2.ErrNoRows { |
358 | log.Error(err.Error()) | 373 | log.Error(err.Error()) |
359 | return | 374 | return |
services/bulletin/bulletin_test.go
0 → 100644
1 | +package bulletin | ||
2 | + | ||
3 | +import ( | ||
4 | + "oppmg/protocol" | ||
5 | + "testing" | ||
6 | +) | ||
7 | + | ||
8 | +func Test_validQuestion(t *testing.T) { | ||
9 | + input := protocol.Question{ | ||
10 | + Content: []protocol.QuestionContent{{Id: 5, Content: "A"}, {Id: 7, Content: "B"}, {-1, "C"}}, | ||
11 | + } | ||
12 | + t.Log(input) | ||
13 | + validQuestion(&input) | ||
14 | + t.Log(input) | ||
15 | +} |
-
请 注册 或 登录 后发表评论