/// <summary> /// /// </summary> /// <param name="info"></param> /// <returns></returns> public long InsertInfo(AssemblyLineInfo info) { ///生产线代码②、生产线简称④不允许重复,单字段进行全表校验 int cnt = dal.GetCounts("[ASSEMBLY_LINE] = N'" + info.AssemblyLine + "'"); if (cnt > 0) { throw new Exception("MC:0x00000167");///流水线代码重复 } ///生产线名称③同一车间代码下不允许重复 cnt = dal.GetCounts("[ASSEMBLY_LINE_NAME] = N'" + info.AssemblyLineName + "' and [WORKSHOP] = N'" + info.Workshop + "'"); if (cnt > 0) { throw new Exception("MC:0x00000168");///流水线名称重复 } cnt = dal.GetCounts("[ASSEMBLY_LINE_NICKNAME] = N'" + info.AssemblyLineNickname + "'"); if (cnt > 0 && !string.IsNullOrEmpty(info.AssemblyLineNickname)) { throw new Exception("MC:0x00000169");///流水线简称重复 } return(dal.Add(info)); }
/// <summary> /// 获取流水线数据,用于比对SAP代码与LES代码之间关系 /// </summary> /// <returns></returns> public List <AssemblyLineInfo> GetListForInterfaceDataSync() { string sql = "select [PLANT],[WORKSHOP],[ASSEMBLY_LINE],[ASSEMBLY_LINE_NAME]" + "from [LES].[TM_BAS_ASSEMBLY_LINE] with(nolock) " + "where [VALID_FLAG] = 1;"; Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(sql); List <AssemblyLineInfo> list = new List <AssemblyLineInfo>(); using (IDataReader dr = db.ExecuteReader(dbCommand)) { while (dr.Read()) { AssemblyLineInfo info = new AssemblyLineInfo(); info.Plant = DBConvert.GetString(dr, dr.GetOrdinal("PLANT")); info.Workshop = DBConvert.GetString(dr, dr.GetOrdinal("WORKSHOP")); info.AssemblyLine = DBConvert.GetString(dr, dr.GetOrdinal("ASSEMBLY_LINE")); info.AssemblyLineName = DBConvert.GetString(dr, dr.GetOrdinal("ASSEMBLY_LINE_NAME")); list.Add(info); } } return(list); }
/// 同步工厂布局 /// </summary> /// <returns></returns> public static void Sync(string loginUser) { ///从中间表提取未处理工厂布局数据 List<SapPlantStructureInfo> sapPlantStructureInfos = new SapPlantStructureBLL().GetListByPage("[PROCESS_FLAG] = " + (int)ProcessFlagConstants.Untreated + "", "[ID] asc", 1, 1000, out int dataCnt); if (dataCnt == 0) return; StringBuilder stringBuilder = new StringBuilder(); ///获取所有有效工厂信息 List<PlantInfo> plantInfos = new PlantBLL().GetList(string.Empty, "ID"); ///获取所有有效车间信息 List<WorkshopInfo> workshopInfos = new WorkshopBLL().GetList(string.Empty, "ID"); ///获取所有有效生产线信息 List<AssemblyLineInfo> assemblyLineInfos = new AssemblyLineBLL().GetList(string.Empty, "ID"); ///获取所有有效工段信息 List<WorkshopSectionInfo> workshopSectionInfos = new WorkshopSectionBLL().GetList(string.Empty, "ID"); ///获取所有有效工位信息 List<LocationInfo> locationInfos = new LocationBLL().GetList(string.Empty, "ID"); ///已处理完成的ID List<long> dealedIds = new List<long>(); ///逐条处理中间表数据 foreach (var sapPlantStructureInfo in sapPlantStructureInfos) { #region 工厂 if (string.IsNullOrEmpty(sapPlantStructureInfo.Werks)) { stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_PLANT_STRUCTURE] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'3x00000019'," +///工厂信息不存在 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapPlantStructureInfo.Id + ";"); continue; } /// PlantInfo plantInfo = plantInfos.FirstOrDefault(d => d.Plant == sapPlantStructureInfo.Werks); ///如果业务表工厂中不存在,就添加 if (plantInfo == null) { #region TM_BAS_PLANT ///将这样的数据更新为挂起状态 stringBuilder.AppendFormat("insert into [LES].[TM_BAS_PLANT] (" + "[FID] ," + "[PLANT] ," + "[PLANT_NAME] ," + "[VALID_FLAG] ," + "[CREATE_USER] ," + "[CREATE_DATE]," + "[SAP_PLANT_CODE]) values (" + "NEWID() ," //// FID - uniqueidentifier + "N'{0}' ," //// PLANT - nvarchar(5) + "N'{1}' ," //// PLANT_NAME - nvarchar(100) + "{2} ," //// VALID_FLAG - bit + "N'{3}' ," //// CREATE_USER - nvarchar(50) + "GETDATE(),"//// CREATE_DATE - datetime + "N'{4}'); ",///SAP_PLANT_CODE sapPlantStructureInfo.Werks,//// PLANT - nvarchar(5),0 sapPlantStructureInfo.Name1, //// PLANT_NAME - nvarchar(100),1 1, //// VALID_FLAG - bit,2 loginUser,//// CREATE_USER - nvarchar(50),3 sapPlantStructureInfo.Werks);///SAP_PLANT_CODE,4 #endregion ///添加到工厂集合 PlantInfo plant = new PlantInfo(); plant.Plant = sapPlantStructureInfo.Werks; plantInfos.Add(plant); } else { ///更新工厂名称 stringBuilder.AppendFormat("update [LES].[TM_BAS_PLANT] " + "set [PLANT_NAME] = N'" + sapPlantStructureInfo.Name1 + "'," + "[MODIFY_DATE] = GETDATE()," + "[MODIFY_USER] = N'" + loginUser + "' " + "where [ID] = " + plantInfo.Id + ";"); } #endregion #region 车间 if (string.IsNullOrEmpty(sapPlantStructureInfo.Zbm)) { stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_PLANT_STRUCTURE] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'0x00000079'," +///车间代码不能为空 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapPlantStructureInfo.Id + ";"); continue; } ///如果存在工厂, 判断(工厂-部门) WorkshopInfo workshopInfo = workshopInfos.FirstOrDefault(d => d.Workshop == sapPlantStructureInfo.Zbm && d.Plant == sapPlantStructureInfo.Werks); ///如果部门不存在进行添加 if (workshopInfo == null) { #region TM_BAS_WORKSHOP stringBuilder.AppendFormat("insert into [LES].[TM_BAS_WORKSHOP] (" + "[FID] ," + "[PLANT] ," + "[WORKSHOP] ," + "[WORKSHOP_NAME] ," + "[COMMENTS] ," + "[VALID_FLAG] ," + "[CREATE_USER] ," + "[CREATE_DATE] )VALUES ( " + "NEWID() ," //// FID - uniqueidentifier + "N'{0}' ," //// PLANT - nvarchar(20) + "N'{1}' ," //// WORKSHOP - nvarchar(20) + "N'{2}' ," //// WORKSHOP_NAME - nvarchar(100) + "NULL ," //// COMMENTS - nvarchar(200) + "{3} ," //// VALID_FLAG - bit + "N'{4}' ," //// CREATE_USER - nvarchar(50) + "GETDATE()) ;", //// CREATE_DATE - datetime sapPlantStructureInfo.Werks,//// PLANT - nvarchar(20),0 sapPlantStructureInfo.Zbm,//// WORKSHOP - nvarchar(20),1 sapPlantStructureInfo.Zbmms,//// WORKSHOP_NAME - nvarchar(100),2 1,//// VALID_FLAG - bit,3 loginUser);//// CREATE_USER - nvarchar(50),4 #endregion WorkshopInfo workshop = new WorkshopInfo(); workshop.Plant = sapPlantStructureInfo.Werks; workshop.Workshop = sapPlantStructureInfo.Zbm; workshopInfos.Add(workshop); } else { ///更新车间名称 stringBuilder.AppendFormat("update [LES].[TM_BAS_WORKSHOP] " + "set [WORKSHOP_NAME] = N'" + sapPlantStructureInfo.Zbmms + "'," + "[MODIFY_DATE] = GETDATE()," + "[MODIFY_USER] = N'" + loginUser + "' " + "where [ID] = " + workshopInfo.Id + ";"); } #endregion #region 生产线 if (string.IsNullOrEmpty(sapPlantStructureInfo.Zcj)) { stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_PLANT_STRUCTURE] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'0x00000105'," +///生产线代码不能为空 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapPlantStructureInfo.Id + ";"); continue; } ///如果存在工厂,部门, 判断(工厂-部门-生产线) AssemblyLineInfo assemblyLineInfo = assemblyLineInfos.FirstOrDefault(d => d.AssemblyLine == sapPlantStructureInfo.Zcj && d.Workshop == sapPlantStructureInfo.Zbm && d.Plant == sapPlantStructureInfo.Werks); ///如果生产线不存在进行添加 if (assemblyLineInfo == null) { #region TM_BAS_ASSEMBLY_LINE stringBuilder.AppendFormat("insert into [LES].[TM_BAS_ASSEMBLY_LINE](" + "[FID] ," + "[PLANT] ," + "[WORKSHOP] ," + "[ASSEMBLY_LINE] ," + "[ASSEMBLY_LINE_NAME] ," + "[VALID_FLAG] ," + "[CREATE_USER] ," + "[CREATE_DATE]) values (" + "NEWID() ," //// FID - uniqueidentifier + "N'{0}' ," //// PLANT - nvarchar(20) + "N'{1}' ," //// WORKSHOP - nvarchar(20) + "N'{2}' ," //// ASSEMBLY_LINE - nvarchar(20) + "N'{3}' ," //// ASSEMBLY_LINE_NAME - nvarchar(100) + "{4} ," //// VALID_FLAG - bit + "N'{5}' ," //// CREATE_USER - nvarchar(50) + "GETDATE()) ;", //// CREATE_DATE - datetime sapPlantStructureInfo.Werks,//// PLANT - nvarchar(20),0 sapPlantStructureInfo.Zbm,//// WORKSHOP - nvarchar(20),1 sapPlantStructureInfo.Zcj,//// ASSEMBLY_LINE - nvarchar(20),2 sapPlantStructureInfo.Zcjms,//// ASSEMBLY_LINE_NAME - nvarchar(100),3 1,//// VALID_FLAG - bit,4 loginUser);//// CREATE_USER - nvarchar(50),5 #endregion AssemblyLineInfo assemblyLine = new AssemblyLineInfo(); assemblyLine.Plant = sapPlantStructureInfo.Werks; assemblyLine.Workshop = sapPlantStructureInfo.Zbm; assemblyLine.AssemblyLine = sapPlantStructureInfo.Zcj; assemblyLineInfos.Add(assemblyLine); } else { ///更新生产线名称 stringBuilder.AppendFormat("update [LES].[TM_BAS_ASSEMBLY_LINE] " + "set [ASSEMBLY_LINE_NAME] = N'" + sapPlantStructureInfo.Zcjms + "'," + "[MODIFY_DATE] = GETDATE()," + "[MODIFY_USER] = N'" + loginUser + "' " + "where [ID] = " + assemblyLineInfo.Id + ";"); } #endregion #region 工段 if (string.IsNullOrEmpty(sapPlantStructureInfo.LineNo)) { stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_PLANT_STRUCTURE] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'0x00000088'," +///工段代码不能为空 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapPlantStructureInfo.Id + ";"); continue; } ///如果存在 工厂-部门-生产线,判断工段 WorkshopSectionInfo workshopSectionInfo = workshopSectionInfos.FirstOrDefault(d => d.WorkshopSection == sapPlantStructureInfo.LineNo && d.AssemblyLine == sapPlantStructureInfo.Zcj && d.Workshop == sapPlantStructureInfo.Zbm && d.Plant == sapPlantStructureInfo.Werks); ///如果工段不存在进行添加 if (workshopSectionInfo == null) { #region TM_BAS_WORKSHOP_SECTION stringBuilder.AppendFormat("insert into [LES].[TM_BAS_WORKSHOP_SECTION] (" + "[FID] ," + "[PLANT] ," + "[WORKSHOP] ," + "[ASSEMBLY_LINE] ," + "[WORKSHOP_SECTION] ," + "[WORKSHOP_SECTION_NAME] ," + "[VALID_FLAG] ," + "[CREATE_USER] ," + "[CREATE_DATE] )VALUES (" + "NEWID() ," //// FID - uniqueidentifier + "N'{0}' ," //// PLANT - nvarchar(20) + "N'{1}' ," //// WORKSHOP - nvarchar(20) + "N'{2}' ," //// ASSEMBLY_LINE - nvarchar(20) + "N'{3}' ," //// WORKSHOP_SECTION - nvarchar(20) + "N'{4}' ," //// WORKSHOP_SECTION_NAME - nvarchar(200 + "{5} ," //// VALID_FLAG - bit + "N'{6}' ," //// CREATE_USER - nvarchar(50) + "GETDATE());",//// CREATE_DATE - datetime sapPlantStructureInfo.Werks,//// PLANT - nvarchar(20),0 sapPlantStructureInfo.Zbm,//// WORKSHOP - nvarchar(20),1 sapPlantStructureInfo.Zcj, //// ASSEMBLY_LINE - nvarchar(20),2 sapPlantStructureInfo.LineNo,//// WORKSHOP_SECTION - nvarchar(20),3 sapPlantStructureInfo.LineNoms,//// WORKSHOP_SECTION_NAME - nvarchar(200),4 1,//// VALID_FLAG - bit,5 loginUser);//// CREATE_USER - nvarchar(50),6 #endregion WorkshopSectionInfo workshopSection = new WorkshopSectionInfo(); workshopSection.Plant = sapPlantStructureInfo.Werks; workshopSection.Workshop = sapPlantStructureInfo.Zbm; workshopSection.AssemblyLine = sapPlantStructureInfo.Zcj; workshopSection.WorkshopSection = sapPlantStructureInfo.LineNo; workshopSectionInfos.Add(workshopSection); } else { ///更新工段名称 stringBuilder.AppendFormat("update [LES].[TM_BAS_WORKSHOP_SECTION] " + "set [WORKSHOP_SECTION_NAME] = N'" + sapPlantStructureInfo.LineNoms + "'," + "[MODIFY_DATE] = GETDATE()," + "[MODIFY_USER] = N'" + loginUser + "' " + "where [ID] = " + workshopSectionInfo.Id + ";"); } #endregion #region 工位 if (string.IsNullOrEmpty(sapPlantStructureInfo.Vlsch)) { stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_PLANT_STRUCTURE] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'0x00000172'," +///工位代码不能为空 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapPlantStructureInfo.Id + ";"); continue; } ///如果存在 工厂-部门-生产线-工段,判断工位 LocationInfo locationInfo = locationInfos.FirstOrDefault(d => d.Location == sapPlantStructureInfo.Vlsch && d.WorkshopSection == sapPlantStructureInfo.LineNo && d.AssemblyLine == sapPlantStructureInfo.Zcj && d.Workshop == sapPlantStructureInfo.Zbm && d.Plant == sapPlantStructureInfo.Werks); if (locationInfo == null) { #region TM_BAS_LOCATION stringBuilder.AppendFormat("insert into [LES].[TM_BAS_LOCATION] (" + "[FID] ," + "[PLANT] ," + "[WORKSHOP] ," + "[ASSEMBLY_LINE] ," + "[WORKSHOP_SECTION] ," + "[LOCATION] ," + "[LOCATION_NAME] ," + "[VALID_FLAG] ," + "[CREATE_USER] ," + "[CREATE_DATE]," + "[SEQUENCE_NO]) values ( " + "NEWID() ," //// FID - uniqueidentifier + "N'{0}' ," //// PLANT - nvarchar(20) + "N'{1}' ," //// WORKSHOP - nvarchar(20) + "N'{2}' ," //// ASSEMBLY_LINE - nvarchar(20) + "N'{3}' ," //// WORKSHOP_SECTION - nvarchar(20) + "N'{4}' ," //// LOCATION - nvarchar(20) + "N'{5}' ," //// LOCATION_NAME - nvarchar(50) + "{6} ," //// VALID_FLAG - bit + "N'{7}' ," //// CREATE_USER - nvarchar(50) + "GETDATE()," //// CREATE_DATE - datetime + "{8}) ;", /// sapPlantStructureInfo.Werks, //// PLANT - nvarchar(20),0 sapPlantStructureInfo.Zbm,//// WORKSHOP - nvarchar(20),1 sapPlantStructureInfo.Zcj,//// ASSEMBLY_LINE - nvarchar(20),2 sapPlantStructureInfo.LineNo,//// WORKSHOP_SECTION - nvarchar(20),3 sapPlantStructureInfo.Vlsch,//// LOCATION - nvarchar(20),4 sapPlantStructureInfo.Txt,//// LOCATION_NAME - nvarchar(50),5 1,//// VALID_FLAG - bit,6 loginUser,//// CREATE_USER - nvarchar(50),7 sapPlantStructureInfo.Zsx); ///xsx nvarchar(20) #endregion LocationInfo location = new LocationInfo(); location.Plant = sapPlantStructureInfo.Werks; location.Workshop = sapPlantStructureInfo.Zbm; location.AssemblyLine = sapPlantStructureInfo.Zcj; location.WorkshopSection = sapPlantStructureInfo.LineNo; location.Location = sapPlantStructureInfo.Vlsch; locationInfos.Add(location); } else { ///更新工位名称 stringBuilder.AppendFormat("update [LES].[TM_BAS_LOCATION] " + "set [LOCATION_NAME] = N'" + sapPlantStructureInfo.Txt + "'," + "[SEQUENCE_NO]=N'" + sapPlantStructureInfo.Zsx + "', " + "[MODIFY_DATE] = GETDATE()," + "[MODIFY_USER] = N'" + loginUser + "' " + "where [ID] = " + locationInfo.Id + ";"); } #endregion dealedIds.Add(sapPlantStructureInfo.Id); } if (dealedIds.Count > 0) ///已处理的中间表数据更新为已处理状态 工厂布局中间表 TI_IFM_SAP_PLANT_STRUCTURE stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_PLANT_STRUCTURE] " + "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(); } }
/// <summary> /// 生产线启动生产流程 /// </summary> /// <param name="strAssemblyLineId"></param> public void StartProcess(string strAssemblyLineId, string strCreateUser, DeviceAction deviceAction) { try { //读取生产线数据 DataHelper dataHelper = new DataHelper(); DataLogHelper logHelper = new DataLogHelper(); AssemblyLineInfo assembly = dataHelper.GetAssemblyLine(strAssemblyLineId); //线程休眠的基础单位 int iSleepUnit = 1000; if (assembly != null) { //获取生产线的所有设备信息 DeviceInfoCollection devices = dataHelper.GetAssemblyLineDevices(strAssemblyLineId); //获取相应的工艺流程信息 TechnologicalProcess process = dataHelper.GetTechnologicalProcess(assembly.ProcessId); DateTime dtMainStart = DateTime.Now; #region 主工艺流程日志记录 ProcessLog proLog = new ProcessLog() { AssemblyLineId = strAssemblyLineId, ProcessId = process.ProcessId, Created = DateTime.Now, CreateUser = strCreateUser, ProcessStatus = SysHelper.Enums.ProcessStatusType.Start, ProduceMaterialType = SysHelper.Enums.MaterialTypeEnum.Z, Production = decimal.Zero, TakeTime = 0 }; logHelper.AddMainProcessLog(proLog); #endregion //子工艺流程步骤数量 int iExProcessNum = 3; #region 工艺子流程循环 for (int iExIndex = 1; iExIndex <= iExProcessNum; iExIndex++) { //提取子工艺流程审批环节 TeExProcess exProcess = dataHelper.GetTeExProcess(process.ProcessId, iExIndex); if (exProcess != null) { //子工艺开始时间 DateTime dtExStart = DateTime.Now; #region 子工艺流程日志记录 ExProcessLog exLog = new ExProcessLog() { ProcessLogId = proLog.ProcessLogId, ExProcessId = exProcess.ExProcessId, Created = DateTime.Now, CreateUser = strCreateUser, ProcessStatus = SysHelper.Enums.ProcessStatusType.Start, ProduceMaterialType = SysHelper.Enums.MaterialTypeEnum.Z, Production = decimal.Zero, TakeTime = 0 }; //先记录数据 logHelper.AddExProcessLog(exLog); #endregion //是否达到启动条件 bool isStartExProcess = false; #region 判断启动的设备参数是否达到启动条件 DeviceProduceLog deviceLog = logHelper.GetDeviceProduceLog(exProcess.StartDeviceId, exProcess.ParType); if (deviceLog != null) { if (deviceLog.ParValue.Value >= exProcess.ParValue) { isStartExProcess = true; } } //循环等待达到启动条件 while (!isStartExProcess) { //每个循环先暂停10秒 int iStartSleep = iSleepUnit * 10; System.Threading.Thread.Sleep(iStartSleep); deviceLog = logHelper.GetDeviceProduceLog(exProcess.StartDeviceId, exProcess.ParType); if (deviceLog != null) { if (deviceLog.ParValue.Value >= exProcess.ParValue) { isStartExProcess = true; } } } #endregion if (isStartExProcess) { #region 循环启动设备 foreach (ExProcessStep step in exProcess.Steps) { //先找到需要操作的设备 foreach (DeviceInfo device in devices) { if (device.ProcessDeviceId == step.ProcessDeviceId) { string strDeviceId = device.DeviceId; //定义设备的操作类型 //提取步骤的参数控制数 foreach (ExProcessStepPars par in step.StepPars) { #region 记录操作的日志 DeviceActionLog actionLog = new DeviceActionLog() { DeviceId = strDeviceId, Created = DateTime.Now, CreateUser = strCreateUser, SensorId = par.SensorId, ActionType = par.ActionType, ParType = par.ParType, ParUnit = par.ParUnit, ParValue = par.ParValue, ToDeviceId = string.Empty, ToSensorId = string.Empty }; logHelper.AddDeviceActionLog(actionLog); #endregion //将操作放入委托里面进行执行(步骤执行完成才执行后续步骤) if (deviceAction(strDeviceId, par.SensorId, par.ActionType, par.ParType, par.ParValue)) { //判断是否需要等待 if (par.ParTime > 0) { int iSleepSet = par.ParTime * 60 * iSleepUnit; System.Threading.Thread.Sleep(iSleepSet); } //判断是否是完成参数 if (par.IsFinish) { } } } break; } } } #endregion } //子工艺完成时间 DateTime dtExEnd = DateTime.Now; TimeSpan tSpan = dtExEnd - dtExStart; //得到子工艺完成花费的分钟 exLog.TakeTime = Convert.ToInt32(tSpan.TotalMinutes); exLog.FinishTime = dtExEnd; exLog.ProcessStatus = SysHelper.Enums.ProcessStatusType.End; //exLog.ProduceMaterialType = SysHelper.Enums.MaterialTypeEnum. logHelper.UpdateExProcessLog(exLog); } } #endregion DateTime dtMainEnd = DateTime.Now; TimeSpan mSpan = dtMainEnd - dtMainStart; proLog.TakeTime = Convert.ToInt32(mSpan.TotalMinutes); proLog.FinishTime = dtMainEnd; proLog.ProcessStatus = SysHelper.Enums.ProcessStatusType.End; logHelper.UpdateMainProcessLog(proLog); } } catch (Exception ex) { throw ex; } }
/// <summary> /// SyncWorkSchedule /// </summary> /// <param name="loginUser"></param> public static void Sync(string loginUser) { List <SapWorkCalendarInfo> sapWorkCalendarInfos = new SapWorkCalendarBLL().GetListByPage("" + "[PROCESS_FLAG] in (" + (int)ProcessFlagConstants.Untreated + "," + (int)ProcessFlagConstants.Resend + ")", "[ID]", 1, 1000, out int dataCnt); if (dataCnt == 0) { return; } ///获取业务表中需要修改的数据 List <WorkScheduleInfo> workScheduleInfos = new WorkScheduleBLL().GetListForInterfaceDataSync(sapWorkCalendarInfos.Select(d => d.ProductionDate.GetValueOrDefault()).ToList()); StringBuilder stringBuilder = new StringBuilder(); ///获取工厂信息,准备对比 List <PlantInfo> plantInfos = new PlantBLL().GetListForInterfaceDataSync(); ///获取车间信息,准备对比 List <WorkshopInfo> workshopInfos = new WorkshopBLL().GetListForInterfaceDataSync(); ///获取生产线信息,准备对比 List <AssemblyLineInfo> assemblyLineInfos = new AssemblyLineBLL().GetListForInterfaceDataSync(); ///已处理完成的ID List <long> dealedIds = new List <long>(); ///逐条处理中间表数据 foreach (var sapWorkCalendarInfo in sapWorkCalendarInfos) { ///处理工厂不对等的数据 PlantInfo plantInfo = plantInfos.FirstOrDefault(d => d.SapPlantCode == sapWorkCalendarInfo.Dwerk); if (plantInfo == null) { ///将这样的数据更新为挂起状态 stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_WORK_CALENDAR] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'3x00000019'," +///工厂信息不存在 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapWorkCalendarInfo.Id + ";"); continue; } ///处理车间不对等的数据 WorkshopInfo workshopInfo = workshopInfos.FirstOrDefault(d => d.Plant == plantInfo.Plant && d.Workshop == sapWorkCalendarInfo.Zcj); if (workshopInfo == null) { ///将这样的数据更新为挂起状态 stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_WORK_CALENDAR] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'7x00000015'," +///车间信息不存在 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapWorkCalendarInfo.Id + ";"); continue; } ///处理生产线不对等的数据 AssemblyLineInfo assemblyLineInfo = assemblyLineInfos.FirstOrDefault(d => d.Plant == plantInfo.Plant && d.Workshop == workshopInfo.Workshop && d.AssemblyLine == sapWorkCalendarInfo.LineNo); if (assemblyLineInfo == null) { ///将这样的数据更新为挂起状态 stringBuilder.AppendLine("update [LES].[TI_IFM_SAP_WORK_CALENDAR] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'7x00000016'," +///流水线信息不存在 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapWorkCalendarInfo.Id + ";"); continue; } ///当前业务数据表中无此工厂代码+车间+生产线+日期+班次 即为新增 ///TODO: SAP班次的枚举? int lesShift = Convert.ToInt32(sapWorkCalendarInfo.Shift); /// WorkScheduleInfo workScheduleInfo = workScheduleInfos.FirstOrDefault(d => d.Plant == plantInfo.Plant && d.Workshop == sapWorkCalendarInfo.Zcj && d.AssemblyLine == sapWorkCalendarInfo.LineNo && d.Date == sapWorkCalendarInfo.ProductionDate && d.Shift == lesShift); ///如果为空 进行新增 if (workScheduleInfo == null) { /// 工厂, 日期,班次是必填项 if (string.IsNullOrEmpty(sapWorkCalendarInfo.Dwerk) || sapWorkCalendarInfo.ProductionDate == null || string.IsNullOrEmpty(sapWorkCalendarInfo.Shift)) { ///将这样的数据更新为挂起状态 stringBuilder.Append("update [LES].[TI_IFM_SAP_WORK_CALENDAR] " + "set [PROCESS_FLAG] = " + (int)ProcessFlagConstants.Suspend + "," + "[PROCESS_TIME] = GETDATE()," + "[COMMENTS] = N'7x00000014'," +///工厂, 日期,班次是必填项 "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [ID] = " + sapWorkCalendarInfo.Id.ToString() + ";"); continue; } /// 新增 stringBuilder.AppendFormat("insert into [LES].[TM_BAS_WORK_SCHEDULE] (" + "[FID]" + "[PLANT] ," + "[WORKSHOP] ," + "[ASSEMBLY_LINE] ," + "[DATE] ," + "[SHIFT] ," + "[BEGIN_TIME] ," + "[END_TIME] ," + "[VALID_FLAG] ," + "[CREATE_USER] ," + "[CREATE_DATE]) values (" + "N'{0}' ," /// 工厂 - nvarchar(8) + "N'{1}' ," /// 车间 - nvarchar(32) + "N'{2}' ," /// 生产线 - nvarchar(32) + "N'{3}' ," /// 日期 - datetime + "{4} ," /// 班次 - int + "N'{5}' ," /// 开始时间 - datetime + "N'{6}' ," /// 结束时间 - datetime + "{7} ," /// VALID_FLAG - bit + "N'{8}' ," /// CREATE_USER - nvarchar(32) + "GETDATE() ) ;", /// CREATE_DATE - datetime plantInfo.Plant, /// 工厂 - nvarchar(8),0 workshopInfo.Workshop, /// 车间 - nvarchar(32),1 assemblyLineInfo.AssemblyLine, /// 生产线 - nvarchar(32),2 sapWorkCalendarInfo.ProductionDate, /// 日期 - datetime,3 lesShift, /// 班次 - int,4, sapWorkCalendarInfo.BeginTime, /// 开始时间 - datetime,5 sapWorkCalendarInfo.EndTime, /// 结束时间 - datetime,6 1, /// VALID_FLAG - bit,7 loginUser); /// CREATE_USER - nvarchar(32),8 workScheduleInfos.Add(new WorkScheduleInfo() { Plant = plantInfo.Plant, Workshop = sapWorkCalendarInfo.Zcj, AssemblyLine = sapWorkCalendarInfo.LineNo, Date = sapWorkCalendarInfo.ProductionDate, Shift = lesShift }); } else { ///此次循环的数据在业务表中存在,进行修改 stringBuilder.AppendLine("update [LES].[TM_BAS_WORK_SCHEDULE] " + "set [BEGIN_TIME] = N'" + workScheduleInfo.BeginTime.GetValueOrDefault() + "'," + "[END_TIME] =N'" + workScheduleInfo.EndTime.GetValueOrDefault() + "'," + "[MODIFY_USER] = N'" + loginUser + "'," + "[MODIFY_DATE] = GETDATE() " + "where [PLANT] = N'" + plantInfo.Plant + "' and " + "[WORKSHOP] = N'" + workshopInfo.Workshop + "' and " + "[ASSEMBLY_LINE] = N'" + assemblyLineInfo.AssemblyLine + "' and " + "[DATE] = N'" + sapWorkCalendarInfo.ProductionDate.Value.ToString("yyyy-MM-dd HH:mm:ss") + "' and " + "[SHIFT] = N'" + lesShift + "';"); } dealedIds.Add(sapWorkCalendarInfo.Id); } if (dealedIds.Count > 0) { ///已处理的中间表数据更新为已处理状态 stringBuilder.Append("update [LES].[TI_IFM_SAP_WORK_CALENDAR] " + "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(); } }