diff --git a/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs b/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs index 62e76d5..3f8e9f9 100644 --- a/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs +++ b/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs @@ -41,9 +41,18 @@ namespace Ewide.Application.Service.HouseCode.Dto public string Id { get; set; } } - public class DeleteProjectInput + public class DeleteHouseCodeInput { [Required(ErrorMessage = "房屋编码ID不可为空")] public string Id { get; set; } } + + public class QueryHouseCodeInput : PageInputBase + { + public string HouseCode { get; set; } + public string Address { get; set; } + public string ProjectId { get; set; } + public string ZoonId { get; set; } + public int Type { get; set; } + } } diff --git a/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeOutput.cs b/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeOutput.cs new file mode 100644 index 0000000..8e47132 --- /dev/null +++ b/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeOutput.cs @@ -0,0 +1,23 @@ +using Ewide.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ewide.Application.Service.HouseCode.Dto +{ + public class HouseCodeOutput : PageInputBase + { + public string HouseCode { get; set; } + public string Address { get; set; } + public string ProjectId { get; set; } + public string ZoonId { get; set; } + public int Type { get; set; } + public int ProjectFullName { get; set; } + public int ProjectName { get; set; } + public int AreaName { get; set; } + public int RoadName { get; set; } + public int CommName { get; set; } + } +} diff --git a/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs b/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs index 142fa0c..f468ddf 100644 --- a/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs +++ b/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs @@ -9,10 +9,6 @@ using Furion.FriendlyException; using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; using Dapper; using Ewide.Core.Extension; @@ -51,26 +47,21 @@ namespace Ewide.Application.Service.HouseCode } [HttpPost("/houseCode/delete")] - public async Task DeleteHouseCode(DeleteProjectInput input) + public async Task DeleteHouseCode(DeleteHouseCodeInput input) { var houseCode = _houseCodeRep.FirstOrDefault(p => p.Id == input.Id); await houseCode.DeleteNowAsync(); } - //public async Task QueryHouseCodePageList([FromBody] AddHouseCodeInput input) - //{ - // var areaCodeRep = Db.GetRepository(); - // var projectCodeRep = Db.GetRepository(); - // var houseCodes = await _houseCodeRep.DetachedEntities - // .Join(projectCodeRep.DetachedEntities, c => c.ProjectId, p => p.Id, (c, p) => new { c, p }) - // .Join(areaCodeRep.DetachedEntities, cp => cp.p.AreaCode, a => a.Code, (cp, a) => new { cp, a }) - // .Where(!string.IsNullOrEmpty(input.HouseCode), cpa => cpa.cp.c.HouseCode.Contains(input.HouseCode)) - //} - - public async Task QueryPage() + [HttpPost("/houseCode/page")] + public async Task QueryPage([FromBody] QueryHouseCodeInput input) { - var sql = "SELECT * FROM bs_house_code"; - return await _dapperRepository.QueryPageData(sql, new PageInputBase()); + var sql = @"SELECT HC.*,HP.Note,AA.Name AreaName,RA.Name RoadName,CA.Name CommName FROM bs_house_code HC +LEFT JOIN bs_house_projectinfo HP ON HP.Id=HC.ProjectId +LEFT JOIN sys_area_code CA ON CA.Code = HP.AreaCode +LEFT JOIN sys_area_code RA ON RA.AdCode = SUBSTR(CA.AdCode,1,9) +LEFT JOIN sys_area_code AA ON AA.AdCode = SUBSTR(CA.AdCode,1,6) WHERE HC.Address like @Address"; + return await _dapperRepository.QueryPageData(sql, input, param: new { Address = '%' + input.Address + '%' }); } } } diff --git a/Api/Ewide.Core/Extension/PageExtensions.cs b/Api/Ewide.Core/Extension/PageExtensions.cs index f10172d..71222f8 100644 --- a/Api/Ewide.Core/Extension/PageExtensions.cs +++ b/Api/Ewide.Core/Extension/PageExtensions.cs @@ -15,7 +15,17 @@ namespace Ewide.Core.Extension { public static class PageExtensions { - public static string OrderBuilder(PageInputBase pageInput, bool descSort = true) + private static string OrderBuilder(PageInputBase pageInput) + { + var orderStr = string.Empty; + if (!string.IsNullOrEmpty(pageInput.SortField)) + { + orderStr = $"{pageInput.SortField} {(pageInput.SortOrder == pageInput.DescStr ? "Desc" : "Asc")}"; + } + return orderStr; + } + + private static string OrderBuilder(PageInputBase pageInput, bool descSort = true) { var type = typeof(T); var hasId = type.GetProperty("Id") != null; @@ -24,12 +34,12 @@ namespace Ewide.Core.Extension var defaultField = hasSort ? "Sort" : (hasId ? "Id" : ""); // 约定默认每张表都有Id排序 - var orderStr = string.IsNullOrEmpty(defaultField) ? "" : defaultField + (descSort ? " Asc" : " Desc"); + var orderStr = string.IsNullOrEmpty(defaultField) ? "" : defaultField + (descSort ? " Desc" : " Asc"); // 排序是否可用-排序字段和排序顺序都为非空才启用排序 - if (!string.IsNullOrEmpty(pageInput.SortField) && !string.IsNullOrEmpty(pageInput.SortOrder)) + if (!string.IsNullOrEmpty(pageInput.SortField)) { - orderStr = $"{pageInput.SortField} {(pageInput.SortOrder == pageInput.DescStr ? "Asc" : "Desc")}"; + orderStr = OrderBuilder(pageInput); } return orderStr; } @@ -46,7 +56,7 @@ namespace Ewide.Core.Extension public static Task> QueryPageData(this IDapperRepository source, string sql, PageInputBase input, object param = null, System.Data.IDbTransaction transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) { - return source.QueryAsync(sql, + return source.QueryAsync(PageSqlBuild(sql,input), param: param, transaction: transaction, commandTimeout: commandTimeout, @@ -63,5 +73,12 @@ namespace Ewide.Core.Extension commandType: commandType ); } + + private static string PageSqlBuild(string sql , PageInputBase input) + { + var orderStr = OrderBuilder(input); + var r = "SELECT * FROM (" + sql + ") T " + (string.IsNullOrEmpty(orderStr) ? string.Empty : "Order by " + orderStr) + " LIMIT " + ((input.PageNo - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString(); + return r; + } } } diff --git a/Api/Ewide.Core/Extension/XnInputBase.cs b/Api/Ewide.Core/Extension/XnInputBase.cs index a0ab4ad..0121260 100644 --- a/Api/Ewide.Core/Extension/XnInputBase.cs +++ b/Api/Ewide.Core/Extension/XnInputBase.cs @@ -70,6 +70,6 @@ namespace Ewide.Core /// /// 降序排序(不要问我为什么是descend不是desc,前端约定参数就是这样) /// - public virtual string DescStr { get; set; } = "descend"; + public virtual string DescStr => "descend"; } }