Пример #1
0
        /// <summary>
        /// 分步教学-原料自动出库演示操作
        /// </summary>
        /// <param name="inputDtos"></param>
        /// <returns></returns>
        public async Task <OperationResult> MaterialOutStorageShowTask(params MaterialOutStorageInfoInputDto[] inputDtos)
        {
            inputDtos.CheckNotNull("inputDtos");
            OperationResult result1 = new OperationResult();
            OperationResult result2 = new OperationResult();
            int             count0  = inputDtos.Count();

            DisTaskDispatchInfoInputDto[]    dispatchInfos = new DisTaskDispatchInfoInputDto[count0];
            MaterialStorageLogInfoInputDto[] logInfos      = new MaterialStorageLogInfoInputDto[count0];
            MaterialStorageLogRepository.UnitOfWork.BeginTransaction();
            int count1 = 0;

            for (int i = 0; i < inputDtos.Count(); i++)
            {
                int count = inputDtos[i].MaterialBatchs.Count();
                if (count == 1)
                {
                    DisTaskDispatchInfoInputDto dispatchInfo = new DisTaskDispatchInfoInputDto();
                    dispatchInfo.DisStepAction     = DisStepActionInfoRepository.TrackEntities.Where(m => m.StepActionCode == "StepAction_MaterialOutStorageShow").FirstOrDefault();
                    dispatchInfo.TaskCode          = "Task_MaterialOutStorageShow" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    dispatchInfo.CreatedTime       = inputDtos[i].CreatedTime;
                    dispatchInfo.TaskResult        = "成功";
                    dispatchInfo.FinishTime        = DateTime.Now;
                    dispatchInfo.LastUpdatedTime   = inputDtos[i].LastUpdatedTime;
                    dispatchInfo.LastUpdatorUserId = inputDtos[i].LastUpdatorUserId;
                    dispatchInfo.CreatorUserId     = inputDtos[i].CreatorUserId;
                    dispatchInfo.Description       = "原料自动出库演示";
                    dispatchInfo.OutStorage_Id     = inputDtos[i].Id;
                    dispatchInfos[i] = dispatchInfo;
                    //更新库位表
                    MatWareHouseLocationInfo locationInfo = new MatWareHouseLocationInfo();
                    var  bid        = inputDtos[i].MaterialBatchs[0].Id;
                    Guid locationid = MaterialBatchRepository.TrackEntities.Where(x => x.Id == bid).FirstOrDefault().MatWareHouseLocation.Id;
                    locationInfo = MatWareHouseLocationInfoRepository.TrackEntities.Where(x => x.Id == locationid).FirstOrDefault();
                    Guid?palletid = locationInfo.PalletID;
                    locationInfo.PalletID = null;
                    count1 += await MatWareHouseLocationInfoRepository.UpdateAsync(locationInfo);

                    //更新出库单
                    MaterialOutStorageInfo outstorageInfo = new MaterialOutStorageInfo();
                    var oid = inputDtos[i].Id;
                    outstorageInfo                   = MaterialOutStorageRepository.TrackEntities.Where(x => x.Id == oid).FirstOrDefault();
                    outstorageInfo.PalletID          = palletid;
                    outstorageInfo.FinishTime        = DateTime.Now;
                    outstorageInfo.OutStorageStatus  = 2;
                    outstorageInfo.PalletQuantity    = 1;
                    outstorageInfo.LastUpdatedTime   = inputDtos[i].LastUpdatedTime;
                    outstorageInfo.LastUpdatorUserId = inputDtos[i].LastUpdatorUserId;
                    count1 += await MaterialOutStorageRepository.UpdateAsync(outstorageInfo);

                    //更新批次表
                    MaterialBatchInfo batchInfo = new MaterialBatchInfo();
                    batchInfo = MaterialBatchRepository.TrackEntities.Where(x => x.Id == bid).FirstOrDefault();
                    if (batchInfo.Quantity != outstorageInfo.Quantity)
                    {
                        return(new OperationResult(OperationResultType.Error, "Service:选择库位库存与出库单数量不一致!"));
                    }
                    batchInfo.Quantity          = 0;
                    batchInfo.LastUpdatedTime   = inputDtos[i].LastUpdatedTime;
                    batchInfo.LastUpdatorUserId = inputDtos[i].LastUpdatorUserId;
                    count1 += await MaterialBatchRepository.UpdateAsync(batchInfo);

                    //插入库存日志表
                    MaterialStorageLogInfoInputDto logInfo = new MaterialStorageLogInfoInputDto();
                    logInfo.MaterialBatch = MaterialBatchRepository.TrackEntities.Where(x => x.Id == bid).FirstOrDefault();
                    var mid = outstorageInfo.MaterialID;
                    logInfo.Material          = MaterialInfoRepository.TrackEntities.Where(x => x.Id == mid).FirstOrDefault();
                    logInfo.StorageChangeType = 2;
                    logInfo.OriginalAmount    = outstorageInfo.Quantity;
                    logInfo.ChangedAmount     = -outstorageInfo.Quantity;
                    logInfo.CurrentAmount     = 0;
                    logInfo.OutStorageID      = oid;
                    logInfo.CreatorUserId     = inputDtos[i].CreatorUserId;
                    logInfo.CreatedTime       = inputDtos[i].CreatedTime;
                    logInfo.LastUpdatedTime   = inputDtos[i].LastUpdatedTime;
                    logInfo.LastUpdatorUserId = inputDtos[i].LastUpdatorUserId;
                    logInfos[i] = logInfo;
                }
                else
                {
                    return(new OperationResult(OperationResultType.Error, "选择库位数据异常,该组数据不被存储。"));
                }
            }
            result1 = await DisTaskDispatchInfoRepository.InsertAsync(dispatchInfos);

            result2 = await MaterialStorageLogRepository.InsertAsync(logInfos);

            MaterialStorageLogRepository.UnitOfWork.Commit();
            return(count1 >= 3
               ? new OperationResult(OperationResultType.Success, "原料自动出库任务操作成功!")
               : new OperationResult(OperationResultType.Error, "原料自动出库任务操作失败!"));
            // return new OperationResult(OperationResultType.Success, "原料自动出库任务操作成功");
        }
Пример #2
0
        /// <summary>
        /// 设置出库任务的库位
        /// </summary>
        /// <param name="id">入库任务编号</param>
        /// <param name="roleIds">库位编号集合</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> SetMaterialOutStorageMaterialBatch(Guid MaterialOutStorageId, MaterialOutStorageInfoInputDto MaterialOutStorageDtos, Guid[] MaterialBatchIds, string UserName)
        {
            int count = 0;
            //
            //////////////出库单
            //MaterialOutStorageInfo materialoutstorageInfo = new MaterialOutStorageInfo();
            //materialoutstorageInfo = MaterialOutStorageRepository.TrackEntities.Where(m => m.Id == MaterialOutStorageId).FirstOrDefault();
            //////////////
            decimal dQuantity        = MaterialOutStorageDtos.Quantity.Value;
            decimal dChangedQuantity = 0;
            //
            decimal dPalletQuantity = MaterialOutStorageDtos.PalletQuantity.Value;

            dPalletQuantity = 0;
            //
            decimal dPartQuantity = 0;

            //////////////库位表
            foreach (Guid MaterialBatchId in MaterialBatchIds)
            {
                MaterialBatchInfo materialbatchInfo = new MaterialBatchInfo();
                //
                materialbatchInfo = MaterialBatchRepository.TrackEntities.Where(m => m.Id == MaterialBatchId).FirstOrDefault();
                //
                decimal dMaterialBatchQuantity = materialbatchInfo.Quantity.Value;
                //
                if (dQuantity >= dMaterialBatchQuantity)
                {
                    materialbatchInfo.Quantity = 0;
                    dQuantity        = dQuantity - dMaterialBatchQuantity;
                    dChangedQuantity = dMaterialBatchQuantity;
                    //
                    dPalletQuantity++;
                }
                else if (dQuantity > 0)
                {
                    dPartQuantity = 0;
                    materialbatchInfo.Quantity = dMaterialBatchQuantity - dQuantity;
                    //部分出库 库位清零
                    dPartQuantity = materialbatchInfo.Quantity.Value;
                    materialbatchInfo.Quantity = 0;
                    //
                    dChangedQuantity = dQuantity;
                    dQuantity        = 0;
                    //
                    dPalletQuantity++;
                }
                else
                {
                    break;
                }
                //
                materialbatchInfo.LastUpdatorUserId = UserName;
                materialbatchInfo.LastUpdatedTime   = DateTime.Now;
                //
                count += await MaterialBatchRepository.UpdateAsync(materialbatchInfo);

                //////////////
                //////////////流水帐

                MaterialStorageLogInfo materialstoragelogInfo = new MaterialStorageLogInfo();
                //
                Guid MaterialBatch_Id = materialbatchInfo.Id;
                materialstoragelogInfo.MaterialBatch = MaterialBatchRepository.TrackEntities.Where(m => m.Id == MaterialBatch_Id).FirstOrDefault();
                //
                Guid MaterialID = MaterialOutStorageDtos.MaterialID.Value;
                materialstoragelogInfo.Material = MaterialInfoRepository.TrackEntities.Where(m => m.Id == MaterialID).FirstOrDefault();
                //
                materialstoragelogInfo.OutStorageID = MaterialOutStorageDtos.Id;
                //
                materialstoragelogInfo.OriginalAmount = dMaterialBatchQuantity;
                //materialstoragelogInfo.ChangedAmount = dChangedQuantity;
                //修改 关永强 Bug 成品出库改变数量应为负数
                materialstoragelogInfo.ChangedAmount = -dChangedQuantity;
                materialstoragelogInfo.CurrentAmount = materialbatchInfo.Quantity;
                //
                //出库
                materialstoragelogInfo.StorageChangeType = (int)StorageChangeTypeEnumModel.StorageChangeType.OutStorageChangeType;
                //
                if (dPartQuantity > 0)
                {
                    materialstoragelogInfo.Remark = "部分出库,应进行退库操作!数量为:" + dPartQuantity.ToString();
                }
                //
                materialstoragelogInfo.CreatorUserId     = UserName;
                materialstoragelogInfo.CreatedTime       = DateTime.Now;
                materialstoragelogInfo.LastUpdatorUserId = materialstoragelogInfo.CreatorUserId;
                materialstoragelogInfo.LastUpdatedTime   = materialstoragelogInfo.CreatedTime;
                //
                count += await MaterialStorageLogRepository.InsertAsync(materialstoragelogInfo);

                //////////////库位表
                MatWareHouseLocationInfo matwarehouselocationInfo = new MatWareHouseLocationInfo();
                //
                matwarehouselocationInfo = MatWareHouseLocationInfoRepository.TrackEntities.Where(m => m.Id == materialbatchInfo.MatWareHouseLocation.Id).FirstOrDefault();
                //
                matwarehouselocationInfo.PalletID = null;
                //
                count += await MatWareHouseLocationInfoRepository.UpdateAsync(matwarehouselocationInfo);
            }
            //
            //出库单
            MaterialOutStorageDtos.OutStorageTime = DateTime.Now;
            MaterialOutStorageDtos.FinishTime     = DateTime.Now;
            //已完成
            MaterialOutStorageDtos.OutStorageStatus = (int)OutStorageStatusEnumModel.OutStorageStatus.OutStorageFinishStatus;
            MaterialOutStorageDtos.PalletQuantity   = dPalletQuantity;
            //
            MaterialOutStorageInfo materialoutstorageInfo = new MaterialOutStorageInfo();

            materialoutstorageInfo = MaterialOutStorageDtos.MapTo(materialoutstorageInfo);
            //
            count += await MaterialOutStorageRepository.UpdateAsync(materialoutstorageInfo);

            //
            return(count > 0
                ? new OperationResult(OperationResultType.Success, "出库任务“{0}”指派库位批次操作成功".FormatWith("Test"))
                : OperationResult.Success);
        }