feat 点位图

This commit is contained in:
2024-04-02 16:59:26 +08:00
parent 726c013193
commit 5940914e57
13 changed files with 426 additions and 2 deletions

View File

@@ -0,0 +1,93 @@
using Dlhis.Basic.Map.Request;
using Dlhis.Basic.Map.Response;
using Dlhis.Basic.Map.Services;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Dlhis.Basic.Map.Controllers;
/// <summary>
/// 点位图
/// </summary>
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class PointMapsController : ControllerBase
{
private readonly IPointMapService _pointMapService;
private readonly IPointMapDetailService _pointMapDetailService;
public PointMapsController(IPointMapService pointMapService,
IPointMapDetailService pointMapDetailService)
{
_pointMapService = pointMapService;
_pointMapDetailService = pointMapDetailService;
}
/// <summary>
/// 点位图分页
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("page")]
public async Task<Pagination<PointMapResponse>> GetPointMapPageAsync([FromQuery] PageDto request)
{
return await _pointMapService.GetPageAsync(request);
}
/// <summary>
/// 保存点位图
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("save")]
public async Task SavePointMapAsync(SavePointMapRequest request)
{
await _pointMapService.SaveAsync(request);
}
/// <summary>
/// 删除点位图
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("{id}")]
public async Task DeletePointMapAsync(long id)
{
await _pointMapService.DeleteAsync(id);
}
/// <summary>
/// 点位数据明细保存
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost("detail/save")]
public async Task SaveDetailAsync(SavePointMapDetailRequest request)
{
await _pointMapDetailService.SaveAsync(request);
}
/// <summary>
/// 点位数据明细
/// </summary>
/// <param name="pointMapCode"></param>
/// <returns></returns>
[HttpGet("detail/list")]
public async Task<List<PointMapDetailResponse>> GetDetailListByPointMapCodeAsync([FromQuery] Guid pointMapCode)
{
return await _pointMapDetailService.GetListByPointMapCodeAsync(pointMapCode);
}
/// <summary>
/// 删除点位数据明细
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpDelete("detail/{id}")]
public async Task DeleteDetailAsync(long id)
{
await _pointMapDetailService.DeleteAsync(id);
}
}

View File

@@ -0,0 +1,38 @@
using Dlhis.Entity.Basic.Enums;
using System.ComponentModel.DataAnnotations;
namespace Dlhis.Basic.Map.Request;
public class SavePointMapDetailRequest
{
public long? Id { get; set; }
/// <summary>
/// 点位图code
/// </summary>
[Required]
public Guid PointMapCode { get; set; }
/// <summary>
/// 数据code 如果是设备那么为设备code
/// </summary>
[Required]
public Guid UniqueCode { get; set; }
/// <summary>
/// 数据类型 PointMapDetailEnumType
/// </summary>
[EnumDataType(typeof(PointMapDetailEnumType))]
public PointMapDetailEnumType Type { get; set; }
/// <summary>
/// XYZ
/// </summary>
[Required]
public string Position { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
}

View File

@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations;
namespace Dlhis.Basic.Map.Request;
public class SavePointMapRequest
{
public long? Id { get; set; }
/// <summary>
/// 位置名称
/// </summary>
[Required(ErrorMessage = "位置名称不可为空")]
public string Name { get; set; }
/// <summary>
/// 图
/// </summary>
[Required(ErrorMessage = "图片不可为空")]
public string ImageUrl { get; set; }
public string Remark { get; set; }
}

View File

@@ -0,0 +1,26 @@
using Dlhis.Entity.Basic.Enums;
namespace Dlhis.Basic.Map.Response;
public class PointMapDetailResponse
{
/// <summary>
/// 数据code
/// </summary>
public Guid UniqueCode { get; set; }
/// <summary>
/// 数据类型
/// </summary>
public PointMapDetailEnumType Type { get; set; }
/// <summary>
/// XYZ
/// </summary>
public string Position { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
}

View File

@@ -0,0 +1,23 @@
using SqlSugar;
namespace Dlhis.Basic.Map.Response;
public class PointMapResponse
{
public long Id { get; set; }
public Guid Code { get; set; }
/// <summary>
/// 位置名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 图
/// </summary>
public string ImageUrl { get; set; }
public string Remark { get; set; }
}

View File

@@ -0,0 +1,13 @@
using Dlhis.Basic.Map.Request;
using Dlhis.Basic.Map.Response;
namespace Dlhis.Basic.Map.Services;
public interface IPointMapDetailService : IScopeDependency
{
Task SaveAsync(SavePointMapDetailRequest request);
Task DeleteAsync(long id);
Task<List<PointMapDetailResponse>> GetListByPointMapCodeAsync(Guid pointMapCode);
}

View File

@@ -0,0 +1,14 @@
using Dlhis.Basic.Map.Request;
using Dlhis.Basic.Map.Response;
using Kurisu.Core.DataAccess.Dto;
namespace Dlhis.Basic.Map.Services;
public interface IPointMapService : IScopeDependency
{
Task<Pagination<PointMapResponse>> GetPageAsync(PageDto request);
Task SaveAsync(SavePointMapRequest request);
Task DeleteAsync(long id);
}

View File

@@ -0,0 +1,45 @@
using Dlhis.Basic.Map.Request;
using Dlhis.Basic.Map.Response;
using Dlhis.Entity.Basic.Entity;
using Kurisu.SqlSugar.Services;
using Mapster;
namespace Dlhis.Basic.Map.Services.Implements;
public class PointMapDetailService : IPointMapDetailService
{
private readonly IDbContext _dbContext;
public PointMapDetailService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task SaveAsync(SavePointMapDetailRequest request)
{
if (!request.Id.HasValue)
{
var entity = request.Adapt<PointMapDetailEntity>();
await _dbContext.InsertAsync(entity);
}
else
{
var entity = await _dbContext.Queryable<PointMapDetailEntity>().Where(x => x.Id == request.Id).SingleAsync();
request.Adapt(entity);
await _dbContext.UpdateAsync(entity);
}
}
public async Task DeleteAsync(long id)
{
await _dbContext.Deleteable<PointMapDetailEntity>().Where(x => x.Id == id).ExecuteCommandAsync();
}
public async Task<List<PointMapDetailResponse>> GetListByPointMapCodeAsync(Guid pointMapCode)
{
return await _dbContext.Queryable<PointMapDetailEntity>()
.Where(x => x.PointMapCode == pointMapCode)
.Select<PointMapDetailResponse>()
.ToListAsync();
}
}

View File

@@ -0,0 +1,56 @@
using Dlhis.Basic.Map.Request;
using Dlhis.Basic.Map.Response;
using Dlhis.Entity.Basic.Entity;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
using Mapster;
namespace Dlhis.Basic.Map.Services.Implements;
public class PointMapService : IPointMapService
{
private readonly IDbContext _dbContext;
public PointMapService(IDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<Pagination<PointMapResponse>> GetPageAsync(PageDto request)
{
return await _dbContext.Queryable<PointMapEntity>()
.Select<PointMapResponse>()
.ToPageListAsync(request);
}
public async Task SaveAsync(SavePointMapRequest request)
{
if (!request.Id.HasValue)
{
var entity = request.Adapt<PointMapEntity>();
entity.Code = Guid.NewGuid();
await _dbContext.InsertAsync(entity);
}
else
{
var entity = await _dbContext.Queryable<PointMapEntity>().Where(x => x.Id == request.Id).SingleAsync();
entity.ThrowIfNull("点位图不存在,无法编辑!");
request.Adapt(entity);
await _dbContext.UpdateAsync(entity);
}
}
public async Task DeleteAsync(long id)
{
var entity = await _dbContext.Queryable<PointMapEntity>().Where(x => x.Id == id).SingleAsync();
if (entity != null)
{
await _dbContext.Deleteable<PointMapEntity>().Where(x => x.Id == id).ExecuteCommandAsync();
await _dbContext.Deleteable<PointMapDetailEntity>().Where(x => x.PointMapCode == entity.Code).ExecuteCommandAsync();
}
}
}

View File

@@ -1,6 +1,4 @@
using Dlhis.Entity.Basic.Enums;
using SqlSugar.DbConvert;
using SqlSugar;
using Kurisu.AspNetCore.Utils.Extensions;
namespace Dlhis.Canteen.MealSupplementRecord.Response;

View File

@@ -0,0 +1,44 @@
using Dlhis.Entity.Basic.Enums;
using Kurisu.Core.DataAccess.Entity;
using Kurisu.SqlSugar;
using SqlSugar;
using SqlSugar.DbConvert;
namespace Dlhis.Entity.Basic.Entity;
/// <summary>
/// 点位图数据
/// </summary>
[SugarTable(TableName = "PointMapDetail", TableDescription = "点位图数据")]
public class PointMapDetailEntity : SugarBaseEntity, ITenantId
{
/// <summary>
/// 点位图code
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "点位图code")]
public Guid PointMapCode { get; set; }
/// <summary>
/// 数据code
/// </summary>
public Guid UniqueCode { get; set; }
/// <summary>
/// 数据类型
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "数据类型", ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))]
public PointMapDetailEnumType Type { get; set; }
/// <summary>
/// XYZ
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "XYZ")]
public string Position { get; set; }
/// <summary>
/// 备注
/// </summary>
public string Remark { get; set; }
public string TenantId { get; set; }
}

View File

@@ -0,0 +1,36 @@
using Kurisu.Core.DataAccess.Entity;
using Kurisu.SqlSugar;
using SqlSugar;
namespace Dlhis.Entity.Basic.Entity;
/// <summary>
/// 点位图
/// </summary>
[SugarTable(TableName = "PointMaps", TableDescription = "点位图")]
public class PointMapEntity : SugarBaseEntity, ITenantId, IImageUrl
{
/// <summary>
/// code
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "code")]
public Guid Code { get; set; }
/// <summary>
/// 位置名称
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "点位名称")]
public string Name { get; set; }
/// <summary>
/// 图
/// </summary>
[SugarColumn(IsNullable = false, ColumnDescription = "图片地址")]
public string ImageUrl { get; set; }
[SugarColumn(ColumnDescription = "备注")]
public string Remark { get; set; }
public string TenantId { get; set; }
}

View File

@@ -0,0 +1,16 @@
using System.ComponentModel;
namespace Dlhis.Entity.Basic.Enums;
/// <summary>
/// 点位图数据类型
/// </summary>
[Description("点位图数据类型")]
public enum PointMapDetailEnumType
{
/// <summary>
/// 设备
/// </summary>
[Description("设备")]
Device = 1,
}