// 感觉写的还可以的代码



using AGV.Common.Base;
using AGV.Common.Diagnostics;
using AGV.Common.Enums;
using AGV.Common.Service;
using AGV.DTO;
using AGV.Entity;
using AGV.Global;
using AGV.Interface;
using AGV.Service;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace AGV.Service
{      
 /// 
///       抓取mes端数据 Bill
/// 
    public class MESService : ServiceBase, IMESService
    {
        private IAgvTaskService _agvTaskService;

        private IAppCallCarService _appCallCarService;

        public ProductLineInfoDTO GetProductLineByName(string name)
        {
            if (!string.IsNullOrEmpty(name))
            {
                List list = Db.From()
                                                  .Where(Product_Line_Info._.Name.ToUpper() == name.ToUpper()
                                                         && Product_Line_Info._.Valid == "Y")
                                                  .Select(Product_Line_Info._.All)
                                                  .ToList();
                if (list != null && list.Count > 0)
                {
                    return list.FirstOrDefault();
                }
            }
            return null;
        }
        public IAgvTaskService AgvTaskService
        {
            get { return _agvTaskService; }
            set { _agvTaskService = value; }
        }

        public IAppCallCarService AppCallCarService
        {
            get { return _appCallCarService; }
            set { _appCallCarService = value; }
        }
        AgvTaskDTO task = new AgvTaskDTO();

        //组织代码--
        private const string ORG_CODE = "C100";

        private DateTime beginRecord = DateTime.Now;
        private  TimeSpan ts;
        private double minutes;
        private string beginTime;
        TrafficCenter trafficCenter = TrafficCenter.Instance;
        MesWebService.MesWebServiceSoapClient mesService = new MesWebService.MesWebServiceSoapClient();

        List tasks = new List();
        //  _agvTaskService=new AgvTaskService();
        /// 
        /// 每隔 多少秒 抓取一下MES端提供的任务数据
        /// 
        /// 多少秒
        public bool FetchProductLinesTask(int secondsInterval)
        {
            /* 15-17 minute check the tasks that 30 minutes earlier than now   
             * */
            ts = DateTime.Now- beginRecord;

            if (15item.Pallet_Barcode== palletBarCode))
                {
                    successNum++;
                    continue;
                }
                string toStation = (string)jobj["data"][i]["AGV_TARGET_PLACE_CODE"];
                string moCode = (string)jobj["data"][i]["MO_CODE"];    //工单 

                task.Receive_Date = Convert.ToDateTime(jobj["data"][i]["DATETIME_CREATED"]);  //接收时间

                task.From_Station = GetProductLineByName(productLineName)?.Station_RFID;
               // task.From_Station = ServiceHelper.CallService(item=>item.GetProductLineByName(productLineName)).Station_RFID;

                task.Call_From = CallCarRequestFromEnum.MES;
                task.Valid = "Y";
                task.Status = TaskStatusEnum.NewTask;
                task.Task_Type = TaskTypeEnum.Warehousing;
                task.Car_Type = CarTypeEnum.Hybrid.ToString();
                task.To_Station = toStation;
                task.Pallet_Barcode = palletBarCode;
                task.Mo_Code = moCode;
                task.WorkCenter_Code = productLineName;


                Thread.Sleep(500);
                if (trafficCenter.AgvTaskService.AddAgvTask(task))
                {
                    successNum++;
                }
                else
                {
                    Logger.Log.Error(string.Format("从MES提取任务更新到数据库失败,时间={0}", DateTime.Now));
                }
            }
            if (successNum == taskNum)
            {
                return true;
            }
            return false;
        }
    }


}

 

你可能感兴趣的:(C#)