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
8890ea24
Commit
8890ea24
authored
Aug 26, 2019
by
Tu Bach
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into tubn
parents
7a345766
0193956c
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
334 additions
and
185 deletions
+334
-185
pom.xml
pom.xml
+2
-2
src/main/java/com/viettel/campaign/filter/CorsFilter.java
src/main/java/com/viettel/campaign/filter/CorsFilter.java
+21
-22
src/main/java/com/viettel/campaign/job/CampaignJob.java
src/main/java/com/viettel/campaign/job/CampaignJob.java
+63
-63
src/main/java/com/viettel/campaign/repository/ccms_full/impl/CampaignExecuteRepositoryImp.java
...pository/ccms_full/impl/CampaignExecuteRepositoryImp.java
+6
-5
src/main/java/com/viettel/campaign/repository/ccms_full/impl/CampaignRepositoryImpl.java
...ign/repository/ccms_full/impl/CampaignRepositoryImpl.java
+3
-3
src/main/java/com/viettel/campaign/service/CustomerService.java
...in/java/com/viettel/campaign/service/CustomerService.java
+2
-0
src/main/java/com/viettel/campaign/service/impl/CustomerServiceImpl.java
...om/viettel/campaign/service/impl/CustomerServiceImpl.java
+83
-52
src/main/java/com/viettel/campaign/service/impl/ScenarioServiceImpl.java
...om/viettel/campaign/service/impl/ScenarioServiceImpl.java
+105
-24
src/main/java/com/viettel/campaign/utils/Config.java
src/main/java/com/viettel/campaign/utils/Config.java
+2
-1
src/main/java/com/viettel/campaign/web/rest/CustomerController.java
...ava/com/viettel/campaign/web/rest/CustomerController.java
+22
-11
src/main/java/com/viettel/campaign/web/rest/ScenarioController.java
...ava/com/viettel/campaign/web/rest/ScenarioController.java
+1
-1
src/main/resources/application.yml
src/main/resources/application.yml
+5
-1
src/main/resources/i18n/language_en.properties
src/main/resources/i18n/language_en.properties
+10
-0
src/main/resources/i18n/language_vi.properties
src/main/resources/i18n/language_vi.properties
+9
-0
No files found.
pom.xml
View file @
8890ea24
...
...
@@ -49,8 +49,8 @@
<dependency>
<groupId>
com.oracle
</groupId>
<artifactId>
ojdbc7
</artifactId>
<scope>
system
</scope
>
<systemPath>
${project.basedir}/lib/ojdbc7.jar
</systemPath
>
<!-- <scope>system</scope>--
>
<!-- <systemPath>${project.basedir}/lib/ojdbc7.jar</systemPath>--
>
<version>
1.0
</version>
</dependency>
<dependency>
...
...
src/main/java/com/viettel/campaign/filter/CorsFilter.java
View file @
8890ea24
...
...
@@ -2,7 +2,6 @@ package com.viettel.campaign.filter;
import
com.viettel.campaign.utils.RedisUtil
;
import
com.viettel.econtact.filter.UserSession
;
import
org.apache.log4j.Logger
;
import
org.springframework.stereotype.Component
;
import
javax.servlet.*
;
...
...
@@ -31,27 +30,27 @@ public class CorsFilter implements Filter {
HttpServletRequest
request
=
(
HttpServletRequest
)
req
;
chain
.
doFilter
(
req
,
resp
);
//
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
//
chain.doFilter(req, resp);
//
return;
//
}
//
if ("/".equals(request.getRequestURI())) {
//
chain.doFilter(req, resp);
//
return;
//
}
//
String xAuthToken = request.getHeader("X-Auth-Token");
//
if (xAuthToken == null || "".equals(xAuthToken)) {
//
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is null.");
//
return;
//
}
//
Object obj = RedisUtil.getInstance().get(xAuthToken);
//
if (obj instanceof UserSession) {
//
chain.doFilter(req, resp);
//
} else {
//
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is invalid.");
//
}
// chain.doFilter(req, response
);
if
(
"OPTIONS"
.
equalsIgnoreCase
(
request
.
getMethod
()))
{
chain
.
doFilter
(
req
,
resp
);
return
;
}
if
(
"/"
.
equals
(
request
.
getRequestURI
()))
{
chain
.
doFilter
(
req
,
resp
);
return
;
}
String
xAuthToken
=
request
.
getHeader
(
"X-Auth-Token"
);
if
(
xAuthToken
==
null
||
""
.
equals
(
xAuthToken
))
{
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"The token is null."
);
return
;
}
Object
obj
=
RedisUtil
.
getInstance
().
get
(
xAuthToken
);
if
(
obj
instanceof
UserSession
)
{
chain
.
doFilter
(
req
,
resp
);
}
else
{
response
.
sendError
(
HttpServletResponse
.
SC_UNAUTHORIZED
,
"The token is invalid."
);
}
}
@Override
...
...
src/main/java/com/viettel/campaign/job/CampaignJob.java
View file @
8890ea24
...
...
@@ -42,69 +42,69 @@ public class CampaignJob {
// @Scheduled(fixedRate = 5000)
// @Transactional( propagation = Propagation.REQUIRED)
public
void
process
()
{
//
log.info(Thread.currentThread().getName() + " The Task executed at " + dateFormat.format(new Date()));
//
List<ProcessConfig> list = processConfigService.findAll();
//
//
list.parallelStream().forEach(p -> {
//
boolean isExecute = DateTimeUtil.isRun(p.getConfigValue(), p.getLastProcess());
//
switch (p.getConfigCode()){
//
case CUSTOMER_INACTIVE_DUARATION:
//
if(isExecute){
//
List<Customer> customers = customerService.findAllByCondition(p.getSiteId(), new Date());
//
updateCustomer(customers);
//
updateCustomerTime(customers);
//
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
//
p.setLastProcess(new Date());
//
processConfigService.update(p);
//
}
//
break;
//
case CRON_EXPRESSION_CHECK_START:
//
// process
//
if(isExecute){
//
List<Long> status = new ArrayList<>();
//
status.add(1L);
//
status.add(1L);
//
List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
//
campaigns.parallelStream().forEach(campaign -> {
//
log.info("Chuyen trang thai chien dich ... #{} ... tu Du thao sang Trien khai", campaign.getCampaignId());
//
campaign.setProcessStatus(1);
//
campaign.setStatus(2L);
//
campaign.setCampaignStart(new Date());
//
campaignService.updateProcess(campaign);
//
//write log
//
saveLog(campaign, 1);
//
});
//
//
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
//
p.setLastProcess(new Date());
//
processConfigService.update(p);
//
}
//
break;
//
case CRON_EXPRESSION_CHECK_END:
//
// process
//
if(isExecute){
//
List<Long> status = new ArrayList<>();
//
status.add(2L);
//
status.add(3L);
//
List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
//
campaigns.parallelStream().forEach(campaign -> {
//
log.info("Chuyen trang thai chien dich ... #{} ... sang Ket thuc", campaign.getCampaignId());
//
campaign.setStatus(4L);
//
campaign.setCampaignEnd(new Date());
//
campaignService.updateProcess(campaign);
//
//write log
//
saveLog(campaign, 2);
//
});
//
//
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
//
p.setLastProcess(new Date());
//
processConfigService.update(p);
//
}
//
break;
//
default:
//
// update last check time
//
}
//
});
log
.
info
(
Thread
.
currentThread
().
getName
()
+
" The Task executed at "
+
dateFormat
.
format
(
new
Date
()));
List
<
ProcessConfig
>
list
=
processConfigService
.
findAll
();
list
.
parallelStream
().
forEach
(
p
->
{
boolean
isExecute
=
DateTimeUtil
.
isRun
(
p
.
getConfigValue
(),
p
.
getLastProcess
());
switch
(
p
.
getConfigCode
()){
case
CUSTOMER_INACTIVE_DUARATION:
if
(
isExecute
){
List
<
Customer
>
customers
=
customerService
.
findAllByCondition
(
p
.
getSiteId
(),
new
Date
());
updateCustomer
(
customers
);
updateCustomerTime
(
customers
);
log
.
info
(
"Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}"
,
p
.
getSiteId
());
p
.
setLastProcess
(
new
Date
());
processConfigService
.
update
(
p
);
}
break
;
case
CRON_EXPRESSION_CHECK_START:
// process
if
(
isExecute
){
List
<
Long
>
status
=
new
ArrayList
<>();
status
.
add
(
1L
);
status
.
add
(
1L
);
List
<
Campaign
>
campaigns
=
campaignService
.
findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn
(
p
.
getSiteId
(),
new
Date
(),
status
);
campaigns
.
parallelStream
().
forEach
(
campaign
->
{
log
.
info
(
"Chuyen trang thai chien dich ... #{} ... tu Du thao sang Trien khai"
,
campaign
.
getCampaignId
());
campaign
.
setProcessStatus
(
1
);
campaign
.
setStatus
(
2L
);
campaign
.
setCampaignStart
(
new
Date
());
campaignService
.
updateProcess
(
campaign
);
//write log
saveLog
(
campaign
,
1
);
});
log
.
info
(
"Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}"
,
p
.
getSiteId
());
p
.
setLastProcess
(
new
Date
());
processConfigService
.
update
(
p
);
}
break
;
case
CRON_EXPRESSION_CHECK_END:
// process
if
(
isExecute
){
List
<
Long
>
status
=
new
ArrayList
<>();
status
.
add
(
2L
);
status
.
add
(
3L
);
List
<
Campaign
>
campaigns
=
campaignService
.
findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn
(
p
.
getSiteId
(),
new
Date
(),
status
);
campaigns
.
parallelStream
().
forEach
(
campaign
->
{
log
.
info
(
"Chuyen trang thai chien dich ... #{} ... sang Ket thuc"
,
campaign
.
getCampaignId
());
campaign
.
setStatus
(
4L
);
campaign
.
setCampaignEnd
(
new
Date
());
campaignService
.
updateProcess
(
campaign
);
//write log
saveLog
(
campaign
,
2
);
});
log
.
info
(
"Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}"
,
p
.
getSiteId
());
p
.
setLastProcess
(
new
Date
());
processConfigService
.
update
(
p
);
}
break
;
default
:
// update last check time
}
});
}
...
...
src/main/java/com/viettel/campaign/repository/ccms_full/impl/CampaignExecuteRepositoryImp.java
View file @
8890ea24
...
...
@@ -149,7 +149,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
sql
.
append
(
" f.complete_name surveyStatus,"
);
sql
.
append
(
" g.status status,"
);
sql
.
append
(
" a.status recordStatus,"
);
sql
.
append
(
"
(a.end_time - a.start_call)*24*60
callTime"
);
sql
.
append
(
"
nvl((a.end_time - a.start_call)*24*60, 0)
callTime"
);
sql
.
append
(
" from contact_cust_result a"
);
sql
.
append
(
" left join campaign b on a.campaign_id = b.campaign_id"
);
sql
.
append
(
" left join vsa_users c on a.agent_id = c.user_id"
);
...
...
@@ -175,6 +175,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
sql
.
append
(
" select a.*, rownum row_ from data_temp a"
);
sql
.
append
(
" where a.callTime >= :p_call_time_from"
);
sql
.
append
(
" and a.callTime <= :p_call_time_to"
);
sql
.
append
(
" order by a.createTime desc"
);
sql
.
append
(
" ),"
);
sql
.
append
(
" count_total as ("
);
sql
.
append
(
" select count(*) totalRow from data"
);
...
...
@@ -195,8 +196,8 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
query
.
setParameter
(
"p_call_time_to"
,
dto
.
getCallTimeTo
());
query
.
setParameter
(
"p_list_campaign_code"
,
dto
.
getCampaignCode
());
query
.
setParameter
(
"p_phone_number"
,
dto
.
getPhoneNumber
());
query
.
setParameter
(
"p_campaign_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCampaignName
())
?
null
:
dto
.
getCampaignName
().
toUpperCase
());
query
.
setParameter
(
"p_user_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getAgentId
())
?
null
:
dto
.
getAgentId
().
toUpperCase
());
query
.
setParameter
(
"p_campaign_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCampaignName
())
?
null
:
dto
.
getCampaignName
().
t
rim
().
t
oUpperCase
());
query
.
setParameter
(
"p_user_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getAgentId
())
?
null
:
dto
.
getAgentId
().
t
rim
().
t
oUpperCase
());
query
.
setParameter
(
"p_page_number"
,
dto
.
getPage
());
query
.
setParameter
(
"p_page_size"
,
dto
.
getPageSize
());
...
...
@@ -342,8 +343,8 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
query
.
setParameter
(
"p_call_time_to"
,
dto
.
getCallTimeTo
());
query
.
setParameter
(
"p_list_campaign_code"
,
dto
.
getCampaignCode
());
query
.
setParameter
(
"p_phone_number"
,
dto
.
getPhoneNumber
());
query
.
setParameter
(
"p_campaign_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCampaignName
())
?
null
:
dto
.
getCampaignName
().
toUpperCase
());
query
.
setParameter
(
"p_user_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getAgentId
())
?
null
:
dto
.
getAgentId
().
toUpperCase
());
query
.
setParameter
(
"p_campaign_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCampaignName
())
?
null
:
dto
.
getCampaignName
().
t
rim
().
t
oUpperCase
());
query
.
setParameter
(
"p_user_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getAgentId
())
?
null
:
dto
.
getAgentId
().
t
rim
().
t
oUpperCase
());
query
.
setParameter
(
"p_page_number"
,
dto
.
getPage
());
query
.
setParameter
(
"p_page_size"
,
dto
.
getPageSize
());
...
...
src/main/java/com/viettel/campaign/repository/ccms_full/impl/CampaignRepositoryImpl.java
View file @
8890ea24
...
...
@@ -309,7 +309,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
"ORDER BY START_TIME DESC"
);
SQLQuery
query
=
session
.
createSQLQuery
(
sb
.
toString
());
query
.
setParameter
(
"p_company_site_id"
,
requestDto
.
getCompanySiteId
());
query
.
setParameter
(
"p_code"
,
DataUtil
.
isNullOrEmpty
(
requestDto
.
getCampaignCode
())
?
null
:
requestDto
.
getCampaignCode
().
toUpperCase
());
query
.
setParameter
(
"p_code"
,
DataUtil
.
isNullOrEmpty
(
requestDto
.
getCampaignCode
())
?
null
:
requestDto
.
getCampaignCode
().
t
rim
().
t
oUpperCase
());
query
.
addScalar
(
"campaignId"
,
new
LongType
());
query
.
addScalar
(
"campaignCode"
,
new
StringType
());
...
...
@@ -742,8 +742,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
SQLQuery
query
=
session
.
createSQLQuery
(
sb
.
toString
());
query
.
setParameter
(
"p_company_site_id"
,
dto
.
getCompanySiteId
());
query
.
setParameter
(
"p_campaign_id"
,
dto
.
getCampaignId
());
query
.
setParameter
(
"p_cus_list_code"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCustListCode
())
?
null
:
dto
.
getCustListCode
().
toUpperCase
());
query
.
setParameter
(
"p_cus_list_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCustListName
())
?
null
:
dto
.
getCustListName
().
toUpperCase
());
query
.
setParameter
(
"p_cus_list_code"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCustListCode
())
?
null
:
dto
.
getCustListCode
().
t
rim
().
t
oUpperCase
());
query
.
setParameter
(
"p_cus_list_name"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCustListName
())
?
null
:
dto
.
getCustListName
().
t
rim
().
t
oUpperCase
());
query
.
setParameter
(
"p_to_date"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCustListCode
())
?
null
:
dto
.
getCreateTimeTo
());
query
.
setParameter
(
"p_from_date"
,
DataUtil
.
isNullOrEmpty
(
dto
.
getCustListCode
())
?
null
:
dto
.
getCreateTimeFr
());
query
.
setParameter
(
"p_page_number"
,
dto
.
getPage
());
...
...
src/main/java/com/viettel/campaign/service/CustomerService.java
View file @
8890ea24
...
...
@@ -34,6 +34,8 @@ public interface CustomerService {
ResultDTO
getAllCustomerList
(
int
page
,
int
pageSize
,
String
sort
,
Long
companySiteId
);
// THÍM NÀO MERGE CONFLICT THÌ GIỮ LẠI HỘ E CÁI METHOD NÀY VỚI
// VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY
ResultDTO
createCustomerList
(
CustomerListDTO
customerListDTO
,
String
userName
);
ResultDTO
updateCustomerList
(
CustomerListDTO
customerListDTO
);
...
...
src/main/java/com/viettel/campaign/service/impl/CustomerServiceImpl.java
View file @
8890ea24
...
...
@@ -421,6 +421,7 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
ResultDTO
getCustomerDetailById
(
Long
companySiteId
,
Long
customerListId
,
Long
customerId
)
{
ResultDTO
resultDTO
=
new
ResultDTO
();
SessionFactory
sessionFactory
=
HibernateUtil
.
getSessionFactory
();
...
...
@@ -599,35 +600,38 @@ public class CustomerServiceImpl implements CustomerService {
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
ResultDTO
createCustomerList
(
CustomerListDTO
customerListDTO
,
String
userName
)
{
// THÍM NÀO MERGE CONFLICT THÌ GIỮ LẠI HỘ E CÁI METHOD NÀY VỚI
// VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY
ResultDTO
resultDTO
=
new
ResultDTO
();
CustomerListMapper
customerListMapper
=
new
CustomerListMapper
();
CustomerList
customerList
=
new
CustomerList
();
try
{
if
(
customerListDTO
!=
null
)
{
// insert
CustomerList
findCustomer
=
customerListRepository
.
findByCustomerListCode
(
customerListDTO
.
getCustomerListCode
());
if
(
findCustomer
==
null
)
{
customerListDTO
.
setCreateBy
(
userName
);
customerList
=
customerListMapper
.
toPersistenceBean
(
customerListDTO
);
customerListRepository
.
save
(
customerList
);
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
}
else
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
}
}
else
{
CustomerList
cl
=
customerListRepository
.
findByCustomerListCode
(
customerListDTO
.
getCustomerListCode
());
if
(
cl
!=
null
)
{
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
ERROR
);
resultDTO
.
setDescription
(
"Entity exists"
);
return
resultDTO
;
}
else
{
cl
=
new
CustomerList
();
cl
.
setCustomerListCode
(
customerListDTO
.
getCustomerListCode
());
cl
.
setCustomerListName
(
customerListDTO
.
getCustomerListName
());
cl
.
setStatus
((
short
)
1
);
cl
.
setCreateBy
(
userName
);
cl
.
setCreateAt
(
new
Date
());
cl
.
setUpdateBy
(
null
);
cl
.
setUpdateAt
(
null
);
cl
.
setSource
(
null
);
cl
.
setDeptCreate
(
null
);
cl
.
setCompanySiteId
(
customerListDTO
.
getCompanySiteId
());
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
SUCCESS
);
resultDTO
.
setDescription
(
Constants
.
ApiErrorDesc
.
SUCCESS
);
resultDTO
.
setData
(
customerListRepository
.
save
(
cl
));
return
resultDTO
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
LOGGER
.
error
(
e
.
getMessage
());
resultDTO
.
setErrorCode
(
Constants
.
ApiErrorCode
.
ERROR
);
resultDTO
.
setDescription
(
"Error"
);
return
resultDTO
;
}
return
resultDTO
;
}
@Override
...
...
@@ -880,6 +884,7 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
List
<
CustomizeFields
>
getDynamicHeader
(
Long
companySiteId
)
{
LOGGER
.
info
(
"------------------GET DYNAMIC HEADER-------------------"
);
List
<
CustomizeFields
>
headerList
;
...
...
@@ -893,10 +898,12 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
Map
<
String
,
Object
>
readAndValidateCustomer
(
String
path
,
List
<
CustomizeFields
>
dynamicHeader
,
UserSession
userSession
,
Long
customerListId
)
{
LOGGER
.
info
(
"------------READ AND VALIDATE--------------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"dd/MM/yyyy HH:mm:ss"
);
DataFormatter
dataFormat
=
new
DataFormatter
();
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"dd/MM/yyyy"
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
StringBuilder
sb
=
new
StringBuilder
();
boolean
validateOk
=
false
;
...
...
@@ -972,14 +979,7 @@ public class CustomerServiceImpl implements CustomerService {
for
(
int
j
=
0
;
j
<
row
.
getPhysicalNumberOfCells
();
j
++)
{
Cell
dataCell
=
dataRow
.
getCell
(
j
);
if
(
dataCell
!=
null
)
{
switch
(
dataCell
.
getCellTypeEnum
())
{
case
NUMERIC:
obj
[
j
]
=
dataCell
.
getNumericCellValue
();
break
;
default
:
obj
[
j
]
=
dataCell
.
getStringCellValue
();
break
;
}
obj
[
j
]
=
dataFormat
.
formatCellValue
(
dataCell
);
}
else
{
Cell
headerCell
=
row
.
getCell
(
j
);
if
(
headerCell
.
getStringCellValue
().
equals
(
BundleUtils
.
getLangString
(
"customer.cusType"
,
locale
)))
{
...
...
@@ -1016,9 +1016,12 @@ public class CustomerServiceImpl implements CustomerService {
&&
!
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
));
if
(
validateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
()))
{
str
.
concat
(
BundleUtils
.
getLangString
(
"customer.emailMax50"
,
locale
));
if
(!
validateEmail
(
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
()))
{
str
.
concat
(
BundleUtils
.
getLangString
(
"customer.emailInvalid"
,
locale
));
}
else
{
str
.
concat
(
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
);
}
else
{
sb
.
append
(
BundleUtils
.
getLangString
(
"customer.invalidCustomer"
,
locale
));
...
...
@@ -1032,17 +1035,17 @@ public class CustomerServiceImpl implements CustomerService {
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
));
}
for
(
int
j
=
12
;
j
<
header
.
size
();
j
++)
{
if
(
rawDataList
.
get
(
i
).
length
>
j
&&
rawDataList
.
get
(
i
)[
j
]
!=
null
)
{
if
(
header
.
get
(
j
).
getType
().
equals
(
"text"
))
{
sb
.
append
(
validateDynamicLength
(
header
.
get
(
j
).
getTitle
(),
rawDataList
.
get
(
i
)[
j
].
toString
(),
header
.
get
(
j
).
getMinLength
(),
header
.
get
(
j
).
getMaxLength
(),
locale
));
}
else
if
(
header
.
get
(
j
).
getType
().
equals
(
"date"
))
{
sb
.
append
(
validateUsingRegexp
(
header
.
get
(
j
).
getTitle
(),
rawDataList
.
get
(
i
)[
j
].
toString
(),
header
.
get
(
j
).
getRegexpForValidation
(),
locale
));
}
else
if
(
header
.
get
(
j
).
getType
().
equals
(
"number"
))
{
sb
.
append
(
validateDynamicLength
(
header
.
get
(
j
).
getTitle
(),
rawDataList
.
get
(
i
)[
j
].
toString
(),
header
.
get
(
j
).
getMin
(),
header
.
get
(
j
).
getMax
(),
locale
));
}
}
}
//
for (int j = 12; j < header.size(); j++) {
//
if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) {
//
if (header.get(j).getType().equals("text")) {
//
sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMinLength(), header.get(j).getMaxLength(), locale));
//
} else if (header.get(j).getType().equals("date")) {
//
sb.append(validateUsingRegexp(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getRegexpForValidation(), locale));
//
} else if (header.get(j).getType().equals("number")) {
//
sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMin(), header.get(j).getMax(), locale));
//
}
//
}
//
}
Row
dataRow
=
sheet
.
getRow
(
4
+
i
);
Cell
resultCell
=
dataRow
.
createCell
(
row
.
getPhysicalNumberOfCells
()
-
1
);
if
(
sb
.
length
()
>
0
)
{
...
...
@@ -1061,7 +1064,7 @@ public class CustomerServiceImpl implements CustomerService {
for
(
int
i
=
0
;
i
<
rawDataList
.
size
();
i
++)
{
Customer
c
=
new
Customer
();
c
.
setName
(
rawDataList
.
get
(
i
)[
1
].
toString
());
c
.
setSiteId
(
userSession
.
get
Company
SiteId
());
c
.
setSiteId
(
userSession
.
getSiteId
());
c
.
setCode
(
null
);
c
.
setDescription
(
rawDataList
.
get
(
i
)[
8
].
toString
());
c
.
setCompanyName
(
rawDataList
.
get
(
i
)[
7
].
toString
());
...
...
@@ -1107,11 +1110,12 @@ public class CustomerServiceImpl implements CustomerService {
}
c
.
setIpccStatus
(
"active"
);
Customer
saved
=
customerRepository
.
save
(
c
);
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
if
(
rawDataList
.
get
(
i
).
length
>
2
&&
rawDataList
.
get
(
i
)[
2
]
!=
null
)
{
String
[]
mainPhone
=
rawDataList
.
get
(
i
)[
2
].
toString
().
split
(
";"
);
for
(
int
j
=
0
;
j
<
mainPhone
.
length
;
j
++)
{
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
cc
.
setSiteId
(
userSession
.
getSiteId
());
cc
.
setContactType
((
short
)
5
);
cc
.
setContact
(
mainPhone
[
j
]);
cc
.
setIsDirectLine
((
short
)
1
);
...
...
@@ -1126,6 +1130,9 @@ public class CustomerServiceImpl implements CustomerService {
if
(
rawDataList
.
get
(
i
).
length
>
3
&&
rawDataList
.
get
(
i
)[
3
]
!=
null
)
{
String
[]
subPhone
=
rawDataList
.
get
(
i
)[
3
].
toString
().
split
(
";"
);
for
(
int
j
=
0
;
j
<
subPhone
.
length
;
j
++)
{
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
cc
.
setSiteId
(
userSession
.
getSiteId
());
cc
.
setContactType
((
short
)
5
);
cc
.
setContact
(
subPhone
[
j
]);
cc
.
setIsDirectLine
((
short
)
0
);
...
...
@@ -1138,8 +1145,11 @@ public class CustomerServiceImpl implements CustomerService {
}
}
if
(
rawDataList
.
get
(
i
).
length
>
4
&&
rawDataList
.
get
(
i
)[
4
]
!=
null
)
{
String
[]
email
=
rawDataList
.
get
(
i
)[
3
].
toString
().
split
(
";"
);
String
[]
email
=
rawDataList
.
get
(
i
)[
4
].
toString
().
split
(
";"
);
for
(
int
j
=
0
;
j
<
email
.
length
;
j
++)
{
CustomerContact
cc
=
new
CustomerContact
();
cc
.
setCustomerId
(
saved
.
getCustomerId
());
cc
.
setSiteId
(
userSession
.
getSiteId
());
cc
.
setContactType
((
short
)
2
);
cc
.
setContact
(
email
[
j
]);
cc
.
setIsDirectLine
((
short
)
1
);
...
...
@@ -1156,7 +1166,7 @@ public class CustomerServiceImpl implements CustomerService {
for
(
int
j
=
0
;
j
<
dynamicHeader
.
size
();
j
++)
{
cfo
.
setCustomizeFieldId
(
dynamicHeader
.
get
(
j
).
getCustomizeFieldId
());
if
(
rawDataList
.
get
(
i
).
length
>
(
12
+
j
)
&&
rawDataList
.
get
(
i
)[
12
+
j
]
!=
null
)
{
switch
(
dynamicHeader
.
get
(
i
).
getType
())
{
switch
(
dynamicHeader
.
get
(
j
).
getType
())
{
case
"combobox"
:
CustomizeFieldOptionValue
cfov
=
customizeFieldOptionValueRepository
.
findCustomizeFieldOptionValueByNameEqualsAndStatus
(
rawDataList
.
get
(
i
)[
12
+
j
].
toString
(),
1L
);
...
...
@@ -1221,7 +1231,7 @@ public class CustomerServiceImpl implements CustomerService {
if
(
str
.
length
()
>
50
)
{
result
=
BundleUtils
.
getLangString
(
"customer.phoneMax50"
,
locale
);
}
for
(
int
i
=
0
;
i
<
str
.
length
()
;
i
++)
{
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
CustomerContact
cc
=
customerContactRepository
.
findCustomerContactByContactEquals
(
arr
[
i
]);
if
(
cc
!=
null
)
{
return
result
.
concat
(
BundleUtils
.
getLangString
(
"customer.phoneExists"
,
locale
));
...
...
@@ -1230,6 +1240,18 @@ public class CustomerServiceImpl implements CustomerService {
return
result
;
}
private
String
validateDuplicateEmail
(
String
str
,
Locale
locale
)
{
String
result
=
""
;
String
[]
arr
=
str
.
split
(
";"
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
CustomerContact
cc
=
customerContactRepository
.
findCustomerContactByContactEquals
(
arr
[
i
]);
if
(
cc
!=
null
)
{
return
result
.
concat
(
BundleUtils
.
getLangString
(
"customer.emailExists"
,
locale
));
}
}
return
result
;
}
private
String
validateUsingRegexp
(
String
header
,
String
data
,
String
regexp
,
Locale
locale
)
{
if
(
data
.
matches
(
regexp
))
{
return
header
+
" "
+
BundleUtils
.
getLangString
(
"customer.notMatch"
,
locale
);
...
...
@@ -1251,8 +1273,14 @@ public class CustomerServiceImpl implements CustomerService {
}
private
boolean
validateEmail
(
String
str
)
{
String
[]
arr
=
str
.
split
(
";"
);
String
regexp
=
"^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"
;
return
str
.
matches
(
regexp
);
for
(
int
i
=
0
;
i
<
arr
.
length
;
i
++)
{
if
(!
arr
[
i
].
matches
(
regexp
))
{
return
false
;
}
}
return
true
;
}
private
boolean
validateLetter
(
String
str
)
{
...
...
@@ -1262,6 +1290,7 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold>
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
byte
[]
buildTemplate
(
Long
companySiteId
)
{
LOGGER
.
info
(
"-----------BUILD TEMPLATE-----------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
...
...
@@ -1414,6 +1443,7 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
List
<
CustomizeFieldObject
>
getCustomizeField
(
Long
customerId
)
{
List
<
CustomizeFieldObject
>
customizeFieldDTOList
;
try
{
...
...
@@ -1494,6 +1524,7 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
@Transactional
(
DataSourceQualify
.
CCMS_FULL
)
public
List
<
CustomerDTO
>
getIndividualCustomerInfo
(
CampaignCustomerDTO
campaignCustomerDTO
)
{
List
<
CustomerDTO
>
customerList
;
try
{
...
...
src/main/java/com/viettel/campaign/service/impl/ScenarioServiceImpl.java
View file @
8890ea24
...
...
@@ -6,6 +6,7 @@ import com.viettel.campaign.repository.ccms_full.*;
import
com.viettel.campaign.service.ScenarioService
;
import
com.viettel.campaign.utils.BundleUtils
;
import
com.viettel.campaign.utils.Constants
;
import
com.viettel.campaign.utils.DataUtil
;
import
com.viettel.campaign.utils.WorkBookBuilder
;
import
com.viettel.campaign.web.dto.*
;
import
com.viettel.econtact.filter.UserSession
;
...
...
@@ -23,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
...
...
@@ -253,8 +255,9 @@ public class ScenarioServiceImpl implements ScenarioService {
FileInputStream
fis
=
new
FileInputStream
(
file
);
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
fis
);
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Row
row
=
sheet
.
getRow
(
3
);
Row
row
=
sheet
.
getRow
(
2
);
//<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
);
...
...
@@ -264,14 +267,26 @@ public class ScenarioServiceImpl implements ScenarioService {
resultStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
//</editor-fold>
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
for
(
int
i
=
0
;
i
<
fileHeaderList
.
size
();
i
++)
{
Cell
cell
=
row
.
getCell
(
i
);
if
(!
cell
.
getStringCellValue
().
equals
(
fileHeaderList
.
get
(
i
).
split
(
"#"
)[
0
]))
{
result
.
put
(
"file"
,
file
);
result
.
put
(
"message"
,
BundleUtils
.
getLangString
(
"common.invalidTemplate"
,
locale
));
return
result
;
}
}
//</editor-fold>
//kt file du lieu rong
if
(
sheet
.
getPhysicalNumberOfRows
()
==
3
)
{
if
(
sheet
.
getPhysicalNumberOfRows
()
==
2
)
{
result
.
put
(
"message"
,
BundleUtils
.
getLangString
(
"customer.noData"
,
locale
));
result
.
put
(
"file"
,
file
);
return
result
;
}
else
{
Cell
resultCell
=
sheet
.
getRow
(
3
).
createCell
(
sheet
.
getRow
(
3
).
getPhysicalNumberOfCells
());
Cell
resultCell
=
sheet
.
getRow
(
2
).
createCell
(
sheet
.
getRow
(
2
).
getPhysicalNumberOfCells
());
resultCell
.
setCellValue
(
BundleUtils
.
getLangString
(
"customer.result"
,
locale
));
resultCell
.
setCellStyle
(
resultStyle
);
}
...
...
@@ -279,48 +294,114 @@ public class ScenarioServiceImpl implements ScenarioService {
List
<
Object
[]>
rawDataList
=
new
ArrayList
<>();
//validate row
for
(
int
i
=
4
;
i
<
sheet
.
getPhysicalNumberOfRows
();
i
++)
{
for
(
int
i
=
3
;
i
<
sheet
.
getPhysicalNumberOfRows
();
i
++)
{
Row
dataRow
=
sheet
.
getRow
(
i
);
if
(
dataRow
!=
null
)
{
Object
[]
obj
=
new
Object
[
row
.
getPhysicalNumberOfCells
()];
for
(
int
j
=
0
;
j
<
row
.
getPhysicalNumberOfCells
();
j
++)
{
Cell
dataCell
=
dataRow
.
getCell
(
j
);
if
(
dataCell
!=
null
)
{
// switch (dataCell.getCellTypeEnum()) {
// case NUMERIC:
// obj[j] = dataCell.getNumericCellValue();
// break;
// default:
// obj[j] = dataCell.getStringCellValue();
// break;
// }
}
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);
// break;
// } else {
// obj[j] = null;
// }
switch
(
dataCell
.
getCellTypeEnum
())
{
case
NUMERIC:
obj
[
j
]
=
dataCell
.
getNumericCellValue
();
break
;
default
:
obj
[
j
]
=
dataCell
.
getStringCellValue
();
break
;
}
}
}
rawDataList
.
add
(
obj
);
}
}
//<editor-fold desc="Validate dữ liệu" defaultstate="collapsed">
String
selectedType
=
""
;
for
(
int
i
=
0
;
i
<
rawDataList
.
size
();
i
++)
{
if
(
rawDataList
.
get
(
i
)[
0
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
0
].
toString
().
trim
().
equals
(
""
))
selectedType
=
rawDataList
.
get
(
i
)[
1
].
toString
().
trim
();
//validate question
if
((
rawDataList
.
get
(
i
)[
0
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
0
].
toString
().
trim
().
equals
(
""
))
||
(
rawDataList
.
get
(
i
)[
1
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
1
].
toString
().
trim
().
equals
(
""
))
||
(
rawDataList
.
get
(
i
)[
2
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
().
equals
(
""
))
||
(
rawDataList
.
get
(
i
)[
5
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
5
].
toString
().
trim
().
equals
(
""
))
||
(
rawDataList
.
get
(
i
)[
6
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
6
].
toString
().
trim
().
equals
(
""
)))
{
if
(
rawDataList
.
get
(
i
)[
0
]
==
null
||
!
DataUtil
.
isNumber
(
rawDataList
.
get
(
i
)[
0
].
toString
()))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.questionCode.required"
));
}
if
(
rawDataList
.
get
(
i
)[
1
]
==
null
||
rawDataList
.
get
(
i
)[
1
].
toString
().
trim
().
equals
(
""
))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.questionType.required"
));
}
if
(
rawDataList
.
get
(
i
)[
2
]
==
null
||
rawDataList
.
get
(
i
)[
2
].
toString
().
trim
().
equals
(
""
))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.question.required"
));
}
if
(
rawDataList
.
get
(
i
)[
5
]
==
null
||
rawDataList
.
get
(
i
)[
5
].
toString
().
trim
().
equals
(
""
))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.required.required"
));
}
if
(
rawDataList
.
get
(
i
)[
6
]
==
null
||
rawDataList
.
get
(
i
)[
6
].
toString
().
trim
().
equals
(
""
))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.default.required"
));
}
}
//validate answer
if
((
rawDataList
.
get
(
i
)[
3
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
3
].
toString
().
trim
().
equals
(
""
))
||
(
rawDataList
.
get
(
i
)[
4
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
().
equals
(
""
))
||
(
rawDataList
.
get
(
i
)[
7
]
!=
null
&&
!
rawDataList
.
get
(
i
)[
7
].
toString
().
trim
().
equals
(
""
)))
{
if
((
rawDataList
.
get
(
i
)[
3
]
==
null
||
rawDataList
.
get
(
i
)[
3
].
toString
().
trim
().
equals
(
""
))
&&
(!
selectedType
.
equals
(
BundleUtils
.
getLangString
(
"scenario.template.text"
))))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.answer.required"
));
}
if
(
rawDataList
.
get
(
i
)[
4
]
==
null
&&
rawDataList
.
get
(
i
)[
4
].
toString
().
trim
().
equals
(
""
))
{
sb
.
append
(
BundleUtils
.
getLangString
(
"scenario.hashInput.required"
));
}
}
Row
dataRow
=
sheet
.
getRow
(
3
+
i
);
Cell
resultCell
=
dataRow
.
createCell
(
row
.
getPhysicalNumberOfCells
()
-
1
);
if
(
sb
.
length
()
>
0
)
{
resultCell
.
setCellValue
(
sb
.
toString
());
isValid
=
false
;
}
else
{
isValid
=
true
;
resultCell
.
setCellValue
(
"Ok"
);
}
sb
=
new
StringBuilder
();
}
selectedType
=
""
;
//</editor-fold>
//insert data
if
(
isValid
)
{
logger
.
info
(
"----- Data valid, start import scenario question -----"
);
for
(
int
i
=
0
;
i
<
rawDataList
.
size
();
i
++)
{
buildQuestionsLst
(
rawDataList
);
}
}
else
{
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
workbook
.
write
(
fos
);
result
.
put
(
"file"
,
file
);
result
.
put
(
"message"
,
BundleUtils
.
getLangString
(
"customer.importFailed"
,
locale
));
}
}
catch
(
Exception
ex
)
{
logger
.
info
(
ex
.
getMessage
(),
ex
);
result
.
put
(
"message"
,
BundleUtils
.
getLangString
(
"customer.errorValidate"
,
locale
));
}
logger
.
info
(
"Import Questions result:"
,
result
);
return
result
;
}
private
boolean
validateQuestionIndex
(
Object
index
)
{
if
(
index
!=
null
&&
DataUtil
.
isLong
(
index
.
toString
()))
return
true
;
return
false
;
}
private
List
<
ScenarioQuestionDTO
>
buildQuestionsLst
(
List
<
Object
[]>
rawDatas
)
{
List
<
ScenarioQuestionDTO
>
lstQuestions
=
new
ArrayList
<>();
ScenarioQuestionDTO
questionDTO
=
null
;
for
(
int
i
=
0
;
i
<
rawDatas
.
size
();
i
++)
{
if
(
rawDatas
.
get
(
i
)[
0
]
!=
null
&&
!
rawDatas
.
get
(
i
)[
0
].
toString
().
trim
().
equals
(
""
))
{
questionDTO
=
new
ScenarioQuestionDTO
();
// questionDTO.setCampaignId();
}
}
return
lstQuestions
;
}
}
src/main/java/com/viettel/campaign/utils/Config.java
View file @
8890ea24
...
...
@@ -16,6 +16,7 @@ public class Config {
public
static
final
String
APP_CONF_FILE_PATH
=
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
"etc"
+
File
.
separator
+
"app.conf"
;
public
static
final
String
LOG_CONF_FILE_PATH
=
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
"etc"
+
File
.
separator
+
"log.conf"
;
public
static
final
String
EXCEL_DIR
=
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
"etc"
;
public
static
String
amcd_xmlrpc_url
;
public
static
int
num_client_amcd_xmlprc
;
...
...
@@ -60,7 +61,7 @@ public class Config {
}
catch
(
IOException
ex
)
{
Logger
.
getLogger
(
Config
.
class
.
getName
()).
error
(
ex
.
getMessage
(),
ex
);
}
//
PassTranformer.setInputKey("Ipcc#987654321#@!");
PassTranformer
.
setInputKey
(
"Ipcc#987654321#@!"
);
// rabbitConnection = properties.getProperty("rabbit_connection_string");
// fbGatewayUser = PassTranformer.decrypt(properties.getProperty("rabbit_user", "").trim());
...
...
src/main/java/com/viettel/campaign/web/rest/CustomerController.java
View file @
8890ea24
...
...
@@ -5,6 +5,7 @@ import com.viettel.campaign.model.ccms_full.CustomizeFieldObject;
import
com.viettel.campaign.model.ccms_full.CustomizeFields
;
import
com.viettel.campaign.service.CustomerService
;
import
com.viettel.campaign.utils.BundleUtils
;
import
com.viettel.campaign.utils.Config
;
import
com.viettel.campaign.utils.Constants
;
import
com.viettel.campaign.utils.RedisUtil
;
import
com.viettel.campaign.web.dto.*
;
...
...
@@ -108,13 +109,16 @@ public class CustomerController {
@PostMapping
(
"/createCustomerList"
)
@ResponseBody
public
ResultDTO
createCustomerList
(
@RequestBody
@Valid
CustomerListDTO
customerListDTO
,
HttpServletRequest
request
)
{
ResultDTO
result
=
new
ResultDTO
();
// THÍM NÀO MERGE CONFLICT THÌ GIỮ LẠI HỘ E CÁI METHOD NÀY VỚI
// VIẾT ĐI VIẾT LẠI 4 LẦN RỒI ĐẤY
String
xAuthToken
=
request
.
getHeader
(
"X-Auth-Token"
);
UserSession
userSession
=
(
UserSession
)
RedisUtil
.
getInstance
().
get
(
xAuthToken
);
result
=
customerService
.
createCustomerList
(
customerListDTO
,
userSession
.
getUserName
());
return
result
;
if
(
userSession
==
null
)
{
userSession
=
new
UserSession
();
userSession
.
setSiteId
(
customerListDTO
.
getCompanySiteId
());
userSession
.
setUserName
(
"its4"
);
}
return
customerService
.
createCustomerList
(
customerListDTO
,
userSession
.
getUserName
());
}
@PostMapping
(
"/updateCustomerList"
)
...
...
@@ -187,12 +191,17 @@ public class CustomerController {
@PostMapping
(
value
=
"/importFile"
)
public
ResponseEntity
<?>
importFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestParam
(
"customerListId"
)
Lo
ng
customerListId
,
@RequestHeader
(
"X-Auth-Token"
)
String
authToken
)
{
@RequestParam
(
"customerListId"
)
Stri
ng
customerListId
,
HttpServletRequest
request
)
{
LOGGER
.
info
(
"------------IMPORT FILE TEMPLATE--------------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
try
{
UserSession
userSession
=
(
UserSession
)
RedisUtil
.
getInstance
().
get
(
authToken
);
UserSession
userSession
=
(
UserSession
)
RedisUtil
.
getInstance
().
get
(
request
.
getHeader
(
"X-Auth-Token"
));
if
(
userSession
==
null
)
{
userSession
=
new
UserSession
();
userSession
.
setSiteId
(
662691L
);
userSession
.
setUserName
(
"its3"
);
}
if
(
file
.
isEmpty
())
{
return
new
ResponseEntity
<>(
BundleUtils
.
getLangString
(
"customer.fileNotSelected"
),
HttpStatus
.
OK
);
}
...
...
@@ -201,7 +210,7 @@ public class CustomerController {
}
String
path
=
saveUploadFile
(
file
);
List
<
CustomizeFields
>
dynamicHeaders
=
customerService
.
getDynamicHeader
(
userSession
.
getCompanySiteId
());
Map
<
String
,
Object
>
map
=
customerService
.
readAndValidateCustomer
(
path
,
dynamicHeaders
,
userSession
,
customerListId
);
Map
<
String
,
Object
>
map
=
customerService
.
readAndValidateCustomer
(
path
,
dynamicHeaders
,
userSession
,
Long
.
parseLong
(
customerListId
)
);
File
fileExport
=
(
File
)
map
.
get
(
"file"
);
String
message
=
(
String
)
map
.
get
(
"message"
);
return
ResponseEntity
.
ok
()
...
...
@@ -239,11 +248,13 @@ public class CustomerController {
String
currentTime
=
new
SimpleDateFormat
(
"yyyy_MM_dd_hh_mm_ss"
).
format
(
new
Date
());
String
fileName
=
FilenameUtils
.
getBaseName
(
file
.
getOriginalFilename
())
+
"_"
+
currentTime
+
"."
+
FilenameUtils
.
getExtension
(
file
.
getOriginalFilename
());
byte
[]
content
=
file
.
getBytes
();
File
uploadFolder
=
new
File
(
BundleUtils
.
getGlobalConfig
(
"import.uploadFolder"
));
// File uploadFolder = new File(BundleUtils.getGlobalConfig("import.uploadFolder"));
File
uploadFolder
=
new
File
(
Config
.
EXCEL_DIR
);
if
(!
uploadFolder
.
exists
())
{
uploadFolder
.
mkdir
();
}
Path
path
=
Paths
.
get
(
BundleUtils
.
getGlobalConfig
(
"import.uploadFolder"
),
fileName
);
// Path path = Paths.get(BundleUtils.getGlobalConfig("import.uploadFolder"), fileName);
Path
path
=
Paths
.
get
(
Config
.
EXCEL_DIR
,
fileName
);
Files
.
write
(
path
,
content
);
return
path
.
toString
();
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/viettel/campaign/web/rest/ScenarioController.java
View file @
8890ea24
...
...
@@ -122,7 +122,7 @@ public class ScenarioController {
String
message
=
(
String
)
map
.
get
(
"message"
);
return
ResponseEntity
.
ok
()
.
header
(
"Content-Type"
,
Constants
.
MIME_TYPE
.
EXCEL_XLSX
)
.
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=
template_import_customer
.xlsx"
)
.
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename=
import_scenario_result
.xlsx"
)
.
header
(
"Message"
,
message
)
.
body
(
Files
.
readAllBytes
(
fileExport
.
toPath
()));
}
catch
(
Exception
e
)
{
...
...
src/main/resources/application.yml
View file @
8890ea24
...
...
@@ -11,6 +11,11 @@ spring:
ddl-auto
:
none
naming
:
physical-strategy
:
org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
servlet
:
multipart
:
enabled
:
true
max-file-size
:
3MB
max-request-size
:
3MB
# kafka:
# consumer:
# bootstrap-servers: 192.168.1.201:9092
...
...
@@ -40,4 +45,3 @@ datasource-property:
src/main/resources/i18n/language_en.properties
View file @
8890ea24
...
...
@@ -108,6 +108,7 @@ customer.emailExists=Email exists;
common.fileNotSelected
=
Please select a file
common.fileInvalidFormat
=
File invalid
common.invalidTemplate
=
Template invalid format
#IMPORT SCENARIO TEMPLATE
scenario.template.title
=
IMPORT QUESTIONS
...
...
@@ -125,3 +126,12 @@ scenario.template.result=Result
scenario.template.singleChoice
=
SingleChoice
scenario.template.multiChoice
=
MultiChoice
scenario.template.text
=
Text
scenario.questionCode.required
=
"Question index is required"
scenario.questionType.required
=
"Question type is required"
scenario.question.required
=
"Question content is required"
scenario.answer.required
=
"Answer is required for SingleChoice or MultiChoice question"
scenario.hashInput.required
=
"Has input is required"
scenario.required.required
=
"Require is required"
scenario.default.required
=
"Default is required"
src/main/resources/i18n/language_vi.properties
View file @
8890ea24
...
...
@@ -110,6 +110,7 @@ customer.emailExists=Email đã tồn tại;
common.fileNotSelected
=
Bạn chưa chọn file
common.fileInvalidFormat
=
File không hợp lệ
common.invalidTemplate
=
Template sai định dạng
#IMPORT SCENARIO TEMPLATE
scenario.template.title
=
IMPORT CÂU HỎI
...
...
@@ -128,6 +129,14 @@ scenario.template.singleChoice=SingleChoice
scenario.template.multiChoice
=
MultiChoice
scenario.template.text
=
Text
scenario.questionCode.required
=
"Mã câu hỏi bắt buộc nhập"
scenario.questionType.required
=
"Loại câu hỏi bắt buộc nhập"
scenario.question.required
=
"Câu hỏi bắt buộc nhập"
scenario.answer.required
=
"Câu trả lời cho câu hỏi SingleChoice, MultiChoice bắt buộc nhập"
scenario.hashInput.required
=
"Trường Nhập text bắt buộc nhập"
scenario.required.required
=
"Trường Bắt buộc bắt buộc nhập"
scenario.default.required
=
"Trường Mặc định bắt buộc nhập"
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