public async Task GenerateAsync(int purchaseId, PurchaseSettingThreshold threshold, int departmentId, int userId) { var clients = await _mediator.ListAsync <ListHospitalGoodsClientRequest, ListHospitalGoodsClientResponse>(new ListHospitalGoodsClientRequest { HospitalGoodsId = threshold.HospitalGoodsId }); if (!clients.Any()) { return; } var qty = await GetPurchaseGoodsQtyAsync(threshold, departmentId); if (qty <= 0) { return; } Create(new PurchaseGoodsCreateApiModel { HospitalClientId = clients.First().HospitalClient.Id, HospitalGoodsId = threshold.HospitalGoodsId, Qty = qty, PurchaseId = purchaseId, }, userId); }
private async Task <int> GetPurchaseGoodsQtyByPercentAsync(PurchaseSettingThreshold threshold, int storeQty, int departmentId) { var department = await _mediator.GetByIdAsync <GetHospitalDepartmentRequest, GetHospitalDepartmentResponse>(departmentId); var total = _storeRecordContext.GetConsumeAmount(departmentId, threshold.HospitalGoodsId, department.Hospital.ConsumeDays); var average = total / department.Hospital.ConsumeDays; if (storeQty < average * threshold.DownQty) { return(average * threshold.UpQty - storeQty); } return(0); }
public PurchaseSettingThreshold Create(PurchaseSettingThresholdCreateApiModel created, int userId) { var setting = new PurchaseSettingThreshold { PurchaseSettingId = created.PurchaseSettingId, HospitalGoodsId = created.HospitalGoodsId, DownQty = created.DownQty, UpQty = created.UpQty, CreateUserId = userId, CreateTime = DateTime.Now, ThresholdTypeId = created.ThresholdTypeId, }; _context.PurchaseSettingThreshold.Add(setting); _context.SaveChanges(); return(setting); }
private async Task <int> GetPurchaseGoodsQtyAsync(PurchaseSettingThreshold threshold, int departmentId) { var store = _storeContext.GetIndexByGoods(departmentId, threshold.HospitalGoodsId); var storeQty = store?.Qty ?? 0; var qty = 0; switch (threshold.ThresholdTypeId) { case (int)PurchaseSettingThresholdType.ByQty: if (storeQty < threshold.DownQty) { qty = threshold.UpQty - storeQty; } break; case (int)PurchaseSettingThresholdType.ByPercent: qty = await GetPurchaseGoodsQtyByPercentAsync(threshold, storeQty, departmentId); break; } return(qty); }