167 lines
6.2 KiB
C#
167 lines
6.2 KiB
C#
using Ewide.Application.Entity;
|
|
using Ewide.Application.Service.HouseProjectInfo.Dto;
|
|
using Ewide.Core;
|
|
using Ewide.Core.Service;
|
|
using Ewide.Core.Util;
|
|
using Ewide.EntityFramework.Core;
|
|
using Furion;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DatabaseAccessor.Extensions;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
using MySqlConnector;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ewide.Application.Service.HouseProjectInfo
|
|
{
|
|
[ApiDescriptionSettings(Name = "xml", Order = 3)]
|
|
public class XMLHandler : IDynamicApiController, ITransient
|
|
{
|
|
private readonly DefaultDbContext _db;
|
|
|
|
public XMLHandler(DefaultDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
[HttpGet("/xml/detail")]
|
|
public async Task XMLDoneAsync()
|
|
{
|
|
XmlSerializerUtil xmlHandler = new XmlSerializerUtil();
|
|
xmlHandler.WriteDataSeed();
|
|
//拿到数据保存到 XML文件
|
|
//Dictionary<string, object> dicDataBase = await GetDataBase();
|
|
//foreach (KeyValuePair<string, object> item in dicDataBase)
|
|
//{
|
|
// xmlHandler.WriteXML(item.Value.GetType(), item.Value, item.Key);
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 读取数据库的所有表 并拿到数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task<Dictionary<string, object>> GetDataBase()
|
|
{
|
|
Dictionary<string, object> dicDataBase = new Dictionary<string, object>();
|
|
var defaultConnection = App.Configuration["ConnectionStrings:DefaultConnection"];
|
|
//获取 所有继承 IEntity 接口的表
|
|
IEnumerable<IEntityType> entityTypedb = _db.Model.GetEntityTypes().Where(x => typeof(IEntity).IsAssignableFrom(x.ClrType)).ToList();
|
|
|
|
foreach (IEntityType item in entityTypedb)
|
|
{
|
|
MethodInfo mi = _db.GetType().GetMethods().FirstOrDefault(s => s.Name == "Set");
|
|
MethodInfo miConstructed = mi.MakeGenericMethod(item.ClrType);
|
|
object objList = miConstructed.Invoke(_db, null);
|
|
var objsource = item.ClrType.MakeList(objList);
|
|
dicDataBase.Add(item.ClrType.Name, objsource);
|
|
}
|
|
await _db.Database.CloseConnectionAsync();
|
|
return dicDataBase;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 项目管理相关服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Name = "HouseProjectInfo", Order = 170)]
|
|
public class HouseProjectInfoService : IHouseProjectInfoService, ITransient, IDynamicApiController
|
|
{
|
|
private readonly IRepository<BsHouseProjectInfo> _houseProjectInfoRep;
|
|
|
|
public HouseProjectInfoService(IRepository<BsHouseProjectInfo> houseProjectInfoRep)
|
|
{
|
|
_houseProjectInfoRep = houseProjectInfoRep;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加项目
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/houseProjectInfo/add")]
|
|
public async Task AddProject(AddProjectInput input)
|
|
{
|
|
await _houseProjectInfoRep.InsertNowAsync(input.Adapt<BsHouseProjectInfo>());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除项目
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/houseProjectInfo/delete")]
|
|
public async Task DeleteProject(DeleteProjectInput input)
|
|
{
|
|
var project = _houseProjectInfoRep.FirstOrDefault(p => p.Id == input.Id);
|
|
await project.DeleteNowAsync();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 编辑项目
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/houseProjectInfo/edit")]
|
|
public async Task UpdateProject(UpdateProjectInput input)
|
|
{
|
|
var project = input.Adapt<BsHouseProjectInfo>();
|
|
await project.UpdateExcludeAsync(new[] { nameof(BsHouseProjectInfo.AreaId) }, true);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过ID获取项目
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/houseProjectInfo/detailById")]
|
|
public async Task<BsHouseProjectInfo> GetProjectById([Required] string id)
|
|
{
|
|
return await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 分页查询
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/houseProjectInfo/page")]
|
|
public async Task<dynamic> QueryProjectPageList([FromBody] HouseProjectInfoInput input)
|
|
{
|
|
var areaID = !string.IsNullOrEmpty(input.AreaId);
|
|
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
|
var projects = await _houseProjectInfoRep.DetachedEntities
|
|
.Join(areaCodeRep.DetachedEntities, p => p.AreaId, a => a.Code, (p, a) => new { p, AreaName = a.Name })
|
|
.Where(areaID, x => x.p.AreaId == input.AreaId)
|
|
.Select(x => new { x.p.Id, x.p.Name, x.p.Note, x.p.Sort, x.p.AreaId, x.AreaName, x.p.Type }.Adapt<HouseProjectOutput>()).ToPagedListAsync(input.PageNo, input.PageSize);
|
|
return XnPageResult<HouseProjectOutput>.PageResult(projects);
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("/houseProjectInfo/detail")]
|
|
public async Task<dynamic> GetProject([FromQuery] QueryProjectInput input)
|
|
{
|
|
var user = await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.Id);
|
|
var userDto = user.Adapt<UserOutput>();
|
|
|
|
return userDto;
|
|
}
|
|
}
|
|
}
|