Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
task-kolon
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
piplus-v3
task-kolon
Commits
4353c979
Commit
4353c979
authored
Jun 06, 2016
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增量保存sales数据和products数据
parent
e24c7782
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
162 additions
and
21 deletions
+162
-21
KolonMemberController.java
...main/java/com/hdp/pi/api/kolon/KolonMemberController.java
+6
-2
KolonMemberService.java
...ain/java/com/hdp/pi/service/kolon/KolonMemberService.java
+6
-2
KolonMemberServiceImpl.java
...java/com/hdp/pi/service/kolon/KolonMemberServiceImpl.java
+139
-3
FtpUtil.java
src/main/java/com/hdp/pi/utils/kolon/FtpUtil.java
+8
-14
kolon.properties
src/main/resources/kolon.properties
+3
-0
No files found.
src/main/java/com/hdp/pi/api/kolon/KolonMemberController.java
View file @
4353c979
...
@@ -54,7 +54,9 @@ public class KolonMemberController extends JWTSecurityController{
...
@@ -54,7 +54,9 @@ public class KolonMemberController extends JWTSecurityController{
public
@ResponseBody
String
syncData
(
HttpServletRequest
req
)
{
public
@ResponseBody
String
syncData
(
HttpServletRequest
req
)
{
DTO
dto
=
DTO
.
newDTO
();
DTO
dto
=
DTO
.
newDTO
();
try
{
try
{
kolonMemberService
.
syncData
();
kolonMemberService
.
syncMemberData
();
kolonMemberService
.
syncProductData
();
kolonMemberService
.
syncSaleData
();
return
dto
.
toJson
();
return
dto
.
toJson
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -107,7 +109,9 @@ public class KolonMemberController extends JWTSecurityController{
...
@@ -107,7 +109,9 @@ public class KolonMemberController extends JWTSecurityController{
@RequestParam
(
value
=
"time"
,
required
=
false
)
String
time
)
{
@RequestParam
(
value
=
"time"
,
required
=
false
)
String
time
)
{
DTO
dto
=
DTO
.
newDTO
();
DTO
dto
=
DTO
.
newDTO
();
try
{
try
{
kolonMemberService
.
syncData
();
kolonMemberService
.
syncMemberData
();
kolonMemberService
.
syncProductData
();
kolonMemberService
.
syncSaleData
();
String
lastSendTime
=
null
;
String
lastSendTime
=
null
;
if
(
time
!=
null
){
if
(
time
!=
null
){
...
...
src/main/java/com/hdp/pi/service/kolon/KolonMemberService.java
View file @
4353c979
...
@@ -32,9 +32,13 @@ public interface KolonMemberService {
...
@@ -32,9 +32,13 @@ public interface KolonMemberService {
void
matchData
(
String
[]
s
);
void
matchData
(
String
[]
s
);
/**
/**
* 同步数据
* 同步
会员
数据
*/
*/
void
syncData
();
void
syncMemberData
();
void
syncProductData
();
void
syncSaleData
();
/**
/**
* 生成文件并发送到FTP服务器,返回最后更新的时间
* 生成文件并发送到FTP服务器,返回最后更新的时间
...
...
src/main/java/com/hdp/pi/service/kolon/KolonMemberServiceImpl.java
View file @
4353c979
...
@@ -10,15 +10,20 @@ import java.util.List;
...
@@ -10,15 +10,20 @@ import java.util.List;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
au.com.bytecode.opencsv.CSVWriter
;
import
au.com.bytecode.opencsv.CSVWriter
;
import
com.hdp.pi.domain.kolon.KolonMember
;
import
com.hdp.pi.domain.kolon.KolonMember
;
import
com.hdp.pi.domain.kolon.Product
;
import
com.hdp.pi.domain.kolon.Sale
;
import
com.hdp.pi.dto.kolon.KolonMemberDTO
;
import
com.hdp.pi.dto.kolon.KolonMemberDTO
;
import
com.hdp.pi.repository.kolon.KolonMemberPreassignSnRepository
;
import
com.hdp.pi.repository.kolon.KolonMemberPreassignSnRepository
;
import
com.hdp.pi.repository.kolon.KolonMemberRepository
;
import
com.hdp.pi.repository.kolon.KolonMemberRepository
;
import
com.hdp.pi.repository.kolon.ProductRepository
;
import
com.hdp.pi.repository.kolon.SaleRepository
;
import
com.hdp.pi.utils.kolon.FtpUtil
;
import
com.hdp.pi.utils.kolon.FtpUtil
;
import
com.hdp.pi.utils.kolon.Util
;
import
com.hdp.pi.utils.kolon.Util
;
...
@@ -31,12 +36,27 @@ public class KolonMemberServiceImpl implements KolonMemberService {
...
@@ -31,12 +36,27 @@ public class KolonMemberServiceImpl implements KolonMemberService {
@Autowired
@Autowired
private
FtpUtil
ftpUtil
;
private
FtpUtil
ftpUtil
;
@Value
(
"${kolon.property.ftp.getFileName}"
)
private
String
memberFileName
;
@Value
(
"${kolon.property.ftp.saleFileName}"
)
private
String
saleFileName
;
@Value
(
"${kolon.property.ftp.productFileName}"
)
private
String
productFileName
;
@Autowired
@Autowired
private
KolonMemberRepository
kolonMemberRepository
;
private
KolonMemberRepository
kolonMemberRepository
;
@Autowired
@Autowired
private
KolonMemberPreassignSnRepository
kolonMemberPreassignSnRepository
;
private
KolonMemberPreassignSnRepository
kolonMemberPreassignSnRepository
;
@Autowired
private
ProductRepository
productRepository
;
@Autowired
private
SaleRepository
saleRepository
;
@Override
@Override
public
KolonMember
findOneByCsNo
(
Long
csNo
)
{
public
KolonMember
findOneByCsNo
(
Long
csNo
)
{
return
kolonMemberRepository
.
findFirstByCsNo
(
csNo
);
return
kolonMemberRepository
.
findFirstByCsNo
(
csNo
);
...
@@ -130,8 +150,8 @@ public class KolonMemberServiceImpl implements KolonMemberService {
...
@@ -130,8 +150,8 @@ public class KolonMemberServiceImpl implements KolonMemberService {
}
}
@Override
@Override
public
void
syncData
()
{
public
void
sync
Member
Data
()
{
List
<
String
[]>
list
=
ftpUtil
.
readCSVFile
();
List
<
String
[]>
list
=
ftpUtil
.
readCSVFile
(
memberFileName
);
if
(
list
!=
null
)
{
if
(
list
!=
null
)
{
boolean
firstRow
=
true
;
boolean
firstRow
=
true
;
for
(
String
[]
row
:
list
)
{
for
(
String
[]
row
:
list
)
{
...
@@ -142,9 +162,125 @@ public class KolonMemberServiceImpl implements KolonMemberService {
...
@@ -142,9 +162,125 @@ public class KolonMemberServiceImpl implements KolonMemberService {
}
}
}
}
}
}
ftpUtil
.
moveFile
();
ftpUtil
.
moveFile
(
memberFileName
);
}
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Exception
.
class
)
private
void
saveProductAbsentIf
(
Product
product
){
if
(
product
==
null
||
product
.
id
==
null
){
return
;
}
Product
p
=
productRepository
.
findOne
(
product
.
id
);
if
(
p
==
null
){
productRepository
.
save
(
product
);
}
}
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Exception
.
class
)
private
void
saveSale
(
Sale
sale
){
if
(
sale
==
null
){
return
;
}
if
(
sale
.
oId
==
null
){
return
;
}
if
(
sale
.
oDate
==
null
){
return
;
}
if
(
sale
.
customer
==
null
){
return
;
}
if
(
sale
.
item
==
null
){
return
;
}
if
(
sale
.
quantity
==
null
){
return
;
}
if
(
sale
.
amount
==
null
){
return
;
}
saleRepository
.
save
(
sale
);
}
private
String
getByIndex
(
String
[]
row
,
int
index
){
if
(
row
==
null
){
return
""
;
}
if
(
index
<
0
||
index
>=
row
.
length
){
return
""
;
}
return
row
[
index
];
}
private
Product
newProduct
(
String
[]
row
){
Product
p
=
new
Product
();
try
{
p
.
id
=
getByIndex
(
row
,
0
);
p
.
title
=
getByIndex
(
row
,
1
);
p
.
category
=
getByIndex
(
row
,
2
);
p
.
image
=
getByIndex
(
row
,
3
);
p
.
link
=
getByIndex
(
row
,
4
);
p
.
avaliable
=
getByIndex
(
row
,
5
);
p
.
dept
=
getByIndex
(
row
,
6
);
p
.
seaons
=
getByIndex
(
row
,
7
);
p
.
planyy
=
getByIndex
(
row
,
8
);
p
.
color
=
getByIndex
(
row
,
9
);
p
.
price
=
getByIndex
(
row
,
10
);
}
catch
(
Throwable
e
){
e
.
printStackTrace
();
}
return
p
;
}
private
Sale
newSale
(
String
[]
row
){
Sale
s
=
new
Sale
();
try
{
s
.
oId
=
getByIndex
(
row
,
0
);
s
.
oDate
=
Integer
.
valueOf
(
getByIndex
(
row
,
1
));
s
.
customer
=
getByIndex
(
row
,
2
);
s
.
item
=
getByIndex
(
row
,
3
);
s
.
quantity
=
Integer
.
valueOf
(
getByIndex
(
row
,
4
));
s
.
amount
=
Double
.
valueOf
(
getByIndex
(
row
,
5
));
}
catch
(
Throwable
e
){
e
.
printStackTrace
();
}
return
s
;
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Exception
.
class
)
public
void
syncProductData
()
{
List
<
String
[]>
list
=
ftpUtil
.
readCSVFile
(
productFileName
);
if
(
list
!=
null
)
{
boolean
firstRow
=
true
;
for
(
String
[]
row
:
list
)
{
if
(
firstRow
)
{
firstRow
=
false
;
}
else
{
saveProductAbsentIf
(
newProduct
(
row
));
}
}
}
ftpUtil
.
moveFile
(
productFileName
);
}
@Override
@Transactional
(
propagation
=
Propagation
.
REQUIRED
,
rollbackFor
=
Exception
.
class
)
public
void
syncSaleData
()
{
List
<
String
[]>
list
=
ftpUtil
.
readCSVFile
(
saleFileName
);
if
(
list
!=
null
)
{
boolean
firstRow
=
true
;
for
(
String
[]
row
:
list
)
{
if
(
firstRow
)
{
firstRow
=
false
;
}
else
{
saveSale
(
newSale
(
row
));
}
}
}
ftpUtil
.
moveFile
(
saleFileName
);
}
@Override
@Override
public
Date
sendData
(
Date
time
)
{
public
Date
sendData
(
Date
time
)
{
...
...
src/main/java/com/hdp/pi/utils/kolon/FtpUtil.java
View file @
4353c979
...
@@ -51,12 +51,6 @@ public class FtpUtil {
...
@@ -51,12 +51,6 @@ public class FtpUtil {
@Value
(
"${kolon.property.ftp.getFileHistoryDir}"
)
@Value
(
"${kolon.property.ftp.getFileHistoryDir}"
)
private
String
getFileHistoryDir
;
private
String
getFileHistoryDir
;
/**
* FTP文件名称
*/
@Value
(
"${kolon.property.ftp.getFileName}"
)
private
String
getFileName
;
/**
/**
* 临时路径
* 临时路径
*/
*/
...
@@ -125,14 +119,14 @@ public class FtpUtil {
...
@@ -125,14 +119,14 @@ public class FtpUtil {
/**
/**
* 读取文件数据
* 读取文件数据
*/
*/
public
List
<
String
[]>
readCSVFile
()
{
public
List
<
String
[]>
readCSVFile
(
String
fileName
)
{
List
<
String
[]>
list
=
new
ArrayList
<
String
[]>();
List
<
String
[]>
list
=
new
ArrayList
<
String
[]>();
try
{
try
{
FTPClient
ftpClient
=
this
.
getFTPClient
();
FTPClient
ftpClient
=
this
.
getFTPClient
();
InputStream
csv
=
ftpClient
.
retrieveFileStream
(
getFileDir
InputStream
csv
=
ftpClient
.
retrieveFileStream
(
getFileDir
+
getF
ileName
);
+
f
ileName
);
if
(
csv
==
null
)
{
if
(
csv
==
null
)
{
logger
.
warn
(
"kolon数据同步失败,没有找到【"
+
getFileDir
+
getF
ileName
logger
.
warn
(
"kolon数据同步失败,没有找到【"
+
getFileDir
+
f
ileName
+
"】数据文件"
);
+
"】数据文件"
);
return
null
;
return
null
;
}
}
...
@@ -153,17 +147,17 @@ public class FtpUtil {
...
@@ -153,17 +147,17 @@ public class FtpUtil {
/**
/**
* 移动文件
* 移动文件
*/
*/
public
void
moveFile
()
{
public
void
moveFile
(
String
fileName
)
{
try
{
try
{
FTPClient
ftpClient
=
this
.
getFTPClient
();
FTPClient
ftpClient
=
this
.
getFTPClient
();
// 新的文件名
// 新的文件名
String
suffix
=
getFileName
.
substring
(
getF
ileName
.
lastIndexOf
(
"."
));
String
suffix
=
fileName
.
substring
(
f
ileName
.
lastIndexOf
(
"."
));
String
name
=
getF
ileName
String
name
=
f
ileName
.
substring
(
0
,
getF
ileName
.
lastIndexOf
(
"."
));
.
substring
(
0
,
f
ileName
.
lastIndexOf
(
"."
));
String
newFileName
=
name
+
"_"
+
getTime
()
+
suffix
;
String
newFileName
=
name
+
"_"
+
getTime
()
+
suffix
;
ftpClient
.
rename
(
getFileDir
+
getF
ileName
,
getFileHistoryDir
ftpClient
.
rename
(
getFileDir
+
f
ileName
,
getFileHistoryDir
+
newFileName
);
+
newFileName
);
ftpClient
.
disconnect
();
ftpClient
.
disconnect
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
...
src/main/resources/kolon.properties
View file @
4353c979
...
@@ -31,6 +31,9 @@ kolon.property.ftp.password = yang19821123
...
@@ -31,6 +31,9 @@ kolon.property.ftp.password = yang19821123
kolon.property.ftp.getFileDir
=
/Emarsys/
kolon.property.ftp.getFileDir
=
/Emarsys/
kolon.property.ftp.getFileHistoryDir
=
/Emarsys/history/
kolon.property.ftp.getFileHistoryDir
=
/Emarsys/history/
kolon.property.ftp.getFileName
=
contact.csv
kolon.property.ftp.getFileName
=
contact.csv
kolon.property.ftp.saleFileName
=
sales.csv
kolon.property.ftp.productFileName
=
products.csv
kolon.property.ftp.tempFileDir
=
/temp
kolon.property.ftp.tempFileDir
=
/temp
kolon.property.ftp.tempAddFileName
=
/temp/tempAddContact.csv
kolon.property.ftp.tempAddFileName
=
/temp/tempAddContact.csv
...
...
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