From 9fbb4ad5d92a715de93cdf1421a465c35ebf1d90 Mon Sep 17 00:00:00 2001 From: "nodyang@aliyun.com" Date: Tue, 8 Oct 2024 10:55:21 +0800 Subject: [PATCH] =?UTF-8?q?Db=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB/DB.csproj | 5 +++- DB/DbFactory.cs | 2 +- DB/Entity/Log.cs | 24 ++++++++++++++++++ DB/Entity/Point.cs | 27 ++++++++++++++++++++ DB/Entity/Role.cs | 19 ++++++++++++++ DB/Entity/User.cs | 17 +++++++++++++ DB/SystemEntityTypeBuilder.cs | 12 +++++---- RfidWeb/Form1.Designer.cs | 24 +++++++++++++----- RfidWeb/Form1.cs | 47 +++++++++++++++++++++++++++++------ Tool/RfidSetting.cs | 2 +- Tool/SnowflakeFactory.cs | 11 ++++++++ Tool/Tool.csproj | 1 + 12 files changed, 170 insertions(+), 21 deletions(-) create mode 100644 DB/Entity/Log.cs create mode 100644 DB/Entity/Point.cs create mode 100644 DB/Entity/Role.cs create mode 100644 DB/Entity/User.cs create mode 100644 Tool/SnowflakeFactory.cs diff --git a/DB/DB.csproj b/DB/DB.csproj index 21ca4ec..870410d 100644 --- a/DB/DB.csproj +++ b/DB/DB.csproj @@ -101,11 +101,14 @@ + + + + - {a49bc7e3-39b7-4f68-8780-fb4da3461aff} diff --git a/DB/DbFactory.cs b/DB/DbFactory.cs index 30a66fa..fdc72ff 100644 --- a/DB/DbFactory.cs +++ b/DB/DbFactory.cs @@ -23,7 +23,7 @@ namespace DB return conn; }); - context.Options.ConvertToLowercase = false; + context.Options.ConvertToLowercase = true; return context; } } diff --git a/DB/Entity/Log.cs b/DB/Entity/Log.cs new file mode 100644 index 0000000..5b05b58 --- /dev/null +++ b/DB/Entity/Log.cs @@ -0,0 +1,24 @@ +namespace DB.Entity +{ + public class Log:BaseChimsDb + { + public string LogLevel { get; set; } + public string Msg { get; set; } + + + /// + /// 1到100 系统功能日志 + /// 400 系统错误日志 + /// + /// + public short LogType { get; set; } + } + + public class LogMapper : SystemEntityTypeBuilder + { + public LogMapper() : base("Log") + { + + } + } +} \ No newline at end of file diff --git a/DB/Entity/Point.cs b/DB/Entity/Point.cs new file mode 100644 index 0000000..7150e64 --- /dev/null +++ b/DB/Entity/Point.cs @@ -0,0 +1,27 @@ +namespace DB.Entity +{ + public class Point:BaseChimsDb + { + /// + /// plc 点位名称 + /// + public string PointName { get; set; } + /// + /// plc 点位地址 + /// + public string PointAddress { get; set; } + /// + /// plc 数据类型 bool float int bit + /// + public string DataType { get; set; } + } + + + public class PointMapper : SystemEntityTypeBuilder + { + public PointMapper() : base("Point") + { + + } + } +} \ No newline at end of file diff --git a/DB/Entity/Role.cs b/DB/Entity/Role.cs new file mode 100644 index 0000000..39f55c6 --- /dev/null +++ b/DB/Entity/Role.cs @@ -0,0 +1,19 @@ +namespace DB.Entity +{ + public class Role:BaseChimsDb + { + public string RoleName { get; set; } + + public short RoleLevel { get; set; } + + + } + + public class RoleMapper : SystemEntityTypeBuilder + { + public RoleMapper() : base("role") + { + + } + } +} \ No newline at end of file diff --git a/DB/Entity/User.cs b/DB/Entity/User.cs new file mode 100644 index 0000000..71d3dc2 --- /dev/null +++ b/DB/Entity/User.cs @@ -0,0 +1,17 @@ +namespace DB.Entity +{ + public class User:BaseChimsDb + { + public string UserName { get; set; } + public string Pwd { get; set; } + public long RoleId { get; set; } + } + + public class UserMapper : SystemEntityTypeBuilder + { + public UserMapper() : base("user") + { + + } + } +} \ No newline at end of file diff --git a/DB/SystemEntityTypeBuilder.cs b/DB/SystemEntityTypeBuilder.cs index 5d3dac6..b476c75 100644 --- a/DB/SystemEntityTypeBuilder.cs +++ b/DB/SystemEntityTypeBuilder.cs @@ -34,11 +34,11 @@ namespace DB /// /// - public int IsEnable { get; set; } = 1; + public short IsEnable { get; set; } = 1; /// /// - public int IsDelete { get; set; } = 0; + public short IsDelete { get; set; } = 0; @@ -50,25 +50,27 @@ namespace DB /// /// [UpdateIgnore] + public string CreateUserId { get; set; } = ""; /// /// [UpdateIgnore] + public string CreateUserName { get; set; } = ""; /// /// public DateTime LastModifyDate { get; set; } = DateTime.Now; - + /// /// public string LastModifyUserId { get; set; } = ""; - + /// /// public string LastModifyUserName { get; set; } = ""; - public int SortCode { get; set; } = 0; + } } diff --git a/RfidWeb/Form1.Designer.cs b/RfidWeb/Form1.Designer.cs index 4122500..3088e88 100644 --- a/RfidWeb/Form1.Designer.cs +++ b/RfidWeb/Form1.Designer.cs @@ -23,25 +23,37 @@ #region Windows 窗体设计器生成的代码 /// - /// 设计器支持所需的方法 - 不要修改 - /// 使用代码编辑器修改此方法的内容。 + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. /// private void InitializeComponent() { + this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // + // button1 + // + this.button1.Location = new System.Drawing.Point(662, 241); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(137, 97); + this.button1.TabIndex = 0; + this.button1.Text = "初始化数据库"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1180, 553); - this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.ClientSize = new System.Drawing.Size(1770, 830); + this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); - } + private System.Windows.Forms.Button button1; + #endregion } } diff --git a/RfidWeb/Form1.cs b/RfidWeb/Form1.cs index 9465715..89a319c 100644 --- a/RfidWeb/Form1.cs +++ b/RfidWeb/Form1.cs @@ -9,7 +9,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; - +using Chloe.PostgreSQL.DDL; +using Chloe.RDBMS.DDL; +using DB; +using DB.Entity; +using NewLife.Data; +using NewLife.Log; using Tool; namespace RfidWeb @@ -21,21 +26,49 @@ namespace RfidWeb public Form1() { - + + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true); InitializeComponent(); + + // 如果所有的日志在记录之前需要在控制台显示出来 + logNet.BeforeSaveToFile += (object sender, HslEventArgs e) => + { + Console.WriteLine(e.HslMessage.ToString()); + }; logNet.ConsoleOutput = true; logNet.WriteInfo("nihao"); + + } + private void button1_Click(object sender, EventArgs e) + { + DbInfo.Init(typeof(RoleMapper).Assembly); - // 如果所有的日志在记录之前需要在控制台显示出来 - logNet.BeforeSaveToFile += (object sender, HslEventArgs e) => - { - Console.WriteLine(e.HslMessage.ToString()); - }; + var dbContext = DbFactory.GetContext; + new PostgreSQLTableGenerator(dbContext).CreateTables(TableCreateMode.CreateNew); + dbContext.Insert(new Role() + { + ID = SnowflakeFactory.NewId, + RoleName = "管理层", + RoleLevel = 1 + }); + dbContext.Insert(new Role() + { + ID = SnowflakeFactory.NewId, + RoleName = "设备层", + RoleLevel = 2 + }); + dbContext.Insert(new Role() + { + ID = SnowflakeFactory.NewId, + RoleName = "使用层", + RoleLevel = 3 + }); } } } diff --git a/Tool/RfidSetting.cs b/Tool/RfidSetting.cs index 5ebb114..7cf8d66 100644 --- a/Tool/RfidSetting.cs +++ b/Tool/RfidSetting.cs @@ -13,7 +13,7 @@ namespace Tool [Config("Core")] public class RfidSetting : Config { - public string Db { get; set; } = "server=127.0.0.1;database=postgres;uid=postgres;pwd=yangwei"; + public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456"; public string PlcIp { get; set; } = "127.0.0.1"; diff --git a/Tool/SnowflakeFactory.cs b/Tool/SnowflakeFactory.cs new file mode 100644 index 0000000..88e2b35 --- /dev/null +++ b/Tool/SnowflakeFactory.cs @@ -0,0 +1,11 @@ +using NewLife.Data; + +namespace Tool +{ + public class SnowflakeFactory + { + private static readonly Snowflake GetInstance = new Snowflake(); + + public static long NewId => GetInstance.NewId(); + } +} \ No newline at end of file diff --git a/Tool/Tool.csproj b/Tool/Tool.csproj index db2e9c4..3a608c8 100644 --- a/Tool/Tool.csproj +++ b/Tool/Tool.csproj @@ -64,6 +64,7 @@ +