Commit a5235e60 by mushishixian

sku模式统计

parent 7babdd53
...@@ -31,5 +31,15 @@ func BuildRedisGroupConfigs() ( map[string]RedisGroupDatabase) { ...@@ -31,5 +31,15 @@ func BuildRedisGroupConfigs() ( map[string]RedisGroupDatabase) {
WriteTimeout: time.Duration(lib.Instance("redis").GetInt("api.write_timeout"))*time.Second, WriteTimeout: time.Duration(lib.Instance("redis").GetInt("api.write_timeout"))*time.Second,
MinIdleConns:lib.Instance("redis").GetInt("api.min_idle_conns"), MinIdleConns:lib.Instance("redis").GetInt("api.min_idle_conns"),
}, },
"sku": {
MasterHost: lib.Instance("redis").GetString("sku.master.host"),
Password:lib.Instance("redis").GetString("sku.master.password"),
SlaveHost: lib.Instance("redis").GetStringSlice("sku.slave.host"),
ReadonlyPassword:lib.Instance("redis").GetString("sku.slave.password"),
DialTimeout: time.Duration(lib.Instance("redis").GetInt("sku.dial_timeout"))*time.Second,
ReadTimeout: time.Duration(lib.Instance("redis").GetInt("sku.read_timeout"))*time.Second,
WriteTimeout: time.Duration(lib.Instance("redis").GetInt("sku.write_timeout"))*time.Second,
MinIdleConns:lib.Instance("redis").GetInt("sku.min_idle_conns"),
},
} }
} }
...@@ -61,3 +61,23 @@ func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) { ...@@ -61,3 +61,23 @@ func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) {
} }
return return
} }
//修改sku_mode
func UpdateSupplierSkuMode(supplierId, skuMode int) (err error) {
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).Get(supplier)
if supplier.SupplierId == 0 {
return err
}
if err != nil {
return err
}
supplier.SkuMode = skuMode
//还要去写映射表lie_supplier_merger_mapping
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).Update(supplier)
if err != nil {
return err
}
return
}
...@@ -5,4 +5,5 @@ type Supplier struct { ...@@ -5,4 +5,5 @@ type Supplier struct {
SupplierCode string SupplierCode string
SupplierName string SupplierName string
SkuNum int SkuNum int
SkuMode int
} }
package service
import (
"fmt"
"github.com/ichunt2019/cfg/lib"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"go_supplier_sever/app/dao"
"go_supplier_sever/app/model"
"time"
)
//从ES统计出sku类型,然后写到供应商的sku_mode字段
func SaveSkuModeFromES() (err error) {
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
rows, err := dao.Dao.GetDb("supplier").Table("lie_supplier_channel").Where("is_type = ?", 0).OrderBy("supplier_id desc").Rows(supplier)
if err != nil {
return err
}
defer rows.Close()
for rows.Next() {
err = rows.Scan(supplier)
//去es查询sku数量
params := req.Param{
"status/condition": 1,
"canal/condition": supplier.SupplierCode,
}
url := lib.Instance("config").GetString("es.es_sku_url")
resp, err := req.Post(url, params)
if err != nil {
return err
}
result := resp.String()
goodsIdArr := gjson.Get(result, "data.goods_id").Array()
if len(goodsIdArr) > 0 {
//取一个goods_id就好
goodsId := goodsIdArr[0].String()
//去redis里面找出对应的goods_label
redisCon := dao.Dao.GetRedisDbGroup("sku")
result := redisCon.HGet("goods_tag", goodsId).String()
goodsLabel := gjson.Get(result, "goods_label").Int()
if int(goodsLabel) != 0 {
//fmt.Println(supplier.SupplierId, goodsLabel)
err = dao.UpdateSupplierSkuMode(supplier.SupplierId, int(goodsLabel))
if err != nil {
return err
}
}
}
time.Sleep(100 * time.Millisecond)
}
fmt.Println("执行完成")
return
}
package main
import (
"flag"
"fmt"
"go_supplier_sever/app/service"
"go_supplier_sever/boot"
)
var (
configPath string
logPath string
)
func main() {
flag.StringVar(&configPath, "config", "./config/dev/", "配置文件")
flag.StringVar(&logPath, "logdir", "./logs/", "日志文件存储目录")
flag.Parse()
boot.Init(configPath, logPath)
err := service.SaveSkuModeFromES()
if err != nil {
fmt.Println(err)
}
}
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
url = "amqp://guest:guest@192.168.1.252:5672/" url = "amqp://guest:guest@192.168.1.252:5672/"
[es] [es]
es_sku_url = "http://soso12.ichunt.com/search/Es/searchSku" es_sku_url = "http://soso12.liexin.com/search/Es/searchSku"
\ No newline at end of file \ No newline at end of file
...@@ -12,3 +12,17 @@ ...@@ -12,3 +12,17 @@
"192.168.1.235:6379", "192.168.1.235:6379",
"192.168.1.237:6379", "192.168.1.237:6379",
] ]
[sku]
dial_timeout = 20
min_idle_conns = 10
read_timeout = 10
write_timeout = 10
[sku.master]
host = "192.168.1.235:6379"
password = "icDb29mLy2s"
[sku.slave]
password = "icDb29mLy2s"
host = [
"192.168.1.235:6379",
"192.168.1.237:6379",
]
\ No newline at end of file
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