feat: 资源面板配置接口
Signed-off-by: devad <cossjie@foxmail.com> Former-commit-id: 6a45c0696142ecd131f0ba11e659c869bd97d09c
This commit is contained in:
parent
0bf4208e46
commit
42275e0d82
|
@ -303,3 +303,47 @@ type (
|
|||
// DeleteFlag int64 `json:"delete_flag"` // 是否删除 0:未删除,1:已经删除
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
ResourcePanelConfigReq {
|
||||
Id int64 `json:"id"` //id
|
||||
Title string `json:"title"` //标题
|
||||
TitleColor string `json:"titleColor"` //标题色
|
||||
MainColor string `json:"mainColor"` //主色调
|
||||
MainColor2 string `json:"mainColor2"` //次主色调
|
||||
TextColor string `json:"textColor"` //文字颜色
|
||||
BackgroundColor string `json:"backgroundColor"` //背景底色
|
||||
Center string `json:"center"` //中心点
|
||||
CenterPosition string `json:"centerPosition"` //comment 中心点坐标
|
||||
ProvinceBgColor string `json:"provinceBgColor"` //三级地图底色
|
||||
StatusIng string `json:"statusIng"` //接入中图标
|
||||
StatusUn string `json:"statusUn"` //未接入图标
|
||||
StatusEnd string `json:"statusEnd"` //已接入图标
|
||||
TitleIcon string `json:"titleIcon"` //标题底图
|
||||
SubTitleIcon string `json:"subTitleIcon"` //小标题底图
|
||||
NumberBg string `json:"numberBg"` //数字底图
|
||||
TaskBg string `json:"taskBg"` //任务底图
|
||||
}
|
||||
|
||||
ResourcePanelConfigResp {
|
||||
Id int64 `json:"id"` //id
|
||||
Title string `json:"title"` //标题,
|
||||
TitleColor string `json:"titleColor"` //标题色,
|
||||
MainColor string `json:"mainColor"` //主色调,
|
||||
MainColor2 string `json:"mainColor2"` //次主色调,
|
||||
TextColor string `json:"textColor"` //文字颜色,
|
||||
BackgroundColor string `json:"backgroundColor"` //背景底色,
|
||||
Center string `json:"center"` //中心点,
|
||||
CenterPosition string `json:"centerPosition"` //comment 中心点坐标,
|
||||
ProvinceBgColor string `json:"provinceBgColor"` //三级地图底色,
|
||||
StatusIng string `json:"statusIng"` //接入中图标,
|
||||
StatusUn string `json:"statusUn"` //未接入图标,
|
||||
StatusEnd string `json:"statusEnd"` //已接入图标,
|
||||
TitleIcon string `json:"titleIcon"` //标题底图,
|
||||
SubTitleIcon string `json:"subTitleIcon"` //小标题底图,
|
||||
NumberBg string `json:"numberBg"` //数字底图,
|
||||
TaskBg string `json:"taskBg"` //任务底图,
|
||||
CreateTime string `json:"createTime"` //创建时间,
|
||||
UpdateTime string `json:"updateTime"` //更新时间
|
||||
}
|
||||
)
|
|
@ -50,6 +50,12 @@ service pcm {
|
|||
|
||||
@handler listDomainResourceHandler
|
||||
get /core/listDomainResource returns (DomainResourceResp)
|
||||
|
||||
@handler getResourcePanelConfigHandler
|
||||
get /core/getResourcePanelConfigHandler () returns (ResourcePanelConfigResp)
|
||||
|
||||
@handler putResourcePanelConfigHandler
|
||||
put /core/resourcePanelConfigHandler (ResourcePanelConfigReq) returns ()
|
||||
}
|
||||
|
||||
//hpc二级接口
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"PCM/common/result"
|
||||
|
||||
"PCM/adaptor/PCM-CORE/api/internal/logic/core"
|
||||
"PCM/adaptor/PCM-CORE/api/internal/svc"
|
||||
)
|
||||
|
||||
func GetResourcePanelConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := core.NewGetResourcePanelConfigLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetResourcePanelConfig()
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"PCM/common/result"
|
||||
|
||||
"PCM/adaptor/PCM-CORE/api/internal/logic/core"
|
||||
"PCM/adaptor/PCM-CORE/api/internal/svc"
|
||||
"PCM/adaptor/PCM-CORE/api/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func PutResourcePanelConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ResourcePanelConfigReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := core.NewPutResourcePanelConfigLogic(r.Context(), svcCtx)
|
||||
err := l.PutResourcePanelConfig(&req)
|
||||
result.HttpResult(r, w, nil, err)
|
||||
}
|
||||
}
|
|
@ -67,6 +67,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/core/listDomainResource",
|
||||
Handler: core.ListDomainResourceHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/core/getResourcePanelConfigHandler",
|
||||
Handler: core.GetResourcePanelConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/core/resourcePanelConfigHandler",
|
||||
Handler: core.PutResourcePanelConfigHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"PCM/adaptor/PCM-CORE/api/internal/svc"
|
||||
"PCM/adaptor/PCM-CORE/api/internal/types"
|
||||
"PCM/adaptor/PCM-CORE/model"
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetResourcePanelConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetResourcePanelConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetResourcePanelConfigLogic {
|
||||
return &GetResourcePanelConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetResourcePanelConfigLogic) GetResourcePanelConfig() (resp *types.ResourcePanelConfigResp, err error) {
|
||||
rpcModel := model.ResourcePanelConfig{}
|
||||
l.svcCtx.DbEngin.Find(&rpcModel)
|
||||
tool.Convert(rpcModel, &resp)
|
||||
return resp, nil
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"PCM/adaptor/PCM-CORE/api/internal/svc"
|
||||
"PCM/adaptor/PCM-CORE/api/internal/types"
|
||||
"PCM/adaptor/PCM-CORE/model"
|
||||
"PCM/common/tool"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PutResourcePanelConfigLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPutResourcePanelConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PutResourcePanelConfigLogic {
|
||||
return &PutResourcePanelConfigLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PutResourcePanelConfigLogic) PutResourcePanelConfig(req *types.ResourcePanelConfigReq) error {
|
||||
rpcModel := model.ResourcePanelConfig{}
|
||||
tool.Convert(req, &rpcModel)
|
||||
rpcModel.UpdateTime = time.Now()
|
||||
|
||||
update := l.svcCtx.DbEngin.Model(&rpcModel).Updates(rpcModel)
|
||||
err := update.Error
|
||||
if err != nil {
|
||||
logx.WithContext(l.ctx).Errorf("PCM 资源面板数据更新失败 err: %s", err.Error())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -278,6 +278,48 @@ type DomainResource struct {
|
|||
NodeCount string `json:"nodeCount"` //节点数量
|
||||
}
|
||||
|
||||
type ResourcePanelConfigReq struct {
|
||||
Id int64 `json:"id,optional"` //id
|
||||
Title string `json:"title,optional"` //标题
|
||||
TitleColor string `json:"titleColor,optional"` //标题色
|
||||
MainColor string `json:"mainColor,optional"` //主色调
|
||||
MainColor2 string `json:"mainColor2,optional"` //次主色调
|
||||
TextColor string `json:"textColor,optional"` //文字颜色
|
||||
BackgroundColor string `json:"backgroundColor,optional"` //背景底色
|
||||
Center string `json:"center,optional"` //中心点
|
||||
CenterPosition string `json:"centerPosition,optional"` //comment 中心点坐标
|
||||
ProvinceBgColor string `json:"provinceBgColor,optional"` //三级地图底色
|
||||
StatusIng string `json:"statusIng,optional"` //接入中图标
|
||||
StatusUn string `json:"statusUn,optional"` //未接入图标
|
||||
StatusEnd string `json:"statusEnd,optional"` //已接入图标
|
||||
TitleIcon string `json:"titleIcon,optional"` //标题底图
|
||||
SubTitleIcon string `json:"subTitleIcon,optional"` //小标题底图
|
||||
NumberBg string `json:"numberBg,optional"` //数字底图
|
||||
TaskBg string `json:"taskBg,optional"` //任务底图
|
||||
}
|
||||
|
||||
type ResourcePanelConfigResp struct {
|
||||
Id int64 `json:"id"` //id
|
||||
Title string `json:"title"` //标题,
|
||||
TitleColor string `json:"titleColor"` //标题色,
|
||||
MainColor string `json:"mainColor"` //主色调,
|
||||
MainColor2 string `json:"mainColor2"` //次主色调,
|
||||
TextColor string `json:"textColor"` //文字颜色,
|
||||
BackgroundColor string `json:"backgroundColor"` //背景底色,
|
||||
Center string `json:"center"` //中心点,
|
||||
CenterPosition string `json:"centerPosition"` //comment 中心点坐标,
|
||||
ProvinceBgColor string `json:"provinceBgColor"` //三级地图底色,
|
||||
StatusIng string `json:"statusIng"` //接入中图标,
|
||||
StatusUn string `json:"statusUn"` //未接入图标,
|
||||
StatusEnd string `json:"statusEnd"` //已接入图标,
|
||||
TitleIcon string `json:"titleIcon"` //标题底图,
|
||||
SubTitleIcon string `json:"subTitleIcon"` //小标题底图,
|
||||
NumberBg string `json:"numberBg"` //数字底图,
|
||||
TaskBg string `json:"taskBg"` //任务底图,
|
||||
CreateTime string `json:"createTime"` //创建时间,
|
||||
UpdateTime string `json:"updateTime"` //更新时间
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
SlurmVersion string `json:"slurmVersion"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ ResourcePanelConfigModel = (*customResourcePanelConfigModel)(nil)
|
||||
|
||||
type (
|
||||
// ResourcePanelConfigModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customResourcePanelConfigModel.
|
||||
ResourcePanelConfigModel interface {
|
||||
resourcePanelConfigModel
|
||||
}
|
||||
|
||||
customResourcePanelConfigModel struct {
|
||||
*defaultResourcePanelConfigModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewResourcePanelConfigModel returns a model for the database table.
|
||||
func NewResourcePanelConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ResourcePanelConfigModel {
|
||||
return &customResourcePanelConfigModel{
|
||||
defaultResourcePanelConfigModel: newResourcePanelConfigModel(conn, c, opts...),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
resourcePanelConfigFieldNames = builder.RawFieldNames(&ResourcePanelConfig{})
|
||||
resourcePanelConfigRows = strings.Join(resourcePanelConfigFieldNames, ",")
|
||||
resourcePanelConfigRowsExpectAutoSet = strings.Join(stringx.Remove(resourcePanelConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
resourcePanelConfigRowsWithPlaceHolder = strings.Join(stringx.Remove(resourcePanelConfigFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
|
||||
cachePcmResourcePanelConfigIdPrefix = "cache:pcm:resourcePanelConfig:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
resourcePanelConfigModel interface {
|
||||
Insert(ctx context.Context, data *ResourcePanelConfig) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*ResourcePanelConfig, error)
|
||||
Update(ctx context.Context, data *ResourcePanelConfig) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultResourcePanelConfigModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
ResourcePanelConfig struct {
|
||||
Id int64 `db:"id"`
|
||||
Title string `db:"title"` // 标题
|
||||
TitleColor string `db:"title_color"` // 标题色
|
||||
MainColor string `db:"main_color"` // 主色调
|
||||
MainColor2 string `db:"main_color2"` // 次主色调
|
||||
TextColor string `db:"text_color"` // 文字颜色
|
||||
BackgroundColor string `db:"background_color"` // 背景底色
|
||||
Center string `db:"center"` // 中心点
|
||||
CenterPosition string `db:"center_position"` // 中心点坐标
|
||||
ProvinceBgColor string `db:"province_bg_color"` // 三级地图底色
|
||||
StatusIng string `db:"status_ing"` // 接入中图标
|
||||
StatusUn string `db:"status_un"` // 未接入图标
|
||||
StatusEnd string `db:"status_end"` // 已接入图标
|
||||
TitleIcon string `db:"title_icon"` // 标题底图
|
||||
SubTitleIcon string `db:"sub_title_icon"` // 小标题底图
|
||||
NumberBg string `db:"number_bg"` // 数字底图
|
||||
TaskBg string `db:"task_bg"` // 任务底图
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newResourcePanelConfigModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultResourcePanelConfigModel {
|
||||
return &defaultResourcePanelConfigModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`resource_panel_config`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) Delete(ctx context.Context, id int64) error {
|
||||
pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, pcmResourcePanelConfigIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) FindOne(ctx context.Context, id int64) (*ResourcePanelConfig, error) {
|
||||
pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, id)
|
||||
var resp ResourcePanelConfig
|
||||
err := m.QueryRowCtx(ctx, &resp, pcmResourcePanelConfigIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourcePanelConfigRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) Insert(ctx context.Context, data *ResourcePanelConfig) (sql.Result, error) {
|
||||
pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, data.Id)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, resourcePanelConfigRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.TitleColor, data.MainColor, data.MainColor2, data.TextColor, data.BackgroundColor, data.Center, data.CenterPosition, data.ProvinceBgColor, data.StatusIng, data.StatusUn, data.StatusEnd, data.TitleIcon, data.SubTitleIcon, data.NumberBg, data.TaskBg)
|
||||
}, pcmResourcePanelConfigIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) Update(ctx context.Context, data *ResourcePanelConfig) error {
|
||||
pcmResourcePanelConfigIdKey := fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, data.Id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, resourcePanelConfigRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.TitleColor, data.MainColor, data.MainColor2, data.TextColor, data.BackgroundColor, data.Center, data.CenterPosition, data.ProvinceBgColor, data.StatusIng, data.StatusUn, data.StatusEnd, data.TitleIcon, data.SubTitleIcon, data.NumberBg, data.TaskBg, data.Id)
|
||||
}, pcmResourcePanelConfigIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cachePcmResourcePanelConfigIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resourcePanelConfigRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultResourcePanelConfigModel) tableName() string {
|
||||
return m.table
|
||||
}
|
Loading…
Reference in New Issue