package v1
|
|
import (
|
"aps_crm/conf"
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"aps_crm/pkg/logx"
|
"aps_crm/proto/code"
|
"github.com/gin-gonic/gin"
|
"github.com/spf13/cast"
|
"google.golang.org/grpc"
|
"google.golang.org/grpc/credentials/insecure"
|
)
|
|
type CodeApi struct{}
|
|
var (
|
codeServiceConn *grpc.ClientConn
|
)
|
|
func InitCodeServiceConn() {
|
var err error
|
codeServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Aps, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
if err != nil {
|
logx.Errorf("grpc dial product service error: %v", err.Error())
|
return
|
}
|
}
|
|
func CloseCodeServiceConn() {
|
if codeServiceConn != nil {
|
codeServiceConn.Close()
|
}
|
}
|
|
// GetCodeList
|
//
|
// @Tags 编码
|
// @Summary 获取编码列表
|
// @Produce application/json
|
// @Param object query request.GetCodeList true "参数"
|
// @Success 200 {object} response.ListResponse
|
//
|
// @Router /api/code/getCodeList [get]
|
func (ca *CodeApi) GetCodeList(c *gin.Context) {
|
var params request.GetCodeList
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
params.CodeStandID = c.Query("codeStandID")
|
params.Name = c.Query("name")
|
params.Type = c.Query("type")
|
client := code.NewCodeServiceClient(codeServiceConn)
|
list, err := client.GetCodeList(ctx.GetCtx(), &code.GetCodeListRequest{
|
Page: cast.ToInt32(params.Page),
|
PageSize: cast.ToInt32(params.PageSize),
|
CodeStandID: params.CodeStandID,
|
Name: params.Name,
|
Type: params.Type,
|
})
|
if err != nil {
|
logx.Errorf("GetCodeList err: %v", err.Error())
|
ctx.FailWithMsg(ecode.UnknownErr, "grpc调用错误")
|
return
|
}
|
ctx.OkWithDetailed(response.ListResponse{
|
Data: list.List,
|
Count: list.Total,
|
})
|
}
|