eb96aaa2ef
CI / changes (push) Successful in 37s
CI / ad (push) Successful in 44s
CI / admin (push) Successful in 39s
CI / bff (push) Successful in 32s
CI / chore (push) Successful in 38s
CI / express (push) Successful in 42s
CI / product (push) Successful in 43s
CI / sale (push) Successful in 42s
CI / task (push) Successful in 42s
CI / user (push) Successful in 42s
CI / wecom (push) Successful in 41s
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
"lone-services/pkg/modelbase"
|
|
"lone-services/pkg/utils"
|
|
"lone-services/pkg/validate"
|
|
product "lone-services/rpc/product/pb"
|
|
"lone-services/services/task/internal/dao"
|
|
"lone-services/services/task/internal/model"
|
|
"strconv"
|
|
|
|
"lone-services/rpc/task/pb"
|
|
"lone-services/services/task/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type InfoLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
logx.Logger
|
|
BaseLogic
|
|
}
|
|
|
|
func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
|
|
return &InfoLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
Logger: logx.WithContext(ctx),
|
|
}
|
|
}
|
|
|
|
func (l *InfoLogic) Info(in *task.IdRequest) (*task.Response, error) {
|
|
var v validate.InfoValidator
|
|
if fail := l.checkParams(in, &v); fail != nil {
|
|
return fail, nil
|
|
}
|
|
|
|
var info dao.TaskInfo
|
|
modelObj := model.TaskModel{}.Init()
|
|
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
|
err := modelObj.GetOne(w, &info)
|
|
if err != nil {
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
if info.ProductId < utils.NumberOne {
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
|
|
cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName)
|
|
if err != nil {
|
|
logx.Errorf("get rpc client err: %v", err)
|
|
return l.fail(utils.ErrorInternalServer)
|
|
}
|
|
productClient := product.NewProductClient(cli.Conn())
|
|
productInfo, err := productClient.InfoById(context.Background(), &product.InfoByIdReq{Id: info.ProductId})
|
|
if err != nil {
|
|
logx.Errorf("get products err: %v", err)
|
|
return l.fail(utils.ErrorInternalServer)
|
|
}
|
|
if info.Id < utils.NumberOne {
|
|
return l.fail(utils.ErrorNotFund)
|
|
}
|
|
info.ProductName = productInfo.Name
|
|
|
|
return l.ok(info)
|
|
}
|