Beispiel #1
0
        /// <summary>
        /// Проверка существования в базе такого контейнера
        /// </summary>
        /// <param name="realContainer">realContainer</param>
        /// <returns>true если контейнеров нет, false если такой контейнер найден</returns>
        private async Task <bool> CheckRealContainerNotExistAsync(RealContainer realContainer)
        {
            using (var sqlConnect = Connections.GetLM())
            {
                var sql    = $@"SELECT 
                            {_bodyModel}
                          FROM [BankValues].[Cassetes] cass
                            {_joinModel}
                          WHERE cass.idCreditOrg = @CreditOrgId
                          and idCasseteType = @RealContainerTypeId
                          and cass.idModel = @ModelId
                          and idNominal = @NominalId
                          and cass.idCurrency= @CurrencyId
                          and cass.idVendor = @VendorId
                          and cass.idCasseteModel = @CasseteModelId
                          and idPosition = @PositionId
                          and Volume = @Volume
                          and idStatus = @StatusId
                          and QrCode = @QrCode
                          and Model = @Model
                          and sSeal = @Seal
                          and sSealDouble = @SealDouble
                          and bSealIntegrity = @SealIntegrity
                          and bSealIntegrityDouble = @SealIntegrityDouble
                          and sSerialNumber = @SerialNumber
                          and cass.idCity = @CityId";
                var result = await sqlConnect.QueryAsync <RealContainer>(sql, new
                {
                    realContainer.RealContainerTypeId,
                    realContainer.ModelId,
                    realContainer.NominalId,
                    realContainer.CurrencyId,
                    realContainer.VendorId,
                    realContainer.PositionId,
                    realContainer.Volume,
                    realContainer.StatusId,
                    realContainer.Model,
                    realContainer.CreditOrgId,
                    realContainer.QrCode,
                    realContainer.Seal,
                    realContainer.SealDouble,
                    realContainer.SealIntegrity,
                    realContainer.SealIntegrityDouble,
                    realContainer.SerialNumber,
                    realContainer.CasseteModelId,
                    realContainer.CityId
                });

                return(!result.Any());
            }
        }
Beispiel #2
0
        /// <summary>
        /// 生成红包,为RealContainer赋值
        /// </summary>
        public void GenerateRedPackage()
        {
            //求固定红包的概率
            int fixCount = (int)Math.Floor(Count * FixMoneyLevel / 100.0);

            //求固定红包的数量,如果固定红包没那么多,会把名额留给随机红包
            if (fixCount > FixMoney.Count)
            {
                fixCount = FixMoney.Count;
            }

            //生成固定金额的红包
            for (int i = 0; i < fixCount; i++)
            {
                if (Money > 0)
                {
                    Random rd          = new Random();
                    int    randomIndex = rd.Next(0, FixMoney.Count - 1);
                    double val         = FixMoney[randomIndex];
                    if (Money - val >= 0)
                    {
                        this.RealContainer.Add(val);
                        FixMoney.Remove(val);
                        Money -= val;
                        SendMoney.Add(val);
                    }
                    else
                    {
                        fixCount--;
                    }
                }
            }
            //求随机红包的数量
            int randomCount = Count - fixCount;

            Console.WriteLine("需要产生随机红包的金额:{0}", Money);
            //产生随机红包
            randNum(randomCount);
            //为红包池进行随机排序
            RealContainer = RealContainer.OrderBy(x => Guid.NewGuid()).ToList();
            //添加到随机队列
            foreach (var item in RealContainer)
            {
                RandomRealContainer.Enqueue(item);
            }
            Console.WriteLine("红包金额剩余_balance:{0}", Money);
        }
        public async Task <List <RealContainer> > FindRealContainersAsync(string qrCode, int creditOrgId, int?typeId, int?excludeTypeId, string method, string sortField, string sortType, int offset, int limit)
        {
            var qrCodeParts   = RealContainer.TryParseCompositeQR(qrCode);
            var isCompositeQR = qrCodeParts?.Length > 1;
            var searchCode    = isCompositeQR ? qrCodeParts[(int)RealContainerQrEnum.ContainerNum].ToString("X").PadLeft(6, '0') : qrCode;

            var specification = _specificationCreator.CreateSpecification(method, searchCode, creditOrgId, typeId, excludeTypeId);

            // Получаем контейнеры по QR коду в базе
            var container = await _realcontainerRepository.GetListAsync(specification, sortField, sortType, offset, limit);

            // Если QR код составной и по нему найден контейнер необходимо осуществить проверку корректности QR кода
            if (isCompositeQR && container.Count == 1)
            {
                // Если значения в QR коде расходятся с данными из базы, помечаем контейнер к проверке
                if (container[0].CheckQRcode(qrCodeParts).Count != 0)
                {
                    container[0].NeedCheck = true;
                    await _realcontainerRepository.SetPropertiesAsync(new int[] { container[0].RealContainerId }, bNeedCheck : true);
                }
            }

            return(container);
        }
Beispiel #4
0
 public async Task <int> UpdateRealContainerAsync(
     [FromBody][Required(ErrorMessage = "Не задан обязательный параметр `realContainer`")] RealContainer realContainer,
     [FromQuery][Required(ErrorMessage = "Не задан обязательный параметр `force`")] bool force)
 {
     return(await _serviceReal.UpdateRealContainerAsync(realContainer, force));
 }
Beispiel #5
0
 public async Task <List <RealContainer> > InsertRealContainerCopyAsync([FromBody][Required(ErrorMessage = "Не задан обязательный параметр `realContainer`")] RealContainer realContainer)
 {
     return(await _serviceReal.InsertRealContainerCopyAsync(realContainer));
 }
 public async Task <List <RealContainer> > InsertRealContainerCopyAsync(RealContainer realContainer)
 {
     return(await _realcontainerRepository.InsertCopyAsync(realContainer));
 }
 public async Task <RealContainer> InsertRealContainerAsync(RealContainer realContainer)
 {
     return(await _realcontainerRepository.InsertAsync(realContainer));
 }
 public async Task <int> UpdateRealContainerAsync(RealContainer realContainer, bool force)
 {
     return(await _realcontainerRepository.UpdateAsync(realContainer, force));
 }
Beispiel #9
0
        /// <summary>
        /// Создает указанное кол-во копий контейнеров в базе с разными QR
        /// </summary>
        /// <param name="realContainer">realContainer</param>
        /// <returns>коллекция созданных контейнеров</returns>
        public async Task <List <RealContainer> > InsertCopyAsync(RealContainer realContainer)
        {
            using (var sqlConnect = Connections.GetLM())
            {
                List <string> copyCassetes = new List <string>();

                realContainer.QrCode = await GetUniqueNumaratorAsync(realContainer.CreditOrgId, realContainer.CountCopyCassetes);

                long qrCount = long.Parse(realContainer.QrCode);

                for (int i = 0; i < realContainer.CountCopyCassetes; i++)
                {
                    realContainer.QrCode = (qrCount++).ToString();
                    realContainer.UpdateQrCodeNum();
                    copyCassetes.Add(@"(@RealContainerTypeId
                            , @ModelId
                            , @NominalId
                            , @CurrencyId
                            , @VendorId
                            , @PositionId
                            , @Volume
                            , @CreditOrgId
                            , @StatusId
                            , '@QrCode'
                            , '@QrCodeNum'
                            , @Model
                            , @Seal
                            , @SealDouble
                            , @SealIntegrity
                            , @SealIntegrityDouble
                            , @SerialNumber
                            , @BDepo
                            , @CasseteModelId
                            , @IdCreateUser
                            , @CityId)".Replace("@QrCodeNum", realContainer.QrCodeNum.ToString()).Replace("@QrCode", realContainer.QrCode));
                }

                if (await CheckRealContainerNotExistAsync(realContainer) && await CheckCreditOrgAsync(realContainer.CreditOrgId))
                {
                    var sql = @"INSERT INTO [BankValues].[Cassetes]
                            ([idCasseteType]
                            ,[idModel]
                            ,[idNominal]
                            ,[idCurrency]
                            ,[idVendor]
                            ,[idPosition]
                            ,[Volume]
                            ,[idCreditOrg]
                            ,[idStatus]
                            ,[QrCode]
                            ,[QrCodeNum]
                            ,[Model]
                            ,[sSeal]
                            ,[sSealDouble]
                            ,[bSealIntegrity]
                            ,[bSealIntegrityDouble]
                            ,[sSerialNUmber]
                            ,[bDepo]
                            ,[idCasseteModel]
                            ,[idCreateUser]
                            ,[idCity])
                        OUTPUT INSERTED.[idCassete]
                        VALUES ";
                    sql = sql + string.Join(", ", copyCassetes.ToArray());
                    var newRealContainerId = await sqlConnect.QueryMultipleAsync(sql, new
                    {
                        realContainer.RealContainerTypeId,
                        realContainer.ModelId,
                        realContainer.NominalId,
                        realContainer.CurrencyId,
                        realContainer.VendorId,
                        realContainer.PositionId,
                        realContainer.Volume,
                        realContainer.CreditOrgId,
                        realContainer.StatusId,
                        realContainer.Model,
                        realContainer.Seal,
                        realContainer.SealDouble,
                        realContainer.SealIntegrity,
                        realContainer.SealIntegrityDouble,
                        realContainer.SerialNumber,
                        realContainer.BDepo,
                        realContainer.CasseteModelId,
                        realContainer.IdCreateUser,
                        realContainer.CityId
                    });

                    var results = newRealContainerId.Read <int>().ToArray();
                    if (results.Length == 0)
                    {
                        return(null);
                    }

                    var realContainers = await GetAsync(results);

                    return(realContainers);
                }
            }

            return(new List <RealContainer>());
        }
Beispiel #10
0
        /// <summary>
        /// Создает контейнер в базе данных формирует номер QR кода
        /// </summary>
        /// <param name="realContainer">realContainer</param>
        /// <returns>созданный контейнер</returns>
        public async Task <RealContainer> InsertAsync(RealContainer realContainer)
        {
            using (var sqlConnect = Connections.GetLM())
            {
                string[] bCodeForCheck = { "Bag", "SecurePack", "RKCBag", "TechBag", "MoneyPack", "CoinBag", "BanknotePack" };

                var qrCode = realContainer.QrCode;
                if (realContainer.BCode != null && bCodeForCheck.Contains(realContainer.BCode.Trim()))
                {
                    realContainer.VendorId       = null;
                    realContainer.NominalId      = null;
                    realContainer.PositionId     = null;
                    realContainer.CasseteModelId = null;

                    realContainer.QrCode = qrCode;
                    realContainer.UpdateQrCodeNum();

                    if (!await CheckRealContainerNotExistAsync(realContainer.QrCode, realContainer.CreditOrgId) || !await CheckCreditOrgAsync(realContainer.CreditOrgId))
                    {
                        throw new Exception($"Контейнер с номером \"{realContainer.QrCode}\" уже существует в базе.");
                    }
                }
                else
                {
                    qrCode = await GetUniqueNumaratorAsync(realContainer.CreditOrgId);

                    realContainer.QrCode = qrCode;
                    realContainer.UpdateQrCodeNum();

                    if (!await CheckRealContainerNotExistAsync(realContainer) || !await CheckCreditOrgAsync(realContainer.CreditOrgId))
                    {
                        throw new Exception($"Контейнер с заданными параметрами и номером \"{realContainer.QrCode}\" уже существует в базе.");
                    }
                }

                var sql = @"INSERT INTO [BankValues].[Cassetes]
                            ([idCasseteType]
                            ,[idModel]
                            ,[idNominal]
                            ,[idCurrency]
                            ,[idVendor]
                            ,[idPosition]
                            ,[Volume]
                            ,[idCreditOrg]
                            ,[idStatus]
                            ,[QrCode]
                            ,[QrCodeNum]
                            ,[Model]
                            ,[sSeal]
                            ,[sSealDouble]
                            ,[bSealIntegrity]
                            ,[bSealIntegrityDouble]
                            ,[sSerialNUmber]
                            ,[bDepo]
                            ,[idCasseteModel]
                            ,[idCreateUser]
                            ,[idCity])
                        OUTPUT INSERTED.[idCassete]
                        VALUES
                            (@RealContainerTypeId
                            ,@ModelId
                            ,@NominalId
                            ,@CurrencyId
                            ,@VendorId
                            ,@PositionId
                            ,@Volume
                            ,@CreditOrgId
                            ,@StatusId
                            ,@QrCode
                            ,@QrCodeNum
                            ,@Model
                            ,@Seal
                            ,@SealDouble
                            ,@SealIntegrity
                            ,@SealIntegrityDouble
                            ,@SerialNumber
                            ,@BDepo
                            ,@CasseteModelId
                            ,@IdCreateUser
                            ,@CityId)";
                var newRealContainerId = await sqlConnect.QuerySingleAsync <int>(sql, new
                {
                    realContainer.RealContainerTypeId,
                    realContainer.ModelId,
                    realContainer.NominalId,
                    realContainer.CurrencyId,
                    realContainer.VendorId,
                    realContainer.PositionId,
                    realContainer.Volume,
                    realContainer.CreditOrgId,
                    realContainer.StatusId,
                    realContainer.QrCode,
                    realContainer.QrCodeNum,
                    realContainer.Model,
                    realContainer.Seal,
                    realContainer.SealDouble,
                    realContainer.SealIntegrity,
                    realContainer.SealIntegrityDouble,
                    realContainer.SerialNumber,
                    realContainer.BDepo,
                    realContainer.CasseteModelId,
                    realContainer.IdCreateUser,
                    realContainer.CityId
                });

                if (newRealContainerId == 0)
                {
                    throw new Exception($"Не удалось добавить контейнеры.");
                }

                var realContainers = await GetAsync(new[] { newRealContainerId });

                return(realContainers.SingleOrDefault());
            }
        }
Beispiel #11
0
        /// <summary>
        /// обновляет существующий контейнер
        /// </summary>
        /// <param name="realContainer">realContainer</param>
        /// <param name="force">необходимость проверки на блокировку</param>
        /// <returns>1 удаление прошло успешно, 0 ничего не удалено</returns>
        public async Task <int> UpdateAsync(RealContainer realContainer, bool force)
        {
            using (var sqlConnect = Connections.GetLM())
            {
                if (await CheckRealContainerIsBlockedAsync(realContainer.RealContainerId, sqlConnect, force))
                {
                    // изменение статуса заблокировно
                    return(0);
                }

                realContainer.UpdateQrCodeNum();

                var sql    = @"UPDATE [BankValues].[Cassetes]
                           SET [idCasseteType] = @RealContainerTypeId
                              ,[idModel] = @ModelId
                              ,[idNominal] = @NominalId
                              ,[idCurrency] = @CurrencyId
                              ,[idVendor] = @VendorId
                              ,[idPosition] = @PositionId
                              ,[Volume] = @Volume
                              ,[idCreditOrg] = @CreditOrgId
                              ,[idStatus] = @StatusId
                              ,[QrCode] = @QrCode
                              ,[QrCodeNum] = @QrCodeNum
                              ,[Model] = @Model
                              ,[sSeal] = @Seal
                              ,[sSealDouble] = @SealDouble
                              ,[bSealIntegrity] = @SealIntegrity
                              ,[bSealIntegrityDouble] = @SealIntegrityDouble
                              ,[sSerialNumber] = @SerialNumber
                              ,[bDepo] = @BDepo
                              ,[idCasseteModel] = @CasseteModelId
                              ,[idCity] = @CityId
                         WHERE idCassete = @RealContainerId";
                var result = await sqlConnect.ExecuteAsync(sql, new
                {
                    realContainer.RealContainerTypeId,
                    realContainer.ModelId,
                    realContainer.NominalId,
                    realContainer.CurrencyId,
                    realContainer.VendorId,
                    realContainer.PositionId,
                    realContainer.Volume,
                    realContainer.CreditOrgId,
                    realContainer.StatusId,
                    realContainer.QrCode,
                    realContainer.QrCodeNum,
                    realContainer.Model,
                    realContainer.Seal,
                    realContainer.SealDouble,
                    realContainer.SealIntegrity,
                    realContainer.SealIntegrityDouble,
                    realContainer.SerialNumber,
                    realContainer.BDepo,
                    realContainer.RealContainerId,
                    realContainer.CasseteModelId,
                    realContainer.CityId,
                });

                return(result);
            }
        }