diff --git a/HKLib/DB/DbContext.cs b/HKLib/DB/DbContext.cs new file mode 100644 index 0000000..7870807 --- /dev/null +++ b/HKLib/DB/DbContext.cs @@ -0,0 +1,41 @@ +using HKLib.DB.Model; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using XExten.Advance.StaticFramework; + +namespace HKLib.DB +{ + public class DbContext + { + public static SqlSugarScope Context = new SqlSugarScope(new ConnectionConfig() + { + ConnectionString = Route(), + DbType = DbType.Sqlite,//数据库类型 + IsAutoCloseConnection = true //不设成true要手动close + }, db => + { + db.Aop.OnLogExecuting = (sql, pars) => + { + + }; + }); + + static string Route() + { + var dir = SyncStatic.CreateDir(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Database")); + return SyncStatic.CreateFile(Path.Combine(dir, "data.db3")); + } + public static void InitTable() + { + var Tables = Assembly.GetAssembly(typeof(DbContext)) + .GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray(); + Context.CodeFirst.InitTables(Tables); + } + } +} diff --git a/HKLib/DB/Model/BaseEntity.cs b/HKLib/DB/Model/BaseEntity.cs new file mode 100644 index 0000000..3cd1a4a --- /dev/null +++ b/HKLib/DB/Model/BaseEntity.cs @@ -0,0 +1,20 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.DB.Model +{ + public class BaseEntity + { + [SugarColumn(IsPrimaryKey = true)] + public Guid Id { get; set; } + [SugarColumn(ColumnDataType = "DATETIME")] + public DateTime CreateTime { get; set; } + public void Create() + { + this.Id = Guid.NewGuid(); + this.CreateTime = DateTime.Now; + } + } +} diff --git a/HKLib/DB/Model/Entity/OrgTable.cs b/HKLib/DB/Model/Entity/OrgTable.cs new file mode 100644 index 0000000..7254c47 --- /dev/null +++ b/HKLib/DB/Model/Entity/OrgTable.cs @@ -0,0 +1,21 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.DB.Model.Entity +{ + [SugarTable("Org")] + public class OrgTable : BaseEntity + { + /// + /// 机构名称 + /// + public string Name { get; set; } + + /// + /// 加盟返回的Id + /// + public string SId { get; set; } + } +} diff --git a/HKLib/Dto/ReportDto.cs b/HKLib/Dto/ReportDto.cs index 60bb9eb..1d88b1c 100644 --- a/HKLib/Dto/ReportDto.cs +++ b/HKLib/Dto/ReportDto.cs @@ -18,13 +18,5 @@ namespace HKLib.Dto /// 姓名 /// public string Name { get; set; } - /// - /// 组织 - /// - public string Org { get; set; } - /// - /// 设备位置 - /// - public string Location { get; set; } } } diff --git a/HKLib/HKLib.csproj b/HKLib/HKLib.csproj index 3f18926..e6702eb 100644 --- a/HKLib/HKLib.csproj +++ b/HKLib/HKLib.csproj @@ -9,5 +9,6 @@ + diff --git a/HKLib/Interfaces/HKLibHelper.cs b/HKLib/Interfaces/HKLibHelper.cs index a5683f2..076fe3e 100644 --- a/HKLib/Interfaces/HKLibHelper.cs +++ b/HKLib/Interfaces/HKLibHelper.cs @@ -1,10 +1,10 @@ using HKLib.Dto; using HKLib.RabbitMQ.Config; using HKLib.RabbitMQ.Publisher; +using Newtonsoft.Json.Linq; using XExten.Advance.HttpFramework.MultiCommon; using XExten.Advance.HttpFramework.MultiFactory; using XExten.Advance.LinqFramework; -using static RabbitMQ.Client.Logging.RabbitMqClientEventSource; namespace HKLib.Interfaces { @@ -23,11 +23,36 @@ namespace HKLib.Interfaces }).Build().RunStringFirst(); } + /// + /// 添加机构 + /// + public static string SetOrg(string input) + { + return IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}/{input}"; + t.ReqType = MultiType.GET; + }).Build().RunStringFirst().ToModel()["data"].ToString(); + } + + /// + /// 修改机构 + /// + public static bool AlterOrg(string input,string Sid) + { + return IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}"; + t.ReqType = MultiType.POST; + t.JsonParam = (new { Name = input, Id = Sid }).ToJson(); + }).Build().RunStringFirst().ToModel()["isSuccess"].ToString().AsBool(); + } + /// /// 根据用户命获取下拉用户列表 /// /// - public static void GetUserList(string keyword) + public static void GetUserList(string keyword) { IHttpMultiClient.HttpMulti.AddNode(t => { @@ -52,7 +77,7 @@ namespace HKLib.Interfaces /// 变更卡状态 销户 /// /// - public static void CardStutasChange(CardStutasDto input) + public static void CardStutasChange(CardStutasDto input) { IHttpMultiClient.HttpMulti.AddNode(t => { @@ -66,7 +91,8 @@ namespace HKLib.Interfaces /// 报表数据 /// /// - public static void Report(ReportDto input) + /// 1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表 + public static void Report(ReportDto input,int type=1) { IHttpMultiClient.HttpMulti.AddNode(t => { diff --git a/HKLib/Logic/ServiceHandler.cs b/HKLib/Logic/ServiceHandler.cs new file mode 100644 index 0000000..83ac556 --- /dev/null +++ b/HKLib/Logic/ServiceHandler.cs @@ -0,0 +1,35 @@ +using HKLib.DB; +using HKLib.DB.Model.Entity; +using HKLib.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.Logic +{ + public class ServiceHandler + { + #region 机构类 + public static bool AddOrg(string Name) + { + var SiD = HKLibHelper.SetOrg(Name); + return DbContext.Context.Insertable(new OrgTable + { + Name = Name, + SId = SiD + }).CallEntityMethod(t => t.Create()).ExecuteCommand() > 0; + } + public static List GetOrgList() + { + return DbContext.Context.Queryable().ToList(); + } + public static bool AlterOrg(string Name, string Id) + { + var s = HKLibHelper.AlterOrg(Name, Id); + if (s) + return DbContext.Context.Updateable().SetColumns(t => t.Name == Name).Where(t => t.SId == Id).ExecuteCommandHasChange(); + else return false; + } + #endregion + } +}