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
57bf4800
Commit
57bf4800
authored
Sep 12, 2019
by
đinh thị đầm
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://git.myitsol.com/hanv/service-campaign
parents
8db5fc4d
94f54711
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
363 additions
and
143 deletions
+363
-143
src/main/java/com/viettel/campaign/repository/ccms_full/CustomerListRepository.java
...campaign/repository/ccms_full/CustomerListRepository.java
+3
-0
src/main/java/com/viettel/campaign/service/impl/CustomerServiceImpl.java
...om/viettel/campaign/service/impl/CustomerServiceImpl.java
+353
-134
src/main/java/com/viettel/campaign/utils/Constants.java
src/main/java/com/viettel/campaign/utils/Constants.java
+2
-0
src/main/resources/i18n/language_en.properties
src/main/resources/i18n/language_en.properties
+3
-5
src/main/resources/i18n/language_vi.properties
src/main/resources/i18n/language_vi.properties
+2
-4
No files found.
src/main/java/com/viettel/campaign/repository/ccms_full/CustomerListRepository.java
View file @
57bf4800
...
...
@@ -14,6 +14,9 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long
CustomerList
findByCustomerListCode
(
String
customerListCode
);
@Query
(
"select c from CustomerList c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id and c.status = 1"
)
List
<
CustomerList
>
findAllCustomerList
(
@Param
(
"p_ids"
)
List
<
Long
>
p_ids
,
@Param
(
"p_company_site_id"
)
Long
p_company_site_id
);
@Modifying
@Query
(
"update CustomerList c set c.status = 0 where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id"
)
int
deleteCustomerList
(
@Param
(
"p_customer_list_id"
)
Long
p_customer_list_id
,
@Param
(
"p_company_site_id"
)
Long
p_company_site_id
);
...
...
src/main/java/com/viettel/campaign/service/impl/CustomerServiceImpl.java
View file @
57bf4800
...
...
@@ -393,10 +393,9 @@ public class CustomerServiceImpl implements CustomerService {
public
ResultDTO
deleteCustomer
(
CustomerRequestDTO
customerRequestDTO
)
{
ResultDTO
resultDTO
=
new
ResultDTO
();
List
<
Long
>
listId
=
new
ArrayList
<>();
listId
.
add
(
customerRequestDTO
.
getCustomerId
());
try
{
if
(
customerRequestDTO
!=
null
)
{
listId
.
add
(
customerRequestDTO
.
getCustomerId
());
if
(
customerListMappingRepository
.
findAllCustomerListMapping
(
listId
,
customerRequestDTO
.
getCustomerListId
(),
customerRequestDTO
.
getCompanySiteId
()).
size
()
>
0
)
{
// delete
// customerRepository.deleteById(customerDTO.getCustomerId());
...
...
@@ -405,8 +404,8 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
DELETE_
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
DELETE_
ERROR
);
}
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
...
...
@@ -425,10 +424,15 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO
resultDTO
=
new
ResultDTO
();
try
{
if
(
customerRequestDTO
!=
null
)
{
// customerRepository.deleteIds(ids);
if
(
customerListMappingRepository
.
findAllCustomerListMapping
(
customerRequestDTO
.
getIds
(),
customerRequestDTO
.
getCustomerListId
(),
customerRequestDTO
.
getCompanySiteId
()).
size
()
>
0
)
{
//customerRepository.deleteIds(ids);
customerListMappingRepository
.
deleteMappingByCustomerIds
(
customerRequestDTO
.
getIds
(),
customerRequestDTO
.
getCustomerListId
(),
customerRequestDTO
.
getCompanySiteId
());
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
DELETE_ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
DELETE_ERROR
);
}
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
...
...
@@ -721,17 +725,23 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
ResultDTO
deleteCustomerList
(
CustomerListDTO
customerListDTO
)
{
ResultDTO
resultDTO
=
new
ResultDTO
();
List
<
Long
>
ids
=
new
ArrayList
<>();
ids
.
add
(
customerListDTO
.
getCustomerListId
());
try
{
// delete
if
(
DataUtil
.
isNullOrZero
(
campaignCustomerListRepository
.
campaignCount
(
customerListDTO
.
getCustomerListId
())))
{
if
(
customerListRepository
.
findAllCustomerList
(
ids
,
customerListDTO
.
getCompanySiteId
()).
size
()
>
0
)
{
customerListRepository
.
deleteCustomerList
(
customerListDTO
.
getCustomerListId
(),
customerListDTO
.
getCompanySiteId
());
customerListMappingRepository
.
deleteMappingByCustomerListId
(
customerListDTO
.
getCustomerListId
(),
customerListDTO
.
getCompanySiteId
());
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
DELETE_ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
DELETE_ERROR
);
}
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
...
...
@@ -751,12 +761,17 @@ public class CustomerServiceImpl implements CustomerService {
try
{
if
(
customerRequestDTO
!=
null
)
{
if
(
DataUtil
.
isNullOrZero
(
campaignCustomerListRepository
.
campaignIdsCount
(
customerRequestDTO
.
getIds
())))
{
if
(
customerListRepository
.
findAllCustomerList
(
customerRequestDTO
.
getIds
(),
customerRequestDTO
.
getCompanySiteId
()).
size
()
>
0
)
{
customerListRepository
.
deleteCustomerListIds
(
customerRequestDTO
.
getIds
(),
customerRequestDTO
.
getCompanySiteId
());
customerListMappingRepository
.
deleteMappingByCustomerListIds
(
customerRequestDTO
.
getIds
(),
customerRequestDTO
.
getCompanySiteId
());
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
DELETE_ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
DELETE_ERROR
);
}
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
...
...
@@ -965,8 +980,11 @@ public class CustomerServiceImpl implements CustomerService {
DataFormatter
dataFormat
=
new
DataFormatter
();
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"dd/MM/yyyy"
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
Map
<
String
,
Integer
>
headerMap
=
new
HashMap
<>();
List
<
String
>
stringHeader
=
new
ArrayList
<>();
StringBuilder
sb
=
new
StringBuilder
();
int
failedCount
=
0
;
int
objectSize
;
XSSFWorkbook
workbook
=
null
;
boolean
isMainPhoneNull
=
false
,
isSecondPhoneNull
=
false
,
isEmailNull
=
false
;
try
{
...
...
@@ -988,62 +1006,53 @@ public class CustomerServiceImpl implements CustomerService {
header
.
add
(
new
CustomizeFields
(
"combobox"
,
BundleUtils
.
getLangString
(
"customer.smsAllowed"
,
locale
)));
header
.
addAll
(
dynamicHeader
);
for
(
CustomizeFields
cf
:
header
)
{
stringHeader
.
add
(
cf
.
getTitle
().
split
(
"#"
)[
0
].
trim
());
}
//</editor-fold>
File
file
=
new
File
(
path
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
workbook
=
new
XSSFWorkbook
(
fis
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
Row
row
=
sheet
.
getRow
(
3
);
//<editor-fold desc="Tạo style cho cột kết quả" defaultstate="collapsed">
Font
resultFont
=
workbook
.
createFont
();
resultFont
.
setBold
(
true
);
resultFont
.
setFontHeightInPoints
((
short
)
11
);
CellStyle
resultStyle
=
workbook
.
createCellStyle
();
resultStyle
.
setFont
(
resultFont
);
resultStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
resultStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
resultStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
//</editor-fold>
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
if
(
row
.
getPhysicalNumberOfCells
()
>
header
.
size
())
{
for
(
int
i
=
0
;
i
<
row
.
getPhysicalNumberOfCells
();
i
++)
{
if
(
sheet
.
isColumnHidden
(
i
))
{
sheet
.
setColumnHidden
(
i
,
false
);
}
if
(
isColumnNullOrBlank
(
sheet
,
i
))
{
sheet
.
shiftColumns
(
i
+
1
,
i
+
1
,
-
1
);
sheet
.
removeMergedRegion
(
0
);
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
1
,
0
,
13
));
if
(
row
.
getLastCellNum
()
>
header
.
size
())
{
for
(
int
i
=
0
;
i
<
row
.
getLastCellNum
();
i
++)
{
Cell
c
=
row
.
getCell
(
i
);
if
(
c
!=
null
&&
!
c
.
getStringCellValue
().
trim
().
equals
(
""
))
{
if
(
stringHeader
.
contains
(
c
.
getStringCellValue
().
trim
())
&&
!
headerMap
.
containsKey
(
c
.
getStringCellValue
().
trim
()))
{
headerMap
.
put
(
c
.
getStringCellValue
().
trim
(),
c
.
getColumnIndex
());
}
}
for
(
int
i
=
0
;
i
<
header
.
size
();
i
++)
{
Cell
cell
=
row
.
getCell
(
i
);
if
(!
cell
.
getStringCellValue
().
equals
(
header
.
get
(
i
).
getTitle
().
split
(
"#"
)[
0
]))
{
}
if
(
headerMap
.
size
()
!=
header
.
size
())
{
result
.
put
(
"content"
,
Files
.
readAllBytes
(
file
.
toPath
()));
result
.
put
(
"message"
,
"template-invalid"
);
return
result
;
}
}
}
else
if
(
row
.
get
PhysicalNumberOfCells
()
<
header
.
size
())
{
objectSize
=
row
.
getLastCellNum
();
}
else
if
(
row
.
get
LastCellNum
()
<
header
.
size
())
{
result
.
put
(
"content"
,
Files
.
readAllBytes
(
file
.
toPath
()));
result
.
put
(
"message"
,
"template-invalid"
);
return
result
;
}
else
{
for
(
int
i
=
0
;
i
<
header
.
size
();
i
++)
{
Cell
cell
=
row
.
getCell
(
i
);
if
(!
cell
.
getStringCellValue
().
equals
(
header
.
get
(
i
).
getTitle
().
split
(
"#"
)[
0
]))
{
Cell
c
=
row
.
getCell
(
i
);
if
(
c
!=
null
&&
!
""
.
equals
(
c
.
getStringCellValue
().
trim
()))
{
if
(
stringHeader
.
contains
(
c
.
getStringCellValue
().
trim
())
&&
!
headerMap
.
containsKey
(
c
.
getStringCellValue
().
trim
()))
{
headerMap
.
put
(
c
.
getStringCellValue
().
trim
(),
c
.
getColumnIndex
());
}
}
}
if
(
headerMap
.
size
()
!=
header
.
size
())
{
result
.
put
(
"content"
,
Files
.
readAllBytes
(
file
.
toPath
()));
result
.
put
(
"message"
,
"template-invalid"
);
return
result
;
}
}
objectSize
=
row
.
getLastCellNum
();
}
//</editor-fold>
...
...
@@ -1054,13 +1063,6 @@ public class CustomerServiceImpl implements CustomerService {
result
.
put
(
"message"
,
"template-no-data"
);
result
.
put
(
"content"
,
Files
.
readAllBytes
(
file
.
toPath
()));
return
result
;
}
else
{
Cell
resultCell
=
sheet
.
getRow
(
3
).
getCell
(
header
.
size
());
if
(
resultCell
==
null
)
{
resultCell
=
sheet
.
getRow
(
3
).
createCell
(
header
.
size
());
}
resultCell
.
setCellValue
(
BundleUtils
.
getLangString
(
"customer.result"
,
locale
));
resultCell
.
setCellStyle
(
resultStyle
);
}
//</editor-fold>
...
...
@@ -1068,23 +1070,36 @@ public class CustomerServiceImpl implements CustomerService {
for
(
int
i
=
4
;
i
<=
sheet
.
getPhysicalNumberOfRows
();
i
++)
{
Row
dataRow
=
sheet
.
getRow
(
i
);
if
(
dataRow
!=
null
)
{
Object
[]
obj
=
new
Object
[
row
.
getPhysicalNumberOfCells
()
-
1
];
for
(
int
j
=
0
;
j
<
row
.
getPhysicalNumberOfCells
()
-
1
;
j
++)
{
Cell
dataCell
=
dataRow
.
getCell
(
j
);
Object
[]
obj
=
new
Object
[
objectSize
+
1
];
// for (int j = 0; j < header.size(); j++) {
// Cell dataCell = dataRow.getCell(j);
// if (dataCell != null) {
// obj[j] = dataFormat.formatCellValue(dataCell);
// } else {
// Cell headerCell = row.getCell(j);
// if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.cusType", locale))) {
// obj[j] = BundleUtils.getLangString("customer.cusType.normal", locale);
// } else if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.callAllowed", locale)) || headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.emailAllowed", locale))
// || headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.smsAllowed", locale))) {
// obj[j] = BundleUtils.getLangString("customer.yes", locale);
// } else {
// obj[j] = null;
// }
// }
// }
headerMap
.
forEach
((
k
,
v
)
->
{
Cell
dataCell
=
dataRow
.
getCell
(
v
);
if
(
dataCell
!=
null
)
{
obj
[
j
]
=
dataFormat
.
formatCellValue
(
dataCell
);
}
else
{
Cell
headerCell
=
row
.
getCell
(
j
);
if
(
headerCell
.
getStringCellValue
().
equals
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
)))
{
obj
[
j
]
=
BundleUtils
.
getLangString
(
"customer.cusType.normal"
,
locale
);
}
else
if
(
headerCell
.
getStringCellValue
().
equals
(
BundleUtils
.
getLangString
(
"customer.callAllowed"
,
locale
))
||
headerCell
.
getStringCellValue
().
equals
(
BundleUtils
.
getLangString
(
"customer.emailAllowed"
,
locale
))
||
headerCell
.
getStringCellValue
().
equals
(
BundleUtils
.
getLangString
(
"customer.smsAllowed"
,
locale
)))
{
obj
[
j
]
=
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
);
obj
[
v
]
=
dataFormat
.
formatCellValue
(
dataCell
);
}
else
{
obj
[
j
]
=
null
;
}
}
if
(
k
.
equals
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
)))
{
obj
[
v
]
=
BundleUtils
.
getLangString
(
"customer.cusType.normal"
,
locale
);
}
else
if
(
k
.
equals
(
BundleUtils
.
getLangString
(
"customer.callAllowed"
,
locale
))
||
k
.
equals
(
BundleUtils
.
getLangString
(
"customer.emailAllowed"
,
locale
))
||
k
.
equals
(
BundleUtils
.
getLangString
(
"customer.smsAllowed"
,
locale
)))
{
obj
[
v
]
=
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
);
}
else
obj
[
v
]
=
null
;
}
});
rawDataList
.
add
(
obj
);
}
}
...
...
@@ -1093,54 +1108,61 @@ public class CustomerServiceImpl implements CustomerService {
//<editor-fold desc="Validate dữ liệu" defaultstate="collapsed">
for
(
int
i
=
0
;
i
<
rawDataList
.
size
();
i
++)
{
if
(
rawDataList
.
get
(
i
).
length
>
1
&&
rawDataList
.
get
(
i
)[
1
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
1
].
toString
().
trim
().
equals
(
""
))
{
String
str
=
validateLength
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
1
].
toString
(),
1000
,
locale
);
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
&&
!
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
equals
(
""
))
{
String
str
=
validateLength
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
])].
toString
(),
1000
,
locale
);
if
(!
str
.
equals
(
""
))
{
sb
.
append
(
str
);
}
}
else
sb
.
append
(
BundleUtils
.
getLangString
(
"customer.nameRequired"
,
locale
));
if
(
rawDataList
.
get
(
i
).
length
>
4
&&
(
rawDataList
.
get
(
i
)[
2
]
==
null
||
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
().
equals
(
""
)))
{
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])
&&
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])]
==
null
||
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
equals
(
""
)))
{
isMainPhoneNull
=
true
;
}
else
{
if
(
validateNumberOnly
(
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
()))
{
sb
.
append
(
validateExistPhone
(
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
(),
locale
));
if
(
validateNumberOnly
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
()))
{
sb
.
append
(
validateExistPhone
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
(),
locale
));
}
else
{
sb
.
append
(
BundleUtils
.
getLangString
(
"customer.onlyNumber"
,
locale
));
}
}
if
(
rawDataList
.
get
(
i
).
length
>
4
&&
(
rawDataList
.
get
(
i
)[
3
]
==
null
||
rawDataList
.
get
(
i
)[
3
].
toString
().
trim
().
equals
(
""
)))
{
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])
&&
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])]
==
null
||
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
().
equals
(
""
)))
{
isSecondPhoneNull
=
true
;
}
else
{
if
(
validateNumberOnly
(
rawDataList
.
get
(
i
)[
3
].
toString
().
trim
()))
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
3
].
toString
(),
50
,
locale
));
if
(
validateNumberOnly
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
()))
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])
].
toString
(),
50
,
locale
));
}
else
{
sb
.
append
(
BundleUtils
.
getLangString
(
"customer.onlyNumber"
,
locale
));
}
}
if
(
rawDataList
.
get
(
i
).
length
>
4
&&
(
rawDataList
.
get
(
i
)[
4
]
==
null
||
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
().
equals
(
""
)))
{
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])
&&
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])]
==
null
||
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
equals
(
""
)))
{
isEmailNull
=
true
;
}
else
{
if
(!
validateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
()))
{
if
(!
validateEmail
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
()))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"customer.emailInvalid"
,
locale
));
}
else
{
sb
.
append
(
validateDuplicateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
(),
locale
));
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
4
].
toString
(),
5
0
,
locale
));
sb
.
append
(
validateDuplicateEmail
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
(),
locale
));
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])].
toString
(),
10
0
,
locale
));
}
}
if
(
isEmailNull
&&
isMainPhoneNull
&&
isSecondPhoneNull
)
{
sb
.
append
(
BundleUtils
.
getLangString
(
"customer.invalidRecord"
,
locale
));
}
if
(
rawDataList
.
get
(
i
).
length
>
5
&&
rawDataList
.
get
(
i
)[
5
]
!=
null
)
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
5
].
toString
(),
500
,
locale
));
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])
]
!=
null
)
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])
].
toString
(),
500
,
locale
));
}
if
(
rawDataList
.
get
(
i
).
length
>
6
&&
rawDataList
.
get
(
i
)[
6
]
!=
null
)
{
sb
.
append
(
validateCusType
(
rawDataList
.
get
(
i
)[
6
].
toString
().
trim
(),
locale
));
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
))
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
))]
!=
null
)
{
sb
.
append
(
validateCusType
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
))].
toString
().
trim
(),
locale
));
}
if
(
rawDataList
.
get
(
i
).
length
>
7
&&
rawDataList
.
get
(
i
)[
7
]
!=
null
)
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
7
].
toString
(),
100
,
locale
));
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
)
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])].
toString
(),
100
,
locale
));
}
if
(
rawDataList
.
get
(
i
).
length
>
8
&&
rawDataList
.
get
(
i
)[
8
]
!=
null
)
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
8
].
toString
(),
2000
,
locale
));
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
)
{
sb
.
append
(
validateLength
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
],
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])].
toString
(),
2000
,
locale
));
}
// for (int j = 12; j < header.size(); j++) {
// if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) {
...
...
@@ -1153,13 +1175,13 @@ public class CustomerServiceImpl implements CustomerService {
// }
// }
// }
Row
dataRow
=
sheet
.
getRow
(
4
+
i
);
Cell
resultCell
=
dataRow
.
createCell
(
row
.
getPhysicalNumberOfCells
()
-
1
);
//
Row dataRow = sheet.getRow(4 + i);
//
Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1);
if
(
sb
.
length
()
>
0
)
{
r
esultCell
.
setCellValue
(
sb
.
toString
()
);
r
awDataList
.
get
(
i
)[
objectSize
]
=
sb
.
toString
(
);
failedCount
++;
}
else
{
r
esultCell
.
setCellValue
(
"Ok"
)
;
r
awDataList
.
get
(
i
)[
objectSize
]
=
"Ok"
;
}
sb
=
new
StringBuilder
();
isEmailNull
=
false
;
...
...
@@ -1168,18 +1190,24 @@ public class CustomerServiceImpl implements CustomerService {
}
//</editor-fold>
byte
[]
content
=
buildResultTemplate
(
rawDataList
,
header
,
headerMap
,
row
.
getLastCellNum
());
//<editor-fold desc="Insert dữ liệu nếu validate Ok" defaultstate="collapsed">
if
(
failedCount
==
0
)
{
for
(
int
i
=
0
;
i
<
rawDataList
.
size
();
i
++)
{
Customer
c
=
new
Customer
();
c
.
setName
(
rawDataList
.
get
(
i
)[
1
].
toString
().
trim
());
c
.
setName
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.fullname"
,
locale
).
split
(
"#"
)[
0
])
].
toString
().
trim
());
c
.
setSiteId
(
userSession
.
getSiteId
());
c
.
setCode
(
null
);
if
(
rawDataList
.
get
(
i
).
length
>
8
&&
rawDataList
.
get
(
i
)[
8
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
8
].
toString
().
trim
().
equals
(
""
))
{
c
.
setDescription
(
rawDataList
.
get
(
i
)[
8
].
toString
().
trim
());
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
&&
!
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
equals
(
""
))
{
c
.
setDescription
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.description"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
());
}
if
(
rawDataList
.
get
(
i
).
length
>
7
&&
rawDataList
.
get
(
i
)[
7
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
7
].
toString
().
trim
().
equals
(
""
))
{
c
.
setCompanyName
(
rawDataList
.
get
(
i
)[
7
].
toString
().
trim
());
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
&&
!
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
equals
(
""
))
{
c
.
setCompanyName
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.companyName"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
());
}
c
.
setCustomerImg
(
null
);
c
.
setCreateDate
(
new
Date
());
...
...
@@ -1188,8 +1216,10 @@ public class CustomerServiceImpl implements CustomerService {
c
.
setCreateBy
(
userSession
.
getUserName
());
c
.
setUpdateBy
(
null
);
c
.
setGender
((
short
)
1
);
if
(
rawDataList
.
get
(
i
).
length
>
5
&&
rawDataList
.
get
(
i
)[
5
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
5
].
toString
().
trim
().
equals
(
""
))
{
c
.
setCurrentAddress
(
rawDataList
.
get
(
i
)[
5
].
toString
().
trim
());
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
&&
!
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
equals
(
""
))
{
c
.
setCurrentAddress
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.address"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
());
}
// c.setPlaceOfBirth();
// c.setDateOfBirth();
...
...
@@ -1197,7 +1227,7 @@ public class CustomerServiceImpl implements CustomerService {
c
.
setEmail
(
null
);
c
.
setUserName
(
null
);
c
.
setAreaCode
(
null
);
switch
(
rawDataList
.
get
(
i
)[
6
].
toString
().
trim
())
{
switch
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
))
].
toString
().
trim
())
{
case
"VIP"
:
c
.
setCustomerType
(
2L
);
break
;
...
...
@@ -1208,25 +1238,26 @@ public class CustomerServiceImpl implements CustomerService {
c
.
setCustomerType
(
1L
);
break
;
}
if
(
rawDataList
.
get
(
i
)[
9
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
if
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.callAllowed"
,
locale
))
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
c
.
setCallAllowed
(
1L
);
}
else
{
c
.
setCallAllowed
(
0L
);
}
if
(
rawDataList
.
get
(
i
)[
10
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
if
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.emailAllowed"
,
locale
))
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
c
.
setEmailAllowed
(
1L
);
}
else
{
c
.
setEmailAllowed
(
0L
);
}
if
(
rawDataList
.
get
(
i
)[
11
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
if
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.smsAllowed"
,
locale
))
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
c
.
setSmsAllowed
(
1L
);
}
else
{
c
.
setSmsAllowed
(
0L
);
}
c
.
setIpccStatus
(
"active"
);
Customer
saved
=
customerRepository
.
save
(
c
);
if
(
rawDataList
.
get
(
i
).
length
>
2
&&
rawDataList
.
get
(
i
)[
2
]
!=
null
)
{
String
[]
mainPhone
=
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
().
split
(
";"
);
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
)
{
String
[]
mainPhone
=
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.mainPhone"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
split
(
";"
);
for
(
int
j
=
0
;
j
<
mainPhone
.
length
;
j
++)
{
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
...
...
@@ -1242,8 +1273,9 @@ public class CustomerServiceImpl implements CustomerService {
customerContactRepository
.
save
(
cc
);
}
}
if
(
rawDataList
.
get
(
i
).
length
>
3
&&
rawDataList
.
get
(
i
)[
3
]
!=
null
)
{
String
[]
subPhone
=
rawDataList
.
get
(
i
)[
3
].
toString
().
trim
().
split
(
";"
);
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
)
{
String
[]
subPhone
=
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.secondPhone"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
trim
().
split
(
";"
);
for
(
int
j
=
0
;
j
<
subPhone
.
length
;
j
++)
{
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
...
...
@@ -1259,8 +1291,9 @@ public class CustomerServiceImpl implements CustomerService {
customerContactRepository
.
save
(
cc
);
}
}
if
(
rawDataList
.
get
(
i
).
length
>
4
&&
rawDataList
.
get
(
i
)[
4
]
!=
null
)
{
String
[]
email
=
rawDataList
.
get
(
i
)[
4
].
toString
().
split
(
";"
);
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])]
!=
null
)
{
String
[]
email
=
rawDataList
.
get
(
i
)[
headerMap
.
get
(
BundleUtils
.
getLangString
(
"customer.email"
,
locale
).
split
(
"#"
)[
0
])].
toString
().
split
(
";"
);
for
(
int
j
=
0
;
j
<
email
.
length
;
j
++)
{
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
...
...
@@ -1280,29 +1313,29 @@ public class CustomerServiceImpl implements CustomerService {
CustomizeFieldObject
cfo
=
new
CustomizeFieldObject
();
cfo
.
setObjectId
(
saved
.
getCustomerId
());
cfo
.
setCustomizeFieldId
(
dynamicHeader
.
get
(
j
).
getCustomizeFieldId
());
if
(
rawDataList
.
get
(
i
).
length
>
(
12
+
j
)
&&
rawDataList
.
get
(
i
)[
12
+
j
]
!=
null
)
{
if
(
rawDataList
.
get
(
i
).
length
>
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
&&
rawDataList
.
get
(
i
)[
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
]
!=
null
)
{
switch
(
dynamicHeader
.
get
(
j
).
getType
())
{
case
"combobox"
:
CustomizeFieldOptionValue
cfov
=
customizeFieldOptionValueRepository
.
findCustomizeFieldOptionValueByNameEqualsAndStatus
(
rawDataList
.
get
(
i
)[
12
+
j
].
toString
().
trim
(),
1L
);
customizeFieldOptionValueRepository
.
findCustomizeFieldOptionValueByNameEqualsAndStatus
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
].
toString
().
trim
(),
1L
);
cfo
.
setFieldOptionValueId
(
cfov
.
getFieldOptionValueId
());
break
;
case
"checkbox"
:
if
(
rawDataList
.
get
(
i
)[
12
+
j
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
if
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
].
toString
().
trim
().
equals
(
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
)))
{
cfo
.
setValueCheckbox
(
1L
);
}
else
{
cfo
.
setValueCheckbox
(
0L
);
}
break
;
case
"date"
:
Date
date
=
dateFormat
.
parse
(
rawDataList
.
get
(
i
)[
12
+
j
].
toString
().
trim
());
Date
date
=
dateFormat
.
parse
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
].
toString
().
trim
());
cfo
.
setValueDate
(
date
);
break
;
case
"number"
:
cfo
.
setValueNumber
(
Long
.
parseLong
(
rawDataList
.
get
(
i
)[
12
+
j
].
toString
().
trim
()));
cfo
.
setValueNumber
(
Long
.
parseLong
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
].
toString
().
trim
()));
break
;
default
:
cfo
.
setValueText
(
rawDataList
.
get
(
i
)[
12
+
j
].
toString
().
trim
());
cfo
.
setValueText
(
rawDataList
.
get
(
i
)[
headerMap
.
get
(
dynamicHeader
.
get
(
j
).
getTitle
())
].
toString
().
trim
());
break
;
}
}
...
...
@@ -1319,18 +1352,14 @@ public class CustomerServiceImpl implements CustomerService {
clm
.
setCustomerListId
(
customerListId
);
customerListMappingRepository
.
save
(
clm
);
}
workbook
.
write
(
os
);
os
.
flush
();
os
.
close
();
// workbook.write(os);
workbook
.
close
();
result
.
put
(
"content"
,
os
.
toByteArray
()
);
result
.
put
(
"content"
,
content
);
result
.
put
(
"message"
,
"import-success"
);
}
else
{
workbook
.
write
(
os
);
os
.
flush
();
os
.
close
();
// workbook.write(os);
workbook
.
close
();
result
.
put
(
"content"
,
os
.
toByteArray
()
);
result
.
put
(
"content"
,
content
);
result
.
put
(
"message"
,
"import-error"
);
}
//</editor-fold>
...
...
@@ -1351,12 +1380,23 @@ public class CustomerServiceImpl implements CustomerService {
String
[]
arr
=
str
.
split
(
";"
);
List
<
CustomerContact
>
contactList
;
if
(
str
.
length
()
>
50
)
{
result
=
BundleUtils
.
getLangString
(
"customer.phoneMax50"
,
locale
);
result
+=
BundleUtils
.
getLangString
(
"customer.phoneMax50"
,
locale
);
}
if
(
arr
.
length
>
3
)
{
result
+=
BundleUtils
.
getLangString
(
"customer.3phone"
,
locale
);
}
else
{
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
if
(
arr
[
i
].
length
()
<
8
||
arr
[
i
].
length
()
>
15
)
{
result
+=
BundleUtils
.
getLangString
(
"customer.phone8to15"
,
locale
);
break
;
}
}
}
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
contactList
=
customerContactRepository
.
findCustomerContactsByContactEquals
(
arr
[
i
]);
if
(
contactList
.
size
()
!=
0
)
{
return
result
.
concat
(
BundleUtils
.
getLangString
(
"customer.phoneExists"
,
locale
));
result
+=
BundleUtils
.
getLangString
(
"customer.phoneExists"
,
locale
);
break
;
}
}
return
result
;
...
...
@@ -1376,7 +1416,7 @@ public class CustomerServiceImpl implements CustomerService {
private
String
validateDuplicateEmail
(
String
str
,
Locale
locale
)
{
String
result
=
""
;
String
[]
arr
=
str
.
split
(
"
;
"
);
String
[]
arr
=
str
.
split
(
"
,
"
);
List
<
CustomerContact
>
contactList
;
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
contactList
=
customerContactRepository
.
findCustomerContactsByContactEquals
(
arr
[
i
]);
...
...
@@ -1408,7 +1448,7 @@ public class CustomerServiceImpl implements CustomerService {
}
private
boolean
validateEmail
(
String
str
)
{
String
[]
arr
=
str
.
split
(
"
;
"
);
String
[]
arr
=
str
.
split
(
"
,
"
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
Matcher
matcher
=
EMAIL_REGEXP
.
matcher
(
arr
[
i
]);
if
(!
matcher
.
matches
())
{
...
...
@@ -1448,6 +1488,183 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold>
private
byte
[]
buildResultTemplate
(
List
<
Object
[]>
rawData
,
List
<
CustomizeFields
>
header
,
Map
<
String
,
Integer
>
dataMap
,
int
lastNum
)
throws
IOException
{
LOGGER
.
info
(
"---------------CREATE RESULT FILE--------------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
XSSFWorkbook
workbook
=
null
;
Map
<
String
,
Integer
>
headerMap
=
new
HashMap
<>();
try
{
workbook
=
new
XSSFWorkbook
();
CreationHelper
creationHelper
=
workbook
.
getCreationHelper
();
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
Sheet
sheet
=
workbook
.
createSheet
(
"RESULT"
);
dataMap
.
put
(
BundleUtils
.
getLangString
(
"customer.result"
,
locale
),
lastNum
);
//<editor-fold desc="Tạo style và font" defaultstate="collapsed">
Font
headerFont
=
workbook
.
createFont
();
Font
importantFont
=
workbook
.
createFont
();
importantFont
.
setColor
(
IndexedColors
.
RED
.
index
);
headerFont
.
setBold
(
true
);
CellStyle
headerStyle
=
workbook
.
createCellStyle
();
CellStyle
importantStyle
=
workbook
.
createCellStyle
();
CellStyle
columnStyle
=
workbook
.
createCellStyle
();
importantStyle
.
setFont
(
importantFont
);
headerStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
headerStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
headerStyle
.
setFont
(
headerFont
);
columnStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
columnStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
columnStyle
.
setWrapText
(
true
);
//</editor-fold>
//<editor-fold desc="Thêm combobox" defaultstate="collapsed">
//<editor-fold desc="Cho những trường động" defaultstate="collapsed">
DataValidationHelper
dataValidationHelper
=
sheet
.
getDataValidationHelper
();
for
(
int
i
=
12
;
i
<
header
.
size
();
i
++)
{
if
(
header
.
get
(
i
).
getType
().
equals
(
"combobox"
))
{
String
[]
constraint
;
List
<
CustomizeFieldOptionValue
>
list
=
customizeFieldOptionValueRepository
.
findCustomizeFieldOptionValuesByFieldOptionIdAndStatus
(
header
.
get
(
i
).
getFieldOptionsId
(),
1L
);
constraint
=
new
String
[
list
.
size
()];
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
constraint
[
j
]
=
list
.
get
(
j
).
getName
();
}
DataValidationConstraint
comboboxConstraint
=
dataValidationHelper
.
createExplicitListConstraint
(
constraint
);
CellRangeAddressList
comboboxCellRange
=
new
CellRangeAddressList
(
4
,
9999
,
12
+
i
,
12
+
i
);
DataValidation
comboboxValidation
=
dataValidationHelper
.
createValidation
(
comboboxConstraint
,
comboboxCellRange
);
comboboxValidation
.
setSuppressDropDownArrow
(
true
);
comboboxValidation
.
setShowErrorBox
(
true
);
sheet
.
addValidationData
(
comboboxValidation
);
}
else
if
(
header
.
get
(
i
).
getType
().
equals
(
"checkbox"
))
{
DataValidationConstraint
yesNoConstraint
=
dataValidationHelper
.
createExplicitListConstraint
(
new
String
[]{
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
),
BundleUtils
.
getLangString
(
"customer.not"
,
locale
)});
CellRangeAddressList
checkboxCellRange
=
new
CellRangeAddressList
(
4
,
9999
,
12
+
i
,
12
+
i
);
DataValidation
yesNoValidation
=
dataValidationHelper
.
createValidation
(
yesNoConstraint
,
checkboxCellRange
);
yesNoValidation
.
setShowErrorBox
(
true
);
yesNoValidation
.
setSuppressDropDownArrow
(
true
);
sheet
.
addValidationData
(
yesNoValidation
);
}
}
//</editor-fold>
//<editor-fold desc="Cho những trường tĩnh" defaultstate="collapsed">
DataValidationConstraint
cusTypeConstraint
=
dataValidationHelper
.
createExplicitListConstraint
(
new
String
[]{
BundleUtils
.
getLangString
(
"customer.cusType.normal"
,
locale
),
BundleUtils
.
getLangString
(
"customer.cusType.vip"
,
locale
),
BundleUtils
.
getLangString
(
"customer.cusType.blacklist"
,
locale
)});
DataValidationConstraint
isAllowConstraint
=
dataValidationHelper
.
createExplicitListConstraint
(
new
String
[]{
BundleUtils
.
getLangString
(
"customer.yes"
,
locale
),
BundleUtils
.
getLangString
(
"customer.not"
,
locale
)});
CellRangeAddressList
cusTypeCellRangeAddressList
=
new
CellRangeAddressList
(
4
,
9999
,
6
,
6
);
CellRangeAddressList
callCellRangeAddressList
=
new
CellRangeAddressList
(
4
,
9999
,
9
,
9
);
CellRangeAddressList
emailCellRangeAddressList
=
new
CellRangeAddressList
(
4
,
9999
,
10
,
10
);
CellRangeAddressList
smsCellRangeAddressList
=
new
CellRangeAddressList
(
4
,
9999
,
11
,
11
);
DataValidation
cusTypeValidation
=
dataValidationHelper
.
createValidation
(
cusTypeConstraint
,
cusTypeCellRangeAddressList
);
DataValidation
callValidation
=
dataValidationHelper
.
createValidation
(
isAllowConstraint
,
callCellRangeAddressList
);
DataValidation
emailValidation
=
dataValidationHelper
.
createValidation
(
isAllowConstraint
,
emailCellRangeAddressList
);
DataValidation
smsValidation
=
dataValidationHelper
.
createValidation
(
isAllowConstraint
,
smsCellRangeAddressList
);
cusTypeValidation
.
setSuppressDropDownArrow
(
true
);
cusTypeValidation
.
setShowErrorBox
(
true
);
callValidation
.
setSuppressDropDownArrow
(
true
);
callValidation
.
setShowErrorBox
(
true
);
emailValidation
.
setSuppressDropDownArrow
(
true
);
emailValidation
.
setShowErrorBox
(
true
);
smsValidation
.
setSuppressDropDownArrow
(
true
);
smsValidation
.
setShowErrorBox
(
true
);
sheet
.
addValidationData
(
cusTypeValidation
);
sheet
.
addValidationData
(
callValidation
);
sheet
.
addValidationData
(
emailValidation
);
sheet
.
addValidationData
(
smsValidation
);
//</editor-fold>
//</editor-fold>
//<editor-fold desc="Ghi header" defaultstate="collapsed">
Drawing
drawing
=
sheet
.
createDrawingPatriarch
();
ClientAnchor
anchor
=
creationHelper
.
createClientAnchor
();
Row
row0
=
sheet
.
createRow
(
0
);
Row
row2
=
sheet
.
createRow
(
2
);
Row
row3
=
sheet
.
createRow
(
3
);
Cell
cell0
=
row0
.
createCell
(
0
);
cell0
.
setCellStyle
(
headerStyle
);
cell0
.
setCellValue
(
BundleUtils
.
getLangString
(
"customer.importCustomer"
,
locale
));
Cell
cell2
=
row2
.
createCell
(
0
);
cell2
.
setCellStyle
(
importantStyle
);
cell2
.
setCellValue
(
BundleUtils
.
getLangString
(
"customer.notice"
,
locale
));
for
(
int
i
=
0
;
i
<
header
.
size
();
i
++)
{
sheet
.
setDefaultColumnStyle
(
i
,
columnStyle
);
Cell
headerCell
=
row3
.
createCell
(
i
);
headerCell
.
setCellValue
(
header
.
get
(
i
).
getTitle
().
split
(
"#"
)[
0
]);
headerStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
headerStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
headerStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
headerStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
headerFont
.
setFontHeightInPoints
((
short
)
11
);
headerCell
.
setCellStyle
(
headerStyle
);
if
(
i
==
0
)
{
sheet
.
setColumnWidth
(
i
,
2500
);
}
else
{
sheet
.
setColumnWidth
(
i
,
6000
);
}
anchor
.
setCol1
(
headerCell
.
getColumnIndex
());
anchor
.
setCol2
(
headerCell
.
getColumnIndex
()
+
2
);
anchor
.
setRow1
(
row3
.
getRowNum
());
anchor
.
setRow2
(
row3
.
getRowNum
()
+
4
);
if
(
header
.
get
(
i
).
getTitle
().
contains
(
"#"
))
{
Comment
comment
=
drawing
.
createCellComment
(
anchor
);
RichTextString
str
=
creationHelper
.
createRichTextString
(
header
.
get
(
i
).
getTitle
().
split
(
"#"
)[
1
]);
comment
.
setString
(
str
);
comment
.
setAuthor
(
"APACHE POI"
);
headerCell
.
setCellComment
(
comment
);
}
headerMap
.
put
(
header
.
get
(
i
).
getTitle
().
split
(
"#"
)[
0
].
trim
(),
i
);
}
sheet
.
setColumnWidth
(
header
.
size
(),
8000
);
Cell
resultCell
=
row3
.
createCell
(
header
.
size
());
resultCell
.
setCellStyle
(
headerStyle
);
resultCell
.
setCellValue
(
BundleUtils
.
getLangString
(
"customer.result"
,
locale
));
headerMap
.
put
(
BundleUtils
.
getLangString
(
"customer.result"
,
locale
),
headerMap
.
size
());
//</editor-fold>
//<editor-fold desc="Ghi dữ liệu">
for
(
int
i
=
0
;
i
<
rawData
.
size
();
i
++)
{
Row
dataRow
=
sheet
.
createRow
(
4
+
i
);
int
finalI
=
i
;
headerMap
.
forEach
((
k
,
v
)
->
{
Cell
c
=
dataRow
.
createCell
(
v
);
c
.
setCellType
(
CellType
.
STRING
);
if
(
rawData
.
get
(
finalI
).
length
>
dataMap
.
get
(
k
)
&&
rawData
.
get
(
finalI
)[
dataMap
.
get
(
k
)]
!=
null
&&
!
""
.
equals
(
rawData
.
get
(
finalI
)[
dataMap
.
get
(
k
)].
toString
().
trim
()))
{
c
.
setCellValue
(
rawData
.
get
(
finalI
)[
dataMap
.
get
(
k
)].
toString
());
}
});
// for (int j = 0; j < header.size(); j++) {
// headerMap.get(header.get(j).getTitle().split("#")[0]);
// if (rawData.get(i).length > header.size() + 1 && rawData.get(i)[j] != null && !"".equals(rawData.get(i)[j].toString().trim())) {
// Cell c = dataRow.createCell(j);
// c.setCellType(CellType.STRING);
// c.setCellValue(rawData.get(i)[j].toString());
// }
// }
}
//</editor-fold>
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
1
,
0
,
13
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
2
,
2
,
0
,
13
));
workbook
.
write
(
os
);
os
.
flush
();
os
.
close
();
return
os
.
toByteArray
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
return
null
;
}
finally
{
if
(
workbook
!=
null
)
workbook
.
close
();
}
}
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
byte
[]
buildTemplate
(
Long
companySiteId
)
throws
IOException
{
...
...
@@ -1459,6 +1676,7 @@ public class CustomerServiceImpl implements CustomerService {
CreationHelper
creationHelper
=
workbook
.
getCreationHelper
();
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
Sheet
sheet
=
workbook
.
createSheet
(
"IMPORT"
);
DataFormat
dataFormat
=
workbook
.
createDataFormat
();
//<editor-fold desc="Tạo array header" defaultstate="collapsed">
List
<
CustomizeFields
>
header
=
new
ArrayList
<>();
...
...
@@ -1494,6 +1712,7 @@ public class CustomerServiceImpl implements CustomerService {
columnStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
columnStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
columnStyle
.
setWrapText
(
true
);
columnStyle
.
setDataFormat
(
dataFormat
.
getFormat
(
"@"
));
//</editor-fold>
//<editor-fold desc="Thêm combobox" defaultstate="collapsed">
...
...
src/main/java/com/viettel/campaign/utils/Constants.java
View file @
57bf4800
...
...
@@ -7,10 +7,12 @@ public class Constants {
public
interface
ApiErrorCode
{
String
ERROR
=
"01"
;
String
SUCCESS
=
"00"
;
String
DELETE_ERROR
=
"02"
;
}
public
interface
ApiErrorDesc
{
String
ERROR
=
"ERROR"
;
String
SUCCESS
=
"SUCCESS"
;
String
DELETE_ERROR
=
"DELETE_ERROR"
;
}
public
interface
FileType
{
String
pdf
=
"pdf"
;
...
...
src/main/resources/i18n/language_en.properties
View file @
57bf4800
...
...
@@ -87,15 +87,13 @@ customer.cusType.vip = VIP
customer.cusType.blacklist
=
Blacklist
customer.yes
=
Yes
customer.not
=
No
customer.noData
=
Template empty
customer.nameRequired
=
Full name required;
customer.emailMax100
=
Email must less than 100 character;
customer.invalidRecord
=
Invalid Record, required one more contact information;
customer.onlyNumber
=
Phone contain number only;
customer.importSuccess
=
Import Successful
customer.importFailed
=
Import Failed
customer.errorValidate
=
Error while validating
customer.phoneMax50
=
Mobile phone must less than 50 character;
customer.phoneMax50
=
Mobile phone must less than 50 characters;
customer.phone8to15
=
Mobile phone from 8 to 15 characters;
customer.3phone
=
Max 3 mobile phone;
customer.phoneExists
=
Mobile phone exists;
customer.notMatch
=
not match regexp validation
customer.notGreaterThan
=
not greater than
...
...
src/main/resources/i18n/language_vi.properties
View file @
57bf4800
...
...
@@ -89,15 +89,13 @@ customer.cusType.vip = VIP
customer.cusType.blacklist
=
Blacklist
customer.yes
=
Có
customer.not
=
Không
customer.noData
=
Template không có dữ liệu
customer.nameRequired
=
Họ và tên không được để trống;
customer.emailMax100
=
Email không được quá 100 kí tự;
customer.invalidRecord
=
Bắt buộc nhập 1 trong 3 thông tin liên lạc(Số điện thoại chính, Số điện thoại phụ, Email);
customer.onlyNumber
=
Số điện thoại chỉ được nhập số;
customer.importSuccess
=
Import dữ liệu thành công
customer.importFailed
=
Import dữ liệu thất bại
customer.errorValidate
=
Validate dữ liệu lỗi
customer.phoneMax50
=
Số điện thoại không được quá 50 kí tự;
customer.phone8to15
=
Số điện thoại chỉ được từ 8 đến 15 kí tự;
customer.3phone
=
Tối đa chỉ được nhập 3 số điện thoại;
customer.phoneExists
=
Số điện thoại chính đã tồn tại;
customer.notMatch
=
không đúng định dạng
customer.notGreaterThan
=
không được lớn hơn
...
...
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