feat: 授权码删除、锁定、更新接口完成

This commit is contained in:
wood911010 committed 2025-09-17 00:42:45 +08:00
1 parent 188406c517
commit d8fd24390d
11 files changed
+2316 -7

No files matched your search

+662
View File
@@ -734,6 +734,129 @@ const docTemplate = `{
}
},
"/api/v1/authorization-codes": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "分页查询授权码列表,支持筛选和排序",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "查询授权码列表",
"parameters": [
{
"minimum": 1,
"type": "integer",
"description": "页码,默认1",
"name": "page",
"in": "query"
},
{
"maximum": 100,
"minimum": 1,
"type": "integer",
"description": "每页条数,默认20,最大100",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "客户ID筛选",
"name": "customer_id",
"in": "query"
},
{
"enum": [
"normal",
"locked",
"expired"
],
"type": "string",
"description": "状态筛选",
"name": "status",
"in": "query"
},
{
"type": "string",
"description": "创建开始时间",
"name": "start_date",
"in": "query"
},
{
"type": "string",
"description": "创建结束时间",
"name": "end_date",
"in": "query"
},
{
"enum": [
"created_at",
"updated_at",
"code"
],
"type": "string",
"description": "排序字段,默认created_at",
"name": "sort",
"in": "query"
},
{
"enum": [
"asc",
"desc"
],
"type": "string",
"description": "排序方向,默认desc",
"name": "order",
"in": "query"
}
],
"responses": {
"200": {
"description": "查询成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCodeListResponse"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"post": {
"security": [
{
@@ -814,6 +937,300 @@ const docTemplate = `{
}
}
},
"/api/v1/authorization-codes/{id}": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "根据授权码ID获取授权码详细信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "获取授权码详情",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "查询成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCode"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"put": {
"security": [
{
"BearerAuth": []
}
],
"description": "更新授权码信息,所有字段都是可选的,需要指定变更类型和原因",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "更新授权码",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "授权码信息",
"name": "authorization_code",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.AuthorizationCodeUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "更新成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCode"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "删除指定的授权码(软删除)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "删除授权码",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除成功",
"schema": {
"$ref": "#/definitions/models.APIResponse"
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/v1/authorization-codes/{id}/lock": {
"put": {
"security": [
{
"BearerAuth": []
}
],
"description": "锁定或解锁指定的授权码,可以设置锁定原因",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "锁定/解锁授权码",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "锁定/解锁信息",
"name": "lock_request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.AuthorizationCodeLockRequest"
}
}
],
"responses": {
"200": {
"description": "操作成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCode"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/v1/login": {
"post": {
"description": "管理员用户登录接口",
@@ -940,6 +1357,95 @@ const docTemplate = `{
}
}
},
"models.AuthorizationCode": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"created_at": {
"type": "string"
},
"created_by": {
"type": "string"
},
"current_activations": {
"type": "integer"
},
"custom_parameters": {
"type": "object"
},
"customer_id": {
"type": "string"
},
"customer_name": {
"type": "string"
},
"customer_name_display": {
"type": "string"
},
"deployment_type": {
"type": "string"
},
"deployment_type_display": {
"type": "string"
},
"description": {
"type": "string"
},
"encryption_type": {
"type": "string"
},
"encryption_type_display": {
"type": "string"
},
"end_date": {
"type": "string"
},
"feature_config": {
"type": "object"
},
"id": {
"type": "string"
},
"is_locked": {
"type": "boolean"
},
"lock_reason": {
"type": "string"
},
"locked_at": {
"type": "string"
},
"locked_by": {
"type": "string"
},
"max_activations": {
"type": "integer"
},
"software_id": {
"type": "string"
},
"software_version": {
"type": "string"
},
"start_date": {
"type": "string"
},
"status": {
"type": "string"
},
"status_display": {
"type": "string"
},
"updated_at": {
"type": "string"
},
"usage_limits": {
"type": "object"
}
}
},
"models.AuthorizationCodeCreateRequest": {
"type": "object",
"required": [
@@ -1002,6 +1508,162 @@ const docTemplate = `{
}
}
},
"models.AuthorizationCodeListItem": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"created_at": {
"type": "string"
},
"current_activations": {
"type": "integer"
},
"customer_id": {
"type": "string"
},
"customer_name": {
"type": "string"
},
"customer_name_display": {
"type": "string"
},
"deployment_type": {
"type": "string"
},
"deployment_type_display": {
"type": "string"
},
"description": {
"type": "string"
},
"end_date": {
"type": "string"
},
"id": {
"type": "string"
},
"is_locked": {
"type": "boolean"
},
"max_activations": {
"type": "integer"
},
"start_date": {
"type": "string"
},
"status": {
"type": "string"
},
"status_display": {
"type": "string"
}
}
},
"models.AuthorizationCodeListResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/models.AuthorizationCodeListItem"
}
},
"page": {
"type": "integer"
},
"page_size": {
"type": "integer"
},
"total": {
"type": "integer"
},
"total_pages": {
"type": "integer"
}
}
},
"models.AuthorizationCodeLockRequest": {
"type": "object",
"properties": {
"is_locked": {
"description": "true-锁定,false-解锁",
"type": "boolean"
},
"lock_reason": {
"description": "锁定原因",
"type": "string",
"maxLength": 500
},
"reason": {
"description": "变更原因(记录到变更历史)",
"type": "string",
"maxLength": 500
}
}
},
"models.AuthorizationCodeUpdateRequest": {
"type": "object",
"required": [
"change_type"
],
"properties": {
"change_type": {
"type": "string",
"enum": [
"renewal",
"upgrade",
"limit_change",
"feature_toggle",
"lock",
"unlock",
"other"
]
},
"custom_parameters": {},
"deployment_type": {
"type": "string",
"enum": [
"standalone",
"cloud",
"hybrid"
]
},
"description": {
"type": "string",
"maxLength": 1000
},
"encryption_type": {
"type": "string",
"enum": [
"standard",
"advanced"
]
},
"feature_config": {},
"max_activations": {
"type": "integer",
"minimum": 1
},
"reason": {
"type": "string",
"maxLength": 500
},
"software_id": {
"type": "string"
},
"software_version": {
"type": "string"
},
"usage_limits": {},
"validity_days": {
"type": "integer",
"maximum": 36500,
"minimum": 1
}
}
},
"models.Customer": {
"type": "object",
"properties": {
+662
View File
@@ -731,6 +731,129 @@
}
},
"/api/v1/authorization-codes": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "分页查询授权码列表,支持筛选和排序",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "查询授权码列表",
"parameters": [
{
"minimum": 1,
"type": "integer",
"description": "页码,默认1",
"name": "page",
"in": "query"
},
{
"maximum": 100,
"minimum": 1,
"type": "integer",
"description": "每页条数,默认20,最大100",
"name": "page_size",
"in": "query"
},
{
"type": "string",
"description": "客户ID筛选",
"name": "customer_id",
"in": "query"
},
{
"enum": [
"normal",
"locked",
"expired"
],
"type": "string",
"description": "状态筛选",
"name": "status",
"in": "query"
},
{
"type": "string",
"description": "创建开始时间",
"name": "start_date",
"in": "query"
},
{
"type": "string",
"description": "创建结束时间",
"name": "end_date",
"in": "query"
},
{
"enum": [
"created_at",
"updated_at",
"code"
],
"type": "string",
"description": "排序字段,默认created_at",
"name": "sort",
"in": "query"
},
{
"enum": [
"asc",
"desc"
],
"type": "string",
"description": "排序方向,默认desc",
"name": "order",
"in": "query"
}
],
"responses": {
"200": {
"description": "查询成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCodeListResponse"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"post": {
"security": [
{
@@ -811,6 +934,300 @@
}
}
},
"/api/v1/authorization-codes/{id}": {
"get": {
"security": [
{
"BearerAuth": []
}
],
"description": "根据授权码ID获取授权码详细信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "获取授权码详情",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "查询成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCode"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"put": {
"security": [
{
"BearerAuth": []
}
],
"description": "更新授权码信息,所有字段都是可选的,需要指定变更类型和原因",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "更新授权码",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "授权码信息",
"name": "authorization_code",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.AuthorizationCodeUpdateRequest"
}
}
],
"responses": {
"200": {
"description": "更新成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCode"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
},
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "删除指定的授权码(软删除)",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "删除授权码",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "删除成功",
"schema": {
"$ref": "#/definitions/models.APIResponse"
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/v1/authorization-codes/{id}/lock": {
"put": {
"security": [
{
"BearerAuth": []
}
],
"description": "锁定或解锁指定的授权码,可以设置锁定原因",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"授权码管理"
],
"summary": "锁定/解锁授权码",
"parameters": [
{
"type": "string",
"description": "授权码ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "锁定/解锁信息",
"name": "lock_request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/models.AuthorizationCodeLockRequest"
}
}
],
"responses": {
"200": {
"description": "操作成功",
"schema": {
"allOf": [
{
"$ref": "#/definitions/models.APIResponse"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/models.AuthorizationCode"
}
}
}
]
}
},
"400": {
"description": "请求参数无效",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"401": {
"description": "未认证",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"404": {
"description": "授权码不存在",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
},
"500": {
"description": "服务器内部错误",
"schema": {
"$ref": "#/definitions/models.ErrorResponse"
}
}
}
}
},
"/api/v1/login": {
"post": {
"description": "管理员用户登录接口",
@@ -937,6 +1354,95 @@
}
}
},
"models.AuthorizationCode": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"created_at": {
"type": "string"
},
"created_by": {
"type": "string"
},
"current_activations": {
"type": "integer"
},
"custom_parameters": {
"type": "object"
},
"customer_id": {
"type": "string"
},
"customer_name": {
"type": "string"
},
"customer_name_display": {
"type": "string"
},
"deployment_type": {
"type": "string"
},
"deployment_type_display": {
"type": "string"
},
"description": {
"type": "string"
},
"encryption_type": {
"type": "string"
},
"encryption_type_display": {
"type": "string"
},
"end_date": {
"type": "string"
},
"feature_config": {
"type": "object"
},
"id": {
"type": "string"
},
"is_locked": {
"type": "boolean"
},
"lock_reason": {
"type": "string"
},
"locked_at": {
"type": "string"
},
"locked_by": {
"type": "string"
},
"max_activations": {
"type": "integer"
},
"software_id": {
"type": "string"
},
"software_version": {
"type": "string"
},
"start_date": {
"type": "string"
},
"status": {
"type": "string"
},
"status_display": {
"type": "string"
},
"updated_at": {
"type": "string"
},
"usage_limits": {
"type": "object"
}
}
},
"models.AuthorizationCodeCreateRequest": {
"type": "object",
"required": [
@@ -999,6 +1505,162 @@
}
}
},
"models.AuthorizationCodeListItem": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"created_at": {
"type": "string"
},
"current_activations": {
"type": "integer"
},
"customer_id": {
"type": "string"
},
"customer_name": {
"type": "string"
},
"customer_name_display": {
"type": "string"
},
"deployment_type": {
"type": "string"
},
"deployment_type_display": {
"type": "string"
},
"description": {
"type": "string"
},
"end_date": {
"type": "string"
},
"id": {
"type": "string"
},
"is_locked": {
"type": "boolean"
},
"max_activations": {
"type": "integer"
},
"start_date": {
"type": "string"
},
"status": {
"type": "string"
},
"status_display": {
"type": "string"
}
}
},
"models.AuthorizationCodeListResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/models.AuthorizationCodeListItem"
}
},
"page": {
"type": "integer"
},
"page_size": {
"type": "integer"
},
"total": {
"type": "integer"
},
"total_pages": {
"type": "integer"
}
}
},
"models.AuthorizationCodeLockRequest": {
"type": "object",
"properties": {
"is_locked": {
"description": "true-锁定,false-解锁",
"type": "boolean"
},
"lock_reason": {
"description": "锁定原因",
"type": "string",
"maxLength": 500
},
"reason": {
"description": "变更原因(记录到变更历史)",
"type": "string",
"maxLength": 500
}
}
},
"models.AuthorizationCodeUpdateRequest": {
"type": "object",
"required": [
"change_type"
],
"properties": {
"change_type": {
"type": "string",
"enum": [
"renewal",
"upgrade",
"limit_change",
"feature_toggle",
"lock",
"unlock",
"other"
]
},
"custom_parameters": {},
"deployment_type": {
"type": "string",
"enum": [
"standalone",
"cloud",
"hybrid"
]
},
"description": {
"type": "string",
"maxLength": 1000
},
"encryption_type": {
"type": "string",
"enum": [
"standard",
"advanced"
]
},
"feature_config": {},
"max_activations": {
"type": "integer",
"minimum": 1
},
"reason": {
"type": "string",
"maxLength": 500
},
"software_id": {
"type": "string"
},
"software_version": {
"type": "string"
},
"usage_limits": {},
"validity_days": {
"type": "integer",
"maximum": 36500,
"minimum": 1
}
}
},
"models.Customer": {
"type": "object",
"properties": {
+430
View File
@@ -10,6 +10,65 @@ definitions:
timestamp:
type: string
type: object
models.AuthorizationCode:
properties:
code:
type: string
created_at:
type: string
created_by:
type: string
current_activations:
type: integer
custom_parameters:
type: object
customer_id:
type: string
customer_name:
type: string
customer_name_display:
type: string
deployment_type:
type: string
deployment_type_display:
type: string
description:
type: string
encryption_type:
type: string
encryption_type_display:
type: string
end_date:
type: string
feature_config:
type: object
id:
type: string
is_locked:
type: boolean
lock_reason:
type: string
locked_at:
type: string
locked_by:
type: string
max_activations:
type: integer
software_id:
type: string
software_version:
type: string
start_date:
type: string
status:
type: string
status_display:
type: string
updated_at:
type: string
usage_limits:
type: object
type: object
models.AuthorizationCodeCreateRequest:
properties:
custom_parameters: {}
@@ -55,6 +114,116 @@ definitions:
id:
type: string
type: object
models.AuthorizationCodeListItem:
properties:
code:
type: string
created_at:
type: string
current_activations:
type: integer
customer_id:
type: string
customer_name:
type: string
customer_name_display:
type: string
deployment_type:
type: string
deployment_type_display:
type: string
description:
type: string
end_date:
type: string
id:
type: string
is_locked:
type: boolean
max_activations:
type: integer
start_date:
type: string
status:
type: string
status_display:
type: string
type: object
models.AuthorizationCodeListResponse:
properties:
list:
items:
$ref: '#/definitions/models.AuthorizationCodeListItem'
type: array
page:
type: integer
page_size:
type: integer
total:
type: integer
total_pages:
type: integer
type: object
models.AuthorizationCodeLockRequest:
properties:
is_locked:
description: true-锁定,false-解锁
type: boolean
lock_reason:
description: 锁定原因
maxLength: 500
type: string
reason:
description: 变更原因(记录到变更历史)
maxLength: 500
type: string
type: object
models.AuthorizationCodeUpdateRequest:
properties:
change_type:
enum:
- renewal
- upgrade
- limit_change
- feature_toggle
- lock
- unlock
- other
type: string
custom_parameters: {}
deployment_type:
enum:
- standalone
- cloud
- hybrid
type: string
description:
maxLength: 1000
type: string
encryption_type:
enum:
- standard
- advanced
type: string
feature_config: {}
max_activations:
minimum: 1
type: integer
reason:
maxLength: 500
type: string
software_id:
type: string
software_version:
type: string
usage_limits: {}
validity_days:
maximum: 36500
minimum: 1
type: integer
required:
- change_type
type: object
models.Customer:
properties:
address:
@@ -824,6 +993,86 @@ paths:
tags:
- 认证
/api/v1/authorization-codes:
get:
consumes:
- application/json
description: 分页查询授权码列表,支持筛选和排序
parameters:
- description: 页码,默认1
in: query
minimum: 1
name: page
type: integer
- description: 每页条数,默认20,最大100
in: query
maximum: 100
minimum: 1
name: page_size
type: integer
- description: 客户ID筛选
in: query
name: customer_id
type: string
- description: 状态筛选
enum:
- normal
- locked
- expired
in: query
name: status
type: string
- description: 创建开始时间
in: query
name: start_date
type: string
- description: 创建结束时间
in: query
name: end_date
type: string
- description: 排序字段,默认created_at
enum:
- created_at
- updated_at
- code
in: query
name: sort
type: string
- description: 排序方向,默认desc
enum:
- asc
- desc
in: query
name: order
type: string
produces:
- application/json
responses:
"200":
description: 查询成功
schema:
allOf:
- $ref: '#/definitions/models.APIResponse'
- properties:
data:
$ref: '#/definitions/models.AuthorizationCodeListResponse'
type: object
"400":
description: 请求参数无效
schema:
$ref: '#/definitions/models.ErrorResponse'
"401":
description: 未认证
schema:
$ref: '#/definitions/models.ErrorResponse'
"500":
description: 服务器内部错误
schema:
$ref: '#/definitions/models.ErrorResponse'
security:
- BearerAuth: []
summary: 查询授权码列表
tags:
- 授权码管理
post:
consumes:
- application/json
@@ -872,6 +1121,187 @@ paths:
summary: 创建授权码
tags:
- 授权码管理
/api/v1/authorization-codes/{id}:
delete:
consumes:
- application/json
description: 删除指定的授权码(软删除)
parameters:
- description: 授权码ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 删除成功
schema:
$ref: '#/definitions/models.APIResponse'
"400":
description: 请求参数无效
schema:
$ref: '#/definitions/models.ErrorResponse'
"401":
description: 未认证
schema:
$ref: '#/definitions/models.ErrorResponse'
"404":
description: 授权码不存在
schema:
$ref: '#/definitions/models.ErrorResponse'
"500":
description: 服务器内部错误
schema:
$ref: '#/definitions/models.ErrorResponse'
security:
- BearerAuth: []
summary: 删除授权码
tags:
- 授权码管理
get:
consumes:
- application/json
description: 根据授权码ID获取授权码详细信息
parameters:
- description: 授权码ID
in: path
name: id
required: true
type: string
produces:
- application/json
responses:
"200":
description: 查询成功
schema:
allOf:
- $ref: '#/definitions/models.APIResponse'
- properties:
data:
$ref: '#/definitions/models.AuthorizationCode'
type: object
"400":
description: 请求参数无效
schema:
$ref: '#/definitions/models.ErrorResponse'
"401":
description: 未认证
schema:
$ref: '#/definitions/models.ErrorResponse'
"404":
description: 授权码不存在
schema:
$ref: '#/definitions/models.ErrorResponse'
"500":
description: 服务器内部错误
schema:
$ref: '#/definitions/models.ErrorResponse'
security:
- BearerAuth: []
summary: 获取授权码详情
tags:
- 授权码管理
put:
consumes:
- application/json
description: 更新授权码信息,所有字段都是可选的,需要指定变更类型和原因
parameters:
- description: 授权码ID
in: path
name: id
required: true
type: string
- description: 授权码信息
in: body
name: authorization_code
required: true
schema:
$ref: '#/definitions/models.AuthorizationCodeUpdateRequest'
produces:
- application/json
responses:
"200":
description: 更新成功
schema:
allOf:
- $ref: '#/definitions/models.APIResponse'
- properties:
data:
$ref: '#/definitions/models.AuthorizationCode'
type: object
"400":
description: 请求参数无效
schema:
$ref: '#/definitions/models.ErrorResponse'
"401":
description: 未认证
schema:
$ref: '#/definitions/models.ErrorResponse'
"404":
description: 授权码不存在
schema:
$ref: '#/definitions/models.ErrorResponse'
"500":
description: 服务器内部错误
schema:
$ref: '#/definitions/models.ErrorResponse'
security:
- BearerAuth: []
summary: 更新授权码
tags:
- 授权码管理
/api/v1/authorization-codes/{id}/lock:
put:
consumes:
- application/json
description: 锁定或解锁指定的授权码,可以设置锁定原因
parameters:
- description: 授权码ID
in: path
name: id
required: true
type: string
- description: 锁定/解锁信息
in: body
name: lock_request
required: true
schema:
$ref: '#/definitions/models.AuthorizationCodeLockRequest'
produces:
- application/json
responses:
"200":
description: 操作成功
schema:
allOf:
- $ref: '#/definitions/models.APIResponse'
- properties:
data:
$ref: '#/definitions/models.AuthorizationCode'
type: object
"400":
description: 请求参数无效
schema:
$ref: '#/definitions/models.ErrorResponse'
"401":
description: 未认证
schema:
$ref: '#/definitions/models.ErrorResponse'
"404":
description: 授权码不存在
schema:
$ref: '#/definitions/models.ErrorResponse'
"500":
description: 服务器内部错误
schema:
$ref: '#/definitions/models.ErrorResponse'
security:
- BearerAuth: []
summary: 锁定/解锁授权码
tags:
- 授权码管理
/api/v1/login:
post:
consumes:
@@ -153,4 +153,277 @@ func (h *AuthorizationCodeHandler) GetAuthorizationCodeList(c *gin.Context) {
Message: successMessage,
Data: data,
})
}
}
// GetAuthorizationCode 获取授权码详情
// @Summary 获取授权码详情
// @Description 根据授权码ID获取授权码详细信息
// @Tags 授权码管理
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param id path string true "授权码ID"
// @Success 200 {object} models.APIResponse{data=models.AuthorizationCode} "查询成功"
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
// @Failure 401 {object} models.ErrorResponse "未认证"
// @Failure 404 {object} models.ErrorResponse "授权码不存在"
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
// @Router /api/v1/authorization-codes/{id} [get]
func (h *AuthorizationCodeHandler) GetAuthorizationCode(c *gin.Context) {
id := c.Param("id")
if id == "" {
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
return
}
// 设置语言到Context中
ctx := middleware.WithLanguage(c.Request.Context(), c)
data, err := h.authCodeService.GetAuthorizationCode(ctx, id)
if err != nil {
// 错误已经在Service层完全包装好了,直接使用
var i18nErr *i18n.I18nError
if errors.As(err, &i18nErr) {
c.JSON(i18nErr.HttpCode, models.ErrorResponse{
Code: i18nErr.Code,
Message: i18nErr.Message,
Timestamp: time.Now().Format(time.RFC3339),
})
} else {
// 兜底:理论上不应该到这里,因为Service层应该返回I18nError
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
}
return
}
lang := middleware.GetLanguage(c)
successMessage := i18n.GetErrorMessage("000000", lang)
c.JSON(http.StatusOK, models.APIResponse{
Code: "000000",
Message: successMessage,
Data: data,
})
}
// UpdateAuthorizationCode 更新授权码
// @Summary 更新授权码
// @Description 更新授权码信息,所有字段都是可选的,需要指定变更类型和原因
// @Tags 授权码管理
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param id path string true "授权码ID"
// @Param authorization_code body models.AuthorizationCodeUpdateRequest true "授权码信息"
// @Success 200 {object} models.APIResponse{data=models.AuthorizationCode} "更新成功"
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
// @Failure 401 {object} models.ErrorResponse "未认证"
// @Failure 404 {object} models.ErrorResponse "授权码不存在"
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
// @Router /api/v1/authorization-codes/{id} [put]
func (h *AuthorizationCodeHandler) UpdateAuthorizationCode(c *gin.Context) {
id := c.Param("id")
if id == "" {
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
return
}
var req models.AuthorizationCodeUpdateRequest
if err := c.ShouldBindJSON(&req); err != nil {
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message + ": " + err.Error(),
Timestamp: time.Now().Format(time.RFC3339),
})
return
}
// 设置语言到Context中
ctx := middleware.WithLanguage(c.Request.Context(), c)
data, err := h.authCodeService.UpdateAuthorizationCode(ctx, id, &req)
if err != nil {
// 错误已经在Service层完全包装好了,直接使用
var i18nErr *i18n.I18nError
if errors.As(err, &i18nErr) {
c.JSON(i18nErr.HttpCode, models.ErrorResponse{
Code: i18nErr.Code,
Message: i18nErr.Message,
Timestamp: time.Now().Format(time.RFC3339),
})
} else {
// 兜底:理论上不应该到这里,因为Service层应该返回I18nError
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
}
return
}
lang := middleware.GetLanguage(c)
successMessage := i18n.GetErrorMessage("000000", lang)
c.JSON(http.StatusOK, models.APIResponse{
Code: "000000",
Message: successMessage,
Data: data,
})
}
// LockUnlockAuthorizationCode 锁定/解锁授权码
// @Summary 锁定/解锁授权码
// @Description 锁定或解锁指定的授权码,可以设置锁定原因
// @Tags 授权码管理
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param id path string true "授权码ID"
// @Param lock_request body models.AuthorizationCodeLockRequest true "锁定/解锁信息"
// @Success 200 {object} models.APIResponse{data=models.AuthorizationCode} "操作成功"
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
// @Failure 401 {object} models.ErrorResponse "未认证"
// @Failure 404 {object} models.ErrorResponse "授权码不存在"
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
// @Router /api/v1/authorization-codes/{id}/lock [put]
func (h *AuthorizationCodeHandler) LockUnlockAuthorizationCode(c *gin.Context) {
id := c.Param("id")
if id == "" {
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
return
}
var req models.AuthorizationCodeLockRequest
if err := c.ShouldBindJSON(&req); err != nil {
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message + ": " + err.Error(),
Timestamp: time.Now().Format(time.RFC3339),
})
return
}
// 设置语言到Context中
ctx := middleware.WithLanguage(c.Request.Context(), c)
data, err := h.authCodeService.LockUnlockAuthorizationCode(ctx, id, &req)
if err != nil {
// 错误已经在Service层完全包装好了,直接使用
var i18nErr *i18n.I18nError
if errors.As(err, &i18nErr) {
c.JSON(i18nErr.HttpCode, models.ErrorResponse{
Code: i18nErr.Code,
Message: i18nErr.Message,
Timestamp: time.Now().Format(time.RFC3339),
})
} else {
// 兜底:理论上不应该到这里,因为Service层应该返回I18nError
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
}
return
}
lang := middleware.GetLanguage(c)
successMessage := i18n.GetErrorMessage("000000", lang)
c.JSON(http.StatusOK, models.APIResponse{
Code: "000000",
Message: successMessage,
Data: data,
})
}
// DeleteAuthorizationCode 删除授权码
// @Summary 删除授权码
// @Description 删除指定的授权码(软删除)
// @Tags 授权码管理
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param id path string true "授权码ID"
// @Success 200 {object} models.APIResponse "删除成功"
// @Failure 400 {object} models.ErrorResponse "请求参数无效"
// @Failure 401 {object} models.ErrorResponse "未认证"
// @Failure 404 {object} models.ErrorResponse "授权码不存在"
// @Failure 500 {object} models.ErrorResponse "服务器内部错误"
// @Router /api/v1/authorization-codes/{id} [delete]
func (h *AuthorizationCodeHandler) DeleteAuthorizationCode(c *gin.Context) {
id := c.Param("id")
if id == "" {
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900001", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
return
}
// 设置语言到Context中
ctx := middleware.WithLanguage(c.Request.Context(), c)
err := h.authCodeService.DeleteAuthorizationCode(ctx, id)
if err != nil {
// 错误已经在Service层完全包装好了,直接使用
var i18nErr *i18n.I18nError
if errors.As(err, &i18nErr) {
c.JSON(i18nErr.HttpCode, models.ErrorResponse{
Code: i18nErr.Code,
Message: i18nErr.Message,
Timestamp: time.Now().Format(time.RFC3339),
})
} else {
// 兜底:理论上不应该到这里,因为Service层应该返回I18nError
lang := middleware.GetLanguage(c)
status, errCode, message := i18n.NewI18nErrorResponse("900004", lang)
c.JSON(status, models.ErrorResponse{
Code: errCode,
Message: message,
Timestamp: time.Now().Format(time.RFC3339),
})
}
return
}
lang := middleware.GetLanguage(c)
successMessage := i18n.GetErrorMessage("000000", lang)
c.JSON(http.StatusOK, models.APIResponse{
Code: "000000",
Message: successMessage,
Data: nil,
})
}
+4
View File
@@ -91,6 +91,10 @@ func SetupRouter() *gin.Engine {
// 授权码管理
auth.GET("/v1/authorization-codes", authCodeHandler.GetAuthorizationCodeList)
auth.POST("/v1/authorization-codes", authCodeHandler.CreateAuthorizationCode)
auth.GET("/v1/authorization-codes/:id", authCodeHandler.GetAuthorizationCode)
auth.PUT("/v1/authorization-codes/:id", authCodeHandler.UpdateAuthorizationCode)
auth.PUT("/v1/authorization-codes/:id/lock", authCodeHandler.LockUnlockAuthorizationCode)
auth.DELETE("/v1/authorization-codes/:id", authCodeHandler.DeleteAuthorizationCode)
}
// 管理员接口
+26 -3
View File
@@ -56,9 +56,9 @@ type AuthorizationCode struct {
LockReason *string `gorm:"type:text" json:"lock_reason"`
LockedAt *time.Time `gorm:"type:datetime(3)" json:"locked_at"`
LockedBy *string `gorm:"type:varchar(36)" json:"locked_by"`
FeatureConfig JSON `gorm:"type:json" json:"feature_config"`
UsageLimits JSON `gorm:"type:json" json:"usage_limits"`
CustomParameters JSON `gorm:"type:json" json:"custom_parameters"`
FeatureConfig JSON `gorm:"type:json" json:"feature_config" swaggertype:"object"`
UsageLimits JSON `gorm:"type:json" json:"usage_limits" swaggertype:"object"`
CustomParameters JSON `gorm:"type:json" json:"custom_parameters" swaggertype:"object"`
Status string `gorm:"-" json:"status,omitempty"`
StatusDisplay string `gorm:"-" json:"status_display,omitempty"`
CreatedAt time.Time `gorm:"type:datetime(3);not null" json:"created_at"`
@@ -152,4 +152,27 @@ type AuthorizationCodeListResponse struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
TotalPages int `json:"total_pages"`
}
// AuthorizationCodeUpdateRequest 更新授权码请求结构
type AuthorizationCodeUpdateRequest struct {
SoftwareID *string `json:"software_id" binding:"omitempty"`
Description *string `json:"description" binding:"omitempty,max=1000"`
ValidityDays *int `json:"validity_days" binding:"omitempty,min=1,max=36500"`
DeploymentType *string `json:"deployment_type" binding:"omitempty,oneof=standalone cloud hybrid"`
EncryptionType *string `json:"encryption_type" binding:"omitempty,oneof=standard advanced"`
SoftwareVersion *string `json:"software_version" binding:"omitempty"`
MaxActivations *int `json:"max_activations" binding:"omitempty,min=1"`
FeatureConfig interface{} `json:"feature_config" binding:"omitempty"`
UsageLimits interface{} `json:"usage_limits" binding:"omitempty"`
CustomParameters interface{} `json:"custom_parameters" binding:"omitempty"`
ChangeType string `json:"change_type" binding:"required,oneof=renewal upgrade limit_change feature_toggle lock unlock other"`
Reason *string `json:"reason" binding:"omitempty,max=500"`
}
// AuthorizationCodeLockRequest 锁定/解锁授权码请求结构
type AuthorizationCodeLockRequest struct {
IsLocked bool `json:"is_locked" binding:""` // true-锁定,false-解锁
LockReason *string `json:"lock_reason" binding:"omitempty,max=500"` // 锁定原因
Reason *string `json:"reason" binding:"omitempty,max=500"` // 变更原因(记录到变更历史)
}
+1
View File
@@ -7,6 +7,7 @@ import (
)
// JSON 类型用于GORM JSON字段
// swagger:type object
type JSON json.RawMessage
// 实现 driver.Valuer 接口
@@ -139,6 +139,16 @@ func (r *authorizationCodeRepository) GetAuthorizationCodeList(ctx context.Conte
}, nil
}
// UpdateAuthorizationCode 更新授权码
func (r *authorizationCodeRepository) UpdateAuthorizationCode(ctx context.Context, authCode *models.AuthorizationCode) error {
return r.db.WithContext(ctx).Save(authCode).Error
}
// DeleteAuthorizationCode 删除授权码(软删除)
func (r *authorizationCodeRepository) DeleteAuthorizationCode(ctx context.Context, id string) error {
return r.db.WithContext(ctx).Delete(&models.AuthorizationCode{}, "id = ?", id).Error
}
// CheckCustomerExists 检查客户是否存在
func (r *authorizationCodeRepository) CheckCustomerExists(ctx context.Context, customerID string) (bool, error) {
var count int64
@@ -58,6 +58,12 @@ type AuthorizationCodeRepository interface {
// GetAuthorizationCodeList 查询授权码列表
GetAuthorizationCodeList(ctx context.Context, req *models.AuthorizationCodeListRequest) (*models.AuthorizationCodeListResponse, error)
// UpdateAuthorizationCode 更新授权码
UpdateAuthorizationCode(ctx context.Context, authCode *models.AuthorizationCode) error
// DeleteAuthorizationCode 删除授权码(软删除)
DeleteAuthorizationCode(ctx context.Context, id string) error
// CheckCustomerExists 检查客户是否存在
CheckCustomerExists(ctx context.Context, customerID string) (bool, error)
}
@@ -4,6 +4,7 @@ import (
"context"
"crypto/rand"
"encoding/json"
"errors"
"fmt"
"strings"
"time"
@@ -45,7 +46,7 @@ func (s *authorizationCodeService) CreateAuthorizationCode(ctx context.Context,
// 业务逻辑:计算开始时间和结束时间
now := time.Now()
startDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) // 当天00:00:00开始
startDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) // 当天00:00:00开始
endDate := startDate.AddDate(0, 0, req.ValidityDays-1).Add(23*time.Hour + 59*time.Minute + 59*time.Second) // 有效期最后一天的23:59:59结束
// 获取当前用户ID
@@ -145,7 +146,7 @@ func (s *authorizationCodeService) GetAuthorizationCodeList(ctx context.Context,
for i := range result.List {
item := &result.List[i]
s.fillAuthCodeDisplayFields(item, lang, now)
// 根据状态筛选
if req.Status != "" && item.Status != req.Status {
// 移除不匹配的项 - 这里简化处理,实际应该在查询时过滤
@@ -156,11 +157,244 @@ func (s *authorizationCodeService) GetAuthorizationCodeList(ctx context.Context,
return result, nil
}
// GetAuthorizationCode 获取单个授权码详情
func (s *authorizationCodeService) GetAuthorizationCode(ctx context.Context, id string) (*models.AuthorizationCode, error) {
lang := pkgcontext.GetLanguageFromContext(ctx)
// 业务逻辑:参数验证
if id == "" {
return nil, i18n.NewI18nError("900001", lang)
}
// 委托给Repository层进行数据访问
authCode, err := s.authCodeRepo.GetAuthorizationCodeByID(ctx, id)
if err != nil {
// 根据Repository错误类型包装为完整的I18nError
if errors.Is(err, repository.ErrAuthorizationCodeNotFound) {
return nil, i18n.NewI18nError("300001", lang)
}
// 数据库相关错误
return nil, i18n.NewI18nError("900004", lang, err.Error())
}
// 填充多语言显示字段和计算状态
s.fillAuthorizationCodeDisplayFields(authCode, lang)
return authCode, nil
}
// fillAuthorizationCodeDisplayFields 填充完整授权码模型的多语言显示字段
func (s *authorizationCodeService) fillAuthorizationCodeDisplayFields(authCode *models.AuthorizationCode, lang string) {
// 计算状态
now := time.Now()
if authCode.IsLocked {
authCode.Status = "locked"
} else if now.After(authCode.EndDate) {
authCode.Status = "expired"
} else {
authCode.Status = "normal"
}
// 添加多语言显示字段
authCode.StatusDisplay = i18n.GetEnumMessage("authorization_status", authCode.Status, lang)
authCode.DeploymentTypeDisplay = i18n.GetEnumMessage("deployment_type", authCode.DeploymentType, lang)
if authCode.EncryptionType != nil {
authCode.EncryptionTypeDisplay = i18n.GetEnumMessage("encryption_type", *authCode.EncryptionType, lang)
}
// TODO: 统计当前激活数量
authCode.CurrentActivations = 0
// TODO: 获取客户名称
// 可以考虑在Repository层通过JOIN获取,或在这里单独查询
}
// UpdateAuthorizationCode 更新授权码
func (s *authorizationCodeService) UpdateAuthorizationCode(ctx context.Context, id string, req *models.AuthorizationCodeUpdateRequest) (*models.AuthorizationCode, error) {
lang := pkgcontext.GetLanguageFromContext(ctx)
// 业务逻辑:参数验证
if id == "" {
return nil, i18n.NewI18nError("900001", lang)
}
if req == nil {
return nil, i18n.NewI18nError("900001", lang)
}
// 先查询现有授权码
existingAuthCode, err := s.authCodeRepo.GetAuthorizationCodeByID(ctx, id)
if err != nil {
if errors.Is(err, repository.ErrAuthorizationCodeNotFound) {
return nil, i18n.NewI18nError("300001", lang)
}
return nil, i18n.NewI18nError("900004", lang, err.Error())
}
// 获取当前用户ID
// currentUserID := "admin_uuid" // TODO: 从JWT token中获取
// 只更新提供的字段
if req.SoftwareID != nil {
existingAuthCode.SoftwareID = req.SoftwareID
}
if req.Description != nil {
existingAuthCode.Description = req.Description
}
if req.ValidityDays != nil {
// 重新计算开始时间和结束时间
now := time.Now()
startDate := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
endDate := startDate.AddDate(0, 0, *req.ValidityDays-1).Add(23*time.Hour + 59*time.Minute + 59*time.Second)
existingAuthCode.StartDate = startDate
existingAuthCode.EndDate = endDate
}
if req.DeploymentType != nil {
existingAuthCode.DeploymentType = *req.DeploymentType
}
if req.EncryptionType != nil {
existingAuthCode.EncryptionType = req.EncryptionType
}
if req.SoftwareVersion != nil {
existingAuthCode.SoftwareVersion = req.SoftwareVersion
}
if req.MaxActivations != nil {
existingAuthCode.MaxActivations = *req.MaxActivations
}
// 处理JSON字段
if req.FeatureConfig != nil {
featureConfigBytes, err := json.Marshal(req.FeatureConfig)
if err != nil {
return nil, i18n.NewI18nError("300010", lang)
}
existingAuthCode.FeatureConfig = models.JSON(featureConfigBytes)
}
if req.UsageLimits != nil {
usageLimitsBytes, err := json.Marshal(req.UsageLimits)
if err != nil {
return nil, i18n.NewI18nError("300010", lang)
}
existingAuthCode.UsageLimits = models.JSON(usageLimitsBytes)
}
if req.CustomParameters != nil {
customParametersBytes, err := json.Marshal(req.CustomParameters)
if err != nil {
return nil, i18n.NewI18nError("300010", lang)
}
existingAuthCode.CustomParameters = models.JSON(customParametersBytes)
}
// 设置更新者 - 注意这里没有UpdatedBy字段,会通过BeforeUpdate钩子自动设置UpdatedAt
// existingAuthCode.UpdatedBy = &currentUserID // 如果表结构有这个字段的话
// 委托给Repository层进行数据更新
if err := s.authCodeRepo.UpdateAuthorizationCode(ctx, existingAuthCode); err != nil {
return nil, i18n.NewI18nError("900004", lang, err.Error())
}
// 填充多语言显示字段和计算状态
s.fillAuthorizationCodeDisplayFields(existingAuthCode, lang)
// TODO: 记录变更历史到 authorization_changes 表
// s.recordAuthorizationChange(ctx, id, req.ChangeType, req.Reason, currentUserID)
return existingAuthCode, nil
}
// LockUnlockAuthorizationCode 锁定/解锁授权码
func (s *authorizationCodeService) LockUnlockAuthorizationCode(ctx context.Context, id string, req *models.AuthorizationCodeLockRequest) (*models.AuthorizationCode, error) {
lang := pkgcontext.GetLanguageFromContext(ctx)
// 业务逻辑:参数验证
if id == "" {
return nil, i18n.NewI18nError("900001", lang)
}
if req == nil {
return nil, i18n.NewI18nError("900001", lang)
}
// 先查询现有授权码
existingAuthCode, err := s.authCodeRepo.GetAuthorizationCodeByID(ctx, id)
if err != nil {
if errors.Is(err, repository.ErrAuthorizationCodeNotFound) {
return nil, i18n.NewI18nError("300001", lang)
}
return nil, i18n.NewI18nError("900004", lang, err.Error())
}
// 获取当前用户ID
currentUserID := "admin_uuid" // TODO: 从JWT token中获取
// 更新锁定状态
now := time.Now()
existingAuthCode.IsLocked = req.IsLocked
if req.IsLocked {
// 锁定
existingAuthCode.LockReason = req.LockReason
existingAuthCode.LockedAt = &now
existingAuthCode.LockedBy = &currentUserID
} else {
// 解锁
existingAuthCode.LockReason = nil
existingAuthCode.LockedAt = nil
existingAuthCode.LockedBy = nil
}
// 委托给Repository层进行数据更新
if err := s.authCodeRepo.UpdateAuthorizationCode(ctx, existingAuthCode); err != nil {
return nil, i18n.NewI18nError("900004", lang, err.Error())
}
// 填充多语言显示字段和计算状态
s.fillAuthorizationCodeDisplayFields(existingAuthCode, lang)
// TODO: 记录变更历史到 authorization_changes 表
// changeType := "lock"
// if !req.IsLocked {
// changeType = "unlock"
// }
// s.recordAuthorizationChange(ctx, id, changeType, req.Reason, currentUserID)
return existingAuthCode, nil
}
// DeleteAuthorizationCode 删除授权码(软删除)
func (s *authorizationCodeService) DeleteAuthorizationCode(ctx context.Context, id string) error {
lang := pkgcontext.GetLanguageFromContext(ctx)
// 业务逻辑:参数验证
if id == "" {
return i18n.NewI18nError("900001", lang)
}
// 先查询现有授权码,确保存在
_, err := s.authCodeRepo.GetAuthorizationCodeByID(ctx, id)
if err != nil {
if errors.Is(err, repository.ErrAuthorizationCodeNotFound) {
return i18n.NewI18nError("300001", lang)
}
return i18n.NewI18nError("900004", lang, err.Error())
}
// 委托给Repository层进行软删除
if err := s.authCodeRepo.DeleteAuthorizationCode(ctx, id); err != nil {
return i18n.NewI18nError("900004", lang, err.Error())
}
// TODO: 记录变更历史到 authorization_changes 表
// currentUserID := "admin_uuid" // TODO: 从JWT token中获取
// s.recordAuthorizationChange(ctx, id, "delete", nil, currentUserID)
return nil
}
// fillAuthCodeDisplayFields 填充授权码列表项多语言显示字段
func (s *authorizationCodeService) fillAuthCodeDisplayFields(item *models.AuthorizationCodeListItem, lang string, now time.Time) {
// 计算状态
endDate, _ := time.Parse("2006-01-02T15:04:05Z07:00", item.EndDate)
if item.IsLocked {
item.Status = "locked"
} else if now.After(endDate) {
+4
View File
@@ -38,4 +38,8 @@ type EnumService interface {
type AuthorizationCodeService interface {
CreateAuthorizationCode(ctx context.Context, req *models.AuthorizationCodeCreateRequest) (*models.AuthorizationCodeCreateResponse, error)
GetAuthorizationCodeList(ctx context.Context, req *models.AuthorizationCodeListRequest) (*models.AuthorizationCodeListResponse, error)
GetAuthorizationCode(ctx context.Context, id string) (*models.AuthorizationCode, error)
UpdateAuthorizationCode(ctx context.Context, id string, req *models.AuthorizationCodeUpdateRequest) (*models.AuthorizationCode, error)
LockUnlockAuthorizationCode(ctx context.Context, id string, req *models.AuthorizationCodeLockRequest) (*models.AuthorizationCode, error)
DeleteAuthorizationCode(ctx context.Context, id string) error
}