Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
service-campaign
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nguyen Ha
service-campaign
Commits
2e0e6f96
Commit
2e0e6f96
authored
Aug 29, 2019
by
Nguyen Ha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix sonar
parent
d712ba6d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
33 deletions
+39
-33
src/main/java/com/viettel/campaign/service/impl/CustomerServiceImpl.java
...om/viettel/campaign/service/impl/CustomerServiceImpl.java
+39
-33
No files found.
src/main/java/com/viettel/campaign/service/impl/CustomerServiceImpl.java
View file @
2e0e6f96
...
...
@@ -46,6 +46,7 @@ import javax.persistence.criteria.CriteriaQuery;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.text.DateFormat
;
import
java.text.SimpleDateFormat
;
...
...
@@ -103,8 +104,7 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO
resultDTO
=
new
ResultDTO
();
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
Session
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
Session
session
=
null
;
if
(
DataUtil
.
isNullOrZero
(
companySiteId
))
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -113,6 +113,8 @@ public class CustomerServiceImpl implements CustomerService {
}
try
{
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
// StringBuilder sqlStrBuilder = new StringBuilder();
// sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-customer-detail-by-params"));
...
...
@@ -193,7 +195,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
}
finally
{
session
.
close
();
if
(
session
!=
null
)
session
.
close
();
}
return
resultDTO
;
...
...
@@ -224,8 +226,7 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO
resultDTO
=
new
ResultDTO
();
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
Session
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
Session
session
=
null
;
if
(
DataUtil
.
isNullOrZero
(
companySiteId
))
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -234,6 +235,8 @@ public class CustomerServiceImpl implements CustomerService {
}
try
{
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
// StringBuilder sqlStrBuilder = new StringBuilder();
// sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-customer-detail-by-params"));
...
...
@@ -339,7 +342,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
}
finally
{
session
.
close
();
if
(
session
!=
null
)
session
.
close
();
}
return
resultDTO
;
...
...
@@ -429,8 +432,7 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO
resultDTO
=
new
ResultDTO
();
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
Session
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
Session
session
=
null
;
if
(
DataUtil
.
isNullOrZero
(
companySiteId
))
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -439,6 +441,8 @@ public class CustomerServiceImpl implements CustomerService {
}
try
{
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
// StringBuilder sqlStrBuilder = new StringBuilder();
// sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-customer-detail-by-id"));
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -494,7 +498,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
}
finally
{
session
.
close
();
if
(
session
!=
null
)
session
.
close
();
}
return
resultDTO
;
...
...
@@ -522,8 +526,7 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO
resultDTO
=
new
ResultDTO
();
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
Session
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
Session
session
=
null
;
if
(
DataUtil
.
isNullOrZero
(
companySiteId
))
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -532,6 +535,8 @@ public class CustomerServiceImpl implements CustomerService {
}
try
{
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
// StringBuilder sb = new StringBuilder();
// sb.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params"));
...
...
@@ -594,7 +599,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
}
finally
{
session
.
close
();
if
(
session
!=
null
)
session
.
close
();
}
return
resultDTO
;
...
...
@@ -759,8 +764,7 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO
resultDTO
=
new
ResultDTO
();
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
Session
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
Session
session
=
null
;
if
(
DataUtil
.
isNullOrEmpty
(
searchCustomerRequestDTO
.
getCompanySiteId
()))
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -769,6 +773,8 @@ public class CustomerServiceImpl implements CustomerService {
}
try
{
session
=
sessionFactory
.
openSession
();
session
.
beginTransaction
();
// StringBuilder sb = new StringBuilder();
// sb.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params"));
StringBuilder
sb
=
new
StringBuilder
();
...
...
@@ -865,7 +871,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
}
finally
{
session
.
close
();
if
(
session
!=
null
)
session
.
close
();
}
return
resultDTO
;
...
...
@@ -885,16 +891,11 @@ public class CustomerServiceImpl implements CustomerService {
try
{
List
<
CustomerContact
>
data
=
customerContactRepository
.
findByCustomerIdAndAndContactTypeAndContact
(
customer
.
getCustomerId
(),
customer
.
getContactType
(),
customer
.
getContact
(),
SQLBuilder
.
buildPageable
(
customer
));
if
(
customer
!=
null
)
{
result
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
result
.
setDescription
(
"customer contact data"
);
result
.
setListData
(
data
);
result
.
setTotalRow
(
customerContactRepository
.
findByCustomerIdAndAndContactTypeAndContact
(
customer
.
getCustomerId
(),
customer
.
getContactType
(),
customer
.
getContact
(),
null
).
size
());
}
else
{
result
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
result
.
setDescription
(
"customer contact data null"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -940,7 +941,7 @@ public class CustomerServiceImpl implements CustomerService {
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
Map
<
String
,
Object
>
readAndValidateCustomer
(
String
path
,
List
<
CustomizeFields
>
dynamicHeader
,
UserSession
userSession
,
Long
customerListId
)
{
public
Map
<
String
,
Object
>
readAndValidateCustomer
(
String
path
,
List
<
CustomizeFields
>
dynamicHeader
,
UserSession
userSession
,
Long
customerListId
)
throws
IOException
{
LOGGER
.
info
(
"------------READ AND VALIDATE--------------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
DataFormatter
dataFormat
=
new
DataFormatter
();
...
...
@@ -948,6 +949,7 @@ public class CustomerServiceImpl implements CustomerService {
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
StringBuilder
sb
=
new
StringBuilder
();
int
failedCount
=
0
;
XSSFWorkbook
workbook
=
null
;
try
{
//<editor-fold desc="Khởi tạo mảng header tĩnh" defaultstate="collapsed">
...
...
@@ -971,7 +973,7 @@ public class CustomerServiceImpl implements CustomerService {
File
file
=
new
File
(
path
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
fis
);
workbook
=
new
XSSFWorkbook
(
fis
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Row
row
=
sheet
.
getRow
(
3
);
...
...
@@ -1056,11 +1058,11 @@ public class CustomerServiceImpl implements CustomerService {
&&
rawDataList
.
get
(
i
)[
4
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
().
equals
(
""
))
{
String
str
=
validatePhone
(
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
(),
locale
);
str
.
concat
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
3
].
toString
(),
50
,
locale
));
str
+=
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
3
].
toString
(),
50
,
locale
));
if
(!
validateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
()))
{
str
.
concat
(
BundleUtils
.
getLangString
(
"customer.emailInvalid"
,
locale
));
str
+=
(
BundleUtils
.
getLangString
(
"customer.emailInvalid"
,
locale
));
}
else
{
str
.
concat
(
validateDuplicateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
(),
locale
));
str
+=
(
validateDuplicateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
(),
locale
));
}
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
4
].
toString
(),
50
,
locale
));
sb
.
append
(
str
);
...
...
@@ -1265,6 +1267,8 @@ public class CustomerServiceImpl implements CustomerService {
LOGGER
.
info
(
e
.
getMessage
());
result
.
put
(
"message"
,
"validate-error"
);
return
result
;
}
finally
{
if
(
workbook
!=
null
)
workbook
.
close
();
}
}
...
...
@@ -1335,11 +1339,12 @@ public class CustomerServiceImpl implements CustomerService {
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
byte
[]
buildTemplate
(
Long
companySiteId
)
{
public
byte
[]
buildTemplate
(
Long
companySiteId
)
throws
IOException
{
LOGGER
.
info
(
"-----------BUILD TEMPLATE-----------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
XSSFWorkbook
workbook
=
null
;
try
{
XSSFWorkbook
workbook
=
new
XSSFWorkbook
();
workbook
=
new
XSSFWorkbook
();
CreationHelper
creationHelper
=
workbook
.
getCreationHelper
();
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
Sheet
sheet
=
workbook
.
createSheet
(
"IMPORT"
);
...
...
@@ -1478,11 +1483,12 @@ public class CustomerServiceImpl implements CustomerService {
workbook
.
write
(
os
);
os
.
flush
();
os
.
close
();
workbook
.
close
();
return
os
.
toByteArray
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
return
null
;
}
finally
{
if
(
workbook
!=
null
)
workbook
.
close
();
}
}
...
...
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