fix: 自动化代码需检测简称,简称不可以重复。

This commit is contained in:
pixelmaxQM
2024-11-11 22:40:41 +08:00
parent 58204373aa
commit fbd0f4b9c6
6 changed files with 18 additions and 8 deletions
+2 -2
View File
@@ -52,9 +52,9 @@ func (s *autoCodeHistory) First(ctx context.Context, info common.GetById) (strin
// Repeat 检测重复
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (s *autoCodeHistory) Repeat(businessDB, structName, Package string) bool {
func (s *autoCodeHistory) Repeat(businessDB, structName, abbreviation, Package string) bool {
var count int64
global.GVA_DB.Model(&model.SysAutoCodeHistory{}).Where("business_db = ? and struct_name = ? and package = ? and flag = 0", businessDB, structName, Package).Count(&count)
global.GVA_DB.Model(&model.SysAutoCodeHistory{}).Where("business_db = ? and (struct_name = ? OR abbreviation = ?) and package = ?", businessDB, structName, abbreviation, Package).Count(&count).Debug()
return count > 0
}
+7 -2
View File
@@ -64,8 +64,8 @@ func (s *autoCodeTemplate) Create(ctx context.Context, info request.AutoCode) er
if err != nil {
return err
}
// 增加判断: 重复创建struct
if AutocodeHistory.Repeat(info.BusinessDB, info.StructName, info.Package) {
// 增加判断: 重复创建struct 或者重复的简称
if AutocodeHistory.Repeat(info.BusinessDB, info.StructName, info.Abbreviation, info.Package) {
return errors.New("已经创建过此数据结构,请勿重复创建!")
}
@@ -190,6 +190,11 @@ func (s *autoCodeTemplate) Preview(ctx context.Context, info request.AutoCode) (
if err != nil {
return nil, errors.Wrap(err, "查询包失败!")
}
// 增加判断: 重复创建struct 或者重复的简称
if AutocodeHistory.Repeat(info.BusinessDB, info.StructName, info.Abbreviation, info.Package) {
return nil, errors.New("已经创建过此数据结构或重复简称,请勿重复创建!")
}
codes := make(map[string]strings.Builder)
preview := make(map[string]string)
codes, _, _, err = s.generate(ctx, info, entity)