123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- using DbCommon.BusinessCore.BaseCore;
- using DbCommon.Enties.DbModels;
- using ProjectManagementSystem.Common.Config;
- using ProjectManagementSystem.Common.Logger;
- using ProjectManagementSystem.Device.CommandCallback;
- using System;
- using System.Collections.Concurrent;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ProjectManagementSystem.Common.Core
- {
- public class RouteCalled
- {
- private static RouteCalled m_instance;
- private ConcurrentQueue<InfoBox> m_calledRoute = new ConcurrentQueue<InfoBox>();
- private LocationPropertyManager m_locationManager = new LocationPropertyManager();
- public static RouteCalled Instance
- {
- get
- {
- if (m_instance == null)
- {
- m_instance = new RouteCalled();
- }
- return m_instance;
- }
- }
- private RouteCalled()
- {
- Task.Factory.StartNew(UserThread, TaskCreationOptions.LongRunning);
- }
- public void Call(InfoBox infoBox)
- {
- m_calledRoute.Enqueue(infoBox);
- }
- public void RouteProc()
- {
- while (m_calledRoute.TryDequeue(out InfoBox infoBox))
- {
- CLog.Instance.SystemLog.WriteInfo($"线路{infoBox.Route} 叫料{infoBox.BoxCalled} 叫料取消{infoBox.BoxCancelCall}");
- int route = infoBox.Route;
- var routeConfig = ExcelConfig.Instance.RouteConfigList.FirstOrDefault(d => d.Route > 0 && d.Route == route);
- if (routeConfig != null
- && !string.IsNullOrEmpty(routeConfig.LocationCode))
- {
- string location = string.IsNullOrEmpty(routeConfig.Remark1) ? routeConfig.LocationCode : routeConfig.Remark1;
- LocationStatus status = infoBox.BoxCalled ? (LocationStatus)routeConfig.CallLineStauts : (LocationStatus)routeConfig.CancelLineStauts;
- bool result = true;
- if (location.Contains(","))
- {
- string[] loacations = location.Split(new char[] { ',' });
- for (int i = 0; i < loacations.Length; i++)
- {
- var lData = m_locationManager.GetById(loacations[i]);
- lData.Status = status;
- result &= m_locationManager.UpdateWithTaskId(lData);
- }
- }
- else
- {
- var lData = m_locationManager.GetById(location);
- if (lData != null
- && (lData.Status != status))
- {
- lData.Status = status;
- result = m_locationManager.UpdateWithTaskId(lData);
- if (result)
- {
- CLog.Instance.SystemLog.WriteInfo($"更新库位状态成功:{location}:{status}");
- }
- }
- }
- }
- }
- }
- private void UserThread()
- {
- CLog.Instance.SystemLog.WriteDebug($"RouteCalled已启动");
- byte conter = 0;
- while (true)
- {
- try
- {
- RouteProc();
- }
- catch (Exception ex)
- {
- CLog.Instance.SystemLog.WriteException("RouteCalled", ex);
- Thread.Sleep(5000);
- }
- conter++;
- Thread.Sleep(100);
- }
- }
- }
- }
|