Commit 5027cb0d authored by ='s avatar =

Merge remote-tracking branch 'origin/master'

parents 74256bb3 f9da8efc
...@@ -996,6 +996,11 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -996,6 +996,11 @@ public class CustomerServiceImpl implements CustomerService {
//</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">
if (row.getPhysicalNumberOfCells() != 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++) { for (int i = 0; i < header.size(); i++) {
Cell cell = row.getCell(i); Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) { if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) {
...@@ -1004,6 +1009,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1004,6 +1009,7 @@ public class CustomerServiceImpl implements CustomerService {
return result; return result;
} }
} }
}
//</editor-fold> //</editor-fold>
List<Object[]> rawDataList = new ArrayList<>(); List<Object[]> rawDataList = new ArrayList<>();
......
...@@ -198,19 +198,20 @@ public class CustomerController { ...@@ -198,19 +198,20 @@ public class CustomerController {
try { try {
UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token")); UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token"));
if (file.isEmpty()) { if (file.isEmpty()) {
return new ResponseEntity<>("file-empty", HttpStatus.OK); return new ResponseEntity<>("file-empty", HttpStatus.BAD_REQUEST);
} }
// if (!Objects.equals(FilenameUtils.getExtension(file.getOriginalFilename()), Constants.FileType.xlsx)) {
// return new ResponseEntity<>("template-invalid", HttpStatus.OK);
// }
String path = saveUploadFile(file); String path = saveUploadFile(file);
List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId()); List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId());
Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, Long.parseLong(customerListId)); Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, Long.parseLong(customerListId));
String message = (String) map.get("message"); String message = (String) map.get("message");
byte[] content = (byte[]) map.get("content"); byte[] content = (byte[]) map.get("content");
if (message.equals("import-success")) {
return ResponseEntity.ok() return ResponseEntity.ok()
.header("Message", message) .header("Message", message)
.body(content); .body(content);
} else {
return ResponseEntity.badRequest().header("Message", message).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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment