Commit ef80ebc2 by mushishixian

统计

parent 43a9e07d
/logs
/.idea
/config/*.toml
*.properties
*.exe
*.exe~
gowatch.yml
/logs
/.idea
/.history
/config/*.toml
*.properties
*.exe
*.exe~
gowatch.yml
......@@ -6,6 +6,8 @@ import (
"github.com/imroc/req"
"github.com/tidwall/gjson"
"go_supplier_sever/app/model"
"strconv"
"time"
)
func StatisticsSuppliersSkuNum() (err error) {
......@@ -44,7 +46,50 @@ func StatisticsSuppliersSkuNum() (err error) {
return
}
//添加erp同步记录
//统计供应商是否上传过sku
func StatisticsSuppliersHasUploadedSku() (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()
var num int
for rows.Next() {
time.Sleep(100 * time.Millisecond)
err = rows.Scan(supplier)
//设置一个判断是否有上传sku的时间,目前是决定取2021年1月1日0点作为标准,这个时间往后的,有上传sku都是有合作过的
startTime, _ := time.Parse("2006-01-02 15:04:05", "2021-01-01 00:00:00")
startTimeUnix := strconv.Itoa(int(startTime.Unix()))
endTimeUnix := strconv.Itoa(int(time.Now().Unix()))
//去es查询sku数量
params := req.Param{
"canal/condition": supplier.SupplierCode,
"create_time/range": startTimeUnix + "," + endTimeUnix,
}
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()
//fmt.Println("供应商ID : ", supplier.SupplierId, "数量 : ", int(skuNum))
hasUploadedSku := -1
if skuNum > 0 {
num++
hasUploadedSku = 1
}
err = UpdateSupplierHasUploadedSku(supplier.SupplierId, hasUploadedSku)
if err != nil {
return err
}
}
fmt.Println("执行完成,历史有sku合作的供应商数量为 : ", num)
return
}
func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) {
supplier := new(model.Supplier)
//先去根据供应商内部编码找出对应的supplierId
......@@ -64,6 +109,25 @@ func UpdateSupplierSkuNum(supplierId, skuNum int) (err error) {
return
}
func UpdateSupplierHasUploadedSku(supplierId int, hasUploadedSku 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.UploadedSku = hasUploadedSku
//还要去写映射表lie_supplier_merger_mapping
_, err = Dao.GetDb("supplier").Table("lie_supplier_channel").Where("supplier_id = ?", supplierId).Cols("sku_num").Update(supplier)
if err != nil {
return err
}
return
}
//修改sku_mode
func UpdateSupplierSkuMode(supplierId, skuMode int) (err error) {
supplier := new(model.Supplier)
......
......@@ -4,6 +4,7 @@ type Supplier struct {
SupplierId int
SupplierCode string
SupplierName string
UploadedSku int
SkuNum int
SkuMode int
}
package service
import "go_supplier_sever/app/dao"
import (
"fmt"
"go_supplier_sever/app/dao"
)
func StatisticsSupplierSkuNum() (err error) {
func StatisticsSupplierSkuStatus() (err error) {
fmt.Println("开始统计")
//先找出所有需要判断的供应商
return dao.StatisticsSuppliersSkuNum()
err = dao.StatisticsSuppliersSkuNum()
if err != nil {
return err
}
err = dao.StatisticsSuppliersHasUploadedSku()
return err
}
......@@ -18,7 +18,8 @@ func main() {
flag.Parse()
boot.Init(configPath, logPath)
err := service.StatisticsSupplierSkuNum()
//统计供应商sku相关情况
err := service.StatisticsSupplierSkuStatus()
if err != nil {
fmt.Println(err)
}
......
[rabbit_mq_default]
url = "amqp://guest:guest@192.168.1.252:5672/"
[es]
es_sku_url = "http://soso12.liexin.com/search/Es/searchSku"
\ No newline at end of file
[rabbit_mq_default]
url = "amqp://guest:guest@192.168.1.252:5672/"
[es]
es_sku_url = "http://so.liexin.net/search/Es/searchSku"
\ 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