优化代码生成查询
This commit is contained in:
parent
98b61a7360
commit
19eaa91b8d
@ -22,7 +22,10 @@ namespace ZR.Admin.WebApi.Extensions
|
|||||||
{
|
{
|
||||||
types.GetProperty("CreateTime").SetValue(source, DateTime.Now, null);
|
types.GetProperty("CreateTime").SetValue(source, DateTime.Now, null);
|
||||||
}
|
}
|
||||||
|
if (types.GetProperty("AddTime") != null)
|
||||||
|
{
|
||||||
|
types.GetProperty("AddTime").SetValue(source, DateTime.Now, null);
|
||||||
|
}
|
||||||
if (types.GetProperty("UpdateTime") != null)
|
if (types.GetProperty("UpdateTime") != null)
|
||||||
{
|
{
|
||||||
types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
|
types.GetProperty("UpdateTime").SetValue(source, DateTime.Now, null);
|
||||||
|
|||||||
@ -2,7 +2,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using SqlSugar;
|
|
||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Attribute;
|
using Infrastructure.Attribute;
|
||||||
using Infrastructure.Enums;
|
using Infrastructure.Enums;
|
||||||
@ -48,28 +47,7 @@ namespace ${options.ApiControllerNamespace}.Controllers
|
|||||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:list")]
|
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:list")]
|
||||||
public IActionResult Query${replaceDto.ModelTypeName}([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
public IActionResult Query${replaceDto.ModelTypeName}([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
||||||
{
|
{
|
||||||
//开始拼装查询条件
|
var response = _${replaceDto.ModelTypeName}Service.GetList(parm);
|
||||||
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
|
||||||
|
|
||||||
//搜索条件查询语法参考Sqlsugar
|
|
||||||
$foreach(column in genTable.Columns)
|
|
||||||
$if(column.IsQuery)
|
|
||||||
$if(column.CsharpType == "string")
|
|
||||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
|
||||||
$elseif(column.CsharpType == "DateTime")
|
|
||||||
predicate = predicate.AndIF(parm.Begin${column.CsharpField} == null, it => it.${column.CsharpField} >= DateTime.Now.AddDays(-1));
|
|
||||||
predicate = predicate.AndIF(parm.Begin${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.Begin${column.CsharpField});
|
|
||||||
predicate = predicate.AndIF(parm.End${column.CsharpField} != null, it => it.${column.CsharpField} <= parm.End${column.CsharpField});
|
|
||||||
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
|
|
||||||
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
|
||||||
$end
|
|
||||||
$end
|
|
||||||
$end
|
|
||||||
$if(genTable.SortField != "" && genTable.SortField != null)
|
|
||||||
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm, x => x.${genTable.SortField}, "${genTable.SortType}");
|
|
||||||
$else
|
|
||||||
var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm);
|
|
||||||
$end
|
|
||||||
return SUCCESS(response);
|
return SUCCESS(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using ${options.ModelsNamespace};
|
||||||
|
using ${options.ModelsNamespace}.Dto;
|
||||||
using ${options.ModelsNamespace}.Models;
|
using ${options.ModelsNamespace}.Models;
|
||||||
|
|
||||||
|
|
||||||
namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service
|
namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -12,5 +13,6 @@ namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNam
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface I${replaceDto.ModelTypeName}Service : IBaseService<${replaceDto.ModelTypeName}>
|
public interface I${replaceDto.ModelTypeName}Service : IBaseService<${replaceDto.ModelTypeName}>
|
||||||
{
|
{
|
||||||
|
PagedInfo<${replaceDto.ModelTypeName}> GetList(${replaceDto.ModelTypeName}QueryDto parm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using Infrastructure.Attribute;
|
using Infrastructure.Attribute;
|
||||||
|
using ${options.ModelsNamespace};
|
||||||
|
using ${options.ModelsNamespace}.Dto;
|
||||||
using ${options.ModelsNamespace}.Models;
|
using ${options.ModelsNamespace}.Models;
|
||||||
using ${options.IRepositoriesNamespace};
|
using ${options.IRepositoriesNamespace};
|
||||||
using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service;
|
using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service;
|
||||||
|
using System;
|
||||||
|
using SqlSugar;
|
||||||
|
|
||||||
namespace ${options.ServicesNamespace}.${options.SubNamespace}
|
namespace ${options.ServicesNamespace}.${options.SubNamespace}
|
||||||
{
|
{
|
||||||
@ -23,6 +27,38 @@ namespace ${options.ServicesNamespace}.${options.SubNamespace}
|
|||||||
|
|
||||||
#region 业务逻辑代码
|
#region 业务逻辑代码
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查询${genTable.FunctionName}列表
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public PagedInfo<${replaceDto.ModelTypeName}> GetList(${replaceDto.ModelTypeName}QueryDto parm)
|
||||||
|
{
|
||||||
|
//开始拼装查询条件
|
||||||
|
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
||||||
|
|
||||||
|
//搜索条件查询语法参考Sqlsugar
|
||||||
|
$foreach(column in genTable.Columns)
|
||||||
|
$if(column.IsQuery)
|
||||||
|
$if(column.CsharpType == "string")
|
||||||
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
||||||
|
$elseif(column.CsharpType == "DateTime")
|
||||||
|
predicate = predicate.AndIF(parm.Begin${column.CsharpField} == null, it => it.${column.CsharpField} >= DateTime.Now.AddDays(-1));
|
||||||
|
predicate = predicate.AndIF(parm.Begin${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.Begin${column.CsharpField});
|
||||||
|
predicate = predicate.AndIF(parm.End${column.CsharpField} != null, it => it.${column.CsharpField} <= parm.End${column.CsharpField});
|
||||||
|
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
|
||||||
|
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
||||||
|
$end
|
||||||
|
$end
|
||||||
|
$end
|
||||||
|
$if(genTable.SortField != "" && genTable.SortField != null)
|
||||||
|
var response = Queryable().GetPages(predicate.ToExpression(), parm, x => x.${genTable.SortField}, "${genTable.SortType}");
|
||||||
|
$else
|
||||||
|
var response = Queryable().Where(predicate.ToExpression()).ToPage(parm);
|
||||||
|
$end
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using ZR.CodeGenerator.Model;
|
|
||||||
using ZR.Model.System.Generate;
|
using ZR.Model.System.Generate;
|
||||||
|
|
||||||
namespace ZR.CodeGenerator
|
namespace ZR.CodeGenerator
|
||||||
@ -98,10 +97,10 @@ namespace ZR.CodeGenerator
|
|||||||
sb.AppendLine(" <el-col :lg=\"12\">");
|
sb.AppendLine(" <el-col :lg=\"12\">");
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($" <el-radio-group v-model=\"form.{columnName}\">");
|
sb.AppendLine($" <el-radio-group v-model=\"form.{columnName}\">");
|
||||||
if (string.IsNullOrEmpty(dbFieldInfo.DictType))
|
//if (string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||||
{
|
//{
|
||||||
sb.AppendLine(" <el-radio :label=\"1\">请选择字典生成</el-radio>");
|
// sb.AppendLine(" <el-radio :label=\"1\">请选择字典生成</el-radio>");
|
||||||
}
|
//}
|
||||||
sb.AppendLine($" <el-radio v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"{value}\">{{{{item.dictLabel}}}}</el-radio>");
|
sb.AppendLine($" <el-radio v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"{value}\">{{{{item.dictLabel}}}}</el-radio>");
|
||||||
sb.AppendLine(" </el-radio-group>");
|
sb.AppendLine(" </el-radio-group>");
|
||||||
sb.AppendLine(" </el-form-item>");
|
sb.AppendLine(" </el-form-item>");
|
||||||
@ -131,10 +130,10 @@ namespace ZR.CodeGenerator
|
|||||||
sb.AppendLine(" <el-col :lg=\"12\">");
|
sb.AppendLine(" <el-col :lg=\"12\">");
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($" <el-select v-model=\"form.{columnName}\" placeholder=\"请选择{labelName}\"> ");
|
sb.AppendLine($" <el-select v-model=\"form.{columnName}\" placeholder=\"请选择{labelName}\"> ");
|
||||||
if (string.IsNullOrEmpty(dbFieldInfo.DictType))
|
//if (string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||||
{
|
//{
|
||||||
sb.AppendLine($" <el-option label=\"请选择字典生成\" value=\"\"></el-option>");
|
// sb.AppendLine($" <el-option label=\"请选择字典生成\" value=\"\"></el-option>");
|
||||||
}
|
//}
|
||||||
sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>");
|
sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>");
|
||||||
sb.AppendLine(" </el-select>");
|
sb.AppendLine(" </el-select>");
|
||||||
sb.AppendLine(" </el-form-item>");
|
sb.AppendLine(" </el-form-item>");
|
||||||
@ -146,10 +145,10 @@ namespace ZR.CodeGenerator
|
|||||||
sb.AppendLine(" <el-col :lg=\"24\">");
|
sb.AppendLine(" <el-col :lg=\"24\">");
|
||||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
sb.AppendLine($" <el-form-item label=\"{labelName}\" prop=\"{columnName}\">");
|
||||||
sb.AppendLine($" <el-checkbox-group v-model=\"form.{columnName}Checked\"> ");
|
sb.AppendLine($" <el-checkbox-group v-model=\"form.{columnName}Checked\"> ");
|
||||||
if (string.IsNullOrEmpty(dbFieldInfo.DictType))
|
//if (string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||||
{
|
//{
|
||||||
sb.AppendLine($" <el-checkbox>请选择字典生成</el-checkbox>");
|
// sb.AppendLine($" <el-checkbox>请选择字典生成</el-checkbox>");
|
||||||
}
|
//}
|
||||||
sb.AppendLine($" <el-checkbox v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictValue\">{{{{item.dictLabel}}}}</el-checkbox>");
|
sb.AppendLine($" <el-checkbox v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictValue\">{{{{item.dictLabel}}}}</el-checkbox>");
|
||||||
sb.AppendLine(" </el-checkbox-group>");
|
sb.AppendLine(" </el-checkbox-group>");
|
||||||
sb.AppendLine(" </el-form-item>");
|
sb.AppendLine(" </el-form-item>");
|
||||||
@ -215,7 +214,7 @@ namespace ZR.CodeGenerator
|
|||||||
{
|
{
|
||||||
string columnName = dbFieldInfo.CsharpFieldFl;
|
string columnName = dbFieldInfo.CsharpFieldFl;
|
||||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||||
string showToolTip = dbFieldInfo.CsharpType == "string" ? ":show-overflow-tooltip=\"true\"" : "";
|
string showToolTip = ShowToolTip(dbFieldInfo);
|
||||||
string formatter = GetFormatter(dbFieldInfo.HtmlType, columnName);
|
string formatter = GetFormatter(dbFieldInfo.HtmlType, columnName);
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
//自定义排序字段
|
//自定义排序字段
|
||||||
@ -254,7 +253,7 @@ namespace ZR.CodeGenerator
|
|||||||
}
|
}
|
||||||
else if (dbFieldInfo.IsList)
|
else if (dbFieldInfo.IsList)
|
||||||
{
|
{
|
||||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\" {showToolTip}{formatter}/>");
|
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\"{showToolTip}{formatter}/>");
|
||||||
}
|
}
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
@ -309,5 +308,20 @@ namespace ZR.CodeGenerator
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 超出隐藏
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="column"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string ShowToolTip(GenTableColumn column)
|
||||||
|
{
|
||||||
|
if (column.CsharpType.Equals("string") ||
|
||||||
|
column.HtmlType.Equals(GenConstants.HTML_DATETIME))
|
||||||
|
{
|
||||||
|
return $" :show-overflow-tooltip=\"true\"";
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
|
using Infrastructure.Extensions;
|
||||||
using JinianNet.JNTemplate;
|
using JinianNet.JNTemplate;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
@ -384,7 +385,7 @@ namespace ZR.CodeGenerator
|
|||||||
TableId = genTable.TableId,
|
TableId = genTable.TableId,
|
||||||
TableName = genTable.TableName,
|
TableName = genTable.TableName,
|
||||||
CsharpType = GetCSharpDatatype(column.DataType),
|
CsharpType = GetCSharpDatatype(column.DataType),
|
||||||
CsharpField = FirstUpperCase(column.DbColumnName),//TODO 优化下划线处理
|
CsharpField = FirstUpperCase(column.DbColumnName.UnderScoreToCamelCase()),
|
||||||
IsRequired = !column.IsNullable,
|
IsRequired = !column.IsNullable,
|
||||||
IsIncrement = column.IsIdentity,
|
IsIncrement = column.IsIdentity,
|
||||||
Create_by = genTable.Create_by,
|
Create_by = genTable.Create_by,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user