初始化项目

This commit is contained in:
2025-12-10 15:41:52 +08:00
parent 339dd97f66
commit 232009bbc2
25 changed files with 419 additions and 467 deletions

View File

@@ -19,24 +19,23 @@ var (
type applicationService struct{}
// CreateApplication 创建应用
func (s *applicationService) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (id int64, err error) {
func (s *applicationService) CreateApplication(ctx context.Context, req *dto.CreateApplicationReq) (id string, err error) {
// 检查应用名称是否已存在
existingApp, err := dao.Application.GetByName(ctx, req.Name)
if err != nil {
return 0, err
return "", err
}
if existingApp != nil {
return 0, gerror.New("应用名称已存在")
return "", gerror.New("应用名称已存在")
}
// 生成API密钥
appKey, appSecret, err := s.generateAPIKeys()
if err != nil {
return 0, err
return "", err
}
application := &entity.Application{
TenantId: req.TenantID,
Name: req.Name,
Code: req.Code,
Description: req.Description,
@@ -56,7 +55,7 @@ func (s *applicationService) CreateApplication(ctx context.Context, req *dto.Cre
}
// UpdateApplication 更新应用
func (s *applicationService) UpdateApplication(ctx context.Context, id int64, req *dto.UpdateApplicationReq) (affected int64, err error) {
func (s *applicationService) UpdateApplication(ctx context.Context, id string, req *dto.UpdateApplicationReq) (affected int64, err error) {
// 检查应用是否存在
existingApp, err := dao.Application.GetByID(ctx, id)
if err != nil {
@@ -116,17 +115,7 @@ func (s *applicationService) UpdateApplication(ctx context.Context, id int64, re
}
// GetApplicationsByTenant 获取租户下的应用列表
func (s *applicationService) GetApplicationsByTenant(ctx context.Context, tenantID int64, platform, status string, page, size int) (list []*entity.Application, total int64, err error) {
// 构建过滤条件
filter := make(map[string]interface{})
filter["tenant_id"] = tenantID
if platform != "" {
filter["platform"] = platform
}
if status != "" {
filter["status"] = status
}
func (s *applicationService) GetApplicationsByTenant(ctx context.Context, tenantID string, platform, status string, page, size int) (list []*entity.Application, total int64, err error) {
// 调用DAO的GetByTenantID方法获取租户下的所有应用
apps, err := dao.Application.GetByTenantID(ctx, tenantID)
if err != nil {
@@ -164,12 +153,12 @@ func (s *applicationService) GetApplicationByKey(ctx context.Context, appKey str
}
// GetApplicationByID 根据ID获取应用
func (s *applicationService) GetApplicationByID(ctx context.Context, id int64) (application *entity.Application, err error) {
func (s *applicationService) GetApplicationByID(ctx context.Context, id string) (application *entity.Application, err error) {
return dao.Application.GetByID(ctx, id)
}
// DeleteApplication 删除应用
func (s *applicationService) DeleteApplication(ctx context.Context, id int64) (affected int64, err error) {
func (s *applicationService) DeleteApplication(ctx context.Context, id string) (affected int64, err error) {
err = dao.Application.Delete(ctx, id)
if err != nil {
return 0, err
@@ -216,7 +205,7 @@ func (s *applicationService) generateAPIKeys() (appKey, appSecret string, err er
}
// ResetAPIKeys 重置API密钥
func (s *applicationService) ResetAPIKeys(ctx context.Context, id int64) (appKey, appSecret string, err error) {
func (s *applicationService) ResetAPIKeys(ctx context.Context, id string) (appKey, appSecret string, err error) {
// 检查应用是否存在
existingApp, err := dao.Application.GetByID(ctx, id)
if err != nil {