Exemplo n.º 1
0
        /// <summary>
        /// 成品自动入库任务
        /// </summary>
        /// <param name="inputDtos"></param>
        /// <returns></returns>
        public async Task <OperationResult> ProductInStorageShowTask(params MaterialInStorageInfoInputDto[] 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].MatWareHouseLocations.Count();
                if (count == 1)
                {   //成品自动入库,若需要校验RFID扫描的托盘编号和初始值是否一致,后期可以放开这个条件。目前测试不需要这个条件
                    //Guid? pid = inputDtos[i].PalletID;
                    //string palletcode = MatPalletInfoRepository.TrackEntities.Where(m => m.Id == pid).FirstOrDefault().PalletCode;
                    //if (palletcode == inputDtos[i].PalletCode)
                    //{
                    DisTaskDispatchInfoInputDto dispatchInfo = new DisTaskDispatchInfoInputDto();
                    dispatchInfo.DisStepAction     = DisStepActionInfoRepository.TrackEntities.Where(m => m.StepActionCode == "StepAction_ProductInStorage").FirstOrDefault();
                    dispatchInfo.TaskCode          = "Task_ProductInStorageShow" + 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.InStorage_Id      = inputDtos[i].Id;
                    dispatchInfos[i] = dispatchInfo;
                    //更新库位表
                    MatWareHouseLocationInfo locationInfo = new MatWareHouseLocationInfo();
                    Guid locationid = inputDtos[i].MatWareHouseLocations[0].Id;
                    locationInfo          = MatWareHouseLocationInfoRepository.TrackEntities.Where(x => x.Id == locationid).FirstOrDefault();
                    locationInfo.PalletID = inputDtos[i].PalletID;
                    count1 += await MatWareHouseLocationInfoRepository.UpdateAsync(locationInfo);

                    //插入出库单
                    MaterialInStorageInfo instorageInfo = new MaterialInStorageInfo();
                    instorageInfo.MaterialID        = MaterialInfoRepository.TrackEntities.Where(x => x.MaterialType == 3).FirstOrDefault().Id;
                    instorageInfo.InStorageBillCode = "InStorage" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    instorageInfo.Quantity          = inputDtos[i].Quantity;
                    instorageInfo.PalletID          = inputDtos[i].PalletID;
                    instorageInfo.InStorageStatus   = 2;
                    instorageInfo.AuditStatus       = 3;
                    instorageInfo.InStorageTime     = inputDtos[i].CreatedTime;
                    instorageInfo.AuditPerson       = inputDtos[i].CreatorUserId;
                    instorageInfo.FinishTime        = DateTime.Now;
                    instorageInfo.InStorageType     = 3;
                    instorageInfo.PalletQuantity    = 1;
                    instorageInfo.CreatedTime       = inputDtos[i].CreatedTime;
                    instorageInfo.CreatorUserId     = inputDtos[i].CreatorUserId;
                    instorageInfo.LastUpdatedTime   = inputDtos[i].LastUpdatedTime;
                    instorageInfo.LastUpdatorUserId = inputDtos[i].LastUpdatorUserId;
                    count1 += await MaterialInStorageRepository.InsertAsync(instorageInfo);

                    //插入批次表
                    MaterialBatchInfo batchInfo = new MaterialBatchInfo();
                    batchInfo.BatchCode            = "Batch" + DateTime.Now.ToString("yyyyMMddhhmmss");
                    batchInfo.Material             = MaterialInfoRepository.TrackEntities.Where(x => x.MaterialType == 3).FirstOrDefault();
                    batchInfo.MatWareHouseLocation = MatWareHouseLocationInfoRepository.TrackEntities.Where(x => x.Id == locationid).FirstOrDefault();
                    batchInfo.MaterialInStorage    = instorageInfo;
                    batchInfo.Quantity             = inputDtos[i].Quantity;
                    batchInfo.CreatorUserId        = inputDtos[i].CreatorUserId;
                    batchInfo.LastUpdatedTime      = inputDtos[i].LastUpdatedTime;
                    batchInfo.LastUpdatorUserId    = inputDtos[i].LastUpdatorUserId;
                    count1 += await MaterialBatchRepository.InsertAsync(batchInfo);

                    //插入库存日志表
                    MaterialStorageLogInfoInputDto logInfo = new MaterialStorageLogInfoInputDto();
                    logInfo.MaterialBatch = batchInfo;
                    var mid = inputDtos[i].MaterialID;
                    logInfo.Material          = MaterialInfoRepository.TrackEntities.Where(x => x.MaterialType == 3).FirstOrDefault();
                    logInfo.StorageChangeType = 1;
                    logInfo.OriginalAmount    = 0;
                    logInfo.ChangedAmount     = inputDtos[i].Quantity;
                    logInfo.CurrentAmount     = inputDtos[i].Quantity;
                    logInfo.InStorageID       = instorageInfo.Id;
                    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, "托盘编号与初始值不一致!" + inputDtos[i].PalletCode + ";原PalletCode:" + palletcode);
                    //}
                }
                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, "成品自动回库任务操作失败!"));
        }