作者 yangfu

app page

正在显示 36 个修改的文件 包含 2009 行增加2 行删除
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func CreateAppPageShareUrlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageCreateShareRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewCreateAppPageShareUrlLogic(r.Context(), svcCtx)
resp, err := l.CreateAppPageShareUrl(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func DeleteAppPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageDeleteRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewDeleteAppPageLogic(r.Context(), svcCtx)
resp, err := l.DeleteAppPage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func GetAppPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewGetAppPageLogic(r.Context(), svcCtx)
resp, err := l.GetAppPage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func GetAppPageShareDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetAppPageShareDetailRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewGetAppPageShareDetailLogic(r.Context(), svcCtx)
resp, err := l.GetAppPageShareDetail(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func SaveAppPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageSaveRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewSaveAppPageLogic(r.Context(), svcCtx)
resp, err := l.SaveAppPage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func SaveAsAppPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageSaveAsRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewSaveAsAppPageLogic(r.Context(), svcCtx)
resp, err := l.SaveAsAppPage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func SearchAppPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageSearchRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewSearchAppPageLogic(r.Context(), svcCtx)
resp, err := l.SearchAppPage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package page
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/logic/page"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
)
func UpdateAppPageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AppPageUpdateRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := page.NewUpdateAppPageLogic(r.Context(), svcCtx)
resp, err := l.UpdateAppPage(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -5,6 +5,7 @@ import (
"net/http"
chart "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/chart"
page "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/page"
table "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/table"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
... ... @@ -107,4 +108,57 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/app-page/:id",
Handler: page.GetAppPageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/app-page",
Handler: page.SaveAppPageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/app-page/saveas",
Handler: page.SaveAsAppPageHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/app-page/:id",
Handler: page.DeleteAppPageHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/app-page/:id",
Handler: page.UpdateAppPageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/app-page/search",
Handler: page.SearchAppPageHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/app-page/create-share",
Handler: page.CreateAppPageShareUrlHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.JwtAuth.AccessSecret),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/api/app-page/get-share-detail/:key",
Handler: page.GetAppPageShareDetailHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type CreateAppPageShareUrlLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCreateAppPageShareUrlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppPageShareUrlLogic {
return &CreateAppPageShareUrlLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CreateAppPageShareUrlLogic) CreateAppPageShareUrl(req *types.AppPageCreateShareRequest) (resp *types.AppPageCreateShareResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
)
if appPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.AppPageCreateShareResponse{}
if appPage.Key != "" {
return
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
appPage.Key = tool.Krand(18, tool.KC_RAND_KIND_ALL)
if appPage, err = l.svcCtx.AppPageRepository.UpdateWithVersion(l.ctx, conn, appPage); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建页面分享链接失败", err)
}
resp = &types.AppPageCreateShareResponse{
Key: appPage.Key,
}
return
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAppPageLogic {
return &DeleteAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteAppPageLogic) DeleteAppPage(req *types.AppPageDeleteRequest) (resp *types.AppPageDeleteResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
)
if appPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.AppPageDeleteResponse{}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if appPage, err = l.svcCtx.AppPageRepository.Delete(l.ctx, conn, appPage); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("删除页面失败", err)
}
return
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppPageLogic {
return &GetAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetAppPageLogic) GetAppPage(req *types.AppPageGetRequest) (resp *types.AppPageGetResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
charts []*domain.Chart
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
if appPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErr(err)
}
queryOptions := domain.IndexTenantId(tenantId)().WithKV("ids", appPage.Charts)
if _, charts, err = l.svcCtx.ChartRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.AppPageGetResponse{
AppPage: types.NewAppPageItem(appPage, charts),
}
return
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetAppPageShareDetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetAppPageShareDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAppPageShareDetailLogic {
return &GetAppPageShareDetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetAppPageShareDetailLogic) GetAppPageShareDetail(req *types.GetAppPageShareDetailRequest) (resp *types.GetAppPageShareDetailResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
charts []*domain.Chart
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
if appPage, err = l.svcCtx.AppPageRepository.FindOneByKey(l.ctx, conn, req.Key); err != nil {
return nil, xerr.NewErr(err)
}
queryOptions := domain.IndexTenantId(tenantId)().WithKV("ids", appPage.Charts)
if _, charts, err = l.svcCtx.ChartRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.GetAppPageShareDetailResponse{
AppPage: types.NewAppPageItem(appPage, charts),
}
return
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SaveAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSaveAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveAppPageLogic {
return &SaveAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *types.AppPageSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
appPage = &domain.AppPage{
Name: req.Name,
Charts: req.Charts,
TenantId: tenantId,
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if appPage, err = l.svcCtx.AppPageRepository.Insert(l.ctx, conn, appPage); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建页面失败", err)
}
resp = &types.AppPageSaveResponse{
Id: appPage.Id,
}
return
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SaveAsAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSaveAsAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveAsAppPageLogic {
return &SaveAsAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SaveAsAppPageLogic) SaveAsAppPage(req *types.AppPageSaveAsRequest) (resp *types.AppPageSaveAsResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
tenantId = contextdata.GetTenantFromCtx(l.ctx)
fromAppPage *domain.AppPage
)
if fromAppPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErr(err)
}
appPage = &domain.AppPage{
Name: req.Name,
Charts: fromAppPage.Charts,
TenantId: tenantId,
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if appPage, err = l.svcCtx.AppPageRepository.Insert(l.ctx, conn, appPage); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("创建页面失败", err)
}
resp = &types.AppPageSaveAsResponse{
Id: appPage.Id,
}
return
}
... ...
package page
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSearchAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchAppPageLogic {
return &SearchAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SearchAppPageLogic) SearchAppPage(req *types.AppPageSearchRequest) (resp *types.AppPageSearchResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPages []*domain.AppPage
charts []*domain.Chart
tenantId = contextdata.GetTenantFromCtx(l.ctx)
total int64
chartIds []int64
)
if total, appPages, err = l.svcCtx.AppPageRepository.Find(l.ctx, conn, domain.IndexTenantId(tenantId)().WithOffsetLimit(req.Page, req.Size)); err != nil {
return nil, xerr.NewErr(err)
}
lo.ForEach(appPages, func(item *domain.AppPage, index int) {
chartIds = append(chartIds, item.Charts...)
})
queryOptions := domain.IndexTenantId(tenantId)().WithKV("ids", chartIds)
if _, charts, err = l.svcCtx.ChartRepository.Find(l.ctx, conn, queryOptions); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.AppPageSearchResponse{
Total: total,
}
for _, page := range appPages {
resp.List = append(resp.List, types.NewAppPageItem(page, charts))
}
return
}
... ...
package page
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateAppPageLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUpdateAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAppPageLogic {
return &UpdateAppPageLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UpdateAppPageLogic) UpdateAppPage(req *types.AppPageUpdateRequest) (resp *types.AppPageUpdateResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
)
if appPage, err = l.svcCtx.AppPageRepository.FindOne(l.ctx, conn, req.Id); err != nil {
return nil, xerr.NewErr(err)
}
resp = &types.AppPageUpdateResponse{}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
appPage.Name = req.Name
appPage.Charts = req.Charts
if appPage, err = l.svcCtx.AppPageRepository.UpdateWithVersion(l.ctx, conn, appPage); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("更新页面失败", err)
}
return
}
... ...
... ... @@ -21,6 +21,7 @@ type ServiceContext struct {
RedisCache gzcache.GZCache
ChartRepository domain.ChartRepository
ChartSettingRepository domain.ChartSettingRepository
AppPageRepository domain.AppPageRepository
ByteMetadataService bytelib.ByteMetadataService
}
... ... @@ -38,6 +39,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
Redis: redis,
ChartRepository: repository.NewChartRepository(cache.NewCachedRepository(mlCache)),
ChartSettingRepository: repository.NewChartSettingRepository(cache.NewCachedRepository(mlCache)),
AppPageRepository: repository.NewAppPageRepository(cache.NewCachedRepository(mlCache)),
ByteMetadataService: bytelib.ByteMetadataService{
Service: gateway.NewService(c.ByteMetadata.Name, c.ByteMetadata.Host, c.ByteMetadata.Timeout),
... ...
... ... @@ -2,6 +2,7 @@ package types
import (
"github.com/jinzhu/copier"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
)
... ... @@ -32,3 +33,23 @@ func NewPropertyItem(property domain.ChartProperty) ChartProperty {
copier.Copy(&chartProperty, property)
return chartProperty
}
func NewAppPageItem(appPage *domain.AppPage, charts []*domain.Chart) AppPageItem {
chartsMap := lo.SliceToMap(charts, func(item *domain.Chart) (int64, *domain.Chart) {
return item.Id, item
})
item := AppPageItem{
Id: appPage.Id,
Name: appPage.Name,
}
for _, id := range appPage.Charts {
if v, ok := chartsMap[id]; ok {
item.Charts = append(item.Charts, AppPageChartItem{
ChartId: v.Id,
Name: v.Name,
Cover: v.Cover,
})
}
}
return item
}
... ...
... ... @@ -110,6 +110,20 @@ type ChartProperty struct {
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
Cover string `json:"cover,optional"` // 封面
Other Other `json:"other,optional"` // 其他额外配置
}
type Other struct {
Quarter *Quarter `json:"quarter,optional,omitempty"` // 四分图
}
type Quarter struct {
XAxisLabel string `json:"xAxisLabel"` // x轴标签名
XAxisLabelList []string `json:"xAxisLabelList"` // 标签名
YAxisLabel string `json:"yAxisLabel"` // x轴标签名
YAxisLabelList []string `json:"yAxisLabelList"` // 标签名
Area string `json:"area"` // 图形面积
SeriesList string `json:"seriesList"` // 图形系列
}
type Title struct {
... ... @@ -121,6 +135,7 @@ type Title struct {
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
}
type TableAbility struct {
... ... @@ -134,6 +149,9 @@ type Series struct {
DataSourceId int64 `json:"dataSourceId,optional,omitempty"` // 数据源ID(from值为ByteBank时有值)
CustomText string `json:"customText,optional,omitempty"` // 自定义数据文本(from值为User时有值)
MatchExpressions []Expression `json:"matchExpressions,optional,omitempty"` // 条件匹配表达式(总体指标)
TargetText string `json:"targetText,optional,omitempty"` // 指标名文本
TargetNum string `json:"targetNum,optional,omitempty"` // 指标数值
TargetUnit string `json:"targetUnit,optional,omitempty"` // 指标单位
}
type Expression struct {
... ... @@ -193,3 +211,85 @@ type SearchTableDataRequest struct {
type SearchTableDataResponse struct {
}
type AppPageGetRequest struct {
Id int64 `path:"id"`
}
type AppPageGetResponse struct {
AppPage AppPageItem `json:"page"`
}
type AppPageSaveRequest struct {
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"` // 图表
}
type AppPageSaveResponse struct {
Id int64 `json:"id"`
}
type AppPageSaveAsRequest struct {
Id int64 `json:"id"` // 页面ID
Name string `json:"name"` // 名称
}
type AppPageSaveAsResponse struct {
Id int64 `path:"id"`
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"` // 图表
}
type AppPageCreateShareRequest struct {
Id int64 `json:"id"` // 页面ID
}
type AppPageCreateShareResponse struct {
Key string `json:"key,optional"` // 分享,预览时绑定映射到Id
}
type AppPageDeleteRequest struct {
Id int64 `path:"id"` // 页面ID
}
type AppPageDeleteResponse struct {
}
type AppPageUpdateRequest struct {
Id int64 `path:"id"`
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"` // 图表
}
type AppPageUpdateResponse struct {
}
type AppPageSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
}
type AppPageSearchResponse struct {
List []AppPageItem `json:"list"`
Total int64 `json:"total"`
}
type AppPageItem struct {
Id int64 `json:"id,optional"` // 唯一标识
Name string `json:"name,optional"` // 名称
Charts []AppPageChartItem `json:"charts,optional"` // 图表
}
type AppPageChartItem struct {
ChartId int64 `json:"chartId"` // 图表ID
Name string `json:"name"` // 图表名称
Cover string `json:"cover"` // 图表封面
}
type GetAppPageShareDetailRequest struct {
Key string `path:"key"`
}
type GetAppPageShareDetailResponse struct {
AppPage AppPageItem `json:"page"`
}
... ...
syntax = "v1"
info(
title: "xx实例"
desc: "xx实例"
author: "author"
email: "email"
version: "v1"
)
@server(
prefix: app_page/v1
group: app_page
jwt: JwtAuth
)
service Core {
@handler getAppPage
post /app_page/:id (AppPageGetRequest) returns (AppPageGetResponse)
@handler saveAppPage
post /app_page (AppPageSaveRequest) returns (AppPageSaveResponse)
@handler deleteAppPage
delete /app_page/:id (AppPageDeleteRequest) returns (AppPageDeleteResponse)
@handler updateAppPage
put /app_page/:id (AppPageUpdateRequest) returns (AppPageUpdateResponse)
@handler searchAppPage
post /app_page/search (AppPageSearchRequest) returns (AppPageSearchResponse)
}
type (
AppPageGetRequest {
Id int64 `path:"id"`
}
AppPageGetResponse struct{
AppPage AppPageItem `json:"app_page"`
}
AppPageSaveRequest struct{
AppPage AppPageItem `json:"app_page"`
}
AppPageSaveResponse struct{}
AppPageDeleteRequest struct{
Id int64 `path:"id"`
}
AppPageDeleteResponse struct{}
AppPageUpdateRequest struct{
Id int64 `path:"id"`
AppPage AppPageItem `json:"app_page"`
}
AppPageUpdateResponse struct{}
AppPageSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
AppPageSearchResponse{
List []AppPageItem `json:"list"`
Total int64 `json:"total"`
}
AppPageItem struct{
}
)
... ...
syntax = "proto3";
option go_package ="./pb";
package pb;
message AppPageGetReq {
int64 Id = 1;
}
message AppPageGetResp{
AppPageItem User = 1;
}
message AppPageSaveReq {
}
message AppPageSaveResp{
}
message AppPageDeleteReq {
int64 Id = 1;
}
message AppPageDeleteResp{
}
message AppPageUpdateReq {
int64 Id = 1;
}
message AppPageUpdateResp{
}
message AppPageSearchReq {
int64 PageNumber = 1;
int64 PageSize = 2;
}
message AppPageSearchResp{
repeated AppPageItem List =1;
int64 Total =2;
}
message AppPageItem {
}
service AppPageService {
rpc AppPageGet(AppPageGetReq) returns(AppPageGetResp);
rpc AppPageSave(AppPageSaveReq) returns(AppPageSaveResp);
rpc AppPageDelete(AppPageDeleteReq) returns(AppPageDeleteResp);
rpc AppPageUpdate(AppPageUpdateReq) returns(AppPageUpdateResp);
rpc AppPageSearch(AppPageSearchReq) returns(AppPageSearchResp);
}
... ...
... ... @@ -9,5 +9,6 @@ func Migrate(db *gorm.DB) {
db.AutoMigrate(
&models.Chart{},
&models.ChartSetting{},
&models.AppPage{},
)
}
... ...
package models
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gorm.io/gorm"
"gorm.io/plugin/soft_delete"
)
type AppPage struct {
Id int64 // 唯一标识
Name string // 名称
Charts []int64 `gorm:"serializer:json"` // 图表
Key string // 分享,预览时绑定映射到Id
TenantId int64 // 租户ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
}
func (m *AppPage) TableName() string {
return "app_page"
}
func (m *AppPage) BeforeCreate(tx *gorm.DB) (err error) {
// m.CreatedAt = time.Now().Unix()
// m.UpdatedAt = time.Now().Unix()
return
}
func (m *AppPage) BeforeUpdate(tx *gorm.DB) (err error) {
// m.UpdatedAt = time.Now().Unix()
return
}
func (m *AppPage) CacheKeyFunc() string {
if m.Id == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}
func (m *AppPage) CacheKeyFuncByObject(obj interface{}) string {
if v, ok := obj.(*AppPage); ok {
return v.CacheKeyFunc()
}
return ""
}
func (m *AppPage) CachePrimaryKeyFunc() string {
if len(m.Key) == 0 {
return ""
}
return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), m.Key)
}
... ...
... ... @@ -15,6 +15,7 @@ type Chart struct {
Sort int `gorm:"index:idx_chart_t_pid_sort"` // 排序
Name string // 名称
Group string `gorm:"index:idx_chart_group"` // 分组
Cover string // 封面
ChartType string
TenantId int64 `gorm:"index:idx_chart_t_pid_sort"` // 租户ID
... ...
... ... @@ -17,6 +17,7 @@ type ChartSetting struct {
Title domain.Title `gorm:"serializer:json"`
TableAbility domain.TableAbility `gorm:"serializer:json"` // 表格能力
Series []domain.Series `gorm:"serializer:json"` // 系列值-数据绑定
Other domain.Other `gorm:"serializer:json"`
TenantId int64 `gorm:"index:idx_chart_setting_t_id"` // 租户ID
CreatedAt int64 `json:",omitempty"`
... ...
package repository
import (
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"github.com/tiptok/gocomm/pkg/cache"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/models"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"gorm.io/gorm"
)
type AppPageRepository struct {
*cache.CachedRepository
}
func (repository *AppPageRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.AppPage) (*domain.AppPage, error) {
var (
err error
m = &models.AppPage{}
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
if tx = tx.Model(m).Save(m); tx.Error != nil {
return nil, tx.Error
}
dm.Id = m.Id
return repository.ModelToDomainModel(m)
}
func (repository *AppPageRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.AppPage) (*domain.AppPage, error) {
var (
err error
m *models.AppPage
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Updates(m)
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *AppPageRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.AppPage) (*domain.AppPage, error) {
var (
err error
m *models.AppPage
tx = transaction.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return nil, err
}
oldVersion := dm.Version
m.Version += 1
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m)
if tx.RowsAffected == 0 {
return nil, domain.ErrUpdateFail
}
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *AppPageRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.AppPage) (*domain.AppPage, error) {
var (
tx = conn.DB()
m = &models.AppPage{Id: dm.Identify().(int64)}
)
queryFunc := func() (interface{}, error) {
tx = tx.Where("id = ?", m.Id).Delete(m)
return m, tx.Error
}
if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return dm, err
}
return repository.ModelToDomainModel(m)
}
func (repository *AppPageRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.AppPage, error) {
var (
err error
tx = conn.DB()
m = new(models.AppPage)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("id = ?", id).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.AppPage)
cacheModel.Id = id
if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *AppPageRepository) FindOneByKey(ctx context.Context, conn transaction.Conn, key string) (*domain.AppPage, error) {
var (
err error
tx = conn.DB()
m = new(models.AppPage)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("key = ?", key).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
cacheModel := new(models.AppPage)
cacheModel.Key = key
if err = repository.QueryUniqueIndexCache(cacheModel.CachePrimaryKeyFunc, m, m.CacheKeyFuncByObject, queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *AppPageRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.AppPage, error) {
var (
tx = conn.DB()
ms []*models.AppPage
dms = make([]*domain.AppPage, 0)
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
return dms, nil
}
if _, err := repository.Query(queryFunc); err != nil {
return 0, nil, err
}
for _, item := range ms {
if dm, err := repository.ModelToDomainModel(item); err != nil {
return 0, dms, err
} else {
dms = append(dms, dm)
}
}
return total, dms, nil
}
func (repository *AppPageRepository) ModelToDomainModel(from *models.AppPage) (*domain.AppPage, error) {
to := &domain.AppPage{}
err := copier.Copy(to, from)
return to, err
}
func (repository *AppPageRepository) DomainModelToModel(from *domain.AppPage) (*models.AppPage, error) {
to := &models.AppPage{}
err := copier.Copy(to, from)
return to, err
}
func NewAppPageRepository(cache *cache.CachedRepository) domain.AppPageRepository {
return &AppPageRepository{CachedRepository: cache}
}
... ...
... ... @@ -120,6 +120,9 @@ func (repository *ChartRepository) Find(ctx context.Context, conn transaction.Co
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc") //.Order("pid asc").Order("sort asc")
if v, ok := queryOptions["ids"]; ok {
tx.Where("id in (?)", v)
}
if v, ok := queryOptions["tenantId"]; ok {
tx.Where("tenant_id = ?", v)
}
... ...
package domain
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db/transaction"
)
type AppPage struct {
Id int64 // 唯一标识
Name string // 名称
Charts []int64 // 图表
Key string // 分享,预览时绑定映射到Id
TenantId int64 // 租户ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
}
type AppPageRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *AppPage) (*AppPage, error)
Update(ctx context.Context, conn transaction.Conn, dm *AppPage) (*AppPage, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *AppPage) (*AppPage, error)
Delete(ctx context.Context, conn transaction.Conn, dm *AppPage) (*AppPage, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*AppPage, error)
FindOneByKey(ctx context.Context, conn transaction.Conn, key string) (*AppPage, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*AppPage, error)
}
func (m *AppPage) Identify() interface{} {
if m.Id == 0 {
return nil
}
return m.Id
}
... ...
... ... @@ -19,10 +19,21 @@ type ChartProperty struct {
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
Cover string `json:"cover,optional"` // 封面
Other Other `json:"other,optional"` // 其他额外配置
//XAxis interface{} `json:"xAxis"` // X轴
//YAxis interface{} `json:"yAxis"` // Y轴
}
type Other struct {
Quarter *Quarter `json:"quarter,optional,omitempty"` // 四分图
}
type Quarter struct {
XAxisLabel string `json:"xAxisLabel"` // x轴标签名
XAxisLabelList []string `json:"xAxisLabelList"` // 标签名
YAxisLabel string `json:"yAxisLabel"` // x轴标签名
YAxisLabelList []string `json:"yAxisLabelList"` // 标签名
Area string `json:"area"` // 图形面积
SeriesList string `json:"seriesList"` // 图形系列
}
type Title struct {
TitleSwitch bool `json:"titleSwitch,optional"` // 组件标题开关
IntroduceSwitch bool `json:"introduceSwitch,optional"` // 组件说明开关
... ... @@ -32,6 +43,7 @@ type Title struct {
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
}
type TableAbility struct {
... ... @@ -46,6 +58,9 @@ type Series struct {
DataSourceId int64 `json:"dataSourceId,optional,omitempty"` // 数据源ID(from值为ByteBank时有值)
CustomText string `json:"customText,optional,omitempty"` // 自定义数据文本(from值为User时有值)
MatchExpressions []Expression `json:"matchExpressions,omitempty"` // 条件匹配表达式(总体指标)
TargetText string `json:"targetText,optional,omitempty"` // 指标名文本
TargetNum string `json:"targetNum,optional,omitempty"` // 指标数值
TargetUnit string `json:"targetUnit,optional,omitempty"` // 指标单位
}
type Expression struct {
... ...
... ... @@ -14,6 +14,7 @@ type ChartSetting struct {
Title Title
TableAbility TableAbility // 表格能力
Series []Series // 系列值-数据绑定
Other Other
TenantId int64 // 租户ID
CreatedAt int64 `json:",omitempty"`
... ... @@ -44,5 +45,6 @@ func (m *ChartSetting) ChartProperty(cover string) ChartProperty {
TableAbility: m.TableAbility,
Series: m.Series,
Cover: cover,
Other: m.Other,
}
}
... ...
import "core/chart.api"
import "core/table.api"
import "core/app_page.api"
// import "./core/chart_stting.api"
\ No newline at end of file
... ...
... ... @@ -15,6 +15,234 @@
"application/json"
],
"paths": {
"v1/api/app-page/get-share-detail/{key}": {
"get": {
"summary": "开放接口-获取应用页详情通过KEY",
"operationId": "getAppPageShareDetail",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/GetAppPageShareDetailResponse"
}
}
},
"parameters": [
{
"name": "key",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"page"
]
}
},
"v1/app-page": {
"post": {
"summary": "保存应用页",
"operationId": "saveAppPage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageSaveResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AppPageSaveRequest"
}
}
],
"requestBody": {},
"tags": [
"page"
]
}
},
"v1/app-page/create-share": {
"post": {
"summary": "创建应用页分享",
"operationId": "createAppPageShareUrl",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageCreateShareResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AppPageCreateShareRequest"
}
}
],
"requestBody": {},
"tags": [
"page"
]
}
},
"v1/app-page/saveas": {
"post": {
"summary": "应用页另存为",
"operationId": "saveAsAppPage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageSaveAsResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AppPageSaveAsRequest"
}
}
],
"requestBody": {},
"tags": [
"page"
]
}
},
"v1/app-page/search": {
"post": {
"summary": "搜索",
"operationId": "searchAppPage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageSearchResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AppPageSearchRequest"
}
}
],
"requestBody": {},
"tags": [
"page"
]
}
},
"v1/app-page/{id}": {
"get": {
"summary": "获取应用页详情",
"operationId": "getAppPage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"requestBody": {},
"tags": [
"page"
]
},
"delete": {
"summary": "删除应用页",
"operationId": "deleteAppPage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageDeleteResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AppPageDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"page"
]
},
"put": {
"summary": "更新应用页",
"operationId": "updateAppPage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/AppPageUpdateResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/AppPageUpdateRequest"
}
}
],
"requestBody": {},
"tags": [
"page"
]
}
},
"v1/chart": {
"post": {
"summary": "保存图表",
... ... @@ -155,6 +383,34 @@
]
}
},
"v1/chart/saveas": {
"post": {
"summary": "图表另存为",
"operationId": "saveAsChart",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/ChartSaveAsResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/ChartSaveAsRequest"
}
}
],
"requestBody": {},
"tags": [
"chart"
]
}
},
"v1/chart/search": {
"post": {
"summary": "搜索图表",
... ... @@ -391,6 +647,269 @@
}
},
"definitions": {
"AppPageChartItem": {
"type": "object",
"properties": {
"chartId": {
"type": "integer",
"format": "int64",
"description": " 图表ID"
},
"name": {
"type": "string",
"description": " 图表名称"
},
"cover": {
"type": "string",
"description": " 图表封面"
}
},
"title": "AppPageChartItem",
"required": [
"chartId",
"name",
"cover"
]
},
"AppPageCreateShareRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 页面ID"
}
},
"title": "AppPageCreateShareRequest",
"required": [
"id"
]
},
"AppPageCreateShareResponse": {
"type": "object",
"properties": {
"key": {
"type": "string",
"description": " 分享,预览时绑定映射到Id"
}
},
"title": "AppPageCreateShareResponse"
},
"AppPageDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 页面ID"
}
},
"title": "AppPageDeleteRequest",
"required": [
"id"
]
},
"AppPageDeleteResponse": {
"type": "object",
"title": "AppPageDeleteResponse"
},
"AppPageGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "AppPageGetRequest",
"required": [
"id"
]
},
"AppPageGetResponse": {
"type": "object",
"properties": {
"page": {
"$ref": "#/definitions/AppPageItem"
}
},
"title": "AppPageGetResponse",
"required": [
"page"
]
},
"AppPageItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 唯一标识"
},
"name": {
"type": "string",
"description": " 名称"
},
"charts": {
"type": "array",
"items": {
"$ref": "#/definitions/AppPageChartItem"
},
"description": " 图表"
}
},
"title": "AppPageItem"
},
"AppPageSaveAsRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 页面ID"
},
"name": {
"type": "string",
"description": " 名称"
}
},
"title": "AppPageSaveAsRequest",
"required": [
"id",
"name"
]
},
"AppPageSaveAsResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string",
"description": " 名称"
},
"charts": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 图表"
}
},
"title": "AppPageSaveAsResponse",
"required": [
"id",
"name",
"charts"
]
},
"AppPageSaveRequest": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": " 名称"
},
"charts": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 图表"
}
},
"title": "AppPageSaveRequest",
"required": [
"name",
"charts"
]
},
"AppPageSaveResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "AppPageSaveResponse",
"required": [
"id"
]
},
"AppPageSearchRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
}
},
"title": "AppPageSearchRequest",
"required": [
"page",
"size"
]
},
"AppPageSearchResponse": {
"type": "object",
"properties": {
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/AppPageItem"
}
},
"total": {
"type": "integer",
"format": "int64"
}
},
"title": "AppPageSearchResponse",
"required": [
"list",
"total"
]
},
"AppPageUpdateRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string",
"description": " 名称"
},
"charts": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
},
"description": " 图表"
}
},
"title": "AppPageUpdateRequest",
"required": [
"id",
"name",
"charts"
]
},
"AppPageUpdateResponse": {
"type": "object",
"title": "AppPageUpdateResponse"
},
"ChartComponentItem": {
"type": "object",
"properties": {
... ... @@ -541,6 +1060,10 @@
"cover": {
"type": "string",
"description": " 封面"
},
"other": {
"$ref": "#/definitions/Other",
"description": " 其他额外配置"
}
},
"title": "ChartProperty"
... ... @@ -567,6 +1090,37 @@
"type": "object",
"title": "ChartRenameResponse"
},
"ChartSaveAsRequest": {
"type": "object",
"properties": {
"chartId": {
"type": "integer",
"format": "int64",
"description": " 图表Id"
},
"name": {
"type": "string",
"description": " 名称"
}
},
"title": "ChartSaveAsRequest",
"required": [
"chartId",
"name"
]
},
"ChartSaveAsResponse": {
"type": "object",
"properties": {
"chart": {
"$ref": "#/definitions/ChartItem"
}
},
"title": "ChartSaveAsResponse",
"required": [
"chart"
]
},
"ChartSaveRequest": {
"type": "object",
"properties": {
... ... @@ -776,6 +1330,30 @@
"toValue"
]
},
"GetAppPageShareDetailRequest": {
"type": "object",
"properties": {
"key": {
"type": "string"
}
},
"title": "GetAppPageShareDetailRequest",
"required": [
"key"
]
},
"GetAppPageShareDetailResponse": {
"type": "object",
"properties": {
"page": {
"$ref": "#/definitions/AppPageItem"
}
},
"title": "GetAppPageShareDetailResponse",
"required": [
"page"
]
},
"GetTableDetailRequest": {
"type": "object",
"properties": {
... ... @@ -814,6 +1392,63 @@
"type": "object",
"title": "LoadChartDataResponse"
},
"Other": {
"type": "object",
"properties": {
"quarter": {
"$ref": "#/definitions/Quarter",
"description": " 四分图"
}
},
"title": "Other",
"required": [
"quarter"
]
},
"Quarter": {
"type": "object",
"properties": {
"xAxisLabel": {
"type": "string",
"description": " x轴标签名"
},
"xAxisLabelList": {
"type": "array",
"items": {
"type": "string"
},
"description": " 标签名"
},
"yAxisLabel": {
"type": "string",
"description": " x轴标签名"
},
"yAxisLabelList": {
"type": "array",
"items": {
"type": "string"
},
"description": " 标签名"
},
"area": {
"type": "string",
"description": " 图形面积"
},
"seriesList": {
"type": "string",
"description": " 图形系列"
}
},
"title": "Quarter",
"required": [
"xAxisLabel",
"xAxisLabelList",
"yAxisLabel",
"yAxisLabelList",
"area",
"seriesList"
]
},
"SearchTableByModuleRequest": {
"type": "object",
"properties": {
... ... @@ -945,6 +1580,18 @@
"$ref": "#/definitions/Expression"
},
"description": " 条件匹配表达式(总体指标)"
},
"targetText": {
"type": "string",
"description": " 指标名文本"
},
"targetNum": {
"type": "string",
"description": " 指标数值"
},
"targetUnit": {
"type": "string",
"description": " 指标单位"
}
},
"title": "Series",
... ... @@ -953,7 +1600,10 @@
"from",
"dataSourceId",
"customText",
"matchExpressions"
"matchExpressions",
"targetText",
"targetNum",
"targetUnit"
]
},
"TableAbility": {
... ... @@ -1010,6 +1660,10 @@
"fileUrl": {
"type": "string",
"description": " 组件图片/视频"
},
"align": {
"type": "string",
"description": " 文本对齐方式 left center right"
}
},
"title": "Title",
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: page
jwt: JwtAuth
)
service Core {
@doc "获取应用页详情"
@handler getAppPage
get /app-page/:id (AppPageGetRequest) returns (AppPageGetResponse)
@doc "保存应用页"
@handler saveAppPage
post /app-page (AppPageSaveRequest) returns (AppPageSaveResponse)
@doc "应用页另存为"
@handler saveAsAppPage
post /app-page/saveas (AppPageSaveAsRequest) returns (AppPageSaveAsResponse)
@doc "删除应用页"
@handler deleteAppPage
delete /app-page/:id (AppPageDeleteRequest) returns (AppPageDeleteResponse)
@doc "更新应用页"
@handler updateAppPage
put /app-page/:id (AppPageUpdateRequest) returns (AppPageUpdateResponse)
@doc "搜索"
@handler searchAppPage
post /app-page/search (AppPageSearchRequest) returns (AppPageSearchResponse)
@doc "创建应用页分享"
@handler createAppPageShareUrl
post /app-page/create-share (AppPageCreateShareRequest) returns (AppPageCreateShareResponse)
}
type (
AppPageGetRequest {
Id int64 `path:"id"`
}
AppPageGetResponse struct{
AppPage AppPageItem `json:"page"`
}
AppPageSaveRequest struct{
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"`// 图表
}
AppPageSaveResponse struct{
Id int64 `json:"id"`
}
AppPageSaveAsRequest struct{
Id int64 `json:"id"` // 页面ID
Name string `json:"name"` // 名称
}
AppPageSaveAsResponse struct{
Id int64 `path:"id"`
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"`// 图表
}
AppPageCreateShareRequest struct{
Id int64 `json:"id"` // 页面ID
}
AppPageCreateShareResponse struct{
Key string `json:"key,optional"` // 分享,预览时绑定映射到Id
}
AppPageDeleteRequest struct{
Id int64 `path:"id"` // 页面ID
}
AppPageDeleteResponse struct{}
AppPageUpdateRequest struct{
Id int64 `path:"id"`
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"`// 图表
}
AppPageUpdateResponse struct{}
AppPageSearchRequest struct{
Page int `json:"page"`
Size int `json:"size"`
}
AppPageSearchResponse{
List []AppPageItem `json:"list"`
Total int64 `json:"total"`
}
AppPageItem struct{
Id int64 `json:"id,optional"` // 唯一标识
Name string `json:"name,optional"` // 名称
Charts []AppPageChartItem `json:"charts,optional"`// 图表
}
AppPageChartItem struct{
ChartId int64 `json:"chartId"` // 图表ID
Name string `json:"name"` // 图表名称
Cover string `json:"cover"` // 图表封面
}
)
@server(
prefix: v1
group: page
)
service Core {
@doc "开放接口-获取应用页详情通过KEY"
@handler getAppPageShareDetail
get /api/app-page/get-share-detail/:key (GetAppPageShareDetailRequest) returns (GetAppPageShareDetailResponse)
}
type (
GetAppPageShareDetailRequest struct{
Key string `path:"key"`
}
GetAppPageShareDetailResponse struct{
AppPage AppPageItem `json:"page"`
}
)
\ No newline at end of file
... ...
... ... @@ -155,6 +155,18 @@ type(
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
Cover string `json:"cover,optional"` // 封面
Other Other `json:"other,optional"` // 其他额外配置
}
Other struct {
Quarter *Quarter `json:"quarter,optional,omitempty"` // 四分图
}
Quarter struct {
XAxisLabel string `json:"xAxisLabel"` // x轴标签名
XAxisLabelList []string `json:"xAxisLabelList"` // 标签名
YAxisLabel string `json:"yAxisLabel"` // x轴标签名
YAxisLabelList []string `json:"yAxisLabelList"` // 标签名
Area string `json:"area"` // 图形面积
SeriesList string `json:"seriesList"` // 图形系列
}
Title struct {
TitleSwitch bool `json:"titleSwitch,optional"` // 组件标题开关
... ... @@ -165,6 +177,7 @@ type(
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
}
TableAbility struct {
FilterSwitch bool `json:"filterSwitch,optional"` // 表筛选功能开关
... ... @@ -176,6 +189,9 @@ type(
DataSourceId int64 `json:"dataSourceId,optional,omitempty"` // 数据源ID(from值为ByteBank时有值)
CustomText string `json:"customText,optional,omitempty"` // 自定义数据文本(from值为User时有值)
MatchExpressions []Expression `json:"matchExpressions,optional,omitempty"` // 条件匹配表达式(总体指标)
TargetText string `json:"targetText,optional,omitempty"` // 指标名文本
TargetNum string `json:"targetNum,optional,omitempty"` // 指标数值
TargetUnit string `json:"targetUnit,optional,omitempty"` // 指标单位
}
Expression struct {
Operator string `json:"operator"` // 操作符号 <,>,==,<>,<=,>=
... ...
... ... @@ -16,3 +16,8 @@ CREATE TABLE `chart_setting` (
`series` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '系列值-数据绑定',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
CREATE TABLE `app_page` (
`id` int(0) NOT NULL COMMENT '唯一标识',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
... ...