/// <summary> /// 在线替换 /// </summary> /// <param name="bomRepleaceConditionInfos"></param> /// <param name="loginUser"></param> public void OnlineReplacement(List <BomRepleaceConditionInfo> bomRepleaceConditionInfos, string loginUser) { if (bomRepleaceConditionInfos.Count == 0) { return; } ///生产订单 List <PullOrdersInfo> pullOrdersInfos = new PullOrdersDAL().GetList("" + " and [CHANGE_FLAG]=" + (int)ChangeFlagConstants.NotReplaced + "", string.Empty); if (pullOrdersInfos.Count == 0) { return; } ///车辆状态点信息集合 List <VehiclePointStatusInfo> vehiclePointStatusInfos = new VehiclePointStatusDAL().GetList("" + "and [ORDER_NO] in ('" + string.Join("','", bomRepleaceConditionInfos.Select(d => d.StartPorderCode).ToArray()) + "')", string.Empty); if (vehiclePointStatusInfos.Count == 0) { return; } ///状态点集合 List <StatusPointInfo> statusPointInfos = new StatusPointDAL().GetList("" + "[STATUS_POINT_CODE] in ('" + string.Join("','", vehiclePointStatusInfos.Select(d => d.StatusPointCode).ToArray()) + "')", string.Empty); if (statusPointInfos.Count == 0) { return; } ///时间窗(过点累计方式)零件类 List <TwdPartBoxInfo> twdPartBoxInfos = new TwdPartBoxDAL().GetList("" + " and [STATUS] =" + (int)BasicDataStatusConstants.Enable + " " + " and [REQUIREMENT_ACCUMULATE_MODE]=" + (int)RequirementAccumulateModeConstants.PassSpot + "" + " and [STATUS_POINT_CODE] in ('" + string.Join("','", statusPointInfos.Select(d => d.StatusPointCode).ToArray()) + "')", string.Empty); ///排序拉动方式 零件类 List <JisPartBoxInfo> jisPartBoxInfos = new JisPartBoxDAL().GetList("" + " and [STATUS] =" + (int)BasicDataStatusConstants.Enable + "" + " and [STATUS_POINT_CODE] in ('" + string.Join("','", statusPointInfos.Select(d => d.StatusPointCode).ToArray()) + "')", string.Empty); ///相应的物料拉动信息 List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandardInfos = new MaintainInhouseLogisticStandardDAL().GetList("" + " and [STATUS] =" + (int)BasicDataStatusConstants.Enable + "" + " (and [INHOUSE_PART_CLASS] in ('" + string.Join("','", twdPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "')" + " or [INHOUSE_PART_CLASS] in ('" + string.Join("','", jisPartBoxInfos.Select(d => d.PartBoxCode).ToArray()) + "'))", string.Empty); if (maintainInhouseLogisticStandardInfos.Count == 0) { return; } foreach (BomRepleaceConditionInfo bomRepleaceConditionInfo in bomRepleaceConditionInfos) { ///有效时间内 if (!(bomRepleaceConditionInfo.ExecuteStartTime <= DateTime.Now) || !(DateTime.Now <= bomRepleaceConditionInfo.ExecuteEndTime)) { continue; } ///根据起始生产订单号,获取车辆状态点信息判断其是否在线,若未上线则不执行以下逻辑 PullOrdersInfo pullOrdersInfo = pullOrdersInfos.FirstOrDefault(d => d.OrderNo == bomRepleaceConditionInfo.StartPorderCode); if (pullOrdersInfo == null || pullOrdersInfo.OrderStatus != (int)OrderStatusConstants.AlreadOnline) { continue; } ///若已上线或已下线则需要根据其获取顺序号之后的所有在线生产订单,依次循环进行逻辑处理 TODO:已下线的逻辑? ///同一起始生产订单号可能出现在多条生产线的状态点上,以下为单生产订单处理逻辑 TODO:多条生产线的逻辑? ///已上线的生产订单: ///本生产订单对应的车辆状态点信息 List <VehiclePointStatusInfo> vehiclePointStatuss = vehiclePointStatusInfos.Where(d => d.OrderNo == pullOrdersInfo.OrderNo).ToList(); if (vehiclePointStatuss.Count == 0) { continue; } ///当前车辆最大状态点信息 VehiclePointStatusInfo vehiclePointStatusInfo = vehiclePointStatuss.Where(d => d.OrderNo == pullOrdersInfo.OrderNo).OrderByDescending(d => d.PassTime).FirstOrDefault(); if (vehiclePointStatusInfo == null) { continue; } ///当前顺序号之后的所有的车辆状态点信息 List <VehiclePointStatusInfo> vehiclePoints = vehiclePointStatusInfos.Where(d => d.SeqNo >= vehiclePointStatusInfo.SeqNo).ToList(); ///当前顺序号之后的所有在线生产订单 pullOrdersInfos = (from p in pullOrdersInfos join v in vehiclePoints on p.OrderNo equals v.OrderNo select p).Distinct().ToList(); ///依次循环进行逻辑处理 foreach (PullOrdersInfo pullOrder in pullOrdersInfos) { ///根据生产订单号获取其物料清单,作为后续匹配更改单的源数据 List <PullOrderBomInfo> pullOrderBomInfos = new PullOrderBomDAL().GetList("" + "and [ORDERFID]='" + pullOrdersInfo.Fid + "'", string.Empty); if (pullOrderBomInfos.Count == 0) { continue; } ///本生产订单对应的车辆状态点信息 List <VehiclePointStatusInfo> vehicles = vehiclePointStatusInfos.Where(d => d.OrderNo == pullOrdersInfo.OrderNo).ToList(); if (vehicles.Count == 0) { continue; } ///本产生订单对应的所有状态点信息 List <StatusPointInfo> statusPoints = statusPointInfos.Where(d => vehicles.Select(v => v.StatusPointCode).Contains(d.StatusPointCode)).ToList(); if (statusPoints.Count == 0) { continue; } ///已在线的生产订单在此时,需要根据所在状态点位置 VehiclePointStatusInfo vehiclePointStatus = vehiclePointStatusInfos.Where(d => d.OrderNo == pullOrder.OrderNo).OrderByDescending(d => d.PassTime).FirstOrDefault(); if (vehiclePointStatus == null) { continue; } StatusPointInfo statusPointInfo = statusPointInfos.FirstOrDefault(d => d.StatusPointCode == vehiclePointStatus.StatusPointCode); if (statusPointInfo == null) { continue; } ///将物料拉动的结果集分为三个部分,其一为未累计、其二为已累计未拉动、其三为已拉动 ///该生产订单对应的其后状态点 List <StatusPointInfo> notStatusPoints = statusPoints.Where(d => d.StatusPointSeq > statusPointInfo.StatusPointSeq).ToList(); ///该生产订单对应的状态点及之前的状态点 List <StatusPointInfo> yesStatusPoints = statusPoints.Where(d => d.StatusPointSeq <= statusPointInfo.StatusPointSeq).ToList(); ///其后的状态点 if (notStatusPoints.Count > 0) { ///其一为当前状态点位置之后的状态点对应的时间窗(过点累计方式)、排序拉动方式相应的物料拉动信息物料、供应商、工位 ///该逻辑获取的数据在此不做后续处理,但此逻辑请事先在程序中实现,将会到离队归队时使用 List <TwdPartBoxInfo> twdPartBoxs = twdPartBoxInfos.Where(d => notStatusPoints.Select(s => s.StatusPointCode).Contains(d.StatusPointCode)).ToList(); List <JisPartBoxInfo> jisPartBoxs = jisPartBoxInfos.Where(d => notStatusPoints.Select(s => s.StatusPointCode).Contains(d.StatusPointCode)).ToList(); ///零件类对应的物料拉动信息 if (twdPartBoxs.Count != 0 || jisPartBoxs.Count != 0) { ///生产订单的产线下的物料拉动信息 List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandards = maintainInhouseLogisticStandardInfos. Where(d => d.AssemblyLine == pullOrder.AssemblyLine).Where(d => (twdPartBoxs.Select(t => t.PartBoxCode).Contains(d.InhousePartClass)) || (jisPartBoxs.Select(j => j.PartBoxCode).Contains(d.InhousePartClass))).ToList(); if (maintainInhouseLogisticStandards.Count != 0) { ///拉动信息对应的Bom清单 List <PullOrderBomInfo> pullOrderBoms = pullOrderBomInfos.Where(d => maintainInhouseLogisticStandards.Select(m => m.PartNo).Contains(d.Zcomno) && maintainInhouseLogisticStandards.Select(m => m.SupplierNum).Contains(d.SupplierNum)).ToList(); } } } ///其二、其三目前没有较理想的方式区分开,暂时以已拉动处理、当前状态点位置之前包括该状态点位置对应的拉动方式相关物料拉动信息 if (yesStatusPoints.Count > 0) { List <TwdPartBoxInfo> twdPartBoxs = twdPartBoxInfos.Where(d => yesStatusPoints.Select(s => s.StatusPointCode).Contains(d.StatusPointCode)).ToList(); List <JisPartBoxInfo> jisPartBoxs = jisPartBoxInfos.Where(d => yesStatusPoints.Select(s => s.StatusPointCode).Contains(d.StatusPointCode)).ToList(); ///零件类对应的物料拉动信息 if (twdPartBoxs.Count != 0 || jisPartBoxs.Count != 0) { ///生产订单的产线下的物料拉动信息 List <MaintainInhouseLogisticStandardInfo> maintainInhouseLogisticStandards = maintainInhouseLogisticStandardInfos. Where(d => d.AssemblyLine == pullOrder.AssemblyLine).Where(d => (twdPartBoxs.Select(t => t.PartBoxCode).Contains(d.InhousePartClass)) || (jisPartBoxs.Select(j => j.PartBoxCode).Contains(d.InhousePartClass))).ToList(); maintainInhouseLogisticStandards = maintainInhouseLogisticStandards.Where(d => d.PartNo == bomRepleaceConditionInfo.OldPartNo).ToList(); ///根据已拉动的物料拉动信息,与替换条件中的旧物料号对比 ///若不存在于已拉动物料中,则只需要执行生产订单物料清单替换逻辑即可 ///否则需要进行新物料号的自动紧急拉动且生成旧物料号的余料退库单(退库地点为物料拉动信息中的来源库存地点) ///同时也需要执行生产订单物料清单替换逻辑 if (maintainInhouseLogisticStandards.Count > 0) { ///拉动信息对应的Bom清单 List <PullOrderBomInfo> pullOrderBoms = pullOrderBomInfos.Where(d => maintainInhouseLogisticStandards.Select(m => m.PartNo).Contains(d.Zcomno) && maintainInhouseLogisticStandards.Select(m => m.SupplierNum).Contains(d.SupplierNum)).ToList(); foreach (PullOrderBomInfo pullOrderBom in pullOrderBoms) { MaintainInhouseLogisticStandardInfo maintainInhouseLogisticStandardInfo = maintainInhouseLogisticStandards.FirstOrDefault(d => d.PartNo == pullOrderBom.Zcomno && d.SupplierNum == pullOrderBom.SupplierNum); if (maintainInhouseLogisticStandardInfo == null) { continue; } ///进行新物料号的自动紧急拉动 ///生成旧物料号的余料退库单(退库地点为物料拉动信息中的来源库存地点) } } new BomRepleaceConditionBLL().ReplacementCriteria(pullOrder, loginUser); } } } } }
/// <summary> /// 执行导入EXCEL数据 /// </summary> /// <param name="dataTable"></param> /// <param name="fieldNames"></param> /// <returns></returns> public bool ImportDataByExcel(DataTable dataTable, Dictionary <string, string> fieldNames, string loginUser) { List <JisPartBoxInfo> jisPartBoxes = CommonDAL.DatatableConvertToList <JisPartBoxInfo>(dataTable).ToList(); if (jisPartBoxes.Count == 0 || jisPartBoxes == null) { throw new Exception("MC:1x00000043");///数据格式不符合导入规范 } ///获取业务表中要变更的数据集合,准备对比 List <JisPartBoxInfo> jisParts = new JisPartBoxDAL().GetList(" [PART_BOX_CODE] in ('" + string.Join("', '", jisPartBoxes.Select(d => d.PartBoxCode).ToList().ToArray()) + "')", ""); List <JisPartBoxInfo> boxInfos = new JisPartBoxDAL().GetList(" [PART_BOX_NAME] in ('" + string.Join("', '", jisPartBoxes.Select(d => d.PartBoxName).ToList().ToArray()) + "')", ""); ///执行的SQL语句 string sql = string.Empty; List <string> fields = new List <string>(fieldNames.Keys); ///逐条处理中间表数据 foreach (var item in jisPartBoxes) { JisPartBoxInfo info = jisParts.FirstOrDefault(d => d.PartBoxCode == item.PartBoxCode); if (info == null) { if (string.IsNullOrEmpty(item.PartBoxCode) || string.IsNullOrEmpty(item.PartBoxName) || string.IsNullOrEmpty(item.Plant) || string.IsNullOrEmpty(item.Workshop) || string.IsNullOrEmpty(item.AssemblyLine) || string.IsNullOrEmpty(item.StatusPointCode) || string.IsNullOrEmpty(item.TWmNo) || string.IsNullOrEmpty(item.TZoneNo)) { throw new Exception("MC:0x00000452");///零件类代码、零件类名称、工厂、车间、产线、状态点、目标仓库存储区为必填项 } JisPartBoxInfo jisPartBoxInfo = boxInfos.FirstOrDefault(d => d.PartBoxName == item.PartBoxName); if (jisPartBoxInfo != null) { throw new Exception("MC:0x00000303");///零件类名称重复 } ///字段 string insertFieldString = string.Empty; ///值 string insertValueString = string.Empty; for (int i = 0; i < fields.Count; i++) { string valueStr = CommonDAL.GetFieldValueForSql <JisPartBoxInfo>(item, fields[i]); if (string.IsNullOrEmpty(valueStr)) { throw new Exception("MC:1x00000043");///数据格式不符合导入规范 } insertFieldString += "[" + fieldNames[fields[i]] + "],"; insertValueString += valueStr + ","; } ///判断业务主键是否重复,以防止EXCEL中有重复数据,适用于基础数据导入 sql += "if not exists (select * from LES.TM_MPM_TWD_PART_BOX with(nolock) where [PART_BOX_CODE] = N'" + item.PartBoxCode + "' and [VALID_FLAG] = 1)" + " insert into [LES].[TM_MPM_JIS_PART_BOX] (" + "[FID]," + insertFieldString + "[STATUS]," + "[CREATE_USER]," + "[CREATE_DATE]," + "[VALID_FLAG]" + ") values (" + "NEWID(),"///FID + insertValueString + (int)BasicDataStatusConstants.Created + "," + "N'" + loginUser + "'," ///CREATE_USER + "GETDATE()," ///CREATE_DATE + "1" ///VALID_FLAG + ");"; jisParts.Add(item); continue; } if (info.Status == (int)BasicDataStatusConstants.Created) { if (string.IsNullOrEmpty(item.PartBoxName) || string.IsNullOrEmpty(item.Plant) || string.IsNullOrEmpty(item.Workshop) || string.IsNullOrEmpty(item.AssemblyLine) || string.IsNullOrEmpty(item.StatusPointCode) || string.IsNullOrEmpty(item.TWmNo) || string.IsNullOrEmpty(item.TZoneNo)) { throw new Exception("MC:0x00000452");///零件类代码、零件类名称、工厂、车间、产线、状态点、目标仓库存储区为必填项 } JisPartBoxInfo jisPartBoxInfo = boxInfos.FirstOrDefault(d => d.PartBoxName == item.PartBoxName && d.Id != info.Id); if (jisPartBoxInfo != null) { throw new Exception("MC:0x00000303");///零件类名称重复 } ///值 string valueString = string.Empty; for (int i = 0; i < fields.Count; i++) { string valueStr = CommonDAL.GetFieldValueForSql <JisPartBoxInfo>(item, fields[i]); if (string.IsNullOrEmpty(valueStr)) { throw new Exception("MC:1x00000043");///数据格式不符合导入规范 } valueString += "[" + fieldNames[fields[i]] + "] = " + valueStr + ","; } sql += "update [LES].[TM_MPM_JIS_PART_BOX] set " + valueString + "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + info.Id + ";"; } } if (string.IsNullOrEmpty(sql)) { return(false); } return(CommonDAL.ExecuteNonQueryBySql(sql)); }