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
b5d0ef35
Commit
b5d0ef35
authored
Aug 29, 2019
by
Vu Duy Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
anhvd commit import scenario
parent
0fd8d25d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
15 deletions
+26
-15
src/main/java/com/viettel/campaign/service/impl/ScenarioServiceImpl.java
...om/viettel/campaign/service/impl/ScenarioServiceImpl.java
+23
-9
src/main/java/com/viettel/campaign/web/rest/ScenarioController.java
...ava/com/viettel/campaign/web/rest/ScenarioController.java
+3
-6
No files found.
src/main/java/com/viettel/campaign/service/impl/ScenarioServiceImpl.java
View file @
b5d0ef35
...
@@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream;
...
@@ -26,6 +26,7 @@ import java.io.ByteArrayOutputStream;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.nio.file.Files
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
...
@@ -261,6 +262,7 @@ public class ScenarioServiceImpl implements ScenarioService {
...
@@ -261,6 +262,7 @@ public class ScenarioServiceImpl implements ScenarioService {
File
file
=
new
File
(
path
);
File
file
=
new
File
(
path
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
FileInputStream
fis
=
new
FileInputStream
(
file
);
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
fis
);
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
fis
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Sheet
sheet
=
workbook
.
getSheetAt
(
0
);
Row
row
=
sheet
.
getRow
(
2
);
Row
row
=
sheet
.
getRow
(
2
);
...
@@ -270,17 +272,25 @@ public class ScenarioServiceImpl implements ScenarioService {
...
@@ -270,17 +272,25 @@ public class ScenarioServiceImpl implements ScenarioService {
resultFont
.
setFontHeightInPoints
((
short
)
11
);
resultFont
.
setFontHeightInPoints
((
short
)
11
);
CellStyle
resultStyle
=
workbook
.
createCellStyle
();
CellStyle
resultStyle
=
workbook
.
createCellStyle
();
resultStyle
.
setFont
(
resultFont
);
resultStyle
.
setFont
(
resultFont
);
resultStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
resultStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
resultStyle
.
setFillForegroundColor
(
IndexedColors
.
LIGHT_GREEN
.
getIndex
());
resultStyle
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
resultStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderRight
(
BorderStyle
.
THIN
);
resultStyle
.
setRightBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
resultStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderBottom
(
BorderStyle
.
THIN
);
resultStyle
.
setBottomBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
resultStyle
.
setBorderLeft
(
BorderStyle
.
THIN
);
resultStyle
.
setLeftBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
resultStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
resultStyle
.
setBorderTop
(
BorderStyle
.
THIN
);
resultStyle
.
setTopBorderColor
(
IndexedColors
.
BLACK
.
getIndex
());
//</editor-fold>
//</editor-fold>
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
for
(
int
i
=
0
;
i
<
fileHeaderList
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
fileHeaderList
.
size
();
i
++)
{
Cell
cell
=
row
.
getCell
(
i
);
Cell
cell
=
row
.
getCell
(
i
);
if
(!
cell
.
getStringCellValue
().
equals
(
fileHeaderList
.
get
(
i
).
split
(
"#"
)[
0
]))
{
if
(!
cell
.
getStringCellValue
().
equals
(
fileHeaderList
.
get
(
i
).
split
(
"#"
)[
0
]))
{
result
.
put
(
"
file"
,
file
);
result
.
put
(
"
content"
,
Files
.
readAllBytes
(
file
.
toPath
())
);
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
INVALID_FORMAT
);
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
INVALID_FORMAT
);
return
result
;
return
result
;
}
}
...
@@ -289,8 +299,8 @@ public class ScenarioServiceImpl implements ScenarioService {
...
@@ -289,8 +299,8 @@ public class ScenarioServiceImpl implements ScenarioService {
//kt file du lieu rong
//kt file du lieu rong
if
(
sheet
.
getPhysicalNumberOfRows
()
==
2
)
{
if
(
sheet
.
getPhysicalNumberOfRows
()
==
2
)
{
result
.
put
(
"content"
,
Files
.
readAllBytes
(
file
.
toPath
()));
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
EMPTY
);
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
EMPTY
);
result
.
put
(
"file"
,
file
);
return
result
;
return
result
;
}
else
{
}
else
{
Cell
resultCell
=
sheet
.
getRow
(
2
).
createCell
(
sheet
.
getRow
(
2
).
getPhysicalNumberOfCells
());
Cell
resultCell
=
sheet
.
getRow
(
2
).
createCell
(
sheet
.
getRow
(
2
).
getPhysicalNumberOfCells
());
...
@@ -397,14 +407,18 @@ public class ScenarioServiceImpl implements ScenarioService {
...
@@ -397,14 +407,18 @@ public class ScenarioServiceImpl implements ScenarioService {
lstQuestion
.
forEach
(
question
->
{
lstQuestion
.
forEach
(
question
->
{
// questionService.add(question);
// questionService.add(question);
});
});
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
workbook
.
write
(
os
);
workbook
.
write
(
fos
);
os
.
flush
();
result
.
put
(
"file"
,
file
);
os
.
close
();
workbook
.
close
();
result
.
put
(
"content"
,
os
.
toByteArray
());
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
SUCCESS
);
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
SUCCESS
);
}
else
{
}
else
{
FileOutputStream
fos
=
new
FileOutputStream
(
file
);
workbook
.
write
(
os
);
workbook
.
write
(
fos
);
os
.
flush
();
result
.
put
(
"file"
,
file
);
os
.
close
();
workbook
.
close
();
result
.
put
(
"content"
,
os
.
toByteArray
());
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
ERROR
);
result
.
put
(
"code"
,
Constants
.
FILE_UPLOAD_RESP_CODE
.
ERROR
);
}
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
...
...
src/main/java/com/viettel/campaign/web/rest/ScenarioController.java
View file @
b5d0ef35
...
@@ -119,14 +119,11 @@ public class ScenarioController {
...
@@ -119,14 +119,11 @@ public class ScenarioController {
}
}
String
path
=
saveUploadFile
(
file
);
String
path
=
saveUploadFile
(
file
);
Map
<
String
,
Object
>
map
=
scenarioService
.
readAndValidateCustomer
(
path
,
scenarioId
,
campaignId
,
userSession
.
getCompanySiteId
());
Map
<
String
,
Object
>
map
=
scenarioService
.
readAndValidateCustomer
(
path
,
scenarioId
,
campaignId
,
userSession
.
getCompanySiteId
());
File
fileExport
=
(
File
)
map
.
get
(
"file"
);
String
code
=
(
String
)
map
.
get
(
"code"
);
String
code
=
(
String
)
map
.
get
(
"code"
);
HttpHeaders
headers
=
new
HttpHeaders
();
byte
[]
content
=
(
byte
[])
map
.
get
(
"content"
);
headers
.
add
(
"Content-Type"
,
Constants
.
MIME_TYPE
.
EXCEL_XLSX
);
headers
.
add
(
"Message"
,
code
);
return
ResponseEntity
.
ok
()
return
ResponseEntity
.
ok
()
.
header
s
(
headers
)
.
header
(
"Message"
,
code
)
.
body
(
Files
.
readAllBytes
(
fileExport
.
toPath
())
);
.
body
(
content
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
());
logger
.
error
(
e
.
getMessage
());
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
...
...
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