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;
+ }
}
}
diff --git a/Api/Ewide.Core/Extension/PageExtensions.cs b/Api/Ewide.Core/Extension/PageExtensions.cs
index f80f55f..1fb8905 100644
--- a/Api/Ewide.Core/Extension/PageExtensions.cs
+++ b/Api/Ewide.Core/Extension/PageExtensions.cs
@@ -1,6 +1,7 @@
using Dapper;
using Furion.DatabaseAccessor;
using Mapster;
+using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
@@ -40,13 +41,6 @@ namespace Ewide.Core.Extension
return orderStr;
}
- private static string PageSqlBuilder(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;
- }
-
public static Task> ToPageData(this IQueryable source, PageInputBase input) where T : new()
{
return source.OrderBy(OrderBuilder(input)).ToPagedListAsync(input.PageNo, input.PageSize);
@@ -78,5 +72,16 @@ namespace Ewide.Core.Extension
commandType: commandType
);
}
+
+ private static string PageSqlBuilder(string sql , PageInputBase input)
+ {
+ var sqlStrList = new List();
+ var orderStr = OrderBuilder(input);
+ 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;
+ }
}
}