init 项目代码初始化
This commit is contained in:
69
Src/Dlhis.Canteen/Setting/Controllers/SettingController.cs
Normal file
69
Src/Dlhis.Canteen/Setting/Controllers/SettingController.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Dlhis.Canteen.Setting.Request;
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
using Dlhis.Canteen.Setting.Services;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// 就餐配置
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class SettingController : ControllerBase
|
||||
{
|
||||
private readonly ICanteenSettingService _settingService;
|
||||
|
||||
public SettingController(ICanteenSettingService settingService)
|
||||
{
|
||||
_settingService = settingService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("page")]
|
||||
public async Task<Pagination<CanteenSettingResponse>> GetPageAsync([FromQuery] CanteenSettingPageRequest request)
|
||||
{
|
||||
return await _settingService.GetPageAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置保存
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("save")]
|
||||
public async Task SaveSettingAsync(CanteenSettingSaveRequest request)
|
||||
{
|
||||
await _settingService.SaveSettingAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 配置启用状态
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("enable")]
|
||||
public async Task SetEnableAsync(CanteenSettingSetEnableRequest request)
|
||||
{
|
||||
await _settingService.SetEnableAsync(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户配置
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("user")]
|
||||
public async Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userId)
|
||||
{
|
||||
return await _settingService.GetUserSettingAsync(userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Request;
|
||||
|
||||
public class CanteenSettingPageRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置唯一类型 CanteenSettingUnqiueEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(CanteenSettingUnqiueEnumType))]
|
||||
public CanteenSettingUnqiueEnumType? UniqueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置项
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(CanteenSettingItemEnumType))]
|
||||
public CanteenSettingItemEnumType? Item { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Request;
|
||||
|
||||
public class CanteenSettingSaveRequest
|
||||
{
|
||||
public long? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置生效范围
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(CanteenSettingUnqiueEnumType))]
|
||||
public CanteenSettingUnqiueEnumType UniqueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一值 eg:UniqueType = 1时,传入非空字符串
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "值不能为空")]
|
||||
public string UniqueValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义分类分类
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "分类不能为空")]
|
||||
public string Catalog { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数 CanteenSettingItemEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(CanteenSettingItemEnumType))]
|
||||
public CanteenSettingItemEnumType Item { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace Dlhis.Canteen.Setting.Request
|
||||
{
|
||||
public class CanteenSettingSetEnableRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
}
|
||||
41
Src/Dlhis.Canteen/Setting/Response/CanteenSettingResponse.cs
Normal file
41
Src/Dlhis.Canteen/Setting/Response/CanteenSettingResponse.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Response;
|
||||
|
||||
public class CanteenSettingResponse
|
||||
{
|
||||
public CanteenSettingUnqiueEnumType UniqueType { get; set; }
|
||||
public string UniqueTypeDesc => UniqueType.GetDescription();
|
||||
|
||||
/// <summary>
|
||||
/// 唯一值
|
||||
/// </summary>
|
||||
public string UniqueValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一值说明
|
||||
/// </summary>
|
||||
public string UniqueValueDesc { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分类
|
||||
/// </summary>
|
||||
public string Catalog { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数
|
||||
/// </summary>
|
||||
public CanteenSettingItemEnumType Item { get; set; }
|
||||
public string ItemDesc => Item.GetDescription();
|
||||
|
||||
/// <summary>
|
||||
/// 值
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用
|
||||
/// </summary>
|
||||
public bool Enable { get; set; }
|
||||
}
|
||||
23
Src/Dlhis.Canteen/Setting/Services/ICanteenSettingService.cs
Normal file
23
Src/Dlhis.Canteen/Setting/Services/ICanteenSettingService.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Dlhis.Canteen.Setting.Request;
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Services;
|
||||
|
||||
public interface ICanteenSettingService : IScopeDependency
|
||||
{
|
||||
Task<Pagination<CanteenSettingResponse>> GetPageAsync(CanteenSettingPageRequest request);
|
||||
|
||||
Task SaveSettingAsync(CanteenSettingSaveRequest request);
|
||||
|
||||
Task SetEnableAsync(CanteenSettingSetEnableRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 获取人员的就餐配置信息
|
||||
/// </summary>
|
||||
/// <param name="userId">就餐人员档案号</param>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
using Dlhis.Canteen.Setting.Request;
|
||||
using Dlhis.Canteen.Setting.Response;
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Canteen.Setting.Services.Implements;
|
||||
|
||||
/// <summary>
|
||||
/// 餐饮配置
|
||||
/// </summary>
|
||||
public class CanteenSettingService : ICanteenSettingService
|
||||
{
|
||||
private readonly IDbContext _context;
|
||||
|
||||
public CanteenSettingService(IDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Pagination<CanteenSettingResponse>> GetPageAsync(CanteenSettingPageRequest request)
|
||||
{
|
||||
var page = await _context.Queryable<CanteenSettingEntity>()
|
||||
.LeftJoin<CanteenUserEntity>((setting, user) => setting.UniqueValue == user.UserId)
|
||||
.WhereIF(request.UniqueType.HasValue, setting => setting.UniqueType == request.UniqueType)
|
||||
.WhereIF(request.Item.HasValue, setting => setting.Item == request.Item)
|
||||
.WhereIF(request.Search.IsPresent(), setting => setting.UniqueValue.Contains(request.Search))
|
||||
.Select((setting, user) => new CanteenSettingResponse
|
||||
{
|
||||
UniqueType = setting.UniqueType,
|
||||
UniqueValue = setting.UniqueValue,
|
||||
//UniqueValueDesc = user.UserName,
|
||||
Catalog = setting.Catalog,
|
||||
Enable = setting.Enable,
|
||||
Item = setting.Item,
|
||||
Value = setting.Value
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task SaveSettingAsync(CanteenSettingSaveRequest request)
|
||||
{
|
||||
await CheckDuplicateSettingAsync(request);
|
||||
|
||||
if (!request.Id.HasValue)
|
||||
{
|
||||
var entity = request.Adapt<CanteenSettingEntity>();
|
||||
await _context.InsertAsync(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _context.Queryable<CanteenSettingEntity>().FirstAsync(x => x.Id == request.Id);
|
||||
request.Adapt(entity);
|
||||
|
||||
await _context.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SetEnableAsync(CanteenSettingSetEnableRequest request)
|
||||
{
|
||||
var entity = await _context.Queryable<CanteenSettingEntity>().FirstAsync(x => x.Id == request.Id);
|
||||
entity.ThrowIfNull("配置不存在,无法修改状态");
|
||||
|
||||
entity.Enable = request.Enable;
|
||||
await _context.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
|
||||
public async Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userId)
|
||||
{
|
||||
var setting = await _context.Queryable<CanteenSettingEntity>()
|
||||
.Where(x => x.UniqueType == CanteenSettingUnqiueEnumType.Person && (x.UniqueValue == userId) || x.UniqueType == CanteenSettingUnqiueEnumType.Tenant)
|
||||
.ToListAsync();
|
||||
|
||||
//从基地 -> 个人,确保下面循环做到覆盖,并且以个人配置为主
|
||||
setting = setting.OrderBy(x => x.UniqueType).ToList();
|
||||
|
||||
var result = new Dictionary<CanteenSettingItemEnumType, string>();
|
||||
setting.ForEach(x =>
|
||||
{
|
||||
if (result.ContainsKey(x.Item))
|
||||
{
|
||||
result[x.Item] = x.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(x.Item, x.Value);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//*********************************************** help methods ***************************************************//
|
||||
|
||||
private async Task CheckDuplicateSettingAsync(CanteenSettingSaveRequest request)
|
||||
{
|
||||
//Tenant只有一条数据, Person对应UniqueValue唯一 , Catalog不作为唯一判断
|
||||
|
||||
var exists = await _context.Queryable<CanteenSettingEntity>()
|
||||
.Where(x => x.UniqueType == request.UniqueType)
|
||||
.Where(x => x.Catalog == request.Catalog)
|
||||
.Where(x => x.Item == request.Item)
|
||||
.WhereIF(request.UniqueType != CanteenSettingUnqiueEnumType.Tenant, x => x.UniqueValue == request.UniqueValue)
|
||||
.WhereIF(request.Id.HasValue, x => x.Id != request.Id)
|
||||
.AnyAsync();
|
||||
|
||||
exists.ThrowIfTrue("配置项重复,请检查.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user