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
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package analysisadminlogic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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 GraphCreateLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
}
|
|
|
|
func NewGraphCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GraphCreateLogic {
|
|
return &GraphCreateLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *GraphCreateLogic) GraphCreate(in *analysis.AdminGraphCreateReq) (*analysis.Response, error) {
|
|
req := validator.AdminGraphCreateValidator{
|
|
Type: int(in.GetType()),
|
|
Name: in.GetName(),
|
|
Title: toAdminGraphTitles(in.GetTitle()),
|
|
Images: toAdminGraphImages(in.GetImages()),
|
|
}
|
|
if msg := validate.ValidateStruct(&req); msg != utils.StringEmpty {
|
|
return outParams(msg), nil
|
|
}
|
|
if _, fail := common.RequireAdmin(l.ctx); fail != nil {
|
|
return fail, nil
|
|
}
|
|
|
|
titleJson, _ := jsoniter.MarshalToString(toDaoGraphTitles(req.Title))
|
|
imagesJson, _ := jsoniter.MarshalToString(toDaoGraphImages(req.Images))
|
|
now := utils.Now()
|
|
err := model.GraphModel{}.Init().Create(&dao.UserGraph{
|
|
Type: req.Type,
|
|
Name: req.Name,
|
|
Title: titleJson,
|
|
Images: imagesJson,
|
|
Status: int8(utils.StatusOk),
|
|
CreateAt: now,
|
|
UpdateAt: now,
|
|
})
|
|
if err != nil {
|
|
l.Errorf("admin graph create: %v", err)
|
|
return common.FailResponse(utils.Fail), nil
|
|
}
|
|
return common.OkResponse(nil), nil
|
|
}
|