예제 #1
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();
            }
        }
예제 #2
0
        /// <summary>
        /// Sync
        /// </summary>
        public static void Sync(string loginUser)
        {
            ///获取未处理的检验模式中间表数据
            List <WmsVmiTranDetailInfo> wmsVmiTranDetailInfos = new WmsVmiTranDetailBLL().GetList("[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", string.Empty);

            if (wmsVmiTranDetailInfos.Count == 0)
            {
                return;
            }
            StringBuilder @string = new StringBuilder();

            ///获取仓库信息
            List <WarehouseInfo> warehouseInfos = new WarehouseBLL().GetList("" +
                                                                             "[WAREHOUSE] in ('" + string.Join("','", wmsVmiTranDetailInfos.Select(d => d.VmiWarehouseCode).ToArray()) + "') "
                                                                             // + " and [WAREHOUSE_TYPE] = " + (int)WarehouseTypeConstants.VMI + ""
                                                                             , string.Empty);

            if (warehouseInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000230' where " +
                                   "[ID] in (" + string.Join(",", wmsVmiTranDetailInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///获取供应商信息
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetList("" +
                                                                          "[SUPPLIER_NUM] in ('" + string.Join("','", wmsVmiTranDetailInfos.Select(d => d.SupplierCode).ToArray()) + "') and " +
                                                                          "[SUPPLIER_TYPE] = " + (int)SupplierTypeConstants.MaterialSupplier + "", string.Empty);

            if (supplierInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000229' where " +
                                   "[ID] in (" + string.Join(",", wmsVmiTranDetailInfos.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_TRAN_DETAIL] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000429' where " +
                                   "[ID] in (" + string.Join(",", wmsVmiTranDetailInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }

            ///获取相关物料基础信息
            List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetList("[PART_NO] in ('" + string.Join("','", wmsVmiTranDetailInfos.Select(d => d.PartNo).ToArray()) + "')", string.Empty);
            ///获取相关物料仓储信息
            List <PartsStockInfo> partsStockInfos = new PartsStockBLL().GetList("" +
                                                                                "[PART_NO] in ('" + string.Join("','", wmsVmiTranDetailInfos.Select(d => d.PartNo).ToArray()) + "') and " +
                                                                                "[WM_NO] in ('" + string.Join("','", warehouseInfos.Select(d => d.Warehouse).ToArray()) + "')", string.Empty);
            ///

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

            foreach (WmsVmiTranDetailInfo wmsVmiTranDetailInfo in wmsVmiTranDetailInfos)
            {
                var vmiWareHouseInfo = warehouseInfos.FirstOrDefault(fod => fod.Warehouse == wmsVmiTranDetailInfo.VmiWarehouseCode);
                if (vmiWareHouseInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000230' where " +///VMI供应商信息未维护
                                       "[ID] = " + wmsVmiTranDetailInfo.Id + ";");
                    continue;
                }
                if (vmiWareHouseInfo.WarehouseType != (int)WarehouseTypeConstants.VMI)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000518' where " +///VMI供应商信息未维护
                                       "[ID] = " + wmsVmiTranDetailInfo.Id + ";");
                    continue;
                }

                ///VMI供应商关系
                VmiSupplierInfo vmiSupplierInfo = vmiSupplierInfos.FirstOrDefault(d => d.SupplierNum == wmsVmiTranDetailInfo.SupplierCode && d.WmNo == wmsVmiTranDetailInfo.VmiWarehouseCode);
                if (vmiSupplierInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000429' where " +///VMI供应商信息未维护
                                       "[ID] = " + wmsVmiTranDetailInfo.Id + ";");
                    continue;
                }
                if (!vmiSupplierInfo.VmiFlag.GetValueOrDefault())
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000466' where " +///该供应商未启用WMS功能
                                       "[ID] = " + wmsVmiTranDetailInfo.Id + ";");
                    continue;
                }
                if (string.IsNullOrEmpty(vmiSupplierInfo.ZoneNo))
                {
                    @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000481' where " +///VMI存储区未配置
                                       "[ID] = " + wmsVmiTranDetailInfo.Id + ";");
                    continue;
                }

                ///指定存储区
                wmsVmiTranDetailInfo.ZoneNo = vmiSupplierInfo.ZoneNo;
                ///创建交易
                TranDetailsInfo tranDetailsInfo = TranDetailsBLL.CreateTranDetailsInfo(loginUser);
                ///PartsStockInfo -> TranDetailsInfo
                PartsStockInfo partsStockInfo = partsStockInfos.FirstOrDefault(d =>
                                                                               d.PartNo == wmsVmiTranDetailInfo.PartNo && d.WmNo == vmiSupplierInfo.WmNo && d.ZoneNo == vmiSupplierInfo.ZoneNo);
                TranDetailsBLL.GetTranDetailsInfo(partsStockInfo, ref tranDetailsInfo);

                ///WmsVmiTranDetailInfo -> TranDetailsInfo
                wmsVmiTranDetailInfo.Dloc = partsStockInfo.Dloc;

                TranDetailsBLL.GetTranDetailsInfo(wmsVmiTranDetailInfo, ref tranDetailsInfo);
                ///MaintainPartsInfo -> TranDetailsInfo
                MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == tranDetailsInfo.PartNo);
                TranDetailsBLL.GetTranDetailsInfo(maintainPartsInfo, ref tranDetailsInfo);

                ///SupplierInfo -> TranDetailsInfo
                SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == tranDetailsInfo.SupplierNum);
                TranDetailsBLL.GetTranDetailsInfo(supplierInfo, ref tranDetailsInfo);
                ///包装数量计算
                TranDetailsBLL.CalculateTranDetailsInfo(ref tranDetailsInfo);

                ///获取库存交易记录的生成语句
                @string.AppendLine(TranDetailsDAL.GetInsertSql(tranDetailsInfo));
                dealedIds.Add(wmsVmiTranDetailInfo.Id);
            }
            if (dealedIds.Count > 0)
            {
                ///已处理的中间表数据更新为已处理状态
                @string.AppendLine("update [LES].[TI_IFM_WMS_VMI_TRAN_DETAIL] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                   "[PROCESS_TIME] = GETDATE() where " +
                                   "[ID] in (" + string.Join(",", dealedIds.ToArray()) + ");");
            }
            ///执行
            using (var trans = new TransactionScope())
            {
                if (@string.Length > 0)
                {
                    BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                }
                trans.Complete();
            }
        }
예제 #3
0
        /// <summary>
        /// 供应商发货单同步
        /// </summary>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public static void Sync(string loginUser)
        {
            ///获取没有处理的物料发货单表
            List <SrmVmiShippingNoteInfo> srmVmiShippingNoteInfos = new SrmVmiShippingNoteBLL().GetList("[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", "[ID]");

            if (srmVmiShippingNoteInfos.Count == 0)
            {
                return;
            }
            ///获取没有处理的物料发货单详情表
            List <SrmVmiShippingNoteDetailInfo> srmVmiShippingNoteDetailInfos = new SrmVmiShippingNoteDetailBLL().GetList("[NOTE_FID] in ('" + string.Join("','", srmVmiShippingNoteInfos.Select(d => d.LogFid).ToArray()) + "')", "[ID]");

            if (srmVmiShippingNoteDetailInfos.Count == 0)
            {
                return;
            }
            StringBuilder @string = new StringBuilder();
            ///获取相关仓库信息
            List <WarehouseInfo> warehouseInfos = new WarehouseBLL().GetList("[WAREHOUSE] in ('" + string.Join("','", srmVmiShippingNoteInfos.Select(d => d.VmiWmNo).ToArray()) + "')", string.Empty);

            if (warehouseInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000230' where " +///仓库信息不存在
                                   "[ID] in (" + string.Join("','", srmVmiShippingNoteInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///获取相关供应商基础信息
            List <SupplierInfo> supplierInfos = new SupplierBLL().GetList("[SUPPLIER_NUM] in ('" + string.Join("','", srmVmiShippingNoteInfos.Select(d => d.SupplierCode).ToArray()) + "')", string.Empty);

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

            if (vmiSupplierInfos.Count == 0)
            {
                @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                   "[PROCESS_TIME] = GETDATE()," +
                                   "[COMMENTS] = N'0x00000429' where " +///VMI供应商信息未维护
                                   "[ID] in (" + string.Join("','", srmVmiShippingNoteInfos.Select(d => d.Id).ToArray()) + ");");
                BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                return;
            }
            ///获取相关物料基础信息
            List <MaintainPartsInfo> maintainPartsInfos = new MaintainPartsBLL().GetList("" +
                                                                                         "[PART_NO] in ('" + string.Join("','", srmVmiShippingNoteDetailInfos.Select(d => d.Partno).ToArray()) + "')", string.Empty);
            ///获取相关物料仓储信息
            List <PartsStockInfo> partsStockInfos = new PartsStockBLL().GetList("" +
                                                                                "[PART_NO] in ('" + string.Join("','", srmVmiShippingNoteDetailInfos.Select(d => d.Partno).ToArray()) + "') and " +
                                                                                "[WM_NO] in ('" + string.Join("','", warehouseInfos.Select(d => d.Warehouse).ToArray()) + "')", string.Empty);
            ///获取相关包装器具基础信息
            List <PackageApplianceInfo> packageApplianceInfos = new List <PackageApplianceInfo>();

            if (partsStockInfos.Count > 0)
            {
                ///标准包装
                List <string> packageModels = partsStockInfos.
                                              Where(d => !string.IsNullOrEmpty(d.PackageModel)).
                                              Select(d => d.PackageModel).ToList();
                ///入库包装
                packageModels.AddRange(partsStockInfos.
                                       Where(d => !string.IsNullOrEmpty(d.InboundPackageModel) && !packageModels.Contains(d.InboundPackageModel)).
                                       Select(d => d.InboundPackageModel).ToList());
                ///上线包装
                packageModels.AddRange(partsStockInfos.
                                       Where(d => !string.IsNullOrEmpty(d.InhousePackageModel) && !packageModels.Contains(d.InhousePackageModel)).
                                       Select(d => d.InhousePackageModel).ToList());
                ///
                packageApplianceInfos = new PackageApplianceBLL().GetList("[PAKCAGE_NO] in ('" + string.Join("','", packageModels.ToArray()) + "')", string.Empty);
            }

            ///获取系统配置
            Dictionary <string, string> configs = new ConfigBLL().GetValuesByCodes(new string[] {
                "RELEASE_VMI_RECEIVE_ACTUAL_QTY_EQUALS_REQUIRED",
                "ENABLE_VMI_FLAG"
            });
            ///
            List <long> dealedIds = new List <long>();

            ///如果数据不为空,按照规则分发
            foreach (SrmVmiShippingNoteInfo srmVmiShippingNoteInfo in srmVmiShippingNoteInfos)
            {
                ///本单据的对应仓库
                WarehouseInfo warehouseInfo = warehouseInfos.FirstOrDefault(d => d.Warehouse == srmVmiShippingNoteInfo.VmiWmNo);
                ///如果未处理的物料发货单中仓库码不存在, 修改中间表数据为挂起状态
                if (warehouseInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000230' where " +///仓库信息不存在
                                       "[ID] = " + srmVmiShippingNoteInfo.Id + ";");
                    continue;
                }
                ///仓库类型不是VMI
                if (warehouseInfo.WarehouseType.GetValueOrDefault() != (int)WarehouseTypeConstants.VMI)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000219' where " +///仓库类型错误
                                       "[ID] = " + srmVmiShippingNoteInfo.Id + ";");
                    continue;
                }
                ///本发货单的物料明细
                List <SrmVmiShippingNoteDetailInfo> srmVmiShippingNoteDetails = srmVmiShippingNoteDetailInfos.Where(d =>
                                                                                                                    d.NoteFid.GetValueOrDefault() == srmVmiShippingNoteInfo.Fid).ToList();
                if (srmVmiShippingNoteDetails.Count == 0)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000465' where " +///发货单物料数据错误
                                       "[ID] = " + srmVmiShippingNoteInfo.Id + ";");
                    continue;
                }
                ///供应商
                SupplierInfo supplierInfo = supplierInfos.FirstOrDefault(d => d.SupplierNum == srmVmiShippingNoteInfo.SupplierCode);
                if (supplierInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000229' where " +///供应商信息不存在
                                       "[ID] = " + srmVmiShippingNoteInfo.Id + ";");
                    continue;
                }
                ///VMI供应商关系
                VmiSupplierInfo vmiSupplierInfo = vmiSupplierInfos.FirstOrDefault(d => d.SupplierNum == supplierInfo.SupplierNum && d.WmNo == warehouseInfo.Warehouse);
                if (vmiSupplierInfo == null)
                {
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000429' where " +///VMI供应商信息未维护
                                       "[ID] = " + srmVmiShippingNoteInfo.Id + ";");
                    continue;
                }

                ///如果该仓库启用的是VMI模块则需要将单据写入VMI入库单
                if (warehouseInfo.VmiEnable.GetValueOrDefault())
                {
                    ///发布VMI入库单时实收数量默认等于需求数量
                    configs.TryGetValue("RELEASE_VMI_RECEIVE_ACTUAL_QTY_EQUALS_REQUIRED", out string release_vmi_receive_actual_qty_equals_required);
                    ///创建VMI入库单,TODO:默认类型与状态
                    VmiReceiveInfo vmiReceiveInfo = VmiReceiveBLL.CreateVmiReceiveInfo(
                        loginUser,
                        (int)VmiReceiveTypeConstants.ProductionWarehousing,
                        (int)WmmOrderStatusConstants.Published);
                    ///SrmVmiShippingNoteInfo -> VmiReceiveInfo
                    VmiReceiveBLL.GetVmiReceiveInfo(srmVmiShippingNoteInfo, ref vmiReceiveInfo);
                    ///SupplierInfo -> VmiReceiveInfo
                    VmiReceiveBLL.GetVmiReceiveInfo(supplierInfo, ref vmiReceiveInfo);
                    ///VmiSupplierInfo -> VmiReceiveInfo
                    VmiReceiveBLL.GetVmiReceiveInfo(vmiSupplierInfo, ref vmiReceiveInfo);
                    ///生成入库单语句
                    @string.AppendLine(VmiReceiveDAL.GetInsertSql(vmiReceiveInfo));
                    ///
                    foreach (SrmVmiShippingNoteDetailInfo srmVmiShippingNoteDetail in srmVmiShippingNoteDetails)
                    {
                        ///创建VMI入库单明细
                        VmiReceiveDetailInfo vmiReceiveDetailInfo = VmiReceiveDetailBLL.CreateVmiReceiveDetailInfo(loginUser);
                        ///VmiReceiveInfo -> VmiReceiveDetailInfo
                        VmiReceiveDetailBLL.GetVmiReceiveDetailInfo(vmiReceiveInfo, ref vmiReceiveDetailInfo);
                        ///MaintainPartsInfo -> VmiReceiveDetailInfo
                        MaintainPartsInfo maintainPartsInfo = maintainPartsInfos.FirstOrDefault(d => d.PartNo == srmVmiShippingNoteDetail.Partno);
                        VmiReceiveDetailBLL.GetVmiReceiveDetailInfo(maintainPartsInfo, ref vmiReceiveDetailInfo);
                        ///PartsStockInfo -> VmiReceiveDetailInfo
                        PartsStockInfo partsStockInfo = partsStockInfos.FirstOrDefault(d => d.PartNo == srmVmiShippingNoteDetail.Partno && d.WmNo == warehouseInfo.Warehouse);
                        VmiReceiveDetailBLL.GetVmiReceiveDetailInfo(partsStockInfo, ref vmiReceiveDetailInfo);
                        ///PackageApplianceInfo -> VmiReceiveDetailInfo
                        PackageApplianceInfo packageApplianceInfo = partsStockInfo == null ? null : packageApplianceInfos.FirstOrDefault(d => d.PackageNo == partsStockInfo.InboundPackageModel);
                        VmiReceiveDetailBLL.GetVmiReceiveDetailInfo(packageApplianceInfo, ref vmiReceiveDetailInfo);
                        ///SrmVmiShippingNoteDetailInfo -> VmiReceiveDetailInfo
                        VmiReceiveDetailBLL.GetVmiReceiveDetailInfo(srmVmiShippingNoteDetail, ref vmiReceiveDetailInfo);
                        ///发布VMI入库单时实收数量默认等于需求数量
                        if (!string.IsNullOrEmpty(release_vmi_receive_actual_qty_equals_required) && release_vmi_receive_actual_qty_equals_required.ToLower() == "true")
                        {
                            ///ACTUAL_BOX_NUM
                            vmiReceiveDetailInfo.ActualBoxNum = vmiReceiveDetailInfo.RequiredBoxNum;
                            ///ACTUAL_QTY
                            vmiReceiveDetailInfo.ActualQty = vmiReceiveDetailInfo.RequiredQty;
                        }
                        ///生成入库单明细语句
                        @string.AppendLine(VmiReceiveDetailDAL.GetInsertSql(vmiReceiveDetailInfo));
                    }
                    dealedIds.Add(srmVmiShippingNoteInfo.Id);
                }
                ///如果未启用VMI模块,则根据WMS系统开关决定是否写入中间表
                else
                {
                    ///是否启用WMS系统标记
                    configs.TryGetValue("ENABLE_VMI_FLAG", out string enable_vmi_flag);
                    if (!string.IsNullOrEmpty(enable_vmi_flag) && enable_vmi_flag.ToLower() == "true" && vmiSupplierInfo.VmiFlag.GetValueOrDefault())
                    {
                        ///创建WMS入库单
                        WmsVmiInboundOrderInfo wmsVmiInboundOrderInfo = WmsVmiInboundOrderBLL.CreateWmsVmiInboundOrderInfo((int)ProcessFlagConstants.Untreated, loginUser);
                        ///SrmVmiShippingNoteInfo -> WmsVmiInboundOrderInfo
                        WmsVmiInboundOrderBLL.GetWmsVmiInboundOrderInfo(srmVmiShippingNoteInfo, ref wmsVmiInboundOrderInfo);
                        ///生成入库单语句
                        @string.AppendLine(WmsVmiInboundOrderDAL.GetInsertSql(wmsVmiInboundOrderInfo));
                        ///
                        foreach (SrmVmiShippingNoteDetailInfo srmVmiShippingNoteDetail in srmVmiShippingNoteDetails)
                        {
                            ///创建WMS入库单明细
                            WmsVmiInboundOrderDetailInfo wmsVmiInboundOrderDetailInfo = WmsVmiInboundOrderDetailBLL.CreateWmsVmiInboundOrderDetailInfo(loginUser);
                            ///WmsVmiInboundOrderInfo -> WmsVmiInboundOrderDetailInfo
                            WmsVmiInboundOrderDetailBLL.GetWmsVmiInboundOrderDetailInfo(wmsVmiInboundOrderInfo, ref wmsVmiInboundOrderDetailInfo);
                            ///
                            PartsStockInfo partsStockInfo = partsStockInfos.FirstOrDefault(d => d.PartNo == srmVmiShippingNoteDetail.Partno && d.WmNo == warehouseInfo.Warehouse);
                            WmsVmiInboundOrderDetailBLL.GetWmsVmiInboundOrderDetailInfo(partsStockInfo, ref wmsVmiInboundOrderDetailInfo);
                            ///SrmVmiShippingNoteDetailInfo -> WmsVmiInboundOrderDetailInfo
                            WmsVmiInboundOrderDetailBLL.GetWmsVmiInboundOrderDetailInfo(srmVmiShippingNoteDetail, ref wmsVmiInboundOrderDetailInfo);
                            ///生成WMS入库单明细语句
                            @string.AppendLine(WmsVmiInboundOrderDetailDAL.GetInsertSql(wmsVmiInboundOrderDetailInfo));
                        }
                        ///
                        string targetSystem = "VMI";
                        string methodCode   = "LES-WMS-001";
                        @string.AppendLine(BLL.LES.CommonBLL.GetCreateOutboundLogSql(
                                               targetSystem,
                                               wmsVmiInboundOrderInfo.LogFid.GetValueOrDefault(),
                                               methodCode,
                                               srmVmiShippingNoteInfo.ShippingCode,
                                               loginUser));
                        dealedIds.Add(srmVmiShippingNoteInfo.Id);
                        continue;
                    }
                    @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                       "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," +
                                       "[PROCESS_TIME] = GETDATE()," +
                                       "[COMMENTS] = N'0x00000466' where " +///该供应商未启用WMS功能
                                       "[ID] = " + srmVmiShippingNoteInfo.Id + ";");
                    continue;
                }
            }
            if (dealedIds.Count > 0)
            {
                ///已处理的中间表数据更新为已处理状态
                @string.AppendLine("update [LES].[TI_IFM_SRM_VMI_SHIPPING_NOTE] set " +
                                   "[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Processed + "," +
                                   "[PROCESS_TIME] = GETDATE() where " +
                                   "[ID] in (" + string.Join(",", dealedIds.ToArray()) + ");");
            }
            ///执行
            using (var trans = new TransactionScope())
            {
                if (@string.Length > 0)
                {
                    BLL.SYS.CommonBLL.ExecuteNonQueryBySql(@string.ToString());
                }
                trans.Complete();
            }
        }