/// <summary>
        /// 加工点投标提交
        /// </summary>
        /// <param name="processorBidDto"></param>
        /// <returns></returns>
        public virtual async Task Bid(ProcessorBidDto processorBidDto)
        {
            var processQuote = await Manager.GetAll()
                               .IgnoreQueryFilters()
                               .Where(o => !o.IsDeleted)
                               .Include(o => o.ProcessQuoteBids)
                               .Where(o => o.Id == processorBidDto.ProcessQuoteId)
                               .SingleOrDefaultAsync();

            if (processQuote.QuoteStatus != QuoteStatus.询价中)
            {
                throw new UserFriendlyException(L("非询价中状态的询价不能进行投标"));
            }
            if (processQuote.ExpireDate < DateTime.Now)
            {
                throw new UserFriendlyException(L("此询价已超过截止日期,不能投标"));
            }

            //todo:需要区分是公开投标还是邀请投标
            if (processQuote.QuoteScope == QuoteScope.邀请投标)
            {
                var bidInfo = processQuote.ProcessQuoteBids.Where(o => o.ToTenantId == AbpSession.TenantId).SingleOrDefault();
                bidInfo.BidDate = DateTime.Now;
                bidInfo.BidType = processorBidDto.BidType;
                bidInfo.Remarks = processorBidDto.Remarks;
                var bidData = bidInfo.BidData;
                bidData.Cost           = processorBidDto.Cost;
                bidInfo.BidData        = bidData;
                bidInfo.QuoteBidStatus = bidInfo.BidType == 0 ? QuoteBidStatus.已放弃 : QuoteBidStatus.已投标;
            }
            else
            {
                //公开投标的不存在放弃投标
                var bidInfo = new ProcessQuoteBid()
                {
                    ProcessQuoteId = processQuote.Id,
                    ToTenantId     = AbpSession.TenantId,
                    BidDate        = DateTime.Now,
                    BidType        = 1,
                    Remarks        = processorBidDto.Remarks,
                    BidData        = new BidData()
                    {
                        Cost = processorBidDto.Cost
                    },
                    QuoteBidStatus = QuoteBidStatus.已投标
                };
                processQuote.ProcessQuoteBids.Add(bidInfo);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加或编辑询价信息
        /// </summary>
        /// <param name="processQuoteSubmitDto"></param>
        /// <param name="isPublish"></param>
        /// <returns></returns>
        public virtual async Task SubmitProcessQuote(ProcessQuoteSubmitDto processQuoteSubmitDto, bool isPublish = false)
        {
            if (string.IsNullOrEmpty(processQuoteSubmitDto.QuoteName))
            {
                throw new UserFriendlyException(L("请输入询价名称"));
            }

            if (processQuoteSubmitDto.ProcessQuoteTasks.Count == 0)
            {
                throw new UserFriendlyException(L("询价明细数量不能为0"));
            }
            if (processQuoteSubmitDto.QuoteScope == QuoteScope.邀请投标 && processQuoteSubmitDto.UnitIds.Count == 0)
            {
                throw new UserFriendlyException(L("邀请投标的请至少选择一个加工点"));
            }


            ProcessQuote processQuote = null;
            var          manager      = Manager as ProcessQuoteManager;

            if (processQuoteSubmitDto.Id == 0)
            {
                #region 添加
                processQuote = processQuoteSubmitDto.MapTo <ProcessQuote>();
                processQuote.ProcessQuoteBids = new List <ProcessQuoteBid>();
                foreach (var addUnitId in processQuoteSubmitDto.UnitIds)
                {
                    var unit = await MESUnitManager.GetByIdFromCacheAsync(addUnitId);

                    var unitTenantBinded = unit.IsTenantBinded();
                    //发布状态下,往来单位必须绑定账号
                    if (isPublish && !unitTenantBinded)
                    {
                        throw new UserFriendlyException($"{unit.UnitName}尚未绑定模来模往账号");
                    }
                    //产生新的投标明细
                    var quoteBid = new ProcessQuoteBid()
                    {
                        UnitId         = addUnitId,
                        ToTenantId     = unit.GetTenantId(),
                        QuoteBidStatus = unitTenantBinded ? QuoteBidStatus.未发送 : QuoteBidStatus.未加入
                    };
                    processQuote.ProcessQuoteBids.Add(quoteBid);
                }
                await manager.InsertAsync(processQuote);

                #endregion
            }
            else
            {
                processQuote = await Manager.GetAll()
                               .Include(o => o.ProcessQuoteTasks)
                               .Include(o => o.ProcessQuoteBids)
                               .Where(o => o.Id == processQuoteSubmitDto.Id).SingleAsync();

                if (processQuote.QuoteStatus != QuoteStatus.草稿)
                {
                    throw new UserFriendlyException(L("只有草稿状态的询价单才能修改"));
                }

                processQuote.QuoteName    = processQuoteSubmitDto.QuoteName;
                processQuote.QuoteScope   = processQuoteSubmitDto.QuoteScope;
                processQuote.QuotePayType = processQuoteSubmitDto.QuotePayType;
                processQuote.ExpireDate   = processQuoteSubmitDto.ExpireDate;
                processQuote.Files        = processQuoteSubmitDto.Files;

                #region 询价明细的保存
                //新增
                var addedTasks = processQuoteSubmitDto.ProcessQuoteTasks.Where(o => o.Id == 0).MapTo <List <ProcessQuoteTask> >();
                foreach (var addTask in addedTasks)
                {
                    processQuote.ProcessQuoteTasks.Add(addTask);
                }
                //修改
                foreach (var oldTask in processQuote.ProcessQuoteTasks.Where(o => processQuoteSubmitDto.ProcessQuoteTasks.Exists(m => m.Id == o.Id)))
                {
                    var newTask = processQuoteSubmitDto.ProcessQuoteTasks.Single(o => o.Id == oldTask.Id);
                    newTask.MapTo(oldTask);
                }
                //删除
                var deletedTaskIds = processQuote.ProcessQuoteTasks.Where(o => !processQuoteSubmitDto.ProcessQuoteTasks.Exists(m => m.Id == o.Id))
                                     .Select(o => o.Id);

                await ProcessQuoteTaskRepository.DeleteAsync(o => deletedTaskIds.Contains(o.Id));

                #endregion

                #region 投标明细的保存
                //新增
                var addedUnitIds = processQuoteSubmitDto.UnitIds.Where(o => processQuote.ProcessQuoteBids.Count(b => b.UnitId == o) < 0);
                foreach (var addUnitId in addedUnitIds)
                {
                    var unit = await MESUnitManager.GetByIdFromCacheAsync(addUnitId);

                    var unitTenantBinded = unit.IsTenantBinded();
                    //发布状态下,往来单位必须绑定账号
                    if (isPublish && !unitTenantBinded)
                    {
                        throw new UserFriendlyException($"{unit.UnitName}尚未绑定模来模往账号");
                    }
                    //产生新的投标明细
                    var quoteBid = new ProcessQuoteBid()
                    {
                        UnitId         = addUnitId,
                        ToTenantId     = unit.GetTenantId(),
                        QuoteBidStatus = unitTenantBinded ? QuoteBidStatus.未发送 : QuoteBidStatus.未加入
                    };
                    processQuote.ProcessQuoteBids.Add(quoteBid);
                }
                //删除
                var deletedBidIds = processQuote.ProcessQuoteBids.Where(o => !processQuoteSubmitDto.UnitIds.Exists(m => m == o.UnitId))
                                    .Select(o => o.Id);
                await ProcessQuoteBidRepository.DeleteAsync(o => deletedBidIds.Contains(o.Id));

                #endregion

                await Manager.UpdateAsync(processQuote);
            }

            await CurrentUnitOfWork.SaveChangesAsync();

            //设置询价中的所有询价任务为“已询价状态"
            var tasks = await ProcessTaskManager.GetAll()
                        .Where(o => processQuote.ProcessQuoteTasks.Where(t => t.ProcessTaskId.HasValue).Select(t => t.ProcessTaskId).Contains(o.Id))
                        .ToListAsync();

            foreach (var task in tasks)
            {
                task.SetStatus(ProcessTask.Status_Quoted);
            }
            //发布
            if (isPublish)
            {
                await manager.Publish(processQuote.Id);
            }
        }