/// <summary> /// Handler /// </summary> public void Handler() { ///获取发单状态⑪为10未发单,且发单时间⑨已小于等于当前时间的时间窗窗口时间数据 ///按发单时间⑨从早到晚进行排序,若发单时间⑨相同的情况下按ID排序,如果其中有相同零件类的多条窗口时间数据则以发单时间⑨最晚的一条作为有效数据 List <TwdWindowTimeInfo> twdWindowTimeInfos = new TwdWindowTimeBLL().GetList("" + "[SEND_TIME_STATUS] = " + (int)SendTimeStatusConstants.NoSend + " and " + "[SEND_TIME] <= GETDATE() and " + "[SEND_TIME] = (select max([SEND_TIME]) from [LES].[TT_MPM_TWD_WINDOW_TIME] a with(nolock) " + "where [LES].[TT_MPM_TWD_WINDOW_TIME].[PART_BOX_FID] = a.[PART_BOX_FID])", "[ID]"); if (twdWindowTimeInfos.Count == 0) { return; } ///根据窗口时间中的零件类外键①获取时间窗零件类、同时获取对应的物料拉动信息、注意此处的数据都需要为已启用状态 List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxBLL().GetList("" + "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " + "[FID] in ('" + string.Join("','", twdWindowTimeInfos.Select(d => d.PartBoxFid.GetValueOrDefault()).ToArray()) + "')", string.Empty); if (twdPartBoxInfos.Count == 0) { return; } ///物料拉动信息 List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("" + "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " + "[INHOUSE_PART_CLASS] in ('" + string.Join("','", twdPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "') and " + "[INHOUSE_SYSTEM_MODE] = N'" + (int)PullModeConstants.Twd + "'", string.Empty); if (maintainInhouseLogisticStandardInfos.Count == 0) { return; } ///供应商信息 List <string> supplierNums = twdPartBoxInfos.Where(d => !string.IsNullOrEmpty(d.SupplierNum)).Select(d => d.SupplierNum).ToList(); supplierNums.AddRange(maintainInhouseLogisticStandardInfos.Where(d => !string.IsNullOrEmpty(d.SupplierNum)).Select(d => d.SupplierNum).ToList()); List <SupplierInfo> supplierInfos = new SupplierBLL().GetList("" + "[SUPPLIER_NUM] in ('" + string.Join("','", supplierNums.ToArray()) + "')", string.Empty); ///逐条进行处理 foreach (TwdWindowTimeInfo twdWindowTimeInfo in twdWindowTimeInfos) { ///获取未发单时间窗对应的零件类 TwdPartBoxInfo twdPartBoxInfo = twdPartBoxInfos.FirstOrDefault(d => d.Fid.GetValueOrDefault() == twdWindowTimeInfo.PartBoxFid.GetValueOrDefault()); if (twdPartBoxInfo == null) { continue; } ///获取零件类对应的物料拉动信息 List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandards = maintainInhouseLogisticStandardInfos.Where(d => d.InhousePartClass == twdWindowTimeInfo.PartBoxCode).ToList(); if (maintainInhouseLogisticStandards.Count == 0) { continue; } ///根据已获得的物料拉动信息获取对应的计数器,此处可以直接过滤出其当前计数⑮大于零的数据 List <TwdCounterInfo> twdCounterInfos = new TwdCounterBLL().GetList("" + "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " + "[PART_PULL_FID] in ('" + string.Join("','", maintainInhouseLogisticStandards.Select(d => d.Fid).ToArray()) + "') and " + "isnull([CURRENT_QTY],0) > 0", string.Empty); if (twdCounterInfos.Count == 0) { continue; } ///生成拉动单 StringBuilder @string = new StringBuilder(); @string.AppendLine(CreateTwdPullOrder(twdCounterInfos, twdPartBoxInfo, supplierInfos, twdWindowTimeInfo, maintainInhouseLogisticStandards)); ///数据库语句执行 using (TransactionScope trans = new TransactionScope()) { if (@string.Length > 0) { CommonBLL.ExecuteNonQueryBySql(@string.ToString()); } trans.Complete(); } } }
/// <summary> /// 生成TWD拉动窗口时间 /// </summary> private void TWDHandler() { ///获取所有已启用的零件类,按零件类逐个进行逻辑处理 List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxBLL().GetList("[STATUS] = " + (int)BasicDataStatusConstants.Enable + "", "[ID]"); if (twdPartBoxInfos.Count == 0) { return; } ///TWD窗口时间自动生成延后天数 string twdWindowTimeAutoCreatePostponeDays = new ConfigBLL().GetValueByCode("TWD_WINDOW_TIME_AUTO_CREATE_POSTPONE_DAYS"); if (!int.TryParse(twdWindowTimeAutoCreatePostponeDays, out int intTwdWindowTimeAutoCreatePostponeDays)) { intTwdWindowTimeAutoCreatePostponeDays = 3;///默认为3天 } ///TWD窗口时间参考前提天数 string twdWindowTimeReferenceAdvanceDays = new ConfigBLL().GetValueByCode("TWD_WINDOW_TIME_REFERENCE_ADVANCE_DAYS"); if (!int.TryParse(twdWindowTimeReferenceAdvanceDays, out int intTwdWindowTimeReferenceAdvanceDays)) { intTwdWindowTimeReferenceAdvanceDays = 2;///默认为2天 } ///当前时间 DateTime currentDay = DateTime.Now.Date; StringBuilder sb = new StringBuilder(); ///从提前日期一直获取到延后日期 List <TwdWindowTimeInfo> twdWindowTimeInfos = new TwdWindowTimeBLL().GetList("" + "[WORK_DAY] >= N'" + currentDay.AddDays(0 - intTwdWindowTimeReferenceAdvanceDays) + "' and " + "[WORK_DAY] <= N'" + currentDay.AddDays(intTwdWindowTimeAutoCreatePostponeDays) + "'", string.Empty); if (twdWindowTimeInfos.Count == 0) { return; } foreach (TwdPartBoxInfo twdPartBoxInfo in twdPartBoxInfos) { List <TwdWindowTimeInfo> twdWindowTimes = new List <TwdWindowTimeInfo>(); for (int j = intTwdWindowTimeReferenceAdvanceDays; j > 0; j--) { DateTime workDay = currentDay.AddDays(0 - j); twdWindowTimes = twdWindowTimeInfos.Where(d => d.PartBoxFid.GetValueOrDefault() == twdPartBoxInfo.Fid.GetValueOrDefault() && d.WorkDay.GetValueOrDefault() == workDay).ToList(); if (twdWindowTimes.Count > 0) { break; } } if (twdWindowTimes.Count == 0) { continue; } foreach (TwdWindowTimeInfo twdWindowTime in twdWindowTimes) { for (int i = 0; i < intTwdWindowTimeAutoCreatePostponeDays; i++) { ///累计时间 DateTime createDay = currentDay.AddDays(i); List <TwdWindowTimeInfo> windowTimeInfos = twdWindowTimeInfos.Where(d => d.PartBoxFid.GetValueOrDefault() == twdPartBoxInfo.Fid.GetValueOrDefault() && d.WorkDay.GetValueOrDefault() == createDay).ToList(); if (windowTimeInfos.Count > 0) { continue; } ///提前时间 int advanceTime = twdPartBoxInfo.RequirementAccumulateTime.GetValueOrDefault() + ///需求累积时间 twdPartBoxInfo.LoadTime.GetValueOrDefault() + ///装货时间 twdPartBoxInfo.TransportTime.GetValueOrDefault() + ///运输时间 twdPartBoxInfo.UnloadTime.GetValueOrDefault(); ///卸货时间 ///历史窗口时间 DateTime windowTime = twdWindowTime.WindowTime.GetValueOrDefault(); ///现窗口时间 DateTime createWindowTime = new DateTime(createDay.Year, createDay.Month, createDay.Day, windowTime.Hour, windowTime.Minute, 0); DateTime createSendTime = createWindowTime.AddMinutes(0 - advanceTime); #region TT_MPM_TWD_WINDOW_TIME sb.Append("insert into [LES].[TT_MPM_TWD_WINDOW_TIME] (" + "[FID]," + "[PART_BOX_FID]," + "[PART_BOX_CODE]," + "[PART_BOX_NAME]," + "[PLANT]," + "[WORKSHOP]," + "[ASSEMBLY_LINE]," + "[SUPPLIER_NUM]," + "[WORK_DAY]," + "[SEND_TIME]," + "[WINDOW_TIME]," + "[SEND_TIME_STATUS]," + "[TIME_ZONE]," + "[COMMENTS]," + "[VALID_FLAG]," + "[CREATE_DATE]," + "[CREATE_USER]) values (" + "NEWID()," + "N'" + twdWindowTime.PartBoxFid.GetValueOrDefault() + "'," + "N'" + twdWindowTime.PartBoxCode + "'," + "N'" + twdPartBoxInfo.PartBoxName + "'," + "N'" + twdPartBoxInfo.Plant + "'," + "N'" + twdPartBoxInfo.Workshop + "'," + "N'" + twdPartBoxInfo.AssemblyLine + "'," + "N'" + twdPartBoxInfo.SupplierNum + "'," + "N'" + createDay + "'," + "N'" + createSendTime + "'," + "N'" + createWindowTime + "'," + "" + (int)SendTimeStatusConstants.NoSend + "," + "N'" + twdWindowTime.TimeZone + "'," + "NULL," + "1," + "GETDATE()," + "N'" + loginUser + "');"); #endregion } } } ///执行 using (TransactionScope trans = new TransactionScope()) { if (sb.Length > 0) { BLL.LES.CommonBLL.ExecuteNonQueryBySql(sb.ToString()); } trans.Complete(); } }