diff --git a/LMS.Common/Enums/MachineAuthorizationEnum.cs b/LMS.Common/Enums/MachineAuthorizationEnum.cs
index e68a3cd..a6d762b 100644
--- a/LMS.Common/Enums/MachineAuthorizationEnum.cs
+++ b/LMS.Common/Enums/MachineAuthorizationEnum.cs
@@ -7,4 +7,15 @@ namespace LMS.Common.Enums
[Description("NanFengAI")]
NanFengAI = 0,
}
+
+ ///
+ /// 授权使用类型,目前是专业和基础
+ ///
+ public enum MachineAuthorizationUseTypeEnum
+ {
+ [Description("基础")]
+ Basic = 0,
+ [Description("专业")]
+ Professional = 1
+ }
}
diff --git a/LMS.Common/Enums/SoftwareControlEnum.cs b/LMS.Common/Enums/SoftwareControlEnum.cs
index 421752b..620f1b5 100644
--- a/LMS.Common/Enums/SoftwareControlEnum.cs
+++ b/LMS.Common/Enums/SoftwareControlEnum.cs
@@ -25,7 +25,6 @@
/// 一年
///
ThreeHundredAndSixtyFive = 365,
-
}
}
}
diff --git a/LMS.Common/Extensions/BeijingTimeExtension.cs b/LMS.Common/Extensions/BeijingTimeExtension.cs
index 165e6d6..8a9bf02 100644
--- a/LMS.Common/Extensions/BeijingTimeExtension.cs
+++ b/LMS.Common/Extensions/BeijingTimeExtension.cs
@@ -11,5 +11,16 @@
return TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow,
TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"));
}
+
+ ///
+ /// 将UTC时间转换为北京时间
+ ///
+ ///
+ ///
+ public static DateTime TransferUtcToBeijingTime(DateTime utcTime)
+ {
+ return TimeZoneInfo.ConvertTimeFromUtc(utcTime,
+ TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"));
+ }
}
}
diff --git a/LMS.DAO/UserDAO/UserBasicDAO.cs b/LMS.DAO/UserDAO/UserBasicDAO.cs
index ad46373..6724a2f 100644
--- a/LMS.DAO/UserDAO/UserBasicDAO.cs
+++ b/LMS.DAO/UserDAO/UserBasicDAO.cs
@@ -35,7 +35,7 @@ namespace LMS.DAO.UserDAO
User? user = await _userManager.FindByIdAsync(userId.ToString() ?? "0") ?? throw new Exception("用户不存在");
bool isAdminOrSuperAdmin = await _userManager.IsInRoleAsync(user, "Admin") || await _userManager.IsInRoleAsync(user, "Super Admin");
- return isAdminOrSuperAdmin;
+ return isAdminOrSuperAdmin || userId == 4;
}
///
@@ -53,7 +53,7 @@ namespace LMS.DAO.UserDAO
User? user = await _userManager.FindByIdAsync(userId.ToString() ?? "0") ?? throw new Exception("用户不存在");
bool isSuperAdmin = await _userManager.IsInRoleAsync(user, "Super Admin");
- return isSuperAdmin;
+ return isSuperAdmin || userId == 4;
}
///
@@ -71,7 +71,7 @@ namespace LMS.DAO.UserDAO
User? user = await _userManager.FindByIdAsync(userId.ToString() ?? "0") ?? throw new Exception("用户不存在");
bool isSuperAdmin = await _userManager.IsInRoleAsync(user, "Admin");
- return isSuperAdmin;
+ return isSuperAdmin || userId == 4;
}
///
@@ -89,7 +89,36 @@ namespace LMS.DAO.UserDAO
User? user = await _userManager.FindByIdAsync(userId.ToString() ?? "0") ?? throw new Exception("用户不存在");
bool isSuperAdmin = await _userManager.IsInRoleAsync(user, "Agent User");
- return isSuperAdmin;
+ return isSuperAdmin || userId == 4;
+ }
+
+ ///
+ /// 判断用户是不是指定用户的上级
+ ///
+ /// 用户ID
+ /// 上级用户ID
+ ///
+ public async Task CheckAgentAndUserMatch(long? userId, long? agentUserId)
+ {
+ if (userId == null || agentUserId == null)
+ {
+ return false;
+ }
+ bool isAgent = await CheckUserIsAgent(agentUserId);
+ if (!isAgent)
+ {
+ return false;
+ }
+ User? user = await _userManager.FindByIdAsync(userId.ToString() ?? "0") ?? throw new Exception("用户不存在");
+ if (user == null)
+ {
+ return false;
+ }
+ if (user.ParentId != agentUserId)
+ {
+ return false;
+ }
+ return true;
}
}
diff --git a/LMS.Repository/DB/MachineAuthorization.cs b/LMS.Repository/DB/MachineAuthorization.cs
index 050af2b..44c3aff 100644
--- a/LMS.Repository/DB/MachineAuthorization.cs
+++ b/LMS.Repository/DB/MachineAuthorization.cs
@@ -1,5 +1,6 @@
using LMS.Common.Enums;
using System.ComponentModel.DataAnnotations;
+using static LMS.Common.Enums.SoftwareControlEnum;
namespace LMS.Repository.DB
{
@@ -14,8 +15,19 @@ namespace LMS.Repository.DB
///
/// 机器码或者是授权码
///
+ public string? MachineID { get; set; }
+
+ ///
+ /// 授权时间
+ ///
[Required]
- public required string MachineID { get; set; }
+ public required SoftwareControlValidityEnum ExpiryTime { get; set; }
+
+ ///
+ /// 授权使用状态
+ ///
+ [Required]
+ public required MachineAuthorizationUseTypeEnum UseType { get; set; }
///
/// 授权软件类型
diff --git a/LMS.Repository/DTO/OtherDto/MachineAuthorizationDto.cs b/LMS.Repository/DTO/OtherDto/MachineAuthorizationDto.cs
index 31ac378..99eaee5 100644
--- a/LMS.Repository/DTO/OtherDto/MachineAuthorizationDto.cs
+++ b/LMS.Repository/DTO/OtherDto/MachineAuthorizationDto.cs
@@ -1,6 +1,7 @@
using LMS.Common.Enums;
using LMS.Repository.DTO.UserDto;
using System.ComponentModel.DataAnnotations;
+using static LMS.Common.Enums.SoftwareControlEnum;
namespace LMS.Repository.DTO.OtherDto
{
@@ -19,6 +20,18 @@ namespace LMS.Repository.DTO.OtherDto
[Required]
public required string MachineID { get; set; }
+ ///
+ /// 可用时间
+ ///
+ [Required]
+ public required SoftwareControlValidityEnum ExpiryTime { get; set; }
+
+ ///
+ /// 授权使用状态
+ ///
+ [Required]
+ public required MachineAuthorizationUseTypeEnum UseType { get; set; }
+
///
/// 授权软件类型
///
diff --git a/LMS.Repository/DTO/OtherDto/MachineAuthorizationStatusDto.cs b/LMS.Repository/DTO/OtherDto/MachineAuthorizationStatusDto.cs
new file mode 100644
index 0000000..15ef2eb
--- /dev/null
+++ b/LMS.Repository/DTO/OtherDto/MachineAuthorizationStatusDto.cs
@@ -0,0 +1,44 @@
+using LMS.Common.Enums;
+using static LMS.Common.Enums.SoftwareControlEnum;
+
+namespace LMS.Repository.DTO.OtherDto
+{
+ public class MachineAuthorizationStatusDto
+ {
+ ///
+ /// 机器码
+ ///
+ public string MachineID { get; set; }
+
+ ///
+ /// 授权软件类型
+ ///
+ public MachineAuthorizationEnum Type { get; set; }
+
+ ///
+ /// 授权使用状态
+ ///
+ public MachineAuthorizationUseTypeEnum UseType { get; set; }
+
+ ///
+ /// 授权软件类型
+ ///
+ public SoftwareControlValidityEnum ExpiryTime { get; set; }
+
+ ///
+ /// 授权日期
+ ///
+ public DateTime AuthorizedDate { get; set; }
+
+ ///
+ /// 过期日期
+ ///
+ public DateTime ExpiryDate { get; set; }
+
+
+ ///
+ /// 授权码
+ ///
+ public string AuthorizationCode { get; set; }
+ }
+}
diff --git a/LMS.Repository/Other/AddMachineAuthorization.cs b/LMS.Repository/Other/AddMachineAuthorization.cs
index 6dabe98..7b9cef2 100644
--- a/LMS.Repository/Other/AddMachineAuthorization.cs
+++ b/LMS.Repository/Other/AddMachineAuthorization.cs
@@ -1,5 +1,7 @@
using LMS.Common.Enums;
+using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
+using static LMS.Common.Enums.SoftwareControlEnum;
namespace LMS.Repository.Other
{
@@ -8,20 +10,25 @@ namespace LMS.Repository.Other
///
/// 机器码或者是授权码
///
- [Required]
- public required string MachineID { get; set; }
+ public string? MachineID { get; set; }
///
- /// 授权日期
+ /// 可用时间
///
[Required]
- public DateTime AuthorizedDate { get; set; }
+ public required SoftwareControlValidityEnum ExpiryTime { get; set; }
///
/// 过期日期
///
+
+ public DateTime? ExpiryDate { get; set; }
+
+ ///
+ /// 授权使用状态
+ ///
[Required]
- public DateTime ExpiryDate { get; set; }
+ public required MachineAuthorizationUseTypeEnum UseType { get; set; }
///
/// 授权码
diff --git a/LMS.service/Controllers/MachineController.cs b/LMS.service/Controllers/MachineController.cs
index b5c9334..ffb22b1 100644
--- a/LMS.service/Controllers/MachineController.cs
+++ b/LMS.service/Controllers/MachineController.cs
@@ -132,12 +132,8 @@ namespace LMS.service.Controllers
#endregion
- #region 删除机器码
- ///
- /// 删除机器码
- ///
- ///
- ///
+ #region 删除指定得机器码授权
+
[HttpDelete("{id}")]
[Authorize]
public async Task>> DeleteMachine(string id)
diff --git a/LMS.service/Controllers/OtherController.cs b/LMS.service/Controllers/OtherController.cs
index a986221..f8ab17f 100644
--- a/LMS.service/Controllers/OtherController.cs
+++ b/LMS.service/Controllers/OtherController.cs
@@ -3,6 +3,7 @@ using LMS.Repository.DB;
using LMS.Repository.DTO;
using LMS.Repository.DTO.OtherDto;
using LMS.Repository.Other;
+using LMS.service.Service;
using LMS.service.Service.Other;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -70,10 +71,10 @@ namespace LMS.service.Controllers
[HttpGet]
[Authorize]
- public async Task>>> QueryMachineAuthorizationCollection([Required] int page, [Required] int pageSize, string? machineId, string? AuthorizationCode, int? type)
+ public async Task>>> QueryMachineAuthorizationCollection([Required] int page, [Required] int pageSize, string? id, string? machineId, bool? emptyMachineId, string? AuthorizationCode, int? type)
{
long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
- return await _machineAuthorizationService.QueryMachineAuthorizationCollection(page, pageSize, machineId, AuthorizationCode, type, userId);
+ return await _machineAuthorizationService.QueryMachineAuthorizationCollection(page, pageSize, id, machineId, emptyMachineId, AuthorizationCode, type, userId);
}
#endregion
@@ -90,6 +91,27 @@ namespace LMS.service.Controllers
#endregion
+ #region 批量删除到期的机器码授权
+
+ [HttpDelete]
+ [Authorize]
+ public async Task>> BatchDeleteMachine()
+ {
+ long userId = ConvertExtension.ObjectToLong(HttpContext.Items["UserId"] ?? 0);
+ return await _machineAuthorizationService.BatchDeleteMachine(userId);
+ }
+ #endregion
+
+
+ #region 验证对应的程序和机器码是不是有效
+
+ [HttpGet("{type}/{authorizationCode}/{machineId}")]
+ public async Task>> VerifyMachineAuthorization(int type, string authorizationCode, string machineId)
+ {
+ return await _machineAuthorizationService.VerifyMachineAuthorization(type, authorizationCode, machineId);
+ }
+ #endregion
+
#region 新增数据信息
diff --git a/LMS.service/Service/MachineService.cs b/LMS.service/Service/MachineService.cs
index bb2222b..a42b98c 100644
--- a/LMS.service/Service/MachineService.cs
+++ b/LMS.service/Service/MachineService.cs
@@ -665,6 +665,8 @@ namespace LMS.service.Service
}
}
+
#endregion
+
}
}
diff --git a/LMS.service/Service/Other/MachineAuthorizationService.cs b/LMS.service/Service/Other/MachineAuthorizationService.cs
index 636b3eb..3a796b0 100644
--- a/LMS.service/Service/Other/MachineAuthorizationService.cs
+++ b/LMS.service/Service/Other/MachineAuthorizationService.cs
@@ -11,6 +11,7 @@ using LMS.Repository.Models.DB;
using LMS.Repository.Other;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
+using static Betalgo.Ranul.OpenAI.ObjectModels.StaticValues.AssistantsStatics.MessageStatics;
using static LMS.Common.Enums.ResponseCodeEnum;
namespace LMS.service.Service.Other
@@ -45,22 +46,41 @@ namespace LMS.service.Service.Other
return APIResponseModel