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.RGV;
using WCS.Entity.Protocol.Robot;
using WCS.Entity.Protocol.Station;
using WCS.Entity.Protocol.Truss;
using WCS.WorkEngineering.Extensions;
using WCS.WorkEngineering.Worlds;
using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
using TaskStatus = WCS.Entity.TaskStatus;
using TaskType = WCS.Entity.TaskType;

namespace WCS.WorkEngineering.Systems
{
    /// <summary>
    ///  RGV交互系统
    /// </summary>
    [BelongTo(typeof(RgvWorld))]
    [Description("RGV交互系统")]
    public class RGVSystems : DeviceSystem<Device<IRGV520, IRGV521, IBCR81>>
    {
        protected override bool ParallelDo => true;

        /// <summary>
        /// 取货点设备集合
        /// </summary>
        private readonly Dictionary<string, List<Device<IStation520, IStation521, IStation523>>> _pickUpDevices = new();

        public RGVSystems()
        {
            //获取所有的巷道集合
            var rgvList = Device.All.Where(v => v.HasFlag(DeviceFlags.RGV));
            foreach (var rgv in rgvList)
            {
                _pickUpDevices.Add(rgv.Code, rgv.Sources.Where(v => v.HasFlag(DeviceFlags.输送机)).Select(v => new Device<IStation520, IStation521, IStation523>(v, this.World)).ToList());
            }
        }

        public override void Do(Device<IRGV520, IRGV521, IBCR81> obj)
        {
            try
            {
                if (obj.Data.VoucherNo != obj.Data2.VoucherNo)
                {
                    World.Log($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}", LogLevelEnum.High);
                    return;
                }

                if (obj.Data2.WorkMode != RGVWorkMode.Automatic)
                {
                    World.Log(obj.Data2.WorkMode.GetDescription());
                    return;
                }
                //wcs任务完成确认信号未清除
                if (obj.Data.RES1 == 1)
                {
                    World.Log("wcs任务完成确认信号未清除");
                    return;
                }
                if (obj.Data2.Status.HasFlag(RGVStatus.Taskfinishi))
                {
                    switch (obj.Data2.CmdType)
                    {
                        case RGVCmdType.PickGoods: //单独取货任务完成,默认只有空托盘才会下发单独取货任务
                            World.Log($"任务处理:开始-取货完成-任务号[{obj.Data2.TaskNumber}]起始地址[{obj.Data2.StartPosition}]目标地址[{obj.Data2.DestPosition}]");
                            //开始申请读码信息
                            var bcrCode = obj.Data3.GetBCRCode();
                            if (bcrCode.IsNullOrWhiteSpace() || bcrCode.Contains(":"))
                            {
                                World.Log("扫码失败，内容为空", LogLevelEnum.Mid);
                                return;
                            }
                            World.Log($"任务处理:扫码结果-{bcrCode}");
                            var taskNumber = 0;
                            SqlSugarHelper.Do(_db =>
                            {
                                var db = _db.Default;

                                //检查库存表是否有残留库存信息
                                if (db.Queryable<BillInvnow>().Any(x => x.ContGrpBarCode == bcrCode))
                                {
                                    //删除库存
                                    var invNow = db.Queryable<BillInvnow>().Where(x => x.ContGrpBarCode == bcrCode).OrderByDescending(x => x.AddTime).First();

                                    if (invNow.IsTorsChk) //是一楼码垛入库
                                    {
                                        db.DeleteableRowLock(invNow).ExecuteCommand(); //删除库存

                                        var invInit = db.Queryable<BillInvinit>().Where(x => x.ContGrpBarCode == bcrCode).OrderByDescending(x => x.AddTime).First();
                                        db.DeleteableRowLock(invInit).ExecuteCommand();//删除条码

                                        var taskInfos = db.Queryable<WCS_TaskInfo>().Where(x => x.BarCode == bcrCode && x.Status == TaskStatus.NewBuild && x.BusType == "人工满托入库").ToList();
                                        foreach (var task in taskInfos)
                                        {
                                            //取消任务
                                            task.Status = TaskStatus.Cancel;
                                            task.ManualRemarks = "托盘已使用，需在二楼组盘";
                                            db.Updateable(task).ExecuteCommand();
                                            task.AddWCS_TASK_DTL(db, obj.Entity.Code, "", "取消任务");
                                        }
                                    }

                                    World.Log($"【{obj.Entity.Code}】上的托盘 【{bcrCode}】存在历史库存信息,请检查对应托盘条码是否存在未完成的出库任务！！！！！", LogLevelEnum.High);
                                    return;
                                }

                                var dev = Device.All.First(x => x.Code == obj.Data2.DestPosition.ToString());
                                if (dev.HasFlag(DeviceFlags.桁架码垛位))
                                {
                                    //开始绑定任务，并下发新的任务信息到小车
                                    var palletizingInfo = db.Queryable<WCS_Palletizing>().Single(x => x.Id == obj.Data2.TaskNumber);
                                    if (palletizingInfo == null)
                                    {
                                        World.Log($"未找到对应的码垛信息{obj.Data2.TaskNumber}", LogLevelEnum.Mid);
                                        return;
                                    }
                                    palletizingInfo.PalleCode = bcrCode;
                                    db.UpdateableRowLock(palletizingInfo).UpdateColumns(x => new { x.PalleCode }).ExecuteCommand();
                                    taskNumber = palletizingInfo.Id;
                                    World.Log($"任务处理:当前任务为桁架区域补空托任务");
                                }
                                else if (dev.HasFlag(DeviceFlags.环形库码垛工位))
                                {
                                    //开始处理对应的搬运任务信息
                                    var task = db.Queryable<WCS_TaskInfo>().UpdLock().First(x => x.Type == TaskType.Delivery && x.ID == obj.Data2.TaskNumber && x.AddrTo == obj.Data2.DestPosition.ToString());
                                    if (task == null)
                                    {
                                        World.Log($"未找到对应的搬运任务{obj.Data2.TaskNumber}", LogLevelEnum.Mid);
                                        return;
                                    }

                                    task.BarCode = bcrCode;
                                    db.UpdateableRowLock(task).UpdateColumns(x => new { x.BarCode }).ExecuteCommand();
                                    task.AddWCS_TASK_DTL(db, obj.Entity.Code, obj.Data2.DestPosition.ToString(), $"环形库码垛位{obj.Data2.DestPosition}搬运任务绑定条码信息{bcrCode}");
                                    taskNumber = task.ID;
                                    World.Log($"任务处理:当前任务为环形库区域补空托任务");
                                }
                                else //默认除了桁架码垛工位与环形库码垛工位外的任务就只有芯股用空托入库了
                                {
                                    //开始处理对应的入库任务信息
                                    var task = db.Queryable<WCS_TaskInfo>().UpdLock().First(x => x.Type == TaskType.EnterDepot && x.ID == obj.Data2.TaskNumber && x.AddrNext == obj.Data2.DestPosition.ToString());
                                    if (task == null)
                                    {
                                        World.Log($"未找到对应的空托入库任务{obj.Data2.TaskNumber}", LogLevelEnum.Mid);
                                        return;
                                    }

                                    task.BarCode = bcrCode;
                                    db.UpdateableRowLock(task).UpdateColumns(x => new { x.BarCode }).ExecuteCommand();
                                    task.AddWCS_TASK_DTL(db, obj.Entity.Code, obj.Data2.DestPosition.ToString(), $"空托入库任务绑定条码信息{bcrCode}");
                                    taskNumber = task.ID;
                                    World.Log($"任务处理:当前任务为芯股用空托入库");
                                }
                            });
                            if (taskNumber == 0)
                            {
                                World.Log($"取货完成处理失败", LogLevelEnum.Mid);
                                return;
                            }

                            //清空目标点信息
                            var destDev = new Device<IStation520>(Device.All.FirstOrDefault(x => x.Code == obj.Data2.DestPosition.ToString())!, World);
                            destDev.Data.TaskNumber = 0;
                            destDev.Data.GoodsStart = 0;
                            destDev.Data.GoodsEnd = 0;
                            obj.Data2.TaskNumber = taskNumber;
                            obj.Data.RES1 = 1;
                            World.Log($"任务处理:结束-取货完成-任务号[{obj.Data2.TaskNumber}]起始地址[{obj.Data2.StartPosition}]目标地址[{obj.Data2.DestPosition}]");
                            break;

                        case RGVCmdType.PutGoods:
                            Device destPosition = null;
                            bool isPalletizing = false;
                            try
                            {
                                World.Log($"任务处理:开始-放货完成-任务号[{obj.Data2.TaskNumber}]起始地址[{obj.Data2.StartPosition}]目标地址[{obj.Data2.DestPosition}]");
                                WCS_TaskInfo finishiTask = null;
                                var startPosition = Device.All.Where(x => x.Code == obj.Data2.StartPosition.ToString())
                                    .Select(x => new Device<IStation520, IStation521, IStation523>(x, World))
                                    .FirstOrDefault();
                                destPosition = Device.All.FirstOrDefault(x => x.Code == obj.Data2.DestPosition.ToString());
                                isPalletizing = destPosition!.HasFlag(DeviceFlags.桁架码垛位, DeviceFlags.环形库码垛工位);
                                short countQty = 0;
                                short shortCode = 0;
                                SqlSugarHelper.Do(_db =>
                                {
                                    var db = _db.Default;
                                    if (isPalletizing)
                                    {
                                        if (destPosition.HasFlag(DeviceFlags.桁架码垛位))
                                        {
                                            var palletizingInfo = db.Queryable<WCS_Palletizing>()
                                                .First(x => x.Id == obj.Data.TaskNumber);
                                            countQty = palletizingInfo.CountQty.ToShort();
                                            shortCode = palletizingInfo.ShortCode;
                                            World.Log($"任务处理:当前任务为桁架区域补空托任务");
                                        }
                                        else if (destPosition.HasFlag(DeviceFlags.环形库码垛工位))
                                        {
                                            var deliveryTask = db.Queryable<WCS_TaskInfo>().UpdLock()
                                                .First(x => x.ID == obj.Data.TaskNumber);
                                            countQty = deliveryTask.FullQty;
                                            shortCode = deliveryTask.PalletType;
                                            deliveryTask.Status = TaskStatus.RgvCompleted;
                                            deliveryTask.EditTime = DateTime.Now;
                                            deliveryTask.LastInteractionPoint = obj.Entity.Code;
                                            db.Updateable(deliveryTask).UpdateColumns(x => new { x.Status, x.EditTime, x.LastInteractionPoint }).ExecuteCommand();
                                            deliveryTask.AddWCS_TASK_DTL(db, deliveryTask.AddrTo, $"RGV任务执行结束");
                                            World.Log($"任务处理:当前任务为环形库区域补空托任务");
                                        }
                                    }
                                    else
                                    {
                                        var taskInfo = db.Queryable<WCS_TaskInfo>().UpdLock().First(x => x.ID == obj.Data.TaskNumber);
                                        taskInfo.Status = TaskStatus.RgvCompleted;
                                        taskInfo.EditTime = DateTime.Now;
                                        taskInfo.LastInteractionPoint = obj.Entity.Code;
                                        db.Updateable(taskInfo).UpdateColumns(x => new { x.Status, x.EditTime, x.LastInteractionPoint }).ExecuteCommand();
                                        taskInfo.AddWCS_TASK_DTL(db, taskInfo.AddrTo, $"RGV任务执行结束");
                                        World.Log($"任务处理:当前任务为芯股用空托入库");
                                    }
                                });

                                if (startPosition.Data.TaskNumber == obj.Data.TaskNumber) //初始化起始点信息
                                {
                                    startPosition.Data.TaskNumber = 0;
                                    startPosition.Data.GoodsEnd = 0;
                                    World.Log($"任务处理:初始化取货点{startPosition.Entity.Code}任务及目标地址信息");
                                }

                                //目标地址是码垛工位
                                if (isPalletizing)
                                {
                                    if (destPosition.HasFlag(DeviceFlags.桁架码垛位))
                                    {
                                        var dest = new Device<ITruss530, ITruss531>(destPosition!, World);
                                        if (dest.Data2.MaxQuantity == 0)
                                        {
                                            dest.Data.MaxQuantity = countQty;
                                            dest.Data.Quantity = 0;
                                            dest.Data.Type = shortCode;
                                            dest.Data.VoucherNo++;
                                            World.Log($"任务处理:写入码垛信息-码垛位[{dest.Entity.Code}]最大码垛数量[{dest.Data.MaxQuantity}]已码数量[{dest.Data.Quantity}]垛形[{dest.Data.Type}]凭证号[{dest.Data.VoucherNo}]");
                                        }
                                        else
                                        {
                                            World.Log($"桁架垛型信息未清除，无法写入新垛型信息请检查确认，最大码垛数量[{dest.Data.MaxQuantity}]已码数量[{dest.Data.Quantity}]垛形[{dest.Data.Type}]凭证号[{dest.Data.VoucherNo}]", LogLevelEnum.Mid);
                                            return;
                                        }
                                    }
                                    else if (destPosition.HasFlag(DeviceFlags.环形库码垛工位))
                                    {
                                        var dest = new Device<IRobot530>(destPosition!, World);
                                        dest.Data.MaxQuantity = countQty;
                                        dest.Data.Type = shortCode;
                                        dest.Data.VoucherNo++;
                                        World.Log($"任务处理:写入码垛信息-码垛位[{dest.Entity.Code}]最大码垛数量[{dest.Data.MaxQuantity}]垛形[{dest.Data.Type}]凭证号[{dest.Data.VoucherNo}]");
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                World.Log($"处理小车放货完成是出现错误:{e.Message}-{e.StackTrace}");
                                return;
                            }
                            obj.Data.RES1 = 1;
                            World.Log($"任务处理:结束-放货完成-任务号[{obj.Data2.TaskNumber}]起始地址[{obj.Data2.StartPosition}]目标地址[{obj.Data2.DestPosition}]");
                            break;

                        case RGVCmdType.Move:
                            World.Log($"任务处理:开始-移动完成-任务号[{obj.Data2.TaskNumber}]目标地址[{obj.Data2.DestPosition}]");
                            obj.Data.RES1 = 1;
                            World.Log($"任务处理:结束-移动完成-任务号[{obj.Data2.TaskNumber}]目标地址[{obj.Data2.DestPosition}]");
                            break;

                        case RGVCmdType.ChangePutGoods:
                            break;

                        case RGVCmdType.ChangePickGoods:
                            break;

                        case RGVCmdType.PickPutGoods:
                            World.Log($"任务处理:开始-取放货完成-任务号[{obj.Data2.TaskNumber}]起始地址[{obj.Data2.StartPosition}]目标地址[{obj.Data2.DestPosition}]");
                            var statDev = Device.All.FirstOrDefault(x => x.Code == obj.Data.StartPosition.ToString());

                            var stDev = new Device<IStation520, IStation521>(Device.All.FirstOrDefault(x => x.Code == obj.Data.StartPosition.ToString())!, World);
                            stDev.Data.TaskNumber = 0;
                            stDev.Data.GoodsStart = 0;
                            stDev.Data.GoodsEnd = 0;
                            World.Log($"任务处理:清除目标地址信息-目标货位{stDev.Entity.Code}");

                            obj.Data.RES1 = 1;
                            World.Log($"任务处理:结束-取放货完成-任务号[{obj.Data2.TaskNumber}]起始地址[{obj.Data2.StartPosition}]目标地址[{obj.Data2.DestPosition}]");
                            break;

                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                    return;
                }

                if (obj.Data2.SystemStatus != RGVSystemStatus.空闲)
                {
                    World.Log(obj.Data2.SystemStatus.GetDescription());
                    return;
                }

                if (obj.Data2.Status.HasFlag(RGVStatus.RES1)) //离开非安全区域
                {
                    World.Log($"任务处理:开始-下发移动任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                    obj.Data.TaskNumber = obj.Data.TaskNumber;
                    obj.Data.CmdType = RGVCmdType.Move;
                    obj.Data.DestPosition = obj.Entity.Code switch
                    {
                        "RGV1" => 1668,
                        "RGV2" => 1683,
                        "RGV3" => 1698,
                        "RGV4" => 1713,
                        "RGV5" => 1728,
                        "RGV6" => 1743,
                        _ => throw new ArgumentOutOfRangeException()
                    };
                    obj.Data.VoucherNo++;
                    World.Log($"任务处理:结束-下发移动任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                    return;
                }

                if (obj.Data2.CmdType == RGVCmdType.PickGoods && !obj.Data2.Status.HasFlag(RGVStatus.Taskfinishi))
                {
                    if (obj.Data2.Status.HasFlag(RGVStatus.PH_Status))
                    {
                        World.Log($"任务处理:开始-下发放货任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]起始地址[{obj.Data.StartPosition}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                        obj.Data.TaskNumber = obj.Data.TaskNumber;
                        obj.Data.CmdType = RGVCmdType.PutGoods;
                        obj.Data.StartPosition = obj.Data2.StartPosition;
                        obj.Data.DestPosition = obj.Data2.DestPosition;
                        obj.Data.VoucherNo++;
                        World.Log($"任务处理:结束-下发放货任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]起始地址[{obj.Data.StartPosition}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                        return;
                    }
                }
                var pickUpDevices = _pickUpDevices.FirstOrDefault(x => x.Key == obj.Entity.Code).Value;

                //有货且需要搬运货物的站台
                var devs = pickUpDevices.Where(v => v.Data3.Status.HasFlag(StationStatus.PH_Status) && v.Data.TaskNumber != 0)
                                                      .Where(v => v.Entity.Code.ToShort() != v.Data.GoodsEnd && v.Data.GoodsEnd != 0)
                                                      .ToList();
                //筛选出目标站台无货的站台
                var putDev = obj.Entity.Targets.Where(x => x.HasFlag(DeviceFlags.输送机))
                    .Select(x => new Device<IStation520, IStation521, IStation523>(x, World))
                    .Where(x => !x.Data3.Status.HasFlag(StationStatus.PH_Status))
                    .Where(x => !x.Data3.Status.HasFlag(StationStatus.OT_Status))
                    .Select(x => x.Entity.Code.ToShort());
                //var devList = devs.OrderBy(x => x.Entity.Code).Where(x => putDev.Contains(x.Data.GoodsEnd));
                var devList = devs.OrderBy(x => x.Data.TaskNumber).Where(x => putDev.Contains(x.Data.GoodsEnd));

                if (!devList.Any())
                {
                    World.Log($"无可用任务");
                }

                foreach (var dev in devList)
                {
                    //区分任务是拆盘机到码垛工位，还是码垛工位到拆盘机
                    if (dev.Entity.HasFlag(DeviceFlags.拆盘机))
                    {
                        World.Log($"任务处理:开始-下发取货任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]RGV运行状态[{obj.Data2.WorkMode.GetDescription()}]起始地址[{obj.Data.StartPosition}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                        obj.Data.TaskNumber = dev.Data.TaskNumber;
                        obj.Data.CmdType = RGVCmdType.PickGoods;
                        obj.Data.StartPosition = dev.Entity.Code.ToShort();
                        obj.Data.DestPosition = dev.Data.GoodsEnd;
                        obj.Data.VoucherNo++;
                        World.Log($"任务处理:结束-下发取货任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]起始地址[{obj.Data.StartPosition}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                        return;
                    }

                    //if (dev.Entity.HasFlag(DeviceFlags.二次码垛RGV取货口))
                    //{
                    //    obj.Data.TaskNumber = dev.Data.TaskNumber;
                    //    obj.Data.CmdType = RGVCmdType.PickPutGoods;
                    //    obj.Data.StartPosition = dev.Entity.Code.ToShort();
                    //    obj.Data.DestPosition = dev.Data.GoodsEnd;
                    //    obj.Data.VoucherNo++;
                    //    return;
                    //}

                    World.Log($"任务处理:开始-下发满托入库任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]RGV运行状态[{obj.Data2.WorkMode.GetDescription()}]起始地址[{obj.Data.StartPosition}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                    //非拆盘机起始任务
                    //站台中的任务号
                    WCS_TaskInfo task = null;
                    SqlSugarHelper.Do(_db =>
                    {
                        var db = _db.Default;
                        var taskInfo = db.Queryable<WCS_TaskInfo>().First(p => p.ID == dev.Data.TaskNumber && p.Status == TaskStatus.ConveyorExecution);
                        if (taskInfo == null)
                        {
                            World.Log($"任务处理:未找到对应的任务{dev.Entity.Code}--{dev.Data.TaskNumber}-1");
                            return;
                        }

                        taskInfo.Status = TaskStatus.RgvExecution;
                        taskInfo.AddrNext = obj.Entity.Code;
                        taskInfo.EditWho = "WCS";
                        taskInfo.EditTime = DateTime.Now; ;
                        db.UpdateableRowLock(taskInfo).UpdateColumns(x => new { x.Status, x.AddrNext, x.EditWho, x.EditTime }).ExecuteCommand();
                        taskInfo.AddWCS_TASK_DTL(db, dev.Entity.Code, obj.Entity.Code, $"任务分配至{obj.Entity.Code}");
                        task = taskInfo;
                    });
                    if (task == null)
                    {
                        World.Log($"任务处理:未找到对应的任务{dev.Entity.Code}--{dev.Data.TaskNumber}-2");
                        return;
                    }
                    World.Log($"任务处理:满托入库业务流程处理完成-任务[{task.ID}]状态已变更为[{task.Status}]开始准备写入PLC");
                    obj.Data.TaskNumber = task.ID;
                    obj.Data.CmdType = RGVCmdType.PickPutGoods;
                    obj.Data.StartPosition = dev.Entity.Code.ToShort();
                    obj.Data.DestPosition = dev.Data.GoodsEnd;
                    obj.Data.VoucherNo++;
                    World.Log($"任务处理:结束-下发满托入库任务-任务号[{obj.Data.TaskNumber}]任务类型[{obj.Data.CmdType}]起始地址[{obj.Data.StartPosition}]目标地址[{obj.Data.DestPosition}]凭证号[{obj.Data.VoucherNo}]");
                    return;
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Destination array was not long enough. Check the destination index, length, and the array's lower bounds")
                {
                    World.Log($"未知异常:{ex.StackTrace}");
                }
                else if (ex.Message == "Number was less than the array's lower bound in the first dimension")
                {
                    World.Log($"未知异常:{ex.StackTrace}");
                }
                else throw new KnownException(ex.Message, LogLevelEnum.Mid);
            }
        }

        public override bool Select(Device dev)
        {
            return dev.Code is "RGV1" or "RGV2" or "RGV3" or "RGV4" or "RGV5" or "RGV6";
            //return dev.HasFlag(Extensions.DeviceFlags.RGV);
        }
    }

    /// <summary>
    ///  库存表
    /// </summary>
    [SugarTable("Bill_InvNow")]
    public partial class BillInvnow : BaseModel
    {
        /// <summary>
        ///  仓库ID 关联仓库表 ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long WarehouseId { get; set; }

        /// <summary>
        ///  组盘ID
        ///  创建库存的时候 获取条码表ContGrpId
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long ContGrpId { get; set; }

        /// <summary>
        ///  容器条码 同联容器表容器条码 ContBarCode
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ContGrpBarCode { get; set; }

        /// <summary>
        /// 组盘类型(1物料盘 2空盘)
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public FJContGrpType ContGrpType { get; set; }

        /// <summary>
        ///  箱条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BoxBarCode { get; set; }

        /// <summary>
        ///  Bom单号 关联投料单 帘线工序工单号 BillCode
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BomDocsNo { get; set; }

        /// <summary>
        ///  Bom物料ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long BomMatId { get; set; }

        /// <summary>
        ///  Bom物料编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BomMatCode { get; set; }

        /// <summary>
        ///  Bom物料
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
        public string BomMatName { get; set; }

        /// <summary>
        ///  垛形主表 ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long BomSetId { get; set; }

        /// <summary>
        ///  垛型编码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
        public string SetGrpCode { get; set; }

        /// <summary>
        ///  库存状态码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecStateCode { get; set; }

        /// <summary>
        /// 单据编号 关联单据表单据编号 DocsNo
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecDocsNo { get; set; }

        /// <summary>
        ///  单据行号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecDocsRowNo { get; set; }

        /// <summary>
        ///  单据类型编号 同单据表TypeNum
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecDocsTypeCode { get; set; }

        /// <summary>
        ///  出入库标识
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public FJInvInOutType InvInOut { get; set; }

        /// <summary>
        ///  执行人
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecWho { get; set; }

        /// <summary>
        ///  执行时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime ExecTime { get; set; }

        /// <summary>
        ///  行
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int PutRow { get; set; }

        /// <summary>
        ///  列
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int PutCol { get; set; }

        /// <summary>
        ///  层
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int PutLayer { get; set; }

        /// <summary>
        ///  入库条码号 FJ材料号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InvBarCode { get; set; }

        /// <summary>
        ///  库存状态
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InvStateCode { get; set; }

        /// <summary>
        ///  入库单号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InDocsNo { get; set; }

        /// <summary>
        ///  入库单行号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InDocsRowNo { get; set; }

        /// <summary>
        ///  供应编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string SuppCode { get; set; }

        /// <summary>
        ///  供应商名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string SuppName { get; set; }

        /// <summary>
        ///  海关编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string CustCode { get; set; }

        /// <summary>
        ///  海关名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string CustName { get; set; }

        /// <summary>
        ///  物料ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long MatId { get; set; }

        /// <summary>
        ///  物料编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string MatCode { get; set; }

        /// <summary>
        ///  物料名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
        public string MatName { get; set; }

        /// <summary>
        ///  总重量
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal TolWQty { get; set; }

        /// <summary>
        ///  净重
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal NetWQty { get; set; }

        /// <summary>
        ///  皮重
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal TareWQty { get; set; }

        /// <summary>
        ///  总长
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal LengthQty { get; set; }

        /// <summary>
        ///  碳当量
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal CaQty { get; set; }

        /// <summary>
        ///  销售总量
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal SolderQty { get; set; }

        /// <summary>
        ///  暂定
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int ContUsageQty { get; set; }

        /// <summary>
        ///  批次号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BatchNo { get; set; }

        /// <summary>
        ///  生产时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime ProductTime { get; set; }

        /// <summary>
        ///  第一次入库时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime OneInTime { get; set; }

        /// <summary>
        ///  盘条条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string RodBarCode { get; set; }

        /// <summary>
        ///  工字轮条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string HWBarCode { get; set; }

        /// <summary>
        ///  RFID条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string RFIDBarCode { get; set; }

        /// <summary>
        ///  材料号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string CLBarCode { get; set; }

        /// <summary>
        ///  工字轮条码类型
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string HWTypeCode { get; set; }

        /// <summary>
        ///  炉号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BoilerNo { get; set; }

        /// <summary>
        ///  包号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string PackNo { get; set; }

        /// <summary>
        ///  牌号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BrandNo { get; set; }

        /// <summary>
        ///  执行标准
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecStd { get; set; }

        /// <summary>
        ///  许可证号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string LicenceCode { get; set; }

        /// <summary>
        ///  改手盘标记
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsSurplus { get; set; }

        /// <summary>
        ///  返工标记
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsRework { get; set; }

        /// <summary>
        ///  是否黑盘
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsBlack { get; set; }

        /// <summary>
        ///  是否芯股
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsCore { get; set; }

        /// <summary>
        ///  快投标记
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsFast { get; set; }

        /// <summary>
        ///  是否异常
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsFail { get; set; }

        /// <summary>
        ///  异常原因
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)]
        public string FailReason { get; set; }

        /// <summary>
        ///  单/双丝
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string SilkTypeCode { get; set; }

        /// <summary>
        ///  等级
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string Grade { get; set; }

        /// <summary>
        ///  是否退料
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsBack { get; set; }

        /// <summary>
        ///  退料原因
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)]
        public string BackReason { get; set; }

        /// <summary>
        ///  是否扭转检测
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsTorsChk { get; set; }

        /// <summary>
        ///  扭转次数
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int TorsChkQty { get; set; }

        /// <summary>
        ///  扭转检测时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime TorsChkTime { get; set; }

        /// <summary>
        /// 正反面
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = true, ColumnDescription = "正反面")]
        public int SideNum { get; set; }

        /// <summary>
        ///  扭转检测结果值
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
        public decimal? TorsChkValue { get; set; }

        /// <summary>
        ///  扭转检测设备号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string TorsChkMachCode { get; set; }

        /// <summary>
        ///  工序订单号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ProcessDocsCode { get; set; }

        /// <summary>
        ///  生产机台号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ProductMachCode { get; set; }

        /// <summary>
        ///  生成产线号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ProductLineNo { get; set; }

        /// <summary>
        /// 货物大小
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public int Size { get; set; }

        /// <summary>
        ///  托盘类型
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "托盘类型")]
        public FJPalletType PalletType { get; set; }

        /// <summary>
        ///  需要二次码垛的物料
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "循环码垛物料")]
        public bool Secondary { get; set; }
    }

    /// <summary>
    ///  条码表
    /// </summary>
    [SugarTable("Bill_InvInit")]
    public partial class BillInvinit : BaseModel
    {
        /// <summary>
        ///  仓库ID 关联仓库表 ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long WarehouseId { get; set; }

        /// <summary>
        ///  组盘ID
        ///  创建条码表时生成 同库存表组盘ID ContGrpId
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long ContGrpId { get; set; }

        /// <summary>
        ///  容器条码 同联容器表容器条码 ContBarCode
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ContGrpBarCode { get; set; }

        /// <summary>
        ///  箱条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BoxBarCode { get; set; }

        /// <summary>
        ///  Bom单号 关联投料单 帘线工序工单号 BillCode
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BomDocsNo { get; set; }

        /// <summary>
        ///  Bom物料ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long BomMatId { get; set; }

        /// <summary>
        ///  Bom物料编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BomMatCode { get; set; }

        /// <summary>
        ///  Bom物料
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
        public string BomMatName { get; set; }

        /// <summary>
        ///  垛形主表 ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long BomSetId { get; set; }

        /// <summary>
        ///  垛型编码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
        public string SetGrpCode { get; set; }

        /// <summary>
        ///  库存状态码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecStateCode { get; set; }

        /// <summary>
        ///  单据编号 关联单据表单据编号 DocsNo
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecDocsNo { get; set; }

        /// <summary>
        ///  单据行号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecDocsRowNo { get; set; }

        /// <summary>
        ///  单据类型编号 同单据表TypeNum
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecDocsTypeCode { get; set; }

        /// <summary>
        ///  出入库标识
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public FJInvInOutType InvInOut { get; set; }

        /// <summary>
        ///  执行人
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecWho { get; set; }

        /// <summary>
        ///  执行时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime ExecTime { get; set; }

        /// <summary>
        ///  行
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int PutRow { get; set; }

        /// <summary>
        ///  列
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int PutCol { get; set; }

        /// <summary>
        ///  层
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int PutLayer { get; set; }

        /// <summary>
        ///  入库条码号 FJ材料号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InvBarCode { get; set; }

        /// <summary>
        ///  库存状态
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InvStateCode { get; set; }

        /// <summary>
        ///  入库单号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InDocsNo { get; set; }

        /// <summary>
        ///  入库单行号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string InDocsRowNo { get; set; }

        /// <summary>
        ///  供应编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string SuppCode { get; set; }

        /// <summary>
        ///  供应商名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string SuppName { get; set; }

        /// <summary>
        ///  海关编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string CustCode { get; set; }

        /// <summary>
        ///  海关名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string CustName { get; set; }

        /// <summary>
        ///  物料ID
        /// </summary>
        [SugarColumn(ColumnDataType = "bigint", IsNullable = false)]
        public long MatId { get; set; }

        /// <summary>
        ///  物料编号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string MatCode { get; set; }

        /// <summary>
        ///  物料名称
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 100, IsNullable = true)]
        public string MatName { get; set; }

        /// <summary>
        ///  总重量
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal TolWQty { get; set; }

        /// <summary>
        ///  净重
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal NetWQty { get; set; }

        /// <summary>
        ///  皮重
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal TareWQty { get; set; }

        /// <summary>
        ///  总长
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal LengthQty { get; set; }

        /// <summary>
        ///  碳当量
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal CaQty { get; set; }

        /// <summary>
        ///  销售总量
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = false)]
        public decimal SolderQty { get; set; }

        /// <summary>
        ///  暂定
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int ContUsageQty { get; set; }

        /// <summary>
        ///  批次号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BatchNo { get; set; }

        /// <summary>
        ///  生产时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime ProductTime { get; set; }

        /// <summary>
        ///  第一次入库时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime OneInTime { get; set; }

        /// <summary>
        ///  盘条条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string RodBarCode { get; set; }

        /// <summary>
        ///  工字轮条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string HWBarCode { get; set; }

        /// <summary>
        ///  RFID条码
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string RFIDBarCode { get; set; }

        /// <summary>
        /// 材料号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string CLBarCode { get; set; }

        /// <summary>
        ///  工字轮条码类型
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string HWTypeCode { get; set; }

        /// <summary>
        ///  炉号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BoilerNo { get; set; }

        /// <summary>
        ///  包号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string PackNo { get; set; }

        /// <summary>
        ///  牌号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string BrandNo { get; set; }

        /// <summary>
        ///  执行标准
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ExecStd { get; set; }

        /// <summary>
        ///  许可证号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string LicenceCode { get; set; }

        /// <summary>
        ///  改手盘标记
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsSurplus { get; set; }

        /// <summary>
        ///  返工标记
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsRework { get; set; }

        /// <summary>
        ///  是否黑盘
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsBlack { get; set; }

        /// <summary>
        ///  是否芯股
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsCore { get; set; }

        /// <summary>
        ///  快投标记
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsFast { get; set; }

        /// <summary>
        ///  是否异常
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsFail { get; set; }

        /// <summary>
        ///  异常原因
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)]
        public string FailReason { get; set; }

        /// <summary>
        /// 单/双丝
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string SilkTypeCode { get; set; }

        /// <summary>
        ///  等级
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string Grade { get; set; }

        /// <summary>
        ///  是否退料
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsBack { get; set; }

        /// <summary>
        ///  退料原因
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 200, IsNullable = true)]
        public string BackReason { get; set; }

        /// <summary>
        ///  是否扭转检测
        /// </summary>
        [SugarColumn(ColumnDataType = "bit", IsNullable = false)]
        public bool IsTorsChk { get; set; }

        /// <summary>
        ///  扭转次数
        /// </summary>
        [SugarColumn(ColumnDataType = "int", IsNullable = false)]
        public int TorsChkQty { get; set; }

        /// <summary>
        ///  扭转检测时间
        /// </summary>
        [SugarColumn(ColumnDataType = "datetime", IsNullable = false)]
        public DateTime TorsChkTime { get; set; }

        /// <summary>
        ///  扭转检测结果值
        /// </summary>
        [SugarColumn(ColumnDataType = "decimal", Length = 18, IsNullable = true)]
        public decimal? TorsChkValue { get; set; }

        /// <summary>
        ///  扭转检测设备号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string TorsChkMachCode { get; set; }

        /// <summary>
        ///  工序订单号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ProcessDocsCode { get; set; }

        /// <summary>
        ///  生产机台号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ProductMachCode { get; set; }

        /// <summary>
        ///  生成产线号
        /// </summary>
        [SugarColumn(ColumnDataType = "nvarchar", Length = 50, IsNullable = true)]
        public string ProductLineNo { get; set; }

        /// <summary>
        /// 货物大小
        /// </summary>
        [SugarColumn(IsNullable = false)]
        public int Size { get; set; }

        /// <summary>
        ///  托盘类型
        /// </summary>
        [SugarColumn(IsNullable = true, ColumnDescription = "托盘类型")]
        public FJPalletType PalletType { get; set; }

        /// <summary>
        /// 组盘类型
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public FJContGrpType ContGrpType { get; set; }
    }

    /// <summary>
    ///  基础表实体
    /// </summary>
    public class BaseModel
    {
        public BaseModel()
        { }

        /// <summary>
        ///  ID
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, ColumnDescription = "ID")]
        public virtual long Id { get; set; }

        /// <summary>
        ///  备注
        /// </summary>
        [SugarColumn(ColumnName = "Memo", Length = 500, IsNullable = true, ColumnDataType = "nvarchar", DefaultValue = "", ColumnDescription = "备注")]
        public virtual string Memo { get; set; }

        /// <summary>
        ///  创建用户
        /// </summary>
        [SugarColumn(ColumnName = "AddWho", Length = 50, ColumnDataType = "nvarchar", DefaultValue = "", IsNullable = false, ColumnDescription = "创建用户")]
        public virtual string AddWho { get; set; } = "";

        /// <summary>
        ///  更新用户
        /// </summary>
        [SugarColumn(ColumnName = "EditWho", Length = 50, ColumnDataType = "nvarchar", DefaultValue = "", IsNullable = false, ColumnDescription = "更新用户")]
        public virtual string EditWho { get; set; } = "";

        /// <summary>
        ///  创建时间
        /// </summary>
        [SugarColumn(ColumnName = "AddTime", DefaultValue = "1900-1-1", IsNullable = false, ColumnDescription = "创建时间")]
        public virtual DateTime AddTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        [SugarColumn(ColumnName = "EditTime", DefaultValue = "1900-1-1", IsNullable = false, ColumnDescription = "更新时间")]
        public virtual DateTime EditTime { get; set; } = DateTime.Now;
    }

    /// <summary>
    ///  组盘类型
    /// </summary>
    public enum FJContGrpType
    {
        /// <summary>
        ///  物料盘
        /// </summary>
        [Description("物料盘")]
        Material = 1,

        /// <summary>
        ///  空盘
        /// </summary>
        [Description("空盘")]
        EmptyCon = 2,
    }

    /// <summary>
    ///  托盘类型
    /// </summary>
    public enum FJPalletType
    {
        /// <summary>
        ///  09使用的托盘
        /// </summary>
        [Description("09使用的托盘")]
        Pallet09 = 1,

        /// <summary>
        ///  非09使用的托盘
        /// </summary>
        [Description("非09使用的托盘")]
        PalletNo09 = 2,
    }

    /// <summary>
    ///  出入库类型
    /// </summary>
    public enum FJInvInOutType
    {
        /// <summary>
        ///  默认
        /// </summary>
        [Description("默认")]
        Default = 0,

        /// <summary>
        /// 入库
        /// </summary>
        [Description("入库")]
        In = 1,

        /// <summary>
        /// 出库
        /// </summary>
        [Description("出库")]
        Out = 2,
    }
}