public async Task <ResponseModel> GetPageCompanyInfo([FromQuery] EntityCompanyPageQuery companyPageQuery) { if (companyPageQuery == null) { return(Fail(ErrorCodeEnum.ParamIsNullArgument)); } var result = await ICompanyService.GetPageCompanyInfo(companyPageQuery); return(Success(result)); }
/// <summary> /// 企业搜索分页 /// </summary> /// <param name="companyPageQuery"></param> /// <returns></returns> public async Task <PageBase <TableCompany> > GetPageCompanyInfo(EntityCompanyPageQuery companyPageQuery) { var result = new PageBase <TableCompany> { CurrentPage = companyPageQuery.CurrentPage, PageSize = companyPageQuery.PageSize }; var strSql = new StringBuilder(); //计算总数 strSql.Append(@" SELECT @totalCount = COUNT(1) FROM dbo.T_Company "); if (!string.IsNullOrEmpty(companyPageQuery.CompanyName)) { strSql.Append(" where CompanyName like '%' + @companyName +'%' ;"); } //分页信息 strSql.Append(@"; SELECT * FROM (SELECT ROW_NUMBER() OVER ( ORDER BY CreateTime DESC ) RowNumber , Id , CompanyName , Provice , City , County , AddressDetail , Longitude , Latitude , Industry , Economy , CompanyDetail , ZipCode , FoundedTime , IssureTime , IndustryCode , Owner , CompanyScale , CompanyIncome , ChiefSafeyName , ChiefSafeyPhone , ViceSafeyName , ViceSafeyPhone , OnDutyPhone , EmergencyPhone , CompanyProductDetail , CreateTime , Memo , Status , RiskLevel , ProvCode , CityCode , CountyCode FROM T_Company "); if (!string.IsNullOrEmpty(companyPageQuery.CompanyName)) { strSql.Append(" where CompanyName like '%' + @companyName +'%' "); } strSql.Append(@" ) AS a WHERE a.RowNumber > @startIndex AND a.RowNumber <= @endIndex "); strSql.Append(@" order by a.RowNumber "); var paras = new DynamicParameters(new { companyName = companyPageQuery.CompanyName, startIndex = (companyPageQuery.CurrentPage - 1) * companyPageQuery.PageSize, endIndex = companyPageQuery.CurrentPage * companyPageQuery.PageSize }); var companyRep = GetRepositoryInstance <TableCompany>(); paras.Add("totalCount", dbType: DbType.Int32, direction: ParameterDirection.Output); var sqlQuery = new SqlQuery(strSql.ToString(), paras); result.Items = companyRep.FindAll(sqlQuery).ToList(); result.TotalCounts = paras.Get <int?>("totalCount") ?? 0; result.TotalPages = Convert.ToInt32(Math.Ceiling(result.TotalCounts / (companyPageQuery.PageSize * 1.0))); return(result); }