From 42275e0d82e15fd358bee580849522f25304cac8 Mon Sep 17 00:00:00 2001 From: devad Date: Wed, 24 May 2023 17:20:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B5=84=E6=BA=90=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: devad Former-commit-id: 6a45c0696142ecd131f0ba11e659c869bd97d09c --- adaptor/PCM-CORE/api/desc/core/pcm-core.api | 44 ++++++ adaptor/PCM-CORE/api/desc/pcm.api | 6 + .../core/getresourcepanelconfighandler.go | 18 +++ .../core/putresourcepanelconfighandler.go | 26 ++++ .../PCM-CORE/api/internal/handler/routes.go | 10 ++ .../logic/core/getresourcepanelconfiglogic.go | 32 +++++ .../logic/core/putresourcepanelconfiglogic.go | 40 ++++++ adaptor/PCM-CORE/api/internal/types/types.go | 42 ++++++ .../model/resourcepanelconfigmodel.go | 27 ++++ .../model/resourcepanelconfigmodel_gen.go | 126 ++++++++++++++++++ 10 files changed, 371 insertions(+) create mode 100644 adaptor/PCM-CORE/api/internal/handler/core/getresourcepanelconfighandler.go create mode 100644 adaptor/PCM-CORE/api/internal/handler/core/putresourcepanelconfighandler.go create mode 100644 adaptor/PCM-CORE/api/internal/logic/core/getresourcepanelconfiglogic.go create mode 100644 adaptor/PCM-CORE/api/internal/logic/core/putresourcepanelconfiglogic.go create mode 100755 adaptor/PCM-CORE/model/resourcepanelconfigmodel.go create mode 100755 adaptor/PCM-CORE/model/resourcepanelconfigmodel_gen.go diff --git a/adaptor/PCM-CORE/api/desc/core/pcm-core.api b/adaptor/PCM-CORE/api/desc/core/pcm-core.api index 47c268f3..17b6d3ee 100644 --- a/adaptor/PCM-CORE/api/desc/core/pcm-core.api +++ b/adaptor/PCM-CORE/api/desc/core/pcm-core.api @@ -302,4 +302,48 @@ type ( NodeCount string `json:"nodeCount"` //节点数量 // 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"` //更新时间 + } ) \ No newline at end of file diff --git a/adaptor/PCM-CORE/api/desc/pcm.api b/adaptor/PCM-CORE/api/desc/pcm.api index 9f1b671d..6dc1a14a 100644 --- a/adaptor/PCM-CORE/api/desc/pcm.api +++ b/adaptor/PCM-CORE/api/desc/pcm.api @@ -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二级接口 diff --git a/adaptor/PCM-CORE/api/internal/handler/core/getresourcepanelconfighandler.go b/adaptor/PCM-CORE/api/internal/handler/core/getresourcepanelconfighandler.go new file mode 100644 index 00000000..3a4052f1 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/core/getresourcepanelconfighandler.go @@ -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) + } +} diff --git a/adaptor/PCM-CORE/api/internal/handler/core/putresourcepanelconfighandler.go b/adaptor/PCM-CORE/api/internal/handler/core/putresourcepanelconfighandler.go new file mode 100644 index 00000000..0cca6ad7 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/handler/core/putresourcepanelconfighandler.go @@ -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) + } +} diff --git a/adaptor/PCM-CORE/api/internal/handler/routes.go b/adaptor/PCM-CORE/api/internal/handler/routes.go index c1ba6219..7acf9dc8 100644 --- a/adaptor/PCM-CORE/api/internal/handler/routes.go +++ b/adaptor/PCM-CORE/api/internal/handler/routes.go @@ -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"), ) diff --git a/adaptor/PCM-CORE/api/internal/logic/core/getresourcepanelconfiglogic.go b/adaptor/PCM-CORE/api/internal/logic/core/getresourcepanelconfiglogic.go new file mode 100644 index 00000000..3be7e089 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/core/getresourcepanelconfiglogic.go @@ -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 +} diff --git a/adaptor/PCM-CORE/api/internal/logic/core/putresourcepanelconfiglogic.go b/adaptor/PCM-CORE/api/internal/logic/core/putresourcepanelconfiglogic.go new file mode 100644 index 00000000..5e2aa407 --- /dev/null +++ b/adaptor/PCM-CORE/api/internal/logic/core/putresourcepanelconfiglogic.go @@ -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 +} diff --git a/adaptor/PCM-CORE/api/internal/types/types.go b/adaptor/PCM-CORE/api/internal/types/types.go index b6e70758..50522c5d 100644 --- a/adaptor/PCM-CORE/api/internal/types/types.go +++ b/adaptor/PCM-CORE/api/internal/types/types.go @@ -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"` diff --git a/adaptor/PCM-CORE/model/resourcepanelconfigmodel.go b/adaptor/PCM-CORE/model/resourcepanelconfigmodel.go new file mode 100755 index 00000000..3bb1bce8 --- /dev/null +++ b/adaptor/PCM-CORE/model/resourcepanelconfigmodel.go @@ -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...), + } +} diff --git a/adaptor/PCM-CORE/model/resourcepanelconfigmodel_gen.go b/adaptor/PCM-CORE/model/resourcepanelconfigmodel_gen.go new file mode 100755 index 00000000..4c464703 --- /dev/null +++ b/adaptor/PCM-CORE/model/resourcepanelconfigmodel_gen.go @@ -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 +}