Beispiel #1
0
        /// <summary>
        /// 添加日志
        /// </summary>
        public static void AddLog(string logType, string LogName, MesRequestParamModel LogMessMode)
        {
            var message = string.Format("MES无数据-参数信息:SqlServer_{0},Database_{1},UserID_{2},StartDate_{3},EndDate_{4},CustomerIDString_{5}", LogMessMode.SqlServer, LogMessMode.Database, LogMessMode.UserID_ID, LogMessMode.StartDate, LogMessMode.EndDate, LogMessMode.CustomerIDString);

            _LogService.AddLog(new LogMessageRecord()
            {
                LogType    = logType,
                LogName    = LogName,
                LogMessage = message,
                LogTime    = DateTime.Now,
                LogRemark  = "同步数据失败"
            });
        }
Beispiel #2
0
        public static void AddMESSyncFailedLog(string logType, string LogName, MesRequestParamModel LogMessMode)
        {
            var message = string.Format("同步失败-参数信息-->:SqlServer_{0},Database_{1},UserID_{2},StartDate_{3},EndDate_{4},CustomerIDString_{5}", LogMessMode.SqlServer, LogMessMode.Database, LogMessMode.UserID_ID, LogMessMode.StartDate, LogMessMode.EndDate, LogMessMode.CustomerIDString);

            _SyncFailedLogServer.AddMESSyncFailedLog(new MES_PIS_SyncFailedRecord()
            {
                SyncType           = logType,
                SyncName           = LogName,
                SyncTime           = DateTime.Now,
                SyncRequest        = message,
                SyncResult         = "同步数据失败",
                Is_ManuallySuccess = false,
                FailedNumber       = 0,
                OperateID          = 0,
                OperateTime        = DateTime.Now,
            });
        }
Beispiel #3
0
        //获取MES接口
        public static Recordset GetMesAPIData(MesRequestParamModel mesRequest)
        {
            //3 转换MES接口的数据
            try
            {
                WP_WIPRouteSteps wp = new WP_WIPRouteSteps();
                Recordset        re = wp.ListWIPHistory(mesRequest.SqlServer, mesRequest.Database, mesRequest.UserID_ID, mesRequest.StartDate, mesRequest.EndDate, mesRequest.CustomerIDString);
                //var i = re.GetString();
                //Recordset re = wp.ListWIPHistory("azapsectusql42", "jems", 794, "2018/03/29 12:00", "2018/03/29 14:00", "17");

                return(re);
            }
            catch (Exception ex)
            {
                AddMESSyncFailedLog("MES_PIS", "MES数据自动同步", mesRequest);
                return(new Recordset());
            }
        }
Beispiel #4
0
        //添加数据
        public static void AddMES_PIS(MesDataSyncService mes_Service, List <MES_StationDataRecordDTO> mesDataList, List <ProcessIDTransformConfigDTO> pisConfigList, CurentTimeModel CurrentDate, MesRequestParamModel mesRequest)
        {
            var isSendEMail     = false;
            var isAddFailRecord = false;

            try
            {
                var resultModelList          = new List <MES_StationDataRecordDTO>();
                var convertModel             = mesDataList.GroupBy(p => new { p.MES_ProcessID, p.Color }).ToDictionary(p => p.Key, m => m);
                var mesPickIngConfigList     = pisConfigList.Select(m => new { m.PIS_ProcessID, m.PIS_ProcessName, m.MES_PickingID, m.Color }).ToList();
                var mesNgConfigList          = pisConfigList.Select(m => new { m.PIS_ProcessID, m.PIS_ProcessName, m.MES_NgID, m.Color }).ToList();
                var mesReworkConfigList      = pisConfigList.Select(m => new { m.PIS_ProcessID, m.PIS_ProcessName, m.MES_ReworkID, m.Color }).ToList();
                var mesGoodProductConfigList = pisConfigList.Select(m => new { m.PIS_ProcessID, m.PIS_ProcessName, m.MES_GoodProductID, m.Color }).ToList();
                //筛选领料--待商议
                var AllPickIngModel     = convertModel.Where(p => mesPickIngConfigList.Where(m => m.MES_PickingID == p.Key.MES_ProcessID && m.Color == p.Key.Color).Count() > 0);
                var AllGoodProductModel = convertModel.Where(p => mesGoodProductConfigList.Where(m => m.MES_GoodProductID == p.Key.MES_ProcessID && m.Color == p.Key.Color).Count() > 0);
                var AllNgModel          = convertModel.Where(p => mesNgConfigList.Where(m => m.MES_NgID == p.Key.MES_ProcessID && m.Color == p.Key.Color).Count() > 0);
                var AllReworkModel      = convertModel.Where(p => mesReworkConfigList.Where(m => m.MES_ReworkID == p.Key.MES_ProcessID && m.Color == p.Key.Color).Count() > 0);

                //Pick
                foreach (var item in AllPickIngModel)
                {
                    isAddFailRecord = true;
                    MES_StationDataRecord AddPisModel = new MES_StationDataRecord();
                    var pisPickConfigModel            = mesPickIngConfigList.Where(p => p.MES_PickingID == item.Key.MES_ProcessID && p.Color == item.Key.Color).FirstOrDefault();
                    AddPisModel.Date              = CurrentDate.CurrentDay;
                    AddPisModel.TimeInterVal      = CurrentDate.CurrentInterval;
                    AddPisModel.StartTimeInterval = CurrentDate.CurrentStartMinute;
                    AddPisModel.EndTimeInterval   = CurrentDate.CurrentEndMinute;
                    AddPisModel.PIS_ProcessID     = pisPickConfigModel.PIS_ProcessID;
                    AddPisModel.PIS_ProcessName   = pisPickConfigModel.PIS_ProcessName;
                    AddPisModel.MES_ProcessID     = item.Key.MES_ProcessID;
                    AddPisModel.MES_ProcessName   = item.Value.FirstOrDefault().MES_ProcessName;
                    AddPisModel.ProductQuantity   = item.Value.Count();
                    AddPisModel.ProjectName       = mesRequest.CustomerIDString;
                    AddPisModel.ProcessType       = "PIS-PICK";
                    //resultModelList.Add(AddPisModel);
                    var result = mes_Service.AddMesData(AddPisModel);
                    if (!result)
                    {
                        isSendEMail = true;
                    }
                }

                //GoodProduct
                foreach (var item in AllGoodProductModel)
                {
                    isAddFailRecord = true;
                    MES_StationDataRecord AddPisModel = new MES_StationDataRecord();
                    var pisPickConfigModel            = mesGoodProductConfigList.Where(p => p.MES_GoodProductID == item.Key.MES_ProcessID && p.Color == item.Key.Color).FirstOrDefault();
                    AddPisModel.Date              = CurrentDate.CurrentDay;
                    AddPisModel.TimeInterVal      = CurrentDate.CurrentInterval;
                    AddPisModel.StartTimeInterval = CurrentDate.CurrentStartMinute;
                    AddPisModel.EndTimeInterval   = CurrentDate.CurrentEndMinute;
                    AddPisModel.PIS_ProcessID     = pisPickConfigModel.PIS_ProcessID;
                    AddPisModel.PIS_ProcessName   = pisPickConfigModel.PIS_ProcessName;
                    AddPisModel.MES_ProcessID     = item.Key.MES_ProcessID;
                    AddPisModel.MES_ProcessName   = item.Value.FirstOrDefault().MES_ProcessName;
                    AddPisModel.ProductQuantity   = item.Value.Count();
                    AddPisModel.ProjectName       = mesRequest.CustomerIDString;
                    AddPisModel.ProcessType       = "PIS-GP";
                    var result = mes_Service.AddMesData(AddPisModel);
                    if (!result)
                    {
                        isSendEMail = true;
                    }
                }

                //NG
                foreach (var item in AllNgModel)
                {
                    isAddFailRecord = true;
                    MES_StationDataRecord AddPisModel = new MES_StationDataRecord();
                    var pisNgConfigModel = mesNgConfigList.Where(p => p.MES_NgID == item.Key.MES_ProcessID && p.Color == item.Key.Color).FirstOrDefault();
                    AddPisModel.Date              = CurrentDate.CurrentDay;
                    AddPisModel.TimeInterVal      = CurrentDate.CurrentInterval;
                    AddPisModel.StartTimeInterval = CurrentDate.CurrentStartMinute;
                    AddPisModel.EndTimeInterval   = CurrentDate.CurrentEndMinute;
                    AddPisModel.PIS_ProcessID     = pisNgConfigModel.PIS_ProcessID;
                    AddPisModel.PIS_ProcessName   = pisNgConfigModel.PIS_ProcessName;
                    AddPisModel.MES_ProcessID     = item.Key.MES_ProcessID;
                    AddPisModel.MES_ProcessName   = item.Value.FirstOrDefault().MES_ProcessName;
                    AddPisModel.ProductQuantity   = item.Value.Count();
                    AddPisModel.ProjectName       = mesRequest.CustomerIDString;
                    AddPisModel.ProcessType       = "PIS-NG";
                    //resultModelList.Add(AddPisModel);
                    var result = mes_Service.AddMesData(AddPisModel);
                    if (!result)
                    {
                        isSendEMail = true;
                    }
                }

                //Rework
                foreach (var item in AllReworkModel)
                {
                    isAddFailRecord = true;
                    MES_StationDataRecord AddPisModel = new MES_StationDataRecord();
                    var pisReworkConfigModel          = mesReworkConfigList.Where(p => p.MES_ReworkID == item.Key.MES_ProcessID && p.Color == item.Key.Color).FirstOrDefault();
                    AddPisModel.Date              = CurrentDate.CurrentDay;
                    AddPisModel.TimeInterVal      = CurrentDate.CurrentInterval;
                    AddPisModel.StartTimeInterval = CurrentDate.CurrentStartMinute;
                    AddPisModel.EndTimeInterval   = CurrentDate.CurrentEndMinute;
                    AddPisModel.PIS_ProcessID     = pisReworkConfigModel.PIS_ProcessID;
                    AddPisModel.PIS_ProcessName   = pisReworkConfigModel.PIS_ProcessName;
                    AddPisModel.MES_ProcessID     = item.Key.MES_ProcessID;
                    AddPisModel.MES_ProcessName   = item.Value.FirstOrDefault().MES_ProcessName;
                    AddPisModel.ProductQuantity   = item.Value.Count();
                    AddPisModel.ProjectName       = mesRequest.CustomerIDString;
                    AddPisModel.ProcessType       = "PIS-ReWork";
                    var result = mes_Service.AddMesData(AddPisModel);
                    if (!result)
                    {
                        isSendEMail = true;
                    }
                }

                if (isAddFailRecord)
                {
                    //发邮件记日志
                    if (isSendEMail)
                    {
                        AddMESSyncFailedLog("MES_PIS", "MES数据自动同步", mesRequest);
                    }
                }
                else
                {
                    AddLog("无数据", "没有获取到对应配置的数据", mesRequest);
                }
            }
            catch (Exception ex)
            {
                AddLog("Failed", "AddPIS", mesRequest);
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //NewmMes_Service.SynchronizeMesInfo(syncParam);
            //mes_Service.SynchronizeMesInfo(syncParam);

            ProcessIDTRSConfigService process_Service = new ProcessIDTRSConfigService
                                                        (
                new UnitOfWork(_DatabaseFactory),
                new EnumerationRepository(_DatabaseFactory),
                new ProcessIDTRSConfigRepository(_DatabaseFactory),
                new ProductInputRepository(_DatabaseFactory),
                new MES_PIS_SyncFailedRecordRepository(_DatabaseFactory),
                new FlowChartDetailRepository(_DatabaseFactory)
                                                        );

            MesDataSyncService mes_Service = new MesDataSyncService
                                             (
                new UnitOfWork(_DatabaseFactory),
                new EnumerationRepository(_DatabaseFactory),
                new MesDataSyncRepository(_DatabaseFactory),
                new ProductInputRepository(_DatabaseFactory),
                new ProcessIDTRSConfigRepository(_DatabaseFactory)
                                             );

            LogMessageRecordService Log_Service = new LogMessageRecordService
                                                  (
                new UnitOfWork(_DatabaseFactory),
                new LogMessageRecodeRepository(_DatabaseFactory)
                                                  );

            MES_PIS_SyncFailedRecordService SyncFailedLogServer = new MES_PIS_SyncFailedRecordService
                                                                  (
                new MES_PIS_SyncFailedRecordRepository(_DatabaseFactory),
                new UnitOfWork(_DatabaseFactory)
                                                                  );

            MES_SNOriginalService SNOriginalService = new MES_SNOriginalService
                                                      (
                new UnitOfWork(_DatabaseFactory),
                new MES_SNOriginalRepository(_DatabaseFactory),
                new Mes_StationColorRepository(_DatabaseFactory),
                new ShipMentRepository(_DatabaseFactory)
                                                      );

            _LogService          = Log_Service;
            _SyncFailedLogServer = SyncFailedLogServer;
            EnumerationRepository enumration = new EnumerationRepository(_DatabaseFactory);

            //一 获取枚举表-构造参数
            //二 获取临时表的数据
            //三 获取配置表的数据判断是否需要同步
            //四 判断数据是插入还是更新
            //1 获取当前日期和时段

            //测试代码
            //var starttime = DateTime.Now;
            if (false)
            {
                var i = 0;
                while (true)
                {
                    Thread t1 = new Thread(new ThreadStart(AddData));
                    t1.Start();
                    Thread.Sleep(60000);
                    Console.Write(++i + ", ");
                }
            }
            else
            {
                var startTime            = string.Empty;
                var endTime              = string.Empty;
                var current_Date         = string.Empty;
                var current_TimeInterval = string.Empty;
                var _currentDateTime     = DateTime.Now.AddMinutes(-10);
                //var _currentDateTime = Convert.ToDateTime("2018/09/28 10:10");
                //while (_currentDateTime.AddMinutes(10) < Convert.ToDateTime("2018/09/28 15:10"))
                //{
                //    _currentDateTime = _currentDateTime.AddMinutes(10);
                var currentDateInfoModel = GetCurrentTime(_currentDateTime);
                current_TimeInterval = currentDateInfoModel.CurrentInterval;
                current_Date         = currentDateInfoModel.CurrentDay;
                startTime            = currentDateInfoModel.CurrentStartMinute;
                endTime = currentDateInfoModel.CurrentEndMinute;
                //获取需要同步的专案
                var projectList = enumration.GetMES_Project("MES_ProjectType");
                //2 获取配置表需要同步的制程
                var ProcessConfList = process_Service.GetSyscProcessConfig();

                foreach (var project in projectList)
                {
                    #region
                    List <MES_StationDataRecordDTO> MesPeocessInfoList = new List <MES_StationDataRecordDTO>();
                    var requestParam       = project.Enum_Value.Split(',');
                    var SqlServer          = requestParam[0].ToString();
                    var Database           = requestParam[1].ToString();
                    var UserID_ID          = int.Parse(requestParam[2]);
                    var customerIDString   = requestParam[5].ToString();
                    var assemblyIDString   = requestParam[6].ToString();
                    var customerNameString = requestParam[7].ToString();
                    //获取专案下面最新的一条数据
                    var       LastDatemodel = mes_Service.GetLastSyncDate(customerIDString);
                    var       model         = new MES_StationDataRecordDTO();
                    Recordset resultMesData = new Recordset();
                    //第一条数据直接滴啊用接口
                    if (LastDatemodel == null)
                    {
                        MesRequestParamModel mesRequest = new MesRequestParamModel()
                        {
                            SqlServer        = SqlServer,
                            Database         = Database,
                            UserID_ID        = UserID_ID,
                            StartDate        = startTime,
                            EndDate          = endTime,
                            CustomerIDString = customerIDString,
                            AssemblyIDString = assemblyIDString
                        };
                        resultMesData = GetMesAPIData(mesRequest);
                        if (resultMesData.RecordCount == 0)
                        {
                            AddLog("MES-无数据数据", "RequestMESAPI", mesRequest);
                            continue;
                        }

                        MesPeocessInfoList = ConvertMesDateToPis(resultMesData, customerNameString);
                        AddMES_PIS(mes_Service, MesPeocessInfoList, ProcessConfList, currentDateInfoModel, mesRequest);
                    }
                    else
                    {
                        //当前同步的开始时间=已经同步的结束的时间
                        if (LastDatemodel.EndTimeInterval == startTime)
                        {
                            MesRequestParamModel mesRequest = new MesRequestParamModel()
                            {
                                SqlServer        = SqlServer,
                                Database         = Database,
                                UserID_ID        = UserID_ID,
                                StartDate        = startTime,
                                EndDate          = endTime,
                                CustomerIDString = customerIDString,
                                AssemblyIDString = assemblyIDString
                            };

                            resultMesData = GetMesAPIData(mesRequest);
                            if (resultMesData.RecordCount == 0)
                            {
                                AddLog("MES-无数据数据", "RequestMESAPI", mesRequest);
                                continue;
                            }
                            MesPeocessInfoList = ConvertMesDateToPis(resultMesData, customerNameString);
                            AddMES_PIS(mes_Service, MesPeocessInfoList, ProcessConfList, currentDateInfoModel, mesRequest);
                        }
                        else
                        {
                            for (int i = 12; i >= 0; i--)
                            {
                                Recordset resultMesDataForFail = new Recordset();
                                //往前面推10分钟-最多查询前面一个小时数据
                                var tempTineModel = GetCurrentTime(_currentDateTime.AddMinutes(-(10 * i)));
                                if (Convert.ToDateTime(LastDatemodel.EndTimeInterval) > Convert.ToDateTime(tempTineModel.CurrentStartMinute))
                                {
                                    continue;
                                }
                                else
                                {
                                    current_Date         = tempTineModel.CurrentDay;
                                    current_TimeInterval = tempTineModel.CurrentInterval;
                                    startTime            = tempTineModel.CurrentStartMinute;
                                    endTime = tempTineModel.CurrentEndMinute;
                                    MesRequestParamModel mesRequest = new MesRequestParamModel()
                                    {
                                        SqlServer        = SqlServer,
                                        Database         = Database,
                                        UserID_ID        = UserID_ID,
                                        StartDate        = startTime,
                                        EndDate          = endTime,
                                        CustomerIDString = customerIDString,
                                        AssemblyIDString = assemblyIDString
                                    };
                                    resultMesDataForFail = GetMesAPIData(mesRequest);
                                    if (resultMesDataForFail.RecordCount == 0)
                                    {
                                        AddLog("MES-无数据数据", "RequestMESAPI", mesRequest);
                                        //记日志或者发邮件
                                        continue;
                                    }
                                    MesPeocessInfoList = ConvertMesDateToPis(resultMesDataForFail, customerNameString);
                                    //AddMES_PIS(mes_Service, MesPeocessInfoList, ProcessConfList, tempTineModel, mesRequest);
                                    //找到相等时的时段执行完直接跳出
                                }
                                //原逻辑
                                #region
                                //if (LastDatemodel.EndTimeInterval == tempTineModel.CurrentStartMinute)
                                //{
                                //    current_Date = tempTineModel.CurrentDay;
                                //    current_TimeInterval = tempTineModel.CurrentInterval;
                                //    startTime = tempTineModel.CurrentStartMinute;
                                //    endTime = tempTineModel.CurrentEndMinute;
                                //    MesRequestParamModel mesRequest = new MesRequestParamModel()
                                //    {
                                //        SqlServer = SqlServer,
                                //        Database = Database,
                                //        UserID_ID = UserID_ID,
                                //        StartDate = startTime,
                                //        EndDate = endTime,
                                //        CustomerIDString = customerIDString,
                                //        AssemblyIDString = assemblyIDString
                                //    };
                                //    resultMesDataForFail = GetMesAPIData(mesRequest);
                                //    if (resultMesDataForFail.RecordCount == 0)
                                //    {
                                //        AddLog("MES-无数据数据", "RequestMESAPI", mesRequest);
                                //        //记日志或者发邮件
                                //        continue;
                                //    }
                                //    //MesPeocessInfoList = ConvertMesDateToPis(resultMesDataForFail);
                                //    //AddMES_PIS(mes_Service, MesPeocessInfoList, ProcessConfList, tempTineModel, mesRequest);
                                //    //找到相等时的时段执行完直接跳出
                                //    break;
                                //}
                                //else
                                //{
                                //    current_Date = tempTineModel.CurrentDay;
                                //    current_TimeInterval = tempTineModel.CurrentInterval;
                                //    startTime = tempTineModel.CurrentStartMinute;
                                //    endTime = tempTineModel.CurrentEndMinute;
                                //    MesRequestParamModel mesRequest = new MesRequestParamModel()
                                //    {
                                //        SqlServer = SqlServer,
                                //        Database = Database,
                                //        UserID_ID = UserID_ID,
                                //        StartDate = startTime,
                                //        EndDate = endTime,
                                //        CustomerIDString = customerIDString,
                                //        AssemblyIDString = assemblyIDString
                                //    };
                                //    resultMesDataForFail = GetMesAPIData(mesRequest);
                                //    if (resultMesDataForFail.RecordCount == 0)
                                //    {
                                //        AddLog("MES-无数据数据", "RequestMESAPI", mesRequest);
                                //        //记日志或者发邮件
                                //        continue;
                                //    }
                                //    //MesPeocessInfoList = ConvertMesDateToPis(resultMesDataForFail);
                                //    //AddMES_PIS(mes_Service, MesPeocessInfoList, ProcessConfList, tempTineModel, mesRequest);
                                //}

                                #endregion
                                //}
                            }
                            #endregion
                        }
                    }
                    //测试代码
                    //var endtime = DateTime.Now;
                    //Console.WriteLine("总耗时毫秒:" + (endtime - starttime).TotalMilliseconds);
                    //Console.WriteLine("总耗时秒:" + (endtime - starttime).Milliseconds);
                    //Console.WriteLine("总耗时分:" + (endtime - starttime).TotalMinutes);
                    //Console.ReadKey();
                }
            }
        }