15a5616308
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / aiserver (push) Successful in 0s
CI / analysis (push) Successful in 37s
CI / bff (push) Successful in 18s
CI / chore (push) Successful in 0s
CI / equipment (push) Successful in 0s
CI / express (push) Successful in 1s
CI / factory (push) Successful in 0s
CI / message (push) Successful in 0s
CI / order (push) Successful in 0s
CI / payment (push) Successful in 0s
CI / percutaneous (push) Successful in 0s
CI / product (push) Successful in 0s
CI / record (push) Successful in 1s
CI / sale (push) Successful in 0s
CI / store (push) Successful in 22s
CI / support (push) Successful in 0s
CI / task (push) Successful in 0s
CI / user (push) Successful in 21s
CI / water (push) Successful in 0s
CI / wecom (push) Successful in 0s
CI / ws (push) Successful in 0s
106 lines
2.7 KiB
Go
106 lines
2.7 KiB
Go
package analysisadminlogic
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
analysis "lone-services/rpc/analysis/pb"
|
|
"lone-services/services/analysis/internal/dao"
|
|
"lone-services/services/analysis/internal/logic/common"
|
|
"lone-services/services/analysis/internal/model"
|
|
"lone-services/services/analysis/internal/svc"
|
|
"lone-services/services/analysis/validator"
|
|
|
|
jsoniter "github.com/json-iterator/go"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GraphListLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGraphListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GraphListLogic {
|
|
return &GraphListLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GraphListLogic) GraphList(in *analysis.AdminGraphListReq) (*analysis.Response, error) {
|
|
var req validator.AdminGraphListValidator
|
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
|
return outParams(msg), nil
|
|
}
|
|
if _, fail := common.RequireAdmin(l.ctx); fail != nil {
|
|
return fail, nil
|
|
}
|
|
|
|
params := modelbase.Params{
|
|
Eq: map[string]string{
|
|
"status": strconv.Itoa(utils.StatusOk),
|
|
},
|
|
Order: "id desc",
|
|
Page: int(req.Page),
|
|
Size: int(req.Size),
|
|
}
|
|
if req.Type > utils.NumberZero {
|
|
params.Eq["type"] = strconv.Itoa(int(req.Type))
|
|
}
|
|
if req.Name != utils.StringEmpty {
|
|
params.Like = map[string]string{
|
|
"name LIKE ?": "%" + req.Name + "%",
|
|
}
|
|
}
|
|
|
|
var rows []dao.UserGraph
|
|
page, err := model.GraphModel{}.Init().Page(params, &rows)
|
|
if err != nil {
|
|
l.Errorf("admin graph list: %v", err)
|
|
return common.FailResponse(utils.Fail), nil
|
|
}
|
|
if len(rows) == utils.NumberZero {
|
|
page.Items = []dao.GraphResource{}
|
|
return common.OkResponse(page), nil
|
|
}
|
|
|
|
var types []dao.UserGraphType
|
|
err = model.GraphTypeModel{}.Init().Items(modelbase.Params{
|
|
Eq: map[string]string{
|
|
"status": strconv.Itoa(utils.StatusOk),
|
|
},
|
|
}, &types)
|
|
if err != nil {
|
|
l.Errorf("admin graph list types: %v", err)
|
|
return common.FailResponse(utils.Fail), nil
|
|
}
|
|
typeMap := make(map[int]string, len(types))
|
|
for _, t := range types {
|
|
typeMap[int(t.Id)] = t.Name
|
|
}
|
|
|
|
list := make([]dao.GraphResource, 0, len(rows))
|
|
for _, row := range rows {
|
|
var title []dao.GraphTitleItem
|
|
var images []dao.GraphImageItem
|
|
_ = jsoniter.UnmarshalFromString(row.Title, &title)
|
|
_ = jsoniter.UnmarshalFromString(row.Images, &images)
|
|
list = append(list, dao.GraphResource{
|
|
Id: row.Id,
|
|
Type: row.Type,
|
|
TypeName: typeMap[row.Type],
|
|
Name: row.Name,
|
|
Title: title,
|
|
Images: images,
|
|
CreateAt: row.CreateAt,
|
|
})
|
|
}
|
|
page.Items = list
|
|
return common.OkResponse(page), nil
|
|
}
|