添加项目文件。

This commit is contained in:
2026-10-12 16:22:04 +08:00
parent 7c68a0ca0a
commit aad11be43d
1000 changed files with 120807 additions and 0 deletions
@@ -0,0 +1,64 @@
using AdminService.ImageUpload;
using Common;
using CommonInfrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AdminApi.Controllers
{
[Route("adminapi/[controller]")]
[ApiController]
public class ImageUploadController : BaseController
{
private readonly IImageUploadService _imageUploadService;
public ImageUploadController(IImageUploadService imageUploadService)
{
_imageUploadService = imageUploadService;
}
[HttpPost("upload")]
public async Task<IActionResult> UploadFile(IFormFile file, [FromQuery] string? name = null)
{
if (string.IsNullOrWhiteSpace(name))
name = Request.Form["name"].FirstOrDefault();
var result = await _imageUploadService.UploadImageAsync(file, name);
return result.isOk
? Json(this.ToResult(new { path = result.path, fileName = result.fileName }))
: Json(this.ToFailResult<object>(result.errorMessage));
}
[HttpPost("upload/temp")]
public async Task<IActionResult> UploadTempFile(IFormFile file)
{
var result = await _imageUploadService.UploadImageAsync(file);
return result.isOk
? Json(this.ToResult(new { path = result.path, fileName = result.fileName }))
: Json(this.ToFailResult<object>(result.errorMessage));
}
[HttpPost("upload/config")]
public async Task<IActionResult> UploadConfigFile(IFormFile file, [FromQuery] string? number = null)
{
if (!string.Equals(Path.GetExtension(file?.FileName), ".png", StringComparison.OrdinalIgnoreCase))
return Json(this.ToFailResult<object>("配置图片必须是 PNG 格式"));
if (string.IsNullOrWhiteSpace(number))
number = Request.Form["number"].FirstOrDefault();
number = number?.Trim();
if (string.IsNullOrWhiteSpace(number)
|| number != Path.GetFileName(number)
|| number.Any(c => !char.IsLetterOrDigit(c) && c != '_' && c != '-'))
{
return Json(this.ToFailResult<object>("图片编号无效"));
}
var result = await _imageUploadService.UploadImageAsync(file, number);
return result.isOk
? Json(this.ToResult(new { path = result.path, fileName = result.fileName, number }))
: Json(this.ToFailResult<object>(result.errorMessage));
}
}
}
@@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AdminService.Admin;
using Common;
using CommonInfrastructure;
using Domain.Admin.Admin;
using Domain.Admin.Admin.ENum;
using Domain.Admin.Admin.Param;
using Microsoft.AspNetCore.Mvc;
using MongoRepository;
namespace AdminApi.Controllers
{
[Route("adminapi/[controller]")]
[ApiController]
public class OperationLogController : BaseController
{
private readonly IAdminOperationLogService _operationLogService;
private readonly IMongoBaseRepository<SystemUser> _systemUserRepo;
private readonly IMongoBaseRepository<AdminOperationLog> _logRepo;
public OperationLogController(IAdminOperationLogService operationLogService, IMongoBaseRepository<SystemUser> systemUserRepo, IMongoBaseRepository<AdminOperationLog> logRepo)
{
_operationLogService = operationLogService;
_systemUserRepo = systemUserRepo;
_logRepo = logRepo;
}
[HttpPost("list")]
public async Task<PageResponse<OperationLogDto>> GetList([FromBody] OperationLogQueryParam param)
{
var (list, count) = await _operationLogService.QueryPage(param);
if (list == null)
return this.ToPageResult(new List<OperationLogDto>(), 0);
var dtos = list.Select(MapToDto);
return this.ToPageResult(dtos, (int)count);
}
[HttpGet("admins")]
public async Task<BaseResponse<List<AdminOptionDto>>> GetAdmins()
{
var users = await _systemUserRepo.FilterByAsync(x => x.State == 1);
var result = users.Select(x => new AdminOptionDto { Value = x.Id, Label = x.DisplayName }).ToList();
return this.ToResult(result);
}
[HttpGet("modules")]
public BaseResponse<List<ModuleOptionDto>> GetModules()
{
var modules = Enum.GetValues<EnumOperationModule>()
.Select(x => new ModuleOptionDto { Value = (int)x, Label = ((int)x).ToString() })
.ToList();
return this.ToResult(modules);
}
[HttpPost("Delete")]
public async Task<BaseResponse<string>> Delete(string id)
{
var result = await _logRepo.DeleteByIdAsync(id);
if (result.ok)
return this.ToResult("删除成功");
else
return this.ToFailResult<string>("删除失败");
}
[HttpPost("BatchDelete")]
public async Task<BaseResponse<string>> BatchDelete([FromBody] List<string> ids)
{
int success = 0, fail = 0;
foreach (var id in ids)
{
var result = await _logRepo.DeleteByIdAsync(id);
if (result.ok)
success++;
else
fail++;
}
if (fail == 0)
return this.ToResult($"成功删除 {success} 条");
return this.ToResult($"删除完成:成功 {success} 条,失败 {fail} 条");
}
private static OperationLogDto MapToDto(AdminOperationLog entity)
{
return new OperationLogDto
{
Id = entity.Id,
AdminId = entity.AdminId ?? "",
AdminName = entity.AdminName ?? "",
Module = entity.Module,
ActionType = entity.ActionType ?? "",
Description = entity.Description ?? "",
HttpMethod = entity.HttpMethod ?? "",
RequestPath = entity.RequestPath ?? "",
Ip = entity.Ip ?? "",
Status = entity.Status,
OperateTime = entity.OperateTime
};
}
}
public class OperationLogDto
{
public string Id { get; set; }
public string AdminId { get; set; }
public string AdminName { get; set; }
public int Module { get; set; }
public string ActionType { get; set; }
public string Description { get; set; }
public string HttpMethod { get; set; }
public string RequestPath { get; set; }
public string Ip { get; set; }
public int Status { get; set; }
public DateTime OperateTime { get; set; }
}
public class AdminOptionDto
{
public string Value { get; set; }
public string Label { get; set; }
}
public class ModuleOptionDto
{
public int Value { get; set; }
public string Label { get; set; }
}
}