v 1.0.7
新增软件授权和数据信息
This commit is contained in:
parent
a37c40a2ef
commit
61c4e0f977
10
LMS.Common/Enums/DataInfoEnum.cs
Normal file
10
LMS.Common/Enums/DataInfoEnum.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using LMS.Common.Attributes;
|
||||
|
||||
namespace LMS.Common.Enums
|
||||
{
|
||||
public enum DataInfoTypeEnum
|
||||
{
|
||||
[Description("Discord")]
|
||||
Discord = 0,
|
||||
}
|
||||
}
|
||||
10
LMS.Common/Enums/MachineAuthorizationEnum.cs
Normal file
10
LMS.Common/Enums/MachineAuthorizationEnum.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace LMS.Common.Enums
|
||||
{
|
||||
public enum MachineAuthorizationEnum
|
||||
{
|
||||
[Description("NanFengAI")]
|
||||
NanFengAI = 0,
|
||||
}
|
||||
}
|
||||
@ -41,6 +41,10 @@ namespace LMS.DAO
|
||||
|
||||
public DbSet<SoftwareControl> SoftwareControl { get; set; }
|
||||
|
||||
public DbSet<MachineAuthorization> MachineAuthorization { get; set; }
|
||||
|
||||
public DbSet<DataInfo> DataInfo { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
30
LMS.Repository/DB/DataInfo.cs
Normal file
30
LMS.Repository/DB/DataInfo.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using LMS.Common.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.DB
|
||||
{
|
||||
public class DataInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string ID { get; set; }
|
||||
/// <summary>
|
||||
/// 数据的类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required DataInfoTypeEnum Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据的字符串
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string DataString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreatedTime { get; set; }
|
||||
}
|
||||
}
|
||||
64
LMS.Repository/DB/MachineAuthorization.cs
Normal file
64
LMS.Repository/DB/MachineAuthorization.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using LMS.Common.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.DB
|
||||
{
|
||||
public class MachineAuthorization
|
||||
{
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 机器码或者是授权码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string MachineID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权软件类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required MachineAuthorizationEnum Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime AuthorizedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过期日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime ExpiryDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string AuthorizationCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户ID
|
||||
/// </summary>
|
||||
public long CreatedUserID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户ID
|
||||
/// </summary>
|
||||
public long UpdatedUserID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
public DateTime UpdatedDate { get; set; }
|
||||
}
|
||||
}
|
||||
66
LMS.Repository/DTO/OtherDto/MachineAuthorizationDto.cs
Normal file
66
LMS.Repository/DTO/OtherDto/MachineAuthorizationDto.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using LMS.Common.Enums;
|
||||
using LMS.Repository.DTO.UserDto;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.DTO.OtherDto
|
||||
{
|
||||
public class MachineAuthorizationDto
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// ID
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string ID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 机器码或者是授权码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string MachineID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权软件类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required MachineAuthorizationEnum Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime AuthorizedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过期日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime ExpiryDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string AuthorizationCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建用户
|
||||
/// </summary>
|
||||
public UserBaseDto? CreatedUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户ID
|
||||
/// </summary>
|
||||
public UserBaseDto? UpdatedUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
public DateTime UpdatedDate { get; set; }
|
||||
}
|
||||
}
|
||||
20
LMS.Repository/Other/AddDataInfo.cs
Normal file
20
LMS.Repository/Other/AddDataInfo.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using LMS.Common.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.Other
|
||||
{
|
||||
public class AddDataInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据的类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required DataInfoTypeEnum Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据的字符串
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string DataString { get; set; }
|
||||
}
|
||||
}
|
||||
38
LMS.Repository/Other/AddMachineAuthorization.cs
Normal file
38
LMS.Repository/Other/AddMachineAuthorization.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using LMS.Common.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace LMS.Repository.Other
|
||||
{
|
||||
public class AddMachineAuthorization
|
||||
{
|
||||
/// <summary>
|
||||
/// 机器码或者是授权码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string MachineID { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime AuthorizedDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 过期日期
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTime ExpiryDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权码
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required string AuthorizationCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 授权软件类型
|
||||
/// </summary>
|
||||
[Required]
|
||||
public required MachineAuthorizationEnum Type { get; set; }
|
||||
}
|
||||
}
|
||||
@ -46,7 +46,7 @@ namespace LMS.service.Configuration
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(jobKey)
|
||||
.WithIdentity("MonthlyTaskTrigger", "DefaultGroup")
|
||||
.WithCronSchedule("0 0 18 24 * ?")); // 每月1号凌晨0点
|
||||
.WithCronSchedule("0 0 0 1 * ?")); // 每月1号凌晨0点
|
||||
});
|
||||
|
||||
// 添加 Quartz 托管服务
|
||||
|
||||
@ -5,6 +5,7 @@ using LMS.DAO.UserDAO;
|
||||
using LMS.service.Configuration.InitConfiguration;
|
||||
using LMS.service.Extensions.Mail;
|
||||
using LMS.service.Service;
|
||||
using LMS.service.Service.Other;
|
||||
using LMS.service.Service.PermissionService;
|
||||
using LMS.service.Service.PromptService;
|
||||
using LMS.service.Service.RoleService;
|
||||
@ -35,8 +36,8 @@ namespace Lai_server.Configuration
|
||||
services.AddScoped<ForwardWordService>();
|
||||
services.AddScoped<SoftwareControlService>();
|
||||
services.AddScoped<SoftwareService>();
|
||||
|
||||
|
||||
services.AddScoped<MachineAuthorizationService>();
|
||||
services.AddScoped<DataInfoService>();
|
||||
|
||||
// 注入 DAO
|
||||
services.AddScoped<UserBasicDao>();
|
||||
|
||||
132
LMS.service/Controllers/OtherController.cs
Normal file
132
LMS.service/Controllers/OtherController.cs
Normal file
@ -0,0 +1,132 @@
|
||||
using LMS.Common.Extensions;
|
||||
using LMS.Repository.DB;
|
||||
using LMS.Repository.DTO;
|
||||
using LMS.Repository.DTO.OtherDto;
|
||||
using LMS.Repository.Other;
|
||||
using LMS.service.Service.Other;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using static LMS.Common.Enums.ResponseCodeEnum;
|
||||
|
||||
namespace LMS.service.Controllers
|
||||
{
|
||||
[Route("lms/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class OtherController(MachineAuthorizationService machineAuthorizationService, DataInfoService dataInfoService) : Controller
|
||||
{
|
||||
private readonly MachineAuthorizationService _machineAuthorizationService = machineAuthorizationService;
|
||||
private readonly DataInfoService _dataInfoService = dataInfoService;
|
||||
|
||||
#region 新增机器码/指定授权码
|
||||
|
||||
/// <summary>
|
||||
/// 新增机器码/指定授权码
|
||||
/// </summary>
|
||||
/// <param name="addMachineAuthorization"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<object>>> AddMachineAuthorization(AddMachineAuthorization addMachineAuthorization)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
||||
}
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _machineAuthorizationService.AddMachineAuthorization(addMachineAuthorization, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 修改机器码/指定授权码
|
||||
[HttpPost("{id}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<object>>> ModifyMachineAuthorization(string id, AddMachineAuthorization addMachineAuthorization)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
||||
}
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _machineAuthorizationService.ModifyMachineAuthorization(id, addMachineAuthorization, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取指定的机器授权码
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<MachineAuthorizationDto>>> GetMachineAuthorization(string id)
|
||||
{
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _machineAuthorizationService.GetMachineAuthorization(id, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取指定的机器码授权码列表
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<CollectionResponse<MachineAuthorizationDto>>>> QueryMachineAuthorizationCollection([Required] int page, [Required] int pageSize, string? machineId, string? AuthorizationCode, int? type)
|
||||
{
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _machineAuthorizationService.QueryMachineAuthorizationCollection(page, pageSize, machineId, AuthorizationCode, type, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除指定的机器码授权码
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<object>>> DeleteMachineAuthorization(string id)
|
||||
{
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _machineAuthorizationService.DeleteMachineAuthorization(id, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 新增数据信息
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<APIResponseModel<object>>> AddDataInfo(AddDataInfo addDataInfo)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError);
|
||||
}
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _dataInfoService.AddDataInfo(addDataInfo);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 查询指定类型的数据信息
|
||||
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<CollectionResponse<DataInfo>>>> QueryDataInfoCollection([Required] int page, [Required] int pageSize, int? type)
|
||||
{
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _dataInfoService.QueryDataInfoCollection(page, pageSize, type, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除指定的数据信息
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[Authorize]
|
||||
public async Task<ActionResult<APIResponseModel<object>>> DeleteDataInfo(string id)
|
||||
{
|
||||
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
|
||||
return await _dataInfoService.DeleteDataInfo(id, userId);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
141
LMS.service/Service/Other/DataInfoService.cs
Normal file
141
LMS.service/Service/Other/DataInfoService.cs
Normal file
@ -0,0 +1,141 @@
|
||||
using LMS.Common.Enums;
|
||||
using LMS.Common.Extensions;
|
||||
using LMS.DAO;
|
||||
using LMS.DAO.UserDAO;
|
||||
using LMS.Repository.DB;
|
||||
using LMS.Repository.DTO;
|
||||
using LMS.Repository.DTO.UserDto;
|
||||
using LMS.Repository.Other;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using static LMS.Common.Enums.ResponseCodeEnum;
|
||||
|
||||
namespace LMS.service.Service.Other
|
||||
{
|
||||
public class DataInfoService(ApplicationDbContext dbContext, UserBasicDao userBasicDao)
|
||||
{
|
||||
private readonly ApplicationDbContext _context = dbContext;
|
||||
private readonly UserBasicDao _userBasicDao = userBasicDao;
|
||||
|
||||
#region 新增数据信息
|
||||
/// <summary>
|
||||
/// 新增数据信息
|
||||
/// </summary>
|
||||
/// <param name="addDataInfo"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult<APIResponseModel<object>>> AddDataInfo(AddDataInfo addDataInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 判断类型是不是存在
|
||||
if (!Enum.IsDefined(typeof(DataInfoTypeEnum), addDataInfo.Type))
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError, "授权类型不存在");
|
||||
}
|
||||
// 直接开始添加
|
||||
DataInfo dataInfo = new DataInfo
|
||||
{
|
||||
ID = Guid.NewGuid().ToString(),
|
||||
Type = addDataInfo.Type,
|
||||
DataString = addDataInfo.DataString,
|
||||
CreatedTime = BeijingTimeExtension.GetBeijingTime()
|
||||
};
|
||||
await _context.DataInfo.AddAsync(dataInfo);
|
||||
await _context.SaveChangesAsync();
|
||||
return APIResponseModel<object>.CreateSuccessResponseModel("数据新增成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取数据信息
|
||||
/// <summary>
|
||||
/// 获取数据信息
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="requestUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult<APIResponseModel<CollectionResponse<DataInfo>>>> QueryDataInfoCollection(int page, int pageSize, int? type, long requestUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(requestUserId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<CollectionResponse<DataInfo>>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
|
||||
IQueryable<DataInfo> query = _context.DataInfo;
|
||||
|
||||
if (type.HasValue)
|
||||
{
|
||||
query = query.Where(x => x.Type == (DataInfoTypeEnum)type);
|
||||
}
|
||||
|
||||
// 总数
|
||||
int total = await query.CountAsync();
|
||||
|
||||
// 分页
|
||||
query = query.OrderByDescending(x => x.CreatedTime).Skip((page - 1) * pageSize).Take(pageSize);
|
||||
|
||||
List<DataInfo> dataInfos = await query.ToListAsync();
|
||||
|
||||
CollectionResponse<DataInfo> collectionResponse = new CollectionResponse<DataInfo>
|
||||
{
|
||||
Total = total,
|
||||
Collection = dataInfos,
|
||||
Current = page,
|
||||
};
|
||||
return APIResponseModel<CollectionResponse<DataInfo>>.CreateSuccessResponseModel(collectionResponse);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<CollectionResponse<DataInfo>>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除指定的数据信息
|
||||
/// <summary>
|
||||
/// 删除指定的数据信息
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult<APIResponseModel<object>>> DeleteDataInfo(string id, long userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(userId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
|
||||
DataInfo? dataInfo = await _context.DataInfo.FirstOrDefaultAsync(x => x.ID == id);
|
||||
if (dataInfo == null)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.IdDateNotFound);
|
||||
}
|
||||
|
||||
_context.DataInfo.Remove(dataInfo);
|
||||
await _context.SaveChangesAsync();
|
||||
return APIResponseModel<object>.CreateSuccessResponseModel("删除成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
323
LMS.service/Service/Other/MachineAuthorizationService.cs
Normal file
323
LMS.service/Service/Other/MachineAuthorizationService.cs
Normal file
@ -0,0 +1,323 @@
|
||||
using AutoMapper;
|
||||
using LMS.Common.Enums;
|
||||
using LMS.Common.Extensions;
|
||||
using LMS.DAO;
|
||||
using LMS.DAO.UserDAO;
|
||||
using LMS.Repository.DB;
|
||||
using LMS.Repository.DTO;
|
||||
using LMS.Repository.DTO.OtherDto;
|
||||
using LMS.Repository.DTO.UserDto;
|
||||
using LMS.Repository.Models.DB;
|
||||
using LMS.Repository.Other;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using static LMS.Common.Enums.ResponseCodeEnum;
|
||||
|
||||
namespace LMS.service.Service.Other
|
||||
{
|
||||
public class MachineAuthorizationService(UserBasicDao userBasicDao, ApplicationDbContext dbContext, IMapper mapper)
|
||||
{
|
||||
private readonly UserBasicDao _userBasicDao = userBasicDao;
|
||||
private readonly ApplicationDbContext _dbContext = dbContext;
|
||||
private readonly IMapper _mapper = mapper;
|
||||
|
||||
|
||||
#region 新增机器码/指定授权码
|
||||
/// <summary>
|
||||
/// 新增机器码/指定授权码
|
||||
/// </summary>
|
||||
/// <param name="addMachineAuthorization"></param>
|
||||
/// <param name="requestUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult<APIResponseModel<object>>> AddMachineAuthorization(AddMachineAuthorization addMachineAuthorization, long requestUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(requestUserId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
|
||||
// 判断类型是不是存在
|
||||
if (!Enum.IsDefined(typeof(MachineAuthorizationEnum), addMachineAuthorization.Type))
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError, "授权类型不存在");
|
||||
}
|
||||
|
||||
// 判断相同的机器码和对应的类型的授权的是不是存在
|
||||
MachineAuthorization? machineAuthorizationExist = await _dbContext.MachineAuthorization.FirstOrDefaultAsync(x => x.MachineID == addMachineAuthorization.MachineID && x.Type == addMachineAuthorization.Type);
|
||||
if (machineAuthorizationExist != null)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError, "相同的机器码和对应的类型的授权已经存在");
|
||||
}
|
||||
|
||||
// 业务逻辑
|
||||
MachineAuthorization machineAuthorization = new MachineAuthorization
|
||||
{
|
||||
ID = Guid.NewGuid().ToString(),
|
||||
MachineID = addMachineAuthorization.MachineID,
|
||||
AuthorizationCode = addMachineAuthorization.AuthorizationCode,
|
||||
AuthorizedDate = addMachineAuthorization.AuthorizedDate,
|
||||
ExpiryDate = addMachineAuthorization.ExpiryDate,
|
||||
Type = addMachineAuthorization.Type,
|
||||
CreatedUserID = requestUserId,
|
||||
CreatedDate = BeijingTimeExtension.GetBeijingTime(),
|
||||
UpdatedUserID = requestUserId,
|
||||
UpdatedDate = BeijingTimeExtension.GetBeijingTime()
|
||||
};
|
||||
|
||||
await _dbContext.MachineAuthorization.AddAsync(machineAuthorization);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
return APIResponseModel<object>.CreateSuccessResponseModel("新增成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 修改机器码/指定授权码
|
||||
|
||||
/// <summary>
|
||||
/// 修改机器码/指定授权码
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="addMachineAuthorization"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<ActionResult<APIResponseModel<object>>> ModifyMachineAuthorization(string id, AddMachineAuthorization addMachineAuthorization, long userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(userId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
|
||||
// 判断类型是不是存在
|
||||
if (!Enum.IsDefined(typeof(MachineAuthorizationEnum), addMachineAuthorization.Type))
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError, "授权类型不存在");
|
||||
}
|
||||
|
||||
MachineAuthorization? machineAuthorization = await _dbContext.MachineAuthorization.FirstOrDefaultAsync(x => x.ID == id);
|
||||
if (machineAuthorization == null)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.IdDateNotFound);
|
||||
}
|
||||
|
||||
|
||||
// 排除对应的机器码和类型,排除自己
|
||||
MachineAuthorization? machineAuthorizationExist = await _dbContext.MachineAuthorization.FirstOrDefaultAsync(x => x.MachineID == addMachineAuthorization.MachineID && x.Type == addMachineAuthorization.Type && x.ID != id);
|
||||
if (machineAuthorizationExist != null)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.ParameterError, "相同的机器码和对应的类型的授权已经存在");
|
||||
}
|
||||
|
||||
// 开始修改
|
||||
machineAuthorization.MachineID = addMachineAuthorization.MachineID;
|
||||
machineAuthorization.AuthorizationCode = addMachineAuthorization.AuthorizationCode;
|
||||
machineAuthorization.Type = addMachineAuthorization.Type;
|
||||
machineAuthorization.UpdatedUserID = userId;
|
||||
machineAuthorization.UpdatedDate = BeijingTimeExtension.GetBeijingTime();
|
||||
machineAuthorization.AuthorizedDate = addMachineAuthorization.AuthorizedDate;
|
||||
machineAuthorization.ExpiryDate = addMachineAuthorization.ExpiryDate;
|
||||
|
||||
_dbContext.MachineAuthorization.Update(machineAuthorization);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return APIResponseModel<object>.CreateSuccessResponseModel("修改成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取指定的机器授权码
|
||||
/// <summary>
|
||||
/// 获取指定的机器授权码
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public async Task<ActionResult<APIResponseModel<MachineAuthorizationDto>>> GetMachineAuthorization(string id, long userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(userId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<MachineAuthorizationDto>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
MachineAuthorization? machineAuthorization = await _dbContext.MachineAuthorization.FirstOrDefaultAsync(x => x.ID == id);
|
||||
if (machineAuthorization == null)
|
||||
{
|
||||
return APIResponseModel<MachineAuthorizationDto>.CreateErrorResponseModel(ResponseCode.IdDateNotFound);
|
||||
}
|
||||
|
||||
User? createdUser = await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == machineAuthorization.CreatedUserID);
|
||||
User? updatedUser = await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == machineAuthorization.UpdatedUserID);
|
||||
UserBaseDto createdUserBasic = _mapper.Map<UserBaseDto>(createdUser);
|
||||
UserBaseDto updatedUserBasic = _mapper.Map<UserBaseDto>(updatedUser);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
createdUserBasic.HideContactInfo();
|
||||
updatedUserBasic.HideContactInfo();
|
||||
}
|
||||
MachineAuthorizationDto machineAuthorizationDto = new MachineAuthorizationDto
|
||||
{
|
||||
ID = machineAuthorization.ID,
|
||||
MachineID = machineAuthorization.MachineID,
|
||||
AuthorizationCode = machineAuthorization.AuthorizationCode,
|
||||
AuthorizedDate = machineAuthorization.AuthorizedDate,
|
||||
ExpiryDate = machineAuthorization.ExpiryDate,
|
||||
Type = machineAuthorization.Type,
|
||||
CreatedUser = createdUserBasic,
|
||||
CreatedDate = machineAuthorization.CreatedDate,
|
||||
UpdatedUser = updatedUserBasic,
|
||||
UpdatedDate = machineAuthorization.UpdatedDate
|
||||
};
|
||||
return APIResponseModel<MachineAuthorizationDto>.CreateSuccessResponseModel(ResponseCode.Success, machineAuthorizationDto);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<MachineAuthorizationDto>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取指定的机器码授权码列表
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定的机器码授权码列表
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="pageSize"></param>
|
||||
/// <param name="machineId"></param>
|
||||
/// <param name="authorizationCode"></param>
|
||||
/// <param name="requestUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult<APIResponseModel<CollectionResponse<MachineAuthorizationDto>>>> QueryMachineAuthorizationCollection(int page, int pageSize, string? machineId, string? authorizationCode, int? type, long requestUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(requestUserId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<CollectionResponse<MachineAuthorizationDto>>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
|
||||
IQueryable<MachineAuthorization> query = _dbContext.MachineAuthorization;
|
||||
if (!string.IsNullOrWhiteSpace(machineId))
|
||||
{
|
||||
query = query.Where(x => x.MachineID.Contains(machineId));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(authorizationCode))
|
||||
{
|
||||
query = query.Where(x => x.AuthorizationCode.Contains(authorizationCode));
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
query = query.Where(x => x.Type == (MachineAuthorizationEnum)type);
|
||||
}
|
||||
|
||||
// 总数
|
||||
int total = await query.CountAsync();
|
||||
|
||||
// 降序/分页
|
||||
List<MachineAuthorization> machineAuthorizations = await query.OrderByDescending(x => x.CreatedDate).Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
|
||||
|
||||
List<MachineAuthorizationDto> machineAuthorizationDtos = new List<MachineAuthorizationDto>();
|
||||
for (int i = 0; i < machineAuthorizations.Count; i++)
|
||||
{
|
||||
var machineAuthorization = machineAuthorizations[i];
|
||||
User? createdUser = await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == machineAuthorization.CreatedUserID);
|
||||
User? updatedUser = await _dbContext.Users.FirstOrDefaultAsync(x => x.Id == machineAuthorization.UpdatedUserID);
|
||||
UserBaseDto createdUserBasic = _mapper.Map<UserBaseDto>(createdUser);
|
||||
UserBaseDto updatedUserBasic = _mapper.Map<UserBaseDto>(updatedUser);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
createdUserBasic.HideContactInfo();
|
||||
updatedUserBasic.HideContactInfo();
|
||||
}
|
||||
MachineAuthorizationDto machineAuthorizationDto = new MachineAuthorizationDto
|
||||
{
|
||||
ID = machineAuthorization.ID,
|
||||
MachineID = machineAuthorization.MachineID,
|
||||
AuthorizationCode = machineAuthorization.AuthorizationCode,
|
||||
AuthorizedDate = machineAuthorization.AuthorizedDate,
|
||||
ExpiryDate = machineAuthorization.ExpiryDate,
|
||||
Type = machineAuthorization.Type,
|
||||
CreatedUser = createdUserBasic,
|
||||
CreatedDate = machineAuthorization.CreatedDate,
|
||||
UpdatedUser = updatedUserBasic,
|
||||
UpdatedDate = machineAuthorization.UpdatedDate
|
||||
};
|
||||
machineAuthorizationDtos.Add(machineAuthorizationDto);
|
||||
}
|
||||
|
||||
CollectionResponse<MachineAuthorizationDto> collectionResponse = new CollectionResponse<MachineAuthorizationDto>
|
||||
{
|
||||
Total = total,
|
||||
Collection = machineAuthorizationDtos,
|
||||
Current = page,
|
||||
};
|
||||
return APIResponseModel<CollectionResponse<MachineAuthorizationDto>>.CreateSuccessResponseModel(ResponseCode.Success, collectionResponse);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<CollectionResponse<MachineAuthorizationDto>>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除指定的机器码授权码
|
||||
/// <summary>
|
||||
/// 删除指定的机器码授权码
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="requestUserId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult<APIResponseModel<object>>> DeleteMachineAuthorization(string id, long requestUserId)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isSuperAdmin = await _userBasicDao.CheckUserIsSuperAdmin(requestUserId);
|
||||
if (!isSuperAdmin)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.NotPermissionAction);
|
||||
}
|
||||
|
||||
MachineAuthorization? machineAuthorization = await _dbContext.MachineAuthorization.FirstOrDefaultAsync(x => x.ID == id);
|
||||
if (machineAuthorization == null)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.IdDateNotFound);
|
||||
}
|
||||
|
||||
_dbContext.MachineAuthorization.Remove(machineAuthorization);
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return APIResponseModel<object>.CreateSuccessResponseModel("删除成功");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return APIResponseModel<object>.CreateErrorResponseModel(ResponseCode.SystemError, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -26,6 +26,6 @@
|
||||
],
|
||||
"Enrich": [ "FromLogContext" ]
|
||||
},
|
||||
"Version": "1.0.6",
|
||||
"Version": "1.0.7",
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
32
SQL/v1.0.7/DataInfo.sql
Normal file
32
SQL/v1.0.7/DataInfo.sql
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Navicat Premium Dump SQL
|
||||
|
||||
Source Server : 亿速云(国内)
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80018 (8.0.18)
|
||||
Source Host : yisurds-66dc0b453c05d4.rds.ysydb1.com:14080
|
||||
Source Schema : LMS_TEST
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80018 (8.0.18)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 28/03/2025 20:54:04
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for DataInfo
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `DataInfo`;
|
||||
CREATE TABLE `DataInfo` (
|
||||
`ID` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'ID',
|
||||
`Type` int(11) NOT NULL COMMENT '数据的类型',
|
||||
`DataString` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '数据的字符串',
|
||||
`CreatedTime` datetime NOT NULL COMMENT '创建时间',
|
||||
PRIMARY KEY (`ID`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '数据信息表' ROW_FORMAT = Dynamic;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
38
SQL/v1.0.7/MachineAuthorization.sql
Normal file
38
SQL/v1.0.7/MachineAuthorization.sql
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Navicat Premium Dump SQL
|
||||
|
||||
Source Server : 亿速云(国内)
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80018 (8.0.18)
|
||||
Source Host : yisurds-66dc0b453c05d4.rds.ysydb1.com:14080
|
||||
Source Schema : LMS_TEST
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80018 (8.0.18)
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 28/03/2025 20:53:54
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for MachineAuthorization
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `MachineAuthorization`;
|
||||
CREATE TABLE `MachineAuthorization` (
|
||||
`ID` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'ID',
|
||||
`MachineID` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '机器码或者是授权码',
|
||||
`AuthorizedDate` datetime NOT NULL COMMENT '授权日期',
|
||||
`ExpiryDate` datetime NOT NULL COMMENT '过期日期',
|
||||
`AuthorizationCode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '授权码',
|
||||
`CreatedUserID` bigint(20) NOT NULL COMMENT '创建用户ID',
|
||||
`CreatedDate` datetime NOT NULL COMMENT '创建时间',
|
||||
`UpdatedUserID` bigint(20) NOT NULL COMMENT '更新用户ID',
|
||||
`UpdatedDate` datetime NOT NULL COMMENT '更新时间',
|
||||
`Type` int(10) NOT NULL COMMENT '授权类型',
|
||||
PRIMARY KEY (`ID`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '机器授权表' ROW_FORMAT = Dynamic;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
Loading…
x
Reference in New Issue
Block a user