From 8944412929ca57bf921d4dd12f419778bd6cce62 Mon Sep 17 00:00:00 2001
From: zs <zhousong@weben-smart.com>
Date: 周三, 14 5月 2025 16:19:05 +0800
Subject: [PATCH] 任务管理高级查询
---
Weben_CMS专用代码生成器/Code/Templete/AppService/AppService模板.txt | 168 ++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 110 insertions(+), 58 deletions(-)
diff --git "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/AppService/AppService\346\250\241\346\235\277.txt" "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/AppService/AppService\346\250\241\346\235\277.txt"
index 4a694b4..2a60352 100644
--- "a/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/AppService/AppService\346\250\241\346\235\277.txt"
+++ "b/Weben_CMS\344\270\223\347\224\250\344\273\243\347\240\201\347\224\237\346\210\220\345\231\250/Code/Templete/AppService/AppService\346\250\241\346\235\277.txt"
@@ -1,4 +1,4 @@
-using CMS.Plugin.$NameSpacePath$.Application.Contracts.Dtos.$EntityName$;
+锘縰sing CMS.Plugin.$NameSpacePath$.Application.Contracts.Dtos.$EntityName$;
using CMS.Plugin.$NameSpacePath$.Application.Contracts.Services;
using CMS.Plugin.$NameSpacePath$.Domain.Shared;
using CmsQueryExtensions;
@@ -10,37 +10,38 @@
using Volo.Abp.Data;
using Volo.Abp.ObjectExtending;
using Volo.Abp.ObjectMapping;
+using CmsQueryExtensions.Entitys;
namespace CMS.Plugin.$NameSpacePath$.Application.Implements;
/// <summary>
-/// $ChinaComment$应用服务
+/// $ChinaComment$搴旂敤鏈嶅姟
/// </summary>
public class $EntityName$AppService : CMSPluginAppService, I$EntityName$AppService
{
- private readonly I$EntityName$Repository $EntityInstanceName$Repository;
+ private readonly I$EntityName$Repository _$EntityInstanceName$Repository;
/// <summary>
/// Initializes a new instance of the <see cref="$EntityName$AppService"/> class.
/// </summary>
/// <param name="$EntityName$Repository">The task job repository.</param>
- public $EntityName$AppService(I$EntityName$Repository _$EntityName$Repository)
+ public $EntityName$AppService(I$EntityName$Repository $EntityInstanceName$Repository)
{
- $EntityInstanceName$Repository = _$EntityName$Repository;
+ _$EntityInstanceName$Repository = $EntityInstanceName$Repository;
}
/// <summary>
- /// 获取指定$ChinaComment$
+ /// 鑾峰彇鎸囧畾$ChinaComment$
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual async Task<$EntityName$Dto> GetAsync(Guid id)
{
- return ObjectMapper.Map<$EntityName$, $EntityName$Dto>(await $EntityInstanceName$Repository.GetAsync(id));
+ return ObjectMapper.Map<$EntityName$, $EntityName$Dto>(await _$EntityInstanceName$Repository.GetAsync(id));
}
/// <summary>
- /// 分页获取$ChinaComment$
+ /// 鍒嗛〉鑾峰彇$ChinaComment$
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
@@ -53,36 +54,36 @@
input.Sorting = nameof($EntityName$.Sort);
}
- #region 动态构造查询条件
+ #region 鍔ㄦ�佹瀯閫犳煡璇㈡潯浠�
- //动态构造查询条件
+ //鍔ㄦ�佹瀯閫犳煡璇㈡潯浠�
var whereConditions = DynamicGetQueryParams(input);
#endregion
- var count = await $EntityInstanceName$Repository.GetCountAsync(whereConditions);
- var list = await $EntityInstanceName$Repository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount);
+ var count = await _$EntityInstanceName$Repository.GetCountAsync(whereConditions);
+ var list = await _$EntityInstanceName$Repository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount);
return new PagedResultDto<$EntityName$Dto>(count, ObjectMapper.Map<List<$EntityName$>, List<$EntityName$Dto>>(list));
}
/// <summary>
- /// 动态构造查询条件
+ /// 鍔ㄦ�佹瀯閫犳煡璇㈡潯浠�
/// </summary>
- /// <param name="input">输入参数</param>
+ /// <param name="input">杈撳叆鍙傛暟</param>
/// <returns></returns>
private FunReturnResultModel<Expression<Func<$EntityName$, bool>>> DynamicGetQueryParams(Get$EntityName$Input input)
{
- //动态构造查询条件
+ //鍔ㄦ�佹瀯閫犳煡璇㈡潯浠�
var whereConditions = WhereConditionsExtensions.GetWhereConditions<$EntityName$, Get$EntityName$Input>(input);
if (!whereConditions.IsSuccess)
{
- throw new Exception("动态构造查询条件失败:" + whereConditions.ErrMsg);
+ throw new Exception("鍔ㄦ�佹瀯閫犳煡璇㈡潯浠跺け璐�:" + whereConditions.ErrMsg);
}
- //也可再次自定义构建查询条件
+ //涔熷彲鍐嶆鑷畾涔夋瀯寤烘煡璇㈡潯浠�
Expression<Func<$EntityName$, bool>> extendExpression = a => a.IsDeleted == false;
- // 使用 System.Linq.PredicateBuilder 的 And
+ // 浣跨敤 System.Linq.PredicateBuilder 鐨� And
var pres = (System.Linq.Expressions.Expression<Func<$EntityName$, bool>>)(whereConditions.data);
whereConditions.data = System.Linq.PredicateBuilder.And(pres, extendExpression);
@@ -90,7 +91,7 @@
}
/// <summary>
- /// 新建$ChinaComment$
+ /// 鏂板缓$ChinaComment$
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
@@ -99,20 +100,21 @@
{
await CheckCreateOrUpdateDtoAsync(input);
- var exist = await $EntityInstanceName$Repository.NameExistAsync(input.$ValidateRepeatName$);
+ var exist = await _$EntityInstanceName$Repository.NameExistAsync(input.$ValidateRepeatName$);
if (exist)
{
throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.$ValidateRepeatName$]);
}
- var maxSort = await $EntityInstanceName$Repository.GetMaxSortAsync();
+ var maxSort = await _$EntityInstanceName$Repository.GetMaxSortAsync();
var sort = input.Sort ?? maxSort;
var insertObj = ObjectMapper.Map<$EntityName$CreateDto, $EntityName$>(input);
insertObj.Sort = sort;
input.MapExtraPropertiesTo(insertObj, MappingPropertyDefinitionChecks.None);
- await $EntityInstanceName$Repository.InsertAsync(insertObj);
+ insertObj.CreatorName = input.CreatorName;//鍒涘缓浜�
+ await _$EntityInstanceName$Repository.InsertAsync(insertObj);
//if (input.Sort.HasValue && insertObj.Sort != maxSort)
//{
@@ -123,7 +125,7 @@
}
/// <summary>
- /// 更新$ChinaComment$
+ /// 鏇存柊$ChinaComment$
/// </summary>
/// <param name="id"></param>
/// <param name="input"></param>
@@ -133,8 +135,8 @@
{
await CheckCreateOrUpdateDtoAsync(input);
- var updateObj = await $EntityInstanceName$Repository.GetAsync(id);
- var exist = await $EntityInstanceName$Repository.NameExistAsync(input.$ValidateRepeatName$, updateObj.Id);
+ var updateObj = await _$EntityInstanceName$Repository.GetAsync(id);
+ var exist = await _$EntityInstanceName$Repository.NameExistAsync(input.$ValidateRepeatName$, updateObj.Id);
if (exist)
{
throw new UserFriendlyException(L[CMSPluginDomainErrorCodes.NameAlreadyExists, input.$ValidateRepeatName$]);
@@ -145,32 +147,34 @@
$UpdateAttributes$
- await $EntityInstanceName$Repository.UpdateAsync(updateObj);
+ updateObj.LastModifierName = input.LastModifierName;//淇敼浜�
+
+ await _$EntityInstanceName$Repository.UpdateAsync(updateObj);
return ObjectMapper.Map<$EntityName$, $EntityName$Dto>(updateObj);
}
/// <summary>
- /// 克隆$ChinaComment$
+ /// 鍏嬮殕$ChinaComment$
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
- public async Task<List<$EntityName$Dto>> CloneAsync(IEnumerable<Guid> ids)
+ public async Task<List<$EntityName$Dto>> CloneAsync(IEnumerable<Guid> ids, MyCurrentUser myCurrentUser)
{
//var $EntityInstanceName$s = new List<$EntityName$>();
//if (ids != null)
//{
- // var sort = await $EntityInstanceName$Repository.GetMaxSortAsync();
+ // var sort = await _$EntityInstanceName$Repository.GetMaxSortAsync();
// foreach (var id in ids)
// {
- // var $EntityName$ = await $EntityInstanceName$Repository.FindAsync(id);
+ // var $EntityName$ = await _$EntityInstanceName$Repository.FindAsync(id);
// if ($EntityName$ != null)
// {
// var name = $EntityName$.Name + $EntityName$Consts.CloneTag;
// var notExist = false;
// while (!notExist)
// {
- // var exist = await $EntityInstanceName$Repository.NameExistAsync(name);
+ // var exist = await _$EntityInstanceName$Repository.NameExistAsync(name);
// if (exist || $EntityInstanceName$s.Any(x => x.Name == name))
// {
// name += $EntityName$Consts.CloneTag;
@@ -180,7 +184,7 @@
// notExist = true;
// }
- // //$EntityName$ = await $EntityInstanceName$Repository.InsertAsync($EntityName$.Clone(GuidGenerator.Create(), name, sort++));
+ // //$EntityName$ = await _$EntityInstanceName$Repository.InsertAsync($EntityName$.Clone(GuidGenerator.Create(), name, sort++));
// $EntityInstanceName$s.Add($EntityName$);
// }
// }
@@ -191,21 +195,21 @@
}
/// <summary>
- /// 删除单个$ChinaComment$
+ /// 鍒犻櫎鍗曚釜$ChinaComment$
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual Task DeleteAsync(Guid id)
{
- return $EntityInstanceName$Repository.DeleteAsync(id);
+ return _$EntityInstanceName$Repository.DeleteAsync(id);
}
/// <summary>
- /// 删除多个$ChinaComment$
+ /// 鍒犻櫎澶氫釜$ChinaComment$
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
- public async Task DeleteManyAsync(IEnumerable<Guid> ids)
+ public async Task DeleteManyAsync(IEnumerable<Guid> ids, MyCurrentUser myCurrentUser)
{
foreach (var id in ids)
{
@@ -213,15 +217,37 @@
}
}
+ /// <summary>
+ /// 鐗╃悊鍒犻櫎$ChinaComment$
+ /// </summary>
+ /// <param name="id">涓婚敭ID</param>
+ /// <param name="cancellationToken"></param>
+ /// <returns></returns>
+ public virtual async Task DeletePermanentlyAsync(Guid id, MyCurrentUser myCurrentUser, CancellationToken cancellationToken = default)
+ {
+ _$EntityInstanceName$Repository.DeletePermanentlyAsync(id);
+ }
+
/// <summary>
- /// 调整排序$ChinaComment$
+ /// 鎵归噺鐗╃悊鍒犻櫎$ChinaComment$锛堢洿鎺ュ垹闄わ紝涓嶈蒋鍒犻櫎锛�
+ /// </summary>
+ /// <param name="ids">瑕佸垹闄ょ殑涓婚敭ID鍒楄〃</param>
+ /// <param name="cancellationToken"></param>
+ /// <returns></returns>
+ public virtual async Task BatchDeletePermanentlyAsync(IEnumerable<Guid> ids, MyCurrentUser myCurrentUser, CancellationToken cancellationToken = default)
+ {
+ _$EntityInstanceName$Repository.BatchDeletePermanentlyAsync(ids);
+ }
+
+ /// <summary>
+ /// 璋冩暣鎺掑簭$ChinaComment$
/// </summary>
/// <param name="id"></param>
/// <param name="sort"></param>
/// <returns></returns>
public virtual async Task AdjustSortAsync(Guid id, int sort)
{
- var list = await $EntityInstanceName$Repository.GetListAsync(null, nameof($EntityName$.Sort));
+ var list = await _$EntityInstanceName$Repository.GetListAsync(null, nameof($EntityName$.Sort));
if (list != null && list.Any())
{
var initSort = 1;
@@ -248,16 +274,16 @@
}
}
- await $EntityInstanceName$Repository.UpdateManyAsync(list);
+ await _$EntityInstanceName$Repository.UpdateManyAsync(list);
}
/// <summary>
- /// 导入$ChinaComment$
+ /// 瀵煎叆$ChinaComment$
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
/// <exception cref="UserFriendlyException"></exception>
- public async Task ImportAsync($EntityName$sImportModel input)
+ public async Task ImportAsync($EntityName$sImportModel input, MyCurrentUser myCurrentUser)
{
Check.NotNull(input, nameof(input));
@@ -267,14 +293,14 @@
if (importItems != null && importItems.Any())
{
- #region 导入校验
+ #region 瀵煎叆鏍¢獙
- // 判断名称是否重复,并输出第几行重复
+ // 鍒ゆ柇鍚嶇О鏄惁閲嶅锛屽苟杈撳嚭绗嚑琛岄噸澶�
var duplicate$EntityName$s = importItems.GroupBy(x => x.$ValidateRepeatName$).Where(x => x.Count() > 1).ToList();
if (duplicate$EntityName$s?.Any() == true)
{
- var duplicate$EntityName$Msgs = duplicate$EntityName$s.Select(x => $"第 {string.Join(",", x.Select(x => x.RowIndex))} 行:{x.Key} 名称重复");
- var errorMsg = $"导入失败!配置, {string.Join(",", duplicate$EntityName$Msgs)},终止导入";
+ var duplicate$EntityName$Msgs = duplicate$EntityName$s.Select(x => $"绗� {string.Join(",", x.Select(x => x.RowIndex))} 琛岋細{x.Key} 鍚嶇О閲嶅");
+ var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝 {string.Join(",", duplicate$EntityName$Msgs)}锛岀粓姝㈠鍏�";
throw new UserFriendlyException(errorMsg);
}
@@ -289,11 +315,11 @@
if (impItem.$ValidateRepeatName$.IsNullOrWhiteSpace())
{
- var errorMsg = $"导入失败!配置,第{impItem.RowIndex}行:$EntityName$名称不能为空";
+ var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊impItem.RowIndex}琛岋細$EntityName$鍚嶇О涓嶈兘涓虹┖";
throw new UserFriendlyException(errorMsg);
}
- var old$EntityName$ = await $EntityInstanceName$Repository.FindByNameAsync(impItem.$ValidateRepeatName$);
+ var old$EntityName$ = await _$EntityInstanceName$Repository.FindByNameAsync(impItem.$ValidateRepeatName$);
if (old$EntityName$ != null)
{
var $EntityInstanceName$UpdateDto = new $EntityName$UpdateDto
@@ -315,37 +341,39 @@
}
}
- // 新增
+ // 鏂板
foreach (var $EntityInstanceName$Dto in $EntityInstanceName$CreateDtos)
{
try
{
+ $EntityInstanceName$Dto.Item.CreatorName = myCurrentUser.UserAccount;//鍒涘缓浜�
await CreateAsync($EntityInstanceName$Dto.Item);
}
catch (Exception e)
{
- var errorMsg = $"导入失败!配置,第{$EntityInstanceName$Dto.RowIndex}行:{e.Message},终止导入";
+ var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊$EntityInstanceName$Dto.RowIndex}琛岋細{e.Message}锛岀粓姝㈠鍏�";
throw new UserFriendlyException(errorMsg);
}
}
- // 更新
+ // 鏇存柊
foreach (var $EntityInstanceName$Dto in $EntityInstanceName$UpdateDtos)
{
try
{
+ $EntityInstanceName$Dto.Item.LastModifierName = myCurrentUser.UserAccount;//淇敼浜�
await UpdateAsync($EntityInstanceName$Dto.Id, $EntityInstanceName$Dto.Item);
}
catch (Exception e)
{
- var errorMsg = $"导入失败!配置,第{$EntityInstanceName$Dto.RowIndex}行:{e.Message},终止导入";
+ var errorMsg = $"瀵煎叆澶辫触锛侀厤缃紝绗瑊$EntityInstanceName$Dto.RowIndex}琛岋細{e.Message}锛岀粓姝㈠鍏�";
throw new UserFriendlyException(errorMsg);
}
}
}
/// <summary>
- /// 导出$ChinaComment$
+ /// 瀵煎嚭$ChinaComment$
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
@@ -358,28 +386,28 @@
input.Sorting = nameof($EntityName$.Sort);
}
- #region 动态构造查询条件
+ #region 鍔ㄦ�佹瀯閫犳煡璇㈡潯浠�
- //动态构造查询条件
+ //鍔ㄦ�佹瀯閫犳煡璇㈡潯浠�
var whereConditions = DynamicGetQueryParams(input);
#endregion
- var list = await $EntityInstanceName$Repository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true);
+ var list = await _$EntityInstanceName$Repository.GetListAsync(whereConditions, input.Sorting, input.MaxResultCount, input.SkipCount, includeDetails: true);
var result = ObjectMapper.Map<List<$EntityName$>, List<$EntityName$Dto>>(list);
var sheets = new Dictionary<string, object>
{
- ["配置"] = ExportHelper.ConvertListToExportData(result),
+ ["閰嶇疆"] = ExportHelper.ConvertListToExportData(result),
};
- var fileName = result.Count > 1 ? "$ChinaComment$列表" : result.Count == 1 ? result[0]?.$ValidateRepeatName$ : "$EntityName$模版";
+ var fileName = "$PageMenuName$";
return (sheets, fileName);
}
/// <summary>
- /// 校验$ChinaComment$,当新建或更新时
+ /// 鏍¢獙$ChinaComment$锛屽綋鏂板缓鎴栨洿鏂版椂
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
@@ -389,4 +417,28 @@
$UpdateAttributesForCheckCreateOrUpdateDtoAsync$
return Task.CompletedTask;
}
+
+ /// <summary>
+ /// 鏍规嵁鏉′欢鑾峰彇$ChinaComment$鍒楄〃
+ /// </summary>
+ /// <param name="whereConditions"></param>
+ /// <param name="cancellationToken"></param>
+ /// <returns></returns>
+ public async Task<List<$EntityName$>> GetListByFilterAsync(Expression<Func<$EntityName$, bool>> whereConditions, CancellationToken cancellationToken = default)
+ {
+ return await _$EntityInstanceName$Repository.GetListByFilterAsync(whereConditions);
+ }
+
+ /// <summary>
+ /// 鏍规嵁鏉′欢鑾峰彇鍗曚釜$ChinaComment$
+ /// </summary>
+ /// <param name="whereConditions"></param>
+ /// <param name="isMultipleThrowException">鏄惁鏌ヨ鍑哄鏉″氨鎶ラ敊</param>
+ /// <param name="cancellationToken"></param>
+ /// <returns></returns>
+ /// <exception cref="UserFriendlyException"></exception>
+ public async Task<$EntityName$> GetSingleByFilterAsync(Expression<Func<$EntityName$, bool>> whereConditions, bool is鈥婱ultipleThrowException = false, CancellationToken cancellationToken = default)
+ {
+ return await _$EntityInstanceName$Repository.GetSingleByFilterAsync(whereConditions, is鈥婱ultipleThrowException);
+ }
}
--
Gitblit v1.9.3