Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wang
/
go_supplier_task
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
8936a131
authored
Mar 16, 2021
by
wang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
更改一些bug
parent
46e21aca
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
11 deletions
cmd/cron/merge/cron.go
conf/dev/database.ini
model/ly_sku_entity.go
resources/erpSupplierZy.csv
service/service_ly.go
service/service_mapping.go
cmd/cron/merge/cron.go
View file @
8936a131
...
...
@@ -22,6 +22,8 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
panic
(
err
)
}
//service.NewServiceSupplier().MergerCriteria()
//return
//service.NewServiceLy().Merger()
//service.NewErpService().SyncErp()
//return
...
...
conf/dev/database.ini
View file @
8936a131
[xorm]
ShowSQL
=
tru
e
ShowSQL
=
fals
e
[pool_class]
user_name
=
root
...
...
model/ly_sku_entity.go
View file @
8936a131
...
...
@@ -13,7 +13,7 @@ type LySkuEntity struct {
GoodsId
string
`json:"goods_id"`
Encoded
string
`json:"encoded"`
//内部编码
Canal
string
`json:"canal" form:"canal" `
//供应商编码-渠道标签
UpdateTime
int
`json:"update_time" xorm:"
cre
ated"`
UpdateTime
int
`json:"update_time" xorm:"
upd
ated"`
}
//将 LySkuEntity 的值赋值到 SkuRedisInfo(两个结构字段和类型不一样不会赋值)
...
...
resources/erpSupplierZy.csv
View file @
8936a131
...
...
@@ -562,7 +562,7 @@
6297,深圳市禾耀科技发展有限公司,深圳市禾耀科技发展有限公司,ZY0000015,,代理,
6301,深圳市鸿源精密器材有限公司,深圳市鸿源精密器材有限公司,ZY0000220,,原厂,
6311,深圳市因德尔科技有限公司,深圳市因德尔科技有限公司,ZY0000230,,代理,
6327,深圳市同泰科技有限公司,深圳市同泰科技有限公司,ZY0000270,,代理,
6333,山东宝乘电子有限公司,山东宝乘电子有限公司,ZY0000261,,原厂,
6363,深圳市天微电子股份有限公司,深圳市天微电子股份有限公司,ZY0000057,,原厂,
6385,深圳市金碧电子科技有限公司,深圳市金碧电子科技有限公司,ZY0000121,,代理,
...
...
service/service_ly.go
View file @
8936a131
package
service
/**
(9462, 'L0009462', 'SURLINK INTERNATIONAL LTD', 'L0007633', '', 1, 0, 0, 0, '', 1, '', 0, 0, 0, 1368, 0, 2, 0, 10141, 10141, 0, 0, '', '', '', '', '', '', '1.00', '1.00', 1, 0),
(9463, 'L0009463', 'UNICHEER TECHNOLOGY CO.,LIMITED', 'L0007648', '', 1, 0, 0, 0, '', 1, '', 0, 0, 0, 1368, 0, 2, 1, 10141,
*/
import
(
"encoding/json"
"fmt"
...
...
@@ -10,6 +15,7 @@ import (
"go_supplier_task/pkg/common"
syncLog
"go_supplier_task/pkg/logger/sync"
"go_supplier_task/pkg/mysql"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"strings"
"time"
...
...
@@ -37,16 +43,20 @@ func (this *ServiceLy) Merger() {
maxNumTable
:=
10
maxNumDataBase
:=
10
for
dataBaseNum
:=
0
;
dataBaseNum
<
maxNumDataBase
;
dataBaseNum
++
{
common
.
PrintStdout
()
.
Printf
(
"%s,第%d个数据库开始"
,
LyTaskName
,
dataBaseNum
)
for
tableNum
:=
0
;
tableNum
<
maxNumTable
;
tableNum
++
{
common
.
PrintStdout
()
.
Printf
(
"%s,第%d个表开始"
,
LyTaskName
,
tableNum
)
dataBaseConn
:=
fmt
.
Sprintf
(
"sku_%d"
,
dataBaseNum
)
tableName
:=
fmt
.
Sprintf
(
"lie_sku_%d"
,
tableNum
)
skuDb
:=
mysql
.
Conn
(
dataBaseConn
)
//连接
totalNum
,
err
:=
skuDb
.
Table
(
tableName
)
.
Where
(
"supplier_id=? and canal!=''"
,
17
)
.
Count
()
//countRes,err:=skuDb.QueryString("SELECT count(*) count from ? where supplier_id=? and canal!=''",tableName,17)
if
err
!=
nil
{
syncLog
.
SyncInsertLog
(
"ly_merger"
,
LyTaskName
+
"查询sku出错,err:"
+
err
.
Error
())
panic
(
nil
)
}
common
.
PrintStdout
()
.
Printf
(
"%s,||||||||||||||||||||||第%d个库第%d个表开始,需处理数据%d条||||||||||||
\n
"
,
LyTaskName
,
dataBaseNum
,
tableNum
,
totalNum
)
goodsId
:=
int64
(
0
)
for
{
count
:=
0
lYSkuEntity
:=
&
model
.
LySkuEntity
{}
rows
,
err
:=
skuDb
.
Table
(
tableName
)
.
Where
(
"goods_id>? and supplier_id=? and canal!=''"
,
goodsId
,
17
)
.
OrderBy
(
"goods_id"
,)
.
Limit
(
10
)
.
Rows
(
lYSkuEntity
)
if
err
!=
nil
{
...
...
@@ -61,6 +71,7 @@ func (this *ServiceLy) Merger() {
}
count
++
goodsId
=
gconv
.
Int64
(
lYSkuEntity
.
GoodsId
)
common
.
PrintStdout
()
.
Printf
(
"%s,goodsid:%d 处理中
\n
"
,
LyTaskName
,
goodsId
)
this
.
updateDBRedisMongo
(
lYSkuEntity
,
skuDb
,
tableName
)
//修改redis、mongoDb、mysqldb、日志
}
if
(
count
==
0
){
...
...
@@ -124,14 +135,23 @@ func (this *ServiceLy) updateDBRedisMongo(lySkuEntity *model.LySkuEntity,dbconn
update
:=
bson
.
M
{
"canal"
:
canal
}
err
=
skuCache
.
MongoUpdateSku
(
lySkuEntity
.
GoodsId
,
update
)
if
(
err
!=
nil
){
msg
:=
fmt
.
Sprintf
(
"%s 修改mongosku数据出错,goodsId:%s,err:%s,updateData:%s"
,
LyTaskName
,
lySkuEntity
.
GoodsId
,
err
.
Error
(),
update
)
syncLog
.
SyncInsertLog
(
"ly_merger"
,
msg
)
if
(
err
==
mgo
.
ErrNotFound
){
msg
:=
fmt
.
Sprintf
(
"%s 在mongo sku不存在,goodsId:%s,err:%s,updateData:%s"
,
LyTaskName
,
lySkuEntity
.
GoodsId
,
err
.
Error
(),
update
)
syncLog
.
SyncInsertLog
(
"ly_merger"
,
msg
)
}
else
{
msg
:=
fmt
.
Sprintf
(
"%s 修改mongosku数据出错,goodsId:%s,err:%s,updateData:%s"
,
LyTaskName
,
lySkuEntity
.
GoodsId
,
err
.
Error
(),
update
)
syncLog
.
SyncInsertLog
(
"ly_merger"
,
msg
)
}
//回滚redis
common
.
PrintStdout
()
.
Printf
(
"因mongodb错误,正在回滚redis
\n
"
)
oldSkuRedisInfoMap
[
"canal"
]
=
lySkuEntity
.
Canal
this
.
insertRedisSkuInfo
(
lySkuEntity
.
GoodsId
,
newSkuRedisInfoMap
)
common
.
PrintStdout
()
.
Printf
(
"回滚redis成功, 程序结束
\n
"
)
panic
(
nil
)
common
.
PrintStdout
()
.
Printf
(
"回滚redis成功,
\n
"
)
if
(
err
!=
mgo
.
ErrNotFound
){
panic
(
nil
)
}
return
}
//=====================修改mongo end======================
...
...
@@ -173,7 +193,7 @@ func (this *ServiceLy) updateDBRedisMongo(lySkuEntity *model.LySkuEntity,dbconn
panic
(
nil
)
}
common
.
PrintStdout
()
.
Printf
(
"goodsId:%s,操作成功"
,
lySkuEntity
.
GoodsId
)
panic
(
nil
)
//
panic(nil)
//===================修改DB 和增加日志end====================
}
else
{
//没有映射数据
...
...
service/service_mapping.go
View file @
8936a131
...
...
@@ -127,6 +127,9 @@ func (this *ServiceSupplier) GetStatus2SupplierInfo(supplierName string,purchase
//组装采购员
cmsEntitys
:=
[]
CmsEntity
{}
//采购员 cmsDB数据
dbCms
:=
mysql
.
Conn
(
"cms"
)
//spu实例化链接
if
(
len
(
purchaseNames
)
==
0
){
purchaseNames
=
append
(
purchaseNames
,
"0"
)
}
err
=
dbCms
.
Table
(
"user_info"
)
.
Join
(
"INNER"
,
"lie_intracode"
,
"user_info.userId=lie_intracode.admin_id"
)
.
In
(
"user_info.name"
,
purchaseNames
...
)
.
Find
(
&
cmsEntitys
)
...
...
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