Esempio n. 1
0
        public static void  SyncMESGoldenLine()
        {
            GL_WIPHourOutputService gL_GoldenStation = new GL_WIPHourOutputService(
                new GL_WIPHourOutputRepository(_DatabaseFactory),
                new GoldenLineRepository(_DatabaseFactory),
                new GL_LineShiftPerfRepository(_DatabaseFactory),
                new GL_BuildPlanRepository(_DatabaseFactory),
                new GL_ShiftTimeRepository(_DatabaseFactory),
                new UnitOfWork(_DatabaseFactory)
                );
            string   MesProject = "Milan-CTU-Housing";
            DateTime ExcTime    = DateTime.Now;
            //先通过信息获取Mes班次信息。
            MESTimeInfo MesTimeInfo = gL_GoldenStation.GetMesTime(ExcTime, MesProject);
            //获取MES同步信息
            var MesData = GetMesAPIData(MesTimeInfo.StartTime, MesTimeInfo.EndTime);

            //将数据传到后端插入到数据库
            gL_GoldenStation.ExcuteGL_MesHourOutPut(MesData, MesTimeInfo, MesProject);
        }
Esempio n. 2
0
        public MESTimeInfo GetMesTime(DateTime excuteTime, string MesProject)
        {
            MESTimeInfo ReturnMesInfo = new MESTimeInfo();

            try
            {
                #region
                //设置推迟时间  推迟时间应大于间隔时间  如间隔30分钟  只一般delay时间大于30分钟。
                int DelayTime = -15;

                //1 获取所有的customter
                var customerModel = GL_WIPHourOutputRepository.GetEnGL_Customer(MesProject);

                //根据OP获取设置的班次
                var shiftModelList = GL_WIPHourOutputRepository.GetShiftTimeList(customerModel.Organization_UID);

                //获取当前属于哪个生产日期  如果当前“时间”不加日期的时间小于

                var             currentDayTemp1 = excuteTime.AddMinutes(DelayTime).ToShortTimeString();
                var             currentDay      = excuteTime.AddMinutes(DelayTime).ToString("yyyy-MM-dd");
                var             currentTime     = excuteTime.AddMinutes(DelayTime).ToString("yyyy-MM-dd HH:mm");
                GL_ShiftTimeDTO ShiftTimeModel  = new GL_ShiftTimeDTO();

                //取出白天还是夜晚 同步12区间小时
                var ShiftTimeID  = 0;
                var actHourIndex = 0;
                var shiftdate    = string.Empty;
                Dictionary <string, int> outputDic = new Dictionary <string, int>();

                Dictionary <string, int> outputMESDic = new Dictionary <string, int>(); //存储从MES同步获取的数据
                #region 2 判断当前时间是那个班次
                var currentdate = Convert.ToDateTime(currentTime);
                foreach (var item in shiftModelList)
                {
                    currentDay = excuteTime.AddMinutes(DelayTime).ToString("yyyy-MM-dd");
                    if (DateTime.Compare(DateTime.Parse(currentDayTemp1), DateTime.Parse(item.StartTime)) < 0 && DateTime.Compare(DateTime.Parse(item.StartTime), DateTime.Parse(item.End_Time)) > 0)
                    {
                        currentDay = excuteTime.AddDays(-1).AddMinutes(DelayTime).ToString("yyyy-MM-dd");
                    }

                    var startTimeDate = Convert.ToDateTime(currentDay + " " + item.StartTime);
                    var endTimeDate   = Convert.ToDateTime(currentDay + " " + item.End_Time);

                    if (startTimeDate > endTimeDate)
                    {
                        endTimeDate = endTimeDate.AddDays(1);
                    }

                    var flagBanChi = currentdate >= startTimeDate && currentdate < endTimeDate;
                    if (flagBanChi)  //如果当前时间属于该时段
                    {
                        int hourIndex = Math.Abs(endTimeDate.Hour - startTimeDate.Hour);
                        //actHourIndex = hourIndex;
                        for (int k = 0; k < hourIndex; k++)
                        {
                            //如果是相等刚好是跨天的哪一个小时
                            var flag = currentdate >= startTimeDate.AddHours(k) && currentdate < startTimeDate.AddHours(k + 1);
                            if (flag)
                            {
                                shiftdate                    = startTimeDate.ToString("yyyy-MM-dd");
                                actHourIndex                 = k + 1;
                                ShiftTimeID                  = item.ShiftTimeID;
                                ReturnMesInfo.ShiftID        = item.ShiftTimeID;
                                ReturnMesInfo.StartTime      = startTimeDate.AddHours(k).ToString("yyyy/MM/dd HH:mm");
                                ReturnMesInfo.EndTime        = startTimeDate.AddHours(k + 1).ToString("yyyy/MM/dd HH:mm");
                                ReturnMesInfo.shiftdate      = shiftdate;
                                ReturnMesInfo.currentDayTime = DateTime.Parse(currentTime);
                                ReturnMesInfo.actHourIndex   = k + 1;
                                break;
                            }
                        }
                    }
                }
            }
            #endregion



            catch (Exception ex)
            {
                //后续记录到失败日志表   outputDic = GoldenLineRepository.GetOutput(customerModel.MESProject_Name, string.Empty, startTimeDate.AddHours(k), startTimeDate.AddHours(k + 1),item.Plant_Organization_UID);
            }
            #endregion
            return(ReturnMesInfo);
        }
Esempio n. 3
0
        public void ExcuteGL_MesHourOutPut(Dictionary <string, int> MesData, MESTimeInfo Mesnfo, string MesProject)
        {
            try
            {
                #region

                //1 获取所有的customter
                var customerModel = GL_WIPHourOutputRepository.GetEnGL_Customer(MesProject);

                //根据OP获取设置的班次
                var shiftModelList = GL_WIPHourOutputRepository.GetShiftTimeList(customerModel.Organization_UID);



                List <GL_WIPHourOutputDTO> addList    = new List <GL_WIPHourOutputDTO>();
                List <GL_WIPHourOutputDTO> updateList = new List <GL_WIPHourOutputDTO>();


                //根据专案ID获取该专案下的所有(MES站点)
                var allStationDTOs = GL_WIPHourOutputRepository.GetAllMesStationDTO(customerModel.Project_UID);

                //获取已经获取到的数据的站点
                List <GL_StationDTO> inGL_StationDTOs = new List <GL_StationDTO>();
                //获取没有获取到的数据的站点
                List <GL_StationDTO> noGL_StationDTOs = new List <GL_StationDTO>();
                //3 添加和更新数据
                foreach (var itemKeyValue in MesData)
                {
                    //判断配置的工站表里面有个是否存在该工站
                    var stationResult = allStationDTOs.FirstOrDefault(o => o.BG_Organization_UID == customerModel.Organization_UID && o.CustomerID == customerModel.Project_UID && o.MESStationName == itemKeyValue.Key);
                    if (stationResult == null)
                    {
                        continue;
                    }

                    GL_WIPHourOutputDTO hourOutputModel = new GL_WIPHourOutputDTO();
                    hourOutputModel.CustomerID   = customerModel.Project_UID;
                    hourOutputModel.LineID       = stationResult.LineID;
                    hourOutputModel.StationID    = stationResult.StationID;
                    hourOutputModel.AssemblyID   = 0;
                    hourOutputModel.OutputDate   = Mesnfo.currentDayTime;
                    hourOutputModel.ShiftTimeID  = Mesnfo.ShiftID;
                    hourOutputModel.HourIndex    = Mesnfo.actHourIndex;
                    hourOutputModel.ActualOutput = itemKeyValue.Value;
                    hourOutputModel.StandOutput  = 0;
                    hourOutputModel.ShiftDate    = Mesnfo.shiftdate;
                    var model = GL_WIPHourOutputRepository.GetGL_WIPHourOutputBy(hourOutputModel);
                    if (model == null)
                    {
                        addList.Add(hourOutputModel);
                    }
                    else
                    {
                        hourOutputModel.WHOID = model.WHOID;
                        updateList.Add(hourOutputModel);
                    }
                    inGL_StationDTOs.Add(stationResult);
                }
                //得到没有产生数据的站点
                foreach (var item in allStationDTOs)
                {
                    var isStationDTO = inGL_StationDTOs.FirstOrDefault(o => o.StationID == item.StationID);
                    if (isStationDTO == null)
                    {
                        noGL_StationDTOs.Add(item);
                    }
                }
                //根据没有获取到的数据,得到的ActualOutput 就为0.
                foreach (var item in noGL_StationDTOs)
                {
                    GL_WIPHourOutputDTO hourOutputModel = new GL_WIPHourOutputDTO();
                    hourOutputModel.CustomerID   = customerModel.Project_UID;
                    hourOutputModel.LineID       = item.LineID;
                    hourOutputModel.StationID    = item.StationID;
                    hourOutputModel.AssemblyID   = 0;
                    hourOutputModel.OutputDate   = Mesnfo.currentDayTime;
                    hourOutputModel.ShiftTimeID  = Mesnfo.ShiftID;
                    hourOutputModel.HourIndex    = Mesnfo.actHourIndex;
                    hourOutputModel.ActualOutput = 0;
                    hourOutputModel.StandOutput  = 0;
                    hourOutputModel.ShiftDate    = Mesnfo.shiftdate;
                    var model = GL_WIPHourOutputRepository.GetGL_WIPHourOutputBy(hourOutputModel);
                    if (model == null)
                    {
                        addList.Add(hourOutputModel);
                    }
                    else
                    {
                        hourOutputModel.WHOID = model.WHOID;
                        updateList.Add(hourOutputModel);
                    }
                }

                GL_WIPHourOutputRepository.AddGL_WIPHourOutput(addList);
                GL_WIPHourOutputRepository.UpDateGL_WIPHourOutput(updateList);
            }
            #endregion

            catch (Exception ex)
            {
                //后续记录到失败日志表
            }
        }