182 lines
6.3 KiB
Go
182 lines
6.3 KiB
Go
package sys
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"hotgo/internal/library/maoyuadmin"
|
|
"hotgo/internal/model/input/sysin"
|
|
"hotgo/internal/service"
|
|
)
|
|
|
|
// 毛隅萌宠管理:互动动作配置(新增/编辑/启用停用)、宠物档案(只读)、场景生成任务(只读)、互动通知(只读)。
|
|
|
|
func init() { service.RegisterSysMaoyuPet(NewSysMaoyuPet()) }
|
|
|
|
type sSysMaoyuPet struct{}
|
|
|
|
func NewSysMaoyuPet() *sSysMaoyuPet { return &sSysMaoyuPet{} }
|
|
|
|
func (s *sSysMaoyuPet) ActionConfigList(ctx context.Context, in *sysin.MaoyuActionConfigListInp) (list []*sysin.MaoyuActionConfigListModel, totalCount int, err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
normalizeCultivatePage(&in.PageReq)
|
|
values := cultivatePageValues(in.Page, in.PerPage)
|
|
cultivateSetQuery(values, "keyword", in.Keyword)
|
|
cultivateSetQuery(values, "status", in.Status)
|
|
cultivateSetQuery(values, "version", in.Version)
|
|
setTimeRange(values, in.CreatedAt)
|
|
var page maoyuadmin.Page[*sysin.MaoyuActionConfigListModel]
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/action-configs", values, &page); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if page.Items == nil {
|
|
page.Items = []*sysin.MaoyuActionConfigListModel{}
|
|
}
|
|
return page.Items, page.Total, nil
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) ActionConfigView(ctx context.Context, in *sysin.MaoyuActionConfigViewInp) (*sysin.MaoyuActionConfigViewModel, error) {
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := new(sysin.MaoyuActionConfigViewModel)
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/action-configs/"+url.PathEscape(in.Id), nil, result); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) ActionConfigEdit(ctx context.Context, in *sysin.MaoyuActionConfigEditInp) error {
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
body := map[string]any{
|
|
"action_name": in.ActionName, "daily_limit": in.DailyLimit, "cooldown_seconds": in.CooldownSeconds,
|
|
"mutex_group": in.MutexGroup, "asset_key": in.AssetKey, "effect_config": in.EffectConfig, "sort_no": in.SortNo,
|
|
}
|
|
if id := strings.TrimSpace(in.Id); id != "" {
|
|
return maoyuadmin.DefaultClient(ctx).Put(ctx, scope, "/action-configs/"+url.PathEscape(id), body, nil)
|
|
}
|
|
body["action_code"] = in.ActionCode
|
|
return maoyuadmin.DefaultClient(ctx).Post(ctx, scope, "/action-configs", body, nil)
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) ActionConfigStatus(ctx context.Context, in *sysin.MaoyuActionConfigStatusInp) error {
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return maoyuadmin.DefaultClient(ctx).Post(ctx, scope, "/action-configs/"+url.PathEscape(in.Id)+"/status", map[string]any{
|
|
"reason": strings.TrimSpace(in.Reason),
|
|
}, nil)
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) PetList(ctx context.Context, in *sysin.MaoyuPetListInp) (list []*sysin.MaoyuPetListModel, totalCount int, err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
normalizeCultivatePage(&in.PageReq)
|
|
values := cultivatePageValues(in.Page, in.PerPage)
|
|
cultivateSetQuery(values, "user_id", in.UserId)
|
|
cultivateSetQuery(values, "pet_type", in.PetType)
|
|
cultivateSetQuery(values, "status", in.Status)
|
|
cultivateSetQuery(values, "keyword", in.Keyword)
|
|
setTimeRange(values, in.CreatedAt)
|
|
var page maoyuadmin.Page[*sysin.MaoyuPetListModel]
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/pets", values, &page); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if page.Items == nil {
|
|
page.Items = []*sysin.MaoyuPetListModel{}
|
|
}
|
|
return page.Items, page.Total, nil
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) PetView(ctx context.Context, in *sysin.MaoyuPetViewInp) (*sysin.MaoyuPetViewModel, error) {
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := new(sysin.MaoyuPetViewModel)
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/pets/"+url.PathEscape(in.Id), nil, result); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) JobList(ctx context.Context, in *sysin.MaoyuJobListInp) (list []*sysin.MaoyuJobListModel, totalCount int, err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
normalizeCultivatePage(&in.PageReq)
|
|
values := cultivatePageValues(in.Page, in.PerPage)
|
|
cultivateSetQuery(values, "pet_id", in.PetId)
|
|
cultivateSetQuery(values, "user_id", in.UserId)
|
|
cultivateSetQuery(values, "status", in.Status)
|
|
cultivateSetQuery(values, "error_code", in.ErrorCode)
|
|
setTimeRange(values, in.CreatedAt)
|
|
var page maoyuadmin.Page[*sysin.MaoyuJobListModel]
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/generation-jobs", values, &page); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if page.Items == nil {
|
|
page.Items = []*sysin.MaoyuJobListModel{}
|
|
}
|
|
return page.Items, page.Total, nil
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) JobView(ctx context.Context, in *sysin.MaoyuJobViewInp) (*sysin.MaoyuJobViewModel, error) {
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
result := new(sysin.MaoyuJobViewModel)
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/generation-jobs/"+url.PathEscape(in.Id), nil, result); err != nil {
|
|
return nil, err
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *sSysMaoyuPet) NoticeList(ctx context.Context, in *sysin.MaoyuNoticeListInp) (list []*sysin.MaoyuNoticeListModel, totalCount int, err error) {
|
|
if err = in.Filter(ctx); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
scope, err := maoyuAdminScope(ctx)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
normalizeCultivatePage(&in.PageReq)
|
|
values := cultivatePageValues(in.Page, in.PerPage)
|
|
cultivateSetQuery(values, "recipient_id", in.RecipientId)
|
|
cultivateSetQuery(values, "actor_id", in.ActorId)
|
|
cultivateSetQuery(values, "event_type", in.EventType)
|
|
cultivateSetQuery(values, "status", in.Status)
|
|
cultivateSetQuery(values, "post_id", in.PostId)
|
|
setTimeRange(values, in.CreatedAt)
|
|
var page maoyuadmin.Page[*sysin.MaoyuNoticeListModel]
|
|
if err = maoyuadmin.DefaultClient(ctx).Get(ctx, scope, "/interaction-notices", values, &page); err != nil {
|
|
return nil, 0, err
|
|
}
|
|
if page.Items == nil {
|
|
page.Items = []*sysin.MaoyuNoticeListModel{}
|
|
}
|
|
return page.Items, page.Total, nil
|
|
}
|