예제 #1
0
        /// <summary>
        /// 虚拟流转对象逻辑
        /// </summary>
        /// <param name="placeId"></param>
        /// <param name="objectId"></param>
        /// <returns></returns>
        private async Task <CheckBarcodeModel> CheckVirtualObject(int placeId, int objectId)
        {
            _logger.LogWarning($"虚拟流转对象");
            var checkBarcodeModel = new CheckBarcodeModel();
            var boxs = await _boxObjectRepository.GetQueryable()
                       .Where(a => a.Box.PlaceId == placeId && a.ExchangeObject.ParentId == objectId && a.Box.Enabled && a.ExchangeObject.ObjectType != EnumObjectType.道)
                       .Select(a => a.Box).ToListAsync();

            if (boxs.Count > 0)
            {
                _logger.LogWarning($"虚拟流转对象存在下级流转对象并在该交换场所存在箱格");
                checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                checkBarcodeModel.Record =
                    boxs.Select(a => new CheckedBarcodeRecord {
                    FileCount = 1, Message = "", No = a.Id
                })
                    .ToList();
            }
            else
            {
                _logger.LogWarning($"除渠道箱外全部返回");
                boxs = await _boxObjectRepository.GetQueryable()
                       .Where(a => a.Box.PlaceId == placeId && a.Box.Enabled && a.ExchangeObject.ObjectType != EnumObjectType.道)
                       .Select(a => a.Box).ToListAsync();

                checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                checkBarcodeModel.Record =
                    boxs.Select(a => new CheckedBarcodeRecord {
                    FileCount = 1, Message = "", No = a.Id
                })
                    .ToList();
            }
            return(checkBarcodeModel);
        }
예제 #2
0
        /// <summary>
        ///  //查找上级流转对象逻辑
        /// </summary>
        /// <param name="exchangeObject"></param>
        /// <param name="placeId"></param>
        /// <returns></returns>
        private async Task <CheckBarcodeModel> CheckParent(ExchangeObject exchangeObject, int placeId)
        {
            _logger.LogWarning($"循环判断上级流转对象在这有没有箱子");
            var checkBarcodeModel = new CheckBarcodeModel();

            while (exchangeObject.ParentId != null)
            {
                var o = exchangeObject;
                exchangeObject = await _objectRepository.GetQueryable().Where(a => a.Id == o.ParentId.Value)
                                 .FirstOrDefaultAsync();

                var exchangeObject1 = exchangeObject;
                var boxs            = await _boxObjectRepository.GetQueryable()
                                      .Where(a => a.Box.PlaceId == placeId && a.ExchangeObjectId == exchangeObject1.Id && a.Box.Enabled)
                                      .Select(a => a.Box).ToListAsync();

                if (boxs.Count > 0)
                {
                    checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                    checkBarcodeModel.Record = boxs.Select(a =>
                                                           new CheckedBarcodeRecord {
                        FileCount = 1, Message = "", No = a.Id
                    }).ToList();
                    return(checkBarcodeModel);
                }
                if (exchangeObject.IsVirtual)
                {
                    return(await CheckVirtualObject(placeId, exchangeObject.Id));
                }
            }

            return(checkBarcodeModel);
        }
예제 #3
0
        public async Task <CheckBarcodeModel> CheckBarcodeType(string barcodeNo, int placeId)
        {
            _logger.LogWarning($"--------------开始检查条码:{barcodeNo}--------------");
            var checkBarcodeModel = new CheckBarcodeModel();

            if (barcodeNo.Length == 33 || barcodeNo.Length == 26 || barcodeNo.Contains("(01)000001500011"))
            {
                var barcode = await _barcodeRepository.GetByNoAsync(barcodeNo);

                var letter = await _letterRepository.GetLetter(barcodeNo);

                if (letter == null)
                {
                    letter = new Letter
                    {
                        BarcodeNo           = barcodeNo,
                        ReceiveDepartmentId = await _barcodeManager.GetReceiveDepartmentId(barcodeNo),
                        SendDepartmentId    = await _barcodeManager.GetSendDepartmentId(barcodeNo),
                        //如果数据库中没有Letter记录,那么LetterType一定是收信
                        LetterType = EnumLetterType.收信
                    };
                    letter.SecretLevel  = letter.GetSecretLevel(barcodeNo);
                    letter.UrgencyLevel = letter.GetUrgencyLevel(barcodeNo);
                    letter.LetterNo     = letter.GetLetterNo(barcodeNo);
                    letter.LetterType   = GetLetterType(barcodeNo);
                }

                if (barcode != null)
                {
                    _logger.LogWarning($"当前流转状态:{barcode.Status.ToString()}");
                    switch (barcode.Status)
                    {
                    case EnumBarcodeStatus.已签收:
                    {
                        if (barcode.CurrentPlaceId == placeId && barcode.SubStatus == EnumBarcodeSubStatus.正常)
                        {
                            checkBarcodeModel.Type = EnumCheckBarcodeType.无效;
                        }
                        else if (barcode.SubStatus == EnumBarcodeSubStatus.退回)
                        {
                            var receiveDepartmentId = letter.ReceiveDepartmentId;
                            letter.ReceiveDepartmentId = letter.SendDepartmentId;
                            letter.SendDepartmentId    = receiveDepartmentId;
                            if (letter.LetterType == EnumLetterType.发信)
                            {
                                letter.LetterType = EnumLetterType.收信;
                            }
                            else if (letter.LetterType == EnumLetterType.收信)
                            {
                                letter.LetterType = EnumLetterType.发信;
                            }
                            return(await CheckBarcodeTypeCommon(letter, placeId));
                        }
                        else
                        {
                            return(await CheckBarcodeTypeCommon(letter, placeId));
                        }
                    }
                    break;

                    case EnumBarcodeStatus.已就绪:
                    case EnumBarcodeStatus.已勘误:
                        return(await CheckBarcodeTypeCommon(letter, placeId));

                    case EnumBarcodeStatus.已投递:
                        _logger.LogWarning($"重复投箱");
                        checkBarcodeModel.Type = EnumCheckBarcodeType.条码已经投箱;
                        break;

                    case EnumBarcodeStatus.申请退回:
                    {
                        _logger.LogWarning($"申请退回信件:对调收发单位信息");
                        var receiveDepartmentId = letter.ReceiveDepartmentId;
                        letter.ReceiveDepartmentId = letter.SendDepartmentId;
                        letter.SendDepartmentId    = receiveDepartmentId;
                        if (letter.LetterType == EnumLetterType.发信)
                        {
                            letter.LetterType = EnumLetterType.收信;
                        }
                        else if (letter.LetterType == EnumLetterType.收信)
                        {
                            letter.LetterType = EnumLetterType.发信;
                        }
                        return(await CheckBarcodeTypeCommon(letter, placeId));
                    }

                    case EnumBarcodeStatus.已退回:
                        _logger.LogWarning($"条码无效:已退回的文件");
                        checkBarcodeModel.Type = EnumCheckBarcodeType.无效;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    _logger.LogWarning($"不存在流转记录");
                    return(await CheckBarcodeTypeCommon(letter, placeId));
                }
            }
            _logger.LogWarning($"--------------结束检查条码:{JsonConvert.SerializeObject(checkBarcodeModel)}--------------");
            return(checkBarcodeModel);
        }
예제 #4
0
        private async Task <CheckBarcodeModel> CheckBarcodeTypeCommon(Letter letter, int placeId)
        {
            _logger.LogWarning($"进入通用逻辑");
            var checkBarcodeModel = new CheckBarcodeModel();

            if (letter.SendDepartmentId == 0)
            {
                _logger.LogWarning($"发件单位错误");
                return(checkBarcodeModel);
            }


            _logger.LogWarning($"信件类型:{letter.LetterType.ToString()}");
            switch (letter.LetterType)
            {
            case EnumLetterType.收信:
            {
                var exchangeObject = await _objectRepository.GetQueryable().Where(a =>
                                                                                  a.ObjectType == EnumObjectType.机构 && a.Value == letter.ReceiveDepartmentId)
                                     .FirstOrDefaultAsync();

                if (exchangeObject == null)
                {
                    _logger.LogWarning($"不存在的收件流转对象");
                    checkBarcodeModel.Type = EnumCheckBarcodeType.无效;
                    return(checkBarcodeModel);
                }
                var objectId = exchangeObject.Id;
                var boxs     = await _boxObjectRepository.GetQueryable()
                               .Where(a => a.Box.PlaceId == placeId && a.ExchangeObjectId == objectId && a.Box.Enabled && a.ExchangeObject.ObjectType != EnumObjectType.道)
                               .Select(a => a.Box).ToListAsync();

                if (boxs.Count > 0)
                {
                    _logger.LogWarning($"结束:当前场所存在收件箱格");
                    checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                    checkBarcodeModel.Record =
                        boxs.Select(a => new CheckedBarcodeRecord {
                            FileCount = 1, Message = "", No = a.Id
                        })
                        .ToList();
                }
                else
                {
                    _logger.LogWarning($"递归上级流转对象在本场所有箱格");
                    var parentObject = exchangeObject;
                    while (parentObject.ParentId != null)
                    {
                        var o = parentObject;
                        var tempParentObject = await _objectRepository.GetQueryable().Where(a => a.Id == o.ParentId.Value)
                                               .FirstOrDefaultAsync();

                        boxs = await _boxObjectRepository.GetQueryable()
                               .Where(a => a.Box.PlaceId == placeId && a.ExchangeObjectId == tempParentObject.Id && a.Box.Enabled)
                               .Select(a => a.Box).ToListAsync();

                        if (boxs.Count > 0)
                        {
                            _logger.LogWarning($"结束:存在上级流转对象箱格");
                            checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                            checkBarcodeModel.Record =
                                boxs.Select(a => new CheckedBarcodeRecord {
                                    FileCount = 1, Message = "", No = a.Id
                                })
                                .ToList();
                            return(checkBarcodeModel);
                        }

                        parentObject = tempParentObject;
                    }

                    if (exchangeObject.IsVirtual)
                    {
                        _logger.LogWarning($"收件流转对象为虚拟对象");
                        var childBoxs = await _boxObjectRepository.GetQueryable()
                                        .Where(a => a.Box.PlaceId == placeId && a.ExchangeObject.ParentId == exchangeObject.Id && a.Box.Enabled)
                                        .Select(a => a.Box).ToListAsync();

                        if (childBoxs.Count > 0)
                        {
                            checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                            checkBarcodeModel.Record =
                                childBoxs.Select(a => new CheckedBarcodeRecord {
                                    FileCount = 1, Message = "", No = a.Id
                                })
                                .ToList();
                            _logger.LogWarning($"结束:存在收件流转对象下级的箱格");
                            return(checkBarcodeModel);
                        }

                        boxs = await _boxObjectRepository.GetQueryable()
                               .Where(a => a.Box.PlaceId == placeId && a.Box.Enabled && a.ExchangeObject.ObjectType != EnumObjectType.道)
                               .Select(a => a.Box).ToListAsync();

                        checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                        checkBarcodeModel.Record =
                            boxs.Select(a => new CheckedBarcodeRecord {
                                FileCount = 1, Message = "", No = a.Id
                            })
                            .ToList();
                        _logger.LogWarning($"结束:除渠道箱外全部返回");
                        return(checkBarcodeModel);
                    }
                }

                break;
            }

            case EnumLetterType.发信:
            {
                var receiveDepartment = await _departmentRepository.GetByIdAsync(letter.ReceiveDepartmentId);

                var receiveChannel = receiveDepartment.ReceiveChannel;
                if (letter.SecretLevel == EnumSecretLevel.绝密)
                {
                    receiveChannel = EnumChannel.机要通信;
                }

                if (receiveChannel == EnumChannel.机要通信)
                {
                    //2018.12.26添加机要通信渠道箱不允许投非密件
                    if (letter.SecretLevel == EnumSecretLevel.普通)
                    {
                        _logger.LogWarning($"结束:非密件不允许走机要通信渠道");
                        return(checkBarcodeModel);
                    }
                    //2019.2.12添加直接到部级的单位不允许投箱
                    if (letter.BarcodeNo.Contains("015000"))
                    {
                        _logger.LogWarning($"结束:直接到部级不允许投箱");
                        return(checkBarcodeModel);
                    }
                }

                //同城渠道可以走直送
                var allowChannels = new List <int>();
                allowChannels.Add((int)receiveChannel);
                if (receiveChannel == EnumChannel.城交换)
                {
                    allowChannels.Add((int)EnumChannel.直送);
                }

                var channelExchangeObjects = await _objectRepository.GetQueryable().Where(a =>
                                                                                          a.ObjectType == EnumObjectType.道 && allowChannels.Contains(a.Value))
                                             .ToListAsync();

                if (channelExchangeObjects.Count > 0)
                {
                    var boxs = await _boxObjectRepository.GetQueryable()
                               .Where(a => a.Box.PlaceId == placeId && channelExchangeObjects.Exists(b => b.Id == a.ExchangeObjectId) && a.Box.Enabled)
                               .Select(a => a.Box).ToListAsync();

                    if (boxs.Count > 0)
                    {
                        checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                        checkBarcodeModel.Record = boxs.Select(a =>
                                                               new CheckedBarcodeRecord {
                                FileCount = 1, Message = "", No = a.Id
                            }).ToList();
                        _logger.LogWarning($"结束:存在对外的渠道箱");
                        return(checkBarcodeModel);
                    }

                    var currentSend = false;
                    var place       = await _placeRepository.GetByIdAsync(placeId);

                    var sendDepartment = await _departmentRepository.GetByIdAsync(letter.SendDepartmentId);

                    while (sendDepartment.ParentId != null)
                    {
                        if (place.DepartmentId == sendDepartment.Id)
                        {
                            currentSend = true;
                            break;
                        }

                        sendDepartment = await _departmentRepository.GetByIdAsync(sendDepartment.ParentId.Value);
                    }

                    if (currentSend)
                    {
                        var insideExchangeObjects = await _objectRepository.GetQueryable().Where(a =>
                                                                                                 a.ObjectType == EnumObjectType.道 && a.Value == (int)EnumChannel.内部)
                                                    .ToListAsync();

                        List <ExchangeObject> matchExchangeObjects;
                        if (receiveChannel == EnumChannel.城交换 && letter.SecretLevel != EnumSecretLevel.绝密)
                        {
                            matchExchangeObjects = insideExchangeObjects.Where(a => a.RestrictionCode.Contains("同城交换")).ToList();
                        }
                        else
                        {
                            matchExchangeObjects = insideExchangeObjects.Where(a => a.RestrictionCode.Contains("机要通信")).ToList();
                        }

                        if (matchExchangeObjects.Count > 0)
                        {
                            _logger.LogWarning($"结束:内部限制码渠道箱匹配成功");
                            boxs = await _boxObjectRepository.GetQueryable()
                                   .Where(a => a.Box.PlaceId == placeId && matchExchangeObjects.Any(b => b.Id == a.ExchangeObjectId) && a.Box.Enabled)
                                   .Select(a => a.Box).ToListAsync();

                            if (boxs.Count == 0)
                            {
                                _logger.LogWarning($"结束:内部渠道箱匹配成功");
                                boxs = await _boxObjectRepository.GetQueryable()
                                       .Where(a => a.Box.PlaceId == placeId && insideExchangeObjects.Any(b => b.Id == a.ExchangeObjectId) && a.Box.Enabled)
                                       .Select(a => a.Box).ToListAsync();
                            }
                        }
                        if (boxs.Count > 0)
                        {
                            checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                            checkBarcodeModel.Record = boxs.Select(a =>
                                                                   new CheckedBarcodeRecord {
                                    FileCount = 1, Message = "", No = a.Id
                                }).ToList();
                        }
                    }
                    else
                    {
                        checkBarcodeModel.Type = EnumCheckBarcodeType.无效;
                    }
                }
            }
            break;

            case EnumLetterType.内交换:
            {
                var exchangeObject = await _objectRepository.GetQueryable().Where(a =>
                                                                                  a.ObjectType == EnumObjectType.机构 && a.Value == letter.ReceiveDepartmentId)
                                     .FirstOrDefaultAsync();

                if (exchangeObject == null)
                {
                    _logger.LogWarning($"不存在的收件流转对象");
                    checkBarcodeModel.Type = EnumCheckBarcodeType.无效;
                    return(checkBarcodeModel);
                }
                var tempObject = exchangeObject;
                var boxs       = await _boxObjectRepository.GetQueryable()
                                 .Where(a => a.Box.PlaceId == placeId && a.ExchangeObjectId == tempObject.Id && a.Box.Enabled)
                                 .Select(a => a.Box).ToListAsync();

                if (boxs.Count > 0)
                {
                    checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                    checkBarcodeModel.Record =
                        boxs.Select(a => new CheckedBarcodeRecord {
                            FileCount = 1, Message = "", No = a.Id
                        })
                        .ToList();
                    _logger.LogWarning($"结束:当前场所下存在收件流转对象箱格");
                    return(checkBarcodeModel);
                }

                var parentObject = exchangeObject;
                while (parentObject.ParentId != null)
                {
                    var o = parentObject;
                    var tempParentObject = await _objectRepository.GetQueryable().Where(a => a.Id == o.ParentId.Value)
                                           .FirstOrDefaultAsync();

                    boxs = await _boxObjectRepository.GetQueryable()
                           .Where(a => a.Box.PlaceId == placeId && a.ExchangeObjectId == tempParentObject.Id && a.Box.Enabled)
                           .Select(a => a.Box).ToListAsync();

                    if (boxs.Count > 0)
                    {
                        checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                        checkBarcodeModel.Record =
                            boxs.Select(a => new CheckedBarcodeRecord {
                                FileCount = 1, Message = "", No = a.Id
                            })
                            .ToList();
                        _logger.LogWarning($"结束:存在流转对象上级对象箱格");
                        return(checkBarcodeModel);
                    }

                    parentObject = tempParentObject;
                }

                if (exchangeObject.IsVirtual)
                {
                    _logger.LogWarning($"流转对象为虚拟流转对象");
                    var childBoxs = await _boxObjectRepository.GetQueryable()
                                    .Where(a => a.Box.PlaceId == placeId && a.ExchangeObject.ParentId == exchangeObject.Id && a.Box.Enabled)
                                    .Select(a => a.Box).ToListAsync();

                    if (childBoxs.Count > 0)
                    {
                        _logger.LogWarning($"结束:存在流转对象子对象箱格");
                        checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                        checkBarcodeModel.Record =
                            childBoxs.Select(a => new CheckedBarcodeRecord {
                                FileCount = 1, Message = "", No = a.Id
                            })
                            .ToList();
                        return(checkBarcodeModel);
                    }
                }

                var currentSend = false;
                //判断是否是该场所下的单位发件
                var place = await _placeRepository.GetByIdAsync(placeId);

                var sendDepartment = await _departmentRepository.GetByIdAsync(letter.SendDepartmentId);

                while (sendDepartment.ParentId != null)
                {
                    if (place.DepartmentId == sendDepartment.Id)
                    {
                        currentSend = true;
                        break;
                    }
                    sendDepartment = await _departmentRepository.GetByIdAsync(sendDepartment.ParentId.Value);
                }

                if (currentSend)
                {
                    _logger.LogWarning($"当前场所下单位发件");
                    //当前场所下单位发件
                    var exchangeObjects = await _objectRepository.GetQueryable().Where(a =>
                                                                                       a.ObjectType == EnumObjectType.道 && a.Value == (int)EnumChannel.内部)
                                          .ToListAsync();

                    var receiveCode          = letter.GetReceiveCode(letter.BarcodeNo);
                    var matchExchangeObjects = exchangeObjects.Where(a => receiveCode.Contains(a.RestrictionCode)).ToList();
                    if (matchExchangeObjects.Count > 0)
                    {
                        if (matchExchangeObjects.Count > 1)
                        {
                            //匹配数量超过一个,排除限制码为空的对象
                            matchExchangeObjects = exchangeObjects.Where(a => receiveCode.Contains(a.RestrictionCode) && !string.IsNullOrWhiteSpace(a.RestrictionCode)).ToList();
                        }
                        boxs = await _boxObjectRepository.GetQueryable()
                               .Where(a => a.Box.PlaceId == placeId && matchExchangeObjects.Any(b => b.Id == a.ExchangeObjectId) && a.Box.Enabled)
                               .Select(a => a.Box).ToListAsync();

                        _logger.LogWarning($"结束:内部限制码渠道箱匹配成功");
                    }
                    else
                    {
                        boxs = await _boxObjectRepository.GetQueryable()
                               .Where(a => a.Box.PlaceId == placeId && exchangeObjects.Any(b => b.Id == a.ExchangeObjectId) && a.Box.Enabled)
                               .Select(a => a.Box).ToListAsync();

                        _logger.LogWarning($"结束:内部渠道箱匹配成功");
                    }
                    checkBarcodeModel.Type   = EnumCheckBarcodeType.唯一指定;
                    checkBarcodeModel.Record = boxs.Select(a =>
                                                           new CheckedBarcodeRecord {
                            FileCount = 1, Message = "", No = a.Id
                        }).ToList();
                }
                else
                {
                    checkBarcodeModel.Type = EnumCheckBarcodeType.无效;
                }
            }
            break;
            }
            return(checkBarcodeModel);
        }