75 lines
1.3 KiB
Go
75 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"time"
|
|
"yintai-api/app/admin/request"
|
|
"yintai-api/app/common/dao"
|
|
err2 "yintai-api/app/common/err"
|
|
"yintai-api/app/common/model"
|
|
|
|
"github.com/spf13/cast"
|
|
)
|
|
|
|
type Config struct{}
|
|
|
|
func (r *Config) Create(req request.ConfigCreate) int64 {
|
|
m := new(model.Config)
|
|
m.CreateTime = time.Now().Unix()
|
|
if err := dao.NewConfig().Create(m); err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
return m.ID
|
|
}
|
|
|
|
func (r *Config) Update(req request.ConfigUpdate) {
|
|
m, err := dao.NewConfig().Get(cast.ToInt64(req.ID))
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
if m == nil {
|
|
err2.NotEsxErr()
|
|
return
|
|
}
|
|
|
|
m.UpdateTime = time.Now().Unix()
|
|
if err = dao.NewConfig().Update(m); err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
func (r *Config) Delete(req request.ConfigDelete) {
|
|
m, err := dao.NewConfig().Get(cast.ToInt64(req.ID))
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
if m == nil {
|
|
err2.NotEsxErr()
|
|
return
|
|
}
|
|
|
|
if err = dao.NewConfig().Delete(m.ID); err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (r *Config) List(req request.ConfigList) (any, int64) {
|
|
req.Pagination()
|
|
lists, count, err := dao.NewConfig().List(req.Page, req.Size, req.Sort)
|
|
if err != nil {
|
|
err2.DbErr(err)
|
|
}
|
|
|
|
res := make([]map[string]any, 0)
|
|
for _, list := range lists {
|
|
res = append(res, list.Format())
|
|
}
|
|
|
|
return res, count
|
|
}
|