Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/NewLifeX/NewLife.Cube
Browse files Browse the repository at this point in the history
  • Loading branch information
YYNNB committed Aug 7, 2023
2 parents 77f4a81 + ac217a6 commit 47f510d
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 163 deletions.
4 changes: 2 additions & 2 deletions CubeDemo/CubeDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.8" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.707-beta0322" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.801" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions CubeDemoNC/CubeDemoNC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.8" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.707-beta0322" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.9" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.801" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions CubeSSO/CubeSSO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.4.2023.707" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.707-beta0322" />
<PackageReference Include="NewLife.Core" Version="10.5.2023.801" />
<PackageReference Include="NewLife.Stardust.Extensions" Version="2.9.2023.801" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion NewLife.Cube.Blazor/NewLife.Cube.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="7.8.4" />
<PackageReference Include="BootstrapBlazor" Version="7.9.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ layui.use(['form'], function() {
foreach (var item in entity.Permissions.OrderBy(e => e.Key))
{
var id = "pf" + entity.ID + "_" + ((Int32)item.Key);
@Html.CheckBox(id, role.Has(entity.ID, (PermissionFlags)item.Key), new { @parentkey = "auth_child" + entity.ID, @proparentkey = "pro_" + item.Key + "_" + entity.ParentID, @prokey = "pro_" + (Int32)PermissionFlags.All + "_" + entity.ParentID,title=item.Value,lay_filter="pro_child"})
@Html.CheckBox(id, role.Has(entity.ID, (PermissionFlags)item.Key), new { @parentkey = "auth_child" + entity.ID, @proparentkey = "pro_" + item.Key + "_" + entity.ParentID, @prokey = "pro_" + (UInt32)PermissionFlags.All + "_" + entity.ParentID,title=item.Value,lay_filter="pro_child"})
@*@Html.Label(id, item.Value)*@
@*var chec = role.Has(entity.ID, (PermissionFlags)item.Key)?"checked":"";*@
<script type="text/javascript">
Expand All @@ -345,7 +345,7 @@ layui.use(['form'], function() {
@Html.CheckBox("pc_readonly_" + entity.ID, false, new { @class = "pro_detail", @prochildkey = "pro_" + (Int32)PermissionFlags.Detail + "_" + entity.ID,title="只读",lay_skin="primary",lay_filter="pro_detail"})
@*@Html.Label("pc_readonly_" + entity.ID, "只读")*@
<text>&nbsp;</text>
@Html.CheckBox("pc_all_" + entity.ID, false, new { @class = "pro_all", @prochildkey = "pro_" + (Int32)PermissionFlags.All + "_" + entity.ID,title="全部",lay_skin="primary",lay_filter="pro_all" })
@Html.CheckBox("pc_all_" + entity.ID, false, new { @class = "pro_all", @prochildkey = "pro_" + (UInt32)PermissionFlags.All + "_" + entity.ID,title="全部",lay_skin="primary",lay_filter="pro_all" })
@*@Html.Label("pc_all_" + entity.ID, "全部")*@
}
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
{
var id = "pf" + entity.ID + "_" + ((Int32)item.Key);
<div class="form-check form-check-sm form-check-custom form-check-solid me-5">
@Html.CheckBox(id, role.Has(entity.ID, (PermissionFlags)item.Key), new { @class = "form-check-input", @parentkey = "auth_child" + entity.ID, @proparentkey = "pro_" + item.Key + "_" + entity.ParentID, @prokey = "pro_" + (Int32)PermissionFlags.All + "_" + entity.ParentID })
@Html.CheckBox(id, role.Has(entity.ID, (PermissionFlags)item.Key), new { @class = "form-check-input", @parentkey = "auth_child" + entity.ID, @proparentkey = "pro_" + item.Key + "_" + entity.ParentID, @prokey = "pro_" + (UInt32)PermissionFlags.All + "_" + entity.ParentID })
@Html.Label(id, item.Value)
</div>
}
Expand All @@ -104,7 +104,7 @@
</div>

<div class="form-check form-check-sm form-check-custom form-check-solid me-5">
@Html.CheckBox("pc_all_" + entity.ID, false, new { @class = "form-check-input pro_all", @prochildkey = "pro_" + (Int32)PermissionFlags.All + "_" + entity.ID })
@Html.CheckBox("pc_all_" + entity.ID, false, new { @class = "form-check-input pro_all", @prochildkey = "pro_" + (UInt32)PermissionFlags.All + "_" + entity.ID })
@Html.Label("pc_all_" + entity.ID, "全部")
</div>
</div>
Expand Down
261 changes: 130 additions & 131 deletions NewLife.Cube/Entity/定时作业.Biz.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,148 +5,147 @@
using XCode;
using XCode.Membership;

namespace NewLife.Cube.Entity
namespace NewLife.Cube.Entity;

/// <summary>定时作业。定时执行任务</summary>
public partial class CronJob : Entity<CronJob>
{
/// <summary>定时作业。定时执行任务</summary>
public partial class CronJob : Entity<CronJob>
#region 对象操作
static CronJob()
{
#region 对象操作
static CronJob()
{
// 累加字段,生成 Update xx Set Count=Count+1234 Where xxx
//var df = Meta.Factory.AdditionalFields;
//df.Add(nameof(Kind));

// 过滤器 UserModule、TimeModule、IPModule
Meta.Modules.Add<UserModule>();
Meta.Modules.Add<TimeModule>();
Meta.Modules.Add<IPModule>();

// 单对象缓存
var sc = Meta.SingleCache;
sc.FindSlaveKeyMethod = k => Find(_.Name == k);
sc.GetSlaveKeyMethod = e => e.Name;
}

/// <summary>验证并修补数据,通过抛出异常的方式提示验证失败。</summary>
/// <param name="isNew">是否插入</param>
public override void Valid(Boolean isNew)
{
// 如果没有脏数据,则不需要进行任何处理
if (!HasDirty) return;
// 累加字段,生成 Update xx Set Count=Count+1234 Where xxx
//var df = Meta.Factory.AdditionalFields;
//df.Add(nameof(Kind));

// 过滤器 UserModule、TimeModule、IPModule
Meta.Modules.Add<UserModule>();
Meta.Modules.Add<TimeModule>();
Meta.Modules.Add<IPModule>();

// 单对象缓存
var sc = Meta.SingleCache;
sc.FindSlaveKeyMethod = k => Find(_.Name == k);
sc.GetSlaveKeyMethod = e => e.Name;
}

// 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
if (Name.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Name), "名称不能为空!");
/// <summary>验证并修补数据,通过抛出异常的方式提示验证失败。</summary>
/// <param name="isNew">是否插入</param>
public override void Valid(Boolean isNew)
{
// 如果没有脏数据,则不需要进行任何处理
if (!HasDirty) return;

// 建议先调用基类方法,基类方法会做一些统一处理
base.Valid(isNew);
}
// 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
if (Name.IsNullOrEmpty()) throw new ArgumentNullException(nameof(Name), "名称不能为空!");

/// <summary>已重载。优先显示名</summary>
/// <returns></returns>
public override String ToString() => !DisplayName.IsNullOrEmpty() ? DisplayName : Name;
#endregion
// 建议先调用基类方法,基类方法会做一些统一处理
base.Valid(isNew);
}

#region 扩展属性
#endregion
/// <summary>已重载。优先显示名</summary>
/// <returns></returns>
public override String ToString() => !DisplayName.IsNullOrEmpty() ? DisplayName : Name;
#endregion

#region 扩展查询
/// <summary>根据编号查找</summary>
/// <param name="id">编号</param>
/// <returns>实体对象</returns>
public static CronJob FindById(Int32 id)
{
if (id <= 0) return null;
#region 扩展属性
#endregion

// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id);
#region 扩展查询
/// <summary>根据编号查找</summary>
/// <param name="id">编号</param>
/// <returns>实体对象</returns>
public static CronJob FindById(Int32 id)
{
if (id <= 0) return null;

//// 单对象缓存
//return Meta.SingleCache[id];
// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Id == id);

return Find(_.Id == id);
}
//// 单对象缓存
//return Meta.SingleCache[id];

/// <summary>根据名称查找</summary>
/// <param name="name">名称</param>
/// <returns>实体对象</returns>
public static CronJob FindByName(String name)
{
// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Name.EqualIgnoreCase(name));

// 单对象缓存
//return Meta.SingleCache.GetItemWithSlaveKey(name) as CronJob;

return Find(_.Name == name);
}
#endregion

#region 高级查询
/// <summary>高级查询</summary>
/// <param name="name">名称</param>
/// <param name="start">更新时间开始</param>
/// <param name="end">更新时间结束</param>
/// <param name="key">关键字</param>
/// <param name="page">分页参数信息。可携带统计和数据权限扩展查询等信息</param>
/// <returns>实体列表</returns>
public static IList<CronJob> Search(String name, DateTime start, DateTime end, String key, PageParameter page)
{
var exp = new WhereExpression();

if (!name.IsNullOrEmpty()) exp &= _.Name == name;
exp &= _.UpdateTime.Between(start, end);
if (!key.IsNullOrEmpty()) exp &= _.DisplayName.Contains(key) | _.Method.Contains(key) | _.Argument.Contains(key) | _.Remark.Contains(key) | _.CreateIP.Contains(key) | _.UpdateIP.Contains(key);

return FindAll(exp, page);
}
#endregion

#region 业务操作
/// <summary>检查并添加定时作业</summary>
/// <param name="name">作业名称。唯一</param>
/// <param name="method">作业方法。定时执行</param>
/// <param name="cron">Cron表达式。仅用于首次创建,后续可通过页面修改</param>
/// <param name="enable">创建时是否启用。后续可通过页面修改</param>
/// <returns></returns>
public static CronJob Add(String name, MethodInfo method, String cron, Boolean enable = true)
return Find(_.Id == id);
}

/// <summary>根据名称查找</summary>
/// <param name="name">名称</param>
/// <returns>实体对象</returns>
public static CronJob FindByName(String name)
{
// 实体缓存
if (Meta.Session.Count < 1000) return Meta.Cache.Find(e => e.Name.EqualIgnoreCase(name));

// 单对象缓存
//return Meta.SingleCache.GetItemWithSlaveKey(name) as CronJob;

return Find(_.Name == name);
}
#endregion

#region 高级查询
/// <summary>高级查询</summary>
/// <param name="name">名称</param>
/// <param name="start">更新时间开始</param>
/// <param name="end">更新时间结束</param>
/// <param name="key">关键字</param>
/// <param name="page">分页参数信息。可携带统计和数据权限扩展查询等信息</param>
/// <returns>实体列表</returns>
public static IList<CronJob> Search(String name, DateTime start, DateTime end, String key, PageParameter page)
{
var exp = new WhereExpression();

if (!name.IsNullOrEmpty()) exp &= _.Name == name;
exp &= _.UpdateTime.Between(start, end);
if (!key.IsNullOrEmpty()) exp &= _.DisplayName.Contains(key) | _.Method.Contains(key) | _.Argument.Contains(key) | _.Remark.Contains(key) | _.CreateIP.Contains(key) | _.UpdateIP.Contains(key);

return FindAll(exp, page);
}
#endregion

#region 业务操作
/// <summary>检查并添加定时作业</summary>
/// <param name="name">作业名称。唯一</param>
/// <param name="method">作业方法。定时执行</param>
/// <param name="cron">Cron表达式。仅用于首次创建,后续可通过页面修改</param>
/// <param name="enable">创建时是否启用。后续可通过页面修改</param>
/// <returns></returns>
public static CronJob Add(String name, MethodInfo method, String cron, Boolean enable = true)
{
if (method == null || !method.IsStatic) throw new ArgumentOutOfRangeException(nameof(method), "定时作业执行方法必须是带有单个String参数的静态方法。");

if (name.IsNullOrEmpty()) name = method.Name;
var job = FindByName(name);
if (job != null) return job;

job = new CronJob
{
if (method == null || !method.IsStatic) throw new ArgumentOutOfRangeException(nameof(method), "定时作业执行方法必须是带有单个String参数的静态方法。");

if (name.IsNullOrEmpty()) name = method.Name;
var job = FindByName(name);
if (job != null) return job;

job = new CronJob
{
Name = name,
DisplayName = method.GetDisplayName(),
Method = $"{method.DeclaringType.FullName}.{method.Name}",
Cron = cron,
Enable = enable,
Remark = method.GetDescription(),
};

job.Insert();

return job;
}

/// <summary>检查并添加定时作业</summary>
/// <param name="name">作业名称。唯一</param>
/// <param name="action">作业回调</param>
/// <param name="cron">Cron表达式。仅用于首次创建,后续可通过页面修改</param>
/// <param name="enable">创建时是否启用。后续可通过页面修改</param>
/// <returns></returns>
public static CronJob Add(String name, Action<String> action, String cron, Boolean enable = true) => Add(name, action.Method, cron, enable);

///// <summary>添加定时作业</summary>
///// <param name="name"></param>
///// <param name="action"></param>
///// <param name="cron"></param>
///// <param name="enable"></param>
///// <returns></returns>
//public static CronJob Add(String name, Action<CronJob> action, String cron, Boolean enable = true) => Add(name, action.Method, cron, enable);
#endregion
Name = name,
DisplayName = method.GetDisplayName(),
Method = $"{method.DeclaringType.FullName}.{method.Name}",
Cron = cron,
Enable = enable,
Remark = method.GetDescription(),
};

job.Insert();

return job;
}

/// <summary>检查并添加定时作业</summary>
/// <param name="name">作业名称。唯一</param>
/// <param name="action">作业回调</param>
/// <param name="cron">Cron表达式。仅用于首次创建,后续可通过页面修改</param>
/// <param name="enable">创建时是否启用。后续可通过页面修改</param>
/// <returns></returns>
public static CronJob Add(String name, Action<String> action, String cron, Boolean enable = true) => Add(name, action.Method, cron, enable);

///// <summary>添加定时作业</summary>
///// <param name="name"></param>
///// <param name="action"></param>
///// <param name="cron"></param>
///// <param name="enable"></param>
///// <returns></returns>
//public static CronJob Add(String name, Action<CronJob> action, String cron, Boolean enable = true) => Add(name, action.Method, cron, enable);
#endregion
}
6 changes: 3 additions & 3 deletions NewLife.Cube/NewLife.Cube.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@
<Compile Include="..\NewLife.CubeNC\WebMiddleware\TenantMiddleware.cs" Link="WebMiddleware\TenantMiddleware.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NewLife.Core" Version="10.4.2023.707" />
<PackageReference Include="NewLife.Core" Version="10.5.2023.801" />
<PackageReference Include="NewLife.IP" Version="2.1.2023.704-beta0221" />
<PackageReference Include="NewLife.Stardust" Version="2.9.2023.707-beta0322" />
<PackageReference Include="NewLife.XCode" Version="11.8.2023.707-beta0320" />
<PackageReference Include="NewLife.Stardust" Version="2.9.2023.801" />
<PackageReference Include="NewLife.XCode" Version="11.9.2023.801" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 47f510d

Please sign in to comment.