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.

99 lines
3.4 KiB
C#

1 month ago
#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,out int infoRes)
1 month ago
{
resIds = new List<long>();
infoRes = 0;
1 month ago
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);
var res = _rep.Update(info);
if (!res)
{
throw new ArgumentNullException($"锁具:{deviceRecord.deviceCode};记录数据更新失败");
}
var dt = new Dictionary<string, object>();
dt.Add("device_code", info.deviceCode);
dt.Add("use_state", deviceRecord.useState);
infoRes = _rep.Context.Updateable(dt).AS("device_base_info").WhereColumns("device_code").ExecuteCommand();
if (infoRes < 1)
{
throw new ArgumentNullException($"锁具:{deviceRecord.deviceCode};基础数据更新失败");
}
}
else
{
throw new ArgumentNullException($"锁具:{deviceRecord.deviceCode};不存在已开锁的锁具记录");
1 month ago
}
return false;
}
public bool UpdateRfid(string deviceCode,string locationName, out int infoRes)
{
infoRes = 0;
var dt = new Dictionary<string, object>();
dt.Add("device_code", deviceCode);
dt.Add("location_name", locationName);
infoRes = _rep.Context.Updateable(dt).AS("device_base_info").WhereColumns("device_code").ExecuteCommand();
if (infoRes < 1)
{
throw new ArgumentNullException($"锁具:{deviceCode};RFID:{locationName};信息更新失败");
}
return false;
}
1 month ago
private decimal CalculateHoursDifference(DateTime startTime, DateTime endTime)
{
TimeSpan duration = endTime - startTime;
return Convert.ToDecimal(duration.TotalHours);
}
}
}