pry преди 2 години
родител
ревизия
3a3d36aa97
променени са 28 файла, в които са добавени 885 реда и са изтрити 74 реда
  1. +10
    -8
      HKCard.sln
  2. +1
    -1
      HKCardIN/HKCardIN.csproj
  3. +4
    -2
      HKCardOUT/Bootstrapper.cs
  4. +1
    -0
      HKCardOUT/HKCardOUT.csproj
  5. +23
    -0
      HKCardOUT/Logic/Model/CardStutas.cs
  6. +3
    -4
      HKCardOUT/Logic/RemoteService.cs
  7. +68
    -55
      HKCardOUT/Logic/Service/HKCore.cs
  8. +22
    -0
      HKCardOUT/MqHandle.cs
  9. +6
    -4
      HKCardOUT/options.json
  10. +12
    -0
      HKLib/Configer.cs
  11. +41
    -0
      HKLib/DB/DbContext.cs
  12. +20
    -0
      HKLib/DB/Model/BaseEntity.cs
  13. +21
    -0
      HKLib/DB/Model/Entity/OrgTable.cs
  14. +18
    -0
      HKLib/Dto/CardStutasDto.cs
  15. +22
    -0
      HKLib/Dto/ReportDto.cs
  16. +22
    -0
      HKLib/Dto/TimeSpilte.cs
  17. +30
    -0
      HKLib/Dto/UserDto.cs
  18. +14
    -0
      HKLib/HKLib.csproj
  19. +105
    -0
      HKLib/Interfaces/HKLibHelper.cs
  20. +35
    -0
      HKLib/Logic/ServiceHandler.cs
  21. +28
    -0
      HKLib/RabbitMq/Config/AcceptEntity.cs
  22. +13
    -0
      HKLib/RabbitMq/Config/IAccept.cs
  23. +26
    -0
      HKLib/RabbitMq/Config/MQEnum.cs
  24. +117
    -0
      HKLib/RabbitMq/Config/MQFactory.cs
  25. +26
    -0
      HKLib/RabbitMq/Config/PushEntity.cs
  26. +81
    -0
      HKLib/RabbitMq/Config/PushManage.cs
  27. +74
    -0
      HKLib/RabbitMq/Publisher/ServiceQueryPush.cs
  28. +42
    -0
      HKLib/RabbitMq/Subscriber/ServiceQueryExcute.cs

+ 10
- 8
HKCard.sln Целия файл

@@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UHFHelper", "UHFHelper\UHFH
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test\test.csproj", "{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HKLib", "HKLib\HKLib.csproj", "{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HKCardManager", "HKCardManager\HKCardManager.csproj", "{96C17249-7F4A-4D25-B658-507A8E876582}"
EndProject
Global
@@ -83,14 +85,14 @@ Global
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|Any CPU.Build.0 = Release|Any CPU
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|x86.ActiveCfg = Release|x86
{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|x86.Build.0 = Release|x86
{96C17249-7F4A-4D25-B658-507A8E876582}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Debug|x86.ActiveCfg = Debug|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Debug|x86.Build.0 = Debug|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Release|Any CPU.ActiveCfg = Release|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Release|Any CPU.Build.0 = Release|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Release|x86.ActiveCfg = Release|Any CPU
{96C17249-7F4A-4D25-B658-507A8E876582}.Release|x86.Build.0 = Release|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|x86.ActiveCfg = Debug|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|x86.Build.0 = Debug|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|Any CPU.Build.0 = Release|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|x86.ActiveCfg = Release|Any CPU
{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


+ 1
- 1
HKCardIN/HKCardIN.csproj Целия файл

@@ -32,10 +32,10 @@
<ItemGroup>
<PackageReference Include="HandyControls" Version="3.4.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Stylet" Version="1.3.6" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HKLog\HKLog.csproj" />


+ 4
- 2
HKCardOUT/Bootstrapper.cs Целия файл

@@ -31,9 +31,9 @@ namespace HKCardOUT
bool ping = PingHelper.PingTest();
//1.检测网络上下线
bool network = HKHelpers.GetInstance().GetNetworkState();
if (ping&& network!= DataBus.NetWordState)
if (ping && network != DataBus.NetWordState)
{
DataBus.NetWordState = network&& ping;
DataBus.NetWordState = network && ping;
if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功");
else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!");
}
@@ -69,6 +69,8 @@ namespace HKCardOUT
DataBus.PM = configer["PM"];
DataBus.Count = configer["Count"].AsInt();
DataBus.AT = configer["AT"];
HKLib.Configer.SaasRoute = DataBus.SaasRoute;
HKLib.Configer.MqAddress = configer["MQ"];
DbContext.InitTable();
RemoteService.PullShopInfo();
base.Configure();


+ 1
- 0
HKCardOUT/HKCardOUT.csproj Целия файл

@@ -53,6 +53,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HKControl\HKControl.csproj" />
<ProjectReference Include="..\HKLib\HKLib.csproj" />
<ProjectReference Include="..\HKLog\HKLog.csproj" />
<ProjectReference Include="..\UHFHelper\UHFHelper.csproj" />
</ItemGroup>


+ 23
- 0
HKCardOUT/Logic/Model/CardStutas.cs Целия файл

@@ -0,0 +1,23 @@
using HKCardOUT.Logic;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;

namespace Logic.Model
{
[SugarTable("CardStutas")]
public class CardStutas: BaseEntity
{
/// <summary>
/// 卡号
/// </summary>
[SugarColumn(IsNullable = false)]
public string CardNo { get; set; }
/// <summary>
/// 卡状态 0.禁用 1.正常 2.挂失 3.作废
/// </summary>
[SugarColumn(IsNullable = false)]
public int Stutas { get; set; }
}
}

+ 3
- 4
HKCardOUT/Logic/RemoteService.cs Целия файл

@@ -19,16 +19,15 @@ namespace HKCardOUT.Logic
public class RemoteService
{
/// <summary>
/// 判断卡状态
/// 获取所有卡状态和卡号
/// </summary>
/// <param name="input"></param>
public static int CheckCardStuatas(string CardNo)
public static int CheckCardStuatas()
{
var data = IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = ApiRoute.CheckCardStatus;
t.ReqType = MultiType.POST;
t.JsonParam = (new { cardNum = CardNo }).ToJson();
t.ReqType = MultiType.GET;
}).Build().RunStringFirst().ToModel<JObject>()["data"]["cardState"];
return data != null ? data.ToString().AsInt() : 0;
}


+ 68
- 55
HKCardOUT/Logic/Service/HKCore.cs Целия файл

@@ -2,6 +2,7 @@
using HKCardOUT.Helper;
using HKCardOUT.Logic.Model;
using HKControl;
using Logic.Model;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -27,6 +28,14 @@ namespace HKCardOUT.Logic.Service
if (Old.Count > 3) return null;
return Old;
}

bool GetCardStutas(string CardNo)
{
var data = DbContext.Context.Queryable<CardStutas>().First(t => t.CardNo == CardNo);
if (data == null) return false;
if (data.Stutas != 1) return false;
return true;
}
/// <summary>
/// 早上消费
/// </summary>
@@ -37,6 +46,7 @@ namespace HKCardOUT.Logic.Service
{
try
{
if(!GetCardStutas(input.CardNo)) return false;
var Old = Commom(input);
if (Old == null) return false;
var AM = DataBus.AM.Split(",").Select(t => t.AsInt()).ToList();
@@ -52,29 +62,30 @@ namespace HKCardOUT.Logic.Service
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
if (entity.Id != Guid.Empty)
{
//有网络直接同步
if (DataBus.NetWordState)
{
//先出餐后推数据
if (DataBus.StartDevice)
{
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
}
else
////有网络直接同步
//if (DataBus.NetWordState)
//{
// //先出餐后推数据
// if (DataBus.StartDevice)
// {
// Main.GetInstance.Start(input.Location.AsInt());
// UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
// }
// var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
// if (res)
// DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
// return res;
//}
//else
//{

//}
if (DataBus.StartDevice)
{
if (DataBus.StartDevice)
{
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
return true;
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
return true;
}
}
return false;
@@ -96,6 +107,7 @@ namespace HKCardOUT.Logic.Service
{
try
{
if (!GetCardStutas(input.CardNo)) return false;
var Old = Commom(input);
if (Old == null) return false;
var PM = DataBus.PM.Split(",").Select(t => t.AsInt()).ToList();
@@ -110,29 +122,29 @@ namespace HKCardOUT.Logic.Service
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
if (entity.Id != Guid.Empty)
{
//有网络直接同步
if (DataBus.NetWordState)
{
//先出餐后推数据
if (DataBus.StartDevice)
{
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
}
else
{
////有网络直接同步
//if (DataBus.NetWordState)
//{
// //先出餐后推数据
// if (DataBus.StartDevice)
// {
// Main.GetInstance.Start(input.Location.AsInt());
// UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
// }
// var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
// if (res)
// DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
// return res;
//}
//else
//{
if (DataBus.StartDevice)
{
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
return true;
}
//}
}
}
return false;
@@ -154,6 +166,7 @@ namespace HKCardOUT.Logic.Service
{
try
{
if (!GetCardStutas(input.CardNo)) return false;
var Old = Commom(input);
if (Old == null) return false;
var AT = DataBus.AT.Split(",").Select(t => t.AsInt()).ToList();
@@ -168,29 +181,29 @@ namespace HKCardOUT.Logic.Service
var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
if (entity.Id != Guid.Empty)
{
//有网络直接同步
if (DataBus.NetWordState)
{
//先出餐后推数据
if (DataBus.StartDevice)
{
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
if (res)
DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
return res;
}
else
{
////有网络直接同步
//if (DataBus.NetWordState)
//{
// //先出餐后推数据
// if (DataBus.StartDevice)
// {
// Main.GetInstance.Start(input.Location.AsInt());
// UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
// }
// var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
// if (res)
// DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
// return res;
//}
//else
//{
if (DataBus.StartDevice)
{
Main.GetInstance.Start(input.Location.AsInt());
UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
}
return true;
}
//}
}
}
return false;


+ 22
- 0
HKCardOUT/MqHandle.cs Целия файл

@@ -0,0 +1,22 @@
using HKCardOUT.Logic;
using HKLib.Dto;
using HKLib.RabbitMQ.Config;
using Logic.Model;
using System;
using System.Collections.Generic;
using System.Text;
using XExten.Advance.LinqFramework;

namespace HKCardOUT
{
public class MqHandle : IAccept
{
public void AcceptMQ<T>(string msg)
{
var dto = msg.ToModel<CardStutasDto>();

DbContext.Context.Updateable<CardStutas>().SetColumns(t => t.Stutas == dto.Stutas).Where(t => t.CardNo == dto.CardNo).ExecuteCommand();

}
}
}

+ 6
- 4
HKCardOUT/options.json Целия файл

@@ -1,7 +1,7 @@
{
//服务地址
"SaasRoute": "https://bpa.black-pa.com:21527/kitchen/",
//启动设备调试
//启动设备调试
"StartDevice": true,
//串口
"COM": "COM3",
@@ -19,8 +19,10 @@
"PM": "11,14",
//下午
"AT": "17,20",
//每个时间段的刷卡次数
"Count":1,
//每个时间段的刷卡次数
"Count": 1,
//取消单卡刷卡限制
"Cancel":false
"Cancel": false,
//MQ地址
"MQ": "host=10.2.1.21:5672;username=guest;password=guest"
}

+ 12
- 0
HKLib/Configer.cs Целия файл

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace HKLib
{
public class Configer
{
public static string MqAddress { get; set; }
public static string SaasRoute { get; set; }
}
}

+ 41
- 0
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);
}
}
}

+ 20
- 0
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;
}
}
}

+ 21
- 0
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
{
/// <summary>
/// 机构名称
/// </summary>
public string Name { get; set; }

/// <summary>
/// 加盟返回的Id
/// </summary>
public string SId { get; set; }
}
}

+ 18
- 0
HKLib/Dto/CardStutasDto.cs Целия файл

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace HKLib.Dto
{
public class CardStutasDto
{
/// <summary>
/// 卡号
/// </summary>
public string CardNo { get; set; }
/// <summary>
/// 状态 0.禁用 1.正常 2.挂失 3.作废
/// </summary>
public int Stutas { get; set; }
}
}

+ 22
- 0
HKLib/Dto/ReportDto.cs Целия файл

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace HKLib.Dto
{
public class ReportDto
{
/// <summary>
/// 开始时间
/// </summary>
public DateTime STime { get; set; }
/// <summary>
/// 结束时间
/// </summary>
public DateTime ETime { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string Name { get; set; }
}
}

+ 22
- 0
HKLib/Dto/TimeSpilte.cs Целия файл

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace HKLib.Dto
{
public class TimeSpilte
{
/// <summary>
/// 早 例如 8,10
/// </summary>
public string AM { get; set; }
/// <summary>
/// 中 例如 11,13
/// </summary>
public string PM { get; set; }
/// <summary>
/// 晚 例如 17,19
/// </summary>
public string AT { get; set; }
}
}

+ 30
- 0
HKLib/Dto/UserDto.cs Целия файл

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace HKLib.Dto
{
public class UserDto
{
/// <summary>
/// 机构
/// </summary>
public string Org { get; set; }
/// <summary>
/// 姓名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string Phone { get; set; }
/// <summary>
/// 卡号
/// </summary>
public string CardNo { get; set; }
/// <summary>
/// 身份证号
/// </summary>
public string IdCard { get; set; }
}
}

+ 14
- 0
HKLib/HKLib.csproj Целия файл

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyNetQ" Version="6.5.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Snowflake.Core" Version="2.0.0" />
<PackageReference Include="XExten.Advance" Version="1.2.4.2-preview" />
<PackageReference Include="SqlSugarCore" Version="5.1.2.7" />
</ItemGroup>
</Project>

+ 105
- 0
HKLib/Interfaces/HKLibHelper.cs Целия файл

@@ -0,0 +1,105 @@
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;

namespace HKLib.Interfaces
{
public class HKLibHelper
{
/// <summary>
/// 设置刷卡时间端
/// </summary>
public static void SetTime(TimeSpilte input)
{
IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = $"{Configer.SaasRoute}";
t.JsonParam = input.ToJson();
t.ReqType = MultiType.POST;
}).Build().RunStringFirst();
}

/// <summary>
/// 添加机构
/// </summary>
public static string SetOrg(string input)
{
return IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = $"{Configer.SaasRoute}/{input}";
t.ReqType = MultiType.GET;
}).Build().RunStringFirst().ToModel<JObject>()["data"].ToString();
}

/// <summary>
/// 修改机构
/// </summary>
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<JObject>()["isSuccess"].ToString().AsBool();
}

/// <summary>
/// 根据用户命获取下拉用户列表
/// </summary>
/// <param name="keyword"></param>
public static void GetUserList(string keyword)
{
IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = $"{Configer.SaasRoute}/{keyword}";
t.ReqType = MultiType.GET;
}).Build().RunStringFirst();
}
/// <summary>
/// 添加用户
/// </summary>
/// <param name="input"></param>
public static void AddUser(UserDto input)
{
IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = $"{Configer.SaasRoute}";
t.ReqType = MultiType.POST;
t.JsonParam = input.ToJson();
}).Build().RunStringFirst();
}
/// <summary>
/// 变更卡状态 销户
/// </summary>
/// <param name="input"></param>
public static void CardStutasChange(CardStutasDto input)
{
IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = $"{Configer.SaasRoute}";
t.ReqType = MultiType.POST;
t.JsonParam = input.ToJson();
}).Build().RunStringFirst();
ServiceQueryPush.QueryPush.PushMQ(input, "CardStutasChanged", MQEnum.Top);
}
/// <summary>
/// 报表数据
/// </summary>
/// <param name="input"></param>
/// <param name="type">1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表</param>
public static void Report(ReportDto input,int type=1)
{
IHttpMultiClient.HttpMulti.AddNode(t =>
{
t.NodePath = $"{Configer.SaasRoute}";
t.ReqType = MultiType.POST;
t.JsonParam = input.ToJson();
}).Build().RunStringFirst();
}
}
}

+ 35
- 0
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<OrgTable> GetOrgList()
{
return DbContext.Context.Queryable<OrgTable>().ToList();
}
public static bool AlterOrg(string Name, string Id)
{
var s = HKLibHelper.AlterOrg(Name, Id);
if (s)
return DbContext.Context.Updateable<OrgTable>().SetColumns(t => t.Name == Name).Where(t => t.SId == Id).ExecuteCommandHasChange();
else return false;
}
#endregion
}
}

+ 28
- 0
HKLib/RabbitMq/Config/AcceptEntity.cs Целия файл

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HKLib.RabbitMQ.Config
{
public class AcceptEntity
{
/// <summary>
/// 队列名称
/// </summary>
public String QueeName { get; set; }
/// <summary>
/// 推送模式
/// </summary>
public MQEnum SendType { get; set; }
/// <summary>
/// 管道名称
/// </summary>
public String ExchangeName { get; set; }
/// <summary>
/// 路由名称
/// </summary>
public String RouteName { get; set; }
}
}

+ 13
- 0
HKLib/RabbitMq/Config/IAccept.cs Целия файл

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HKLib.RabbitMQ.Config
{
public interface IAccept
{
void AcceptMQ<T>(string msg);
}
}

+ 26
- 0
HKLib/RabbitMq/Config/MQEnum.cs Целия файл

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;

namespace HKLib.RabbitMQ.Config
{
public enum MQEnum
{
/// <summary>
/// 订阅模式
/// </summary>
[Description("订阅模式")]
Sub = 10,
/// <summary>
/// 推送模式
/// </summary>
[Description("推送模式")]
Push = 20,
/// <summary>
/// 主路由模式
/// </summary>
[Description("主路由模式")]
Top = 30
}
}

+ 117
- 0
HKLib/RabbitMq/Config/MQFactory.cs Целия файл

@@ -0,0 +1,117 @@
using EasyNetQ;
using EasyNetQ.Topology;
using HKLib.DataBus.数据缓存;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace HKLib.RabbitMQ.Config
{
public class MQFactory
{
private volatile static IBus Bus = null;
/// <summary>
/// 创建链接
/// </summary>
/// <returns></returns>
public static IBus CreateMQ()
{
if (Bus == null)
Bus = RabbitHutch.CreateBus(Configer.MqAddress);
return Bus;
}
/// <summary>
/// 释放链接
/// </summary>
public static void DisposeBus()
{
Bus?.Dispose();
}
/// <summary>
/// 同步执行
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Param"></param>
/// <returns></returns>
public static bool SendMQ<T>(PushEntity<T> Param)
{
try
{
if (Bus == null)
CreateMQ();
new PushManage().SendMQ(Param, Bus);
return true;
}
catch (Exception)
{
return false;
}
}
/// <summary>
/// 推荐异步执行
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Param"></param>
/// <returns></returns>
public static async Task SendMQAsync<T>(PushEntity<T> Param)
{

if (Bus == null)
CreateMQ();
await new PushManage().SendMQAsync(Param, Bus);
}
/// <summary>
/// 订阅消息
/// </summary>
/// <typeparam name="TAccept"></typeparam>
/// <param name="Args"></param>
public static void Subscriber<TAccept, T>(AcceptEntity Args) where TAccept : IAccept, new()
{
try
{
if (Bus == null)
CreateMQ();
if (string.IsNullOrEmpty(Args.ExchangeName))
return;
Expression<Action<IAccept>> methodCall;
IExchange EX = null;
if (Args.SendType == MQEnum.Sub)
{
EX = Bus.Advanced.ExchangeDeclare(Args.ExchangeName, ExchangeType.Fanout);
}
if (Args.SendType == MQEnum.Push)
{
EX = Bus.Advanced.ExchangeDeclare(Args.ExchangeName, ExchangeType.Direct);
}
if (Args.SendType == MQEnum.Top)
{
EX = Bus.Advanced.ExchangeDeclare(Args.ExchangeName, ExchangeType.Topic);
}
IQueue queue = Bus.Advanced.QueueDeclare(Args.QueeName ?? null);
Bus.Advanced.Bind(EX, queue, Args.RouteName);
Bus.Advanced.Consume(queue, (body, properties, info) => Task.Factory.StartNew(() =>
{
try
{
var message = Encoding.UTF8.GetString(body);
//处理消息
methodCall = job => job.AcceptMQ<T>(message);
methodCall.Compile()(new TAccept());
}
catch (Exception ex)
{
throw ex;
}
}));
}
catch (Exception ex)
{

}
}
}
}

+ 26
- 0
HKLib/RabbitMq/Config/PushEntity.cs Целия файл

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace HKLib.RabbitMQ.Config
{
public class PushEntity<T>
{
/// <summary>
/// 推送内容
/// </summary>
public T BodyData { get; set; }
/// <summary>
/// 推送模式
/// </summary>
public MQEnum SendType { get; set; }
/// <summary>
/// 管道名称
/// </summary>
public String ExchangeName { get; set; }
/// <summary>
/// 路由名称
/// </summary>
public String RouteName { get; set; }
}
}

+ 81
- 0
HKLib/RabbitMq/Config/PushManage.cs Целия файл

@@ -0,0 +1,81 @@
using EasyNetQ;
using EasyNetQ.Topology;
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.Threading.Tasks;

namespace HKLib.RabbitMQ.Config
{
public class PushManage
{
/// <summary>
/// 发布消息队列异步
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Param"></param>
/// <param name="Bus"></param>
/// <returns></returns>
public async Task SendMQAsync<T>(PushEntity<T> Param, IBus Bus)
{
//one to one
var msg = new Message<T>(Param.BodyData);
IExchange EX = null;
if (Param.SendType == MQEnum.Sub)
{
EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Fanout);
}
if (Param.SendType == MQEnum.Push)
{
EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Direct);
}
if (Param.SendType == MQEnum.Top)
{
EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Topic);
}
await Bus.Advanced.PublishAsync(EX, Param.RouteName, false, msg).ContinueWith(t =>
{
//消息投递失败
if (!t.IsCompleted && t.IsFaulted)
{
// //将消息记录到数据库轮询
// IRepository Repository = new Repository();
// SystemLog Log = new SystemLog
// {
// LogName = "消息队列",
// Source = "发布队列",
// EventData = JsonConvert.SerializeObject(Param.BodyData)
// };
// Repository.Insert(Log);
}
});
}
/// <summary>
/// 发布消息队列同步
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="Param"></param>
/// <param name="Bus"></param>
public void SendMQ<T>(PushEntity<T> Param, IBus Bus)
{
//one to one
var msg = new Message<T>(Param.BodyData);
IExchange EX = null;
if (Param.SendType == MQEnum.Sub)
{
EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Fanout);
}
if (Param.SendType == MQEnum.Push)
{
EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Direct);
}
if (Param.SendType == MQEnum.Top)
{
EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Topic);
}
Bus.Advanced.Publish(EX, Param.RouteName, false, msg);
}
}
}

+ 74
- 0
HKLib/RabbitMq/Publisher/ServiceQueryPush.cs Целия файл

@@ -0,0 +1,74 @@
using EasyNetQ;
using HKLib.RabbitMQ.Config;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace HKLib.RabbitMQ.Publisher
{
public class ServiceQueryPush
{
public static ServiceQueryPush QueryPush => new Lazy<ServiceQueryPush>().Value;
public async Task<bool> PushMQAsync<T>(T Entity,string Key, MQEnum MQType = MQEnum.Push)
{
//推送模式
//推送模式下需指定管道名称和路由键值名称
//消息只会被发送到指定的队列中去
//订阅模式
//订阅模式下只需指定管道名称
//消息会被发送到该管道下的所有队列中
//主题路由模式
//路由模式下需指定管道名称和路由值
//消息会被发送到该管道下,和路由值匹配的队列中去
PushEntity<T> entity = new PushEntity<T>();
entity.BodyData = Entity;
entity.SendType = MQType;
if (MQType == MQEnum.Push)
{
entity.ExchangeName = "Message.Direct";
entity.RouteName = Key;
}
else if (MQType == MQEnum.Sub)
{
entity.ExchangeName = "Message.Fanout";
}
else
{
entity.ExchangeName = "Message.Topic";
entity.RouteName = Key;
}
return await MQFactory.SendMQAsync(entity).ContinueWith(t => { return t.IsCompleted ? true : false; });
}
public bool PushMQ<T>(T Entity, string Key, MQEnum MQType = MQEnum.Push)
{
//推送模式
//推送模式下需指定管道名称和路由键值名称
//消息只会被发送到指定的队列中去
//订阅模式
//订阅模式下只需指定管道名称
//消息会被发送到该管道下的所有队列中
//主题路由模式
//路由模式下需指定管道名称和路由值
//消息会被发送到该管道下,和路由值匹配的队列中去
PushEntity<T> entity = new PushEntity<T>();
entity.BodyData = Entity;
entity.SendType = MQType;
if (MQType == MQEnum.Push)
{
entity.ExchangeName = "Message.Direct";
entity.RouteName = Key;
}
else if (MQType == MQEnum.Sub)
{
entity.ExchangeName = "Message.Fanout";
}
else
{
entity.ExchangeName = "Message.Topic";
entity.RouteName = Key;
}
return MQFactory.SendMQ(entity);
}
}
}

+ 42
- 0
HKLib/RabbitMq/Subscriber/ServiceQueryExcute.cs Целия файл

@@ -0,0 +1,42 @@
using EasyNetQ;
using HKLib.RabbitMQ.Config;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace HKLib.RabbitMQ.Subscriber
{
public class ServiceQueryExcute
{
public static ServiceQueryExcute QueryExcute => new Lazy<ServiceQueryExcute>().Value;
public void ExtuteMQ<TImpl,T>(string Key,MQEnum Type) where TImpl : IAccept, new()
{
Task.Run(() =>
{
AcceptEntity accept = new AcceptEntity();
if (Type == MQEnum.Push)
{
accept.SendType = MQEnum.Push;
accept.ExchangeName = "Message.Direct";
accept.QueeName = "Meesage.DirectQuene";
accept.RouteName = Key;
}
else if (Type == MQEnum.Sub)
{
accept.SendType = MQEnum.Sub;
accept.ExchangeName = "Message.Fanout";
accept.QueeName = "Meesage.FanoutQuene";
}
else
{
accept.SendType = MQEnum.Top;
accept.ExchangeName = "Message.Topic";
accept.QueeName = "Meesage.FanoutQuene";
accept.RouteName = Key;
}
MQFactory.Subscriber<TImpl, T>(accept);
});
}
}
}

Зареждане…
Отказ
Запис