using Newtonsoft.Json;
using PlcSiemens.Core.Extension;
using ServiceCenter.Extensions;
using ServiceCenter.Logs;
using ServiceCenter.SqlSugars;
using SqlSugar;
using System.ComponentModel;
using WCS.Core;
using WCS.Entity;
using WCS.Entity.Protocol.BCR;
using WCS.Entity.Protocol.Station;
using WCS.WorkEngineering.Extensions;
using WCS.WorkEngineering.Worlds;
using TaskStatus = WCS.Entity.TaskStatus;
namespace WCS.WorkEngineering.Systems
{
///
/// 满轮主线预写入目标地址
///
[BelongTo(typeof(SortingMainLineWorld))]
[Description("满轮主线预写入目标地址")]
public class 满轮主线预写入目标地址 : DeviceSystem>
{
protected override bool ParallelDo => true;
public override void Do(Device obj)
{
try
{
var devCode = obj.Entity.Code switch
{
"18" => "22",
"38" => "41",
"58" => "61",
"118" => "122",
"138" => "141",
"158" => "161",
_ => throw new ArgumentOutOfRangeException()
};
var dev = new Device(Device.All.First(x => x.Code == devCode), World);
dev.Data.Mode = StationMode.Automatic;
//从DB83中获取待处理条码组
var pendingBcrList = obj.Data2.GetBcrCodeList().Where(x => !x.IsNullOrEmpty());
//从DB525获取已处理条码组
var cacheBcrList = obj.Data3.GetBcrCodeList();
//筛选出未处理条码组
var codes = pendingBcrList.Where(x => !cacheBcrList.Contains(x));
World.Log($"扫码器:{JsonConvert.SerializeObject(pendingBcrList)}");
World.Log($"缓存信息:{JsonConvert.SerializeObject(cacheBcrList)}");
//循环处理所有缓存条码组中没有的条码
foreach (var bcrCode in codes)
{
WCS_TaskInfo taskInfo = null;
fjSysConfig config = new fjSysConfig();
SqlSugarHelper.Do(_db =>
{
var db = _db.Default;
var task = db.Queryable().NoLock().First(x => x.BarCode == bcrCode && x.Status == TaskStatus.NewBuild);
if (task == null)
{
World.Log($"{bcrCode}:找不到匹配的任务", LogLevelEnum.High);
return;
}
var config1 = db.Queryable().NoLock().First(x => x.Code == $"{task.WarehouseCode}-Flow");
if (config1 == null)
{
config.Code = "4";
}
config = config1;
taskInfo = task;
});
if (taskInfo == null)
{
continue;
}
var srmCode = taskInfo.WarehouseCode.WarehouseToSrm();
var path = DevicePath.GetPath(obj.Entity.Code, srmCode);
if (path == null || path is { Points.Count: < 2 })
{
World.Log($"{bcrCode}:路径错误,当前位置{obj.Entity.Code},目标位置:{srmCode}", LogLevelEnum.High);
continue;
}
var next = path.Points[1].Code;
#region 计算应该去哪个分拣库
//应该要去的分拣库
if (taskInfo.WarehouseCode.Contains("N"))
{
next = config.SContent switch
{
"1" => "418",
"2" => "818",
"3" => "1218",
_ => next
};
}
else if (taskInfo.WarehouseCode.Contains("S"))
{
next = config.SContent switch
{
"1" => "618",
"2" => "1018",
"3" => "1418",
_ => next
};
}
#endregion 计算应该去哪个分拣库
if (taskInfo == null) continue;
//开始赋值
obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
.SetValue(obj.Data3, taskInfo.ID);
obj.Data3.GetType().GetProperty($"TaskNumber{obj.Data3.NextIndex}")
.SetValue(obj.Data3, taskInfo.ID);
obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
.SetValue(obj.Data3, next.ToShort());
obj.Data3.GetType().GetProperty($"GoodsEnd{obj.Data3.NextIndex}")
.SetValue(obj.Data3, next.ToShort());
obj.Data3.GetType().GetProperty($"BcrCode{obj.Data3.NextIndex}").SetValue(obj.Data3, bcrCode);
if (obj.Data3.NextIndex >= 49)
{
obj.Data3.NextIndex = 0;
}
else
{
obj.Data3.NextIndex++;
}
}
dev.Data.Mode = StationMode.Automatic;
}
catch (Exception e)
{
World.Log($"{e.Message}:---{e.StackTrace}", LogLevelEnum.High);
}
}
public override bool Select(Device dev)
{
var codes = new List();
if (WorkStart.WareHouses.Contains("FJ1")) codes.AddRange(new List() { "18", "118" });
if (WorkStart.WareHouses.Contains("FJ2")) codes.AddRange(new List() { "38", "58" });
if (WorkStart.WareHouses.Contains("FJ3")) codes.AddRange(new List() { "138", "158" });
return codes.Contains(dev.Code);
return false;
}
}
///
/// 主线分流
///
public class MainlineDiversion
{
///
/// 任务号
///
public int TaskId { get; set; }
///
/// 仓库号
///
public string WarehouseCode { get; set; }
}
///
/// 配置信息表
///
[Tenant("fj")]
[SugarTable("sys_config", "配置信息表")]
public class fjSysConfig : BaseModel
{
///
/// 编号
///
[SugarColumn(ColumnName = "code", Length = 100)]
public string Code { get; set; }
///
/// 名称
///
[SugarColumn(ColumnName = "name", Length = 100)]
public string Name { get; set; }
///
/// 内容
///
[SugarColumn(ColumnName = "scontent", Length = 100)]
public string SContent { get; set; }
///
/// 类型
///
[SugarColumn(ColumnName = "stype", Length = 50)]
public string SType { get; set; }
[SugarColumn(ColumnName = "default1", Length = 100, IsNullable = true)]
public string Default1 { get; set; }
[SugarColumn(ColumnName = "default2", Length = 100, IsNullable = true)]
public string Default2 { get; set; }
[SugarColumn(ColumnName = "default3", Length = 100, IsNullable = true)]
public string Default3 { get; set; }
}
///
/// 物料表
///
[Tenant("fj")]
[SugarTable("Base_MatInfo")]
public partial class BaseMatinfo : BaseModel
{
///
/// 仓库ID
///
[SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
public long WarehouseId { get; set; }
///
/// 编码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = false)]
public string Code { get; set; }
///
/// 名称
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = false)]
public string Name { get; set; }
///
/// 短描述
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string ShortDesc { get; set; }
///
/// 长描述
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 500, IsNullable = true)]
public string FullDesc { get; set; }
///
/// 补充描述
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 500, IsNullable = true)]
public string ExtDesc { get; set; }
///
/// 英文名
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string Enname { get; set; }
///
/// 组ID
///
[SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
public long MatGrpId { get; set; }
///
/// 叶类编码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string Leafcode { get; set; }
///
/// 叶类名称
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string LeafName { get; set; }
///
/// 中类编码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string MidCode { get; set; }
///
/// 中类名称
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string MidName { get; set; }
///
/// 大类编码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string HeadCode { get; set; }
///
/// 大类名称
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string HeadName { get; set; }
///
/// 规格型号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string Description { get; set; }
///
/// 材质
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string Texture { get; set; }
///
/// 图号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string FigureNo { get; set; }
///
/// 强度
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string Strength { get; set; }
///
/// 镀层
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string Plating { get; set; }
///
/// 镀层克重
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? PlatingWeight { get; set; }
///
/// 镀层主元素含量
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? PlatingContQty { get; set; }
///
/// 线密度
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? Linear { get; set; }
///
/// 产品号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string ProCode { get; set; }
///
/// 产品描述
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string ProName { get; set; }
///
/// 产品强度
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string ProStre { get; set; }
///
/// 线密度上限
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? LinearMax { get; set; }
///
/// 线密度下限
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? LinearMin { get; set; }
///
/// 线密度目标值
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? LinearTar { get; set; }
///
/// 单丝倍数
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? Mono { get; set; }
///
/// 工字轮型号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string SpoolType { get; set; }
///
/// 工字轮料号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string SpoolCode { get; set; }
///
/// 单卷长度
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? Length { get; set; }
///
/// 涂油量
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? OilQty { get; set; }
///
/// 润滑液种类
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string LubType { get; set; }
///
/// 排线间距
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? LineSpace { get; set; }
///
/// 线长度
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? LineLength { get; set; }
///
/// 捻向
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string LayDirect { get; set; }
///
/// 客户标准索引号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string CumIndex { get; set; }
///
/// 有无焊点
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string IsSolder { get; set; }
///
/// SKU号
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string SkuCode { get; set; }
///
/// SKU描述
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)]
public string SkuDesc { get; set; }
///
/// 控制扭转
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string Tors { get; set; }
///
/// 包装组ID
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string PackGrpId { get; set; }
///
/// 黑盘取样
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string BlackSamp { get; set; }
///
/// 黑盘检验
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string BlackChk { get; set; }
///
/// 客户编码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string CustCode { get; set; }
///
/// 客户描述
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string CustName { get; set; }
///
/// 收货地址编码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string AddressCode { get; set; }
///
/// 收货地址名称
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string AddressName { get; set; }
///
/// 生产批次数量(箱/批)
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? Qty { get; set; }
///
/// 每箱最大焊点盘数(个)
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? BoxMaxSolder { get; set; }
///
/// 工字轮最大焊点数(个)
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? SpoolMaxSolder { get; set; }
///
/// OVC比例
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? Ovc { get; set; }
///
/// 起鼓等级
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string DrummLevel { get; set; }
///
/// 公司代码
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
public string ComCode { get; set; }
///
/// 公司名称
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
public string ComName { get; set; }
///
/// 计量单位
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 10, IsNullable = true)]
public string CalcUnit { get; set; }
///
/// 库存单位
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 10, IsNullable = true)]
public string StockUnit { get; set; }
///
/// 单重
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
public decimal? Weight { get; set; }
///
/// 单重单位
///
[SugarColumn(ColumnDataType = "nvarchar", Length = 10, IsNullable = true)]
public string WeightUnit { get; set; }
///
/// 是否启用时效
///
[SugarColumn(ColumnDataType = "bit", IsNullable = false)]
public bool IsHold { get; set; }
///
/// 时效时长(小时)
///
[SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
public decimal HoldDuration { get; set; }
///
/// 超时时间-小时
///
[SugarColumn(ColumnDataType = "int", IsNullable = true)]
public int TimeOut { get; set; }
}
}