Merge pull request 'Dictionary data lists support paging queries Signed-off-by' (#50) from devad/pcm-coordinator:master into master
Former-commit-id: e9baacfc140ae7552d32eff8230089a801cc848a
This commit is contained in:
commit
8abba1912b
|
@ -673,6 +673,7 @@ type (
|
||||||
Description string `form:"description,optional"`
|
Description string `form:"description,optional"`
|
||||||
Type string `form:"type,optional"`
|
Type string `form:"type,optional"`
|
||||||
Status string `form:"status,optional"`
|
Status string `form:"status,optional"`
|
||||||
|
PageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
DictEditReq {
|
DictEditReq {
|
||||||
|
@ -723,6 +724,7 @@ type (
|
||||||
Type string `form:"type,optional"`
|
Type string `form:"type,optional"`
|
||||||
ParentId string `form:"parentId,optional"`
|
ParentId string `form:"parentId,optional"`
|
||||||
Status string `form:"status,optional"`
|
Status string `form:"status,optional"`
|
||||||
|
PageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
DictItemEditReq {
|
DictItemEditReq {
|
||||||
|
@ -754,6 +756,10 @@ type (
|
||||||
DictItems {
|
DictItems {
|
||||||
List []DictItemInfo `json:"list,omitempty"`
|
List []DictItemInfo `json:"list,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DictCodeReq {
|
||||||
|
DictCode string `path:"dictCode"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -765,3 +771,17 @@ type (
|
||||||
Ids []string `json:"ids,omitempty" validate:"required"`
|
Ids []string `json:"ids,omitempty" validate:"required"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
PageInfo {
|
||||||
|
PageNum int `form:"pageNum"`
|
||||||
|
PageSize int `form:"pageSize"`
|
||||||
|
}
|
||||||
|
|
||||||
|
PageResult {
|
||||||
|
List interface{} `json:"list,omitempty"`
|
||||||
|
Total int64 `json:"total,omitempty"`
|
||||||
|
PageNum int `json:"pageNum,omitempty"`
|
||||||
|
PageSize int `json:"pageSize,omitempty"`
|
||||||
|
}
|
||||||
|
)
|
|
@ -874,7 +874,7 @@ service pcm {
|
||||||
get /dict/:id (CId) returns (DictResp)
|
get /dict/:id (CId) returns (DictResp)
|
||||||
|
|
||||||
@handler ListDict
|
@handler ListDict
|
||||||
get /dicts (DictReq) returns (Dicts)
|
get /dicts (DictReq) returns (PageResult)
|
||||||
|
|
||||||
@handler AddDict
|
@handler AddDict
|
||||||
post /dict (DictEditReq) returns (DictResp)
|
post /dict (DictEditReq) returns (DictResp)
|
||||||
|
@ -889,7 +889,7 @@ service pcm {
|
||||||
get /dictItem/:id (CId) returns (DictItemResp)
|
get /dictItem/:id (CId) returns (DictItemResp)
|
||||||
|
|
||||||
@handler ListDictItem
|
@handler ListDictItem
|
||||||
get /dictItems (DictItemReq) returns (DictItems)
|
get /dictItems (DictItemReq) returns (PageResult)
|
||||||
|
|
||||||
@handler AddDictItem
|
@handler AddDictItem
|
||||||
post /dictItem (DictItemEditReq) returns (DictItemResp)
|
post /dictItem (DictItemEditReq) returns (DictItemResp)
|
||||||
|
@ -899,4 +899,7 @@ service pcm {
|
||||||
|
|
||||||
@handler DeleteDictItem
|
@handler DeleteDictItem
|
||||||
delete /dictItem/:id (CId) returns (DictItemResp)
|
delete /dictItem/:id (CId) returns (DictItemResp)
|
||||||
|
|
||||||
|
@handler ListDictItemByCode
|
||||||
|
get /dictItem/code/:dictCode (DictCodeReq) returns (PageResult)
|
||||||
}
|
}
|
|
@ -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 ListDictItemByCodeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.DictCodeReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
result.ParamErrorResult(r, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := dictionary.NewListDictItemByCodeLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.ListDictItemByCode(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1125,6 +1125,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/dictItem/:id",
|
Path: "/dictItem/:id",
|
||||||
Handler: dictionary.DeleteDictItemHandler(serverCtx),
|
Handler: dictionary.DeleteDictItemHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/dictItem/code/:dictCode",
|
||||||
|
Handler: dictionary.ListDictItemByCodeHandler(serverCtx),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/pcm/v1"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -30,6 +30,7 @@ func (l *EditDictItemLogic) EditDictItem(req *types.DictItemEditReq) (resp *type
|
||||||
dictItem := &types.DictItemInfo{}
|
dictItem := &types.DictItemInfo{}
|
||||||
result := l.svcCtx.DbEngin.Table("t_dict_item").First(&dictItem, req.Id)
|
result := l.svcCtx.DbEngin.Table("t_dict_item").First(&dictItem, req.Id)
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
logx.Errorf("Dictionary data editing failure. errors: %s", err.Error())
|
||||||
return nil, errors.New("DictItem does not exist")
|
return nil, errors.New("DictItem does not exist")
|
||||||
}
|
}
|
||||||
utils.Convert(req, &dictItem)
|
utils.Convert(req, &dictItem)
|
||||||
|
|
|
@ -31,6 +31,7 @@ func (l *EditDictLogic) EditDict(req *types.DictEditReq) (resp *types.DictResp,
|
||||||
dict := &types.DictInfo{}
|
dict := &types.DictInfo{}
|
||||||
result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.Id)
|
result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.Id)
|
||||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||||
|
logx.Errorf("Dictionary editing failure. errors: %s", err.Error())
|
||||||
return nil, errors.New("Dict does not exist")
|
return nil, errors.New("Dict does not exist")
|
||||||
}
|
}
|
||||||
utils.Convert(req, &dict)
|
utils.Convert(req, &dict)
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package dictionary
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"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 ListDictItemByCodeLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListDictItemByCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDictItemByCodeLogic {
|
||||||
|
return &ListDictItemByCodeLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListDictItemByCodeLogic) ListDictItemByCode(req *types.DictCodeReq) (resp *types.PageResult, err error) {
|
||||||
|
var dictList []types.DictItemInfo
|
||||||
|
resp = &types.PageResult{}
|
||||||
|
db := l.svcCtx.DbEngin.Model(&types.DictInfo{}).Table("t_dict")
|
||||||
|
|
||||||
|
// 左连接查询
|
||||||
|
db.Select("t_dict_item.*").Joins("left join t_dict_item on t_dict.id = t_dict_item.dict_id").
|
||||||
|
Where("t_dict.dict_code = ?", req.DictCode).
|
||||||
|
Where("t_dict_item.status", 1).
|
||||||
|
Order("t_dict_item.sort_order").Scan(&dictList)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
resp.List = dictList
|
||||||
|
return resp, nil
|
||||||
|
}
|
|
@ -2,8 +2,6 @@ package dictionary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
|
||||||
|
@ -24,16 +22,44 @@ func NewListDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *List
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.DictItems, err error) {
|
func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.PageResult, err error) {
|
||||||
resp = &types.DictItems{}
|
limit := req.PageSize
|
||||||
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`)
|
offset := req.PageSize * (req.PageNum - 1)
|
||||||
|
resp = &types.PageResult{}
|
||||||
|
var dictList []types.DictItemInfo
|
||||||
|
db := l.svcCtx.DbEngin.Model(&types.DictItemInfo{}).Table("t_dict_item")
|
||||||
|
|
||||||
if req.ItemText != "" {
|
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)
|
db = db.Where("item_text LIKE ?", "%"+req.ItemText+"%")
|
||||||
}
|
}
|
||||||
tx := l.svcCtx.DbEngin.Raw(sql).Scan(&resp.List)
|
if req.ItemValue != "" {
|
||||||
if tx.Error != nil {
|
db = db.Where("item_value LIKE ?", "%"+req.ItemValue+"%")
|
||||||
logx.Errorf(tx.Error.Error())
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
}
|
||||||
|
if req.Type != "" {
|
||||||
|
db = db.Where("type = ?", req.Type)
|
||||||
|
}
|
||||||
|
if req.ParentId != "" {
|
||||||
|
db = db.Where("parent_id = ?", req.ParentId)
|
||||||
|
}
|
||||||
|
if req.Status != "" {
|
||||||
|
db = db.Where("status = ?", req.Status)
|
||||||
|
}
|
||||||
|
if req.DictId != "" {
|
||||||
|
db = db.Where("dict_id = ?", req.DictId)
|
||||||
|
}
|
||||||
|
var total int64
|
||||||
|
err = db.Count(&total).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
db = db.Limit(limit).Offset(offset)
|
||||||
|
err = db.Order("create_time desc").Find(&dictList).Error
|
||||||
|
|
||||||
|
resp.List = dictList
|
||||||
|
resp.PageSize = req.PageSize
|
||||||
|
resp.PageNum = req.PageNum
|
||||||
|
resp.Total = total
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package dictionary
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
|
||||||
|
@ -24,16 +22,38 @@ func NewListDictLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDict
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.Dicts, err error) {
|
func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.PageResult, err error) {
|
||||||
resp = &types.Dicts{}
|
limit := req.PageSize
|
||||||
sqlStr := "select * from t_dict where `deleted_at` IS NULL ORDER BY create_time Desc"
|
offset := req.PageSize * (req.PageNum - 1)
|
||||||
|
resp = &types.PageResult{}
|
||||||
|
var dictList []types.DictInfo
|
||||||
|
db := l.svcCtx.DbEngin.Model(&types.DictInfo{}).Table("t_dict")
|
||||||
|
|
||||||
if req.DictName != "" {
|
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)
|
db = db.Where("dict_name LIKE ?", "%"+req.DictName+"%")
|
||||||
}
|
}
|
||||||
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&resp.List)
|
if req.DictCode != "" {
|
||||||
if tx.Error != nil {
|
db = db.Where("dict_code LIKE ?", "%"+req.DictCode+"%")
|
||||||
logx.Errorf(tx.Error.Error())
|
|
||||||
return nil, tx.Error
|
|
||||||
}
|
}
|
||||||
|
if req.Type != "" {
|
||||||
|
db = db.Where("type = ?", req.Type)
|
||||||
|
}
|
||||||
|
if req.Status != "" {
|
||||||
|
db = db.Where("status = ?", req.Status)
|
||||||
|
}
|
||||||
|
var total int64
|
||||||
|
err = db.Count(&total).Error
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
db = db.Limit(limit).Offset(offset)
|
||||||
|
err = db.Order("create_time desc").Find(&dictList).Error
|
||||||
|
|
||||||
|
resp.List = dictList
|
||||||
|
resp.PageSize = req.PageSize
|
||||||
|
resp.PageNum = req.PageNum
|
||||||
|
resp.Total = total
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -653,6 +653,7 @@ type DictReq struct {
|
||||||
Description string `form:"description,optional"`
|
Description string `form:"description,optional"`
|
||||||
Type string `form:"type,optional"`
|
Type string `form:"type,optional"`
|
||||||
Status string `form:"status,optional"`
|
Status string `form:"status,optional"`
|
||||||
|
PageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type DictEditReq struct {
|
type DictEditReq struct {
|
||||||
|
@ -702,6 +703,7 @@ type DictItemReq struct {
|
||||||
Type string `form:"type,optional"`
|
Type string `form:"type,optional"`
|
||||||
ParentId string `form:"parentId,optional"`
|
ParentId string `form:"parentId,optional"`
|
||||||
Status string `form:"status,optional"`
|
Status string `form:"status,optional"`
|
||||||
|
PageInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
type DictItemEditReq struct {
|
type DictItemEditReq struct {
|
||||||
|
@ -734,6 +736,10 @@ type DictItems struct {
|
||||||
List []DictItemInfo `json:"list,omitempty"`
|
List []DictItemInfo `json:"list,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DictCodeReq struct {
|
||||||
|
DictCode string `path:"dictCode"`
|
||||||
|
}
|
||||||
|
|
||||||
type CId struct {
|
type CId struct {
|
||||||
Id string `path:"id":"id,omitempty" validate:"required"`
|
Id string `path:"id":"id,omitempty" validate:"required"`
|
||||||
}
|
}
|
||||||
|
@ -742,6 +748,18 @@ type CIds struct {
|
||||||
Ids []string `json:"ids,omitempty" validate:"required"`
|
Ids []string `json:"ids,omitempty" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PageInfo struct {
|
||||||
|
PageNum int `form:"pageNum"`
|
||||||
|
PageSize int `form:"pageSize"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PageResult struct {
|
||||||
|
List interface{} `json:"list,omitempty"`
|
||||||
|
Total int64 `json:"total,omitempty"`
|
||||||
|
PageNum int `json:"pageNum,omitempty"`
|
||||||
|
PageSize int `json:"pageSize,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type Job struct {
|
type Job struct {
|
||||||
SlurmVersion string `json:"slurmVersion"`
|
SlurmVersion string `json:"slurmVersion"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
Loading…
Reference in New Issue