/// <summary>
        /// 分页获取 数目
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async ValueTask <int> GetCouponGetRuleAuditCountAsync(GetCouponGetRuleAuditListRequest request, CancellationToken cancellationToken)
        {
            Dictionary <string, List <SqlParameter> > query = CreateCondition(request, true);
            string condition = query.Keys.FirstOrDefault();

            #region sql
            var sql = $@"SELECT 
                           Count(1)
                        FROM {DBName} WITH ( NOLOCK )
                        {condition}
                        ";
            #endregion

            using (var dbHelper = _factory.CreateDbHelper("Activity", true))
            {
                using (var cmd = new SqlCommand(sql))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddRange(query[condition].ToArray());
                    var result = Convert.ToInt32(await dbHelper.ExecuteScalarAsync(cmd).ConfigureAwait(false));
                    return(result);
                }
            }
        }
        /// <summary>
        /// 分页查询  领取规则审核 list
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async ValueTask <List <GetCouponRuleAuditModel> > GetCouponGetRuleAuditListAsync(GetCouponGetRuleAuditListRequest request, CancellationToken cancellationToken)
        {
            List <GetCouponRuleAuditEntity> entity = await _ICouponGetRuleAuditRepository.GetCouponGetRuleAuditListAsync(request, cancellationToken).ConfigureAwait(false);

            List <GetCouponRuleAuditModel> models = ObjectMapper.ConvertTo <GetCouponRuleAuditEntity, GetCouponRuleAuditModel>(entity).ToList();

            return(models);
        }
 /// <summary>
 /// 分页查询  领取规则审核  count
 /// </summary>
 /// <param name="request"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public async ValueTask <int> GetCouponGetRuleAuditCountAsync(GetCouponGetRuleAuditListRequest request, CancellationToken cancellationToken)
 {
     return(await _ICouponGetRuleAuditRepository.GetCouponGetRuleAuditCountAsync(request, cancellationToken).ConfigureAwait(false));
 }
        /// <summary>
        /// 获取 分页查询数据 参数
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private Dictionary <string, List <SqlParameter> > CreateCondition(GetCouponGetRuleAuditListRequest request, bool isQueryCount = false)
        {
            Dictionary <string, List <SqlParameter> > dic = new Dictionary <string, List <SqlParameter> >();
            string condition    = $" where 1 = 1";
            var    sqlParaments = new List <SqlParameter>();

            if (request.RuleID > 0)
            {
                condition += " AND  RuleID = @RuleID ";
                sqlParaments.Add(new SqlParameter("@RuleID", request.RuleID));
            }
            if (request.GetRuleGUID != Guid.Empty)
            {
                condition += "  AND  GetRuleGUID = @GetRuleGUID ";
                sqlParaments.Add(new SqlParameter("@GetRuleGUID", request.GetRuleGUID));
            }
            if (!string.IsNullOrWhiteSpace(request.PromtionName))
            {
                condition += "  AND  PromtionName like @PromtionName ";
                sqlParaments.Add(new SqlParameter("@PromtionName", "%" + request.PromtionName + "%"));
            }
            if (!string.IsNullOrWhiteSpace(request.Description))
            {
                condition += "  AND  Description like @Description ";
                sqlParaments.Add(new SqlParameter("@Description", "%" + request.Description + "%"));
            }
            if (request.SupportUserRange > 0)
            {
                condition += " AND  SupportUserRange = @SupportUserRange ";
                sqlParaments.Add(new SqlParameter("@SupportUserRange", request.SupportUserRange));
            }
            if (request.MinDiscount > 0)
            {
                condition += " AND  Discount >= @MinDiscount ";
                sqlParaments.Add(new SqlParameter("@MinDiscount", request.MinDiscount));
            }
            if (request.MaxDiscount > 0)
            {
                condition += " AND  Discount <= @MaxDiscount ";
                sqlParaments.Add(new SqlParameter("@MaxDiscount", request.MaxDiscount));
            }
            if (request.MinMinmoney > 0)
            {
                condition += " AND Minmoney >= @MinMinmoney ";
                sqlParaments.Add(new SqlParameter("@MinMinmoney", request.MinMinmoney));
            }
            if (request.MaxMinmoney > 0)
            {
                condition += " AND  Minmoney <= @MaxMinmoney ";
                sqlParaments.Add(new SqlParameter("@MaxMinmoney", request.MaxMinmoney));
            }
            if (request.AllowChanel > 0)
            {
                condition += " AND  AllowChanel = @AllowChanel ";
                sqlParaments.Add(new SqlParameter("@AllowChanel", request.AllowChanel));
            }
            if (request.DepartmentId > 0)
            {
                condition += " AND  DepartmentId = @DepartmentId ";
                sqlParaments.Add(new SqlParameter("@DepartmentId", request.DepartmentId));
            }
            if (request.IntentionId > 0)
            {
                condition += " AND  IntentionId = @IntentionId ";
                sqlParaments.Add(new SqlParameter("@IntentionId", request.IntentionId));
            }

            if (request.AuditStatus > 0)
            {
                condition += " AND  AuditStatus = @AuditStatus ";
                sqlParaments.Add(new SqlParameter("@IntentionId", request.IntentionId));
            }

            if (!isQueryCount)
            {
                condition += " ORDER BY PKID DESC ";
                condition += " OFFSET(@PageSize * (@CurrentPage - 1)) ROWS FETCH NEXT @PageSize ROWS ONLY ";
                sqlParaments.Add(new SqlParameter("@CurrentPage", request.CurrentPage));
                sqlParaments.Add(new SqlParameter("@PageSize", request.PageSize));
            }
            dic.Add(condition, sqlParaments);
            return(dic);
        }
        /// <summary>
        /// 分页查询数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async ValueTask <List <GetCouponRuleAuditEntity> > GetCouponGetRuleAuditListAsync(GetCouponGetRuleAuditListRequest request, CancellationToken cancellationToken)
        {
            Dictionary <string, List <SqlParameter> > query = CreateCondition(request, false);
            string condition = query.Keys.FirstOrDefault();

            #region sql
            string sql = $@"SELECT [PKID]
                                      ,[GetCouponRulePKID]
                                      ,[RuleID]
                                      ,[Description]
                                      ,[PromtionName]
                                      ,[Discount]
                                      ,[Minmoney]
                                      ,[AllowChanel]
                                      ,[Term]
                                      ,[ValiStartDate]
                                      ,[ValiEndDate]
                                      ,[Quantity]
                                      ,[GetQuantity]
                                      ,[SingleQuantity]
                                      ,[DXStartDate]
                                      ,[DXEndDate]
                                      ,[GetRuleGUID]
                                      ,[Channel]
                                      ,[SupportUserRange]
                                      ,[DetailShowStartDate]
                                      ,[DetailShowEndDate]
                                      ,[DepartmentId]
                                      ,[IntentionId]
                                      ,[Creater]
                                      ,[DepartmentName]
                                      ,[IntentionName]
                                      ,[CouponType]
                                      ,[DeadLineDate]
                                      ,[IsPush]
                                      ,[PushSetting]
                                      ,[BusinessLineId]
                                      ,[BusinessLineName]
                                      ,[RemindQuantity]
                                      ,[RemindEmails]
                                      ,[Applicant]
                                      ,[Auditor]
                                      ,[AuditDateTime]
                                      ,[AuditStatus]
                                      ,[AuditMessage]
                                      ,[WorkOrderId]
                                      ,[CreateDateTime]
                                      ,[LastUpdateDateTime]
                                  FROM  {DBName} with (nolock)
                                  {condition}
                                ;";
            #endregion

            using (var dbHelper = _factory.CreateDbHelper("Activity", true))
            {
                using (var cmd = new SqlCommand(sql))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddRange(query[condition].ToArray());
                    var result = await dbHelper.ExecuteSelectAsync <GetCouponRuleAuditEntity>(cmd, cancellationToken).ConfigureAwait(false);

                    return(result.ToList());
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取获优惠券领取规则审核记录 - 分页
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async override ValueTask <OperationResult <PagedModel <GetCouponRuleAuditModel> > > GetCouponGetRuleAuditListAsync([FromBody] GetCouponGetRuleAuditListRequest request)
        {
            try
            {
                PagedModel <GetCouponRuleAuditModel> result = new PagedModel <GetCouponRuleAuditModel>()
                {
                    Pager = new PagerModel()
                    {
                        CurrentPage = request.CurrentPage > 0 ? request.CurrentPage : 1,
                        PageSize    = request.PageSize > 0 ? request.PageSize : 10,
                    }
                };

                result.Pager.Total = await _ICouponGetRuleAuditManager.GetCouponGetRuleAuditCountAsync(request, HttpContext.RequestAborted).ConfigureAwait(false);

                List <GetCouponRuleAuditModel> source = await _ICouponGetRuleAuditManager.GetCouponGetRuleAuditListAsync(request, HttpContext.RequestAborted).ConfigureAwait(false);

                result.Source = source;
                return(OperationResult.FromResult(result));
            }
            catch (Exception ex)
            {
                return(OperationResult.FromError <PagedModel <GetCouponRuleAuditModel> >("-1", ex.Message));
            }
        }