50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"yintai-api/app/api/request"
|
|
"yintai-api/app/common/consts"
|
|
"yintai-api/app/common/dao"
|
|
err2 "yintai-api/app/common/err"
|
|
|
|
"github.com/spf13/cast"
|
|
)
|
|
|
|
type Process struct{}
|
|
|
|
func (r *Process) List(req request.ProcessList2) (any, int64) {
|
|
req.Pagination()
|
|
lists, count, err := dao.NewProcess().List(req.Lang, req.Title, req.Content, req.ProcessTime, cast.ToInt64(req.CategoryID), req.Page, req.Size, req.Sort)
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
listLang := make([]string, 0)
|
|
for _, list := range lists {
|
|
listLang = append(listLang, fmt.Sprintf("%d_%s", list.ID, list.Lang))
|
|
}
|
|
|
|
res := make([]map[string]any, 0)
|
|
for _, list := range lists {
|
|
res = append(res, list.Format())
|
|
for _, lang := range consts.LangSupport {
|
|
lang = fmt.Sprintf("%d_%s", list.ID, list.Lang)
|
|
if slices.Contains(listLang, lang) {
|
|
continue
|
|
}
|
|
res = append(res, r.Get(lang, list.ID))
|
|
}
|
|
}
|
|
|
|
return res, count
|
|
}
|
|
|
|
func (r *Process) Get(lang string, id int64) map[string]any {
|
|
x, err := dao.NewProcess().GetLang(lang, id)
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
return x.Format()
|
|
}
|