From 58b2982c2051caed1b3a32438087230fa6a90e62 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 12 Aug 2021 12:09:00 +0800 Subject: [PATCH] feat(fix): convert userId to string --- controllers/score.go | 23 +++++++++++++---------- lastupdate.tmp | 2 +- models/marking.go | 32 ++++++++++++++++---------------- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/controllers/score.go b/controllers/score.go index 5f03205..8f84047 100644 --- a/controllers/score.go +++ b/controllers/score.go @@ -73,7 +73,8 @@ func (c *TestPaperApiController) Point() { scoresstr := requestBody["scores"].(string) testIdstr := requestBody["testId"].(string) testDetailIdstr := requestBody["testDetailId"].(string) - userId, _ := strconv.ParseInt(userIdstr, 10, 64) + // userId, _ := strconv.ParseInt(userIdstr, 10, 64) + userId := userIdstr scores := strings.Split(scoresstr, "-") testDetailIds := strings.Split(testDetailIdstr, "-") testId, _ := strconv.ParseInt(testIdstr, 10, 64) @@ -105,10 +106,10 @@ func (c *TestPaperApiController) Point() { test.Examiner_first_id = userId test.Examiner_first_score = sum final = true - } else if topic.Score_type == 2 && test.Examiner_first_id == 0 { + } else if topic.Score_type == 2 && test.Examiner_first_id == "-1" { test.Examiner_first_id = userId test.Examiner_first_score = sum - } else if topic.Score_type == 2 && test.Examiner_second_id == 0 { + } else if topic.Score_type == 2 && test.Examiner_second_id == "-1" { test.Examiner_second_id = userId test.Examiner_second_score = sum if math.Abs(float64(test.Examiner_second_score)-float64(test.Examiner_first_score)) <= float64(topic.Standard_error) { @@ -118,7 +119,7 @@ func (c *TestPaperApiController) Point() { final = true } else { newUnderTest := models.UnderCorrectedPaper{} - newUnderTest.User_id = 10000 + newUnderTest.User_id = "10000" newUnderTest.Test_question_type = 3 newUnderTest.Test_id = underTest.Test_id newUnderTest.Question_id = underTest.Question_id @@ -149,7 +150,7 @@ func (c *TestPaperApiController) Point() { test.Question_status = 2 newUnderTest := models.UnderCorrectedPaper{} - newUnderTest.User_id = 10000 + newUnderTest.User_id = "10000" newUnderTest.Test_question_type = 4 newUnderTest.Test_id = underTest.Test_id newUnderTest.Question_id = underTest.Question_id @@ -179,10 +180,10 @@ func (c *TestPaperApiController) Point() { if topic.Score_type == 1 { tempTest.Examiner_first_id = userId tempTest.Examiner_first_score = score - } else if topic.Score_type == 2 && tempTest.Examiner_first_id == 0 { + } else if topic.Score_type == 2 && tempTest.Examiner_first_id == "-1" { tempTest.Examiner_first_id = userId tempTest.Examiner_first_score = score - } else if topic.Score_type == 2 && tempTest.Examiner_second_id == 0 { + } else if topic.Score_type == 2 && tempTest.Examiner_second_id == "-1" { tempTest.Examiner_second_id = userId tempTest.Examiner_second_score = score // if final{ @@ -219,7 +220,8 @@ func (c *TestPaperApiController) Problem() { userIdstr := requestBody["userId"].(string) problemTypestr := requestBody["problemType"].(string) testIdstr := requestBody["testId"].(string) - userId, _ := strconv.ParseInt(userIdstr, 10, 64) + // userId, _ := strconv.ParseInt(userIdstr, 10, 64) + userId := userIdstr testId, _ := strconv.ParseInt(testIdstr, 10, 64) problemType, _ := strconv.ParseInt(problemTypestr, 10, 64) var underTest models.UnderCorrectedPaper @@ -229,7 +231,7 @@ func (c *TestPaperApiController) Problem() { underTest.GetUnderCorrectedPaper(userId, testId) var newUnderTest = underTest underTest.Delete() - newUnderTest.User_id = 10000 + newUnderTest.User_id = "10000" newUnderTest.Test_question_type = 6 newUnderTest.Problem_type = problemType has, _ := newUnderTest.IsDuplicate() @@ -322,7 +324,8 @@ func (c *TestPaperApiController) Review() { var requestBody map[string]interface{} json.Unmarshal(c.Ctx.Input.RequestBody, &requestBody) userIdstr := requestBody["userId"].(string) - userId, _ := strconv.ParseInt(userIdstr, 10, 64) + // userId, _ := strconv.ParseInt(userIdstr, 10, 64) + userId := userIdstr var records []models.ScoreRecord models.GetLatestRecores(userId, &records) data := make(map[string]interface{}) diff --git a/lastupdate.tmp b/lastupdate.tmp index a220da6..deae7d8 100755 --- a/lastupdate.tmp +++ b/lastupdate.tmp @@ -1 +1 @@ -{"C:\\Users\\dav1d\\code\\OpenCt\\openscore\\controllers":1628686352928000000} \ No newline at end of file +{"C:\\Users\\dav1d\\code\\OpenCt\\openscore\\controllers":1628741261391809200} \ No newline at end of file diff --git a/models/marking.go b/models/marking.go index 813528c..b057d86 100644 --- a/models/marking.go +++ b/models/marking.go @@ -33,19 +33,19 @@ type TestPaper struct { Question_id int64 Candidate string Question_status int64 - Examiner_first_id int64 `xorm:"default(0)"` + Examiner_first_id string `xorm:"default('-1')"` Examiner_first_score int64 Examiner_first_self_score int64 - Examiner_second_id int64 `xorm:"default(0)"` + Examiner_second_id string `xorm:"default('-1')"` Examiner_second_score int64 Examiner_second_self_score int64 - Examiner_third_id int64 `xorm:"default(0)"` + Examiner_third_id string `xorm:"default('-1')"` Examiner_third_score int64 Examiner_third_self_score int64 - Leader_id int64 `xorm:"default(0)"` + Leader_id string `xorm:"default('-1')"` Leader_score int64 Final_score int64 - Final_score_id int64 + Final_score_id string Pratice_error int64 Answer_test_id int64 Example_test_id int64 @@ -56,24 +56,24 @@ type TestPaperInfo struct { Question_detail_id int64 Test_id int64 Pic_src string - Examiner_first_id int64 `xorm:"default(0)"` + Examiner_first_id string `xorm:"default('-1')"` Examiner_first_score int64 Examiner_first_self_score int64 - Examiner_second_id int64 `xorm:"default(0)"` + Examiner_second_id string `xorm:"default('-1')"` Examiner_second_score int64 Examiner_second_self_score int64 - Examiner_third_id int64 `xorm:"default(0)"` + Examiner_third_id string `xorm:"default('-1')"` Examiner_third_score int64 Examiner_third_self_score int64 - Leader_id int64 `xorm:"default(0)"` + Leader_id string `xorm:"default('-1')"` Leader_score int64 Final_score int64 - Final_score_id int64 `xorm:"default(0)"` + Final_score_id string `xorm:"default('-1')"` } type UnderCorrectedPaper struct { UnderCorrected_id int64 `xorm:"pk autoincr"` - User_id int64 + User_id string Test_id int64 Question_id int64 Test_question_type int64 @@ -84,7 +84,7 @@ type ScoreRecord struct { Record_id int64 `xorm:"pk autoincr"` Question_id int64 Test_id int64 - User_id int64 + User_id string Score_time time.Time Score int64 Test_record_type int64 @@ -93,7 +93,7 @@ type ScoreRecord struct { type PaperDistribution struct { Distribution_id int64 `xorm:"pk autoincr"` - User_id int64 + User_id string Question_id int64 Test_distribution_number int64 PaperType int64 @@ -197,7 +197,7 @@ func (t *TestPaperInfo) GetTestPaperInfo(id int64) error { return err } -func (u *UnderCorrectedPaper) GetUnderCorrectedPaper(userId int64, testId int64) error { +func (u *UnderCorrectedPaper) GetUnderCorrectedPaper(userId string, testId int64) error { has, err := x.Where(builder.Eq{"test_id": testId, "user_id": userId}).Get(u) if !has || err != nil { log.Println("could not find under corrected paper") @@ -214,7 +214,7 @@ func (u *UnderCorrectedPaper) Delete() error { return err } -func (u *PaperDistribution) GetPaperDistribution(id int64) error { +func (u *PaperDistribution) GetPaperDistribution(id string) error { has, err := x.Where(builder.Eq{"user_id": id}).Get(u) if !has || err != nil { log.Println("could not find paper distribution") @@ -274,7 +274,7 @@ func (u *UnderCorrectedPaper) IsDuplicate() (bool, error) { return has, err } -func GetLatestRecores(userId int64, records *[]ScoreRecord) error { +func GetLatestRecores(userId string, records *[]ScoreRecord) error { // x.QueryString("select top 10 * from scoreRecord where user_id = " + strconv.FormatInt(userId, 10) + " order by record_id desc") err := x.Limit(10).Where(builder.Eq{"user_id": userId}).Desc("record_id").Find(records) if err != nil {