Learn.Archives/Learn.Archives.API/Controllers/PublicController.cs

81 lines
2.7 KiB
C#

using Learn.Archives.API.Controllers.Dto;
using Learn.Archives.API.Expand;
using Learn.Archives.Core.Common;
using Learn.Archives.Core.Model;
using Learn.Archives.Core.Model.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using System.Security.Claims;
using UserCenter.Model;
namespace Learn.Archives.API.Controllers
{
/// <summary>
/// 通用接口
/// </summary>
[Authorize(AuthenticationSchemes = Authentication.Admin)]
[Route("api/[controller]")]
public class PublicController : Controller
{
private readonly IHostEnvironment _environment;
public PublicController(Repository<School> baseService, IHostEnvironment environment)
{
_environment = environment;
}
/// <summary>
/// App.EntityDto.Enum 枚举转下拉列表
/// </summary>
/// <param name="type">枚举名称 例子type='ExamStatusEnum'</param>
/// <returns></returns>
[HttpGet, Route("enum/{type}")]
[ResponseCache(Duration = 5)]
public List<ComboModel> GetExamStatusData(string type)
{
if (!AppCommon.EnumType.ContainsKey(type))
Oh.Error("无效类型");
return Enum.GetValues(AppCommon.EnumType[type]).Cast<object>()
.Select(enumValue => new ComboModel() { Text = enumValue.ToString(), Value = (int)enumValue }).ToList();
}
/// <summary>
/// App.EntityDto.Enum 枚举转下拉列表
/// </summary>
/// <param name="type">枚举名称 例子type='ExamStatusEnum'</param>
/// <returns></returns>
[HttpGet, Route("enum/{type}/Dic")]
[ResponseCache(Duration = 5)]
public Dictionary<int, string?> GetExamStatusDictionary(string type)
{
if (!AppCommon.EnumType.ContainsKey(type))
Oh.Error("无效类型");
return Enum.GetValues(AppCommon.EnumType[type]).Cast<object>()
.ToDictionary(s => (int)s, s => s.ToString());
}
/// <summary>
/// 获取当前环境变量,配置文件
/// </summary>
/// <returns></returns>
[HttpGet]
public IActionResult NewENV()
{
var envName = _environment.EnvironmentName;
var env = "无配置";
if (_environment.IsDevelopment())
env = "开发环境";
else if (_environment.IsStaging())
env = "测试/预发布环境";
else if (_environment.IsProduction())
env = "生产环境";
return Ok(new
{
envName,
env,
AppCommon.Config
});
}
}
}