{"record":{"id":"3ae9717785b4b254","repo":"flipped-aurora/gin-vue-admin","slug":"error-3ae971","errorCode":null,"errorMessage":"请不要搞事","messagePattern":"请不要搞事","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_dictionary.go","lineNumber":43,"sourceCode":"func (dictionaryService *DictionaryService) CreateSysDictionary(ctx context.Context, sysDictionary system.SysDictionary) (system.SysDictionary, error) {\n\tif (!errors.Is(global.GVA_DB.WithContext(ctx).First(&system.SysDictionary{}, \"type = ?\", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {\n\t\treturn system.SysDictionary{}, errors.New(\"存在相同的type，不允许创建\")\n\t}\n\t// Create 会把自增主键回写进 sysDictionary,直接返回创建后的实体(含 ID),免去调用方二次回查\n\terr := global.GVA_DB.WithContext(ctx).Create(&sysDictionary).Error\n\treturn sysDictionary, err\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: DeleteSysDictionary\n//@description: 删除字典数据\n//@param: sysDictionary model.SysDictionary\n//@return: err error\n\nfunc (dictionaryService *DictionaryService) DeleteSysDictionary(ctx context.Context, sysDictionary system.SysDictionary) (err error) {\n\terr = global.GVA_DB.WithContext(ctx).Where(\"id = ?\", sysDictionary.ID).Preload(\"SysDictionaryDetails\").First(&sysDictionary).Error\n\tif err != nil && errors.Is(err, gorm.ErrRecordNotFound) {\n\t\treturn errors.New(\"请不要搞事\")\n\t}\n\tif err != nil {\n\t\treturn err\n\t}\n\terr = global.GVA_DB.WithContext(ctx).Delete(&sysDictionary).Error\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif sysDictionary.SysDictionaryDetails != nil {\n\t\treturn global.GVA_DB.WithContext(ctx).Where(\"sys_dictionary_id=?\", sysDictionary.ID).Delete(sysDictionary.SysDictionaryDetails).Error\n\t}\n\treturn\n}\n\n//@author: [piexlmax](https://github.com/piexlmax)\n//@function: UpdateSysDictionary\n//@description: 更新字典数据","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_dictionary.go#L25-L61","documentation":"DeleteSysDictionary first loads the dictionary (with its details) by the given ID. If the record is not found, it returns this playful message instead of a raw gorm.ErrRecordNotFound, signaling the caller tried to delete a dictionary that doesn't exist. Any other DB error is passed through unchanged.","triggerScenarios":"Calling DeleteSysDictionary with a SysDictionary whose ID doesn't exist — deleted already, wrong ID, or ID=0 from an unbound request.","commonSituations":"Double-click delete (second request hits an already-deleted row); stale list data after another admin deleted it; API consumers passing fabricated IDs; tests with unpersisted structs.","solutions":["Refresh the dictionary list and confirm the record still exists before deleting","Verify the ID being sent is the actual dictionary ID (not 0/undefined)","Treat this as an idempotent outcome if the goal is 'ensure deleted' — ignore or handle gracefully in the caller"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var count int64\nglobal.GVA_DB.Model(&system.SysDictionary{}).Where(\"id = ?\", dict.ID).Count(&count)\nif count == 0 {\n    return errors.New(\"dictionary not found; nothing to delete\")\n}","typeGuard":null,"tryCatchPattern":"if err := dictService.DeleteSysDictionary(ctx, dict); err != nil {\n    if err.Error() == \"请不要搞事\" {\n        // record already gone: treat as idempotent success or refresh list\n        return nil\n    }\n    return err\n}","preventionTips":["Refresh list data before deleting so IDs are current","Avoid double-submitting delete requests (disable button while in-flight)","Handle 'already deleted' as a non-fatal idempotent outcome in batch jobs","Verify the ID is non-zero before calling delete"],"tags":["dictionary","record-not-found","go"],"backgroundTag":"record-not-found-on-delete","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}