修改泛型通用接口
This commit is contained in:
@@ -83,22 +83,6 @@ public class VmGetListInput : VmBaseInput
|
||||
/// 输出字段
|
||||
/// </summary>
|
||||
public string o { get; set; } = "*";
|
||||
|
||||
/// <summary>
|
||||
/// 转换为QueryInput
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmQueryInput ToQueryInput()
|
||||
{
|
||||
VmQueryInput arg = this.Adapt<VmQueryInput>();
|
||||
|
||||
if (!string.IsNullOrEmpty(q))
|
||||
{
|
||||
arg.q = q.ToObject<DObject>();
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,7 +99,7 @@ public class VmQueryInput : VmGetListInput
|
||||
/// <summary>
|
||||
/// 新增数据输入参数
|
||||
/// </summary>
|
||||
public class VmCreateInput : VmBaseInput
|
||||
public class VmEditInput : VmBaseInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据
|
||||
@@ -128,17 +112,6 @@ public class VmCreateInput : VmBaseInput
|
||||
public List<DObject>? items { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改数据输入参数
|
||||
/// </summary>
|
||||
public class VmUpdateInput : VmCreateInput
|
||||
{
|
||||
///// <summary>
|
||||
///// 要更新的数据id
|
||||
///// </summary>
|
||||
//public string? id { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除数据输入参数
|
||||
/// </summary>
|
||||
|
||||
@@ -24,11 +24,12 @@ internal class VmQueryParser
|
||||
_dataAccess = dataAccess;
|
||||
_root = rootModel;
|
||||
_input = input;
|
||||
ParseQueryInput();
|
||||
}
|
||||
/// <summary>
|
||||
/// 解析查询参数
|
||||
/// </summary>
|
||||
public void ParseQueryInput()
|
||||
private void ParseQueryInput()
|
||||
{
|
||||
// 初始化根模型
|
||||
Navigates.Clear();
|
||||
@@ -263,6 +264,92 @@ internal class VmQueryParser
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
public List<IConditionalModel> GetConditionalModels()
|
||||
{
|
||||
List<IConditionalModel> wheres = new();
|
||||
// 处理软删除
|
||||
var softDeletedProp = _root.GetSoftDeleted();
|
||||
if (softDeletedProp != null && !Navigates[MAIN_ALIES].wheres.Any(a => a.code == softDeletedProp.code))
|
||||
{
|
||||
wheres.Add(new ConditionalModel { FieldName = MAIN_ALIES + "." + softDeletedProp.field, FieldValue = "0", ConditionalType = ConditionalType.Equal, CSharpTypeName = softDeletedProp.csType });
|
||||
}
|
||||
|
||||
foreach (VmNavigate? nav in Navigates.Values.Where(a => (a.path == MAIN_ALIES || a.navConfig.navType == eNavigateType.OneToOne) && a.wheres.Count > 0))
|
||||
{
|
||||
foreach (VmWhereProp where in nav.wheres)
|
||||
{
|
||||
// 当条件为集合数据时
|
||||
if (where.value is IEnumerable<object> arrObj)
|
||||
{
|
||||
object[] val = arrObj.ToArray();
|
||||
string op = val[0].ToString()!;
|
||||
switch (op)
|
||||
{
|
||||
case "><":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case ">=<":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThan, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case "><=":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThan, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case ">=<=":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[1].ToString(), ConditionalType = ConditionalType.GreaterThanOrEqual, CSharpTypeName = where.csType });
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = val[2].ToString(), ConditionalType = ConditionalType.LessThanOrEqual, CSharpTypeName = where.csType });
|
||||
break;
|
||||
case "in":
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = string.Join(',', val.Skip(1)), ConditionalType = ConditionalType.In, CSharpTypeName = where.csType });
|
||||
break;
|
||||
default: op = string.Empty; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConditionalType conditionalType = ConditionalType.Equal;
|
||||
string? value = where.value?.ToString();
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value.Length >= 2)
|
||||
{
|
||||
string op = value[..2];
|
||||
switch (op)
|
||||
{
|
||||
case "%%": conditionalType = ConditionalType.Like; break;
|
||||
case ">>": conditionalType = ConditionalType.GreaterThan; break;
|
||||
case "<<": conditionalType = ConditionalType.LessThan; break;
|
||||
case ">=": conditionalType = ConditionalType.GreaterThanOrEqual; break;
|
||||
case "<=": conditionalType = ConditionalType.LessThanOrEqual; break;
|
||||
case "==": conditionalType = ConditionalType.Equal; break;
|
||||
default: op = string.Empty; break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(op))
|
||||
{
|
||||
value = value.RemovePreFix(op);
|
||||
if (value.ToLower() == "null")
|
||||
{
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
wheres.Add(new ConditionalModel { FieldName = where.fieldName, FieldValue = value, ConditionalType = conditionalType, CSharpTypeName = where.csType });
|
||||
}
|
||||
}
|
||||
}
|
||||
return wheres;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成查询过滤条件
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <returns></returns>
|
||||
public List<IConditionalModel> FilterSofeDeleted()
|
||||
{
|
||||
List<IConditionalModel> wheres = new();
|
||||
foreach (VmNavigate? nav in Navigates.Values.Where(a => (a.path == MAIN_ALIES || a.navConfig.navType == eNavigateType.OneToOne) && a.wheres.Count > 0))
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Tnb.Vengine.Domain;
|
||||
[SugarTable("sys_vmodel")]
|
||||
public partial class Vmodel : Entity
|
||||
{
|
||||
public string[] SOFT_DELETED = new string[] { "deleted", "isDeleted", "softDeleted" };
|
||||
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
@@ -188,12 +190,23 @@ public partial class Vmodel : Entity
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型的主键字段属性
|
||||
/// 获取模型的主键属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmDbProp GetPrimary()
|
||||
{
|
||||
return dbProps.First(a => a.pkey);
|
||||
var key = dbProps.FirstOrDefault(a => a.pkey);
|
||||
ThrowIf.IsNull(key, $"模型({fullCode})没有定义主键属性");
|
||||
return key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取模型的软删除属性
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public VmDbProp? GetSoftDeleted()
|
||||
{
|
||||
return dbProps.FirstOrDefault(a => SOFT_DELETED.Contains(a.code));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user