This commit is contained in:
2026-08-16 01:19:10 +08:00
parent c4b114762b
commit c554152f4f
43 changed files with 1311 additions and 318 deletions
+15
View File
@@ -124,6 +124,21 @@ func (s *DictionaryService) DictionaryDetail(ctx context.Context, id uint) (*dto
}
return detailDTO(v), nil
}
func (s *DictionaryService) DictionaryPath(ctx context.Context, id uint) ([]*dto.DictionaryDetailResponse, error) {
path := make([]*dto.DictionaryDetailResponse, 0)
for id != 0 {
value, err := s.uc.FindDictionaryDetail(ctx, id)
if err != nil {
return nil, err
}
path = append([]*dto.DictionaryDetailResponse{detailDTO(value)}, path...)
if value.ParentID == nil {
break
}
id = *value.ParentID
}
return path, nil
}
func (s *DictionaryService) DictionaryTree(ctx context.Context, id uint, typ string) ([]*dto.DictionaryDetailResponse, error) {
items, err := s.uc.DictionaryDetailTree(ctx, id, typ)
if err != nil {
+4 -4
View File
@@ -29,10 +29,10 @@ type MediaCategoryResponse struct {
}
type StorageObjectResponse struct {
Name string `json:"name"`
Key string `json:"key"`
URL string `json:"url"`
Size int64 `json:"size"`
Key string `json:"Key"`
Size int64 `json:"Size"`
LastModified time.Time `json:"LastModified"`
ContentType string `json:"ContentType"`
}
type InitUploadResponse struct {
+4 -4
View File
@@ -15,10 +15,10 @@ type DepartmentListRequest struct {
Name string `json:"name"`
}
type DeleteDepartmentRequest struct {
ID uint `json:"ID"`
ID uint `json:"ID" form:"id"`
}
type SetDepartmentUsersRequest struct {
DepartmentID uint `json:"deptId"`
DepartmentID uint `json:"deptId" form:"deptId"`
UserIDs []uint `json:"userIds"`
}
type SetUserDepartmentsRequest struct {
@@ -60,10 +60,10 @@ type PositionListRequest struct {
Status *bool `json:"status"`
}
type DeletePositionRequest struct {
ID uint `json:"ID"`
ID uint `json:"ID" form:"id"`
}
type SetPositionUsersRequest struct {
PositionID uint `json:"positionId"`
PositionID uint `json:"positionId" form:"positionId"`
UserIDs []uint `json:"userIds"`
}
type SetUserPositionsRequest struct {
+12 -6
View File
@@ -87,13 +87,19 @@ func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, nam
return s.Templates(ctx, page, size, &biz.ExportTemplate{Name: name, TableName: tableName, TemplateID: templateID, StartCreatedAt: start, EndCreatedAt: end})
}
func exportDTO(v *biz.ExportTemplate) *dto.ExportTemplateResponse {
conditions := make([]dto.ExportConditionResponse, 0, len(v.Conditions))
for _, x := range v.Conditions {
conditions = append(conditions, dto.ExportConditionResponse{From: x.From, Column: x.Column, Operator: x.Operator})
var conditions []dto.ExportConditionResponse
if v.Conditions != nil {
conditions = make([]dto.ExportConditionResponse, 0, len(v.Conditions))
for _, x := range v.Conditions {
conditions = append(conditions, dto.ExportConditionResponse{From: x.From, Column: x.Column, Operator: x.Operator})
}
}
joins := make([]dto.ExportJoinResponse, 0, len(v.Joins))
for _, x := range v.Joins {
joins = append(joins, dto.ExportJoinResponse{Join: x.Join, Table: x.Table, On: x.On})
var joins []dto.ExportJoinResponse
if v.Joins != nil {
joins = make([]dto.ExportJoinResponse, 0, len(v.Joins))
for _, x := range v.Joins {
joins = append(joins, dto.ExportJoinResponse{Join: x.Join, Table: x.Table, On: x.On})
}
}
return &dto.ExportTemplateResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, DBName: v.DBName, Name: v.Name, TableName: v.TableName, TemplateID: v.TemplateID, TemplateInfo: v.TemplateInfo, SQL: v.SQL, ImportSQL: v.ImportSQL, Limit: v.Limit, Order: v.Order, Conditions: conditions, Joins: joins}
}
+24 -10
View File
@@ -6,7 +6,9 @@ import (
"errors"
"fmt"
"io"
"strconv"
"strings"
"time"
"github.com/xuri/excelize/v2"
)
@@ -59,7 +61,23 @@ func (s *ExportService) Export(ctx context.Context, tid string, params map[strin
for rowIndex, row := range rows {
for column, key := range keys {
cell, _ := excelize.CoordinatesToCellName(column+1, rowIndex+2)
_ = file.SetCellValue(sheet, cell, row[key])
lookup := strings.ReplaceAll(strings.ReplaceAll(key, `"`, ""), "`", "")
if len(template.Joins) > 0 {
if parts := strings.Split(lookup, " as "); len(parts) > 1 {
lookup = strings.TrimSpace(parts[1])
} else if parts = strings.Split(lookup, "."); len(parts) > 1 {
lookup = parts[1]
}
}
value := fmt.Sprintf("%v", row[lookup])
if timestamp, ok := row[lookup].(time.Time); ok {
value = timestamp.Format("2006-01-02 15:04:05")
}
if number, parseErr := strconv.ParseFloat(value, 64); parseErr == nil {
_ = file.SetCellValue(sheet, cell, number)
} else {
_ = file.SetCellValue(sheet, cell, value)
}
}
}
buffer, err := file.WriteToBuffer()
@@ -108,11 +126,7 @@ func (s *ExportService) Import(ctx context.Context, tid string, reader io.Reader
return err
}
defer file.Close()
sheets := file.GetSheetList()
if len(sheets) == 0 {
return errors.New("工作簿没有工作表")
}
rows, err := file.GetRows(sheets[0])
rows, err := file.GetRows("Sheet1")
if err != nil {
return err
}
@@ -128,6 +142,9 @@ func (s *ExportService) Import(ctx context.Context, tid string, reader io.Reader
reverse[labels[key]] = key
}
headers := rows[0]
for index := range headers {
headers[index] = strings.TrimSpace(headers[index])
}
items := make([]map[string]any, 0, len(rows)-1)
for _, row := range rows[1:] {
item := map[string]any{}
@@ -142,8 +159,5 @@ func (s *ExportService) Import(ctx context.Context, tid string, reader io.Reader
}
items = append(items, item)
}
if err = s.uc.ImportExportRows(ctx, template, items); err != nil {
return fmt.Errorf("导入失败: %w", err)
}
return nil
return s.uc.ImportExportRows(ctx, template, items)
}
+1 -1
View File
@@ -75,7 +75,7 @@ func (s *MediaService) Storage(ctx context.Context, prefix, cursor string, limit
}
out := make([]*dto.StorageObjectResponse, 0, len(items))
for _, v := range items {
out = append(out, &dto.StorageObjectResponse{Name: v.Name, Key: v.Path, URL: v.URL, Size: v.Size})
out = append(out, &dto.StorageObjectResponse{Key: v.Path, Size: v.Size, LastModified: v.LastModified, ContentType: v.ContentType})
}
return out, next, more, nil
}
+4 -4
View File
@@ -76,10 +76,10 @@ func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, sta
return out, total, nil
}
func (s *TaskService) Trigger(ctx context.Context, id uint) error { return s.uc.Trigger(ctx, id) }
func (s *TaskService) Reload(ctx context.Context) error { return s.uc.Reload(ctx) }
func (s *TaskService) Subscribe() chan []byte { return s.uc.Subscribe() }
func (s *TaskService) Unsubscribe(events chan []byte) { s.uc.Unsubscribe(events) }
func (s *TaskService) Trigger(ctx context.Context, id uint) error { return s.uc.Trigger(ctx, id) }
func (s *TaskService) Reload(ctx context.Context) error { return s.uc.Reload(ctx) }
func (s *TaskService) Subscribe(userID uint) chan []byte { return s.uc.Subscribe(userID) }
func (s *TaskService) Unsubscribe(userID uint, events chan []byte) { s.uc.Unsubscribe(userID, events) }
func (s *TaskService) RegisteredMethods() []*dto.TaskMethodResponse {
methods := biz.RegisteredTaskMethods()