Ejemplo n.º 1
0
        /// <summary>
        /// 同步数据
        /// </summary>
        /// <returns></returns>
        public static string SyncGoldenLineCT()
        {
            string result = "";
            GL_GoldenStationCTRecordService gL_GoldenStationCTRecordService = new GL_GoldenStationCTRecordService(
                new GL_GoldenStationCTRecordRepository(_DatabaseFactory),
                new UnitOfWork(_DatabaseFactory)
                );
            //获取所有要同步的站点
            var stationDTOs = gL_GoldenStationCTRecordService.GetStationDTO();
            //获取所有的班次
            var shiftTimeDTOs = gL_GoldenStationCTRecordService.GetShiftTimeDTO(0, 0);


            //获取所有线
            var lineDTOs = gL_GoldenStationCTRecordService.GetLineDTO();
            List <GoldenLineCTRecordDTO> GoldenLineCTRecordDTOs = new List <GoldenLineCTRecordDTO>();
            DateTime dateNow = DateTime.Now;

            // DateTime dateNow = DateTime.Now.AddDays(-1).AddHours(7);

            if (stationDTOs != null && stationDTOs.Count > 0)
            {
                stationDTOs = stationDTOs.Where(o => o.IsGoldenLine == true).ToList();
                string connectionString = "";
                foreach (var item in stationDTOs)
                {
                    if (item.Plant_Organization_UID == 1)
                    {
                        connectionString = GetCTUConnectionStrings();
                    }
                    else if (item.Plant_Organization_UID == 35)
                    {
                        connectionString = GetConnectionStrings();
                    }

                    var shiftTimes = shiftTimeDTOs.Where(o => o.Plant_Organization_UID == item.Plant_Organization_UID && o.BG_Organization_UID == item.BG_Organization_UID);

                    var      shiftTimeDTO  = GetGL_ShiftTimeDTO(shiftTimes.ToList(), dateNow);
                    DateTime StartTime     = Convert.ToDateTime((dateNow.ToString("yyyy-MM-dd ") + shiftTimeDTO.StartTime));
                    DateTime EndTime       = Convert.ToDateTime((dateNow.ToString("yyyy-MM-dd ") + shiftTimeDTO.End_Time));
                    DateTime CycleTimeDate = dateNow;

                    //同步当前班次的数据

                    if (StartTime > EndTime)
                    {
                        // EndTime = EndTime.AddDays(1);
                        StartTime     = StartTime.AddDays(-1);
                        CycleTimeDate = StartTime;

                        //if (CycleTimeDate.Date.ToString("yyyy-MM-dd") == EndTime.Date.ToString("yyyy-MM-dd"))
                        //{
                        //    CycleTimeDate = CycleTimeDate.AddDays(-1);
                        //}
                    }

                    var WipeventDTOs = GetWipevent(item.MESProjectName, item.MESLineName, item.MESStationName, StartTime, dateNow, connectionString);

                    if (WipeventDTOs != null)
                    {
                        var goldenLineCTRecordDTO = GetGoldenLineCTRecords(WipeventDTOs, item.LineCycleTime, item.StationID, shiftTimeDTO.ShiftTimeID, StartTime, EndTime, CycleTimeDate.ToString("yyyy-MM-dd"));

                        if (goldenLineCTRecordDTO != null)
                        {
                            GoldenLineCTRecordDTOs.Add(goldenLineCTRecordDTO);
                        }
                    }

                    // 同步更新上一个班次的数据 这里要判断是否同步

                    ///Start StartTime 代表最后同步时间 及上一个班次的当前时间
                    var      nextshiftTimeDTO  = GetGL_ShiftTimeDTO(shiftTimes.ToList(), StartTime);
                    DateTime nextStartTime     = Convert.ToDateTime((StartTime.ToString("yyyy-MM-dd ") + nextshiftTimeDTO.StartTime));
                    DateTime nextEndTime       = StartTime;
                    DateTime nextCycleTimeDate = StartTime;

                    if (nextStartTime > nextEndTime)
                    {
                        nextStartTime     = nextStartTime.AddDays(-1);
                        nextCycleTimeDate = nextStartTime;
                        //if (nextCycleTimeDate.Date.ToString("yyyy-MM-dd") == nextEndTime.Date.ToString("yyyy-MM-dd"))
                        //{
                        //    nextCycleTimeDate = nextCycleTimeDate.AddDays(-1);
                        //}
                    }

                    //根据当前的班次,站点,日期找出当前站点上一个班次的数据明细,获取最后更新时间
                    var nextGoldenLineCTRecordDTOs = gL_GoldenStationCTRecordService.GetGoldenLineCTRecordDTO(item.StationID, nextshiftTimeDTO.ShiftTimeID, nextCycleTimeDate.ToString("yyyy-MM-dd"));
                    if (nextGoldenLineCTRecordDTOs != null)
                    {
                        var GoldenLineCTRecordDTO = nextGoldenLineCTRecordDTOs.FirstOrDefault();

                        if (GoldenLineCTRecordDTO != null)
                        {
                            DateTime nextstratEndTime = nextEndTime.AddMinutes(-5);
                            //最后超过5分钟没同步就必须同步
                            if (GoldenLineCTRecordDTO.UpdateTime <= nextstratEndTime)
                            {
                                var nextWipeventDTOs = GetWipevent(item.MESProjectName, item.MESLineName, item.MESStationName, nextStartTime, nextEndTime, connectionString);
                                if (nextWipeventDTOs != null)
                                {
                                    var goldenLineCTRecordDTO = GetGoldenLineCTRecords(nextWipeventDTOs, item.LineCycleTime, item.StationID, nextshiftTimeDTO.ShiftTimeID, nextStartTime, nextEndTime, nextCycleTimeDate.ToString("yyyy-MM-dd"));
                                    if (goldenLineCTRecordDTO != null)
                                    {
                                        GoldenLineCTRecordDTOs.Add(goldenLineCTRecordDTO);
                                    }
                                }
                            }
                        }
                    }
                    ///End
                }
            }

            result = gL_GoldenStationCTRecordService.InsertANDUpdateGoldenLineCTRecord(GoldenLineCTRecordDTOs);
            return(result);
        }
Ejemplo n.º 2
0
        public static string SyncGoldenLineWeekPlan()
        {
            string result = "";
            GL_GoldenStationCTRecordService gL_GoldenStationCTRecordService = new GL_GoldenStationCTRecordService(new GL_GoldenStationCTRecordRepository(_DatabaseFactory), new UnitOfWork(_DatabaseFactory));
            //获取本周计划
            var ThisWeekPlans = gL_GoldenStationCTRecordService.GetWeekPlan(GetWeekDates(GetCurrentWeek(DateTime.Now)));
            //获取下周计划
            var NextWeekPlans = gL_GoldenStationCTRecordService.GetWeekPlan(GetWeekDates(GetNextWeek(DateTime.Now)));
            //根据本周计划和下周计划组装下周计划
            List <GLBuildPlanDTO> GLBuildPlanDTOs = new List <GLBuildPlanDTO>();

            foreach (var item in ThisWeekPlans)
            {
                GLBuildPlanDTO gLBuildPlanDTO = new GLBuildPlanDTO();
                string         nextOutputDate = Convert.ToDateTime(item.OutputDate).AddDays(7).ToString(FormatConstants.DateTimeFormatStringByDate);
                if (NextWeekPlans != null && NextWeekPlans.Count > 0)
                {
                    var NextWeekPlan = NextWeekPlans.FirstOrDefault(o => o.LineID == item.LineID && o.ShiftTimeID == item.ShiftTimeID && o.OutputDate == nextOutputDate);
                    if (NextWeekPlan == null)
                    {
                        //新增
                        gLBuildPlanDTO.OutputDate = nextOutputDate;
                        // BuildPlanID
                        gLBuildPlanDTO.CustomerID    = item.CustomerID;
                        gLBuildPlanDTO.LineID        = item.LineID;
                        gLBuildPlanDTO.PlanOutput    = item.PlanOutput;
                        gLBuildPlanDTO.ShiftTimeID   = item.ShiftTimeID;
                        gLBuildPlanDTO.PlanHC        = item.PlanHC;
                        gLBuildPlanDTO.ActualHC      = item.ActualHC;
                        gLBuildPlanDTO.Created_UID   = item.Created_UID;
                        gLBuildPlanDTO.Created_Date  = item.Created_Date;
                        gLBuildPlanDTO.Modified_UID  = item.Modified_UID;
                        gLBuildPlanDTO.Modified_Date = item.Modified_Date;
                    }
                    else
                    {
                        //编辑
                        gLBuildPlanDTO.BuildPlanID = NextWeekPlan.BuildPlanID;
                        gLBuildPlanDTO.OutputDate  = nextOutputDate;
                        gLBuildPlanDTO.CustomerID  = NextWeekPlan.CustomerID;
                        gLBuildPlanDTO.LineID      = NextWeekPlan.LineID;
                        if (NextWeekPlan.PlanOutput == 0)
                        {
                            gLBuildPlanDTO.PlanOutput = item.PlanOutput;
                        }
                        gLBuildPlanDTO.ShiftTimeID = item.ShiftTimeID;
                        if (NextWeekPlan.PlanHC == null)
                        {
                            gLBuildPlanDTO.PlanHC = item.PlanHC;
                        }

                        if (NextWeekPlan.PlanHC == null)
                        {
                            gLBuildPlanDTO.PlanHC = item.PlanHC;
                        }
                        gLBuildPlanDTO.Created_UID   = NextWeekPlan.Created_UID;
                        gLBuildPlanDTO.Created_Date  = NextWeekPlan.Created_Date;
                        gLBuildPlanDTO.Modified_UID  = item.Modified_UID;
                        gLBuildPlanDTO.Modified_Date = item.Modified_Date;
                    }
                }
                else
                {
                    //新增
                    gLBuildPlanDTO.OutputDate = nextOutputDate;
                    // BuildPlanID
                    gLBuildPlanDTO.CustomerID    = item.CustomerID;
                    gLBuildPlanDTO.LineID        = item.LineID;
                    gLBuildPlanDTO.PlanOutput    = item.PlanOutput;
                    gLBuildPlanDTO.ShiftTimeID   = item.ShiftTimeID;
                    gLBuildPlanDTO.PlanHC        = item.PlanHC;
                    gLBuildPlanDTO.ActualHC      = item.ActualHC;
                    gLBuildPlanDTO.Created_UID   = item.Created_UID;
                    gLBuildPlanDTO.Created_Date  = item.Created_Date;
                    gLBuildPlanDTO.Modified_UID  = item.Modified_UID;
                    gLBuildPlanDTO.Modified_Date = item.Modified_Date;
                }
                GLBuildPlanDTOs.Add(gLBuildPlanDTO);
            }

            result = gL_GoldenStationCTRecordService.SyncGoldenLineWeekPlan(GLBuildPlanDTOs);
            return(result);
        }