优化结构

This commit is contained in:
Yvan
2026-08-22 12:13:16 +08:00
parent d987244d0e
commit b27a66e9d3
200 changed files with 1794 additions and 1715 deletions
+10 -10
View File
@@ -3,21 +3,21 @@ package service
import (
"context"
"encoding/json"
"kra/internal/biz/system"
"time"
"kra/internal/biz"
"kra/internal/service/dto"
)
type TaskService struct {
uc *biz.TaskApplicationUsecase
uc *system.TaskApplicationUsecase
}
func NewTaskService(uc *biz.TaskApplicationUsecase) *TaskService {
func NewTaskService(uc *system.TaskApplicationUsecase) *TaskService {
return &TaskService{uc: uc}
}
func taskDomain(v *dto.TaskRequest) *biz.TimedTask {
return &biz.TimedTask{ID: v.ID, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: v.Params, HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: v.HTTPHeader, HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled}
func taskDomain(v *dto.TaskRequest) *system.TimedTask {
return &system.TimedTask{ID: v.ID, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: v.Params, HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: v.HTTPHeader, HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled}
}
func (s *TaskService) CreateRequest(ctx context.Context, req *dto.TaskRequest) (uint, error) {
value := taskDomain(req)
@@ -30,12 +30,12 @@ func (s *TaskService) UpdateRequest(ctx context.Context, req *dto.TaskRequest) e
return s.Update(ctx, taskDomain(req))
}
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool) ([]*dto.TaskResponse, int64, error) {
return s.Tasks(ctx, page, size, &biz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
return s.Tasks(ctx, page, size, &system.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
}
func (s *TaskService) Create(ctx context.Context, v *biz.TimedTask) error {
func (s *TaskService) Create(ctx context.Context, v *system.TimedTask) error {
return s.uc.Create(ctx, v)
}
func (s *TaskService) Update(ctx context.Context, v *biz.TimedTask) error {
func (s *TaskService) Update(ctx context.Context, v *system.TimedTask) error {
return s.uc.Update(ctx, v)
}
func (s *TaskService) Delete(ctx context.Context, id uint) error {
@@ -44,10 +44,10 @@ func (s *TaskService) Delete(ctx context.Context, id uint) error {
func (s *TaskService) Toggle(ctx context.Context, id uint, enabled bool) error {
return s.uc.Toggle(ctx, id, enabled)
}
func taskDTO(v *biz.TimedTask, next *time.Time) *dto.TaskResponse {
func taskDTO(v *system.TimedTask, next *time.Time) *dto.TaskResponse {
return &dto.TaskResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: json.RawMessage(v.Params), HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: json.RawMessage(v.HTTPHeader), HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled, NextRunAt: next}
}
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*dto.TaskResponse, int64, error) {
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *system.TimedTask) ([]*dto.TaskResponse, int64, error) {
items, total, next, err := s.uc.List(ctx, page, size, q)
if err != nil {
return nil, 0, err