wxw
2024-08-13 a3236b51b5691b8c47f4ebaf1d885314a4bab3bd
拼箱功能开发
7个文件已修改
1个文件已添加
2697 ■■■■■ 已修改文件
Pda/View/HouseDataSetting/lingXiangUnbind.html 169 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/Model/ModelVm/PdaVm/PdaCrVm.cs 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs 2386 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/WMS.IBLL/IPdaServer/IPdaAsnServer.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/WMS.IBLL/IPdaServer/IPdaCrServer.cs 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/Wms/Controllers/PdaAsnController.cs 9 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Wms/Wms/Controllers/PdaCrController.cs 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Pda/View/HouseDataSetting/lingXiangUnbind.html
New file
@@ -0,0 +1,169 @@
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="user-scalable=0,width=device-width,initial-scale=1.0" />
        <!-- <meta name="viewport" content="width=device-width, initial-scale=0.665, minimum-scale=0.5, maximum-scale=2.0, user-scalable=no" /> -->
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Boxline PDA</title>
        <link rel="stylesheet" href="/layui/css/layui.css" />
        <link rel="stylesheet" href="/css/style.css" />
        <script src="/js/adaptive.js"></script>
        <link rel="stylesheet" href="/css/my.css" />
        <link rel="stylesheet" href="/css/adapter.css" />
        <style type="text/css">
            .layout-bill-info {
                height: 255px;
            }
            .layout-tbl-submit {
                margin-top: 10px;
            }
        </style>
    </head>
    <body>
        <div id="" class="main-content">
            <div id="" class="layout-title">
                <table border="" cellspacing="" cellpadding="">
                    <tr>
                        <td class="img-back"><a href="../index.html"><img src="/assets/back.jpg" ></a></td>
                        <td class="title-text">零箱解绑</td>
                        <td class="title-menu-icon"><img id="menuImg" src="/assets/menu.jpg" ></td>
                    </tr>
                </table>
            </div>
            <div id="" class="layout-sub-content">
                <div id="menuList" class="menu">
                    <ul class="" style="text-align: center;">
                        <li><a href="../index.html">主页</a></li>
                        <!-- <li><a href="productEnterConfirm.html">入库信息确认</a></li> -->
                        <li><a href="../login.html">重新登录</a></li>
                    </ul>
                </div>
                <div id="" class="layout-bill-info">
                    <form class="layui-form" action="">
                        <div id="layout-boxcode" class="layui-form-item layout-input">
                            <label class="layui-form-label">托盘条码:</label>
                            <div class="layui-input-block">
                                <input id="PalletNo" type="text" lay-verify="required" placeholder="请扫描托盘条码"
                                    autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div id="BOX" class="layui-form-item layout-input">
                            <label class="layui-form-label" lang>外箱条码:</label>
                            <div class="layui-input-block">
                                <input id="BOXCODE" type="text" lay-verify="required" lang langholder
                                    placeholder="请扫描外箱条码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <table class="layout-tbl-submit" border="" cellspacing="" cellpadding="">
                            <tr>
                                <td style="width: 23%;"></td>
                                <td>
                                    <button class="layout-btn layout-btn-red" lang type="button" lay-submit
                                        lay-filter="formUnbind">解绑</button>
                                </td>
                                <td style="width: 33%;"></td>
                            </tr>
                        </table>
                    </form>
                </div>
            </div>
        </div>
        <script src="/js/jquery-3.5.1.min.js"></script>
        <script src="/layui/layui.js"></script>
        <script src="/js/public.js"></script>
        <script src="/js/jquery.cookie.js"></script>
        <script>
            layui.use(['form', 'jquery'], function() {
                var form = layui.form
                $("#menuImg").click(function(e){
                    //console.log("menuImg")
                    e.stopPropagation()
                    if($("#menuList").is(":hidden")){
                        $("#menuList").show()
                    }else{
                        $("#menuList").hide()
                    }
                })
                $('body').click(function(){
                    // //console.log("body")
                    $("#menuList").hide()
                })
                //当托盘条码输入框失去焦点时,检查一下托盘状态
                $("#PalletNo").on('input',function(){
                    if($("#PalletNo").val() == "" || $("#PalletNo").val().length<10){
                        return
                    }
                    if ($("#PalletNo").val().length>=10) {
                        $("#PalletNo").val($("#PalletNo").val().substr(-10))
                    }
                })
                var isChongFu = true;
                form.on('submit(formUnbind)', function(data) {
                    if (!$("#PalletNo").val()) {
                        layer.msg('请扫描托盘条码', {
                            icon: 2,
                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        });
                        return;
                    }
                    if (!$("#BOXCODE").val()) {
                        layer.msg('请扫描外箱条码', {
                            icon: 2,
                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        });
                        return;
                    }
                    if (isChongFu == true) {
                        isChongFu = false;
                        var param = {
                            "PalletNo": $("#PalletNo").val(),
                            "BoxNo": $("#BOXCODE").val(),
                        }
                        sendData(IP + "/PdaCr/LingxingUnbind", param, 'post', function(res) {
                            if (res.code == 0) { //成功
                                layer.msg("解绑成功", {
                                    icon: 1,
                                    time: 2000 //2秒关闭(如果不配置,默认是3秒)
                                }, function () {
                                    tableData = null
                                    $("#PalletNo").val('')
                                    $("#BOXCODE").val('')
                                    isChongFu = true;
                                });
                            } else { //不成功
                                layer.msg(res.msg, {
                                    icon: 2,
                                    time: 2000 //2秒关闭(如果不配置,默认是3秒)
                                }, function() {isChongFu = true;});
                            }
                        });
                        return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
                    }else{
                        layer.msg("请勿重复点击", {
                            icon: 2,
                            time: 2000 //2秒关闭(如果不配置,默认是3秒)
                        });
                    }
                });
                // form.verify({
                //     stock: [/^[\S]{6}$/, '托盘条码必须为六位字符']
                // });
            })
        </script>
    </body>
</html>
Wms/Model/ModelVm/PdaVm/PdaCrVm.cs
@@ -69,4 +69,10 @@
        /// </summary>
        public string Ruku { get; set; }
    }
    public class PdaPalletUnBindVm
    {
        public string PalletNo { get; set; }
        public string BoxNo { get; set; }
    }
}
Wms/WMS.BLL/BllPdaServer/PdaAsnServer.cs
@@ -261,7 +261,7 @@
                {
                    throw new Exception("当前单号存在异常!");
                }
                return notice;
            }
@@ -310,14 +310,14 @@
                {
                    throw new Exception("空托盘数量不可为空");
                }
                var stockDetail = Db.Queryable<DataStockDetail>().Where(m=>m.IsDel == "0" && m.PalletNo == model.PalletNo).ToList();
                var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == model.PalletNo).ToList();
                if (stockDetail.Count > 0)
                {
                    throw new Exception("当前托盘在库内已有库存信息,请核实");
                }
                //获取托盘信息
                var pallet = Db.Queryable<SysPallets>().First(m=>m.IsDel == "0" && m.PalletNo == model.PalletNo);
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息");
@@ -327,11 +327,11 @@
                    throw new Exception("托盘状态不能未使用状态");
                }
                //获取托盘信息
                var sku = Db.Queryable<SysMaterials>().First(m=>m.IsDel == "0" && m.SkuNo == "100099");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == "100099");
                var pNum = 0;
                var bNum = 0;
                new Common().GetPackQtyInfo(sku.PackagNo,ref pNum,ref bNum);
                new Common().GetPackQtyInfo(sku.PackagNo, ref pNum, ref bNum);
                var datetime = Db.GetDate();
                Db.BeginTran();
@@ -352,8 +352,8 @@
                    LotNo = "",
                    LotText = "",
                    SupplierLot = "",
                    InspectMark ="0", //0 否 1 是
                    BitPalletMark = pNum== (int)model.Qty? "0":"1",
                    InspectMark = "0", //0 否 1 是
                    BitPalletMark = pNum == (int)model.Qty ? "0" : "1",
                    IsBale = "0",
                    IsBelt = "0",
                    CreateUser = (int)model.CreateUser,
@@ -372,7 +372,7 @@
                    Status = "2",
                    CompleteTime = DateTime.Now,
                    Qty = (int)model.Qty,
                    FullQty = pNum,
                    FullQty = pNum,
                    SkuNo = sku.SkuNo,
                    SkuName = sku.PackagNo,
                    LotNo = "",
@@ -392,7 +392,7 @@
                Db.Insertable(modelbb).ExecuteCommand();
                //添加库存
                #region 库存明细
                var sd1 = new DataStockDetail()
                {
@@ -464,7 +464,7 @@
                    CreateUser = 0,
                    CreateTime = datetime
                };
                };
                Db.Insertable(box2).ExecuteCommand();
                #endregion
@@ -541,12 +541,12 @@
                    throw new Exception("当前托盘已有任务,请先取消任务再解绑托盘");
                }
                //获取任务信息
                var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" &&( a.Status == "1" || a.Status == "0"));
                var logtask = Db.Queryable<LogTask>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && (a.Status == "1" || a.Status == "0"));
                if (logtask != null)
                {
                    throw new Exception("该托盘有任务任务正在执行 请核实!");
                }
                //获取箱码信息
                var box = Db.Queryable<BllBoxInfo>().First(a => a.PalletNo == upBindPalletNo && a.IsDel == "0" && a.BindNo == bind.Id);
                //判断空托入库的托盘是否有该托盘
@@ -555,8 +555,8 @@
                    strMsg = "该托盘不是空托托盘 或未绑定 请核实托盘";
                    return strMsg;
                }
                Db.BeginTran();
                var time = DateTime.Now;
@@ -589,13 +589,13 @@
                Db.Insertable(modelpb).ExecuteCommand();
                //删除库存信息
                var stockDetail = Db.Queryable<DataStockDetail>().First(m=>m.IsDel == "0" && m.PalletNo == upBindPalletNo);
                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == upBindPalletNo);
                Db.Deleteable(stockDetail).ExecuteCommand();
                var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.StockDetailId == stockDetail.Id).ToList();
                Db.Deleteable(boxInfo).ExecuteCommand();
                var stock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == box.SkuNo);
                stock.Qty -= bind.Qty;
                if (stock.Qty==0)
                if (stock.Qty == 0)
                {
                    Db.Deleteable(stock).ExecuteCommand();
                }
@@ -607,8 +607,8 @@
                {
                    Db.Updateable(stock).ExecuteCommand();
                }
                // 更改托盘使用状态
                string sqlStr = string.Empty;
                sqlStr = $"update SysPallets set Status = '0' where PalletNo = '{upBindPalletNo}';";
@@ -773,10 +773,10 @@
                    throw new Exception("-1:未获取到对应入库单单据明细信息,请核实!");
                }
                var bind2 = Db.Queryable<BllPalletBind>().Where(a => a.IsDel == "0" && a.Id != model.Id && model.ASNDetailNo == noticeDetail.Id).ToList();
                Db.BeginTran();
                if (bind2.Count(m=>m.InspectMark == "1")>0)
                if (bind2.Count(m => m.InspectMark == "1") > 0)
                {
                    noticeDetail.IsSampling = "1";
                }
@@ -789,9 +789,9 @@
                //判断已组数量是否为0
                if (noticeDetail.FactQty == 0)
                {
                    noticeDetail.Status = "0"; //入库单明细状态
                    //获取状态不是等待执行的明细信息
                    var count = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.Id != noticeDetail.Id && m.ASNNo == bind.ASNNo && m.Status != "0");
                    if (count == 0)
@@ -1901,7 +1901,7 @@
                {
                    throw new Exception("箱码信息不存在!");
                }
                return models;
            }
            catch (Exception ex)
@@ -2454,9 +2454,9 @@
                    }
                }
                int isTextTable = model.TableType;
                #endregion
                Db.BeginTran();
@@ -2648,7 +2648,7 @@
                            //box.Qty = box.Qty;
                            //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
                            factQty += box.Qty;
                            boxFullQty += box.Qty;
                            if (box.InspectMark == "1") //判断是否取样
@@ -2684,7 +2684,7 @@
                if (isSample == "1")
                {
                    bind.InspectMark = "1";
                    bind.SamplingQty = bind.SamplingQty == null? sampleQty : bind.SamplingQty + sampleQty;
                    bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                }
                Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
@@ -2717,7 +2717,7 @@
                    var sqlString2 = string.Empty;
                    sqlString2 += $"update BllArrivalNotice set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='0';";
                    sqlString2 += $"update BllArrivalNoticeDetail set Status = '1',UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='0';";
                    Db.Ado.ExecuteCommand(sqlString2);
                }
                else if (detail.Status == "1")
@@ -2725,7 +2725,7 @@
                    var sqlString2 = string.Empty;
                    sqlString2 += $"update BllArrivalNotice set UpdateTime= getDate(),UpdateUser = {userId} where ASNNo = '{model.AsnNo}' and Status ='1';";
                    sqlString2 += $"update BllArrivalNoticeDetail set UpdateTime= getDate(),UpdateUser = {userId} where id = '{model.AsnDetailId}' and Status ='1';";
                    Db.Ado.ExecuteCommand(sqlString2);
                }
@@ -2780,7 +2780,7 @@
                if (string.IsNullOrEmpty(model.LotNo))
                {
                     throw new Exception("物料不为空!");
                    throw new Exception("物料不为空!");
                }
                else
                {
@@ -2839,7 +2839,7 @@
                }
                //判断托盘是否在库外
                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo))
                if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo))
                {
                    throw new Exception("该托盘已有储位信息,请核实!");
                }
@@ -2847,7 +2847,7 @@
                {
                    throw new Exception("该托盘在库存已有其它物料批次信息,请核实!");
                }
                #region 包装
                var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
@@ -2859,39 +2859,39 @@
                //判断是否标签页判断包装
                //if (isTextTable == 0)
                //{
                    if (pack == null)
                    {
                        throw new Exception("获取物料包装失败,请核实!");
                    }
                    if (pack.L5Num.HasValue)
                    {
                        pNum = (int)pack.L5Num;
                        bNum = (int)pack.L4Num;
                    }
                    else if (pack.L4Num.HasValue)
                    {
                        pNum = (int)pack.L4Num;
                        bNum = (int)pack.L3Num;
                    }
                    else if (pack.L3Num.HasValue)
                    {
                        pNum = (int)pack.L3Num;
                        bNum = (int)pack.L2Num;
                    }
                    else if (pack.L2Num.HasValue)
                    {
                        pNum = (int)pack.L2Num;
                        bNum = (int)pack.L1Num;
                    }
                    else if (pack.L1Num.HasValue)
                    {
                        pNum = (int)pack.L1Num;
                        bNum = (int)pack.L1Num;
                    }
                    if (pNum == 0 || bNum == 0)
                    {
                        throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                    }
                if (pack == null)
                {
                    throw new Exception("获取物料包装失败,请核实!");
                }
                if (pack.L5Num.HasValue)
                {
                    pNum = (int)pack.L5Num;
                    bNum = (int)pack.L4Num;
                }
                else if (pack.L4Num.HasValue)
                {
                    pNum = (int)pack.L4Num;
                    bNum = (int)pack.L3Num;
                }
                else if (pack.L3Num.HasValue)
                {
                    pNum = (int)pack.L3Num;
                    bNum = (int)pack.L2Num;
                }
                else if (pack.L2Num.HasValue)
                {
                    pNum = (int)pack.L2Num;
                    bNum = (int)pack.L1Num;
                }
                else if (pack.L1Num.HasValue)
                {
                    pNum = (int)pack.L1Num;
                    bNum = (int)pack.L1Num;
                }
                if (pNum == 0 || bNum == 0)
                {
                    throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                }
                //}
                #endregion
@@ -2911,7 +2911,7 @@
                }
                #endregion
                //liudl  && m.Status != "2"  组盘既入库完成无需根据托盘状态判断
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                var bindId = 0;
                if (bind == null)
                {
@@ -2988,7 +2988,7 @@
                    Db.Updateable(sd1).ExecuteCommand(); //修改质检信息
                }
                else
                else
                {
                    // 库存不存在 插入数据
                    sd1 = new DataStockDetail()
@@ -3059,7 +3059,7 @@
                    }
                    //添加库存明细
                    sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
                }
                }
                #endregion
                #region 箱码信息
@@ -3260,7 +3260,7 @@
                #endregion
                #region 库存明细
                sd1.Qty = bind.Qty;
                sd1.Qty = bind.Qty;
                //更改库存明细数量
                Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
                #endregion
@@ -3277,7 +3277,7 @@
                    {
                        dataStock.Qty += model.SkuQty;
                    }
                    if (bind.InspectMark == "1")
                    {
                        dataStock.IsSampling = bind.InspectMark;
@@ -3352,14 +3352,12 @@
            }
        }
        //JC26绑定托盘 贴标物料
        public void BindPalletPasteCode(PdaPalletBindVm model, int userId)
        {
            try
            {
                #region 判断
                //0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库
                var TypeLot = "5, 6";
@@ -3375,7 +3373,6 @@
                {
                    throw new Exception("托盘号不可为空!");
                }
                //根据单据号获取入库单总单
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
                if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
@@ -3397,20 +3394,16 @@
                    }
                    else
                    {
                        if (!TypeLot.Contains(notice.Type))
                        {
                            throw new Exception("物料批次不可为空!");
                        }
                        model.LotNo = "";
                        throw new Exception("物料批次不可为空!");
                    }
                }
                //判断箱码信息
                if (string.IsNullOrEmpty(model.BoxNo))
                {
                    throw new Exception("箱码信息不可为空!");
                }
                //是否连续组托 0:否  1:是
                if (model.IsContinue == "1")
                {
                    if (string.IsNullOrWhiteSpace(model.TailBoxNo))
@@ -3419,15 +3412,13 @@
                    }
                }
                var comTime = DateTime.Now;
                //托盘是否存在
                //托盘信息是否存在
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息,请核实!");
                }
                // 验证入库单明细是否存在
                //验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo));
                if (detail == null)
                {
@@ -3439,17 +3430,21 @@
                {
                    throw new Exception("该托盘已有储位信息,请核实!");
                }
                if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo))
                /*if (stockDetail != null && stockDetail.SkuNo != detail.SkuNo)
                {
                    throw new Exception("该托盘在库存已有其它物料批次信息,请核实!");
                }
                    throw new Exception("该托盘在库存已有其它物料信息,请核实!");
                }*/
                #endregion
                #region 包装
                //开启事务
                Db.BeginTran();
                //当前时间
                var comTime = DateTime.Now;
                #region 包装
                var package = Db.Queryable<SysPackag>().Where(m => m.IsDel == "0");
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo);    // liudl 由Sku包装编号变更为入库单明细包装编号
                var pack = package.First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo);    // liudl 由Sku包装编号变更为入库单明细包装编号
                var pNum = 0;//托盘物品数量 
                var bNum = 0;//箱码物品数量 
@@ -3491,7 +3486,6 @@
                #endregion
                #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
                var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
                if (palletBind != null)
                {
@@ -3505,1012 +3499,1368 @@
                        }
                    }
                }
                #endregion
                /* 因考虑可能会有拼箱(同物料不同批次),逻辑如下
                 * 查询出要绑定托盘的箱码信息、分组整理、判断是否有拼箱(允许有多个),循环添加箱码<->库存箱码 和 对应的托盘绑定<->库存托盘明细信息
                 * 循环箱码需要判断是否是当前单据,如不是:更新对应单据
                 *
                 *
                 */
                #region 箱码信息
                var msgStr = $"箱号为{model.BoxNo}";
                var boxInfoList = new List<BllBoxInfo>();
                //#region 箱码信息
                //var msgStr = $"箱号为{model.BoxNo}";
                //var boxInfoList = new List<BllBoxInfo>();
                //首箱
                var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList();
                if (boxInfo.Count == 0)
                {
                    throw new Exception("箱码信息不存在!");
                }
                boxInfoList.AddRange(boxInfo);
                //是否连续组托
                if (model.IsContinue == "1")
                {
                    //尾箱
                    var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo).ToList();
                    if (boxInfo2.Count == 0)
                    {
                        throw new Exception("尾箱码信息不存在!");
                    }
                    boxInfoList.AddRange(boxInfo2);
                    var sql = $"select * from BllBoxInfo where IsDel = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
                    var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
                    boxInfoList.AddRange(list);
                    msgStr += $"尾箱号为{model.TailBoxNo}";
                }
                //和选择的批次同批次的箱码信息
                var sameBoxInfoList = boxInfoList.Where(w => w.LotNo == model.LotNo).ToList();
                //和选择的批次不同批次的箱码信息(拼箱批次)
                var notBoxInfoList = boxInfoList.Where(w => w.LotNo != model.LotNo).ToList();
                //拼箱数量(和选择的批次不同批次的箱码数量)
                decimal pinBoxQty = notBoxInfoList.Sum(s => s.Qty);
                #endregion
                ////首箱
                //var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList();
                //if (boxInfo.Count == 0)
                //{
                //    throw new Exception("箱码信息不存在!");
                //}
                //boxInfo = boxInfo.Where(m => m.Status == "0").ToList();
                //if (boxInfo.Count == 0)
                //{
                //    throw new Exception("箱码已被使用!");
                //}
                //boxInfoList.AddRange(boxInfo);
                ////是否连续组托
                //if (model.IsContinue == "1")
                //{
                //    //尾箱
                //    var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo).ToList();
                //    if (boxInfo2.Count == 0)
                //    {
                //        throw new Exception("尾箱码信息不存在!");
                //    }
                //    boxInfo2 = boxInfo2.Where(m => m.Status == "0").ToList();
                //    if (boxInfo2.Count == 0)
                //    {
                //        throw new Exception("尾箱箱码已被使用!");
                //    }
                //    boxInfoList.AddRange(boxInfo2);
                //    var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
                //    var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
                //    boxInfoList.AddRange(list);
                //    msgStr += $"尾箱号为{model.TailBoxNo}";
                //}
                if (sameBoxInfoList.Count <= 0)
                {
                    throw new Exception("箱码信息不存在!");
                }
                else
                {
                    #region 托盘绑定信息
                    var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                    var bindId = 0;
                    if (bind == null)
                    {
                        bind = new BllPalletBind
                        {
                            ASNNo = model.AsnNo,
                            ASNDetailNo = (int)model.AsnDetailId,
                            PalletNo = model.PalletNo,
                            PalletNo2 = "",
                            PalletNo3 = "",
                            Qty = model.SkuQty - pinBoxQty,//不包含拼箱中非同批次数量
                            FullQty = pNum,
                            Status = "2",//入库完成
                            Type = "0",
                            LotNo = model.LotNo,
                            LotText = detail.LotText,
                            SupplierLot = detail.SupplierLot,
                            //InspectMark = model.IsSample,      //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                            //SamplingQty = 0,     //取样数量  后期业务开发时 接口传值需添加对应字段判断
                            BitPalletMark = "1",
                            IsBale = "0",
                            IsBelt = "0",
                            CreateUser = userId,
                            Demo = model.Demo,
                        };
                        // 插入托盘绑定表
                        bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                    }
                    else
                    {
                        bindId = bind.Id;
                        bind.Qty += model.SkuQty;
                    }
                    if (bind.Qty < 0)
                    {
                        throw new Exception("组盘数量不能小于0");
                    }
                    #endregion
                //#endregion
                    #region 库存明细和质检信息
                    //获取该批次最终质检结果
                    BllQualityInspect quality = new BllQualityInspect();
                    //判断是否为退货入库单
                    if (notice.Type == "3")
                    {
                        quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
                    }
                    else
                    {
                        quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
                    }
                    var tags = "0";
                    if (notice.Type == "3" || notice.Type == "4")
                    {
                        tags = "1";
                    }
                //// 更改箱支关系表
                //decimal factQty = 0.00m;//托盘总数量
                //var isSample = "0";//是否取样
                //var sampleQty = 0m;//取样数量
                    // 判断库存明细是否已有此托盘信息
                    var sd1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo);
                    var sdId1 = 0;
                    if (sd1 != null)
                    {
                        sdId1 = sd1.Id;
                        // 库存已存在 更新数据
                        sd1.Qty = bind.Qty;
                        sd1.CompleteTime = comTime;
                        sd1.UpdateUser = userId;
                        sd1.UpdateTime = comTime;
                //var boxInfoStr = boxInfoList.Select(m => m.BoxNo3).ToList();//支码集合
                //var dataBoxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && boxInfoStr.Contains(m.BoxNo3));//从库存中获取对应的箱码信息集合
                        Db.Updateable(sd1).ExecuteCommand();
                    }
                    else
                    {
                        // 库存不存在 插入数据
                        sd1 = new DataStockDetail()
                        {
                            LotNo = bind.LotNo,
                            LotText = bind.LotText,
                            SupplierLot = bind.SupplierLot,
                            SkuNo = sku.SkuNo,
                            SkuName = sku.SkuName,
                            Standard = sku.Standard,
                            Qty = bind.Qty,
                            LockQty = 0,
                            FrozenQty = 0,
                            InspectQty = 0,
                            ASNNo = bind.ASNNo,
                            ASNDetailNo = bind.ASNDetailNo,
                            WareHouseNo = "",//所属仓库
                            RoadwayNo = "",//所属巷道
                            AreaNo = "",//所属区域
                            LocatNo = "",//储位地址
                            PalletNo = bind.PalletNo,
                            PalletNo2 = bind.PalletNo2,
                            PalletNo3 = bind.PalletNo3,
                            PalletTags = tags,
                            CompleteTime = comTime,
                            ProductionTime = bind.ProductionTime,
                            ExpirationTime = bind.ExpirationTime,
                            Status = "0",
                            InspectMark = bind.InspectMark,
                            InspectStatus = sku.IsInspect,
                            BitPalletMark = bind.BitPalletMark,
                            PackagNo = detail.PackagNo,                    //liudl 由sku的包装编号变为入库单明细的包装编码
                            IsBale = bind.IsBale,
                            IsBelt = bind.IsBelt,
                //var boxGroup = boxInfoList.GroupBy(m => new {  m.BoxNo ,m.LotNo}).ToList();  //根据箱码、批此分组
                //foreach (var g in boxGroup)//21
                //{
                //    var isYou = false;//需判断是否是存在库存
                //    var count = dataBoxInfo.Count(m => m.BoxNo == g.Key.BoxNo);
                //    if (count >0)
                //    {
                //        isYou = true;
                //    }
                            IsDel = "0",
                            CreateUser = 0,
                            CreateTime = comTime
                        };
                //    var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo && m.LotNo == g.Key.LotNo);
                        //维护库存明细货主/供应商信息
                        if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                        {
                            sd1.OwnerNo = notice.CustomerNo;//货主编码
                            sd1.OwnerName = notice.CustomerName;//货主名称
                        }
                        else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
                        {
                            sd1.SupplierNo = notice.CustomerNo;//供应商编码
                            sd1.SupplierName = notice.CustomerName;//供应商名称
                        }
                        if (quality != null)
                        {
                            //修改合格不合格数量
                            if (quality.IsQualified == "1") //合格
                            {
                                //增加合格数量
                                quality.PassQty += bind.Qty;
                                sd1.InspectStatus = "1";
                            }
                            else if (quality.IsQualified == "0") //不合格
                            {
                                //增加不合格数量
                                quality.FailQty += bind.Qty;
                                sd1.InspectStatus = "2";
                            }
                            Db.Updateable(quality).ExecuteCommand(); //修改质检信息
                        }
                        //添加库存明细
                        sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
                    }
                    #endregion
                //    var bindId = 0;
                //    if (bind == null && !isYou)
                //    {
                //        bind = new BllPalletBind
                //        {
                //            ASNNo = model.AsnNo,
                //            ASNDetailNo = (int)model.AsnDetailId,
                //            PalletNo = model.PalletNo,
                    // 更改箱支关系表
                    decimal factQty = 0.00m;//托盘总数量
                    var isSample = "0";//是否取样
                    var sampleQty = 0m;//取样数量
                //            Qty = model.SkuQty,
                //            FullQty = pNum,
                //            Status = "2",//入库完成
                //            Type = "0",
                //            LotNo = model.LotNo,
                //            LotText = detail.LotText,
                //            SupplierLot = detail.SupplierLot,
                //            //InspectMark = model.IsSample,      //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                //            //SamplingQty = 0,     //取样数量  后期业务开发时 接口传值需添加对应字段判断
                //            BitPalletMark = "1",
                //            IsBale = "0",
                //            IsBelt = "0",
                //            CreateUser = userId,
                //            Demo = model.Demo,
                    //标签组托
                    var boxGroup = sameBoxInfoList.GroupBy(m => m.BoxNo).ToList();
                    foreach (var g in boxGroup)
                    {
                        decimal boxFullQty = 0;//箱内总数量
                        foreach (var box in g)
                        {
                            if (box.BindNo != null && box.BindNo != 0)
                            {
                                continue;
                            }
                            //箱内物料批次与单据明细不符合
                            if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
                            {
                                throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                            }
                //        };
                //        // 插入托盘绑定表
                //        bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                //    }
                //    else
                //    {
                //        bindId = bind.Id;
                //        bind.Qty += model.SkuQty;
                //    }
                //    if (bind.Qty < 0)
                //    {
                //        throw new Exception("组盘数量不能小于0");
                //    }
                            box.ASNNo = model.AsnNo;
                            box.ASNDetailNo = model.AsnDetailId;
                            box.BindNo = bindId;
                            box.PalletNo = model.PalletNo;
                            box.Status = "2";
                            //box.InspectMark = model.IsSample;  //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                            //box.SamplingQty = 0;    //取样数量  后期业务开发时 接口传值需添加对应字段判断
                            box.CompleteTime = comTime;
                            box.UpdateTime = comTime;
                            box.UpdateUser = userId;
                            //box.Qty = box.Qty;
                            //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
                //    decimal boxFullQty = 0;//箱内总数量
                //    foreach (var box in g)//支码 2
                //    {
                //        if (box.BindNo != null && box.BindNo != 0)
                //        {
                //            continue;
                //        }
                //        //箱内物料与单据明细不符合  同托盘可同物料不同批次
                //        if (box.SkuNo != detail.SkuNo)
                //        {
                //            throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                //        }
                            factQty += box.Qty;
                            boxFullQty += box.Qty;
                            if (box.InspectMark == "1") //判断是否取样
                            {
                                isSample = "1";
                                sampleQty += (decimal)box.SamplingQty;
                            }
                //        box.ASNNo = model.AsnNo;
                //        box.ASNDetailNo = model.AsnDetailId;
                //        box.BindNo = bindId;
                //        box.PalletNo = model.PalletNo;
                //        box.Status = "2";
                //        //box.InspectMark = model.IsSample;  //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                //        //box.SamplingQty = 0;    //取样数量  后期业务开发时 接口传值需添加对应字段判断
                //        box.CompleteTime = comTime;
                //        box.UpdateTime = comTime;
                //        box.UpdateUser = userId;
                            #region 库存箱码明细
                            var box2 = new DataBoxInfo()
                            {
                                StockDetailId = sdId1,
                                BindNo = bind.Id,
                                BoxNo = box.BoxNo,
                                BoxNo2 = box.BoxNo2,
                                BoxNo3 = box.BoxNo3,
                                PalletNo = box.PalletNo,
                                PalletNo2 = box.PalletNo2,
                                PalletNo3 = box.PalletNo3,
                                Qty = box.Qty,
                                FullQty = box.FullQty,
                                Status = "2",//0:未组托  1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
                                LotNo = box.LotNo,
                                LotText = box.LotText,
                                SkuNo = box.SkuNo,
                                SkuName = box.SkuName,
                                Standard = sku.Standard,
                                ProductionTime = box.ProductionTime,
                                SupplierLot = box.SupplierLot,
                                InspectStatus = sku.IsInspect,
                                InspectMark = box.InspectMark,
                                BitBoxMark = box.BitBoxMark,
                                ExpirationTime = box.ExpirationTime,
                //        //box.Qty = box.Qty;
                //        //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
                                CreateUser = 0,
                                CreateTime = comTime
                            };
                            //添加库存箱码明细
                            Db.Insertable(box2).ExecuteCommand();
                            #endregion
                        }
                        if (boxFullQty > bNum)
                        {
                            throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                        }
                    }
                    //更改箱支关系表信息
                    Db.Updateable(boxInfoList).ExecuteCommand();
                //        factQty += box.Qty;
                //        boxFullQty += box.Qty;
                //        if (box.InspectMark == "1") //判断是否取样
                //        {
                //            isSample = "1";
                //            sampleQty += (decimal)box.SamplingQty;
                //        }
                    // 更新托盘绑定表
                    bind.Qty += factQty;
                //        #region 库存箱码明细
                //        var box2 = new DataBoxInfo()
                //        {
                //            StockDetailId = sdId1,
                //            BindNo = bind.Id,
                //            BoxNo = box.BoxNo,
                //            BoxNo2 = box.BoxNo2,
                //            BoxNo3 = box.BoxNo3,
                //            PalletNo = box.PalletNo,
                //            PalletNo2 = box.PalletNo2,
                //            PalletNo3 = box.PalletNo3,
                //            Qty = box.Qty,
                //            FullQty = box.FullQty,
                //            Status = "2",//0:未组托  1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
                //            LotNo = box.LotNo,
                //            LotText = box.LotText,
                //            SkuNo = box.SkuNo,
                //            SkuName = box.SkuName,
                //            Standard = sku.Standard,
                //            ProductionTime = box.ProductionTime,
                //            SupplierLot = box.SupplierLot,
                //            InspectStatus = sku.IsInspect,
                //            InspectMark = box.InspectMark,
                //            BitBoxMark = box.BitBoxMark,
                //            ExpirationTime = box.ExpirationTime,
                    if (bind.FullQty < bind.Qty)
                    {
                        throw new Exception("托盘绑定数量已超出该物料包装数量");
                    }
                //            CreateUser = 0,
                //            CreateTime = comTime
                //        };
                //        //添加库存箱码明细
                //        Db.Insertable(box2).ExecuteCommand();
                //        #endregion
                //    }
                //    if (boxFullQty > bNum)
                //    {
                //        throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                //    }
                //}
                //Db.Updateable(boxInfoList).ExecuteCommand();
                    if (bind.FullQty == bind.Qty)
                    {
                        bind.BitPalletMark = "0";
                        sd1.BitPalletMark = "0";
                    }
                    if (bind.Qty > pNum)
                    {
                        throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                    }
                    if (isSample == "1")
                    {
                        bind.InspectMark = "1";
                        bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                    }
                    Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                //#region 库存明细
                ////获取该批次最终质检结果
                //BllQualityInspect quality = new BllQualityInspect();
                ////判断是否为退货入库单
                //if (notice.Type == "3")
                //{
                //    quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
                //}
                //else
                //{
                //    quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
                //}
                //var tags = "0";
                //if (notice.Type == "3" || notice.Type == "4")
                //{
                //    tags = "1";
                //}
                    #region 入库单及明细
                    detail.FactQty += factQty;//已组数量
                    detail.CompleteQty += factQty;//完成数量
                    if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
                    {
                        detail.IsSampling = "1";
                    }
                    detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
                    if (detail.CompleteQty >= detail.Qty)
                    {
                        detail.Status = "2";
                        detail.CompleteTime = comTime;
                    }
                    detail.UpdateUser = userId;
                    detail.UpdateTime = comTime;
                    //更新入库单明细
                    Db.Updateable(detail).ExecuteCommand();
                //// 判断库存明细是否已有此托盘信息
                //var sd1 = Db.Queryable<DataStockDetail>()
                //    .First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo);
                //var sdId1 = 0;
                //if (sd1 != null)
                //{
                //    sdId1 = sd1.Id;
                //    // 库存已存在 更新数据
                //    sd1.Qty = bind.Qty;
                //    sd1.CompleteTime = comTime;
                //    sd1.UpdateUser = userId;
                //    sd1.UpdateTime = comTime;
                    notice.UpdateUser = userId;
                    notice.UpdateTime = comTime;
                    if (notice.Status == "0")
                    {
                        notice.Status = "1";
                    }
                    var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
                    if (asnDetailNum == 0)
                    {
                        notice.Status = "2";//执行完成
                        notice.CompleteTime = comTime;//完成时间
                    }
                    //更新入库单
                    Db.Updateable(notice).ExecuteCommand();
                    #endregion
                //    Db.Updateable(sd1).ExecuteCommand(); //修改质检信息
                //}
                //else
                //{
                //    // 库存不存在 插入数据
                //    sd1 = new DataStockDetail()
                //    {
                //        LotNo = bind.LotNo,
                //        LotText = bind.LotText,
                //        SupplierLot = bind.SupplierLot,
                //        SkuNo = sku.SkuNo,
                //        SkuName = sku.SkuName,
                //        Standard = sku.Standard,
                //        Qty = bind.Qty,
                //        LockQty = 0,
                //        FrozenQty = 0,
                //        InspectQty = 0,
                //        ASNNo = bind.ASNNo,
                //        ASNDetailNo = bind.ASNDetailNo,
                //        WareHouseNo = "",//所属仓库
                //        RoadwayNo = "",//所属巷道
                //        AreaNo = "",//所属区域
                //        LocatNo = "",//储位地址
                //        PalletNo = bind.PalletNo,
                //        PalletNo2 = bind.PalletNo2,
                //        PalletNo3 = bind.PalletNo3,
                //        PalletTags = tags,
                //        CompleteTime = comTime,
                //        ProductionTime = bind.ProductionTime,
                //        ExpirationTime = bind.ExpirationTime,
                //        Status = "0",
                //        InspectMark = bind.InspectMark,
                //        InspectStatus = sku.IsInspect,
                //        BitPalletMark = bind.BitPalletMark,
                //        PackagNo = detail.PackagNo,                    //liudl 由sku的包装编号变为入库单明细的包装编码
                //        IsBale = bind.IsBale,
                //        IsBelt = bind.IsBelt,
                    #region 库存明细
                    sd1.Qty = bind.Qty;
                    //更改库存明细数量
                    Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
                    #endregion
                //        IsDel = "0",
                //        CreateUser = 0,
                //        CreateTime = comTime
                //    };
                    #region 库存
                    var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
                    if (dataStock != null)
                    {
                        dataStock.Qty += factQty;
                //    //维护库存明细货主/供应商信息
                //    if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                //    {
                //        sd1.OwnerNo = notice.CustomerNo;//货主编码
                //        sd1.OwnerName = notice.CustomerName;//货主名称
                //    }
                //    else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
                //    {
                //        sd1.SupplierNo = notice.CustomerNo;//供应商编码
                //        sd1.SupplierName = notice.CustomerName;//供应商名称
                //    }
                //    if (quality != null)
                //    {
                //        //修改合格不合格数量
                //        if (quality.IsQualified == "1") //合格
                //        {
                //            //增加合格数量
                //            quality.PassQty += bind.Qty;
                //            sd1.InspectStatus = "1";
                //        }
                //        else if (quality.IsQualified == "0") //不合格
                //        {
                //            //增加不合格数量
                //            quality.FailQty += bind.Qty;
                //            sd1.InspectStatus = "2";
                //        }
                //        Db.Updateable(quality).ExecuteCommand(); //修改质检信息
                //    }
                //    //添加库存明细
                //    sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
                //}
                //#endregion
                        if (bind.InspectMark == "1")
                        {
                            dataStock.IsSampling = bind.InspectMark;
                        }
                        Db.Updateable(dataStock).ExecuteCommand();
                    }
                    else
                    {
                        var stock = new DataStock()
                        {
                            SkuNo = sku.SkuNo,
                            SkuName = sku.SkuName,
                            Standard = sku.Standard,
                            LotNo = bind.LotNo,
                            LotText = bind.LotText,
                            Qty = bind.Qty,
                            LockQty = 0,
                            FrozenQty = 0,
                            IsSampling = bind.InspectMark,
                            IsDel = "0",
                            CreateUser = userId,
                            CreateTime = comTime
                        };
                        //维护库存货主信息
                        if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                        {
                            stock.OwnerNo = notice.CustomerNo;//货主编码
                            stock.OwnerName = notice.CustomerName;//货主名称
                        }
                        Db.Insertable(stock).ExecuteCommand();
                    }
                    #endregion
                //#region 箱码信息
                //var msgStr = $"箱号为{model.BoxNo}";
                //var boxInfoList = new List<BllBoxInfo>();
                    #region 质检请验
                    if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
                    {
                        var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
                        if (qualityRequest == null)
                        {
                            string qcNo = new Common().GetMaxNo("QC");
                            qualityRequest = new BllQualityInspectionRequest();
                            qualityRequest.QcNo = qcNo;
                            qualityRequest.Status = "0";
                            qualityRequest.SkuNo = sku.SkuNo;
                            qualityRequest.SkuName = sku.SkuName;
                            qualityRequest.LotNo = bind.LotNo;
                            qualityRequest.SupplierLot = bind.SupplierLot;
                            qualityRequest.Qty = detail.Qty;
                            qualityRequest.SamplingQty = 0;
                            qualityRequest.ASNNo = detail.ASNNo;
                            qualityRequest.CreateUser = userId;
                            qualityRequest.CreateTime = comTime;
                            //添加质检请验单
                            Db.Insertable(qualityRequest).ExecuteCommand();
                        }
                    }
                    #endregion
                }
                //拼箱
                if (notBoxInfoList.Count > 0)
                {
                    var gbox = notBoxInfoList.GroupBy(g => g.BoxNo).ToList();
                    if (gbox.Count > 1)
                    {
                        throw new Exception("一个托盘上只能有1个拼箱!");
                    }
                    gbox = notBoxInfoList.GroupBy(g => g.LotNo).ToList();
                    if (gbox.Count > 1)
                    {
                        throw new Exception("一个箱内最多能有2个不同批次物料!");
                    }
                    var pinBoxNo = notBoxInfoList[0].BoxNo;//拼箱箱码
                    var pinBoxLotNo = notBoxInfoList[0].LotNo;//拼箱批次号
                ////首箱
                //var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo).ToList();
                //if (boxInfo.Count == 0)
                //{
                //    throw new Exception("箱码信息不存在!");
                //}
                //boxInfo = boxInfo.Where(m => m.Status == "0").ToList();
                //if (boxInfo.Count == 0)
                //{
                //    throw new Exception("箱码已被使用!");
                //}
                //boxInfoList.AddRange(boxInfo);
                ////是否连续组托
                //if (model.IsContinue == "1")
                //{
                //    //尾箱
                //    var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo).ToList();
                //    if (boxInfo2.Count == 0)
                //    {
                //        throw new Exception("尾箱码信息不存在!");
                //    }
                //    boxInfo2 = boxInfo2.Where(m => m.Status == "0").ToList();
                //    if (boxInfo2.Count == 0)
                //    {
                //        throw new Exception("尾箱箱码已被使用!");
                //    }
                //    boxInfoList.AddRange(boxInfo2);
                //    var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; ";
                //    var list = Db.Ado.SqlQuery<BllBoxInfo>(sql);
                //    boxInfoList.AddRange(list);
                //    msgStr += $"尾箱号为{model.TailBoxNo}";
                //}
                    var dataBoxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.BoxNo == pinBoxNo && w.LotNo == pinBoxLotNo).ToList();
                    if (dataBoxList.Count > 0)//已有库存
                    {
                        //原托盘绑定信息
                        var oldPalletBind = Db.Queryable<BllPalletBind>().First(w => w.Id == notBoxInfoList[0].BindNo);
                        //原入库单明细
                        var oldAsnDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.Id == oldPalletBind.ASNDetailNo);
                        #region 托盘绑定信息
                        var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == oldAsnDetail.Id && m.PalletNo == model.PalletNo);
                        var bindId = 0;
                        if (bind == null)
                        {
                            bind = new BllPalletBind
                            {
                                ASNNo = oldAsnDetail.ASNNo,
                                ASNDetailNo = oldAsnDetail.Id,
                                PalletNo = model.PalletNo,
                                PalletNo2 = "",
                                PalletNo3 = "",
                                Qty = pinBoxQty,
                                FullQty = pNum,
                                Status = "2",//入库完成
                                Type = "0",
                                LotNo = pinBoxLotNo,
                                LotText = oldAsnDetail.LotText,
                                SupplierLot = oldAsnDetail.SupplierLot,
                                //InspectMark = model.IsSample,      //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                                //SamplingQty = 0,     //取样数量  后期业务开发时 接口传值需添加对应字段判断
                                BitPalletMark = "1",
                                IsBale = "0",
                                IsBelt = "0",
                                CreateUser = userId,
                                Demo = model.Demo,
                            };
                            // 插入托盘绑定表
                            bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                        }
                        else
                        {
                            bindId = bind.Id;
                            bind.Qty += pinBoxQty;
                //#endregion
                            Db.Updateable(bind).ExecuteCommand();
                        }
                        #endregion
                //// 更改箱支关系表
                //decimal factQty = 0.00m;//托盘总数量
                //var isSample = "0";//是否取样
                //var sampleQty = 0m;//取样数量
                        // 插入库存明细数据
                        var sd1 = new DataStockDetail()
                        {
                            LotNo = pinBoxNo,
                            LotText = notBoxInfoList[0].LotText,
                            SupplierLot = notBoxInfoList[0].SupplierLot,
                            SkuNo = sku.SkuNo,
                            SkuName = sku.SkuName,
                            Standard = sku.Standard,
                            Qty = pinBoxQty,
                            LockQty = 0,
                            FrozenQty = 0,
                            InspectQty = 0,
                            ASNNo = oldPalletBind.ASNNo,
                            ASNDetailNo = oldPalletBind.ASNDetailNo,
                            WareHouseNo = "",//所属仓库
                            RoadwayNo = "",//所属巷道
                            AreaNo = "",//所属区域
                            LocatNo = "",//储位地址
                            PalletNo = oldPalletBind.PalletNo,
                            PalletNo2 = oldPalletBind.PalletNo2,
                            PalletNo3 = oldPalletBind.PalletNo3,
                            PalletTags = "0",
                            CompleteTime = comTime,
                            ProductionTime = oldPalletBind.ProductionTime,
                            ExpirationTime = oldPalletBind.ExpirationTime,
                            Status = "0",
                            InspectMark = oldPalletBind.InspectMark,
                            InspectStatus = sku.IsInspect,
                            BitPalletMark = oldPalletBind.BitPalletMark,
                            PackagNo = oldAsnDetail.PackagNo,
                            IsBale = oldPalletBind.IsBale,
                            IsBelt = oldPalletBind.IsBelt,
                            IsDel = "0",
                            CreateUser = 0,
                            CreateTime = comTime
                        };
                        //添加库存明细
                        var sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
                        foreach (var item in dataBoxList)
                        {
                            item.StockDetailId = sdId1;//库存明细id
                            item.BindNo = bind.Id;//托盘绑定id
                        }
                        //更新库存箱支明细表
                        Db.Updateable(dataBoxList).ExecuteCommand();
                //var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList();
                //foreach (var g in boxGroup)
                //{
                //    decimal boxFullQty = 0;//箱内总数量
                //    foreach (var box in g)
                //    {
                //        if (box.BindNo != null && box.BindNo != 0)
                //        {
                //            continue;
                //        }
                //        //箱内物料批次与单据明细不符合
                //        if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
                //        {
                //            throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                //        }
                        //托盘解绑信息
                        var palletUnbind = Db.Queryable<BllPalletUnbind>().First(w => w.IsDel == "0" && w.UpbindPalletNo == oldPalletBind.PalletNo && w.BoxNo == pinBoxNo);
                        if (palletUnbind == null)
                        {
                            throw new Exception("拼箱的托盘解绑信息不存在!");
                        }
                        palletUnbind.BindPalletNo = model.PalletNo;//绑定托盘号
                        palletUnbind.UpdateTime = comTime;
                        palletUnbind.UpdateUser = userId;
                        //更新托盘解绑绑定表信息
                        Db.Updateable(palletUnbind).ExecuteCommand();
                    }
                    else
                    {
                        string sql = $@"SELECT detail.* FROM BllArrivalNoticeDetail as detail
                                        JOIN BllArrivalNotice as notice ON detail.ASNNo=notice.ASNNo
                                        WHERE notice.IsDel='0'
                                        AND notice.Status='1'
                                        AND detail.IsDel='0'
                                        AND detail.LotNo='{pinBoxLotNo}'
                                        AND detail.SkuNo='{sku.SkuNo}'
                                        ORDER BY detail.CreateTime ";
                        //找到拼箱内其他批次所属入库单明细
                        var arrDetail = Db.Ado.SqlQuery<BllArrivalNoticeDetail>(sql).FirstOrDefault();
                        if (arrDetail == null)
                        {
                            throw new Exception("拼箱内物料所属入库单明细不存在!");
                        }
                        //找到拼箱内其他批次所属入库单
                        var arrNotice = Db.Queryable<BllArrivalNotice>().First(w => w.IsDel == "0" && w.ASNNo == arrDetail.ASNNo && w.Status == "1");
                        if (arrNotice == null)
                        {
                            throw new Exception("拼箱内物料所属入库单不存在!");
                        }
                        #region 托盘绑定信息
                        var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == arrDetail.Id && m.PalletNo == model.PalletNo);
                        var bindId = 0;
                        if (bind == null)
                        {
                            bind = new BllPalletBind
                            {
                                ASNNo = arrDetail.ASNNo,
                                ASNDetailNo = arrDetail.Id,
                                PalletNo = model.PalletNo,
                                PalletNo2 = "",
                                PalletNo3 = "",
                                Qty = pinBoxQty,
                                FullQty = pNum,
                                Status = "2",//入库完成
                                Type = "0",
                                LotNo = pinBoxLotNo,
                                LotText = arrDetail.LotText,
                                SupplierLot = arrDetail.SupplierLot,
                                //InspectMark = model.IsSample,      //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                                //SamplingQty = 0,     //取样数量  后期业务开发时 接口传值需添加对应字段判断
                                BitPalletMark = "1",
                                IsBale = "0",
                                IsBelt = "0",
                                CreateUser = userId,
                                Demo = model.Demo,
                            };
                            // 插入托盘绑定表
                            bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                        }
                        else
                        {
                            bindId = bind.Id;
                            bind.Qty += pinBoxQty;
                //        box.ASNNo = model.AsnNo;
                //        box.ASNDetailNo = model.AsnDetailId;
                //        box.BindNo = bindId;
                //        box.PalletNo = model.PalletNo;
                //        box.Status = "2";
                //        //box.InspectMark = model.IsSample;  //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                //        //box.SamplingQty = 0;    //取样数量  后期业务开发时 接口传值需添加对应字段判断
                //        box.CompleteTime = comTime;
                //        box.UpdateTime = comTime;
                //        box.UpdateUser = userId;
                            Db.Updateable(bind).ExecuteCommand();
                        }
                        #endregion
                //        //box.Qty = box.Qty;
                //        //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
                        #region 库存明细和质检信息
                        //获取该批次最终质检结果
                        BllQualityInspect quality = new BllQualityInspect();
                        //判断是否为退货入库单
                        if (arrNotice.Type == "3")
                        {
                            quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == arrDetail.ASNNo && a.SkuNo == arrDetail.SkuNo && a.LotNo == arrDetail.LotNo).OrderByDescending(a => a.CreateTime).First();
                        }
                        else
                        {
                            quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == arrDetail.SkuNo && a.LotNo == arrDetail.LotNo).OrderByDescending(a => a.CreateTime).First();
                        }
                        var tags = "0";
                        if (arrNotice.Type == "3" || arrNotice.Type == "4")
                        {
                            tags = "1";
                        }
                //        factQty += box.Qty;
                //        boxFullQty += box.Qty;
                //        if (box.InspectMark == "1") //判断是否取样
                //        {
                //            isSample = "1";
                //            sampleQty += (decimal)box.SamplingQty;
                //        }
                        // 判断库存明细是否已有此托盘信息
                        var sd1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.ASNDetailNo == arrDetail.Id && m.PalletNo == model.PalletNo);
                        var sdId1 = 0;
                        if (sd1 != null)
                        {
                            sdId1 = sd1.Id;
                            // 库存已存在 更新数据
                            sd1.Qty = pinBoxQty;
                            sd1.CompleteTime = comTime;
                            sd1.UpdateUser = userId;
                            sd1.UpdateTime = comTime;
                //        #region 库存箱码明细
                //        var box2 = new DataBoxInfo()
                //        {
                //            StockDetailId = sdId1,
                //            BindNo = bind.Id,
                //            BoxNo = box.BoxNo,
                //            BoxNo2 = box.BoxNo2,
                //            BoxNo3 = box.BoxNo3,
                //            PalletNo = box.PalletNo,
                //            PalletNo2 = box.PalletNo2,
                //            PalletNo3 = box.PalletNo3,
                //            Qty = box.Qty,
                //            FullQty = box.FullQty,
                //            Status = "2",//0:未组托  1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
                //            LotNo = box.LotNo,
                //            LotText = box.LotText,
                //            SkuNo = box.SkuNo,
                //            SkuName = box.SkuName,
                //            Standard = sku.Standard,
                //            ProductionTime = box.ProductionTime,
                //            SupplierLot = box.SupplierLot,
                //            InspectStatus = sku.IsInspect,
                //            InspectMark = box.InspectMark,
                //            BitBoxMark = box.BitBoxMark,
                //            ExpirationTime = box.ExpirationTime,
                            Db.Updateable(sd1).ExecuteCommand();
                        }
                        else
                        {
                            // 库存不存在 插入数据
                            sd1 = new DataStockDetail()
                            {
                                LotNo = pinBoxLotNo,
                                LotText = notBoxInfoList[0].LotText,
                                SupplierLot = bind.SupplierLot,
                                SkuNo = sku.SkuNo,
                                SkuName = sku.SkuName,
                                Standard = sku.Standard,
                                Qty = pinBoxQty,
                                LockQty = 0,
                                FrozenQty = 0,
                                InspectQty = 0,
                                ASNNo = arrDetail.ASNNo,
                                ASNDetailNo = arrDetail.Id,
                                WareHouseNo = "",//所属仓库
                                RoadwayNo = "",//所属巷道
                                AreaNo = "",//所属区域
                                LocatNo = "",//储位地址
                                PalletNo = bind.PalletNo,
                                PalletNo2 = bind.PalletNo2,
                                PalletNo3 = bind.PalletNo3,
                                PalletTags = tags,
                                CompleteTime = comTime,
                                ProductionTime = bind.ProductionTime,
                                ExpirationTime = bind.ExpirationTime,
                                Status = "0",
                                InspectMark = bind.InspectMark,
                                InspectStatus = sku.IsInspect,
                                BitPalletMark = bind.BitPalletMark,
                                PackagNo = detail.PackagNo,                    //liudl 由sku的包装编号变为入库单明细的包装编码
                                IsBale = bind.IsBale,
                                IsBelt = bind.IsBelt,
                //            CreateUser = 0,
                //            CreateTime = comTime
                //        };
                //        //添加库存箱码明细
                //        Db.Insertable(box2).ExecuteCommand();
                //        #endregion
                //    }
                //    if (boxFullQty > bNum)
                //    {
                //        throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                //    }
                //}
                //Db.Updateable(boxInfoList).ExecuteCommand();
                                IsDel = "0",
                                CreateUser = 0,
                                CreateTime = comTime
                            };
                //// 更新托盘绑定表
                //bind.Qty += factQty;
                            //维护库存明细货主/供应商信息
                            if (arrNotice.Type == "0" || arrNotice.Type == "2" || arrNotice.Type == "4" || arrNotice.Type == "6" || arrNotice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                            {
                                sd1.OwnerNo = arrNotice.CustomerNo;//货主编码
                                sd1.OwnerName = arrNotice.CustomerName;//货主名称
                            }
                            else if (arrNotice.Type == "1" || arrNotice.Type == "5")//1:采购入库,2:其它入库
                            {
                                sd1.SupplierNo = arrNotice.CustomerNo;//供应商编码
                                sd1.SupplierName = arrNotice.CustomerName;//供应商名称
                            }
                            if (quality != null)
                            {
                                //修改合格不合格数量
                                if (quality.IsQualified == "1") //合格
                                {
                                    //增加合格数量
                                    quality.PassQty += bind.Qty;
                                    sd1.InspectStatus = "1";
                                }
                                else if (quality.IsQualified == "0") //不合格
                                {
                                    //增加不合格数量
                                    quality.FailQty += bind.Qty;
                                    sd1.InspectStatus = "2";
                                }
                                Db.Updateable(quality).ExecuteCommand(); //修改质检信息
                            }
                            //添加库存明细
                            sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
                        }
                        #endregion
                ////if (bind.FullQty < bind.Qty && isTextTable == 0)
                //if (bind.FullQty < bind.Qty)
                //{
                //    throw new Exception("托盘绑定数量已超出该物料包装数量");
                //}
                        // 更改箱支关系表
                        decimal factQty = 0.00m;//托盘总数量
                        var isSample = "0";//是否取样
                        var sampleQty = 0m;//取样数量
                //if (bind.FullQty == bind.Qty)
                //{
                //    bind.BitPalletMark = "0";
                //    sd1.BitPalletMark = "0";
                //}
                ////if (bind.Qty > pNum && isTextTable == 0)
                //if (bind.Qty > pNum)
                //{
                //    throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                //}
                        //标签组托
                        var boxGroup = notBoxInfoList.GroupBy(m => m.BoxNo).ToList();
                        foreach (var g in boxGroup)
                        {
                            decimal boxFullQty = 0;//箱内总数量
                            foreach (var box in g)
                            {
                                if (box.BindNo != null && box.BindNo != 0)
                                {
                                    continue;
                                }
                                //箱内物料批次与单据明细不符合
                                if (box.SkuNo != detail.SkuNo || box.LotNo != model.LotNo)
                                {
                                    throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!");
                                }
                //if (isSample == "1")
                //{
                //    bind.InspectMark = "1";
                //    bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                //}
                //Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                                box.ASNNo = arrDetail.ASNNo;
                                box.ASNDetailNo = arrDetail.Id;
                                box.BindNo = bindId;
                                box.PalletNo = model.PalletNo;
                                box.Status = "2";
                                //box.InspectMark = model.IsSample;  //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                                //box.SamplingQty = 0;    //取样数量  后期业务开发时 接口传值需添加对应字段判断
                                box.CompleteTime = comTime;
                                box.UpdateTime = comTime;
                                box.UpdateUser = userId;
                //#region 入库单及明细
                //decimal addQty = factQty;
                                //box.Qty = box.Qty;
                                //box.BitBoxMark = box.Qty == box.FullQty ? "0" : "1";
                //detail.FactQty += addQty;//已组数量
                //detail.CompleteQty += addQty;//完成数量
                //if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
                //{
                //    detail.IsSampling = "1";
                //}
                //detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
                //if (detail.CompleteQty >= detail.Qty)
                //{
                //    detail.Status = "2";
                //    detail.CompleteTime = comTime;
                //}
                //detail.UpdateUser = userId;
                //detail.UpdateTime = comTime;
                ////更新入库单明细
                //Db.Updateable(detail).ExecuteCommand();
                                factQty += box.Qty;
                                boxFullQty += box.Qty;
                                if (box.InspectMark == "1") //判断是否取样
                                {
                                    isSample = "1";
                                    sampleQty += (decimal)box.SamplingQty;
                                }
                //notice.UpdateUser = userId;
                //notice.UpdateTime = comTime;
                //if (notice.Status == "0")
                //{
                //    notice.Status = "1";
                //}
                //var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>()
                //                .Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
                //if (asnDetailNum == 0)
                //{
                //    notice.Status = "2";
                //    notice.CompleteTime = comTime;//完成时间
                //}
                ////更新入库单
                //Db.Updateable(notice).ExecuteCommand();
                //#endregion
                                #region 库存箱码明细
                                var box2 = new DataBoxInfo()
                                {
                                    StockDetailId = sdId1,
                                    BindNo = bind.Id,
                                    BoxNo = box.BoxNo,
                                    BoxNo2 = box.BoxNo2,
                                    BoxNo3 = box.BoxNo3,
                                    PalletNo = box.PalletNo,
                                    PalletNo2 = box.PalletNo2,
                                    PalletNo3 = box.PalletNo3,
                                    Qty = box.Qty,
                                    FullQty = box.FullQty,
                                    Status = "2",//0:未组托  1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
                                    LotNo = box.LotNo,
                                    LotText = box.LotText,
                                    SkuNo = box.SkuNo,
                                    SkuName = box.SkuName,
                                    Standard = sku.Standard,
                                    ProductionTime = box.ProductionTime,
                                    SupplierLot = box.SupplierLot,
                                    InspectStatus = sku.IsInspect,
                                    InspectMark = box.InspectMark,
                                    BitBoxMark = box.BitBoxMark,
                                    ExpirationTime = box.ExpirationTime,
                //#region 库存明细
                //sd1.Qty = bind.Qty;
                ////更改库存明细数量
                //Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
                //#endregion
                                    CreateUser = 0,
                                    CreateTime = comTime
                                };
                                //添加库存箱码明细
                                Db.Insertable(box2).ExecuteCommand();
                                #endregion
                            }
                            if (boxFullQty > bNum)
                            {
                                throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!");
                            }
                        }
                        //更改箱支关系表信息
                        Db.Updateable(boxInfoList).ExecuteCommand();
                //#region 库存
                //var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
                //if (dataStock != null)
                //{
                //    dataStock.Qty += factQty;
                        // 更新托盘绑定表
                        bind.Qty += factQty;
                //    if (bind.InspectMark == "1")
                //    {
                //        dataStock.IsSampling = bind.InspectMark;
                //    }
                //    Db.Updateable(dataStock).ExecuteCommand();
                //}
                //else
                //{
                //    var stock = new DataStock()
                //    {
                //        SkuNo = sku.SkuNo,
                //        SkuName = sku.SkuName,
                //        Standard = sku.Standard,
                //        LotNo = bind.LotNo,
                //        LotText = bind.LotText,
                //        Qty = bind.Qty,
                //        LockQty = 0,
                //        FrozenQty = 0,
                //        IsSampling = bind.InspectMark,
                //        IsDel = "0",
                //        CreateUser = userId,
                //        CreateTime = comTime
                //    };
                //    //维护库存货主信息
                //    if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                //    {
                //        stock.OwnerNo = notice.CustomerNo;//货主编码
                //        stock.OwnerName = notice.CustomerName;//货主名称
                //    }
                //    Db.Insertable(stock).ExecuteCommand();
                //}
                //#endregion
                        if (bind.FullQty < bind.Qty)
                        {
                            throw new Exception("托盘绑定数量已超出该物料包装数量");
                        }
                //#region 质检请验
                //if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
                //{
                //    var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
                //    if (qualityRequest == null)
                //    {
                //        string qcNo = new Common().GetMaxNo("QC");
                //        qualityRequest = new BllQualityInspectionRequest();
                //        qualityRequest.QcNo = qcNo;
                //        qualityRequest.Status = "0";
                //        qualityRequest.SkuNo = sku.SkuNo;
                //        qualityRequest.SkuName = sku.SkuName;
                //        qualityRequest.LotNo = bind.LotNo;
                //        qualityRequest.SupplierLot = bind.SupplierLot;
                //        qualityRequest.Qty = detail.Qty;
                //        qualityRequest.SamplingQty = 0;
                //        qualityRequest.ASNNo = detail.ASNNo;
                //        qualityRequest.CreateUser = userId;
                //        qualityRequest.CreateTime = comTime;
                //        //添加质检请验单
                //        Db.Insertable(qualityRequest).ExecuteCommand();
                //    }
                //}
                //#endregion
                        if (bind.FullQty == bind.Qty)
                        {
                            bind.BitPalletMark = "0";
                            sd1.BitPalletMark = "0";
                        }
                        if (bind.Qty > pNum)
                        {
                            throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                        }
                        if (isSample == "1")
                        {
                            bind.InspectMark = "1";
                            bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                        }
                        Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                        #region 入库单及明细
                        arrDetail.FactQty += factQty;//已组数量
                        arrDetail.CompleteQty += factQty;//完成数量
                        if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
                        {
                            arrDetail.IsSampling = "1";
                        }
                        arrDetail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
                        if (arrDetail.CompleteQty >= detail.Qty)
                        {
                            arrDetail.Status = "2";
                            arrDetail.CompleteTime = comTime;
                        }
                        arrDetail.UpdateUser = userId;
                        arrDetail.UpdateTime = comTime;
                        //更新入库单明细
                        Db.Updateable(arrDetail).ExecuteCommand();
                        arrNotice.UpdateUser = userId;
                        arrNotice.UpdateTime = comTime;
                        if (arrNotice.Status == "0")
                        {
                            arrNotice.Status = "1";
                        }
                        var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == arrDetail.ASNNo && m.Status != "2");
                        if (asnDetailNum == 0)
                        {
                            arrNotice.Status = "2";//执行完成
                            arrNotice.CompleteTime = comTime;//完成时间
                        }
                        //更新入库单
                        Db.Updateable(arrNotice).ExecuteCommand();
                        #endregion
                        #region 库存明细
                        sd1.Qty = bind.Qty;
                        //更改库存明细数量
                        Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
                        #endregion
                        #region 库存
                        var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
                        if (dataStock != null)
                        {
                            dataStock.Qty += factQty;
                            if (bind.InspectMark == "1")
                            {
                                dataStock.IsSampling = bind.InspectMark;
                            }
                            Db.Updateable(dataStock).ExecuteCommand();
                        }
                        else
                        {
                            var stock = new DataStock()
                            {
                                SkuNo = sku.SkuNo,
                                SkuName = sku.SkuName,
                                Standard = sku.Standard,
                                LotNo = bind.LotNo,
                                LotText = bind.LotText,
                                Qty = bind.Qty,
                                LockQty = 0,
                                FrozenQty = 0,
                                IsSampling = bind.InspectMark,
                                IsDel = "0",
                                CreateUser = userId,
                                CreateTime = comTime
                            };
                            //维护库存货主信息
                            if (arrNotice.Type == "0" || arrNotice.Type == "2" || arrNotice.Type == "4" || arrNotice.Type == "6" || arrNotice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                            {
                                stock.OwnerNo = notice.CustomerNo;//货主编码
                                stock.OwnerName = notice.CustomerName;//货主名称
                            }
                            Db.Insertable(stock).ExecuteCommand();
                        }
                        #endregion
                        #region 质检请验
                        if ((arrNotice.Type == "1" || arrNotice.Type == "4" || arrNotice.Type == "5") && sku.IsInspect != "1")
                        {
                            var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
                            if (qualityRequest == null)
                            {
                                string qcNo = new Common().GetMaxNo("QC");
                                qualityRequest = new BllQualityInspectionRequest();
                                qualityRequest.QcNo = qcNo;
                                qualityRequest.Status = "0";
                                qualityRequest.SkuNo = sku.SkuNo;
                                qualityRequest.SkuName = sku.SkuName;
                                qualityRequest.LotNo = bind.LotNo;
                                qualityRequest.SupplierLot = bind.SupplierLot;
                                qualityRequest.Qty = arrDetail.Qty;
                                qualityRequest.SamplingQty = 0;
                                qualityRequest.ASNNo = arrDetail.ASNNo;
                                qualityRequest.CreateUser = userId;
                                qualityRequest.CreateTime = comTime;
                                //添加质检请验单
                                Db.Insertable(qualityRequest).ExecuteCommand();
                            }
                        }
                        #endregion
                    }
                }
                // 更改托盘使用状态
                var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
                //添加托盘记录表数据
                sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
                Db.Ado.ExecuteCommand(sqlStr);
                //new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
                new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId);
                //提交事务
                Db.CommitTran();
            }
            catch (Exception e)
            {
                //回滚事务
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        //JC26绑定托盘 不贴标物料
        public void BindPalletNoPasteCode(PdaPalletBindVm model, int userId)
        {
                #region 判断
                //0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库
                var TypeLot = "5, 6";
                if (string.IsNullOrEmpty(model.AsnNo))
                {
                    throw new Exception("单据号不可为空!");
                }
                if (model.AsnDetailId == null || model.AsnDetailId == 0)
                {
                    throw new Exception("物料不可为空!");
                }
                if (string.IsNullOrEmpty(model.PalletNo))
                {
                    throw new Exception("托盘号不可为空!");
                }
                if (model.SkuQty < 0)
                {
                    throw new Exception("物料数量不能小于0!");
                }
                //根据单据号获取入库单总单
                var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
                if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
                {
                    throw new Exception("该单据已关单!");
                }
            #region 判断
                if (string.IsNullOrEmpty(model.LotNo))
            //0:成品入库 1:采购入库 3:退货入库 4:车间余料入库 5:其它入库 6:代储入库
            var TypeLot = "5, 6";
            if (string.IsNullOrEmpty(model.AsnNo))
            {
                throw new Exception("单据号不可为空!");
            }
            if (model.AsnDetailId == null || model.AsnDetailId == 0)
            {
                throw new Exception("物料不可为空!");
            }
            if (string.IsNullOrEmpty(model.PalletNo))
            {
                throw new Exception("托盘号不可为空!");
            }
            if (model.SkuQty < 0)
            {
                throw new Exception("物料数量不能小于0!");
            }
            //根据单据号获取入库单总单
            var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == model.AsnNo);
            if (notice.Status != "0" && notice.Status != "1" && notice.Status != "2")
            {
                throw new Exception("该单据已关单!");
            }
            if (string.IsNullOrEmpty(model.LotNo))
            {
                throw new Exception("物料批次不为空!");
            }
            else
            {
                //从物料名称-批次中取出批次
                int indexOfDash = model.LotNo.IndexOf("-");
                if (indexOfDash != -1)
                {
                    throw new Exception("物料批次不为空!");
                    model.LotNo = model.LotNo.Substring(indexOfDash + 1);
                }
                else
                {
                    //从物料名称-批次中取出批次
                    int indexOfDash = model.LotNo.IndexOf("-");
                    if (indexOfDash != -1)
                    if (!TypeLot.Contains(notice.Type))
                    {
                        model.LotNo = model.LotNo.Substring(indexOfDash + 1);
                        throw new Exception("物料批次不可为空!");
                    }
                    else
                    {
                        if (!TypeLot.Contains(notice.Type))
                        {
                            throw new Exception("物料批次不可为空!");
                        }
                        model.LotNo = "";
                    model.LotNo = "";
                }
            }
            //int isTextTable = model.TableType;
            #endregion
            var comTime = DateTime.Now;
            //托盘是否存在
            var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
            if (pallet == null)
            {
                throw new Exception("未查询到托盘信息,请核实!");
            }
            // 验证入库单明细是否存在
            var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo));
            if (detail == null)
            {
                throw new Exception("当前物料及批次与单据无关联,请核实!");
            }
            //判断托盘是否在库外
            var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
            if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo))
            {
                throw new Exception("该托盘已有储位信息,请核实!");
            }
            if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo))
            {
                throw new Exception("该托盘在库存已有其它物料批次信息,请核实!");
            }
            #region 包装
            var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
            var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo);    // liudl 由Sku包装编号变更为入库单明细包装编号
            var pNum = 0;//托盘物品数量
            var bNum = 0;//箱码物品数量
            if (pack == null)
            {
                throw new Exception("获取物料包装失败,请核实!");
            }
            if (pack.L5Num.HasValue)
            {
                pNum = (int)pack.L5Num;
                bNum = (int)pack.L4Num;
            }
            else if (pack.L4Num.HasValue)
            {
                pNum = (int)pack.L4Num;
                bNum = (int)pack.L3Num;
            }
            else if (pack.L3Num.HasValue)
            {
                pNum = (int)pack.L3Num;
                bNum = (int)pack.L2Num;
            }
            else if (pack.L2Num.HasValue)
            {
                pNum = (int)pack.L2Num;
                bNum = (int)pack.L1Num;
            }
            else if (pack.L1Num.HasValue)
            {
                pNum = (int)pack.L1Num;
                bNum = (int)pack.L1Num;
            }
            if (pNum == 0 || bNum == 0)
            {
                throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
            }
            #endregion
            #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
            var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
            if (palletBind != null)
            {
                var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
                if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo)))
                {
                    var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
                    if (funSetting == null || funSetting.IsEnable == "OFF")
                    {
                        throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
                    }
                }
            }
            #endregion
            //liudl  && m.Status != "2"  组盘既入库完成无需根据托盘状态判断
            var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
            var bindId = 0;
            if (bind == null)
            {
                bind = new BllPalletBind
                {
                    ASNNo = model.AsnNo,
                    ASNDetailNo = (int)model.AsnDetailId,
                    PalletNo = model.PalletNo,
                //int isTextTable = model.TableType;
                #endregion
                    Qty = model.SkuQty,
                    FullQty = pNum,
                    Status = "2",//入库完成
                    Type = "0",
                    LotNo = model.LotNo,
                    LotText = detail.LotText,
                    SupplierLot = detail.SupplierLot,
                    //InspectMark = model.IsSample,      //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                    //SamplingQty = 0,     //取样数量  后期业务开发时 接口传值需添加对应字段判断
                    BitPalletMark = "1",
                    IsBale = "0",
                    IsBelt = "0",
                    CreateUser = userId,
                    Demo = model.Demo,
                var comTime = DateTime.Now;
                };
                // 插入托盘绑定表
                bindId = Db.Insertable(bind).ExecuteReturnIdentity();
            }
            else
            {
                bindId = bind.Id;
                bind.Qty += model.SkuQty;
            }
            if (bind.Qty < 0)
            {
                throw new Exception("组盘数量不能小于0");
            }
                //托盘是否存在
                var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (pallet == null)
                {
                    throw new Exception("未查询到托盘信息,请核实!");
                }
                // 验证入库单明细是否存在
                var detail = Db.Queryable<BllArrivalNoticeDetail>().First(m => m.IsDel == "0" && m.Id == model.AsnDetailId && m.ASNNo == model.AsnNo && m.LotNo.Contains(model.LotNo));
                if (detail == null)
                {
                    throw new Exception("当前物料及批次与单据无关联,请核实!");
                }
                //判断托盘是否在库外
                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == model.PalletNo);
                if (stockDetail != null && !string.IsNullOrEmpty(stockDetail.WareHouseNo))
                {
                    throw new Exception("该托盘已有储位信息,请核实!");
                }
                if (stockDetail != null && (stockDetail.SkuNo != detail.SkuNo || stockDetail.LotNo != model.LotNo))
                {
                    throw new Exception("该托盘在库存已有其它物料批次信息,请核实!");
                }
            #region 库存明细
            //获取该批次最终质检结果
            BllQualityInspect quality = new BllQualityInspect();
            //判断是否为退货入库单
            if (notice.Type == "3")
            {
                quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
            }
            else
            {
                quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
            }
            var tags = "0";
            if (notice.Type == "3" || notice.Type == "4")
            {
                tags = "1";
            }
                #region 包装
                var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == detail.SkuNo);
                var pack = Db.Queryable<SysPackag>().First(m => m.IsDel == "0" && m.PackagNo == detail.PackagNo);    // liudl 由Sku包装编号变更为入库单明细包装编号
                var pNum = 0;//托盘物品数量
                var bNum = 0;//箱码物品数量
                if (pack == null)
                {
                    throw new Exception("获取物料包装失败,请核实!");
                }
                if (pack.L5Num.HasValue)
                {
                    pNum = (int)pack.L5Num;
                    bNum = (int)pack.L4Num;
                }
                else if (pack.L4Num.HasValue)
                {
                    pNum = (int)pack.L4Num;
                    bNum = (int)pack.L3Num;
                }
                else if (pack.L3Num.HasValue)
                {
                    pNum = (int)pack.L3Num;
                    bNum = (int)pack.L2Num;
                }
                else if (pack.L2Num.HasValue)
                {
                    pNum = (int)pack.L2Num;
                    bNum = (int)pack.L1Num;
                }
                else if (pack.L1Num.HasValue)
                {
                    pNum = (int)pack.L1Num;
                    bNum = (int)pack.L1Num;
                }
                if (pNum == 0 || bNum == 0)
                {
                    throw new Exception($"绑定失败,{detail.SkuNo}物品包装未找到!");
                }
                #endregion
                #region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
                var palletBind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNNo == model.AsnNo && m.PalletNo == model.PalletNo && m.ASNDetailNo != model.AsnDetailId);
                if (palletBind != null)
                {
                    var box = Db.Queryable<BllBoxInfo>().First(m => m.IsDel == "0" && m.BindNo == palletBind.Id && m.BitBoxMark == "0");
                    if (box != null && (box.SkuNo != detail.SkuNo || !detail.LotNo.Contains(box.LotNo)))
                    {
                        var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
                        if (funSetting == null || funSetting.IsEnable == "OFF")
                        {
                            throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
                        }
                    }
                }
                #endregion
                //liudl  && m.Status != "2"  组盘既入库完成无需根据托盘状态判断
                var bind = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0" && m.ASNDetailNo == model.AsnDetailId && m.PalletNo == model.PalletNo);
                var bindId = 0;
                if (bind == null)
                {
                    bind = new BllPalletBind
                    {
                        ASNNo = model.AsnNo,
                        ASNDetailNo = (int)model.AsnDetailId,
                        PalletNo = model.PalletNo,
                        Qty = model.SkuQty,
                        FullQty = pNum,
                        Status = "2",//入库完成
                        Type = "0",
                        LotNo = model.LotNo,
                        LotText = detail.LotText,
                        SupplierLot = detail.SupplierLot,
                        //InspectMark = model.IsSample,      //是否取样托盘  后期业务开发时 接口传值需添加对应字段判断
                        //SamplingQty = 0,     //取样数量  后期业务开发时 接口传值需添加对应字段判断
                        BitPalletMark = "1",
                        IsBale = "0",
                        IsBelt = "0",
                        CreateUser = userId,
                        Demo = model.Demo,
                    };
                    // 插入托盘绑定表
                    bindId = Db.Insertable(bind).ExecuteReturnIdentity();
                }
                else
                {
                    bindId = bind.Id;
                    bind.Qty += model.SkuQty;
                }
                if (bind.Qty < 0)
                {
                    throw new Exception("组盘数量不能小于0");
                }
                #region 库存明细
                //获取该批次最终质检结果
                BllQualityInspect quality = new BllQualityInspect();
                //判断是否为退货入库单
                if (notice.Type == "3")
                {
                    quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.ASNNo == detail.ASNNo && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
                }
                else
                {
                    quality = Db.Queryable<BllQualityInspect>().Where(a => a.IsDel == "0" && a.SkuNo == detail.SkuNo && a.LotNo == detail.LotNo).OrderByDescending(a => a.CreateTime).First();
                }
                var tags = "0";
                if (notice.Type == "3" || notice.Type == "4")
                {
                    tags = "1";
                }
                // 判断库存明细是否已有此托盘信息
                var sd1 = Db.Queryable<DataStockDetail>()
                    .First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo && m.LotNo == bind.LotNo);
                var sdId1 = 0;
                if (sd1 != null)
                {
                    sdId1 = sd1.Id;
                    // 库存已存在 更新数据
                    sd1.Qty = bind.Qty;
                    sd1.CompleteTime = comTime;
                    sd1.UpdateUser = userId;
                    sd1.UpdateTime = comTime;
                    Db.Updateable(sd1).ExecuteCommand(); //修改质检信息
                }
                else
                {
                    // 库存不存在 插入数据
                    sd1 = new DataStockDetail()
                    {
                        LotNo = bind.LotNo,
                        LotText = bind.LotText,
                        SupplierLot = bind.SupplierLot,
                        SkuNo = sku.SkuNo,
                        SkuName = sku.SkuName,
                        Standard = sku.Standard,
                        Qty = bind.Qty,
                        LockQty = 0,
                        FrozenQty = 0,
                        InspectQty = 0,
                        ASNNo = bind.ASNNo,
                        ASNDetailNo = bind.ASNDetailNo,
                        WareHouseNo = "",//所属仓库
                        RoadwayNo = "",//所属巷道
                        AreaNo = "",//所属区域
                        LocatNo = "",//储位地址
                        PalletNo = bind.PalletNo,
                        PalletNo2 = bind.PalletNo2,
                        PalletNo3 = bind.PalletNo3,
                        PalletTags = tags,
                        CompleteTime = comTime,
                        ProductionTime = bind.ProductionTime,
                        ExpirationTime = bind.ExpirationTime,
                        Status = "0",
                        InspectMark = bind.InspectMark,
                        InspectStatus = sku.IsInspect,
                        BitPalletMark = bind.BitPalletMark,
                        PackagNo = detail.PackagNo,                    //liudl 由sku的包装编号变为入库单明细的包装编码
                        IsBale = bind.IsBale,
                        IsBelt = bind.IsBelt,
                        IsDel = "0",
                        CreateUser = 0,
                        CreateTime = comTime
                    };
                    //维护库存明细货主/供应商信息
                    if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                    {
                        sd1.OwnerNo = notice.CustomerNo;//货主编码
                        sd1.OwnerName = notice.CustomerName;//货主名称
                    }
                    else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
                    {
                        sd1.SupplierNo = notice.CustomerNo;//供应商编码
                        sd1.SupplierName = notice.CustomerName;//供应商名称
                    }
                    if (quality != null)
                    {
                        //修改合格不合格数量
                        if (quality.IsQualified == "1") //合格
                        {
                            //增加合格数量
                            quality.PassQty += bind.Qty;
                            sd1.InspectStatus = "1";
                        }
                        else if (quality.IsQualified == "0") //不合格
                        {
                            //增加不合格数量
                            quality.FailQty += bind.Qty;
                            sd1.InspectStatus = "2";
                        }
                        Db.Updateable(quality).ExecuteCommand(); //修改质检信息
                    }
                    //添加库存明细
                    sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
                }
                #endregion
                // 更改箱支关系表
                var isSample = "0";//是否取样
                var sampleQty = 0m;//取样数量
                //if (bind.FullQty < bind.Qty && isTextTable == 0)
                if (bind.FullQty < bind.Qty)
                {
                    throw new Exception("托盘绑定数量已超出该物料包装数量");
                }
                if (bind.FullQty == bind.Qty)
                {
                    bind.BitPalletMark = "0";
                    sd1.BitPalletMark = "0";
                }
                //if (bind.Qty > pNum && isTextTable == 0)
                if (bind.Qty > pNum)
                {
                    throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
                }
                if (isSample == "1")
                {
                    bind.InspectMark = "1";
                    bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                }
                Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
                #region 入库单及明细
                decimal addQty = model.SkuQty;
                detail.FactQty += addQty;//已组数量
                detail.CompleteQty += addQty;//完成数量
                if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
                {
                    detail.IsSampling = "1";
                }
                detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
                if (detail.CompleteQty >= detail.Qty)
                {
                    detail.Status = "2";
                    detail.CompleteTime = comTime;
                }
                detail.UpdateUser = userId;
                detail.UpdateTime = comTime;
                //更新入库单明细
                Db.Updateable(detail).ExecuteCommand();
                notice.UpdateUser = userId;
                notice.UpdateTime = comTime;
                if (notice.Status == "0")
                {
                    notice.Status = "1";
                }
                var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>()
                                .Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
                if (asnDetailNum == 0)
                {
                    notice.Status = "2";
                    notice.CompleteTime = comTime;//完成时间
                }
                //更新入库单
                Db.Updateable(notice).ExecuteCommand();
                #endregion
                #region 库存明细
            // 判断库存明细是否已有此托盘信息
            var sd1 = Db.Queryable<DataStockDetail>()
                .First(m => m.IsDel == "0" && m.ASNDetailNo == bind.ASNDetailNo && m.PalletNo == model.PalletNo && m.LotNo == bind.LotNo);
            var sdId1 = 0;
            if (sd1 != null)
            {
                sdId1 = sd1.Id;
                // 库存已存在 更新数据
                sd1.Qty = bind.Qty;
                //更改库存明细数量
                Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
                #endregion
                sd1.CompleteTime = comTime;
                sd1.UpdateUser = userId;
                sd1.UpdateTime = comTime;
                #region 库存
                var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
                if (dataStock != null)
                Db.Updateable(sd1).ExecuteCommand(); //修改质检信息
            }
            else
            {
                // 库存不存在 插入数据
                sd1 = new DataStockDetail()
                {
                    dataStock.Qty += model.SkuQty;
                    LotNo = bind.LotNo,
                    LotText = bind.LotText,
                    SupplierLot = bind.SupplierLot,
                    SkuNo = sku.SkuNo,
                    SkuName = sku.SkuName,
                    Standard = sku.Standard,
                    Qty = bind.Qty,
                    LockQty = 0,
                    FrozenQty = 0,
                    InspectQty = 0,
                    ASNNo = bind.ASNNo,
                    ASNDetailNo = bind.ASNDetailNo,
                    WareHouseNo = "",//所属仓库
                    RoadwayNo = "",//所属巷道
                    AreaNo = "",//所属区域
                    LocatNo = "",//储位地址
                    PalletNo = bind.PalletNo,
                    PalletNo2 = bind.PalletNo2,
                    PalletNo3 = bind.PalletNo3,
                    PalletTags = tags,
                    CompleteTime = comTime,
                    ProductionTime = bind.ProductionTime,
                    ExpirationTime = bind.ExpirationTime,
                    Status = "0",
                    InspectMark = bind.InspectMark,
                    InspectStatus = sku.IsInspect,
                    BitPalletMark = bind.BitPalletMark,
                    PackagNo = detail.PackagNo,                    //liudl 由sku的包装编号变为入库单明细的包装编码
                    IsBale = bind.IsBale,
                    IsBelt = bind.IsBelt,
                    if (bind.InspectMark == "1")
                    {
                        dataStock.IsSampling = bind.InspectMark;
                    }
                    Db.Updateable(dataStock).ExecuteCommand();
                }
                else
                    IsDel = "0",
                    CreateUser = 0,
                    CreateTime = comTime
                };
                //维护库存明细货主/供应商信息
                if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                {
                    var stock = new DataStock()
                    {
                        SkuNo = sku.SkuNo,
                        SkuName = sku.SkuName,
                        Standard = sku.Standard,
                        LotNo = bind.LotNo,
                        LotText = bind.LotText,
                        Qty = bind.Qty,
                        LockQty = 0,
                        FrozenQty = 0,
                        IsSampling = bind.InspectMark,
                        IsDel = "0",
                        CreateUser = userId,
                        CreateTime = comTime
                    };
                    //维护库存货主信息
                    if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                    {
                        stock.OwnerNo = notice.CustomerNo;//货主编码
                        stock.OwnerName = notice.CustomerName;//货主名称
                    }
                    Db.Insertable(stock).ExecuteCommand();
                    sd1.OwnerNo = notice.CustomerNo;//货主编码
                    sd1.OwnerName = notice.CustomerName;//货主名称
                }
                #endregion
                #region 质检请验
                if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
                else if (notice.Type == "1" || notice.Type == "5")//1:采购入库,2:其它入库
                {
                    var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
                    if (qualityRequest == null)
                    {
                        string qcNo = new Common().GetMaxNo("QC");
                        qualityRequest = new BllQualityInspectionRequest();
                        qualityRequest.QcNo = qcNo;
                        qualityRequest.Status = "0";
                        qualityRequest.SkuNo = sku.SkuNo;
                        qualityRequest.SkuName = sku.SkuName;
                        qualityRequest.LotNo = bind.LotNo;
                        qualityRequest.SupplierLot = bind.SupplierLot;
                        qualityRequest.Qty = detail.Qty;
                        qualityRequest.SamplingQty = 0;
                        qualityRequest.ASNNo = detail.ASNNo;
                        qualityRequest.CreateUser = userId;
                        qualityRequest.CreateTime = comTime;
                        //添加质检请验单
                        Db.Insertable(qualityRequest).ExecuteCommand();
                    }
                    sd1.SupplierNo = notice.CustomerNo;//供应商编码
                    sd1.SupplierName = notice.CustomerName;//供应商名称
                }
                #endregion
                if (quality != null)
                {
                    //修改合格不合格数量
                    if (quality.IsQualified == "1") //合格
                    {
                        //增加合格数量
                        quality.PassQty += bind.Qty;
                        sd1.InspectStatus = "1";
                    }
                    else if (quality.IsQualified == "0") //不合格
                    {
                        //增加不合格数量
                        quality.FailQty += bind.Qty;
                        sd1.InspectStatus = "2";
                    }
                    Db.Updateable(quality).ExecuteCommand(); //修改质检信息
                }
                //添加库存明细
                sdId1 = Db.Insertable(sd1).ExecuteReturnIdentity();
            }
            #endregion
                // 更改托盘使用状态
                var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
                //添加托盘记录表数据
                sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
                Db.Ado.ExecuteCommand(sqlStr);
                new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}的组盘信息", userId);
            // 更改箱支关系表
            var isSample = "0";//是否取样
            var sampleQty = 0m;//取样数量
            //if (bind.FullQty < bind.Qty && isTextTable == 0)
            if (bind.FullQty < bind.Qty)
            {
                throw new Exception("托盘绑定数量已超出该物料包装数量");
            }
            if (bind.FullQty == bind.Qty)
            {
                bind.BitPalletMark = "0";
                sd1.BitPalletMark = "0";
            }
            //if (bind.Qty > pNum && isTextTable == 0)
            if (bind.Qty > pNum)
            {
                throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!");
            }
            if (isSample == "1")
            {
                bind.InspectMark = "1";
                bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
            }
            Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand();
            #region 入库单及明细
            decimal addQty = model.SkuQty;
            detail.FactQty += addQty;//已组数量
            detail.CompleteQty += addQty;//完成数量
            if (isSample == "1") //后期业务开发时 接口传值改为判断是否取样
            {
                detail.IsSampling = "1";
            }
            detail.Status = "1";//0:等待执行 1:正在执行 2:执行完成
            if (detail.CompleteQty >= detail.Qty)
            {
                detail.Status = "2";
                detail.CompleteTime = comTime;
            }
            detail.UpdateUser = userId;
            detail.UpdateTime = comTime;
            //更新入库单明细
            Db.Updateable(detail).ExecuteCommand();
            notice.UpdateUser = userId;
            notice.UpdateTime = comTime;
            if (notice.Status == "0")
            {
                notice.Status = "1";
            }
            var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>()
                            .Count(m => m.IsDel == "0" && m.ASNNo == detail.ASNNo && m.Status != "2");
            if (asnDetailNum == 0)
            {
                notice.Status = "2";
                notice.CompleteTime = comTime;//完成时间
            }
            //更新入库单
            Db.Updateable(notice).ExecuteCommand();
            #endregion
            #region 库存明细
            sd1.Qty = bind.Qty;
            //更改库存明细数量
            Db.Updateable(sd1).Where(m => m.Id == sdId1).ExecuteCommand();
            #endregion
            #region 库存
            var dataStock = Db.Queryable<DataStock>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo);
            if (dataStock != null)
            {
                dataStock.Qty += model.SkuQty;
                if (bind.InspectMark == "1")
                {
                    dataStock.IsSampling = bind.InspectMark;
                }
                Db.Updateable(dataStock).ExecuteCommand();
            }
            else
            {
                var stock = new DataStock()
                {
                    SkuNo = sku.SkuNo,
                    SkuName = sku.SkuName,
                    Standard = sku.Standard,
                    LotNo = bind.LotNo,
                    LotText = bind.LotText,
                    Qty = bind.Qty,
                    LockQty = 0,
                    FrozenQty = 0,
                    IsSampling = bind.InspectMark,
                    IsDel = "0",
                    CreateUser = userId,
                    CreateTime = comTime
                };
                //维护库存货主信息
                if (notice.Type == "0" || notice.Type == "2" || notice.Type == "4" || notice.Type == "6" || notice.Type == "7")//0:成品入库,2:中间品入库,4:车间余料入库,6:代储入库,7:寄存入库
                {
                    stock.OwnerNo = notice.CustomerNo;//货主编码
                    stock.OwnerName = notice.CustomerName;//货主名称
                }
                Db.Insertable(stock).ExecuteCommand();
            }
            #endregion
            #region 质检请验
            if ((notice.Type == "1" || notice.Type == "4" || notice.Type == "5") && sku.IsInspect != "1")
            {
                var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == sku.SkuNo && m.LotNo == bind.LotNo && m.SupplierLot == bind.SupplierLot);
                if (qualityRequest == null)
                {
                    string qcNo = new Common().GetMaxNo("QC");
                    qualityRequest = new BllQualityInspectionRequest();
                    qualityRequest.QcNo = qcNo;
                    qualityRequest.Status = "0";
                    qualityRequest.SkuNo = sku.SkuNo;
                    qualityRequest.SkuName = sku.SkuName;
                    qualityRequest.LotNo = bind.LotNo;
                    qualityRequest.SupplierLot = bind.SupplierLot;
                    qualityRequest.Qty = detail.Qty;
                    qualityRequest.SamplingQty = 0;
                    qualityRequest.ASNNo = detail.ASNNo;
                    qualityRequest.CreateUser = userId;
                    qualityRequest.CreateTime = comTime;
                    //添加质检请验单
                    Db.Insertable(qualityRequest).ExecuteCommand();
                }
            }
            #endregion
            // 更改托盘使用状态
            var sqlStr = $"update SysPallets set Status = '1' where PalletNo = '{model.PalletNo}';";
            //添加托盘记录表数据
            sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);";
            Db.Ado.ExecuteCommand(sqlStr);
            new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}的组盘信息", userId);
        }
        #endregion
@@ -4954,7 +5304,7 @@
        #region JC23取样业务接口
        //获取未组托或已组托的箱码级别
        public BoxInfoDto GetBoxLevel(string boxNo,string boxNo3)
        public BoxInfoDto GetBoxLevel(string boxNo, string boxNo3)
        {
            try
            {
@@ -4974,7 +5324,7 @@
                }
                var str = "0";
                var data = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo && m.Status != "2")
                    .GroupBy(m=>new {m.BoxNo,m.SkuNo,m.SkuName,m.LotNo}).Select(m=>new BoxInfoDto()
                    .GroupBy(m => new { m.BoxNo, m.SkuNo, m.SkuName, m.LotNo }).Select(m => new BoxInfoDto()
                    {
                        SkuNo = m.SkuNo,
                        SkuName = m.SkuName,
@@ -4989,7 +5339,7 @@
                }
                var count = Db.Queryable<BllBoxInfo>().Count(m =>
                    m.IsDel == "0" && m.BoxNo == boxNo && !string.IsNullOrWhiteSpace(m.BoxNo3));
                str = count>0 ? "2" : "1";
                str = count > 0 ? "2" : "1";
                data[0].BoxLevel = str;
                return data[0];
            }
@@ -5020,7 +5370,7 @@
                    throw new Exception("未查询到等待执行的托盘绑定信息");
                }
                if (bindList.Count>1)
                if (bindList.Count > 1)
                {
                    throw new Exception("托盘绑定信息存在多条信息,请核实");
                }
@@ -5067,7 +5417,7 @@
                    throw new Exception("取样数量不能为空");
                }
                if (model.BoxLevel!= "1" && model.BoxLevel != "2")
                if (model.BoxLevel != "1" && model.BoxLevel != "2")
                {
                    throw new Exception("取样标识错误,请刷新页面");
                }
@@ -5114,7 +5464,7 @@
                        {
                            item.Qty -= sampleQty;
                            item.InspectMark = "1";//抽检托标记
                            item.SamplingQty = item.SamplingQty == null? sampleQty: item.SamplingQty + sampleQty;
                            item.SamplingQty = item.SamplingQty == null ? sampleQty : item.SamplingQty + sampleQty;
                        }
                    }
                    Db.Updateable(boxList).ExecuteCommand();
@@ -5128,7 +5478,7 @@
                            throw new Exception("箱码状态已组托,但未查询到托盘绑定信息");
                        }
                        bind.BitPalletMark = "1";
                        bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                        bind.SamplingQty = bind.SamplingQty == null ? sampleQty : bind.SamplingQty + sampleQty;
                        bind.Qty -= sampleQty;
                        bind.InspectMark = "1";
                        Db.Updateable(bind).ExecuteCommand();
@@ -5145,11 +5495,11 @@
                    }
                }
                }
                else if (model.BoxLevel == "1")
                {
                    if (boxList.Count>1)
                    if (boxList.Count > 1)
                    {
                        throw new Exception("一级箱码查询错误,含有多条相同箱码数据");
                    }
@@ -5229,7 +5579,7 @@
                var bind = bindList.First();
                var boxInfoCount = Db.Queryable<BllBoxInfo>().Count(m => m.IsDel == "0" && m.BindNo == bind.Id);
                if (boxInfoCount>0)
                if (boxInfoCount > 0)
                {
                    throw new Exception("当前托盘绑定信息是有箱码的,请在标签页取样");
                }
Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -1227,5 +1227,86 @@
        }
        #endregion
        #region 零箱解绑
        public void LingxingUnbind(string palletNo,string boxNo, int userId)
        {
            try
            {
                if (string.IsNullOrEmpty(palletNo))
                {
                    throw new Exception("托盘号不能为空");
                }
                if (string.IsNullOrEmpty(boxNo))
                {
                    throw new Exception("箱码不能为空");
                }
                //开启事务
                Db.BeginTran();
                var comTime = DateTime.Now;
                //托盘库存明细信息
                var detail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
                if (detail == null)
                {
                    throw new Exception("该托盘库存明细信息不存在");
                }
                //库存箱支明细信息
                var boxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.StockDetailId == detail.Id && w.BoxNo == boxNo).ToList();
                if (boxList.Count <= 0)
                {
                    throw new Exception("该箱码库存箱支信息不存在");
                }
                decimal boxQty = 0;//箱内数量
                foreach (var item in boxList)
                {
                    boxQty += item.Qty;
                    item.StockDetailId = 0;//清空托盘外键
                }
                //更新库存箱支明细表
                Db.Updateable(boxList).ExecuteCommand();
                detail.Qty -= boxQty;//托盘库存数量
                detail.BitPalletMark = "1";//零托标记
                //更新托盘库存表
                Db.Updateable(detail).ExecuteCommand();
                //添加托盘解绑绑定记录
                var unBind = new BllPalletUnbind()
                {
                    UpbindPalletNo = palletNo,
                    BindPalletNo = "",
                    LotNo = detail.LotNo,
                    LotText = detail.LotText,
                    SupplierLot = detail.SupplierLot,
                    SkuNo = detail.SkuNo,
                    SkuName = detail.SkuName,
                    Standard = detail.Standard,
                    Qty = boxQty,
                    PalletNo2 = detail.PalletNo2,
                    PalletNo3 = detail.PalletNo3,
                    BoxNo = boxNo,
                    InspectNo = "",
                    InspectStatus = detail.InspectStatus,
                    IsDel = "0",
                    CreateTime = comTime,
                    CreateUser = userId
                };
                Db.Insertable(unBind).ExecuteCommand();
                //添加操作日志
                new OperationCrServer().AddLogOperationCr("库内作业", "操作日志", boxNo, "编辑", $"零箱解绑:原托盘码:{palletNo}上的箱码{boxNo}解绑", userId);
                //提交事务
                Db.CommitTran();
            }
            catch (Exception e)
            {
                //回滚事务
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        #endregion
    }
}
Wms/WMS.IBLL/IPdaServer/IPdaAsnServer.cs
@@ -58,7 +58,7 @@
        ///// </summary>
        ///// <param name="model"></param>
        ///// <param name="userId"></param>
        //void BindPalletPasteCode(PdaPalletBindVm model, int userId);
        void BindPalletPasteCode(PdaPalletBindVm model, int userId);
        /// <summary>
        /// JC26绑定托盘 不贴标物料
Wms/WMS.IBLL/IPdaServer/IPdaCrServer.cs
@@ -139,5 +139,15 @@
        /// <param name="userId"></param>
        void AgvTransport2(string soNo, string palletNo, string areaNo, int userId);
        #endregion
        #region 零托解绑
        /// <summary>
        /// 零托解绑
        /// </summary>
        /// <param name="palletNo"></param>
        /// <param name="boxNo"></param>
        /// <param name="userId"></param>
        public void LingxingUnbind(string palletNo, string boxNo, int userId);
        #endregion
    }
}
Wms/Wms/Controllers/PdaAsnController.cs
@@ -585,7 +585,14 @@
                {
                    throw new Exception("未获取到用户信息");
                }
                _PdaAsnSvc.BindPalletNoPasteCode(model, int.Parse(UserId));
                if (model.TableType == 0)
                {
                    _PdaAsnSvc.BindPalletPasteCode(model, int.Parse(UserId));
                }
                else if (model.TableType == 1)
                {
                    _PdaAsnSvc.BindPalletNoPasteCode(model, int.Parse(UserId));
                }
                return Ok(new { code = 0, msg = "绑定成功!" });
Wms/Wms/Controllers/PdaCrController.cs
@@ -403,5 +403,39 @@
        }
        #endregion
        #region 零箱解绑
        /// <summary>
        /// 零箱解绑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult LingxingUnbind(PdaPalletUnBindVm model)
        {
            try
            {
                //获取当前登录的用户ID
                var claimsIdentity = this.User.Identity as ClaimsIdentity;
                if (claimsIdentity == null)
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
                if (string.IsNullOrWhiteSpace(userId))
                {
                    return Ok(new { code = 1, msg = "未获取到当前操作人信息" });
                }
                var uId = int.Parse(userId);
                _pdaCrSvc.LingxingUnbind(model.PalletNo, model.BoxNo, uId);
                return Ok(new { data = "", code = 0, msg = "成功" });
            }
            catch (Exception e)
            {
                return Ok(new { data = "", code = 1, msg = $"异常:{e.Message}" });
            }
        }
        #endregion
    }
}