using HH.WMS.BLL;
|
using HH.WMS.BLL.OutStock;
|
using HH.WMS.Common;
|
using HH.WMS.Entitys;
|
using HH.WMS.Entitys.Basic;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Configuration;
|
using System.Linq;
|
using System.Timers;
|
using System.Web;
|
|
namespace HH.WMS.WebApi.Extension
|
{
|
public class ExecuteSortingTask : IExecuteThreadTimed
|
{
|
public void Run(object source, ElapsedEventArgs elapsedEventArgs)
|
{
|
try
|
{
|
//分拣中的分拣单
|
var beingSorting = BLLCreator.CreateDapper<TN_WM_SORTING_LISTEntity>().GetSingleEntity(new
|
{
|
CN_S_STATE = Constants.Sorting_Being
|
});
|
if (beingSorting != null)
|
{
|
//分拣明细
|
var sortingLocations = BLLCreator.CreateDapper<TN_WM_SORTING_LOCATIONEntity>().GetList(new
|
{
|
CN_S_SORTING_NO = beingSorting.CN_S_SORTING_NO,
|
CN_B_SEND = false
|
}).OrderBy(o => o.CN_T_CREATE).GroupBy(g => new
|
{
|
g.CN_S_SORTING_NO,
|
g.CN_S_TRAY_CODE,
|
g.CN_S_LOCATION_CODE,
|
g.CN_S_NEED_SORT,
|
g.CN_S_AREA_CODE
|
}).Select(s => new TN_WM_SORTING_LOCATIONEntity()
|
{
|
CN_S_SORTING_NO = s.Key.CN_S_SORTING_NO,
|
CN_S_TRAY_CODE = s.Key.CN_S_TRAY_CODE,
|
CN_S_LOCATION_CODE = s.Key.CN_S_LOCATION_CODE,
|
CN_S_NEED_SORT = s.Key.CN_S_NEED_SORT,
|
CN_S_STOCK_CODE = beingSorting.CN_S_STOCK_CODE,
|
CN_S_AREA_CODE = s.Key.CN_S_AREA_CODE
|
}).ToList();
|
|
var sends = new List<TN_WM_SORTING_LOCATIONEntity>();
|
if (sortingLocations.Any())
|
{
|
//整托的
|
sends.AddRange(CalcEndBit(sortingLocations, Constants.N));
|
//散托的
|
sends.AddRange(CalcEndBit(sortingLocations, Constants.Y));
|
//存在可用暂存分拣货位
|
if (sends.Any())
|
{
|
var or = BLLCreator.Create<OutStockBLL>().ExecuteSortingTask(sends);
|
if (!or.Success)
|
Log.DomainInfo("ExecuteSortingTask Error", or.Msg);
|
else
|
Log.DomainInfo("生成成功 分拣明细", JsonConvert.SerializeObject(sends));
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Log.DomainInfo("ExecuteSortingTask Error", ex.Message);
|
}
|
}
|
|
#region 计算终点货位
|
/// <summary>
|
/// 计算终点货位
|
/// </summary>
|
/// <param name="sl"></param>
|
/// <param name="needSort"></param>
|
/// <returns></returns>
|
private List<TN_WM_SORTING_LOCATIONEntity> CalcEndBit(List<TN_WM_SORTING_LOCATIONEntity> sl, string needSort)
|
{
|
var res = new List<TN_WM_SORTING_LOCATIONEntity>();
|
var ss = sl.FindAll(f => f.CN_S_NEED_SORT == needSort);
|
|
if (ss.Any())
|
{
|
string area = needSort == "Y"
|
? Util.ToString(ConfigurationManager.AppSettings["DisperArea"]) :
|
Util.ToString(ConfigurationManager.AppSettings["FullArea"]);
|
|
//是否存在货位
|
var emptyLocations = BLLCreator.CreateDapper<TN_WM_LOCATION_EXTEntity>().GetList(new
|
{
|
CN_S_AREA_CODE = area,
|
CN_S_LOCATION_STATE = Constants.Location_State_Normal,
|
CN_S_USE_STATE = Constants.Use_State_Empty,
|
}).OrderBy(o => o.CN_S_LOCATION_CODE);
|
|
foreach (var el in emptyLocations)
|
{
|
foreach (var fs in ss)
|
{
|
if (!fs.CN_B_SEND)
|
{
|
fs.CN_B_SEND = true;
|
fs.EndBit = el.CN_S_LOCATION_CODE;
|
fs.EndArea = area;
|
|
res.Add(fs);
|
break;
|
}
|
}
|
}
|
}
|
return res;
|
}
|
#endregion
|
}
|
}
|