order apis
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"lone-services/pkg/discovery"
|
||||
"lone-services/pkg/logRedis"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/mysql"
|
||||
"lone-services/pkg/redis"
|
||||
@@ -124,6 +125,16 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if err := logRedis.Init(logRedis.LogRedisConfig{
|
||||
Host: utils.GetConfigString("log-redis.host"),
|
||||
Port: utils.GetConfigInt("log-redis.port"),
|
||||
Password: utils.GetConfigString("log-redis.password"),
|
||||
DB: utils.GetConfigInt("log-redis.db"),
|
||||
}); err != nil {
|
||||
logx.Errorf("log redis init: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
debug := utils.GetConfigBool("mysql.debug")
|
||||
modelbase.Init(db, modelbase.Config{Prefix: utils.GetConfigString("mysql.prefix"), Debug: debug})
|
||||
|
||||
|
||||
@@ -14,13 +14,19 @@ import (
|
||||
)
|
||||
|
||||
type (
|
||||
EmtpyRequest = express.EmtpyRequest
|
||||
Request = express.Request
|
||||
Response = express.Response
|
||||
CreateRequest = express.CreateRequest
|
||||
EmtpyRequest = express.EmtpyRequest
|
||||
IdRequest = express.IdRequest
|
||||
Response = express.Response
|
||||
StatusRequest = express.StatusRequest
|
||||
|
||||
Express interface {
|
||||
Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
|
||||
Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Edit(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Names(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
defaultExpress struct {
|
||||
@@ -34,12 +40,32 @@ func NewExpress(cli zrpc.Client) Express {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Ping(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Ping(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Items(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Items(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Create(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Edit(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Edit(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Info(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Info(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Names(ctx context.Context, in *EmtpyRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Names(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultExpress) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := express.NewExpressClient(m.cli.Conn())
|
||||
return client.Status(ctx, in, opts...)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package dao
|
||||
|
||||
type Express struct {
|
||||
Id int64 `json:"id" gorm:"id"` // ID
|
||||
Name string `json:"name" gorm:"name"` // 名称
|
||||
TransitId uint8 `json:"transit_id" gorm:"transit_id"` // 快递公司,1为顺丰,2为京东,3为。。。
|
||||
AppCode string `json:"app_code" gorm:"app_code"` // app 代码
|
||||
AppSecretKey string `json:"app_secret_key" gorm:"app_secret_key"` // app 密钥
|
||||
AppUrl string `json:"app_url" gorm:"app_url"` // 接口地址
|
||||
CardNumber string `json:"card_number" gorm:"card_number"` // 月结卡号
|
||||
PdfCode string `json:"pdf_code" gorm:"pdf_code"` // pdf文件编码
|
||||
Province string `json:"province" gorm:"province"` // 省
|
||||
City string `json:"city" gorm:"city"` // 市
|
||||
County string `json:"county" gorm:"county"` // 县/区
|
||||
Address string `json:"address" gorm:"address"` // 地址
|
||||
CompanyName string `json:"company_name" gorm:"company_name"` // 公司名
|
||||
Contact string `json:"contact" gorm:"contact"` // 联系人
|
||||
Mobile string `json:"mobile" gorm:"mobile"` // 联系人手机号
|
||||
Other string `json:"other" gorm:"other"` // 基它数据
|
||||
Status uint8 `json:"status" gorm:"status"` // 状态,1为正常,2为禁用
|
||||
Reason string `json:"reason" gorm:"reason"` // 原因
|
||||
AdminId int64 `json:"admin_id" gorm:"admin_id"` // 操作人ID
|
||||
AdminName string `json:"admin_name" gorm:"admin_name"` // 操作人姓名
|
||||
}
|
||||
type ExpressInfo struct {
|
||||
Id int64 `json:"id" gorm:"id"` // ID
|
||||
Name string `json:"name" gorm:"name"` // 名称
|
||||
TransitId uint8 `json:"transit_id" gorm:"transit_id"` // 快递公司,1为顺丰,2为京东,3为。。。
|
||||
AppCode string `json:"app_code" gorm:"app_code"` // app 代码
|
||||
AppSecretKey string `json:"app_secret_key" gorm:"app_secret_key"` // app 密钥
|
||||
AppUrl string `json:"app_url" gorm:"app_url"` // 接口地址
|
||||
CardNumber string `json:"card_number" gorm:"card_number"` // 月结卡号
|
||||
PdfCode string `json:"pdf_code" gorm:"pdf_code"` // pdf文件编码
|
||||
Province string `json:"province" gorm:"province"` // 省
|
||||
City string `json:"city" gorm:"city"` // 市
|
||||
County string `json:"county" gorm:"county"` // 县/区
|
||||
Address string `json:"address" gorm:"address"` // 地址
|
||||
CompanyName string `json:"company_name" gorm:"company_name"` // 公司名
|
||||
Contact string `json:"contact" gorm:"contact"` // 联系人
|
||||
Mobile string `json:"mobile" gorm:"mobile"` // 联系人手机号
|
||||
Other string `json:"other" gorm:"other"` // 基它数据
|
||||
Status uint8 `json:"status" gorm:"status"` // 状态,1为正常,2为禁用
|
||||
Reason string `json:"reason" gorm:"reason"` // 原因
|
||||
}
|
||||
|
||||
type ExpressNames struct {
|
||||
Id int64 `json:"id" gorm:"id"` // ID
|
||||
Name string `json:"name" gorm:"name"` // 名称
|
||||
}
|
||||
|
||||
type ExpressStatus struct {
|
||||
Id int64 `json:"id" gorm:"id"` // ID
|
||||
Status uint8 `json:"status" gorm:"status"` // 状态,1为正常,2为禁用
|
||||
Reason string `json:"reason" gorm:"reason"` // 原因
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/express/pb"
|
||||
"lone-services/services/express/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogic {
|
||||
return &CreateLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateLogic) Create(in *express.CreateRequest) (*express.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &express.Response{}, nil
|
||||
}
|
||||
+6
-6
@@ -2,30 +2,30 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
express "lone-services/rpc/express/pb"
|
||||
|
||||
"lone-services/rpc/express/pb"
|
||||
"lone-services/services/express/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PingLogic struct {
|
||||
type EditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
|
||||
return &PingLogic{
|
||||
func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic {
|
||||
return &EditLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PingLogic) Ping(in *express.Request) (*express.Response, error) {
|
||||
func (l *EditLogic) Edit(in *express.CreateRequest) (*express.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return l.ok("this is a test")
|
||||
return &express.Response{}, nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/express/pb"
|
||||
"lone-services/services/express/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 *express.IdRequest) (*express.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &express.Response{}, nil
|
||||
}
|
||||
@@ -2,8 +2,10 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/rpc/express/pb"
|
||||
"lone-services/services/express/internal/dao"
|
||||
"lone-services/services/express/internal/model"
|
||||
"lone-services/services/express/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
@@ -13,6 +15,7 @@ type ItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic {
|
||||
@@ -24,7 +27,12 @@ func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic
|
||||
}
|
||||
|
||||
func (l *ItemsLogic) Items(in *express.EmtpyRequest) (*express.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
modelObj := model.ExpressModel{}.Init()
|
||||
w := modelbase.Params{}
|
||||
|
||||
var data []dao.ExpressInfo
|
||||
items, _ := modelObj.Page(w, &data)
|
||||
|
||||
return l.ok(items)
|
||||
|
||||
return &express.Response{}, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/express/pb"
|
||||
"lone-services/services/express/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type NamesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NamesLogic {
|
||||
return &NamesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *NamesLogic) Names(in *express.EmtpyRequest) (*express.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &express.Response{}, nil
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/express/pb"
|
||||
"lone-services/services/express/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type StatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic {
|
||||
return &StatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *StatusLogic) Status(in *express.StatusRequest) (*express.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return &express.Response{}, nil
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/express/internal/dao"
|
||||
)
|
||||
|
||||
type ExpressModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m ExpressModel) TableName() string {
|
||||
return modelbase.Prefix() + "express"
|
||||
}
|
||||
|
||||
func (m ExpressModel) Init() ExpressModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m ExpressModel) Create(data *dao.Express) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -23,12 +23,32 @@ func NewExpressServer(svcCtx *svc.ServiceContext) *ExpressServer {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Ping(ctx context.Context, in *express.Request) (*express.Response, error) {
|
||||
l := logic.NewPingLogic(ctx, s.svcCtx)
|
||||
return l.Ping(in)
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Items(ctx context.Context, in *express.EmtpyRequest) (*express.Response, error) {
|
||||
l := logic.NewItemsLogic(ctx, s.svcCtx)
|
||||
return l.Items(in)
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Create(ctx context.Context, in *express.CreateRequest) (*express.Response, error) {
|
||||
l := logic.NewCreateLogic(ctx, s.svcCtx)
|
||||
return l.Create(in)
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Edit(ctx context.Context, in *express.CreateRequest) (*express.Response, error) {
|
||||
l := logic.NewEditLogic(ctx, s.svcCtx)
|
||||
return l.Edit(in)
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Info(ctx context.Context, in *express.IdRequest) (*express.Response, error) {
|
||||
l := logic.NewInfoLogic(ctx, s.svcCtx)
|
||||
return l.Info(in)
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Names(ctx context.Context, in *express.EmtpyRequest) (*express.Response, error) {
|
||||
l := logic.NewNamesLogic(ctx, s.svcCtx)
|
||||
return l.Names(in)
|
||||
}
|
||||
|
||||
func (s *ExpressServer) Status(ctx context.Context, in *express.StatusRequest) (*express.Response, error) {
|
||||
l := logic.NewStatusLogic(ctx, s.svcCtx)
|
||||
return l.Status(in)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package validator
|
||||
|
||||
import "lone-services/pkg/validate"
|
||||
|
||||
type EditValidator struct {
|
||||
Id int64 `validate:""`
|
||||
Name string `validate:"required"`
|
||||
TransitId int32 `validate:"required"`
|
||||
AppCode string `validate:"required"`
|
||||
AppSecretKey string `validate:"required"`
|
||||
AppUrl string `validate:"required"`
|
||||
CardNumber string `validate:"required"`
|
||||
Province string
|
||||
City string
|
||||
County string
|
||||
Address string
|
||||
CompanyName string
|
||||
Contact string
|
||||
Mobile string
|
||||
PdfCode string
|
||||
Other string
|
||||
}
|
||||
|
||||
// GetMessage 校验提示消息
|
||||
func (p EditValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Name.required": "请输入名称",
|
||||
"TransitId.required": "缺少快递ID",
|
||||
"AppCode.required": "请输入APP代码",
|
||||
"AppSecretKey.required": "请输入APP密钥",
|
||||
"AppUrl.required": "请输入接口地址",
|
||||
"CardNumber.required": "请输入月结卡号",
|
||||
}
|
||||
}
|
||||
|
||||
type StatusValidator struct {
|
||||
Id int64 `validate:"required"`
|
||||
Status int32 `validate:"required,oneof=1 2"`
|
||||
Reason string `validate:"required_if=Status 2"`
|
||||
}
|
||||
|
||||
// GetMessage 修改状态 - 提示消息
|
||||
func (p StatusValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Id.required": "ID不能为空",
|
||||
"Status.required": "状态不能为空",
|
||||
"Status.oneof": "状态传值不对",
|
||||
"Reason.required_if": "理由不能为空",
|
||||
}
|
||||
}
|
||||
|
||||
type InfoValidator struct {
|
||||
Id int64 `validate:"required"`
|
||||
}
|
||||
|
||||
func (p InfoValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"Id.required": "ID不能为空",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user