更新代码生成器,修正对已有扩展查询的识别兼容
This commit is contained in:
parent
12bd6c7f17
commit
36bd1ea8be
|
@ -305,7 +305,7 @@ public class EntityBuilder : ClassBuilder
|
||||||
if (!Business)
|
if (!Business)
|
||||||
{
|
{
|
||||||
// 读取biz文件,识别其中已生成的扩展查询方法,避免在数据类中重复生成
|
// 读取biz文件,识别其中已生成的扩展查询方法,避免在数据类中重复生成
|
||||||
var bizFile = GetFileName(null, Option.ChineseFileName);
|
var bizFile = GetFileName(".Biz.cs", Option.ChineseFileName);
|
||||||
LoadCodeFile(bizFile);
|
LoadCodeFile(bizFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1512,7 +1512,7 @@ public class EntityBuilder : ClassBuilder
|
||||||
var pks = Table.PrimaryKeys;
|
var pks = Table.PrimaryKeys;
|
||||||
if (pks.Length > 0)
|
if (pks.Length > 0)
|
||||||
{
|
{
|
||||||
if (BuildExtendFind(pks)) methods++;
|
if (BuildExtendFind(pks, methods)) methods++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 索引
|
// 索引
|
||||||
|
@ -1537,16 +1537,14 @@ public class EntityBuilder : ClassBuilder
|
||||||
// 只有整数和字符串能生成查询函数
|
// 只有整数和字符串能生成查询函数
|
||||||
if (cs.Any(e => !IsIntOrString(e))) continue;
|
if (cs.Any(e => !IsIntOrString(e))) continue;
|
||||||
|
|
||||||
if (methods > 0) WriteLine();
|
|
||||||
|
|
||||||
// 返回类型
|
// 返回类型
|
||||||
if (di.Unique)
|
if (di.Unique)
|
||||||
{
|
{
|
||||||
if (BuildExtendFind(cs)) methods++;
|
if (BuildExtendFind(cs, methods)) methods++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (BuildExtendFindAll(cs)) methods++;
|
if (BuildExtendFindAll(cs, methods)) methods++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1562,7 +1560,10 @@ public class EntityBuilder : ClassBuilder
|
||||||
if (item.Count() > 1)
|
if (item.Count() > 1)
|
||||||
{
|
{
|
||||||
var dc = Table.GetColumn(item.Key);
|
var dc = Table.GetColumn(item.Key);
|
||||||
if (dc != null) BuildExtendFindAll([dc]);
|
if (dc != null)
|
||||||
|
{
|
||||||
|
if (BuildExtendFindAll([dc], methods)) methods++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1571,7 +1572,8 @@ public class EntityBuilder : ClassBuilder
|
||||||
|
|
||||||
/// <summary>生成扩展Find查询单对象</summary>
|
/// <summary>生成扩展Find查询单对象</summary>
|
||||||
/// <param name="columns"></param>
|
/// <param name="columns"></param>
|
||||||
protected virtual Boolean BuildExtendFind(IDataColumn[] columns)
|
/// <param name="index"></param>
|
||||||
|
protected virtual Boolean BuildExtendFind(IDataColumn[] columns, Int32 index)
|
||||||
{
|
{
|
||||||
var methodName = columns.Select(e => e.Name).Join("And");
|
var methodName = columns.Select(e => e.Name).Join("And");
|
||||||
methodName = $"FindBy{methodName}";
|
methodName = $"FindBy{methodName}";
|
||||||
|
@ -1587,11 +1589,11 @@ public class EntityBuilder : ClassBuilder
|
||||||
var args = ps.Join(", ", e => $"{e.Value} {e.Key}");
|
var args = ps.Join(", ", e => $"{e.Value} {e.Key}");
|
||||||
|
|
||||||
// 如果方法名已存在,则不生成
|
// 如果方法名已存在,则不生成
|
||||||
var key = $"{methodName}({args})";
|
var key = $"{methodName}({ps.Join(",", e => e.Value)})";
|
||||||
if (Members.Contains(key)) return false;
|
if (Members.Contains(key)) return false;
|
||||||
Members.Add(key);
|
Members.Add(key);
|
||||||
|
|
||||||
//WriteLine();
|
if (index > 0) WriteLine();
|
||||||
WriteLine("/// <summary>根据{0}查找</summary>", columns.Select(e => e.DisplayName).Join("、"));
|
WriteLine("/// <summary>根据{0}查找</summary>", columns.Select(e => e.DisplayName).Join("、"));
|
||||||
foreach (var dc in columns)
|
foreach (var dc in columns)
|
||||||
{
|
{
|
||||||
|
@ -1671,7 +1673,8 @@ public class EntityBuilder : ClassBuilder
|
||||||
|
|
||||||
/// <summary>生成扩展FindAll查询对象列表</summary>
|
/// <summary>生成扩展FindAll查询对象列表</summary>
|
||||||
/// <param name="columns"></param>
|
/// <param name="columns"></param>
|
||||||
protected virtual Boolean BuildExtendFindAll(IDataColumn[] columns)
|
/// <param name="index"></param>
|
||||||
|
protected virtual Boolean BuildExtendFindAll(IDataColumn[] columns, Int32 index)
|
||||||
{
|
{
|
||||||
var methodName = columns.Select(e => e.Name).Join("And");
|
var methodName = columns.Select(e => e.Name).Join("And");
|
||||||
methodName = $"FindAllBy{methodName}";
|
methodName = $"FindAllBy{methodName}";
|
||||||
|
@ -1687,11 +1690,11 @@ public class EntityBuilder : ClassBuilder
|
||||||
var args = ps.Join(", ", e => $"{e.Value} {e.Key}");
|
var args = ps.Join(", ", e => $"{e.Value} {e.Key}");
|
||||||
|
|
||||||
// 如果方法名已存在,则不生成
|
// 如果方法名已存在,则不生成
|
||||||
var key = $"{methodName}({args})";
|
var key = $"{methodName}({ps.Join(",", e => e.Value)})";
|
||||||
if (Members.Contains(key)) return false;
|
if (Members.Contains(key)) return false;
|
||||||
Members.Add(key);
|
Members.Add(key);
|
||||||
|
|
||||||
//WriteLine();
|
if (index > 0) WriteLine();
|
||||||
WriteLine("/// <summary>根据{0}查找</summary>", columns.Select(e => e.DisplayName).Join("、"));
|
WriteLine("/// <summary>根据{0}查找</summary>", columns.Select(e => e.DisplayName).Join("、"));
|
||||||
foreach (var dc in columns)
|
foreach (var dc in columns)
|
||||||
{
|
{
|
||||||
|
|
|
@ -166,13 +166,20 @@ internal class MemberSection
|
||||||
var rs = new List<MemberSection>();
|
var rs = new List<MemberSection>();
|
||||||
if (txt.IsNullOrEmpty()) return rs;
|
if (txt.IsNullOrEmpty()) return rs;
|
||||||
|
|
||||||
var reg = new Regex(@"([\w\<\>,]+)\s(\w+)\(([^\)]*)\)\s*(?://)*{");
|
var reg = new Regex(@"([\w\<\>,]+)\s(\w+)\(([^\)]*)\)\s*(?://)*(?:{|=>)");
|
||||||
foreach (Match item in reg.Matches(txt))
|
foreach (Match item in reg.Matches(txt))
|
||||||
{
|
{
|
||||||
|
var types = new List<String>();
|
||||||
|
foreach (var elm in item.Groups[3].Value.Split(","))
|
||||||
|
{
|
||||||
|
var str = elm.Trim();
|
||||||
|
var p = str.IndexOf(' ');
|
||||||
|
if (p > 0) types.Add(str[..p]);
|
||||||
|
}
|
||||||
rs.Add(new MemberSection
|
rs.Add(new MemberSection
|
||||||
{
|
{
|
||||||
Name = item.Groups[2].Value,
|
Name = item.Groups[2].Value,
|
||||||
FullName = $"{item.Groups[2].Value}({item.Groups[3].Value})",
|
FullName = $"{item.Groups[2].Value}({types.Join(",")})",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<EntityModel xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="https://newlifex.com https://newlifex.com/Model202309.xsd" Document="https://newlifex.com/xcode/model" xmlns="https://newlifex.com/Model202309.xsd">
|
<EntityModel xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="https://newlifex.com https://newlifex.com/Model202407.xsd" Document="https://newlifex.com/xcode/model" xmlns="https://newlifex.com/Model202407.xsd">
|
||||||
<Option>
|
<Option>
|
||||||
<!--类名模板。其中{name}替换为Table.Name,如{name}Model/I{name}Dto等-->
|
<!--类名模板。其中{name}替换为Table.Name,如{name}Model/I{name}Dto等-->
|
||||||
<ClassNameTemplate />
|
<ClassNameTemplate />
|
||||||
|
|
Binary file not shown.
|
@ -260,6 +260,9 @@ public partial class Area : IArea, IEntity<AreaModel>
|
||||||
#region 关联映射
|
#region 关联映射
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得地区字段信息的快捷方式</summary>
|
/// <summary>取得地区字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -332,6 +332,9 @@ public partial class Parameter : IParameter, IEntity<ParameterModel>
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得字典参数字段信息的快捷方式</summary>
|
/// <summary>取得字典参数字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -29,7 +29,7 @@ public partial class Log : ILog, IEntity<LogModel>
|
||||||
[DisplayName("编号")]
|
[DisplayName("编号")]
|
||||||
[Description("编号")]
|
[Description("编号")]
|
||||||
[DataObjectField(true, false, false, 0)]
|
[DataObjectField(true, false, false, 0)]
|
||||||
[BindColumn("ID", "编号", "")]
|
[BindColumn("ID", "编号", "", DataScale = "time")]
|
||||||
public Int64 ID { get => _ID; set { if (OnPropertyChanging("ID", value)) { _ID = value; OnPropertyChanged("ID"); } } }
|
public Int64 ID { get => _ID; set { if (OnPropertyChanging("ID", value)) { _ID = value; OnPropertyChanged("ID"); } } }
|
||||||
|
|
||||||
private String? _Category;
|
private String? _Category;
|
||||||
|
@ -272,6 +272,20 @@ public partial class Log : ILog, IEntity<LogModel>
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region 数据清理
|
||||||
|
/// <summary>清理指定时间段内的数据</summary>
|
||||||
|
/// <param name="start">开始时间。未指定时清理小于指定时间的所有数据</param>
|
||||||
|
/// <param name="end">结束时间</param>
|
||||||
|
/// <returns>清理行数</returns>
|
||||||
|
public static Int32 DeleteWith(DateTime start, DateTime end)
|
||||||
|
{
|
||||||
|
return Delete(_.ID.Between(start, end, Meta.Factory.Snow));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得日志字段信息的快捷方式</summary>
|
/// <summary>取得日志字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -478,6 +478,9 @@ public partial class User : IUser, IEntity<UserModel>
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得用户字段信息的快捷方式</summary>
|
/// <summary>取得用户字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -250,6 +250,9 @@ public partial class Tenant : ITenant, IEntity<TenantModel>
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得租户字段信息的快捷方式</summary>
|
/// <summary>取得租户字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -223,6 +223,9 @@ public partial class TenantUser : ITenantUser, IEntity<TenantUserModel>
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得租户关系字段信息的快捷方式</summary>
|
/// <summary>取得租户关系字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -367,6 +367,9 @@ public partial class Menu : IMenu, IEntity<MenuModel>
|
||||||
#region 关联映射
|
#region 关联映射
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得菜单字段信息的快捷方式</summary>
|
/// <summary>取得菜单字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -300,6 +300,9 @@ public partial class Role : IRole, IEntity<RoleModel>
|
||||||
#region 关联映射
|
#region 关联映射
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得角色字段信息的快捷方式</summary>
|
/// <summary>取得角色字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -375,6 +375,9 @@ public partial class Department : IDepartment, IEntity<DepartmentModel>
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 扩展查询
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region 字段名
|
#region 字段名
|
||||||
/// <summary>取得部门字段信息的快捷方式</summary>
|
/// <summary>取得部门字段信息的快捷方式</summary>
|
||||||
public partial class _
|
public partial class _
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"XCodeTool": {
|
"XCodeTool": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": ""
|
"commandLineArgs": "../../XCode/Membership/Member.xml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -475,7 +475,6 @@ public class MemberSectionTests
|
||||||
{
|
{
|
||||||
var code =
|
var code =
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#region 扩展属性
|
#region 扩展属性
|
||||||
/// <summary>部门</summary>
|
/// <summary>部门</summary>
|
||||||
[XmlIgnore, IgnoreDataMember, ScriptIgnore]
|
[XmlIgnore, IgnoreDataMember, ScriptIgnore]
|
||||||
|
@ -571,13 +570,27 @@ public class MemberSectionTests
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public static IList<Area> FindAllByName(String name) => Meta.Cache.Entities.FindAll(e => e.Name == name || e.FullName == name);
|
||||||
|
|
||||||
|
/// <summary>根据父级、名称查找</summary>
|
||||||
|
/// <param name="parentId">父级</param>
|
||||||
|
/// <param name="name">名称</param>
|
||||||
|
/// <returns>实体列表</returns>
|
||||||
|
public static IList<Department> FindAllByParentIDAndName(Int32 parentId, String name)
|
||||||
|
{
|
||||||
|
|
||||||
|
// 实体缓存
|
||||||
|
if (Meta.Session.Count < 1000) return Meta.Cache.FindAll(e => e.ParentID == parentId && e.Name.EqualIgnoreCase(name));
|
||||||
|
|
||||||
|
return FindAll(_.ParentID == parentId & _.Name == name);
|
||||||
|
}
|
||||||
|
|
||||||
""";
|
""";
|
||||||
|
|
||||||
var list = MemberSection.GetMethods(code);
|
var list = MemberSection.GetMethods(code);
|
||||||
|
|
||||||
Assert.NotNull(list);
|
Assert.NotNull(list);
|
||||||
Assert.Equal(6, list.Count);
|
Assert.Equal(8, list.Count);
|
||||||
|
|
||||||
Assert.Equal("FindByID", list[0].Name);
|
Assert.Equal("FindByID", list[0].Name);
|
||||||
Assert.Equal("FindByName", list[1].Name);
|
Assert.Equal("FindByName", list[1].Name);
|
||||||
|
@ -585,13 +598,17 @@ public class MemberSectionTests
|
||||||
Assert.Equal("FindAllByMobile", list[3].Name);
|
Assert.Equal("FindAllByMobile", list[3].Name);
|
||||||
Assert.Equal("FindAllByCode", list[4].Name);
|
Assert.Equal("FindAllByCode", list[4].Name);
|
||||||
Assert.Equal("FindAllByRoleID", list[5].Name);
|
Assert.Equal("FindAllByRoleID", list[5].Name);
|
||||||
|
Assert.Equal("FindAllByName", list[6].Name);
|
||||||
|
Assert.Equal("FindAllByParentIDAndName", list[7].Name);
|
||||||
|
|
||||||
Assert.Equal("FindByID(Int32 id)", list[0].FullName);
|
Assert.Equal("FindByID(Int32)", list[0].FullName);
|
||||||
Assert.Equal("FindByName(String name)", list[1].FullName);
|
Assert.Equal("FindByName(String)", list[1].FullName);
|
||||||
Assert.Equal("FindAllByMail(String mail)", list[2].FullName);
|
Assert.Equal("FindAllByMail(String)", list[2].FullName);
|
||||||
Assert.Equal("FindAllByMobile(String mobile)", list[3].FullName);
|
Assert.Equal("FindAllByMobile(String)", list[3].FullName);
|
||||||
Assert.Equal("FindAllByCode(String code)", list[4].FullName);
|
Assert.Equal("FindAllByCode(String)", list[4].FullName);
|
||||||
Assert.Equal("FindAllByRoleID(Int32 roleId)", list[5].FullName);
|
Assert.Equal("FindAllByRoleID(Int32)", list[5].FullName);
|
||||||
|
Assert.Equal("FindAllByName(String)", list[6].FullName);
|
||||||
|
Assert.Equal("FindAllByParentIDAndName(Int32,String)", list[7].FullName);
|
||||||
|
|
||||||
//Assert.Equal(lines.Length, list.Sum(e => e.Lines.Length));
|
//Assert.Equal(lines.Length, list.Sum(e => e.Lines.Length));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
@ -244,7 +244,6 @@ public partial class CorePerson
|
||||||
return Find(_.Pname == pname & _.CreditNo == creditNo);
|
return Find(_.Pname == pname & _.CreditNo == creditNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>根据楼宇ID查找</summary>
|
/// <summary>根据楼宇ID查找</summary>
|
||||||
/// <param name="buildId">楼宇ID</param>
|
/// <param name="buildId">楼宇ID</param>
|
||||||
/// <returns>实体列表</returns>
|
/// <returns>实体列表</returns>
|
||||||
|
|
Loading…
Reference in New Issue