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#

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.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)
{
resIds = new List<long>();
infoRes = 0;
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};不存在已开锁的锁具记录");
}
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;
}
private decimal CalculateHoursDifference(DateTime startTime, DateTime endTime)
{
TimeSpan duration = endTime - startTime;
return Convert.ToDecimal(duration.TotalHours);
}
}
}