Commit d2c46ed7 by mushishixian

优化

parent 7d598cad
No preview for this file type
No preview for this file type
The file could not be displayed because it is too large.
...@@ -14,16 +14,16 @@ type RecvPro struct { ...@@ -14,16 +14,16 @@ type RecvPro struct {
} }
func init() { func init() {
queueExchange := rabbitmq.QueueExchange{ //queueExchange := rabbitmq.QueueExchange{
"bom_match", // "bom_match",
"bom_match", // "bom_match",
"bom", // "bom",
"direct", // "direct",
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/", // "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
} //}
//
str := `{"bom_id":48,"delivery_type":1,"sort_type":1}` //str := `{"bom_id":141,"delivery_type":1,"sort_type":1}`
rabbitmq.Send(queueExchange, str) //rabbitmq.Send(queueExchange, str)
} }
func (t *RecvPro) Consumer(dataByte []byte) (err error) { func (t *RecvPro) Consumer(dataByte []byte) (err error) {
......
...@@ -12,7 +12,10 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/" ...@@ -12,7 +12,10 @@ url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
[api] [api]
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.net upload = http://api.liexin.com/oss/upload
[oss]
upload_key = fh6y5t4rr351d2c3bryi
[falcon] [falcon]
push_url = http://192.168.1.237:1988/v1/push push_url = http://192.168.1.237:1988/v1/push
......
[database] [database]
username = root user_name = root
password = root password = root
host = 192.168.2.250 host = 192.168.2.239
database = lie_scm_wms_sync database = lie_bom
table_prefix = lie_
type = mysql
[rabbitmq] [rabbitmq]
url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/" url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
[api] [api]
base = http://192.168.2.232:40001 base = http://192.168.2.232:40001
goods = http://192.168.2.232:60004
upload = http://api.liexin.net
[oss]
upload_key = fh6y5t4rr351d2c3bryi
[falcon] [falcon]
push_url = http://192.168.1.237:1988/v1/push 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
...@@ -45,11 +45,16 @@ type Api struct { ...@@ -45,11 +45,16 @@ type Api struct {
Upload string `ini:"upload"` Upload string `ini:"upload"`
} }
type Oss struct {
UploadKey string `ini:"upload_key"`
}
var DatabaseSetting = &Database{} var DatabaseSetting = &Database{}
var RedisSetting = &Redis{} var RedisSetting = &Redis{}
var RabbitMQSetting = &RabbitMQ{} var RabbitMQSetting = &RabbitMQ{}
var ESSetting = &ES{} var ESSetting = &ES{}
var ApiSetting = &Api{} var ApiSetting = &Api{}
var OssSetting = &Oss{}
var ( var (
cfg *ini.File cfg *ini.File
......
...@@ -34,3 +34,11 @@ func GetBomCompleteInfo(bomId int) (bom model.Bom) { ...@@ -34,3 +34,11 @@ func GetBomCompleteInfo(bomId int) (bom model.Bom) {
bom.BomIMatchings = bomMatchings bom.BomIMatchings = bomMatchings
return bom return bom
} }
//更新没有匹配的到bom详情
func UpdateBomMatchStatus(bomId int) (err error) {
isMatchStatus := 1
err = model.Db.Table("lie_bom").Where("bom_id = ? ", bomId).
Updates(map[string]interface{}{"is_match": isMatchStatus}).Error
return err
}
...@@ -21,6 +21,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -21,6 +21,7 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
tableName := "lie_bom_item_matching_" + tableEnd tableName := "lie_bom_item_matching_" + tableEnd
var isBuyBomItemIdList, noBuyBomItemIdList []int var isBuyBomItemIdList, noBuyBomItemIdList []int
for _, matching := range matchingList { for _, matching := range matchingList {
time.Sleep(500 * time.Millisecond)
//先去数据库查询是否存在该记录,有的话修改,没有就新增 //先去数据库查询是否存在该记录,有的话修改,没有就新增
var match model.BomItemMatching var match model.BomItemMatching
model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match) model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match)
......
...@@ -65,6 +65,7 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -65,6 +65,7 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
BrandName: goods.BrandName, BrandName: goods.BrandName,
GoodsType: goods.GoodsType, GoodsType: goods.GoodsType,
SupplierID: goods.SupplierID, SupplierID: goods.SupplierID,
Pdf: goods.Pdf,
SupplierName: goods.SupplierName, SupplierName: goods.SupplierName,
Delivery: delivery, Delivery: delivery,
DeliveryType: goodsMap.DeliveryType, DeliveryType: goodsMap.DeliveryType,
......
...@@ -59,7 +59,8 @@ func MatchGoods(message model.BomMessage) (err error) { ...@@ -59,7 +59,8 @@ func MatchGoods(message model.BomMessage) (err error) {
}() }()
} }
wg.Wait() wg.Wait()
return nil //全部处理完以后要去修改主表的同步状态
return UpdateBomMatchStatus(bomId)
//return SearchGoods(bomId, bomItems) //return SearchGoods(bomId, bomItems)
} }
...@@ -79,7 +80,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -79,7 +80,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg
//第一次先去精确匹配 //第一次先去精确匹配
goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, client, true) goodsMapList, err := getUpdateGoodsData(bomId, bomItems, deliveryType, client, true)
if err != nil { if err != nil {
fmt.Println(err) return
} }
//要删除已经精确匹配过的bomItem //要删除已经精确匹配过的bomItem
var fuzzyBomItems []model.BomItem var fuzzyBomItems []model.BomItem
...@@ -91,7 +92,7 @@ func SearchGoods(bomId int, bomItems []model.BomItem, deliveryType, sort int, wg ...@@ -91,7 +92,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, client, true)
if err != nil { if err != nil {
fmt.Println(err) return
} }
//再删除模糊匹配到的数据,就得到完全没有匹配的数据了 //再删除模糊匹配到的数据,就得到完全没有匹配的数据了
var notMatchBomItems []model.BomItem var notMatchBomItems []model.BomItem
......
...@@ -23,6 +23,7 @@ type BomItemMatching struct { ...@@ -23,6 +23,7 @@ type BomItemMatching struct {
DeliveryType int `json:"delivery_type"` DeliveryType int `json:"delivery_type"`
Number int `json:"number"` Number int `json:"number"`
Price float64 `json:"price"` Price float64 `json:"price"`
Pdf string `json:"pdf"`
// Stock 库存 // Stock 库存
Stock int `json:"stock"` Stock int `json:"stock"`
// Moq 起订量 // Moq 起订量
......
...@@ -3,33 +3,49 @@ package service ...@@ -3,33 +3,49 @@ package service
import ( import (
"bom_server/configs" "bom_server/configs"
"errors" "errors"
"fmt"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/syyongx/php2go" "github.com/syyongx/php2go"
"os"
"strconv" "strconv"
"time" "time"
) )
type Response struct { type Response struct {
Code int `json:"code"` Code int `json:"code"`
Message int `json:"message"`
Data interface{} `json:"data"`
} }
func UploadToOss(path, fileType, k1, key string) (err error) { func UploadToOss(path, fileType, key string) (err error) {
if path == "" { if path == "" {
return nil return nil
} }
url := configs.ApiSetting.Upload url := configs.ApiSetting.Upload
uploadKey := "1232" uploadKey := configs.OssSetting.UploadKey
md5Input := strconv.FormatInt(time.Now().Unix(), 10) now := time.Now().Unix()
nowStr := strconv.Itoa(int(now))
params := req.Param{ params := req.Param{
"source": 1, "source": 1,
"k1": time.Now().Unix(), "k1": now,
"k2": php2go.Md5(php2go.Md5(md5Input)) + uploadKey, "k2": php2go.Md5(php2go.Md5(nowStr) + uploadKey),
"FileType": fileType, "FileType": fileType,
} }
resp, err := req.Post(url, params) req.Debug = true
file, err := os.Open("Bom_48.xlsx")
defer file.Close()
if err != nil {
fmt.Println(err)
return
}
resp, err := req.Post(url, req.FileUpload{
File: file,
FieldName: "upload",
}, params)
if err != nil { if err != nil {
return err return err
} }
fmt.Println(resp.String())
var response Response var response Response
if err = resp.ToJSON(&response); err != nil { if err = resp.ToJSON(&response); err != nil {
return errors.New(resp.String()) return errors.New(resp.String())
......
...@@ -11,18 +11,20 @@ import ( ...@@ -11,18 +11,20 @@ import (
) )
//导出excel //导出excel
func Export(bomId int) (err error) { func Export(bomId int) (ossPath string, err error) {
bomItemXlsxData, err := getBomData(bomId) bomItemXlsxData, err := getBomData(bomId)
if err != nil { if err != nil {
return err return
} }
t := time.Now() t := time.Now()
f := excelize.NewFile() f := excelize.NewFile()
index := f.NewSheet("Sheet1") index := f.NewSheet("Sheet1")
f.SetActiveSheet(index)
f.SetColWidth("Sheet1", "B", "B", 20) f.SetColWidth("Sheet1", "B", "B", 20)
f.SetColWidth("Sheet1", "D", "E", 20) f.SetColWidth("Sheet1", "D", "E", 20)
f.SetColWidth("Sheet1", "F", "F", 20) f.SetColWidth("Sheet1", "F", "F", 20)
f.SetColWidth("Sheet1", "J", "J", 20) f.SetColWidth("Sheet1", "J", "J", 20)
f.SetColWidth("Sheet1", "L", "L", 20)
f.SetCellValue("Sheet1", "A1", "序号") f.SetCellValue("Sheet1", "A1", "序号")
f.SetCellValue("Sheet1", "B1", "需求型号") f.SetCellValue("Sheet1", "B1", "需求型号")
f.SetCellValue("Sheet1", "C1", "数量") f.SetCellValue("Sheet1", "C1", "数量")
...@@ -36,7 +38,6 @@ func Export(bomId int) (err error) { ...@@ -36,7 +38,6 @@ func Export(bomId int) (err error) {
f.SetCellValue("Sheet1", "K1", "单价") f.SetCellValue("Sheet1", "K1", "单价")
f.SetCellValue("Sheet1", "L1", "小计") f.SetCellValue("Sheet1", "L1", "小计")
for k, xlsxData := range bomItemXlsxData { for k, xlsxData := range bomItemXlsxData {
f.SetActiveSheet(index)
keyStr := strconv.FormatInt(int64(k+2), 10) keyStr := strconv.FormatInt(int64(k+2), 10)
f.SetCellValue("Sheet1", "A"+keyStr, xlsxData["no"]) f.SetCellValue("Sheet1", "A"+keyStr, xlsxData["no"])
f.SetCellValue("Sheet1", "B"+keyStr, xlsxData["goods_name"]) f.SetCellValue("Sheet1", "B"+keyStr, xlsxData["goods_name"])
...@@ -46,23 +47,26 @@ func Export(bomId int) (err error) { ...@@ -46,23 +47,26 @@ func Export(bomId int) (err error) {
f.SetCellValue("Sheet1", "E"+keyStr, xlsxData["recommend_goods_name"]) f.SetCellValue("Sheet1", "E"+keyStr, xlsxData["recommend_goods_name"])
f.SetCellValue("Sheet1", "F"+keyStr, xlsxData["supplier_name"]) f.SetCellValue("Sheet1", "F"+keyStr, xlsxData["supplier_name"])
f.SetCellValue("Sheet1", "G"+keyStr, xlsxData["stock"]) f.SetCellValue("Sheet1", "G"+keyStr, xlsxData["stock"])
f.SetCellValue("Sheet1", "H"+keyStr, xlsxData["MOQ"]) f.SetCellValue("Sheet1", "H"+keyStr, xlsxData["moq"])
f.SetCellValue("Sheet1", "I"+keyStr, xlsxData["MPQ"]) f.SetCellValue("Sheet1", "I"+keyStr, xlsxData["mpq"])
f.SetCellValue("Sheet1", "J"+keyStr, xlsxData["delivery"]) f.SetCellValue("Sheet1", "J"+keyStr, xlsxData["delivery"])
f.SetCellValue("Sheet1", "K"+keyStr, xlsxData["price"]) f.SetCellValue("Sheet1", "K"+keyStr, xlsxData["price"])
f.SetCellValue("Sheet1", "L"+keyStr, xlsxData["total"]) f.SetCellValue("Sheet1", "L"+keyStr, xlsxData["total"])
} else { } else {
fmt.Println(xlsxData)
f.MergeCell("Sheet1", "E"+keyStr, "L"+keyStr) f.MergeCell("Sheet1", "E"+keyStr, "L"+keyStr)
style, _ := f.NewStyle(`{"font":{"color":"#D3281E"}}`)
f.SetCellStyle("Sheet1", "E"+keyStr, "E"+keyStr, style)
f.SetCellValue("Sheet1", "E"+keyStr, "参数可能不完整,客服 将与您进一步确认,或调整商品") f.SetCellValue("Sheet1", "E"+keyStr, "参数可能不完整,客服 将与您进一步确认,或调整商品")
} }
if err := f.SaveAs("Book1" + ".xlsx"); err != nil { bomIdStr := strconv.Itoa(bomId)
fmt.Println(err) err = f.SaveAs("Bom_" + bomIdStr + ".xlsx")
if err != nil {
return
} }
} }
elapsed := time.Since(t) elapsed := time.Since(t)
fmt.Println(elapsed) fmt.Println(elapsed)
return nil return
} }
func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error) { func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error) {
...@@ -82,11 +86,17 @@ func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error) ...@@ -82,11 +86,17 @@ func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error)
} }
for k, bomItem := range bomItems { for k, bomItem := range bomItems {
for _, bomMatching := range bomMatchings { for _, bomMatching := range bomMatchings {
var total interface{}
total = float64(bomMatching.Number) * bomMatching.Price
if bomMatching.Number > bomMatching.Stock {
total = "库存不足"
}
if bomItem.BomItemID == bomMatching.BomItemID { if bomItem.BomItemID == bomMatching.BomItemID {
//处理小计
bomItemXlsxData[k] = map[string]interface{}{ bomItemXlsxData[k] = map[string]interface{}{
"no": k + 1, "no": k + 1,
"goods_name": bomItem.GoodsName, "goods_name": bomItem.GoodsName,
"number": bomItem.Number, "number": bomMatching.Number,
"brand_name": bomItem.BrandName, "brand_name": bomItem.BrandName,
"recommend_goods_name": bomMatching.GoodsName, "recommend_goods_name": bomMatching.GoodsName,
"supplier_name": bomMatching.SupplierName, "supplier_name": bomMatching.SupplierName,
...@@ -95,7 +105,17 @@ func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error) ...@@ -95,7 +105,17 @@ func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error)
"mpq": bomMatching.Mpq, "mpq": bomMatching.Mpq,
"delivery": bomMatching.Delivery, "delivery": bomMatching.Delivery,
"price": bomMatching.Price, "price": bomMatching.Price,
"total": bomMatching.Number, "total": total,
}
}
// 处理没有匹配到的数据
if !checkInBomItem(bomItem.BomItemID, bomMatchings) {
bomItemXlsxData[k] = map[string]interface{}{
"no": k + 1,
"goods_name": bomItem.GoodsName,
"number": bomMatching.Number,
"brand_name": bomItem.BrandName,
"recommend_goods_name": "",
} }
} }
} }
...@@ -103,10 +123,11 @@ func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error) ...@@ -103,10 +123,11 @@ func getBomData(bomId int) (bomItemXlsxData []map[string]interface{}, err error)
return return
} }
func checkInBomItem(bomItemId int, bomItems []model.BomItem) bool { func checkInBomItem(bomItemId int, bomMatchings []model.BomItemMatching) bool {
for _, bomItem := range bomItems { for _, bomItem := range bomMatchings {
if bomItemId == bomItem.BomItemID { if bomItemId == bomItem.BomItemID {
return true return true
} }
} }
return false
} }
package main
import (
"bom_server/internal/service"
"fmt"
)
func Export(bomId int)(result interface{}) {
ossPath, err := service.Export(bomId)
if err!=nil {
return err
}
fmt.Println(ossPath)
return "12123"
}
package main package main
import ( import (
"net/http" "bom_server/configs"
"bom_server/internal/model"
"flag"
"github.com/hprose/hprose-golang/rpc" "github.com/hprose/hprose-golang/rpc"
"net/http"
) )
func hello(name string) string {
return "Hello " + name + "!"
}
func export(bomId int) {
}
func main() { func main() {
var path string
flag.StringVar(&path, "config", "conf/config.ini", "../conf/config.ini")
flag.Parse()
configs.Setup(path)
model.Setup()
service := rpc.NewHTTPService() service := rpc.NewHTTPService()
service.AddFunction("hello", hello, rpc.Options{}) service.AddFunction("export", Export, rpc.Options{})
http.ListenAndServe(":8080", service) err := http.ListenAndServe(":8080", service)
if err != nil {
panic(err)
}
} }
...@@ -2,7 +2,6 @@ package main ...@@ -2,7 +2,6 @@ package main
import ( import (
"bom_server/configs" "bom_server/configs"
"bom_server/internal/model"
"bom_server/internal/service" "bom_server/internal/service"
"flag" "flag"
"fmt" "fmt"
...@@ -11,6 +10,7 @@ import ( ...@@ -11,6 +10,7 @@ import (
type Stub struct { type Stub struct {
Hello func(string) (string, error) Hello func(string) (string, error)
Export func(int) interface{}
AsyncHello func(func(string, error), string) `name:"hello"` AsyncHello func(func(string, error), string) `name:"hello"`
} }
...@@ -18,10 +18,10 @@ func testHprose() { ...@@ -18,10 +18,10 @@ func testHprose() {
client := rpc.NewClient("http://127.0.0.1:8080/") client := rpc.NewClient("http://127.0.0.1:8080/")
var stub *Stub var stub *Stub
client.UseService(&stub) client.UseService(&stub)
stub.AsyncHello(func(result string, err error) { //stub.AsyncHello(func(result string, err error) {
fmt.Println(result, err) // fmt.Println(result, err)
}, "async world") //}, "async world")
fmt.Println(stub.Hello("world")) fmt.Println(stub.Export(48))
} }
func main() { func main() {
...@@ -29,6 +29,8 @@ func main() { ...@@ -29,6 +29,8 @@ func main() {
flag.StringVar(&path, "config", "conf/config.ini", "../conf/config.ini") flag.StringVar(&path, "config", "conf/config.ini", "../conf/config.ini")
flag.Parse() flag.Parse()
configs.Setup(path) configs.Setup(path)
model.Setup() //model.Setup()
service.Export(48) //service.Export(48)
service.UploadToOss("sadsa", "xlsx", "123213")
//testHprose()
} }
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