This commit is contained in:
2025-03-28 17:51:34 +08:00
parent da612380e0
commit 5c8802d2f0
68 changed files with 3422 additions and 630 deletions

View File

@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"strconv"
"strings"
"time"
"management/internal/db/model/dto"
@@ -19,35 +18,25 @@ func ListCategoriesCondition(ctx context.Context, q dto.SearchDto) ([]*db.Catego
countArg := &db.CountCategoriesConditionParams{
IsStatus: q.SearchStatus != 9999,
Status: int16(q.SearchStatus),
IsParentID: q.SearchParentID != 0,
IsID: q.SearchID != 0,
ID: int32(q.SearchID),
IsParentID: q.SearchParentID != 0 && q.SearchParentID != 1,
ParentID: int32(q.SearchParentID),
Name: q.SearchName,
}
dataArg := &db.ListCategoriesConditionParams{
IsStatus: q.SearchStatus != 9999,
Status: int16(q.SearchStatus),
IsParentID: q.SearchParentID != 0,
IsID: q.SearchID != 0,
ID: int32(q.SearchID),
IsParentID: q.SearchParentID != 0 && q.SearchParentID != 1,
ParentID: int32(q.SearchParentID),
Name: q.SearchName,
Skip: (int32(q.Page) - 1) * int32(q.Rows),
Size: int32(q.Rows),
}
if len(q.SearchKey) > 0 {
switch strings.ToLower(q.SearchName) {
case "id":
id, err := strconv.Atoi(q.SearchKey)
if err == nil {
countArg.IsID = true
countArg.ID = int32(id)
dataArg.IsID = true
dataArg.ID = int32(id)
}
case "name":
countArg.Name = q.SearchKey
dataArg.Name = q.SearchKey
}
}
count, err := db.Engine.CountCategoriesCondition(ctx, countArg)
if err != nil {
return nil, 0, err
@@ -70,6 +59,15 @@ func DTreeCategory(ctx context.Context, id int32) ([]*dto.DTreeDto, error) {
return toDtree(id, all), nil
}
func XmSelectCategory(ctx context.Context, id int32) ([]*dto.XmSelectTreeDto, error) {
all, err := db.Engine.AllCategories(ctx)
if err != nil {
return nil, err
}
return toXmSelectTree(id, all), nil
}
func GetParentCategorySelectLetter(ctx context.Context, letter string) ([]*global.DataDict, error) {
all := AllCategories(ctx)
if len(all) == 0 {
@@ -178,6 +176,25 @@ func toDtree(parentId int32, data []*db.Category) []*dto.DTreeDto {
item.Last = !hasChildren(v.ID, data)
item.ParentId = strconv.FormatInt(int64(v.ParentID), 10)
item.Children = toDtree(v.ID, data)
if v.ParentID == 0 {
item.Spread = true
}
res = append(res, &item)
}
}
return res
}
func toXmSelectTree(parentId int32, data []*db.Category) []*dto.XmSelectTreeDto {
var res []*dto.XmSelectTreeDto
for _, v := range data {
if v.ParentID == parentId {
item := dto.XmSelectTreeDto{
Name: v.Name,
Value: strconv.FormatInt(int64(v.ID), 10),
Children: toXmSelectTree(v.ID, data),
}
res = append(res, &item)
}
}