| | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "google.golang.org/grpc" |
| | | "google.golang.org/grpc/credentials/insecure" |
| | | "wms/conf" |
| | | "wms/constvar" |
| | | cd "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | | "wms/pkg/contextx" |
| | | "wms/pkg/logx" |
| | | "wms/proto/code" |
| | | "wms/proto/init_client" |
| | | "wms/request" |
| | | ) |
| | | |
| | | type CodeApi struct{} |
| | | |
| | | var ( |
| | | codeServiceConn *grpc.ClientConn |
| | | ) |
| | | |
| | | func InitCodeServiceConn() { |
| | | var err error |
| | | codeServiceConn, err = grpc.Dial(conf.GrpcServerConf.ApsAddr, 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() |
| | | } |
| | | } |
| | | //var ( |
| | | // codeServiceConn *grpc.ClientConn |
| | | //) |
| | | // |
| | | //func InitCodeServiceConn() { |
| | | // var err error |
| | | // codeServiceConn, err = grpc.Dial(conf.GrpcServerConf.ApsAddr, 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 |
| | | // |
| | |
| | | params.CodeStandID = c.Query("codeStandID") |
| | | params.Name = c.Query("name") |
| | | params.Type = c.Query("type") |
| | | client := code.NewCodeServiceClient(codeServiceConn) |
| | | client := code.NewCodeServiceClient(init_client.ApsConn) |
| | | list, err := client.GetCodeList(ctx.GetCtx(), &code.GetCodeListRequest{ |
| | | Page: cast.ToInt32(params.Page), |
| | | PageSize: cast.ToInt32(params.PageSize), |
| | |
| | | id = 0 |
| | | err error |
| | | ) |
| | | switch params.Type { |
| | | case "物料编码": |
| | | switch constvar.CodeStandardType(params.Type) { |
| | | case constvar.CodeStandardType_Material: |
| | | id, err = models.NewMaterialSearch().MaxAutoIncr() |
| | | case constvar.CodeStandardType_Incoming: |
| | | id, err = models.NewOperationSearch().SetBaseOperationType(constvar.BaseOperationTypeIncoming).MaxAutoIncr() |
| | | case constvar.CodeStandardType_Outgoing: |
| | | id, err = models.NewOperationSearch().SetBaseOperationType(constvar.BaseOperationTypeOutgoing).MaxAutoIncr() |
| | | case constvar.CodeStandardType_Internal: |
| | | id, err = models.NewOperationSearch().SetBaseOperationType(constvar.BaseOperationTypeInternal).MaxAutoIncr() |
| | | case constvar.CodeStandardType_Disuse: |
| | | id, err = models.NewOperationSearch().SetBaseOperationType(constvar.BaseOperationTypeDisuse).MaxAutoIncr() |
| | | default: |
| | | util.ResponseFormat(c, cd.RequestError, "编码规则不存在") |
| | | return |