/// <summary> /// 分页获取活动用户 /// </summary> /// <returns></returns> public PageLuckyCharmUserModel PageActivtiyUser(int pageIndex, int pageSize, string phone, int pkid, string areaName, int checkState) { var result = new PageLuckyCharmUserModel() { Users = new List <LuckyCharmUserModel>() }; try { using (var client = new LuckyCharmClient()) { var request = new PageLuckyCharmUserRequest() { AreaName = areaName, PKID = pkid, Phone = phone, PageIndex = pageIndex, PageSize = pageSize, CheckState = checkState }; var users = client.PageLuckyCharmUser(request); if (users.Success) { result.Total = users.Result.Total; foreach (var item in users.Result.Users) { result.Users.Add(new LuckyCharmUserModel() { ActivityId = item.ActivityId, AreaId = item.AreaId, AreaName = item.AreaName, Phone = item.Phone, UserId = item.UserId, UserName = item.UserName, PKID = item.PKID, }); } } } } catch (Exception e) { Logger.Error($"PageActivtiyUser -> {pageIndex}-{pageSize}-{phone}-{pkid}-{areaName}-{checkState}", e); throw; } return(result); }
public void Execute(IJobExecutionContext context) { Logger.InfoFormat("定时审核服务于{0}时,开始运行", DateTime.Now); using (var client = new LuckyCharmClient()) { var condition = new PageLuckyCharmUserRequest() { CheckState = 0, AreaName = "上海市闵行区", PageIndex = 0, PageSize = 10 }; var IsRun = true; while (IsRun) { try { var users = client.PageLuckyCharmUserAsync(condition); if (!users.Result.Success) { Logger.ErrorFormat("分页获取失败,错误编码:{0} 描述:{1}", users.Result.ErrorCode, users.Result.ErrorMessage); } if (users.Result.Result.Total <= 0) { break; } foreach (var item in users.Result.Result.Users) { //该处可以加入其他的业务逻辑判断,当前的限定上海市闵行区的条件查询只是一个举例 //同时可以调用另外的重载client.AuditLuckyCharmUser(AreaName)完成直接的逻辑审核; var isSuccess = client.AuditLuckyCharmUser(item.PKID); if (!isSuccess.Result) { Logger.ErrorFormat("审核失败,错误编码:{0} 描述:{1}", isSuccess.ErrorCode, isSuccess.ErrorMessage); } } } catch (Exception ex) { Logger.ErrorFormat("发生不可预测错误:{0}", ex); } finally { IsRun = false; } } } Logger.InfoFormat("定时审核服务于{0}时,结束运行", DateTime.Now); }
/// <summary> /// 根据条件分页获取报名参加用户的列表 /// </summary> /// <param name="model"></param> /// <returns></returns> public static async Task <List <LuckyCharmUserModel> > PageActivityUser(PageLuckyCharmUserRequest model) { //string sql = @"select top @pageSize * from (select row_number() over(order by PKID asc) as rownumber,* //from Activity.dbo.T_LuckyCharmUser WITH (NOLOCK) {0})temp_row where rownumber>10"; string sql = @"select * from Activity.dbo.T_LuckyCharmUser WITH (NOLOCK) {0} ORDER BY PKID DESC OFFSET (@PageIndex - 1) * @PageSize ROW FETCH NEXT @PageSize ROW ONLY" ; var parameters = new Dictionary <string, object>(); if (!string.IsNullOrWhiteSpace(model.AreaName)) { parameters.Add("AreaName", model.AreaName); } if (model.PKID > 0) { parameters.Add("PKID", model.PKID); } if (!string.IsNullOrWhiteSpace(model.Phone)) { parameters.Add("Phone", model.Phone); } if (model.CheckState >= 0) { parameters.Add("CheckState", model.CheckState); } StringBuilder condition = new StringBuilder("where IsDelete=0 "); foreach (var key in parameters.Keys) { condition.AppendFormat("and {0}=@{1} ", key, key); } using (var cmd = new SqlCommand(string.Format(sql, condition.ToString()))) { foreach (var key in parameters.Keys) { cmd.AddParameter(string.Format("@{0}", key), parameters[key]); } cmd.AddParameter("@PageSize", model.PageSize); cmd.AddParameter("@PageIndex", model.PageIndex); var result = await DbHelper.ExecuteSelectAsync <LuckyCharmUserModel>(true, cmd); return(result?.ToList()); } }
/// <summary> /// 根据条件获取用户总数 /// </summary> /// <param name="model"></param> /// <returns></returns> public static async Task <int> TotalActivityUser(PageLuckyCharmUserRequest model) { string sql = @"select count(1) from Activity.dbo.T_LuckyCharmUser WITH (NOLOCK) {0}"; var parameters = new Dictionary <string, object>(); if (!string.IsNullOrWhiteSpace(model.AreaName)) { parameters.Add("AreaName", model.AreaName); } if (model.PKID > 0) { parameters.Add("PKID", model.PKID); } if (!string.IsNullOrWhiteSpace(model.Phone)) { parameters.Add("Phone", model.Phone); } if (model.CheckState >= 0) { parameters.Add("CheckState", model.CheckState); } StringBuilder condition = new StringBuilder("where IsDelete=0 "); foreach (var key in parameters.Keys) { condition.AppendFormat("and {0}=@{1} ", key, key); } using (var cmd = new SqlCommand(string.Format(sql, condition.ToString()))) { foreach (var key in parameters.Keys) { cmd.AddParameter(string.Format("@{0}", key), parameters[key]); } int.TryParse((await DbHelper.ExecuteScalarAsync(true, cmd)).ToString(), out int result); return(result); } }
public void PageActivityUserTest() { //var condition = new PageLuckyCharmUserRequest() { AreaName = "上海市闵行区", PageIndex = 1, PageSize = 10 }; var condition = new PageLuckyCharmUserRequest() { CheckState = 0, PageIndex = 1, PageSize = 10 }; //var results = DalLuckyCharm.IsExistUserByPKID(2); //Assert.AreEqual(results.Result, true); //return;++ System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); using (var client = new LuckyCharmClient()) { for (int i = 0; i < 10; i++) { stopwatch.Start(); var result = client.GetLuckyCharmActivity(3); stopwatch.Stop(); Console.WriteLine($"第{i}次耗时:{stopwatch.ElapsedMilliseconds}"); Assert.IsTrue(result.Success); } } }
public async Task <OperationResult <PageLuckyCharmUserResponse> > PageLuckyCharmUserAsync(PageLuckyCharmUserRequest request) { return(await LuckyCharmManager.PageActivityUserAsync(request)); }
public static async Task <OperationResult <PageLuckyCharmUserResponse> > PageActivityUserAsync(PageLuckyCharmUserRequest model) { if (model.PageIndex < 1) { model.PageIndex = 1; } if (model.PageSize <= 0) { model.PageSize = 10; } var user = await DalLuckyCharm.PageActivityUser(model); var total = await DalLuckyCharm.TotalActivityUser(model); var result = new PageLuckyCharmUserResponse(); result.Users = Mapper.Map <List <LuckyCharmUserInfoRespone> >(user); result.Total = total; return(OperationResult.FromResult(result)); }