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
9ffdc023
Commit
9ffdc023
authored
Aug 08, 2019
by
Đào Nhật Quang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quangdn
parent
e5e6e51e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
0 deletions
+79
-0
pom.xml
pom.xml
+12
-0
src/main/java/com/viettel/campaign/web/rest/controller/CustomerController.java
...ttel/campaign/web/rest/controller/CustomerController.java
+67
-0
src/main/resources/templates/test_download.xlsx
src/main/resources/templates/test_download.xlsx
+0
-0
No files found.
pom.xml
View file @
9ffdc023
...
...
@@ -189,6 +189,18 @@
<artifactId>
modelmapper
</artifactId>
<version>
2.3.2
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.17
</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
3.17
</version>
</dependency>
</dependencies>
<dependencyManagement>
...
...
src/main/java/com/viettel/campaign/web/rest/controller/CustomerController.java
View file @
9ffdc023
...
...
@@ -7,13 +7,24 @@ import com.viettel.campaign.service.CustomerService;
import
com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO
;
import
com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO
;
import
org.apache.log4j.Logger
;
import
org.apache.poi.xssf.usermodel.XSSFRow
;
import
org.apache.poi.xssf.usermodel.XSSFSheet
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
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.stereotype.Controller
;
import
org.springframework.util.ResourceUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.validation.Valid
;
import
java.io.File
;
import
java.nio.file.Files
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Controller
...
...
@@ -159,4 +170,60 @@ public class CustomerController {
ResultDTO
result
=
customerService
.
getCustomerContact
(
customerId
,
contactType
,
contact
);
return
new
ResponseEntity
(
result
,
HttpStatus
.
OK
);
}
@GetMapping
(
value
=
"/downloadFileTemplate"
)
public
ResponseEntity
<
byte
[]>
downloadFileTemplate
()
{
LOGGER
.
debug
(
"--------DOWNLOAD FILE TEMPLATE---------"
);
try
{
File
file
=
ResourceUtils
.
getFile
(
"classpath:templates/test_download.xlsx"
);
byte
[]
content
=
Files
.
readAllBytes
(
file
.
toPath
());
return
ResponseEntity
.
ok
()
.
header
(
HttpHeaders
.
CONTENT_DISPOSITION
,
"attachment; filename="
+
file
.
getName
())
.
contentType
(
MediaType
.
APPLICATION_OCTET_STREAM
)
.
body
(
content
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
}
}
@PostMapping
(
value
=
"/importFile"
)
public
ResponseEntity
<
byte
[]>
importFile
(
@RequestParam
(
"file"
)
MultipartFile
file
)
{
LOGGER
.
debug
(
"--------IMPORT FILE TEMPLATE---------"
);
try
{
List
<
CustomerDTO
>
listCustomer
=
new
ArrayList
<>();
XSSFWorkbook
workbook
=
new
XSSFWorkbook
(
file
.
getInputStream
());
XSSFSheet
sheet
=
workbook
.
getSheetAt
(
0
);
for
(
int
i
=
0
;
i
<
sheet
.
getPhysicalNumberOfRows
();
i
++)
{
CustomerDTO
customer
=
new
CustomerDTO
();
XSSFRow
row
=
sheet
.
getRow
(
i
);
customer
.
setCustomerId
(
Double
.
valueOf
(
row
.
getCell
(
0
).
getNumericCellValue
()).
longValue
());
customer
.
setCreateDate
(
row
.
getCell
(
1
).
getDateCellValue
());
customer
.
setName
(
row
.
getCell
(
2
).
getStringCellValue
());
listCustomer
.
add
(
customer
);
}
// for (int i = 0; i < listCustomer.size(); i++) {
// validate du lieu
// }
// if (okay) {
// for (int i = 0; i < listCustomer.size(); i++) {
// customerService.createCustomer(listCustomer.get(i));
// }
// return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
// .contentType(MediaType.APPLICATION_OCTET_STREAM)
// .body(file.getBytes());
// } else {
// return ResponseEntity.ok()
// .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + file.getName())
// .header("Message", "Validate failed!")
// .contentType(MediaType.APPLICATION_OCTET_STREAM)
// .body(file.getBytes());
// }
return
null
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
.
getMessage
());
return
new
ResponseEntity
<>(
HttpStatus
.
BAD_REQUEST
);
}
}
}
src/main/resources/templates/test_download.xlsx
0 → 100644
View file @
9ffdc023
File added
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