Commit 90330ea2 by mushishixian

导出excel服务

parent d2c46ed7
No preview for this file type
The file could not be displayed because it is too large.
......@@ -73,6 +73,7 @@ func Setup(filePath string) {
mapTo("rabbitmq", RabbitMQSetting)
mapTo("es", ESSetting)
mapTo("api", ApiSetting)
mapTo("oss", OssSetting)
RedisSetting.IdleTimeout = RedisSetting.IdleTimeout * time.Second
}
......
......@@ -20,8 +20,10 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
tableEnd := string(bomIdStr[len(bomIdStr)-1])
tableName := "lie_bom_item_matching_" + tableEnd
var isBuyBomItemIdList, noBuyBomItemIdList []int
for _, matching := range matchingList {
time.Sleep(500 * time.Millisecond)
for key, matching := range matchingList {
if key == 0 || key == 1 || key == 2 {
time.Sleep(5 * time.Second)
}
//先去数据库查询是否存在该记录,有的话修改,没有就新增
var match model.BomItemMatching
model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match)
......
......@@ -12,17 +12,18 @@ import (
)
type Response struct {
Code int `json:"code"`
Message int `json:"message"`
Data interface{} `json:"data"`
Code int `json:"code"`
Message string `json:"message"`
Data []string `json:"data"`
}
func UploadToOss(path, fileType, key string) (err error) {
func UploadToOss(path, fileType string) (ossPath string, err error) {
if path == "" {
return nil
return
}
url := configs.ApiSetting.Upload
uploadKey := configs.OssSetting.UploadKey
fmt.Println(uploadKey)
now := time.Now().Unix()
nowStr := strconv.Itoa(int(now))
params := req.Param{
......@@ -41,17 +42,22 @@ func UploadToOss(path, fileType, key string) (err error) {
resp, err := req.Post(url, req.FileUpload{
File: file,
FieldName: "upload",
FileName: "Bom_48.xlsx",
}, params)
if err != nil {
return err
return
}
fmt.Println(resp.String())
var response Response
if err = resp.ToJSON(&response); err != nil {
return errors.New(resp.String())
err = errors.New(resp.String())
return
}
if response.Code != 200 {
err = errors.New(response.Message)
return
}
return nil
if len(response.Data) == 2 {
ossPath = response.Data[0]
}
return
}
......@@ -17,6 +17,8 @@ func Export(bomId int) (ossPath string, err error) {
return
}
t := time.Now()
bomIdStr := strconv.Itoa(bomId)
filePath := "Bom_" + bomIdStr + ".xlsx"
f := excelize.NewFile()
index := f.NewSheet("Sheet1")
f.SetActiveSheet(index)
......@@ -58,12 +60,12 @@ func Export(bomId int) (ossPath string, err error) {
f.SetCellStyle("Sheet1", "E"+keyStr, "E"+keyStr, style)
f.SetCellValue("Sheet1", "E"+keyStr, "参数可能不完整,客服 将与您进一步确认,或调整商品")
}
bomIdStr := strconv.Itoa(bomId)
err = f.SaveAs("Bom_" + bomIdStr + ".xlsx")
err = f.SaveAs(filePath)
if err != nil {
return
}
}
ossPath,err = UploadToOss(filePath, "xlsx")
elapsed := time.Since(t)
fmt.Println(elapsed)
return
......
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"
}
......@@ -3,20 +3,35 @@ package main
import (
"bom_server/configs"
"bom_server/internal/model"
"bom_server/internal/service"
"flag"
"github.com/hprose/hprose-golang/rpc"
"net/http"
)
func Export(bomId int) (result interface{}) {
ossPath, err := service.Export(bomId)
response := make(map[string]interface{})
if err != nil {
response["err_code"] = -1
response["err_msg"] = err.Error()
} else {
response["err_code"] = 0
response["err_msg"] = "ok"
response["data"] = ossPath
}
return response
}
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("export", Export, rpc.Options{})
err := http.ListenAndServe(":8080", service)
server := rpc.NewHTTPService()
server.AddFunction("export", Export)
err := http.ListenAndServe(":8080", server)
if err != nil {
panic(err)
}
......
package main
import (
"bom_server/configs"
"bom_server/internal/service"
"flag"
"fmt"
"github.com/hprose/hprose-golang/rpc"
"time"
)
type Stub struct {
......@@ -14,6 +12,7 @@ type Stub struct {
AsyncHello func(func(string, error), string) `name:"hello"`
}
func testHprose() {
client := rpc.NewClient("http://127.0.0.1:8080/")
var stub *Stub
......@@ -21,16 +20,20 @@ func testHprose() {
//stub.AsyncHello(func(result string, err error) {
// fmt.Println(result, err)
//}, "async world")
//fmt.Println(stub.Hello("sd"))
start:=time.Now()
fmt.Println(stub.Export(48))
fmt.Println(time.Now().Sub(start))
}
func main() {
var path string
flag.StringVar(&path, "config", "conf/config.ini", "../conf/config.ini")
flag.Parse()
configs.Setup(path)
//var path string
//flag.StringVar(&path, "config", "conf/config.ini", "../conf/config.ini")
//flag.Parse()
//configs.Setup(path)
//model.Setup()
//service.Export(48)
service.UploadToOss("sadsa", "xlsx", "123213")
//testHprose()
//osspath,err:=service.Export(48)
//fmt.Println(err)
//fmt.Println(osspath)
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