Exemplo n.º 1
0
        public async Task <Result <DtoGetCodeResponse> > Get([FromBody] DtoGetCodeRequest request)
        {
            DateTime dt;

            if (!DateTime.TryParse(request.tExpireTime, out dt))
            {
                return(Result.Fail <DtoGetCodeResponse>("失效时间格式错误", this.GetReqNo()));
            }

            var result = await this.requestService.GetCode(this.GetAccountId(), this.GetGroup(), request);

            result.reqno = this.GetReqNo();
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="iAccountId"></param>
        /// <param name="iPrefixCode"></param>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <Result <DtoGetCodeResponse> > GetCode(int iAccountId, int iPrefixCode, DtoGetCodeRequest request)
        {
            if (await this.requestRepository.Query()
                .Include(x => x.TcGroup)
                .Where(x => x.iAccountId == iAccountId && x.TcGroup.iPrefixCode == iPrefixCode && x.sOuterNo == request.sOuterNo)
                .AnyAsync())
            {
                return(Result.Fail <DtoGetCodeResponse>($"{request.sOuterNo}已存在", ""));
            }

            var tc = new TcRequsets()
            {
                iAccountId  = iAccountId,
                iGroupId    = iPrefixCode,
                iNumber     = request.iNumber,
                sMemo       = request.sMemo,
                sOuterNo    = request.sOuterNo,
                sRequestNo  = SequenceService.GetId(iPrefixCode),
                tCreateTime = DateTime.Now,
                tExpireTime = DateTime.Parse(request.tExpireTime),
            };

            CheckGroupCapacity(iPrefixCode);

            var infoGroup = await this.groupRepository.Query().AsNoTracking()
                            .Where(x => x.iPrefixCode == iPrefixCode)
                            .SingleOrDefaultAsync();

            var listline = new List <TcRequestLines>();

            for (int i = 1; i <= request.iNumber; i++)
            {
                string code = await this.redisCache.ListLeftPopAsync(string.Format(this.KEY_TC_GROUP_LIST, iPrefixCode));

                if (string.IsNullOrWhiteSpace(code))
                {
                    throw new Exception("");
                }

                TcRequestLines line = new TcRequestLines()
                {
                    iCode     = int.Parse(code),
                    iFullCode = GetFullCode(iPrefixCode, int.Parse(code), infoGroup.iLength)
                };
                listline.Add(line);
            }
            tc.TcRequestLines = listline;

            this.requestRepository.Add(tc);
            await this.requestRepository.SaveChangesAsync();

            return(Result.Ok <DtoGetCodeResponse>(new DtoGetCodeResponse()
            {
                iLength = infoGroup.iLength,
                tExpireTime = request.tExpireTime,
                iPrefixCode = iPrefixCode,
                sOuterNo = request.sOuterNo,
                sTcNo = tc.sRequestNo,
                aNumbers = tc.TcRequestLines.Select(x => x.iFullCode)
            }, ""));
        }