/// <summary>
        /// 看板生成拉动单
        /// </summary>
        /// <param name="cardNos"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public bool CreateKanbanPullOrder(List <String> cardNos, string loginUser, bool isFilterLoginUser = false)
        {
            if (cardNos.Count == 0)
            {
                throw new Exception("MC:3x00000011");///看板卡数据不能为空
            }
            #region 初始化SQL脚本
            ///主表字符串
            string sqlKanbanPullOrder = @"insert into [LES].[TT_MPM_KANBAN_PULL_ORDER] (
                FID,
                ORDER_CODE,
				PART_BOX_CODE,
				PART_BOX_NAME,
				ROUTE_CODE,
				ROUTE_NAME,
				SOURCE_ZONE_NO,
				SOURCE_WM_NO,
				TARGET_ZONE_NO,
				TARGET_WM_NO,
				PICK_UP_FINISH_TIME,
				PICK_UP_USER,
				DELIVERY_FINISH_TIME,
				DELIVERY_USER,
				PRINT_CNT,
				PRINT_TIME,
				PRINT_USER,
				STATUS,
				VALID_FLAG,
				CREATE_DATE,
				CREATE_USER) VALUES ({0});"                ;
            ///明细表字符串
            string sqlKanbanPullOrderDetail = @"insert into [LES].[TT_MPM_KANBAN_PULL_ORDER_DETAIL] (
                FID,
				ORDER_FID,
				ORDER_CODE,
                ORDER_STATUS,
				CARD_NO,
				PART_NO,
				PART_NAME,
				SUPPLIER_CODE,
				SUPPLIER_NAME,
				PART_QTY,
				PACKAGE_CODE,
				PACKAGE_QTY,
				VALID_FLAG,
				CREATE_DATE,
				CREATE_USER) VALUES ({0});"                ;
            #endregion

            ///获取所有看板卡信息

            List <KanbanCardInfo> kanbanCardInfos = GetKanBanCardsListIsByLoginUser(cardNos, loginUser, isFilterLoginUser);
            if (kanbanCardInfos.Count == 0)
            {
                throw new Exception("MC:3x00000011");///看板卡数据不能为空
            }
            if (cardNos.Count != kanbanCardInfos.Count)
            {
                throw new Exception("MC:0x00000257");///所提交的看板卡状态必须为已启用且不能为已扫描
            }
            ///根据看板卡信息中的零件类代码②对物料需求进行分组
            var groupbyPartboxcode = kanbanCardInfos.GroupBy(ml => new { ml.PartBoxCode }).Select(w => w.Key).ToList();

            #region 根据零件类获取看板拉动物料拉动对应拉动零件
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos
                = new MaintainInhouseLogisticStandardBLL().GetList(
                      "[INHOUSE_PART_CLASS] in ('"
                      + string.Join("','", groupbyPartboxcode.Select(w => w.PartBoxCode))
                      + "') and [STATUS] = " + (int)BasicDataStatusConstants.Enable
                      + " AND [INHOUSE_SYSTEM_MODE]=N'"
                      + (int)PullModeConstants.Kanban
                      + "'", string.Empty);
            if (maintainInhouseLogisticStandardInfos.Count == 0)
            {
                throw new Exception("0x00000233");///没有已启用的物料拉动信息
            }
            #endregion

            #region 获取所有看板零件类以分组方式去重
            List <KanbanPartBoxInfo> kanbanPartBoxInfos = new KanbanPartBoxDAL().GetList(
                string.Format("[STATUS] = "
                              + (int)BasicDataStatusConstants.Enable
                              + " and [PART_BOX_CODE] in ('{0}') ", string.Join("','", groupbyPartboxcode.Select(w => w.PartBoxCode))), string.Empty);
            if (kanbanPartBoxInfos.Count == 0)
            {
                throw new Exception("MC:3x00000014");///看板零件类数据错误
            }
            #endregion

            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("update [LES].[TM_MPM_KANBAN_CARD] " +
                                     "set [USED_STATUS] = " + (int)KanbanCardUseStatusConstants.Scaned + "," +
                                     "[MODIFY_USER] = N'" + loginUser + "'," +
                                     "[MODIFY_DATE] = GETDATE() " +
                                     "where [ID] in (" + string.Join(",", kanbanCardInfos.Select(d => d.Id).ToArray()) + ");");

            #region 遍历看板卡信息
            foreach (var partboxcode in groupbyPartboxcode)
            {
                ///获取看板零件类信息
                KanbanPartBoxInfo kanbanPartBoxInfo = kanbanPartBoxInfos.FirstOrDefault(d => d.PartBoxCode == partboxcode.PartBoxCode);
                ///TT_MPM_KANBAN_PULL_ORDER.FID
                Guid pullOrderFid = Guid.NewGuid();
                ///看板拉动单号②依据序列号规则中的KANBAN_PULL_ORDER_CODE进行生成,明细中拉动单号③相同于主表
                string orderCode = new SeqDefineDAL().GetCurrentCode("KANBAN_PULL_ORDER_CODE", "KB");///TODO:看板拉动单号生成

                ///看板拉动单外键①为NEW.GUID,同时作为看板拉动单明细的主表外键②,明细中外键①为NEW.GUID
                ///物流路线代码⑤名称⑥、来源仓库⑧存储区⑦、目标仓库⑩存储区⑨从零件类代码③对应的看板零件类TM_MPM_KANBAN_PART_BOX信息中获取
                ///创建时间获取数据库服务器时间,创建人取自于参数操作用户
                ///创建后看板拉动单状态⑱为20.已发布,数据有效标记⑲为true,看板拉动单其它字段在生成时留空
                #region TT_MPM_KANBAN_PULL_ORDER
                string sqlKanbanPullOrderValue = "N'" + pullOrderFid.ToString() + "'"           ///FID
                                                 + ",N'" + orderCode + "'"                      ///ORDER_CODE
                                                 + ",N'" + kanbanPartBoxInfo.PartBoxCode + "'"  ///PART_BOX_CODE
                                                 + ",N'" + kanbanPartBoxInfo.PartBoxName + "'"  ///PART_BOX_NAME
                                                 + ",N'" + kanbanPartBoxInfo.RouteCode + "'"    ///ROUTE_CODE
                                                 + ",N'" + kanbanPartBoxInfo.RouteName + "'"    ///ROUTE_NAME
                                                 + ",N'" + kanbanPartBoxInfo.SourceZoneNo + "'" ///SOURCE_ZONE_NO
                                                 + ",N'" + kanbanPartBoxInfo.SourceWmNo + "'"   ///SOURCE_WM_NO
                                                 + ",N'" + kanbanPartBoxInfo.TargetZoneNo + "'" ///TARGET_ZONE_NO
                                                 + ",N'" + kanbanPartBoxInfo.TargetWmNo + "'"   ///TARGET_WM_NO
                                                 + ",NULL"                                      ///PICK_UP_FINISH_TIME
                                                 + ",NULL"                                      ///PICK_UP_USER
                                                 + ",NULL"                                      ///DELIVERY_FINISH_TIME
                                                 + ",NULL"                                      ///DELIVERY_USER
                                                 + ",NULL"                                      ///PRINT_CNT
                                                 + ",NULL"                                      ///PRINT_TIME
                                                 + ",NULL"                                      ///PRINT_USER
                                                 + "," + (int)PullOrderStatusConstants.Released ///STATUS
                                                 + ",1"                                         ///VALID_FLAG
                                                 + ",GETDATE()"                                 ///CREATE_DATE
                                                 + ",N'" + loginUser + "'";                     ///CREATE_USER
                #endregion

                stringBuilder.AppendLine(string.Format(sqlKanbanPullOrder, sqlKanbanPullOrderValue));

                List <KanbanCardInfo> kanbanCards = kanbanCardInfos.Where(d => d.PartBoxCode == partboxcode.PartBoxCode).ToList();

                #region 根据看板卡信息获取所有零件物料拉动信息
                var maintainInhouseLogisticStandardInfosparts = from a in maintainInhouseLogisticStandardInfos
                                                                join b in kanbanCards.Where(w => w.PartBoxCode == partboxcode.PartBoxCode).GroupBy(w => new { w.PartBoxCode, w.PartNo }).Select(w => new { w.Key.PartBoxCode, w.Key.PartNo })
                                                                on new { a.InhousePartClass, a.PartNo } equals new { InhousePartClass = b.PartBoxCode, b.PartNo }
                select a;
                #endregion


                foreach (var kanbanCard in kanbanCards)
                {
                    ///看板卡号①=④、物料号④=⑤、物料名称⑤=⑥、物料数量⑧=⑨、包装型号⑨=⑩
                    ///包装数量⑪默认为1,数据有效标记⑫为true
                    ///若看板卡信息中指定了供应商代码⑥名称⑦,则看板拉动单明细中供应商代码⑦名称⑧从看板卡信息中获取
                    #region TT_MPM_KANBAN_PULL_ORDER_DETAIL
                    string sqlKanbanPullOrderDetailValue = "NEWID()"                                      ///FID
                                                           + ",N'" + pullOrderFid.ToString() + "'"        ///ORDER_FID
                                                           + ",N'" + orderCode + "'"                      ///ORDER_CODE
                                                           + "," + (int)PullOrderStatusConstants.Released ///ORDER_STATUS
                                                           + ",N'" + kanbanCard.CardNo + "'"              ///CARD_NO
                                                           + ",N'" + kanbanCard.PartNo + "'"              ///PART_NO
                                                           + ",N'" + kanbanCard.PartName + "'"            ///PART_NAME
                                                           + ",N'" + kanbanCard.SupplierCode + "'"        ///SUPPLIER_CODE
                                                           + ",N'" + kanbanCard.SupplierName + "'"        ///SUPPLIER_NAME
                                                           + "," + kanbanCard.PartQty.GetValueOrDefault() ///PART_QTY
                                                           + ",N'" + kanbanCard.PackageCode + "'"         ///PACKAGE_CODE
                                                           + ",1"                                         ///PACKAGE_QTY
                                                           + ",1"                                         ///VALID_FLAG
                                                           + ",GETDATE()"                                 ///CREATE_DATE
                                                           + ",N'" + loginUser + "'";                     ///CREATE_USER
                    #endregion

                    stringBuilder.AppendLine(string.Format(sqlKanbanPullOrderDetail, sqlKanbanPullOrderDetailValue));
                }
                #region 单据衔接
                MaterialPullingOrderInfo mpOrder = new MaterialPullingOrderInfo();
                mpOrder.OrderNo          = orderCode;
                mpOrder.PartBoxCode      = kanbanPartBoxInfo.PartBoxCode;                                                                               ///零件类2
                mpOrder.PartBoxName      = kanbanPartBoxInfo.PartBoxName;                                                                               ///零件类名称3
                mpOrder.Plant            = string.Empty;                                                                                                ///工厂4
                mpOrder.Workshop         = string.Empty;                                                                                                ///车间5
                mpOrder.AssemblyLine     = string.Empty;                                                                                                ///流水线6
                mpOrder.SupplierNum      = string.Empty;                                                                                                ///供应商代码7
                mpOrder.SupplierName     = string.Empty;                                                                                                ///供应商名称
                mpOrder.SourceZoneNo     = kanbanPartBoxInfo.SourceZoneNo;                                                                              ///来源存储区8
                mpOrder.SourceWmNo       = kanbanPartBoxInfo.SourceWmNo;                                                                                ///来源仓库9
                mpOrder.TargetZoneNo     = kanbanPartBoxInfo.TargetZoneNo;                                                                              ///目标存储区10
                mpOrder.TargetWmNo       = kanbanPartBoxInfo.TargetWmNo;                                                                                ///目标仓库11
                mpOrder.TargetDock       = string.Empty;                                                                                                ///道口12
                mpOrder.PlanShippingTime = DateTime.Now.AddMinutes(kanbanPartBoxInfo.PickUpTime.GetValueOrDefault());                                   ///建议交货时间
                mpOrder.PlanDeliveryTime = mpOrder.PlanShippingTime.GetValueOrDefault().AddMinutes(kanbanPartBoxInfo.DeliveryTime.GetValueOrDefault()); ///预计到厂时间14 = 建议交货时间 – 送货时间
                mpOrder.PublishTime      = DateTime.Now;
                mpOrder.AsnFlag          = false;
                mpOrder.OrderType        = 0;///TODO:对于看板拉动单应该的值,如果后续用到则需要定义枚举
                mpOrder.MaterialPullingOrderDetailInfos = (from m in maintainInhouseLogisticStandardInfosparts
                                                           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 = kanbanCards.Where(w => w.PartNo == m.PartNo).Count(),                 ///需求包装数量9
                    RequirePartQty = (kanbanCards.Where(w => w.PartNo == m.PartNo).Sum(w => w.PartQty) ?? 0), ///需求物料数量10
                    TargetZoneNo = kanbanPartBoxInfo.TargetZoneNo,
                    TargetWmNo = kanbanPartBoxInfo.TargetWmNo
                }).ToList();
                ///执行单据衔接
                stringBuilder.AppendLine(MaterialPullingCommonBLL.Handler(mpOrder, loginUser));
                #endregion
            }
            #endregion

            ///数据保存时使用SQL拼接多条insert语句方式一次提交执行,执行失败需要同步返回至客户端
            using (TransactionScope trans = new TransactionScope())
            {
                CommonDAL.ExecuteNonQueryBySql(stringBuilder.ToString());
                trans.Complete();
            }
            return(true);
        }
        /// <summary>
        /// 对于MPM-036逻辑进行函数封装
        /// </summary>
        /// <param name="emergencyPullingCartInfos"></param>
        /// <param name="loginUser"></param>
        public static string Handler(List <EmergencyPullingCartInfo> emergencyPullingCartInfos, string loginUser)
        {
            ///执行语句
            StringBuilder @string = new StringBuilder();
            ///获取系统配置是否允许过量提前拉动
            string allowedFlag = new ConfigDAL().GetValueByCode("ENABLE_EXCEED_COUNTER_QTY_WHEN_ADVANCE_PULL");

            ///接收紧急拉动购物车对象集合进行处理
            if (emergencyPullingCartInfos.Count == 0)
            {
                throw new Exception("MC:0x00000084");///数据错误
            }
            ///对应的物料拉动信息
            List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardBLL().GetList("" +
                                                                                                                                               " and [STATUS] =" + (int)BasicDataStatusConstants.Enable + "" +
                                                                                                                                               " and [FID] in ('" + string.Join("','", emergencyPullingCartInfos.Select(d => d.LogisticStandardFid).ToArray()) + "')", string.Empty);

            if (maintainInhouseLogisticStandardInfos.Count == 0)
            {
                throw new Exception("MC:0x00000213");///物料拉动信息数据错误
            }
            ///首先需要将其按照拉动方式、零件类进行分组,每个分组产生一张紧急拉动单
            var cartGroups = emergencyPullingCartInfos.GroupBy(d => new { d.PullMode, d.PartBoxCode }).ToList();

            #region 手工拉动 PLAN
            var planCartGroups = cartGroups.Where(d => d.Key.PullMode == (int)PullModeConstants.Plan).ToList();
            ///计划拉动零件类
            List <PlanPartBoxInfo> planPartBoxInfos = new PlanPartBoxBLL().GetList("" +
                                                                                   " and [STATUS] = " + (int)BasicDataStatusConstants.Enable + "" +
                                                                                   " and [PART_BOX_CODE] in ('" + string.Join("','", planCartGroups.Select(d => d.Key.PartBoxCode).ToArray()) + "')", string.Empty);
            foreach (var planCartGroup in planCartGroups)
            {
                ///从参数集合从提取对应的紧急拉动购物车集合
                List <EmergencyPullingCartInfo> pullingCartInfos = emergencyPullingCartInfos.Where(d =>
                                                                                                   d.PullMode == planCartGroup.Key.PullMode && d.PartBoxCode == planCartGroup.Key.PartBoxCode).ToList();
                if (pullingCartInfos.Count == 0)
                {
                    continue;
                }
                ///计划零件类
                PlanPartBoxInfo planPartBoxInfo = planPartBoxInfos.FirstOrDefault(d => d.PartBoxCode == planCartGroup.Key.PartBoxCode);
                if (planPartBoxInfo == null)
                {
                    continue;
                }
                ///计划拉动-->仓储衔接主表
                MaterialPullingOrderInfo materialPulling = MaterialPullingCommonBLL.CreateMaterialPullingOrderInfo();
                ///计划拉动单主表
                PlanPullOrderInfo planPullOrderInfo = PlanPullOrderBLL.CreatePlanPullOrder(loginUser);
                ///OrderType 拉动单类型
                planPullOrderInfo.OrderType = (int)PullOrderTypeConstants.Emergency;
                ///PlanPartBoxInfo-->PlanPullOrderInfo
                PlanPullOrderBLL.GetPlanPullOrder(planPartBoxInfo, ref planPullOrderInfo);
                ///计划拉动单主表sql
                @string.AppendLine(PlanPullOrderDAL.GetInsertSql(planPullOrderInfo));
                ///PlanPullOrderInfo -> MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPlanPullingOrderInfo(planPullOrderInfo, ref materialPulling);
                foreach (EmergencyPullingCartInfo planCartInfo in pullingCartInfos)
                {
                    ///物料拉动信息
                    MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d => d.Fid == planCartInfo.LogisticStandardFid);
                    if (maintainInhouseLogisticStandardInfo == null)
                    {
                        continue;
                    }
                    ///物料包装数量在此需要根据单包装数量以及物料需求数量进行向上圆整计算
                    ///REQUIRED_BOX_QTY:物料包装数量  PULL_PACKAGE_QTY:单包装数量 REQUIRED_PART_QTY:物料需求数量
                    if (planCartInfo.PullPackageQty.GetValueOrDefault() == 0)
                    {
                        continue;                                                      ///O不能做被除数
                    }
                    planCartInfo.RequiredBoxQty = Convert.ToInt32(Math.Ceiling(planCartInfo.RequiredPartQty.GetValueOrDefault() / planCartInfo.PullPackageQty.GetValueOrDefault()));
                    ///仓储衔接明细表
                    MaterialPullingOrderDetailInfo detailInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderDetailInfo();
                    ///计划拉动单明细
                    PlanPullOrderDetailInfo planPullOrderDetailInfo = PlanPullOrderDetailBLL.CreatePlanPullOrderDetail(loginUser);
                    ///MaintainInhouseLogisticStandardInfo -> PlanPullOrderDetailInfo
                    PlanPullOrderDetailBLL.GetPlanPullOrderDetail(maintainInhouseLogisticStandardInfo, ref planPullOrderDetailInfo);
                    ///TwdPullOrderInfo -> TwdPullOrderDetailInfo
                    PlanPullOrderDetailBLL.GetPlanPullOrderDetailInfo(planPullOrderInfo, ref planPullOrderDetailInfo);
                    ///RequiredPackageQty
                    planPullOrderDetailInfo.RequiredPackageQty = planCartInfo.RequiredBoxQty.GetValueOrDefault();
                    ///RequiredPartQty
                    planPullOrderDetailInfo.RequiredPartQty = planCartInfo.RequiredPartQty.GetValueOrDefault();
                    ///计划拉动明细sql
                    @string.AppendLine(PlanPullOrderDetailDAL.GetInsertSql(planPullOrderDetailInfo));
                    ///PlanPullOrderDetailInfo -> MaterialPullingOrderDetailInfo
                    MaterialPullingCommonBLL.GetMaterialPullingOrderDetail(planPullOrderDetailInfo, ref detailInfo);
                    ///仓储明细集合Add
                    materialPulling.MaterialPullingOrderDetailInfos.Add(detailInfo);
                }
                ///拉动单生成后需要调用拉动仓储衔接函数获取语句
                @string.AppendLine(MaterialPullingCommonBLL.Handler(materialPulling, loginUser));
            }

            #endregion

            #region 提前拉动 TWD
            var twdCartGroups = cartGroups.Where(d => d.Key.PullMode == (int)PullModeConstants.Pcs || d.Key.PullMode == (int)PullModeConstants.Twd).ToList();
            ///TWD计数器
            List <TwdCounterInfo> twdCounterInfos = new TwdCounterBLL().GetList("" +
                                                                                "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                "[PART_PULL_FID] in ('" + string.Join("','", maintainInhouseLogisticStandardInfos.Select(d => d.Fid).ToArray()) + "')  and " +
                                                                                "isnull([CURRENT_QTY],0) > 0", string.Empty);
            ///TWD零件类
            List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxBLL().GetList("" +
                                                                                "[STATUS] =" + (int)BasicDataStatusConstants.Enable + " and " +
                                                                                "[PART_BOX_CODE] in ('" + string.Join("','", twdCartGroups.Select(d => d.Key.PartBoxCode).ToArray()) + "')", string.Empty);
            foreach (var twdCartGroup in twdCartGroups)
            {
                ///从参数集合从提取对应的紧急拉动购物车集合
                List <EmergencyPullingCartInfo> pullingCartInfos = emergencyPullingCartInfos.Where(d =>
                                                                                                   d.PullMode == twdCartGroup.Key.PullMode && d.PartBoxCode == twdCartGroup.Key.PartBoxCode).ToList();
                if (pullingCartInfos.Count == 0)
                {
                    continue;
                }
                ///TWD零件类
                TwdPartBoxInfo twdPartBoxInfo = twdPartBoxInfos.FirstOrDefault(d => d.PartBoxCode == twdCartGroup.Key.PartBoxCode);
                if (twdPartBoxInfo == null)
                {
                    continue;
                }
                ///触发层级拉动的集合
                List <EmergencyPullingCartInfo> pullingLevelCartInfos = pullingCartInfos.Where(d => d.TriggerPullFlag == true).ToList();
                foreach (EmergencyPullingCartInfo pullingLevelCartInfo in pullingLevelCartInfos)
                {
                    ///需要根据其物料拉动信息外键获取对应的计数器数据(状态必须为已启用)
                    TwdCounterInfo twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                                   d.PartPullFid == pullingLevelCartInfo.LogisticStandardFid.GetValueOrDefault() &&
                                                                                   d.Status == (int)BasicDataStatusConstants.Enable);
                    if (twdCounterInfo == null)
                    {
                        continue;
                    }
                    ///在此之前需要根据物料图号、供应商、层级仓库、层级存储区在物料拉动信息中获取匹配的目标仓库、目标存储区数据
                    MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d =>
                                                                                                                                                  d.PartNo == pullingLevelCartInfo.PartNo &&
                                                                                                                                                  d.SupplierNum == pullingLevelCartInfo.SupplierNum &&
                                                                                                                                                  d.WmNo == pullingLevelCartInfo.TriggerWmNo &&
                                                                                                                                                  d.ZoneNo == pullingLevelCartInfo.TriggerZoneNo);
                    ///触发层级拉动
                    @string.AppendFormat(TwdCounterBLL.LevelPullCounter(maintainInhouseLogisticStandardInfo, pullingLevelCartInfo.RequiredPartQty.GetValueOrDefault(), loginUser, twdCounterInfo.Fid.GetValueOrDefault(), twdPartBoxInfo));
                }
                ///提前拉动的集合
                List <EmergencyPullingCartInfo> advancePullCartInfos = pullingCartInfos.Where(d =>
                                                                                              d.TriggerPullFlag == false && d.EmergencyPullMode == (int)EmergencyPullModeConstants.AdvancePull).ToList();
                if (advancePullCartInfos.Count == 0)
                {
                    continue;
                }
                ///仓储衔接主表
                MaterialPullingOrderInfo materialPulling = MaterialPullingCommonBLL.CreateMaterialPullingOrderInfo();
                ///TWD拉动单主表
                TwdPullOrderInfo twdPullOrderInfo = TwdPullOrderBLL.CreateTwdPullOrderInfo(loginUser);
                ///TwdPartBoxInfo -> TwdPullOrderInfo
                TwdPullOrderBLL.GetTwdPullOrderInfo(twdPartBoxInfo, ref twdPullOrderInfo);
                ///TWD拉动单主表sql
                @string.AppendLine(TwdPullOrderDAL.GetInsertSql(twdPullOrderInfo));
                ///TwdPullOrderInfo-->MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPullingOrderInfo(twdPullOrderInfo, ref materialPulling);
                int rowNo = 0; ///行号
                               ///逐条循环每个购物车
                foreach (EmergencyPullingCartInfo advancePullCartInfo in advancePullCartInfos)
                {
                    ///需要根据其物料拉动信息外键获取对应的计数器数据(状态必须为已启用)
                    ///TT_MPM_TWD_COUNTER TWD计数器
                    TwdCounterInfo twdCounterInfo = twdCounterInfos.FirstOrDefault(d =>
                                                                                   d.PartPullFid == advancePullCartInfo.LogisticStandardFid.GetValueOrDefault() &&
                                                                                   d.Status == (int)BasicDataStatusConstants.Enable);
                    if (twdCounterInfo == null)
                    {
                        continue;
                    }
                    ///物料拉动信息
                    MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandardInfos.FirstOrDefault(d => d.Fid == advancePullCartInfo.LogisticStandardFid);
                    if (maintainInhouseLogisticStandardInfo == null)
                    {
                        continue;
                    }
                    ///物料包装数量在此需要根据单包装数量以及物料需求数量进行向上圆整计算
                    ///REQUIRED_BOX_QTY:物料包装数量  PULL_PACKAGE_QTY:单包装数量 REQUIRED_PART_QTY:物料需求数量
                    if (advancePullCartInfo.PullPackageQty.GetValueOrDefault() == 0)
                    {
                        continue;                                                             ///O不能做被除数
                    }
                    advancePullCartInfo.RequiredBoxQty = Convert.ToInt32(Math.Ceiling(advancePullCartInfo.RequiredPartQty.GetValueOrDefault() / advancePullCartInfo.PullPackageQty.GetValueOrDefault()));
                    ///若该系统配置标记为false时、计数器当前累计数量不允许小于购物车物料需求数量,
                    if (allowedFlag.ToLower() == "false" && twdCounterInfo.CurrentQty.GetValueOrDefault() < advancePullCartInfo.RequiredPartQty.GetValueOrDefault())
                    {
                        continue;
                    }
                    ///仓储衔接明细表
                    MaterialPullingOrderDetailInfo detailInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderDetailInfo();
                    ///TWD明细表
                    TwdPullOrderDetailInfo pullOrderDetailInfo = TwdPullOrderDetailBLL.CreateTwdPullOrderDetailInfo(loginUser);
                    ///MaintainInhouseLogisticStandardInfo -> TwdPullOrderDetailInfo
                    TwdPullOrderDetailBLL.GetTwdPullOrderDetailInfo(maintainInhouseLogisticStandardInfo, ref pullOrderDetailInfo);
                    ///TwdPullOrderInfo -> TwdPullOrderDetailInfo
                    TwdPullOrderDetailBLL.GetTwdPullOrderDetailInfo(twdPullOrderInfo, ref pullOrderDetailInfo);
                    ///ROW_NO,行号
                    pullOrderDetailInfo.RowNo = ++rowNo;
                    ///REQUIRED_PACKAGE_QTY,需求包装数
                    pullOrderDetailInfo.RequiredPackageQty = advancePullCartInfo.RequiredBoxQty.GetValueOrDefault();
                    ///REQUIRED_PART_QTY,需求物料数量
                    pullOrderDetailInfo.RequiredPartQty = advancePullCartInfo.RequiredPartQty.GetValueOrDefault();
                    ///TWD明细表sql
                    @string.AppendLine(TwdPullOrderDetailDAL.GetInsertSql(pullOrderDetailInfo));
                    ///TwdPullOrderDetailInfo -> MaterialPullingOrderDetailInfo
                    MaterialPullingCommonBLL.GetMaterialPullingOrderDetailInfo(pullOrderDetailInfo, ref detailInfo);
                    ///仓储衔接集合Add
                    materialPulling.MaterialPullingOrderDetailInfos.Add(detailInfo);
                    ///否则直接对计数器的当前累计数量按购物车物料需求数量进行扣减
                    @string.AppendLine("update [LES].[TT_MPM_TWD_COUNTER] " +
                                       "set [CURRENT_QTY] = isnull([CURRENT_QTY],0) - " + advancePullCartInfo.RequiredPartQty.GetValueOrDefault() + "," +
                                       "[MODIFY_DATE] = GETDATE()," +
                                       "[MODIFY_USER] = N'" + loginUser + "' " +
                                       "where [ID]= " + twdCounterInfo.Id + ";");
                    ///同时记录计数器日志并标记其类型为提前拉动
                    TwdCounterLogInfo twdCounterLogInfo = TwdCounterLogBLL.CreateTwdCounterLogInfo(twdCounterInfo.Fid.GetValueOrDefault(), loginUser);
                    ///TwdCounterInfo -> TwdCounterLogInfo
                    TwdCounterLogBLL.GetTwdCounterLogInfo(twdCounterInfo, ref twdCounterLogInfo);
                    ///PART_QTY,物料数量
                    twdCounterLogInfo.PartQty = 0 - advancePullCartInfo.RequiredPartQty.GetValueOrDefault();
                    ///SOURCE_DATA,目视来源数据
                    twdCounterLogInfo.SourceData = twdPullOrderInfo.OrderCode;
                    ///SOURCE_DATA_FID,数据来源外键
                    twdCounterLogInfo.SourceDataFid = twdPullOrderInfo.Fid;
                    ///SOURCE_DATA_TYPE,数据来源类型
                    twdCounterLogInfo.SourceDataType = (int)TwdCounterSourceDataTypeConstants.AdvancePull;
                    ///计数器日志sql
                    @string.AppendLine(TwdCounterLogDAL.GetInsertSql(twdCounterLogInfo));
                }
                ///拉动单生成后需要调用拉动仓储衔接函数获取语句
                @string.AppendLine(MaterialPullingCommonBLL.Handler(materialPulling, loginUser));
            }

            #endregion

            return(@string.ToString());
        }