change - 修改

main
WenJY 1 month ago
parent ddd65e54cb
commit 76b33786f5

@ -60,7 +60,7 @@ namespace Sln.Iot.Business
/// <param name="idStr"></param> /// <param name="idStr"></param>
/// <param name="password"></param> /// <param name="password"></param>
[EnableCors("cors")] [EnableCors("cors")]
[WebApi(HttpMethodType.POST)] [WebApi(HttpMethodType.GET)]
public ApiResInfo Unlock(string idStr,string password) public ApiResInfo Unlock(string idStr,string password)
{ {
BufferRequestInfo bufferRequestInfo = new BufferRequestInfo(); BufferRequestInfo bufferRequestInfo = new BufferRequestInfo();
@ -95,7 +95,7 @@ namespace Sln.Iot.Business
/// <param name="idStr"></param> /// <param name="idStr"></param>
/// <param name="password"></param> /// <param name="password"></param>
[EnableCors("cors")] [EnableCors("cors")]
[WebApi(HttpMethodType.POST)] [WebApi(HttpMethodType.GET)]
public ApiResInfo LockUp(string idStr,string password) public ApiResInfo LockUp(string idStr,string password)
{ {
BufferRequestInfo bufferRequestInfo = new BufferRequestInfo(); BufferRequestInfo bufferRequestInfo = new BufferRequestInfo();

@ -0,0 +1,85 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Business
* CF6CB45C-6484-468E-9853-31ADA6821183
*
* WenJY
*
* 2025-05-27 11:14:04
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using Sln.Iot.Business.@base;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.Serilog;
using Sln.Iot.Socket.Adapter;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace Sln.Iot.Business
{
public class RfidBusiness:BaseBusiness
{
public RfidBusiness(SerilogHelper logger, AppConfig appConfig, StringChange stringChange) : base(logger, appConfig, stringChange)
{
}
public override FilterResult BufferAnalysis(ISocketClient client, BufferRequestInfo requestInfo, int bodyLength)
{
ByteBlock byteBlock = new ByteBlock(requestInfo.Body);
if (byteBlock.CanReadLen < 1)
{
return FilterResult.Cache;
}
int pos = byteBlock.Pos;
try
{
var amount = requestInfo.BufferLength / bodyLength;
_logger.Info($"收到{amount}个RFID数据开始循环解析......");
for (int i = 0; i < amount; i++)
{
byte[] ids = new byte[3];
Array.Copy(requestInfo.buffer, 1, ids, 0, ids.Length);
string idsStr = _stringChange.bytesToHexStr(ids,ids.Length);
var status = _stringChange.bytesToHexStr(requestInfo.Body, requestInfo.Body.Length);
_logger.Info($"设备编号:{idsStr};RFID:{status}");
}
return FilterResult.Success;
}
catch (Exception e)
{
base._logger.Error($"RFID数据解析异常{e.Message}");
}
return FilterResult.Cache;
}
public override void ResponseHandle(ISocketClient client, BufferRequestInfo requestInfo)
{
//throw new System.NotImplementedException();
}
}
}

@ -0,0 +1,103 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Business
* A937102D-813C-4FB6-8ECE-BC01749B020F
*
* WenJY
*
* 2025-05-27 10:57:06
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using System.Collections.Generic;
using Sln.Iot.Business.@base;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.Model.dao;
using Sln.Iot.Repository.service;
using Sln.Iot.Serilog;
using Sln.Iot.Socket.Adapter;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace Sln.Iot.Business
{
public class StatusBusiness:BaseBusiness
{
private readonly IDeviceRecordService _deviceRecordService;
public StatusBusiness(SerilogHelper logger, AppConfig appConfig, StringChange stringChange, IDeviceRecordService deviceRecordService) : base(logger, appConfig, stringChange)
{
_deviceRecordService = deviceRecordService;
}
public override FilterResult BufferAnalysis(ISocketClient client, BufferRequestInfo requestInfo, int bodyLength)
{
ByteBlock byteBlock = new ByteBlock(requestInfo.Body);
if (byteBlock.CanReadLen < 1)
{
return FilterResult.Cache;
}
int pos = byteBlock.Pos;
try
{
var amount = requestInfo.BufferLength / bodyLength;
_logger.Info($"收到{amount}个物联锁具状态,开始循环解析......");
for (int i = 0; i < amount; i++)
{
byte[] ids = new byte[3];
Array.Copy(requestInfo.buffer, 1, ids, 0, ids.Length);
string idsStr = _stringChange.bytesToHexStr(ids,ids.Length);
var status = _stringChange.bytesToHexStr(requestInfo.Body, requestInfo.Body.Length);
_logger.Info($"设备编号:{idsStr};状态:{status}");
if (status == "00")
{
//更新锁具信息
DeviceRecord deviceRecord = new DeviceRecord()
{
deviceCode = idsStr,
closeTime = DateTime.Now,
useState = '0'
};
var res = _deviceRecordService.UpdateCloseTime(deviceRecord,out List<long> resIds);
}
}
return FilterResult.Success;
}
catch (Exception e)
{
base._logger.Error($"物联网锁具状态解析异常:{e.Message}");
}
return FilterResult.Cache;
}
public override void ResponseHandle(ISocketClient client, BufferRequestInfo requestInfo)
{
//throw new System.NotImplementedException();
}
}
}

@ -1 +1 @@
aeff8618efbc09ca6762690d721ce79cb58971fc 968ac897ee046c2748b0f7b8bdf8e9f908c9423a

@ -0,0 +1,70 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Model.dao
* 0840C4D2-F080-4B20-AB87-CC968CD18BAC
*
* WenJY
*
* 2025-05-27 11:28:05
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using SqlSugar;
namespace Sln.Iot.Model.dao
{
[SugarTable("device_record_use"), TenantAttribute("iot")]
public class DeviceRecord
{
/// <summary>
/// 编号 ,IsIdentity = true
///</summary>
[SugarColumn(ColumnName="obj_id" ,IsPrimaryKey = true )]
public long objid { get; set; }
/// <summary>
/// 设备编码
/// </summary>
[SugarColumn(ColumnName="device_code" )]
public string deviceCode { get; set; }
/// <summary>
/// 开锁时间
///</summary>
[SugarColumn(ColumnName="open_time" )]
public DateTime openTime { get; set; }
/// <summary>
/// 关锁时间
/// </summary>
[SugarColumn(ColumnName="close_time" )]
public DateTime closeTime { get; set; }
/// <summary>
/// 使用时间
/// </summary>
[SugarColumn(ColumnName="use_time" )]
public decimal useTime { get; set; }
/// <summary>
/// 使用状态
/// </summary>
[SugarColumn(ColumnName="use_state" )]
public char useState{get;set;}
}
}

@ -1 +1 @@
e0d4ce9551bcb776d90e1f41c3b7f0bb972e7184 a3b2a551f0af1bc0fe51e6e6d221d8e6b1d4e4b0

@ -1 +1 @@
ea2626c3e079c404cdc49d7821099424990bbe2c 1c4ccaf144c2819dd96d15f6185e36b4696b9541

@ -0,0 +1,37 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Repository.service
* 4D26DFC3-EE8E-4335-983C-A5E1327C99A3
*
* WenJY
*
* 2025-05-27 14:05:40
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System.Collections.Generic;
using Sln.Iot.Model.dao;
using Sln.Iot.Repository.service.@base;
namespace Sln.Iot.Repository.service
{
public interface IDeviceRecordService:IBaseService<DeviceRecord>
{
bool UpdateCloseTime(DeviceRecord deviceRecord,out List<long> resIds);
}
}

@ -0,0 +1,63 @@
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Repository.service.Impl
* 83CD1830-F4B4-49D3-A5A6-A5932F8AD185
*
* WenJY
*
* 2025-05-27 14:06:04
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Sln.Iot.Model.dao;
using Sln.Iot.Repository.service.@base;
namespace Sln.Iot.Repository.service.Impl
{
public class DeviceRecordServiceImpl: BaseServiceImpl<DeviceRecord>, IDeviceRecordService
{
public DeviceRecordServiceImpl(Repository<DeviceRecord> rep) : base(rep)
{
}
public bool UpdateCloseTime(DeviceRecord deviceRecord, out List<long> resIds)
{
resIds = new List<long>();
var info = _rep.GetList(x=> x.deviceCode == deviceRecord.deviceCode && x.useState == '1').FirstOrDefault();
if (info != null)
{
resIds.Add(info.objid);
info.closeTime = deviceRecord.closeTime;
info.useState = deviceRecord.useState;
info.useTime = CalculateHoursDifference(info.openTime, deviceRecord.closeTime);
_rep.Update(info);
}
return false;
}
private decimal CalculateHoursDifference(DateTime startTime, DateTime endTime)
{
TimeSpan duration = endTime - startTime;
return Convert.ToDecimal(duration.TotalHours);
}
}
}

@ -138,6 +138,10 @@ namespace Sln.Iot.Socket.Adapter
{ {
switch (dataType) switch (dataType)
{ {
case 0x32:
length = 1;
break;
case 0x33: case 0x33:
length = 4; length = 4;
break; break;
@ -153,6 +157,9 @@ namespace Sln.Iot.Socket.Adapter
case 0x37: case 0x37:
length = 5; length = 5;
break; break;
case 0x39:
length = 8;
break;
default: default:
length = 1; length = 1;
break; break;

@ -43,6 +43,10 @@ class Program
case 0x08: case 0x08:
_business = ServiceProvider.GetService<CheckTimeBusiness>(); _business = ServiceProvider.GetService<CheckTimeBusiness>();
break; break;
case 0x32:
bodyLength = 1;
_business = ServiceProvider.GetService<StatusBusiness>();
break;
case 0x33: //登录指令 case 0x33: //登录指令
_business = ServiceProvider.GetService<LoginBusiness>(); _business = ServiceProvider.GetService<LoginBusiness>();
break; break;
@ -53,6 +57,10 @@ class Program
bodyLength = info.BufferLength; bodyLength = info.BufferLength;
_business = ServiceProvider.GetService<LocalBusiness>(); _business = ServiceProvider.GetService<LocalBusiness>();
break; break;
case 0x39:
bodyLength = 8;
_business = ServiceProvider.GetService<RfidBusiness>();
break;
default: default:
break; break;
} }

@ -6,11 +6,11 @@
"virtualValue": 99999, "virtualValue": 99999,
"SqlConfig": [ "SqlConfig": [
{ {
"configId": "tao_iot", //tao: "configId": "iot", //tao:
"dbType": 0, //tidb mysql "dbType": 0, //tidb mysql
"isFlag": true, "isFlag": true,
//"connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123; //"connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123;
"connStr": "server=1.13.177.47;Port=3306;Database=tao_iot;Uid=root;Pwd=haiwei@123;" "connStr": "server=119.45.202.115;Port=3306;Database=no_power_control;Uid=root;Pwd=haiwei@123;"
} }
] ]
} }

@ -6,11 +6,11 @@
"virtualValue": 99999, "virtualValue": 99999,
"SqlConfig": [ "SqlConfig": [
{ {
"configId": "tao_iot", //tao: "configId": "iot", //tao:
"dbType": 0, //tidb mysql "dbType": 0, //tidb mysql
"isFlag": true, "isFlag": true,
//"connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123; //"connStr": "server=127.0.0.1;Port=4000;Database=tao_iot;Uid=root;" //Pwd=haiwei@123;
"connStr": "server=1.13.177.47;Port=3306;Database=tao_iot;Uid=root;Pwd=haiwei@123;" "connStr": "server=119.45.202.115;Port=3306;Database=no_power_control;Uid=root;Pwd=haiwei@123;"
} }
] ]
} }

Loading…
Cancel
Save