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
b184e2d6
Commit
b184e2d6
authored
Aug 25, 2019
by
Vu Duy Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
anhvd commit
parent
03ae6a62
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
536 additions
and
45 deletions
+536
-45
log/campaign.log
log/campaign.log
+207
-10
src/main/java/com/viettel/campaign/service/ScenarioService.java
...in/java/com/viettel/campaign/service/ScenarioService.java
+7
-0
src/main/java/com/viettel/campaign/service/impl/ScenarioServiceImpl.java
...om/viettel/campaign/service/impl/ScenarioServiceImpl.java
+189
-7
src/main/java/com/viettel/campaign/web/rest/CampaignController.java
...ava/com/viettel/campaign/web/rest/CampaignController.java
+0
-28
src/main/java/com/viettel/campaign/web/rest/ScenarioController.java
...ava/com/viettel/campaign/web/rest/ScenarioController.java
+95
-0
src/main/resources/.DS_Store
src/main/resources/.DS_Store
+0
-0
src/main/resources/i18n/language_en.properties
src/main/resources/i18n/language_en.properties
+17
-0
src/main/resources/i18n/language_vi.properties
src/main/resources/i18n/language_vi.properties
+21
-0
No files found.
log/campaign.log
View file @
b184e2d6
This diff is collapsed.
Click to expand it.
src/main/java/com/viettel/campaign/service/ScenarioService.java
View file @
b184e2d6
...
...
@@ -2,8 +2,11 @@ package com.viettel.campaign.service;
import
com.viettel.campaign.model.ccms_full.Scenario
;
import
com.viettel.campaign.web.dto.*
;
import
com.viettel.econtact.filter.UserSession
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author anhvd_itsol
...
...
@@ -19,4 +22,8 @@ public interface ScenarioService {
Integer
countDuplicateScenarioCode
(
Long
companySiteId
,
String
code
,
Long
scenarioId
);
ResultDTO
saveContacQuestResult
(
ContactQuestResultDTO
dto
);
XSSFWorkbook
buildTemplate
();
Map
<
String
,
Object
>
readAndValidateCustomer
(
String
path
,
UserSession
userSession
);
}
src/main/java/com/viettel/campaign/service/impl/ScenarioServiceImpl.java
View file @
b184e2d6
This diff is collapsed.
Click to expand it.
src/main/java/com/viettel/campaign/web/rest/CampaignController.java
View file @
b184e2d6
...
...
@@ -300,32 +300,4 @@ public class CampaignController {
return
new
ResponseEntity
<>(
result
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"/import-file"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<?>
importFile
(
@RequestParam
(
"file"
)
MultipartFile
file
,
@RequestHeader
(
"X-Auth-Token"
)
String
authToken
)
{
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
try
{
UserSession
userSession
=
(
UserSession
)
RedisUtil
.
getInstance
().
get
(
authToken
);
if
(
file
.
isEmpty
())
{
return
new
ResponseEntity
<>(
BundleUtils
.
getLangString
(
"common.fileNotSelected"
),
HttpStatus
.
OK
);
}
if
(!
Objects
.
equals
(
FilenameUtils
.
getExtension
(
file
.
getOriginalFilename
()),
Constants
.
FileType
.
xlsx
))
{
return
new
ResponseEntity
<>(
BundleUtils
.
getLangString
(
"common.fileInvalidFormat"
,
locale
),
HttpStatus
.
OK
);
}
//String path = saveUploadFile(file);
// List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId());
// Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, customerListId);
// File fileExport = (File) map.get("file");
// 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("Message", message)
// .body(Files.readAllBytes(fileExport.toPath()));
return
new
ResponseEntity
<>(
null
,
HttpStatus
.
OK
);
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
}
}
}
src/main/java/com/viettel/campaign/web/rest/ScenarioController.java
View file @
b184e2d6
...
...
@@ -2,15 +2,32 @@ package com.viettel.campaign.web.rest;
import
com.viettel.campaign.model.ccms_full.Scenario
;
import
com.viettel.campaign.service.ScenarioService
;
import
com.viettel.campaign.utils.BundleUtils
;
import
com.viettel.campaign.utils.Constants
;
import
com.viettel.campaign.utils.RedisUtil
;
import
com.viettel.campaign.web.dto.ContactQuestResultDTO
;
import
com.viettel.campaign.web.dto.ResultDTO
;
import
com.viettel.campaign.web.dto.ScenarioDTO
;
import
com.viettel.econtact.filter.UserSession
;
import
org.apache.commons.io.FilenameUtils
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
/**
* @author anhvd_itsol
...
...
@@ -54,4 +71,82 @@ public class ScenarioController {
ResultDTO
resultDTO
=
scenarioService
.
saveContacQuestResult
(
dto
);
return
new
ResponseEntity
<>(
resultDTO
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"/download-file-template"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<?>
downloadFileTemplate
(
HttpServletResponse
response
)
{
XSSFWorkbook
workbook
=
null
;
byte
[]
contentReturn
=
null
;
try
{
String
fileName
=
"import_scenario_template.xlsx"
;
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
);
OutputStream
outputStream
;
workbook
=
scenarioService
.
buildTemplate
();
outputStream
=
response
.
getOutputStream
();
workbook
.
write
(
outputStream
);
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
workbook
.
write
(
byteArrayOutputStream
);
contentReturn
=
byteArrayOutputStream
.
toByteArray
();
}
catch
(
Exception
ex
)
{
logger
.
error
(
ex
.
getMessage
(),
ex
);
return
new
ResponseEntity
<
byte
[]>(
null
,
null
,
HttpStatus
.
BAD_REQUEST
);
}
finally
{
if
(
workbook
!=
null
)
{
try
{
workbook
.
close
();
}
catch
(
IOException
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
}
}
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
parseMediaType
(
"application/vnd.ms-excel"
));
return
new
ResponseEntity
<
byte
[]>(
contentReturn
,
headers
,
HttpStatus
.
OK
);
}
@RequestMapping
(
value
=
"/import-file"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<?>
importFile
(
@RequestParam
MultipartFile
file
)
{
logger
.
info
(
"------------IMPORT FILE TEMPLATE--------------"
);
Locale
locale
=
new
Locale
(
"vi"
,
"VN"
);
try
{
UserSession
userSession
=
new
UserSession
();
// UserSession userSession = (UserSession) RedisUtil.getInstance().get(authToken);
if
(
file
.
isEmpty
())
{
return
new
ResponseEntity
<>(
BundleUtils
.
getLangString
(
"common.fileNotSelected"
),
HttpStatus
.
OK
);
}
if
(!
Objects
.
equals
(
FilenameUtils
.
getExtension
(
file
.
getOriginalFilename
()),
Constants
.
FileType
.
xlsx
))
{
return
new
ResponseEntity
<>(
BundleUtils
.
getLangString
(
"common.fileInvalidFormat"
,
locale
),
HttpStatus
.
OK
);
}
String
path
=
saveUploadFile
(
file
);
Map
<
String
,
Object
>
map
=
scenarioService
.
readAndValidateCustomer
(
path
,
userSession
);
File
fileExport
=
(
File
)
map
.
get
(
"file"
);
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
(
"Message"
,
message
)
.
body
(
Files
.
readAllBytes
(
fileExport
.
toPath
()));
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
());
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
}
}
private
String
saveUploadFile
(
MultipartFile
file
)
{
try
{
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
(
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
"etc"
+
File
.
separator
+
"upload"
);
if
(!
uploadFolder
.
exists
())
{
uploadFolder
.
mkdir
();
}
Path
path
=
Paths
.
get
(
System
.
getProperty
(
"user.dir"
)
+
File
.
separator
+
"etc"
,
fileName
);
Files
.
write
(
path
,
content
);
return
path
.
toString
();
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
());
}
return
null
;
}
}
src/main/resources/.DS_Store
View file @
b184e2d6
No preview for this file type
src/main/resources/i18n/language_en.properties
View file @
b184e2d6
...
...
@@ -106,3 +106,20 @@ customer.fileNotSelected=Please select a file
common.fileNotSelected
=
Please select a file
common.fileInvalidFormat
=
File invalid
#IMPORT SCENARIO TEMPLATE
scenario.template.title
=
IMPORT QUESTIONS
scenario.template.questionCode
=
Question code
scenario.template.questionType
=
Question type
scenario.template.question
=
Question
scenario.template.answer
=
Answer
scenario.template.hashInput
=
Hash input?
scenario.template.required
=
Required?
scenario.template.default
=
Default?
scenario.template.mappingQuestion
=
Mapping question
scenario.template.yes
=
Yes
scenario.template.no
=
No
scenario.template.result
=
Result
scenario.template.singleChoice
=
SingleChoice
scenario.template.multiChoice
=
MultiChoice
scenario.template.text
=
Text
src/main/resources/i18n/language_vi.properties
View file @
b184e2d6
...
...
@@ -108,3 +108,24 @@ customer.fileNotSelected=Bạn chưa chọn file
common.fileNotSelected
=
Bạn chưa chọn file
common.fileInvalidFormat
=
File không hợp lệ
#IMPORT SCENARIO TEMPLATE
scenario.template.title
=
IMPORT CÂU HỎI
scenario.template.questionCode
=
Mã câu hỏi
scenario.template.questionType
=
Loại câu hỏi
scenario.template.question
=
Câu hỏi
scenario.template.answer
=
Câu trả lời
scenario.template.hashInput
=
Nhập text?
scenario.template.required
=
Bắt buộc?
scenario.template.default
=
Mặc định?
scenario.template.mappingQuestion
=
Câu hỏi liên kết
scenario.template.yes
=
Có
scenario.template.no
=
Không
scenario.template.result
=
Kết quả
scenario.template.singleChoice
=
SingleChoice
scenario.template.multiChoice
=
MultiChoice
scenario.template.text
=
Text
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