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/"
base = http://192.168.2.232:40001
goods = http://192.168.2.232:60004
upload = http://api.liexin.com/oss/upload
api_port = 60010
[oss]
upload_key = fh6y5t4rr351d2c3bryi
......@@ -22,4 +23,4 @@ push_url = http://192.168.1.237:1988/v1/push
[es]
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
\ No newline at end of file
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
......@@ -43,6 +43,7 @@ type RabbitMQ struct {
type Api struct {
Goods string `ini:"goods"`
Upload string `ini:"upload"`
ApiPort string `ini:"api_port"`
}
type Oss struct {
......
package logic
import (
"bom_server/configs"
"bom_server/internal/model"
"encoding/json"
"fmt"
es "gopkg.in/olivere/elastic.v5"
"strconv"
)
......@@ -13,7 +17,7 @@ func GetBomItems(bomId int) (bomItems []model.BomItem) {
return bomItems
}
func GetBomItem(bomId,bomItemId int)(bomItem model.BomItem) {
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).
......@@ -43,3 +47,44 @@ func UpdateNoMatchBomItem(bomItems []model.BomItem) (err error) {
}
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) {
return bomMatchings
}
//获取单个matching
func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) {
bomIdStr := strconv.FormatInt(int64(bomId), 10)
tableEnd := string(bomIdStr[len(bomIdStr)-1])
......@@ -23,8 +24,6 @@ func GetBomMatching(bomId, bomItemId int) (bomMatching model.BomItemMatching) {
return bomMatching
}
//根据matchingList去修改
func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err error) {
bomIdStr := strconv.FormatInt(int64(bomId), 10)
......@@ -52,14 +51,15 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
noBuyBomItemIdList = append(noBuyBomItemIdList, matching.BomItemID)
}
}
now := time.Now().Unix()
//分别去更新
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 {
return
}
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 {
return
}
......
......@@ -78,7 +78,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
}
defer client.Stop()
//第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, client, true)
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, sort, client, true)
if err != nil {
return
}
......@@ -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 {
return
}
......@@ -151,12 +151,6 @@ func UpdateSingleBomMatching(bomSn string, bomItemId int, goodsId string) (bomIt
return
}
//通过搜索去匹配单个matching
func SaveBomMatchingByGoodsName(bomId int, bomItemId int, goodsName string) (bomItemInfo model.BomItem, err error) {
return
}
//判断是否在里面
func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
for _, goodsMap := range goodsMapList {
......@@ -167,11 +161,15 @@ func checkInGoodsMap(bom model.BomItem, goodsMapList []GoodsMap) bool {
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 {
return
}
index := configs.ESSetting.GoodsIndexName
//如果是大陆收货(type=1),就要包含专卖和自营
if deliveryType == 1 {
index = index + ",zhuanmai,liexin_ziying"
}
search := client.MultiSearch().Index(index)
//多重搜索,第一次先去精确匹配
for _, bom := range bomItems {
......@@ -180,7 +178,7 @@ func getUpdateGoodsData(bomId int, bomItems []model.BomItem, deliveryType int, c
bom.GoodsName = common.SubKeyWordStr(bom.GoodsName)
}
//构建一个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)
}
res, err := search.Do(context.Background())
......@@ -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)
source := es.NewSearchSource().IndexBoost("liexin_ziying", 2).Query(query).
Sort("_score", false).Sort("sort", false).Sort("single_price", true).
From(0).Size(1)
Sort("_score", false).Sort("sort", false).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)
return searchRequest
}
......
......@@ -23,6 +23,7 @@ type Bom struct {
IsSyncCrm int `json:"is_sync_crm"`
// bom详情
BomItems []BomItem
Where string `json:"where"`
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
}
......@@ -50,24 +50,3 @@ func UpdateBomMatching(c *gin.Context) {
c.JSON(200, response)
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
import (
"bom_server/configs"
"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.POST("/bom/export", Export)
router.POST("/bom_matching/refresh", RefreshBomMatchingGoods)
router.POST("/bom_matching/update", UpdateBomMatching)
//router.GET("/config/list", ListConfigApi)
//router.POST("/config/rollback", RollbackConfigApi)
//服务器列表
//router.GET("/workers/list", ListWorkersApi)
router.POST("/bom_item/update", UpdateBomItem)
return router
}
func InitApiServer() (err error) {
router := InitRouter()
apiPort := strconv.Itoa(60010)
s := &http.Server{
Addr: ":" + apiPort,
Addr: ":" + configs.ApiSetting.ApiPort,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
......@@ -42,5 +29,3 @@ func InitApiServer() (err error) {
}
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