From c59b1b2c65e5f12f5c75ad859995c4246ab012bd Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Sat, 12 Oct 2024 17:39:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=87=E7=AD=BE12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/service/Question.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/api/service/Question.go b/api/service/Question.go index 0e23314..0fef1f1 100644 --- a/api/service/Question.go +++ b/api/service/Question.go @@ -387,19 +387,24 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion } // 验证一级标签 + firstLabelId, err := strconv.ParseInt(req.FirstLabelId, 10, 64) if err != nil { return false, err } - if &firstLabelId != question.FirstLabelId { - labelDao := dao.LabelDao{} - _, err = labelDao.GetLabelFirstById(firstLabelId) - if err != nil { - return false, err - } - + if question.FirstLabelId == nil { questionData["first_label_id"] = firstLabelId + } else { + if firstLabelId != *question.FirstLabelId { + labelDao := dao.LabelDao{} + _, err = labelDao.GetLabelFirstById(firstLabelId) + if err != nil { + return false, err + } + + questionData["first_label_id"] = firstLabelId + } } // 验证二级标签 @@ -415,14 +420,14 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion return false, err } - if &firstLabelId != question.FirstLabelId { + if &secondLabelId != question.SecondLabelId { labelDao := dao.LabelDao{} _, err = labelDao.GetLabelFirstById(secondLabelId) if err != nil { return false, err } - questionData["first_label_id"] = firstLabelId + questionData["second_label_id"] = secondLabelId } } @@ -492,7 +497,7 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion return false, errors.New(err.Error()) } - tx.Commit() + //tx.Commit() return true, nil }