Commit 19b5ff3b by mushishixian

完善修改

parent a86b8559
The file could not be displayed because it is too large.
...@@ -7,7 +7,8 @@ import ( ...@@ -7,7 +7,8 @@ import (
//根据bom_id查出bom表信息 //根据bom_id查出bom表信息
func GetBomItems(bomId int) (bomItems []model.BomItem) { func GetBomItems(bomId int) (bomItems []model.BomItem) {
tableEnd := strconv.FormatInt(int64(bomId), 10) 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("bom_id = ?", bomId).Find(&bomItems)
return bomItems return bomItems
} }
...@@ -2,10 +2,30 @@ package logic ...@@ -2,10 +2,30 @@ package logic
import ( import (
"bom_server/internal/model" "bom_server/internal/model"
"strconv"
"time"
) )
//根据bom_id查出bom表信息 //根据matchingList去修改
func GetBomMatchings(bomId int) (bomMatchings []model.BomItem) { func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err error) {
model.Db.Where("bom_id = ?", bomId).Find(&bomMatchings) bomIdStr := strconv.FormatInt(int64(bomId), 10)
return bomMatchings tableEnd := string(bomIdStr[len(bomIdStr)-1])
tableName := "lie_bom_item_matching_" + tableEnd
for _, matching := range matchingList {
//先去数据库查询是否存在该记录,有的话修改,没有就新增
var match model.BomItemMatching
model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match)
if match.BomItemID != 0 {
matching.UpdateTime = int(time.Now().Unix())
if err = model.Db.Table(tableName).Model(&match).Updates(matching).Error; err != nil {
return
}
} else {
if err = model.Db.Table(tableName).Create(&matching).Error; err != nil {
return
}
}
}
return nil
} }
...@@ -20,7 +20,10 @@ type GoodsMap struct { ...@@ -20,7 +20,10 @@ type GoodsMap struct {
func UpdateGoodsData(goodsMapList []GoodsMap) () { func UpdateGoodsData(goodsMapList []GoodsMap) () {
//根据goodsIds去商品服务获取对应的商品信息 //根据goodsIds去商品服务获取对应的商品信息
var goodsIds []string var (
goodsIds []string
bomId int
)
for _, goodsMap := range goodsMapList { for _, goodsMap := range goodsMapList {
goodsIds = append(goodsIds, goodsMap.GoodsId) goodsIds = append(goodsIds, goodsMap.GoodsId)
} }
...@@ -38,16 +41,17 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () { ...@@ -38,16 +41,17 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
if err := resp.ToJSON(&responseData); err != nil { if err := resp.ToJSON(&responseData); err != nil {
fmt.Println(err) fmt.Println(err)
} }
bomMatchingList := map[string]model.BomItemMatching{} var bomMatchingList []model.BomItemMatching
for _, goodsMap := range goodsMapList { for _, goodsMap := range goodsMapList {
for _, goods := range responseData.Data { for _, goods := range responseData.Data {
if goodsMap.GoodsId == goods.GoodsID { if goodsMap.GoodsId == goods.GoodsID {
bomId = goodsMap.BomId
//组装需要去更新的商品信息 //组装需要去更新的商品信息
bomMatching := model.BomItemMatching{ bomMatching := model.BomItemMatching{
BomID: goodsMap.BomId, BomID: goodsMap.BomId,
BomItemID: goodsMap.BomItemId, BomItemID: goodsMap.BomItemId,
GoodsID: goods.GoodsID, GoodsID: goods.GoodsID,
GoodsType: goods.AcType, GoodsType: goods.GoodsType,
SupplierID: goods.SupplierID, SupplierID: goods.SupplierID,
SupplierName: goods.SupplierName, SupplierName: goods.SupplierName,
CnDelivery: goods.CnDeliveryTime, CnDelivery: goods.CnDeliveryTime,
...@@ -68,12 +72,23 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () { ...@@ -68,12 +72,23 @@ func UpdateGoodsData(goodsMapList []GoodsMap) () {
fmt.Println(err) fmt.Println(err)
} }
bomMatching.LadderPrice = string(ladderPriceStr) bomMatching.LadderPrice = string(ladderPriceStr)
//获取美元和人民币的价格 //获取美元和人民币的价格(需要去判断数量)
bomMatching.CnPrice = 0 if len(goods.LadderPrice) > 0 {
bomMatching.HkPrice = 0 for _, price := range goods.LadderPrice {
if goodsMap.Number <= price.Purchases {
bomMatching.CnPrice = price.PriceCn
bomMatching.HkPrice = price.PriceUs
break
}
}
}
} }
bomMatchingList[bomMatching.GoodsID] = bomMatching bomMatchingList = append(bomMatchingList, bomMatching)
} }
} }
} }
err = BatchSaveMatchings(bomId, bomMatchingList)
if err != nil {
fmt.Println(err)
}
} }
...@@ -71,9 +71,13 @@ func SearchGoods(bomId int, bomItems []model.BomItem) { ...@@ -71,9 +71,13 @@ func SearchGoods(bomId int, bomItems []model.BomItem) {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
UpdateGoodsData(goodsMapList) //要删除已经精确匹配过的bomItem
//for _, bom := range bomItems {
// for _, goodsMap := range goodsMapList {
//
// }
//}
//第二次去模糊匹配 //第二次去模糊匹配
//todo : 先删除第一次已经精确匹配的bom
goodsMapList, err = getUpdateGoodsData(bomId, bomItems, client, true) goodsMapList, err = getUpdateGoodsData(bomId, bomItems, client, true)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
...@@ -111,6 +115,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client, ...@@ -111,6 +115,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, client *es.Client,
} }
var goodsMap GoodsMap var goodsMap GoodsMap
goodsMap.GoodsId = strconv.FormatInt(int64(goods.GoodsID), 10) goodsMap.GoodsId = strconv.FormatInt(int64(goods.GoodsID), 10)
goodsMap.Number = bomItems[key].Number
goodsMap.GoodsName = goods.GoodsName goodsMap.GoodsName = goods.GoodsName
goodsMap.BomItemId = bomItems[key].BomItemID goodsMap.BomItemId = bomItems[key].BomItemID
goodsMap.BomId = bomId goodsMap.BomId = bomId
......
...@@ -2,7 +2,7 @@ package model ...@@ -2,7 +2,7 @@ package model
type BomItemMatching struct { type BomItemMatching struct {
// MatchingID 匹配ID // MatchingID 匹配ID
MatchingID int `json:"matching_id"` MatchingID int `json:"matching_id" gorm:"primary_key"`
// BomID bom主表Id(为了方便逆向查找bom_item表) // BomID bom主表Id(为了方便逆向查找bom_item表)
BomID int `json:"bom_id"` BomID int `json:"bom_id"`
// BomItemID bom详情ID // BomItemID bom详情ID
...@@ -41,3 +41,7 @@ type BomItemMatching struct { ...@@ -41,3 +41,7 @@ type BomItemMatching struct {
// LadderPrice 阶梯价 // LadderPrice 阶梯价
LadderPrice string `json:"ladder_price"` LadderPrice string `json:"ladder_price"`
} }
func (BomItemMatching) TableName() string {
return "bom_item_matching"
}
\ 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