using HH.WCS.Mobox3.DoubleCoin.models; using HH.WCS.Mobox3.DoubleCoin.util; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HH.WCS.Mobox3.DoubleCoin.wms { public class SpecHelper { /// /// 获取静置时间 /// /// /// public static int GetWaitTime(string spec) { try { var db = new SqlHelper().GetInstance(); var specConfig = db.Queryable().First(o => o.S_SPE == spec); if (specConfig != null) { return specConfig.N_STANDING_TIME ?? 1; } else { return 1; } } catch (Exception ex) { LogHelper.Error("获取静置时间失败", ex); return 1; } } /// /// 获取过期时间 /// /// /// public static int GetExportTime(string spec) { try { var db = new SqlHelper().GetInstance(); var specConfig = db.Queryable().First(o => o.S_SPE == spec); if (specConfig != null) { return specConfig.N_EXPIRE_TIME ?? 1; } else { return 1; } } catch (Exception ex) { LogHelper.Error("获取过期时间失败", ex); return 1; } } /// /// 插入设备生产明细 /// public static void InsertEquipProDetail(TN_EquipProDetail model) { try { var db = new SqlHelper().GetInstance(); var log = JsonConvert.SerializeObject(model); if (model != null) { model.Expiration = System.DateTime.Now.AddMinutes(GetExportTime(model.Spec)); if (db.Insertable(model).ExecuteCommand() > 0) { LogHelper.Info($"插入设备生产明细成功,{log}"); } else { LogHelper.Info($"插入设备生产明细失败,{log}"); } } } catch (Exception ex) { LogHelper.Error("插入设备生产明细失败", ex); } } /// /// 更新设备生产明细的过期时间 /// public static void UpdateEquipProDetail(string cg_SID) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(a => a.S_ID == cg_SID); if (target != null) { target.Expiration = System.DateTime.Now.AddMinutes(GetExportTime(target.Spec)); db.Updateable().UpdateColumns(it => new { it.Expiration }).ExecuteCommand(); } } catch (Exception ex) { LogHelper.Error("插入设备生产明细失败", ex); } } /// /// 插入部件用料明细 /// /// public static void InsertComponentDetail(TN_Component_Detail model) { try { var db = new SqlHelper().GetInstance(); var log = JsonConvert.SerializeObject(model); if (model != null) { model.OutAreaTime = System.DateTime.Now; model.Type = "满托出库上线"; if (db.Insertable(model).ExecuteCommand() > 0) { LogHelper.Info($"插入部件用料明细成功,{log}"); } else { LogHelper.Info($"插入部件用料明细失败,{log}"); } } } catch (Exception ex) { LogHelper.Error("插入部件用料明细失败", ex); } } /// /// 更新部件用料明细 /// public static void UpdateComponentDetail(string taskNo) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(o => o.TaskNo == taskNo); if (target != null) { target.EndTime = System.DateTime.Now; if (db.Updateable(target).ExecuteCommand() > 0) { LogHelper.Info($"更新部件用料明细成功,{taskNo}"); } else { LogHelper.Info($"更新部件用料明细失败,{taskNo}"); } } } catch (Exception ex) { LogHelper.Error("更新部件用料明细失败", ex); } } /// /// 插入回炉料明细 /// /// public static void InsertRemeltDetail(TN_RemeltDetail model) { try { var db = new SqlHelper().GetInstance(); var log = JsonConvert.SerializeObject(model); if (model != null) { model.RemeltTime = System.DateTime.Now; if (db.Insertable(model).ExecuteCommand() > 0) { LogHelper.Info($"插入回炉料明细成功,{log}"); } else { LogHelper.Info($"插入回炉料明细失败,{log}"); } } } catch (Exception ex) { LogHelper.Error("插入回炉料明细失败", ex); } } /// /// 更新回炉料明细 /// public static void UpdateRemeltDetail(string taskNo) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(o => o.TaskNo == taskNo); if (target != null) { target.EndTime = System.DateTime.Now; if (db.Updateable(target).ExecuteCommand() > 0) { LogHelper.Info($"更新回炉料明细成功,{taskNo}"); } else { LogHelper.Info($"更新回炉料明细失败,{taskNo}"); } } } catch (Exception ex) { LogHelper.Error("更新回炉料明细失败", ex); } } /// /// 插入余料回库明细 /// /// public static void InsertSurplusDetail(TN_SurplusDetail model) { try { var db = new SqlHelper().GetInstance(); var log = JsonConvert.SerializeObject(model); if (model != null) { model.RemeltTime = System.DateTime.Now; if (db.Insertable(model).ExecuteCommand() > 0) { LogHelper.Info($"插入余料回库明细成功,{log}"); } else { LogHelper.Info($"插入余料回库明细失败,{log}"); } } } catch (Exception ex) { LogHelper.Error("插入余料回库明细失败", ex); } } /// /// 更新余料回库明细 /// public static void UpdateSurplusDetail(string taskNo) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(o => o.TaskNo == taskNo); if (target != null) { target.EndTime = System.DateTime.Now; if (db.Updateable(target).ExecuteCommand() > 0) { LogHelper.Info($"更新余料回库明细成功,{taskNo}"); } else { LogHelper.Info($"更新余料回库明细失败,{taskNo}"); } } } catch (Exception ex) { LogHelper.Error("更新余料回库明细失败", ex); } } /// /// 更新余料回库明细 /// public static void UpdateSurplusDetail(string taskNo,float weight) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(o => o.TaskNo == taskNo); if (target != null) { target.Weight = weight; if (db.Updateable(target).ExecuteCommand() > 0) { LogHelper.Info($"更新余料回库明细成功,{taskNo}"); } else { LogHelper.Info($"更新余料回库明细失败,{taskNo}"); } } } catch (Exception ex) { LogHelper.Error("更新余料回库明细失败", ex); } } /// /// 插入WMS库存明细 /// /// public static void InsertInventoryM(TN_InventoryM model) { try { var db = new SqlHelper().GetInstance(); var log = JsonConvert.SerializeObject(model); if (model != null) { var target = db.Queryable().First(o => o.RFID == model.RFID); if (target != null) { db.Deleteable(target).ExecuteCommand(); } model.Expiration = System.DateTime.Now.AddMinutes(GetExportTime(model.Spec)); if (db.Insertable(model).ExecuteCommand() > 0) { LogHelper.Info($"插入WMS库存明细成功,{log}"); } else { LogHelper.Info($"插入WMS库存明细失败,{log}"); } } } catch (Exception ex) { LogHelper.Error("插入WMS库存明细失败", ex); } } /// /// 更新WMS库存明细的过期时间 /// public static void UpdateInventoryM(string cg_SID) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(a => a.S_ID == cg_SID); if (target != null) { target.Expiration = System.DateTime.Now.AddMinutes(GetExportTime(target.Spec)); db.Updateable().UpdateColumns(it => new { it.Expiration }).ExecuteCommand(); } } catch (Exception ex) { LogHelper.Error("插入设备生产明细失败", ex); } } } }