From b8dbe7312e31c161c40f92f3b4607e59455712c8 Mon Sep 17 00:00:00 2001 From: jagger Date: Mon, 11 Mar 2024 18:34:59 +0800 Subject: [PATCH] :sparkles: Dictionary configuration function is implemented Signed-off-by: jagger Former-commit-id: 3408273f72bacda5687fae7e0d41d4aff5ff33f7 --- api/desc/core/pcm-core.api | 111 ++++++++++++++++++ api/desc/pcm.api | 37 ++++++ .../handler/dictionary/adddicthandler.go | 24 ++++ .../handler/dictionary/adddictitemhandler.go | 24 ++++ .../handler/dictionary/deletedicthandler.go | 24 ++++ .../dictionary/deletedictitemhandler.go | 24 ++++ .../handler/dictionary/editdicthandler.go | 24 ++++ .../handler/dictionary/editdictitemhandler.go | 24 ++++ .../handler/dictionary/getdicthandler.go | 24 ++++ .../handler/dictionary/getdictitemhandler.go | 24 ++++ .../handler/dictionary/listdicthandler.go | 24 ++++ .../handler/dictionary/listdictitemhandler.go | 24 ++++ api/internal/handler/routes.go | 57 +++++++++ .../logic/dictionary/adddictitemlogic.go | 56 +++++++++ api/internal/logic/dictionary/adddictlogic.go | 43 +++++++ .../logic/dictionary/deletedictitemlogic.go | 39 ++++++ .../logic/dictionary/deletedictlogic.go | 43 +++++++ .../logic/dictionary/editdictitemlogic.go | 38 ++++++ .../logic/dictionary/editdictlogic.go | 40 +++++++ .../logic/dictionary/getdictitemlogic.go | 38 ++++++ api/internal/logic/dictionary/getdictlogic.go | 38 ++++++ .../logic/dictionary/listdictitemlogic.go | 39 ++++++ .../logic/dictionary/listdictlogic.go | 39 ++++++ api/internal/types/types.go | 106 +++++++++++++++++ 24 files changed, 964 insertions(+) create mode 100644 api/internal/handler/dictionary/adddicthandler.go create mode 100644 api/internal/handler/dictionary/adddictitemhandler.go create mode 100644 api/internal/handler/dictionary/deletedicthandler.go create mode 100644 api/internal/handler/dictionary/deletedictitemhandler.go create mode 100644 api/internal/handler/dictionary/editdicthandler.go create mode 100644 api/internal/handler/dictionary/editdictitemhandler.go create mode 100644 api/internal/handler/dictionary/getdicthandler.go create mode 100644 api/internal/handler/dictionary/getdictitemhandler.go create mode 100644 api/internal/handler/dictionary/listdicthandler.go create mode 100644 api/internal/handler/dictionary/listdictitemhandler.go create mode 100644 api/internal/logic/dictionary/adddictitemlogic.go create mode 100644 api/internal/logic/dictionary/adddictlogic.go create mode 100644 api/internal/logic/dictionary/deletedictitemlogic.go create mode 100644 api/internal/logic/dictionary/deletedictlogic.go create mode 100644 api/internal/logic/dictionary/editdictitemlogic.go create mode 100644 api/internal/logic/dictionary/editdictlogic.go create mode 100644 api/internal/logic/dictionary/getdictitemlogic.go create mode 100644 api/internal/logic/dictionary/getdictlogic.go create mode 100644 api/internal/logic/dictionary/listdictitemlogic.go create mode 100644 api/internal/logic/dictionary/listdictlogic.go diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 463f2137..f67c756f 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -819,3 +819,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"` + } +) \ No newline at end of file diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 69910fb3..f082f3f2 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -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) } \ No newline at end of file diff --git a/api/internal/handler/dictionary/adddicthandler.go b/api/internal/handler/dictionary/adddicthandler.go new file mode 100644 index 00000000..f97da1bb --- /dev/null +++ b/api/internal/handler/dictionary/adddicthandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/adddictitemhandler.go b/api/internal/handler/dictionary/adddictitemhandler.go new file mode 100644 index 00000000..44dbe883 --- /dev/null +++ b/api/internal/handler/dictionary/adddictitemhandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/deletedicthandler.go b/api/internal/handler/dictionary/deletedicthandler.go new file mode 100644 index 00000000..e65e54c2 --- /dev/null +++ b/api/internal/handler/dictionary/deletedicthandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/deletedictitemhandler.go b/api/internal/handler/dictionary/deletedictitemhandler.go new file mode 100644 index 00000000..65139c09 --- /dev/null +++ b/api/internal/handler/dictionary/deletedictitemhandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/editdicthandler.go b/api/internal/handler/dictionary/editdicthandler.go new file mode 100644 index 00000000..fe0ef391 --- /dev/null +++ b/api/internal/handler/dictionary/editdicthandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/editdictitemhandler.go b/api/internal/handler/dictionary/editdictitemhandler.go new file mode 100644 index 00000000..295e9095 --- /dev/null +++ b/api/internal/handler/dictionary/editdictitemhandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/getdicthandler.go b/api/internal/handler/dictionary/getdicthandler.go new file mode 100644 index 00000000..b1b56d0d --- /dev/null +++ b/api/internal/handler/dictionary/getdicthandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/getdictitemhandler.go b/api/internal/handler/dictionary/getdictitemhandler.go new file mode 100644 index 00000000..bbfe113f --- /dev/null +++ b/api/internal/handler/dictionary/getdictitemhandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/listdicthandler.go b/api/internal/handler/dictionary/listdicthandler.go new file mode 100644 index 00000000..72dac7c8 --- /dev/null +++ b/api/internal/handler/dictionary/listdicthandler.go @@ -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) + } +} diff --git a/api/internal/handler/dictionary/listdictitemhandler.go b/api/internal/handler/dictionary/listdictitemhandler.go new file mode 100644 index 00000000..16df182d --- /dev/null +++ b/api/internal/handler/dictionary/listdictitemhandler.go @@ -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) + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index decfc7b4..73b25377 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -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"), + ) } diff --git a/api/internal/logic/dictionary/adddictitemlogic.go b/api/internal/logic/dictionary/adddictitemlogic.go new file mode 100644 index 00000000..22f8f667 --- /dev/null +++ b/api/internal/logic/dictionary/adddictitemlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/adddictlogic.go b/api/internal/logic/dictionary/adddictlogic.go new file mode 100644 index 00000000..fa8b01bd --- /dev/null +++ b/api/internal/logic/dictionary/adddictlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/deletedictitemlogic.go b/api/internal/logic/dictionary/deletedictitemlogic.go new file mode 100644 index 00000000..a65a5069 --- /dev/null +++ b/api/internal/logic/dictionary/deletedictitemlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/deletedictlogic.go b/api/internal/logic/dictionary/deletedictlogic.go new file mode 100644 index 00000000..47eb68f8 --- /dev/null +++ b/api/internal/logic/dictionary/deletedictlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/editdictitemlogic.go b/api/internal/logic/dictionary/editdictitemlogic.go new file mode 100644 index 00000000..1960a483 --- /dev/null +++ b/api/internal/logic/dictionary/editdictitemlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/editdictlogic.go b/api/internal/logic/dictionary/editdictlogic.go new file mode 100644 index 00000000..26e6930b --- /dev/null +++ b/api/internal/logic/dictionary/editdictlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/getdictitemlogic.go b/api/internal/logic/dictionary/getdictitemlogic.go new file mode 100644 index 00000000..3fa71aec --- /dev/null +++ b/api/internal/logic/dictionary/getdictitemlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/getdictlogic.go b/api/internal/logic/dictionary/getdictlogic.go new file mode 100644 index 00000000..cb230204 --- /dev/null +++ b/api/internal/logic/dictionary/getdictlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/listdictitemlogic.go b/api/internal/logic/dictionary/listdictitemlogic.go new file mode 100644 index 00000000..2179aeec --- /dev/null +++ b/api/internal/logic/dictionary/listdictitemlogic.go @@ -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 +} diff --git a/api/internal/logic/dictionary/listdictlogic.go b/api/internal/logic/dictionary/listdictlogic.go new file mode 100644 index 00000000..15959cef --- /dev/null +++ b/api/internal/logic/dictionary/listdictlogic.go @@ -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 +} diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 7073c61b..ed84c8ae 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -787,6 +787,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"`