优化结构

This commit is contained in:
Yvan
2026-08-21 10:13:27 +08:00
parent 80e62acf7d
commit 5a548e0725
36 changed files with 971 additions and 3321 deletions
@@ -0,0 +1,23 @@
package dto
import (
"encoding/json"
"kra/app/system/internal/biz"
)
type IntegrationConfigRequest struct {
Enabled bool `json:"enabled"`
Config json.RawMessage `json:"config"`
}
type IntegrationConfigResponse struct {
Kind string `json:"kind"`
Provider string `json:"provider"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
Configured bool `json:"configured"`
Config json.RawMessage `json:"config"`
Fields []biz.IntegrationConfigField `json:"fields"`
}
@@ -5,21 +5,6 @@ import (
"time"
)
type PaymentConfigRequest struct {
Provider string `json:"provider"`
Enabled bool `json:"enabled"`
Config json.RawMessage `json:"config"`
}
// PaymentConfigResponse is the transport representation returned by the
// payment configuration endpoint. Values are already masked by the usecase's
// repository boundary.
type PaymentConfigResponse struct {
Provider string `json:"provider"`
Enabled bool `json:"enabled"`
Config json.RawMessage `json:"config"`
}
type PaymentOrderListRequest struct {
Page int `form:"page"`
PageSize int `form:"pageSize"`
+2 -2
View File
@@ -96,8 +96,8 @@ type OperationRecordResponse = dto.OperationRecordResponse
type OperationRecordSearchRequest = dto.OperationRecordSearchRequest
type PaymentCallbackAck = dto.PaymentCallbackAck
type PaymentCallbackRequest = dto.PaymentCallbackRequest
type PaymentConfigRequest = dto.PaymentConfigRequest
type PaymentConfigResponse = dto.PaymentConfigResponse
type IntegrationConfigRequest = dto.IntegrationConfigRequest
type IntegrationConfigResponse = dto.IntegrationConfigResponse
type PaymentFulfillRequest = dto.PaymentFulfillRequest
type PaymentOrderListRequest = dto.PaymentOrderListRequest
type PaymentOrderResponse = dto.PaymentOrderResponse
@@ -0,0 +1,88 @@
package service
import (
"context"
"encoding/json"
"kra/app/system/internal/biz"
)
type IntegrationConfigService struct{ uc *biz.IntegrationConfigUsecase }
func NewIntegrationConfigService(uc *biz.IntegrationConfigUsecase) *IntegrationConfigService {
return &IntegrationConfigService{uc: uc}
}
func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*IntegrationConfigResponse, error) {
configs, err := s.uc.List(ctx, kind)
if err != nil {
return nil, err
}
byProvider := make(map[string]*biz.IntegrationConfig, len(configs))
for _, config := range configs {
if config != nil {
byProvider[config.Provider] = config
}
}
definitions := biz.IntegrationDefinitions(kind)
result := make([]*IntegrationConfigResponse, 0, len(definitions)+len(configs))
for _, definition := range definitions {
config, configured := byProvider[definition.Provider]
values := mergeConfigJSON(definition.Defaults, nil)
enabled := false
if configured {
values = mergeConfigJSON(definition.Defaults, config.Values)
enabled = config.Enabled
delete(byProvider, definition.Provider)
}
result = append(result, &IntegrationConfigResponse{Kind: definition.Kind, Provider: definition.Provider, Name: definition.Name, Description: definition.Description, Enabled: enabled, Configured: configured, Config: values, Fields: definition.Fields})
}
for _, config := range configs {
if _, exists := byProvider[config.Provider]; !exists {
continue
}
result = append(result, &IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values})
}
return result, nil
}
func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider string) (*IntegrationConfigResponse, error) {
config, err := s.uc.Find(ctx, kind, provider)
if err != nil {
return nil, err
}
definition, found := biz.IntegrationDefinition(config.Kind, config.Provider)
response := &IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values}
if found {
response.Name = definition.Name
response.Description = definition.Description
response.Fields = definition.Fields
response.Config = mergeConfigJSON(definition.Defaults, config.Values)
}
return response, nil
}
func (s *IntegrationConfigService) Save(ctx context.Context, kind, provider string, req *IntegrationConfigRequest) error {
if req == nil {
return s.uc.Save(ctx, nil)
}
return s.uc.Save(ctx, &biz.IntegrationConfig{Kind: kind, Provider: provider, Enabled: req.Enabled, Values: req.Config})
}
func (s *IntegrationConfigService) Delete(ctx context.Context, kind, provider string) error {
return s.uc.Delete(ctx, kind, provider)
}
func mergeConfigJSON(defaults map[string]any, raw json.RawMessage) json.RawMessage {
values := make(map[string]any, len(defaults))
for key, value := range defaults {
values[key] = value
}
stored := map[string]any{}
_ = json.Unmarshal(raw, &stored)
for key, value := range stored {
values[key] = value
}
encoded, _ := json.Marshal(values)
return encoded
}
-20
View File
@@ -10,26 +10,6 @@ import (
type PaymentService struct{ uc *biz.PaymentUsecase }
func NewPaymentService(uc *biz.PaymentUsecase) *PaymentService { return &PaymentService{uc: uc} }
func (s *PaymentService) Configs(ctx context.Context) ([]*PaymentConfigResponse, error) {
configs, err := s.uc.Configs(ctx)
if err != nil {
return nil, err
}
result := make([]*PaymentConfigResponse, 0, len(configs))
for _, config := range configs {
if config == nil {
continue
}
result = append(result, &PaymentConfigResponse{Provider: config.Provider, Enabled: config.Enabled, Config: config.Values})
}
return result, nil
}
func (s *PaymentService) SaveConfig(ctx context.Context, req *PaymentConfigRequest) error {
if req == nil {
return errors.New("支付配置请求为空")
}
return s.uc.SaveConfig(ctx, &biz.PaymentConfig{Provider: req.Provider, Enabled: req.Enabled, Values: req.Config})
}
func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*PaymentOrderResponse, error) {
order, err := s.uc.Order(ctx, provider, tradeNo)
if err != nil {
@@ -44,7 +44,8 @@ var apiMetadata = map[string]apiMetadataValue{
"GET /menu/getMenuRoles": {group: "菜单", description: "获取菜单关联角色列表"},
"GET /position/findPosition": {group: "岗位", description: "根据ID获取岗位"},
"GET /position/getPositionUsers": {group: "岗位", description: "获取岗位成员ID列表"},
"GET /payment/configs": {group: "支付", description: "获取支付渠道配置"},
"GET /integration/configs/:kind": {group: "集成配置", description: "按类型获取集成配置"},
"GET /integration/configs/:kind/:provider": {group: "集成配置", description: "获取指定集成配置"},
"GET /payment/orders": {group: "支付", description: "分页查询支付订单"},
"GET /securityConfig/getSecurityConfig": {group: "安全配置", description: "获取安全配置"},
"GET /sysDictionary/exportSysDictionary": {group: "系统字典", description: "导出字典JSON"},
@@ -127,7 +128,8 @@ var apiMetadata = map[string]apiMetadataValue{
"POST /menu/getMenuList": {group: "菜单", description: "分页获取基础menu列表"},
"POST /menu/setMenuRoles": {group: "菜单", description: "全量覆盖菜单关联角色列表"},
"POST /menu/updateBaseMenu": {group: "菜单", description: "更新菜单"},
"POST /payment/config": {group: "支付", description: "保存支付渠道配置"},
"PUT /integration/configs/:kind/:provider": {group: "集成配置", description: "保存集成配置"},
"DELETE /integration/configs/:kind/:provider": {group: "集成配置", description: "删除集成配置"},
"POST /payment/order": {group: "支付", description: "查询支付订单"},
"POST /position/createPosition": {group: "岗位", description: "创建岗位"},
"POST /position/getPositionList": {group: "岗位", description: "获取岗位列表"},
+1 -1
View File
@@ -3,4 +3,4 @@ package service
import "github.com/google/wire"
// ProviderSet is service providers.
var ProviderSet = wire.NewSet(NewAuthService, NewUserService, NewSystemConfigService, NewAuthorityService, NewPermissionService, NewAccessControlService, NewAPIService, NewMenuService, NewDepartmentService, NewPositionService, NewDictionaryService, NewParameterService, NewTokenService, NewSecurityService, NewVersionService, NewExportService, NewAuditService, NewAuditRecorder, NewLogViewerService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService, NewPaymentService)
var ProviderSet = wire.NewSet(NewAuthService, NewUserService, NewSystemConfigService, NewAuthorityService, NewPermissionService, NewAccessControlService, NewAPIService, NewMenuService, NewDepartmentService, NewPositionService, NewDictionaryService, NewParameterService, NewTokenService, NewSecurityService, NewVersionService, NewExportService, NewAuditService, NewAuditRecorder, NewLogViewerService, NewTaskService, NewMediaService, NewAnnouncementService, NewEmailService, NewPaymentService, NewIntegrationConfigService)