79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
using Cowain.Preheat.BLL;
|
|
using Cowain.Preheat.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity;
|
|
using JSON = Newtonsoft.Json.JsonConvert;
|
|
|
|
namespace Cowain.Injecting.BLL
|
|
{
|
|
public class BatteryRepeatService : ServiceBase
|
|
{
|
|
|
|
public BatteryRepeatService(IUnityContainer unityContainer) : base(unityContainer)
|
|
{
|
|
|
|
}
|
|
|
|
public List<TBatteryInfo> GetIncomingCell()
|
|
{
|
|
using (var Context = new PreheatEntities())
|
|
{
|
|
var cellList = Context.Set<TBatteryRepeat>().OrderBy(x => x.Id).ThenByDescending(x => x.ScanTime).Take(300).ToList();
|
|
if (cellList == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return JSON.DeserializeObject<List<TBatteryInfo>>(JSON.SerializeObject(cellList));
|
|
}
|
|
}
|
|
|
|
public List<TBatteryInfo> QueryIncomingCell(DateTime startTime, DateTime endTime)
|
|
{
|
|
using (var Context = new PreheatEntities())
|
|
{
|
|
var cellList = Context.Set<TBatteryRepeat>().Where(x => x.ScanTime > startTime && x.ScanTime < endTime).OrderBy(x => x.Id).ThenByDescending(x => x.ScanTime).Take(1000).ToList();
|
|
if (cellList == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return JSON.DeserializeObject<List<TBatteryInfo>>(JSON.SerializeObject(cellList));
|
|
}
|
|
}
|
|
|
|
public List<TBatteryInfo> QueryIncomingCellByCode(string code)
|
|
{
|
|
using (var Context = new PreheatEntities())
|
|
{
|
|
var cellList = Context.Set<TBatteryRepeat>().Where(x => x.BatteryCode.Contains(code)).OrderBy(x => x.Id).ThenByDescending(x => x.ScanTime).ToList();
|
|
|
|
if (cellList == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return JSON.DeserializeObject<List<TBatteryInfo>>(JSON.SerializeObject(cellList));
|
|
}
|
|
}
|
|
|
|
public int Delete(TBatteryInfo t)
|
|
{
|
|
using (var Context = new PreheatEntities())
|
|
{
|
|
var repeat = Context.Set<TBatteryRepeat>().Where(x => x.Id == t.Id).FirstOrDefault();
|
|
if (null == repeat)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
Context.Set<TBatteryRepeat>().Attach(repeat);
|
|
Context.Set<TBatteryRepeat>().Remove(repeat);
|
|
return Context.SaveChanges();
|
|
}
|
|
}
|
|
}
|
|
}
|