Commit 3dbcbe39 by mushishixian

sku统计

parent 6b1436d0
package dao
import (
"github.com/ichunt2019/cfg/lib"
"github.com/imroc/req"
"github.com/tidwall/gjson"
"go_supplier_sever/app/model"
)
func StatisticsSuppliersSkuNum() (err error) {
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
rows, err := 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()
skuNum := gjson.Get(result, "data.total").Int()
if skuNum == 0 {
continue
}
err = UpdateSupplierSkuNum(supplier.SupplierId, int(skuNum))
if err != nil {
return err
}
}
return
}
//添加erp同步记录
func UpdateSupplierSkuNum(supplierId, skuNum 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.SkuNum = skuNum
//还要去写映射表lie_supplier_merger_mapping
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).Update(supplier)
if err != nil {
return err
}
return
}
......@@ -4,4 +4,5 @@ type Supplier struct {
SupplierId int
SupplierCode string
SupplierName string
SkuNum int
}
package service
import "go_supplier_sever/app/dao"
func StatisticsSupplierSkuNum() (err error) {
//先找出所有需要判断的供应商
return dao.StatisticsSuppliersSkuNum()
}
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.StatisticsSupplierSkuNum()
if err != nil {
fmt.Println(err)
}
}
title = "TOML 例子"
viewpath = "/home/www/templates/"
[owner]
name = "Tom Preston-Werner"
organization = "GitHub"
bio = "GitHub Cofounder & CEO\nLikes tater tots and beer."
dob = 1979-05-27T07:32:00Z # 日期时间是一等公民。为什么不呢?
[servers]
# 你可以依照你的意愿缩进。使用空格或Tab。TOML不会在意。
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[clients]
data = [["gamma", "delta"],[1, 2]]
[database]
[database.default]
host = "192.168.2.232"
[supplier_no_brand]
3 = [615,757,46596,43172,52,46481,47811,48817]
7 = [47778]
9 = [47778,4589,12369]
[rabbit_mq_default]
url = "amqp://guest:guest@192.168.2.232:5672/"
\ No newline at end of file
url = "amqp://guest:guest@192.168.2.232:5672/"
[es]
es_sku_url = "http://soso12.ichunt.com/search/Es/searchSku"
\ No newline at end of file
......@@ -12,6 +12,7 @@ require (
github.com/ichunt2019/go-redis-pool v0.0.0-20210305064829-86b9011c57f5
github.com/ichunt2019/ichunt-micro-registry v1.0.1
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042
github.com/imroc/req v0.3.0
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/spf13/viper v1.7.1
github.com/tidwall/gjson v1.6.8
......
......@@ -168,6 +168,7 @@ github.com/ichunt2019/ichunt-micro-registry v1.0.1 h1:IrNy60FRIPzqf+Fk/hH5BbEwQg
github.com/ichunt2019/ichunt-micro-registry v1.0.1/go.mod h1:OPGbBtYiHTjmxOZ43l32PLsiw+89CEDANx/Cs5Y9zkQ=
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042 h1:SIV0HiSBdAxCXD6tvPXo3HUkzdlcDUh2/4MITVWWf1c=
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042/go.mod h1:6TmzpwF0PZdjqPWxrm8Slw5ESkDEIik5w8f/uc3m+WI=
github.com/imroc/req v0.3.0 h1:3EioagmlSG+z+KySToa+Ylo3pTFZs+jh3Brl7ngU12U=
github.com/imroc/req v0.3.0/go.mod h1:F+NZ+2EFSo6EFXdeIbpfE9hcC233id70kf0byW97Caw=
github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
......
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