コード例 #1
0
        public async Task <ResultEntity> AddReceiveLetter(ReceiveLetterEditDto receiveLetter)
        {
            var result                = new ResultEntity();
            var sendDepartmentCode    = TextHelper.RepairZeroRight(await _departmentManager.GetDepartmentCode(receiveLetter.SendDepartmentId), 11);
            var receiveDepartmentCode = TextHelper.RepairZeroRight(await _departmentManager.GetDepartmentCode(receiveLetter.ReceiveDepartmentId), 11);
            var serialNumber          = await _serialNumberManager.GetSerialNumber(receiveLetter.SendDepartmentId, EnumSerialNumberType.内部交换);

            var barcodeNo = _barcodeManager.MakeBarcodeLength33(sendDepartmentCode, receiveDepartmentCode,
                                                                (EnumSecretLevel)receiveLetter.SecretLevel, (EnumUrgentLevel)receiveLetter.UrgencyLevel,
                                                                serialNumber);

            if (barcodeNo == "")
            {
                result.Message = "条码生成失败";
                return(result);
            }
            receiveLetter.BarcodeNo = barcodeNo;
            receiveLetter.LetterNo  = barcodeNo.Substring(15, 7);
            var letter = Mapper.Map <Letter>(receiveLetter);
            await _letterRepository.AddAsync(letter);

            var barcode = new Barcode
            {
                BarcodeNo  = barcodeNo,
                Entity     = EnumBarcodeEntity.信件,
                Souce      = EnumBarcodeSouce.本系统,
                Status     = EnumBarcodeStatus.已就绪,
                SubStatus  = EnumBarcodeSubStatus.正常,
                CreateTime = DateTime.Now,
                CreateBy   = receiveLetter.CreateBy
            };

            barcode.BarcodeType = barcode.AnalysisBarcodeType(barcodeNo);
            await _barcodeRepository.AddAsync(barcode);

            var baroceLog = new BarcodeLog
            {
                BarcodeNumber = barcodeNo,
                BarcodeStatus = EnumBarcodeStatus.已就绪,
                DepartmentId  = letter.SendDepartmentId,
                OperationTime = DateTime.Now,
                OperatorId    = receiveLetter.CreateBy,
            };

            await _barcodeLogRepository.AddAsync(baroceLog);

            result.Success = true;
            await _unitOfWork.CommitAsync();

            result.Data = letter.Id;
            return(result);
        }
コード例 #2
0
        public async Task <ResultEntity> CancelLetter(int letterId, int departmentId, int operatorId, int applicantId)
        {
            var result = new ResultEntity();
            var letter = await _letterRepository.GetByIdAsync(letterId);

            var barcode = await _barcodeRepository.GetByNoAsync(letter.BarcodeNo);

            if (barcode == null || barcode.Status != EnumBarcodeStatus.已投递)
            {
                result.Message = "流转状态不正确,无法勘误!";
            }
            else
            {
                barcode.Status = EnumBarcodeStatus.已勘误;
                var cancelLetter = new CancelLetter
                {
                    LetterId = letterId,
                    OperationDepartmentId = departmentId,
                    OperatorId            = operatorId,
                    ApplicantId           = 0,
                    OperationTime         = DateTime.Now
                };
                var barcodeLog = new BarcodeLog
                {
                    BarcodeNumber   = barcode.BarcodeNo,
                    BarcodeStatus   = EnumBarcodeStatus.已勘误,
                    CurrentObjectId = barcode.CurrentObjectId,
                    CurrentPlaceId  = barcode.CurrentPlaceId,
                    DepartmentId    = letter.ReceiveDepartmentId,
                    OperationTime   = DateTime.Now,
                    OperatorId      = null,
                    Remark          = "文件已勘误"
                };

                result = await _boxManager.Cancel(barcode.CurrentObjectId);

                if (result.Success)
                {
                    await _barcodeLogRepository.AddAsync(barcodeLog);

                    await _cancelLetterRepository.AddAsync(cancelLetter);

                    await _unitOfWork.CommitAsync();
                }
            }
            return(result);
        }
コード例 #3
0
        public async Task <ResultEntity> BackLetter(int letterId, int departmentId, int operatorId)
        {
            var result = new ResultEntity();
            var letter = await _letterRepository.GetByIdAsync(letterId);

            var existBack = await _backLetterRepository.GetQueryable().Where(a => a.LetterId == letterId).CountAsync() > 0;

            if (existBack)
            {
                result.Message = "该文件已经存在退回记录,请勿重复操作!";
            }
            else
            {
                var barcode = await _barcodeRepository.GetByNoAsync(letter.BarcodeNo);

                if (barcode == null || barcode.Status != EnumBarcodeStatus.已签收)
                {
                    result.Message = "流转状态不正确,无法退回!";
                }
                else
                {
                    barcode.Status = EnumBarcodeStatus.申请退回;
                    var backLetter = new BackLetter
                    {
                        LetterId = letterId,
                        OperationDepartmentId = departmentId,
                        OperatorId            = operatorId,
                        OperationTime         = DateTime.Now
                    };
                    var barcodeLog = new BarcodeLog
                    {
                        BarcodeNumber   = barcode.BarcodeNo,
                        BarcodeStatus   = EnumBarcodeStatus.申请退回,
                        CurrentObjectId = barcode.CurrentObjectId,
                        CurrentPlaceId  = barcode.CurrentPlaceId,
                        DepartmentId    = letter.ReceiveDepartmentId,
                        OperationTime   = DateTime.Now,
                        OperatorId      = operatorId,
                        Remark          = "文件已申请退回"
                    };


                    //退信后干掉分拣记录
                    var sortingLetter = await _sortingRepository.GetQueryable().AsNoTracking().Where(a => a.BarcodeNo == letter.BarcodeNo && !a.Sorted)
                                        .FirstOrDefaultAsync();

                    if (sortingLetter != null)
                    {
                        await _sortingRepository.DeleteByIdAsync(sortingLetter.Id);
                    }

                    await _barcodeLogRepository.AddAsync(barcodeLog);

                    await _backLetterRepository.AddAsync(backLetter);

                    await _unitOfWork.CommitAsync();

                    result.Success = true;
                }
            }

            return(result);
        }
コード例 #4
0
        public async Task <ResultEntity> AddSendLetter(LetterSendEditDto sendLetter)
        {
            var result = new ResultEntity();
            var letter = Mapper.Map <Letter>(sendLetter);

            if (string.IsNullOrWhiteSpace(letter.BarcodeNo))
            {
                var receiveDepartment = await _departmentManager.GetAsync(sendLetter.ReceiveDepartmentId);

                var sendDepartmentCode    = TextHelper.RepairZeroRight(await _departmentManager.GetDepartmentCode(sendLetter.SendDepartmentId), 11);
                var receiveDepartmentCode = TextHelper.RepairZeroRight(await _departmentManager.GetDepartmentCode(sendLetter.ReceiveDepartmentId), 11);
                letter.LetterType = letter.GetSendLetterType(sendDepartmentCode, receiveDepartmentCode);
                if (receiveDepartment.ReceiveChannel == EnumChannel.机要通信)
                {
                    letter.LetterType = EnumLetterType.发信;
                }
                int serialNumber;
                var barcodeNo = "";
                switch (letter.LetterType)
                {
                case EnumLetterType.发信:
                    switch (receiveDepartment.ReceiveChannel)
                    {
                    case EnumChannel.城交换:
                        serialNumber = await _serialNumberManager.GetSerialNumber(letter.SendDepartmentId, EnumSerialNumberType.城交换);

                        barcodeNo = _barcodeManager.MakeBarcodeLength26(sendDepartmentCode, receiveDepartmentCode,
                                                                        letter.SecretLevel, letter.UrgencyLevel,
                                                                        serialNumber);
                        break;

                    case EnumChannel.机要通信:
                        serialNumber = await _serialNumberManager.GetSerialNumber(letter.SendDepartmentId, EnumSerialNumberType.机要通信);

                        barcodeNo = _barcodeManager.MakeBarcodeLength33(sendDepartmentCode, receiveDepartmentCode,
                                                                        letter.SecretLevel, letter.UrgencyLevel,
                                                                        serialNumber);
                        break;
                    }
                    break;

                case EnumLetterType.内交换:
                    serialNumber = await _serialNumberManager.GetSerialNumber(letter.SendDepartmentId, EnumSerialNumberType.内部交换);

                    barcodeNo = _barcodeManager.MakeBarcodeLength33(sendDepartmentCode, receiveDepartmentCode,
                                                                    letter.SecretLevel, letter.UrgencyLevel,
                                                                    serialNumber);
                    break;

                default:
                    throw new ArgumentOutOfRangeException($"发信类型有误");
                }

                if (barcodeNo == "")
                {
                    result.Message = "条码生成失败";
                    return(result);
                }
                letter.BarcodeNo = barcodeNo;
                letter.LetterNo  = letter.GetLetterNo(barcodeNo);
            }
            else
            {
                var receiveDepartment = await _departmentManager.GetAsync(sendLetter.ReceiveDepartmentId);

                var sendDepartment = await _departmentManager.GetAsync(sendLetter.SendDepartmentId);

                var sendDepartmentCode    = TextHelper.RepairZeroRight(await _departmentManager.GetDepartmentCode(sendLetter.SendDepartmentId), 11);
                var receiveDepartmentCode = TextHelper.RepairZeroRight(await _departmentManager.GetDepartmentCode(sendLetter.ReceiveDepartmentId), 11);
                letter.LetterType = letter.GetSendLetterType(sendDepartmentCode, receiveDepartmentCode);
                letter.LetterNo   = letter.GetLetterNo(letter.BarcodeNo);
                if (receiveDepartment.ReceiveChannel == EnumChannel.机要通信)
                {
                    letter.LetterType = EnumLetterType.发信;
                }

                if (sendDepartment.ReceiveChannel == EnumChannel.机要通信)
                {
                    letter.LetterType = EnumLetterType.收信;
                }
            }
            await _letterRepository.AddAsync(letter);

            var barcode = new Barcode
            {
                BarcodeNo  = letter.BarcodeNo,
                Entity     = EnumBarcodeEntity.信件,
                Souce      = EnumBarcodeSouce.本系统,
                Status     = EnumBarcodeStatus.已就绪,
                SubStatus  = EnumBarcodeSubStatus.正常,
                CreateTime = DateTime.Now,
                CreateBy   = letter.CreateBy
            };

            barcode.BarcodeType = barcode.AnalysisBarcodeType(letter.BarcodeNo);
            await _barcodeRepository.AddAsync(barcode);

            var baroceLog = new BarcodeLog
            {
                BarcodeNumber = letter.BarcodeNo,
                BarcodeStatus = EnumBarcodeStatus.已就绪,
                DepartmentId  = letter.SendDepartmentId,
                OperationTime = DateTime.Now,
                OperatorId    = letter.CreateBy,
            };

            await _barcodeLogRepository.AddAsync(baroceLog);

            result.Success = true;
            await _unitOfWork.CommitAsync();

            result.Data = letter.Id;
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// 用户取件
        /// </summary>
        /// <param name="boxId">箱子ID</param>
        /// <param name="cardValue">卡号</param>
        /// <param name="placeId">场所ID</param>
        /// <returns></returns>
        public async Task <int> UserGetLetter(int boxId, string cardValue, int placeId)
        {
            //箱子的流转对象签收人是否包含此人
            //不包含返回0
            //包含,依次签收箱内文件
            _logger.LogWarning($"--------------用户取件开始--------------");
            var user = await _cardRepository.GetQueryable().Where(a => a.Value == cardValue).Select(a => a.User).FirstOrDefaultAsync();

            if (user == null)
            {
                return(0);
            }
            var boxObjects = await _boxObjectRepository.GetQueryable().Where(a => a.BoxId == boxId).Select(a => a.ExchangeObject).ToListAsync();

            var objectSigners = await _objectSignerRepository.GetQueryable()
                                .Where(a => boxObjects.Any(b => b.Id == a.ExchangeObjectId)).Select(a => a.User).ToListAsync();

            if (objectSigners.Any(a => a.Id == user.Id))
            {
                var barcodes = await _barcodeRepository.GetQueryable().Where(a =>
                                                                             a.Status == EnumBarcodeStatus.已投递 && boxObjects.Any(b => b.Id == a.CurrentObjectId)).ToListAsync();

                _logger.LogWarning($"barcodes.Count:{barcodes.Count}");
                foreach (var barcode in barcodes)
                {
                    barcode.Status          = EnumBarcodeStatus.已签收;
                    barcode.CurrentPlaceId  = placeId;
                    barcode.CurrentObjectId = boxObjects[0].Id;
                    var barcodeLog = new BarcodeLog
                    {
                        BarcodeNumber     = barcode.BarcodeNo,
                        BarcodeStatus     = EnumBarcodeStatus.已签收,
                        BarcodeSubStatus  = barcode.SubStatus,
                        LastOperationTime = barcode.UpdateTime ?? DateTime.Now,
                        DepartmentId      = user.DepartmentId,
                        OperationTime     = DateTime.Now,
                        OperatorId        = user.Id,
                        CurrentPlaceId    = placeId,
                        CurrentObjectId   = boxObjects[0].Id
                    };

                    await _barcodeLogRepository.AddAsync(barcodeLog);

                    var firtExchangeObject = boxObjects.FirstOrDefault();
                    if (firtExchangeObject == null || firtExchangeObject.ObjectType != EnumObjectType.道)
                    {
                        continue;
                    }
                    if (firtExchangeObject.Value != (int)EnumChannel.城交换 &&
                        firtExchangeObject.Value != (int)EnumChannel.机要通信 &&
                        firtExchangeObject.Value != (int)EnumChannel.直送)
                    {
                        continue;
                    }
                    //添加至待分拣列表
                    var sorting = new Sorting
                    {
                        Channel   = (EnumChannel)firtExchangeObject.Value,
                        BarcodeNo = barcode.BarcodeNo
                    };
                    await _sortingRepository.AddAsync(sorting);
                }

                var box = await _boxRepository.GetByIdAsync(boxId);

                box.HasUrgent = false;
                box.FileCount = 0;
                _logger.LogWarning($"--------------用户取件结束:1--------------");
                return(1);
            }
            _logger.LogWarning($"--------------用户取件结束:0--------------");
            return(0);
        }
コード例 #6
0
        public async Task <int> SaveLetter(int placeId, string barCodeNo, int boxId, int fileCount, bool isJiaJi)
        {
            _logger.LogWarning($"--------------开始保存条码:{barCodeNo}--------------");
            var place = await _placeRepository.GetByIdAsync(placeId);

            var letter = await _letterRepository.GetQueryable().Where(a => a.BarcodeNo == barCodeNo).FirstOrDefaultAsync();

            if (letter == null)
            {
                //保存信件基本信息
                letter = new Letter
                {
                    BarcodeNo = barCodeNo
                };
                letter.LetterNo = letter.GetLetterNo(barCodeNo);
                //本系统未登记过的信件,全部判定为收信
                letter.LetterType          = EnumLetterType.收信;
                letter.ReceiveDepartmentId = await _barcodeManager.GetReceiveDepartmentId(barCodeNo);

                letter.SendDepartmentId = await _barcodeManager.GetSendDepartmentId(barCodeNo);

                letter.SecretLevel  = letter.GetSecretLevel(barCodeNo);
                letter.UrgencyLevel = letter.GetUrgencyLevel(barCodeNo);
                letter.CreateTime   = DateTime.Now;
                letter.LetterNo     = letter.GetLetterNo(barCodeNo);
                await _letterRepository.AddAsync(letter);
            }

            var barCode = await _barcodeRepository.GetQueryable().Where(a => a.BarcodeNo == barCodeNo)
                          .FirstOrDefaultAsync();

            var boxObject = await _boxObjectRepository.GetQueryable().Where(a => a.BoxId == boxId).FirstOrDefaultAsync();

            if (barCode == null)
            {
                //添加条码记录
                barCode = new Barcode
                {
                    BarcodeNo       = barCodeNo,
                    Entity          = EnumBarcodeEntity.信件,
                    Souce           = EnumBarcodeSouce.外部,
                    Status          = EnumBarcodeStatus.已投递,
                    SubStatus       = EnumBarcodeSubStatus.正常,
                    CreateTime      = DateTime.Now,
                    CurrentObjectId = boxObject.ExchangeObjectId,
                    CurrentPlaceId  = placeId
                };
                barCode.BarcodeType = barCode.AnalysisBarcodeType(barCodeNo);
                await _barcodeRepository.AddAsync(barCode);
            }

            barCode.CurrentObjectId = boxObject.ExchangeObjectId;
            barCode.CurrentPlaceId  = placeId;
            barCode.UpdateTime      = DateTime.Now;
            switch (barCode.Status)
            {
            case EnumBarcodeStatus.已就绪:
            case EnumBarcodeStatus.已签收:
            case EnumBarcodeStatus.已勘误:
                barCode.Status = EnumBarcodeStatus.已投递;
                break;

            case EnumBarcodeStatus.已投递:
            case EnumBarcodeStatus.已退回:
                break;

            case EnumBarcodeStatus.申请退回:
                barCode.Status    = EnumBarcodeStatus.已投递;
                barCode.SubStatus = EnumBarcodeSubStatus.退回;
                break;
            }
            //添加条码日志记录
            var preBarcodeLog = await _barcodeLogRepository.GetQueryable().Where(a => a.BarcodeNumber == barCodeNo)
                                .OrderByDescending(a => a.Id).FirstOrDefaultAsync();

            var barcodeLog = new BarcodeLog
            {
                BarcodeNumber   = barCodeNo,
                BarcodeStatus   = EnumBarcodeStatus.已投递,
                DepartmentId    = preBarcodeLog?.DepartmentId ?? place.DepartmentId,
                OperationTime   = DateTime.Now,
                OperatorId      = null,
                CurrentObjectId = boxObject.ExchangeObjectId,
                CurrentPlaceId  = placeId
            };

            if (barCode.SubStatus == EnumBarcodeSubStatus.退回)
            {
                barcodeLog.Remark = "已投递申请退回的文件";
            }
            await _barcodeLogRepository.AddAsync(barcodeLog);

            //更新箱格信息
            var box = await _boxRepository.GetByIdAsync(boxId);

            box.FileCount += 1;
            box.HasUrgent  = letter.UrgencyLevel != EnumUrgentLevel.普通 || isJiaJi;

            _logger.LogWarning($"--------------结束保存条码--------------");
            return(1);
        }