2022-09-22 09:57:32 +08:00
|
|
|
using System;
|
|
|
|
|
using SqlSugar;
|
2021-09-08 18:12:08 +08:00
|
|
|
using Infrastructure.Attribute;
|
2023-05-31 18:55:48 +08:00
|
|
|
using Infrastructure.Extensions;
|
2023-03-01 18:23:29 +08:00
|
|
|
using ${options.BaseNamespace}Model;
|
|
|
|
|
using ${options.DtosNamespace};
|
|
|
|
|
using ${options.ModelsNamespace}.${options.SubNamespace};
|
|
|
|
|
using ${options.RepositoriesNamespace};
|
2021-12-15 12:11:21 +08:00
|
|
|
using ${options.IServicsNamespace}.${options.SubNamespace}.I${options.SubNamespace}Service;
|
2022-11-29 11:43:39 +08:00
|
|
|
using System.Linq;
|
|
|
|
|
$if(genTable.TplCategory == "tree")
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
$end
|
2021-09-08 18:12:08 +08:00
|
|
|
|
2021-12-15 11:03:48 +08:00
|
|
|
namespace ${options.ServicesNamespace}.${options.SubNamespace}
|
2021-09-08 18:12:08 +08:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-11-30 21:33:34 +08:00
|
|
|
/// ${genTable.FunctionName}Service业务层处理
|
2021-09-08 18:12:08 +08:00
|
|
|
/// </summary>
|
2021-11-30 21:33:34 +08:00
|
|
|
[AppService(ServiceType = typeof(I${replaceDto.ModelTypeName}Service), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
public class ${replaceDto.ModelTypeName}Service : BaseService<${replaceDto.ModelTypeName}>, I${replaceDto.ModelTypeName}Service
|
2021-09-08 18:12:08 +08:00
|
|
|
{
|
2021-12-28 20:52:08 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 查询${genTable.FunctionName}列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
/// <returns></returns>
|
2022-11-29 11:43:39 +08:00
|
|
|
public PagedInfo<${replaceDto.ModelTypeName}Dto> GetList(${replaceDto.ModelTypeName}QueryDto parm)
|
2021-12-28 20:52:08 +08:00
|
|
|
{
|
|
|
|
|
var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>();
|
|
|
|
|
|
|
|
|
|
$foreach(column in genTable.Columns)
|
|
|
|
|
$if(column.IsQuery)
|
2022-11-29 11:43:39 +08:00
|
|
|
$if(column.HtmlType == "selectMulti")
|
|
|
|
|
predicate = predicate.AndIF(parm.${column.CsharpField} != null, it => parm.${column.CsharpField}.Contains(it.${column.CsharpField}));
|
|
|
|
|
$elseif(column.CsharpType == "string")
|
2021-12-28 20:52:08 +08:00
|
|
|
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.${column.CsharpField}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
|
|
|
|
$elseif(column.CsharpType == "DateTime")
|
2023-05-12 15:10:12 +08:00
|
|
|
$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
|
2023-05-23 18:36:35 +08:00
|
|
|
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});
|
2023-05-12 15:10:12 +08:00
|
|
|
$end
|
2021-12-28 20:52:08 +08:00
|
|
|
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
|
|
|
|
|
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
|
|
|
|
$end
|
|
|
|
|
$end
|
|
|
|
|
$end
|
2022-09-20 21:17:25 +08:00
|
|
|
var response = Queryable()
|
2022-05-09 18:55:03 +08:00
|
|
|
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
2023-07-11 18:32:46 +08:00
|
|
|
//.Includes(x => x.${genTable.SubTable.ClassName}Nav) //填充子对象
|
2022-05-08 14:08:18 +08:00
|
|
|
$end
|
2022-05-22 13:50:27 +08:00
|
|
|
$if(genTable.Options.SortField != "" && genTable.Options.SortField != null)
|
2022-11-29 11:43:39 +08:00
|
|
|
//.OrderBy("${genTable.Options.SortField} ${genTable.Options.SortType}")
|
2022-05-08 14:08:18 +08:00
|
|
|
$end
|
2022-01-11 21:10:16 +08:00
|
|
|
.Where(predicate.ToExpression())
|
2022-11-29 11:43:39 +08:00
|
|
|
.ToPage<${replaceDto.ModelTypeName}, ${replaceDto.ModelTypeName}Dto>(parm);
|
2022-05-08 14:08:18 +08:00
|
|
|
|
2021-12-28 20:52:08 +08:00
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-31 21:13:32 +08:00
|
|
|
$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}), ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
|
|
|
|
$elseif(column.CsharpType == "int" || column.CsharpType == "long")
|
|
|
|
|
predicate = predicate.AndIF(parm.${column.CsharpField} != null, ${codeTool.QueryExp(column.CsharpField, column.QueryType)};
|
|
|
|
|
$end
|
|
|
|
|
$end
|
|
|
|
|
$end
|
|
|
|
|
|
2022-11-29 11:43:39 +08:00
|
|
|
var response = Queryable()
|
|
|
|
|
.Where(predicate.ToExpression())
|
2022-05-22 13:50:27 +08:00
|
|
|
.ToTree(it => it.Children, it => it.${genTable.Options.TreeParentCode}, 0);
|
2021-12-31 21:13:32 +08:00
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
$end
|
2022-11-29 11:43:39 +08:00
|
|
|
|
2023-07-11 18:32:46 +08:00
|
|
|
/// <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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-08 14:08:18 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 添加${genTable.FunctionName}
|
|
|
|
|
/// </summary>
|
2023-02-17 11:02:27 +08:00
|
|
|
/// <param name="model"></param>
|
2022-05-08 14:08:18 +08:00
|
|
|
/// <returns></returns>
|
2023-02-17 11:02:27 +08:00
|
|
|
public int Add${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model)
|
2022-05-08 14:08:18 +08:00
|
|
|
{
|
2023-07-11 18:32:46 +08:00
|
|
|
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
|
|
|
|
return Context.InsertNav(model).Include(s1 => s1.${genTable.SubTable.ClassName}Nav).ExecuteCommand() ? 1 : 0;
|
|
|
|
|
$else
|
2023-02-17 11:02:27 +08:00
|
|
|
return Add(model, true);
|
2023-07-11 18:32:46 +08:00
|
|
|
$end
|
2022-06-10 17:47:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 修改${genTable.FunctionName}
|
|
|
|
|
/// </summary>
|
2023-02-17 11:02:27 +08:00
|
|
|
/// <param name="model"></param>
|
2022-06-10 17:47:52 +08:00
|
|
|
/// <returns></returns>
|
2023-02-17 11:02:27 +08:00
|
|
|
public int Update${replaceDto.ModelTypeName}(${replaceDto.ModelTypeName} model)
|
2022-06-10 17:47:52 +08:00
|
|
|
{
|
2023-02-17 11:02:27 +08:00
|
|
|
//var response = Update(w => w.${replaceDto.PKName} == model.${replaceDto.PKName}, it => new ${replaceDto.ModelTypeName}()
|
|
|
|
|
//{
|
2022-06-10 17:47:52 +08:00
|
|
|
$foreach(item in genTable.Columns)
|
|
|
|
|
$if((item.IsEdit))
|
2023-02-17 11:02:27 +08:00
|
|
|
// $item.CsharpField = model.$item.CsharpField,
|
2022-06-10 17:47:52 +08:00
|
|
|
$end
|
2022-05-08 14:08:18 +08:00
|
|
|
${end}
|
2023-02-17 11:02:27 +08:00
|
|
|
//});
|
|
|
|
|
//return response;
|
2023-07-11 18:32:46 +08:00
|
|
|
$if(null != genTable.SubTableName && "" != genTable.SubTableName)
|
|
|
|
|
return Context.UpdateNav(model).Include(z1 => z1.${genTable.SubTable.ClassName}Nav).ExecuteCommand() ? 1 : 0;
|
|
|
|
|
$else
|
2023-02-17 11:02:27 +08:00
|
|
|
return Update(model, true);
|
2023-07-11 18:32:46 +08:00
|
|
|
$end
|
2022-05-08 14:08:18 +08:00
|
|
|
}
|
2023-03-01 18:23:29 +08:00
|
|
|
$if(replaceDto.ShowBtnTruncate)
|
2022-09-23 09:53:23 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 清空${genTable.FunctionName}
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-05-18 18:29:49 +08:00
|
|
|
public bool Truncate${replaceDto.ModelTypeName}()
|
2022-09-23 09:53:23 +08:00
|
|
|
{
|
2023-05-18 18:29:49 +08:00
|
|
|
var newTableName = $"${genTable.TableName}_{DateTime.Now:yyyyMMdd}";
|
|
|
|
|
if (Queryable().Any() && !Context.DbMaintenance.IsAnyTable(newTableName))
|
|
|
|
|
{
|
|
|
|
|
Context.DbMaintenance.BackupTable("${genTable.TableName}", newTableName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Truncate();
|
2022-09-23 09:53:23 +08:00
|
|
|
}
|
2023-03-01 18:23:29 +08:00
|
|
|
$end
|
2021-09-08 18:12:08 +08:00
|
|
|
}
|
|
|
|
|
}
|