You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.5 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2025 WenJY 保留所有权利。
* CLR版本4.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,out int infoRes);
_logger.Info($"锁具:{idsStr};记录数据更新{(res ? "":"")},基础数据更新{(infoRes > 0 ? "":"")}");
}
}
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();
}
}
}