Commit 4ce8c399 by mushishixian

修改匹配商品接口

parent 90330ea2
No preview for this file type
No preview for this file type
The file could not be displayed because it is too large.
......@@ -4,6 +4,7 @@ go 1.13
require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/gin-gonic/gin v1.6.3
github.com/go-ini/ini v1.56.0
github.com/go-kratos/kratos v0.5.0
github.com/hprose/hprose-golang v2.0.5+incompatible
......@@ -14,7 +15,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/syyongx/php2go v0.9.4
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
gopkg.in/gin-gonic/gin.v1 v1.3.0
gopkg.in/ini.v1 v1.56.0 // indirect
gopkg.in/olivere/elastic.v5 v5.0.85
)
......@@ -68,6 +68,10 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/go-ini/ini v1.56.0 h1:6HjxSjqdmgnujDPhlzR4a44lxK3w03WPN8te0SoUSeM=
github.com/go-ini/ini v1.56.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
......@@ -77,10 +81,18 @@ github.com/go-kratos/kratos v0.5.0/go.mod h1:blOq6FeNF6fpjDiQpi0HWAarpDcCJGrWDJr
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
github.com/go-playground/locales v0.12.1 h1:2FITxuFt/xuCNP1Acdhv62OzaCiviiE4kotfhkmOqEc=
github.com/go-playground/locales v0.12.1/go.mod h1:IUMDtCfWo/w/mtMfIE/IG2K+Ey3ygWanZIBtBW0W2TM=
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
github.com/go-playground/universal-translator v0.16.0 h1:X++omBR/4cE2MNg91AoC3rmGrCjJ8eAeUP/K/EKx4DM=
github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY=
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
......@@ -162,6 +174,7 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
......@@ -185,6 +198,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
......@@ -197,7 +212,10 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.9.0 h1:pDRiWfl+++eC2FEFRy6jXmQlvp4Yh3z1MJKg4UeYM/4=
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
......@@ -208,8 +226,10 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
......@@ -315,7 +335,11 @@ github.com/tjfoc/gmsm v1.0.1/go.mod h1:XxO4hdhhrzAd+G4CjDqaOkd0hUzmtPR/d3EiBBMn/
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tmc/grpc-websocket-proxy v0.0.0-20200122045848-3419fae592fc/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tsuna/gohbase v0.0.0-20190502052937-24ffed0537aa/go.mod h1:3HfLQly3YNLGxNv/2YOfmz30vcjG9hbuME1GpxoLlGs=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
......@@ -394,6 +418,7 @@ golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
......@@ -453,6 +478,8 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gin-gonic/gin.v1 v1.3.0 h1:DjAu49rN1YttQsOkVCPlAO3INcZNFT0IKsNVMk5MRT4=
gopkg.in/gin-gonic/gin.v1 v1.3.0/go.mod h1:Eljh74A/zAvUOQ835v6ySeZ+5gQG6tKjbZTaZ9iWU3A=
gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM=
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
gopkg.in/go-playground/validator.v9 v9.29.1 h1:SvGtYmN60a5CVKTOzMSyfzWDeZRxRuGvRQyEAKbw1xc=
......
package common
type Response struct {
Errcode int
Errmsg string
Data interface{}
Errcode int `json:"errcode"`
Errmsg string `json:"errmsg"`
Data interface{} `json:"data"`
}
......@@ -9,10 +9,18 @@ import (
func GetBomItems(bomId int) (bomItems []model.BomItem) {
bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1])
model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_id = ?", bomId).Find(&bomItems)
model.Db.Table("lie_bom_item_"+tableEnd).Where("del_status = ?", 1).Where("bom_id = ?", bomId).Find(&bomItems)
return bomItems
}
func GetBomItem(bomId,bomItemId int)(bomItem model.BomItem) {
bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1])
model.Db.Table("lie_bom_item_"+tableEnd).
Where("bom_item_id = ?", bomItemId).Where("bom_id = ?", bomId).First(&bomItem)
return bomItem
}
//更新没有匹配的到bom详情
func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) {
if len(bomItems) == 0 {
......
......@@ -3,6 +3,7 @@ package logic
import (
"bom_server/internal/model"
"strconv"
"strings"
"time"
)
......@@ -14,16 +15,21 @@ func GetBomMatchings(bomId int) (bomMatchings []model.BomItemMatching) {
return bomMatchings
}
func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) {
bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1])
model.Db.Table("lie_bom_item_matching_"+tableEnd).
Where("bom_item_id = ?", bomItemId).Where("bom_id = ?", bomId).First(&bomMatching)
return bomMatching
}
//根据matchingList去修改
func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err error) {
bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1])
tableName := "lie_bom_item_matching_" + tableEnd
var isBuyBomItemIdList, noBuyBomItemIdList []int
for key, matching := range matchingList {
if key == 0 || key == 1 || key == 2 {
time.Sleep(5 * time.Second)
}
for _, matching := range matchingList {
//先去数据库查询是否存在该记录,有的话修改,没有就新增
var match model.BomItemMatching
model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match)
......@@ -57,3 +63,44 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
}
return nil
}
//刷新bom匹配的商品信息
func RefreshBomMatchingGoods(bomId int) (err error) {
//先找出bom相关信息
var goodsIds []string
bomMatchings := GetBomMatchings(bomId)
for _, matching := range bomMatchings {
goodsIds = append(goodsIds, matching.GoodsID)
}
goodsIdsStr := strings.Join(goodsIds, ",")
//去请求商品服务
responseData, err := GetGoodsInfo(goodsIdsStr)
if err != nil {
return
}
var bomMatchingList []model.BomItemMatching
for _, matching := range bomMatchings {
for _, goods := range responseData.Data {
if matching.GoodsID == goods.GoodsID {
var goodsMap GoodsMap
goodsMap.Number = matching.Number
goodsMap.GoodsName = matching.GoodsName
goodsMap.DeliveryType = matching.DeliveryType
goodsMap.BomId = matching.BomID
goodsMap.BomItemId = matching.BomItemID
goodsMap.GoodsId = matching.GoodsID
//组装需要去更新的商品信息
bomMatching, err := MatchGoodsInfo(goods, goodsMap)
if err != nil {
return err
}
bomMatchingList = append(bomMatchingList, bomMatching)
}
}
}
err = BatchSaveMatchings(bomId, bomMatchingList)
if err != nil {
return
}
return
}
......@@ -30,19 +30,10 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
goodsIds = append(goodsIds, goodsMap.GoodsId)
}
goodsIdsStr := strings.Join(goodsIds, ",")
goodsServerUrl := configs.ApiSetting.Goods
params := req.Param{
"goods_id": goodsIdsStr,
}
//req.Debug = true
resp, err := req.Post(goodsServerUrl+"/synchronization", params)
responseData, err := GetGoodsInfo(goodsIdsStr)
if err != nil {
return
}
var responseData model.ApiGoodsResponse
if err = resp.ToJSON(&responseData); err != nil {
return
}
//这是匹配到的数据
var bomMatchingList []model.BomItemMatching
for _, goodsMap := range goodsMapList {
......@@ -50,80 +41,9 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
if goodsMap.GoodsId == goods.GoodsID {
bomId = goodsMap.BomId
//组装需要去更新的商品信息
var delivery string
if goodsMap.DeliveryType == 1 {
delivery = goods.CnDeliveryTime
} else {
delivery = goods.HkDeliveryTime
}
bomMatching := model.BomItemMatching{
BomID: goodsMap.BomId,
BomItemID: goodsMap.BomItemId,
BrandId: goods.BrandID,
GoodsID: goods.GoodsID,
GoodsName: goods.GoodsName,
BrandName: goods.BrandName,
GoodsType: goods.GoodsType,
SupplierID: goods.SupplierID,
Pdf: goods.Pdf,
SupplierName: goods.SupplierName,
Delivery: delivery,
DeliveryType: goodsMap.DeliveryType,
Number: goodsMap.Number,
Stock: goods.Stock,
IsBuy: goods.IsBuy,
Moq: goods.Moq,
Mpq: goods.Mpq,
Encap: goods.Encap,
Status: goods.Status,
AddTime: int(time.Now().Unix()),
}
/**
数量处理:
1.要满足最小起订量
2.数量要是满足倍数的规则
*/
if goodsMap.Number < goods.Moq {
bomMatching.Number = goods.Moq
} else {
//不满足倍数规则,则要去帮它按倍数取
if (goodsMap.Number % goods.Mpq) != 0 {
bomMatching.Number = ((goodsMap.Number / goods.Mpq) + 1) * goods.Mpq
}
}
//阶梯价处理
if len(goods.LadderPrice) > 0 {
ladderPriceStr, err := json.Marshal(goods.LadderPrice)
if err != nil {
return err
}
bomMatching.LadderPrice = string(ladderPriceStr)
//获取美元和人民币的价格(需要去判断数量)
if len(goods.LadderPrice) > 0 {
for _, price := range goods.LadderPrice {
//要先去断言,因为商品服务返回的json的值类型不确定...
value := reflect.ValueOf(price.Purchases).Type().String()
var purchases int
if value == "string" {
tempNumber, _ := strconv.ParseInt(price.Purchases.(string), 10, 10)
purchases = int(tempNumber)
} else if value == "float64" {
purchases = int(price.Purchases.(float64))
} else {
purchases = price.Purchases.(int)
}
if goodsMap.Number <= purchases {
//判断是否有优惠价,有的话取优惠价
if price.PriceAc != 0 {
bomMatching.Price = price.PriceAc
} else {
bomMatching.Price = price.PriceCn
}
break
}
}
}
bomMatching, err := MatchGoodsInfo(goods, goodsMap)
if err != nil {
return err
}
bomMatchingList = append(bomMatchingList, bomMatching)
}
......@@ -135,3 +55,99 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
}
return
}
func GetGoodsInfo(goodsIdsStr string) (responseData model.ApiGoodsResponse, err error) {
goodsServerUrl := configs.ApiSetting.Goods
params := req.Param{
"goods_id": goodsIdsStr,
}
//req.Debug = true
resp, err := req.Post(goodsServerUrl+"/synchronization", params)
if err != nil {
return
}
if err = resp.ToJSON(&responseData); err != nil {
return
}
return
}
//处理商品匹配
func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.BomItemMatching, err error) {
//组装需要去更新的商品信息
var delivery string
if goodsMap.DeliveryType == 1 {
delivery = goods.CnDeliveryTime
} else {
delivery = goods.HkDeliveryTime
}
bomMatching = model.BomItemMatching{
BomID: goodsMap.BomId,
BomItemID: goodsMap.BomItemId,
BrandId: goods.BrandID,
GoodsID: goods.GoodsID,
GoodsName: goods.GoodsName,
BrandName: goods.BrandName,
GoodsType: goods.GoodsType,
SupplierID: goods.SupplierID,
Pdf: goods.Pdf,
SupplierName: goods.SupplierName,
Delivery: delivery,
DeliveryType: goodsMap.DeliveryType,
Number: goodsMap.Number,
Stock: goods.Stock,
IsBuy: goods.IsBuy,
Moq: goods.Moq,
Mpq: goods.Mpq,
Encap: goods.Encap,
Status: goods.Status,
AddTime: int(time.Now().Unix()),
}
/**
数量处理:
1.要满足最小起订量
2.数量要是满足倍数的规则
*/
if goodsMap.Number < goods.Moq {
bomMatching.Number = goods.Moq
} else {
//不满足倍数规则,则要去帮它按倍数取
if (goodsMap.Number % goods.Mpq) != 0 {
bomMatching.Number = ((goodsMap.Number / goods.Mpq) + 1) * goods.Mpq
}
}
//阶梯价处理
if len(goods.LadderPrice) > 0 {
ladderPriceStr, err := json.Marshal(goods.LadderPrice)
if err != nil {
return model.BomItemMatching{}, err
}
bomMatching.LadderPrice = string(ladderPriceStr)
//获取美元和人民币的价格(需要去判断数量)
if len(goods.LadderPrice) > 0 {
for _, price := range goods.LadderPrice {
//要先去断言,因为商品服务返回的json的值类型不确定...
value := reflect.ValueOf(price.Purchases).Type().String()
var purchases int
if value == "string" {
tempNumber, _ := strconv.ParseInt(price.Purchases.(string), 10, 10)
purchases = int(tempNumber)
} else if value == "float64" {
purchases = int(price.Purchases.(float64))
} else {
purchases = price.Purchases.(int)
}
if goodsMap.Number <= purchases {
//判断是否有优惠价,有的话取优惠价
if price.PriceAc != 0 {
bomMatching.Price = price.PriceAc
} else {
bomMatching.Price = price.PriceCn
}
break
}
}
}
}
return
}
......@@ -113,6 +113,64 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
return
}
//更新单个matching
func UpdateSingleBomMatching(bomId int, bomItemId int, goodsId string) (bomItemInfo model.BomItem, err error) {
responseData, err := GetGoodsInfo(goodsId)
if err != nil {
return
}
var bomMatchingList []model.BomItemMatching
//先去获取对应的matching
matching := GetBomMatching(bomId, bomItemId)
if len(responseData.Data) > 0 {
for _, goods := range responseData.Data {
var goodsMap GoodsMap
goodsMap.Number = matching.Number
goodsMap.GoodsName = matching.GoodsName
goodsMap.DeliveryType = matching.DeliveryType
goodsMap.BomId = matching.BomID
goodsMap.BomItemId = matching.BomItemID
goodsMap.GoodsId = matching.GoodsID
//组装需要去更新的商品信息
bomMatching, err := MatchGoodsInfo(goods, goodsMap)
if err != nil {
return bomItemInfo, err
}
bomMatchingList = append(bomMatchingList, bomMatching)
}
}
err = BatchSaveMatchings(bomId, bomMatchingList)
if err != nil {
return
}
//还要返回对应的信息
bomItemInfo = GetBomItem(bomId, bomItemId)
bomMatching := GetBomMatching(bomId, bomItemId)
bomItemInfo.Matching = bomMatching
return
}
//通过搜索去匹配单个matching
func SaveSingleBomMatchingBySearch(bomId int, bomItemId, deliveryType, sort int) (err error) {
//client, err := es.NewClient(es.SetURL(configs.ESSetting.Url))
//if err != nil {
// panic(err)
//}
//defer client.Stop()
//var bomItems []model.BomItem
//bomItems = append(bomItems, bomItem)
////直接模糊匹配
//goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, client, true)
//if err != nil {
// return
//}
//err = UpdateGoodsData(goodsMapList)
//if err != nil {
// return
//}
return
}
//判断是否在里面
func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
for _, goodsMap := range goodsMapList {
......
......@@ -19,4 +19,6 @@ type BomItem struct {
AddTime int `json:"add_time"`
// UpdateTime 更新时间
UpdateTime int `json:"update_time"`
Matching BomItemMatching `json:"matching"`
}
......@@ -4,10 +4,9 @@ import (
"bom_server/internal/logic"
"bom_server/internal/model"
"errors"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"os"
"strconv"
"time"
)
//导出excel
......@@ -16,7 +15,6 @@ func Export(bomId int) (ossPath string, err error) {
if err != nil {
return
}
t := time.Now()
bomIdStr := strconv.Itoa(bomId)
filePath := "Bom_" + bomIdStr + ".xlsx"
f := excelize.NewFile()
......@@ -64,10 +62,13 @@ func Export(bomId int) (ossPath string, err error) {
if err != nil {
return
}
//删除文件
}
ossPath,err = UploadToOss(filePath, "xlsx")
elapsed := time.Since(t)
fmt.Println(elapsed)
ossPath, err = UploadToOss(filePath, "xlsx")
if err != nil {
return
}
err = os.Remove(filePath)
return
}
......
#!/bin/bash
cd /data2/gocode/bom_server
git pull origin master
rm ./sh/scm_wms_sync
rm ./cmd/scm_wms_sync
rm ./sh/import_source
rm ./conf/config.ini
mv ./conf/config_production.ini ./conf/config.ini
go build -o ./sh/scm_wms_sync ./main.go
go build -o ./sh/import_source ./cmd/source/main.go
go build -o ./cmd/bom_sync ./cmd/main.go
go build -o ./server/bom_rpc_server ./server/main.go
supervisorctl restart scm:bom_server
\ No newline at end of file
package http
import (
"bom_server/internal/common"
"bom_server/internal/service"
"github.com/gin-gonic/gin"
)
func Export(c *gin.Context) {
bomId := c.GetInt("bom_id")
ossPath, err := service.Export(bomId)
var response common.Response
if err != nil {
response.Errcode = -1
response.Errmsg = err.Error()
} else {
response.Errcode = 0
response.Errmsg = "ok"
response.Data = ossPath
}
c.JSON(200, response)
}
package http
import (
"bom_server/internal/common"
"bom_server/internal/logic"
"github.com/gin-gonic/gin"
"strconv"
)
//刷新价格和库存接口
func RefreshBomMatchingGoods(c *gin.Context) {
bomIdStr, _ := c.GetQuery("bom_id")
bomId, _ := strconv.Atoi(bomIdStr)
var response common.Response
if bomId == 0 {
response.Errcode = -1
response.Errmsg = "bom_id不能为空"
c.JSON(200, response)
return
}
err := logic.RefreshBomMatchingGoods(bomId)
if err != nil {
response.Errcode = -1
response.Errmsg = err.Error()
} else {
response.Errcode = 0
response.Errmsg = "ok"
}
c.JSON(200, response)
return
}
//新增或者修改bom_matching
func UpdateBomMatching(c *gin.Context) {
bomIdStr, _ := c.GetQuery("bom_id")
goodsId, _ := c.GetQuery("goods_id")
bomItemIdStr, _ := c.GetQuery("bom_item_id")
bomId, _ := strconv.Atoi(bomIdStr)
bomItemId, _ := strconv.Atoi(bomItemIdStr)
var response common.Response
bomItemInfo, err := logic.UpdateSingleBomMatching(bomId, bomItemId, goodsId)
if err != nil {
response.Errcode = -1
response.Errmsg = err.Error()
} else {
response.Errcode = 0
response.Errmsg = "ok"
response.Data = bomItemInfo
}
c.JSON(200, response)
return
}
package http
import (
"github.com/gin-gonic/gin"
"net/http"
"strconv"
"time"
)
//单个修改商品,传bom_item_id和商品id,然后去商品服务得到结果,修改bomItem相关信息
func UpdateBomItem(bomId, bomItemId int, goodsId string) {
}
func InitRouter() *gin.Engine {
router := gin.Default()
router.Use(gin.Logger())
router.Use(gin.Recovery())
//跨域设置
//配置列表
router.GET("/bom/export", Export)
router.GET("/bom_matching/refresh", RefreshBomMatchingGoods)
router.GET("/bom_matching/update", UpdateBomMatching)
//router.GET("/config/list", ListConfigApi)
//router.POST("/config/rollback", RollbackConfigApi)
//服务器列表
//router.GET("/workers/list", ListWorkersApi)
return router
}
func InitApiServer() (err error) {
router := InitRouter()
apiPort := strconv.Itoa(8080)
s := &http.Server{
Addr: ":" + apiPort,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
return s.ListenAndServe()
}
......@@ -3,35 +3,17 @@ package main
import (
"bom_server/configs"
"bom_server/internal/model"
"bom_server/internal/service"
"bom_server/server/http"
"flag"
"github.com/hprose/hprose-golang/rpc"
"net/http"
)
func Export(bomId int) (result interface{}) {
ossPath, err := service.Export(bomId)
response := make(map[string]interface{})
if err != nil {
response["err_code"] = -1
response["err_msg"] = err.Error()
} else {
response["err_code"] = 0
response["err_msg"] = "ok"
response["data"] = ossPath
}
return response
}
func main() {
var path string
flag.StringVar(&path, "config", "conf/config.ini", "../conf/config.ini")
flag.Parse()
configs.Setup(path)
model.Setup()
server := rpc.NewHTTPService()
server.AddFunction("export", Export)
err := http.ListenAndServe(":8080", server)
err := http.InitApiServer()
if err != nil {
panic(err)
}
......
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