经皮湿水仪init and bind's all api
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
Nacos:
|
||||
Hosts:
|
||||
- host.docker.internal:8848
|
||||
NamespaceId: test
|
||||
Group: LONE_SERVICES
|
||||
RegisterIP: percutaneous
|
||||
ConfigID: percutaneous
|
||||
@@ -0,0 +1,13 @@
|
||||
package config
|
||||
|
||||
type Config struct {
|
||||
Nacos NacosConf
|
||||
}
|
||||
|
||||
type NacosConf struct {
|
||||
Hosts []string
|
||||
NamespaceId string `json:",optional"`
|
||||
Group string `json:",optional"`
|
||||
RegisterIP string `json:",optional"`
|
||||
ConfigID string `json:",optional"`
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package dao
|
||||
|
||||
import "lone-services/pkg/utils"
|
||||
|
||||
type UsedLog struct {
|
||||
Id int64 `json:"id" gorm:"id"`
|
||||
HostUserId int64 `json:"host_user_id" gorm:"host_user_id"` // 用户ID
|
||||
HostCode string `json:"host_code" gorm:"host_code"` // 设备号
|
||||
UserId int64 `json:"user_id" gorm:"user_id"` // 使用人的ID
|
||||
Data string `json:"data" gorm:"data"` // 数据
|
||||
Stamp utils.CustomTime `json:"stamp" gorm:"stamp"` // 标记,多次使用一个标记
|
||||
Position int32 `json:"position" gorm:"position"` // 位置
|
||||
}
|
||||
|
||||
type UsedLogInfo struct {
|
||||
Id int64 `json:"id" gorm:"id"`
|
||||
HostUserId int64 `json:"host_user_id" gorm:"host_user_id"` // 用户ID
|
||||
HostCode string `json:"host_code" gorm:"host_code"` // 设备号
|
||||
UserId int64 `json:"user_id" gorm:"user_id"` // 使用人的ID
|
||||
Data string `json:"data" gorm:"data"` // 数据
|
||||
Stamp utils.CustomTime `json:"stamp" gorm:"stamp"` // 标记,多次使用一个标记
|
||||
Position int32 `json:"position" gorm:"position"` // 位置
|
||||
CreateTime utils.CustomTime `json:"create_time" gorm:"create_time"` // 时间
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package dao
|
||||
|
||||
import "lone-services/pkg/utils"
|
||||
|
||||
const (
|
||||
UserTypeStore = 1
|
||||
UserTypeUser = 2
|
||||
|
||||
WifiDone = 1
|
||||
WifiNotDone = 2
|
||||
)
|
||||
|
||||
type Wifi struct {
|
||||
Id int64 `json:"id" gorm:"id"`
|
||||
UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID
|
||||
UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店
|
||||
Done int32 `json:"done" gorm:"done"` // 是否配置了wifi,2为没有配置,1为配置了
|
||||
}
|
||||
|
||||
type WifiInfo struct {
|
||||
Id int64 `json:"id" gorm:"id"`
|
||||
UserId int64 `json:"user_id" gorm:"user_id"` // 用户ID
|
||||
UserType int32 `json:"user_type" gorm:"user_type"` // 用户类型,1为用户,2为门店
|
||||
Done int32 `json:"done" gorm:"done"` // 是否配置了wifi,2为没有配置,1为配置了
|
||||
UpdateTime utils.CustomTime `json:"update_time" gorm:"update_time"`
|
||||
CarteTime utils.CustomTime `json:"carte_time" gorm:"carte_time"`
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
percutaneous "lone-services/rpc/percutaneous/pb"
|
||||
"reflect"
|
||||
"strconv"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type BaseLogic struct {
|
||||
}
|
||||
|
||||
func (l *BaseLogic) checkParams(in interface{}, v validate.IValidator) *percutaneous.Response {
|
||||
rv := reflect.ValueOf(in)
|
||||
if rv.Kind() != reflect.Ptr || rv.IsNil() {
|
||||
return &percutaneous.Response{
|
||||
Code: utils.ErrorParams.Code,
|
||||
Msg: "request must be non‑nil proto pointer",
|
||||
}
|
||||
}
|
||||
|
||||
resp := validate.ValidateFromProto(in, v)
|
||||
if resp != utils.StringEmpty {
|
||||
return &percutaneous.Response{
|
||||
Code: utils.ErrorParams.Code,
|
||||
Msg: resp,
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) fail(status utils.Status) (*percutaneous.Response, error) {
|
||||
return l.out(status, status.Msg)
|
||||
}
|
||||
func (l *BaseLogic) out(status utils.Status, msg string) (*percutaneous.Response, error) {
|
||||
return &percutaneous.Response{Code: status.Code, Msg: msg}, nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) outData(status utils.Status, msg, data string) (*percutaneous.Response, error) {
|
||||
return &percutaneous.Response{Code: status.Code, Msg: msg, Data: data}, nil
|
||||
}
|
||||
|
||||
func (l *BaseLogic) ok(data any) (*percutaneous.Response, error) {
|
||||
buf, _ := jsoniter.Marshal(data)
|
||||
return &percutaneous.Response{Code: utils.Ok.Code, Msg: utils.Ok.Msg, Data: string(buf)}, nil
|
||||
}
|
||||
|
||||
func (s BaseLogic) SetWhere(w *modelbase.Params, u utils.UserInfo) {
|
||||
if u.Type == utils.SaleType {
|
||||
s.SetGroupWhere(w, u, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (s BaseLogic) SetGroupWhere(w *modelbase.Params, u utils.UserInfo, checkProvince bool) {
|
||||
if w.Eq == nil {
|
||||
w.Eq = make(map[string]string)
|
||||
}
|
||||
if u.GroupId < utils.NumberOne {
|
||||
return
|
||||
}
|
||||
|
||||
//如果是公司销售
|
||||
if u.Type == utils.SaleType {
|
||||
w.Eq["group_id"] = strconv.Itoa(int(u.GroupId))
|
||||
} else if u.SaleProvince > utils.NumberZero {
|
||||
if checkProvince {
|
||||
w.Eq["sale_province"] = strconv.Itoa(int(u.SaleProvince))
|
||||
} else {
|
||||
w.Eq["group_id"] = strconv.Itoa(int(u.GroupId))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/percutaneous/validator"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UseLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewUseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UseLogic {
|
||||
return &UseLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UseLogic) Use(in *percutaneous.UseRequest) (*percutaneous.Response, error) {
|
||||
var v validator.UseValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
return l.ok(nil)
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UsedLogLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewUsedLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UsedLogLogic {
|
||||
return &UsedLogLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UsedLogLogic) UsedLog(in *percutaneous.UsedLogRequest) (*percutaneous.Response, error) {
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
//items.Items = info
|
||||
//return l.ok(items)
|
||||
return l.ok(nil)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/percutaneous/validator"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WifiCheckLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWifiCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WifiCheckLogic {
|
||||
return &WifiCheckLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WifiCheckLogic) WifiCheck(in *percutaneous.WifiCheckRequest) (*percutaneous.Response, error) {
|
||||
var v validator.HostCodeValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
return l.ok(nil)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/percutaneous/validator"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WifiSetLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewWifiSetLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WifiSetLogic {
|
||||
return &WifiSetLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WifiSetLogic) WifiSet(in *percutaneous.WifiSetRequest) (*percutaneous.Response, error) {
|
||||
var v validator.HostCodeValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
|
||||
return l.ok(nil)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/percutaneous/internal/dao"
|
||||
)
|
||||
|
||||
type UsedLogModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m UsedLogModel) TableName() string {
|
||||
return modelbase.Prefix() + "used_log"
|
||||
}
|
||||
|
||||
func (m UsedLogModel) Init() UsedLogModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m UsedLogModel) Create(data *dao.UsedLog) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/services/percutaneous/internal/dao"
|
||||
)
|
||||
|
||||
type WifiModel struct {
|
||||
modelbase.Base
|
||||
}
|
||||
|
||||
func (m WifiModel) TableName() string {
|
||||
return modelbase.Prefix() + "wifi"
|
||||
}
|
||||
|
||||
func (m WifiModel) Init() WifiModel {
|
||||
m.Table = m.TableName()
|
||||
return m
|
||||
}
|
||||
|
||||
func (m WifiModel) Create(data *dao.Wifi) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.2
|
||||
// Source: percutaneous.proto
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
"lone-services/services/percutaneous/internal/logic"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
)
|
||||
|
||||
type PercutaneousServer struct {
|
||||
svcCtx *svc.ServiceContext
|
||||
percutaneous.UnimplementedPercutaneousServer
|
||||
}
|
||||
|
||||
func NewPercutaneousServer(svcCtx *svc.ServiceContext) *PercutaneousServer {
|
||||
return &PercutaneousServer{
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PercutaneousServer) WifiCheck(ctx context.Context, in *percutaneous.WifiCheckRequest) (*percutaneous.Response, error) {
|
||||
l := logic.NewWifiCheckLogic(ctx, s.svcCtx)
|
||||
return l.WifiCheck(in)
|
||||
}
|
||||
|
||||
func (s *PercutaneousServer) WifiSet(ctx context.Context, in *percutaneous.WifiSetRequest) (*percutaneous.Response, error) {
|
||||
l := logic.NewWifiSetLogic(ctx, s.svcCtx)
|
||||
return l.WifiSet(in)
|
||||
}
|
||||
|
||||
func (s *PercutaneousServer) Use(ctx context.Context, in *percutaneous.UseRequest) (*percutaneous.Response, error) {
|
||||
l := logic.NewUseLogic(ctx, s.svcCtx)
|
||||
return l.Use(in)
|
||||
}
|
||||
|
||||
func (s *PercutaneousServer) UsedLog(ctx context.Context, in *percutaneous.UsedLogRequest) (*percutaneous.Response, error) {
|
||||
l := logic.NewUsedLogLogic(ctx, s.svcCtx)
|
||||
return l.UsedLog(in)
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/services/percutaneous/internal/config"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
Prefix string
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"lone-services/pkg/discovery"
|
||||
"lone-services/pkg/logRedis"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/mysql"
|
||||
"lone-services/pkg/redis"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
percutaneous "lone-services/rpc/percutaneous/pb"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"lone-services/services/percutaneous/internal/config"
|
||||
"lone-services/services/percutaneous/internal/server"
|
||||
"lone-services/services/percutaneous/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/conf"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "etc/percutaneous.yaml", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
var c config.Config
|
||||
conf.MustLoad(*configFile, &c)
|
||||
|
||||
// Nacos配置拉取初始化
|
||||
nacosParam := utils.NacosConfig{
|
||||
Hosts: c.Nacos.Hosts,
|
||||
NamespaceId: c.Nacos.NamespaceId,
|
||||
Group: c.Nacos.Group,
|
||||
ConfigID: c.Nacos.ConfigID,
|
||||
}
|
||||
fmt.Println("Nacos Config:", nacosParam)
|
||||
utils.InitConfig(nacosParam)
|
||||
|
||||
// 日志配置
|
||||
logConf := logx.LogConf{
|
||||
ServiceName: utils.GetConfigString("log.serviceName"),
|
||||
Mode: utils.GetConfigString("log.mode"),
|
||||
Encoding: utils.GetConfigString("log.encoding"),
|
||||
Level: utils.GetConfigString("log.level"),
|
||||
Path: utils.GetConfigString("log.path"),
|
||||
KeepDays: utils.GetConfigInt("log.keepDays"),
|
||||
MaxSize: utils.GetConfigInt("log.maxSize"),
|
||||
MaxBackups: utils.GetConfigInt("log.maxBackups"),
|
||||
Compress: utils.GetConfigBool("log.compress"),
|
||||
}
|
||||
logx.SetUp(logConf)
|
||||
logx.AddWriter(logx.NewWriter(os.Stdout))
|
||||
|
||||
listenOn := utils.GetConfigString("base.listenOn")
|
||||
mode := utils.GetConfigString("base.mode")
|
||||
serviceName := utils.GetConfigString("base.name")
|
||||
|
||||
// 初始化服务发现
|
||||
if err := discovery.Init(discovery.Config{
|
||||
Hosts: c.Nacos.Hosts,
|
||||
NamespaceId: c.Nacos.NamespaceId,
|
||||
Group: c.Nacos.Group,
|
||||
}); err != nil {
|
||||
logx.Errorf("nacos init: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
port, err := listenPort(listenOn)
|
||||
if err != nil {
|
||||
logx.Errorf("parse ListenOn: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// 注册服务
|
||||
if err := discovery.Register(discovery.Instance{
|
||||
ServiceName: serviceName,
|
||||
IP: c.Nacos.RegisterIP,
|
||||
Port: port,
|
||||
Group: c.Nacos.Group,
|
||||
}); err != nil {
|
||||
logx.Errorf("nacos register: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logx.Infof("服务注册成功: %s:%d", c.Nacos.RegisterIP, port)
|
||||
|
||||
defer func() {
|
||||
if err := discovery.Deregister(); err != nil {
|
||||
logx.Errorf("nacos deregister: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// 初始化MySQL
|
||||
db, err := mysql.New(mysql.Config{
|
||||
Host: utils.GetConfigString("mysql.host"),
|
||||
Port: utils.GetConfigInt("mysql.port"),
|
||||
User: utils.GetConfigString("mysql.user"),
|
||||
Password: utils.GetConfigString("mysql.password"),
|
||||
Database: utils.GetConfigString("mysql.database"),
|
||||
Charset: utils.GetConfigString("mysql.charset"),
|
||||
Prefix: utils.GetConfigString("mysql.prefix"),
|
||||
ReadHost: utils.GetConfigString("mysql_read.host"),
|
||||
ReadPort: utils.GetConfigInt("mysql_read.port"),
|
||||
ReadUser: utils.GetConfigString("mysql_read.user"),
|
||||
ReadPassword: utils.GetConfigString("mysql_read.password"),
|
||||
ReadDatabase: utils.GetConfigString("mysql_read.database"),
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("mysql init: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// 初始化Redis
|
||||
if err := redis.Init(redis.Config{
|
||||
Host: utils.GetConfigString("redis.host"),
|
||||
Port: utils.GetConfigInt("redis.port"),
|
||||
Password: utils.GetConfigString("redis.password"),
|
||||
DB: utils.GetConfigInt("redis.db"),
|
||||
}); err != nil {
|
||||
logx.Errorf("redis init: %v", err)
|
||||
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})
|
||||
|
||||
// 初始化服务信息
|
||||
rpcConf := zrpc.RpcServerConf{
|
||||
ListenOn: listenOn,
|
||||
}
|
||||
rpcConf.Mode = mode
|
||||
ctx := svc.NewServiceContext(c, db)
|
||||
|
||||
s := zrpc.MustNewServer(rpcConf, func(grpcServer *grpc.Server) {
|
||||
percutaneous.RegisterPercutaneousServer(grpcServer, server.NewPercutaneousServer(ctx))
|
||||
if mode == service.DevMode || mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
s.AddUnaryInterceptors(validate.UnaryServerInterceptor(validate.MustNew()))
|
||||
|
||||
logx.Infof("Starting rpc server at %s...", listenOn)
|
||||
s.Start()
|
||||
}
|
||||
|
||||
// listenPort 拆分端口
|
||||
func listenPort(listenOn string) (uint64, error) {
|
||||
_, portStr, err := net.SplitHostPort(listenOn)
|
||||
if err != nil {
|
||||
return utils.NumberZero, err
|
||||
}
|
||||
return strconv.ParseUint(portStr, utils.NumberTen, utils.NumberSixtyFourth)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.10.2
|
||||
// Source: percutaneous.proto
|
||||
|
||||
package percutaneousClient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/rpc/percutaneous/pb"
|
||||
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type (
|
||||
Response = percutaneous.Response
|
||||
UseRequest = percutaneous.UseRequest
|
||||
UsedLogRequest = percutaneous.UsedLogRequest
|
||||
WifiCheckRequest = percutaneous.WifiCheckRequest
|
||||
WifiSetRequest = percutaneous.WifiSetRequest
|
||||
|
||||
Percutaneous interface {
|
||||
WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
WifiSet(ctx context.Context, in *WifiSetRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
Use(ctx context.Context, in *UseRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
UsedLog(ctx context.Context, in *UsedLogRequest, opts ...grpc.CallOption) (*Response, error)
|
||||
}
|
||||
|
||||
defaultPercutaneous struct {
|
||||
cli zrpc.Client
|
||||
}
|
||||
)
|
||||
|
||||
func NewPercutaneous(cli zrpc.Client) Percutaneous {
|
||||
return &defaultPercutaneous{
|
||||
cli: cli,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultPercutaneous) WifiCheck(ctx context.Context, in *WifiCheckRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := percutaneous.NewPercutaneousClient(m.cli.Conn())
|
||||
return client.WifiCheck(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultPercutaneous) WifiSet(ctx context.Context, in *WifiSetRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := percutaneous.NewPercutaneousClient(m.cli.Conn())
|
||||
return client.WifiSet(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultPercutaneous) Use(ctx context.Context, in *UseRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := percutaneous.NewPercutaneousClient(m.cli.Conn())
|
||||
return client.Use(ctx, in, opts...)
|
||||
}
|
||||
|
||||
func (m *defaultPercutaneous) UsedLog(ctx context.Context, in *UsedLogRequest, opts ...grpc.CallOption) (*Response, error) {
|
||||
client := percutaneous.NewPercutaneousClient(m.cli.Conn())
|
||||
return client.UsedLog(ctx, in, opts...)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
[base]
|
||||
port = 8060
|
||||
name = "percutaneous-service"
|
||||
listenOn = "0.0.0.0:11600"
|
||||
mode = "dev"
|
||||
[log]
|
||||
path = "logs"
|
||||
serviceName = "percutaneous-service"
|
||||
mode = "file"
|
||||
encoding = "plain"
|
||||
level = "info"
|
||||
keepDays = 7
|
||||
maxSize = 50
|
||||
maxBackups = 5
|
||||
compress = false
|
||||
# 测试的地址
|
||||
[mysql]
|
||||
host = '39.106.171.204'
|
||||
port = 33066
|
||||
user = 'root'
|
||||
password = 'MOLXRZNOU4Y4'
|
||||
database = 'dms-percutaneous'
|
||||
charset = 'utf8mb4'
|
||||
prefix = ''
|
||||
debug = true
|
||||
[mysql_read]
|
||||
host = '39.106.171.204'
|
||||
port = 33066
|
||||
user = 'root'
|
||||
password = 'MOLXRZNOU4Y4'
|
||||
database = 'dms-percutaneous'
|
||||
charset = 'utf8mb4'
|
||||
prefix = ''
|
||||
|
||||
[redis]
|
||||
host = '39.106.171.204'
|
||||
password = 'lLMLcuPpzSj'
|
||||
port = 6379
|
||||
db = 1
|
||||
[log-redis]
|
||||
host = '39.106.171.204'
|
||||
password = 'lLMLcuPpzSj'
|
||||
port = 6379
|
||||
db = 3
|
||||
[encrypt]
|
||||
data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a" #内容数据,
|
||||
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
package validator
|
||||
|
||||
import "lone-services/pkg/validate"
|
||||
|
||||
// UseValidator 查看列表
|
||||
type UseValidator struct {
|
||||
HostCode string `validate:"required"`
|
||||
UserId int64 `validate:"required"`
|
||||
Data string `validate:"required"`
|
||||
Stamp int32 `validate:"required"`
|
||||
Position string
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p UseValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"HostCode.required": "设备不能为空",
|
||||
"UserId.required": "用户不能为空",
|
||||
"Data.required": "数据不能为空",
|
||||
"Stamp.required": "标记不能为空",
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package validator
|
||||
|
||||
import "lone-services/pkg/validate"
|
||||
|
||||
// HostCodeValidator 查看列表
|
||||
type HostCodeValidator struct {
|
||||
HostCode string `validate:"required"`
|
||||
}
|
||||
|
||||
// GetMessage 查看列表 - 提示消息
|
||||
func (p HostCodeValidator) GetMessage() validate.ValidatorMessages {
|
||||
return validate.ValidatorMessages{
|
||||
"HostCode.required": "设备不能为空",
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user