Administrator
2024-03-06 65ecd34acf0a3d33e6c1e10c93e351716d749e2f
Wms/WMS.BLL/BllSoServer/ExportNoticeServer.cs
@@ -204,10 +204,18 @@
                {
                    throw new Exception("未查询到单据信息");
                }
                if (notice.Status != "5")
                {
                    throw new Exception("复核失败,单据非关闭状态");
                }
                var detail = Db.Queryable<BllExportNoticeDetail>().Where(m => m.SONo == notice.SONo && m.IsDel == "0").ToList();
                if (detail.Count == 0)
                {
                    throw new Exception("未查询到单据明细信息");
                }
                if (userId == notice.UpdateUser)
                {
                    throw new Exception("复核失败,复核人员和关闭订单人员不能相同!");
                }
                var list = new List<SoDetail>();
                foreach (var d in detail)
@@ -216,7 +224,7 @@
                    {
                        SkuNo = d.SkuNo,
                        LotNo = d.LotNo,
                        Qty = int.Parse(d.CompleteQty.ToString())
                        Qty = (decimal)d.CompleteQty
                    };
                    list.Add(item);
                }
@@ -225,21 +233,25 @@
                    OrderCode = notice.OrderCode,
                    SoDetails = list
                };
                // 通过接口发送至erp
                var jsonData = JsonConvert.SerializeObject(soInfo);
                #region 通过接口发送至erp
                //系统对接后放开
                /*var jsonData = JsonConvert.SerializeObject(soInfo);
                var response = HttpHelper.DoPost(url, jsonData, "出库单完成上传", "ERP");
                //解析返回数据
                var obj = JsonConvert.DeserializeObject<ErpModel>(response);
                var obj = JsonConvert.DeserializeObject<ErpModel>(response);//解析返回数据
                if (obj.Success != 0)
                {
                    throw new Exception("上传失败" + obj.Message);
                }
                }*/
                #endregion
                notice.Status = "6";
                notice.UpdateTime = DateTime.Now;
                notice.UpdateUser = userId;
                notice.CheckTime = DateTime.Now;
                notice.CheckUser = userId;
                Db.Updateable(notice).ExecuteCommand();
                new OperationSOServer().AddLogOperationSo("出库作业", "出库单据", notice.SONo, "复核", $"复核了单据号为{notice.SONo}的单据信息", userId);
                return true;
            }
            catch (Exception e)
@@ -278,7 +290,8 @@
                    .LeftJoin<SysLogisticsInfo>((a, b) => a.LogisticsId == b.Id)
                    .LeftJoin<SysUserInfor>((a, b, c) => a.CreateUser == c.Id)
                    .LeftJoin<SysUserInfor>((a, b, c, d) => a.CreateUser == d.Id)
                    .Select((a, b, c, d) => new ExportNoticeDto()
                    .LeftJoin<SysUserInfor>((a, b, c, d,e) => a.CheckUser == e.Id)
                    .Select((a, b, c, d,e) => new ExportNoticeDto()
                    {
                        Id = a.Id,
                        SONo = a.SONo,
@@ -300,7 +313,10 @@
                        CreateUserName = c.RealName,
                        UpdateUserName = c.RealName,
                        CreateTime = a.CreateTime,
                        UpdateTime = a.UpdateTime
                        UpdateTime = a.UpdateTime,
                        CheckUserName=e.RealName,
                        CheckTime=a.CheckTime
                    })
                    .OrderByDescending(a => a.CreateTime)
                    .ToOffsetPage(page, limit, ref total);
@@ -321,38 +337,41 @@
                var plnList = new List<string>() { "100099" };
                var skuList = new List<string>();
                var sku = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0" && !plnList.Contains(m.SkuNo)); //排除空托盘的物料集合
                var inspectStatus = "1";//库存内物料的质检状态
                var skuTypeC = new List<string>() { "0" };//标准
                var skuTypeY = new List<string>() { "1" };//非标
                if (type == "0" || type == "2") //标准
                string skuType = string.Empty;
                switch (type)//0:原料 1:包材 2:成品 3:耗材 4:半成品
                {
                    inspectStatus = "0";
                    //if (type == "0") //成品
                    //{
                    skuList = sku.Where(m => inspectStatus==m.IsControlled).Select(m => m.SkuNo).ToList();
                    //}
                    //if (type == "1") //原料
                    //{
                    //    skuList = sku.Where(m => skuTypeY.Contains(m.Type)).Select(m => m.SkuNo).ToList();
                    //}
                    case "0"://成品入库
                        skuType = "(2)";
                        break;
                    case "1"://领料出库
                        skuType = "(0,1,3)";
                        break;
                    case "2"://抽检出库
                        skuType = "(2)";
                        break;
                    case "3"://物料取样出库
                        skuType = "(0)";
                        break;
                    case "4"://不合格品出库
                        skuType = "(2)";
                        break;
                    case "5"://中间品出库
                        skuType = "(4)";
                        break;
                    case "6"://代储出库
                        skuType = "(2)";
                        break;
                    case "8"://寄存出库
                        skuType = "(3)";
                        break;
                    default: //其它出库
                        skuType = "(0,1,2,3,4)";
                        break;
                }
                else if (type == "1" || type == "3") //非标
                skuList = sku.Where(m => skuType.Contains(m.Type)).Select(m => m.SkuNo).ToList();
                if (skuList == null)
                {
                    inspectStatus = "1";
                    //if (type == "2") //成品
                    //{
                    skuList = sku.Where(m => inspectStatus==m.IsControlled).Select(m => m.SkuNo).ToList();
                    //}
                    //if (type == "3") //原料
                    //{
                    //    skuList = sku.Where(m => skuTypeY.Contains(m.Type)).Select(m => m.SkuNo).ToList();
                    //}
                }
                else
                {
                    throw new Exception("单据状态有误");
                    throw new Exception("未查到对应出库类型的物料");
                }
                //skuList = sku.Select(m => m.SkuNo).ToList();
                var stockRst = new StockServer();
@@ -1360,7 +1379,7 @@
        #region 下发出库、出库完成、重新下发任务、取消任务、异常处理
        // 下发出库(调用cs接口给他库位地址)
        public List<OutCommandDto> IssueOutHouse(string soNo, string outMode, int userId, string url, out string str)
        public List<OutCommandDto> IssueOutHouse(string soNo, string unstackingMode, string outMode, string loadingAddre, int userId, string url, out string str)
        {
            try
            {
@@ -1390,6 +1409,10 @@
                var outLpnList = list.Select(m => m.PalletNo).ToList();
                //要出库的明细集合
                var outStockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && outLpnList.Contains(m.PalletNo)).ToList();
                //物料编码表
                var skuList = Db.Queryable<SysMaterials>().Where(w => w.IsDel == "0");
                //包装表
                var packagList = Db.Queryable<SysPackag>().Where(w => w.IsDel == "0");
                Db.BeginTran();
                try
                {
@@ -1397,6 +1420,47 @@
                    //循环分配的信息生成出库任务
                    foreach (var item in list)
                    {
                        string toLocation = string.Empty;//目标位置
                        string unstackingMode2 = unstackingMode;//拆垛方式,0:机器人拆垛 1:PDA拆垛
                        #region 判断是否需要拆箱
                        string isChai = "0";//是否需要拆箱,0:否 1:是
                        var skuInfo = skuList.First(w => w.SkuNo == item.SkuNo);
                        if (skuInfo == null)
                        {
                            throw new Exception("物料信息不存在!");
                        }
                        var packagInfo = packagList.First(w => w.PackagNo == skuInfo.PackagNo);
                        if (packagInfo == null)
                        {
                            throw new Exception("包装信息不存在!");
                        }
                        if (packagInfo.L2Name == "箱")
                        {
                            if (item.Qty % (decimal)packagInfo.L2Num != 0)//能整除说明不用拆箱,不能整除说明需要拆箱
                            {
                                isChai = "1";
                                unstackingMode2 = "1";//需要拆箱需走PDA拆垛
                            }
                        }
                        if (isChai == "0")
                        {
                            var boxInfo = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.PalletNo == item.PalletNo && w.BitBoxMark == "1").ToList();
                            if (boxInfo != null)//托盘上有零箱需要拆箱
                            {
                                isChai = "1";
                                unstackingMode2 = "1";//需要拆箱需走PDA拆垛
                            }
                        }
                        #endregion
                        if (unstackingMode2 == "0")//机器人拆垛
                        {
                            toLocation = loadingAddre;//装车口
                        }
                        else //PDA拆垛
                        {
                            toLocation = outMode;//出库口
                        }
                        // 储位号
                        var locateNo = outStockDetail.First(m => m.PalletNo == item.PalletNo).LocatNo;
@@ -1496,7 +1560,7 @@
                                IsSuccess = 0, //是否下发成功 0失败 1成功
                                StartLocat = locate.LocatNo,//起始位置
                                EndLocat = outMode,//目标位置
                                EndLocat = toLocation,//outMode,//目标位置
                                PalletNo = item.PalletNo,//托盘码
                                IsSend = 1,//是否可再次下发
                                IsCancel = 1,//是否可取消
@@ -1504,7 +1568,7 @@
                                Type = "1",//任务类型 0 入库任务 1 出库任务  2 移库任务
                                Status = "0",//任务状态0:等待执行1正在执行2执行完成
                                OrderType = "1",//0 入库单 1 出库单  2 盘点单  3 移库单
                                Msg = "从" + locate.LocatNo + "到" + outMode + "的出库任务", //关键信息
                                Msg = "从" + locate.LocatNo + "到" + toLocation + "的出库任务", //关键信息
                            };
                            Db.Insertable(exTask).ExecuteCommand();
                            logTaskList.Add(exTask);
@@ -1514,7 +1578,7 @@
                                PalletNo = item.PalletNo,//托盘号
                                StartLocate = locate.LocatNo, // 起始位置
                                StartRoadway = locate.RoadwayNo,//其实巷道
                                EndLocate = outMode, // 目标位置
                                EndLocate = toLocation,//outMode, // 目标位置
                                TaskNo = exTask.TaskNo, // 任务号
                                TaskType = "1",// 任务类型 (出库)
                                OutMode = "",  //目标地址
@@ -1548,9 +1612,10 @@
                            item.TaskNo = exTask.TaskNo; // 出库分配信息中更新任务号
                            item.Status = "1"; // 出库分配信息状态改为正在执行 
                            item.OutMode = outMode;//出库口
                            item.UnstackingMode = unstackingMode2;//拆垛方式
                            item.OutMode = unstackingMode2 == "1" ? outMode : "";//出库口
                            item.LoadingAddre = unstackingMode2 == "0" ? loadingAddre : "";//装车口
                            Db.Updateable(item).ExecuteCommand();
                            #endregion
@@ -1591,7 +1656,8 @@
                            }
                            item.TaskNo = taskNo.TaskNo;
                            item.Status = "1"; // 出库分配信息状态改为正在执行 
                            item.OutMode = taskNo.EndLocat;
                            item.OutMode = unstackingMode2 == "1" ? taskNo.EndLocat : "";//出库口
                            item.LoadingAddre = unstackingMode2 == "0" ? taskNo.EndLocat : "";//装车口
                            Db.Updateable(item).ExecuteCommand();
                            flagList.Add(0);
                            #endregion
@@ -2557,6 +2623,7 @@
                    LocatNo = a.LocatNo,
                    RoadwayNo = a.RoadwayNo,
                    PalletNo = a.PalletNo,
                    Demo = a.Demo,
                }).ToList();
                return list;
@@ -2711,5 +2778,64 @@
        #endregion
        /// <summary>
        /// 判断出库是否需要拆箱
        /// </summary>
        /// <param name="soNo"></param>
        /// <returns></returns>
        public string IsNeedUnpack(string soNo)
        {
            string result = "0";//是否需要拆箱,0:否  1:是
            if (string.IsNullOrEmpty(soNo))
            {
                throw new Exception("未找到对应出库单!");
            }
            try
            {
                var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.SONo == soNo);
                if (notice == null)
                {
                    throw new Exception("未找到对应出库单!");
                }
                //物料编码表
                var skuList = Db.Queryable<SysMaterials>().Where(w => w.IsDel == "0");
                //包装表
                var packagList= Db.Queryable<SysPackag>().Where(w => w.IsDel == "0");
                //出库分配信息
                var allotList = Db.Queryable<BllExportAllot>().Where(w => w.IsDel == "0" && w.SONo == soNo).ToList();
                foreach (var item in allotList)
                {
                    var skuInfo = skuList.First(w => w.SkuNo == item.SkuNo);
                    if (skuInfo == null)
                    {
                        throw new Exception("物料信息不存在!");
                    }
                    var packagInfo = packagList.First(w => w.PackagNo == skuInfo.PackagNo);
                    if (packagInfo == null)
                    {
                        throw new Exception("包装信息不存在!");
                    }
                    if (packagInfo.L2Name == "箱")
                    {
                        if (item.Qty % (decimal)packagInfo.L2Num != 0)//能整除说明不用拆箱,不能整除说明需要拆箱
                        {
                            result = "1";//需要拆箱
                            break;
                        }
                    }
                    var boxInfo = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.PalletNo == item.PalletNo && w.BitBoxMark == "1").ToList();
                    if (boxInfo != null)//托盘上有零箱需要拆箱
                    {
                        result = "1";//需要拆箱
                        break;
                    }
                }
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }
}