77 lines
3.1 KiB
C#
77 lines
3.1 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;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
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(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))
|
|
//}
|
|
|
|
public async Task<dynamic> QueryPage()
|
|
{
|
|
var sql = "SELECT * FROM bs_house_code";
|
|
return await _dapperRepository.QueryPageData(sql, new PageInputBase());
|
|
}
|
|
}
|
|
}
|