update 房屋编码

This commit is contained in:
2021-05-20 09:58:33 +08:00
parent 4ddf8b7431
commit 8709143140
3 changed files with 39 additions and 7 deletions

View File

@@ -11,12 +11,12 @@ namespace Ewide.Application.Entity
[Comment("系统中唯一的房屋编码,生成即不再变更")]
[MaxLength(50)]
[Required]
public string FullNumber { get; set; }
public string HouseCode { get; set; }
[Comment("编号")]
[MaxLength(3)]
[Required]
public string No { get; set; }
public int No { get; set; }
[Comment("项目ID")]
[MaxLength(36)]

View File

@@ -14,13 +14,13 @@ namespace Ewide.Application.Service.HouseCode.Dto
public class AddHouseCodeInput : PageInputBase
{
public string FullNumber { get; set; }
public string HouseCode { get; set; }
[Required(ErrorMessage = "行政区域编码不能为空")]
public string AreaCode { get; set; }
[Required(ErrorMessage = "项目Id不能为空")]
public string ProjectId { get; set; }
[Required(ErrorMessage = "房屋编号不能为空")]
public string No { get; set; }
public int No { get; set; }
[Required(ErrorMessage = "片区Id不能为空")]
public string ZoneId { get; set; }
[Required(ErrorMessage = "房屋地址不能为空")]
@@ -40,4 +40,10 @@ namespace Ewide.Application.Service.HouseCode.Dto
[Required(ErrorMessage = "房屋编码Id不能为空")]
public string Id { get; set; }
}
public class DeleteProjectInput
{
[Required(ErrorMessage = "房屋编码ID不可为空")]
public string Id { get; set; }
}
}

View File

@@ -2,11 +2,13 @@
using Ewide.Application.Service.HouseCode.Dto;
using Ewide.Core;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -28,13 +30,37 @@ namespace Ewide.Application.Service.HouseCode
public async Task AddHouseCode(AddHouseCodeInput input)
{
var areaCodeRep = Db.GetRepository<SysAreaCode>();
var areaCode = areaCodeRep.DetachedEntities.Where(a => a.Code == input.AreaCode).FirstOrDefault();
var areaCode = await areaCodeRep.DetachedEntities.FirstOrDefaultAsync(a => a.Code == input.AreaCode);
if(areaCode == null) throw Oops.Oh("区域编码有误,添加失败");
input.FullNumber = areaCode.AdCode + input.No;
input.HouseCode = areaCode.AdCode + input.No.ToString().PadLeft(3, '0');
var houseCode = input.Adapt<BsHouseCode>();
var isExist = await _houseCodeRep.AnyAsync(p => p.FullNumber == houseCode.FullNumber);
var isExist = await _houseCodeRep.AnyAsync(p => p.HouseCode == houseCode.HouseCode);
if (isExist) throw Oops.Oh("房屋编码已存在,不可重复添加");
await _houseCodeRep.InsertAsync(houseCode);
}
[HttpPost("/houseCode/edit")]
public async Task EditHouseCode(EditHouseCodeInput input)
{
var houseCode = input.Adapt<BsHouseCode>();
await houseCode.UpdateExcludeAsync(new[] { nameof(BsHouseCode.HouseCode) }, true);
}
[HttpPost("/houseCode/delete")]
public async Task DeleteHouseCode(DeleteProjectInput input)
{
var houseCode = _houseCodeRep.FirstOrDefault(p => p.Id == input.Id);
await houseCode.DeleteNowAsync();
}
//public async Task<dynamic> QueryHouseCodePageList([FromBody] AddHouseCodeInput input)
//{
// var areaCodeRep = Db.GetRepository<SysAreaCode>();
// var projectCodeRep = Db.GetRepository<BsHouseProjectInfo>();
// 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))
//}
}
}