Commit c4d0e56e by mushishixian

Merge branch 'dev' into ysx-quote-20200628

parents 8443ca0b a9fa6bb9
...@@ -8,3 +8,4 @@ cmd.exe~ ...@@ -8,3 +8,4 @@ cmd.exe~
/cmd/logs/ /cmd/logs/
/cmd/*.exe~ /cmd/*.exe~
/cmd/logs /cmd/logs
/bat/logs/
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/search_server.go -config=../conf/config.ini
\ No newline at end of file
set MICRO_REGISTRY=etcd ::set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379 ::set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/search_http_server.go -config=../conf/config.ini go run ../cmd/search_http_server.go -config=../conf
\ No newline at end of file \ No newline at end of file
package main package main
import ( import (
"flag"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/client/grpc"
"github.com/micro/go-micro/v2/web"
"log"
"search_server/boot"
_ "search_server/controller" _ "search_server/controller"
"search_server/framework/gin_"
"search_server/pkg/config"
) )
func main() { func main() {
//
var path string //var path string
flag.StringVar(&path, "config", "conf/config.ini", "配置文件") //flag.StringVar(&path, "config", "conf/config.ini", "配置文件")
flag.Parse() //flag.Parse()
if err := boot.Boot(path); err != nil { //if err := boot.Boot(path); err != nil {
log.Println(err) // log.Println(err)
} //}
//
r := gin.New() //r := gin.New()
gin_.BootStrap(r) //gin_.BootStrap(r)
//
c:=grpc.NewClient() //c:=grpc.NewClient()
r:=gin.New() //r:=gin.New()
r.Handle("GET","/test", func(ctx *gin.Context) { //r.Handle("GET","/test", func(ctx *gin.Context) {
news // news
c:=Course.NewCourseService("api.jtthink.com.course",c) // c:=Course.NewCourseService("api.jtthink.com.course",c)
course_rsp,_:=c.ListForTop(context.Background(),&Course.ListRequest{Size:10}) // course_rsp,_:=c.ListForTop(context.Background(),&Course.ListRequest{Size:10})
ctx.JSON(200,gin.H{"Result":course_rsp.Result}) // ctx.JSON(200,gin.H{"Result":course_rsp.Result})
}) //})
service:=web.NewService( //service:=web.NewService(
web.Name("api.jtthink.com.http.course"), // web.Name("api.jtthink.com.http.course"),
web.Handler(r), // web.Handler(r),
) //)
//
//
//
port := config.Get("web.port").String() //port := config.Get("web.port").String()
//web改成micro 就是grpc,并直接注册到etcd里面 ////web改成micro 就是grpc,并直接注册到etcd里面
service := web.NewService( //service := web.NewService(
web.Name("go.micro.api.http.course"), // web.Name("go.micro.api.http.course"),
web.Handler(r), // web.Handler(r),
web.Address(":"+port), // web.Address(":"+port),
) //)
//
if err := service.Init(); err != nil { //if err := service.Init(); err != nil {
log.Println(err) // log.Println(err)
} //}
if err := service.Run(); err != nil { //if err := service.Run(); err != nil {
log.Println(err) // log.Println(err)
} //}
} }
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
func main() { func main() {
cService:=micro.NewService( cService:=micro.NewService(
micro.Name("go.micro.server.search")) micro.Name("go.micro.grpc.search"))
cService.Init() cService.Init()
err:=bom.RegisterBomServiceHandler(cService.Server(),service.NewBomServiceImpl()) err:=bom.RegisterBomServiceHandler(cService.Server(),service.NewBomServiceImpl())
......
package main package main
import ( import (
"flag"
"fmt"
"os" "os"
"search_server/boot"
"search_server/pkg/gredis"
"search_server/service" "search_server/service"
) )
func main() { func main() {
//MouserService := service.NewMouserServiceImpl() //MouserService := service.NewMouserServiceImpl()
//MouserGetData(MouserService) //MouserGetData(MouserService)
var path string
flag.StringVar(&path, "config", "conf", "配置文件")
flag.Parse()
if err := boot.Boot(path); err != nil {
panic(err)
}
lock_key := "searchapi_6666";
//flag := gredis.Set(lock_key,php2go.Time()+2)
flag := gredis.Setnx(lock_key,2222)
fmt.Println(flag)
os.Exit(1)
dd := service.OutLink("LM358","-1") dd := service.OutLink("LM358","-1")
print("niin") print("niin")
print(dd) print(dd)
......
[gorm]
mode = debug
[mysql]
user_name = root
password = root
host = 192.168.2.250
database = test1
table_prefix =
type = mysql
[bom]
user_name = root
password = root
host = 192.168.2.250
database = test
table_prefix =
type = mysql
\ No newline at end of file
[default_redis_read]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[default_redis_write]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis_read]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis_write]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
package controller package controller
import ( //func init() {
"github.com/gin-gonic/gin" // courseService := service.NewCourseServiceImpl()
"search_server/framework/gin_" // gin_.NewBuilder().WithService(courseService).
"search_server/protopb/course" // WithMiddleware(Check_Middleware()).
"search_server/service" // WithMiddleware(Cors_Middleware()).
) // WithEndpoint(Courselist_Endpoint(courseService)).
// WithRequest(Courselist_Request()).
func init() { // WithResponse(Course_Response()).Build("/course", "GET")
courseService := service.NewCourseServiceImpl() //
gin_.NewBuilder().WithService(courseService). // gin_.NewBuilder().WithService(courseService).
WithMiddleware(Check_Middleware()). // WithMiddleware(Check_Middleware()).
WithMiddleware(Cors_Middleware()). // WithEndpoint(Coursedetail_Endpoint(courseService)).
WithEndpoint(Courselist_Endpoint(courseService)). // WithRequest(Coursedetail_Request()).
WithRequest(Courselist_Request()). // WithResponse(Course_Response()).Build("/detail/:course_id", "GET")
WithResponse(Course_Response()).Build("/course", "GET") //
//}
gin_.NewBuilder().WithService(courseService). //
WithMiddleware(Check_Middleware()). ////详细相关
WithEndpoint(Coursedetail_Endpoint(courseService)). //func Coursedetail_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint {
WithRequest(Coursedetail_Request()). // return func(context *gin.Context, request interface{}) (response interface{}, err error) {
WithResponse(Course_Response()).Build("/detail/:course_id", "GET") // rsp := &course.DetailResponse{Course: new(course.CourseModel), Counts: make([]*course.CourseCounts, 0)}
// err = c.GetDetail(context, request.(*course.DetailRequest), rsp)
} // return rsp, err
// }
//详细相关 //}
func Coursedetail_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint { //
return func(context *gin.Context, request interface{}) (response interface{}, err error) { ////这个函数的作用是怎么处理请求
rsp := &course.DetailResponse{Course: new(course.CourseModel), Counts: make([]*course.CourseCounts, 0)} //func Coursedetail_Request() gin_.EncodeRequestFunc {
err = c.GetDetail(context, request.(*course.DetailRequest), rsp) // return func(context *gin.Context) (i interface{}, e error) {
return rsp, err // bReq := &course.DetailRequest{}
} // err := context.BindUri(bReq)
} // if err != nil {
// return nil, err
//这个函数的作用是怎么处理请求 // }
func Coursedetail_Request() gin_.EncodeRequestFunc { // err = context.BindHeader(bReq)
return func(context *gin.Context) (i interface{}, e error) { // if err != nil {
bReq := &course.DetailRequest{} // return nil, err
err := context.BindUri(bReq) // }
if err != nil { // return bReq, nil
return nil, err // }
} //}
err = context.BindHeader(bReq) //
if err != nil { ////获取列表相关
return nil, err //func Courselist_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint {
} // return func(context *gin.Context, request interface{}) (response interface{}, err error) {
return bReq, nil // rsp := &course.ListResponse{}
} // err = c.ListForTop(context, request.(*course.ListRequest), rsp)
} // return rsp, err
// }
//获取列表相关 //}
func Courselist_Endpoint(c *service.CourseServiceImpl) gin_.Endpoint { //
return func(context *gin.Context, request interface{}) (response interface{}, err error) { ////这个函数的作用是怎么处理请求
rsp := &course.ListResponse{} //func Courselist_Request() gin_.EncodeRequestFunc {
err = c.ListForTop(context, request.(*course.ListRequest), rsp) // return func(context *gin.Context) (i interface{}, e error) {
return rsp, err // bReq := &course.ListRequest{}
} // err := context.BindQuery(bReq) //使用的是query 参数
} // if err != nil {
// return nil, err
//这个函数的作用是怎么处理请求 // }
func Courselist_Request() gin_.EncodeRequestFunc { // return bReq, nil
return func(context *gin.Context) (i interface{}, e error) { // }
bReq := &course.ListRequest{} //}
err := context.BindQuery(bReq) //使用的是query 参数 //
if err != nil { ////这个函数作用是:怎么处理响应结果
return nil, err //func Course_Response() gin_.DecodeResponseFunc {
} // return func(context *gin.Context, res interface{}) error {
return bReq, nil // context.JSON(200, res)
} // return nil
} // }
//}
//这个函数作用是:怎么处理响应结果
func Course_Response() gin_.DecodeResponseFunc {
return func(context *gin.Context, res interface{}) error {
context.JSON(200, res)
return nil
}
}
package controller package controller
import ( //func init() {
"github.com/gin-gonic/gin" // courseService:=service.NewCourseTopicServiceImpl()
"search_server/framework/gin_" // gin_.NewBuilder().WithService(courseService).
"search_server/protopb/course" // WithMiddleware(Check_Middleware()).
"search_server/service" // WithEndpoint(CourseTopicList_Endpoint(courseService)).
) // WithRequest(CourseTopicList_Request()).
// WithResponse(Course_Response()).Build("/topic/:cid","GET")
func init() { //}
courseService:=service.NewCourseTopicServiceImpl() //
gin_.NewBuilder().WithService(courseService). //func CourseTopicList_Endpoint(c *service.CourseTopicServiceImpl) gin_.Endpoint {
WithMiddleware(Check_Middleware()). // return func(context *gin.Context, request interface{}) (response interface{}, err error) {
WithEndpoint(CourseTopicList_Endpoint(courseService)). // rsp:=&course.TopicResponse{Result:make([]*course.CourseTopic,0)}
WithRequest(CourseTopicList_Request()). // err=c.GetTopic(context,request.(*course.TopicRequest),rsp)
WithResponse(Course_Response()).Build("/topic/:cid","GET") // return rsp,err
} // }
//}
func CourseTopicList_Endpoint(c *service.CourseTopicServiceImpl) gin_.Endpoint { ////这个函数的作用是怎么处理请求
return func(context *gin.Context, request interface{}) (response interface{}, err error) { //func CourseTopicList_Request() gin_.EncodeRequestFunc{
rsp:=&course.TopicResponse{Result:make([]*course.CourseTopic,0)} // return func(context *gin.Context) (i interface{}, e error) {
err=c.GetTopic(context,request.(*course.TopicRequest),rsp) // bReq:=&course.TopicRequest{}
return rsp,err // err:=context.BindUri(bReq) //使用的是query 参数
} // if err!=nil{
} // return nil,err
//这个函数的作用是怎么处理请求 // }
func CourseTopicList_Request() gin_.EncodeRequestFunc{ // return bReq,nil
return func(context *gin.Context) (i interface{}, e error) { // }
bReq:=&course.TopicRequest{} //}
err:=context.BindUri(bReq) //使用的是query 参数 \ No newline at end of file
if err!=nil{
return nil,err
}
return bReq,nil
}
}
\ No newline at end of file
package controller
import (
"github.com/gin-gonic/gin"
"net/http"
"search_server/model"
"search_server/service"
)
func Zyh(ctx *gin.Context){
zyServiceImpl := service.NewZyServiceImpl()
zyhRequest := &model.ZyhRequest{}
zyhResponse := &model.ZyhResponse{}
if err := ctx.ShouldBind(zyhRequest); err != nil{
ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
err := zyServiceImpl.Zyh(ctx,zyhRequest,zyhResponse)
if err != nil{
}
}
package dao package dao
import ( //func GetCourseList() *gorm.DB {
"github.com/jinzhu/gorm" // return mysql.GetDB().Table(vars.Table_CourseMain).
"search_server/pkg/vars" // Order("course_id desc").Limit(3)
"search_server/pkg/mysql" //}
) //
//const course_list = "select * from course_main order by course_id desc limit ?"
func GetCourseList() *gorm.DB { //
return mysql.GetDB().Table(vars.Table_CourseMain). //func GetCourseListBySql(args ...interface{}) *gorm.DB {
Order("course_id desc").Limit(3) // return mysql.GetDB().Raw(course_list, args...)
} //}
//func GetCourseDetail(course_id int) *gorm.DB {
const course_list = "select * from course_main order by course_id desc limit ?" // return mysql.GetDB().Table(vars.Table_CourseMain).Where("course_id=?", course_id)
//}
func GetCourseListBySql(args ...interface{}) *gorm.DB { //
return mysql.GetDB().Raw(course_list, args...) ////取计数表
} //func GetCourseCounts(course_id int) *gorm.DB {
func GetCourseDetail(course_id int) *gorm.DB { // return mysql.GetDB().Table(vars.Table_CourseCounts).Where("course_id=?", course_id)
return mysql.GetDB().Table(vars.Table_CourseMain).Where("course_id=?", course_id) //}
}
//取计数表
func GetCourseCounts(course_id int) *gorm.DB {
return mysql.GetDB().Table(vars.Table_CourseCounts).Where("course_id=?", course_id)
}
...@@ -33,7 +33,9 @@ require ( ...@@ -33,7 +33,9 @@ require (
github.com/stretchr/testify v1.5.1 // indirect github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4 github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.0 github.com/tidwall/gjson v1.6.0
github.com/urfave/cli v1.22.4 // indirect
github.com/uniplaces/carbon v0.1.6 github.com/uniplaces/carbon v0.1.6
go.etcd.io/bbolt v1.3.4
go.uber.org/zap v1.14.1 // indirect go.uber.org/zap v1.14.1 // indirect
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
......
package model
type ZyhRequest struct {
Yo4tewUid string `form:"Yo4teW_uid"`
ClassIdcondition int64 `form:"class_id/condition"`
Brand_idCondition string `form:"brand_id/condition"`
StockRank string `form:"stock_rank"` //库存排序
AvailRank string `form:"avail_rank"` //显示有货的
ComRank string `form:"com_rank"` //综合排序
SingleRank string `form:"single_rank"` //价格排序
PackingCondition string `form:"packing/condition"`
EncapCondition string `form:"encap/condition"`
P string `form:"p"`
NeedAggs string `form:"need_aggs"`
}
type ZyhResponse struct {
error_code int64 `json:"error_code"`
error_msg string `json:"error_msg"`
data interface{}
}
\ No newline at end of file
...@@ -11,7 +11,8 @@ var ( ...@@ -11,7 +11,8 @@ var (
func SetUp(path string) (err error) { func SetUp(path string) (err error) {
//引入多个文件 //引入多个文件
Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/search.ini", path+"/redis_key.ini", path+"/rabmq_key.ini") Cfg, err = ini.LooseLoad(path+"/config.ini", path+"/search.ini", path+"/redis_key.ini", path+"/rabmq_key.ini", path+"/database.ini",
path+"/redis_config.ini")
return return
} }
......
package config
type BaseDatabase struct {
UserName string
Password string
Host string
Database string
MaxIdleCons int
MaxOpenCons int
Prefix string
}
//多数据库配置
func BuildDatabaseList() (DatabaseList map[string]BaseDatabase) {
return map[string]BaseDatabase{
"mysql": {
UserName: Get("mysql.user_name").String(),
Password: Get("mysql.password").String(),
Host: Get("mysql.host").String(),
Database: Get("mysql.database").String(),
Prefix: Get("mysql.prefix").String(),
},
"bom": {
UserName: Get("bom.user_name").String(),
Password: Get("bom.password").String(),
Host: Get("bom.host").String(),
Database: Get("bom.database").String(),
Prefix: Get("mysql.prefix").String(),
},
}
}
package config
type RedisDatabase struct {
Password string
Host string
Database string
MaxIdle string
MaxActive string
MaxAIdleTimeoutctive string
Prefix string
}
//多数据库配置
func BuildRedisConfgs() (RedisDatabaseMap map[string]RedisDatabase) {
return map[string]RedisDatabase{
"search_read": {
Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"search_write": {
Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"spu_read": {
Host: Get("default_redis_read.host").String(),
Password: Get("default_redis_read.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"spu_write": {
Host: Get("default_redis_write.host").String(),
Password: Get("default_redis_write.password").String(),
MaxIdle: Get("default_redis_read.max_idle").String(),
MaxActive: Get("default_redis_read.max_active").String(),
},
"api_read": {
Host: Get("api_redis_read.host").String(),
Password: Get("api_redis_read.password").String(),
MaxIdle: Get("api_redis_read.max_idle").String(),
MaxActive: Get("api_redis_read.max_active").String(),
},
"api_write": {
Host: Get("api_redis_write.host").String(),
Password: Get("api_redis_write.password").String(),
MaxIdle: Get("api_redis_write.max_idle").String(),
MaxActive: Get("api_redis_write.max_active").String(),
},
}
}
...@@ -7,24 +7,35 @@ import ( ...@@ -7,24 +7,35 @@ import (
"time" "time"
) )
type IchuntRedis struct {
RedisList map[string]*redis.Pool
Current *redis.Pool
}
func(this *IchuntRedis) Connection(connection string) (*IchuntRedis){
this.Current = this.RedisList[connection]
return this
}
var writeConn, readConn *redis.Pool var writeConn, readConn *redis.Pool
func Setup() (err error) { func Setup() (err error) {
writeHost := config.Get("redis.write_host").String() ichuntRedis := &IchuntRedis{}
readHost := config.Get("redis.read_host").String() ichuntRedis.RedisList = make(map[string]*redis.Pool,0)
writePassword := config.Get("redis.write_password").String() RedisDatabaseMap := config.BuildRedisConfgs()
readPassword := config.Get("redis.read_password").String() for redisKey,redisConfig := range RedisDatabaseMap{
writeConn, err = getConn(writeHost, writePassword) ichuntRedis.RedisList[redisKey],err = getConn(redisConfig.Host, redisConfig.Password)
if err != nil { if err != nil{
return panic(err)
} }
readConn, err = getConn(readHost, readPassword)
if err != nil {
return
} }
return nil return nil
} }
func getConn(writeHost, password string) (pool *redis.Pool, err error) { func getConn(writeHost, password string) (pool *redis.Pool, err error) {
maxIdle, _ := config.Get("redis.max_idle").Int() maxIdle, _ := config.Get("redis.max_idle").Int()
maxActive, _ := config.Get("redis.max_active").Int() maxActive, _ := config.Get("redis.max_active").Int()
...@@ -54,8 +65,8 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) { ...@@ -54,8 +65,8 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) {
//最基础的键值操作 //最基础的键值操作
func Set(key string, data interface{}) error { func (this *IchuntRedis) Set(key string, data interface{}) error {
conn := writeConn.Get() conn := this.Current.Get()
defer conn.Close() defer conn.Close()
value, err := json.Marshal(data) value, err := json.Marshal(data)
...@@ -71,8 +82,26 @@ func Set(key string, data interface{}) error { ...@@ -71,8 +82,26 @@ func Set(key string, data interface{}) error {
return nil return nil
} }
func Exists(key string) bool { //Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。
conn := readConn.Get() func(this *IchuntRedis) Setnx(key string, data interface{}) error {
conn := this.Current.Get()
defer conn.Close()
value, err := json.Marshal(data)
if err != nil {
return err
}
_, err = conn.Do("SETNX", key, value)
if err != nil {
return err
}
return nil
}
func(this *IchuntRedis) Exists(key string) bool {
conn := this.Current.Get()
defer conn.Close() defer conn.Close()
exists, err := redis.Bool(conn.Do("EXISTS", key)) exists, err := redis.Bool(conn.Do("EXISTS", key))
...@@ -83,8 +112,8 @@ func Exists(key string) bool { ...@@ -83,8 +112,8 @@ func Exists(key string) bool {
return exists return exists
} }
func Get(key string) (interface{}, error) { func(this *IchuntRedis) Get(key string) (interface{}, error) {
conn := readConn.Get() conn := this.Current.Get()
defer conn.Close() defer conn.Close()
reply, err := conn.Do("GET", key) reply, err := conn.Do("GET", key)
...@@ -95,8 +124,8 @@ func Get(key string) (interface{}, error) { ...@@ -95,8 +124,8 @@ func Get(key string) (interface{}, error) {
return reply, nil return reply, nil
} }
func Delete(key string) (bool, error) { func(this *IchuntRedis) Delete(key string) (bool, error) {
conn := writeConn.Get() conn := this.Current.Get()
defer conn.Close() defer conn.Close()
return redis.Bool(conn.Do("DEL", key)) return redis.Bool(conn.Do("DEL", key))
...@@ -104,8 +133,8 @@ func Delete(key string) (bool, error) { ...@@ -104,8 +133,8 @@ func Delete(key string) (bool, error) {
//哈希操作 //哈希操作
func HSet(key string, k interface{}, data interface{}) error { func(this *IchuntRedis) HSet(key string, k interface{}, data interface{}) error {
conn := writeConn.Get() conn := this.Current.Get()
defer conn.Close() defer conn.Close()
value, err := json.Marshal(data) value, err := json.Marshal(data)
...@@ -121,8 +150,8 @@ func HSet(key string, k interface{}, data interface{}) error { ...@@ -121,8 +150,8 @@ func HSet(key string, k interface{}, data interface{}) error {
return nil return nil
} }
func HGet(key string, k interface{}) (interface{}, error) { func(this *IchuntRedis) HGet(key string, k interface{}) (interface{}, error) {
conn := readConn.Get() conn := this.Current.Get()
defer conn.Close() defer conn.Close()
reply, err := conn.Do("HGET", key, k) reply, err := conn.Do("HGET", key, k)
...@@ -133,9 +162,10 @@ func HGet(key string, k interface{}) (interface{}, error) { ...@@ -133,9 +162,10 @@ func HGet(key string, k interface{}) (interface{}, error) {
return reply, nil return reply, nil
} }
func HDelete(key string, k interface{}) (bool, error) { func(this *IchuntRedis) HDelete(key string, k interface{}) (bool, error) {
conn := writeConn.Get() conn := this.Current.Get()
defer conn.Close() defer conn.Close()
return redis.Bool(conn.Do("HDEL", key, k)) return redis.Bool(conn.Do("HDEL", key, k))
} }
...@@ -9,28 +9,51 @@ import ( ...@@ -9,28 +9,51 @@ import (
) )
//mysql相关 //mysql相关
var mysqlDb *gorm.DB var mysqlDb, bomDb *gorm.DB
var DatabaseConMap = map[string]*gorm.DB{
"mysql": mysqlDb,
"bom": bomDb,
}
func Setup() error { func Setup() error {
DatabaseList := config.BuildDatabaseList()
var err error var err error
userName := config.Get("database.user_name").String() //循环生成数据库链接
password := config.Get("database.password").String() for conName, db := range DatabaseList {
host := config.Get("database.host").String() userName := db.UserName
database := config.Get("database.database").String() password := db.Password
mysqlDb, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8&parseTime=True&loc=Local", host := db.Host
userName, password, host, database)) database := db.Database
if err != nil {
mysqlDb = nil if db.Prefix != "" {
return e.NewFatalError(err.Error()) //这里返回致命异常 gorm.DefaultTableNameHandler = func(DB *gorm.DB, defaultTableName string) string {
return db.Prefix + defaultTableName
}
}
DatabaseConMap[conName], err = gorm.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8&parseTime=True&loc=Local",
userName, password, host, database))
if err != nil {
return e.NewFatalError(err.Error()) //这里返回致命异常
}
DatabaseConMap[conName].SingularTable(true)
if db.MaxIdleCons == 0 {
db.MaxIdleCons = 10
}
if db.MaxOpenCons == 0 {
db.MaxOpenCons = 100
}
DatabaseConMap[conName].DB().SetMaxIdleConns(db.MaxIdleCons)
DatabaseConMap[conName].DB().SetMaxOpenConns(db.MaxOpenCons)
if config.Get("gorm.mode").String() == "debug" {
DatabaseConMap[conName].LogMode(true)
}
} }
mysqlDb.SingularTable(true)
mysqlDb.DB().SetMaxIdleConns(10)
mysqlDb.DB().SetMaxOpenConns(100)
mysqlDb.LogMode(true)
return nil return nil
} }
func GetDB() *gorm.DB { func Connection(conName string) *gorm.DB {
return mysqlDb return DatabaseConMap[conName]
} }
...@@ -15,6 +15,7 @@ func InitRouter() *gin.Engine { ...@@ -15,6 +15,7 @@ func InitRouter() *gin.Engine {
//路由 //路由
r.POST("/search/bom/autospu", controller.AutoSpu) r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend) r.POST("/search/bom/recommend", controller.Recommend)
r.POST("search/ZiYing/zyh", controller.Zyh)
//快手平台相关 //快手平台相关
r.GET("/search/quote", controller.QuoteIndex) r.GET("/search/quote", controller.QuoteIndex)
......
...@@ -2,32 +2,36 @@ package service ...@@ -2,32 +2,36 @@ package service
import ( import (
"fmt" "fmt"
"github.com/syyongx/php2go"
_ "github.com/tidwall/gjson" _ "github.com/tidwall/gjson"
"search_server/model" "search_server/model"
"search_server/pkg/config"
"search_server/pkg/gredis" "search_server/pkg/gredis"
"strings"
) )
//关键词搜索过期时间 //关键词搜索过期时间
var supplier_over_time = map[string]int64{ var supplier_over_time = map[string]int64{
"arrow":3600, "arrow": 3600,
"verical":3600, "verical": 3600,
"mouser":3600, "mouser": 3600,
"master":3600, "master": 3600,
"tme":3600, "tme": 3600,
"buerklin":3600, "buerklin": 3600,
} }
/* /*
联营公共类 联营公共类
联营大类,包括修改新增 sku es redis ,推送数据到队列让其他go服务更新数据到mysql 联营大类,包括修改新增 sku es redis ,推送数据到队列让其他go服务更新数据到mysql
@param goods_list 请求联营格式化后的数据 @param goods_list 请求联营格式化后的数据
@param supplier_info 供应商商品详情 @param supplier_info 供应商商品详情
*/ */
func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info *model.SUPPLIER_REDIS_INFO_) map[string]interface{}{ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList, supplier_info *model.SUPPLIER_REDIS_INFO_) map[string]interface{} {
//originGoods := make(map[string]interface{},0) //originGoods := make(map[string]interface{},0)
// //
//for goods_sn, goods_list := range goods_list { //for goods_sn, goods_list := range goods_list {
// gredis.HGet("") // gredis.HGet("")
// //
// ladderPrice := make([]*model.TierItem, 0) // ladderPrice := make([]*model.TierItem, 0)
// //
...@@ -36,22 +40,46 @@ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info ...@@ -36,22 +40,46 @@ func getSkuByGoodsSn(goods_list map[string]*model.LyClearGoodsList,supplier_info
// //
//fmt.Println(productList) //fmt.Println(productList)
//return productList //return productList
originGoods := make(map[string]interface{}, 0)
sku_uique_judge := config.Get("redis_all.SKU_UNIQUE_JUDGE").String()
for goods_sn, info := range goods_list {
sn_sku := php2go.Md5(strings.ToLower(goods_sn))
sku_id, _ := gredis.HGet(sku_uique_judge, sn_sku) //查询唯一值,反查sku_id
if sku_id == "" { //为空,先创建sku
//lock_key := "searchapi_"+sn_sku;
//flag := gredis.Setnx(lock_key,php2go.Time()+2)
//if flag { //存在锁
//
//}
}
print(info)
//productList[goodsSn] = &LyClearGoodsList
}
fmt.Println(originGoods)
return originGoods
} }
/* /*
新增或者更新redis 新增或者更新redis
*/ */
func toRedis() { func toRedis() {
} }
/* /*
推入队列 推入队列
*/ */
func toGoRabmq() { func toGoRabmq() {
} }
/* /*
更新es 更新es
*/ */
func toEs() { func toEs() {
} }
\ No newline at end of file
package service package service
import ( import (
"context"
"search_server/dao"
. "search_server/protopb/course" . "search_server/protopb/course"
) )
...@@ -12,32 +10,32 @@ func NewCourseModel(id int32, name string) *CourseModel { ...@@ -12,32 +10,32 @@ func NewCourseModel(id int32, name string) *CourseModel {
type CourseServiceImpl struct{} type CourseServiceImpl struct{}
func (this *CourseServiceImpl) ListForTop(ctx context.Context, req *ListRequest, rsp *ListResponse) error { //func (this *CourseServiceImpl) ListForTop(ctx context.Context, req *ListRequest, rsp *ListResponse) error {
course := make([]*CourseModel, 0) // course := make([]*CourseModel, 0)
err := dao.GetCourseListBySql(req.Size).Find(&course).Error // err := dao.GetCourseListBySql(req.Size).Find(&course).Error
if err != nil { // if err != nil {
return err // return err
} // }
rsp.Result = course // rsp.Result = course
return nil // return nil
} //}
func (this *CourseServiceImpl) GetDetail(ctx context.Context, req *DetailRequest, rsp *DetailResponse) error { //func (this *CourseServiceImpl) GetDetail(ctx context.Context, req *DetailRequest, rsp *DetailResponse) error {
//只取课程详细 // //只取课程详细
if req.FetchType == 0 || req.FetchType == 1 || req.FetchType == 3 { // if req.FetchType == 0 || req.FetchType == 1 || req.FetchType == 3 {
if err := dao.GetCourseDetail(int(req.CourseId)).Find(rsp.Course).Error; err != nil { // if err := dao.GetCourseDetail(int(req.CourseId)).Find(rsp.Course).Error; err != nil {
return err // return err
} // }
} // }
//只取计数表详细 // //只取计数表详细
if req.FetchType == 2 || req.FetchType == 3 { // if req.FetchType == 2 || req.FetchType == 3 {
if err := dao.GetCourseCounts(int(req.CourseId)).Find(&rsp.Counts).Error; err != nil { // if err := dao.GetCourseCounts(int(req.CourseId)).Find(&rsp.Counts).Error; err != nil {
return err // return err
} // }
} // }
//
return nil // return nil
//
} //}
func NewCourseServiceImpl() *CourseServiceImpl { func NewCourseServiceImpl() *CourseServiceImpl {
return &CourseServiceImpl{} return &CourseServiceImpl{}
......
package service package service
import (
"context"
. "search_server/protopb/course"
"search_server/pkg/mysql"
)
type CourseTopicServiceImpl struct{} type CourseTopicServiceImpl struct{}
func (this *CourseTopicServiceImpl) GetTopic(ctx context.Context, in *TopicRequest, out *TopicResponse) error { //func (this *CourseTopicServiceImpl) GetTopic(ctx context.Context, in *TopicRequest, out *TopicResponse) error {
if err := mysql.GetDB().Table("course_topic").Find(&out.Result).Error; err != nil { // if err := mysql.GetDB().Table("course_topic").Find(&out.Result).Error; err != nil {
return err // return err
} // }
return nil // return nil
} //}
func NewCourseTopicServiceImpl() *CourseTopicServiceImpl { //func NewCourseTopicServiceImpl() *CourseTopicServiceImpl {
return &CourseTopicServiceImpl{} // return &CourseTopicServiceImpl{}
} //}
package service
import (
"fmt"
"github.com/gin-gonic/gin"
"reflect"
"search_server/model"
"search_server/pkg/config"
)
type ZyServiceImpl struct{}
/*
自营搜索
*/
func (this *ZyServiceImpl) Zyh(ctx *gin.Context, req *model.ZyhRequest, rsp *model.ZyhResponse) error {
//fmt.Printf("%+v",req)
fmt.Println(req.NeedAggs)
fmt.Println(5566)
var (
need_aggs bool
_type byte
)
if req.NeedAggs != ""{
need_aggs = false
}else{
need_aggs = true
}
need_aggs = need_aggs
if need_aggs {
_type = 1
}else{
_type = 1
}
//设置cookie
setCookie(ctx,req)
rsp = zy(ctx , req ,_type,0)
return nil
}
func NewZyServiceImpl() *ZyServiceImpl {
return &ZyServiceImpl{}
}
func setCookie(ctx *gin.Context, req *model.ZyhRequest) error{
//接收用户id
if req.Yo4tewUid != "" && req.Yo4tewUid != "false" {
domain := config.Get("web.domain").String()
ctx.SetCookie("Yo4teW_uid", req.Yo4tewUid, 3600, "/", domain, false, true)
}
return nil
}
//自营筛选接口数据输出
//@param _type 1:输出所有(属性统计+分类+数据详情),2 只输出属性(属性统计)
func zy(ctx *gin.Context, req *model.ZyhRequest,_type byte,isCheck byte) (rsp *model.ZyhResponse){
fmt.Printf("%+v",req)
fmt.Println(reflect.TypeOf(req.ClassIdcondition))
fmt.Println(req.ClassIdcondition)
return nil
}
...@@ -4,7 +4,7 @@ import ( ...@@ -4,7 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"search_server/boot" "search_server/boot"
"search_server/pkg/config" "search_server/pkg/mysql"
) )
func main() { func main() {
...@@ -14,13 +14,20 @@ func main() { ...@@ -14,13 +14,20 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
fmt.Println(err) fmt.Println(err)
} }
//fmt.Println(model.GetExcludeBrandIds(1)) type Result struct {
fmt.Println(config.GetSectionValues("supplier_all")) BinId int `json:"bin_id"`
fmt.Println(config.Cfg.Section("xxx").Key("xxx")) Bin string `json:"bin"`
}
//client := client. var result []Result
//c := course.NewCourseService("go.micro.api.jtthink.course", client) mysql.Connection("bom").Raw("SELECT * FROM lie_bin").Scan(&result)
//course_rsp, _ := c.ListForTop(context.TODO(), &course.ListRequest{Size: 10}) //mysql.Connection()("bom").Table("bin").Find(&result)
//fmt.Println(course_rsp.Result) fmt.Println(result)
type Result2 struct {
BusinessName string `json:"business_name"`
}
var result2 []Result2
mysql.Connection("mysql").Raw("SELECT * FROM lie_business").Scan(&result2)
//mysql.GetDB("bom").Table("bin").Find(&result)
fmt.Println(result2)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment