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"`
|
||||
Type string `form:"type,optional"`
|
||||
Status string `form:"status,optional"`
|
||||
PageInfo
|
||||
}
|
||||
|
||||
DictEditReq {
|
||||
|
@ -723,6 +724,7 @@ type (
|
|||
Type string `form:"type,optional"`
|
||||
ParentId string `form:"parentId,optional"`
|
||||
Status string `form:"status,optional"`
|
||||
PageInfo
|
||||
}
|
||||
|
||||
DictItemEditReq {
|
||||
|
@ -754,6 +756,10 @@ type (
|
|||
DictItems {
|
||||
List []DictItemInfo `json:"list,omitempty"`
|
||||
}
|
||||
|
||||
DictCodeReq {
|
||||
DictCode string `path:"dictCode"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
|
@ -765,3 +771,17 @@ type (
|
|||
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)
|
||||
|
||||
@handler ListDict
|
||||
get /dicts (DictReq) returns (Dicts)
|
||||
get /dicts (DictReq) returns (PageResult)
|
||||
|
||||
@handler AddDict
|
||||
post /dict (DictEditReq) returns (DictResp)
|
||||
|
@ -889,7 +889,7 @@ service pcm {
|
|||
get /dictItem/:id (CId) returns (DictItemResp)
|
||||
|
||||
@handler ListDictItem
|
||||
get /dictItems (DictItemReq) returns (DictItems)
|
||||
get /dictItems (DictItemReq) returns (PageResult)
|
||||
|
||||
@handler AddDictItem
|
||||
post /dictItem (DictItemEditReq) returns (DictItemResp)
|
||||
|
@ -899,4 +899,7 @@ service pcm {
|
|||
|
||||
@handler DeleteDictItem
|
||||
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",
|
||||
Handler: dictionary.DeleteDictItemHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/dictItem/code/:dictCode",
|
||||
Handler: dictionary.ListDictItemByCodeHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
|
|
@ -30,6 +30,7 @@ func (l *EditDictItemLogic) EditDictItem(req *types.DictItemEditReq) (resp *type
|
|||
dictItem := &types.DictItemInfo{}
|
||||
result := l.svcCtx.DbEngin.Table("t_dict_item").First(&dictItem, req.Id)
|
||||
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")
|
||||
}
|
||||
utils.Convert(req, &dictItem)
|
||||
|
|
|
@ -31,6 +31,7 @@ func (l *EditDictLogic) EditDict(req *types.DictEditReq) (resp *types.DictResp,
|
|||
dict := &types.DictInfo{}
|
||||
result := l.svcCtx.DbEngin.Table("t_dict").First(&dict, req.Id)
|
||||
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
||||
logx.Errorf("Dictionary editing failure. errors: %s", err.Error())
|
||||
return nil, errors.New("Dict does not exist")
|
||||
}
|
||||
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 (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"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) {
|
||||
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`)
|
||||
func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.PageResult, err error) {
|
||||
limit := req.PageSize
|
||||
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 != "" {
|
||||
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 tx.Error != nil {
|
||||
logx.Errorf(tx.Error.Error())
|
||||
return nil, tx.Error
|
||||
if req.ItemValue != "" {
|
||||
db = db.Where("item_value LIKE ?", "%"+req.ItemValue+"%")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package dictionary
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||
"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) {
|
||||
resp = &types.Dicts{}
|
||||
sqlStr := "select * from t_dict where `deleted_at` IS NULL ORDER BY create_time Desc"
|
||||
func (l *ListDictLogic) ListDict(req *types.DictReq) (resp *types.PageResult, err error) {
|
||||
limit := req.PageSize
|
||||
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 != "" {
|
||||
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 tx.Error != nil {
|
||||
logx.Errorf(tx.Error.Error())
|
||||
return nil, tx.Error
|
||||
if req.DictCode != "" {
|
||||
db = db.Where("dict_code LIKE ?", "%"+req.DictCode+"%")
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -653,6 +653,7 @@ type DictReq struct {
|
|||
Description string `form:"description,optional"`
|
||||
Type string `form:"type,optional"`
|
||||
Status string `form:"status,optional"`
|
||||
PageInfo
|
||||
}
|
||||
|
||||
type DictEditReq struct {
|
||||
|
@ -702,6 +703,7 @@ type DictItemReq struct {
|
|||
Type string `form:"type,optional"`
|
||||
ParentId string `form:"parentId,optional"`
|
||||
Status string `form:"status,optional"`
|
||||
PageInfo
|
||||
}
|
||||
|
||||
type DictItemEditReq struct {
|
||||
|
@ -734,6 +736,10 @@ type DictItems struct {
|
|||
List []DictItemInfo `json:"list,omitempty"`
|
||||
}
|
||||
|
||||
type DictCodeReq struct {
|
||||
DictCode string `path:"dictCode"`
|
||||
}
|
||||
|
||||
type CId struct {
|
||||
Id string `path:"id":"id,omitempty" validate:"required"`
|
||||
}
|
||||
|
@ -742,6 +748,18 @@ type CIds struct {
|
|||
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 {
|
||||
SlurmVersion string `json:"slurmVersion"`
|
||||
Name string `json:"name"`
|
||||
|
|
Loading…
Reference in New Issue