chengsc
2025-03-17 7642a3e183b5a584d1da5eb6b48e0f9cb2b5c68c
Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Dm;
using Model.ModelDto.BllCheckDto;
using Model.ModelDto.PdaDto;
using SqlSugar;
@@ -1164,5 +1166,88 @@
            }
        }
        #endregion
        #region 箱码拆箱贴标
        /// <summary>
        /// 拆箱添加标签
        /// </summary>
        /// <param name="boxNo"></param>
        /// <param name="devanQty"></param>
        /// <param name="userId"></param>
        public void AddLableByDevanning(string boxNo, decimal devanQty, int userId)
        {
            try
            {
                if (string.IsNullOrEmpty(boxNo))
                {
                    throw new Exception("箱码不能为空");
                }
                //开启事务
                Db.BeginTran();
                //库存箱支明细信息
                var boxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.BoxNo == boxNo).ToList();
                if (boxList.Count != 1)
                {
                    throw new Exception("该箱码信息错误,存在多个此箱码信息");
                }
                var boxInfo = boxList.First();
                if (boxInfo.Qty<=devanQty)
                {
                    throw new Exception("拆箱数量大等于当前箱内数量");
                }
                boxInfo.Qty -= devanQty;
                boxInfo.BitBoxMark = "1";
                //更新箱码库存表
                Db.Updateable(boxInfo).ExecuteCommand();
                var boxStr = boxInfo.BoxNo.Substring(0, boxInfo.BoxNo.Length - 6);//获取箱码前缀-除后六位流水外
                var maxBoxCode = Db.Queryable<BllBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0" && m.Origin == "WMS生成").Max(a => a.BoxNo);
                var boxNoNew = maxBoxCode.Substring(0, maxBoxCode.Length - 6) + (int.Parse(maxBoxCode.Substring(maxBoxCode.Length - 6, 6)) + 1).ToString().PadLeft(6, '0');
                // 添加新箱码信息
                var boxModel = new DataBoxInfo()
                {
                    StockDetailId = boxInfo.StockDetailId,
                    PalletNo = boxInfo.PalletNo,
                    BoxNo = boxNoNew,
                    Qty = devanQty,
                    FullQty = boxInfo.FullQty,
                    Status = "2",//0:未组托  1:已组托 2:已入库 3:已出库 4:已分配 5:已拣货
                    LotNo = boxInfo.LotNo,
                    LotText = boxInfo.LotText,
                    SkuNo = boxInfo.SkuNo,
                    SkuName = boxInfo.SkuName,
                    Standard = boxInfo.Standard,
                    SupplierLot = boxInfo.SupplierLot,
                    InspectStatus = boxInfo.InspectStatus,
                    InspectMark = boxInfo.InspectMark,
                    BitBoxMark = "1",
                    ProductionTime = boxInfo.ProductionTime,
                    ExpirationTime = boxInfo.ExpirationTime,
                    CreateUser = 0,
                    CreateTime = DateTime.Now
                };
                Db.Insertable(boxModel).ExecuteCommand();
                //添加操作日志
                new OperationCrServer().AddLogOperationCr("库内作业", "操作日志", boxNo, "编辑", $"拆箱贴标:原箱码:{boxNo}拆箱,添加新箱码{boxNoNew}", userId);
                //提交事务
                Db.CommitTran();
            }
            catch (Exception e)
            {
                //回滚事务
                Db.RollbackTran();
                throw new Exception(e.Message);
            }
        }
        #endregion
    }
}