68 lines
2.8 KiB
C#
68 lines
2.8 KiB
C#
using Ewide.Application.Entity;
|
|
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.Threading.Tasks;
|
|
using Dapper;
|
|
using Ewide.Core.Extension;
|
|
|
|
namespace Ewide.Application.Service.HouseCode
|
|
{
|
|
public class HouseCodeService : IHouseCodeService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
|
private readonly IDapperRepository _dapperRepository;
|
|
|
|
public HouseCodeService(IRepository<BsHouseCode> HouseCodeRep, IDapperRepository dapperRepository)
|
|
{
|
|
_houseCodeRep = HouseCodeRep;
|
|
_dapperRepository = dapperRepository;
|
|
}
|
|
|
|
[HttpPost("/houseCode/add")]
|
|
public async Task AddHouseCode(AddHouseCodeInput input)
|
|
{
|
|
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
|
var areaCode = await areaCodeRep.DetachedEntities.FirstOrDefaultAsync(a => a.Code == input.AreaCode);
|
|
if(areaCode == null) throw Oops.Oh("区域编码有误,添加失败");
|
|
input.HouseCode = areaCode.AdCode + input.No.ToString().PadLeft(3, '0');
|
|
var houseCode = input.Adapt<BsHouseCode>();
|
|
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(DeleteHouseCodeInput input)
|
|
{
|
|
var houseCode = _houseCodeRep.FirstOrDefault(p => p.Id == input.Id);
|
|
await houseCode.DeleteNowAsync();
|
|
}
|
|
|
|
[HttpPost("/houseCode/page")]
|
|
public async Task<dynamic> QueryPage([FromBody] QueryHouseCodeInput input)
|
|
{
|
|
var sql = @"SELECT HC.*,HP.Note,AA.Name AreaName,RA.Name RoadName,CA.Name CommName FROM bs_house_code HC
|
|
LEFT JOIN bs_house_projectinfo HP ON HP.Id=HC.ProjectId
|
|
LEFT JOIN sys_area_code CA ON CA.Code = HP.AreaCode
|
|
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 + '%' });
|
|
}
|
|
}
|
|
}
|