444
This commit is contained in:
parent
7cef9e7d87
commit
14f4314982
@ -164,14 +164,6 @@ func (r *BaseErrorWord) OperationErrorWord(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取相关错别字题目
|
|
||||||
questionDao := dao.QuestionDao{}
|
|
||||||
questions, err := questionDao.GetQuestionListByWord(baseErrorWord.WordOld)
|
|
||||||
if err == nil && len(questions) <= 0 {
|
|
||||||
responses.Ok(c)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 开始事务
|
// 开始事务
|
||||||
tx := global.Db.Begin()
|
tx := global.Db.Begin()
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -180,69 +172,74 @@ func (r *BaseErrorWord) OperationErrorWord(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
questionOptionDao := dao.QuestionOptionDao{}
|
// 获取相关错别字题目
|
||||||
var questionIds []string
|
questionDao := dao.QuestionDao{}
|
||||||
for _, question := range questions {
|
questions, err := questionDao.GetQuestionListByWord(baseErrorWord.WordOld)
|
||||||
questionName := utils.ReplaceString(question.QuestionName, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
if err == nil && len(questions) > 0 {
|
||||||
questionAnswer := utils.ReplaceString(question.QuestionAnswer, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
var questionIds []string
|
||||||
questionAnalysis := utils.ReplaceString(question.QuestionAnalysis, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
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{})
|
datas := make(map[string]interface{})
|
||||||
if question.QuestionName != questionName {
|
if question.QuestionName != questionName {
|
||||||
datas["question_name"] = 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 {
|
if len(questionIds) > 0 {
|
||||||
datas["question_answer"] = questionAnswer
|
datas := make(map[string]interface{})
|
||||||
}
|
datas["question_ids"] = strings.Join(questionIds, ",")
|
||||||
|
datas["operation_time"] = time.Now().Format("2006-01-02 15:04:05")
|
||||||
if question.QuestionAnalysis != questionAnalysis {
|
err = baseErrorWordDao.EditBaseErrorWordById(tx, baseErrorWord.WordId, datas)
|
||||||
datas["question_analysis"] = questionAnalysis
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(datas) > 0 {
|
|
||||||
err = questionDao.EditQuestionById(tx, question.QuestionId, datas)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
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{})
|
questionOptionDao := dao.QuestionOptionDao{}
|
||||||
datas["question_ids"] = strings.Join(questionIds, ",")
|
questionOptions, err := questionOptionDao.GetQuestionOptionListByWord(baseErrorWord.WordOld)
|
||||||
datas["operation_time"] = time.Now().Format("2006-01-02 15:04:05")
|
if err == nil && len(questionOptions) > 0 {
|
||||||
err = baseErrorWordDao.EditBaseErrorWordById(tx, baseErrorWord.WordId, datas)
|
for _, option := range questionOptions {
|
||||||
if err != nil {
|
datas := make(map[string]interface{})
|
||||||
tx.Rollback()
|
optionValue := utils.ReplaceString(option.OptionValue, baseErrorWord.WordOld, baseErrorWord.WordNew)
|
||||||
responses.FailWithMessage(err.Error(), c)
|
if option.OptionValue != optionValue {
|
||||||
return
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,3 +85,19 @@ func (r *QuestionOptionDao) AddQuestionOption(tx *gorm.DB, model *model.Question
|
|||||||
}
|
}
|
||||||
return model, nil
|
return model, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetQuestionOptionListByWord 获取列表-模糊查询-字
|
||||||
|
func (r *QuestionOptionDao) GetQuestionOptionListByWord(word string) (m []*model.QuestionOption, err error) {
|
||||||
|
query := global.Db
|
||||||
|
|
||||||
|
keyword := "%" + word + "%"
|
||||||
|
|
||||||
|
query = query.
|
||||||
|
Or("option_value LIKE ?", keyword)
|
||||||
|
|
||||||
|
err = query.Find(&m).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user