初始化

This commit is contained in:
2025-11-20 15:56:30 +08:00
commit ab6e620f8e
154 changed files with 29677 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "9.0.9",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using CSRedis;
namespace BLWWS_BLL.Common
{
/// <summary>
/// Redis缓存辅助类
/// </summary>
public class CSRedisCacheHelper
{
public static CSRedisClient redis;
public static CSRedisClient redis3;
public static CSRedisClient redis5;
private const string ip = "127.0.0.1";
private const string port = "6379";
static CSRedisCacheHelper()
{
var redisHostStr = string.Format("{0}:{1}", ip, port);
if (!string.IsNullOrEmpty(redisHostStr))
{
redis = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=1");
redis3 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=3");
//准备存储取电数据
redis5 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=5");
//string channel = "__keyevent@1__:expired";
//var QQQ = new ValueTuple<string, Action<CSRedisClient.SubscribeMessageEventArgs>>(channel, (msg) =>
// {
// if (channel.Equals(""))
// {
// }
// Console.WriteLine(msg.MessageId);
// Console.WriteLine(msg.Body);
// Console.WriteLine("11111111");
// });
//redis.Subscribe(QQQ);
}
}
/// <summary>
/// 添加缓存
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
/// <param name="value"></param>
public static void Set<T>(string key, T value, int ExpireTime)
{
redis?.Set(key, value, ExpireTime * 60);
}
public static T Get<T>(string key)
{
return redis.Get<T>(key);
}
public static void Forever<T>(string key, T value)
{
redis.Set(key, value, -1);
}
public static void Del(string key)
{
redis.Del(key);
}
/// <summary>
/// 判断是否存在
/// </summary>
/// <param name="key"></param>
/// <param name="mac"></param>
/// <returns></returns>
public static bool Contains(string key, string mac)
{
bool result = redis.Exists(mac);
if (!result)
{
result = redis.Exists(key);
}
return result;
}
public static bool Contains(string key)
{
bool result = redis.Exists(key);
return result;
}
}
}

View File

@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace PMSLogProduce.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

View File

@@ -0,0 +1,222 @@
using MessagePack;
namespace PMSLogProduce.Models
{
public class Root
{
public List<DataItem> data { get; set; }
}
public class DataItem
{
/// <summary>
///
/// </summary>
public string ExtendedLocation { get; set; }
/// <summary>
///
/// </summary>
public string OriginQuery { get; set; }
/// <summary>
///
/// </summary>
public string appinfo { get; set; }
/// <summary>
///
/// </summary>
public int disp_type { get; set; }
/// <summary>
///
/// </summary>
public string fetchkey { get; set; }
/// <summary>
/// 本地局域网
/// </summary>
public string location { get; set; }
/// <summary>
///
/// </summary>
public string origip { get; set; }
/// <summary>
///
/// </summary>
public string origipquery { get; set; }
/// <summary>
///
/// </summary>
public string resourceid { get; set; }
/// <summary>
///
/// </summary>
public int role_id { get; set; }
/// <summary>
///
/// </summary>
public int shareImage { get; set; }
/// <summary>
///
/// </summary>
public int showLikeShare { get; set; }
/// <summary>
///
/// </summary>
public string showlamp { get; set; }
/// <summary>
/// IP地址查询
/// </summary>
public string titlecont { get; set; }
/// <summary>
///
/// </summary>
public string tplt { get; set; }
}
[MessagePackObject()]
public class CheckInYuanShidata
{
[Key(0)]
public string? CommandType { get; set; }
[Key(1)]
public double Step { get; set; }
[Key(2)]
public string? IP { get; set; }
[Key(3)]
public string? RequestId { get; set; }
[Key(4)]
public ZhiJie? ZhiJieData { get; set; }
[Key(5)]
public JianJie? JianJieData { get; set; }
[Key(6)]
public DateTime CurrentTime { get; set; }
}
[MessagePackObject()]
public class ZhiJie
{
[Key(0)]
public CheckInData? CheckInData { get; set; }
[Key(1)]
public CheckOutData? CheckOutData { get; set; }
[Key(2)]
public RentData? RentData { get; set; }
}
[MessagePackObject()]
public class JianJie
{
[Key(0)]
public string? OriginallData { get; set; }
}
[MessagePackObject()]
public class CheckInData
{
[Key(0)]
public string? key { get; set; }
[Key(1)]
public string? code { get; set; }
[Key(2)]
public string? roomNumber { get; set; }
[Key(3)]
public DateTime checkInDate;
[Key(4)]
public string? xmlString { get; set; }
[Key(5)]
public string? phoneNumber { get; set; }
[Key(6)]
public string? idNumber { get; set; }
}
[MessagePackObject()]
public class CheckOutData
{
[Key(0)]
public string? key { get; set; }
[Key(1)]
public string? code { get; set; }
[Key(2)]
public string? roomNumber { get; set; }
[Key(3)]
public DateTime checkOutDate { get; set; }
}
[MessagePackObject()]
public class RentData
{
[Key(0)]
public string? key { get; set; }
[Key(1)]
public string? code { get; set; }
[Key(2)]
public string? roomNumber { get; set; }
[Key(3)]
public DateTime rentDate { get; set; }
}
//public class CheckInYuanShidata
//{
// public string CommandType { get; set; }
// public double Step { get; set; }
// public string IP { get; set; }
// public string RequestId { get; set; }
// public JianJie JianJieData { get; set; }
// public ZhiJie ZhiJieData { get; set; }
// public DateTime CurrentTime { get; set; }
//}
//public class JianJie
//{
// public string OriginallData { get; set; }
//}
//public class ZhiJie
//{
// public CheckInData CheckInData { get; set; }
// public CheckOutData CheckOutData { get; set; }
// public RentData RentData { get; set; }
//}
//public class CheckInData
//{
// public string key { get; set; }
// public string code { get; set; }
// public string roomNumber { get; set; }
// public DateTime checkInDate;
// public string xmlString { get; set; }
// public string phoneNumber { get; set; }
// public string idNumber { get; set; }
//}
//public class CheckOutData
//{
// public string key { get; set; }
// public string code { get; set; }
// public string roomNumber { get; set; }
// public DateTime checkOutDate { get; set; }
//}
//public class RentData
//{
// public string key { get; set; }
// public string code { get; set; }
// public string roomNumber { get; set; }
// public DateTime rentDate { get; set; }
//}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Confluent.Kafka" Version="2.11.1" />
<PackageReference Include="CSRedisCore" Version="3.8.806" />
<PackageReference Include="MessagePack" Version="3.1.4" />
<PackageReference Include="NLog" Version="6.0.3" />
<PackageReference Include="RestSharp" Version="112.1.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,6 @@
@PMSLogProduce_HostAddress = http://localhost:5157
GET {{PMSLogProduce_HostAddress}}/weatherforecast/
Accept: application/json
###

29
PMSLogProduce/Program.cs Normal file
View File

@@ -0,0 +1,29 @@
using BLWLogProduce.Services;
namespace PMSLogProduce
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddMemoryCache();
builder.Services.AddHostedService<KafkaProduce>();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}

View File

@@ -0,0 +1,31 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55946",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5157",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@@ -0,0 +1,113 @@

using System.Text;
using System.Text.Json;
using System.Threading.Channels;
using BLWWS_BLL.Common;
using Confluent.Kafka;
using MessagePack;
using Microsoft.Extensions.Caching.Memory;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using PMSLogProduce.Models;
using RestSharp;
using static CSRedis.CSRedisClient;
namespace BLWLogProduce.Services
{
public class KafkaProduce : BackgroundService
{
public IConfiguration Configuration { get; set; }
public IMemoryCache _Cache { get; set; }
public KafkaProduce(IConfiguration configuration, IMemoryCache cache)
{
this.Configuration = configuration;
_Cache = cache;
}
public static Logger logger = LogManager.GetCurrentClassLogger();
protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
await Task.Factory.StartNew((state) =>
{
try
{
string? ipport = Configuration["Kafka:EndPoint"];
string? user = Configuration["Kafka:UserName"];
string? pwd = Configuration["Kafka:PassWord"];
var config = new ProducerConfig
{
BootstrapServers = ipport,
SecurityProtocol = SecurityProtocol.SaslPlaintext,
SaslMechanism = SaslMechanism.Plain,
SaslUsername = user,
SaslPassword = pwd
};
var p = new ProducerBuilder<string, byte[]>(config).Build();
var DingYue1 = ("PMSLogMonitor", new Action<SubscribeMessageEventArgs>(async (args) =>
{
string body = args.Body;
CheckInYuanShidata? usa = System.Text.Json.JsonSerializer.Deserialize<CheckInYuanShidata>(body);
byte[] bytes = MessagePackSerializer.Serialize(usa);
string TopicKey = "blwlog-rcu-udppackage-topic";
string DetailKey = "pms";
Console.WriteLine("推送了数据");
await p.ProduceAsync(TopicKey, new Message<string, byte[]> { Key = DetailKey, Value = bytes });
}));
CSRedisCacheHelper.redis3.Subscribe(DingYue1);
}
catch (Exception ex)
{
logger.Error(ex.Message);
}
}, TaskCreationOptions.LongRunning);
}
/// <summary>
/// 百度api
/// </summary>
/// <returns></returns>
public static string GetBaiduIp(string ip)
{
string location = "";
try
{
string url = $"https://sp0.baidu.com";
//WebClient client = new WebClient();
RestSharp.RestClient client1 = new RestSharp.RestClient(url);
RestSharp.RestRequest request = new RestSharp.RestRequest($"/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={ip}&co=&resource_id=6006&oe=utf8", Method.Get);
var buffer = client1.DownloadData(request);
//var buffer = client.DownloadData(url);
string jsonText = Encoding.UTF8.GetString(buffer);
JObject jo = JObject.Parse(jsonText);
Root root = JsonConvert.DeserializeObject<Root>(jo.ToString());
foreach (var item in root.data)
{
location = item.location;
}
return location;
}
catch (Exception ex)
{
//Console.WriteLine(ex);
return location;
}
}
public static async Task ConsumeMessagesAsync()
{
while (true)
{
//if (_messageChannel.Reader.TryRead(out var nnn))
//{ }
}
}
}
}

View File

@@ -0,0 +1,13 @@
namespace PMSLogProduce
{
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,14 @@
{
"Kafka": {
"EndPoint": "43.138.217.154:9092",
"UserName": "blwmomo",
"PassWord": "blwmomo"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}