作者 yangfu

Merge branch 'dev'

正在显示 50 个修改的文件 包含 768 行增加87 行删除
... ... @@ -26,7 +26,7 @@ _testmain.go
.vscode
app.log
go.sum
#go.sum
lastupdate.tmp
*.log
... ...
... ... @@ -19,7 +19,7 @@ FROM alpine:latest
# Define the project name | 定义项目名称
ARG PROJECT=core
# Define the config file name | 定义配置文件名
ARG CONFIG_FILE=core.yaml
ARG CONFIG_FILE=core-dev.yaml
# Define the author | 定义作者
ARG AUTHOR=785409885@qq.com
... ... @@ -31,6 +31,7 @@ ENV CONFIG_FILE=${CONFIG_FILE}
COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/
COPY --from=builder /build/cmd/chart-server/api/public ./public/
EXPOSE 8080
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
FROM golang:1.19-alpine as builder
# Define the project name | 定义项目名称
ARG PROJECT=core
WORKDIR /build
COPY . .
RUN go env -w GO111MODULE=on \
&& go env -w GOPROXY=https://goproxy.cn,direct \
&& go env -w CGO_ENABLED=0 \
&& go env \
&& go mod tidy \
&& cd cmd/chart-server/api \
&& go build -ldflags="-s -w" -o /build/api/${PROJECT} ${PROJECT}.go
FROM alpine:latest
# Define the project name | 定义项目名称
ARG PROJECT=core
# Define the config file name | 定义配置文件名
ARG CONFIG_FILE=core-prod.yaml
# Define the author | 定义作者
ARG AUTHOR=785409885@qq.com
LABEL org.opencontainers.image.authors=${AUTHOR}
WORKDIR /app
ENV PROJECT=${PROJECT}
ENV CONFIG_FILE=${CONFIG_FILE}
COPY --from=builder /build/api/${PROJECT} ./
COPY --from=builder /build/cmd/chart-server/api/etc/${CONFIG_FILE} ./etc/
COPY --from=builder /build/cmd/chart-server/api/public ./public/
EXPOSE 8080
ENTRYPOINT ./${PROJECT} -f etc/${CONFIG_FILE}
\ No newline at end of file
... ...
... ... @@ -2,7 +2,7 @@ package main
import (
"flag"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/db"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"net/http"
... ... @@ -57,6 +57,6 @@ func main() {
db.Migrate(ctx.DB)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
logx.Infof("Starting server at %s:%d... \n", c.Host, c.Port)
server.Start()
}
... ...
Name: chart
Host: 0.0.0.0
Port: 8080
Verbose: true
HostName: http://sumifcc-bchart-dev.sumifcc.com
Log:
Mode: file
Encoding: plain
Level: debug # info
JwtAuth:
AccessSecret: digital-platform
Expire: 360000
Redis:
Host: 192.168.0.243:6379
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=sumifcc-bchart-dev port=31543 sslmode=disable TimeZone=Asia/Shanghai
ByteMetadata:
Name: ApiByteMetadata
Host: http://character-library-metadata-bastion-test.fjmaimaimai.com
Timeout: 0s
\ No newline at end of file
... ...
Name: chart
Host: 0.0.0.0
Port: 8080
Verbose: false
HostName: http://sumifcc-bchart.sumifcc.com
Log:
Mode: file
Encoding: plain
Level: info
JwtAuth:
AccessSecret: digital-platform
Expire: 360000
Redis:
Host: 192.168.0.243:6379
Type: node
Pass:
DB:
DataSource: host=114.55.200.59 user=postgres password=eagle1010 dbname=sumifcc-bchart-prd port=31543 sslmode=disable TimeZone=Asia/Shanghai
ByteMetadata:
Name: ApiByteMetadata
Host: https://character-library-metadata-bastion.sumifcc.com
Timeout: 0s
\ No newline at end of file
... ...
Name: chart
Host: 0.0.0.0
Port: 8080
Port: 8081
Verbose: true
HostName: http://sumifcc-bchart-dev.sumifcc.com
Log:
#Mode: file
Encoding: plain
Level: debug # info
MaxSize: 1 # 2MB
TimeFormat: 2006-01-02 15:04:05.000
JwtAuth:
AccessSecret: digital-platform
... ...
... ... @@ -12,6 +12,7 @@ type Config struct {
config.Config
Redis redis.RedisConf `json:",optional"`
ByteMetadata ApiService
HostName string // 服务域名
}
type ApiService struct {
... ...
package log
import (
"net/http"
"path/filepath"
"strings"
"github.com/zeromicro/go-zero/rest/httpx"
"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 GetLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.LogGetRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
path := svcCtx.Config.Log.Path
if svcCtx.Config.Log.Mode != "file" {
return
}
if path == "" {
path = "logs"
}
if !strings.HasSuffix(req.Module, ".log") {
req.Module += ".log"
}
handler := http.FileServer(http.Dir(path))
r.URL.Path = filepath.Join(req.Module)
handler.ServeHTTP(w, r)
}
}
... ...
package public
import (
"net/http"
"path/filepath"
"github.com/zeromicro/go-zero/rest/httpx"
"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 GetFileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PublicGetFileRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
handler := http.FileServer(http.Dir("public"))
r.URL.Path = filepath.Join(req.FileName)
handler.ServeHTTP(w, r)
}
}
... ...
... ... @@ -5,7 +5,9 @@ import (
"net/http"
chart "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/chart"
log "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/log"
page "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/page"
public "gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/api/internal/handler/public"
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"
... ... @@ -16,11 +18,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/chart/:id",
Handler: chart.GetChartHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/chart",
Handler: chart.SaveChartHandler(serverCtx),
... ... @@ -72,6 +69,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/chart/load-data",
Handler: chart.LoadChartDataHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/chart/:id",
Handler: chart.GetChartHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
... ... @@ -112,11 +114,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
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),
... ... @@ -155,10 +152,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/app-page/:id",
Handler: page.GetAppPageHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/app-page/get-share-detail/:key",
Handler: page.GetAppPageShareDetailHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: log.GetLogHandler(serverCtx),
},
},
rest.WithPrefix("/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/public/:filename",
Handler: public.GetFileHandler(serverCtx),
},
},
)
}
... ...
... ... @@ -30,7 +30,7 @@ func NewSaveChartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveCha
func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.ChartSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
conn = l.svcCtx.DefaultDBConn()
//parentChart *domain.Chart
chart *domain.Chart
chartSetting *domain.ChartSetting
... ... @@ -62,6 +62,9 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
//if currentSortChart, _ := l.svcCtx.ChartRepository.FindOneByGroup(l.ctx, conn, tenantId, req.Pid); currentSortChart != nil {
// chart.Sort = currentSortChart.Sort + 1
//}
if total, _, _ := l.svcCtx.ChartRepository.FindByTypeAndName(l.ctx, conn, tenantId, req.Type, req.Name); total > 0 {
return nil, xerr.NewErrMsgErr("图表名字重复", nil)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if chart, err = l.svcCtx.ChartRepository.Insert(ctx, conn, chart); err != nil {
return err
... ... @@ -76,6 +79,7 @@ func (l *SaveChartLogic) SaveChart(req *types.ChartSaveRequest) (resp *types.Cha
Title: chartProperty.Title,
TableAbility: chartProperty.TableAbility,
Series: chartProperty.Series,
Other: chartProperty.Other,
TenantId: chart.TenantId,
}
if chartSetting, err = l.svcCtx.ChartSettingRepository.Insert(l.ctx, conn, chartSetting); err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package chart
import (
"context"
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-bchart/cmd/chart-server/interanl/pkg/domain"
"strings"
... ... @@ -26,26 +27,29 @@ func NewSearchChartComponentsLogic(ctx context.Context, svcCtx *svc.ServiceConte
}
func (l *SearchChartComponentsLogic) SearchChartComponents(req *types.ChartComponentSearchRequest) (resp *types.ChartComponentSearchResponse, err error) {
pathMaker := func(filename string) string {
return fmt.Sprintf("%s/%s/%s", l.svcCtx.Config.HostName, "public", filename)
}
var list = []types.ChartComponentItem{
{
Name: "记录型表格",
Code: domain.RecordTable1,
Cover: "",
Cover: pathMaker("RecordTable-1.png"),
},
{
Name: "总体指标",
Code: domain.MetricsCard1,
Cover: "",
Cover: pathMaker("MetricsCard-1.png"),
},
{
Name: "容器卡片",
Code: domain.ContainerCard1,
Cover: "",
Cover: pathMaker("ContainerCard-1.png"),
},
{
Name: "四分图",
Code: domain.QuarterChart1,
Cover: "",
Cover: pathMaker("QuarterChart-1.png"),
},
}
var result = make([]types.ChartComponentItem, 0)
... ...
package log
import (
"context"
"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 GetLogLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetLogLogic {
return &GetLogLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetLogLogic) GetLog(req *types.LogGetRequest) (resp *types.LogGetResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -2,6 +2,7 @@ package page
import (
"context"
"fmt"
"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"
... ... @@ -41,9 +42,12 @@ func (l *CreateAppPageShareUrlLogic) CreateAppPageShareUrl(req *types.AppPageCre
if appPage.Key != "" {
return
}
key := tool.Krand(18, tool.KC_RAND_KIND_ALL)
if found, _ := l.svcCtx.AppPageRepository.FindOneByKey(l.ctx, conn, key); found != nil {
return nil, xerr.NewErrMsgErr("创建页面分享链接失败", fmt.Errorf("重复key"))
}
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)
appPage.Key = key
if appPage, err = l.svcCtx.AppPageRepository.UpdateWithVersion(l.ctx, conn, appPage); err != nil {
return err
}
... ...
... ... @@ -29,7 +29,7 @@ func NewSaveAppPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveA
func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *types.AppPageSaveResponse, err error) {
var (
//conn = l.svcCtx.DefaultDBConn()
conn = l.svcCtx.DefaultDBConn()
appPage *domain.AppPage
tenantId = contextdata.GetTenantFromCtx(l.ctx)
)
... ... @@ -37,6 +37,10 @@ func (l *SaveAppPageLogic) SaveAppPage(req *types.AppPageSaveRequest) (resp *typ
Name: req.Name,
Charts: req.Charts,
TenantId: tenantId,
Cover: req.Cover,
}
if total, _, _ := l.svcCtx.AppPageRepository.FindByName(l.ctx, conn, tenantId, req.Name); total > 0 {
return nil, xerr.NewErrMsgErr("页面名字重复", nil)
}
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 {
... ...
... ... @@ -36,8 +36,13 @@ func (l *UpdateAppPageLogic) UpdateAppPage(req *types.AppPageUpdateRequest) (res
}
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 req.Cover != "" {
appPage.Cover = req.Cover
}
if req.Name != "" {
appPage.Name = req.Name
}
if appPage, err = l.svcCtx.AppPageRepository.UpdateWithVersion(l.ctx, conn, appPage); err != nil {
return err
}
... ...
package public
import (
"context"
"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 GetFileLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetFileLogic {
return &GetFileLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetFileLogic) GetFile(req *types.PublicGetFileRequest) error {
// todo: add your logic here and delete this line
return nil
}
... ...
... ... @@ -55,6 +55,7 @@ func (l *SearchTableByModuleLogic) SearchTableByModule(req *types.SearchTableByM
TableTypes: []string{bytelib.CalculateItem, bytelib.CalculateSet},
Module: bytelib.ModuleCalculateCenter,
ReturnGroupItem: true,
ExcludeTables: []int{0},
})
if err != nil {
batchError.Add(err)
... ...
... ... @@ -26,6 +26,15 @@ func NewSearchTableDataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *S
}
func (l *SearchTableDataLogic) SearchTableData(req *types.SearchTableDataRequest) (resp interface{}, err error) {
if req.ObjectId == 0 {
resp = map[string]interface{}{
"objectId": 0,
"fields": nil,
"total": 0,
"data": make([]string, 0),
}
return
}
tableDataPreviewRequest := &bytelib.TableDataPreviewRequest{
Token: req.Token,
ObjectType: bytelib.ObjectMetaTable,
... ...
... ... @@ -54,17 +54,17 @@ func (l *SearchTableFieldOptionalValuesLogic) SearchTableFieldOptionalValues(req
func newWhere(conditions []*types.Condition) *bytelib.TableQueryWhere {
where := &bytelib.TableQueryWhere{}
for _, c := range conditions {
order := c.Order
if order == "" {
order = "ASC"
}
//order := c.Order
//if order == "" {
// order = "ASC"
//}
where.Conditions = append(where.Conditions, &bytelib.TableQueryCondition{
Field: &bytelib.Field{
Name: c.FieldName,
},
Like: c.Like,
In: c.In,
Order: order,
Like: c.Like,
In: c.In,
//Order: order,
})
}
return where
... ...
... ... @@ -27,7 +27,7 @@ type ServiceContext struct {
}
func NewServiceContext(c config.Config) *ServiceContext {
db := database.OpenGormPGDB(c.DB.DataSource)
db := database.OpenGormPGDB(c.DB.DataSource, c.Log.Mode)
mlCache := cache.NewMultiLevelCache([]string{c.Redis.Host}, c.Redis.Pass)
redisCache := gzcache.NewClusterCache([]string{c.Redis.Host}, c.Redis.Pass)
redis, _ := redis.NewRedis(redis.RedisConf{Host: c.Redis.Host, Pass: c.Redis.Pass, Type: "node"})
... ...
... ... @@ -39,15 +39,17 @@ func NewAppPageItem(appPage *domain.AppPage, charts []*domain.Chart) AppPageItem
return item.Id, item
})
item := AppPageItem{
Id: appPage.Id,
Name: appPage.Name,
Id: appPage.Id,
Name: appPage.Name,
Cover: appPage.Cover,
}
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,
ChartId: v.Id,
Name: v.Name,
Cover: v.Cover,
ChartType: v.ChartType,
})
}
}
... ...
... ... @@ -127,10 +127,12 @@ type Quarter struct {
YAxisFirstLabel string `json:"yAxisFirstLabel"` // y标签1
YAxisSecondLabel string `json:"yAxisSecondLabel"` // y标签2
Area string `json:"area"` // 图形面积
AreaColor bool `json:"areaColor"` // 颜色
SeriesList []QuarterSeries `json:"seriesList"` // 图形系列
}
type QuarterSeries struct {
SeriesValue string `json:"seriesValue"`
}
type Title struct {
... ... @@ -141,8 +143,11 @@ type Title struct {
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,,file]"` // text file ,options=text||file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileName string `json:"fileName,optional"` // 文件名
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
Align string `json:"align,optional"` // 废弃 文本对齐方式 left center right
HeadingAlign string `json:"headingAlign,optional"` // 主标题 文本对齐方式 left center right
SubAlign string `json:"subAlign,optional"` // 副标题 文本对齐方式 left center right
}
type TableAbility struct {
... ... @@ -208,7 +213,7 @@ type GetTableDetailResponse struct {
type SearchTableDataRequest struct {
Token string `header:"x-mmm-accesstoken,optional"`
ObjectId int `json:"objectId"` // 对象ID
ObjectId int `json:"objectId,optional"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
... ... @@ -226,8 +231,9 @@ type AppPageGetResponse struct {
}
type AppPageSaveRequest struct {
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"` // 图表
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"` // 图表
Cover string `json:"cover,optional"` // 封面
}
type AppPageSaveResponse struct {
... ... @@ -262,8 +268,9 @@ type AppPageDeleteResponse struct {
type AppPageUpdateRequest struct {
Id int64 `path:"id"`
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"` // 图表
Name string `json:"name,optional"` // 名称
Charts []int64 `json:"charts"` // 图表
Cover string `json:"cover,optional"` // 封面
}
type AppPageUpdateResponse struct {
... ... @@ -282,13 +289,15 @@ type AppPageSearchResponse struct {
type AppPageItem struct {
Id int64 `json:"id,optional"` // 唯一标识
Name string `json:"name,optional"` // 名称
Cover string `json:"cover,optional"` // 封面
Charts []AppPageChartItem `json:"charts,optional"` // 图表
}
type AppPageChartItem struct {
ChartId int64 `json:"chartId"` // 图表ID
Name string `json:"name"` // 图表名称
Cover string `json:"cover"` // 图表封面
ChartId int64 `json:"chartId"` // 图表ID
Name string `json:"name"` // 图表名称
Cover string `json:"cover"` // 图表封面
ChartType string `json:"chartType,optional"` // 图表类型
}
type GetAppPageShareDetailRequest struct {
... ... @@ -298,3 +307,14 @@ type GetAppPageShareDetailRequest struct {
type GetAppPageShareDetailResponse struct {
AppPage AppPageItem `json:"page"`
}
type LogGetRequest struct {
Module string `path:"module"`
}
type LogGetResponse struct {
}
type PublicGetFileRequest struct {
FileName string `path:"filename"`
}
... ...
... ... @@ -9,11 +9,11 @@ import (
)
type AppPage struct {
Id int64 // 唯一标识
Name string // 名称
Charts []int64 `gorm:"serializer:json"` // 图表
Key string // 分享,预览时绑定映射到Id
Id int64 // 唯一标识
Name string // 名称
Charts []int64 `gorm:"serializer:json"` // 图表
Key string // 分享,预览时绑定映射到Id
Cover string // 封面
TenantId int64 `gorm:"index:idx_app_page_t_id"` // 租户ID
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
... ...
... ... @@ -195,6 +195,36 @@ func (repository *AppPageRepository) Find(ctx context.Context, conn transaction.
return total, dms, nil
}
func (repository *AppPageRepository) FindByName(ctx context.Context, conn transaction.Conn, tenantId int64, name string) (int64, []*domain.AppPage, error) {
var (
tx = conn.DB()
ms []*models.AppPage
dms = make([]*domain.AppPage, 0)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx.Where("tenant_id = ?", tenantId)
tx.Where("name = ?", name)
if tx = tx.Find(&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 int64(len(dms)), dms, nil
}
func (repository *AppPageRepository) ModelToDomainModel(from *models.AppPage) (*domain.AppPage, error) {
to := &domain.AppPage{}
err := copier.Copy(to, from)
... ...
... ... @@ -149,6 +149,39 @@ func (repository *ChartRepository) Find(ctx context.Context, conn transaction.Co
return total, dms, nil
}
// FindByTypeAndName 按类型、名称搜索图表(判断重复的图表)
func (repository *ChartRepository) FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*domain.Chart, error) {
var (
tx = conn.DB()
ms []*models.Chart
dms = make([]*domain.Chart, 0)
//total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc") //.Order("pid asc").Order("sort asc")
tx.Where("tenant_id = ?", tenantId)
tx.Where("type = ?", t)
tx.Where("name = ?", name)
if tx = tx.Find(&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 int64(len(dms)), dms, nil
}
func (repository *ChartRepository) FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*domain.Chart, error) {
var (
err error
... ...
... ... @@ -11,6 +11,7 @@ type AppPage struct {
Charts []int64 // 图表
Key string // 分享,预览时绑定映射到Id
TenantId int64 // 租户ID
Cover string // 封面
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
... ... @@ -26,6 +27,7 @@ type AppPageRepository interface {
FindOneByKey(ctx context.Context, conn transaction.Conn, key string) (*AppPage, error)
FindOneByChartId(ctx context.Context, conn transaction.Conn, tenantId, chartId int64) (*AppPage, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*AppPage, error)
FindByName(ctx context.Context, conn transaction.Conn, tenantId int64, name string) (int64, []*AppPage, error)
}
func (m *AppPage) Identify() interface{} {
... ...
... ... @@ -34,6 +34,7 @@ type ChartRepository interface {
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Chart, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Chart, error)
FindOneByGroup(ctx context.Context, conn transaction.Conn, tenantId, pid int64) (*Chart, error)
FindByTypeAndName(ctx context.Context, conn transaction.Conn, tenantId int64, t string, name string) (int64, []*Chart, error)
}
/*************** 索引函数 开始****************/
... ...
... ... @@ -37,9 +37,12 @@ type Quarter struct {
YAxisFirstLabel string `json:"yAxisFirstLabel"` // y标签1
YAxisSecondLabel string `json:"yAxisSecondLabel"` // y标签2
Area string `json:"area"` // 图形面积
AreaColor bool `json:"areaColor"` // 颜色
SeriesList []QuarterSeries `json:"seriesList"` // 图形系列
}
type QuarterSeries struct {
SeriesValue string `json:"seriesValue"`
}
type Title struct {
... ... @@ -50,8 +53,11 @@ type Title struct {
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,file]"` // text file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileName string `json:"fileName,optional"` // 文件名
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
Align string `json:"align,optional"` // 废弃 文本对齐方式 left center right
HeadingAlign string `json:"headingAlign,optional"` // 主标题 文本对齐方式 left center right
SubAlign string `json:"subAlign,optional"` // 副标题 文本对齐方式 left center right
}
type TableAbility struct {
... ...
... ... @@ -70,6 +70,14 @@ func (gateway Service) Do(ctx context.Context, url string, method string, val in
if err = json.Unmarshal(body, &baseResponse); err != nil {
return err
}
if baseResponse.Code != 0 {
return HttpError{
Base: Response{
Code: baseResponse.Code,
Msg: baseResponse.Msg,
},
}
}
if err = mapping.UnmarshalJsonBytes(baseResponse.Data, result); err != nil {
return err
}
... ...
... ... @@ -40,7 +40,7 @@ type TableQueryWhere struct {
}
func (w *TableQueryWhere) WithPageSize(page, size int) *TableQueryWhere {
w.PageNumber = page - 1
w.PageNumber = page
w.PageSize = size
if page == 0 {
w.PageNumber = 0
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/sumifcc-bchart/sumifcc-bchart.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart service install success!"
else
echo "sumifcc-bchart service install fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart deployment install success!"
else
echo "sumifcc-bchart deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/sumifcc-bchart/sumifcc-bchart.yaml
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
done
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
while [ "$?" == "0" ]
do
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
done
kubectl create -f /tmp/dev/sumifcc-bchart/sumifcc-bchart.yaml --record
kubectl -n mmm-suplus-dev get svc | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart service update success!"
else
echo "sumifcc-bchart service update fail!"
fi
kubectl -n mmm-suplus-dev get pods | grep -q sumifcc-bchart
if [ "$?" == "0" ];then
echo "sumifcc-bchart deployment update success!"
else
echo "sumifcc-bchart deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: sumifcc-bchart
namespace: mmm-suplus-dev
labels:
k8s-app: sumifcc-bchart
spec:
ports:
- name: "http"
port: 80
targetPort: 8080
selector:
k8s-app: sumifcc-bchart
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sumifcc-bchart
namespace: mmm-suplus-dev
labels:
k8s-app: sumifcc-bchart
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: sumifcc-bchart
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
containers:
- name: sumifcc-bchart
image: 192.168.0.243:5000/mmm/sumifcc-bchart:dev
imagePullPolicy: Always
ports:
- containerPort: 8080
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
#!/bin/bash
export PATH=/root/local/bin:$PATH
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
if [ "$?" == "1" ];then
kubectl create -f /tmp/dev/sumifcc-survey-server/sumifcc-survey-server.yaml --record
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server service install success!"
else
echo "sumifcc-survey-server service install fail!"
fi
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server deployment install success!"
else
echo "sumifcc-survey-server deployment install fail!"
fi
else
kubectl delete -f /tmp/dev/sumifcc-survey-server/sumifcc-survey-server.yaml
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
while [ "$?" == "0" ]
do
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
done
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
while [ "$?" == "0" ]
do
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
done
kubectl create -f /tmp/dev/sumifcc-survey-server/sumifcc-survey-server.yaml --record
kubectl -n <replace-your-k8s-namespace> get svc | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server service update success!"
else
echo "sumifcc-survey-server service update fail!"
fi
kubectl -n <replace-your-k8s-namespace> get pods | grep -q sumifcc-survey-server
if [ "$?" == "0" ];then
echo "sumifcc-survey-server deployment update success!"
else
echo "sumifcc-survey-server deployment update fail!"
fi
fi
\ No newline at end of file
... ...
apiVersion: v1
kind: Service
metadata:
name: sumifcc-survey-server
namespace: <replace-your-k8s-namespace>
labels:
k8s-app: sumifcc-survey-server
spec:
ports:
- name: "http"
port: 80
targetPort: 8082
selector:
k8s-app: sumifcc-survey-server
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: sumifcc-survey-server
namespace: <replace-your-k8s-namespace>
labels:
k8s-app: sumifcc-survey-server
spec:
replicas: 1
template:
metadata:
labels:
k8s-app: sumifcc-survey-server
spec:
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference: {}
weight: 100
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- cn-hangzhou.i-bp1djh1xn7taumbue1ze
- cn-hangzhou.i-bp1djh1xn7taumbue1zd
- cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
- cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
containers:
- name: sumifcc-survey-server
image: 192.168.0.243:5000/mmm/sumifcc-survey-server:dev
imagePullPolicy: Always
ports:
- containerPort: 8082
volumeMounts:
- mountPath: /opt/logs
name: accesslogs
env:
- name: LOG_LEVEL
value: "debug"
- name: ERROR_BASE_CODE
value: "1"
- name: ERROR_BASE_CODE_MULTIPLE
value: "1000"
volumes:
- name: accesslogs
emptyDir: {}
\ No newline at end of file
... ...
... ... @@ -20,4 +20,13 @@ goctl api plugin -plugin goctl-swagger="swagger -filename core.json" -api .\doc\
```
docker build -f Dockerfile -t tiptok/sumifcc-bchart:1.0.0 .
```
## 基础镜像
```
docker build -f DockerfileBase -t tiptok/sumifcc-bchart-base:1.0.0 .
docker save -o sumifcc-bchart-base.tar tiptok/sumifcc-bchart-base:1.0.0
docker load --input sumifcc-bchart-base.tar
docker tag
```
\ No newline at end of file
... ...
import "core/chart.api"
import "core/table.api"
import "core/app_page.api"
import "core/log.api"
import "core/public.api"
// import "./core/chart_stting.api"
\ No newline at end of file
... ...
... ... @@ -15,9 +15,6 @@ info(
jwt: JwtAuth
)
service Core {
@doc "获取应用页详情"
@handler getAppPage
get /app-page/:id (AppPageGetRequest) returns (AppPageGetResponse)
@doc "保存应用页"
@handler saveAppPage
post /app-page (AppPageSaveRequest) returns (AppPageSaveResponse)
... ... @@ -48,8 +45,9 @@ type (
}
AppPageSaveRequest struct{
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"`// 图表
Name string `json:"name"` // 名称
Charts []int64 `json:"charts"`// 图表
Cover string `json:"cover,optional"` // 封面
}
AppPageSaveResponse struct{
Id int64 `json:"id"`
... ... @@ -77,8 +75,9 @@ type (
AppPageUpdateRequest struct{
Id int64 `path:"id"`
Name string `json:"name"` // 名称
Name string `json:"name,optional"` // 名称
Charts []int64 `json:"charts"`// 图表
Cover string `json:"cover,optional"` // 封面
}
AppPageUpdateResponse struct{}
... ... @@ -93,12 +92,14 @@ type (
AppPageItem struct{
Id int64 `json:"id,optional"` // 唯一标识
Name string `json:"name,optional"` // 名称
Cover string `json:"cover,optional"` // 封面
Charts []AppPageChartItem `json:"charts,optional"`// 图表
}
AppPageChartItem struct{
ChartId int64 `json:"chartId"` // 图表ID
Name string `json:"name"` // 图表名称
Cover string `json:"cover"` // 图表封面
ChartId int64 `json:"chartId"` // 图表ID
Name string `json:"name"` // 图表名称
Cover string `json:"cover"` // 图表封面
ChartType string `json:"chartType,optional"` // 图表类型
}
)
... ... @@ -108,6 +109,10 @@ type (
group: page
)
service Core {
@doc "获取应用页详情"
@handler getAppPage
get /app-page/:id (AppPageGetRequest) returns (AppPageGetResponse)
@doc "开放接口-获取应用页详情通过KEY"
@handler getAppPageShareDetail
get /api/app-page/get-share-detail/:key (GetAppPageShareDetailRequest) returns (GetAppPageShareDetailResponse)
... ...
... ... @@ -16,9 +16,6 @@ info(
//middleware: Authority
)
service Core {
@doc "获取图表详情"
@handler getChart
get /chart/:id (ChartGetRequest) returns (ChartGetResponse)
@doc "保存图表"
@handler saveChart
post /chart (ChartSaveRequest) returns (ChartSaveResponse)
... ... @@ -49,13 +46,14 @@ service Core {
@server(
prefix: v1
group: chart
//jwt: JwtAuth
//middleware: Authority
)
service Core {
@doc "加载图表数据"
@handler loadChartData
post /chart/load-data (LoadChartDataRequest) returns (LoadChartDataResponse)
@doc "获取图表详情"
@handler getChart
get /chart/:id (ChartGetRequest) returns (ChartGetResponse)
}
type (
... ... @@ -156,7 +154,6 @@ type(
Title Title `json:"title,optional"` // 标题
TableAbility TableAbility `json:"table,optional"` // 表筛选功能
Series []Series `json:"series,optional"` // 系列(数据源)
//Cover string `json:"cover,optional"` // 封面
Other Other `json:"other,optional"` // 其他额外配置
}
Other struct {
... ... @@ -170,9 +167,11 @@ type(
YAxisFirstLabel string `json:"yAxisFirstLabel"` // y标签1
YAxisSecondLabel string `json:"yAxisSecondLabel"` // y标签2
Area string `json:"area"` // 图形面积
AreaColor bool `json:"areaColor"` // 颜色
SeriesList []QuarterSeries `json:"seriesList"` // 图形系列
}
QuarterSeries struct {
SeriesValue string `json:"seriesValue"`
}
Title struct {
TitleSwitch bool `json:"titleSwitch,optional"` // 组件标题开关
... ... @@ -182,8 +181,11 @@ type(
SubTitle string `json:"subTitle,optional"` // 副标题
ExplainType string `json:"explainType,optional,options=[text,,file]"` // text file ,options=text||file
ExplainTxt string `json:"explainTxt,optional"` // 文字说明
FileName string `json:"fileName,optional"` // 文件名
FileUrl string `json:"fileUrl,optional"` // 组件图片/视频
Align string `json:"align,optional"` // 文本对齐方式 left center right
Align string `json:"align,optional"` // 废弃 文本对齐方式 left center right
HeadingAlign string `json:"headingAlign,optional"` // 主标题 文本对齐方式 left center right
SubAlign string `json:"subAlign,optional"` // 副标题 文本对齐方式 left center right
}
TableAbility struct {
FilterSwitch bool `json:"filterSwitch,optional"` // 表筛选功能开关
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
prefix: v1
group: log
)
service Core {
@doc "获取图表详情"
@handler getLog
get /log/:module (LogGetRequest) returns (LogGetResponse)
}
type(
LogGetRequest struct{
Module string `path:"module"`
}
LogGetResponse struct{
}
)
\ No newline at end of file
... ...
syntax = "v1"
info(
title: "天联字库图表模板"
desc: "图表模板"
author: "小火箭"
email: "email"
version: "v1"
)
@server(
group: public
)
service Core {
@doc "获取文件"
@handler getFile
get /public/:filename (PublicGetFileRequest)
}
type(
PublicGetFileRequest struct{
FileName string `path:"filename"`
}
)
\ No newline at end of file
... ...
... ... @@ -80,7 +80,7 @@ type (
SearchTableDataRequest struct{
Token string `header:"x-mmm-accesstoken,optional"`
ObjectId int `json:"objectId"` // 对象ID
ObjectId int `json:"objectId,optional"` // 对象ID
PageNumber int `json:"page,optional"` // 分页数
PageSize int `json:"size,optional"` // 页码
Condition []*Condition `json:"conditions,optional"` // 条件
... ...
此 diff 太大无法显示。
package cache
import (
"fmt"
"github.com/tiptok/gocomm/pkg/cache"
"github.com/tiptok/gocomm/pkg/cache/gzcache"
"github.com/tiptok/gocomm/pkg/log"
"github.com/zeromicro/go-zero/core/logx"
)
func NewMultiLevelCache(hosts []string, password string) *cache.MultiLevelCache {
fmt.Println("starting multi level cache...")
logx.Infof("starting multi level cache...")
mlCache := cache.NewMultiLevelCacheNew(cache.WithDebugLog(true, func() log.Log {
return log.DefaultLog
}))
... ...
package database
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/logx"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
... ... @@ -31,28 +33,52 @@ func OpenGormDB(source string) *gorm.DB {
return db
}
func OpenGormPGDB(source string) *gorm.DB {
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // Slow SQL threshold
LogLevel: logger.Info, // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: false, // Disable color
},
)
fmt.Println("starting db...")
//db, err := gorm.Open(postgres.Open(source), &gorm.Config{
// Logger: newLogger,
//})
func OpenGormPGDB(source string, logMode string) *gorm.DB {
logx.Infof("starting db...")
db, err := gorm.Open(postgres.New(postgres.Config{
DSN: source,
PreferSimpleProtocol: true, // disables implicit prepared statement usage
}), &gorm.Config{
Logger: newLogger,
Logger: NewLogger(logMode), //newLogger,
})
if err != nil {
panic(err)
}
return db
}
func NewLogger(logType string) logger.Interface {
if logType == "console" {
return logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // Slow SQL threshold
LogLevel: logger.Info, // Log level
IgnoreRecordNotFoundError: true, // Ignore ErrRecordNotFound error for logger
Colorful: false, // Disable color
},
)
}
return ZeroLog{}
}
type ZeroLog struct {
}
func (l ZeroLog) LogMode(logger.LogLevel) logger.Interface {
return l
}
func (l ZeroLog) Info(ctx context.Context, s string, values ...interface{}) {
logx.Infof(s, values...)
}
func (l ZeroLog) Warn(ctx context.Context, s string, values ...interface{}) {
logx.Errorf(s, values...)
}
func (l ZeroLog) Error(ctx context.Context, s string, values ...interface{}) {
logx.Errorf(s, values...)
}
func (l ZeroLog) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
now := time.Now()
sql, rows := fc()
logx.Infof("[%v] [rows:%v] %s", now.Sub(begin).String(), rows, sql)
}
... ...