wangxinhui
5 天以前 a0a0df2e824b6fe7e5a3c0afce78127fecf84fc9
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Inbound.cs
@@ -1,5 +1,6 @@
using Autofac.Core;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using SqlSugar;
using System;
@@ -21,9 +22,12 @@
using WIDESEA_Core.Helper;
using WIDESEA_DTO;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.ERP;
using WIDESEA_DTO.MES;
using WIDESEA_DTO.Task;
using WIDESEA_External.Model;
using WIDESEA_Model.Models;
using WIDESEA_TaskInfoRepository;
namespace WIDESEA_TaskInfoService
{
@@ -134,7 +138,7 @@
                {
                    return content.Error($"该站点已有未执行的任务");
                }
                if (stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.老厂退库.ObjToInt())
                if (stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.老厂退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.博思通组盘暂存.ObjToInt())
                {
                    return content.Error($"该托盘状态不正确,不可申请入库");
                }
@@ -193,7 +197,7 @@
        /// </summary>
        /// <param name="palletCode">RFID信息</param>
        /// <returns></returns>
        public WebResponseContent YLPurchaseBoxing(string palletCode)
        public WebResponseContent YLPurchaseBoxing(string palletCode, decimal weight = 0, decimal thickness = 0, decimal wide = 0, string stationCode = "")
        {
            WebResponseContent content = new WebResponseContent();
            try
@@ -203,45 +207,217 @@
                    Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.RfidCode == palletCode);
                    if (stockInfoOld != null && stockInfoOld.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                    {
                        UpdateStock(stockInfoOld, weight, thickness, wide);
                        return content.OK($"临时入库{stockInfoOld.RfidCode}");
                    }
                    else if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && stockInfoOld.StockStatus == StockStatusEmun.老厂退库.ObjToInt())
                    else if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && stockInfoOld.StockStatus == StockStatusEmun.出库完成.ObjToInt() && stockInfoOld.IsPick==WhetherEnum.False.ObjToInt() && stationCode.IsNotEmptyOrNull())
                    {
                        return content.OK($"老厂退库{stockInfoOld.RfidCode}");
                        stockInfoOld.StockStatus = StockStatusEmun.老厂退库.ObjToInt();
                        stockInfoOld.IsFull = WhetherEnum.True.ObjToInt();
                        stockInfoOld.StockOutLength = 0;
                        stockInfoOld.WarehouseId = WarehouseEnum.LLDYL.ObjToInt();
                        UpdateStock(stockInfoOld, weight, thickness, wide);
                        return content.OK($"老厂未领料退库{stockInfoOld.RfidCode}");
                    }
                    else if (stockInfoOld != null && stockInfoOld.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && stockInfoOld.StockStatus == StockStatusEmun.老厂退料暂存.ObjToInt() && stationCode.IsNotEmptyOrNull())
                    {
                        stockInfoOld.StockStatus = StockStatusEmun.老厂退库.ObjToInt();
                        stockInfoOld.IsFull = WhetherEnum.True.ObjToInt();
                        stockInfoOld.IsPick = WhetherEnum.False.ObjToInt();
                        stockInfoOld.StockOutLength = 0;
                        stockInfoOld.WarehouseId = WarehouseEnum.LLDYL.ObjToInt();
                        UpdateStock(stockInfoOld, weight, thickness, wide);
                        return content.OK($"老厂领料退库{stockInfoOld.RfidCode}");
                    }
                    else if (stockInfoOld != null)
                    {
                        return content.Error("RFID信息已存在");
                        throw new Exception($"{palletCode}RFID信息已存在");
                    }
                    #region å¤„理采购绑定RFID逻辑
                    Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x => x.InvOrg == MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault();
                    if (yLInboundCache == null)
                    if (stationCode.IsNullOrEmpty())
                    {
                        return content.Error("未找到原料缓存条码信息");
                    }
                    if (yLInboundCache.BindStatus == WhetherEnum.True.ObjToInt())
                    {
                        return content.Error($"原料缓存条码{yLInboundCache.BarCode}已绑定RFID{yLInboundCache.RfidCode}");
                    }
                    else
                    {
                        //获取采购信息
                        Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _purchaseBSTOrderDetailRepository.QueryFirst(x => x.Barcode == yLInboundCache.BarCode);
                        if (purchaseBSTOrderDetail == null)
                        #region å¤„理采购绑定RFID逻辑
                        Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x => x.InvOrg == MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault();
                        if (yLInboundCache == null)
                        {
                            return content.Error($"未找到条码{yLInboundCache.BarCode}采购信息");
                            return content.Error("未找到原料缓存条码信息");
                        }
                        if (purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus != InOrderStatusEnum.未开始.ObjToInt())
                        if (yLInboundCache.BindStatus == WhetherEnum.True.ObjToInt())
                        {
                            return content.Error($"采购{purchaseBSTOrderDetail.Barcode}信息已入库或入库中");
                            return content.Error($"原料缓存条码{yLInboundCache.BarCode}已绑定RFID{yLInboundCache.RfidCode}");
                        }
                        else
                        {
                            purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus = InOrderStatusEnum.入库中.ObjToInt();
                            purchaseBSTOrderDetail.RfidCode = palletCode;
                            Dt_StockInfo ExistStockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == yLInboundCache.BarCode);
                            if (ExistStockInfo != null && ExistStockInfo.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && ExistStockInfo.StockStatus == StockStatusEmun.博思通组盘暂存.ObjToInt())
                            {
                                yLInboundCache.RfidCode = palletCode;
                                yLInboundCache.BindStatus = WhetherEnum.True.ObjToInt();
                                ExistStockInfo.RfidCode = palletCode;
                                _unitOfWorkManage.BeginTran();
                                //更新组盘信息
                                UpdateStock(ExistStockInfo, weight, thickness, wide);
                                _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                                _unitOfWorkManage.CommitTran();
                                return content.OK($"博思通库存转存{ExistStockInfo.RfidCode}");
                            }
                            else if(ExistStockInfo != null && ExistStockInfo.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && ExistStockInfo.StockStatus == StockStatusEmun.组盘暂存.ObjToInt())
                            {
                                //获取采购信息
                                Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _inboundRepository.PurchaseBSTOrderDetailRepository.QueryFirst(x => x.Barcode == yLInboundCache.BarCode);
                                yLInboundCache.RfidCode = palletCode;
                                yLInboundCache.BindStatus = WhetherEnum.True.ObjToInt();
                                ExistStockInfo.RfidCode = palletCode;
                                purchaseBSTOrderDetail.RfidCode= palletCode;
                                _unitOfWorkManage.BeginTran();
                                UpdateStock(ExistStockInfo, weight, thickness, wide);
                                _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                                _inboundRepository.PurchaseBSTOrderDetailRepository.UpdateData(purchaseBSTOrderDetail);
                                _unitOfWorkManage.CommitTran();
                                return content.OK($"采购入库{ExistStockInfo.RfidCode}");
                            }
                            else
                            {
                                throw new Exception("未知错误");
                            }
                        }
                        #endregion
                    }
                    else if (!stationCode.IsNullOrEmpty() && stockInfoOld == null)
                    {
                        throw new Exception($"{palletCode}RFID信息不存在");
                    }
                    else
                    {
                        throw new Exception("未知错误");
                    }
                }
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        public void UpdateStock(Dt_StockInfo stockInfo, decimal weight = 0, decimal thickness = 0, decimal wide = 0)
        {
            stockInfo.CheckWeight = weight;
            stockInfo.CheckThickness = thickness;
            stockInfo.CheckWide = wide;
            _stockRepository.StockInfoRepository.UpdateData(stockInfo);
        }
        /// <summary>
        /// åŽŸæ–™é‡‡è´­ç»‘å®šRFID
        /// </summary>
        /// <param name="palletCode">纸卷条码</param>
        /// <param name="rfidCode">纸卷RIFD</param>
        /// <returns></returns>
        public WebResponseContent PurchaseBoxing(string palletCode)
        {
            WebResponseContent content=new WebResponseContent();
            try
            {
                if (string.IsNullOrEmpty(palletCode))
                {
                    throw new Exception("条码不能为空");
                }
                Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfoOld != null)
                {
                    throw new Exception("条码信息库存中已存在");
                }
                //获取采购信息
                Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _inboundRepository.PurchaseBSTOrderDetailRepository.QueryFirst(x => x.Barcode == palletCode);
                if (purchaseBSTOrderDetail == null)
                {
                    BSTResponse<BSTStockInfoDTO> bSTResponse = _invokeERPService.BSTStockAsync(palletCode).DeserializeObject<BSTResponse<BSTStockInfoDTO>>();
                    if (bSTResponse.Code == 500)
                    {
                        throw new Exception($"未找到条码{palletCode}采购信息并一期ERP库存也不存在");
                    }
                    BSTStockInfoDTO bSTStockInfoDTO=bSTResponse.Data ?? throw new Exception($"一期ERP未返回{palletCode}的库存信息");
                    Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterialSourceId == bSTStockInfoDTO.MaterialId) ?? throw new Exception($"未找到条码{palletCode}物料信息{bSTStockInfoDTO.MaterialNo}");
                    //生成库存组盘信息
                    Dt_StockInfo stockInfo = new Dt_StockInfo()
                    {
                        MaterielInvOrgId = materielInfo.MaterielInvOrgId,
                        PalletCode = palletCode,
                        RfidCode = "",
                        LocationCode = "",
                        PalletType = 1,
                        WarehouseId = materielInfo.WarehouseId,
                        StockAttribute = materielInfo.MaterielSourceType,
                        StockStatus = StockStatusEmun.博思通组盘暂存.ObjToInt(),
                        MaterielSpec = materielInfo.MaterielSpec,
                        Unit = materielInfo.MaterielUnit,
                        MaterielThickness = bSTStockInfoDTO.Thick,
                        MaterielWide = bSTStockInfoDTO.W,
                        MaterielWeight = bSTStockInfoDTO.Qty,
                        MaterielCode = materielInfo.MaterielCode,
                        MaterielName = materielInfo.MaterielName,
                        StockLength = bSTStockInfoDTO.StockMeter,
                        MaterielId = materielInfo.MaterialSourceId
                    };
                    if (bSTStockInfoDTO.W > 1200)
                    {
                        stockInfo.PalletType = 2;
                    }
                    Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x => x.InvOrg == MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault() ?? throw new Exception("未找到原料条码缓存信息");
                    int Id = yLInboundCache.Id;
                    if (yLInboundCache.BarCode == palletCode)
                    {
                        throw new Exception($"条码{palletCode}已扫码");
                    }
                    else if (yLInboundCache.BarCode != palletCode && yLInboundCache.BindStatus == WhetherEnum.True.ObjToInt())
                    {
                        yLInboundCache = _mapper.Map<Dt_YLInboundCache>(stockInfo);
                        yLInboundCache.Id = Id;
                        _unitOfWorkManage.BeginTran();
                        //新增组盘信息
                        _stockRepository.StockInfoRepository.AddData(stockInfo);
                        _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                        //启动线体
                        WebResponseContent webResponse = YLPurchasePush();
                        if (!webResponse.Status)
                        {
                            throw new Exception(webResponse.Message);
                        }
                        _unitOfWorkManage.CommitTran();
                        return content.OK("成功", yLInboundCache);
                    }
                    else
                    {
                        throw new Exception($"上卷条码{yLInboundCache.BarCode}还未进行绑定");
                    }
                }
                else
                {
                    if (purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus != InOrderStatusEnum.未开始.ObjToInt())
                    {
                        throw new Exception($"条码{palletCode}采购信息已入库或入库中");
                    }
                    Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x => x.InvOrg == MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault();
                    if (yLInboundCache == null)
                    {
                        throw new Exception("未找到原料条码缓存信息");
                    }
                    int Id = yLInboundCache.Id;
                    if (yLInboundCache.BarCode == palletCode)
                    {
                        throw new Exception($"条码{palletCode}已扫码");
                    }
                    else if (yLInboundCache.BarCode != palletCode && yLInboundCache.BindStatus == WhetherEnum.True.ObjToInt())
                    {
                        yLInboundCache = _mapper.Map<Dt_YLInboundCache>(purchaseBSTOrderDetail);
                        yLInboundCache.Id = Id;
                        //获取采购主单
                        Dt_PurchaseBSTOrder purchaseBSTOrder = _purchaseBSTOrderRepository.QueryFirst(x => x.Id == purchaseBSTOrderDetail.PurchaseBSTOrderId);
                        Dt_PurchaseBSTOrder purchaseBSTOrder = _inboundRepository.PurchaseBSTOrderRepository.QueryFirst(x => x.Id == purchaseBSTOrderDetail.PurchaseBSTOrderId);
                        //获取物料
                        Dt_MaterielInfo materielInfo = _basicRepository.MaterielInfoRepository.QueryFirst(x => x.MaterialSourceId == purchaseBSTOrderDetail.MaterialId);
                        //生成库存组盘信息
@@ -249,7 +425,7 @@
                        {
                            MaterielInvOrgId = materielInfo.MaterielInvOrgId,
                            PalletCode = purchaseBSTOrderDetail.Barcode,
                            RfidCode = palletCode,
                            RfidCode = "",
                            LocationCode = "",
                            PalletType = 1,
                            WarehouseId = materielInfo.WarehouseId,
@@ -269,22 +445,30 @@
                        {
                            stockInfo.PalletType = 2;
                        }
                        yLInboundCache.RfidCode = palletCode;
                        yLInboundCache.BindStatus = WhetherEnum.True.ObjToInt();
                        purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus = InOrderStatusEnum.入库中.ObjToInt();
                        _unitOfWorkManage.BeginTran();
                        _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                        //新增组盘信息
                        _stockRepository.StockInfoRepository.AddData(stockInfo);
                        if (purchaseBSTOrder.PurchaseOrderStatus == InOrderStatusEnum.未开始.ObjToInt())
                        {
                            purchaseBSTOrder.PurchaseOrderStatus = InOrderStatusEnum.入库中.ObjToInt();
                            _purchaseBSTOrderRepository.UpdateData(purchaseBSTOrder);
                            _inboundRepository.PurchaseBSTOrderRepository.UpdateData(purchaseBSTOrder);
                        }
                        _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                        _purchaseBSTOrderDetailRepository.UpdateData(purchaseBSTOrderDetail);
                        _inboundRepository.PurchaseBSTOrderDetailRepository.UpdateData(purchaseBSTOrderDetail);
                        //启动线体
                        WebResponseContent webResponse = YLPurchasePush();
                        if (!webResponse.Status)
                        {
                            throw new Exception(webResponse.Message);
                        }
                        _unitOfWorkManage.CommitTran();
                        return content.OK("成功", yLInboundCache);
                    }
                    #endregion
                    content.OK("绑定成功");
                    else
                    {
                       throw new Exception($"上卷条码{yLInboundCache.BarCode}还未进行绑定");
                    }
                }
                
            }
@@ -294,67 +478,29 @@
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// åŽŸæ–™é‡‡è´­ç»‘å®šRFID
        /// æŽ¨é€è‡³WCS原料线体启动
        /// </summary>
        /// <param name="palletCode">纸卷条码</param>
        /// <param name="rfidCode">纸卷RIFD</param>
        /// <returns></returns>
        public WebResponseContent PurchaseBoxing(string palletCode)
        public WebResponseContent YLPurchasePush()
        {
            WebResponseContent content=new WebResponseContent();
            try
            {
                if (string.IsNullOrEmpty(palletCode))
                string url = AppSettings.Get("WCS");
                if (string.IsNullOrEmpty(url))
                {
                    return content.Error("条码不能为空");
                    throw new Exception($"未找到WCSAApi地址,请检查配置文件");
                }
                Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfoOld != null)
                {
                    return content.Error("条码信息库存中已存在");
                }
                //获取采购信息
                Dt_PurchaseBSTOrderDetail purchaseBSTOrderDetail = _purchaseBSTOrderDetailRepository.QueryFirst(x => x.Barcode == palletCode);
                if (purchaseBSTOrderDetail == null)
                {
                    return content.Error($"未找到条码{palletCode}采购信息");
                }
                if (purchaseBSTOrderDetail.PurchaseBSTOrderDetailStatus != InOrderStatusEnum.未开始.ObjToInt())
                {
                    return content.Error($"条码{palletCode}采购信息已入库或入库中");
                }
                Dt_YLInboundCache? yLInboundCache = _inboundRepository.YLInboundCacheRepository.QueryData(x=>x.InvOrg==MaterielInvOrgEnum.老厂.ToString()).FirstOrDefault();
                if (yLInboundCache == null)
                {
                    return content.Error("未找到原料条码缓存信息");
                }
                int Id = yLInboundCache.Id;
                if (yLInboundCache.BarCode==palletCode)
                {
                    return content.Error($"条码{palletCode}已扫码");
                }
                else if (yLInboundCache.BarCode != palletCode && yLInboundCache.BindStatus==WhetherEnum.True.ObjToInt())
                {
                    yLInboundCache = _mapper.Map<Dt_YLInboundCache>(purchaseBSTOrderDetail);
                    yLInboundCache.Id = Id;
                    _inboundRepository.YLInboundCacheRepository.UpdateData(yLInboundCache);
                    return content.OK("成功", yLInboundCache);
                }
                else
                {
                    return content.Error($"上卷条码{yLInboundCache.BarCode}还未进行绑定");
                }
                string response = HttpHelper.Post($"{url}/api/Task/YLPurchasePush?code=406");
                return JsonConvert.DeserializeObject<WebResponseContent>(response) ?? WebResponseContent.Instance.Error("返回错误");
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
                return WebResponseContent.Instance.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// åŽŸæ–™åˆ†é…å··é“
@@ -453,7 +599,7 @@
                    {
                        return content.Error($"未找到对应的终点货位信息");
                    }
                    Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.SourceAddress && ( x.StationArea == nameof(AGVStationAreaEnum.一楼月台码头) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺织布) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺淋膜) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺淋膜)));
                    Dt_AGVStationInfo agvstation = _basicRepository.AGVStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.SourceAddress && ( x.StationArea == nameof(AGVStationAreaEnum.一楼月台码头) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺织布) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺淋膜) || x.StationArea == nameof(AGVStationAreaEnum.一楼无纺淋膜)));
                    if (agvstation != null)
                    {
                        agvstation.IsOccupied = WhetherEnum.False.ObjToInt();
@@ -465,7 +611,7 @@
                        _unitOfWorkManage.BeginTran();
                        if (agvstation != null)
                        {
                            _agvStationInfoRepository.UpdateData(agvstation);
                            _basicRepository.AGVStationInfoRepository.UpdateData(agvstation);
                        }
                        proStockInfo.LocationCode = locationInfoEnd.LocationCode;
                        proStockInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
@@ -484,7 +630,7 @@
                        _unitOfWorkManage.BeginTran();
                        if (agvstation != null)
                        {
                            _agvStationInfoRepository.UpdateData(agvstation);
                            _basicRepository.AGVStationInfoRepository.UpdateData(agvstation);
                        }
                        proStockInfo.LocationCode = locationInfoEnd.LocationCode;
                        proStockInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
@@ -523,11 +669,15 @@
                    }
                    stockInfo.LocationCode = locationInfoEnd.LocationCode;
                    stockInfo.StockStatus = StockStatusEmun.入库完成.ObjToInt();
                    if (task.TaskType!=TaskTypeEnum.Inbound.ObjToInt())
                    {
                        stockInfo.IsFull = WhetherEnum.True.ObjToInt();
                    }
                    _stockService.StockInfoService.Repository.UpdateData(stockInfo);
                    _basicService.LocationInfoService.UpdateLocationStatus(locationInfoEnd, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
                    BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? WIDESEA_Core.Enums.OperateTypeEnum.人工完成 : WIDESEA_Core.Enums.OperateTypeEnum.自动完成);
                    //上报老厂ERP
                    if (stockInfo.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt())
                    if (stockInfo.MaterielInvOrgId == MaterielInvOrgEnum.老厂.ObjToInt() && task.TaskType==TaskTypeEnum.Inbound.ObjToInt())
                    {
                        int Qty = Convert.ToInt32(stockInfo.MaterielWeight);
                        BSTPurchaseUpModel bSTPurchaseUpModel = new BSTPurchaseUpModel()
@@ -537,11 +687,12 @@
                            Rfid = stockInfo.RfidCode,
                            RfidUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                        };
                        BSTResponse bSTResponse = _invokeERPService.BSTPurchaseUp(bSTPurchaseUpModel).DeserializeObject<BSTResponse>();
                        BSTResponse<object> bSTResponse = _invokeERPService.BSTPurchaseUp(bSTPurchaseUpModel).DeserializeObject<BSTResponse<object>>();
                        if (bSTResponse.Code == 500)
                        {
                            throw new Exception($"BST一期ERP同步入库信息失败,错误信息:{bSTResponse.Msg}");
                        }
                        content.Message = bSTResponse.Msg;
                    }
                    _unitOfWorkManage.CommitTran();
                }
@@ -661,7 +812,7 @@
                //{
                //    return content.Error($"框码格式错误{barCode}");
                //}
                Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x=>x.AGVStationCode==startPoint);
                Dt_AGVStationInfo agvstation = _basicRepository.AGVStationInfoRepository.QueryFirst(x=>x.AGVStationCode==startPoint);
                if (agvstation==null)
                {
                    return content.Error($"起点错误{startPoint}");
@@ -737,6 +888,10 @@
                WebResponseContent content = new WebResponseContent();
                try
                {
                    if (matCount<1 || oneCount < 1)
                    {
                        return content.Error("物料总数或单个数量不能小于1");
                    }
                    //string palletCode = @"^C\d{5}$";  // æ­£åˆ™è¡¨è¾¾å¼
                    //bool isValid = Regex.IsMatch(barCode, palletCode);
                    //if (!isValid)
@@ -749,7 +904,7 @@
                    {
                        return content.Error($"未找到物料信息{matCode}");
                    }
                    Dt_AGVStationInfo agvstation = _agvStationInfoRepository.QueryFirst(x => x.AGVStationCode == startPoint);
                    Dt_AGVStationInfo agvstation = _basicRepository.AGVStationInfoRepository.QueryFirst(x => x.AGVStationCode == startPoint);
                    if (agvstation == null)
                    {
                        return content.Error($"起点错误{startPoint}");
@@ -1004,5 +1159,184 @@
            }
            return content;
        }
        /// <summary>
        /// æˆå“/半成品信息同步接口
        /// </summary>
        public WebResponseContent ReceiveProCodeInfo(List<MESProInDTO> proInDTOs)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (proInDTOs == null || proInDTOs.Count <= 0)
                {
                    return content.Error("传入信息为空");
                }
                //获取所有成品,半成品信息
                List<Dt_MESProInOrderInfo> proInOrderInfos = _inboundRepository.MESProInOrderInfoRepository.QueryData();
                //获取所有物料信息
                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData(x => x.MaterielInvOrgId == MaterielInvOrgEnum.新厂.ObjToInt());
                MESProInDTO? CheckMaterialCode = proInDTOs.FirstOrDefault(x => !materielInfos.Select(x => x.MaterielCode).Contains(x.MaterialCode));
                if (CheckMaterialCode != null)
                {
                    return content.Error($"物料编码{nameof(MESProInDTO.MaterialCode)}:{CheckMaterialCode.MaterialCode}信息不存在");
                }
                //获取所有AGV点位
                List<Dt_AGVStationInfo> aGVStationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => !string.IsNullOrEmpty(x.MESPointCode));
                //判断是否存在重复
                MESProInDTO? proInDTO = proInDTOs.FirstOrDefault(x => x.IsMantissa == false && proInOrderInfos.Select(x => x.BarCode).Contains(x.BarCode));
                if (proInDTO != null)
                {
                    return content.Error($"{proInDTO.ProductOrderNo}生产工单{proInDTO.BarCode}条码已存在");
                }
                Dt_MESProInOrderInfo? proInOrderInfo = proInOrderInfos.FirstOrDefault(x => x.MESProInStatus == InOrderStatusEnum.关闭.ObjToInt() && proInDTOs.Select(x => x.ProductOrderNo).Distinct().Contains(x.ProductOrderNo));
                if (proInOrderInfo != null)
                {
                    return content.Error($"{proInOrderInfo.ProductOrderNo}生产工单已关闭");
                }
                List<Dt_MESProInOrderInfo> AddMESProInOrders = new List<Dt_MESProInOrderInfo>();
                foreach (var item in proInDTOs)
                {
                    Dt_MaterielInfo materielInfo = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterialCode);
                    if (materielInfo.MaterielSourceType != MaterielTypeEnum.成品.ObjToInt())
                    {
                        Dt_AGVStationInfo? CheckPointCode = aGVStationInfos.FirstOrDefault(x => x.MESPointCode == item?.PointCode);
                        if (CheckPointCode == null)
                        {
                            return content.Error($"周转位{nameof(MESReturnIssueDTO.PointCode)}{item?.PointCode}不存在,仅成品物料可不传");
                        }
                    }
                    Dt_MESProInOrderInfo AddproInOrderInfo = _mapper.Map<Dt_MESProInOrderInfo>(item);
                    AddproInOrderInfo.WarehouseId = materielInfo.WarehouseId;
                    AddproInOrderInfo.MESProOrderType = materielInfo.MaterielSourceType;
                    AddMESProInOrders.Add(AddproInOrderInfo);
                }
                List<Dt_Task> tasks = new List<Dt_Task>();
                _unitOfWorkManage.BeginTran();
                _inboundRepository.MESProInOrderInfoRepository.AddData(AddMESProInOrders);
                if (AddMESProInOrders.Where(x => x.MESProOrderType == MaterielTypeEnum.半成品.ObjToInt()).Count() > 0)
                {
                    //生成半成品入库
                    WebResponseContent webResponse = PrintInbound(AddMESProInOrders.Where(x => x.MESProOrderType == MaterielTypeEnum.半成品.ObjToInt()).ToList());
                    if (!webResponse.Status)
                    {
                        throw new Exception(webResponse.Message);
                    }
                    tasks = webResponse.Data as List<Dt_Task>;
                    WebResponseContent taskResponse = PushTasksToWCS(tasks);
                    if (taskResponse.Status)
                    {
                        throw new Exception(taskResponse.Message);
                    }
                }
                _unitOfWorkManage.CommitTran();
                content.OK("接收成功");
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// å°åˆ·ä¸‹æ–™MES任务
        /// </summary>
        public WebResponseContent PrintInbound(List<Dt_MESProInOrderInfo> mESProInOrderInfos)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                if (mESProInOrderInfos.Count <= 0)
                {
                    return content.Error("传入信息为空");
                }
                List<Dt_MaterielInfo> materielInfos = _basicRepository.MaterielInfoRepository.QueryData();
                List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>();
                List<Dt_Task> tasks = new List<Dt_Task>();
                //获取所有AGV点位
                List<Dt_AGVStationInfo> aGVStationInfos = _basicRepository.AGVStationInfoRepository.QueryData(x => !string.IsNullOrEmpty(x.MESPointCode));
                //根据半成品信息呼叫对应任务
                foreach (var item in mESProInOrderInfos)
                {
                    Dt_AGVStationInfo? CheckPointCode = aGVStationInfos.FirstOrDefault(x => x.MESPointCode == item?.PointCode);
                    Dt_MaterielInfo? materielInfo = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterialCode);
                    if (materielInfo == null)
                    {
                        return content.Error("未找到物料信息");
                    }
                    if (materielInfo.MaterielSourceType != MaterielTypeEnum.半成品.ObjToInt())
                    {
                        return content.Error($"未找到物料{materielInfo.MaterielCode}半成品信息");
                    }
                    Dt_StockInfo stockInfoOld = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == item.BarCode);
                    if (stockInfoOld != null)
                    {
                        return content.Error("托盘信息已存在");
                    }
                    //生成库存组盘信息
                    Dt_StockInfo stockInfo = new Dt_StockInfo()
                    {
                        MaterielInvOrgId = materielInfo.MaterielInvOrgId,
                        PalletCode = item.BarCode,
                        LocationCode = "",
                        PalletType = 1,
                        WarehouseId = materielInfo.WarehouseId,
                        StockAttribute = materielInfo.MaterielSourceType,
                        StockStatus = StockStatusEmun.入库确认.ObjToInt(),
                        MaterielSpec = materielInfo.MaterielSpec,
                        Unit = materielInfo.MaterielUnit,
                        MaterielThickness = item.Thickness,
                        MaterielWide = item.Wide,
                        MaterielWeight = item.Weight,
                        MaterielCode = materielInfo.MaterielCode,
                        MaterielName = materielInfo.MaterielName,
                        StockLength=item.ProQuantity
                    };
                    if (item.Wide > 1200)
                    {
                        stockInfo.PalletType = 2;
                    }
                    //半成品入库任务
                    Dt_Task newTask = new Dt_Task()
                    {
                        CurrentAddress = CheckPointCode.AGVStationCode,
                        Grade = 0,
                        NextAddress = "",
                        PalletCode = item.BarCode,
                        Roadway = "",
                        SourceAddress = CheckPointCode.AGVStationCode,
                        TargetAddress = "",
                        TaskType = 0,
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = materielInfo.WarehouseId,
                        PalletType = stockInfo.PalletType,
                        TaskLength = (int)item.Wide
                    };
                    TaskTypeEnum taskTypeEnum = CheckPointCode.StationArea switch
                    {
                        nameof(AGVStationAreaEnum.一楼印刷) => TaskTypeEnum.PrintYLInbound,
                        _ => throw new Exception("未找到对应任务")
                    };
                    newTask.TaskType = taskTypeEnum.ObjToInt();
                    stockInfos.Add(stockInfo);
                    tasks.Add(newTask);
                }
                //操作入库数据
                BaseDal.AddData(tasks);
                _stockRepository.StockInfoRepository.AddData(stockInfos);
                //推送任务
                content.OK("发送成功",data:tasks);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
    }
}