/// <summary> /// 发送往来单位公告 /// </summary> /// <param name="sendTenantNoticeDto"></param> /// <returns></returns> public virtual async Task SendNotice(SendTenantNoticeDto sendTenantNoticeDto) { //先产生一条公告 var notice = new Notice() { NoticeTitle = sendTenantNoticeDto.Title, NoticeContent = sendTenantNoticeDto.Content, NoticeType = "往来单位公告", TenantId = AbpSession.TenantId }; var noticeId = await NoticeManager.InsertAndGetIdAsync(notice); var units = await MESUnitManager.GetListByIdsAsync(sendTenantNoticeDto.UnitIds); await MESUnitManager.SendUnitsNotice(units, notice); }
/// <summary> /// 获取当前加工点绑定了的所有模具厂 /// </summary> /// <returns></returns> public virtual async Task <object> GetCustomers() { using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MustHaveTenant)) { var units = await MESUnitManager .GetAll() .Include(o => o.Tenant) .Where(o => MasterDbContext.GetJsonValueNumber(o.Property, "$.TenantId") == AbpSession.TenantId.Value) .Select(o => new { o.TenantId, o.Tenant.Name, o.Id }) .ToListAsync(); var tenants = units .Select(o => new { o.TenantId, o.Name }) .Distinct(); var result = new List <object>(); foreach (var tenant in tenants) { var unitIds = units.Where(o => o.TenantId == tenant.TenantId).Select(o => o.Id); var baseQuery = ProcessTaskManager.GetAll().Where(p => p.TenantId == tenant.TenantId && p.Status.Contains(ProcessTask.Status_SendProcessor) && p.SupplierId != null && unitIds.Contains(p.SupplierId.Value)); //模具厂发过来的所有加工任务 var taskCount = baseQuery.Count(); //延期任务 var delayCount = baseQuery.Where(new DelayTaskSpecification()).Count(); result.Add(new { tenant.TenantId, tenant.Name, taskCount, delayCount }); } return(result); } }
/// <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); } }
/// <summary> /// 获取往来单位有对应标记的接收openid /// </summary> /// <param name="unitId"></param> /// <param name="status"></param> /// <returns></returns> public virtual async Task <List <string> > FindUnitOpenId(int unitId, string status = "") { var unit = await MESUnitManager.GetByIdAsync(unitId); return(await MESUnitManager.FindUnitOpenId(unit, status)); }