Commit 59acfdf8 by huangchengyi

1.0

parents
Showing with 4761 additions and 0 deletions
/go.sum
/.idea/
gowatch.yml
*.exe
*.exe~
cmd.exe~
/cmd/logs/
/cmd/*.exe~
/cmd/logs
/bat/logs/
/conf/*.ini
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/course_server.go --server_address :9092
\ No newline at end of file
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/course_http_server.go -config=../conf/config.ini
\ No newline at end of file
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
micro api
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
micro api
protoc --proto_path=protos --micro_out=protopb/mouser --go_out=protopb/mouser mouser.proto
\ No newline at end of file
::protoc --proto_path=protos --micro_out=users --go_out=users users.proto
protoc --proto_path=protos --micro_out=course --go_out=course course.proto
protoc-go-inject-tag -input=course/course.pb.go
protoc --proto_path=protos --micro_out=course --go_out=course common.proto
protoc --proto_path=protos --micro_out=course --go_out=course course_topic.proto
protoc-go-inject-tag -input=course/course_topic.pb.go
\ No newline at end of file
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/goods_machining.go -config=../conf/config.ini
\ No newline at end of file
::set MICRO_REGISTRY=etcd
::set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run ../cmd/search_http_server.go -config=../conf
\ No newline at end of file
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
go run cmd/user_server.go --server_address :9090
\ No newline at end of file
set MICRO_REGISTRY=etcd
set MICRO_REGISTRY_ADDRESS=192.168.2.232:2379
micro web
protoc --proto_path=../protos -I="C:\Program Files (x86)\protoc\include" --micro_out=../protopb/course --go_out=../protopb/course course.proto
protoc-go-inject-tag -input=../protopb/course/course.pb.go
protoc --proto_path=../protos -I="C:\Program Files (x86)\protoc\include" --micro_out=../protopb/common --go_out=../protopb/common common.proto
protoc --proto_path=../protos -I="C:\Program Files (x86)\protoc\include" --micro_out=../protopb/course --go_out=../protopb/course course_topic.proto
protoc-go-inject-tag -input=../protopb/course/course_topic.pb.go
protoc --proto_path=../protos -I="C:\Program Files (x86)\protoc\include" --micro_out=../protopb/users --go_out=../protopb/users users.proto
protoc --proto_path=../protos -I="C:\Program Files (x86)\protoc\include" --micro_out=../protopb/bom --go_out=../protopb/bom bom.proto
protoc-go-inject-tag -input=../protopb/bom/bom.pb.go
protoc --proto_path=../protos -I="C:\Program Files (x86)\protoc\include" --micro_out=../protopb/goods --go_out=../protopb/goods goods.proto
protoc-go-inject-tag -input=../protopb/goods/goods.pb.go
\ No newline at end of file
package boot
import (
"goods_machining/pkg/config"
"goods_machining/pkg/gredis"
"goods_machining/pkg/logger"
"goods_machining/pkg/mongo"
"goods_machining/pkg/mysql"
)
func Boot(configPath string) (err error) {
if err = config.SetUp(configPath); err != nil {
panic(err)
}
if err = mysql.Setup(); err != nil {
panic(err)
return
}
if err = gredis.Setup(); err != nil {
panic(err)
return
}
if err = mongo.SetUp(); err != nil {
panic(err)
return
}
if err = logger.SetUp(); err != nil {
panic(err)
return
}
return
}
package main
import (
_ "goods_machining/controller"
)
func main() {
//
//var path string
//flag.StringVar(&path, "config", "conf/config.ini", "配置文件")
//flag.Parse()
//if err := boot.Boot(path); err != nil {
// log.Println(err)
//}
//
//r := gin.New()
//gin_.BootStrap(r)
//
//c:=grpc.NewClient()
//r:=gin.New()
//r.Handle("GET","/test", func(ctx *gin.Context) {
// news
// c:=Course.NewCourseService("api.jtthink.com.course",c)
// course_rsp,_:=c.ListForTop(context.Background(),&Course.ListRequest{Size:10})
// ctx.JSON(200,gin.H{"Result":course_rsp.Result})
//})
//service:=web.NewService(
// web.Name("api.jtthink.com.http.course"),
// web.Handler(r),
//)
//
//
//
//port := config.Get("web.port").String()
////web改成micro 就是grpc,并直接注册到etcd里面
//service := web.NewService(
// web.Name("go.micro.api.http.course"),
// web.Handler(r),
// web.Address(":"+port),
//)
//
//if err := service.Init(); err != nil {
// log.Println(err)
//}
//if err := service.Run(); err != nil {
// log.Println(err)
//}
}
package main
import (
"context"
"github.com/micro/go-micro/v2/client/grpc"
"github.com/micro/go-micro/v2/web"
"goods_machining/Course"
"log"
"net/http"
)
func main() {
service:=web.NewService(
web.Name("api.jtthink.com.http.course"))
c:=grpc.NewClient()
service.HandleFunc("/test", func(writer http.ResponseWriter, request *http.Request) {
c:=Course.NewCourseService("go.micro.api.jtthink.course",c)
course_rsp,_:=c.ListForTop(context.Background(),&Course.ListRequest{Size:10})
log.Println(course_rsp.Result)
writer.Write([]byte("http api test"))
})
service.Init()
if err:= service.Run(); err != nil {
log.Println(err)
}
}
\ No newline at end of file
package main
import (
"github.com/micro/go-micro/v2"
"goods_machining/protopb/course"
"goods_machining/service"
"log"
)
func main() {
cService:=micro.NewService(
micro.Name("go.micro.api.jtthink.course"))
cService.Init()
err:=course.RegisterCourseServiceHandler(cService.Server(),service.NewCourseServiceImpl())
if err!=nil{
log.Fatal(err)
}
if err = cService.Run(); err != nil {
log.Println(err)
}
}
\ No newline at end of file
package main
import (
"flag"
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web"
"goods_machining/boot"
//_ "goods_machining/controller"
"goods_machining/pkg/config"
"goods_machining/routes"
)
func main() {
var path string
flag.StringVar(&path, "config", "conf", "配置文件")
flag.Parse()
if err := boot.Boot(path); err != nil {
panic(err)
}
gin.SetMode(config.Get("web.mode").String())
r := routes.InitRouter()
port := config.Get("web.port").String()
//web改成micro 就是grpc,并直接注册到etcd里面
service := web.NewService(
web.Name("go.micro.api.http.search"),
web.Handler(r),
web.Address(":"+port),
)
if err := service.Init(); err != nil {
panic(err)
}
if err := service.Run(); err != nil {
panic(err)
}
}
package main
import (
"github.com/micro/go-micro/v2"
"goods_machining/protopb/bom"
"goods_machining/service"
"log"
)
func main() {
cService:=micro.NewService(
micro.Name("go.micro.grpc.search"))
cService.Init()
err:=bom.RegisterBomServiceHandler(cService.Server(),service.NewBomServiceImpl())
if err!=nil{
log.Fatal(err)
}
if err = cService.Run(); err != nil {
log.Println(err)
}
}
\ No newline at end of file
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/tidwall/gjson"
"os"
"goods_machining/boot"
"goods_machining/service/query"
)
func main() {
//MouserService := service.NewMouserServiceImpl()
//MouserGetData(MouserService)
var path string
flag.StringVar(&path, "config", "conf", "配置文件")
flag.Parse()
if err := boot.Boot(path); err != nil {
panic(err)
}
//lock_key := "searchapi_668777";
////flag := gredis.Set(lock_key,php2go.Time()+2)
//flag,_ := gredis.Setnx(lock_key,2222)
//
//fmt.Println(flag)
//os.Exit(1)
//redisConn := gredis.Conn("search_r")
//defer redisConn.Close()
//attrName, err := gredis.String(redisConn.Do("GET", "hcy1"))
//
//fmt.Println(err)
//fmt.Println(attrName)
//os.Exit(1)
//ss := "LM358"
//mouserRes := service.OutLink(&ss,"-1")
//for k, mouseItem := range mouserRes {
// fmt.Println(k)
// fmt.Println(mouseItem.PriceTemp)
// os.Exit(1)
//}
//fmt.Errorf()
println(query.GetExactGoodsQuery("nninin"))
jsonstr := `{"goods_id":1156147221172418504,"goods_sn":"","spu_id":"2156147221162468806","update_time":1561472211,"goods_status":3,"goods_name":"RC0603FR-07100KL","goods_type":2,"supplier_id":17,"encoded":"10059","batch_sn":"1148","moq":27961,"mpq":1,"stock":1765,"hk_delivery_time":"","cn_delivery_time":"4\u4e2a\u5de5\u4f5c\u65e5","goods_details":"","ladder_price":[{"purchases":2765,"price_cn":0.01072951425,"price_us":0},{"purchases":45654,"price_cn":0.343434,"price_us":6666}],"goods_images":"","canal":"L0000110","cp_time":0}`
m, ok := gjson.Parse(jsonstr).Value().(map[string]interface{})
if !ok {
fmt.Println(ok)
os.Exit(1)
}
goods_id := gjson.Get(jsonstr, "goods_id").String()
ladder := gjson.Get(jsonstr, "ladder_price").Array()
temp1 := []map[string]float64{};
for _,value:=range ladder {
b := value.Map()
temp1 = append(temp1,map[string]float64{
"purchases":b["purchases"].Float(),
"price_cn":b["price_cn"].Float(),
"price_us":b["price_us"].Float(),
})
}
//fmt.Println(ladder)
//
m["goods_id"] = goods_id
m["ladder_price"] = temp1
dd,_ := json.Marshal(m)
fmt.Println(string(dd))
//lines := []string{
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
// `{"name":"john doe","age":25 }`,
// `{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`,
// `{"name":"mary smith","age":32 }`,
//}
//param := strings.Join(lines, "\n")+"\n"
//
//result,err := es.BulkES(param)
//println(result,err)
//var skuEsUpdataList []string
//
//param := map[string]interface{}{
// "goods_status":1,
// "status":1,
// "encoded": "{'ddd'}",
//}
//
//paramjson,_ := json.Marshal(param)
//
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//skuEsUpdataList = append(skuEsUpdataList,string(paramjson))
//
//
//println(strings.Join(skuEsUpdataList,"\n"))
os.Exit(1)
}
//xml := strings.NewReader(resp)
//json, err := xj.Convert(xml)
//if err != nil {
// panic("That's embarrassing...")
//}
//
//json_str := json.String();
////ss := gjson.Get(json_str,"hello").String()
//
//fmt.Println(json_str)
package main
import (
"context"
"github.com/micro/go-micro/v2/client"
"goods_machining/protopb/course"
"github.com/micro/go-micro/v2"
"goods_machining/protopb/users"
"log"
)
type UserService struct{
client client.Client
}
func (this *UserService) Test(ctx context.Context, req *users.UserRequest, rsp *users.UserResponse) error {
rsp.Ret="users"+req.Id
c:=course.NewCourseService("go.micro.api.jtthink.course",this.client)
course_rsp,_:=c.ListForTop(ctx,&course.ListRequest{Size:10})
log.Println(course_rsp.Result)
return nil
}
func NewUserService(c client.Client) *UserService {
return &UserService{client:c}
}
func main() {
service:=micro.NewService(
micro.Name("go.micro.api.jtthink.user"))
service.Init()
err:=users.RegisterUserServiceHandler(service.Server(),NewUserService(service.Client()))
if err!=nil{
log.Fatal(err)
}
if err = service.Run(); err != nil {
log.Println(err)
}
}
[web]
port = 9000
mode = debug
cors_domain = http://bom.liexin.com
domain = liexin.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi
[goods]
api_url = http://192.168.2.232:60004
sz_api_url = http://192.168.2.232:60004
[es]
url = http://192.168.2.232:9200
urls = http://192.168.2.232:9200,http://192.168.2.232:9200
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
attr_index = goods_map
[redis]
write_host = 192.168.1.235:6379
read_host = 192.168.1.235:6379
write_password = icDb29mLy2s
read_password = icDb29mLy2s
max_idle = 10
max_active = 10
idle_timeout = 20
[mongo]
host = 192.168.1.237:27017
username = "ichunt"
password = "huntmon6699"
database = ichunt
maxPoolSize=100
[ZIYING_CACHE]
is_no_ziying_cache=true
#是否是测试环境
[IS_SZ]
is_sz = true
#自营mongodb缓存表 正式线ziying_class_aggs
[AGG_TABLE]
agg_table = ziying_class_aggs
#自营mongodb缓存表 正式线 ziying_first_lists
[FIRSTLISTS_TABLE]
firstLists_table = ziying_first_lists
\ No newline at end of file
[web]
port = 9000
mode = debug
cors_domain = http://bom.liexin.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi
[goods]
api_url = http://192.168.2.232:60004
[es]
url = http://192.168.2.232:9200
urls = http://192.168.2.232:9200,http://192.168.2.232:9200
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
attr_index = goods_map
[database]
user_name = root
password = root
host = 192.168.2.239
database = test
table_prefix =
type = mysql
[redis]
write_host = 192.168.1.235:6379
read_host = 192.168.1.235:6379
write_password = icDb29mLy2s
read_password = icDb29mLy2s
max_idle = 10
max_active = 10
idle_timeout = 20
[mongo]
host = 127.0.0.1:27017
database = liexin_config
[brand]
#是否开启排除品牌
IS_NOT_TI = 1
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
ti_zy_brand_id = 23
\ No newline at end of file
[gorm]
mode = debug
[spu]
user_name = spu
password = spu
host = 192.168.1.234
database = liexin_spu
table_prefix =lie_
type = mysql
#线上地址
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp
[supp]
user_name = liexin_ass
password = `liexin_ass#zsyM`
host = 192.168.2.232
database = liexin_ass
table_prefix =lie_
type = mysql
[cms]
user_name = ichuntcms
password = `ichuntcms#zsyM`
host = 192.168.2.232
database = ichuntcms
table_prefix =
type = mysql
[DINGDING]
SEARCH_API_MONITOR = 6d0fa85e01a02c39347d011ae973fd21b76c6c7ce582d3ea470c6b65a318848d
\ No newline at end of file
[rabmq]
url = amqp://guest:guest@192.168.2.232:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
MQ_BOM_ITEMS_LIST=bom_items_list
; bom更新数据队列
MQ_BOM_SKU_LIST=bom_sku_list
;联营数据更新-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_UPDATE_LIST=search_sku_update_list
;联营数据新增-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_LIST=search_sku_list
; bom任务id
ZIYING_MQ_BOM_ITEMS_LIST=ziying_bom_items_list
; bom更新数据队列
ZIYING_MQ_BOM_SKU_LIST=ziying_bom_sku_list
\ 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]
host = 192.168.1.235:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
\ No newline at end of file
;存放本系统所有的redis键值对和解析
[redis_all]
;供应商redis的首key
SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
;需要展示的供应商列表
SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_
;新增sku时判读sku是否存在
SKU_UNIQUE_JUDGE=sku_unique_judge
;新增sku时判读sku是否存在
SPU_UNIQUE_JUDGE=sku_unique_judge
;品牌信息判断,根据md5后的品牌名称获取id
BRAND_NAME_ALL=brand_name_all
;品牌id,获取品牌名称
BRAND=brand
;供应商品牌信息判断,存在多对一的情况,根据md5后的品牌名称获取标准品牌id
SUPPLIER_BRAND_ALL=supplier_brand_all
;统计调用外联接口的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_TOTAL_PRE=search_api_total_
;统计调用外联接口失败的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_ERORR_PRE=search_api_overtime_
;曝光时间记录哈希集合
SEARCH_SHOW_SKU_TIME=search_show_sku_time
;获取关税信息,根据goods_name,brand_name获取
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营外链原始映射
SKU_RAW_MAP=sku_raw_map
[redis_ziyin]
AGG_TABLE=sz_ziying_class_aggs
FIRST_LISTS_TABLE=ziying_first_lists
ZIYING_CLASS_KEY=ziying_class_string
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营所有sku
SKU=sku
;存放联营所有spu
SPU=SPU
;存放digikey 型号映射
SKU_RAW_MAP=sku_raw_map
POOL_ALIKE_GOODS=pool_alike_goods
[SUPPLIER_ALL]
1 = future
2 = powerandsignal
3 = rochester
4 = tme
5 = verical
6 = element14
7 = digikey
8 = chip1stop
9 = aipco
10 = arrow
11 = bisco
12 = alliedelec
13 = avnet
14 = mouser
#16 = liexin_lianying1
17 = zhuanmai
18 = liexin_ti
19 = peigenesis
20 = powell
21 = rs
1676 = buerklin
[SEARCH_SUPPLIER_MERGE]
17 = zhuanmai
1 = future
3 = rochester
6 = element14
7 = digikey
8 = chip1stop
9 = aipco
12 = alliedelec
13 = avnet
19 = peigenesis
20 = powell
21 = rs
[SEARCH_SUPPLIER]
1 = future
#2 = powerandsignal
3 = rochester
4 = tme
5 = verical
6 = element14
7 = digikey
8 = chip1stop
9 = aipco
10 = arrow
#11 = bisco
12 = alliedelec
13 = avnet
14 = mouser
#15 = company
#16 = liexin_lianying1
17 = zhuanmai
#18 = liexin_ti
19 = peigenesis
20 = powell
21 = rs
#22 = liexin_sell
#100 = ziying
#101 = liexin_jingdiao
1676 = buerklin
#相似物料供应商
[ALIKE_SUPPLIER]
1 = ti
[common]
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[BRAND]
IS_NOT_TI = 0
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS = 23
[supplier]
# 供应商redis的首key
SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_
[ZIYING_BRAND_REPLACE]
FH = FH(风华)
BL = BL(上海贝岭)
TE = TE(泰科)
FM = FM(富满)
CJ = CJ(长电)
ST = ST(意法)
SK = SK(时科)
ON = ON(安森美)
TM = TM(天微)
TP = TP(拓微)
TI = TI(德州仪器)
MD = MD(明达)
EG = EG(屹晶微)
HF = HF(宏发)
DY = DY(迪一)
MK = MK(米客方德)
国民 = Nationz(国民技术)
中芯 = SMIC(中芯国际)
富士 = Fuji Electric(富士电机)
国星 = Nationstar(国星光电)
贝岭 = BL(上海贝岭)
[ZIYING_CONFIG]
Index = liexin_ziying
[SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4}
`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$` = ${1}${2}Μ${4}${5}
`COG` = C0G
`NPO` = NP0
`华科|华新科技|华新科` = 华新
[mathExactGoodsName]
0=M7
1=M1
2=M4
3=M2
4=A7
5=F7
6=X2
7=G4
8=X4
9=m7
10=m1
11=m4
12=m2
13=a7
14=f7
15=x2
16=g4
17=x4
;自营以某些单位进行搜索时,进行特殊处理
[ZIYING_MEASURE]
0=kΩ
1=uf
2=v
3=kg
4=MHz
5=pf
6=pin
7=ppm
8=kw
[OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin
4 = https://www.tme.eu/zh/katalog/#search=liexin
5 = https://www.verical.com/s/liexin/
6 = https://cn.element14.com/search?st=liexin
7 = https://www.digikey.com/products/en?keywords=liexin
8 = https://www.chip1stop.com/CHN/zh/view/searchResult/SearchResultTop?keyword=liexin
9 = http://www.aipco.com/search.php?pn=liexin
10 = https://www.arrow.com/en/products/search?cat=&q=liexin
11 = https://www.biscoind.com?SEARCHTEXT=liexin
12 = https://www.alliedelec.com/view/search?keyword=liexin
13 = https://www.avnet.com/shop/apac/search/liexin
14 = https://www.mouser.com/Search/Refine?Keyword=liexin
15 =
16 =
18 =
19 = https://www.peigenesis.cn/cn/shop/f/liexin.html
20 = https://www.powell.com/e2wItemQuickSearch.aspx?searchText=liexin
21 = https://uk.rs-online.com/web/c/semiconductors/amplifiers-comparators/op-amps/?searchTerm=liexin
22 =
1672 = https://www.masterelectronics.com/parts.aspx?text=liexin
1673 = https://www.rutronik24.com/search-result/qs:liexin
1675 = https://www.zaikostore.com/zaikostore/stockList?productName_forFind=liexin
1676 = https://www.buerklin.com/en/search?text=liexin
1677 = https://www.microchipdirect.com/product/search/all/liexin
1678 = https://estore.heilindasia.com/search.asp?p=liexin
1680 = http://shop.wpgam.com/WPGAStore/index.php?route=product/search&filter_description=true&filter_name=liexin
[AUTH]
SUPER_AUTH_KEY = fh6y5t4rr351d2c3bryi
SEARCH_TOKEN_EXPIRE_TIME = 30
[UNIT_SUPPLIER_LOG_CODE]
333333 = arrow
444444 = master
555555 = mouser
666666 = verical
777777 = tme
888888 = buerklin
999999 = zhuanmai
[SEARCH_API_LOG]
SEARCH_API_ERROR_PRE = search_api_overtime_
\ No newline at end of file
[web]
port = 10001
mode = release
cors_domain = https://bom.ichunt.com
domain = ichunt.com
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi
[goods]
api_url = http://47.106.60.211:60004
sz_api_url = http://47.106.60.211:60004
[es]
url = http://172.18.137.29:9211
urls = http://172.18.137.29:9211,http://172.18.137.30:9211
index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying
search_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin,zhuanmai
hk_delivery_type_supplier = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
attr_index = goods_map
[redis]
write_host = 172.18.137.38:6379
read_host = 172.18.137.39:6379
write_password = icDb29mLy2s
read_password = icDb29mLy2s
max_idle = 10
max_active = 10
idle_timeout = 20
[mongo]
host = 172.18.137.23:27017
username = "ichunt"
password = "huntmon66499"
database = ichunt
maxPoolSize=100
[ZIYING_CACHE]
is_no_ziying_cache=true
#是否是测试环境
[IS_SZ]
is_sz = false
#自营mongodb缓存表 正式线ziying_class_aggs
[AGG_TABLE]
agg_table = ziying_class_aggs
#自营mongodb缓存表 正式线 ziying_first_lists
[FIRSTLISTS_TABLE]
firstLists_table = ziying_first_lists
\ No newline at end of file
[gorm]
mode = debug
#线上地址
#mysql://LxiCSpu:Mysx3Tyzlo00oxlmlly@172.18.137.29:3306
[spu]
user_name = LxiCSpu
password = Mysx3Tyzlo00oxlmlly
host = 172.18.137.29
database = liexin_spu
table_prefix =lie_
type = mysql
#线上地址
#SupDbUser:Supssy2@@!!@$#yxy@172.18.137.21:3306/liexin_supp
[supp]
user_name = SupDbUser
password = `Supssy2@@!!@$#yxy`
host = 172.18.137.21
database = liexin_supp
table_prefix =lie_
type = mysql
#线上地址
#mysql://dtuserread:dAtaL#ym2902m2lLX2y33@172.18.137.22:3306/icdata#utf8
[cms]
user_name = dtuser
password = `dAtaL#ym2902m2lLX2y33`
host = appdb-master.ichunt.db
database = icdata
table_prefix =
type = mysql
[DINGDING]
SEARCH_API_MONITOR = cd1661d0ce733a8ff0b603b532b317aae9de6dbaf39186b0352f272e47a860e8
\ No newline at end of file
[rabmq]
url = amqp://huntweb:xMtMi29zTm@119.23.79.136:5672/
;存放本系统所有的队列名称
[rabmq_all]
; bom任务id
MQ_BOM_ITEMS_LIST=bom_items_list
; bom更新数据队列
MQ_BOM_SKU_LIST=bom_sku_list
;联营数据更新-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_UPDATE_LIST=search_sku_update_list
;联营数据新增-推送入队列-》go后台任务消费(斌哥脚本)
SEARCH_SKU_LIST=search_sku_list
; bom任务id
ZIYING_MQ_BOM_ITEMS_LIST=ziying_bom_items_list
; bom更新数据队列
ZIYING_MQ_BOM_SKU_LIST=ziying_bom_sku_list
\ No newline at end of file
[default_redis_read]
host = 172.18.137.39:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[default_redis_write]
host = 172.18.137.38:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis_read]
host = 172.18.137.38:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
[api_redis_write]
host = 172.18.137.39:6379
password = icDb29mLy2s
max_idle = 50
max_active = 100
idle_timeout = 20
;存放本系统所有的redis键值对和解析
[redis_all]
;供应商redis的首key
SUPPLIER_REDIS_PRE=SUPPLIER_REDIS_INFO_
;需要展示的供应商列表
SUPPLIER_REDIS_LIST_PRE=SUPPLIER_REDIS_LIST_INFO_
;新增sku时判读sku是否存在
SKU_UNIQUE_JUDGE=sku_unique_judge
;新增sku时判读sku是否存在
SPU_UNIQUE_JUDGE=sku_unique_judge
;品牌信息判断,根据md5后的品牌名称获取id
BRAND_NAME_ALL=brand_name_all
;品牌id,获取品牌名称
BRAND=brand
;供应商品牌信息判断,存在多对一的情况,根据md5后的品牌名称获取标准品牌id
SUPPLIER_BRAND_ALL=supplier_brand_all
;统计调用外联接口的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_TOTAL_PRE=search_api_total_
;统计调用外联接口失败的次数的key的前缀 后面接mouser、verical、arrow、master
SEARCH_API_ERORR_PRE=search_api_overtime_
;曝光时间记录哈希集合
SEARCH_SHOW_SKU_TIME=search_show_sku_time
;获取关税信息,根据goods_name,brand_name获取
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营外链原始映射
SKU_RAW_MAP=sku_raw_map
[redis_ziyin]
AGG_TABLE=sz_ziying_class_aggs
FIRST_LISTS_TABLE=ziying_first_lists
ZIYING_CLASS_KEY=ziying_class_string
TAX_CUSTOMS_INFO=tax_customs_info
;存放联营所有sku
SKU=sku
;存放联营所有spu
SPU=SPU
;存放digikey 型号映射
SKU_RAW_MAP=sku_raw_map
POOL_ALIKE_GOODS=pool_alike_goods
[SUPPLIER_ALL]
1 = future
2 = powerandsignal
3 = rochester
4 = tme
5 = verical
6 = element14
7 = digikey
8 = chip1stop
9 = aipco
10 = arrow
11 = bisco
12 = alliedelec
13 = avnet
14 = mouser
15 = company
16 = liexin_lianying1
17 = zhuanmai
18 = liexin_ti
19 = peigenesis
20 = powell
21 = rs
22 = liexin_sell
100 = ziying
101 = liexin_jingdiao
1672 = master
1673 = rutronik
1675 = corestaff
1676 = buerklin
1677 = microchip
1678 = heilind
1680 = wpg
1681 = jameco
1679 = ti
1684 = distrelec
1685 = tlc
1686 = adi
#搜索结果页合并供应商
[SEARCH_SUPPLIER_MERGE]
1 = future
3 = rochester
6 = element14
#7 = digikey
8 = chip1stop
9 = aipco
12 = alliedelec
13 = avnet
19 = peigenesis
20 = powell
21 = rs
1675 = corestaff
1677 = microchip
1678 = heilind
1680 = wpg
1681 = jameco
1679 = ti
1684 = distrelec
1685 = tlc
1686 = adi
#相似物料供应商
[ALIKE_SUPPLIER]
1 = ti
[common]
MOUSER_API = 'http://footstone.liexin.net/webapi/handle_mouser'
[BRAND]
IS_NOT_TI = 0
TI_LY_BRAND_IDS = 23,45069,7754,17484,43215,13421,5220,7636,44534,43556,44543,9429,758,9470,10430,10653,10707,11227,11276,11819,12608,12965,12997,13327,13675,13680,13752
TI_ZY_BRAND_IDS = 23
[supplier]
# 供应商redis的首key
SUPPLIER_REDIS_PRE = SUPPLIER_REDIS_INFO_
[ZIYING_BRAND_REPLACE]
FH = FH(风华)
BL = BL(上海贝岭)
TE = TE(泰科)
FM = FM(富满)
CJ = CJ(长电)
ST = ST(意法)
SK = SK(时科)
ON = ON(安森美)
TM = TM(天微)
TP = TP(拓微)
TI = TI(德州仪器)
MD = MD(明达)
EG = EG(屹晶微)
HF = HF(宏发)
DY = DY(迪一)
MK = MK(米客方德)
国民 = Nationz(国民技术)
中芯 = SMIC(中芯国际)
富士 = Fuji Electric(富士电机)
国星 = Nationstar(国星光电)
贝岭 = BL(上海贝岭)
[ZIYING_CONFIG]
Index = liexin_ziying
[SEARCH_KEYWORD_MAPPING]
`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$` = ${1}${2}Ω${4}
`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$` = ${1}${2}Μ${4}${5}
`COG` = C0G
`NPO` = NP0
`华科|华新科技|华新科` = 华新
[mathExactGoodsName]
0=M7
1=M1
2=M4
3=M2
4=A7
5=F7
6=X2
7=G4
8=X4
9=m7
10=m1
11=m4
12=m2
13=a7
14=f7
15=x2
16=g4
17=x4
;自营以某些单位进行搜索时,进行特殊处理
[ZIYING_MEASURE]
0=kΩ
1=uf
2=v
3=kg
4=MHz
5=pf
6=pin
7=ppm
8=kw
[OFFICIAL_WEBSITE]
1 = https://www.futureelectronics.cn/search/?text=liexin
2 = http://www.powerandsignal.com/Products/Search?searchBox=liexin
3 = https://www.rocelec.com/search?q=liexin
4 = https://www.tme.eu/zh/katalog/#search=liexin
5 = https://www.verical.com/s/liexin/
6 = https://cn.element14.com/search?st=liexin
7 = https://www.digikey.com/products/en?keywords=liexin
8 = https://www.chip1stop.com/CHN/zh/view/searchResult/SearchResultTop?keyword=liexin
9 = http://www.aipco.com/search.php?pn=liexin
10 = https://www.arrow.com/en/products/search?cat=&q=liexin
11 = https://www.biscoind.com?SEARCHTEXT=liexin
12 = https://www.alliedelec.com/view/search?keyword=liexin
13 = https://www.avnet.com/shop/apac/search/liexin
14 = https://www.mouser.com/Search/Refine?Keyword=liexin
15 =
16 =
18 =
19 = https://www.peigenesis.cn/cn/shop/f/liexin.html
20 = https://www.powell.com/e2wItemQuickSearch.aspx?searchText=liexin
21 = https://uk.rs-online.com/web/c/semiconductors/amplifiers-comparators/op-amps/?searchTerm=liexin
22 =
1672 = https://www.masterelectronics.com/parts.aspx?text=liexin
1673 = https://www.rutronik24.com/search-result/qs:liexin
1675 = https://www.zaikostore.com/zaikostore/stockList?productName_forFind=liexin
1676 = https://www.buerklin.com/en/search?text=liexin
1677 = https://www.microchipdirect.com/product/search/all/liexin
1678 = https://estore.heilindasia.com/search.asp?p=liexin
1680 = http://shop.wpgam.com/WPGAStore/index.php?route=product/search&filter_description=true&filter_name=liexin
[AUTH]
SUPER_AUTH_KEY = fh6y5t4rr351d2c3bryi
SEARCH_TOKEN_EXPIRE_TIME = 30
[UNIT_SUPPLIER_LOG_CODE]
333333 = arrow
444444 = master
555555 = mouser
666666 = verical
777777 = tme
888888 = buerklin
999999 = zhuanmai
[SEARCH_API_LOG]
SEARCH_API_ERROR_PRE = search_api_overtime_
package controller
import (
"github.com/gin-gonic/gin"
"net/http"
"goods_machining/framework/gin_"
"goods_machining/pkg/config"
)
//放 通用中间件
//检查服务是否可用
func Check_Middleware() gin_.Middleware {
return func(next gin_.Endpoint) gin_.Endpoint {
return func(context *gin.Context, request interface{}) (response interface{}, err error) {
return next(context, request)
}
}
}
func Cors_Middleware() gin_.Middleware {
return func(next gin_.Endpoint) gin_.Endpoint {
return func(c *gin.Context, request interface{}) (response interface{}, err error) {
method := c.Request.Method
corsDomains := config.Get("web.cors.domain").Strings(",")
for _, domain := range corsDomains {
c.Header("Access-Control-Allow-Origin", domain)
}
c.Header("Access-Control-Allow-Origin", "https://bom.ichunt.com")
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization, Token")
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
c.Header("Access-Control-Allow-Credentials", "true")
//放行所有OPTIONS方法
if method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
}
// 处理请求
return next(c, request)
}
}
}
package controller
import (
"github.com/gin-gonic/gin"
"github.com/syyongx/php2go"
"goods_machining/middleware"
"goods_machining/pkg/common"
"goods_machining/service"
"sync"
)
const goods_slice_count = 50 //每多少个型号id开启一个协程
/*
查询商品详情(自营或者联营)
@doc http://192.168.2.232:3000/project/128/interface/api/649
@param goods_id 支持批量,不建议超过40个,超过会导致处理时间超过2秒,进程异常 : 74564,65897,456464131
@param power[newCustomer] 是否获取新客价 :true
@param power[member] 是否获取会员价 :true
@param power[mobile] 获取会员价时,用户有手机号时必填,用于会员价可见名单。活动价时必须,否则可能导致用户无法享受活动价 :13510507993
@param power[email] 获取会员价时,用户有邮箱时必填,用于会员价可见名单。活动价时必须,否则可能导致用户无法享受活动价 ymx@ichunt.com
@param power[user_id] 获取会员价时,必填,用于会员价可见名单。活动价时必须,否则可能导致用户无法享受活动价,如果用户未登录,可为空,用户是否可见活动价取决于配置 65139
@param power[fast] 仅获取价格与库存 :1
@param power[invoice] 增值税普通发票公司名字,活动价时必须,否则可能导致用户无法享受活动价 :深圳是猎芯科技有限公司
@param power[special_invoice] 增值税专用发票公司名字,活动价时需要,否则可能导致用户无法享受活动价 : 深圳是猎芯科技有限公司
@param power[verify_blacklist] 是否验证黑名单,用于折扣活动提交订单页面与后台下单 :true
*/
func Synchronization(c *gin.Context) {
common.PrintDebugHeader() //开启debug调试
zyService := service.ZiyingService{} //实例化自营查询
lyService := service.LyService{} //实例化自营查询
//抽取自营 或者联营 goods_id
GoodsIdStr := middleware.REQUEST["goods_id"]
if GoodsIdStr == "" {
common.Output(1001,"查询型号ID不得为空","")
}
GoodsRes := make(map[string]interface{}, 0) //接收算好的数据
goodsIdArr := php2go.Explode(",",GoodsIdStr)
wg := sync.WaitGroup{}
zyGoodsId := make([]string,0)
lyGoodsId := make([]string,0)
for _,goods_id := range goodsIdArr {
if len(goods_id) < 19 { //自营
zyGoodsId = append(zyGoodsId,goods_id)
if len(zyGoodsId) >= goods_slice_count {
common.PrintDebugHtml("zy增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId,&GoodsRes,&wg)
zyGoodsId = zyGoodsId[:0:0]
}
}else{ //联营
lyGoodsId = append(lyGoodsId,goods_id)
if len(lyGoodsId) >= goods_slice_count {
common.PrintDebugHtml("ly增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(lyGoodsId,&wg)
lyGoodsId = lyGoodsId[:0:0]
}
}
}
if len(zyGoodsId) >0 {
common.PrintDebugHtml("zy增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1) //协程计数一
go zyService.ZyGoodsDetail(zyGoodsId,&GoodsRes,&wg)
}
if len(lyGoodsId) >= goods_slice_count {
common.PrintDebugHtml("ly增加协程:")
common.PrintDebugHtml(zyGoodsId)
wg.Add(1)
go lyService.LyGoodsDetail(lyGoodsId,&wg)
}
wg.Wait()
common.Output(0,"查询成功",GoodsRes)
}
package dao
import (
"goods_machining/model"
"goods_machining/pkg/mysql"
)
//获取所有内部编码
func GetAllIntraCode() (intracode []model.Intracode, err error) {
err = mysql.Conn("cms").Table("lie_intracode").Select("code_id,admin_id").Find(&intracode)
return
}
//获取所有的用户基础信息
func GetAllUserBaseInfo() (userBaseInfo []model.CmsUserInfo, err error) {
err = mysql.Conn("cms").Table("user_info").Select("name,email,userId").Find(&userBaseInfo)
return
}
package dao
import (
"goods_machining/model"
"goods_machining/pkg/mysql"
)
//获取供应商编码和渠道开发员id
func GetAllSupplierCodeAndUid() (supplierChannels []model.SupplierChannel, err error) {
err = mysql.Conn("supp").Table("lie_supplier_channel").Select("supplier_code,channel_uid").
Where("status = ?", 2).Find(&supplierChannels)
return
}
package dao
import (
"encoding/json"
"github.com/ichunt2019/logger"
"goods_machining/model"
"goods_machining/pkg/mysql"
)
//根据id获取供应商信息
func GetSupplierExtraBySupplierId(supplierId int) (supplierExtra model.SupplierExtra, err error) {
_, err = mysql.Conn("spu").Table("lie_supplier_extra").Select("hk_delivery,cn_delivery,price_json as price_json_str,ad_text,supplier_logo,ad_url,sort").
Where("supplier_id = ?", supplierId).Get(&supplierExtra)
if supplierExtra.PriceJsonStr != "" {
err = json.Unmarshal([]byte(supplierExtra.PriceJsonStr), &supplierExtra.PriceJson)
if err != nil {
logger.Error("%s", err)
}
}
return
}
File mode changed
package main
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"strings"
)
func Sha1(query string, pri_key string) string {
key := []byte(pri_key)
mac := hmac.New(sha1.New, key)
mac.Write([]byte(query))
query = base64.StdEncoding.EncodeToString(mac.Sum(nil))
return query
}
func main() {
ss := strings.Index("attr[456546]","attr")
print(ss)
return
//println(php2go.Sha1("123456"+"123456"))
//ss := Sha1("POST&https%3A%2F%2Fapi.tme.eu%2FProducts%2FSearch.json&Country%3DUS%26Currency%3DUSD%26Language%3DEN%26SearchPlain%3DRMCF0402FT12R0%26Token%3D3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4","a1d8647fa38710140628")
//println(ss)
}
package main
import (
"fmt"
"sort"
)
// 按map的key排序
func main() {
params := make(map[string]interface{})
params["name"] = "xxx"
params["age"] = 23
params["sex"] = 0
params["level"] = 1
// 1.取出所有的key
var keys []string
for k := range params{
keys = append(keys, k)
}
// 对字符串切片排序
sort.Strings(keys)
fmt.Println(keys)
// 打印key, val
for _, k := range keys{
fmt.Printf("key: %v val:%v \n", k, params[k])
}
}
package main
import (
cmap "github.com/orcaman/concurrent-map"
)
func main() {
m := cmap.New()
// Sets item within map, sets "bar" under key "foo"
m.Set("foo", "bar")
m.Set("a1", "dd")
m.Set("b2", "ba343r")
// Retrieve item from map.
if tmp, ok := m.Get("foo"); ok {
bar := tmp.(string)
println(bar)
}
s,_ := m.MarshalJSON()
println(string(s))
// Removes item under key "foo"
//m.Remove("foo")
}
\ No newline at end of file
package main
import (
"encoding/json"
"fmt"
"github.com/iancoleman/orderedmap"
)
func main() {
o := orderedmap.New()
o.Set("error_code", 1)
o.Set("error_msg", "fagaga")
s := orderedmap.New()
s.Set("total",10)
aggs := orderedmap.New()
aggs.Set("1001€品牌",[...]string{"3001€mouser€0","4003€arrowV€0"})
aggs.Set("1002€标称电压",[...]string{"2001€5.5V€0","4003€arrowV€0"})
s.Set("aggs",aggs)
o.Set("data", s)
m1,_ := o.Get("error_msg")
fmt.Print(m1)
bytes, err := json.Marshal(o)
fmt.Print(string(bytes),err)
return
//// use Get instead of i, ok := o["a"]
//val, ok := o.Get("a")
//
//// use Keys instead of for k, v := range o
//key := o.Keys()
//for _, k := range keys {
// v, _ := o.Get(k)
//}
// use o.Delete instead of delete(o, key)
//err := o.Delete("a")
// serialize to a json string using encoding/json
//bytes, err := json.Marshal(o)
//fmt.Print(string(bytes),err)
//prettyBytes, err := json.MarshalIndent(o)
//
//// deserialize a json string using encoding/json
//// all maps (including nested maps) will be parsed as orderedmaps
//s := `{"a": 1}`
//err := json.Unmarshal([]byte(s), &o)
//
//// sort the keys
//o.SortKeys(sort.Strings)
//
//// sort by Pair
//o.Sort(func(a *Pair, b *Pair) bool {
// return a.Value().(float64) < b.Value().(float64)
//})
}
\ No newline at end of file
package main
import (
"github.com/tidwall/sjson"
"gopkg.in/olivere/elastic.v5"
)
const json = `{"name":{"first":"Janet","last":"Prichard"},"age":47}`
const param1 = `{
"query": {
"bool": {
"must": [
]
}
},
"aggs": {
"brand_id": {
"terms": {
"field": "brand_id",
"size": 1000
}
},
"attrs": {
"nested": {
"path": "attrs"
},
"aggs": {
"attr_name": {
"terms": {
"field": "attrs.attr_name",
"size": 5000
},
"aggs": {
"attr_value": {
"terms": {
"field": "attrs.attr_value",
"size": 5000
}
}
}
}
}
}
},
"sort": {
"sort": {
"order": "desc"
}
},
"from": 0,
"size": 0
}`
func main() {
query := elastic.NewBoolQuery()
query1 := elastic.NewBoolQuery()
query2 := elastic.NewBoolQuery()
query1.Must(elastic.NewTermQuery("class_id2",111))
query1.Should(elastic.NewTermQuery("brand_id","108"))
query1.Should(elastic.NewTermQuery("brand_id","107"))
query2.Should(elastic.NewNestedQuery("attrs",elastic.NewBoolQuery().Must(elastic.NewTermQuery("attrs.attr_name","nin"),elastic.NewTermQuery("attrs.attr_value","nni"))))
query2.Should(elastic.NewNestedQuery("attrs",elastic.NewBoolQuery().Must(elastic.NewTermQuery("attrs.attr_name","3333"),elastic.NewTermQuery("attrs.attr_value","333"))))
source := elastic.NewSearchSource()
source.Aggregation("brand_id",elastic.NewTermsAggregation().Field("brand_id").Size(1000))
source.Aggregation("attrs",elastic.NewNestedAggregation().Path("attrs").
SubAggregation("attr_name",elastic.NewTermsAggregation().Field("attrs.attr_name").Size(5000).
SubAggregation("attr_value",elastic.NewTermsAggregation().Field("attrs.attr_value").Size(5000))))
source.FetchSourceContext(elastic.NewFetchSourceContext(true).Include("goods_id", "stock")) //显示字段
source.Size(1)
query.Must(query1)
query.Must(query2)
source.Query(query)
searchRequest := elastic.NewSearchRequest().Source(source)
queryString, _ := searchRequest.Body()
print(queryString)
return
value, _ := sjson.Set(param1, "query.bool.must.-1", map[string]interface{}{"hello":"world"})
value, _ = sjson.Set(value, "query.bool.must.-1", map[string]interface{}{"hellosss":"world"})
println(value)
}
\ No newline at end of file
package main
import (
"fmt"
"github.com/gomodule/redigo/redis"
"log"
)
func main() {
c1, err := redis.Dial("tcp", "192.168.1.235:6379")
if err != nil {
log.Fatalln(err)
}
if _, err := c1.Do("AUTH", "icDb29mLy2s"); err != nil {
c1.Close()
log.Fatalln(err)
}
defer c1.Close()
reply, err := redis.Values(c1.Do("hvals", "Self_StockLock165514"))
if err != nil {
fmt.Print(err,"错误")
// handle error
}
var albums []int64
if err := redis.ScanSlice(reply, &albums); err != nil {
fmt.Println(err)
return
}
fmt.Printf("%v\n", albums)
//if _, err := redis.Scan(reply, &value1,&value2); err != nil {
// // handle error
// }
// fmt.Print(value1,value2)
return
//c1.Send("HGet", "sku","1150969960421953396")
c1.Send("hvals", "Self_StockLock165514")
//c1.Send("HGet", "sku","1159160904159516648333")
//c1.Send("HGet", "sku","1150961577851663286")
c1.Flush()
//echoReceive(c1.Receive())
s,err := c1.Receive()
fmt.Print(err,s.([]uint64))
//echoReceive(c1.Receive())
//echoReceive(c1.Receive())
//echoReceive(c1.Receive())
}
func echoReceive(res interface{}, err error){
if err != nil{
fmt.Println(err)
}else {
if res != nil{
fmt.Printf("--------- ")
fmt.Println(string(res.([]byte)))
}else {
fmt.Println(res)
}
}
}
package main
import (
"flag"
"fmt"
log "github.com/sirupsen/logrus"
"github.com/syyongx/php2go"
"reflect"
"goods_machining/boot"
"goods_machining/service"
)
func StrRandom(lenNum int) string {
randStr := "sdwpkxmiqplmzacbmeruwulurjlauejrifkfghjklzxcvbnmqwwertyuiopkdsieurnvewjeilweiskvnx"
strLen := len(randStr) - 9
var result string
for i := 0; i < lenNum; i++ {
//start := common.Rand(0, strLen)
start := php2go.Rand(0, strLen)
fmt.Println(start)
str := php2go.Substr(randStr, uint(start), 9)
result = result + " " + str
}
return result
}
type LogFormatter struct{}
//格式详情
func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
msg := entry.Message + "\n"
return []byte(msg), nil
}
func main() {
var path string
flag.StringVar(&path, "configPath", "conf", "配置文件")
flag.Parse()
if err := boot.Boot(path); err != nil {
fmt.Println(err)
}
res, _ := service.GetGoodsInfo([]string{"74163","116492","74123","106095","116451","162774","74152","116078","74122","74132"})
fmt.Println(len(res))
}
func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
panic("InterfaceSlice() given a non-slice type")
}
ret := make([]interface{}, s.Len())
for i := 0; i < s.Len(); i++ {
ret[i] = s.Index(i).Interface()
}
return ret
}
package main
import (
"fmt"
"encoding/json"
)
func main() {
var goodsList []interface{}
var productList map[string]interface{}
var price_temp []interface{}
var tiered []interface{}
m := make(map[string]interface{})
m["goods_names"] = "LM358"
m["stock"] = [...]int64{1,23}
price_temp = append(price_temp,[...]int64{3,5})
m["price_temp"] = price_temp;
s := make(map[string]interface{})
s["purchases"]=1
s["price_us"]=0.66
s["price_us"]=0.67
s["price_cn"]=0.33
tiered = append(tiered,s);
m["tiered"] = tiered;
goodsList = append(goodsList, m)
productList = make(map[string]interface{})
productList["595-LM358BIDR"] = goodsList
productList["595-LM358LVIDDFR"] = goodsList
//map的遍历
for k, v := range productList{
fmt.Println(k,v)
}
jsonStr, err := json.Marshal(productList)
if err!=nil{
return
}
fmt.Printf("%s\n",jsonStr)
}
\ No newline at end of file
package main
import (
"fmt"
"encoding/json"
"goods_machining/model"
)
func main() {
var LyClearGoodsList model.LyClearGoodsList
LyClearGoodsList.GoodsName = "LM358"
ladderPrice := make([]*model.TierItem, 0)
ladder := model.TierItem{
Purchases: 1,
PriceUs: 0.44,
PriceCn: 1.55,
}
ladderPrice = append(ladderPrice, &ladder)
LyClearGoodsList.Tiered = ladderPrice
var productList map[string]*model.LyClearGoodsList
productList = make(map[string]*model.LyClearGoodsList,0)
productList["595-LM358BIDR"] = &LyClearGoodsList
//map的遍历
for k, v := range productList{
fmt.Println(k,v)
}
jsonStr, err := json.Marshal(productList)
if err!=nil{
return
}
fmt.Printf("%s\n",jsonStr)
}
\ No newline at end of file
package main
import (
"bytes"
"fmt"
"strconv"
)
func intsToString(values []int) string {
var buf bytes.Buffer
buf.WriteByte('[')
for i, v := range values {
if i > 0 {
buf.WriteString(", ")
}
fmt.Fprintf(&buf, "%d", v)
}
buf.WriteByte(']')
return buf.String()
}
func main() {
var a,b,c float64
a=1.69*100
b=1.7*10
c=a*b/(100*10)
//��ȷ���2.873
fmt.Println(c)
//fmt.Println(fmt.Sprintf("%.2f",c))
//fmt.Println(FloatRound(c,2))
}
// ��ȡС��λ��
func FloatRound(f float64, n int) float64 {
format := "%." + strconv.Itoa(n) + "f"
//fmt.Println(format)
res, _ := strconv.ParseFloat(fmt.Sprintf(format, f), 64)
return res
}
package main
import (
"fmt"
"reflect"
)
// interface{}转为 []interface{}
func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool) {
val, ok := isSlice(slice)
if !ok {
return nil, false
}
sliceLen := val.Len()
out := make([]interface{}, sliceLen)
for i := 0; i < sliceLen; i++ {
out[i] = val.Index(i).Interface()
}
return out, true
}
// 判断是否为slcie数据
func isSlice(arg interface{}) (val reflect.Value, ok bool) {
val = reflect.ValueOf(arg)
if val.Kind() == reflect.Slice {
ok = true
}
return
}
// 看需求写的代码
func faa(arg interface{}) {
slice, ok := CreateAnyTypeSlice(arg)
if !ok {
return
}
for index,value := range slice {
fmt.Println(index,value)
}
}
func main() {
intSlice := []int{1,2,3,4,5,6,7,8}
strSlice := []string{"a","b","c","d"}
boolSlice := []bool{true,true,false,true}
faa(intSlice)
faa(strSlice)
faa(boolSlice)
}
\ No newline at end of file
package main
import (
"fmt"
"reflect"
"regexp"
"strings"
)
func remove2(s interface{}, deleteVal int) []interface{} {
val := reflect.ValueOf(s)
sliceLen := val.Len()
out := make([]interface{}, sliceLen)
if val.Kind() == reflect.Slice {
sliceLen := val.Len()
for i := 0; i < sliceLen; i++ {
if val.Index(i).Int() != int64(deleteVal){
out[i] = val.Index(i).Interface()
}
}
}
return out
}
func main(){
a := []int{1,2,3,4,5}
fmt.Println(remove2(a,3))
test := "a,b,c,d,e"
aaa := test
keywordSlice := strings.Split(test,",")
for _,v := range keywordSlice{
reg := regexp.MustCompile("(?i)"+v)
aaa = reg.ReplaceAllString(aaa,"<b class='f-red'>"+strings.ToUpper(v)+"</b>")
fmt.Println(aaa)
}
}
package main
import (
"bytes"
"fmt"
"io"
)
const debug = false
func main() {
//var buf *bytes.Buffer
var buf io.Writer
fmt.Printf("%T \n",buf)
if debug {
buf = new(bytes.Buffer) // enable collection of output
}
f(buf) // NOTE: subtly incorrect!
if debug {
// ...use buf...
}
}
// If out is non-nil, output will be written to it.
func f(out io.Writer) {
// ...do something...
fmt.Println(out)
fmt.Printf("%T \n",out)
if out != nil {
fmt.Println("!!!!!!!!!!")
out.Write([]byte("done!\n"))
}
var a interface{}
a = map[string]string{
"a":"b",
}
a = nil
b,_ := a.(map[string]string)
fmt.Println(b)
}
\ No newline at end of file
package main
import (
"fmt"
"github.com/imroc/req"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/middleware"
"goods_machining/model"
"goods_machining/pkg/common"
"strconv"
"time"
)
//tme 类
type tme struct {
}
//tme外链网址
const tme_api_url_product string = "https://api.tme.eu/Products/Search.json" //'Products/Search' 查询商品 或者 'Products/GetPricesAndStocks' 查询价格
const tme_api_url_stock string = "https://api.tme.eu/Products/GetPricesAndStocks.json" //'Products/Search' 查询商品 或者 'Products/GetPricesAndStocks' 查询价格
const tme_token string = "3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4"//密钥
const tme_app_secret string = "a1d8647fa38710140628" //账号
//tme请求外链
func OutLinkTme(goodsName *string) map[string]*model.LyClearGoodsList {
if *goodsName == "" {
return nil
}
var (
result string //请求外链原始结果
SymbolList string //外链原始数据的goods_sn
);
if middleware.REQUEST["flags"] == "-1" { //原始数据调试
result = `{"Status":"OK","Data":{"ProductList":[{"Symbol":"0402WGF1000TCE","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.01,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":10000,"Multiples":10000,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/0402wgf1000tce\/0402-smd-resistors\/royal-ohm\/","Guarantee":null,"OfferId":null},{"Symbol":"SMD0402-100R-1%","CustomerSymbol":"","OriginalSymbol":"0402WGF1000TCE","Producer":"ROYAL OHM","Description":"Resistor: thick film; SMD; 0402; 100\u03a9; 63mW; \u00b11%; -55\u00f7155\u00b0C","CategoryId":"100578","Category":"0402 SMD resistors","Photo":"\/\/ce8dc832c.cloudimg.io\/fit\/640x480\/n@4760e4647bc7d903de9205a51f321b69cdbed098\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg?mark_url=_tme-wrk_%2Ftme_new_render3d.png&mark_pos=center&mark_size=100pp","Thumbnail":"\/\/ce8dc832c.cloudimg.io\/fit\/100x75\/webp@3ec3fbcb8427a46b791b093cd6e191b483328d8a\/_cdn_\/D9\/C2\/B0\/00\/0\/732317_1.jpg","Weight":0.006,"WeightUnit":"g","SuppliedAmount":0,"MinAmount":100,"Multiples":100,"ProductStatusList":[],"Unit":"pcs","ProductInformationPage":"\/\/www.tme.eu\/en\/details\/smd0402-100r-1%\/0402-smd-resistors\/royal-ohm\/0402wgf1000tce\/","Guarantee":null,"OfferId":null}],"Amount":2,"PageNumber":1,"CategoryList":{"111000":2,"100299":2,"100300":2,"100578":2,"112309":2}}}`;
}else{
params1 := "Country=US&Currency=USD&Language=EN&SearchPlain="+*goodsName+"&Token="+tme_token
param := "POST"+"&"+php2go.Rawurlencode(tme_api_url_product)+"&"+php2go.Rawurlencode(params1)
common.PrintDebugHtml(param)
sign := common.Sha1(param,tme_app_secret) //生成签名
postParam := params1+"&ApiSignature="+php2go.URLEncode(sign);
common.PrintDebugHtml(postParam)
req.SetTimeout(30 * time.Second)
//resp, err := req.Post(params2,postParam)
req.Debug = true
ss := req.Param{
"SearchPlain":*goodsName,
"Country":"US",
"Currency":"USD",
"Language":"EN",
"Token":"3381c9d5d9663be68eb69ea3ce00af3a2b5789094c7cd488a4",
"ApiSignature":sign,
}
resp, err := req.Post(tme_api_url_product,ss)
if err != nil {
print(tme_api_url_product)
print(err)
}
result = resp.String(); //请求外链拿到结果
}
common.PrintDebugHtml("原始数据:"+result)
productList := make(map[string]*model.LyClearGoodsList,0)
if gjson.Get(result,"Status").String() != "OK" {
common.PrintDebugHtml("请求出错-没有数据")
return nil
}
apiGoodsList := gjson.Get(result, "Data.ProductList").Array()
i := 0;
for _, goods := range apiGoodsList {
goodsSn := goods.Get("Symbol").String()
if i == 0 {
SymbolList = SymbolList+"&SymbolList[0]="+goodsSn
}else{
SymbolList = SymbolList+"&SymbolList["+strconv.Itoa(i)+"]"+goodsSn
}
i ++;
var increment int64 = 1;
if goods.Get("Multiples").Int() > 0 {
increment = goods.Get("Multiples").Int()
}
var moq int64 = 1;
if goods.Get("MinAmount").Int() > 0 {
moq = goods.Get("MinAmount").Int()
}
//拼接联营数据
LyClearGoodsList := model.LyClearGoodsList{
GoodsName: goods.Get("OriginalSymbol").String(),
BrandName: goods.Get("Producer").String(),
Desc: goods.Get("Description").String(),
GoodsSn: goodsSn,
Docurl: goods.Get("DataSheetUrl").String(),
Url: goods.Get("ProductInformationPage").String(),
GoodsImg: goods.Get("Photo").String(),
Increment: increment,
Moq:moq, //最低起订量
}
productList[goodsSn] = &LyClearGoodsList
}
//查询价格库存
params1 := "Country=US&Currency=USD&Language=EN&SymbolList="+SymbolList+"&Token="+tme_token
param := "POST"+"&"+php2go.Rawurlencode(tme_api_url_stock)+php2go.Rawurlencode(params1)
sign := common.Sha1(param,tme_app_secret) //生成签名
req.SetTimeout(10 * time.Second)
resp, err := req.Post(tme_api_url_stock,req.BodyJSON(params1+"&ApiSignature"+sign))
if err != nil {
print(tme_api_url_stock)
print(err)
}
result = resp.String(); //请求外链拿到结果
fmt.Println(result,SymbolList)
if gjson.Get(result,"Status").String() != "OK" {
common.PrintDebugHtml("请求出错-价格库存")
return nil
}
priceData := gjson.Get(result, "Data.ProductList").Array()
for _, info := range priceData {
ladderPrice := make([]*model.TierItem, 0)
priceTemp := make([]interface{}, 0)
//拼接价格梯度
apiPriceTi := info.Get("PriceList").Array()
var apiLowerPrice float64 = 0; //计算最低价格
for _,priceItem := range apiPriceTi{
priceItemStr := priceItem.String();
skuPrice := gjson.Get(priceItemStr, "PriceValue").Float()
quantity := gjson.Get(priceItemStr, "Amount").Int()
if apiLowerPrice == 0 {
apiLowerPrice = skuPrice
}else if apiLowerPrice > skuPrice {
apiLowerPrice = skuPrice
}
ladder := model.TierItem{
Purchases: quantity,
PriceUs: skuPrice,
PriceCn: 0,
}
ladderPrice = append(ladderPrice, &ladder)
//梯度缓存数据
priceTemp = append(priceTemp,[]interface{}{
quantity,
skuPrice,
})
}
goodsSn := info.Get("Symbol").String()
productList[goodsSn].Stock = info.Get("Amount").Int() //库存
productList[goodsSn].Tiered = ladderPrice //梯度价格
productList[goodsSn].PriceTemp = priceTemp //梯度价格2
productList[goodsSn].SinglePrice = apiLowerPrice //最低价格
}
return productList
}
***redis键值: Self_SelfGoods
{
"other_attrs": "",
"goods_id": 203065,
"goods_type": 0,
"supplier_id": 10000,
"brand_id": 4492,
"class_id1": 10152,
"class_id2": 10164,
"goods_name": "RR0603(0201)L1203FTD",
"status": 1,
"encoded": "",
"encap": "0201(0603)",
"packing": 5,
"goods_unit": 1,
"goods_images": "",
"pdf": "",
"goods_brief": "",
"moq": 50,
"mpq": 15000,
"ladder_price": [
{
"purchases": 50,
"price_cn": 0.0044
},
{
"purchases": 1000,
"price_cn": 0.0044
},
{
"purchases": 15000,
"price_cn": 0.0044
}
],
"update_time": 1592218150,
"sku_name": "RR0603(0201)L1203FTD u7f16u5e26 PTC u70edu654fu7535u963b ",
"mpl": 1,
"stock": 0,
"attrs": "",
"cost": "0.000000",
"new_cost": "0.000000",
"supplier_stock": 473349,
"self_supplier_type": 4
}
#############最终结果##########
Array
(
[33072] => Array
(
[other_attrs] => Array
(
[length] =>
[gross_wegiht] => 0.000582
)
[goods_id] => 33072
[goods_type] => 0
[supplier_id] => 10000
[brand_id] => 703
[class_id1] => 161
[class_id2] => 169
[goods_name] => 3362P-1-101LF
[status] => 1
[encoded] => 10141
[encap] => 3362P
[packing] => 8
[goods_unit] => 1
[goods_images] => http://img.ichunt.com/images/goods/bb/a6/bba6b9cb12bf5f581cd4525a9d5995de.png
[pdf] => http://img.ichunt.com/doc/pdf/cms/201809/13/d110c1966263019b39775c419f57b4a2.pdf
[goods_brief] =>
[moq] => 1
[mpq] => 50
[ladder_price] => Array
(
[0] => Array
(
[purchases] => 1
[price_cn] => 0.95
[price_ac] => 0.5944
)
[1] => Array
(
[purchases] => 10
[price_cn] => 0.874
[price_ac] => 0.5944
)
[2] => Array
(
[purchases] => 20
[price_cn] => 0.836
[price_ac] => 0.5944
)
[3] => Array
(
[purchases] => 50
[price_cn] => 0.798
[price_ac] => 0.5944
)
[4] => Array
(
[purchases] => 250
[price_cn] => 0.76
[price_ac] => 0.5944
)
)
[update_time] => 1596436153
[sku_name] => 3362P-1-101LF 精密可调电阻 100Ω(101) 3362P
[mpl] => 1
[stock] => 67
[attrs] => Array
(
[0] => Array
(
[attr_name] => 阻值(欧姆)
[attr_value] => 100Ω(101)
)
[1] => Array
(
[attr_name] => 精度
[attr_value] =>
)
[2] => Array
(
[attr_name] => 温度系数
[attr_value] =>
)
)
[cost] => 0.699248
[new_cost] => 0.602800
[supplier_stock] => 0
[self_supplier_type] => 1
[cn_delivery_time] => 3-7工作日
[brand_name] => BOURNS(伯恩斯)
[supplier_name] => 猎芯自营
[goods_unit_name] => 个
[packing_name] => 管
[mpq_unit_name] => 管
[scm_brand_name] =>
[actual_stock] => 100
[ac_type] => 6
[allow_coupon] => 1
[allow_presale] => 1
[saler_atio] =>
[szlc_price] =>
[class_id1_name] => 电阻
[class_id2_name] => 精密可调电阻
[is_buy] => 1
)
)
package gin_
type ServiceBuilder struct {
service interface{}
endPoint Endpoint
requestFunc EncodeRequestFunc
responseFunc DecodeResponseFunc
methods string
middlewares []Middleware
}
func NewBuilder() *ServiceBuilder {
return &ServiceBuilder{middlewares:make([]Middleware,0)}
}
func(this *ServiceBuilder) WithService(obj interface{}) *ServiceBuilder {
this.service=obj
return this
}
func(this *ServiceBuilder) WithMiddleware(obj Middleware) *ServiceBuilder {
this.middlewares=append(this.middlewares,obj)
return this
}
func(this *ServiceBuilder) WithEndpoint(obj Endpoint) *ServiceBuilder {
this.endPoint=obj
return this
}
func(this *ServiceBuilder) WithRequest(obj EncodeRequestFunc) *ServiceBuilder {
this.requestFunc=obj
return this
}
func(this *ServiceBuilder) WithResponse(obj DecodeResponseFunc) *ServiceBuilder {
this.responseFunc=obj
return this
}
func(this *ServiceBuilder) WithMethods(methods string) *ServiceBuilder {
this.methods=methods
return this
}
func(this *ServiceBuilder) Build(path string,methods string) *ServiceBuilder{
finalEndpoint:=this.endPoint
for _,m:=range this.middlewares{ //遍历中间件
finalEndpoint=m(finalEndpoint)
}
handler:=RegisterHandler(finalEndpoint,this.requestFunc,this.responseFunc)
SetHandler(methods,path,handler)
return this
}
package gin_
import (
"fmt"
"github.com/gin-gonic/gin"
)
type Middleware func(next Endpoint) Endpoint
//业务最终函数原型
type Endpoint func(ctx *gin.Context,request interface{}) (response interface{}, err error)
//怎么取参数
type EncodeRequestFunc func(*gin.Context) (interface{}, error)
//怎么处理业务结果
type DecodeResponseFunc func(*gin.Context, interface{}) error
func RegisterHandler(endpoint Endpoint,encodeFunc EncodeRequestFunc, decodeFunc DecodeResponseFunc) func(context *gin.Context){
return func(ctx *gin.Context) {
defer func() {
if r:=recover();r!=nil{
ctx.JSON(500,gin.H{"error":fmt.Sprintf("fatal error:%s",r)})
return
}
}()
//参数:=怎么取参数(context)
//业务结果,error:=业务最终函数(context,参数)
//
//
//怎么处理业务结果(业务结果)
req,err:=encodeFunc(ctx) //获取参数
if err!=nil{
ctx.JSON(400,gin.H{"error":"param error:"+err.Error()})
return
}
rsp,err:=endpoint(ctx,req) //执行业务过程
if err!=nil{
ctx.JSON(400,gin.H{"error":"response error:"+err.Error()})
return
}
err=decodeFunc(ctx,rsp) //处理 业务执行 结果
if err!=nil{
ctx.JSON(500,gin.H{"error":"server error:"+err.Error()})
return
}
}
}
package gin_
import (
"github.com/gin-gonic/gin"
)
var HandlerMap map[string]map[string]gin.HandlerFunc
func init() {
HandlerMap=make( map[string]map[string]gin.HandlerFunc)
}
func SetHandler(methods string,path string,handler gin.HandlerFunc) {
if _,ok:=HandlerMap[path];ok{
HandlerMap[path][methods]=handler
}else{
HandlerMap[path]=make(map[string]gin.HandlerFunc)
}
HandlerMap[path][methods]=handler
}
func BootStrap(router *gin.Engine) {
for path,hmap:=range HandlerMap{
for method,handler:=range hmap{
router.Handle(method,path,handler)
}
}
}
\ No newline at end of file
module goods_machining
go 1.14
require (
github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd // indirect
github.com/elliotchance/orderedmap v1.3.0 // indirect
github.com/gin-contrib/cors v1.3.1
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.57.0
github.com/go-sql-driver/mysql v1.5.0
github.com/go-xorm/xorm v0.7.9
github.com/gogo/protobuf v1.3.1 // indirect
github.com/golang/protobuf v1.4.2
github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.14.3 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/ichunt2019/logger v1.0.5
github.com/imroc/req v0.3.0
github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect
github.com/micro/go-micro v1.16.0
github.com/micro/go-micro/v2 v2.9.0
github.com/prometheus/client_golang v1.5.1 // indirect
github.com/prometheus/common v0.10.0
github.com/prometheus/procfs v0.0.11 // indirect
github.com/sirupsen/logrus v1.5.0
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect
github.com/syyongx/php2go v0.9.4
github.com/tidwall/gjson v1.6.1
github.com/tidwall/sjson v1.1.1 // indirect
github.com/uniplaces/carbon v0.1.6
go.mongodb.org/mongo-driver v1.3.5 // indirect
go.uber.org/zap v1.14.1 // indirect
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece
google.golang.org/grpc v1.29.1 // indirect
google.golang.org/protobuf v1.24.0
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/olivere/elastic.v5 v5.0.85
sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/core v0.7.2-0.20190928055935-90aeac8d08eb
)
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
*
!.gitignore
\ No newline at end of file
package middleware
import (
"github.com/gin-gonic/gin"
"strings"
)
var Context *gin.Context
var REQUEST map[string]string //等同于php 的$_REQUEST,只接收非数组值
var REQUEST_MAP map[string][]string //接收参数的数组,只支持二维
//将gin的上下文放到全局变量
func ContextVars() gin.HandlerFunc {
return func(c *gin.Context) {
//接收所有的变量+值
REQUEST = make(map[string]string)
REQUEST_MAP = make(map[string][]string)
c.MultipartForm()
for requestName, requstValue := range c.Request.Form {
values := make([]string,0);
if len(requstValue) == 1 {
REQUEST[requestName] = strings.TrimSpace(requstValue[0])
REQUEST_MAP[requestName] = append(values,requstValue[0])
}
if len(requstValue) > 1 { //接收多维数组
var i int
for i = 0; i < len(requstValue); i++ {
values = append(values,requstValue[i])
}
REQUEST_MAP[requestName] = values
}
}
//将gin的上下文放到全局变量
Context = c
c.Next()
}
}
package middleware
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"goods_machining/pkg/config"
"time"
)
func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
corsDomain = append(corsDomain, "https://bom.ichunt.com")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}
package model
import (
"goods_machining/pkg/config"
)
//获取需要排除的品牌id
//branType = 1 : 联营 2 : 自营
func GetExcludeBrandIds(brandType int) (excludeBrandIds []int) {
isNoTi := config.Get("BRAND.IS_NOT_TI").String()
//如果关闭,直接返回空数据
if isNoTi == "0" {
return
}
//返回联营的brand_id切片
if brandType == 1 {
tiLyBrandIds := config.Get("BRAND.TI_LY_BRAND_IDS").Ints(",")
excludeBrandIds = tiLyBrandIds
//获取的是字符串
return
}
//返回自营的ti的brand_id切片
tiZyBrandId := config.Get("BRAND.TI_ZY_BRAND_IDS").Ints(",")
excludeBrandIds = tiZyBrandId
return
}
package model
type ApiGoods struct {
PickType int `json:"pick_type,omitempty"`
BarCode string `json:"barcode,omitempty"`
GoodsId string `json:"goods_id"`
GoodsName string `json:"goods_name"`
GoodsSn string `json:"goods_sn"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
SupplierId int `json:"supplier_id"`
Moq int `json:"-"`
MoqStr interface{} `json:"moq"`
Mpq int `json:"-"`
MpqStr interface{} `json:"mpq"`
Mpl int `json:"-"`
MplStr interface{} `json:"mpl,omitempty"`
Stock int `json:"-"`
StockStr interface{} `json:"stock"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []LadderPrice `json:"ladder_price"`
BrandName string `json:"brand_name"`
SupplierName string `json:"supplier_name"`
BrandId int `json:"brand_id"`
ClassId1 int `json:"class_id1"`
ClassId2 int `json:"class_id2"`
ClassName string `json:"class_name"`
Encoded string `json:"encoded"`
Packing string `json:"packing,omitempty"`
GoodsUnit string `json:"goods_unit,goods_unit"`
GoodsImages string `json:"goods_images"`
GoodsDetails string `json:"goods_details"`
GoodsBrief string `json:"goods_brief,omitempty"`
IsBuy int `json:"is_buy"`
Status int `json:"status"`
Pdf string `json:"pdf"`
Encap string `json:"encap"`
AcType int `json:"ac_type"`
OtherAttrs OtherAttrs `json:"other_attrs"`
UpdateTime int `json:"update_time"`
SkuName string `json:"sku_name,omitempty"`
Attrs Attrs `json:"attrs"`
Cost string `json:"cost,omitempty"`
NewCost string `json:"new_cost,omitempty"`
SupplierStock int `json:"supplier_stock,omitempty"`
SelfSupplierType int `json:"self_supplier_type,omitempty"`
GoodsUnitName string `json:"goods_unit_name,omitempty"`
PackingName string `json:"packing_name,omitempty"`
MpgUnitName string `json:"mpg_unit_name,omitempty"`
ScmBrandName string `json:"scm_brand_name,omitempty"`
AllowCoupon int `json:"allow_coupon"`
ClassId1Name string `json:"class_id1_name"`
CLassId2Name string `json:"class_id2_name"`
SpuId string `json:"spu_id,omitempty"`
BatchSn string `json:"batch_sn"`
Canal string `json:"canal"`
CpTime int `json:"cp_time"`
Coefficient Coefficient `json:"coefficient,omitempty"`
OriginalPrice []OriginalPrice `json:"original_price,omitempty"`
SuppExtendFee SuppExtendFee `json:"supp_extend_fee,omitempty"`
ClassId3 int `json:"class_id3"`
SpuName string `json:"spu_name,omitempty"`
ImagesL string `json:"images_l,omitempty"`
SpuBrief string `json:"spu_brief"`
SpuDetail string `json:"spu_detail"`
ClassName3 string `json:"class_name3"`
ErpTax bool `json:"erp_tax"`
ScmBrand ScmBrand `json:"scm_brand,omitempty"`
ActivityEndTime int64 `json:"activity_end_time,omitempty"`
}
type ZiyinGoodsInfo struct {
GoodsNameOrg string `json:"goods_name_org"`
SampleStatus string `json:"sample_status"`
SampleMaxNumber string `json:"sample_max_number"`
SampleClassId string `json:"sample_class_id"`
SampleClassIdName string `json:"sample_class_id_name"`
Quota int `json:"quota"`
DullGoodsData
}
//经过处理后的商品数据
type DullGoodsData struct {
ApiGoods
//额外增加的字段
GoodsNameTemp string `json:"goods_name_temp,omitempty"`
Multiple int `json:"-"`
MultipleStr interface{} `json:"multiple,omitempty"`
SupplierLogo string `json:"supplier_logo,omitempty"`
SupplierSort int `json:"supplier_sort,omitempty"`
SupplierAd interface{} `json:"supplier_ad"`
SearchSampleApplication string `json:"search_sample_application"`
SearchContactExperts string `json:"search_contact_experts"`
PageFlag int `json:"page_flag"`
SupplierWebsite string `json:"supplier_website"`
PurchaseName string `json:"purchase_name"`
Ratio int `json:"ratio"`
PriceXs float64 `json:"price_xs"`
PriceProfit float64 `json:"price_profit"`
PriceHkxs float64 `json:"price_hkxs"`
CouponId int `json:"coupon_id"`
CouponTitle string `json:"coupon_title"`
LastSearchTime int `json:"last_search_time"`
CustomsTax string `json:"customs_tax"`
Alike string `json:"alike"`
BrandUrl string `json:"brand_url"`
GoodsUrl string `json:"goods_url"`
CompanyName string `json:"-"`
ProviderName string `json:"-"`
}
type Attr struct {
AttrName string `json:"attr_name,omitempty"`
AttrValue string `json:"attr_value,omitempty"`
}
type Attrs map[string]Attr
type OtherAttrs struct {
GrossWeight string `json:"gross_weight,omitempty"`
}
type LadderPrice struct {
Purchases int `json:"-"`
PurchasesStr interface{} `json:"purchases"`
PriceUs float64 `json:"price_us"`
PriceCn float64 `json:"price_cn"`
PriceAc float64 `json:"price_ac,omitempty"`
}
type Coefficient struct {
Cn float64 `json:"cn"`
Hk float64 `json:"hk"`
ExtraRatio float64 `json:"extra_ratio"`
Ratio float64 `json:"ratio"`
Tax float64 `json:"tax"`
}
type OriginalPrice struct {
Purchases int `json:"purchases"`
PriceCn float64 `json:"price_cn"`
PriceUs float64 `json:"price_us"`
}
type SuppExtendFee struct {
Cn struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"cn,omitempty"`
Hk struct {
Max int `json:"max"`
Price float64 `json:"price"`
} `json:"hk,omitempty"`
}
type ScmBrand struct {
ErpBrandName string `json:"erp_brand_name,omitempty"`
ErpBrandId string `json:"erp_brand_id,omitempty"`
ScmBrandId string `json:"scm_brand_id,omitempty"`
}
package model
//联营统一返回格式
type LyResponse struct {
ErrorCode int `json:"error_code"`
ErrorMsg string `json:"error_msg"`
Data interface{} `json:"data"`
}
//联营请求外链后格式化数据
type LyClearGoodsList struct {
SkuId string `json:"sku_id"` //平台型号id (非必填)
SpuId string `json:"spu_id"` //平台spuId (非必填)
BrandId string `json:"brand_id"` //平台品牌id (非必填)
GoodsName string `json:"goods_name"` //型号名称
BrandName string `json:"brand_name"` //品牌名称
Desc string `json:"desc"` //描述
BatchSn string `json:"batch_sn"` //批次号
GoodsSn string `json:"goods_sn"` //api唯一编码
Docurl string `json:"docurl"` //sku对应供应商的文档路径
Url string `json:"url"` //sku对应供应商的商品详情
GoodsImg string `json:"goods_img"` //sku图片
Cat string `json:"cat"` //分类
Encap string `json:"encap"` //包装
Canal string `json:"canal"` //渠道标签
Encoded string `json:"encoded"` //内部编码
RestrictionMessage string `json:"RestrictionMessage"` //额外购买限制内容,如 ‘当前商品不在本地区销售’
Increment int64 `json:"increment"` //最小包装量、倍数 =Mpq
SinglePrice float64 `json:"single_price"` //最小单价
Stock int64 `json:"stock"` //库存
Moq int64 `json:"moq"` //最小起订量、起订量
Packaging string `json:"Packaging"` //包装
RawGoodsId string `json:"raw_goods_id"` //外链原始goods_sn,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
RawBrandName string `json:"raw_brand_name"` //外链原始品牌名称,如digikey:{'raw_goods_id': 'AT28C64X-25PC-ND', 'raw_brand_name': 'Microchip Technology'}
Tiered []*TierItem `json:"tiered"` //价格梯度数量
PriceTemp []interface{} `json:"price_temp"` //拼接梯度,目前只有联营推送队列用
DigiKeyPartNumber string `json:"DigiKeyPartNumber"` //digkey 唯一编码 (额外字段)
ManufacturerLeadWeeks string `json:"ManufacturerLeadWeeks"` //digikey交期(额外字段)
}
type TierItem struct {
Purchases int64 `json:"purchases"` //购买数量
PriceUs float64 `json:"price_us"` //数量对应的英文价格
PriceCn float64 `json:"price_cn"` //数量对应的中文价格
PriceAc float64 `json:"price_ac"`
}
//原始品牌(目前只有digikey使用)
type RawGoods struct {
RawGoodsId string `json:"raw_goods_id"` //原始goods_sn
RawBrandName string `json:"raw_brand_name"` //原始品牌名称
Pack string `json:"pack"` //包装
}
/*
供应商详情
Array
(
[supplier_id] => 4
[supplier_nickname] => tme
[ad_text] => 电子元器件、电工产品和工业自动化元件的全球分销商
[cn_delivery] => 5-9工作日
[hk_delivery] => 4-7工作日
[ad_url] => https://www.ichunt.com/
[sort] => 0
[supplier_logo] => http://img.ichunt.com/images/cms/201912/11/b2c4e3aae9a2312dfe6b9c318b430354.jpg
[status] => 1
[describe] => 电子元器件、电工产品和工业自动化元件的全球分销商
[price_json] => Array
(
[0] => Array
(
[hk] => 1.197
[cn] => 9.2534796
[rate] => 6.9
)
)
)
*/
type SUPPLIER_REDIS_INFO struct {
SupplierId int64 `json:"supplier_id"` //供应商id
SupplierNickname string `json:"supplier_nickname"` //供应商名称
AdText string `json:"ad_text"` //供应商描述
CnDelivery string `json:"cn_delivery"` //国内交货时间
HkDelivery string `json:"hk_delivery"` //香港交货时间
AdUrl string `json:"ad_url"` //供应商官网
Sort string `json:"sort"` //排序
SupplierLogo string `json:"supplier_logo"` //供应商logo
Status string `json:"status"` //状态,1开启
Describe string `json:"describe"` //描述
PriceJson []*PriceJsonItem //价格
}
type PriceJsonItem struct {
hk float64 //购买数量
cn float64 //数量对应的英文价格
rate float64 //数量对应的中文价格
}
/*
联营sku详情
Array
(
[spu_id] => 2.1540893752409E+18
[encoded] =>
[moq] => 624
[mpq] => 1
[old_goods_id] => 0
[goods_type] => 1
[goods_status] => 1
[batch_sn] =>
[stock] => 0
[hk_delivery_time] =>
[cn_delivery_time] =>
[update_time] => 1540967156
[goods_images] =>
[canal] =>
[supplier_id] => 10
[is_expire] => 1
[ladder_price] => Array
(
[0] => Array
(
[purchases] => 624
[price_cn] => 0
[price_us] => 13.42
)
[1] => Array
(
[purchases] => 6240
[price_cn] => 0
[price_us] => 12.12
)
[2] => Array
(
[purchases] => 624000
[price_cn] => 0
[price_us] => 2.383
)
)
)
*/
type LySkuInfo struct {
SpuId string `json:"spu_id"` //spu_id
Encoded string `json:"encoded"`
Moq int64 `json:"moq"`
Mpq int64 `json:"mpq"`
OldGoodsId int64 `json:"old_goods_id"`
GoodsType int `json:"goods_type"`
GoodsStatus int `json:"goods_status"`
BatchSn string `json:"batch_sn"`
Stock int64 `json:"stock"`
UpdateTime int64 `json:"update_time"`
GoodsImages string `json:"goods_images"`
Canal string `json:"canal"`
SupplierId int64 `json:"supplier_id"`
IsExpire string `json:"is_expire"`
HkDeliveryTime string `json:"hk_delivery_time"`
CnDeliveryTime string `json:"cn_delivery_time"`
LadderPrice []*TierItem `json:"ladder_price"`
}
/*
spu详情
Array
(
[class_id1] => 0
[class_id2] => 0
[class_id3] => 0
[brand_id] => 7087
[spu_name] => SI4704-D50-GM
[status] => 1
[images_l] =>
[encap] =>
[pdf] =>
[spu_brief] =>
[update_time] => 1540893752
)
*/
type LySpuInfo struct {
ClassId1 int64 `json:"class_id1"` //一级分类
ClassId2 int64 `json:"class_id2"` //二级分类
ClassId3 int64 `json:"class_id3"` //三级分类
BrandId int64 `json:"brand_id"` //品牌ID
SpuName string `json:"spu_name"` //型号名称
Status int `json:"status"` // 状态
ImagesL string `json:"images_l"` //图片
Encap string `json:"encap"` //封装
Pdf string `json:"pdf"` //pdf
SpuBrief string `json:"spu_brief"` //描述
UpdateTime int64 `json:"update_time"` //更新时间
}
package common
var KeywordRegular = map[string]string{
//`^(.* )?([\d\.]+)(欧|欧姆|R|r)( .*)?$`: `$1$2Ω$4`,
//`^(.* )?([\d\.]+)(U|u|μ)(.?)( .*)?$`: `$1$2Μ$4$5`,
"COG": "C0G",
"NPO|NP0|nPO|npO|npo|nP0|np0": "C0G",
"华科|华新科技|华新科": "华新",
`(欧姆|欧|O|o|R|r)`: "Ω",
`(Uf|uf|μf|uF|UF)`: "μF",
`(Uh|uh|μh|uH|UH)`: "μH",
`K`: "nF",
`v`: "V",
}
var PureNumberRegular = `(\d+(\.\d+)?)`
var PureLetterRegular = `[a-zA-Z0-9]+`
var GetAttrUnitRegular = `[\d.]|±|\+_|\+-|/|\(.*\)|\+/-|`
//属性单位对应属性
var UnitAttrMapping = map[string]string{
"r": "阻值(欧姆)|直流电阻(内阻)",
"Ω": "阻值(欧姆)|直流电阻(内阻)",
"OHM": "阻值(欧姆)|直流电阻(内阻)",
"mh": "电感",
"F": "容值",
"w": "功率",
"W": "功率",
"Ω/r ": "内阻",
"%": "精度",
"V": "额定电压",
"A": "额定电流",
}
//属性对应的基础属性
var UnitBaseMapping = map[string]string{
"μΩ": "Ω",
"mΩ": "Ω",
"Ω": "Ω",
"kΩ": "Ω",
"KΩ": "Ω",
"MΩ": "Ω",
"pF": "F",
"nF": "F",
"μF": "F",
"μf": "F",
"mF": "F",
"F": "F",
"μH": "H",
"mH": "H",
"H": "H",
"V": "V",
"kV": "V",
"mA": "A",
"A": "A",
"W": "W",
"kW": "W",
"KW": "W",
"%": "%",
}
//根据单位对值的转换,比如1kΩ=>1000Ω
var UnitValueMapping = map[string]string{
"μΩ": "0.000001",
"mΩ": "0.001",
"Ω": "1",
"kΩ": "1000",
"KΩ": "1000",
"MΩ": "1000000",
"pF": "1",
"nF": "1000",
"μF": "1000000",
"mF": "1000000000",
"F": "1000000000000",
"μH": "1",
"mH": "1000",
"H": "1000000",
"V": "1",
"kV": "1000",
"mA": "1",
"A": "1000",
"W": "1",
"kW": "1000",
"%": "0.01",
}
package common
import (
"crypto/hmac"
"crypto/md5"
crand "crypto/rand"
"crypto/sha1"
"encoding/base64"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/syyongx/php2go"
"math/big"
"math/rand"
"reflect"
"regexp"
"goods_machining/middleware"
"goods_machining/pkg/config"
"goods_machining/pkg/vars"
"sort"
"strconv"
"strings"
"time"
)
/*
sha1加密(tme目前在用)
@param string query 查询字符串
@param string pri_key 加密字符串
@return 返回加密后的字符串
*/
func Sha1(query string, pri_key string) string {
key := []byte(pri_key)
mac := hmac.New(sha1.New, key)
mac.Write([]byte(query))
query = base64.StdEncoding.EncodeToString(mac.Sum(nil))
return query
}
/*
输出header
*/
func PrintDebugHeader() {
if middleware.REQUEST["flag"] == "101" {
middleware.Context.Header("Content-Type", "text/html; charset=utf-8")
}
}
/*
格式化数据直接输出浏览器
@parm jsonStr 需要json输出的内容
*/
func PrintDebugHtml(jsonStr interface{}) {
if middleware.REQUEST["flag"] != "101" || jsonStr == "" {
return
}
if v, p := jsonStr.(string); p {
middleware.Context.String(200,"</br></br>-----------"+v)
}else{
jsonData,err := json.Marshal(jsonStr)
if err != nil {
fmt.Println("错误:-----",err)
}
middleware.Context.String(200,"</br></br>-----------"+string(jsonData))
}
}
// Md5 md5()
func Md5(str string) string {
hash := md5.New()
hash.Write([]byte(str))
return hex.EncodeToString(hash.Sum(nil))
}
//非精确匹配,字符串截取向下80%,5个字符以下不截,5-10个截一个,10-20个向下取80%,20个以上向下取70%
func SubKeyWordStr(str string) string {
strLen := len(str)
strLenFloat := float64(strLen)
if strLen < 5 {
return str
}
if strLen >= 5 && strLen <= 10 {
str = php2go.Substr(str, 0, strLen-1)
}
if strLen > 10 && strLen <= 20 {
num := php2go.Floor(strLenFloat * 0.2)
str = php2go.Substr(str, 0, strLen-int(num))
}
if strLen > 20 {
num := php2go.Floor(strLenFloat * 0.3)
str = php2go.Substr(str, 0, strLen-int(num))
}
return str
}
//转成字符串的方法
func ToString(a interface{}) string {
if v, p := a.(int); p {
return strconv.Itoa(v)
}
if v, p := a.(int16); p {
return strconv.Itoa(int(v))
}
if v, p := a.(int32); p {
return strconv.Itoa(int(v))
}
if v, p := a.(uint); p {
return strconv.Itoa(int(v))
}
if v, p := a.(float32); p {
return strconv.FormatFloat(float64(v), 'f', -1, 32)
}
if v, p := a.(float64); p {
return strconv.FormatFloat(v, 'f', -1, 32)
}
return "change to String error"
}
//替换字符串,不区分大小写
func CaseInsensitiveReplace(subject string, search string, replace string) string {
searchRegex := regexp.MustCompile("(?i)" + search)
return searchRegex.ReplaceAllString(subject, replace)
}
/*
md5字符串
*/
func GetKey(s string) string {
return php2go.Md5(strings.ToLower(s))
}
/**
* 获取联营活动价
*/
func lyActivityPrice() {
}
/*构造SPU和SKU的ID
*生成19位纯数组id
*/
func CreateId(types string) string {
var id, db string
if types == "sku" {
id = "1"
db = strconv.Itoa(php2go.Rand(0, 9)) + strconv.Itoa(php2go.Rand(0, 9))
} else {
id = "2"
db = "0" + strconv.Itoa(php2go.Rand(0, 9))
}
s := rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000)
return id + strconv.FormatInt(int64(s), 10) + strconv.FormatInt(php2go.Time(), 10) + db
}
/*
* 反爬虫用html标签替换数字,不包括“.”
* number 数字串
*/
func NumberToHtml(number int) (html string) {
numberToClassSlice := vars.NumberToClass
if number != 0 {
//数字转字符串
numberStr := ToString(number)
for i := 0; i < len(numberStr); i++ {
var classHtml string
numStr := php2go.Substr(numberStr, uint(i), 1)
if php2go.IsNumeric(numStr) {
num, _ := strconv.Atoi(numStr)
index := php2go.Rand(0, 3)
class := numberToClassSlice[num][index]
otherClass := StrRandom(3)
classHtml = `<font class="` + class + otherClass + `"></font>`
}
html = html + classHtml
return
}
}
return
}
/**
* 生成纯小写字母的字符串
* 返回形式如下 : yuiopkdsi rnvewjeil xmiqplmza
*/
func StrRandom(lenNum int) string {
randStr := "sdwpkxmiqplmzacbmeruwulurjlauejrifkfghjklzxcvbnmqwwertyuiopkdsieurnvewjeilweiskvnx"
strLen := len(randStr) - 9
var result string
for i := 0; i < lenNum; i++ {
start := php2go.Rand(0, strLen)
str := php2go.Substr(randStr, uint(start), 9)
result = result + " " + str
}
return result
}
//生成范围区间内的随机数
func Rand(min, max int) int {
n, _ := crand.Int(crand.Reader, big.NewInt(int64(max+1)))
return int(n.Int64()) + min
}
func CopyMapString(distmap map[string]string) map[string]string {
tmpmap := make(map[string]string, 0)
for k, v := range distmap {
tmpmap[k] = v
}
return tmpmap
}
//反爬虫加密验证
func CheckSignApi() (resNo int) {
params := make(map[string]string)
ctx := middleware.Context
if ctx == nil {
return
}
referer := ctx.Request.Referer()
request := make(map[string]string)
ctx.MultipartForm()
for name, value := range ctx.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
if request["hcy_test"] == "1122" {
return 0
}
if request["no_rule"] == "1122" {
return 0
}
if request["check_button"] == "2" || strings.Contains(ctx.Request.Referer(), "liexin.com") {
return 0
}
//如果是内部验证通过,则内部通过
if auth() {
return 0
}
//验证必填参数
if referer == "" {
return 4
}
if ctx.Query("asdfghjkl") != "" {
params = request
}
if ctx.PostForm("asdfghjkl") != "" {
params = request
}
params["Yo4teW_gid"], _ = ctx.Cookie("Yo4teW_gid")
if params["asdfghjkl"] == "" || params["Yo4teW_gid"] == "" || params["qwertyuiop"] == "" {
return 1
}
var temp1 []string
//根据参数,按照规则进行签名生成
for k, v := range params {
if k == "asdfghjkl" || k == "_" || k == "callback" {
continue
}
if v == "" || v == "undefined" || v == "null" || v == "NULL" {
continue
}
if len(v) <= 0 {
continue
}
temp1 = append(temp1, k+"="+v)
}
SortSlice(temp1)
temp2 := strings.Join(temp1, "")
r := regexp.MustCompile(`[^0-9a-zA-Z]`)
temp2 = r.ReplaceAllString(temp2, "")
temp2 = strings.ToUpper(temp2)
r = regexp.MustCompile(`[ABC]`)
temp2 = r.ReplaceAllString(temp2, "")
temp3 := php2go.Sha1(temp2)
//'YO4TEW_GID%3DEFDDE3E06D15F887866E9D96DOM_RNK%3D1GOODS_NME%2FONDITION%3DLM358P%3D1PF%3D1TIME_LIEXIN%3D1545009990450';
//验证签名
if temp3 == params["asdfghjkl"] {
return 0
}
return 3
}
//内部免验证通过
func auth() bool {
ctx := middleware.Context
if ctx == nil {
return false
}
request := make(map[string]string)
ctx.MultipartForm()
for name, value := range ctx.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
k1 := request["k1"]
k1Num, _ := strconv.Atoi(k1)
k2 := request["k2"]
key := config.Get("AUTH.SUPER_AUTH_KEY").String()
if k1 != "" && int64(k1Num) < (time.Now().Unix()-600) {
return false
}
//md5(md5($pwd).$salt);
pwd := Md5(Md5(k1) + key)
if k2 == pwd {
return true
}
return false
}
func CreateAnyTypeSlice(slice interface{}) ([]interface{}, bool) {
val, ok := isSlice(slice)
if !ok {
return nil, false
}
sliceLen := val.Len()
out := make([]interface{}, sliceLen)
for i := 0; i < sliceLen; i++ {
out[i] = val.Index(i).Interface()
}
return out, true
}
// 判断是否为slcie数据
func isSlice(arg interface{}) (val reflect.Value, ok bool) {
val = reflect.ValueOf(arg)
if val.Kind() == reflect.Slice {
ok = true
}
return
}
//向左补充字符串
func StrPadLeft(input string, padLength int, padString string) string {
output := padString
for padLength > len(output) {
output += output
}
if len(input) >= padLength {
return input
}
return output[:padLength-len(input)] + input
}
//移除字符串切片中某個元素
func RemoveSliceString(s []string, i string) []string {
b := make([]string,0)
for _,v:=range s{
if v != i{
b= append(b,v)
}
}
return b
}
//map排序
func MapSort(mapList map[int]int) []int{
var(
keys []int
newList []int
)
newList = make([]int,0)
for _,v:=range mapList{
keys = append(keys,v)
}
sort.Ints(keys)
for _,k:=range keys{
newList = append(newList,mapList[k])
}
return newList
}
////////////类型转换/////////////////////
func MyInt(str string) int {
res,_ := strconv.ParseInt(str,10,64)
return int(res)
}
func MyInt8(str string) int8 {
res,_ := strconv.ParseInt(str,10,64)
return int8(res)
}
func MyInt16(str string) int16 {
res,_ := strconv.ParseInt(str,10,64)
return int16(res)
}
func MyInt64(str string) int64 {
res,_ := strconv.ParseInt(str,10,64)
return int64(res)
}
func MyFloat32(str string) float32 {
res,_ := strconv.ParseFloat(str,64)
return float32(res)
}
func MyFloat64(str string) float64 {
res,_ := strconv.ParseFloat(str,64)
return float64(res)
}
func MyFloat64ToStr(numb float64) string {
return strconv.FormatFloat(numb,'f',6,64)
}
func MyInt64ToStr(numb int64) string {
return strconv.FormatInt(numb,10)
}
////////////类型转换/////////////////////
\ No newline at end of file
package common
import (
"github.com/gomodule/redigo/redis"
"github.com/syyongx/php2go"
"github.com/tidwall/gjson"
"goods_machining/pkg/config"
"goods_machining/pkg/gredis"
"strings"
)
//获取上次查询时间等信息
func GetLastSearchTime(goodsId string) (timeStamp int) {
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
key := config.Get("redis_all.SEARCH_SHOW_SKU_TIME").String()
timeStamp, err := redis.Int(redisCon.Do("HGET", key, goodsId))
if err != nil {
timeStamp = 0
}
return
}
//获取关税信息
func GetCustomsTax(goodsName, brandName string) (tax string) {
if goodsName == "" || brandName == "" {
return
}
redisCon := gredis.Conn("search_r")
defer redisCon.Close()
member := php2go.Md5(strings.ToUpper(goodsName + brandName))
key := config.Get("redis_all.TAX_CUSTOMS_INFO")
res, _ := redis.String(redisCon.Do("HGET", key, member))
taxRateRow := gjson.Get(res, "tax_rate_low").Float()
if res == "" || taxRateRow <= 0 {
return
}
return ToString(taxRateRow) + "%"
}
package common
import (
"encoding/json"
"github.com/gomodule/redigo/redis"
"github.com/ichunt2019/logger"
log "github.com/sirupsen/logrus"
"os"
"goods_machining/middleware"
"goods_machining/pkg/config"
"goods_machining/pkg/gredis"
"goods_machining/pkg/message"
"strconv"
"strings"
"time"
)
type SearchApiLog struct {
Msg string `json:"msg"`
MsgCode string `json:"msgCode"`
Ts int64 `json:"ts"`
DateStr string `json:"dateStr"`
App string `json:"app"`
ServerIp string `json:"serverIp"`
FileName string `json:"fileName"`
LineNo string `json:"lineNo"`
Method string `json:"method"`
}
func AnalyzeSearchError(code int, ip, errMsg, file, line, method string) (log SearchApiLog) {
//获取所有参数
request := make(map[string]string)
ctx := middleware.Context
ctx.MultipartForm()
for name, value := range ctx.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
requestByte, _ := json.Marshal(request)
log.Msg = errMsg + string(requestByte)
codeStr := strconv.Itoa(code)
log.MsgCode = StrPadLeft(codeStr, 6, "0")
log.Ts = time.Now().Unix()
log.DateStr = time.Now().Format("2006-01-02 15:04:05")
log.App = "search_api"
log.ServerIp = ip
log.FileName = file
log.LineNo = line
log.Method = method
//还要判断是否要推送消息
unitSupplierLogCode := config.Cfg.Section("UNIT_SUPPLIER_LOG_CODE").KeysHash()
if unitSupplierLogCode[codeStr] == "" {
if !strings.Contains(strings.ToUpper(errMsg), "SOAP-ERROR") {
//推送到钉钉
result, err := message.DingDingPush(errMsg)
if err != nil || result.Errcode != 0 {
logger.Error("%s", err, result)
}
}
} else {
redisCon := gredis.Conn("search_w")
defer redisCon.Close()
key := config.Get("SEARCH_API_LOG.SEARCH_API_ERROR_PRE").String() + unitSupplierLogCode[codeStr]
_, err := redis.Bool(redisCon.Do("INCR", key))
if err != nil {
logger.Error("%s", err)
}
}
return
}
type LogFormatter struct{}
//格式详情
func (s *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
msg := entry.Message + "\n"
return []byte(msg), nil
}
//写入到特定的文件夹给ELK使用的日志
func WriteSearchErrorLog(searchLog string) {
// 设置日志格式为json格式
log.SetFormatter(new(LogFormatter))
path := "../logs/search/"
//设置output,默认为stderr,可以为任何io.Writer,比如文件*os.File
//生成当天的日志
filePath := path + time.Now().Format("20060102") + ".log"
file, _ := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
log.SetOutput(file)
log.Error(searchLog)
}
package common
import "math"
//分页方法,根据传递过来的页数,每页数,总数,返回分页的内容 7个页数 前 1,2,3,4,5 后 的格式返回,小于5页返回具体页数
func Paginator(page, prepage int, nums int64) map[string]interface{} {
var firstpage int //前一页地址
var lastpage int //后一页地址
//根据nums总数,和prepage每页数量 生成分页总数
totalpages := int(math.Ceil(float64(nums) / float64(prepage))) //page总数
if page > totalpages {
page = totalpages
}
if page <= 0 {
page = 1
}
var pages []int
switch {
case page >= totalpages-5 && totalpages > 5: //最后5页
start := totalpages - 5 + 1
firstpage = page - 1
lastpage = int(math.Min(float64(totalpages), float64(page+1)))
pages = make([]int, 5)
for i, _ := range pages {
pages[i] = start + i
}
case page >= 3 && totalpages > 5:
start := page - 3 + 1
pages = make([]int, 5)
firstpage = page - 3
for i, _ := range pages {
pages[i] = start + i
}
firstpage = page - 1
lastpage = page + 1
default:
pages = make([]int, int(math.Min(5, float64(totalpages))))
for i, _ := range pages {
pages[i] = i + 1
}
firstpage = int(math.Max(float64(1), float64(page-1)))
lastpage = page + 1
//fmt.Println(pages)
}
paginatorMap := make(map[string]interface{})
paginatorMap["pages"] = pages
paginatorMap["totalpages"] = totalpages
paginatorMap["firstpage"] = firstpage
paginatorMap["lastpage"] = lastpage
paginatorMap["currpage"] = page
return paginatorMap
}
\ No newline at end of file
package common
import (
"github.com/gin-gonic/gin"
"strings"
)
type RecommendRequest struct {
GoodsName string `form:"goods_name"`
Attrs string `form:"attrs"`
Encap string `form:"encap"`
Num int `form:"num"`
DeliveryType int `form:"delivery_type"`
Flag int `form:"flag"`
BrandName string `form:"brand_name"`
}
//获取所有请求参数放到字典里面
func GetAllRequestParams(c *gin.Context) (request map[string]string){
request = make(map[string]string)
c.MultipartForm()
for name, value := range c.Request.Form {
if value[0] != "" {
request[name] = strings.TrimSpace(value[0])
}
}
return
}
package common
import (
"encoding/json"
"runtime"
"goods_machining/middleware"
"strconv"
"strings"
)
type Response struct {
ErrCode int `json:"error_code"`
ErrMsg string `json:"err_msg"`
Data interface{} `json:"data"`
}
type BomResponse struct {
ErrCode int `json:"error_code"`
ErrMsg string `json:"error_msg"`
Flag int `json:"flag"`
Total int `json:"total"`
Data interface{} `json:"data"`
}
func SuccessResponse(errCode int, errMsg string, data interface{}) Response {
return Response{
ErrCode: errCode,
ErrMsg: errMsg,
Data: data,
}
}
func ErrorResponse(errCode int, errMsg string) Response {
return Response{
ErrCode: errCode,
ErrMsg: errMsg,
Data: []string{},
}
}
//统一输出,里面还要去处理jsonp
func Output(errCode int, errMsg string, data interface{}) {
if data == nil {
data = []string{}
}
response := Response{
ErrCode: errCode,
ErrMsg: errMsg,
Data: data,
}
if errCode >= 100 {
SearchApiLogger(errCode, errMsg)
}
ctx := middleware.Context
if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response)
} else {
referer := ctx.Request.Referer()
referer = strings.TrimRight(referer, "/")
ctx.Header("Access-Control-Allow-Origin", referer)
ctx.Header("Access-Control-Allow-Credentials", "true")
//允许跨站访问的站点域名
//跨域请求头设置
ctx.JSON(200, response)
}
}
//简单的返回数据方法
func ReturnData(errCode int, errMsg string, data interface{}) {
if data == nil {
data = []string{}
if errCode == 0 {
errCode = 1
}
}
response := Response{
ErrCode: errCode,
ErrMsg: errMsg,
Data: data,
}
ctx := middleware.Context
ctx.JSON(200, response)
}
//错误的搜索日志记录
func SearchApiLogger(code int, msg string) {
pc, file, line, _ := runtime.Caller(2)
f := runtime.FuncForPC(pc)
ctx := middleware.Context
errMsg := "提示信息:" + msg + ",请求url:" + ctx.Request.URL.String()
lineNo := strconv.Itoa(line)
searchLog := AnalyzeSearchError(code, ctx.ClientIP(), errMsg, file, lineNo, f.Name())
searchLogByte, _ := json.Marshal(searchLog)
WriteSearchErrorLog(string(searchLogByte))
}
package common
import (
"reflect"
"sort"
)
func getCommon(array interface{}) (reflect.Type, reflect.Value, int) {
t := reflect.TypeOf(array)
v := reflect.ValueOf(array)
l := v.Len()
return t, v, l
}
func SortSlice(array interface{}) {
t, v, _ := getCommon(array)
// res := make([]interface{}, l)
if t.Kind() == reflect.Slice {
switch v.Index(0).Kind() {
case reflect.Int:
array := array.([]int)
sort.Ints(array)
case reflect.String:
array := array.([]string)
sort.Strings(array)
case reflect.Float64:
array := array.([]float64)
sort.Float64s(array)
default:
panic("the param can only be int/string/float64 array")
}
} else {
panic("expects parameter 1 to be array")
}
}
package common
//与supplier相关的变量
var SearchSupplier = map[int]string{
1: "uture",
//2:"powerandsignal",
3: "rochester",
4: "tme",
5: "verical",
6: "element14",
7: "digikey",
8: "chip1stop",
9: "aipco",
10: "arrow",
//11:"bisco",
12: "alliedelec",
13: "avnet",
14: "mouser",
//15:"company",
//16:"liexin_lianying1"
17: "zhuanmai",
//18:"liexin_ti",
19: "peigenesis",
20: "powell",
21: "rs",
//22:"liexin_sell",
//100:"ziying",
//101:"liexin_jingdiao",
1676: "buerklin",
}
package config
import (
"github.com/go-ini/ini"
"strings"
)
var (
Cfg *ini.File
)
func SetUp(path string) (err error) {
//引入多个文件
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", path+"/message.ini")
return
}
func Get(key string) *ini.Key {
if strings.Contains(key, ".") {
keys := strings.Split(key, ".")
return Cfg.Section(keys[0]).Key(keys[1])
}
return Cfg.Section("").Key(key)
}
func GetSectionValues(key string) (result []string) {
values := Cfg.Section(key).Keys()
for _, value := range values {
result = append(result, value.String())
}
return result
}
package config
type MongoDbDatabase struct {
Host string
UserName string
Password string
Database string
MaxPoolSize string
}
func BuildMongoDbConfgs () map[string]MongoDbDatabase{
return map[string]MongoDbDatabase{
"default" : {
Host:Get("mongo.host").String(),
UserName:Get("mongo.username").String(),
Password:Get("mongo.password").String(),
Database:Get("mongo.database").String(),
MaxPoolSize:Get("mongo.maxPoolSize").String(),
},
}
}
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{
"spu": {
UserName: Get("spu.user_name").String(),
Password: Get("spu.password").String(),
Host: Get("spu.host").String(),
Database: Get("spu.database").String(),
Prefix: Get("spu.table_prefix").String(),
},
"supp": {
UserName: Get("supp.user_name").String(),
Password: Get("supp.password").String(),
Host: Get("supp.host").String(),
Database: Get("supp.database").String(),
Prefix: Get("supp.table_prefix").String(),
},
"cms": {
UserName: Get("cms.user_name").String(),
Password: Get("cms.password").String(),
Host: Get("cms.host").String(),
Database: Get("cms.database").String(),
Prefix: Get("cms.table_prefix").String(),
},
"liexin_data": {
UserName: Get("liexin_data.user_name").String(),
Password: Get("liexin_data.password").String(),
Host: Get("liexin_data.host").String(),
Database: Get("liexin_data.database").String(),
Prefix: Get("liexin_data.table_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_r": {
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_w": {
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_redis": {
Host: Get("api_redis.host").String(),
Password: Get("api_redis.password").String(),
MaxIdle: Get("api_redis.max_idle").String(),
MaxActive: Get("api_redis.max_active").String(),
},
}
}
package e
type FatalError struct {
ErrMsg string
}
func (err *FatalError) Error() string {
return err.ErrMsg
}
func NewFatalError( msg string) *FatalError {
return &FatalError{ ErrMsg: msg}
}
func IsFatalError(err error) bool {
if _,ok:=err.(*FatalError);ok{
return true
}
return false
}
\ No newline at end of file
package es
import (
"github.com/imroc/req"
"math/rand"
"net/http"
"goods_machining/pkg/config"
)
type Response struct {
Took int `json:"took"`
TimeOut bool `json:"time_out"`
Shard map[string]int `json:"_shard"`
HitsResult HitsResult `json:"hits"`
}
type HitsResult struct {
Total int `json:"total"`
MaxScore float64 `json:"max_score"`
Hits string `json:"hits"`
}
func CurlES(index string, param string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(param)
resp, err := req.Get(esUrl+"/"+index+"/_search", params)
if err != nil {
return
}
result = resp.String()
return
}
/*
主分片查询
*/
func CurlEsPrimary(index string, param string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(param)
resp, err := req.Get(esUrl+"/"+index+"/_search?preference=_primary_first", params)
if err != nil {
return
}
result = resp.String()
return
}
/*
批量插入 或者 更新 es
POST /_bulk
{ "index":{"_index":"hcy1","_type":"goods","_id":"333333"} }
{ "name":"john doe","age":25 }
{ "index":{"_index":"hcy1","_type":"goods","_id":"6666"} }
{ "name":"mary smith","age":32 }
eg:
方法一:
param := `{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`+"\n"+`{"name":"john doe","age":25 }`+"\n"+`{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`+"\n"+`{"name":"john doe","age":25 }`+"\n"
result,err := es.BulkES(param)
println(result,err)
方法二:
lines := []string{
`{"index":{"_index":"hcy1","_type":"goods","_id":"s1"} }`,
`{"name":"john doe","age":25 }`,
`{"index":{"_index":"hcy1","_type":"goods","_id":"s2"} }`,
`{"name":"mary smith","age":32 }`,
}
param := strings.Join(lines, "\n")+"\n"
*/
func BulkES(param string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
esUrl := endpoints[rand.Intn(len(endpoints))] //随机获取一个节点进行请求
//params := req.BodyJSON(param)
//req.Debug = true
header := make(http.Header)
header.Set("Content-Type", "application/x-ndjson")
resp, err := req.Post(esUrl+"/_bulk?refresh=true", header, param) //refresh=true 立刻插入或修改 立刻生效,不需要等待es缓存写入文档
if err != nil {
return
}
result = resp.String()
return
}
//多条件多索引查询,需要查询的索引和条件自己拼接成queryJson里面
func CurlESMSearch(queryJson string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
req.Debug = false
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(queryJson)
resp, err := req.Post(esUrl+"/_msearch", params)
if err != nil {
return
}
result = resp.String()
return
}
//滚动搜索和索引之间的文档重索引
func ScrollES(param string) (result string, err error) {
endpoints := config.Get("es.urls").Strings(",")
//随机获取一个节点进行请求
req.Debug = false
esUrl := endpoints[rand.Intn(len(endpoints))]
params := req.BodyJSON(param)
resp, err := req.Post(esUrl+"/_search/scroll", params)
if err != nil {
return
}
result = resp.String()
return
}
package gredis
import (
"fmt"
"github.com/gomodule/redigo/redis"
"goods_machining/pkg/config"
"time"
)
type ichuntRedis struct {
RedisList map[string]*redis.Pool
}
var ichuntRedis_ = &ichuntRedis{}
func Conn(connection string) (redis.Conn){
return ichuntRedis_.RedisList[connection].Get()
}
var writeConn, readConn *redis.Pool
func Setup() (err error) {
ichuntRedis_.RedisList = make(map[string]*redis.Pool,0)
RedisDatabaseMap := config.BuildRedisConfgs()
for redisKey,redisConfig := range RedisDatabaseMap{
ichuntRedis_.RedisList[redisKey],err = getConn(redisConfig.Host, redisConfig.Password)
if err != nil{
panic(err)
}
}
return nil
}
//格式化成字符串
func String( a interface{},err error) (string,error) {
return redis.String(a,err)
}
func getConn(writeHost, password string) (pool *redis.Pool, err error) {
maxIdle, _ := config.Get("redis.max_idle").Int()
maxActive, _ := config.Get("redis.max_active").Int()
pool = &redis.Pool{
MaxIdle: maxIdle,
MaxActive: maxActive,
Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", writeHost)
if err != nil {
return nil, err
}
if password != "" {
if _, err := c.Do("AUTH", password); err != nil {
c.Close()
return nil, err
}
}
return c, err
},
TestOnBorrow: func(c redis.Conn, t time.Time) error {
_, err := c.Do("PING")
return err
},
}
return
}
/*
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
@param targetIds string 查询的id 切片
eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
func HgetPi(redisConn *redis.Conn,hkey string,targetIds []string) map[string]string {
skuArr := make(map[string]string,0)
if len(targetIds) == 1 {
oneId := targetIds[0]
info,_ := String((*redisConn).Do("HGET",hkey,oneId))
if info == "" {
skuArr[oneId] = ""
}else{
skuArr[oneId] = info
}
fmt.Print("单个获取")
return skuArr
}
for _,v := range targetIds{
(*redisConn).Send("HGet",hkey,v)
}
(*redisConn).Flush()
for _,goods_id := range targetIds{
info,_ := (*redisConn).Receive()
if info == nil{
skuArr[goods_id] = ""
continue;
}
oneInfo := string(info.([]byte))
skuArr[goods_id] = oneInfo
}
return skuArr
}
package logger
import (
"github.com/ichunt2019/logger"
)
func SetUp() (err error) {
logConfig := make(map[string]string)
logConfig["log_path"] = "logs"
logConfig["log_chan_size"] = "5"
err = logger.InitLogger("file", logConfig)
if err != nil {
return err
}
logger.Init()
return
}
package logger
import (
"io"
"os"
"time"
"strings"
)
func check(e error) {
if e != nil {
panic(e)
}
}
/**
* 判断文件是否存在 存在返回 true 不存在返回false
*/
func checkFileIsExist(filename string) bool {
var exist = true
if _, err := os.Stat(filename); os.IsNotExist(err) {
exist = false
}
return exist
}
/*
@param writeString 写入文件字符串
@param file_pre 附加文件前缀
eg: logic.Loginfo("逾期统计开始","_yuqilv_");
*/
func Log(writeString string,log_file_pre string) {
log_file_pre = "_"+log_file_pre
date := time.Now().Format("2006-01-02")
date2 := time.Now().Format("2006-01-02 15:04:05")
var filename = "./logs/"+date+log_file_pre+".txt"
var f *os.File
var err1 error
if checkFileIsExist(filename) { //如果文件存在
f, err1 = os.OpenFile(filename, os.O_APPEND, 0666) //打开文件
} else {
f, err1 = os.Create(filename) //创建文件
}
check(err1)
ss := StrReplace("\r\n","",writeString,1) //替换多余换行
io.WriteString(f,"\r\n"+date2+"----"+ss) //写入文件(字符串)
//fmt.Print(err)
}
// StrReplace str_replace()
func StrReplace(search, replace, subject string, count int) string {
return strings.Replace(subject, search, replace, count)
}
package message
import (
"encoding/json"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"goods_machining/pkg/config"
"strings"
)
//发送钉钉消息的包
type DingDingRequest struct {
MsgType string `json:"msgtype"`
Text map[string]string `json:"text"`
IsAtAll bool `json:"isAtAll"`
}
type DingDingResponse struct {
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
}
func DingDingPush(content string) (result DingDingResponse, err error) {
accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String()
webhook := "https://oapi.dingtalk.com/robot/send?access_token=" + accessToken
data := make(map[string]interface{})
data["msgtype"] = "text"
data["text"] = map[string]string{
"content": content,
}
req.Debug = false
dataStrByte, _ := json.Marshal(data)
dataStr := string(dataStrByte)
dataStr = strings.Replace(dataStr, "\\", "\\\\", -1)
params := req.BodyJSON(dataStr)
resp, err := req.Post(webhook, params, req.Header{
"Content-Type": "application/json",
"charset": "UTF-8",
})
if resp == nil {
return
}
result.Errcode = int(gjson.Get(resp.String(), "errcode").Int())
result.Errmsg = gjson.Get(resp.String(), "errmsg").String()
return
}
package message
import (
"encoding/json"
"fmt"
"github.com/syyongx/php2go"
"net/http"
"net/url"
"goods_machining/pkg/config"
"strconv"
"time"
)
//普通发短信
func SendMessage(mobile int64, keyWord string, content map[string]interface{}) {
//es连接告警的keyword是 es_connect_monitor
if mobile != 0 {
timeNow := time.Now().Unix()
requestContent, _ := json.Marshal(content)
requestTel, _ := json.Marshal([]int64{mobile})
apiDomain := config.Get("message.api_domain").String()
apiMd5Str := config.Get("message.api_md5_str").String()
resp, err := http.PostForm(apiDomain, url.Values{
"data": {string(requestContent)},
"touser": {string(requestTel)},
"keyword": {keyWord},
"k1": {strconv.FormatInt(timeNow, 10)},
"k2": {php2go.Md5(php2go.Md5(strconv.FormatInt(timeNow, 10)) + apiMd5Str)},
"is_ignore": {},
})
if err != nil {
fmt.Print(err)
}
defer resp.Body.Close()
}
}
package mongo
import (
"fmt"
"gopkg.in/mgo.v2"
"goods_machining/pkg/config"
"strconv"
)
var session *mgo.Session
type ichuntMongo struct {
MongoList map[string]*mgo.Session
}
var ichuntMongo_ = &ichuntMongo{}
func getconn(mongoConfig config.MongoDbDatabase) (*mgo.Session ,error){
url := mongoConfig.Host
maxPoolSize := mongoConfig.MaxPoolSize
maxPoolSizeInt,err := strconv.Atoi(maxPoolSize)
if err != nil{
maxPoolSizeInt = 100
}
url += "?maxPoolSize="+maxPoolSize
session, err = mgo.Dial(url)
if err != nil {
return nil ,err
}
fmt.Println("url",url)
fmt.Println("maxPoolSizeInt",maxPoolSizeInt)
session.SetPoolLimit(maxPoolSizeInt)
session.SetMode(mgo.Monotonic, true)
myDB :=session.DB(mongoConfig.Database)
err = myDB.Login(mongoConfig.UserName,mongoConfig.Password)
if err != nil {
return nil ,err
}
return session,nil
}
func SetUp() (err error) {
err = nil
ichuntMongo_.MongoList = make(map[string]*mgo.Session,0)
mongodbList := config.BuildMongoDbConfgs()
if len(mongodbList) > 0{
for mongoName,mongoConfig := range mongodbList{
ichuntMongo_.MongoList[mongoName],err = getconn(mongoConfig)
if err != nil{
break
}
}
}
return err
}
func Conn(connection string) (*mgo.Session){
return ichuntMongo_.MongoList[connection].Copy()
}
package mq
import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"goods_machining/pkg/config"
)
func PushMsg(listName string, data string) {
queueExchange := rabbitmq.QueueExchange{
listName,
listName,
"",
"direct",
config.Get("rabmq.url").String(),
}
rabbitmq.Send(queueExchange, data)
}
package mysql
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"goods_machining/pkg/config"
"goods_machining/pkg/e"
)
var DatabaseConMap map[string]*xorm.Engine
func Setup() error {
DatabaseConMap = make(map[string]*xorm.Engine, 0)
DatabaseList := config.BuildDatabaseList()
var err error
//循环生成数据库链接
for conName, db := range DatabaseList {
userName := db.UserName
password := db.Password
host := db.Host
database := db.Database
dataSourceName := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", userName, password, host, database)
DatabaseConMap[conName], err = xorm.NewEngine("mysql", dataSourceName)
if err != nil {
return e.NewFatalError(err.Error()) //这里返回致命异常
}
//日志打印SQL
DatabaseConMap[conName].ShowSQL(true)
//设置连接池的空闲数大小
DatabaseConMap[conName].SetMaxIdleConns(db.MaxIdleCons)
//设置最大打开连接数
DatabaseConMap[conName].SetMaxOpenConns(db.MaxOpenCons)
}
return nil
}
func Conn(conName string) *xorm.Engine {
return DatabaseConMap[conName]
}
package vars
const (
Table_CourseMain="course_main"
Table_CourseCounts="course_counts"
)
package vars
//数字转class字符串,按顺序0-9
var NumberToClass = [][]string{
{"sfgdqwer", "asfgdtyhg", "asfgdpolk", "asfgdpoqw"},
{"sfgdrfdf","asfgderfd","asfgdwdsa","asfgdpoer"},
{"asfgdasde","asfgdqwsz","asfgdrtgd","asfgdpovv"},
{"asfgdwsxc","asfgdwsxz","asfgdrfvb","asfgdpoee"},
{"asfgdqazs","asfgdqasd","asfgdqwag","asfgdpogh"},
{"asfgdrtyh","asfgdyutr","asfgdeews","asfgdpotg"},
{"asfgdpluj","asfgdikjf","asfgdesgj","asfgdpfff"},
{"asfgdtrdb","asfgdiksf","asfgdsgkp","asfgdprty"},
{"asfgdpehl","asfgdstgb","asfgderll","asfgdpokf"},
{"asfgdpehg","asfgdstgf","asfgderlf","asfgdpogk"},
}
// Code generated by protoc-gen-micro. DO NOT EDIT.
// source: bom.proto
package bom
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
math "math"
)
import (
context "context"
api "github.com/micro/go-micro/v2/api"
client "github.com/micro/go-micro/v2/client"
server "github.com/micro/go-micro/v2/server"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
// Reference imports to suppress errors if they are not otherwise used.
var _ api.Endpoint
var _ context.Context
var _ client.Option
var _ server.Option
// Api Endpoints for BomService service
func NewBomServiceEndpoints() []*api.Endpoint {
return []*api.Endpoint{}
}
// Client API for BomService service
type BomService interface {
AutoSpu(ctx context.Context, in *AutoSpuRequest, opts ...client.CallOption) (*AutoSpuResponse, error)
}
type bomService struct {
c client.Client
name string
}
func NewBomService(name string, c client.Client) BomService {
return &bomService{
c: c,
name: name,
}
}
func (c *bomService) AutoSpu(ctx context.Context, in *AutoSpuRequest, opts ...client.CallOption) (*AutoSpuResponse, error) {
req := c.c.NewRequest(c.name, "BomService.AutoSpu", in)
out := new(AutoSpuResponse)
err := c.c.Call(ctx, req, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// Server API for BomService service
type BomServiceHandler interface {
AutoSpu(context.Context, *AutoSpuRequest, *AutoSpuResponse) error
}
func RegisterBomServiceHandler(s server.Server, hdlr BomServiceHandler, opts ...server.HandlerOption) error {
type bomService interface {
AutoSpu(ctx context.Context, in *AutoSpuRequest, out *AutoSpuResponse) error
}
type BomService struct {
bomService
}
h := &bomServiceHandler{hdlr}
return s.Handle(s.NewHandler(&BomService{h}, opts...))
}
type bomServiceHandler struct {
BomServiceHandler
}
func (h *bomServiceHandler) AutoSpu(ctx context.Context, in *AutoSpuRequest, out *AutoSpuResponse) error {
return h.BomServiceHandler.AutoSpu(ctx, in, out)
}
// Code generated by protoc-gen-go. DO NOT EDIT.
// source: common.proto
package common
import (
fmt "fmt"
proto "github.com/golang/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
math "math"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Timestamp struct {
Timestamp *timestamp.Timestamp `protobuf:"bytes,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Timestr string `protobuf:"bytes,2,opt,name=timestr,proto3" json:"timestr,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Timestamp) Reset() { *m = Timestamp{} }
func (m *Timestamp) String() string { return proto.CompactTextString(m) }
func (*Timestamp) ProtoMessage() {}
func (*Timestamp) Descriptor() ([]byte, []int) {
return fileDescriptor_555bd8c177793206, []int{0}
}
func (m *Timestamp) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_Timestamp.Unmarshal(m, b)
}
func (m *Timestamp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_Timestamp.Marshal(b, m, deterministic)
}
func (m *Timestamp) XXX_Merge(src proto.Message) {
xxx_messageInfo_Timestamp.Merge(m, src)
}
func (m *Timestamp) XXX_Size() int {
return xxx_messageInfo_Timestamp.Size(m)
}
func (m *Timestamp) XXX_DiscardUnknown() {
xxx_messageInfo_Timestamp.DiscardUnknown(m)
}
var xxx_messageInfo_Timestamp proto.InternalMessageInfo
func (m *Timestamp) GetTimestamp() *timestamp.Timestamp {
if m != nil {
return m.Timestamp
}
return nil
}
func (m *Timestamp) GetTimestr() string {
if m != nil {
return m.Timestr
}
return ""
}
func init() {
proto.RegisterType((*Timestamp)(nil), "common.Timestamp")
}
func init() { proto.RegisterFile("common.proto", fileDescriptor_555bd8c177793206) }
var fileDescriptor_555bd8c177793206 = []byte{
// 121 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x49, 0xce, 0xcf, 0xcd,
0xcd, 0xcf, 0xd3, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x83, 0xf0, 0xa4, 0xe4, 0xd3, 0xf3,
0xf3, 0xd3, 0x73, 0x52, 0xf5, 0xc1, 0xa2, 0x49, 0xa5, 0x69, 0xfa, 0x25, 0x99, 0xb9, 0xa9, 0xc5,
0x25, 0x89, 0xb9, 0x05, 0x10, 0x85, 0x4a, 0xf1, 0x5c, 0x9c, 0x21, 0x30, 0x21, 0x21, 0x0b, 0x2e,
0x4e, 0xb8, 0xbc, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, 0x94, 0x1e, 0xc4, 0x04, 0x3d, 0x98,
0x09, 0x7a, 0x70, 0xe5, 0x41, 0x08, 0xc5, 0x42, 0x12, 0x5c, 0xec, 0x10, 0x4e, 0x91, 0x04, 0x93,
0x02, 0xa3, 0x06, 0x67, 0x10, 0x8c, 0x9b, 0xc4, 0x06, 0xd6, 0x68, 0x0c, 0x08, 0x00, 0x00, 0xff,
0xff, 0x1b, 0x45, 0x2b, 0x0e, 0xa0, 0x00, 0x00, 0x00,
}
This diff is collapsed. Click to expand it.
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