示例#1
0
        /// <summary>
        /// 同步
        /// </summary>
        /// <param name="loginUser"></param>
        public static void Sync(string loginUser)
        {
            ///获取没有处理的送货单数据
            List <SrmDeliveryNoteInfo> srmDeliveryNoteInfos = new SrmDeliveryNoteBLL().GetList("[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty);

            if (srmDeliveryNoteInfos.Count == 0)
            {
                return;
            }
            ///获取没有处理的送货单详情数据- 没有数据主表报错
            List <SrmDeliveryNoteDetailInfo> srmDeliveryNoteDetailInfos = new SrmDeliveryNoteDetailBLL().GetList("[ORDER_FID] in ('" + string.Join("','", srmDeliveryNoteInfos.Select(d => d.Fid.GetValueOrDefault()).ToArray()) + "')", string.Empty);

            if (srmDeliveryNoteDetailInfos.Count == 0)
            {
                return;
            }
            ///获取相关物料供应商信息
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetList("" +
                                                                          "[SUPPLIER_NUM] in ('" + string.Join("','", srmDeliveryNoteInfos.Select(d => d.Suppliercode).ToArray()) + "') and " +
                                                                          "[SUPPLIER_TYPE] = " + (int)SupplierTypeConstants.MaterialSupplier + "", string.Empty);
            ///
            StringBuilder @string = new StringBuilder();

            if (supplierInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000475' where " +///送货单中供应商信息无效
                                   "[ID] in (" + string.Join(",", srmDeliveryNoteInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///获取相关存储区信息
            List <string> zoneNos = srmDeliveryNoteInfos.Where(d => !string.IsNullOrEmpty(d.Targetzoneno)).Select(d => d.Targetzoneno).ToList();

            zoneNos.AddRange(srmDeliveryNoteInfos.Where(d => !string.IsNullOrEmpty(d.Sourcezoneno)).Select(d => d.Sourcezoneno).ToList());
            List <ZonesInfo> zonesInfos = new ZonesBLL().GetList("" +
                                                                 "[ZONE_NO] in ('" + string.Join("','", zoneNos.ToArray()) + "') and " +
                                                                 "[PLANT] in ('" + string.Join("','", srmDeliveryNoteInfos.Select(d => d.Plant).ToArray()) + "')", string.Empty);

            if (zonesInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000485' where " +///送货单中存储区信息不存在
                                   "[ID] in (" + string.Join(",", srmDeliveryNoteInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///
            List <long> dealedIds = new List <long>();

            ///循环写入数据
            foreach (SrmDeliveryNoteInfo srmDeliveryNoteInfo in srmDeliveryNoteInfos)
            {
                ///获取送货单明细
                List <SrmDeliveryNoteDetailInfo> srmDeliveryNoteDetails = srmDeliveryNoteDetailInfos.Where(d => d.OrderFid.GetValueOrDefault() == srmDeliveryNoteInfo.Fid.GetValueOrDefault()).ToList();
                if (srmDeliveryNoteDetails.Count == 0)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000473' where " +///送货单无物料明细
                                       "[ID] = " + srmDeliveryNoteInfo.Id + ";");
                    continue;
                }
                ///供应商信息
                SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == srmDeliveryNoteInfo.Suppliercode);
                if (supplierInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000484' where " +///该送货单中供应商信息不存在
                                       "[ID] = " + srmDeliveryNoteInfo.Id + ";");
                    continue;
                }
                ///校验供应商是否启用了ASN功能
                if (!supplierInfo.AsnFlag.GetValueOrDefault())
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000486' where " +///该供应商未启用ASN功能
                                       "[ID] = " + srmDeliveryNoteInfo.Id + ";");
                    continue;
                }
                ///目标存储区
                ZonesInfo zonesInfo = zonesInfos.FirstOrDefault(d => d.ZoneNo == srmDeliveryNoteInfo.Targetzoneno && d.Plant == srmDeliveryNoteInfo.Plant);
                if (zonesInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000246' where " +///存储区数据错误
                                       "[ID] = " + srmDeliveryNoteInfo.Id + ";");
                    continue;
                }
                ///单据衔接对象创建
                MaterialPullingOrderInfo materialPullingOrderInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderInfo();
                ///SrmDeliveryNoteInfo -> MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPullingOrderInfo(srmDeliveryNoteInfo, ref materialPullingOrderInfo);
                ///SupplierInfo -> MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPullingOrderInfo(supplierInfo, ref materialPullingOrderInfo);
                ///
                materialPullingOrderInfo.TargetWmNo = zonesInfo.WmNo;
                ///PART_BOX_CODE,TODO:考虑由SRM增加字段?
                materialPullingOrderInfo.PartBoxCode = string.Empty;
                ///PART_BOX_NAME,11
                materialPullingOrderInfo.PartBoxName = string.Empty;
                ///
                materialPullingOrderInfo.Route = null;
                ///
                foreach (SrmDeliveryNoteDetailInfo srmDeliveryNoteDetail in srmDeliveryNoteDetails)
                {
                    ///单据衔接明细对象创建
                    MaterialPullingOrderDetailInfo materialPullingOrderDetailInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderDetailInfo();
                    ///SrmDeliveryNoteDetailInfo -> MaterialPullingOrderDetailInfo
                    MaterialPullingCommonBLL.GetMaterialPullingOrderDetailInfo(srmDeliveryNoteDetail, ref materialPullingOrderDetailInfo);
                    ///SRM拉动单明细中的供应商必须为单据的供应商
                    materialPullingOrderDetailInfo.SupplierNum = srmDeliveryNoteInfo.Suppliercode;
                    ///
                    materialPullingOrderInfo.MaterialPullingOrderDetailInfos.Add(materialPullingOrderDetailInfo);
                }
                ///生成创建入库单的语句
                @string.Append(MaterialPullingCommonBLL.CreateReceiveSql(materialPullingOrderInfo, new List <PartsStockInfo>(), loginUser));
                ///执行成功的ID
                dealedIds.Add(srmDeliveryNoteInfo.Id);
            }
            if (dealedIds.Count > 0)
            {
                ///已处理的中间表数据更新为已处理状态
                @string.AppendLine("update [LES].[TI_IFM_SRM_DELIVERY_NOTE] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                   "[PROCESS_TIME] = GETDATE() where " +
                                   "[ID] in (" + string.Join(",", dealedIds.ToArray()) + ");");
            }
            ///执行
            using (TransactionScope trans = new TransactionScope())
            {
                if (@string.Length > 0)
                {
                    BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                }
                trans.Complete();
            }
        }
示例#2
0
        /// <summary>
        /// Sync
        /// </summary>
        public static void Sync(string loginUser)
        {
            ///获取未处理的中间表数据
            List <WmsVmiAsnRunsheetInfo> wmsVmiAsnRunsheetInfos = new WmsVmiAsnRunsheetBLL().GetList("[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty);

            if (wmsVmiAsnRunsheetInfos.Count == 0)
            {
                return;
            }
            List <WmsVmiAsnRunsheetDetailInfo> wmsVmiAsnRunsheetDetailInfos = new WmsVmiAsnRunsheetDetailBLL().GetList("[LOG_FID] in ('" + string.Join("','", wmsVmiAsnRunsheetInfos.Select(d => d.LogFid.GetValueOrDefault()).ToArray()) + "')", string.Empty);

            if (wmsVmiAsnRunsheetDetailInfos.Count == 0)
            {
                return;
            }
            ///获取相关物料供应商信息
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetList("" +
                                                                          "[SUPPLIER_NUM] in ('" + string.Join("','", wmsVmiAsnRunsheetInfos.Select(d => d.Suppliercode).ToArray()) + "') and " +
                                                                          "[SUPPLIER_TYPE] = " + (int)SupplierTypeConstants.MaterialSupplier + "", string.Empty);
            ///
            StringBuilder @string = new StringBuilder();

            if (supplierInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000475' where " +///送货单中供应商信息无效
                                   "[ID] in (" + string.Join("','", wmsVmiAsnRunsheetInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///获取相关存储区信息
            List <string> zoneNos = wmsVmiAsnRunsheetInfos.Where(d => !string.IsNullOrEmpty(d.Targetzoneno)).Select(d => d.Targetzoneno).ToList();

            zoneNos.AddRange(wmsVmiAsnRunsheetInfos.Where(d => !string.IsNullOrEmpty(d.Sourcezoneno)).Select(d => d.Sourcezoneno).ToList());
            List <ZonesInfo> zonesInfos = new ZonesBLL().GetList("" +
                                                                 "[ZONE_NO] in ('" + string.Join("','", zoneNos.ToArray()) + "')  ", string.Empty);

            if (zonesInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000485' where " +///送货单中存储区信息不存在
                                   "[ID] in (" + string.Join(",", wmsVmiAsnRunsheetInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///获取相关仓库信息
            List <WarehouseInfo> warehouseInfos = new WarehouseBLL().GetList("[WAREHOUSE] in ('" + string.Join("','", zonesInfos.Select(d => d.WmNo).ToArray()) + "')", string.Empty);

            if (warehouseInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000230' where " +///仓库信息不存在
                                   "[ID] in (" + string.Join("','", wmsVmiAsnRunsheetInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///供应商VMI关系
            List <VmiSupplierInfo> vmiSupplierInfos = new VmiSupplierBLL().GetList("" +
                                                                                   "[SUPPLIER_NUM] in ('" + string.Join("','", supplierInfos.Select(d => d.SupplierNum).ToArray()) + "') and " +
                                                                                   "[WM_NO] in ('" + string.Join("','", warehouseInfos.Select(d => d.Warehouse).ToArray()) + "')", string.Empty);

            if (vmiSupplierInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000429' where " +///VMI供应商信息未维护
                                   "[ID] in (" + string.Join("','", wmsVmiAsnRunsheetInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }

            ///
            List <long> dealedIds = new List <long>();

            ///循环写入数据
            foreach (WmsVmiAsnRunsheetInfo wmsVmiAsnRunsheetInfo in wmsVmiAsnRunsheetInfos)
            {
                ///获取送货单明细
                List <WmsVmiAsnRunsheetDetailInfo> wmsVmiAsnRunsheetDetails = wmsVmiAsnRunsheetDetailInfos.Where(d => d.OrderFid.GetValueOrDefault() == wmsVmiAsnRunsheetInfo.LogFid.GetValueOrDefault()).ToList();
                if (wmsVmiAsnRunsheetDetails.Count == 0)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000473' where " +///送货单无物料明细
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }
                ///供应商信息
                SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == wmsVmiAsnRunsheetInfo.Suppliercode);
                if (supplierInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000484' where " +///该送货单中供应商信息不存在
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }
                var sourceZoneInfo = zonesInfos.FirstOrDefault(fd => fd.ZoneNo == wmsVmiAsnRunsheetInfo.Sourcezoneno);
                if (sourceZoneInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000500' where " +///存储区不存在
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }


                ///来源仓库
                WarehouseInfo sourceWarehouseInfo = warehouseInfos.FirstOrDefault(d => d.Warehouse == sourceZoneInfo.WmNo);
                if (sourceWarehouseInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000230' where " +///仓库信息不存在
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }


                if (sourceWarehouseInfo.WarehouseType.GetValueOrDefault() != (int)WarehouseTypeConstants.VMI)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000219' where " +///仓库类型错误
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }


                var targetZoneInfo = zonesInfos.FirstOrDefault(fd => fd.ZoneNo == wmsVmiAsnRunsheetInfo.Targetzoneno);
                if (targetZoneInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000500' where " +///存储区不存在
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }

                ///来源仓库
                WarehouseInfo targetWarehouseInfo = warehouseInfos.FirstOrDefault(d => d.Warehouse == targetZoneInfo.WmNo);
                if (targetWarehouseInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000230' where " +///仓库信息不存在
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }
                if (targetWarehouseInfo.WarehouseType.GetValueOrDefault() != (int)WarehouseTypeConstants.RDC)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000219' where " +///存储区不存在
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }
                ///VMI供应商关系
                VmiSupplierInfo vmiSupplierInfo = vmiSupplierInfos.FirstOrDefault(d => d.SupplierNum == supplierInfo.SupplierNum && d.WmNo == sourceWarehouseInfo.Warehouse);
                if (vmiSupplierInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000429' where " +///VMI供应商信息未维护
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }
                if (!vmiSupplierInfo.AsnFlag.GetValueOrDefault())
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000486' where " +///该供应商未启用ASN功能
                                       "[ID] = " + wmsVmiAsnRunsheetInfo.Id + ";");
                    continue;
                }

                ///单据衔接对象创建
                MaterialPullingOrderInfo materialPullingOrderInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderInfo();
                ///WmsVmiAsnRunsheetInfo -> MaterialPullingOrderInfo
                MaterialPullingCommonBLL.GetMaterialPullingOrderInfo(wmsVmiAsnRunsheetInfo, ref materialPullingOrderInfo);
                ///
                materialPullingOrderInfo.SourceWmNo = sourceWarehouseInfo.Warehouse;
                ///
                materialPullingOrderInfo.TargetWmNo = targetWarehouseInfo.Warehouse;
                ///
                materialPullingOrderInfo.AsnFlag = true;
                ///PART_BOX_CODE,TODO:考虑由WMS增加字段?
                materialPullingOrderInfo.PartBoxCode = string.Empty;
                ///PART_BOX_NAME,11
                materialPullingOrderInfo.PartBoxName = string.Empty;
                ///
                materialPullingOrderInfo.Route = null;
                ///
                foreach (WmsVmiAsnRunsheetDetailInfo wmsVmiAsnRunsheetDetail in wmsVmiAsnRunsheetDetails)
                {
                    ///单据衔接明细对象创建
                    MaterialPullingOrderDetailInfo materialPullingOrderDetailInfo = MaterialPullingCommonBLL.CreateMaterialPullingOrderDetailInfo();
                    ///WmsVmiAsnRunsheetDetailInfo -> MaterialPullingOrderDetailInfo
                    MaterialPullingCommonBLL.GetMaterialPullingOrderDetailInfo(wmsVmiAsnRunsheetDetail, ref materialPullingOrderDetailInfo);
                    ///WMS拉动单明细中的供应商必须为单据的供应商
                    materialPullingOrderDetailInfo.SupplierNum = wmsVmiAsnRunsheetInfo.Suppliercode;
                    ///
                    materialPullingOrderInfo.MaterialPullingOrderDetailInfos.Add(materialPullingOrderDetailInfo);
                }
                ///生成创建入库单的语句
                @string.Append(MaterialPullingCommonBLL.CreateReceiveSql(materialPullingOrderInfo, new List <PartsStockInfo>(), loginUser));
                ///执行成功的ID
                dealedIds.Add(wmsVmiAsnRunsheetInfo.Id);
            }
            if (dealedIds.Count > 0)
            {
                ///已处理的中间表数据更新为已处理状态
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_ASN_RUNSHEET] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                   "[PROCESS_TIME] = GETDATE() where " +
                                   "[ID] in (" + string.Join(",", dealedIds.ToArray()) + ");");
            }
            ///执行
            using (TransactionScope trans = new TransactionScope())
            {
                if (@string.Length > 0)
                {
                    BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                }
                trans.Complete();
            }
        }
示例#3
0
        /// <summary>
        /// SyncMaterialReservation
        /// </summary>
        /// <param name="loginUser"></param>
        public static void Sync(string loginUser)
        {
            List <SapMaterialReservationInfo> sapMaterialReservationInfos = new SapMaterialReservationBLL().GetListByPage("" +
                                                                                                                          "DATEDIFF(MINUTE,[CREATE_DATE],GETDATE()) > " + sapMaterialReservationSyncDelayMinute + " and " +
                                                                                                                          "[PROCESS_FLAG] in (" + (int)ProcessFlagConstants.Untreated + "," + (int)ProcessFlagConstants.Resend + ")", "[ID]", 1, int.MaxValue, out int dataCnt);

            if (dataCnt == 0)
            {
                return;
            }
            ///带有库存地点信息的存储区数据
            ///TODO:存储区基础数据维护时限制SAP库存地点编号不能重复
            List <ZonesInfo> zonesInfos = new ZonesBLL().GetList("len([STOCK_PLACE_NO]) > 0", string.Empty);
            ///供应商信息
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetListForInterfaceDataSync(sapMaterialReservationInfos.Select(d => d.Lifnr).ToList());
            ///物料基础信息
            List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetListForInterfaceDataSync(sapMaterialReservationInfos.Select(d => d.Matnr).ToList());
            ///物料仓储信息
            List <PartsStockInfo> partsStockInfos = new PartsStockBLL().GetList("[PART_NO] in ('" + string.Join("','", sapMaterialReservationInfos.Select(d => d.Matnr).ToArray()) + "')", string.Empty);
            ///已处理完成的ID
            List <long>   dealedIds     = new List <long>();
            StringBuilder stringBuilder = new StringBuilder();
            ///Bwart-移动类型
            ///Kostl-成本中心
            ///Lgort-中转库存地点
            ///Umlgo-接收库存地点
            ///Wempf-收货方
            ///Lifnr-供应商
            ///Rsnum-预留单号
            ///Ebeln-采购订单号
            ///Bdter-需求日期
            var gSapMaterialReservationInfos = from p in sapMaterialReservationInfos
                                               group p by new { p.Bwart, p.Kostl, p.Lgort, p.Umlgo, p.Wempf, p.Lifnr, p.Rsnum, p.Ebeln, p.Bdter } into g
                select new { g.Key };

            foreach (var gSapMaterialReservationInfo in gSapMaterialReservationInfos)
            {
                ///校验接收库存地点
                ZonesInfo tZone = zonesInfos.FirstOrDefault(d => d.StockPlaceNo == gSapMaterialReservationInfo.Key.Umlgo);
                if (!string.IsNullOrEmpty(gSapMaterialReservationInfo.Key.Umlgo) && tZone == null)
                {
                    stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                             "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                             "[PROCESS_TIME] = GETDATE()," +
                                             "[COMMENTS] = N'0x00000418'," +///库存地点不存在
                                             "[MODIFY_USER] = N'" + loginUser + "'," +
                                             "[MODIFY_DATE] = GETDATE() " +
                                             "where [EBELN] = '" + gSapMaterialReservationInfo.Key.Ebeln + "';");
                    continue;
                }
                ///校验中转库存地点
                ZonesInfo sZone = zonesInfos.FirstOrDefault(d => d.StockPlaceNo == gSapMaterialReservationInfo.Key.Lgort);
                if (!string.IsNullOrEmpty(gSapMaterialReservationInfo.Key.Lgort) && sZone == null)
                {
                    stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                             "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                             "[PROCESS_TIME] = GETDATE()," +
                                             "[COMMENTS] = N'0x00000418'," +///库存地点不存在
                                             "[MODIFY_USER] = N'" + loginUser + "'," +
                                             "[MODIFY_DATE] = GETDATE() " +
                                             "where [EBELN] = '" + gSapMaterialReservationInfo.Key.Ebeln + "';");
                    continue;
                }
                ///校验供应商
                SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == gSapMaterialReservationInfo.Key.Lifnr);
                if (!string.IsNullOrEmpty(gSapMaterialReservationInfo.Key.Lifnr) && supplierInfo == null)
                {
                    stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                             "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                             "[PROCESS_TIME] = GETDATE()," +
                                             "[COMMENTS] = N'0x00000239'," +///供应商数据错误
                                             "[MODIFY_USER] = N'" + loginUser + "'," +
                                             "[MODIFY_DATE] = GETDATE() " +
                                             "where [EBELN] = '" + gSapMaterialReservationInfo.Key.Ebeln + "';");
                    continue;
                }
                ///是否存在单据明细数据
                List <SapMaterialReservationInfo> sapMaterialReservations = sapMaterialReservationInfos.Where(d => d.Ebeln == gSapMaterialReservationInfo.Key.Ebeln).ToList();
                if (sapMaterialReservations.Count == 0)
                {
                    stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                             "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                             "[PROCESS_TIME] = GETDATE()," +
                                             "[COMMENTS] = N'0x00000084'," +///数据错误
                                             "[MODIFY_USER] = N'" + loginUser + "'," +
                                             "[MODIFY_DATE] = GETDATE() " +
                                             "where [EBELN] = '" + gSapMaterialReservationInfo.Key.Ebeln + "';");
                    continue;
                }

                #region TT_MPM_SAP_PURCHASE_ORDER
                ///采购订单号默认为SAP采购订单号
                string orderCode = gSapMaterialReservationInfo.Key.Ebeln;
                ///如果采购订单号为空,则以预留单号作为采购订单号
                ///TODO:后期考虑这种形式直接写入供应商退货单表
                if (string.IsNullOrEmpty(orderCode))
                {
                    orderCode = gSapMaterialReservationInfo.Key.Rsnum;
                }

                SapPurchaseOrderInfo sapPurchaseOrderInfo = new SapPurchaseOrderInfo();
                sapPurchaseOrderInfo.Fid           = Guid.NewGuid();
                sapPurchaseOrderInfo.OrderCode     = orderCode;
                sapPurchaseOrderInfo.SWmNo         = sZone == null ? string.Empty : sZone.WmNo;
                sapPurchaseOrderInfo.SZoneNo       = sZone == null ? string.Empty : sZone.ZoneNo;
                sapPurchaseOrderInfo.TWmNo         = tZone == null ? string.Empty : tZone.WmNo;
                sapPurchaseOrderInfo.TZoneNo       = tZone == null ? string.Empty : tZone.ZoneNo;
                sapPurchaseOrderInfo.RequireDate   = gSapMaterialReservationInfo.Key.Bdter;
                sapPurchaseOrderInfo.SupplierNum   = supplierInfo == null ? string.Empty : supplierInfo.SupplierNum;
                sapPurchaseOrderInfo.SupplierSname = supplierInfo == null ? string.Empty : supplierInfo.SupplierSname;
                sapPurchaseOrderInfo.SupplierName  = supplierInfo == null ? string.Empty : supplierInfo.SupplierName;
                sapPurchaseOrderInfo.CustCode      = gSapMaterialReservationInfo.Key.Wempf;
                sapPurchaseOrderInfo.SapBwart      = gSapMaterialReservationInfo.Key.Bwart;
                sapPurchaseOrderInfo.SapKostl      = gSapMaterialReservationInfo.Key.Kostl;
                sapPurchaseOrderInfo.SapLgort      = gSapMaterialReservationInfo.Key.Lgort;
                sapPurchaseOrderInfo.SapUmlgo      = gSapMaterialReservationInfo.Key.Umlgo;
                sapPurchaseOrderInfo.SapWempf      = gSapMaterialReservationInfo.Key.Wempf;
                sapPurchaseOrderInfo.SapLifnr      = gSapMaterialReservationInfo.Key.Lifnr;
                sapPurchaseOrderInfo.SapRsnum      = gSapMaterialReservationInfo.Key.Rsnum;
                sapPurchaseOrderInfo.SapEbeln      = gSapMaterialReservationInfo.Key.Ebeln;
                sapPurchaseOrderInfo.Status        = (int)PullOrderStatusConstants.Released;
                sapPurchaseOrderInfo.CreateUser    = loginUser;
                stringBuilder.AppendLine(SapPurchaseOrderDAL.GetInsertSql(sapPurchaseOrderInfo));
                #endregion

                List <SapPurchaseOrderDetailInfo> sapPurchaseOrderDetailInfos = new List <SapPurchaseOrderDetailInfo>();
                foreach (var sapMaterialReservation in sapMaterialReservations)
                {
                    ///校验物料基础信息
                    MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == sapMaterialReservation.Matnr);
                    if (maintainPartsInfo == null)
                    {
                        stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                                 "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                                 "[PROCESS_TIME] = GETDATE()," +
                                                 "[COMMENTS] = N'0x00000417', " +///物料信息数据错误
                                                 "[MODIFY_USER] = N'" + loginUser + "'," +
                                                 "[MODIFY_DATE] = GETDATE() " +
                                                 "where [ID] = '" + sapMaterialReservation.Id + "';");
                        continue;
                    }
                    ///中转库存地点的物料仓储信息
                    PartsStockInfo partsStockInfo = partsStockInfos.FirstOrDefault(d =>
                                                                                   d.PartNo == maintainPartsInfo.PartNo &&
                                                                                   d.SupplierNum == supplierInfo.SupplierNum &&
                                                                                   d.ZoneNo == sZone.ZoneNo &&
                                                                                   d.WmNo == sZone.WmNo);


                    if (!string.IsNullOrEmpty(gSapMaterialReservationInfo.Key.Lgort) && partsStockInfo == null)
                    {
                        stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                                 "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                                 "[PROCESS_TIME] = GETDATE()," +
                                                 "[COMMENTS] = N'0x00000241'," + ///物料仓储信息数据错误
                                                 "[MODIFY_USER] = N'" + loginUser + "'," +
                                                 "[MODIFY_DATE] = GETDATE() " +
                                                 "where [ID] = " + sapMaterialReservation.Id + ";");
                        continue;
                    }
                    ///接收库存地点的物料仓储信息
                    if (tZone != null)
                    {
                        PartsStockInfo tPartsStockInfo = partsStockInfos.FirstOrDefault(d =>
                                                                                        d.PartNo == maintainPartsInfo.PartNo &&
                                                                                        d.SupplierNum == supplierInfo.SupplierNum &&
                                                                                        d.ZoneNo == tZone.ZoneNo &&
                                                                                        d.WmNo == tZone.WmNo);
                        if (tPartsStockInfo == null)
                        {
                            stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                                     "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                                     "[PROCESS_TIME] = GETDATE()," +
                                                     "[COMMENTS] = N'0x00000241'," +///物料仓储信息数据错误
                                                     "[MODIFY_USER] = N'" + loginUser + "'," +
                                                     "[MODIFY_DATE] = GETDATE() " +
                                                     "where [ID] = " + sapMaterialReservation.Id + ";");
                            continue;
                        }
                    }

                    #region TT_MPM_SAP_PURCHASE_ORDER_DETAIL
                    SapPurchaseOrderDetailInfo sapPurchaseOrderDetailInfo = new SapPurchaseOrderDetailInfo();
                    sapPurchaseOrderDetailInfo.OrderFid        = sapPurchaseOrderInfo.Fid;
                    sapPurchaseOrderDetailInfo.PartNo          = maintainPartsInfo.PartNo;
                    sapPurchaseOrderDetailInfo.PartCname       = maintainPartsInfo.PartCname;
                    sapPurchaseOrderDetailInfo.PartEname       = maintainPartsInfo.PartEname;
                    sapPurchaseOrderDetailInfo.PartQty         = sapMaterialReservation.Menge;
                    sapPurchaseOrderDetailInfo.PartPurchaseUom = maintainPartsInfo.PartUnits;
                    sapPurchaseOrderDetailInfo.PartUom         = maintainPartsInfo.PartUnits;
                    sapPurchaseOrderDetailInfo.Package         = partsStockInfo.InboundPackage;
                    sapPurchaseOrderDetailInfo.PackageModel    = partsStockInfo.InboundPackageModel;
                    if (partsStockInfo.InboundPackage.GetValueOrDefault() > 0)
                    {
                        sapPurchaseOrderDetailInfo.RequirePackageQty = Convert.ToInt32(Math.Ceiling(decimal.Parse(sapMaterialReservation.Menge.GetValueOrDefault().ToString()) / partsStockInfo.InboundPackage.GetValueOrDefault()));
                    }
                    sapPurchaseOrderDetailInfo.SapMenge = sapMaterialReservation.Menge;
                    sapPurchaseOrderDetailInfo.SapRsnum = sapMaterialReservation.Rsnum;

                    if (!int.TryParse(sapMaterialReservation.Rspos, out int converintRspos))
                    {
                        throw new Exception("MC:0x00000397");///预留行号错误
                    }
                    sapPurchaseOrderDetailInfo.SapRspos   = converintRspos;
                    sapPurchaseOrderDetailInfo.SapEbeln   = sapMaterialReservation.Ebeln;
                    sapPurchaseOrderDetailInfo.SapEbelp   = sapMaterialReservation.Ebelp;
                    sapPurchaseOrderDetailInfo.SapBwart   = sapMaterialReservation.Bwart;
                    sapPurchaseOrderDetailInfo.SapKostl   = sapMaterialReservation.Kostl;
                    sapPurchaseOrderDetailInfo.SapLgort   = sapMaterialReservation.Lgort;
                    sapPurchaseOrderDetailInfo.SapUmlgo   = sapMaterialReservation.Umlgo;
                    sapPurchaseOrderDetailInfo.SapWempf   = sapMaterialReservation.Wempf;
                    sapPurchaseOrderDetailInfo.SapLifnr   = sapMaterialReservation.Lifnr;
                    sapPurchaseOrderDetailInfo.Status     = (int)PullOrderStatusConstants.Released;
                    sapPurchaseOrderDetailInfo.CreateUser = loginUser;
                    stringBuilder.AppendLine(SapPurchaseOrderDetailDAL.GetInsertSql(sapPurchaseOrderDetailInfo));
                    #endregion

                    sapPurchaseOrderDetailInfos.Add(sapPurchaseOrderDetailInfo);
                    dealedIds.Add(sapMaterialReservation.Id);
                }

                #region 单据衔接
                if (sapPurchaseOrderDetailInfos.Count > 0)
                {
                    int orderType = (int)SapPurchaseOrderTypeConstants.PurchaseOrder;

                    ///若SAP预留单号不为空时,系统认为是预留订单
                    //todo 0是否为空
                    if (!string.IsNullOrEmpty(sapPurchaseOrderInfo.SapRsnum) && sapPurchaseOrderInfo.SapRsnum.ToString() != "0")
                    {
                        orderType = (int)SapPurchaseOrderTypeConstants.ReservationOrder;
                    }
                    ///若SAP采购订单号为空时,系统认为是物料退货
                    if (string.IsNullOrEmpty(sapPurchaseOrderInfo.SapEbeln))
                    {
                        orderType = (int)SapPurchaseOrderTypeConstants.ReturnOrder;
                    }

                    MaterialPullingOrderInfo mpOrder = new MaterialPullingOrderInfo();
                    mpOrder.OrderNo          = sapPurchaseOrderInfo.OrderCode;
                    mpOrder.PartBoxCode      = string.Empty;                                 ///零件类2
                    mpOrder.PartBoxName      = string.Empty;                                 ///零件类名称3
                    mpOrder.Plant            = (sZone == null ? string.Empty : sZone.Plant); ///工厂4,TODO:是否增加工厂字段
                    mpOrder.Workshop         = string.Empty;                                 ///车间5
                    mpOrder.AssemblyLine     = string.Empty;                                 ///流水线6
                    mpOrder.SupplierNum      = sapPurchaseOrderInfo.SupplierNum;             ///供应商代码7
                    mpOrder.SupplierName     = sapPurchaseOrderInfo.SupplierName;            ///供应商名称
                    mpOrder.SourceZoneNo     = sapPurchaseOrderInfo.TZoneNo;                 ///接收存储区
                    mpOrder.SourceWmNo       = sapPurchaseOrderInfo.TWmNo;                   ///接收仓库
                    mpOrder.TargetZoneNo     = sapPurchaseOrderInfo.SZoneNo;                 ///中转存储区
                    mpOrder.TargetWmNo       = sapPurchaseOrderInfo.SWmNo;                   ///中转仓库
                    mpOrder.TargetDock       = string.Empty;                                 ///道口12,TODO:是否增加道口字段
                    mpOrder.PlanShippingTime = sapPurchaseOrderInfo.RequireDate;             ///建议交货时间
                    mpOrder.PlanDeliveryTime = sapPurchaseOrderInfo.RequireDate;             ///预计到厂时间
                    mpOrder.PublishTime      = DateTime.Now;
                    mpOrder.OrderType        = orderType;                                    ///SAP订单类型
                    mpOrder.PullMode         = (int)PullModeConstants.PurchaseOrder;
                    mpOrder.MaterialPullingOrderDetailInfos = (from m in sapPurchaseOrderDetailInfos
                                                               select new MaterialPullingOrderDetailInfo
                    {
                        OrderNo = sapPurchaseOrderInfo.OrderCode,                    ///拉动单号1
                        SupplierNum = sapPurchaseOrderInfo.SupplierNum,              ///供应商2
                        PartNo = m.PartNo,                                           ///物料号3
                        PartCname = m.PartCname,                                     ///物料号中文名称4
                        PartEname = m.PartEname,                                     ///物料号英文名称5
                        Uom = m.PartUom,                                             ///计量单位6
                        PackageQty = m.Package.GetValueOrDefault(),                  ///入库单包装数量7
                        PackageModel = m.PackageModel,                               ///入库包装编号8
                        RequirePackageQty = m.RequirePackageQty.GetValueOrDefault(), ///需求包装数量9
                        RequirePartQty = m.PartQty.GetValueOrDefault(),              ///需求物料数量10
                        SourceWmNo = sapPurchaseOrderInfo.TWmNo,                     ///接收仓库
                        SourceZoneNo = sapPurchaseOrderInfo.TZoneNo,                 ///接收存储区
                        TargetWmNo = sapPurchaseOrderInfo.SWmNo,                     ///中转仓库
                        TargetZoneNo = sapPurchaseOrderInfo.SZoneNo                  ///中转存储区
                    }).ToList();
                    ///执行单据衔接
                    stringBuilder.AppendLine(MaterialPullingCommonBLL.Handler(mpOrder, loginUser));
                }
                #endregion
            }
            if (dealedIds.Count > 0)
            {
                ///已处理的中间表数据更新为已处理状态
                stringBuilder.Append("update [LES].[TI_IFM_SAP_MATERIAL_RESERVATION] " +
                                     "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                     "[PROCESS_TIME] = GETDATE()," +
                                     "[COMMENTS] = NULL," +
                                     "[MODIFY_USER] = N'" + loginUser + "'," +
                                     "[MODIFY_DATE] = GETDATE() " +
                                     "where [ID] in (" + string.Join(",", dealedIds.ToArray()) + ");");
            }
            ///执行
            using (var trans = new TransactionScope())
            {
                if (stringBuilder.Length > 0)
                {
                    BLL.SYS.CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString());
                }
                trans.Complete();
            }
        }
示例#4
0
        public void Handler()
        {
            ///获取交易处理状态⑲为10.未处理的包装交易记录--TT_PCM_PACKAGE_TRAN_DETAIL
            List <PackageTranDetailInfo> packageTranDetailInfos = new PackageTranDetailBLL().GetList("[STATUS] = " + (int)PackageTranStateConstants.UNTREATED + "", "[ID]");

            if (packageTranDetailInfos.Count == 0)
            {
                return;
            }
            ///获取涉及的所有包装库存--TT_PCM_PACKAGE_STOCKS
            List <PackageStocksInfo> packageStocksInfos
                = packageStocksBLL.GetList("[PLANT] in ('" + string.Join("','", packageTranDetailInfos.Select(d => d.Plant).ToArray()) + "') "
                                           + "and [WM_NO] in ('" + string.Join("','", packageTranDetailInfos.Select(d => d.TargetWm).ToArray()) + "') "
                                           + "and [ZONE_NO] in ('" + string.Join("','", packageTranDetailInfos.Select(d => d.TargetZone).ToArray()) + "') "
                                           + "and [DLOC] in ('" + string.Join("','", packageTranDetailInfos.Select(d => d.TargetDloc).ToArray()) + "')", string.Empty);
            ///存储区
            List <ZonesInfo> zonesInfos = new ZonesBLL().GetList("[ZONE_NO] in ('" + string.Join("','", packageTranDetailInfos.Select(d => d.ZoneNo).ToArray()) + "',"
                                                                 + "'" + string.Join("','", packageTranDetailInfos.Select(d => d.TargetZone).ToArray()) + "')", string.Empty);
            ///工厂
            List <PlantInfo> plantInfos = new PlantBLL().GetListForInterfaceDataSync();
            ///供应商
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetListForInterfaceDataSync(packageTranDetailInfos.Select(d => d.SupplierNum).ToList());
            ///物料
            List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetListForInterfaceDataSync(packageTranDetailInfos.Select(d => d.PartNo).ToList());

            ///逐条处理
            foreach (var packageTranDetailInfo in packageTranDetailInfos)
            {
                ///物料信息
                MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == packageTranDetailInfo.PartNo && d.Plant == packageTranDetailInfo.Plant);
                ///创建库存对象
                PackageStocksInfo packageStocksInfo = null;
                StringBuilder     stringBuilder     = new StringBuilder();

                switch (packageTranDetailInfo.TranType.GetValueOrDefault())
                {
                ///对于交易类型②为10//随货入库
                case (int)PackageTranTypeConstants.FullInbound:
                    ///需要对工厂⑤、目标仓库⑪、目标存储区⑫、目标库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, false);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, false);
                    }
                    ///对其满包装数⑭以及库存数⑫进行累加,累加数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.FullPackageStocksUpSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    break;

                ///对于交易类型②为20//随货移库
                case (int)PackageTranTypeConstants.FullMovement:
                    ///来源减少
                    ///需要对工厂⑤、来源仓库⑪、来源存储区⑫、来源库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, true);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, true);
                    }
                    ///对其满包装数⑭以及库存数⑫进行扣减,扣减数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.FullPackageStocksDownSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    ///目标增加
                    ///需要对工厂⑤、目标仓库⑪、目标存储区⑫、目标库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, false);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, false);
                    }
                    ///对其满包装数⑭以及库存数⑫进行累加,累加数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.FullPackageStocksUpSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    break;

                ///对于交易类型②为30//随货出库
                case (int)PackageTranTypeConstants.FullOutbound:
                    ///需要对工厂⑤、来源仓库⑪、来源存储区⑫、来源库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, true);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, true);
                    }
                    ///对其满包装数⑭以及库存数⑫进行扣减,扣减数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.FullPackageStocksDownSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    break;

                ///对于交易类型②为40//空器具入库
                case (int)PackageTranTypeConstants.EmptyInbound:
                    ///需要对工厂⑤、目标仓库⑪、目标存储区⑫、目标库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, false);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, false);
                    }
                    ///对其空包装数⑭以及库存数⑫进行累加,累加数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.EmptyPackageStocksUpSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    break;

                ///对于交易类型②为50//空器具移库
                case (int)PackageTranTypeConstants.EmptyMovement:
                    ///来源减少
                    ///需要对工厂⑤、来源仓库⑪、来源存储区⑫、来源库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, true);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, true);
                    }
                    ///对其空包装数⑭以及库存数⑫进行扣减,扣减数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.EmptyPackageStocksDownSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    ///目标增加
                    ///需要对工厂⑤、目标仓库⑪、目标存储区⑫、目标库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, false);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, false);
                    }
                    ///对其空包装数⑭以及库存数⑫进行累加,累加数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.EmptyPackageStocksUpSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    break;

                ///对于交易类型②为60//空器具出库
                case (int)PackageTranTypeConstants.EmptyOutbound:
                    ///需要对工厂⑤、来源仓库⑪、来源存储区⑫、来源库位⑬的包装库存数据
                    packageStocksInfo = GetPackageStocksData(packageStocksInfos, packageTranDetailInfo, true);
                    if (packageStocksInfo == null)
                    {
                        packageStocksInfo = HandlingPackageStocksData(packageTranDetailInfo, maintainPartsInfo, true);
                    }
                    ///对其空包装数⑭以及库存数⑫进行扣减,扣减数量为包装数量,完成后标记交易处理状态⑲为20.已处理
                    stringBuilder.AppendFormat(packageStocksBLL.EmptyPackageStocksDownSql(packageStocksInfo, packageTranDetailInfo, loginUser));
                    break;
                }
                ///执行
                using (TransactionScope trans = new TransactionScope())
                {
                    if (stringBuilder.Length > 0)
                    {
                        BLL.LES.CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString());
                    }
                    trans.Complete();
                }
            }
        }
示例#5
0
        /// <summary>
        /// Handler
        /// </summary>
        public void Handler()
        {
            InitConfigFlag();
            ///获取未同步的交易记录
            List <TranDetailsInfo> tranDetailsInfos = new TranDetailsBLL().GetList("[TRAN_STATE] = " + (int)WmmTranStateConstants.Created + "", "[ID]");

            if (tranDetailsInfos.Count == 0)
            {
                return;
            }
            ///仓库
            List <string> wmNos = tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.WmNo)).Select(d => d.WmNo).ToList();

            wmNos.AddRange(tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.TargetWm)).Select(d => d.TargetWm).ToList());
            List <WarehouseInfo> warehouseInfos = new WarehouseBLL().GetList("[WAREHOUSE] in ('" + string.Join("','", wmNos.ToArray()) + "')", string.Empty);
            ///存储区
            List <string> zoneNos = tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.ZoneNo)).Select(d => d.ZoneNo).ToList();

            zoneNos.AddRange(tranDetailsInfos.Where(d => !string.IsNullOrEmpty(d.TargetZone)).Select(d => d.TargetZone).ToList());
            List <ZonesInfo> zonesInfos = new ZonesBLL().GetList("[ZONE_NO] in ('" + string.Join("','", zoneNos.ToArray()) + "')", string.Empty);
            ///工厂
            List <PlantInfo> plantInfos = new PlantBLL().GetListForInterfaceDataSync();
            ///供应商
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetListForInterfaceDataSync(tranDetailsInfos.Select(d => d.SupplierNum).ToList());
            ///物料
            List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetListForInterfaceDataSync(tranDetailsInfos.Select(d => d.PartNo).ToList());


            ///逐条处理
            foreach (var tranDetailsInfo in tranDetailsInfos)
            {
                StringBuilder stringBuilder = new StringBuilder();
                ///工厂
                PlantInfo plantInfo = plantInfos.FirstOrDefault(d => d.Plant == tranDetailsInfo.Plant);
                ///供应商
                SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == tranDetailsInfo.SupplierNum);
                ///目标仓库
                WarehouseInfo targetWarehouseInfo = warehouseInfos.FirstOrDefault(d => d.Warehouse == tranDetailsInfo.TargetWm);
                ///目标存储区
                ZonesInfo targetZonesInfo = zonesInfos.FirstOrDefault(d => d.ZoneNo == tranDetailsInfo.TargetZone);
                ///目标工厂
                PlantInfo targetPlantInfo = targetZonesInfo == null ? null : plantInfos.FirstOrDefault(d => d.Plant == targetZonesInfo.Plant);
                ///来源
                ZonesInfo sourceZonesInfo = zonesInfos.FirstOrDefault(d => d.ZoneNo == tranDetailsInfo.ZoneNo);
                ///来源工厂
                PlantInfo sourcePlantInfo = sourceZonesInfo == null ? null : plantInfos.FirstOrDefault(d => d.Plant == sourceZonesInfo.Plant);
                ///物料信息
                MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == tranDetailsInfo.PartNo && d.Plant == tranDetailsInfo.Plant);
                ///创建库存对象
                StocksInfo stocksInfo = null;
                ///
                switch (tranDetailsInfo.TranType.GetValueOrDefault())
                {
                ///物料入库
                case (int)WmmTranTypeConstants.Inbound:
                    ///目标可用库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///撤销入库
                case (int)WmmTranTypeConstants.UndoInbound:
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    UndoStock(ref stocksInfo);
                    stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///物料出库
                case (int)WmmTranTypeConstants.Outbound:
                    ///来源可用库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///撤销出库
                case (int)WmmTranTypeConstants.UndoOutbound:
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    UndoStock(ref stocksInfo);
                    stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///冻结入库
                case (int)WmmTranTypeConstants.FrozenInbound:
                    ///目标冻结库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///冻结出库
                case (int)WmmTranTypeConstants.FrozenOutbound:
                    ///来源冻结库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///物料冻结
                case (int)WmmTranTypeConstants.MaterialFreezing:
                    ///来源可用库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    ///目标冻结库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///状态冻结
                case (int)WmmTranTypeConstants.StateFreezing:
                    ///来源可用库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    ///来源冻结库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///物料解冻
                case (int)WmmTranTypeConstants.MaterialThawing:
                    ///来源冻结库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    ///目标可用库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///状态解冻
                case (int)WmmTranTypeConstants.StateThawing:
                    ///来源可用库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    ///来源冻结库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///冻结移动
                case (int)WmmTranTypeConstants.FrozenMovement:
                    ///来源冻结库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.FrozenReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    ///目标冻结库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    stringBuilder.AppendFormat(stocksBLL.FrozenRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                ///物料移动
                case (int)WmmTranTypeConstants.Movement:
                    ///来源可用库存减少
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, sourceZonesInfo, true);
                    stringBuilder.AppendFormat(stocksBLL.StocksReduceSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    ///目标可用库存增加
                    stocksInfo = HandlingStocksData(tranDetailsInfo, maintainPartsInfo, targetZonesInfo, false);
                    stringBuilder.AppendFormat(stocksBLL.StocksRaiseSql(stocksInfo, tranDetailsInfo.Id, loginUser));
                    break;

                default: continue;
                }
                ///SAP移动数据
                stringBuilder.AppendFormat(CreateSapTranData(tranDetailsInfo, sourceZonesInfo, targetZonesInfo, sourcePlantInfo, targetPlantInfo));
                ///SRM入库数据
                stringBuilder.AppendFormat(CreateSrmTranData(tranDetailsInfo, supplierInfo, targetWarehouseInfo));
                ///WMS入库数据
                stringBuilder.AppendFormat(CreateVmiTranData(tranDetailsInfo, supplierInfo, targetWarehouseInfo));


                #region 执行
                using (TransactionScope trans = new TransactionScope())
                {
                    if (stringBuilder.Length > 0)
                    {
                        BLL.LES.CommonBLL.ExecuteNonQueryBySql(stringBuilder.ToString());
                    }
                    trans.Complete();
                }
                #endregion
                Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + stocksInfo.PartNo + "|" + tranDetailsInfo.TranType.GetValueOrDefault() + "|" + stocksInfo.WmNo + "|" + stocksInfo.ZoneNo + "|" + stocksInfo.Dloc + "|");
            }
        }