Example #1
0
        /// <summary>
        /// 返回当前时间的日期,时段,开始10分钟,结束10分钟
        /// </summary>
        /// <param name="currentDate"></param>
        /// <returns></returns>
        public static CurentTimeModel GetCurrentTime(DateTime currentDate)
        {
            var minute       = currentDate.Minute;
            var currentDay   = currentDate.AddMinutes(30).ToString("yyyy/MM/dd");
            var timeInterval = currentDate.AddHours(+0.5);
            var currentHour  = timeInterval.Hour / 2.0;

            //判断当前时间的时段
            var resultCurrentInterval = string.Empty;
            var resultStartTime       = 0;
            var resultStartTimeSrt    = string.Empty;
            var resultEndHour         = 0;
            var resultEndHourSrt      = string.Empty;

            for (int i = 0; i <= 12; i++)
            {
                if (currentHour >= i & currentHour < i + 1)
                {
                    resultStartTime = i * 2;
                    break;
                }
            }

            resultEndHour = resultStartTime + 2;

            //补齐 开始时段"08:00-10:00"
            if (resultStartTime.ToString().Length == 1)
            {
                resultStartTimeSrt = "0" + resultStartTime.ToString();
            }
            else
            {
                resultStartTimeSrt = resultStartTime.ToString();
            }

            //补齐 结束时段"08:00-10:00"
            if (resultEndHour.ToString().Length == 1)
            {
                resultEndHourSrt = "0" + resultEndHour.ToString();
            }
            else
            {
                resultEndHourSrt = resultEndHour.ToString();
            }

            resultCurrentInterval = resultStartTimeSrt + ":00" + "-" + resultEndHourSrt + ":00";

            //当前的分钟数
            var currentMinute = minute / 10;

            currentMinute = currentMinute * 10;

            var currentStartMinute    = currentMinute;
            var currentEndMinute      = currentMinute + 10;
            var currentStartMinuteStr = string.Empty;
            var currentEndMinuteStr   = string.Empty;

            if (currentEndMinute >= 60)
            {
                currentStartMinuteStr = currentDate.ToString("yyyy/MM/dd HH:50");
                currentEndMinuteStr   = currentDate.AddHours(1).ToString("yyyy/MM/dd HH:00");
            }
            else if (currentStartMinute == 0)
            {
                currentStartMinuteStr = currentDate.ToString("yyyy/MM/dd HH:00");
                currentEndMinuteStr   = currentDate.ToString("yyyy/MM/dd HH:10");
            }
            else
            {
                currentStartMinuteStr = currentDate.ToString("yyyy/MM/dd HH:") + currentStartMinute.ToString();
                currentEndMinuteStr   = currentDate.ToString("yyyy/MM/dd HH:") + currentEndMinute.ToString();
            }

            CurentTimeModel resultModel = new CurentTimeModel
            {
                CurrentDay         = currentDay,
                CurrentInterval    = resultCurrentInterval,
                CurrentStartMinute = currentStartMinuteStr,
                CurrentEndMinute   = currentEndMinuteStr
            };

            return(resultModel);
        }
Example #2
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);
            }
        }