duyongjia
2024-12-27 d3470bb47c0f4627962b270f9667f420e394d0de
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_InboundService/Service/InboundOrderService.cs
@@ -2,6 +2,7 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
@@ -19,7 +20,9 @@
using WIDESEA_IInboundService;
using WIDESEA_IStockService;
using WIDESEA_ITaskInfoRepository;
using WIDESEA_Model;
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.System.Request;
namespace WIDESEA_InboundService
{
@@ -46,6 +49,7 @@
            WebResponseContent content = new WebResponseContent();
            try
            {
                materielGroupDTO.OrderNo = GetOrderNo();
                Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
                (bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, stockInfo);
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
@@ -54,7 +58,7 @@
                    stockInfo = new Dt_StockInfo();
                    stockInfo.PalletCode = materielGroupDTO.PalletCode;
                    stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
                    stockInfo.Creater = "System";
                    stockInfo.Creater = "立库WMS";
                    stockInfo.Details = new List<Dt_StockInfoDetail>();
                   
                }
@@ -66,13 +70,29 @@
                    if(labmaster == null)
                    {
                        //通过条码接口同步条码主数据
                        _sys_JobService.GetLabMaster(lablel);
                        labmaster = _labelMasterRepository.QueryFirst(x => x.LABEL_NO == lablel);
                        if (labmaster == null)
                        var res= _sys_JobService.GetLabMaster(lablel);
                        if (res != null && res.Status)
                        {
                            notExistLabels.Add(labmaster);
                            labmaster = _labelMasterRepository.QueryFirst(x => x.LABEL_NO == lablel);
                            if (labmaster == null)
                            {
                                notExistLabels.Add(labmaster);
                            }
                        }
                        else
                        {
                          return  content = WebResponseContent.Instance.Error("组盘条码在上游WMS系统中不存在!");
                        }
                    } 
                    if(labmaster!=null)
                    {
                        //主数据条码状态允许组盘:01已收料待质检,02已收料无需质检,03待进仓已质检,09已下架;
                        //主数据条码状态不允许组盘:00创建,04已质检待退货,05收料房退货,06库房退货,07已进仓,08已上架,10已出库,11已冻结,12已锁定,20关闭的;
                        if (labmaster.LABEL_STATUS=="00"|| labmaster.LABEL_STATUS == "04" || labmaster.LABEL_STATUS == "05"|| labmaster.LABEL_STATUS == "06" || labmaster.LABEL_STATUS == "07" || labmaster.LABEL_STATUS == "08" || labmaster.LABEL_STATUS == "10" || labmaster.LABEL_STATUS == "11" || labmaster.LABEL_STATUS == "12" || labmaster.LABEL_STATUS == "20")
                        {
                            return content = WebResponseContent.Instance.Error("主数据条码状态不允许组盘!条码状态:"+ labmaster.LABEL_STATUS);
                        }
                    }
                }
                if (notExistLabels.Count == 0)
                {
@@ -96,7 +116,10 @@
                    content = MaterielGroupUpdateData(stockInfo);
                }
                else
                {
                    content = WebResponseContent.Instance.Error("组盘条码在上游WMS系统中不存在!");
                }
            }
            catch (Exception ex)
@@ -112,6 +135,129 @@
        /// <summary>
        /// ä½™æ–™é€€å›žç»„盘
        /// </summary>
        /// <param name="materielGroupDTO"></param>
        /// <returns></returns>
        public WebResponseContent ReturnMaterielGroup(MaterielGroupDTO materielGroupDTO)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                materielGroupDTO.OrderNo = GetOrderNo();
                Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
                (bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, stockInfo);
                if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
                if (stockInfo == null)
                {
                    stockInfo = new Dt_StockInfo();
                    stockInfo.PalletCode = materielGroupDTO.PalletCode;
                    stockInfo.StockStatus = StockStatusEmun.组盘暂存.ObjToInt();
                    stockInfo.Creater = "立库WMS";
                    stockInfo.Details = new List<Dt_StockInfoDetail>();
                }
                List<Dt_StockInfoDetail> stockInfoDetails = new List<Dt_StockInfoDetail>();
                List<Dt_LabelMaster> notExistLabels = new List<Dt_LabelMaster>();
                foreach (var lablel in materielGroupDTO.SerialNumbers)
                {
                    Dt_LabelMaster labmaster = _labelMasterRepository.QueryFirst(x => x.LABEL_NO == lablel);
                    if (labmaster == null)
                    {
                        //通过条码接口同步条码主数据
                        var res = _sys_JobService.GetLabMaster(lablel);
                        if (res != null && res.Status)
                        {
                            labmaster = _labelMasterRepository.QueryFirst(x => x.LABEL_NO == lablel);
                            if (labmaster == null)
                            {
                                notExistLabels.Add(labmaster);
                            }
                        }
                        else
                        {
                            return content = WebResponseContent.Instance.Error("组盘条码在上游WMS系统中不存在!");
                        }
                    }
                    if (labmaster != null)
                    {
                        //主数据条码状态允许组盘:01已收料待质检,02已收料无需质检,03待进仓已质检,09已下架;
                        //主数据条码状态不允许组盘:00创建,04已质检待退货,05收料房退货,06库房退货,07已进仓,08已上架,10已出库,11已冻结,12已锁定,20关闭的;
                        if (labmaster.LABEL_STATUS == "00" || labmaster.LABEL_STATUS == "04" || labmaster.LABEL_STATUS == "05" || labmaster.LABEL_STATUS == "06" || labmaster.LABEL_STATUS == "07" || labmaster.LABEL_STATUS == "08" || labmaster.LABEL_STATUS == "10" || labmaster.LABEL_STATUS == "11" || labmaster.LABEL_STATUS == "12" || labmaster.LABEL_STATUS == "20")
                        {
                            return content = WebResponseContent.Instance.Error("主数据条码状态不允许组盘!条码状态:" + labmaster.LABEL_STATUS);
                        }
                    }
                }
                if (notExistLabels.Count == 0)
                {
                    foreach (var item in materielGroupDTO.SerialNumbers)
                    {
                        Dt_LabelMaster labmaster = _labelMasterRepository.QueryFirst(x => x.LABEL_NO == item);
                        Dt_StockInfoDetail dt_StockInfoDetail = new Dt_StockInfoDetail();
                        dt_StockInfoDetail.Status = 0;
                        dt_StockInfoDetail.OrderNo = materielGroupDTO.OrderNo;
                        dt_StockInfoDetail.StockId = stockInfo.Id != 0 ? stockInfo.Id : 0;
                        dt_StockInfoDetail.MaterielCode = labmaster.MATNR;
                        dt_StockInfoDetail.MaterielName = labmaster.MAKTX;
                        dt_StockInfoDetail.BatchNo = labmaster.BATCH;
                        dt_StockInfoDetail.SerialNumber = labmaster.LABEL_NO;
                        dt_StockInfoDetail.StockQuantity = int.Parse(labmaster.BOX_QTY);
                        dt_StockInfoDetail.OutboundQuantity = 0;
                        dt_StockInfoDetail.Creater = "System";
                        stockInfoDetails.Add(dt_StockInfoDetail);
                        stockInfo.Details.AddRange(stockInfoDetails);
                    }
                    content = MaterielGroupUpdateData(stockInfo);
                }
                else
                {
                    content = WebResponseContent.Instance.Error("组盘条码在上游WMS系统中不存在!");
                }
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error(ex.Message);
            }
            finally
            {
            }
            return content;
        }
        /// <summary>
        /// æ ¹æ®BYDWMS组盘信息,再生成立库组盘信息
        /// </summary>
        /// <param name="inventoryRequest"></param>
        /// <returns></returns>
        public ReturnInventoryResponse returnInventory(ReturnInventoryRequest inventoryRequest)
        {
            ReturnInventoryResponse response= new ReturnInventoryResponse();
            MaterielGroupDTO materielGroupDTO = new MaterielGroupDTO();
            materielGroupDTO.PalletCode = inventoryRequest.TPNUM;
            materielGroupDTO.OrderNo = inventoryRequest.IZLID; //退货入库指令
            List<string> SerialNumbers = new List<string>();
            foreach (ReturnInventory item in inventoryRequest.DATA)
            {
                SerialNumbers.Add(item.LABEL_NO);
            }
            ReturnMaterielGroup(materielGroupDTO);
            return response;
        }
        /// <summary>
        /// ç”Ÿæˆè®¢å•号
        /// </summary>
        /// <returns></returns>
        public string GetOrderNo()
        {
            DataTable dt = BaseDal.QueryTable("SELECT FORMAT(NEXT VALUE FOR dbo.seqOrderNum, '000000000');");
            return DateTime.Now.ToString("yyyyMMdd") + dt.Rows[0][0].ToString();
        }
        /// <summary>
        /// æ’¤é”€ç»„盘
        /// </summary>
        /// <param name="materielGroupDTO"></param>