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