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 lazy = new Lazy(() => new OvenPlcDataService()); public static OvenPlcDataService Instance { get { return lazy.Value; } } private SQLiteHelper _helper = SQLiteHelper.Instance; private SerilogHelper _log = SerilogHelper.Instance; /// /// 插入数据 /// /// /// /// 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; } } /// /// 预固炉温度插入 /// /// 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; } } /// /// 固化炉温度插入 /// /// 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; } } /// /// 获取之前暂存的数据 /// /// 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(); } } } }