using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Globalization;
|
using System.Linq;
|
using System.Text;
|
using WIDESEA.Common;
|
using WIDESEA.Core.Extensions;
|
using WIDESEA.Core.ManageUser;
|
using WIDESEA.Core.Services;
|
using WIDESEA.Core.Utilities;
|
using WIDESEA.Entity.DomainModels;
|
using WIDESEA.Services.IRepositories;
|
using WIDESEA.Services.Repositories;
|
using WIDESEA_Common.LogEnum;
|
|
namespace WIDESEA.Services.Services
|
{
|
public partial class CommonFunction
|
{
|
/// <summary>
|
/// 轴承出库
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public static WebResponseContent BearingOutboundAction(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
//轮对条码
|
string barcode = saveModel.MainData["barcode"].ToString();
|
//车型
|
string materiel = saveModel.MainData["materiel"].ToString();
|
//轴承状态新旧
|
string zcState = saveModel.MainData["zcState"].ToString();
|
//轴承厂家
|
string Manufacturer = saveModel.MainData["Manufacturer"].ToString();
|
//右防尘板
|
string yfcbAVG = saveModel.MainData["yfcbAVG"]?.ToString();
|
//左防尘板
|
string zfcbAVG = saveModel.MainData["zfcbAVG"]?.ToString();
|
//左油档
|
string zydAVG = saveModel.MainData["zydAVG"]?.ToString();
|
//右油档
|
string yydAVG = saveModel.MainData["yydAVG"]?.ToString();
|
//左轴径
|
string zzjAVG = saveModel.MainData["zzjAVG"]?.ToString();
|
//右轴径
|
string yzjAVG = saveModel.MainData["yzjAVG"]?.ToString();
|
//呼叫工位
|
string targetStation = saveModel.MainData["targetStation"].ToString();
|
//轴承方向
|
string ZCdirection = saveModel.MainData["ZCdirection"].ToString();
|
|
//轮对号
|
string ldCode = saveModel.MainData["ldCode"].ToString();
|
|
|
//左出库轴承
|
VV_ContainerInfo leftContainer = null;
|
//右出库轴承
|
VV_ContainerInfo rightContainer = null;
|
List<Dt_materielinfo> materielinfo = Dt_materielinfoRepository.Instance.Find(r => r.materiel_suitMateriel.Contains(materiel));
|
|
|
//获取选配标准
|
List<Dt_selection_standards> listStandard = null;
|
foreach (var item in materielinfo)
|
{
|
listStandard = Dt_selection_standardsRepository.Instance.Find(r => r.selection_carId == item.materiel_id
|
&& r.selection_zc_manufacturer == Manufacturer && r.selection_zc_type.Contains(zcState));
|
if (null != listStandard && listStandard.Count > 0)
|
break;
|
}
|
|
foreach (var item in materielinfo)
|
{
|
List<VV_ContainerInfo> listContainer = VV_ContainerInfoRepository.Instance.Find(r => !r.location_islocked
|
&& r.location_state == LocationState.LocationState_Stored.ToString() && r.containerdtl_madeUnit == Manufacturer
|
&& r.containerdtl_standard.Contains(zcState) && r.materiel_id == item.materiel_id && r.containerdtl_standardResult == 1
|
&& (string.IsNullOrEmpty(r.csize_out_result) || r.csize_out_result == "合格") && r.containerdtl_qualityCheck == true
|
&& r.containerdtl_takeGoogsCheck == true);
|
|
//listContainer = listContainer.OrderBy(x => DateTime.ParseExact(x.containerdtl_ProductDate,"yyyy-MM-dd",CultureInfo.InvariantCulture)).ToList();
|
|
|
|
//&& Convert.ToDateTime(r.containerdtl_ProductDate) > DateTime.Now
|
if (null != listContainer && listContainer.Count > 0)
|
{
|
if ("all".Equals(ZCdirection) || string.IsNullOrEmpty(ZCdirection))
|
{
|
if (null == leftContainer)
|
{
|
leftContainer = GetContainer(listStandard, listContainer, zzjAVG, zfcbAVG, zydAVG, "left");
|
if (null != leftContainer)
|
listContainer.Remove(leftContainer);
|
}
|
if (null == rightContainer)
|
{
|
rightContainer = GetContainer(listStandard, listContainer, yzjAVG, yfcbAVG, yydAVG, "right");
|
if (null != rightContainer)
|
listContainer.Remove(rightContainer);
|
}
|
if (null == leftContainer || null == rightContainer)
|
continue;
|
else
|
break;
|
}
|
else if ("left".Equals(ZCdirection))
|
{
|
leftContainer = GetContainer(listStandard, listContainer, zzjAVG, zfcbAVG, zydAVG, "left");
|
if (null == leftContainer)
|
continue;
|
else
|
break;
|
}
|
else if ("right".Equals(ZCdirection))
|
{
|
rightContainer = GetContainer(listStandard, listContainer, yzjAVG, yfcbAVG, yydAVG, "right");
|
if (null == rightContainer)
|
continue;
|
else
|
break;
|
}
|
}
|
}
|
|
if ("all".Equal(ZCdirection))
|
{
|
if (null == leftContainer || null == rightContainer)
|
return content.Error("未找到可匹配的出库轴承,车型:" + materiel);
|
}
|
|
if (null != leftContainer || null != rightContainer)
|
{
|
IDt_taskinfoRepository taskinfoRepository = Dt_taskinfoRepository.Instance;
|
content = taskinfoRepository.DbContextBeginTransaction(() =>
|
{
|
List<Dt_taskinfo> listTask = new List<Dt_taskinfo>();
|
if (null != leftContainer)
|
{
|
Dt_taskinfo leftTask = GetOutboundTask(leftContainer, targetStation, "left", CommonFunction.GetZCInfo(leftContainer, materiel, barcode, zfcbAVG, zydAVG, zzjAVG, ldCode, targetStation, "left"));
|
listTask.Add(leftTask);
|
}
|
if (null != rightContainer)
|
{
|
Dt_taskinfo rightTask = GetOutboundTask(rightContainer, targetStation, "right", CommonFunction.GetZCInfo(rightContainer, materiel, barcode, yfcbAVG, yydAVG, yzjAVG, ldCode, targetStation, "right"));
|
listTask.Add(rightTask);
|
}
|
taskinfoRepository.AddRange(listTask, true);
|
//下发出库任务给WCS
|
content = WIDESEA_Services.WCSApi.SendTaskToWCS(listTask);
|
if (content.Status)
|
{
|
//if (null != leftContainer)
|
// CommonFunction.WheelsetMatch(barcode, leftContainer.containerdtl_number, "6");
|
//if (null != rightContainer)
|
// CommonFunction.WheelsetMatch(barcode, rightContainer.containerdtl_number, "7");
|
content.OK($"轴承出库任务下发给WCS成功.");
|
}
|
else
|
content.Error($"轴承出库任务下发给WCS失败,原因 => {content.Message}");
|
|
return content;
|
});
|
}
|
else
|
return content.Error("未找到可匹配的出库轴承,车型:" + materiel);
|
}
|
catch (Exception ex)
|
{
|
content.Error("创建轴承出库任务失败:" + ex.Message);
|
}
|
finally
|
{
|
LogRecord.WriteLog((int)LogEnum.OutBound, $"{UserContext.Current.UserTrueName}轴承选配出库:参数:{saveModel.Serialize()},返回参数:{content.Serialize()}");
|
//Logger.AddLog(Core.Enums.LoggerType.Add, saveModel, content, content);
|
}
|
return content;
|
}
|
|
private static Dt_taskinfo GetOutboundTask(VV_ContainerInfo container, string target, string direction, object zcInfo)
|
{
|
Dt_locationinfo locationinfo = Dt_locationinfoRepository.Instance.FindFirst(x => x.location_id == container.location_id);
|
CommonFunction.ChangeLocationState(locationinfo, LocationState.LocationState_Outbound_Wait_Executing.ToString());
|
Dt_taskinfo taskinfo = new Dt_taskinfo();
|
taskinfo.task_id = Guid.NewGuid();
|
taskinfo.task_type = TaskType.TaskType_Box_Pallet_Outbound.ToString();
|
taskinfo.task_state = TaskState.TaskState_Create.ToString();
|
taskinfo.task_barcode = container.containerhead_barcode;
|
taskinfo.task_materielid = container.materiel_id;
|
//起始货位
|
taskinfo.task_fromlocationid = container.location_id;
|
//目的货位
|
taskinfo.task_tolocationid = LayerToStation.OutAreaLayerToStation(locationinfo.location_layer);
|
//起始站台
|
taskinfo.task_beginstation = LayerToStation.OutAreaLayerToStation(locationinfo.location_layer);
|
//目的站台
|
taskinfo.task_endstation = LayerToStation.GetOutboundStation(target, direction);
|
taskinfo.task_grade = 0;
|
taskinfo.task_isunpacked = false;
|
taskinfo.task_creator = UserContext.Current.UserTrueName;
|
taskinfo.task_createtime = DateTime.Now;
|
taskinfo.task_bak_1 = JsonConvert.SerializeObject(zcInfo);
|
taskinfo.task_sn = container.containerdtl_goodsCode;
|
taskinfo.task_materielType = container.containerdtl_type;
|
taskinfo.task_weight = container.containerdtl_goodsWeight;
|
return taskinfo;
|
}
|
|
/// <summary>
|
/// 获取库存
|
/// </summary>
|
/// <param name="listStand"></param>
|
/// <param name="listContainer"></param>
|
/// <param name="fcbAVG"></param>
|
/// <param name="ydAVG"></param>
|
/// <param name="zzAVG"></param>
|
/// <param name="direction"></param>
|
public static VV_ContainerInfo GetContainer(List<Dt_selection_standards> listStand, List<VV_ContainerInfo> listContainer,
|
string zjAVG, string fcbAVG, string ydAVG, string direction)
|
{
|
IQueryable<VV_ContainerInfo> queryble = listContainer.AsQueryable();
|
|
//轴承内径
|
|
Dt_selection_standards zjStand = listStand.Find(r => r.selection_standard_type == "1");
|
if (null != zjStand)
|
{
|
if (!string.IsNullOrEmpty(zjAVG))
|
{
|
//上限
|
decimal zjStandQty_positive = zjStand.selection_positive_value.GetValueOrDefault();
|
//下限
|
decimal zjStandQty_negative = zjStand.selection_negative_value.GetValueOrDefault();
|
decimal mesStand = decimal.Parse(zjAVG);
|
queryble = queryble.Where(r => r.csize_in_result == "合格" && mesStand - (decimal.Parse(r.csize_in_value)) >= zjStandQty_negative
|
&& mesStand - (decimal.Parse(r.csize_in_value)) <= zjStandQty_positive);
|
}
|
else
|
queryble = queryble.Where(r => r.csize_in_result != "不合格");
|
}
|
else
|
queryble = queryble.Where(r => r.csize_in_result != "不合格");
|
|
////防尘板
|
Dt_selection_standards fcbStand = listStand.Find(r => r.selection_standard_type == "2");
|
if (null != fcbStand)
|
{
|
|
if (!string.IsNullOrEmpty(fcbAVG))
|
{
|
//上限
|
decimal fcbStandQty_positive = fcbStand.selection_positive_value.GetValueOrDefault();
|
//下限
|
decimal fcbStandQty_negative = fcbStand.selection_negative_value.GetValueOrDefault();
|
decimal mesStand = decimal.Parse(fcbAVG);
|
queryble = queryble.Where(r => r.csize_four_result == "合格" && mesStand - (decimal.Parse(r.csize_four_3)) >= fcbStandQty_negative
|
&& mesStand - (decimal.Parse(r.csize_four_3)) <= fcbStandQty_positive);
|
}
|
else
|
queryble = queryble.Where(r => r.csize_four_result != "不合格");
|
}
|
else
|
queryble = queryble.Where(r => r.csize_four_result != "不合格");
|
|
////油档
|
Dt_selection_standards ydStand = listStand.Find(r => r.selection_standard_type == "3");
|
if (null != ydStand)
|
{
|
if (!string.IsNullOrEmpty(ydAVG))
|
{
|
//上限
|
decimal ydStandQty_positive = ydStand.selection_positive_value.GetValueOrDefault();
|
//下限
|
decimal ydStandQty_negative = ydStand.selection_negative_value.GetValueOrDefault();
|
decimal mesStand = decimal.Parse(ydAVG);
|
queryble = queryble.Where(r => r.csize_three_result == "合格" && (mesStand - decimal.Parse(r.csize_three_3)) >= ydStandQty_negative
|
&& mesStand - (decimal.Parse(r.csize_three_3)) <= ydStandQty_positive);
|
}
|
else
|
queryble = queryble.Where(r => r.csize_three_result != "不合格");
|
}
|
else
|
queryble = queryble.Where(r => r.csize_three_result != "不合格");
|
|
|
|
//轴承内径
|
//if (!string.IsNullOrEmpty(zjAVG))
|
//{
|
// Dt_selection_standards zjStand = listStand.Find(r => r.selection_standard_type == "1");
|
// if (null == zjStand)
|
// throw new Exception($"请先维护可用的轴承内径过盈量选配标准。");
|
// //上限
|
// decimal zjStandQty_positive = zjStand.selection_positive_value.GetValueOrDefault();
|
// //下限
|
// decimal zjStandQty_negative = zjStand.selection_negative_value.GetValueOrDefault();
|
// decimal mesStand = decimal.Parse(zjAVG);
|
// queryble = queryble.Where(r => r.csize_in_result == "合格" && (decimal.Parse(r.csize_in_value) - mesStand) >= zjStandQty_negative
|
// && (decimal.Parse(r.csize_in_value) - mesStand) <= zjStandQty_positive);
|
//}
|
//else
|
// queryble = queryble.Where(r => r.csize_in_result != "不合格");
|
|
////防尘板
|
//if (!string.IsNullOrEmpty(fcbAVG))
|
//{
|
// Dt_selection_standards fcbStand = listStand.Find(r => r.selection_standard_type == "2");
|
// if (null == fcbStand)
|
// throw new Exception($"请先维护可用的防尘板过盈量选配标准。");
|
// //上限
|
// decimal fcbStandQty_positive = fcbStand.selection_positive_value.GetValueOrDefault();
|
// //下限
|
// decimal fcbStandQty_negative = fcbStand.selection_negative_value.GetValueOrDefault();
|
// decimal mesStand = decimal.Parse(fcbAVG);
|
// queryble = queryble.Where(r => r.csize_four_result == "合格" && (decimal.Parse(r.csize_four_3) - mesStand) >= fcbStandQty_negative
|
// && (decimal.Parse(r.csize_four_3) - mesStand) <= fcbStandQty_positive);
|
//}
|
//else
|
// queryble = queryble.Where(r => r.csize_four_result != "不合格");
|
|
|
////油档
|
//if (!string.IsNullOrEmpty(ydAVG))
|
//{
|
// Dt_selection_standards ydStand = listStand.Find(r => r.selection_standard_type == "3");
|
// if (null == ydStand)
|
// throw new Exception($"请先维护可用的油档过盈量选配标准。");
|
// //上限
|
// decimal ydStandQty_positive = ydStand.selection_positive_value.GetValueOrDefault();
|
// //下限
|
// decimal ydStandQty_negative = ydStand.selection_negative_value.GetValueOrDefault();
|
// decimal mesStand = decimal.Parse(ydAVG);
|
// queryble = queryble.Where(r => r.csize_three_result == "合格" && (decimal.Parse(r.csize_three_3) - mesStand) >= ydStandQty_negative
|
// && (decimal.Parse(r.csize_three_3) - mesStand) <= ydStandQty_positive);
|
//}
|
//else
|
// queryble = queryble.Where(r => r.csize_three_result != "不合格");containerdtl_createtime
|
|
|
|
return queryble.OrderBy(r => r.containerdtl_ProductDate).ThenBy(r => r.containerdtl_createtime).FirstOrDefault();
|
}
|
|
|
}
|
}
|