Example #1
0
        /// <summary>
        /// Handler
        /// </summary>
        public void Handler()
        {
            ///获取已启用计划零件类集合
            List <PlanPartBoxInfo> planPartBoxInfos = new PlanPartBoxBLL().GetList("[STATUS] = " + (int)BasicDataStatusConstants.Enable + "", string.Empty);

            if (planPartBoxInfos.Count == 0)
            {
                throw new Exception("3x00000023");///没有已启用的计划拉动零件类
            }
            ///获取零件类对应物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos
                = new MaintainInhouseLogisticStandardBLL().GetList("[INHOUSE_PART_CLASS] in ('" + string.Join("','", planPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "') and [STATUS] = " + (int)BasicDataStatusConstants.Enable + " and [INHOUSE_SYSTEM_MODE]=N'60'", string.Empty);

            if (maintainInhouseLogisticStandardInfos.Count == 0)
            {
                throw new Exception("0x00000233");///没有已启用的物料拉动信息
            }
            ///循环零件类集合
            foreach (PlanPartBoxInfo planPartBoxInfo in planPartBoxInfos)
            {
                #region 基础变量
                ///窗口时间
                string windowTimes = string.Empty;
                ///当前窗口时间
                DateTime currentWindowTime = DateTime.MinValue;
                ///下一窗口时间
                DateTime nextWindowTime = DateTime.MaxValue;
                ///时区
                string      timeZone    = string.Empty;
                List <long> planTimeIds = new List <long>();
                ///范围 工厂、车间、产线
                string sqlwhere = string.Empty;
                if (!string.IsNullOrEmpty(planPartBoxInfo.AssemblyLine))
                {
                    sqlwhere = "and [ASSEMBLY_LINE] = N'" + planPartBoxInfo.AssemblyLine + "' ";
                }
                else
                {
                    sqlwhere = "and [WERK] = N'" + planPartBoxInfo.Plant + "' ";
                }
                #endregion

                #region 获取生产订单BOM集合
                ///通过这些生产订单号①=①获取订单BOM(TT_BAS_PULL_ORDER_BOM)
                List <PullOrderBomInfo> pullOrderBomInfos = new List <PullOrderBomInfo>();
                ///生产订单集合
                List <PullOrdersInfo> pullOrdersInfos = new List <PullOrdersInfo>();
                ///获取零件类对应的最近一次未发单窗口时间

                ///当此参数为true时以计划拉动窗口时间TT_MPM_PLAN_WINDOW_TIME中发单状态⑥为10.未发单且发单时间④已早于当前时间作为当前执行依据
                if (planPullWindowTimeEnable.ToLower() == "true")
                {
                    PlanWindowTimeInfo planWindowTimeInfo = new PlanWindowTimeBLL().GetLastNoSendTimeInfo(planPartBoxInfo.Fid.GetValueOrDefault());
                    ///并根据窗口时间⑤匹配生产订单计划执行时间同时核对未生成计划拉动单的生产订单(先以小于等于窗口时间作为条件再加上TT_MPM_PLAN_PULL_CREATE_STATUS表的SEQID not exist条件进行过滤)
                    ///如果没有符合条件的窗口时间,则执行下一个零件类
                    if (planWindowTimeInfo == null)
                    {
                        continue;
                    }
                    if (planWindowTimeInfo.WindowTime == null)
                    {
                        continue;
                    }
                    planTimeIds.Add(planWindowTimeInfo.Id);
                    currentWindowTime = planWindowTimeInfo.WindowTime.GetValueOrDefault();
                    ///窗口时间
                    windowTimes = currentWindowTime.ToString("MM:dd");
                    ///时区为窗口时间中设定的时间
                    timeZone       = planWindowTimeInfo.TimeZone;
                    nextWindowTime = new PlanWindowTimeBLL().GetNextWindowTime(planPartBoxInfo.Fid.GetValueOrDefault(), currentWindowTime);
                    ///获取未处理生产订单对应的BOM
                    pullOrderBomInfos = new PullOrderBomBLL().GetUnPlanPullingOrders(currentWindowTime, nextWindowTime, sqlwhere, planPartBoxInfo.Fid.GetValueOrDefault());
                }
                ///若为false时以计划当日零点作为交付时间依据并根据零件类中设定的时间合计⑫+⑬+⑭扣减后作为发单时间
                ///并根据计划当日零点(大于等于)与计划次日零点(小于)之间同时核对未生成计划拉动单的生产订单
                else if (planPullWindowTimeEnable.ToLower() == "false")
                {
                    ///获取计划拉动提前期(分钟)
                    int sumLeadTime = planPartBoxInfo.DelayTime.GetValueOrDefault()
                                      + planPartBoxInfo.DeliveryTime.GetValueOrDefault()
                                      + planPartBoxInfo.PickUpTime.GetValueOrDefault();
                    ///根据提前期用当前时间向后推得窗口时间的零点
                    currentWindowTime = DateTime.Parse(DateTime.Now.AddMinutes(sumLeadTime).ToShortDateString());
                    ///下一窗口时间为次日零点
                    nextWindowTime = currentWindowTime.AddDays(1);
                    ///获取未处理生产订单对应的BOM
                    pullOrderBomInfos = new PullOrderBomBLL().GetUnPlanPullingOrders(currentWindowTime, nextWindowTime, sqlwhere, planPartBoxInfo.Fid.GetValueOrDefault());
                    ///拼接窗口时间
                    List <DateTime> planWindowTimes = new PlanWindowTimeBLL().GetWindowTimesByWorkDay(planPartBoxInfo.Fid.GetValueOrDefault(), currentWindowTime);
                    if (planWindowTimes.Count > 0)
                    {
                        windowTimes = string.Join(",", planWindowTimes.Select(d => d.ToString("HH:mm")).ToArray());
                    }
                    ///拼接时区
                    List <PlanWindowTimeInfo> PlanWindowTimeInfos = new PlanWindowTimeBLL().GetList("", "WINDOW_TIME");
                    if (PlanWindowTimeInfos.Count > 0)
                    {
                        foreach (var p in PlanWindowTimeInfos)
                        {
                            planTimeIds.Add(p.Id);
                        }
                        timeZone = string.Join(",", PlanWindowTimeInfos.Select(d => d.TimeZone).ToArray());
                    }
                }
                else
                {
                    throw new Exception("1x00000045");///系统配置参数错误
                }
                #endregion

                #region 处理集合取交集
                ///根据物料号、供应商、工厂将BOM分组并计算数量
                var pullOrderBomQuery = pullOrderBomInfos
                                        .GroupBy(b => new { b.Zcomno, b.SupplierNum, b.Zkwerk })
                                        .Select(p => new { PartNo = p.Key.Zcomno, p.Key.SupplierNum, Plant = p.Key.Zkwerk, Zqty = p.Sum(x => x.Zqty.GetValueOrDefault()) }).ToList();
                ///获取零件类对应的物料拉动信息
                var maintainInhouseLogisticStandardQuery = maintainInhouseLogisticStandardInfos.Where(d => d.InhousePartClass == planPartBoxInfo.PartBoxCode).ToList();
                ///校验是否全部维护了入库单包装数量,否则除数为零时程序会报错
                int cnt = maintainInhouseLogisticStandardQuery.Count(d => d.InboundPackage.GetValueOrDefault() == 0);
                if (cnt > 0)
                {
                    throw new Exception("3x00000024");///物料拉动信息中入库单包装数量未维护
                }
                ///并将计划零件类对应的物料拉动信息与订单BOM的交集部分作为计划拉动物料需求(比对依据为物料号②、供应商代码③、工厂)
                var materialRequirementInfos = (from m in maintainInhouseLogisticStandardQuery
                                                join b in pullOrderBomQuery
                                                on new { m.PartNo, m.SupplierNum, m.Plant }
                                                equals new { b.PartNo, b.SupplierNum, b.Plant }
                                                select new
                {
                    m.PartNo,                                                                                ///物料号
                    m.SupplierNum,                                                                           ///供应商代码
                    m.Plant,                                                                                 ///工厂代码
                    m.PartCname,                                                                             ///物料中文描述
                    m.PartEname,                                                                             ///物料英文描述
                    m.PartUnits,                                                                             ///计量单位
                    m.InboundPackage,                                                                        ///入库单包装数量
                    m.InboundPackageModel,                                                                   ///入库包装型号
                    RequirePackageQty = Math.Ceiling((b.Zqty * 1.0) / m.InboundPackage.GetValueOrDefault()), ///需求包装数
                    b.Zqty                                                                                   ///需求物料数量
                }).ToList();
                #endregion

                ///生成单据时为了保障效率需要拼接整个insert语句后提交至数据库执行
                StringBuilder sql = new StringBuilder();
                ///检验模式
                if (inspectionModeDistinguishOrderFlag.ToLower() == "true")
                {
                    ///获取所有涉及的检验模式
                    List <PartInspectionModeInfo> partInspectionModeInfos
                        = new PartInspectionModeBLL().GetList("" +
                                                              "[PART_NO] in ('" + string.Join("','", materialRequirementInfos.Select(d => d.PartNo).ToArray()) + "') and " +
                                                              "[SUPPLIER_NUM] in ('" + string.Join("','", materialRequirementInfos.Select(d => d.SupplierNum).ToArray()) + "')", string.Empty);
                    ///给物料需求的集合赋予检验模式
                    var partInspectionmaterialRequirementInfos = (from m in materialRequirementInfos
                                                                  join p in partInspectionModeInfos
                                                                  on new { m.PartNo, m.SupplierNum }
                                                                  equals new { p.PartNo, p.SupplierNum } into g
                                                                  select new
                    {
                        m.PartNo,                                                                         ///物料号
                        m.SupplierNum,                                                                    ///供应商代码
                        m.Plant,                                                                          ///工厂代码
                        m.PartCname,                                                                      ///物料中文描述
                        m.PartEname,                                                                      ///物料英文描述
                        m.PartUnits,                                                                      ///计量单位
                        m.InboundPackage,                                                                 ///入库单包装数量
                        m.InboundPackageModel,                                                            ///入库包装型号
                        m.RequirePackageQty,                                                              ///需求包装数
                        m.Zqty,                                                                           ///需求物料数量
                        Inspection = g.Select(d => d.InspectionMode.GetValueOrDefault()).FirstOrDefault() ///物料检验
                    }).ToList();
                    #region 免检
                    ///免检
                    var exemptionInspectionMaterialRequirementInfos = partInspectionmaterialRequirementInfos.Where(d => d.Inspection == (int)InspectionModeConstants.ExemptionInspection).ToList();
                    ///生成计划拉动单同时记录该生产订单该计划零件类已生成单据
                    ///当有物料需求时,才会生成计划拉动单
                    if (exemptionInspectionMaterialRequirementInfos.Count > 0)
                    {
                        ///实例化主表Guid
                        Guid planPullOrderFid = Guid.NewGuid();
                        ///主表计划拉动单号
                        string orderCode = new SeqDefineBLL().GetCurrentCode("PLAN_PULL_ORDER_CODE", planPartBoxInfo.PartBoxCode.Substring(0, 1).ToUpper());///TODO:计划拉动单编号规则可能还会更改,待客户确认

                        MaterialPullingOrderInfo materialPullingOrderInfo = CreateMaterialPullingOrderInfo(planPartBoxInfo, orderCode, currentWindowTime, true);
                        materialPullingOrderInfo.MaterialPullingOrderDetailInfos = (from m in exemptionInspectionMaterialRequirementInfos
                                                                                    select new MaterialPullingOrderDetailInfo
                        {
                            OrderNo = orderCode,                                                          ///拉动单号1
                            SupplierNum = m.SupplierNum,                                                  ///供应商2
                            PartNo = m.PartNo,                                                            ///物料号3
                            PartCname = m.PartCname,                                                      ///物料号中文名称4
                            PartEname = m.PartEname,                                                      ///物料号英文名称5
                            Uom = m.PartUnits,                                                            ///计量单位6
                            PackageQty = m.InboundPackage.GetValueOrDefault(),                            ///入库单包装数量7
                            PackageModel = m.InboundPackageModel,                                         ///入库包装编号8
                            RequirePackageQty = Convert.ToInt32(m.RequirePackageQty),                     ///需求包装数量9
                            RequirePartQty = m.Zqty,                                                      ///需求物料数量10
                            TargetZoneNo = planPartBoxInfo.TargetZoneNo,
                            InspectMode = m.Inspection                                                    ///校验模式
                        }).ToList();

                        sql.AppendLine(CreatePlanPullOrderSql(planPullOrderFid, materialPullingOrderInfo, windowTimes, timeZone, (int)InspectionFlagConstants.Exemption));
                        sql.AppendLine(CreatePlanPullOrderDetailSql(planPullOrderFid, materialPullingOrderInfo.MaterialPullingOrderDetailInfos));
                        sql.AppendFormat(MaterialPullingCommonBLL.Handler(materialPullingOrderInfo, loginUser));
                    }
                    #endregion

                    #region  免检
                    ///不免检
                    var inspectionmaterialRequirementInfos = partInspectionmaterialRequirementInfos.Where(d => d.Inspection != (int)InspectionModeConstants.ExemptionInspection).ToList();
                    ///生成计划拉动单同时记录该生产订单该计划零件类已生成单据
                    ///当有物料需求时,才会生成计划拉动单
                    if (inspectionmaterialRequirementInfos.Count > 0)
                    {
                        ///实例化主表Guid
                        Guid planPullOrderFid = Guid.NewGuid();
                        ///主表计划拉动单号
                        string orderCode = new SeqDefineBLL().GetCurrentCode("PLAN_PULL_ORDER_CODE", planPartBoxInfo.PartBoxCode.Substring(0, 1).ToUpper());///TODO:计划拉动单编号规则可能还会更改,待客户确认

                        MaterialPullingOrderInfo materialPullingOrderInfo = CreateMaterialPullingOrderInfo(planPartBoxInfo, orderCode, currentWindowTime, false);
                        materialPullingOrderInfo.MaterialPullingOrderDetailInfos = (from m in inspectionmaterialRequirementInfos
                                                                                    select new MaterialPullingOrderDetailInfo
                        {
                            OrderNo = orderCode,                                                          ///拉动单号1
                            SupplierNum = m.SupplierNum,                                                  ///供应商2
                            PartNo = m.PartNo,                                                            ///物料号3
                            PartCname = m.PartCname,                                                      ///物料号中文名称4
                            PartEname = m.PartEname,                                                      ///物料号英文名称5
                            Uom = m.PartUnits,                                                            ///计量单位6
                            PackageQty = m.InboundPackage.GetValueOrDefault(),                            ///入库单包装数量7
                            PackageModel = m.InboundPackageModel,                                         ///入库包装编号8
                            RequirePackageQty = Convert.ToInt32(m.RequirePackageQty),                     ///需求包装数量9
                            RequirePartQty = m.Zqty,                                                      ///需求物料数量10
                            TargetZoneNo = planPartBoxInfo.TargetZoneNo,
                            InspectMode = m.Inspection                                                    ///校验模式
                        }).ToList();
                        ///
                        sql.AppendLine(CreatePlanPullOrderSql(planPullOrderFid, materialPullingOrderInfo, windowTimes, timeZone, (int)InspectionFlagConstants.Inspect));
                        sql.AppendLine(CreatePlanPullOrderDetailSql(planPullOrderFid, materialPullingOrderInfo.MaterialPullingOrderDetailInfos));
                        sql.AppendFormat(MaterialPullingCommonBLL.Handler(materialPullingOrderInfo, loginUser));
                    }
                    #endregion
                }
                else
                {
                    ///生成计划拉动单同时记录该生产订单该计划零件类已生成单据
                    ///当有物料需求时,才会生成计划拉动单
                    if (materialRequirementInfos.Count > 0)
                    {
                        ///实例化主表Guid
                        Guid planPullOrderFid = Guid.NewGuid();
                        ///主表计划拉动单号
                        string orderCode = new SeqDefineBLL().GetCurrentCode("PLAN_PULL_ORDER_CODE", planPartBoxInfo.PartBoxCode.Substring(0, 1).ToUpper());///TODO:计划拉动单编号规则可能还会更改,待客户确认

                        MaterialPullingOrderInfo materialPullingOrderInfo = CreateMaterialPullingOrderInfo(planPartBoxInfo, orderCode, currentWindowTime, false);
                        materialPullingOrderInfo.MaterialPullingOrderDetailInfos = (from m in materialRequirementInfos
                                                                                    select new MaterialPullingOrderDetailInfo
                        {
                            OrderNo = orderCode,                                                          ///拉动单号1
                            SupplierNum = m.SupplierNum,                                                  ///供应商2
                            PartNo = m.PartNo,                                                            ///物料号3
                            PartCname = m.PartCname,                                                      ///物料号中文名称4
                            PartEname = m.PartEname,                                                      ///物料号英文名称5
                            Uom = m.PartUnits,                                                            ///计量单位6
                            PackageQty = m.InboundPackage.GetValueOrDefault(),                            ///入库单包装数量7
                            PackageModel = m.InboundPackageModel,                                         ///入库包装编号8
                            RequirePackageQty = Convert.ToInt32(m.RequirePackageQty),                     ///需求包装数量9
                            RequirePartQty = m.Zqty,                                                      ///需求物料数量10
                            TargetZoneNo = planPartBoxInfo.TargetZoneNo
                        }).ToList();
                        ///生成计划拉动单
                        sql.AppendLine(CreatePlanPullOrderSql(planPullOrderFid, materialPullingOrderInfo, windowTimes, timeZone, null));
                        ///生成计划拉动单明细
                        sql.AppendLine(CreatePlanPullOrderDetailSql(planPullOrderFid, materialPullingOrderInfo.MaterialPullingOrderDetailInfos));
                        ///单据衔接
                        sql.AppendLine(MaterialPullingCommonBLL.Handler(materialPullingOrderInfo, loginUser));
                    }
                }
                ///订单BOM存在时才需要更新
                if (pullOrderBomInfos.Count > 0)
                {
                    ///更新中间表处理状态 = 已处理
                    sql.AppendFormat("update [LES].[TT_MPM_PLAN_PULL_CREATE_STATUS] set " +
                                     "[STATUS] = " + (int)ProcessFlagConstants.Processed + "," +
                                     "[MODIFY_USER] = N'" + loginUser + "'," +
                                     "[MODIFY_DATE] = GETDATE() where " +
                                     "[VALID_FLAG] = 1 and " +
                                     "[PART_BOX_FID] = N'{0}' and " +
                                     "[ORDER_FID] in ('{1}');",
                                     planPartBoxInfo.Fid.GetValueOrDefault(),
                                     string.Join("','", pullOrderBomInfos.Select(d => d.Orderfid.GetValueOrDefault()).ToArray()));
                }

                #region 执行
                if (sql.Length > 0)
                {
                    ///更改窗口时间发单状态
                    if (planPullWindowTimeEnable.ToLower() == "true")
                    {
                        sql.AppendFormat("update [LES].[TT_MPM_PLAN_WINDOW_TIME] set " +
                                         "[SEND_TIME_STATUS] = " + (int)SendTimeStatusConstants.Sent + "," +
                                         "[MODIFY_USER] = N'" + loginUser + "'," +
                                         "[MODIFY_DATE] = GETDATE() where [ID] in (" + string.Join(",", planTimeIds.ToArray()) + ");");
                    }
                    using (TransactionScope trans = new TransactionScope())
                    {
                        if (!BLL.LES.CommonBLL.ExecuteNonQueryBySql(sql.ToString()))
                        {
                            throw new Exception("0x00000736");///写入数据库失败
                        }
                        trans.Complete();
                    }
                }
                #endregion
            }
            #endregion
        }
        /// <summary>
        /// Handler
        /// </summary>
        public void Handler()
        {
            ///获取状态为待处理的车辆状态信息,其中类型为正常过点、校验补入、车辆归队
            List <VehiclePointStatusInfo> vehiclePointStatusInfos = new VehiclePointStatusBLL().GetList("" +
                                                                                                        "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + " and " +
                                                                                                        "[VEHICLE_STATUS] in (" + (int)VehicleStatusTypeConstants.NormalPoint + "," + (int)VehicleStatusTypeConstants.CheckAndFill + "," + (int)VehicleStatusTypeConstants.VehicleReturn + ")", "[ID]");

            if (vehiclePointStatusInfos.Count == 0)
            {
                return;
            }

            #region TWD 计数器及基础数据获取
            ///根据状态点代码获取时间窗零件类中需求累计方式㉒为过点且状态为已启用⑭的数据
            List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxBLL().GetList("" +
                                                                                "[REQUIREMENT_ACCUMULATE_MODE] = " + (int)RequirementAccumulateModeConstants.PassSpot + " and " +
                                                                                "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                "[STATUS_POINT_CODE] in ('" + string.Join("','", vehiclePointStatusInfos.Select(d => d.StatusPointCode).ToArray()) + "')", string.Empty);
            ///物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> twdMaintainInhouseLogisticStandardInfos = new List <MaintainInhouseLogisticStandardInfo>();
            if (twdPartBoxInfos.Count > 0)
            {
                ///同时获取这些零件类下对应的已启用的物料拉动信息
                twdMaintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("" +
                                                                                                           "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                                           "[INHOUSE_SYSTEM_MODE] = N'" + (int)PullModeConstants.Twd + "' and " +
                                                                                                           "[INHOUSE_PART_CLASS] in ('" + string.Join("','", twdPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "')", string.Empty);
            }
            #endregion

            #region JIS 计数器及基础数据获取
            ///根据状态点代码获取排序零件类中状态㉖为已启用的数据
            List <JisPartBoxInfo> jisPartBoxInfos = new JisPartBoxBLL().GetList("" +
                                                                                "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                "[STATUS_POINT_CODE] in ('" + string.Join("','", vehiclePointStatusInfos.Select(d => d.StatusPointCode).ToArray()) + "')", string.Empty);
            ///物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> jisMaintainInhouseLogisticStandardInfos = new List <MaintainInhouseLogisticStandardInfo>();
            if (jisPartBoxInfos.Count > 0)
            {
                ///同时获取这些零件类下对应的已启用的物料拉动信息
                jisMaintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("" +
                                                                                                           "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                                           "[INHOUSE_SYSTEM_MODE] = N'" + (int)PullModeConstants.Jis + "' and " +
                                                                                                           "[INHOUSE_PART_CLASS] in ('" + string.Join("','", jisPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "')", string.Empty);
            }
            #endregion

            foreach (VehiclePointStatusInfo vehiclePointStatusInfo in vehiclePointStatusInfos)
            {
                ///执行语句
                StringBuilder stringBuilder = new StringBuilder();
                ///TWD
                if (twdPartBoxInfos.Count > 0 && twdMaintainInhouseLogisticStandardInfos.Count > 0)
                {
                    stringBuilder.AppendLine(TwdCounterDeal(vehiclePointStatusInfo, twdPartBoxInfos, twdMaintainInhouseLogisticStandardInfos));
                }
                ///JIS
                if (jisPartBoxInfos.Count > 0 && jisMaintainInhouseLogisticStandardInfos.Count > 0)
                {
                    stringBuilder.AppendLine(JisCounterDeal(vehiclePointStatusInfo, jisPartBoxInfos, jisMaintainInhouseLogisticStandardInfos));
                }
                ///单条车辆状态全部类型计数器更新完成后标记其状态为已处理
                stringBuilder.AppendLine("update [LES].[TT_BAS_VEHICLE_POINT_STATUS] set " +
                                         "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                         "[MODIFY_DATE] = GETDATE()," +
                                         "[MODIFY_USER] = N'" + loginUser + "' where " +
                                         "[ID]= " + vehiclePointStatusInfo.Id + ";");
                ///数据库语句执行
                using (TransactionScope trans = new TransactionScope())
                {
                    CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString());
                    trans.Complete();
                }
            }
        }
        /// <summary>
        /// Handler
        /// </summary>
        public void Handler()
        {
            ///获取排序零件类中状态㉖为已启用的数据
            List <JisPartBoxInfo> jisPartBoxInfos = new JisPartBoxBLL().GetList(" and [STATUS] =" + (int)BasicDataStatusConstants.Enable + "", string.Empty);

            if (jisPartBoxInfos.Count == 0)
            {
                return;
            }
            ///获取零件类对应的计数器
            List <JisCounterInfo> jisCounterInfos = new JisCounterBLL().GetList("and [PART_BOX_FID] in ('" + string.Join("','", jisPartBoxInfos.Select(d => d.Fid).ToArray()) + "')", string.Empty);

            if (jisCounterInfos.Count == 0)
            {
                return;
            }
            ///对应的排序计数器日志
            List <JisCounterLogInfo> jisCounterLogInfos = new JisCounterLogBLL().GetList("and [COUNTER_FID] in ('" + string.Join("','", jisCounterInfos.Select(d => d.Fid).ToArray()) + "')", string.Empty);

            if (jisCounterLogInfos.Count == 0)
            {
                return;
            }
            ///计数器日志对应的生产订单
            List <PullOrdersInfo> pullOrdersInfos = new PullOrdersBLL().GetList("and [ORDER_NO] in ('" + string.Join("','", jisCounterLogInfos.Select(d => d.SourceData).ToArray()) + "')", string.Empty);

            if (pullOrdersInfos.Count == 0)
            {
                return;
            }
            ///对应的物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("and [STATUS] =" + (int)BasicDataStatusConstants.Enable + ""
                                                                                                                                               + " and [INHOUSE_PART_CLASS] in ('" + string.Join("','", jisPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "')"
                                                                                                                                               + " and [PART_NO] in ('" + string.Join("','", jisCounterLogInfos.Select(d => d.PartNo).ToArray()) + "')", string.Empty);

            if (maintainInhouseLogisticStandardInfos.Count == 0)
            {
                return;
            }
            foreach (JisPartBoxInfo jisPartBoxInfo in jisPartBoxInfos)
            {
                ///零件类对应的物料拉动信息
                List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandards = maintainInhouseLogisticStandardInfos.Where(d => d.InhousePartClass == jisPartBoxInfo.PartBoxCode).ToList();
                ///计数器
                List <JisCounterInfo> jisCounters = new List <JisCounterInfo>();
                ///获取状态为20.累计完成的排序计数器
                jisCounters = jisCounterInfos.Where(d => d.Status == (int)JisCounterStatusConstants.AccumulativeCompletion && d.PartBoxFid == jisPartBoxInfo.Fid).ToList();
                ///若此时未能成功获取到状态为20.累计完成的排序计数器时,需要获取状态为10.正在累计的排序计数器,判断其创建时间加上最大累积时间是否已超过当前时间
                if (jisCounters.Count == 0)
                {
                    jisCounters = jisCounterInfos.Where(d => d.Status == (int)JisCounterStatusConstants.Accumulating && d.PartBoxFid == jisPartBoxInfo.Fid && d.CreateDate.AddMinutes(jisPartBoxInfo.MaxAccumulativeTime.GetValueOrDefault()) > DateTime.Now).ToList();
                }
                if (jisCounters.Count == 0)
                {
                    continue;
                }
                ///若已超过则需要首先标记排序计数器状态为20.累计完成,之后的逻辑按部就班走
                BLL.LES.CommonBLL.ExecuteNonQueryBySql(@"update[LES].[TT_MPM_JIS_COUNTER] set [STATUS]=" + (int)JisCounterStatusConstants.AccumulativeCompletion + ",[MODIFY_DATE] = getdate(),[MODIFY_USER] = '" + loginUser + "' where [ID] in (" + string.Join(",", jisCounters.Select(d => d.Id).ToArray()) + ");");
                ///根据计数器生成拉动单
                foreach (JisCounterInfo jisCounterInfo in jisCounters)
                {
                    ///sql
                    StringBuilder stringBuilder = new StringBuilder();
                    ///对应的排序计数器日志
                    List <JisCounterLogInfo> jisCounterLogs = jisCounterLogInfos.Where(d => d.CounterFid == jisCounterInfo.Fid).ToList();
                    if (jisCounterLogs.Count == 0)
                    {
                        continue;
                    }
                    ///计数器日志物料对应的物料拉动信息
                    List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogistics = (from maintainInhouseLogisticStandard in maintainInhouseLogisticStandards
                                                                                           join jisCounterLog in jisCounterLogs
                                                                                           on maintainInhouseLogisticStandard.PartNo equals jisCounterLog.PartNo
                                                                                           select maintainInhouseLogisticStandard).ToList();
                    if (maintainInhouseLogistics.Count == 0)
                    {
                        continue;
                    }
                    switch (jisPartBoxInfo.JisPullMode.GetValueOrDefault())
                    {
                    ///排序拉动
                    case (int)JisPullModeConstants.JisPull:
                        stringBuilder.AppendFormat(JisPull(jisPartBoxInfo, jisCounterInfo, jisCounterLogs, maintainInhouseLogistics, pullOrdersInfos, true));
                        break;

                    ///物料成套拉动
                    case (int)JisPullModeConstants.CompletePull:
                        stringBuilder.AppendFormat(JisPull(jisPartBoxInfo, jisCounterInfo, jisCounterLogs, maintainInhouseLogistics, pullOrdersInfos, false));
                        break;

                    default: continue;
                    }
                    ///数据库执行语句
                    if (stringBuilder.Length > 0)
                    {
                        stringBuilder.AppendFormat(@"update[LES].[TT_MPM_JIS_COUNTER] set [STATUS]=" + (int)JisCounterStatusConstants.GeneratedDocuments + ",[MODIFY_DATE] = getdate(),[MODIFY_USER] = '" + loginUser + "' where [ID] = " + jisCounterInfo.Id + "; ");
                        using (TransactionScope trans = new TransactionScope())
                        {
                            BLL.LES.CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString());
                            trans.Complete();
                        }
                    }
                }
            }
        }
Example #4
0
        /// <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>
        /// 主函数
        /// </summary>
        public void Handler()
        {
            ///获取需求累计方式㉒为库存当量的零件类TM_MPM_TWD_PART_BOX
            List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxBLL().GetList("" +
                                                                                "[REQUIREMENT_ACCUMULATE_MODE] = " + (int)RequirementAccumulateModeConstants.InventoryEquivalent + " and " +
                                                                                "[STATUS] = " + (int)BasicDataStatusConstants.Enable + "", string.Empty);

            if (twdPartBoxInfos.Count == 0)
            {
                return;
            }
            ///同时获取对应的物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("" +
                                                                                                                                               "[STATUS] = " + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                                                                               "[INHOUSE_SYSTEM_MODE] = N'" + (int)PullModeConstants.Twd + "' and " +
                                                                                                                                               "[INHOUSE_PART_CLASS] in ('" + string.Join("','", twdPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "')", string.Empty);

            if (maintainInhouseLogisticStandardInfos.Count == 0)
            {
                return;
            }
            ///根据物料拉动信息中的工厂③目标仓库⑩存储区⑪和物料号获取库存数据
            List <StocksInfo> stocksInfos = new StocksBLL().GetList("" +
                                                                    "[PLANT] in ('" + string.Join("','", maintainInhouseLogisticStandardInfos.Select(d => d.Plant).ToArray()) + "') and " +
                                                                    "[WM_NO] in ('" + string.Join("','", maintainInhouseLogisticStandardInfos.Select(d => d.TWmNo).ToArray()) + "') and " +
                                                                    "[ZONE_NO] in ('" + string.Join("','", maintainInhouseLogisticStandardInfos.Select(d => d.TZoneNo).ToArray()) + "') and " +
                                                                    "[PART_NO] in ('" + string.Join("','", maintainInhouseLogisticStandardInfos.Select(d => d.PartNo).ToArray()) + "')", string.Empty);

            StringBuilder stringBuilder = new StringBuilder();

            ///以零件类进行循环
            foreach (TwdPartBoxInfo twdPartBoxInfo in twdPartBoxInfos)
            {
                ///获取零件类对应的物料拉动信息
                List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandards = maintainInhouseLogisticStandardInfos.Where(d => d.InhousePartClass == twdPartBoxInfo.PartBoxCode).ToList();
                if (maintainInhouseLogisticStandards.Count == 0)
                {
                    continue;
                }
                ///物料拉动信息
                foreach (MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandard in maintainInhouseLogisticStandards)
                {
                    ///当系统配置中库存供应商维度标记 = true时,在过滤库存数据时需要考虑供应商
                    ///若物料拉动信息中未维护供应商信息则不考虑,因为两个标记同时符合时才会考虑
                    string supplierNum = string.Empty;
                    if (supplier_stocks_dimension.ToLower() == "true" && !string.IsNullOrEmpty(maintainInhouseLogisticStandard.SupplierNum))
                    {
                        supplierNum = maintainInhouseLogisticStandard.SupplierNum;
                    }
                    ///将工厂③目标仓库⑩存储区⑪物料号或增加供应商维度的过滤完成的库存数据集合中的可用数量进行汇总
                    ///当前库存
                    decimal avaibleQty = new StocksBLL().GetAvailbleQty(
                        maintainInhouseLogisticStandard.PartNo,
                        maintainInhouseLogisticStandard.TWmNo,
                        maintainInhouseLogisticStandard.TZoneNo,
                        supplierNum);
                    ///根据获得的物料拉动信息外键获取计数器
                    TwdCounterInfo twdCounterInfo = TwdCounterBLL.GetInfoByPartPullFid(maintainInhouseLogisticStandard.Fid);
                    if (twdCounterInfo == null)
                    {
                        ///创建计数器
                        twdCounterInfo = TwdCounterBLL.CreateTwdCounterInfo(loginUser);
                        ///以物料拉动信息填充计数器
                        TwdCounterBLL.GetTwdCounterInfo(maintainInhouseLogisticStandard, ref twdCounterInfo);
                        ///以零件类信息填充计数器
                        TwdCounterBLL.GetTwdCounterInfo(twdPartBoxInfo, ref twdCounterInfo);
                        ///
                        twdCounterInfo.Id = new TwdCounterBLL().InsertInfo(twdCounterInfo);
                        if (twdCounterInfo.Id == 0)
                        {
                            throw new Exception("MC:0x00000453");///时间窗计数器创建失败
                        }
                    }
                    ///计数器状态未处于启用
                    if (twdCounterInfo.Status != (int)BasicDataStatusConstants.Enable)
                    {
                        continue;
                    }
                    ///在途库存,已累积 + 已生成未完成TODO:
                    decimal onroadQty = twdCounterInfo.CurrentQty.GetValueOrDefault();
                    ///当可用数量小于等于物料拉动信息中的拉动最小值时,将拉动最大值减去汇总数量得到的则为本次需求数量
                    if (avaibleQty + onroadQty > maintainInhouseLogisticStandard.Min.GetValueOrDefault())
                    {
                        continue;
                    }
                    ///本次需求数量
                    decimal requireQty = maintainInhouseLogisticStandard.Max.GetValueOrDefault() - avaibleQty - onroadQty;
                    ///
                    stringBuilder.AppendLine(TwdCounterBLL.UpdateTwdCounter(maintainInhouseLogisticStandard, twdPartBoxInfo, requireQty, twdCounterInfo.Id, loginUser));
                    ///创建计数器日志
                    TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);
                    ///以物料拉动信息填充计数器日志
                    TwdCounterLogBLL.GetTwdCounterLogInfo(maintainInhouseLogisticStandard, ref twdCounterLogInfo);
                    ///以零件类信息填充计数器日志
                    TwdCounterLogBLL.GetTwdCounterLogInfo(twdPartBoxInfo, ref twdCounterLogInfo);
                    ///PART_QTY
                    twdCounterLogInfo.PartQty = requireQty;
                    ///SOURCE_DATA_FID
                    twdCounterLogInfo.SourceDataFid = Guid.Empty;
                    ///SOURCE_DATA_TYPE
                    twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.Inventory;
                    ///SOURCE_DATA ,供应商|当前可用|在途数量
                    twdCounterLogInfo.SourceData = supplierNum + "|" + avaibleQty + "|" + onroadQty;
                    ///
                    stringBuilder.AppendLine(TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo));
                    ///触发层级拉动
                    stringBuilder.AppendLine(TwdCounterBLL.LevelPullRequirementCounter(
                                                 maintainInhouseLogisticStandard,
                                                 requireQty,
                                                 loginUser,
                                                 twdCounterInfo.Fid.GetValueOrDefault(),
                                                 twdCounterInfo.PartBoxCode));
                }
                ///数据库执行
                using (TransactionScope trans = new TransactionScope())
                {
                    if (stringBuilder.Length > 0)
                    {
                        BLL.LES.CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString());
                    }
                    trans.Complete();
                }
                stringBuilder.Clear();
            }
        }