fix:
This commit is contained in:
commit
4b26bdddd4
@ -5,6 +5,7 @@
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
global using Admin.NET.Core;
|
||||
global using Admin.NET.Core.Utils;
|
||||
global using Furion;
|
||||
global using Furion.DependencyInjection;
|
||||
global using Furion.DynamicApiController;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
// 不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!
|
||||
|
||||
global using Admin.NET.Core.Service;
|
||||
global using Admin.NET.Core.Utils;
|
||||
global using Furion;
|
||||
global using Furion.ConfigurableOptions;
|
||||
global using Furion.DatabaseAccessor;
|
||||
|
||||
@ -91,16 +91,16 @@ public class AggregationBuilder
|
||||
/// <summary>
|
||||
/// 验证字段有效性
|
||||
/// </summary>
|
||||
public static List<string> ValidateFields(string[] fields, Type targetType)
|
||||
public static List<string> ValidateFields<T>(string[] fields, Type targetType)
|
||||
{
|
||||
if (fields == null || fields.Length == 0) return new List<string>();
|
||||
|
||||
return fields
|
||||
.Where(f => !string.IsNullOrWhiteSpace(f))
|
||||
.Select(f => f.Trim())
|
||||
// .Where(f => targetType.GetProperty(
|
||||
// targetType == typeof(UsagetokenOutput) ?
|
||||
// $"{f}Sum" : f) != null)
|
||||
.Where(f => targetType.GetProperty(
|
||||
targetType == typeof(T) ?
|
||||
$"{f}Sum" : f) != null)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,7 +26,6 @@ using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
using @(@Model.NameSpace).Entity;
|
||||
|
||||
namespace @Model.NameSpace;
|
||||
|
||||
@ -36,18 +35,28 @@ namespace @Model.NameSpace;
|
||||
[ApiDescriptionSettings(@(@Model.ProjectLastName)Const.GroupName, Name = "@(@Model.LowerClassName)", Order = 100)]
|
||||
public partial class @(@Model.ClassName)Service : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly SysCacheService _sysCacheService;//默认CacheService
|
||||
private readonly UserManager _userManager;//默认用户管理
|
||||
private readonly IEventPublisher _eventPublisher;//默认事件总线
|
||||
private readonly SqlSugarRepository<@(@Model.ClassName)> _@(@Model.LowerClassName)Rep;
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||
if(@column.FkEntityName != @Model.ClassName){
|
||||
@:private readonly SqlSugarRepository<@(@column.FkEntityName)> _@(@column.LowerFkEntityName)Rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
private TypeAdapterConfig _typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
|
||||
public @(@Model.ClassName)Service(SqlSugarRepository<@(@Model.ClassName)> @(@Model.LowerClassName)Rep
|
||||
,SysCacheService sysCacheService
|
||||
, UserManager userManager
|
||||
,IEventPublisher eventPublisher
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||
if(@column.FkEntityName != @Model.ClassName){
|
||||
@:,SqlSugarRepository<@(@column.FkEntityName)> @(@column.LowerFkEntityName)Rep
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,10 +65,15 @@ public partial class @(@Model.ClassName)Service : IDynamicApiController, ITransi
|
||||
_@(@Model.LowerClassName)Rep = @(@Model.LowerClassName)Rep;
|
||||
@foreach (var column in Model.TableField){
|
||||
if(@column.EffectType == "ForeignKey"||@column.EffectType == "ApiTreeSelector"){
|
||||
if(@column.FkEntityName != @Model.ClassName){
|
||||
@:_@(@column.LowerFkEntityName)Rep = @(@column.LowerFkEntityName)Rep;
|
||||
}
|
||||
}
|
||||
}
|
||||
_typeAdapterConfig.ForType<T, @(@Model.ClassName)>().IgnoreNullValues(true);
|
||||
_sysCacheService = sysCacheService;
|
||||
_eventPublisher = eventPublisher;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -168,28 +182,28 @@ if (@column.ColumnKey == "True"){
|
||||
return await @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input).OrderBuilder(input).ToListAsync();
|
||||
}
|
||||
|
||||
@if(@Model.TableField.Any(x=>x.Statistical == "Y")){
|
||||
@:/// <summary>
|
||||
@:/// 获取@(@Model.BusName)
|
||||
@:/// </summary>
|
||||
@:/// <param name="input"></param>
|
||||
@:/// <returns></returns>
|
||||
@:[ApiDescriptionSettings(Name = "GetTotalSum", Description = "获取@(@Model.BusName)统计", Order = 960), HttpPost]
|
||||
@:[DisplayName("获取@(@Model.BusName)统计")]
|
||||
@:public async Task<List<@(@Model.ClassName)Output>> GetTotalSum(Page@(@Model.ClassName)Input input)
|
||||
@:{
|
||||
@:// 单次查询同时获取统计值
|
||||
@:var querystats = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
||||
/// <summary>
|
||||
/// 获取@(@Model.BusName)
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[ApiDescriptionSettings(Name = "GetTotalSum", Description = "获取@(@Model.BusName)统计", Order = 960), HttpPost]
|
||||
[DisplayName("获取@(@Model.BusName)统计")]
|
||||
public async Task<List<@(@Model.ClassName)Output>> GetTotalSum(Page@(@Model.ClassName)Input input)
|
||||
{
|
||||
// 单次查询同时获取统计值
|
||||
var querystats = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
||||
@if(@Model.TableField.Any(x=>x.IsGroupBy == "Y")){
|
||||
@foreach (var column in Model.TableField){
|
||||
if (@column.IsGroupBy == "Y"){
|
||||
@: .GroupByIF(input.GroupBy.Contains("@column.PropertyName"), u => u.@column.PropertyName)
|
||||
}
|
||||
}
|
||||
@: //.Having(it => SqlFunc.AggregateCount(it.Id) > 0)//聚合函数过滤
|
||||
@: .Select(it => new @(@Model.ClassName)Output
|
||||
@: {
|
||||
@: count = SqlFunc.AggregateCount(it.Id),
|
||||
|
||||
}
|
||||
.Select(it => new @(@Model.ClassName)Output
|
||||
{
|
||||
count = SqlFunc.AggregateCount(it.Id),
|
||||
@foreach (var column in Model.TableField){
|
||||
if (@column.IsGroupBy == "Y"){
|
||||
@: @(@column.PropertyName) = it.@(@column.PropertyName),
|
||||
@ -198,10 +212,9 @@ if (@column.ColumnKey == "True"){
|
||||
@: @(@column.PropertyName) = SqlFunc.AggregateSum(it.@(@column.PropertyName)) ?? 0,
|
||||
}
|
||||
}
|
||||
@: });
|
||||
@:return await querystats.ToListAsync();
|
||||
@:}
|
||||
}
|
||||
});
|
||||
return await querystats.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据输入参数获取@(@Model.BusName)统计
|
||||
@ -220,7 +233,7 @@ if (@column.ColumnKey == "True"){
|
||||
public async Task<List<@(@Model.ClassName)Output>> GetAggregTotalSum(Page@(@Model.ClassName)Input input)
|
||||
{
|
||||
|
||||
@:var query = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input)
|
||||
var query = @(@Model.ClassName)Mid.GetQuery(_@(@Model.LowerClassName)Rep, input);
|
||||
// 输入参数示例
|
||||
//input = new Page@(@Model.ClassName)Input
|
||||
//{
|
||||
@ -253,7 +266,7 @@ if (@column.ColumnKey == "True"){
|
||||
// HAVING(SUM(cost) > 10000) AND(AVG(CAST(response_time AS FLOAT)) < 500)
|
||||
|
||||
// 处理分组字段
|
||||
var groupFields = AggregationBuilder.ValidateFields(input.GroupBy, typeof(@(@Model.ClassName)Output));
|
||||
var groupFields = AggregationBuilder.ValidateFields<@(@Model.ClassName)Output>(input.GroupBy, typeof(@(@Model.ClassName)Output));
|
||||
if (groupFields.Count > 0)
|
||||
{
|
||||
query = query.GroupBy(string.Join(",", groupFields));
|
||||
|
||||
@ -401,7 +401,6 @@ const handleQuery = async (reset = false) => {
|
||||
@if(@Model.TableField.Any(x=>x.Statistical == "Y")){
|
||||
@if (@Model.IsApiService) {
|
||||
@:state.totalSum =getAPI(@(@Model.ClassName)Api).api@(@Model.ClassName)GetTotalSumPost(params).data.result;
|
||||
}
|
||||
} else {
|
||||
@:state.totalSum =(await get@(@Model.ClassName)TotalSum(state.queryParams)).data.result;
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@
|
||||
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerPropertyName)">
|
||||
@:<el-select clearable v-model="state.ruleForm.@(@column.LowerPropertyName)" placeholder="请选择@(@column.ColumnComment)">
|
||||
@:<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="@(@column.NetType.StartsWith("string") ? "item.code" : "Number(item.value)")" :label="`${item.name||''} [${item.code}] ${item.value}`"></el-option>
|
||||
@:<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="@(@column.NetType.StartsWith("string") ? "item.code" : "Number(item.value)")" :label="`${item.label||''} [${item.code}] ${item.value}`"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
@ -142,7 +142,7 @@
|
||||
@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
|
||||
@:<el-form-item label="@column.ColumnComment" prop="@(@column.LowerPropertyName)">
|
||||
@:<el-select clearable v-model="state.ruleForm.@(@column.LowerPropertyName)" placeholder="请选择@(@column.ColumnComment)">
|
||||
@:<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="@(@column.NetType.StartsWith("string") ? "item.value" : "Number(item.value)")" :label="`${item.name||''} (${item.code}) [${item.value}]`"></el-option>
|
||||
@:<el-option v-for="(item,index) in dl('@(@column.DictTypeCode)')" :key="index" :value="@(@column.NetType.StartsWith("string") ? "item.value" : "Number(item.value)")" :label="`${item.label||''} (${item.code}) [${item.value}]`"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user