杨张扬
2025-07-01 1c7cb41e75dece1ec91039625fcc434776df3821
wms/SpecHelper.cs
@@ -77,7 +77,7 @@
                var log = JsonConvert.SerializeObject(model);
                if (model != null)
                {
                    model.EXPIRATION = System.DateTime.Now.AddMinutes(GetExportTime(model.SPEC));
                    model.EXPIRATION = System.DateTime.Now.AddHours(GetExportTime(model.SPEC));
                    if (db.Insertable<TN_EquipProDetail>(model).ExecuteCommand() > 0)
                    {
@@ -326,7 +326,7 @@
                    {
                        db.Deleteable<TN_InventoryM>(target).ExecuteCommand();
                    }
                    model.EXPIRATION = System.DateTime.Now.AddMinutes(GetExportTime(model.SPEC));
                    model.EXPIRATION = System.DateTime.Now.AddHours(GetExportTime(model.SPEC));
                    if (db.Insertable<TN_InventoryM>(model).ExecuteCommand() > 0)
                    {
                        LogHelper.Info($"插入WMS库存明细成功,{log}");
@@ -354,7 +354,7 @@
                var target = db.Queryable<TN_CG_Detail>().First(a => a.S_CNTR_CODE == cntId);
                if (target != null)
                {
                    var targetM = db.Queryable<TN_InventoryM>().First(a => a.S_ID == target.S_ID);
                    var targetM = db.Queryable<TN_InventoryM>().First(a => a.S_ID == target.S_ID || a.RFID == cntId);
                    if (targetM != null)
                    {
@@ -368,7 +368,14 @@
                            LogHelper.Info($"更新WMS库存明细的入库时间,失败,容器号:{cntId}");
                        }
                    }
                    else
                    {
                        LogHelper.Info($"更新WMS库存明细的入库时间,失败,容器号:{cntId},TN_InventoryM为空");
                    }
                }
                else
                {
                    LogHelper.Info($"更新WMS库存明细的入库时间,失败,容器号:{cntId},TN_CG_Detail为空");
                }
            }
            catch (Exception ex)
@@ -396,7 +403,39 @@
            }
            catch (Exception ex)
            {
                LogHelper.Error("更新WMS库存明细的过期时间失败", ex);
                LogHelper.Error("删除WMS库存明细", ex);
            }
        }
        /// <summary>
        /// 计算时间差
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <returns></returns>
        public static int CalculateDaysDifference(DateTime start, DateTime end)
        {
            try
            {
                // 计算总时间差
                TimeSpan difference = end - start;
                // 如果差值为负(end早于start),返回0
                if (difference.TotalDays < 0)
                {
                    return 0;
                }
                // 获取总小时数(包括小数部分)
                double totalHours = difference.TotalHours;
                // 向上取整
                return (int)Math.Ceiling(totalHours);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
    }