{"record":{"id":"42467de2e660a129","repo":"flipped-aurora/gin-vue-admin","slug":"error-42467d","errorCode":null,"errorMessage":"已经创建过此数据结构或重复简称,请勿重复创建!","messagePattern":"已经创建过此数据结构或重复简称,请勿重复创建!","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_template.go","lineNumber":131,"sourceCode":"\tfileTask, err := prepareAutoCodeFileTask(layout, files)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn commitAutoCodeFileTask(fileTask, publishPreparedAutoCodeFile, func() error {\n\t\treturn persistAutoCodeMetadata(createCtx, global.GVA_DB, info, autoPkg.Template, history)\n\t})\n}\n\n// Preview 预览自动化代码\nfunc (s *autoCodeTemplate) Preview(ctx context.Context, info request.AutoCode) (map[string]string, error) {\n\tvar entity model.SysAutoCodePackage\n\terr := global.GVA_DB.WithContext(ctx).Where(\"package_name = ?\", info.Package).First(&entity).Error\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"查询包失败!\")\n\t}\n\t// 增加判断: 重复创建struct 或者重复的简称\n\tif AutocodeHistory.Repeat(ctx, info.BusinessDB, info.StructName, info.Abbreviation, info.Package) && !info.IsAdd {\n\t\treturn nil, errors.New(\"已经创建过此数据结构或重复简称,请勿重复创建!\")\n\t}\n\n\tpreview := make(map[string]string)\n\tcodes, _, _, err := s.generate(ctx, info, entity)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor key, writer := range codes {\n\t\tif len(key) > len(global.GVA_CONFIG.AutoCode.Root) {\n\t\t\tkey, _ = filepath.Rel(global.GVA_CONFIG.AutoCode.Root, key)\n\t\t}\n\t\t// 获取key的后缀 取消.\n\t\tsuffix := filepath.Ext(key)[1:]\n\t\tvar builder strings.Builder\n\t\tbuilder.WriteString(\"```\" + suffix + \"\\n\\n\")\n\t\tbuilder.WriteString(writer.String())\n\t\tbuilder.WriteString(\"\\n\\n```\")\n\t\tpreview[key] = builder.String()","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_template.go#L113-L149","documentation":"autoCodeTemplate.Preview checks AutocodeHistory.Repeat for the given business DB, struct name, abbreviation, and package; if a matching history exists and the request did not opt in via IsAdd, preview is blocked with \"已经创建过此数据结构或重复简称,请勿重复创建!\" (structure already created or duplicate abbreviation, do not duplicate). Unlike Create it also flags duplicate abbreviations.","triggerScenarios":"Previewing generation for a struct/abbreviation that already has autocode history without setting IsAdd=true; reusing an abbreviation already taken by another struct in the same package.","commonSituations":"Iterating on a previously generated table and previewing again without the add/overwrite flag; two structs sharing an abbreviation (e.g. both \"user\") causing model file name collisions.","solutions":["Set info.IsAdd = true in the request to allow regeneration/preview of an existing structure.","Change the abbreviation to a unique value if it collides with another struct.","Remove the obsolete autocode history entry if the old structure is no longer wanted.","Use a different package if the struct legitimately belongs elsewhere."],"exampleFix":"// before\n{\"structName\":\"User\",\"abbreviation\":\"user\",\"isAdd\":false}\n// after\n{\"structName\":\"User\",\"abbreviation\":\"user\",\"isAdd\":true}","handlingStrategy":"validation","validationCode":"if AutocodeHistory.Repeat(ctx, info.BusinessDB, info.StructName, info.Abbreviation, info.Package) && !info.IsAdd {\n    return errors.New(\"结构或简称已存在, 请设置 isAdd=true 或更换简称\")\n}\n// safe to call Preview","typeGuard":null,"tryCatchPattern":"codes, err := autoCodeService.PreviewAutoCode(ctx, info)\nif err != nil {\n    if strings.Contains(err.Error(), \"重复简称\") {\n        return fmt.Errorf(\"请设置 isAdd=true 或更换 abbreviation: %w\", err)\n    }\n    return err\n}","preventionTips":["Set isAdd=true when intentionally regenerating an existing structure.","Enforce unique abbreviations per package in the form UI.","Review autocode history before previewing a previously generated table.","Remove obsolete history entries when structures are retired."],"tags":["autocode","duplicate","validation","preview"],"backgroundTag":"duplicate-record","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}