Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_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
cd90f610
authored
Sep 21, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
81d98087
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
9 deletions
cmd/cron_server.go
controller/sku_controller.go
pkg/common/function.go
pkg/gredis/redis.go
service/ly_service.go → service/service_ly.go
service/ziying_service.go → service/service_zy.go
service/service_zy_cron.go
cmd/cron_server.go
0 → 100644
View file @
cd90f610
package
main
import
(
"flag"
"goods_machining/boot"
)
func
main
()
{
var
path
string
flag
.
StringVar
(
&
path
,
"config"
,
"conf"
,
"配置文件"
)
var
mod
string
;
flag
.
StringVar
(
&
mod
,
"m"
,
"all"
,
"请输入模块id"
)
// 单独计算某个模块,默认计算全部,0计算全部
flag
.
Parse
()
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
panic
(
err
)
}
}
controller/sku_controller.go
View file @
cd90f610
...
...
@@ -10,7 +10,7 @@ import (
)
const
goods_slice_count
=
50
//每多少个型号id开启一个协程
const
goods_slice_count
=
1
//每多少个型号id开启一个协程
/*
查询商品详情(自营或者联营)
...
...
@@ -92,3 +92,6 @@ func Synchronization(c *gin.Context) {
common
.
Output
(
0
,
"查询成功"
,
GoodsRes
)
}
pkg/common/function.go
View file @
cd90f610
...
...
@@ -421,4 +421,7 @@ func MyFloat64ToStr(numb float64) string {
func
MyInt64ToStr
(
numb
int64
)
string
{
return
strconv
.
FormatInt
(
numb
,
10
)
}
func
MyIntToStr
(
i
int
)
string
{
return
strconv
.
Itoa
(
i
)
}
////////////类型转换/////////////////////
\ No newline at end of file
pkg/gredis/redis.go
View file @
cd90f610
...
...
@@ -73,27 +73,30 @@ eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
func
HgetPi
(
redisConn
*
redis
.
Conn
,
hkey
string
,
targetIds
[]
string
)
map
[
string
]
string
{
func
HgetPi
(
redisCon
string
,
hkey
string
,
targetIds
[]
string
)
map
[
string
]
string
{
redisConn
:=
Conn
(
redisCon
)
defer
redisConn
.
Close
()
skuArr
:=
make
(
map
[
string
]
string
,
0
)
if
len
(
targetIds
)
==
1
{
oneId
:=
targetIds
[
0
]
info
,
_
:=
String
((
*
redisConn
)
.
Do
(
"HGET"
,
hkey
,
oneId
))
info
,
err
:=
String
(
redisConn
.
Do
(
"HGET"
,
hkey
,
oneId
))
fmt
.
Print
(
err
)
if
info
==
""
{
skuArr
[
oneId
]
=
""
}
else
{
skuArr
[
oneId
]
=
info
}
fmt
.
Print
(
"单个获取"
)
return
skuArr
}
for
_
,
v
:=
range
targetIds
{
(
*
redisConn
)
.
Send
(
"HGet"
,
hkey
,
v
)
redisConn
.
Send
(
"HGet"
,
hkey
,
v
)
}
(
*
redisConn
)
.
Flush
()
redisConn
.
Flush
()
for
_
,
goods_id
:=
range
targetIds
{
info
,
_
:=
(
*
redisConn
)
.
Receive
()
info
,
_
:=
redisConn
.
Receive
()
if
info
==
nil
{
skuArr
[
goods_id
]
=
""
continue
;
...
...
service/
ly_service
.go
→
service/
service_ly
.go
View file @
cd90f610
File moved
service/
ziying_service
.go
→
service/
service_zy
.go
View file @
cd90f610
...
...
@@ -17,12 +17,14 @@ type ZiyingService struct {
*/
func
(
qs
*
ZiyingService
)
ZyGoodsDetail
(
goodsIds
[]
string
,
goodsRes
*
map
[
string
]
interface
{},
wg
*
sync
.
WaitGroup
)
{
defer
wg
.
Done
();
redisConn
:=
gredis
.
Conn
(
"search_r"
)
//
redisConn := gredis.Conn("search_r")
/////批量获取商品详情
skuArr
:=
gredis
.
HgetPi
(
&
redisConn
,
"Self_SelfGoods"
,
goodsIds
)
skuArr
:=
gredis
.
HgetPi
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
fmt
.
Print
(
skuArr
)
for
goods_id
,
info
:=
range
skuArr
{
A
:=
orderedmap
.
New
()
//初始化有序map,拼接data 数据
A
.
Set
(
"goods_id"
,
goods_id
)
A
.
Set
(
"goods_type"
,
gjson
.
Get
(
info
,
"goods_type"
)
.
Int
())
//查询总条数
...
...
service/service_zy_cron.go
0 → 100644
View file @
cd90f610
package
service
import
(
"fmt"
"github.com/tidwall/gjson"
"goods_machining/pkg/common"
"goods_machining/pkg/gredis"
"goods_machining/pkg/mysql"
)
// 自营定时任务服务
type
ZyCronService
struct
{
}
/*
计算自营折扣信息
*/
func
(
a
*
ZyCronService
)
ZyDiscount
(
goodsId
string
)
{
var
(
i
int
goodsIdTemp
string
dbSpu
=
mysql
.
Conn
(
"liexin_data"
)
//spu实例化链接
redisConn
=
gredis
.
Conn
(
"search_r"
)
)
defer
redisConn
.
Close
()
page_size
:=
1000
for
i
=
1
;
i
<=
1000
;
i
++
{
start
:=
0
;
if
i
==
1
{
start
=
0
;
}
else
{
start
=
(
i
-
1
)
*
page_size
}
sql
:=
"select goods_id from lie_goods where self_supplier_type = 1 and stock >0 limit "
+
common
.
MyIntToStr
(
page_size
)
+
","
+
common
.
MyIntToStr
(
start
);
if
goodsId
!=
""
{
sql
=
"select goods_id from lie_goods where self_supplier_type = 1 and stock >0 limit "
+
goodsId
;
}
goodsInfos
,
err
:=
dbSpu
.
QueryString
(
sql
)
if
err
!=
nil
||
len
(
goodsInfos
)
==
0
{
fmt
.
Print
(
"查询没有数据"
)
break
;
}
for
_
,
info
:=
range
goodsInfos
{
now_goods_id
:=
info
[
"goods_id"
]
/********开始计算系数******/
fmt
.
Println
(
"开始计算系数"
+
goodsIdTemp
)
goodsBatch
,
_
:=
gredis
.
String
(
redisConn
.
Do
(
"HGET"
,
"Self_goods_batch"
,
now_goods_id
))
//获取商品批次信息
apiGoodsList
:=
gjson
.
Get
(
goodsBatch
,
"dc_time"
)
.
Array
()
var
EarlyAddTime
int64
=
0
;
//最早的批次
for
_
,
goods
:=
range
apiGoodsList
{
dc_time
:=
goods
.
Get
(
"dc_time"
)
.
Int
()
if
EarlyAddTime
==
0
{
EarlyAddTime
=
dc_time
continue
;
}
if
dc_time
<
EarlyAddTime
{
EarlyAddTime
=
dc_time
}
}
if
EarlyAddTime
==
0
{
fmt
.
Println
(
"没有批次信息"
)
continue
;
}
}
//redisWrite.Do("HSET",config.Get("redis_all.BRAND_NAME_ALL").String(),brandkey,brandId)
}
}
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