Beispiel #1
0
        public string AddOrUpdateShiftTime(dynamic values)
        {
            GL_ShiftTimeDTO dto          = JsonConvert.DeserializeObject <GL_ShiftTimeDTO>(values.ToString());
            string          errorMessage = _goldenLineService.AddOrUpdateShiftTime(dto, out errorMessage);

            return(errorMessage);
        }
Beispiel #2
0
        /// <summary>
        /// 获取并判断时间点所在的班次范围
        /// </summary>
        /// <param name="GL_ShiftTimeDTOs">班次的所有列表</param>
        /// <param name="dateNow">时间点</param>
        /// <returns></returns>
        public static GL_ShiftTimeDTO GetGL_ShiftTimeDTO(List <GL_ShiftTimeDTO> GL_ShiftTimeDTOs, DateTime dateNow)
        {
            GL_ShiftTimeDTO GL_ShiftTimeDTO = new GL_ShiftTimeDTO();
            string          strdateNow      = dateNow.ToString("yyyy-MM-dd");

            foreach (var item in GL_ShiftTimeDTOs)
            {
                DateTime StartdDateTime = Convert.ToDateTime((strdateNow + " " + item.StartTime));
                DateTime EndDateTime    = Convert.ToDateTime((strdateNow + " " + item.End_Time));
                if (StartdDateTime <= EndDateTime)
                {
                    if ((StartdDateTime < dateNow && dateNow <= EndDateTime) || (StartdDateTime.AddDays(-1) < dateNow && dateNow <= EndDateTime.AddDays(-1)) || (StartdDateTime.AddDays(1) < dateNow && dateNow <= EndDateTime.AddDays(1)))
                    {
                        GL_ShiftTimeDTO = item;
                    }
                }
                else
                {
                    EndDateTime = EndDateTime.AddDays(1);
                    if ((StartdDateTime < dateNow && dateNow <= EndDateTime) || (StartdDateTime.AddDays(-1) < dateNow && dateNow <= EndDateTime.AddDays(-1)) || (StartdDateTime.AddDays(1) < dateNow && dateNow <= EndDateTime.AddDays(1)))
                    {
                        GL_ShiftTimeDTO = item;
                    }
                }
            }

            return(GL_ShiftTimeDTO);
        }
        /// <summary>
        /// 执行
        /// </summary>
        public void ExcuteGL_WIPHourOutput(DateTime excuteTime)
        {
            try
            {
                #region

                //1 获取所有的customter
                var customerList = GL_WIPHourOutputRepository.GetAllEnGL_Customer();
                foreach (var customerModel in customerList)
                {
                    //根据OP获取设置的班次
                    var shiftModelList = GL_WIPHourOutputRepository.GetShiftTimeList(customerModel.Organization_UID);

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

                    var             currentDayTemp1 = excuteTime.AddMinutes(-5).ToShortTimeString();
                    var             currentDay      = excuteTime.AddMinutes(-5).ToString("yyyy-MM-dd");
                    var             currentTime     = excuteTime.AddMinutes(-5).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>();
                    #region 2 判断当前时间是那个班次
                    var currentdate = Convert.ToDateTime(currentTime);
                    foreach (var item in shiftModelList)
                    {
                        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(-5).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);
                        }

                        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;
                                //调用接口
                                outputDic = GoldenLineRepository.GetOutput(customerModel.MESProject_Name, string.Empty, startTimeDate.AddHours(k), startTimeDate.AddHours(k + 1), item.Plant_Organization_UID);
                                break;
                            }
                        }
                    }
                    #endregion

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

                    //3 添加和更新数据
                    foreach (var itemKeyValue in outputDic)
                    {
                        GL_StationDTO stationModel = new GL_StationDTO();
                        stationModel.StationName         = itemKeyValue.Key;
                        stationModel.ProjectName         = customerModel.Project_Name;
                        stationModel.BG_Organization_UID = customerModel.Organization_UID;
                        stationModel.CustomerID          = customerModel.Project_UID;
                        //判断配置的工站表里面有个是否存在该工站
                        var stationResult = GL_WIPHourOutputRepository.GetStation(stationModel);
                        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   = currentdate;
                        hourOutputModel.ShiftTimeID  = ShiftTimeID;
                        hourOutputModel.HourIndex    = actHourIndex;
                        hourOutputModel.ActualOutput = itemKeyValue.Value;
                        hourOutputModel.StandOutput  = 0;
                        hourOutputModel.ShiftDate    = 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)
            {
                //后续记录到失败日志表
            }
        }
        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);
        }
        public void NewExcuteGL_WIPHourOutput(DateTime excuteTime)
        {
            try
            {
                #region

                //1 获取所有的customter
                var customerList = GL_WIPHourOutputRepository.GetAllEnGL_Customer();
                foreach (var customerModel in customerList)
                {
                    //根据OP获取设置的班次
                    var shiftModelList = GL_WIPHourOutputRepository.GetShiftTimeList(customerModel.Organization_UID);

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

                    var             currentDayTemp1 = excuteTime.AddMinutes(-5).ToShortTimeString();
                    var             currentDay      = excuteTime.AddMinutes(-5).ToString("yyyy-MM-dd");
                    var             currentTime     = excuteTime.AddMinutes(-5).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, GL_HoureOutputModel> outputDic = new Dictionary <string, GL_HoureOutputModel>();

                    Dictionary <string, int> outputMESDic = new Dictionary <string, int>(); //存储从MES同步获取的数据
                    #region 2 判断当前时间是那个班次
                    var currentdate = Convert.ToDateTime(currentTime);
                    foreach (var item in shiftModelList)
                    {
                        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(-5).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);
                        }

                        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;
                                //调用接口
                                outputDic = GoldenLineRepository.GetNewOutput(customerModel.MESProject_Name, string.Empty, startTimeDate.AddHours(k), startTimeDate.AddHours(k + 1), item.Plant_Organization_UID);
                                break;
                            }
                        }
                    }
                    #endregion

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


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

                    //获取已经获取到的数据的站点
                    List <GL_StationDTO> inGL_StationDTOs = new List <GL_StationDTO>();
                    //获取没有获取到的数据的站点
                    List <GL_StationDTO> noGL_StationDTOs = new List <GL_StationDTO>();

                    //var s = outputMESDic.Concat(outputDic);  //合并两个数据来源的Output数据
                    //3 添加和更新数据
                    foreach (var itemKeyValue in outputDic)
                    {
                        //判断配置的工站表里面有个是否存在该工站
                        var stationResult = allStationDTOs.FirstOrDefault(o => o.BG_Organization_UID == customerModel.Organization_UID && o.CustomerID == customerModel.Project_UID && o.MESStationName == itemKeyValue.Value.StationName && o.MESLineName == itemKeyValue.Value.LineName);
                        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   = currentdate;
                        hourOutputModel.ShiftTimeID  = ShiftTimeID;
                        hourOutputModel.HourIndex    = actHourIndex;
                        hourOutputModel.ActualOutput = itemKeyValue.Value.Count;
                        hourOutputModel.StandOutput  = 0;
                        hourOutputModel.ShiftDate    = 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   = currentdate;
                        hourOutputModel.ShiftTimeID  = ShiftTimeID;
                        hourOutputModel.HourIndex    = actHourIndex;
                        hourOutputModel.ActualOutput = 0;
                        hourOutputModel.StandOutput  = 0;
                        hourOutputModel.ShiftDate    = 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)
            {
                //后续记录到失败日志表
            }
        }
Beispiel #6
0
        // Add or update shift time entity
        public string AddOrUpdateShiftTime(GL_ShiftTimeDTO dto, out string errorMessage)
        {
            errorMessage = string.Empty;
            GL_ShiftTime entity = AutoMapper.Mapper.Map <GL_ShiftTime>(dto);

            try
            {
                // get exists shift time
                IList <GL_ShiftTimeDTO> existsDtos = GetShiftTimes(dto.Plant_Organization_UID, dto.FunPlant_Organization_UID, dto.BG_Organization_UID);
                TimeSpan ts1 = TimeSpan.Parse(dto.StartTime);
                TimeSpan ts2 = TimeSpan.Parse(dto.End_Time);

                if (ts1 > ts2)
                {
                    ts2 = ts2.Add(new TimeSpan(1, 0, 0, 0));
                }

                // check the overlap shift time
                bool            isIntersection   = false;
                GL_ShiftTimeDTO overlapShiftTime = null;
                foreach (GL_ShiftTimeDTO eDto in existsDtos)
                {
                    TimeSpan ts1a = TimeSpan.Parse(eDto.StartTime);
                    TimeSpan ts2a = TimeSpan.Parse(eDto.End_Time);

                    if (ts1a > ts2a)
                    {
                        ts2a = ts2a.Add(new TimeSpan(1, 0, 0, 0));
                    }

                    TimeSpan ts = getIntersectionTimeSpan(ts1a, ts2a, ts1, ts2);
                    if (ts.Ticks > 0)
                    {
                        overlapShiftTime = eDto;
                        isIntersection   = true;
                        break;
                    }
                }
                if (isIntersection)
                {
                    errorMessage = string.Format("Shift time overlap - {0}, {1}", overlapShiftTime.StartTime, overlapShiftTime.End_Time);
                }

                GL_ShiftTime entityContext;
                if (dto.ShiftTimeID == 0)
                {
                    entityContext = _shiftTimeRepository.Add(entity);
                    _unitOfWork.Commit();
                }
                else
                {
                    entityContext = _shiftTimeRepository.GetById(entity.ShiftTimeID);
                    entityContext.Plant_Organization_UID    = entity.Plant_Organization_UID;
                    entityContext.BG_Organization_UID       = entity.BG_Organization_UID;
                    entityContext.FunPlant_Organization_UID = entity.FunPlant_Organization_UID;
                    entityContext.Shift         = entity.Shift;
                    entityContext.StartTime     = entity.StartTime;
                    entityContext.End_Time      = entity.End_Time;
                    entityContext.Modified_UID  = entity.Modified_UID;
                    entityContext.Modified_Date = entity.Modified_Date;
                    entityContext.Break_Time    = entity.Break_Time;
                    entityContext.Sequence      = entity.Sequence;
                    entityContext.IsEnabled     = entity.IsEnabled;
                    _shiftTimeRepository.Update(entityContext);
                    _unitOfWork.Commit();
                }

                //  var returnDto = AutoMapper.Mapper.Map<GL_ShiftTimeDTO>(entityContext);
                return("");
            }
            catch (Exception ex)
            {
                //  errorMessage = ex.Message;
                return(ex.Message);;
            }
        }
Beispiel #7
0
        /// <summary>
        /// 执行
        /// </summary>
        public void ExcuteOEE_Output(DateTime excuteTime)
        {
            //1 获取所有的customter
            var customerList = GL_WIPHourOutputRepository.GetAllMachineGL_Customer();

            foreach (var customerModel in customerList)
            {
                bool whetherUpdateLasteShfit = false;
                bool Latestflag = true;
                #region 判断当前时间的班次与上一次更新的班次是否相同,日期和班次相同的话就不需要同步上一次班次的数据,否则需要更新
                //根据当前专案获取最后更新时间
                var LasteUpdateTime = OEE_OutputRepository.GetLatestUpdateTime(customerModel.Project_UID);
                if (LasteUpdateTime == DateTime.MinValue)
                {
                    //获取最后更新时间属于哪一个班次
                    Latestflag              = false;
                    LasteUpdateTime         = DateTime.Now;
                    whetherUpdateLasteShfit = false;
                }
                #endregion
                #region 获取继续信息
                //根据OP获取设置的班次
                var shiftModelList = GL_WIPHourOutputRepository.GetShiftTimeList(customerModel.Organization_UID);
                if (shiftModelList.Count == 0)
                {
                    continue;
                }
                //获取当前属于哪个生产日期  如果当前“时间”不加日期的时间小于
                var             currentDayTemp1   = excuteTime.AddMinutes(-5).ToShortTimeString();
                var             currentDay        = excuteTime.AddMinutes(-5).ToString("yyyy-MM-dd");
                var             LatestcurrentDay  = LasteUpdateTime.ToString("yyyy-MM-dd");
                var             currentTime       = excuteTime.AddMinutes(-5).ToString("yyyy-MM-dd HH:mm");
                GL_ShiftTimeDTO ShiftTimeModel    = new GL_ShiftTimeDTO();
                DateTime        TimeIntervalStart = DateTime.Now;
                DateTime        TimeIntervalEnd   = DateTime.Now;
                //取出白天还是夜晚 同步12区间小时
                Double PlanHourVlue                      = 0.0;
                var    ShiftTimeID                       = 0;
                var    LatestShiftTimeID                 = 0;
                var    actHourIndex                      = 0;
                var    shiftdate                         = string.Empty;
                Dictionary <string, int> outputDic       = new Dictionary <string, int>();
                Dictionary <string, int> ALLoutputDic    = new Dictionary <string, int>();
                Dictionary <string, int> outputCNCDic    = new Dictionary <string, int>();
                Dictionary <string, int> ALLoutputCNCDic = new Dictionary <string, int>();

                List <ProPerCT> PorCTS = new List <ProPerCT>();

                Dictionary <string, int> FixtureS    = new Dictionary <string, int>();
                Dictionary <string, int> ALLFixtureS = new Dictionary <string, int>();

                Dictionary <string, int> CTUFixtureS = new Dictionary <string, int>();

                Dictionary <string, double> ActualCTS    = new Dictionary <string, double>();
                Dictionary <string, double> ALLActualCTS = new Dictionary <string, double>();

                List <LocalCNCInfo>         CNCInfoLists    = new List <LocalCNCInfo>();
                List <LocalCNCInfo>         ALLCNCInfoLists = new List <LocalCNCInfo>();
                Dictionary <string, double> ActualCNCCTS    = new Dictionary <string, double>();
                Dictionary <string, double> ALLActualCNCCTS = new Dictionary <string, double>();
                DateTime startTimeDate = DateTime.Now;
                DateTime endTimeDate   = DateTime.Now;

                string   TimeInterval         = string.Empty;
                DateTime LasteststartTimeDate = DateTime.Now;
                DateTime LatestendTimeDate    = DateTime.Now;

                DateTime ALLstartTimeDate = DateTime.Now;
                DateTime ALLendTimeDate   = DateTime.Now; //全天的数据

                DateTime   LatestALLstartTimeDate    = DateTime.Now;
                DateTime   LatestALLendTimeDate      = DateTime.Now;     //全天的数据
                List <int> MissingDownMachineUIDList = new List <int>(); //用于存放有漏失的机台UID
                List <int> MissingDefectCodeUIDList  = new List <int>(); //用于存放有漏失的机台UID
                List <int> OfflineMachineUIDList     = new List <int>(); //用于存放当前断网的机台UID

                #endregion
                #region 2 判断当前时间是那个班次
                var  currentdate = Convert.ToDateTime(currentTime);
                bool flag        = false; //判断是否找到当前
                foreach (var item in shiftModelList)
                {
                    endTimeDate = Convert.ToDateTime(currentDay + " " + item.End_Time);
                    //下面判断当前时间属于哪一个时段
                    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(-5).ToString("yyyy-MM-dd");
                    }
                    startTimeDate = Convert.ToDateTime(currentDay + " " + item.StartTime);

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

                    flag = currentdate >= startTimeDate && currentdate < endTimeDate;
                    if (flag)  //如果当前时间属于该时段
                    {
                        ShiftTimeID = item.ShiftTimeID;
                        #region 判断当前时间是属于那个时段

                        var tempStartTime = startTimeDate;
                        var loopCount     = 0;
                        while (tempStartTime < endTimeDate)
                        {
                            loopCount++;
                            if (tempStartTime < currentdate && tempStartTime.AddHours(2) > currentdate)
                            {
                                TimeInterval      = tempStartTime.ToString("HH:mm") + "-" + tempStartTime.AddHours(2).ToString("HH:mm");
                                TimeIntervalStart = tempStartTime;
                                TimeIntervalEnd   = tempStartTime.AddHours(2);
                                break;
                            }
                            tempStartTime = tempStartTime.AddHours(2);

                            //防止死循环
                            if (loopCount > 12)
                            {
                                break;
                            }
                        }
                        #endregion
                        break;
                    }
                    else
                    {
                        currentDay  = excuteTime.AddMinutes(-5).ToString("yyyy-MM-dd");
                        endTimeDate = Convert.ToDateTime(currentDay + " " + item.End_Time);
                    }
                }
                #endregion

                if (!flag)
                {
                    continue;
                }
                //判断是否需要同步上一班次的数据

                if (currentDay == LatestcurrentDay && ShiftTimeID == LatestShiftTimeID)
                {
                    whetherUpdateLasteShfit = false;
                }
                //设定全天班的开始于结束时间
                var StartTimeStr = OEE_OutputRepository.getStartTime(customerModel.Organization_UID);
                ALLstartTimeDate = Convert.ToDateTime(currentDay + " " + StartTimeStr);
                ALLendTimeDate   = ALLstartTimeDate.AddDays(1);

                LatestALLstartTimeDate = Convert.ToDateTime(LatestcurrentDay + " " + StartTimeStr);
                LatestALLendTimeDate   = LatestALLstartTimeDate.AddDays(1);

                //根据专案ID获取该专案下的所有OEE机台
                var allMachines = OEE_OutputRepository.getAllMachineByProject(customerModel.Project_UID);


                /******************************同步不良数据*****************************/
                MissingDefectCodeUIDList = SyncDefect(customerModel, TimeIntervalStart, TimeIntervalEnd, currentDay, ShiftTimeID, TimeInterval, allMachines);

                /*********************************************/

                /******************************同步停机数据*****************************/
                MissingDownMachineUIDList = SyncDT(customerModel, startTimeDate, endTimeDate, currentDay, ShiftTimeID, TimeInterval, allMachines);

                /*********************************************/

                /******************************同步机台状态数据*****************************/
                // SyncRealStatus(customerModel, startTimeDate, endTimeDate, currentDay, ShiftTimeID, TimeInterval, allMachines);

                /*********************************************/
                //获取断网的机台清单
                //OfflineMachineUIDList = GetOffLineMachine(customerModel.Plant, customerModel.MESProject_Name,  allMachines);

                #region  步Local DB数据
                try
                {
                    ////  获取计划时间
                    var PlanHourValue    = getShiftRealTime(currentDay, excuteTime, startTimeDate, endTimeDate, ShiftTimeID, customerModel.Organization_UID);
                    var ALLPlanHourValue = getShiftRealTime(currentDay, excuteTime, ALLstartTimeDate, ALLendTimeDate, 0, customerModel.Organization_UID);
                    //var PlanHourValue = 12;
                    //var ALLPlanHourValue = 24;
                    //判断该专案该时段是否有数据
                    var EveryDayMachineList = OEE_OutputRepository.judgmentData(customerModel.Project_UID, currentDay, ShiftTimeID);
                    //判断该专案全天是否有数据
                    var ALLEveryDayMachineList = OEE_OutputRepository.ALLjudgmentData(customerModel.Project_UID, currentDay);
                    //获取机台产出数量
                    outputDic    = OEE_OutputRepository.SetOEE_MachineDayOutput(customerModel.Plant, customerModel.MESProject_Name, startTimeDate, endTimeDate);
                    ALLoutputDic = OEE_OutputRepository.SetOEE_MachineDayOutput(customerModel.Plant, customerModel.MESProject_Name, ALLstartTimeDate, ALLendTimeDate);

                    PorCTS = OEE_OutputRepository.GetPorCT(customerModel.Plant, customerModel.MESProject_Name);

                    FixtureS    = OEE_OutputRepository.GetFixtureNum(customerModel.Plant, customerModel.MESProject_Name, startTimeDate, endTimeDate);
                    ALLFixtureS = OEE_OutputRepository.GetFixtureNum(customerModel.Plant, customerModel.MESProject_Name, ALLstartTimeDate, ALLendTimeDate);
                    //成都厂某些制程不能获取治具数量,需要通过机器信息表获取国定的值
                    CTUFixtureS = OEE_OutputRepository.GetCTUFixtureNum(currentDay);

                    //获取机台实际CT
                    ActualCTS = OEE_OutputRepository.GetActualCT(customerModel.Plant, customerModel.MESProject_Name, startTimeDate, endTimeDate);

                    ALLActualCTS = OEE_OutputRepository.GetActualCT(customerModel.Plant, customerModel.MESProject_Name, ALLstartTimeDate, ALLendTimeDate);

                    //获取CNC机台Output

                    //获取CNC机台信息
                    CNCInfoLists    = OEE_OutputRepository.GetCNCActualCT(customerModel.Plant, startTimeDate, endTimeDate);
                    ALLCNCInfoLists = OEE_OutputRepository.GetCNCActualCT(customerModel.Plant, ALLstartTimeDate, ALLendTimeDate);

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

                    //3 添加和更新数据
                    foreach (var Machine in allMachines)
                    {
                        int    OutPutValue = 0;
                        double outValue    = 0.0;
                        OEE_EveryDayMachine stationModel    = new OEE_EveryDayMachine();
                        OEE_EveryDayMachine ALLstationModel = new OEE_EveryDayMachine();
                        #region 当班次
                        stationModel.Plant_Organization_UID    = customerModel.Plant_UID;
                        stationModel.BG_Organization_UID       = customerModel.Organization_UID;
                        stationModel.OEE_MachineInfo_UID       = Machine.OEE_MachineInfo_UID;
                        stationModel.FunPlant_Organization_UID = Machine.FunPlant_Organization_UID;
                        if (FixtureS.TryGetValue(Machine.MachineNo, out OutPutValue))
                        {
                            stationModel.FixtureNum = OutPutValue;
                        }
                        else if ((customerModel.Plant == "CTU" || customerModel.Plant == "CTU_M") && CTUFixtureS.TryGetValue(Machine.MachineNo, out OutPutValue))
                        {
                            stationModel.FixtureNum = OutPutValue;
                        }
                        else
                        {
                            stationModel.FixtureNum = 0;
                        }
                        if (ActualCTS.TryGetValue(Machine.MachineNo, out outValue))
                        {
                            stationModel.ActualCT = outValue;
                        }
                        else
                        {
                            stationModel.ActualCT = 0.0;
                        }

                        var CurrentPorCt = PorCTS.Find(o => o.MachineName == Machine.MachineNo);
                        if (CurrentPorCt != null)
                        {
                            stationModel.PORCT = CurrentPorCt.PorCT;
                        }
                        else
                        {
                            stationModel.PORCT = 0.0;
                        }

                        stationModel.Product_Date = Convert.ToDateTime(currentDay);
                        stationModel.ShiftTimeID  = ShiftTimeID;
                        if (outputDic.TryGetValue(Machine.MachineNo, out OutPutValue))
                        {
                            stationModel.OutPut = OutPutValue;
                        }
                        else
                        {
                            stationModel.OutPut = 0;
                        }
                        //无锡厂需要为CNC机台单独处理

                        var CNCInfoItem = CNCInfoLists.Find(o => o.MachineNo == Machine.MachineNo);
                        if (CNCInfoItem != null)
                        {
                            stationModel.ActualCT  = CNCInfoItem.ActualCT;
                            stationModel.OutPut    = CNCInfoItem.OutPut;
                            stationModel.ResetTime = CNCInfoItem.ResetTime;
                        }

                        stationModel.TotalAvailableHour = 12;
                        stationModel.PlannedHour        = PlanHourValue;
                        stationModel.UpdateTime         = DateTime.Now;

                        //判断是否该机台该天是否已经写入数据库
                        var CurrentItem = EveryDayMachineList.Find(o => o.OEE_MachineInfo_UID == Machine.OEE_MachineInfo_UID);

                        if (CurrentItem != null)
                        {
                            stationModel.OEE_EveryDayMachine_UID = CurrentItem.OEE_EveryDayMachine_UID;
                            updateList.Add(stationModel);
                        }
                        else
                        {
                            addList.Add(stationModel);
                        }

                        #endregion

                        #region 全天班次
                        ALLstationModel.Plant_Organization_UID    = customerModel.Plant_UID;
                        ALLstationModel.BG_Organization_UID       = customerModel.Organization_UID;
                        ALLstationModel.OEE_MachineInfo_UID       = Machine.OEE_MachineInfo_UID;
                        ALLstationModel.FunPlant_Organization_UID = Machine.FunPlant_Organization_UID;

                        if (ALLFixtureS.TryGetValue(Machine.MachineNo, out OutPutValue))
                        {
                            ALLstationModel.FixtureNum = OutPutValue;
                        }
                        else if ((customerModel.Plant == "CTU" || customerModel.Plant == "CTU_M") && CTUFixtureS.TryGetValue(Machine.MachineNo, out OutPutValue))
                        {
                            ALLstationModel.FixtureNum = OutPutValue;
                        }
                        else
                        {
                            ALLstationModel.FixtureNum = 0;
                        }

                        if (ALLActualCTS.TryGetValue(Machine.MachineNo, out outValue))
                        {
                            ALLstationModel.ActualCT = outValue;
                        }

                        else
                        {
                            ALLstationModel.ActualCT = 0.0;
                        }

                        if (CurrentPorCt != null)
                        {
                            ALLstationModel.PORCT = CurrentPorCt.PorCT;
                        }
                        else
                        {
                            ALLstationModel.PORCT = 0.0;
                        }

                        ALLstationModel.Product_Date = Convert.ToDateTime(currentDay);

                        if (ALLoutputDic.TryGetValue(Machine.MachineNo, out OutPutValue))
                        {
                            ALLstationModel.OutPut = OutPutValue;
                        }

                        else
                        {
                            ALLstationModel.OutPut = 0;
                        }
                        //无锡厂需要为CNC机台单独处理

                        var ALLCNCInfoItem = ALLCNCInfoLists.Find(o => o.MachineNo == Machine.MachineNo);
                        if (ALLCNCInfoItem != null)
                        {
                            ALLstationModel.ActualCT  = ALLCNCInfoItem.ActualCT;
                            ALLstationModel.OutPut    = ALLCNCInfoItem.OutPut;
                            ALLstationModel.ResetTime = ALLCNCInfoItem.ResetTime;
                        }

                        ALLstationModel.TotalAvailableHour = 24;
                        ALLstationModel.PlannedHour        = ALLPlanHourValue;
                        ALLstationModel.UpdateTime         = DateTime.Now;

                        if (MissingDownMachineUIDList.Contains(Machine.OEE_MachineInfo_UID))
                        {
                            stationModel.Is_DownType    = 1;
                            ALLstationModel.Is_DownType = 1;
                        }
                        if (MissingDefectCodeUIDList.Contains(Machine.OEE_MachineInfo_UID))
                        {
                            stationModel.AbnormalDFCode    = true;
                            ALLstationModel.AbnormalDFCode = true;
                        }
                        if (OfflineMachineUIDList.Contains(Machine.OEE_MachineInfo_UID))
                        {
                            stationModel.Is_Offline    = true;
                            ALLstationModel.Is_Offline = true;
                        }
                        else
                        {
                            stationModel.Is_Offline    = false;
                            ALLstationModel.Is_Offline = false;
                        }
                        //判断是否该机台该天是否已经写入数据库
                        var ALLCurrentItem = ALLEveryDayMachineList.Find(o => o.OEE_MachineInfo_UID == Machine.OEE_MachineInfo_UID);

                        if (ALLCurrentItem != null)
                        {
                            ALLstationModel.OEE_EveryDayMachine_UID = ALLCurrentItem.OEE_EveryDayMachine_UID;
                            updateList.Add(ALLstationModel);
                        }
                        else
                        {
                            addList.Add(ALLstationModel);
                        }
                    }
                    OEE_OutputRepository.AddList(addList);
                    OEE_OutputRepository.UpDateOEEDailyInfo(updateList);
                    unitOfWork.Commit();
                    #endregion
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());

                    //后续记录到失败日志表
                }

                #endregion
            }



            #region   步机台是否断网


            #endregion
        }