444
This commit is contained in:
+57
-60
@@ -164,14 +164,6 @@ func (r *BaseErrorWord) OperationErrorWord(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取相关错别字题目
|
||||
questionDao := dao.QuestionDao{}
|
||||
questions, err := questionDao.GetQuestionListByWord(baseErrorWord.WordOld)
|
||||
if err == nil && len(questions) <= 0 {
|
||||
responses.Ok(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
@@ -180,69 +172,74 @@ func (r *BaseErrorWord) OperationErrorWord(c *gin.Context) {
|
||||
}
|
||||
}()
|
||||
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
var questionIds []string
|
||||
for _, question := range questions {
|
||||
questionName := utils.ReplaceString(question.QuestionName, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
questionAnswer := utils.ReplaceString(question.QuestionAnswer, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
questionAnalysis := utils.ReplaceString(question.QuestionAnalysis, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
// 获取相关错别字题目
|
||||
questionDao := dao.QuestionDao{}
|
||||
questions, err := questionDao.GetQuestionListByWord(baseErrorWord.WordOld)
|
||||
if err == nil && len(questions) > 0 {
|
||||
var questionIds []string
|
||||
for _, question := range questions {
|
||||
questionName := utils.ReplaceString(question.QuestionName, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
questionAnswer := utils.ReplaceString(question.QuestionAnswer, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
questionAnalysis := utils.ReplaceString(question.QuestionAnalysis, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
|
||||
datas := make(map[string]interface{})
|
||||
if question.QuestionName != questionName {
|
||||
datas["question_name"] = questionName
|
||||
datas := make(map[string]interface{})
|
||||
if question.QuestionName != questionName {
|
||||
datas["question_name"] = questionName
|
||||
}
|
||||
|
||||
if question.QuestionAnswer != questionAnswer {
|
||||
datas["question_answer"] = questionAnswer
|
||||
}
|
||||
|
||||
if question.QuestionAnalysis != questionAnalysis {
|
||||
datas["question_analysis"] = questionAnalysis
|
||||
}
|
||||
|
||||
if len(datas) > 0 {
|
||||
err = questionDao.EditQuestionById(tx, question.QuestionId, datas)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 记录操作id
|
||||
questionIds = append(questionIds, fmt.Sprintf("%d", question.QuestionId))
|
||||
}
|
||||
}
|
||||
|
||||
if question.QuestionAnswer != questionAnswer {
|
||||
datas["question_answer"] = questionAnswer
|
||||
}
|
||||
|
||||
if question.QuestionAnalysis != questionAnalysis {
|
||||
datas["question_analysis"] = questionAnalysis
|
||||
}
|
||||
|
||||
if len(datas) > 0 {
|
||||
err = questionDao.EditQuestionById(tx, question.QuestionId, datas)
|
||||
if len(questionIds) > 0 {
|
||||
datas := make(map[string]interface{})
|
||||
datas["question_ids"] = strings.Join(questionIds, ",")
|
||||
datas["operation_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
err = baseErrorWordDao.EditBaseErrorWordById(tx, baseErrorWord.WordId, datas)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 记录操作id
|
||||
questionIds = append(questionIds, fmt.Sprintf("%d", question.QuestionId))
|
||||
}
|
||||
|
||||
// 获取题目选项详情
|
||||
questionOptions, err := questionOptionDao.GetQuestionOptionFirstByQuestionId(question.QuestionId)
|
||||
if err == nil && len(questionOptions) > 0 {
|
||||
for _, option := range questionOptions {
|
||||
datas = make(map[string]interface{})
|
||||
optionValue := utils.ReplaceString(option.OptionValue, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
if option.OptionValue != optionValue {
|
||||
datas["option_value"] = optionValue
|
||||
}
|
||||
|
||||
if len(datas) > 0 {
|
||||
err = questionOptionDao.EditQuestionOptionById(tx, option.OptionId, datas)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(questionIds) > 0 {
|
||||
datas := make(map[string]interface{})
|
||||
datas["question_ids"] = strings.Join(questionIds, ",")
|
||||
datas["operation_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||
err = baseErrorWordDao.EditBaseErrorWordById(tx, baseErrorWord.WordId, datas)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
// 获取相关错别字题目选项
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
questionOptions, err := questionOptionDao.GetQuestionOptionListByWord(baseErrorWord.WordOld)
|
||||
if err == nil && len(questionOptions) > 0 {
|
||||
for _, option := range questionOptions {
|
||||
datas := make(map[string]interface{})
|
||||
optionValue := utils.ReplaceString(option.OptionValue, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||
if option.OptionValue != optionValue {
|
||||
datas["option_value"] = optionValue
|
||||
}
|
||||
|
||||
if len(datas) > 0 {
|
||||
err = questionOptionDao.EditQuestionOptionById(tx, option.OptionId, datas)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user