Commit 3c0b0a6b by mushishixian

修改bom_item

parent 7f363b05
The file could not be displayed because it is too large.
...@@ -13,6 +13,7 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/" ...@@ -13,6 +13,7 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
base = http://192.168.2.232:40001 base = http://192.168.2.232:40001
goods = http://192.168.2.232:60004 goods = http://192.168.2.232:60004
upload = http://api.liexin.com/oss/upload upload = http://api.liexin.com/oss/upload
api_port = 60010
[oss] [oss]
upload_key = fh6y5t4rr351d2c3bryi upload_key = fh6y5t4rr351d2c3bryi
...@@ -22,4 +23,4 @@ push_url = http://192.168.1.237:1988/v1/push ...@@ -22,4 +23,4 @@ push_url = http://192.168.1.237:1988/v1/push
[es] [es]
url = http://192.168.2.232:9200 url = http://192.168.2.232:9200
goods_index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,zhuanmai,peigenesis,powell,rs,buerklin,liexin_ziying goods_index_name = future,rochester,tme,verical,element14,digikey,chip1stop,aipco,arrow,alliedelec,avnet,mouser,peigenesis,powell,rs,buerklin
\ No newline at end of file \ No newline at end of file
...@@ -43,6 +43,7 @@ type RabbitMQ struct { ...@@ -43,6 +43,7 @@ type RabbitMQ struct {
type Api struct { type Api struct {
Goods string `ini:"goods"` Goods string `ini:"goods"`
Upload string `ini:"upload"` Upload string `ini:"upload"`
ApiPort string `ini:"api_port"`
} }
type Oss struct { type Oss struct {
......
package logic package logic
import ( import (
"bom_server/configs"
"bom_server/internal/model" "bom_server/internal/model"
"encoding/json"
"fmt"
es "gopkg.in/olivere/elastic.v5"
"strconv" "strconv"
) )
...@@ -13,7 +17,7 @@ func GetBomItems(bomId int) (bomItems []model.BomItem) { ...@@ -13,7 +17,7 @@ func GetBomItems(bomId int) (bomItems []model.BomItem) {
return bomItems return bomItems
} }
func GetBomItem(bomId,bomItemId int)(bomItem model.BomItem) { func GetBomItem(bomId, bomItemId int) (bomItem model.BomItem) {
bomIdStr := strconv.FormatInt(int64(bomId), 10) bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1]) tableEnd := string(bomIdStr[len(bomIdStr)-1])
model.Db.Table("lie_bom_item_"+tableEnd). model.Db.Table("lie_bom_item_"+tableEnd).
...@@ -43,3 +47,44 @@ func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) { ...@@ -43,3 +47,44 @@ func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) {
} }
return nil return nil
} }
type Where struct {
Sort int `json:"sort"`
DeliveryType int `json:"delivery_type"`
}
//更新bom_item(去搜索进行重新匹配)
func UpdateBomItem(bomId, bomItemId int) (err error) {
//先去查主表的信息
bom := GetBomInfo(bomId)
bomItem := GetBomItem(bomId, bomItemId)
var bomItems []model.BomItem
bomItems = append(bomItems, bomItem)
//获取排序条件
var where Where
if bom.Where != "" {
err = json.Unmarshal([]byte(bom.Where), &where)
if err != nil {
return err
}
}
if len(bomItems) == 0 {
return
}
client, err := es.NewClient(es.SetURL(configs.ESSetting.Url))
if err != nil {
panic(err)
}
defer client.Stop()
fmt.Println(bomItems[0].BomID)
//直接模糊匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, where.DeliveryType, where.Sort, client, false)
if err != nil {
return
}
err = UpdateGoodsData(goodsMapList)
if err != nil {
return
}
return
}
...@@ -15,6 +15,7 @@ func GetBomMatchings(bomId int) (bomMatchings []model.BomItemMatching) { ...@@ -15,6 +15,7 @@ func GetBomMatchings(bomId int) (bomMatchings []model.BomItemMatching) {
return bomMatchings return bomMatchings
} }
//获取单个matching
func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) { func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) {
bomIdStr := strconv.FormatInt(int64(bomId), 10) bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1]) tableEnd := string(bomIdStr[len(bomIdStr)-1])
...@@ -23,8 +24,6 @@ func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) { ...@@ -23,8 +24,6 @@ func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) {
return bomMatching return bomMatching
} }
//根据matchingList去修改 //根据matchingList去修改
func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err error) { func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err error) {
bomIdStr := strconv.FormatInt(int64(bomId), 10) bomIdStr := strconv.FormatInt(int64(bomId), 10)
...@@ -52,14 +51,15 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -52,14 +51,15 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
noBuyBomItemIdList = append(noBuyBomItemIdList, matching.BomItemID) noBuyBomItemIdList = append(noBuyBomItemIdList, matching.BomItemID)
} }
} }
now := time.Now().Unix()
//分别去更新 //分别去更新
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", isBuyBomItemIdList). err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", isBuyBomItemIdList).
Updates(map[string]interface{}{"item_status": 2}).Error Updates(map[string]interface{}{"item_status": 2, "update_time": now}).Error
if err != nil { if err != nil {
return return
} }
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", noBuyBomItemIdList). err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", noBuyBomItemIdList).
Updates(map[string]interface{}{"item_status": 3}).Error Updates(map[string]interface{}{"item_status": 3, "update_time": now}).Error
if err != nil { if err != nil {
return return
} }
......
...@@ -78,7 +78,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -78,7 +78,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
} }
defer client.Stop() defer client.Stop()
//第一次先去精确匹配 //第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, client, true) goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, sort, client, true)
if err != nil { if err != nil {
return return
} }
...@@ -90,7 +90,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -90,7 +90,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
} }
} }
//第二次去模糊匹配 //第二次去模糊匹配
fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, client, true) fuzzyGoodsMapList, err := getUpdateGoodsData(bomId, fuzzyBomItems, deliveryType, sort, client, false)
if err != nil { if err != nil {
return return
} }
...@@ -151,12 +151,6 @@ func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomIt ...@@ -151,12 +151,6 @@ func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomIt
return return
} }
//通过搜索去匹配单个matching
func SaveBomMatchingByGoodsName(bomId int, bomItemId int, goodsName string) (bomItemInfo model.BomItem, err error) {
return
}
//判断是否在里面 //判断是否在里面
func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool { func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
for _, goodsMap := range goodsMapList { for _, goodsMap := range goodsMapList {
...@@ -167,11 +161,15 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool { ...@@ -167,11 +161,15 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
return false return false
} }
func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType int, client *es.Client, rawSearch bool) (goodsMapList []GoodsMap, err error) { func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType, sort int, client *es.Client, rawSearch bool) (goodsMapList []GoodsMap, err error) {
if len(bomItems) == 0 { if len(bomItems) == 0 {
return return
} }
index := configs.ESSetting.GoodsIndexName index := configs.ESSetting.GoodsIndexName
//如果是大陆收货(type=1),就要包含专卖和自营
if deliveryType == 1 {
index = index + ",zhuanmai,liexin_ziying"
}
search := client.MultiSearch().Index(index) search := client.MultiSearch().Index(index)
//多重搜索,第一次先去精确匹配 //多重搜索,第一次先去精确匹配
for _, bom := range bomItems { for _, bom := range bomItems {
...@@ -180,7 +178,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType int, c ...@@ -180,7 +178,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType int, c
bom.GoodsName = common.SubKeyWordStr(bom.GoodsName) bom.GoodsName = common.SubKeyWordStr(bom.GoodsName)
} }
//构建一个goods_name对应的bomItems列表 //构建一个goods_name对应的bomItems列表
searchRequest := getSearchParams(bom.GoodsName, bom.BrandName, bom.Number, rawSearch) searchRequest := getSearchParams(bom.GoodsName, bom.BrandName, sort, bom.Number, rawSearch)
search.Add(searchRequest) search.Add(searchRequest)
} }
res, err := search.Do(context.Background()) res, err := search.Do(context.Background())
...@@ -216,11 +214,17 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType int, c ...@@ -216,11 +214,17 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType int, c
} }
//构建请求参数 //构建请求参数
func getSearchParams(goodsName, brandName string, number int, flag bool) (searchRequest *es.SearchRequest) { func getSearchParams(goodsName, brandName string, sort, number int, flag bool) (searchRequest *es.SearchRequest) {
query := getTermQuery(goodsName, brandName, number, flag) query := getTermQuery(goodsName, brandName, number, flag)
source := es.NewSearchSource().IndexBoost("liexin_ziying", 2).Query(query). source := es.NewSearchSource().IndexBoost("liexin_ziying", 2).Query(query).
Sort("_score", false).Sort("sort", false).Sort("single_price", true). Sort("_score", false).Sort("sort", false).From(0).Size(1)
From(0).Size(1) //要去判断sort,sort=2是按照价格排序
if sort == 2 {
source.Sort("single_price", true)
//sort=3是按照库存排序
} else if sort == 3 {
source.Sort("stock", false)
}
searchRequest = es.NewSearchRequest().Source(source) searchRequest = es.NewSearchRequest().Source(source)
return searchRequest return searchRequest
} }
......
...@@ -23,6 +23,7 @@ type Bom struct { ...@@ -23,6 +23,7 @@ type Bom struct {
IsSyncCrm int `json:"is_sync_crm"` IsSyncCrm int `json:"is_sync_crm"`
// bom详情 // bom详情
BomItems []BomItem BomItems []BomItem
Where string `json:"where"`
BomIMatchings []BomItemMatching BomIMatchings []BomItemMatching
} }
......
package http
import (
"bom_server/internal/common"
"bom_server/internal/logic"
"fmt"
"github.com/gin-gonic/gin"
"strconv"
)
//修改bom_item的信息,然后去搜索匹配
func UpdateBomItem(c *gin.Context) {
bomItemIdStr := c.PostForm("bom_item_id")
bomIdStr := c.PostForm("bom_id")
fmt.Println(bomIdStr,bomItemIdStr)
bomItemId, _ := strconv.Atoi(bomItemIdStr)
bomId, _ := strconv.Atoi(bomIdStr)
err := logic.UpdateBomItem(bomId, bomItemId)
var response common.Response
if err != nil {
response.Errcode = -1
response.Errmsg = err.Error()
} else {
response.Errcode = 0
response.Errmsg = "ok"
}
c.JSON(200, response)
return
}
...@@ -49,25 +49,4 @@ func UpdateBomMatching(c *gin.Context) { ...@@ -49,25 +49,4 @@ func UpdateBomMatching(c *gin.Context) {
} }
c.JSON(200, response) c.JSON(200, response)
return return
} }
\ No newline at end of file
//通过型号去新增匹配项
func SaveBomMatchingByGoodsName(c *gin.Context) {
bomIdStr, _ := c.GetQuery("bom_id")
goodsName, _ := c.GetQuery("goods_name")
bomItemIdStr, _ := c.GetQuery("bom_item_id")
bomId, _ := strconv.Atoi(bomIdStr)
bomItemId, _ := strconv.Atoi(bomItemIdStr)
var response common.Response
bomItemInfo, err := logic.SaveBomMatchingByGoodsName(bomId, bomItemId, goodsName)
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 package http
import ( import (
"bom_server/configs"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http" "net/http"
"strconv"
"time" "time"
) )
//单个修改商品,传bom_item_id和商品id,然后去商品服务得到结果,修改bomItem相关信息
func UpdateBomItem(bomId, bomItemId int, goodsId string) {
}
func InitRouter() *gin.Engine { func InitRouter() *gin.Engine {
router := gin.Default() router := gin.Default()
router.Use(gin.Logger()) router.Use(gin.Logger())
router.Use(gin.Recovery()) router.Use(gin.Recovery())
//跨域设置
//配置列表
router.POST("/bom/export", Export) router.POST("/bom/export", Export)
router.POST("/bom_matching/refresh", RefreshBomMatchingGoods) router.POST("/bom_matching/refresh", RefreshBomMatchingGoods)
router.POST("/bom_matching/update", UpdateBomMatching) router.POST("/bom_matching/update", UpdateBomMatching)
//router.GET("/config/list", ListConfigApi) router.POST("/bom_item/update", UpdateBomItem)
//router.POST("/config/rollback", RollbackConfigApi)
//服务器列表
//router.GET("/workers/list", ListWorkersApi)
return router return router
} }
func InitApiServer() (err error) { func InitApiServer() (err error) {
router := InitRouter() router := InitRouter()
apiPort := strconv.Itoa(60010)
s := &http.Server{ s := &http.Server{
Addr: ":" + apiPort, Addr: ":" + configs.ApiSetting.ApiPort,
Handler: router, Handler: router,
ReadTimeout: 10 * time.Second, ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second,
...@@ -42,5 +29,3 @@ func InitApiServer() (err error) { ...@@ -42,5 +29,3 @@ func InitApiServer() (err error) {
} }
return s.ListenAndServe() return s.ListenAndServe()
} }
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