diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt index b2f9efc4..51d59833 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt @@ -90,7 +90,6 @@ $if(replaceDto.ShowBtnAdd) { throw new CustomException("请求参数错误"); } - //从 Dto 映射到 实体 var modal = parm.Adapt<${replaceDto.ModelTypeName}>().ToCreate(HttpContext); var response = _${replaceDto.ModelTypeName}Service.Add${replaceDto.ModelTypeName}(modal); @@ -113,18 +112,9 @@ $if(replaceDto.ShowBtnEdit) { throw new CustomException("请求实体不能为空"); } - //从 Dto 映射到 实体 var modal = parm.Adapt<${replaceDto.ModelTypeName}>().ToUpdate(HttpContext); - var response = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == modal.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}() - { - //Update 字段映射 -$foreach(item in genTable.Columns) -$if((item.IsEdit)) - $item.CsharpField = modal.$item.CsharpField, -$end -${end} - }); + var response = _${replaceDto.ModelTypeName}Service.Update${replaceDto.ModelTypeName}(modal); return ToResponse(response); } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt index a0c2451b..f30aecd2 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplIService.txt @@ -20,5 +20,7 @@ $if(genTable.TplCategory == "tree") List<${replaceDto.ModelTypeName}> GetTreeList(${replaceDto.ModelTypeName}QueryDto parm); $end int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm); + + int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm); } } diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt index 67de9fcb..b779e2af 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplModel.txt @@ -38,12 +38,12 @@ $end $if(genTable.TplCategory == "subNav" && genTable.SubTable != null) [Navigate(NavigateType.Dynamic, null)] //自定义关系映射 - public ${genTable.SubTable.ClassName} Sub { get; set; } + public ${genTable.SubTable.ClassName} ${genTable.SubTable.ClassName} { get; set; } $end $if(genTable.TplCategory == "subNavMore" && genTable.SubTable != null) [Navigate(NavigateType.Dynamic, null)] //自定义关系映射 - public List<${genTable.SubTable.ClassName}> Sub { get; set; } + public List<${genTable.SubTable.ClassName}> ${genTable.SubTable.ClassName} { get; set; } $end } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt index a098f0bc..ce428f3c 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplService.txt @@ -54,7 +54,7 @@ $end var response = _${replaceDto.ModelTypeName}Repository .Queryable() $if(null != genTable.SubTableName && "" != genTable.SubTableName) - .Includes(it => it.Sub.MappingField(z => z.${genTable.SubTableFkName}, () => it.${replaceDto.PKName})) + .Includes(it => it.${genTable.SubTable.ClassName}.MappingField(z => z.${genTable.SubTableFkName}, () => it.${replaceDto.PKName})) $end $if(genTable.Options.SortField != "" && genTable.Options.SortField != null) .OrderBy("${genTable.Options.SortField} ${genTable.Options.SortType}") @@ -106,6 +106,24 @@ ${foreach(item in genTable.Columns)} $if((item.IsInsert)) it.$item.CsharpField, $end +${end} + }); + return response; + } + + /// + /// 修改${genTable.FunctionName} + /// + /// + /// + public int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm) + { + var response = _${replaceDto.ModelTypeName}Repository.Update(w => w.${replaceDto.PKName} == parm.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}() + { +$foreach(item in genTable.Columns) +$if((item.IsEdit)) + $item.CsharpField = parm.$item.CsharpField, +$end ${end} }); return response; diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt index 82217260..26951c8a 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/v3/Vue.txt @@ -200,7 +200,7 @@ $if(column.HtmlType == "inputNumber" || column.HtmlType == "customInput") $elseif(column.HtmlType == "datetime") - + $elseif(column.HtmlType == "imageUpload") diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs index 0f0d9857..8ec02cc4 100644 --- a/ZR.CodeGenerator/CodeGeneratorTool.cs +++ b/ZR.CodeGenerator/CodeGeneratorTool.cs @@ -48,16 +48,17 @@ namespace ZR.CodeGenerator string PKName = "Id"; string PKType = "int"; - ReplaceDto replaceDto = new(); - replaceDto.ModelTypeName = dto.GenTable.ClassName;//表名对应C# 实体类名 - replaceDto.PermissionPrefix = dto.GenTable?.Options?.PermissionPrefix; - replaceDto.Author = dto.GenTable.FunctionAuthor; - replaceDto.ShowBtnAdd = dto.GenTable.Options.CheckedBtn.Any(f => f == 1); - replaceDto.ShowBtnEdit = dto.GenTable.Options.CheckedBtn.Any(f => f == 2); - replaceDto.ShowBtnDelete = dto.GenTable.Options.CheckedBtn.Any(f => f == 3); - replaceDto.ShowBtnExport = dto.GenTable.Options.CheckedBtn.Any(f => f == 4); - replaceDto.ShowBtnView = dto.GenTable.Options.CheckedBtn.Any(f => f == 5); - + ReplaceDto replaceDto = new() + { + ModelTypeName = dto.GenTable.ClassName,//表名对应C# 实体类名 + PermissionPrefix = dto.GenTable?.Options?.PermissionPrefix, + Author = dto.GenTable.FunctionAuthor, + ShowBtnAdd = dto.GenTable.Options.CheckedBtn.Any(f => f == 1), + ShowBtnEdit = dto.GenTable.Options.CheckedBtn.Any(f => f == 2), + ShowBtnDelete = dto.GenTable.Options.CheckedBtn.Any(f => f == 3), + ShowBtnExport = dto.GenTable.Options.CheckedBtn.Any(f => f == 4), + ShowBtnView = dto.GenTable.Options.CheckedBtn.Any(f => f == 5) + }; //循环表字段信息 foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns.OrderBy(x => x.Sort)) diff --git a/ZR.Service/System/GenTableService.cs b/ZR.Service/System/GenTableService.cs index b8476965..6d90d278 100644 --- a/ZR.Service/System/GenTableService.cs +++ b/ZR.Service/System/GenTableService.cs @@ -58,7 +58,7 @@ namespace ZR.Service.System var info = GenTableRepository.GetId(tableId); if (info != null && !info.SubTableName.IsEmpty()) { - info.SubTable = GenTableRepository.Queryable().Where(f => f.SubTableName == info.TableName).First(); + info.SubTable = GenTableRepository.Queryable().Where(f => f.TableName == info.SubTableName).First(); } return info; }