22
schangxiang@126.com
2024-12-23 164f2cf0a8d85a2ebd2955f8f322d5f6bb4d3857
LA24030_LuLiPackageLine_Wms/Admin.NET.Application/Service/WmsOperationTask/WmsOperationTaskService.cs
@@ -18,6 +18,9 @@
[ApiDescriptionSettings(ApplicationConst.WmsTaskGroupName, Order = 100)]
public class WmsOperationTaskService : IDynamicApiController, ITransient
{
    private static readonly SemaphoreSlim semaphore = new SemaphoreSlim(1, 1);
    private static readonly SemaphoreSlim semaphore2 = new SemaphoreSlim(1, 1);
    private readonly SqlSugarRepository<WmsRbLineTask> _rep;
    private readonly SqlSugarRepository<WmsStockQuan> _wmsStockQuanRep;
    private readonly SqlSugarRepository<Mes_Package_Gather> _mesPackageGatherRep;
@@ -229,161 +232,175 @@
    [UnitOfWork]
    public async Task<ValidateQiTaoOutput> ValdateQiTao(ValidateQiTaoInput input)
    {
        ValidateQiTaoOutput output = new ValidateQiTaoOutput();
        if (input == null || input.PackageCode == null)
        await semaphore2.WaitAsync();
        try
        {
            throw Oops.Oh("参数不能为空");
        }
            ValidateQiTaoOutput output = new ValidateQiTaoOutput();
            if (input == null || input.PackageCode == null)
            {
                throw Oops.Oh("参数不能为空");
            }
        var package = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
        if (package == null)
        {
            throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
        }
            var package = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
            if (package == null)
            {
                throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
            }
        if (package.UpiStatus == UpiStatusEnum.已下线)
        {
            throw Oops.Oh($"包{input.PackageCode}已下线");
        }
            if (package.UpiStatus == UpiStatusEnum.已下线)
            {
                throw Oops.Oh($"包{input.PackageCode}已下线");
            }
        var unlineObj = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
        if (unlineObj != null)
        {
            throw Oops.Oh($"包号{input.PackageCode}已经下线");
        }
            var unlineObj = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
            if (unlineObj != null)
            {
                throw Oops.Oh($"包号{input.PackageCode}已经下线");
            }
        //判断是否是新生产订单
        var _QiTaoReuslt = "";
        bool isNewOrder = false;
        string _location = "BZ-33";
        var lastPackageUnline = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.UpiFlag == UpiFlagEnum.正常 && x.Location != "人工").OrderByDescending(x => x.Id).FirstAsync();
        if (lastPackageUnline == null)
        {//认为是新生产订单
            isNewOrder = true;
        }
        else
        {
            if (lastPackageUnline.Info5 != package.Info5)
            //判断是否是新生产订单
            var _QiTaoReuslt = "";
            bool isNewOrder = false;
            string _location = "BZ-33";
            var lastPackageUnline = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.UpiFlag == UpiFlagEnum.正常 && x.Location != "人工").OrderByDescending(x => x.Id).FirstAsync();
            if (lastPackageUnline == null)
            {//认为是新生产订单
                isNewOrder = true;
                if (lastPackageUnline.Location == "BZ-33")
                {
                    _location = "BZ-32";
                }
                else
                {
                    _location = "BZ-33";
                }
            }
            else
            {
                _location = lastPackageUnline.Location;
                if (lastPackageUnline.Info5 != package.Info5)
                {//认为是新生产订单
                    isNewOrder = true;
                    if (lastPackageUnline.Location == "BZ-33")
                    {
                        _location = "BZ-32";
                    }
                    else
                    {
                        _location = "BZ-33";
                    }
                }
                else
                {
                    _location = lastPackageUnline.Location;
                }
            }
        }
        if (string.IsNullOrEmpty(_location))
        {//默认
            _location = "BZ-33";
        }
            if (string.IsNullOrEmpty(_location))
            {//默认
                _location = "BZ-33";
            }
        _QiTaoReuslt = (bool)isNewOrder ? "新订单" : "当前订单";
            _QiTaoReuslt = (bool)isNewOrder ? "新订单" : "当前订单";
        //记录工作时间和工作人
        var curUserName = App.User.FindFirst(ClaimConst.RealName)?.Value;
            //记录工作时间和工作人
            var curUserName = App.User.FindFirst(ClaimConst.RealName)?.Value;
        var sysConfig_wms_unline_oper = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_oper);
        if (sysConfig_wms_unline_oper == null)
        {
            throw Oops.Oh($"没有配置 包装下线操作人 值");
        }
        if (sysConfig_wms_unline_oper.Value != curUserName)
        {
            sysConfig_wms_unline_oper.Value = curUserName;
            await _sysConfigRep.UpdateAsync(sysConfig_wms_unline_oper);
            var sysConfig_wms_unline_time = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_time);
            if (sysConfig_wms_unline_time == null)
            var sysConfig_wms_unline_oper = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_oper);
            if (sysConfig_wms_unline_oper == null)
            {
                throw Oops.Oh($"没有配置 包装下线登陆时间 值");
                throw Oops.Oh($"没有配置 包装下线操作人 值");
            }
            sysConfig_wms_unline_time.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            await _sysConfigRep.UpdateAsync(sysConfig_wms_unline_time);
            if (sysConfig_wms_unline_oper.Value != curUserName)
            {
                sysConfig_wms_unline_oper.Value = curUserName;
                await _sysConfigRep.UpdateAsync(sysConfig_wms_unline_oper);
                var sysConfig_wms_unline_time = await _sysConfigRep.GetFirstAsync(x => x.Code == CommonConst.wms_unline_time);
                if (sysConfig_wms_unline_time == null)
                {
                    throw Oops.Oh($"没有配置 包装下线登陆时间 值");
                }
                sysConfig_wms_unline_time.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                await _sysConfigRep.UpdateAsync(sysConfig_wms_unline_time);
            }
            //请求PLC
            //判断方向
            bool myLocation = false;
            if (_location == "BZ-33")
            {
                myLocation = false;
            }
            else
            {
                myLocation = true;
            }
            var client = await WCFServiceHelper.GetWCFService_SAPCC_Client(_sysConfigRep);
            var res = await client.WriteQiTaoInfoAsync(myLocation);
            if (res.result == false)
            {
                throw Oops.Oh(res.resMsg);
            }
            //更新数据
            package.UpiStatus = UpiStatusEnum.已下线;
            package.AreaCode = AreaCodeEnum.下线区域;
            await _mesPackageGatherRep.UpdateAsync(package);
            var upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
            foreach (var item in upiList)
            {
                item.UpiStatus = UpiStatusEnum.已下线;
                item.AreaCode = AreaCodeEnum.下线区域;
                item.UpdateTime = DateTime.Now;
            }
            await _mesBatchOrderUpiRep.UpdateRangeAsync(upiList);
            //删除队列信息
            var lineQueue = await _mes_Package_LineQueueRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
            if (lineQueue != null)
            {
                await _mes_Package_LineQueueRep.DeleteAsync(lineQueue);
            }
            //处理表  mes_order_gather
            await UpdateOrderGather(package, false);
            var _cretaorName = App.User.FindFirst(ClaimConst.RealName)?.Value;
            //新增下线记录表
            var all_upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.Info5 == package.Info5).ToListAsync();
            var all_unlineList = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.Info5 == package.Info5).ToListAsync();
            Mes_Package_UnLine_Record record = new Mes_Package_UnLine_Record();
            record = package.Adapt<Mes_Package_UnLine_Record>();
            record.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            record.Location = _location;
            record.AllPackageNum = all_upiList.GroupBy(x => x.PackageCode).Count();
            record.CurUnlineIndexPackageNum = all_unlineList.GroupBy(x => x.PackageCode).Count() + 1;
            record.CreateTime = DateTime.Now;
            record.CreateUserName = _cretaorName;
            await _mes_Package_UnLine_RecordRep.InsertAsync(record);
            //记录包履历
            WmsRecordPackageProcess wmsRecordPackage = new WmsRecordPackageProcess();
            wmsRecordPackage = package.Adapt<WmsRecordPackageProcess>();
            wmsRecordPackage.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            wmsRecordPackage.Location = "";
            wmsRecordPackage.OperRemark = "正常下线";
            wmsRecordPackage.CreateTime = DateTime.Now;
            wmsRecordPackage.CreateUserName = _cretaorName;
            await _wmsRecordPackageProcessRep.InsertAsync(wmsRecordPackage);
            output = package.Adapt<ValidateQiTaoOutput>();
            output.QiTaoReuslt = _QiTaoReuslt + $",第{record.CurUnlineIndexPackageNum}包下线,共{record.AllPackageNum}包";
            output.IsNewOrder = isNewOrder;
            //output.IsNewOrder = false;
            return output;
        }
        //请求PLC
        //判断方向
        bool myLocation = false;
        if (_location == "BZ-33")
        catch (Exception)
        {
            myLocation = false;
            throw;
        }
        else
        finally
        {
            myLocation = true;
        }
        var client = await WCFServiceHelper.GetWCFService_SAPCC_Client(_sysConfigRep);
        var res = await client.WriteQiTaoInfoAsync(myLocation);
        if (res.result == false)
        {
            throw Oops.Oh(res.resMsg);
            semaphore2.Release();
        }
        //更新数据
        package.UpiStatus = UpiStatusEnum.已下线;
        package.AreaCode = AreaCodeEnum.下线区域;
        await _mesPackageGatherRep.UpdateAsync(package);
        var upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
        foreach (var item in upiList)
        {
            item.UpiStatus = UpiStatusEnum.已下线;
            item.AreaCode = AreaCodeEnum.下线区域;
            item.UpdateTime = DateTime.Now;
        }
        await _mesBatchOrderUpiRep.UpdateRangeAsync(upiList);
        //删除队列信息
        var lineQueue = await _mes_Package_LineQueueRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
        if (lineQueue != null)
        {
            await _mes_Package_LineQueueRep.DeleteAsync(lineQueue);
        }
        //处理表  mes_order_gather
        await UpdateOrderGather(package, false);
        var _cretaorName = App.User.FindFirst(ClaimConst.RealName)?.Value;
        //新增下线记录表
        var all_upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.Info5 == package.Info5).ToListAsync();
        var all_unlineList = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.Info5 == package.Info5).ToListAsync();
        Mes_Package_UnLine_Record record = new Mes_Package_UnLine_Record();
        record = package.Adapt<Mes_Package_UnLine_Record>();
        record.Id = Yitter.IdGenerator.YitIdHelper.NextId();
        record.Location = _location;
        record.AllPackageNum = all_upiList.GroupBy(x => x.PackageCode).Count();
        record.CurUnlineIndexPackageNum = all_unlineList.GroupBy(x => x.PackageCode).Count() + 1;
        record.CreateTime = DateTime.Now;
        record.CreateUserName = _cretaorName;
        await _mes_Package_UnLine_RecordRep.InsertAsync(record);
        //记录包履历
        WmsRecordPackageProcess wmsRecordPackage = new WmsRecordPackageProcess();
        wmsRecordPackage = package.Adapt<WmsRecordPackageProcess>();
        wmsRecordPackage.Id = Yitter.IdGenerator.YitIdHelper.NextId();
        wmsRecordPackage.Location = "";
        wmsRecordPackage.OperRemark = "正常下线";
        wmsRecordPackage.CreateTime = DateTime.Now;
        wmsRecordPackage.CreateUserName = _cretaorName;
        await _wmsRecordPackageProcessRep.InsertAsync(wmsRecordPackage);
        output = package.Adapt<ValidateQiTaoOutput>();
        output.QiTaoReuslt = _QiTaoReuslt + $",第{record.CurUnlineIndexPackageNum}包下线,共{record.AllPackageNum}包";
        output.IsNewOrder = isNewOrder;
        //output.IsNewOrder = false;
        return output;
    }
@@ -454,128 +471,140 @@
    [UnitOfWork]
    public async Task UnlineForNGPackage(UnlineForNGPackageInput input)
    {
        if (input == null)
        await semaphore.WaitAsync();
        try
        {
            throw Oops.Oh("参数不能为空");
        }
        if (string.IsNullOrEmpty(input.PackageCode))
        {
            throw Oops.Oh("包号不能为空");
        }
        //if (string.IsNullOrEmpty(input.Reason))
        //{
        //    throw Oops.Oh("原因不能为空");
        //}
        string _OperRemark = "正常人工下线";
        UpiFlagEnum upiFlagEnum = UpiFlagEnum.正常;
        if (input.IsNG)
        {
            upiFlagEnum = UpiFlagEnum.NG;
            _OperRemark = "NG下线";
        }
        var singlePackage = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
        if (singlePackage == null)
        {
            throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
        }
        if (singlePackage.UpiStatus == UpiStatusEnum.已下线)
        {
            throw Oops.Oh($"包号{input.PackageCode}已经下线");
        }
        singlePackage.UpiFlag = upiFlagEnum;
        singlePackage.UpdateTime = DateTime.Now;
        singlePackage.UpiStatus = UpiStatusEnum.已下线;
        singlePackage.AreaCode = AreaCodeEnum.下线区域;
        var upiLineQueueList = await _mes_Upi_LineQueueRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
        if (upiLineQueueList?.Count > 0)
        {
            await _mes_Upi_LineQueueRep.DeleteAsync(upiLineQueueList);
        }
        var upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
        if (upiList == null)
        {
            throw Oops.Oh($"没有找到包号{input.PackageCode}的板件数据");
        }
        var _cretaorName = App.User.FindFirst(ClaimConst.RealName)?.Value;
        foreach (var item in upiList)
        {
            item.UpiFlag = UpiFlagEnum.NG;
            item.UpdateTime = DateTime.Now;
            item.UpiStatus = UpiStatusEnum.已下线;
            item.AreaCode = AreaCodeEnum.下线区域;
            WmsRecordUpiProcess wmsRecordUpi = new WmsRecordUpiProcess();
            wmsRecordUpi = item.Adapt<WmsRecordUpiProcess>();
            wmsRecordUpi.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            wmsRecordUpi.CreateTime = DateTime.Now;
            wmsRecordUpi.CreateUserName = _cretaorName;
            wmsRecordUpi.Location = "";
            wmsRecordUpi.OperRemark = _OperRemark;
            await _wmsRecordUpiProcessRep.InsertAsync(wmsRecordUpi);
            WmsRecordUpiNg wmsRecordUpiNg = new WmsRecordUpiNg();
            wmsRecordUpiNg = item.Adapt<WmsRecordUpiNg>();
            wmsRecordUpiNg.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            wmsRecordUpiNg.CreateTime = DateTime.Now;
            wmsRecordUpiNg.CreateUserName = _cretaorName;
            wmsRecordUpiNg.OperRemark = _OperRemark;
            await _wmsRecordUpiNgRep.InsertAsync(wmsRecordUpiNg);
            //清理 队列表
            var removeUpiList = await _mes_Upi_LineQueueRep.AsQueryable().Where(x => x.Upi == item.UPI).ToListAsync();
            if (removeUpiList?.Count > 0)
            if (input == null)
            {
                await _mes_Upi_LineQueueRep.DeleteAsync(removeUpiList);
                throw Oops.Oh("参数不能为空");
            }
            if (string.IsNullOrEmpty(input.PackageCode))
            {
                throw Oops.Oh("包号不能为空");
            }
            //if (string.IsNullOrEmpty(input.Reason))
            //{
            //    throw Oops.Oh("原因不能为空");
            //}
            string _OperRemark = "正常人工下线";
            UpiFlagEnum upiFlagEnum = UpiFlagEnum.正常;
            if (input.IsNG)
            {
                upiFlagEnum = UpiFlagEnum.NG;
                _OperRemark = "NG下线";
            }
            var removePackageList = await _mes_Package_LineQueueRep.AsQueryable().Where(x => x.PackageCode == item.PackageCode).ToListAsync();
            if (removePackageList?.Count > 0)
            var singlePackage = await _mesPackageGatherRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).FirstAsync();
            if (singlePackage == null)
            {
                await _mes_Package_LineQueueRep.DeleteAsync(removePackageList);
                throw Oops.Oh($"没有找到包号{input.PackageCode}的汇总数据");
            }
            if (singlePackage.UpiStatus == UpiStatusEnum.已下线)
            {
                throw Oops.Oh($"包号{input.PackageCode}已经下线");
            }
            singlePackage.UpiFlag = upiFlagEnum;
            singlePackage.UpdateTime = DateTime.Now;
            singlePackage.UpiStatus = UpiStatusEnum.已下线;
            singlePackage.AreaCode = AreaCodeEnum.下线区域;
            var upiLineQueueList = await _mes_Upi_LineQueueRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
            if (upiLineQueueList?.Count > 0)
            {
                await _mes_Upi_LineQueueRep.DeleteAsync(upiLineQueueList);
            }
            var upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.PackageCode == input.PackageCode).ToListAsync();
            if (upiList == null)
            {
                throw Oops.Oh($"没有找到包号{input.PackageCode}的板件数据");
            }
            var _cretaorName = App.User.FindFirst(ClaimConst.RealName)?.Value;
            foreach (var item in upiList)
            {
                item.UpiFlag = UpiFlagEnum.NG;
                item.UpdateTime = DateTime.Now;
                item.UpiStatus = UpiStatusEnum.已下线;
                item.AreaCode = AreaCodeEnum.下线区域;
                WmsRecordUpiProcess wmsRecordUpi = new WmsRecordUpiProcess();
                wmsRecordUpi = item.Adapt<WmsRecordUpiProcess>();
                wmsRecordUpi.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                wmsRecordUpi.CreateTime = DateTime.Now;
                wmsRecordUpi.CreateUserName = _cretaorName;
                wmsRecordUpi.Location = "";
                wmsRecordUpi.OperRemark = _OperRemark;
                await _wmsRecordUpiProcessRep.InsertAsync(wmsRecordUpi);
                WmsRecordUpiNg wmsRecordUpiNg = new WmsRecordUpiNg();
                wmsRecordUpiNg = item.Adapt<WmsRecordUpiNg>();
                wmsRecordUpiNg.Id = Yitter.IdGenerator.YitIdHelper.NextId();
                wmsRecordUpiNg.CreateTime = DateTime.Now;
                wmsRecordUpiNg.CreateUserName = _cretaorName;
                wmsRecordUpiNg.OperRemark = _OperRemark;
                await _wmsRecordUpiNgRep.InsertAsync(wmsRecordUpiNg);
                //清理 队列表
                var removeUpiList = await _mes_Upi_LineQueueRep.AsQueryable().Where(x => x.Upi == item.UPI).ToListAsync();
                if (removeUpiList?.Count > 0)
                {
                    await _mes_Upi_LineQueueRep.DeleteAsync(removeUpiList);
                }
                var removePackageList = await _mes_Package_LineQueueRep.AsQueryable().Where(x => x.PackageCode == item.PackageCode).ToListAsync();
                if (removePackageList?.Count > 0)
                {
                    await _mes_Package_LineQueueRep.DeleteAsync(removePackageList);
                }
            }
            //下线更新 订单表数据 _mesOrderGatherRep
            await UpdateOrderGather(singlePackage, input.IsNG);
            WmsRecordPackageProcess wmsRecordPackage = new WmsRecordPackageProcess();
            wmsRecordPackage = singlePackage.Adapt<WmsRecordPackageProcess>();
            wmsRecordPackage.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            wmsRecordPackage.Location = "";
            wmsRecordPackage.OperRemark = _OperRemark;
            wmsRecordPackage.CreateTime = DateTime.Now;
            wmsRecordPackage.CreateUserName = _cretaorName;
            await _wmsRecordPackageProcessRep.InsertAsync(wmsRecordPackage);
            //新增下线记录表
            var all_upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.Info5 == singlePackage.Info5).ToListAsync();
            var all_unlineList = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.Info5 == singlePackage.Info5).ToListAsync();
            Mes_Package_UnLine_Record record = new Mes_Package_UnLine_Record();
            record = singlePackage.Adapt<Mes_Package_UnLine_Record>();
            record.Id = Yitter.IdGenerator.YitIdHelper.NextId();
            record.Location = "人工";
            record.AllPackageNum = all_upiList.GroupBy(x => x.PackageCode).Count();
            record.CurUnlineIndexPackageNum = all_unlineList.GroupBy(x => x.PackageCode).Count() + 1;
            record.CreateTime = DateTime.Now;
            record.CreateUserName = _cretaorName;
            await _mes_Package_UnLine_RecordRep.InsertAsync(record);
            await _mesPackageGatherRep.UpdateAsync(singlePackage);
            await _mesBatchOrderUpiRep.UpdateRangeAsync(upiList);
        }
        catch (Exception)
        {
        //下线更新 订单表数据 _mesOrderGatherRep
        await UpdateOrderGather(singlePackage, input.IsNG);
        WmsRecordPackageProcess wmsRecordPackage = new WmsRecordPackageProcess();
        wmsRecordPackage = singlePackage.Adapt<WmsRecordPackageProcess>();
        wmsRecordPackage.Id = Yitter.IdGenerator.YitIdHelper.NextId();
        wmsRecordPackage.Location = "";
        wmsRecordPackage.OperRemark = _OperRemark;
        wmsRecordPackage.CreateTime = DateTime.Now;
        wmsRecordPackage.CreateUserName = _cretaorName;
        await _wmsRecordPackageProcessRep.InsertAsync(wmsRecordPackage);
        //新增下线记录表
        var all_upiList = await _mesBatchOrderUpiRep.AsQueryable().Where(x => x.Info5 == singlePackage.Info5).ToListAsync();
        var all_unlineList = await _mes_Package_UnLine_RecordRep.AsQueryable().Where(x => x.Info5 == singlePackage.Info5).ToListAsync();
        Mes_Package_UnLine_Record record = new Mes_Package_UnLine_Record();
        record = singlePackage.Adapt<Mes_Package_UnLine_Record>();
        record.Id = Yitter.IdGenerator.YitIdHelper.NextId();
        record.Location = "人工";
        record.AllPackageNum = all_upiList.GroupBy(x => x.PackageCode).Count();
        record.CurUnlineIndexPackageNum = all_unlineList.GroupBy(x => x.PackageCode).Count() + 1;
        record.CreateTime = DateTime.Now;
        record.CreateUserName = _cretaorName;
        await _mes_Package_UnLine_RecordRep.InsertAsync(record);
        await _mesPackageGatherRep.UpdateAsync(singlePackage);
        await _mesBatchOrderUpiRep.UpdateRangeAsync(upiList);
            throw;
        }
        finally
        {
            semaphore.Release();
        }
    }
    /// <summary>
@@ -601,12 +630,19 @@
        var packageList = await _mesPackageGatherRep.AsQueryable().Where(x => x.Info5 == singlePackage.Info5).ToListAsync();
        order.PackageNum = packageList.Count();
        order.UnLinePackageNum = packageList.Where(x => x.UpiStatus == UpiStatusEnum.已下线).Count() + 1;
        if (order.UnLinePackageNum > order.PackageNum)
        {
            order.UnLinePackageNum = order.PackageNum;
        }
        order.NgPackageNum = packageList.Where(x => x.UpiStatus == UpiStatusEnum.已下线 && x.UpiFlag == UpiFlagEnum.NG).Count();
        if (isNG)
        {
            order.NgPackageNum = order.NgPackageNum + 1;
        }
        if (order.NgPackageNum > order.PackageNum)
        {
            order.NgPackageNum = order.PackageNum;
        }
        order.NoUnLinePackageNum = order.PackageNum - order.UnLinePackageNum;