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.AddHours(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 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.AddHours(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_RuKu(string cntId) { try { var db = new SqlHelper().GetInstance(); var target = db.Queryable().First(a => a.S_CNTR_CODE == cntId); if (target != null) { var targetM = db.Queryable().First(a => a.S_ID == target.S_ID); if (targetM != null) { targetM.INAREATIME = System.DateTime.Now; if(db.Updateable(targetM).UpdateColumns(it => new { it.INAREATIME }).ExecuteCommand() > 0) { LogHelper.Info($"更新WMS库存明细的入库时间,成功,容器号:{cntId}"); } else { LogHelper.Info($"更新WMS库存明细的入库时间,失败,容器号:{cntId}"); } } else { LogHelper.Info($"更新WMS库存明细的入库时间,失败,容器号:{cntId},TN_InventoryM为空"); } } else { LogHelper.Info($"更新WMS库存明细的入库时间,失败,容器号:{cntId},TN_CG_Detail为空"); } } catch (Exception ex) { LogHelper.Error("更新WMS库存明细的入库时间失败", ex); } } /// /// 删除WMS库存明细 /// public static void DeleteInventoryM(string cg_SID) { try { var db = new SqlHelper().GetInstance(); if(db.Deleteable().Where(it => it.S_ID == cg_SID).ExecuteCommand() > 0) { LogHelper.Info($"删除WMS库存明细,成功,物料主键:{cg_SID}"); } else { LogHelper.Info($"删除WMS库存明细,失败,物料主键:{cg_SID}"); } } catch (Exception ex) { LogHelper.Error("更新WMS库存明细的过期时间失败", ex); } } public static int CalculateDaysDifference(DateTime start, DateTime end) { try { // 计算总时间差 TimeSpan difference = end - start; // 如果差值为负(end早于start),返回0 if (difference.TotalDays < 0) { return 0; } // 获取总天数(包括小数部分) double totalDays = difference.TotalDays; // 向上取整 return (int)Math.Ceiling(totalDays); } catch (Exception ex) { return 0; } } } }