应用配置和应用历史页面

This commit is contained in:
大石头 2020-01-11 15:54:28 +08:00
parent de8a4a03bd
commit cc6a92619d
7 changed files with 120 additions and 35 deletions

View File

@ -4,8 +4,6 @@ using AntJob.Handlers;
using AntJob.Providers;
using NewLife;
using NewLife.Agent;
using NewLife.Remoting;
using NewLife.Threading;
namespace AntJob.Agent
{

View File

@ -1,25 +1,10 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Xml.Serialization;
using NewLife;
using NewLife.Data;
using NewLife.Log;
using NewLife.Model;
using NewLife.Reflection;
using NewLife.Threading;
using NewLife.Web;
using XCode;
using XCode.Cache;
using XCode.Configuration;
using XCode.DataAccessLayer;
using XCode.Membership;
namespace AntJob.Data.Entity
@ -108,14 +93,14 @@ namespace AntJob.Data.Entity
/// <summary>设备编号</summary>
[XmlIgnore, IgnoreDataMember]
//[ScriptIgnore]
public App App { get { return Extends.Get(nameof(App), k => App.FindByID(AppID)); } }
public App App => Extends.Get(nameof(App), k => App.FindByID(AppID));
/// <summary>设备编号</summary>
[XmlIgnore, IgnoreDataMember]
//[ScriptIgnore]
[DisplayName("设备编号")]
[Map(__.AppID, typeof(App), "ID")]
public String AppName { get { return App?.Name; } }
public String AppName => App?.Name;
#endregion
#region
@ -149,6 +134,23 @@ namespace AntJob.Data.Entity
#endregion
#region
/// <summary>高级查询</summary>
/// <param name="appid"></param>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="key"></param>
/// <param name="p"></param>
/// <returns></returns>
public static IEnumerable<AppConfig> Search(Int32 appid, DateTime start, DateTime end, String key, PageParameter p)
{
var exp = new WhereExpression();
if (appid > 0) exp &= _.AppID == appid.ToInt();
if (!key.IsNullOrEmpty()) exp &= _.Name.Contains(key);
exp &= _.CreateTime.Between(start, end);
return FindAll(exp, p);
}
#endregion
#region

View File

@ -26,11 +26,11 @@ namespace AntJob.Data.Entity
public Int32 ID { get { return _ID; } set { if (OnPropertyChanging(__.ID, value)) { _ID = value; OnPropertyChanged(__.ID); } } }
private Int32 _AppID;
/// <summary>设备编号</summary>
[DisplayName("设备编号")]
[Description("设备编号")]
/// <summary>应用</summary>
[DisplayName("应用")]
[Description("应用")]
[DataObjectField(false, false, false, 0)]
[BindColumn("AppID", "设备编号", "")]
[BindColumn("AppID", "应用", "")]
public Int32 AppID { get { return _AppID; } set { if (OnPropertyChanging(__.AppID, value)) { _AppID = value; OnPropertyChanged(__.AppID); } } }
private String _Name;
@ -148,7 +148,7 @@ namespace AntJob.Data.Entity
/// <summary>编号</summary>
public static readonly Field ID = FindByName(__.ID);
/// <summary>设备编号</summary>
/// <summary>应用</summary>
public static readonly Field AppID = FindByName(__.AppID);
/// <summary>名称</summary>
@ -184,7 +184,7 @@ namespace AntJob.Data.Entity
/// <summary>编号</summary>
public const String ID = "ID";
/// <summary>设备编号</summary>
/// <summary>应用</summary>
public const String AppID = "AppID";
/// <summary>名称</summary>
@ -221,7 +221,7 @@ namespace AntJob.Data.Entity
/// <summary>编号</summary>
Int32 ID { get; set; }
/// <summary>设备编号</summary>
/// <summary>应用</summary>
Int32 AppID { get; set; }
/// <summary>名称</summary>

View File

@ -76,7 +76,7 @@
<Table Name="AppConfig" Description="应用配置。各应用的配置数据">
<Columns>
<Column Name="ID" DataType="Int32" Identity="True" PrimaryKey="True" Description="编号" />
<Column Name="AppID" DataType="Int32" Description="设备编号" />
<Column Name="AppID" DataType="Int32" Description="应用" />
<Column Name="Name" DataType="String" Master="True" Description="名称" />
<Column Name="Content" DataType="String" Length="5000" Description="内容。一般是json格式" />
<Column Name="CreateUserID" DataType="Int32" Description="创建者" />

View File

@ -9,6 +9,7 @@ using NewLife.Data;
using NewLife.Log;
using NewLife.Net;
using NewLife.Remoting;
using NewLife.Security;
using NewLife.Serialization;
using NewLife.Threading;
using XCode;
@ -63,7 +64,9 @@ namespace AntJob.Server
if (!app.Enable) throw new Exception("已禁用!");
// 核对密码
if (!app.Secret.IsNullOrEmpty())
if (app.Secret.IsNullOrEmpty())
app.Secret = Rand.NextString(16);
else
{
var pass2 = app.Secret.MD5();
if (pass != pass2) throw new Exception("密码错误!");
@ -73,6 +76,8 @@ namespace AntJob.Server
if (app.Version.IsNullOrEmpty() || app.Version.CompareTo(ver) < 0) app.Version = ver;
if (app.CompileTime < compile) app.CompileTime = compile;
var autoReg = app.ID == 0;
app.Save();
// 应用上线
@ -84,13 +89,21 @@ namespace AntJob.Server
// 记录当前用户
Session["App"] = app;
WriteHistory("登录", true, $"[{user}/{pass}]登录[{app}]成功");
WriteHistory("登录", true, $"[{user}/{pass}]在[{machine}@{pid}]登录[{app}]成功");
return new
{
app.Name,
app.DisplayName,
};
if (autoReg)
return new
{
app.Name,
app.Secret,
app.DisplayName,
};
else
return new
{
app.Name,
app.DisplayName,
};
}
protected virtual App CheckApp(App app, String user, String pass, String ip)
@ -154,6 +167,8 @@ namespace AntJob.Server
XTrace.Log.Error(ex.Message);
else
XTrace.WriteException(ex);
WriteHistory(filterContext.ActionName, false, ex.GetMessage());
}
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using AntJob.Data.Entity;
using NewLife.Cube;
using NewLife.Web;
namespace AntJob.Web.Areas.Ant.Controllers
{
/// <summary>应用配置</summary>
[AntArea]
[DisplayName("应用配置")]
public class AppConfigController : EntityController<AppConfig>
{
static AppConfigController()
{
MenuOrder = 83;
AppConfig.Meta.Table.DataTable.InsertOnly = true;
}
/// <summary>搜索数据集</summary>
/// <param name="p"></param>
/// <returns></returns>
protected override IEnumerable<AppConfig> Search(Pager p)
{
var appid = p["appid"].ToInt(-1);
var start = p["dtStart"].ToDateTime();
var end = p["dtEnd"].ToDateTime();
return AppConfig.Search(appid, start, end, p["q"], p);
}
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using AntJob.Data.Entity;
using NewLife.Cube;
using NewLife.Web;
namespace AntJob.Web.Areas.Ant.Controllers
{
/// <summary>应用历史</summary>
[AntArea]
[DisplayName("应用历史")]
public class AppHistoryController : EntityController<AppHistory>
{
static AppHistoryController()
{
MenuOrder = 85;
AppOnline.Meta.Table.DataTable.InsertOnly = true;
}
/// <summary>搜索数据集</summary>
/// <param name="p"></param>
/// <returns></returns>
protected override IEnumerable<AppHistory> Search(Pager p)
{
var appid = p["appid"].ToInt(-1);
var act = p["action"];
var success = p["success"]?.ToBoolean();
var start = p["dtStart"].ToDateTime();
var end = p["dtEnd"].ToDateTime();
return AppHistory.Search(appid, act, success, start, end, p["q"], p);
}
}
}