Merge pull request 'Dictionary configuration function is implemented' (#43) from devad/pcm-coordinator:master into master

Former-commit-id: fabd218b267c0253a399ad4cbab58d0c58b6ff64
This commit is contained in:
devad 2024-03-11 18:39:18 +08:00
commit 271175d0c2
24 changed files with 964 additions and 0 deletions

View File

@ -820,3 +820,114 @@ type ClusterRelationInfo {
CAuthType string `json:"cAuthType,omitempty" db:"auth_type"`
CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
type (
DictInfo {
Id string `json:"id,omitempty"`
DictName string `json:"dictName,omitempty"`
DictCode string `json:"dictCode,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty" db:"type"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
DictReq {
Id string `form:"id,optional"`
DictName string `form:"dictName,optional"`
DictCode string `form:"dictCode,optional"`
Description string `form:"description,optional"`
Type string `form:"type,optional"`
Status string `form:"status,optional"`
}
DictEditReq {
Id string `json:"id,optional"`
DictName string `json:"dictName,optional"`
DictCode string `json:"dictCode,optional"`
Description string `json:"description,optional"`
Type string `json:"type,optional"`
Status string `json:"status,optional"`
}
DictResp {
Id string `json:"id,omitempty"`
DictName string `json:"dictName,omitempty"`
DictCode string `json:"dictCode,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Status string `json:"status,omitempty"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
DictItemInfo []*DictItemInfo `json:"dictItemInfo,omitempty"`
}
Dicts {
List []DictInfo `json:"list,omitempty"`
}
DictItemInfo {
Id string `json:"id,omitempty"`
DictId string `json:"dictId,omitempty"`
ItemText string `json:"itemText,omitempty"`
ItemValue string `json:"itemValue,omitempty"`
Description string `json:"description,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
Type string `json:"type,omitempty" db:"type"`
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
DictItemReq {
Id string `form:"id,optional"`
DictId string `form:"dictId,optional"`
ItemText string `form:"itemText,optional"`
ItemValue string `form:"itemValue,optional"`
Description string `form:"description,optional"`
SortOrder string `form:"sortOrder,optional"`
Type string `form:"type,optional"`
ParentId string `form:"parentId,optional"`
Status string `form:"status,optional"`
}
DictItemEditReq {
Id string `json:"id,optional"`
DictId string `json:"dictId,optional"`
ItemText string `json:"itemText,optional"`
ItemValue string `json:"itemValue,optional"`
Description string `json:"description,optional"`
SortOrder string `json:"sortOrder,optional"`
Type string `json:"type,optional"`
ParentId string `json:"parentId,optional"`
Status string `json:"status,optional"`
}
DictItemResp {
Id string `json:"id,omitempty"`
DictId string `json:"dictId,omitempty"`
ItemText string `json:"itemText,omitempty"`
ItemValue string `json:"itemValue,omitempty"`
Description string `json:"description,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
Type string `json:"type,omitempty"`
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
DictInfo *DictInfo `json:"dictInfo,omitempty"`
}
DictItems {
List []DictItemInfo `json:"list,omitempty"`
}
)
type (
CId {
Id string `path:"id":"id,omitempty" validate:"required"`
}
CIds {
Ids []string `json:"ids,omitempty" validate:"required"`
}
)

View File

@ -866,4 +866,41 @@ service pcm {
@handler ScheduleSubmitHandler
post /schedule/submit (ScheduleReq) returns (ScheduleResp)
}
@server(
prefix: pcm/v1
group : dictionary
)
service pcm {
@handler GetDict
get /dict/:id (CId) returns (DictResp)
@handler ListDict
get /dicts (DictReq) returns (Dicts)
@handler AddDict
post /dict (DictEditReq) returns (DictResp)
@handler EditDict
put /dict (DictEditReq) returns (DictResp)
@handler DeleteDict
delete /dict/:id (CId) returns (DictResp)
@handler GetDictItem
get /dictItem/:id (CId) returns (DictItemResp)
@handler ListDictItem
get /dictItems (DictItemReq) returns (DictItems)
@handler AddDictItem
post /dictItem (DictItemEditReq) returns (DictItemResp)
@handler EditDictItem
put /dictItem (DictItemEditReq) returns (DictItemResp)
@handler DeleteDictItem
delete /dictItem/:id (CId) returns (DictItemResp)
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func AddDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DictEditReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewAddDictLogic(r.Context(), svcCtx)
resp, err := l.AddDict(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func AddDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DictItemEditReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewAddDictItemLogic(r.Context(), svcCtx)
resp, err := l.AddDictItem(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func DeleteDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CId
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewDeleteDictLogic(r.Context(), svcCtx)
resp, err := l.DeleteDict(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func DeleteDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CId
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewDeleteDictItemLogic(r.Context(), svcCtx)
resp, err := l.DeleteDictItem(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func EditDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DictEditReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewEditDictLogic(r.Context(), svcCtx)
resp, err := l.EditDict(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func EditDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DictItemEditReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewEditDictItemLogic(r.Context(), svcCtx)
resp, err := l.EditDictItem(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func GetDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CId
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewGetDictLogic(r.Context(), svcCtx)
resp, err := l.GetDict(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func GetDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.CId
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewGetDictItemLogic(r.Context(), svcCtx)
resp, err := l.GetDictItem(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func ListDictHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DictReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewListDictLogic(r.Context(), svcCtx)
resp, err := l.ListDict(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -0,0 +1,24 @@
package dictionary
import (
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/dictionary"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
)
func ListDictItemHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.DictItemReq
if err := httpx.Parse(r, &req); err != nil {
result.ParamErrorResult(r, w, err)
return
}
l := dictionary.NewListDictItemLogic(r.Context(), svcCtx)
resp, err := l.ListDictItem(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -9,6 +9,7 @@ import (
apps "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/apps"
cloud "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/cloud"
core "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/core"
dictionary "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/dictionary"
hpc "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/hpc"
image "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/image"
schedule "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/handler/schedule"
@ -1076,4 +1077,60 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
rest.WithPrefix("/pcm/v1"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/dict/:id",
Handler: dictionary.GetDictHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/dicts",
Handler: dictionary.ListDictHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/dict",
Handler: dictionary.AddDictHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/dict",
Handler: dictionary.EditDictHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/dict/:id",
Handler: dictionary.DeleteDictHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/dictItem/:id",
Handler: dictionary.GetDictItemHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/dictItems",
Handler: dictionary.ListDictItemHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/dictItem",
Handler: dictionary.AddDictItemHandler(serverCtx),
},
{
Method: http.MethodPut,
Path: "/dictItem",
Handler: dictionary.EditDictItemHandler(serverCtx),
},
{
Method: http.MethodDelete,
Path: "/dictItem/:id",
Handler: dictionary.DeleteDictItemHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)
}

View File

@ -0,0 +1,56 @@
package dictionary
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm"
"time"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AddDictItemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDictItemLogic {
return &AddDictItemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AddDictItemLogic) AddDictItem(req *types.DictItemEditReq) (resp *types.DictItemResp, err error) {
dict := &types.DictInfo{}
result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.DictId)
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, errors.New("Dictionary does not exist")
}
var dictItem types.DictItemInfo
dictItem.DictId = req.DictId
dictItem.ItemText = req.ItemText
dictItem.ItemValue = req.ItemValue
dictItem.Description = req.Description
dictItem.SortOrder = req.SortOrder
dictItem.Type = req.Type
if req.ParentId != "" {
dictItem.ParentId = req.ParentId
}
dictItem.ParentId = "0"
dictItem.Status = req.Status
dictItem.Id = utils.GenSnowflakeIDStr()
dictItem.CreateTime = time.Now().Format("2006-01-02 15:04:05")
result = l.svcCtx.DbEngin.Table("t_dict_item").Create(&dictItem)
if result.Error != nil {
logx.Errorf("Failed to create dictionary item , errors: %s", result.Error)
return nil, result.Error
}
return
}

View File

@ -0,0 +1,43 @@
package dictionary
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"time"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AddDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAddDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddDictLogic {
return &AddDictLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AddDictLogic) AddDict(req *types.DictEditReq) (resp *types.DictResp, err error) {
dict := &types.DictInfo{}
dict.DictName = req.DictName
dict.DictCode = req.DictCode
dict.Type = req.Type
dict.Description = req.Description
dict.Id = utils.GenSnowflakeIDStr()
dict.CreateTime = time.Now().Format("2006-01-02 15:04:05")
dict.Status = req.Status
result := l.svcCtx.DbEngin.Table("t_dict").Create(&dict)
if result.Error != nil {
logx.Errorf("Failed to create dictionary , errors: %s", result.Error)
return nil, result.Error
}
return
}

View File

@ -0,0 +1,39 @@
package dictionary
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteDictItemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictItemLogic {
return &DeleteDictItemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteDictItemLogic) DeleteDictItem(req *types.CId) (resp *types.DictItemResp, err error) {
db := l.svcCtx.DbEngin.Table("t_dict_item").Where("id = ?", req.Id).First(&types.DictItemInfo{})
if db.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Dictionary item does not exist")
}
tx := l.svcCtx.DbEngin.Table("t_dict_item").Delete(types.DictItemInfo{}, req.Id)
if tx.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Delete dictionary item failed")
}
return
}

View File

@ -0,0 +1,43 @@
package dictionary
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDeleteDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteDictLogic {
return &DeleteDictLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DeleteDictLogic) DeleteDict(req *types.CId) (resp *types.DictResp, err error) {
var sId int64
l.svcCtx.DbEngin.Table("t_dict").Raw("select d.id from t_dict_item di left join t_dict d on di.dict_id=d.id where d.id=? limit 1", req.Id).Scan(&sId)
if sId != 0 {
return nil, errors.New("Delete failed,The dictionary is associated with a dictionary item")
}
db := l.svcCtx.DbEngin.Table("t_dict").Where("id = ?", req.Id).First(&types.DictInfo{})
if db.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Dictionary does not exist")
}
tx := l.svcCtx.DbEngin.Table("t_dict").Delete(types.DictInfo{}, req.Id)
if tx.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Delete dictionary failed")
}
return
}

View File

@ -0,0 +1,38 @@
package dictionary
import (
"context"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type EditDictItemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDictItemLogic {
return &EditDictItemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *EditDictItemLogic) EditDictItem(req *types.DictItemEditReq) (resp *types.DictItemResp, err error) {
dictItem := &types.DictItemInfo{}
result := l.svcCtx.DbEngin.Table("t_dict_item").First(&dictItem, req.Id)
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, errors.New("DictItem does not exist")
}
utils.Convert(req, &dictItem)
l.svcCtx.DbEngin.Table("t_dict_item").Model(&dictItem).Updates(&dictItem)
return
}

View File

@ -0,0 +1,40 @@
package dictionary
import (
"context"
"fmt"
"github.com/pkg/errors"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type EditDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewEditDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditDictLogic {
return &EditDictLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *EditDictLogic) EditDict(req *types.DictEditReq) (resp *types.DictResp, err error) {
dict := &types.DictInfo{}
result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.Id)
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, errors.New("Dict does not exist")
}
utils.Convert(req, &dict)
tx := l.svcCtx.DbEngin.Table("t_dict").Model(&dict).Updates(&dict)
fmt.Println(tx)
return
}

View File

@ -0,0 +1,38 @@
package dictionary
import (
"context"
"github.com/pkg/errors"
tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetDictItemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictItemLogic {
return &GetDictItemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetDictItemLogic) GetDictItem(req *types.CId) (resp *types.DictItemResp, err error) {
resp = &types.DictItemResp{}
item := &types.DictItemInfo{}
db := l.svcCtx.DbEngin.Table("t_dict_item").Where("id = ?", req.Id).First(&item)
if db.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Dictionary item does not exist")
}
tool.Convert(item, &resp)
return
}

View File

@ -0,0 +1,38 @@
package dictionary
import (
"context"
"github.com/pkg/errors"
tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDictLogic {
return &GetDictLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetDictLogic) GetDict(req *types.CId) (resp *types.DictResp, err error) {
resp = &types.DictResp{}
dict := &types.DictInfo{}
db := l.svcCtx.DbEngin.Table("t_dict").Where("id = ?", req.Id).First(&dict)
if db.Error != nil {
logx.Errorf("err %v", db.Error.Error())
return nil, errors.New("Dictionary does not exist")
}
tool.Convert(dict, &resp)
return
}

View File

@ -0,0 +1,39 @@
package dictionary
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListDictItemLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictItemLogic {
return &ListDictItemLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.DictItems, err error) {
resp = &types.DictItems{}
sql := fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null ORDER BY create_time Desc`)
if req.ItemText != "" {
sql = fmt.Sprintf(`select c.* from t_dict_item c left join t_dict a on c.dict_id = a.id where c.deleted_at is null and c.item_text like '%%%s%%'`, req.ItemText)
}
tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List)
if tx.Error != nil {
logx.Errorf(tx.Error.Error())
return nil, tx.Error
}
return resp, nil
}

View File

@ -0,0 +1,39 @@
package dictionary
import (
"context"
"fmt"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListDictLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictLogic {
return &ListDictLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.Dicts, err error) {
resp = &types.Dicts{}
sqlStr := "select * from t_dict where `deleted_at` IS NULL ORDER BY create_time Desc"
if req.DictName != "" {
sqlStr = fmt.Sprintf("select * from t_dict where `deleted_at` IS NULL and dict_name like '%%%s%%' ORDER BY create_time Desc", req.DictName)
}
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List)
if tx.Error != nil {
logx.Errorf(tx.Error.Error())
return nil, tx.Error
}
return resp, nil
}

View File

@ -788,6 +788,112 @@ type ClusterRelationInfo struct {
CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
type DictInfo struct {
Id string `json:"id,omitempty"`
DictName string `json:"dictName,omitempty"`
DictCode string `json:"dictCode,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty" db:"type"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
type DictReq struct {
Id string `form:"id,optional"`
DictName string `form:"dictName,optional"`
DictCode string `form:"dictCode,optional"`
Description string `form:"description,optional"`
Type string `form:"type,optional"`
Status string `form:"status,optional"`
}
type DictEditReq struct {
Id string `json:"id,optional"`
DictName string `json:"dictName,optional"`
DictCode string `json:"dictCode,optional"`
Description string `json:"description,optional"`
Type string `json:"type,optional"`
Status string `json:"status,optional"`
}
type DictResp struct {
Id string `json:"id,omitempty"`
DictName string `json:"dictName,omitempty"`
DictCode string `json:"dictCode,omitempty"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"`
Status string `json:"status,omitempty"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
DictItemInfo []*DictItemInfo `json:"dictItemInfo,omitempty"`
}
type Dicts struct {
List []DictInfo `json:"list,omitempty"`
}
type DictItemInfo struct {
Id string `json:"id,omitempty"`
DictId string `json:"dictId,omitempty"`
ItemText string `json:"itemText,omitempty"`
ItemValue string `json:"itemValue,omitempty"`
Description string `json:"description,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
Type string `json:"type,omitempty" db:"type"`
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
}
type DictItemReq struct {
Id string `form:"id,optional"`
DictId string `form:"dictId,optional"`
ItemText string `form:"itemText,optional"`
ItemValue string `form:"itemValue,optional"`
Description string `form:"description,optional"`
SortOrder string `form:"sortOrder,optional"`
Type string `form:"type,optional"`
ParentId string `form:"parentId,optional"`
Status string `form:"status,optional"`
}
type DictItemEditReq struct {
Id string `json:"id,optional"`
DictId string `json:"dictId,optional"`
ItemText string `json:"itemText,optional"`
ItemValue string `json:"itemValue,optional"`
Description string `json:"description,optional"`
SortOrder string `json:"sortOrder,optional"`
Type string `json:"type,optional"`
ParentId string `json:"parentId,optional"`
Status string `json:"status,optional"`
}
type DictItemResp struct {
Id string `json:"id,omitempty"`
DictId string `json:"dictId,omitempty"`
ItemText string `json:"itemText,omitempty"`
ItemValue string `json:"itemValue,omitempty"`
Description string `json:"description,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
Type string `json:"type,omitempty"`
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
DictInfo *DictInfo `json:"dictInfo,omitempty"`
}
type DictItems struct {
List []DictItemInfo `json:"list,omitempty"`
}
type CId struct {
Id string `path:"id":"id,omitempty" validate:"required"`
}
type CIds struct {
Ids []string `json:"ids,omitempty" validate:"required"`
}
type Job struct {
SlurmVersion string `json:"slurmVersion"`
Name string `json:"name"`