jiangshuai
2023-10-17 9e2b19b7336af1e58b7e3861f6cc3a28ad641326
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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, &params)
    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,
    })
}