using Models; using Sln.Imm.Daemon.Model.dao; using Sln.Imm.Daemon.Repository.service.@base; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Sln.Imm.Daemon.Repository.service.Impl { public class BaseRecordShutDownServiceImpl : BaseServiceImpl,IBaseRecordShutDownService { public BaseRecordShutDownServiceImpl(Repository rep) : base(rep) { } public bool UpdateShutDownVal(int id) { try { // 1. 根据设备ID和开始时间查找报警记录 var shutDownRecord = _rep.AsQueryable() .Where(x => x.MACHINE_ID == id && x.SHUT_TIME == 0) .First(); if (shutDownRecord == null) { return false; } DateTime endTime = DateTime.Now; shutDownRecord.SHUT_END_TIME = endTime; if (shutDownRecord.SHUT_BEGIN_TIME != null) { //2.计算时长 DateTime startTime = (DateTime)shutDownRecord.SHUT_BEGIN_TIME; TimeSpan continueTime = endTime - startTime; int totalMinutes = (int)Math.Round(continueTime.TotalMinutes); shutDownRecord.SHUT_TIME = totalMinutes; shutDownRecord.DOWNTIME_FLAG = "1"; } bool result = _rep.Update(shutDownRecord); return result; } catch (Exception) { return false; } } } }