From 120625b890206ee9da07f58e70fbd4b2e5100f9d Mon Sep 17 00:00:00 2001 From: ky_yusj <2655568377@qq.com> Date: Thu, 20 May 2021 14:31:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update=20dapper=E5=88=86=E9=A1=B5=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E6=8B=BC=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Ewide.Core/Extension/PageExtensions.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Api/Ewide.Core/Extension/PageExtensions.cs b/Api/Ewide.Core/Extension/PageExtensions.cs index 71222f8..e752626 100644 --- a/Api/Ewide.Core/Extension/PageExtensions.cs +++ b/Api/Ewide.Core/Extension/PageExtensions.cs @@ -76,9 +76,13 @@ namespace Ewide.Core.Extension private static string PageSqlBuild(string sql , PageInputBase input) { + var sqlStrList = new List(); 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; + if (!string.IsNullOrEmpty(orderStr)) sqlStrList.Add(" Order by " + orderStr); + // input.PageSize = 0表示不分页 + if (input.PageSize != 0) sqlStrList.Add(" LIMIT " + ((input.PageNo - 1) * input.PageSize).ToString() + "," + input.PageSize.ToString()); + sql += String.Join("", sqlStrList); + return sql; } } } From dd257e49ae069b4412c53c00472644cde64fb29a Mon Sep 17 00:00:00 2001 From: ky_yusj <2655568377@qq.com> Date: Thu, 20 May 2021 15:25:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?update=20=E8=8E=B7=E5=8F=96=E5=90=8C?= =?UTF-8?q?=E4=B8=80=E5=8C=BA=E5=9F=9F=E4=B8=8B=E7=9A=84=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E7=BC=96=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/HouseCode/HouseCodeService.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs b/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs index f468ddf..5534b39 100644 --- a/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs +++ b/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs @@ -12,9 +12,15 @@ using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; using Dapper; using Ewide.Core.Extension; +using System.ComponentModel.DataAnnotations; +using System.Linq; namespace Ewide.Application.Service.HouseCode { + /// + /// 房屋编码相关 + /// + [ApiDescriptionSettings(Name = "HouseCode", Order = 180)] public class HouseCodeService : IHouseCodeService, IDynamicApiController, ITransient { private readonly IRepository _houseCodeRep; @@ -30,7 +36,7 @@ namespace Ewide.Application.Service.HouseCode public async Task AddHouseCode(AddHouseCodeInput input) { var areaCodeRep = Db.GetRepository(); - var areaCode = await areaCodeRep.DetachedEntities.FirstOrDefaultAsync(a => a.Code == input.AreaCode); + var areaCode = await areaCodeRep.DetachedEntities.FirstOrDefaultAsync(a => a.Code == input.AreaCode && a.LevelType == 4); if(areaCode == null) throw Oops.Oh("区域编码有误,添加失败"); input.HouseCode = areaCode.AdCode + input.No.ToString().PadLeft(3, '0'); var houseCode = input.Adapt(); @@ -63,5 +69,23 @@ 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 + '%' }); } + + /// + /// 获取同一区域下的下一个编号 + /// + /// + /// + [HttpGet("/houseCode/GetNextNoByFullNumber")] + public async Task GetNextNoByFullNumber([Required] string areaCode) + { + var areaCodeRep = Db.GetRepository(); + //取到社区编码 + var commAreaCode = await areaCodeRep.FirstOrDefaultAsync(a => a.Code == areaCode && a.LevelType == 4); + if(commAreaCode == null) throw Oops.Oh("区域编码有误,房屋编码生成失败"); + var maxNo = await _houseCodeRep.DetachedEntities + .Where(h => h.HouseCode.Contains(commAreaCode.AdCode)) + .MaxAsync(h => (int?)h.No); + return maxNo.GetValueOrDefault(0) + 1; + } } }