Ejemplo n.º 1
0
 public Task <string> SubmitForm(ImportMasterEntity entity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         entity.Modify(keyValue);
         entity.F_LastModifyUserId = _usersService.GetCurrentUserId();
         UpdateForm(entity);
     }
     else
     {
         entity.Create();
         //记账标识
         if (entity.F_IsAcct == null)
         {
             entity.F_IsAcct = false;
         }
         if (entity.F_ImpDate == null)
         {
             entity.F_ImpDate = DateTime.Now;
         }
         if (entity.F_EnabledMark == null)
         {
             entity.F_EnabledMark = true;
         }
         entity.F_CreatorUserId = _usersService.GetCurrentUserId();
         _service.Insert(entity);
     }
     return(Task.FromResult(entity.F_Id));
 }
        public async Task <IActionResult> SubmitForm([FromBody] ImportDto input)
        {
            ImportMasterEntity masterEntity;
            var details = new List <ImportDetailEntity>();

            if (input.KeyValue.IsEmpty()) //新增
            {
                masterEntity = new ImportMasterEntity
                {
                    F_Contacts      = input.Master.F_Contacts,
                    F_Costs         = input.Master.F_Costs,
                    F_ImpClass      = input.Master.F_ImpClass,
                    F_ImpDate       = input.Master.F_ImpDate?.ToDate() ?? DateTime.Now,
                    F_ImpNo         = input.Master.F_ImpNo,
                    F_ImpType       = input.Master.F_ImpType,
                    F_Storage       = input.Master.F_Storage,
                    F_Supplier      = input.Master.F_Storage,
                    F_SupplierPhone = input.Master.F_SupplierPhone
                };
            }
            else//修改
            {
                masterEntity = await _importMasterApp.GetForm(input.KeyValue);

                masterEntity.F_Contacts      = input.Master.F_Contacts;
                masterEntity.F_Costs         = input.Master.F_Costs;
                masterEntity.F_ImpClass      = input.Master.F_ImpClass;
                masterEntity.F_ImpDate       = input.Master.F_ImpDate?.ToDate() ?? DateTime.Now;
                masterEntity.F_ImpNo         = input.Master.F_ImpNo;
                masterEntity.F_ImpType       = input.Master.F_ImpType;
                masterEntity.F_Storage       = input.Master.F_Storage;
                masterEntity.F_Supplier      = input.Master.F_Storage;
                masterEntity.F_SupplierPhone = input.Master.F_SupplierPhone;
            }
            var masterId = await _importMasterApp.SubmitForm(masterEntity, input.KeyValue);

            switch (input.Master.F_ImpClass)
            {
            case "药品入库":
            {
                var drugs = (await _drugsApp.GetList()).ToList();
                details = (from item in input.Details
                           let amount = item.F_Amount.ToInt()
                                        where amount != 0
                                        let drug = drugs.FirstOrDefault(t => t.F_Id == item.F_ItemId)
                                                   where drug != null
                                                   select new ImportDetailEntity
                    {
                        F_Id = item.F_Id,
                        F_ImpId = masterId,
                        F_ItemId = item.F_ItemId,
                        F_Amount = amount,
                        F_Code = drug.F_DrugCode,
                        F_Charges = drug.F_Charges,
                        F_Name = drug.F_DrugName,
                        F_Unit = drug.F_DrugUnit,
                        F_Spec = drug.F_DrugSpec,
                        F_TotalCharges = (drug.F_Charges * amount).ToFloat(2)
                    }).ToList();

                await _importDetailApp.InsertBatch(details);

                break;
            }

            case "耗材入库":
                var materials = (await _materialApp.GetList()).ToList();
                details = (from item in input.Details
                           let amount = item.F_Amount.ToInt()
                                        where amount != 0
                                        let material = materials.FirstOrDefault(t => t.F_Id == item.F_ItemId)
                                                       where material != null
                                                       select new ImportDetailEntity
                {
                    F_Id = item.F_Id,
                    F_ImpId = masterId,
                    F_ItemId = item.F_ItemId,
                    F_Amount = amount,
                    F_Code = material.F_MaterialCode,
                    F_Charges = material.F_Charges,
                    F_Name = material.F_MaterialName,
                    F_Unit = material.F_MaterialUnit,
                    F_Spec = material.F_MaterialSpec,
                    F_TotalCharges = (material.F_Charges * amount).ToFloat(2)
                }).ToList();

                await _importDetailApp.InsertBatch(details);

                break;
            }
            //更新主记录总金额
            masterEntity = await _importMasterApp.GetForm(masterId);

            masterEntity.F_Costs = details.Sum(t => t.F_TotalCharges);
            await _importMasterApp.UpdateForm(masterEntity);

            return(Success("操作成功。"));
        }
Ejemplo n.º 3
0
 public Task <int> UpdateForm(ImportMasterEntity entity)
 {
     return(_service.UpdatePartialAsync(entity));
 }