Пример #1
0
        /// <summary>
        /// 生成收件清单
        /// </summary>
        /// <param name="placeId">场所ID</param>
        /// <param name="objectId">流转对象ID</param>
        /// <param name="userId">用户ID</param>
        /// <param name="departmentId">收件单位ID</param>
        /// <returns></returns>
        public async Task <ResultEntity> CreateReceiveBill(int placeId, int objectId, int userId, int departmentId)
        {
            _logger.LogWarning($"--------------开始形成取件清单--------------");
            var result      = new ResultEntity();
            var barcodeLogs = await _barcodeLogRepository.GetQueryable().Where(a =>
                                                                               !a.IsSynBill && a.CurrentPlaceId == placeId && a.CurrentObjectId == objectId &&
                                                                               a.BarcodeStatus == EnumBarcodeStatus.已签收).ToListAsync();

            if (barcodeLogs.Count > 0)
            {
                var exchangeObject = await _exchangeObjectRepository.GetByIdAsync(objectId);

                var user = await _userRepository.GetByIdAsync(userId);

                var barcodeNumbers = barcodeLogs.Select(a => a.BarcodeNumber).ToList();
                var letters        = _letterRepository.GetQueryable().Include(a => a.ReceiveDepartment).Include(a => a.SendDepartment)
                                     .Where(a => barcodeNumbers.Contains(a.BarcodeNo));
                //清单全局使用一个流水,防止串号
                var serialNo = await _serialNumberManager.GetSerialNumber(0, EnumSerialNumberType.清单);

                var exchangeList = new ExchangeList
                {
                    CreateBy         = userId,
                    CreateTime       = DateTime.Now,
                    DepartmentId     = departmentId,
                    ObjectName       = exchangeObject.Name,
                    ExchangeUserId   = userId,
                    ExchangeUserName = user.DisplayName,
                    ObjectId         = objectId,
                    Printed          = false,
                    Type             = EnumListType.收件清单
                };
                exchangeList.ListNo = exchangeList.GetListNo(serialNo);
                await _exchangeListRepository.AddAsync(exchangeList);

                await _unitOfWork.CommitAsync();

                foreach (var letter in letters)
                {
                    var barcodeLog = barcodeLogs.FirstOrDefault(a => a.BarcodeNumber == letter.BarcodeNo);
                    if (barcodeLog != null)
                    {
                        var exchangeListDetail = new ExchangeListDetail
                        {
                            BarcodeNo             = letter.LetterNo,
                            CustomData            = letter.CustomData,
                            DetailType            = barcodeLog.BarcodeSubStatus == EnumBarcodeSubStatus.退回 ? EnumListDetailType.收退件 : EnumListDetailType.收件,
                            ExchangeListId        = exchangeList.Id,
                            ReceiveDepartmentName = letter.ReceiveDepartment.FullName,
                            SendDepartmentName    = letter.SendDepartment.FullName,
                            SecSecretLevelText    = letter.GetSecretLevel(letter.BarcodeNo).ToString(),
                            UrgencyLevelText      = letter.GetUrgencyLevel(letter.BarcodeNo).ToString(),
                            Time = barcodeLog.LastOperationTime
                        };
                        await _exchangeListDetailRepository.AddAsync(exchangeListDetail);

                        barcodeLog.IsSynBill = true;
                    }
                }
                result.Success = true;
                result.Data    = exchangeList.Id;
                await _unitOfWork.CommitAsync();
            }
            else
            {
                _logger.LogWarning($"暂无收件清单");
                result.Message = "暂无收件清单";
            }
            _logger.LogWarning($"--------------结束形成取件清单--------------");
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 生成收发清单
        /// </summary>
        /// <param name="placeId">场所ID</param>
        /// <param name="userId">用户ID</param>
        /// <param name="departmentId">单位ID</param>
        /// <returns></returns>
        public async Task <ResultEntity> CreateReceiveSendBill(int placeId, int userId, int departmentId)
        {
            _logger.LogWarning($"--------------开始形成收发件清单--------------");
            var result = new ResultEntity();

            Stopwatch stopwatch = new Stopwatch();


            stopwatch.Start();
            var receiveBarcodeLogs = await _barcodeLogRepository.GetQueryable().Where(a =>
                                                                                      !a.IsSynBill && a.CurrentPlaceId == placeId && a.DepartmentId == departmentId &&
                                                                                      a.BarcodeStatus == EnumBarcodeStatus.已签收).ToListAsync();

            stopwatch.Stop();
            _logger.LogWarning($"receiveBarcodeLogs:{stopwatch.Elapsed.TotalSeconds}");

            stopwatch.Restart();
            var sendBarcodeLogs = await _barcodeLogRepository.GetQueryable().Where(a =>
                                                                                   !a.IsSynBill && a.CurrentPlaceId == placeId && a.DepartmentId == departmentId &&
                                                                                   a.BarcodeStatus == EnumBarcodeStatus.已投递).ToListAsync();

            stopwatch.Stop();
            _logger.LogWarning($"sendBarcodeLogs:{stopwatch.Elapsed.TotalSeconds}");

            if (receiveBarcodeLogs.Count > 0 || sendBarcodeLogs.Count > 0)
            {
                //清单全局使用一个流水,防止串号
                var serialNo = await _serialNumberManager.GetSerialNumber(0, EnumSerialNumberType.清单);

                var receiveBarcodeNumbers = receiveBarcodeLogs.Select(a => a.BarcodeNumber).ToList();
                stopwatch.Restart();
                var receiveLettesr = await _letterRepository.GetQueryable().Include(a => a.ReceiveDepartment).Include(a => a.SendDepartment)
                                     .Where(a => receiveBarcodeNumbers.Contains(a.BarcodeNo)).ToListAsync();

                stopwatch.Stop();
                _logger.LogWarning($"receiveLettesr:{stopwatch.Elapsed.TotalSeconds}");

                var sendBarcodeNumbers = sendBarcodeLogs.Select(a => a.BarcodeNumber).ToList();
                stopwatch.Restart();
                var sendLetters = await _letterRepository.GetQueryable().Include(a => a.ReceiveDepartment)
                                  .Include(a => a.SendDepartment)
                                  .Where(a => sendBarcodeNumbers.Contains(a.BarcodeNo)).ToListAsync();

                stopwatch.Stop();
                _logger.LogWarning($"sendLetters:{stopwatch.Elapsed.TotalSeconds}");

                var department = await _departmentRepository.GetByIdAsync(departmentId);

                var user = await _userRepository.GetByIdAsync(userId);

                //添加主清单
                var exchangeList = new ExchangeList
                {
                    CreateBy         = userId,
                    ObjectName       = department.Name,
                    ExchangeUserId   = userId,
                    ExchangeUserName = user.DisplayName,
                    CreateTime       = DateTime.Now,
                    DepartmentId     = departmentId,
                    Printed          = false,
                    Type             = EnumListType.收发清单
                };
                exchangeList.ListNo = exchangeList.GetListNo(serialNo);
                await _exchangeListRepository.AddAsync(exchangeList);

                await _unitOfWork.CommitAsync();

                //添加收件详情
                stopwatch.Restart();
                foreach (var letter in receiveLettesr)
                {
                    var barcodeLog = receiveBarcodeLogs.FirstOrDefault(a => a.BarcodeNumber == letter.BarcodeNo);
                    if (barcodeLog != null)
                    {
                        var exchangeListDetail = new ExchangeListDetail
                        {
                            BarcodeNo             = letter.LetterNo,
                            CustomData            = letter.CustomData,
                            DetailType            = barcodeLog.BarcodeSubStatus == EnumBarcodeSubStatus.退回 ? EnumListDetailType.收退件 : EnumListDetailType.收件,
                            ExchangeListId        = exchangeList.Id,
                            ReceiveDepartmentName = letter.ReceiveDepartment.FullName,
                            SendDepartmentName    = letter.SendDepartment.FullName,
                            SecSecretLevelText    = letter.GetSecretLevel(letter.BarcodeNo).ToString(),
                            UrgencyLevelText      = letter.GetUrgencyLevel(letter.BarcodeNo).ToString(),
                            Time = barcodeLog.LastOperationTime
                        };
                        await _exchangeListDetailRepository.AddAsync(exchangeListDetail);

                        barcodeLog.IsSynBill = true;
                    }
                }
                //添加发件详情
                foreach (var letter in sendLetters)
                {
                    var barcodeLog = sendBarcodeLogs.FirstOrDefault(a => a.BarcodeNumber == letter.BarcodeNo);
                    if (barcodeLog != null)
                    {
                        var exchangeListDetail = new ExchangeListDetail
                        {
                            BarcodeNo             = letter.LetterNo,
                            CustomData            = letter.CustomData,
                            DetailType            = barcodeLog.BarcodeSubStatus == EnumBarcodeSubStatus.退回 ? EnumListDetailType.发退件 : EnumListDetailType.发件,
                            ExchangeListId        = exchangeList.Id,
                            ReceiveDepartmentName = letter.ReceiveDepartment.FullName,
                            SendDepartmentName    = letter.SendDepartment.FullName,
                            SecSecretLevelText    = letter.GetSecretLevel(letter.BarcodeNo).ToString(),
                            UrgencyLevelText      = letter.GetUrgencyLevel(letter.BarcodeNo).ToString(),
                            Time = barcodeLog.OperationTime
                        };
                        await _exchangeListDetailRepository.AddAsync(exchangeListDetail);

                        barcodeLog.IsSynBill = true;
                    }
                }
                stopwatch.Stop();
                _logger.LogWarning($"循环插入:{stopwatch.Elapsed.TotalSeconds}");
                await _unitOfWork.CommitAsync();

                result.Success = true;
                result.Data    = exchangeList.Id;
            }
            else
            {
                result.Message = "暂无收发清单数据";
                _logger.LogWarning($"暂无收发清单数据");
            }
            _logger.LogWarning($"--------------结束形成收发件清单--------------");
            return(result);
        }