feat: 添加毛隅管理模块的后台接口与菜单权限
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
package sys
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
|
||||
"hotgo/internal/library/contexts"
|
||||
"hotgo/internal/library/maoyuadmin"
|
||||
"hotgo/internal/model/input/sysin"
|
||||
"hotgo/internal/service"
|
||||
)
|
||||
|
||||
// 毛隅内容治理:概览、动态/评论审核、举报、操作日志。
|
||||
// 与养成内容治理同一套页面协议,业务数据经 maoyu-server 内部接口处理,Manager 不直连毛隅业务库。
|
||||
|
||||
func init() { service.RegisterSysMaoyuContent(NewSysMaoyuContent()) }
|
||||
|
||||
type sSysMaoyuContent struct{}
|
||||
|
||||
func NewSysMaoyuContent() *sSysMaoyuContent { return &sSysMaoyuContent{} }
|
||||
|
||||
// maoyuAdminScope 从管理员登录态构造毛隅内部接口调用范围。
|
||||
func maoyuAdminScope(ctx context.Context) (maoyuadmin.Scope, error) {
|
||||
tenant, err := resolveImAdminTenant(ctx, cultivateTenantID(ctx))
|
||||
if err != nil {
|
||||
return maoyuadmin.Scope{}, err
|
||||
}
|
||||
operatorID := contexts.GetUserId(ctx)
|
||||
if operatorID <= 0 {
|
||||
return maoyuadmin.Scope{}, gerror.New("当前管理员身份无效")
|
||||
}
|
||||
return maoyuadmin.Scope{
|
||||
TenantID: tenant.Id, TenantCode: tenant.Code, OperatorID: operatorID,
|
||||
RoleKey: contexts.GetRoleKey(ctx), RequestID: gctx.CtxId(ctx),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) client(ctx context.Context) *maoyuadmin.Client {
|
||||
return maoyuadmin.DefaultClient(ctx)
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) Dashboard(ctx context.Context, _ *sysin.MaoyuDashboardInp) (*sysin.MaoyuDashboardModel, error) {
|
||||
scope, err := maoyuAdminScope(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := new(sysin.MaoyuDashboardModel)
|
||||
if err = s.client(ctx).Get(ctx, scope, "/dashboard", nil, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) List(ctx context.Context, in *sysin.CultivateContentListInp) (list []*sysin.CultivateContentListModel, 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, "object_type", in.ObjectType)
|
||||
cultivateSetQuery(values, "author_id", in.AuthorId)
|
||||
cultivateSetQuery(values, "status", in.Status)
|
||||
cultivateSetQuery(values, "keyword", strings.TrimSpace(in.Keyword))
|
||||
setTimeRange(values, in.CreatedAt)
|
||||
var page maoyuadmin.Page[*sysin.CultivateContentListModel]
|
||||
if err = s.client(ctx).Get(ctx, scope, "/content-reviews", values, &page); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if page.Items == nil {
|
||||
page.Items = []*sysin.CultivateContentListModel{}
|
||||
}
|
||||
return page.Items, page.Total, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) View(ctx context.Context, in *sysin.CultivateContentViewInp) (*sysin.CultivateContentViewModel, error) {
|
||||
if err := in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
scope, err := maoyuAdminScope(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := new(sysin.CultivateContentViewModel)
|
||||
path := "/content-reviews/" + url.PathEscape(in.ObjectType) + "/" + url.PathEscape(in.Id)
|
||||
if err = s.client(ctx).Get(ctx, scope, path, nil, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) Review(ctx context.Context, in *sysin.CultivateContentReviewInp) error {
|
||||
if err := in.Filter(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
scope, err := maoyuAdminScope(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
path := "/content-reviews/" + url.PathEscape(in.ObjectType) + "/" + url.PathEscape(in.Id) + "/actions"
|
||||
return s.client(ctx).Post(ctx, scope, path, map[string]any{"action": in.Action, "reason": strings.TrimSpace(in.Reason)}, nil)
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) BatchReview(ctx context.Context, in *sysin.CultivateContentBatchReviewInp) (*sysin.CultivateContentBatchReviewModel, error) {
|
||||
if err := in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
scope, err := maoyuAdminScope(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := new(sysin.CultivateContentBatchReviewModel)
|
||||
err = s.client(ctx).Post(ctx, scope, "/content-reviews/batch-actions", map[string]any{
|
||||
"object_type": in.ObjectType, "ids": in.Ids, "action": in.Action, "reason": strings.TrimSpace(in.Reason),
|
||||
}, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) ReportList(ctx context.Context, in *sysin.CultivateReportListInp) (list []*sysin.CultivateReportListModel, 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, "object_type", in.ObjectType)
|
||||
cultivateSetQuery(values, "status", in.Status)
|
||||
cultivateSetQuery(values, "reporter_id", in.ReporterId)
|
||||
setTimeRange(values, in.CreatedAt)
|
||||
var page maoyuadmin.Page[*sysin.CultivateReportListModel]
|
||||
if err = s.client(ctx).Get(ctx, scope, "/reports", values, &page); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if page.Items == nil {
|
||||
page.Items = []*sysin.CultivateReportListModel{}
|
||||
}
|
||||
return page.Items, page.Total, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) ReportView(ctx context.Context, in *sysin.CultivateReportViewInp) (*sysin.CultivateReportViewModel, error) {
|
||||
if err := in.Filter(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
scope, err := maoyuAdminScope(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := new(sysin.CultivateReportViewModel)
|
||||
if err = s.client(ctx).Get(ctx, scope, "/reports/"+url.PathEscape(in.Id), nil, result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) ReportHandle(ctx context.Context, in *sysin.CultivateReportHandleInp) error {
|
||||
if err := in.Filter(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
scope, err := maoyuAdminScope(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return s.client(ctx).Post(ctx, scope, "/reports/"+url.PathEscape(in.Id)+"/actions", map[string]any{
|
||||
"action": in.Action, "handle_result": in.HandleResult, "content_action": in.ContentAction,
|
||||
"user_action": in.UserAction, "reason": in.Reason,
|
||||
}, nil)
|
||||
}
|
||||
|
||||
func (s *sSysMaoyuContent) LogList(ctx context.Context, in *sysin.CultivateOperationLogListInp) (list []*sysin.CultivateOperationLogListModel, 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, "operator_id", in.OperatorId)
|
||||
cultivateSetQuery(values, "operation_type", in.OperationType)
|
||||
cultivateSetQuery(values, "target_type", in.TargetType)
|
||||
cultivateSetQuery(values, "target_id", in.TargetId)
|
||||
cultivateSetQuery(values, "request_id", in.RequestId)
|
||||
setTimeRange(values, in.CreatedAt)
|
||||
var page maoyuadmin.Page[*sysin.CultivateOperationLogListModel]
|
||||
if err = s.client(ctx).Get(ctx, scope, "/operation-logs", values, &page); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if page.Items == nil {
|
||||
page.Items = []*sysin.CultivateOperationLogListModel{}
|
||||
}
|
||||
return page.Items, page.Total, nil
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user