初始化

This commit is contained in:
2025-12-11 14:04:39 +08:00
commit 1f65bbf628
2676 changed files with 838983 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using NewCRICS.Models;
namespace NewCRICS.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
return View();
}
public IActionResult Privacy()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}

View File

@@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace NewCRICS.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ValuesController : ControllerBase
{
}
}

View File

@@ -0,0 +1,271 @@
using System.Collections;
using System.Runtime.CompilerServices;
using Common;
using CommonEntity.CacheEntity;
using CommonEntity.RCUEntity;
using IOT_JieKou;
using LogCap.Common;
using Orleans.Serialization.Buffers;
namespace NewCRICS.Genie
{
/// <summary>
/// EndPointGrain
/// </summary>
public class EndPointGrain : Grain, IDataTran
{
private string EndPoint { get; set; } = string.Empty;
private string HostNumber { get; set; } = string.Empty;
public MyData_Cache _cache { get; set; } = new MyData_Cache();
public async ValueTask TongXin(RCU_UDPData_With_String data)
{
try
{
byte[]? hexdata = data.data;
string? endpoint = data.endpoint;
string? hostnum = data.hostnum;
long? timestamp = data.currenttimestamp;
//AA 55 3C 00 54 33 53 41 34 32 F8 3D 04 81 FC
//01 01 A3 06 01 30 20 00 00 00 00 00 02 02 02 39 01 01 00 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 01 00 00 02 5B 0B
//79 CF
//固定 0xAA 0x55
//3C 00数据的总长度包括包头和 CRC 校验。低地址在前
//54 33 53 41 系统 ID 的四个字节。固定“T3SA”
//34 命令字
//32 F8 帧号 帧号,应答时的帧号为接收到数据的帧号。低地址在前
//3D 04 项目编码。低地址在前
//81 MAC
//FC MAC
//79 CF CRC 校验。低地址在前
byte[] header = hexdata[0..2];
byte[] len = hexdata[2..4];
byte[] guding = hexdata[4..8];
byte cmd = hexdata[8];
byte[] frame1 = hexdata[9..11];
byte[] hotel_code = hexdata[11..13];
byte[] mac = hexdata[13..15];
byte[] byte_data = hexdata[15..^2];
byte[] crc = hexdata[^2..];
if (cmd == 0x32)
{
}
else if (cmd == 0x33)
{
}
//定时上报
// AA 55 35 00 54 33 53 41 34 10 80 EB 03 6B 24
// 01 //协议版本
// 01 //取电状态
// 00 //身份信息
// 00 //无卡逻辑
// 00 00 00 00 00 00 00 00 //服务信息全部回路状态 1~64 64Bit 0 :关 1
// 01 //PMS状态
// 01 //碳达人
// 01 //上报设备数
// 39 //设备类型 - 能耗设备
// 01 //设备地址
// 01 00 //设备回路
// 10 //设备数据长度
// 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 //设备数据
// 07 //设备类型 - 温控
// 01 //设备地址
// 01 00 //设备回路
// 02 //设备数据长度
// 00 00 //设备数据
// F4 AA //CRC16
//能耗设备 - 上报数据格式
//P15设备类型
//P16设备地址
//P17~P18设备回路
//P19设备数据长度
//P20~P21通道电压单位10mV
//P22~P23通道电流单位10mA
//P24~P25通道有功功率单位mW
//P26~P29通道能耗单位Wh1度电 = 1KWh
//P30~P33通道总能耗单位Wh1度电 = 1KWh
else if (cmd == 0x34)
{
ParseDeviceReport(byte_data, this._cache, this.HostNumber);
Common.Cache.Cache.SetCache(HostNumber, this._cache);
}
else if (cmd == 0x35)
{
}
else if (cmd == 0x36)
{
}
}
catch (Exception)
{
}
await ValueTask.CompletedTask;
}
/// <summary>
/// 解析数据
/// </summary>
/// <param name="byte_data"></param>
private static void ParseDeviceReport(byte[] byte_data, MyData_Cache cache, string HostNumber)
{
using (MemoryStream stream = new MemoryStream(byte_data))
{
using (BinaryReader reader = new BinaryReader(stream))
{
//版本
var Version = reader.ReadByte();
//取电
var TakeCardStatus = reader.ReadByte();
//身份
var IdentityInfo = reader.ReadByte();
var NOCardInfo = reader.ReadByte();
cache.Version = Version.ToString("X2");
cache.TakeCardInfo.TakeCardStatus = TakeCardStatus;
cache.TakeCardInfo.IdentityInfo = IdentityInfo;
cache.TakeCardInfo.NOCardInfo = NOCardInfo;
//服务信息全部回路状态 1~64 64Bit 0 :关 1
//把8个字节转换成64个二进制位
var N = reader.ReadBytes(8);
BitArray bitlist = new BitArray(N);
for (int i = 0; i < bitlist.Length; i++)
{
if (i == 1)
{
continue;
}
string SerNo = i.ToString("000");
}
//PMS房态
//定时上报,之后要设置房态要用0C
//只会上报 01 出租02退房
var PMS = reader.ReadByte();
cache.PMS_RoomStatus.PMSStatus = PMS;
//if (PMS != 0x01 && PMS != 0x02)
if (true)
{
}
//碳达人
var CarbonVIP = reader.ReadByte();
cache.TanDaRen.CarbonVIP_Status = CarbonVIP;
var DeviceCount = reader.ReadByte();
int DeviceCount_I = (int)DeviceCount;
for (int i = 0; i < DeviceCount_I; i++)
{
var QA = reader.ReadBytes(4);
//说明是能耗设备
#region
if (QA[0] == 0x39)
{
string address = DeviceConvert.Convert_To_Address(QA);
//设备数据长度
var DeviceInfoLen = reader.ReadByte();
var Len = Convert.ToInt32(DeviceInfoLen);
//设备数据
var Data = reader.ReadBytes(Len);
byte[] DianYa = Data.Take(2).ToArray();
byte[] DianLiu = Data.Skip(2).Take(2).ToArray();
byte[] Power = Data.Skip(4).Take(4).ToArray();
byte[] PowerUsed = Data.Skip(8).Take(4).ToArray();
byte[] TotalPowerUsed = Data.Skip(12).Take(4).ToArray();
uint dianya = BitConverter.ToUInt16(DianYa, 0);
uint dianliu = BitConverter.ToUInt16(DianLiu, 0);
uint gonglv = BitConverter.ToUInt32(Power, 0);
uint nenghao = BitConverter.ToUInt32(PowerUsed, 0);
uint zongnenghao = BitConverter.ToUInt32(TotalPowerUsed, 0);
double V = (double)dianya * 10 / 1000;
double A = (double)dianliu * 10 / 1000;
double P = (double)gonglv / 1000;
double KW_H = (double)nenghao / 1000;
double Sum_KW_H = (double)zongnenghao / 1000;
}
#endregion
#region
//定期上报,
//原本的0E 修改了命令字,改成其它命令字,内容不变,但是空调 只有操作上报。
//空调定期上报的数据,改为在这里上报
else if (QA[0] == 0x07)
{
//07 //设备类型 - 温控
//01 //设备地址
//01 00 //设备回路
//02 //设备数据长度
//00 00 //设备数据
string address = DeviceConvert.Convert_To_Address(QA);
//设备数据长度
var WenKongQiDataLen = reader.ReadByte();
//温控器
var DataLen1 = Convert.ToInt32(WenKongQiDataLen);
///ushort StatusReceiver = reader.ReadUInt16();
ushort StatusReceiver = BitConverter.ToUInt16(reader.ReadBytes(2).Reverse().ToArray(), 0);
}
#endregion
}
}
}
}
public override Task OnActivateAsync(CancellationToken cancellationToken)
{
string KKK = this.GetPrimaryKeyString();
var ssa= this.GetStreamProvider("");
StreamId id= StreamId.Create("ns",Guid.NewGuid().ToString());
//ssa.GetStream(id).OnNextAsync("");
this.HostNumber = KKK;
var take = Common.Cache.Cache.GetCache(KKK).Result;
if (take != null)
{
this._cache = take;
}
else
{
this._cache = new MyData_Cache();
}
this.EndPoint = KKK;
return base.OnActivateAsync(cancellationToken);
}
public override Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
{
return base.OnDeactivateAsync(reason, cancellationToken);
}
}
}

View File

@@ -0,0 +1,20 @@
using FASTER.core;
using Quartz;
namespace NewCRICS.Jobs
{
public class CacheSave : IJob
{
public async Task Execute(IJobExecutionContext context)
{
try
{
//await Common.Cache.Cache.store.TakeFullCheckpointAsync(CheckpointType.FoldOver);
}
catch (Exception)
{
}
}
}
}

View File

@@ -0,0 +1,9 @@
namespace NewCRICS.Models
{
public class ErrorViewModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}
}

20
NewCRICS/Models/MMA.cs Normal file
View File

@@ -0,0 +1,20 @@
using Microsoft.IO;
namespace NewCRICS.Models
{
public class MMA
{
private static readonly RecyclableMemoryStreamManager manager = new RecyclableMemoryStreamManager();
static void Main(string[] args)
{
//https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream
var sourceBuffer = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 };
using (var stream = manager.GetStream())
{
stream.Write(sourceBuffer, 0, sourceBuffer.Length);
}
}
}
}

24
NewCRICS/NewCRICS.csproj Normal file
View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.FASTER.Server" Version="2.6.5" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.1" />
<PackageReference Include="Microsoft.Orleans.Persistence.Redis" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Server" Version="8.2.0" />
<PackageReference Include="Microsoft.Orleans.Streaming" Version="8.2.0" />
<PackageReference Include="Quartz" Version="3.15.1" />
<PackageReference Include="Quartz.AspNetCore" Version="3.15.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\IOT_JieKou\IOT_JieKou.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/Api</Controller_SelectedScaffolderCategoryPath>
</PropertyGroup>
</Project>

125
NewCRICS/Program.cs Normal file
View File

@@ -0,0 +1,125 @@
using NewCRICS.Jobs;
using Orleans.Configuration;
using Quartz;
namespace NewCRICS
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseOrleans(ooo =>
{
// <20><> Orleans <20>ͻ<EFBFBD><CDBB>˺ͷ<CBBA><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>
ooo.Configure<GrainCollectionOptions>(options =>
{
options.CollectionAge = TimeSpan.FromMinutes(10); // <20>ӳ<EFBFBD>Grain<69><6E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
options.DeactivationTimeout = TimeSpan.FromMinutes(10);
});
ooo.Configure<Orleans.Configuration.SchedulingOptions>(options =>
{
//options.MaxActiveThreads = Math.Max(4, Environment.ProcessorCount * 2);
options.MaxPendingWorkItemsSoftLimit = 10000;
options.DelayWarningThreshold = TimeSpan.FromSeconds(5);
});
ooo.UseLocalhostClustering();
ooo.AddRedisGrainStorage("RedisStorage", options =>
{
options.ConfigurationOptions = new StackExchange.Redis.ConfigurationOptions
{
EndPoints = { "localhost:6379" },
AbortOnConnectFail = false,
};
});
});
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddQuartz(q =>
{
var jobKey = new JobKey("CacheSaveJob");
q.AddJob<CacheSave>(opts => opts.WithIdentity(jobKey));
q.AddTrigger(opts => opts
.ForJob(jobKey)
.WithIdentity("CacheSaveJob-trigger")
.WithCalendarIntervalSchedule(x =>
{
x.WithIntervalInMinutes(1).Build();
})
);
#region <EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>
//var jobKey1 = new JobKey("Cache_Save");
//q.AddJob<CacheSave>(opts => opts.WithIdentity(jobKey1));
//q.AddTrigger(opts => opts
// .ForJob(jobKey1)
// .WithIdentity("CacheSaveJob-trigger")
// .StartAt(DateBuilder.TodayAt(h, m, s))
// .WithCalendarIntervalSchedule(x => x
// .WithIntervalInDays(1)
// .InTimeZone(TimeZoneInfo.Local))
//);
//q.AddTrigger(opts => opts
// .ForJob(jobKey1)
// .WithIdentity("ExcelGenerateJob-trigger")
// .WithCronSchedule("0 0 17 * * ?", (schedule) =>
// {
// schedule.WithMisfireHandlingInstructionDoNothing().InTimeZone(TimeZoneInfo.Local);
// }) // ÿ<><C3BF>17:00
//);
//var jobKey2 = new JobKey("ScanExcel");
//q.AddJob<ExcelScan>(opts => opts.WithIdentity(jobKey2));
//q.AddTrigger(opts => opts
// .ForJob(jobKey2)
// .WithIdentity("ExcelScan-trigger")
// .WithCalendarIntervalSchedule(x =>
// {
// x.WithIntervalInSeconds(30).Build();
// })
//);
//var jobKey3 = new JobKey("DeleteFile");
//q.AddJob<ExcelScan>(opts => opts.WithIdentity(jobKey3));
//q.AddTrigger(opts => opts
// .ForJob(jobKey3)
// .WithIdentity("DeleteFile-trigger")
// .WithCronSchedule("0 0 1 * * ?", (schedule) =>
// {
// schedule.WithMisfireHandlingInstructionDoNothing().InTimeZone(TimeZoneInfo.Local);
// }) // ÿ<><C3BF>17:00
//);
#endregion
});
builder.Services.AddQuartzHostedService(q => q.WaitForJobsToComplete = true);
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

View File

@@ -0,0 +1,6 @@
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@@ -0,0 +1,25 @@
@model ErrorViewModel
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

View File

@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - NewCRICS</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/NewCRICS.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">NewCRICS</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2025 - NewCRICS - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>

View File

@@ -0,0 +1,48 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */
a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}
a {
color: #0077cc;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}
button.accept-policy {
font-size: 1rem;
line-height: inherit;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}

View File

@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

View File

@@ -0,0 +1,3 @@
@using NewCRICS
@using NewCRICS.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}

View File

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

View File

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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,19 @@
{
"runtimeOptions": {
"tfm": "net8.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "8.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "8.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

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

View File

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

Some files were not shown because too many files have changed in this diff Show More