diff --git a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
index ceb967c..e4f8d99 100644
--- a/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
+++ b/ZR.Admin.WebApi/Controllers/CodeGeneratorController.cs
@@ -67,22 +67,6 @@ namespace ZR.Admin.WebApi.Controllers
return SUCCESS(vm);
}
- /////
- ///// 获取表格列
- /////
- /////
- /////
- /////
- //[HttpGet("getColumnInfo")]
- //[ActionPermissionFilter(Permission = "tool:gen:list")]
- //public IActionResult QueryColumnInfo(string dbName, string tableName)
- //{
- // if (string.IsNullOrEmpty(dbName) || string.IsNullOrEmpty(tableName))
- // return ToRespose(ResultCode.PARAM_ERROR);
-
- // return SUCCESS(_CodeGeneraterService.GetColumnInfo(dbName, tableName));
- //}
-
///
/// 代码生成器
///
@@ -149,7 +133,7 @@ namespace ZR.Admin.WebApi.Controllers
public IActionResult Remove(string tableIds)
{
long[] tableId = Tools.SpitLongArrary(tableIds);
-
+
GenTableService.DeleteGenTableByIds(tableId);
return SUCCESS(1);
}
@@ -207,7 +191,7 @@ namespace ZR.Admin.WebApi.Controllers
TableName = tableName,
CsharpType = TableMappingHelper.GetPropertyDatatype(column.DataType),
CsharpField = column.DbColumnName.Substring(0, 1).ToUpper() + column.DbColumnName[1..],
- IsRequired = column.IsNullable,
+ IsRequired = !column.IsNullable,
IsIncrement = column.IsIdentity,
Create_by = userName,
Create_time = DateTime.Now,
@@ -222,19 +206,23 @@ namespace ZR.Admin.WebApi.Controllers
{
genTableColumn.HtmlType = GenConstants.HTML_IMAGE_UPLOAD;
}
- if (genTableColumn.CsharpType.ToLower().Contains("datetime"))
+ else if (genTableColumn.CsharpType.ToLower().Contains("datetime"))
{
genTableColumn.HtmlType = GenConstants.HTML_DATETIME;
}
- if (CodeGeneratorTool.radioFiled.Any(f => column.DbColumnName.Contains(f)))
+ else if (CodeGeneratorTool.radioFiled.Any(f => column.DbColumnName.Contains(f)))
{
genTableColumn.HtmlType = GenConstants.HTML_RADIO;
}
- if (column.Length > 200)
+ else if (CodeGeneratorTool.selectFiled.Any(f => column.DbColumnName.Contains(f)))
+ {
+ genTableColumn.HtmlType = GenConstants.HTML_SELECT;
+ }
+ else if (column.Length > 300)
{
genTableColumn.HtmlType = GenConstants.HTML_TEXTAREA;
}
-
+
genTableColumns.Add(genTableColumn);
}
@@ -251,14 +239,14 @@ namespace ZR.Admin.WebApi.Controllers
/// 代码生成保存
///
///
- [HttpPut()]
+ [HttpPut]
//[Log(Title = "代码生成", BusinessType = BusinessType.UPDATE)]
[ActionPermissionFilter(Permission = "tool:gen:edit")]
- public IActionResult EditSave([FromBody]GenTableDto genTableDto)
+ public IActionResult EditSave([FromBody] GenTableDto genTableDto)
{
if (genTableDto == null) throw new CustomException("请求参数错误");
- var genTable = genTableDto.Adapt().ToUpdate();
-
+ var genTable = genTableDto.Adapt().ToUpdate(HttpContext);
+
int rows = GenTableService.UpdateGenTable(genTable);
if (rows > 0)
{
diff --git a/ZR.Admin.WebApi/Extensions/EntityExtension.cs b/ZR.Admin.WebApi/Extensions/EntityExtension.cs
index 2dfb6b3..879a258 100644
--- a/ZR.Admin.WebApi/Extensions/EntityExtension.cs
+++ b/ZR.Admin.WebApi/Extensions/EntityExtension.cs
@@ -57,7 +57,10 @@ namespace ZR.Admin.WebApi.Extensions
{
types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
}
-
+ if (types.GetProperty("Update_Time") != null)
+ {
+ types.GetProperty("Update_Time").SetValue(source, DateTime.Now, null);
+ }
//if (types.GetProperty("UpdateID") != null)
//{
// types.GetProperty("UpdateID").SetValue(source, userSession.UserID, null);
@@ -67,6 +70,10 @@ namespace ZR.Admin.WebApi.Extensions
{
types.GetProperty("UpdateBy").SetValue(source,context.GetName(), null);
}
+ if (types.GetProperty("Update_by") != null)
+ {
+ types.GetProperty("Update_by").SetValue(source, context.GetName(), null);
+ }
return source;
}
diff --git a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs
index 0720d47..d2cb61f 100644
--- a/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs
+++ b/ZR.Admin.WebApi/Extensions/HttpContextExtension.cs
@@ -71,7 +71,7 @@ namespace ZR.Admin.WebApi.Extensions
}
public static string GetName(this HttpContext context)
{
- var uid = context.User.Identity.Name;
+ var uid = context.User?.Identity?.Name;
return uid;
}
diff --git a/ZR.Admin.WebApi/Template/ControllersTemplate.txt b/ZR.Admin.WebApi/Template/ControllersTemplate.txt
index b79a47f..9bb86ba 100644
--- a/ZR.Admin.WebApi/Template/ControllersTemplate.txt
+++ b/ZR.Admin.WebApi/Template/ControllersTemplate.txt
@@ -80,9 +80,12 @@ namespace {ApiControllerNamespace}.Controllers
throw new CustomException("请求参数错误");
}
//从 Dto 映射到 实体
- var addModel = parm.Adapt<{ModelName}>().ToCreate();
+ var model = parm.Adapt<{ModelName}>().ToCreate();
- return SUCCESS(_{ModelName}Service.Add(addModel));
+ return SUCCESS(_{ModelName}Service.Add(model, it => new
+ {
+ {InsertColumn}
+ }));
}
///
@@ -99,9 +102,9 @@ namespace {ApiControllerNamespace}.Controllers
throw new CustomException("请求实体不能为空");
}
//从 Dto 映射到 实体
- var updateModel = parm.Adapt<{ModelName}>().ToUpdate();
+ var model = parm.Adapt<{ModelName}>().ToUpdate();
- var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == updateModel.{PrimaryKey}, it => new {ModelName}()
+ var response = _{ModelName}Service.Update(w => w.{PrimaryKey} == model.{PrimaryKey}, it => new {ModelName}()
{
//Update 字段映射
{UpdateColumn}
diff --git a/ZR.Admin.WebApi/Template/InputDtoTemplate.txt b/ZR.Admin.WebApi/Template/InputDtoTemplate.txt
index 656cdad..0398c07 100644
--- a/ZR.Admin.WebApi/Template/InputDtoTemplate.txt
+++ b/ZR.Admin.WebApi/Template/InputDtoTemplate.txt
@@ -13,8 +13,12 @@ namespace {DtosNamespace}.Dto
{PropertyName}
}
+ ///
+ /// {TableNameDesc}查询对象模型
+ ///
public class {ModelTypeName}QueryDto: PagerInfo
{
+{QueryProperty}
public DateTime? BeginTime { get; set; }
public DateTime? EndTime { get; set; }
}
diff --git a/ZR.Admin.WebApi/Template/VueTemplate.txt b/ZR.Admin.WebApi/Template/VueTemplate.txt
index ac347d3..cd4562f 100644
--- a/ZR.Admin.WebApi/Template/VueTemplate.txt
+++ b/ZR.Admin.WebApi/Template/VueTemplate.txt
@@ -1,24 +1,8 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ {vueQueryFormHtml}
搜索
@@ -47,7 +31,7 @@
编辑
-
+
删除
@@ -103,8 +87,7 @@ export default {
form: {},
// 时间范围数组
timeRange: [],
- // xxx下拉框
- statusOptions: [],
+ {VueDataContent}
// 数据列表
dataList: [],
// 总记录数
diff --git a/ZR.CodeGenerator/CodeGenerateTemplate.cs b/ZR.CodeGenerator/CodeGenerateTemplate.cs
index da85852..0790591 100644
--- a/ZR.CodeGenerator/CodeGenerateTemplate.cs
+++ b/ZR.CodeGenerator/CodeGenerateTemplate.cs
@@ -1,9 +1,4 @@
-using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
using ZR.CodeGenerator.CodeGenerator;
using ZR.Model.System.Generate;
@@ -14,8 +9,6 @@ namespace ZR.CodeGenerator
///
public class CodeGenerateTemplate
{
- #region Template
-
///
/// 生成vuejs模板,目前只有上传文件方法
///
@@ -27,10 +20,10 @@ namespace ZR.CodeGenerator
string js = "";
if (dbColumnInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
{
- js += $"handleUpload{columnName}Success(res, file) {{\n";
- js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\n";
- js += " // this.$refs.upload.clearFiles();\n";
- js += "},\n";
+ js += $"handleUpload{columnName}Success(res, file) {{\r\n";
+ js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\r\n";
+ js += " // this.$refs.upload.clearFiles();\r\n";
+ js += " },\r";
}
return js;
}
@@ -40,17 +33,17 @@ namespace ZR.CodeGenerator
{
string vueViewEditFromRuleContent = "";
//Rule 规则验证
- if (!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement)
+ if ((!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement) && dbFieldInfo.IsRequired)
{
- vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\n";
- vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}},\n";
- vueViewEditFromRuleContent += " ],\n";
+ vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\r\n";
+ vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}},\r\n";
+ vueViewEditFromRuleContent += " ],\r\n";
}
else if (TableMappingHelper.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired)
{
- vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\n";
- vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}},\n";
- vueViewEditFromRuleContent += " ],\n";
+ vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\r\n";
+ vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}},\r\n";
+ vueViewEditFromRuleContent += " ],\r\n";
}
return vueViewEditFromRuleContent;
@@ -60,28 +53,57 @@ namespace ZR.CodeGenerator
public static string GetModelTemplate(GenTableColumn dbFieldInfo)
{
var modelcontent = "";
- modelcontent += " /// \n";
- modelcontent += $" /// 描述 :{dbFieldInfo.ColumnComment}\n";
- modelcontent += $" /// 空值 :{dbFieldInfo.IsRequired}\n";
- modelcontent += " /// \n";
+ modelcontent += " /// \r\n";
+ modelcontent += $" /// 描述 :{dbFieldInfo.ColumnComment}\r\n";
+ modelcontent += $" /// 空值 :{!dbFieldInfo.IsRequired}\r\n";
+ modelcontent += " /// \r\n";
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
{
- modelcontent += $"[SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]\n";
+ modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]\r\n";
}
- modelcontent += $"public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\n\r";
+ modelcontent += $" public {dbFieldInfo.CsharpType}{(GetModelRequired(dbFieldInfo))} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
return modelcontent;
}
+ public static string GetModelRequired(GenTableColumn dbFieldInfo)
+ {
+ string str = "";
+ if (!dbFieldInfo.IsRequired && (dbFieldInfo.CsharpType == "int" || dbFieldInfo.CsharpType == "long" || dbFieldInfo.CsharpType == "DateTime"))
+ {
+ str = "?";
+ }
+
+ return str;
+ }
//DTO model
- public static string GetDtoContent(GenTableColumn dbFieldInfo)
+ public static string GetDtoProperty(GenTableColumn dbFieldInfo)
{
string InputDtoContent = "";
- if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit)
+ if (CodeGeneratorTool.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
{
- InputDtoContent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\n\r";
+ return InputDtoContent;
+ }
+ else if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit || dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
+ {
+ InputDtoContent += $" public {dbFieldInfo.CsharpType}{GetModelRequired(dbFieldInfo)} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
}
return InputDtoContent;
}
+ ///
+ /// 查询Dto属性
+ ///
+ ///
+ ///
+ public static string GetQueryDtoProperty(GenTableColumn dbFieldInfo)
+ {
+ string QueryDtoContent = "";
+ if (dbFieldInfo.IsQuery && !CodeGeneratorTool.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
+ {
+ QueryDtoContent += $" public {dbFieldInfo.CsharpType} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
+ }
+
+ return QueryDtoContent;
+ }
//form-item
public static string GetVueViewFormContent(GenTableColumn dbFieldInfo)
@@ -91,6 +113,10 @@ namespace ZR.CodeGenerator
string vueViewFromContent = "";
string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : "";
string placeHolder = dbFieldInfo.IsIncrement ? "" : $"请输入{labelName}";
+ if (CodeGeneratorTool.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
+ {
+ return vueViewFromContent;
+ }
if (!dbFieldInfo.IsInsert || !dbFieldInfo.IsEdit)
{
return vueViewFromContent;
@@ -98,47 +124,83 @@ namespace ZR.CodeGenerator
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
{
//时间
- vueViewFromContent += $" \n";
- vueViewFromContent += $" \n";
- vueViewFromContent += " \n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += " \r\n";
}
else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
{
//图片
- vueViewFromContent += $" \n";
- vueViewFromContent += $" \n";
- vueViewFromContent += $"
\n";
- vueViewFromContent += " \n";
- vueViewFromContent += " \n";
- vueViewFromContent += $" \n";
- vueViewFromContent += " \n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $"
\r\n";
+ vueViewFromContent += " \r\n";
+ vueViewFromContent += " \r\n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += " \r\n";
}
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
{
- vueViewFromContent += $" \n";
- vueViewFromContent += $" \n";
- vueViewFromContent += " 是\n";
- vueViewFromContent += " 否\n";
- vueViewFromContent += " \n";
- vueViewFromContent += " \n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += " 是\r\n";
+ vueViewFromContent += " 否\r\n";
+ vueViewFromContent += " \r\n";
+ vueViewFromContent += " \r\n";
}
else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
{
- vueViewFromContent += $" \n";
- vueViewFromContent += $" \n";
- vueViewFromContent += " \n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += " \r\n";
+ }
+ else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
+ {
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $" ";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += " \r\n";
+ vueViewFromContent += " \r\n";
}
else
{
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
- vueViewFromContent += $" \n";
- vueViewFromContent += $" \n";
- vueViewFromContent += " \n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += $" \r\n";
+ vueViewFromContent += " \r\n";
}
return vueViewFromContent;
}
+ ///
+ /// 查询表单
+ ///
+ ///
+ ///
+ public static string GetQueryFormHtml(GenTableColumn dbFieldInfo)
+ {
+ string queryFormHtml = "";
+ string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
+ if (!dbFieldInfo.IsQuery || dbFieldInfo.HtmlType == GenConstants.HTML_FILE_UPLOAD) return queryFormHtml;
+
+ if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
+ {
+ queryFormHtml += "\r\n";
+ queryFormHtml += " \r\n";
+ queryFormHtml += "\r\n";
+ }
+ else
+ {
+ string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
+ queryFormHtml += $" \r\n";
+ queryFormHtml += $" \r\n";
+ queryFormHtml += " \r\n";
+ }
+
+ return queryFormHtml;
+ }
+
//table-column
public static string GetTableColumn(GenTableColumn dbFieldInfo)
{
@@ -152,28 +214,26 @@ namespace ZR.CodeGenerator
}
else if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
{
- vueViewListContent += $" \n";
- vueViewListContent += " \n";
- vueViewListContent += $" \n";
- vueViewListContent += " \n";
- vueViewListContent += " \n";
+ vueViewListContent += $" \r\n";
+ vueViewListContent += " \r\n";
+ vueViewListContent += $" \r\n";
+ vueViewListContent += " \r\n";
+ vueViewListContent += " \r\n";
}
//else if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_RADIO))
//{
- // vueViewListContent += $" \n";
- // vueViewListContent += " \n";
+ // vueViewListContent += $" \r\n";
+ // vueViewListContent += " \r\n";
// vueViewListContent += $" ";
- // vueViewListContent += $" {{scope.row.{columnName}===true?'启用':'禁用'}} \n";
- // vueViewListContent += " \n";
- // vueViewListContent += " \n";
+ // vueViewListContent += $" {{scope.row.{columnName}===true?'启用':'禁用'}} \r\n";
+ // vueViewListContent += " \r\n";
+ // vueViewListContent += " \r\n";
//}
else
{
- vueViewListContent += $" \n";
+ vueViewListContent += $" \r\n";
}
return vueViewListContent;
}
- #endregion
-
}
}
diff --git a/ZR.CodeGenerator/CodeGeneratorTool.cs b/ZR.CodeGenerator/CodeGeneratorTool.cs
index 8ff4d6e..c95e7bb 100644
--- a/ZR.CodeGenerator/CodeGeneratorTool.cs
+++ b/ZR.CodeGenerator/CodeGeneratorTool.cs
@@ -23,7 +23,7 @@ namespace ZR.CodeGenerator
///
/// InputDto输入实体是不包含字段
///
- public static readonly string[] inputDtoNoField = new string[] { "DeleteMark", "CreateTime", "updateTime", "addtime" };
+ public static readonly string[] inputDtoNoField = new string[] { "createTime", "updateTime", "addtime" };
public static readonly string[] imageFiled = new string[] { "icon", "img", "image", "url", "pic", "photo" };
public static readonly string[] selectFiled = new string[] { "status", "type", "state", "sex", "gender" };
public static readonly string[] radioFiled = new string[] { "status", "state", "isShow", "isHidden", "ishide" };
@@ -46,11 +46,7 @@ namespace ZR.CodeGenerator
_option.ServicesNamespace = _option.BaseNamespace + "Service";
_option.ApiControllerNamespace = _option.BaseNamespace + "Admin.WebApi";
- //CodeGeneraterService codeGeneraterService = new();
- //List listField = codeGeneraterService.GetColumnInfo(dto.dbName, dbTableInfo.TableName);
GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
-
- //GenerateDtoProfile(_option.ModelsNamespace, profileContent, ifExsitedCovered);
}
///
@@ -61,19 +57,12 @@ namespace ZR.CodeGenerator
///
public static void GenerateSingle(List listField, GenTable tableInfo, GenerateDto dto)
{
- var modelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
-
string PKName = "id";
string PKType = "int";
- string modelContent = "";//数据库模型字段
- string InputDtoContent = "";//输入模型
- //string outputDtoContent = "";//输出模型
- string updateColumn = "";//修改数据映射字段
- string vueViewListContent = string.Empty;//Vue列表输出内容
- string vueViewFormContent = string.Empty;//Vue表单输出内容
- string vueViewEditFromContent = string.Empty;//Vue变量输出内容
- string vueViewEditFromRuleContent = string.Empty;//Vue数据校验
- string vueJsMethod = string.Empty;//Vue js自定义方法
+ ReplaceDto replaceDto = new();
+ replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
+ replaceDto.TableName = tableInfo.TableName;
+ replaceDto.TableDesc = tableInfo.TableComment;
//循环表字段信息
foreach (GenTableColumn dbFieldInfo in listField)
@@ -82,7 +71,7 @@ namespace ZR.CodeGenerator
if (dbFieldInfo.IsInsert || dbFieldInfo.IsEdit)
{
- vueViewEditFromContent += $" {columnName}: undefined,\n";
+ replaceDto.VueViewEditFormHtml += $"{columnName}: undefined,\r\n";
}
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
{
@@ -92,30 +81,35 @@ namespace ZR.CodeGenerator
//编辑字段
if (dbFieldInfo.IsEdit)
{
- updateColumn += $" {dbFieldInfo.CsharpField} = parm.{dbFieldInfo.CsharpField},\n";
+ replaceDto.UpdateColumn += $"{dbFieldInfo.CsharpField} = model.{dbFieldInfo.CsharpField}, ";
+ }
+ //新增字段
+ if (dbFieldInfo.IsInsert)
+ {
+ replaceDto.InsertColumn += $"it.{dbFieldInfo.CsharpField}, ";
+ }
+ //查询
+ //if (dbFieldInfo.IsQuery)
+ //{
+ // replaceDto.Querycondition += $"predicate = predicate.And(m => m.{dbFieldInfo.CsharpField}.Contains(parm.Name));";
+ //}
+ if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
+ {
+ replaceDto.VueDataContent += $"// {dbFieldInfo.ColumnComment}选项列表\n";
+ replaceDto.VueDataContent += $"{FirstLowerCase(dbFieldInfo.CsharpField)}Options: [],";
}
- modelContent += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
- vueViewFormContent += CodeGenerateTemplate.GetVueViewFormContent(dbFieldInfo);
- vueJsMethod += CodeGenerateTemplate.GetVueJsMethod(dbFieldInfo);
- vueViewListContent += CodeGenerateTemplate.GetTableColumn(dbFieldInfo);
- vueViewEditFromRuleContent += CodeGenerateTemplate.GetFormRules(dbFieldInfo);
- InputDtoContent += CodeGenerateTemplate.GetDtoContent(dbFieldInfo);
+ replaceDto.QueryProperty += CodeGenerateTemplate.GetQueryDtoProperty(dbFieldInfo);
+ replaceDto.ModelProperty += CodeGenerateTemplate.GetModelTemplate(dbFieldInfo);
+ replaceDto.VueViewFormHtml += CodeGenerateTemplate.GetVueViewFormContent(dbFieldInfo);
+ replaceDto.VueJsMethod += CodeGenerateTemplate.GetVueJsMethod(dbFieldInfo);
+ replaceDto.VueViewListHtml += CodeGenerateTemplate.GetTableColumn(dbFieldInfo);
+ replaceDto.VueViewEditFormRuleContent += CodeGenerateTemplate.GetFormRules(dbFieldInfo);
+ replaceDto.InputDtoProperty += CodeGenerateTemplate.GetDtoProperty(dbFieldInfo);
+ replaceDto.VueQueryFormHtml += CodeGenerateTemplate.GetQueryFormHtml(dbFieldInfo);
}
- ReplaceDto replaceDto = new();
replaceDto.PKName = PKName;
replaceDto.PKType = PKType;
- replaceDto.ModelTypeName = modelTypeName;
- replaceDto.ModelProperty = modelContent;
- replaceDto.TableName = tableInfo.TableName;
- replaceDto.TableDesc = tableInfo.TableComment;
- replaceDto.InputDtoProperty = InputDtoContent;
- replaceDto.updateColumn = updateColumn;
- replaceDto.VueJsMethod = vueJsMethod;
- replaceDto.VueViewEditFormHtml = vueViewEditFromContent;
- replaceDto.VueViewFormHtml = vueViewFormContent;
- replaceDto.VueViewEditFormRuleContent = vueViewEditFromRuleContent;
- replaceDto.VueViewListHtml = vueViewListContent;
if (dto.genFiles.Contains(1))
{
@@ -205,6 +199,7 @@ namespace ZR.CodeGenerator
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
.Replace("{TableNameDesc}", replaceDto.TableDesc)
.Replace("{PropertyName}", replaceDto.InputDtoProperty)
+ .Replace("{QueryProperty}", replaceDto.QueryProperty)
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
WriteAndSave(fullPath, content);
return Tuple.Create(fullPath, content);
@@ -330,7 +325,8 @@ namespace ZR.CodeGenerator
.Replace("{ModelName}", replaceDto.ModelTypeName)
.Replace("{Permission}", replaceDto.ModelTypeName.ToLower())
.Replace("{PrimaryKey}", replaceDto.PKName)
- .Replace("{UpdateColumn}", replaceDto.updateColumn)
+ .Replace("{UpdateColumn}", replaceDto.UpdateColumn)
+ .Replace("{InsertColumn}", replaceDto.InsertColumn)
.Replace("{KeyTypeName}", replaceDto.PKType);
WriteAndSave(fullPath, content);
return Tuple.Create(fullPath, content);
@@ -362,7 +358,8 @@ namespace ZR.CodeGenerator
.Replace("{Permission}", replaceDto.ModelTypeName.ToLower())
.Replace("{VueViewEditFormContent}", replaceDto.VueViewEditFormHtml)
.Replace("{vueJsMethod}", replaceDto.VueJsMethod)
- //.Replace("{VueViewEditFromBindContent}", vueViewEditFromBindContent)
+ .Replace("{vueQueryFormHtml}", replaceDto.VueQueryFormHtml)
+ .Replace("{VueDataContent}", replaceDto.VueDataContent)
//.Replace("{VueViewSaveBindContent}", vueViewSaveBindContent)
.Replace("{primaryKey}", FirstLowerCase(replaceDto.PKName))
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
@@ -458,7 +455,6 @@ namespace ZR.CodeGenerator
sr?.Close();
sr?.Dispose();
return str;
-
}
///
diff --git a/ZR.CodeGenerator/Model/ReplaceDto.cs b/ZR.CodeGenerator/Model/ReplaceDto.cs
index e1a16b5..e95dc01 100644
--- a/ZR.CodeGenerator/Model/ReplaceDto.cs
+++ b/ZR.CodeGenerator/Model/ReplaceDto.cs
@@ -39,7 +39,14 @@ namespace ZR.CodeGenerator.Model
/// 表描述、说明
///
public string TableDesc { get; set; }
- public string updateColumn { get; set; }
+ ///
+ /// 修改列
+ ///
+ public string UpdateColumn { get; set; }
+ ///
+ /// 插入列
+ ///
+ public string InsertColumn { get; set; }
///
@@ -65,7 +72,25 @@ namespace ZR.CodeGenerator.Model
/// 前端搜索表单html
///
public string VueQueryFormHtml { get; set; }
+ ///
+ /// vue js方法
+ ///
public string VueJsMethod { get; set; }
+ ///
+ /// vue 添加、编辑表单规则
+ ///
public string VueViewEditFormRuleContent { get; set; }
+ ///
+ /// 查询条件
+ ///
+ public string QueryCondition { get; set; }
+ ///
+ /// 查询属性
+ ///
+ public string QueryProperty { get; set; }
+ ///
+ /// vue data内容
+ ///
+ public string VueDataContent { get; set; }
}
}
diff --git a/ZR.Model/System/Dto/GenTableDto.cs b/ZR.Model/System/Dto/GenTableDto.cs
index b5267b0..7820d7b 100644
--- a/ZR.Model/System/Dto/GenTableDto.cs
+++ b/ZR.Model/System/Dto/GenTableDto.cs
@@ -27,27 +27,27 @@ namespace ZR.Model.System.Dto
public class GenTableColumnDto
{
public int ColumnId { get; set; }
- public string ColumnName { get; set; }
public int TableId { get; set; }
-
- public string TableName { get; set; }
public string ColumnComment { get; set; }
-
- public string ColumnType { get; set; }
public string CsharpType { get; set; }
public string CsharpField { get; set; }
- public bool IsPk { get; set; }
public bool IsInsert { get; set; }
+ public bool IsEdit { get; set; }
public bool IsList { get; set; }
- //public bool IsQuery { get; set; }
- /////
- ///// 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
- /////
+ public bool IsQuery { get; set; }
+ public bool IsRequired { get; set; }
+ ///
+ /// 显示类型(文本框、文本域、下拉框、复选框、单选框、日期控件)
+ ///
public string HtmlType { get; set; }
- /////
- ///// 查询类型(等于、不等于、大于、小于、范围)
- /////
- //public string QueryType { get; set; } = "EQ";
- //public int Sort { get; set; }
+ ///
+ /// 查询类型(等于、不等于、大于、小于、范围)
+ ///
+ public string QueryType { get; set; } = "EQ";
+ public int Sort { get; set; }
+ ///
+ /// 字典类型
+ ///
+ public string DictType { get; set; }
}
}
diff --git a/ZR.Model/System/Generate/GenTableColumn.cs b/ZR.Model/System/Generate/GenTableColumn.cs
index 3206d37..e517540 100644
--- a/ZR.Model/System/Generate/GenTableColumn.cs
+++ b/ZR.Model/System/Generate/GenTableColumn.cs
@@ -58,5 +58,9 @@ namespace ZR.Model.System.Generate
///
public string QueryType { get; set; } = "EQ";
public int Sort { get; set; }
+ ///
+ /// 字典类型
+ ///
+ public string DictType { get; set; }
}
}
diff --git a/ZR.Model/System/SysBase.cs b/ZR.Model/System/SysBase.cs
index ced566a..3eb14af 100644
--- a/ZR.Model/System/SysBase.cs
+++ b/ZR.Model/System/SysBase.cs
@@ -22,10 +22,10 @@ namespace ZR.Model.System
[SugarColumn(IsOnlyIgnoreInsert = true)]
public string Update_by { get; set; }
+ //[JsonIgnore]
[SugarColumn(IsOnlyIgnoreInsert = true)]//设置后插入数据不会有此字段
- [JsonIgnore]
[JsonProperty(propertyName: "UpdateTime")]
- public DateTime Update_time { get; set; } = DateTime.Now;
+ public DateTime Update_time { get; set; }
public string Remark { get; set; }
diff --git a/ZR.Service/BaseService.cs b/ZR.Service/BaseService.cs
index 23c9f61..8eb83d0 100644
--- a/ZR.Service/BaseService.cs
+++ b/ZR.Service/BaseService.cs
@@ -54,6 +54,18 @@ namespace ZR.Service
return Db.Insertable(parm).RemoveDataCache().ExecuteCommand();
}
+ ///
+ /// 添加
+ ///
+ ///
+ /// 插入列
+ /// 忽略null列
+ ///
+ public int Add(T parm, Expression> iClumns = null, bool ignoreNull = true)
+ {
+ return Db.Insertable(parm).InsertColumns(iClumns).IgnoreColumns(ignoreNullColumn: ignoreNull).ExecuteCommand();
+ }
+
///
/// 批量添加数据
///
@@ -166,7 +178,7 @@ namespace ZR.Service
/// 查询所有数据(无分页,请慎用)
///
///
- public List GetAll(bool useCache = false, int cacheSecond = 3600)
+ public List GetAll(bool useCache = false, int cacheSecond = 3600)
{
return Db.Queryable().WithCacheIF(useCache, cacheSecond).ToList();
}
diff --git a/ZR.Service/IBaseService.cs b/ZR.Service/IBaseService.cs
index e77d47b..38d2065 100644
--- a/ZR.Service/IBaseService.cs
+++ b/ZR.Service/IBaseService.cs
@@ -42,6 +42,8 @@ namespace ZR.Service
///
int Add(T parm);
+ int Add(T parm, Expression> iClumns = null, bool ignoreNull = false);
+
///
/// 批量添加数据
///
diff --git a/ZR.Service/System/GenTableService.cs b/ZR.Service/System/GenTableService.cs
index 78689e1..782324e 100644
--- a/ZR.Service/System/GenTableService.cs
+++ b/ZR.Service/System/GenTableService.cs
@@ -153,7 +153,7 @@ namespace ZR.Service.System
///
public int InsertGenTableColumn(List tableColumn)
{
- return Db.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark}).ExecuteCommand();
+ return Db.Insertable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand();
}
///
@@ -163,7 +163,31 @@ namespace ZR.Service.System
///
public int UpdateGenTableColumn(List tableColumn)
{
- return Db.Updateable(tableColumn).IgnoreColumns(x => new { x.Remark }).ExecuteCommand();
+ foreach (var item in tableColumn)
+ {
+ Db.Updateable()
+ .Where(f => f.TableId == item.TableId)
+ .SetColumns(it => new GenTableColumn()
+ {
+ ColumnComment = item.ColumnComment,
+ CsharpField = item.CsharpField,
+ CsharpType = item.CsharpType,
+ IsQuery = item.IsQuery,
+ IsEdit = item.IsEdit,
+ IsInsert = item.IsInsert,
+ IsList = item.IsList,
+ QueryType = item.QueryType,
+ HtmlType = item.HtmlType,
+ IsRequired = item.IsRequired,
+ Sort = item.Sort,
+ Update_time = DateTime.Now,
+ DictType = item.DictType
+ })
+ .Where(f => f.ColumnId == item.ColumnId)
+ .ExecuteCommand();
+ }
+
+ return 1;
}
}
}
diff --git a/ZR.Vue/src/views/tool/gen/basicInfoForm.vue b/ZR.Vue/src/views/tool/gen/basicInfoForm.vue
index 757962c..afe4a5b 100644
--- a/ZR.Vue/src/views/tool/gen/basicInfoForm.vue
+++ b/ZR.Vue/src/views/tool/gen/basicInfoForm.vue
@@ -1,23 +1,23 @@
-
+
-
+
-
+
-
+
-
+
diff --git a/ZR.Vue/src/views/tool/gen/editTable.vue b/ZR.Vue/src/views/tool/gen/editTable.vue
index 18481f3..cbd5dde 100644
--- a/ZR.Vue/src/views/tool/gen/editTable.vue
+++ b/ZR.Vue/src/views/tool/gen/editTable.vue
@@ -22,7 +22,7 @@
-
+
@@ -31,25 +31,29 @@
-
+
+
+
+
+
-
+
-
+
-
+
-
+
@@ -66,11 +70,6 @@
-
-
-
-
-
@@ -114,7 +113,7 @@