115 lines
2.3 KiB
Go
115 lines
2.3 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"
|
|
"yintai-api/app/common/model"
|
|
|
|
"github.com/spf13/cast"
|
|
)
|
|
|
|
type Job struct{}
|
|
|
|
func (r *Job) List(req request.JobList2) (any, int64) {
|
|
req.Pagination()
|
|
lists, count, err := dao.NewJob().List(req.Lang, req.City, req.Title, req.Desc, req.Reqs, req.JobType, req.JobArea, req.JobUnit, 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 {
|
|
temp := list.Format()
|
|
temp["category"] = r.GetCate(list)[list.Lang]
|
|
res = append(res, temp)
|
|
|
|
for _, lang := range consts.LangSupport {
|
|
lang = fmt.Sprintf("%d_%s", list.ID, list.Lang)
|
|
if slices.Contains(listLang, lang) {
|
|
continue
|
|
}
|
|
|
|
temp = r.One(lang, list.ID)
|
|
temp["category"] = r.GetCate(list)[list.Lang]
|
|
res = append(res, temp)
|
|
}
|
|
}
|
|
|
|
return res, count
|
|
}
|
|
|
|
func (r *Job) One(lang string, id int64) map[string]any {
|
|
x, err := dao.NewJob().GetLang(id, lang)
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
return x.Format()
|
|
}
|
|
|
|
func (r *Job) Get(req request.JobDelete) any {
|
|
res := make([]map[string]any, 0)
|
|
for _, lang := range consts.LangSupport {
|
|
x, err := dao.NewJob().GetLang(cast.ToInt64(req.ID), lang)
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
if x == nil {
|
|
continue
|
|
}
|
|
|
|
format := x.Format()
|
|
format["category"] = r.GetCate(x)[x.Lang]
|
|
res = append(res, format)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func (r *Job) GetCate(params *model.JobPage) map[string]map[string]any {
|
|
// type:id
|
|
s := map[string]int64{
|
|
model.CateTypeJobType: params.JobType,
|
|
model.CateTypeJobArea: params.JobArea,
|
|
model.CateTypeJobUnit: params.JobUnit,
|
|
}
|
|
|
|
res := make(map[string]map[string]any)
|
|
|
|
for t, id := range s {
|
|
x, err := dao.NewCategory().GetWithType(id, t)
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
if x == nil {
|
|
x = new(model.Category)
|
|
}
|
|
|
|
for _, lang := range consts.LangSupport {
|
|
name := ""
|
|
switch lang {
|
|
case consts.LangZH:
|
|
name = x.Name
|
|
case consts.LangEN:
|
|
name = x.NameEn
|
|
}
|
|
if _, ok := res[lang]; !ok {
|
|
res[lang] = make(map[string]any)
|
|
}
|
|
|
|
res[lang][t] = x.ID
|
|
res[lang][t+"_name"] = name
|
|
}
|
|
}
|
|
|
|
return res
|
|
}
|