update 获取同一区域下的下一个编号
This commit is contained in:
@@ -12,9 +12,15 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Ewide.Core.Extension;
|
using Ewide.Core.Extension;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Ewide.Application.Service.HouseCode
|
namespace Ewide.Application.Service.HouseCode
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 房屋编码相关
|
||||||
|
/// </summary>
|
||||||
|
[ApiDescriptionSettings(Name = "HouseCode", Order = 180)]
|
||||||
public class HouseCodeService : IHouseCodeService, IDynamicApiController, ITransient
|
public class HouseCodeService : IHouseCodeService, IDynamicApiController, ITransient
|
||||||
{
|
{
|
||||||
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
||||||
@@ -30,7 +36,7 @@ namespace Ewide.Application.Service.HouseCode
|
|||||||
public async Task AddHouseCode(AddHouseCodeInput input)
|
public async Task AddHouseCode(AddHouseCodeInput input)
|
||||||
{
|
{
|
||||||
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
||||||
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("区域编码有误,添加失败");
|
if(areaCode == null) throw Oops.Oh("区域编码有误,添加失败");
|
||||||
input.HouseCode = areaCode.AdCode + input.No.ToString().PadLeft(3, '0');
|
input.HouseCode = areaCode.AdCode + input.No.ToString().PadLeft(3, '0');
|
||||||
var houseCode = input.Adapt<BsHouseCode>();
|
var houseCode = input.Adapt<BsHouseCode>();
|
||||||
@@ -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";
|
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 + '%' });
|
return await _dapperRepository.QueryPageData(sql, input, param: new { Address = '%' + input.Address + '%' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取同一区域下的下一个编号
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="areaCode"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("/houseCode/GetNextNoByFullNumber")]
|
||||||
|
public async Task<dynamic> GetNextNoByFullNumber([Required] string areaCode)
|
||||||
|
{
|
||||||
|
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
||||||
|
//取到社区编码
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user