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
7d598cad
authored
May 27, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
处理数量规则
parent
10d1366d
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
141 additions
and
39 deletions
Book1.xlsx
cmd/cmd.exe~
internal/logic/bom.go
internal/logic/bom_matching.go
internal/logic/goods.go
internal/model/bom.go
internal/service/oss.go
internal/service/xlsx.go
test/main.go
Book1.xlsx
0 → 100644
View file @
7d598cad
No preview for this file type
cmd/cmd.exe~
View file @
7d598cad
The file could not be displayed because it is too large.
internal/logic/bom.go
View file @
7d598cad
...
...
@@ -7,9 +7,11 @@ import (
//根据bom_id查出bom表信息
func
GetBomInfo
(
bomId
int
)
(
bom
model
.
Bom
)
{
if
err
:=
model
.
Db
.
Where
(
"bom_id = ?"
,
bomId
)
.
First
(
&
bom
)
.
Error
;
err
!=
nil
{
err
:=
model
.
Db
.
Where
(
"bom_id = ?"
,
bomId
)
.
First
(
&
bom
)
.
Error
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
fmt
.
Println
(
err
)
return
bom
}
...
...
@@ -23,3 +25,12 @@ func GetBomInfoWithItems(bomId int) (bom model.Bom) {
bom
.
BomItems
=
bomItems
return
bom
}
func
GetBomCompleteInfo
(
bomId
int
)
(
bom
model
.
Bom
)
{
bom
=
GetBomInfo
(
bomId
)
bomItems
:=
GetBomItems
(
bomId
)
bom
.
BomItems
=
bomItems
bomMatchings
:=
GetBomMatchings
(
bomId
)
bom
.
BomIMatchings
=
bomMatchings
return
bom
}
internal/logic/bom_matching.go
View file @
7d598cad
...
...
@@ -6,6 +6,14 @@ import (
"time"
)
//根据bom_id查出bom表信息
func
GetBomMatchings
(
bomId
int
)
(
bomMatchings
[]
model
.
BomItemMatching
)
{
bomIdStr
:=
strconv
.
FormatInt
(
int64
(
bomId
),
10
)
tableEnd
:=
string
(
bomIdStr
[
len
(
bomIdStr
)
-
1
])
model
.
Db
.
Table
(
"lie_bom_item_matching_"
+
tableEnd
)
.
Where
(
"bom_id = ?"
,
bomId
)
.
Find
(
&
bomMatchings
)
return
bomMatchings
}
//根据matchingList去修改
func
BatchSaveMatchings
(
bomId
int
,
matchingList
[]
model
.
BomItemMatching
)
(
err
error
)
{
bomIdStr
:=
strconv
.
FormatInt
(
int64
(
bomId
),
10
)
...
...
internal/logic/goods.go
View file @
7d598cad
...
...
@@ -77,6 +77,20 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
Status
:
goods
.
Status
,
AddTime
:
int
(
time
.
Now
()
.
Unix
()),
}
/**
数量处理:
1.要满足最小起订量
2.数量要是满足倍数的规则
*/
if
goodsMap
.
Number
<
goods
.
Moq
{
bomMatching
.
Number
=
goods
.
Moq
}
else
{
//不满足倍数规则,则要去帮它按倍数取
if
(
goodsMap
.
Number
%
goods
.
Mpq
)
!=
0
{
bomMatching
.
Number
=
((
goodsMap
.
Number
/
goods
.
Mpq
)
+
1
)
*
goods
.
Mpq
}
}
//阶梯价处理
if
len
(
goods
.
LadderPrice
)
>
0
{
ladderPriceStr
,
err
:=
json
.
Marshal
(
goods
.
LadderPrice
)
...
...
internal/model/bom.go
View file @
7d598cad
...
...
@@ -23,6 +23,7 @@ type Bom struct {
IsSyncCrm
int
`json:"is_sync_crm"`
// bom详情
BomItems
[]
BomItem
BomIMatchings
[]
BomItemMatching
}
type
BomMessage
struct
{
...
...
internal/service/oss.go
View file @
7d598cad
...
...
@@ -35,7 +35,7 @@ func UploadToOss(path, fileType, k1, key string) (err error) {
return
errors
.
New
(
resp
.
String
())
}
if
response
.
Code
!=
200
{
return
return
}
return
nil
}
internal/service/xlsx.go
View file @
7d598cad
package
service
import
(
"bom_server/internal/logic"
"bom_server/internal/model"
"errors"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"math/rand"
"strconv"
"time"
)
func
init
()
{
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
}
var
letterRunes
=
[]
rune
(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
)
func
RandStringRunes
(
n
int
)
string
{
b
:=
make
([]
rune
,
n
)
for
i
:=
range
b
{
b
[
i
]
=
letterRunes
[
rand
.
Intn
(
len
(
letterRunes
))]
}
return
string
(
b
)
}
//导出excel
func
Export
()
{
func
Export
(
bomId
int
)
(
err
error
)
{
bomItemXlsxData
,
err
:=
getBomData
(
bomId
)
if
err
!=
nil
{
return
err
}
t
:=
time
.
Now
()
f
:=
excelize
.
NewFile
()
// Create a new sheet.
str
:=
RandStringRunes
(
10
)
index
:=
f
.
NewSheet
(
"Sheet1"
)
for
i
:=
1
;
i
<=
200
;
i
++
{
// Set value of a cell.
temp
:=
strconv
.
FormatInt
(
int64
(
i
),
10
)
f
.
SetCellValue
(
"Sheet1"
,
"A"
+
temp
,
str
)
f
.
SetCellValue
(
"Sheet1"
,
"B"
+
temp
,
str
)
}
f
.
SetActiveSheet
(
index
)
// Save xlsx file by the given path.
if
err
:=
f
.
SaveAs
(
"Book1"
+
str
+
".xlsx"
);
err
!=
nil
{
fmt
.
Println
(
err
)
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
.
SetCellValue
(
"Sheet1"
,
"A1"
,
"序号"
)
f
.
SetCellValue
(
"Sheet1"
,
"B1"
,
"需求型号"
)
f
.
SetCellValue
(
"Sheet1"
,
"C1"
,
"数量"
)
f
.
SetCellValue
(
"Sheet1"
,
"D1"
,
"品牌"
)
f
.
SetCellValue
(
"Sheet1"
,
"E1"
,
"推荐型号"
)
f
.
SetCellValue
(
"Sheet1"
,
"F1"
,
"供应商"
)
f
.
SetCellValue
(
"Sheet1"
,
"G1"
,
"库存"
)
f
.
SetCellValue
(
"Sheet1"
,
"H1"
,
"起订"
)
f
.
SetCellValue
(
"Sheet1"
,
"I1"
,
"MPQ"
)
f
.
SetCellValue
(
"Sheet1"
,
"J1"
,
"货期(工作日)"
)
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"
])
f
.
SetCellValue
(
"Sheet1"
,
"C"
+
keyStr
,
xlsxData
[
"number"
])
f
.
SetCellValue
(
"Sheet1"
,
"D"
+
keyStr
,
xlsxData
[
"brand_name"
])
if
xlsxData
[
"recommend_goods_name"
]
!=
""
{
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"
,
"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
)
f
.
SetCellValue
(
"Sheet1"
,
"E"
+
keyStr
,
"参数可能不完整,客服 将与您进一步确认,或调整商品"
)
}
if
err
:=
f
.
SaveAs
(
"Book1"
+
".xlsx"
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
elapsed
:=
time
.
Since
(
t
)
fmt
.
Println
(
elapsed
)
return
nil
}
func
getBomData
(
bomId
int
)
(
bomItemXlsxData
[]
map
[
string
]
interface
{},
err
error
)
{
//先去找出bom相关的item
bom
:=
logic
.
GetBomCompleteInfo
(
bomId
)
if
len
(
bom
.
BomItems
)
==
0
{
err
=
errors
.
New
(
"没有商品的bom单"
)
return
}
bomItems
:=
bom
.
BomItems
bomMatchings
:=
bom
.
BomIMatchings
bomItemXlsxData
=
make
([]
map
[
string
]
interface
{},
200
)
//组装数据
if
len
(
bomItems
)
==
0
{
err
=
errors
.
New
(
"导出bom单不存在商品"
)
return
}
for
k
,
bomItem
:=
range
bomItems
{
for
_
,
bomMatching
:=
range
bomMatchings
{
if
bomItem
.
BomItemID
==
bomMatching
.
BomItemID
{
bomItemXlsxData
[
k
]
=
map
[
string
]
interface
{}{
"no"
:
k
+
1
,
"goods_name"
:
bomItem
.
GoodsName
,
"number"
:
bomItem
.
Number
,
"brand_name"
:
bomItem
.
BrandName
,
"recommend_goods_name"
:
bomMatching
.
GoodsName
,
"supplier_name"
:
bomMatching
.
SupplierName
,
"stock"
:
bomMatching
.
Stock
,
"moq"
:
bomMatching
.
Moq
,
"mpq"
:
bomMatching
.
Mpq
,
"delivery"
:
bomMatching
.
Delivery
,
"price"
:
bomMatching
.
Price
,
"total"
:
bomMatching
.
Number
,
}
}
}
}
return
}
func
checkInBomItem
(
bomItemId
int
,
bomItems
[]
model
.
BomItem
)
bool
{
for
_
,
bomItem
:=
range
bomItems
{
if
bomItemId
==
bomItem
.
BomItemID
{
return
true
}
}
}
test/main.go
View file @
7d598cad
package
main
import
(
"bom_server/configs"
"bom_server/internal/model"
"bom_server/internal/service"
"flag"
"fmt"
"time"
"github.com/hprose/hprose-golang/rpc"
)
...
...
@@ -24,9 +25,10 @@ func testHprose() {
}
func
main
()
{
for
i
:=
0
;
i
<
100
;
i
++
{
go
service
.
Export
()
}
fmt
.
Println
(
21321
)
time
.
Sleep
(
100
*
time
.
Second
)
var
path
string
flag
.
StringVar
(
&
path
,
"config"
,
"conf/config.ini"
,
"../conf/config.ini"
)
flag
.
Parse
()
configs
.
Setup
(
path
)
model
.
Setup
()
service
.
Export
(
48
)
}
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