init
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ${options.DtosNamespace}.${options.SubNamespace}.Dto;
|
||||
using ${options.ModelsNamespace}.${options.SubNamespace};
|
||||
using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service;
|
||||
using ${options.ApiControllerNamespace}.Filters;
|
||||
$if(replaceDto.ShowBtnImport)
|
||||
using MiniExcelLibs;
|
||||
$end
|
||||
|
||||
//创建时间:${replaceDto.AddTime}
|
||||
namespace ${options.ApiControllerNamespace}.Controllers.${options.SubNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.functionName}
|
||||
/// </summary>
|
||||
[Verify]
|
||||
[Route("${genTable.ModuleName}/${genTable.BusinessName}")]
|
||||
public class ${replaceDto.ModelTypeName}Controller : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}接口
|
||||
/// </summary>
|
||||
private readonly I${replaceDto.ModelTypeName}Service _${replaceDto.ModelTypeName}Service;
|
||||
|
||||
public ${replaceDto.ModelTypeName}Controller(I${replaceDto.ModelTypeName}Service ${replaceDto.ModelTypeName}Service)
|
||||
{
|
||||
_${replaceDto.ModelTypeName}Service = ${replaceDto.ModelTypeName}Service;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("list")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:list")]
|
||||
public IActionResult Query${replaceDto.ModelTypeName}([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
$if(genTable.TplCategory == "tree")
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}列表树
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("treeList")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:list")]
|
||||
public IActionResult QueryTree${replaceDto.ModelTypeName}([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetTreeList(parm);
|
||||
return SUCCESS(response);
|
||||
}
|
||||
$end
|
||||
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}详情
|
||||
/// </summary>
|
||||
/// <param name="${replaceDto.PKName}"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{${replaceDto.PKName}}")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:query")]
|
||||
public IActionResult Get${replaceDto.ModelTypeName}(${replaceDto.PKType} ${replaceDto.PKName})
|
||||
{
|
||||
var response = _${replaceDto.ModelTypeName}Service.GetInfo(${replaceDto.PKName});
|
||||
|
||||
var info = response.Adapt<${replaceDto.ModelTypeName}Dto>();
|
||||
return SUCCESS(info);
|
||||
}
|
||||
|
||||
$if(replaceDto.ShowBtnAdd)
|
||||
/// <summary>
|
||||
/// 添加${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:add")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.INSERT)]
|
||||
public IActionResult Add${replaceDto.ModelTypeName}([FromBody] ${replaceDto.ModelTypeName}Dto parm)
|
||||
{
|
||||
var modal = parm.Adapt<${replaceDto.ModelTypeName}>().ToCreate(HttpContext);
|
||||
|
||||
var response = _${replaceDto.ModelTypeName}Service.Add${replaceDto.ModelTypeName}(modal);
|
||||
|
||||
return SUCCESS(response);
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnEdit)
|
||||
/// <summary>
|
||||
/// 更新${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:edit")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult Update${replaceDto.ModelTypeName}([FromBody] ${replaceDto.ModelTypeName}Dto parm)
|
||||
{
|
||||
var modal = parm.Adapt<${replaceDto.ModelTypeName}>().ToUpdate(HttpContext);
|
||||
var response = _${replaceDto.ModelTypeName}Service.Update${replaceDto.ModelTypeName}(modal);
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
|
||||
/// <summary>
|
||||
/// 删除${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("delete/{ids}")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")]
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.DELETE)]
|
||||
public IActionResult Delete${replaceDto.ModelTypeName}([FromRoute]string ids)
|
||||
{
|
||||
var idArr = Tools.SplitAndConvert<${replaceDto.PKType}>(ids);
|
||||
|
||||
return ToResponse(_${replaceDto.ModelTypeName}Service.Delete(idArr$if(replaceDto.enableLog), "删除${genTable.FunctionName}"$end));
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnExport)
|
||||
/// <summary>
|
||||
/// 导出${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[HttpGet("export")]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:export")]
|
||||
public IActionResult Export([FromQuery] ${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
parm.PageNum = 1;
|
||||
parm.PageSize = 100000;
|
||||
var list = _${replaceDto.ModelTypeName}Service.ExportList(parm).Result;
|
||||
if (list == null || list.Count <= 0)
|
||||
{
|
||||
return ToResponse(ResultCode.FAIL, "没有要导出的数据");
|
||||
}
|
||||
var result = ExportExcelMini(list, "${genTable.FunctionName}", "${genTable.FunctionName}");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnTruncate)
|
||||
/// <summary>
|
||||
/// 清空${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Log(Title = "${genTable.FunctionName}", BusinessType = BusinessType.CLEAN)]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:delete")]
|
||||
[HttpPost("clean")]
|
||||
public IActionResult Clear()
|
||||
{
|
||||
if (!HttpContextExtension.IsAdmin(HttpContext))
|
||||
{
|
||||
return ToResponse(ResultCode.FAIL, "操作失败");
|
||||
}
|
||||
return SUCCESS(_${replaceDto.ModelTypeName}Service.Truncate${replaceDto.ModelTypeName}());
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnImport)
|
||||
/// <summary>
|
||||
/// 导入
|
||||
/// </summary>
|
||||
/// <param name="formFile"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("importData")]
|
||||
[Log(Title = "${genTable.FunctionName}导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false)]
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:import")]
|
||||
public IActionResult ImportData([FromForm(Name = "file")] IFormFile formFile)
|
||||
{
|
||||
List<${replaceDto.ModelTypeName}Dto> list = new();
|
||||
using (var stream = formFile.OpenReadStream())
|
||||
{
|
||||
list = stream.Query<${replaceDto.ModelTypeName}Dto>(startCell: "A1").ToList();
|
||||
}
|
||||
|
||||
return SUCCESS(_${replaceDto.ModelTypeName}Service.Import${replaceDto.ModelTypeName}(list.Adapt<List<${replaceDto.ModelTypeName}>>()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}导入模板下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("importTemplate")]
|
||||
[Log(Title = "${genTable.FunctionName}模板", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
|
||||
[AllowAnonymous]
|
||||
public IActionResult ImportTemplateExcel()
|
||||
{
|
||||
var result = DownloadImportTemplate(new List<${replaceDto.ModelTypeName}Dto>() { }, "${replaceDto.ModelTypeName}");
|
||||
return ExportExcel(result.Item2, result.Item1);
|
||||
}
|
||||
|
||||
$end
|
||||
$if(showCustomInput)
|
||||
/// <summary>
|
||||
/// 保存排序
|
||||
/// </summary>
|
||||
/// <param name="id">主键</param>
|
||||
/// <param name="value">排序值</param>
|
||||
/// <returns></returns>
|
||||
[ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:edit")]
|
||||
[HttpGet("ChangeSort")]
|
||||
[Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
|
||||
public IActionResult ChangeSort(int id = 0, int value = 0)
|
||||
{
|
||||
if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
|
||||
var response = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == id, it => new ${replaceDto.ModelTypeName}()
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
$if((item.htmlType == "customInput"))
|
||||
$item.CsharpField = value,
|
||||
$end
|
||||
${end}
|
||||
});
|
||||
|
||||
return ToResponse(response);
|
||||
}
|
||||
$end
|
||||
}
|
||||
}
|
||||
76
DOAN.Admin.WebApi/wwwroot/CodeGenTemplate/csharp/TplDto.txt
Normal file
76
DOAN.Admin.WebApi/wwwroot/CodeGenTemplate/csharp/TplDto.txt
Normal file
@@ -0,0 +1,76 @@
|
||||
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
||||
using ${subTableOptions.ModelsNamespace}.${subTableOptions.SubNamespace};
|
||||
$end
|
||||
|
||||
namespace ${options.DtosNamespace}.${options.SubNamespace}.Dto
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}查询对象
|
||||
/// </summary>
|
||||
public class ${replaceDto.ModelTypeName}QueryDto : PagerInfo
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
$if(item.IsQuery)
|
||||
$if(item.htmlType.StartsWith("date"))
|
||||
public DateTime? Begin$item.CsharpField { get; set; }
|
||||
public DateTime? End$item.CsharpField { get; set; }
|
||||
$elseif(item.htmlType == "selectMulti")
|
||||
public ${item.CsharpType}[] $item.CsharpField { get; set; }
|
||||
$else
|
||||
public $item.CsharpType$if(item.CsharpType != "string")?$end $item.CsharpField { get; set; }
|
||||
$end
|
||||
$end
|
||||
$end
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}输入输出对象
|
||||
/// </summary>
|
||||
public class ${replaceDto.ModelTypeName}Dto
|
||||
{
|
||||
$foreach(item in genTable.Columns)
|
||||
$set(labelName = "")
|
||||
$if(item.ColumnComment != "")
|
||||
$set(labelName = item.ColumnComment)
|
||||
$else
|
||||
$set(labelName = item.CsharpField)
|
||||
$end
|
||||
$if(item.IsRequired)
|
||||
[Required(ErrorMessage = "${item.ColumnComment}不能为空")]
|
||||
$end
|
||||
$if(replaceDto.ShowBtnExport)
|
||||
$if(item.IsExport)
|
||||
[ExcelColumn(Name = "$labelName"$if(item.CsharpType == "DateTime"), Format = "yyyy-MM-dd HH:mm:ss", Width = 20$end)]
|
||||
[ExcelColumnName("$labelName")]
|
||||
$else
|
||||
[ExcelIgnore]
|
||||
$end
|
||||
$end
|
||||
$if(item.CsharpType == "long" && replaceDto.useSnowflakeId == true && item.IsPk)
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
$end
|
||||
public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; }
|
||||
|
||||
$end
|
||||
|
||||
$if(genTable.TplCategory == "subNav" && genTable.SubTable != null)
|
||||
$if(replaceDto.ShowBtnExport)
|
||||
[ExcelIgnore]
|
||||
$end
|
||||
public ${genTable.SubTable.ClassName}Dto ${genTable.SubTable.ClassName}Nav { get; set; }
|
||||
$end
|
||||
|
||||
$if(genTable.TplCategory == "subNavMore" && genTable.SubTable != null)
|
||||
$if(replaceDto.ShowBtnExport)
|
||||
[ExcelIgnore]
|
||||
$end
|
||||
public List<${genTable.SubTable.ClassName}Dto> ${genTable.SubTable.ClassName}Nav { get; set; }
|
||||
$end
|
||||
$foreach(column in dicts)
|
||||
$if(column.IsExport)
|
||||
[ExcelColumn(Name = "$if(column.ColumnComment == "")${column.CsharpField}${else}${column.ColumnComment}${end}")]
|
||||
public string ${column.CsharpField}Label { get; set; }
|
||||
$end
|
||||
$end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using ${options.DtosNamespace}.${options.SubNamespace}.Dto;
|
||||
using ${options.ModelsNamespace}.${options.SubNamespace};
|
||||
|
||||
namespace ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}service接口
|
||||
/// </summary>
|
||||
public interface I${replaceDto.ModelTypeName}Service : IBaseService<${replaceDto.ModelTypeName}>
|
||||
{
|
||||
PagedInfo<${replaceDto.ModelTypeName}Dto> GetList(${replaceDto.ModelTypeName}QueryDto parm);
|
||||
|
||||
${replaceDto.ModelTypeName} GetInfo(${replaceDto.PKType} ${replaceDto.PKName});
|
||||
|
||||
$if(genTable.TplCategory == "tree")
|
||||
List<${replaceDto.ModelTypeName}> GetTreeList(${replaceDto.ModelTypeName}QueryDto parm);
|
||||
$end
|
||||
|
||||
${replaceDto.ModelTypeName} Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm);
|
||||
$if(replaceDto.ShowBtnEdit)
|
||||
int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} parm);
|
||||
$end
|
||||
$if(replaceDto.ShowBtnTruncate)
|
||||
bool Truncate${replaceDto.ModelTypeName}();
|
||||
$end
|
||||
|
||||
$if(replaceDto.ShowBtnImport)
|
||||
(string, object, object) Import${replaceDto.ModelTypeName}(List<${replaceDto.ModelTypeName}> list);
|
||||
$end
|
||||
|
||||
$if(replaceDto.ShowBtnExport)
|
||||
PagedInfo<${replaceDto.ModelTypeName}Dto> ExportList(${replaceDto.ModelTypeName}QueryDto parm);
|
||||
$end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
$if(genTable.TplCategory.Contains("subNav") && genTable.SubTable != null)
|
||||
using ${subTableOptions.ModelsNamespace}.${subTableOptions.SubNamespace};
|
||||
$end
|
||||
|
||||
namespace ${options.ModelsNamespace}.${options.SubNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}
|
||||
/// </summary>
|
||||
[SugarTable("${genTable.TableName}")]
|
||||
public class ${replaceDto.ModelTypeName}
|
||||
{
|
||||
${foreach(item in genTable.Columns)}
|
||||
/// <summary>
|
||||
/// ${item.ColumnComment} ${item.Remark}
|
||||
/// </summary>
|
||||
$if(item.IsPk || item.IsIncrement)
|
||||
[SugarColumn(IsPrimaryKey = ${item.IsPk.ToString().ToLower()}, IsIdentity = ${item.IsIncrement.ToString().ToLower()}$if(item.CsharpField.ToLower() != item.ColumnName.ToLower()), ColumnName = "$item.ColumnName"$end)]
|
||||
$elseif(item.CsharpField.ToLower() != item.ColumnName.ToLower())
|
||||
[SugarColumn(ColumnName = "$item.ColumnName")]
|
||||
$elseif(item.AutoFillType == 1 && item.CsharpType == "DateTime")
|
||||
[SugarColumn(InsertServerTime = true, IsOnlyIgnoreUpdate = true)]
|
||||
$elseif(item.AutoFillType == 2 && item.CsharpType == "DateTime")
|
||||
[SugarColumn(UpdateServerTime = true, IsOnlyIgnoreInsert = true)]
|
||||
$elseif(item.AutoFillType == 3 && item.CsharpType == "DateTime")
|
||||
[SugarColumn(InsertServerTime = true, UpdateServerTime = true)]
|
||||
$elseif(item.AutoFillType == 1)
|
||||
[SugarColumn(IsOnlyIgnoreUpdate = true)]
|
||||
$end
|
||||
public $item.CsharpType$item.RequiredStr $item.CsharpField { get; set; }
|
||||
|
||||
${end}
|
||||
$if(genTable.TplCategory == "tree")
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<${replaceDto.ModelTypeName}> Children { get; set; }
|
||||
$end
|
||||
$if((genTable.TplCategory == "subNav" || genTable.TplCategory == "sub") && genTable.SubTable != null)
|
||||
[Navigate(NavigateType.OneToOne, nameof(${replaceDto.PKName}))] //自定义关系映射
|
||||
public ${genTable.SubTable.ClassName} ${genTable.SubTable.ClassName}Nav { get; set; }
|
||||
$end
|
||||
$if(genTable.TplCategory == "subNavMore" && genTable.SubTable != null)
|
||||
[Navigate(NavigateType.OneToMany, nameof(${genTable.SubTable.ClassName}.${genTable.SubTableFkName}), nameof(${replaceDto.PKName}))] //自定义关系映射
|
||||
public List<${genTable.SubTable.ClassName}> ${genTable.SubTable.ClassName}Nav { get; set; }
|
||||
$end
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Infrastructure.Attribute;
|
||||
using ${options.ModelsNamespace}.${options.SubNamespace};
|
||||
|
||||
namespace ${options.RepositoriesNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}仓储
|
||||
/// </summary>
|
||||
[AppService(ServiceLifetime = LifeTime.Transient)]
|
||||
public class ${replaceDto.ModelTypeName}Repository : BaseRepository<${replaceDto.ModelTypeName}>
|
||||
{
|
||||
}
|
||||
}
|
||||
230
DOAN.Admin.WebApi/wwwroot/CodeGenTemplate/csharp/TplService.txt
Normal file
230
DOAN.Admin.WebApi/wwwroot/CodeGenTemplate/csharp/TplService.txt
Normal file
@@ -0,0 +1,230 @@
|
||||
using Infrastructure.Attribute;
|
||||
using Infrastructure.Extensions;
|
||||
using ${options.DtosNamespace}.${options.SubNamespace}.Dto;
|
||||
using ${options.ModelsNamespace}.${options.SubNamespace};
|
||||
using ${options.RepositoriesNamespace};
|
||||
using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service;
|
||||
$if(genTable.TplCategory == "tree")
|
||||
using System.Collections.Generic;
|
||||
$end
|
||||
|
||||
namespace ${options.ServicesNamespace}.${options.SubNamespace}
|
||||
{
|
||||
/// <summary>
|
||||
/// ${genTable.FunctionName}Service业务层处理
|
||||
/// </summary>
|
||||
[AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
|
||||
public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<${replaceDto.ModelTypeName}Dto> GetList(${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
var predicate = QueryExp(parm);
|
||||
|
||||
var response = Queryable()
|
||||
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
||||
//.Includes(x => x.${genTable.SubTable.ClassName}Nav) //填充子对象
|
||||
$end
|
||||
$if(genTable.Options.SortField != "" && genTable.Options.SortField != null)
|
||||
//.OrderBy("${genTable.Options.SortField} ${genTable.Options.SortType}")
|
||||
$end
|
||||
.Where(predicate.ToExpression())
|
||||
.ToPage<${replaceDto.ModelTypeName}, ${replaceDto.ModelTypeName}Dto>(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
$if(genTable.TplCategory == "tree")
|
||||
/// <summary>
|
||||
/// 查询${genTable.FunctionName}树列表
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public List<${replaceDto.ModelTypeName}> GetTreeList(${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
||||
|
||||
$foreach(column in genTable.Columns)
|
||||
$if(column.IsQuery)
|
||||
$if(column.CsharpType == "string")
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${tool.QueryExp(column.CsharpField, column.QueryType)};
|
||||
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
|
||||
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${tool.QueryExp(column.CsharpField, column.QueryType)};
|
||||
$end
|
||||
$end
|
||||
$end
|
||||
|
||||
var response = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.ToTree(it => it.Children, it => it.${genTable.Options.TreeParentCode}, 0);
|
||||
|
||||
return response;
|
||||
}
|
||||
$end
|
||||
|
||||
/// <summary>
|
||||
/// 获取详情
|
||||
/// </summary>
|
||||
/// <param name="${replaceDto.PKName}"></param>
|
||||
/// <returns></returns>
|
||||
public ${replaceDto.ModelTypeName} GetInfo(${replaceDto.PKType} ${replaceDto.PKName})
|
||||
{
|
||||
var response = Queryable()
|
||||
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
||||
.Includes(x => x.${genTable.SubTable.ClassName}Nav) //填充子对象
|
||||
$end
|
||||
.Where(x => x.${replaceDto.PKName} == ${replaceDto.PKName})
|
||||
.First();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public ${replaceDto.ModelTypeName} Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model)
|
||||
{
|
||||
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
||||
return Context.InsertNav(model).Include(s1 => s1.${genTable.SubTable.ClassName}Nav).ExecuteReturnEntity();
|
||||
$else
|
||||
$if(replaceDto.useSnowflakeId)
|
||||
Insertable(model).ExecuteReturnSnowflakeId();
|
||||
return model;
|
||||
$else
|
||||
return Insertable(model).ExecuteReturnEntity();
|
||||
$end
|
||||
$end
|
||||
}
|
||||
|
||||
$if(replaceDto.ShowBtnEdit)
|
||||
/// <summary>
|
||||
/// 修改${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model)
|
||||
{
|
||||
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
||||
return Context.UpdateNav(model).Include(z1 => z1.${genTable.SubTable.ClassName}Nav).ExecuteCommand() ? 1 : 0;
|
||||
$else
|
||||
return Update(model, true$if(replaceDto.enableLog), "修改${genTable.FunctionName}"$end);
|
||||
$end
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnTruncate)
|
||||
/// <summary>
|
||||
/// 清空${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Truncate${replaceDto.ModelTypeName}()
|
||||
{
|
||||
var newTableName = $"${genTable.TableName}_{DateTime.Now:yyyyMMdd}";
|
||||
if (Queryable().Any() && !Context.DbMaintenance.IsAnyTable(newTableName))
|
||||
{
|
||||
Context.DbMaintenance.BackupTable("${genTable.TableName}", newTableName);
|
||||
}
|
||||
|
||||
return Truncate();
|
||||
}
|
||||
$end
|
||||
$if(replaceDto.ShowBtnImport)
|
||||
/// <summary>
|
||||
/// 导入${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public (string, object, object) Import${replaceDto.ModelTypeName}(List<${replaceDto.ModelTypeName}> list)
|
||||
{
|
||||
var x = Context.Storageable(list)
|
||||
.SplitInsert(it => !it.Any())
|
||||
$foreach(column in genTable.Columns)
|
||||
$if(column.IsRequired && column.IsIncrement == false)
|
||||
.SplitError(x => x.Item.${column.CsharpField}.IsEmpty(), "${column.ColumnComment}不能为空")
|
||||
$end
|
||||
$end
|
||||
//.WhereColumns(it => it.UserName)//如果不是主键可以这样实现(多字段it=>new{it.x1,it.x2})
|
||||
.ToStorage();
|
||||
var result = x.AsInsertable.ExecuteCommand();//插入可插入部分;
|
||||
|
||||
string msg = $"插入{x.InsertList.Count} 更新{x.UpdateList.Count} 错误数据{x.ErrorList.Count} 不计算数据{x.IgnoreList.Count} 删除数据{x.DeleteList.Count} 总共{x.TotalList.Count}";
|
||||
Console.WriteLine(msg);
|
||||
|
||||
//输出错误信息
|
||||
foreach (var item in x.ErrorList)
|
||||
{
|
||||
Console.WriteLine("错误" + item.StorageMessage);
|
||||
}
|
||||
foreach (var item in x.IgnoreList)
|
||||
{
|
||||
Console.WriteLine("忽略" + item.StorageMessage);
|
||||
}
|
||||
|
||||
return (msg, x.ErrorList, x.IgnoreList);
|
||||
}
|
||||
|
||||
$end
|
||||
$if(replaceDto.ShowBtnExport)
|
||||
/// <summary>
|
||||
/// 导出${genTable.FunctionName}
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
public PagedInfo<${replaceDto.ModelTypeName}Dto> ExportList(${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
var predicate = QueryExp(parm);
|
||||
|
||||
var response = Queryable()
|
||||
.Where(predicate.ToExpression())
|
||||
.Select((it) => new ${replaceDto.ModelTypeName}Dto()
|
||||
{
|
||||
$foreach(column in dicts)
|
||||
$if(column.DictType != "")
|
||||
${column.CsharpField}Label = it.${column.CsharpField}.GetConfigValue<Model.System.SysDictData>("${column.DictType}"),
|
||||
$end
|
||||
$end
|
||||
}, true)
|
||||
.ToPage(parm);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
$end
|
||||
/// <summary>
|
||||
/// 查询导出表达式
|
||||
/// </summary>
|
||||
/// <param name="parm"></param>
|
||||
/// <returns></returns>
|
||||
private static Expressionable<${replaceDto.ModelTypeName}> QueryExp(${replaceDto.ModelTypeName}QueryDto parm)
|
||||
{
|
||||
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
||||
|
||||
$foreach(column in genTable.Columns)
|
||||
$if(column.IsQuery)
|
||||
$if(column.HtmlType == "selectMulti")
|
||||
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => parm.${column.CsharpField}.Contains(it.${column.CsharpField}));
|
||||
$elseif(column.CsharpType == "string")
|
||||
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${tool.QueryExp(column.CsharpField, column.QueryType)};
|
||||
$elseif(column.CsharpType == "DateTime")
|
||||
$if(column.HtmlType == "month")
|
||||
DateTime monthEnd = Convert.ToDateTime(parm.${column.CsharpField}).AddMonths(1);
|
||||
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => it.${column.CsharpField} >= parm.${column.CsharpField} && it.${column.CsharpField} < monthEnd);
|
||||
$else
|
||||
predicate = predicate.AndIF(parm.Begin${column.CsharpField} == null, it => it.${column.CsharpField} >= DateTime.Now.ToShortDateString().ParseToDateTime());
|
||||
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});
|
||||
$end
|
||||
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
|
||||
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${tool.QueryExp(column.CsharpField, column.QueryType)};
|
||||
$end
|
||||
$end
|
||||
$end
|
||||
return predicate;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user