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.

141 lines
4.5 KiB
C#

using Sln.Iot.Model.Entity;
using Sln.Iot.Repository.dao;
using Sln.Iot.Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sln.Iot.Repository.service
{
public class OvenPlcDataService
{
private static readonly Lazy<OvenPlcDataService> lazy = new Lazy<OvenPlcDataService>(() => new OvenPlcDataService());
public static OvenPlcDataService Instance
{
get
{
return lazy.Value;
}
}
private SQLiteHelper<OvenPlcData> _helper = new SQLiteHelper<OvenPlcData>();
private SerilogHelper _log = SerilogHelper.Instance;
/// <summary>
/// 插入数据
/// </summary>
/// <param name="GUID"></param>
/// <param name=""></param>
/// <returns></returns>
public bool InsertData(string guid, int data)
{
try
{
var res = _helper.Insert(new OvenPlcData()
{
GUID = guid,
PreheatOvenTempActValue = data,
});
return res == 0 ? false : true;
}
catch (Exception ex)
{
_log.Error("插入烤炉数据失败", ex);
return false;
}
}
/// <summary>
/// 预固炉温度插入
/// </summary>
/// <returns></returns>
public bool UpdateDataPreCure(string guid, UnitsProcess3Entity data)
{
try
{
var res = _helper.Update(new OvenPlcData()
{
GUID = guid,
PreCureOven1TempActValue = data.PreCureOven1TempActValue,
PreCureOven2TempActValue = data.PreCureOven2TempActValue,
PreCureOven3TempActValue = data.PreCureOven3TempActValue,
PreCureOven4TempActValue = data.PreCureOven4TempActValue,
});
return res == 0 ? false : true;
}
catch (Exception ex)
{
_log.Error("更新预固炉温度数据失败", ex);
return false;
}
}
/// <summary>
/// 固化炉温度插入
/// </summary>
/// <returns></returns>
public bool UpdateDataCure(string guid, UnitsProcess3Entity data)
{
try
{
var res = _helper.Update(new OvenPlcData()
{
GUID = guid,
CureOven1TempActValue = data.CureOven1TempActValue,
CureOven2TempActValue = data.CureOven2TempActValue,
CureOven3TempActValue = data.CureOven3TempActValue,
CureOven4TempActValue = data.CureOven4TempActValue,
});
return res == 0 ? false : true;
}
catch (Exception ex)
{
_log.Error("更新固化炉炉温度数据失败", ex);
return false;
}
}
/// <summary>
/// 获取之前暂存的数据
/// </summary>
/// <returns></returns>
public UnitsProcess3Entity GetData(string guid)
{
try
{
var res = _helper.QuerySingle(x => x.GUID == guid);
if (res == null)
{
return new UnitsProcess3Entity();
}
UnitsProcess3Entity entity = new UnitsProcess3Entity()
{
PreheatOvenTempActValue = res.PreheatOvenTempActValue,
PreCureOven1TempActValue = res.PreCureOven1TempActValue,
PreCureOven2TempActValue = res.PreCureOven2TempActValue,
PreCureOven3TempActValue = res.PreCureOven3TempActValue,
PreCureOven4TempActValue = res.PreCureOven4TempActValue,
CureOven1TempActValue = res.CureOven1TempActValue,
CureOven2TempActValue = res.CureOven2TempActValue,
CureOven3TempActValue = res.CureOven3TempActValue,
CureOven4TempActValue = res.CureOven4TempActValue,
};
_helper.Delete(guid);
return entity;
}
catch (Exception ex)
{
_log.Error("获取或删除隧道烤箱传感器数据失败", ex);
return new UnitsProcess3Entity();
}
}
}
}