From 8709143140ad95d8b271b0fa87eee934373765ed Mon Sep 17 00:00:00 2001 From: ky_yusj <2655568377@qq.com> Date: Thu, 20 May 2021 09:58:33 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=88=BF=E5=B1=8B=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Api/Ewide.Application/Entity/BsHouseCode.cs | 4 +-- .../Service/HouseCode/Dto/HouseCodeInput.cs | 10 ++++-- .../Service/HouseCode/HouseCodeService.cs | 32 +++++++++++++++++-- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Api/Ewide.Application/Entity/BsHouseCode.cs b/Api/Ewide.Application/Entity/BsHouseCode.cs index d46069f..8dd47a9 100644 --- a/Api/Ewide.Application/Entity/BsHouseCode.cs +++ b/Api/Ewide.Application/Entity/BsHouseCode.cs @@ -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)] diff --git a/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs b/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs index a66cf94..62e76d5 100644 --- a/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs +++ b/Api/Ewide.Application/Service/HouseCode/Dto/HouseCodeInput.cs @@ -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; } + } } diff --git a/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs b/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs index 9652f8f..0d6ba65 100644 --- a/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs +++ b/Api/Ewide.Application/Service/HouseCode/HouseCodeService.cs @@ -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(); - 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(); - 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(); + 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 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)) + //} } }