Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
bom_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
90330ea2
authored
May 27, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
导出excel服务
parent
d2c46ed7
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
38 deletions
Bom_48.xlsx
cmd/cmd.exe~
configs/config.go
internal/logic/bom_matching.go
internal/service/oss.go
internal/service/xlsx.go
server/export.go
server/main.go
test/main.go
Bom_48.xlsx
View file @
90330ea2
No preview for this file type
cmd/cmd.exe~
View file @
90330ea2
The file could not be displayed because it is too large.
configs/config.go
View file @
90330ea2
...
...
@@ -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
}
...
...
internal/logic/bom_matching.go
View file @
90330ea2
...
...
@@ -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
)
...
...
internal/service/oss.go
View file @
90330ea2
...
...
@@ -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
}
internal/service/xlsx.go
View file @
90330ea2
...
...
@@ -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
...
...
server/export.go
View file @
90330ea2
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"
}
server/main.go
View file @
90330ea2
...
...
@@ -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
()
serv
ice
:=
rpc
.
NewHTTPService
()
serv
ice
.
AddFunction
(
"export"
,
Export
,
rpc
.
Options
{}
)
err
:=
http
.
ListenAndServe
(
":8080"
,
serv
ice
)
serv
er
:=
rpc
.
NewHTTPService
()
serv
er
.
AddFunction
(
"export"
,
Export
)
err
:=
http
.
ListenAndServe
(
":8080"
,
serv
er
)
if
err
!=
nil
{
panic
(
err
)
}
...
...
test/main.go
View file @
90330ea2
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
()
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment