Commit 57bf4800 authored by đinh thị đầm's avatar đinh thị đầm
parents 8db5fc4d 94f54711
...@@ -14,6 +14,9 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long ...@@ -14,6 +14,9 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long
CustomerList findByCustomerListCode(String customerListCode); CustomerList findByCustomerListCode(String customerListCode);
@Query("select c from CustomerList c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id and c.status = 1")
List<CustomerList> findAllCustomerList(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("update CustomerList c set c.status = 0 where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id") @Query("update CustomerList c set c.status = 0 where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteCustomerList(@Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id); int deleteCustomerList(@Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
......
...@@ -393,10 +393,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -393,10 +393,9 @@ public class CustomerServiceImpl implements CustomerService {
public ResultDTO deleteCustomer(CustomerRequestDTO customerRequestDTO) { public ResultDTO deleteCustomer(CustomerRequestDTO customerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
List<Long> listId = new ArrayList<>(); List<Long> listId = new ArrayList<>();
listId.add(customerRequestDTO.getCustomerId());
try { try {
if (customerRequestDTO != null) { if (customerRequestDTO != null) {
listId.add(customerRequestDTO.getCustomerId());
if (customerListMappingRepository.findAllCustomerListMapping(listId, customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId()).size() > 0) { if (customerListMappingRepository.findAllCustomerListMapping(listId, customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId()).size() > 0) {
// delete // delete
// customerRepository.deleteById(customerDTO.getCustomerId()); // customerRepository.deleteById(customerDTO.getCustomerId());
...@@ -405,8 +404,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -405,8 +404,8 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.DELETE_ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.DELETE_ERROR);
} }
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
...@@ -425,10 +424,15 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -425,10 +424,15 @@ public class CustomerServiceImpl implements CustomerService {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
if (customerRequestDTO != null) { if (customerRequestDTO != null) {
// customerRepository.deleteIds(ids); if (customerListMappingRepository.findAllCustomerListMapping(customerRequestDTO.getIds(), customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId()).size() > 0) {
customerListMappingRepository.deleteMappingByCustomerIds(customerRequestDTO.getIds(), customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId()); //customerRepository.deleteIds(ids);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); customerListMappingRepository.deleteMappingByCustomerIds(customerRequestDTO.getIds(), customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId());
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.DELETE_ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.DELETE_ERROR);
}
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
...@@ -721,17 +725,23 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -721,17 +725,23 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO deleteCustomerList(CustomerListDTO customerListDTO) { public ResultDTO deleteCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
List<Long> ids = new ArrayList<>();
ids.add(customerListDTO.getCustomerListId());
try { try {
// delete // delete
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) { if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) {
customerListRepository.deleteCustomerList(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId()); if (customerListRepository.findAllCustomerList(ids, customerListDTO.getCompanySiteId()).size() > 0) {
customerListRepository.deleteCustomerList(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId()); customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.DELETE_ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.DELETE_ERROR);
}
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
...@@ -751,12 +761,17 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -751,12 +761,17 @@ public class CustomerServiceImpl implements CustomerService {
try { try {
if (customerRequestDTO != null) { if (customerRequestDTO != null) {
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignIdsCount(customerRequestDTO.getIds()))) { if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignIdsCount(customerRequestDTO.getIds()))) {
customerListRepository.deleteCustomerListIds(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId()); if (customerListRepository.findAllCustomerList(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId()).size() > 0) {
customerListRepository.deleteCustomerListIds(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId());
customerListMappingRepository.deleteMappingByCustomerListIds(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId()); customerListMappingRepository.deleteMappingByCustomerListIds(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.DELETE_ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.DELETE_ERROR);
}
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
...@@ -965,8 +980,11 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -965,8 +980,11 @@ public class CustomerServiceImpl implements CustomerService {
DataFormatter dataFormat = new DataFormatter(); DataFormatter dataFormat = new DataFormatter();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Map<String, Integer> headerMap = new HashMap<>();
List<String> stringHeader = new ArrayList<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int failedCount = 0; int failedCount = 0;
int objectSize;
XSSFWorkbook workbook = null; XSSFWorkbook workbook = null;
boolean isMainPhoneNull = false, isSecondPhoneNull = false, isEmailNull = false; boolean isMainPhoneNull = false, isSecondPhoneNull = false, isEmailNull = false;
try { try {
...@@ -988,62 +1006,53 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -988,62 +1006,53 @@ public class CustomerServiceImpl implements CustomerService {
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.smsAllowed", locale))); header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.smsAllowed", locale)));
header.addAll(dynamicHeader); header.addAll(dynamicHeader);
for (CustomizeFields cf : header) {
stringHeader.add(cf.getTitle().split("#")[0].trim());
}
//</editor-fold> //</editor-fold>
File file = new File(path); File file = new File(path);
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
workbook = new XSSFWorkbook(fis); workbook = new XSSFWorkbook(fis);
ByteArrayOutputStream os = new ByteArrayOutputStream();
XSSFSheet sheet = workbook.getSheetAt(0); XSSFSheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(3); Row row = sheet.getRow(3);
//<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);
CellStyle resultStyle = workbook.createCellStyle();
resultStyle.setFont(resultFont);
resultStyle.setBorderLeft(BorderStyle.THIN);
resultStyle.setBorderRight(BorderStyle.THIN);
resultStyle.setBorderBottom(BorderStyle.THIN);
resultStyle.setBorderTop(BorderStyle.THIN);
resultStyle.setAlignment(HorizontalAlignment.CENTER);
resultStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//</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()) { if (row.getLastCellNum() > header.size()) {
for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { for (int i = 0; i < row.getLastCellNum(); i++) {
if (sheet.isColumnHidden(i)) { Cell c = row.getCell(i);
sheet.setColumnHidden(i, false); if (c != null && !c.getStringCellValue().trim().equals("")) {
} if (stringHeader.contains(c.getStringCellValue().trim()) && !headerMap.containsKey(c.getStringCellValue().trim())) {
if (isColumnNullOrBlank(sheet, i)) { headerMap.put(c.getStringCellValue().trim(), c.getColumnIndex());
sheet.shiftColumns(i + 1, i + 1, -1); }
sheet.removeMergedRegion(0);
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 13));
} }
} }
for (int i = 0; i < header.size(); i++) { if (headerMap.size() != header.size()) {
Cell cell = row.getCell(i); result.put("content", Files.readAllBytes(file.toPath()));
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) { result.put("message", "template-invalid");
result.put("content", Files.readAllBytes(file.toPath())); return result;
result.put("message", "template-invalid");
return result;
}
} }
} else if (row.getPhysicalNumberOfCells() < header.size()) { objectSize = row.getLastCellNum();
} else if (row.getLastCellNum() < header.size()) {
result.put("content", Files.readAllBytes(file.toPath())); result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid"); result.put("message", "template-invalid");
return result; return result;
} else { } else {
for (int i = 0; i < header.size(); i++) { for (int i = 0; i < header.size(); i++) {
Cell cell = row.getCell(i); Cell c = row.getCell(i);
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) { if (c != null && !"".equals(c.getStringCellValue().trim())) {
result.put("content", Files.readAllBytes(file.toPath())); if (stringHeader.contains(c.getStringCellValue().trim()) && !headerMap.containsKey(c.getStringCellValue().trim())) {
result.put("message", "template-invalid"); headerMap.put(c.getStringCellValue().trim(), c.getColumnIndex());
return result; }
} }
} }
if (headerMap.size() != header.size()) {
result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid");
return result;
}
objectSize = row.getLastCellNum();
} }
//</editor-fold> //</editor-fold>
...@@ -1054,13 +1063,6 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1054,13 +1063,6 @@ public class CustomerServiceImpl implements CustomerService {
result.put("message", "template-no-data"); result.put("message", "template-no-data");
result.put("content", Files.readAllBytes(file.toPath())); result.put("content", Files.readAllBytes(file.toPath()));
return result; return result;
} else {
Cell resultCell = sheet.getRow(3).getCell(header.size());
if (resultCell == null) {
resultCell = sheet.getRow(3).createCell(header.size());
}
resultCell.setCellValue(BundleUtils.getLangString("customer.result", locale));
resultCell.setCellStyle(resultStyle);
} }
//</editor-fold> //</editor-fold>
...@@ -1068,23 +1070,36 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1068,23 +1070,36 @@ public class CustomerServiceImpl implements CustomerService {
for (int i = 4; i <= sheet.getPhysicalNumberOfRows(); i++) { for (int i = 4; i <= sheet.getPhysicalNumberOfRows(); i++) {
Row dataRow = sheet.getRow(i); Row dataRow = sheet.getRow(i);
if (dataRow != null) { if (dataRow != null) {
Object[] obj = new Object[row.getPhysicalNumberOfCells() - 1]; Object[] obj = new Object[objectSize + 1];
for (int j = 0; j < row.getPhysicalNumberOfCells() - 1; j++) { // for (int j = 0; j < header.size(); j++) {
Cell dataCell = dataRow.getCell(j); // Cell dataCell = dataRow.getCell(j);
// if (dataCell != null) {
// obj[j] = dataFormat.formatCellValue(dataCell);
// } 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);
// } else {
// obj[j] = null;
// }
// }
// }
headerMap.forEach((k, v) -> {
Cell dataCell = dataRow.getCell(v);
if (dataCell != null) { if (dataCell != null) {
obj[j] = dataFormat.formatCellValue(dataCell); obj[v] = dataFormat.formatCellValue(dataCell);
} else { } else {
Cell headerCell = row.getCell(j); if (k.equals(BundleUtils.getLangString("customer.cusType", locale))) {
if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.cusType", locale))) { obj[v] = BundleUtils.getLangString("customer.cusType.normal", locale);
obj[j] = BundleUtils.getLangString("customer.cusType.normal", locale); } else if (k.equals(BundleUtils.getLangString("customer.callAllowed", locale)) || k.equals(BundleUtils.getLangString("customer.emailAllowed", locale))
} else if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.callAllowed", locale)) || headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.emailAllowed", locale)) || k.equals(BundleUtils.getLangString("customer.smsAllowed", locale))) {
|| headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.smsAllowed", locale))) { obj[v] = BundleUtils.getLangString("customer.yes", locale);
obj[j] = BundleUtils.getLangString("customer.yes", locale); } else obj[v] = null;
} else {
obj[j] = null;
}
} }
} });
rawDataList.add(obj); rawDataList.add(obj);
} }
} }
...@@ -1093,54 +1108,61 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1093,54 +1108,61 @@ public class CustomerServiceImpl implements CustomerService {
//<editor-fold desc="Validate dữ liệu" defaultstate="collapsed"> //<editor-fold desc="Validate dữ liệu" defaultstate="collapsed">
for (int i = 0; i < rawDataList.size(); i++) { for (int i = 0; i < rawDataList.size(); i++) {
if (rawDataList.get(i).length > 1 && rawDataList.get(i)[1] != null && !rawDataList.get(i)[1].toString().trim().equals("")) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.fullname", locale).split("#")[0])
String str = validateLength(BundleUtils.getLangString("customer.fullname", locale).split("#")[0], rawDataList.get(i)[1].toString(), 1000, locale); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.fullname", locale).split("#")[0])] != null
&& !rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.fullname", locale).split("#")[0])].toString().trim().equals("")) {
String str = validateLength(BundleUtils.getLangString("customer.fullname", locale).split("#")[0], rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.fullname", locale).split("#")[0])].toString(), 1000, locale);
if (!str.equals("")) { if (!str.equals("")) {
sb.append(str); sb.append(str);
} }
} else sb.append(BundleUtils.getLangString("customer.nameRequired", locale)); } else sb.append(BundleUtils.getLangString("customer.nameRequired", locale));
if (rawDataList.get(i).length > 4 && (rawDataList.get(i)[2] == null || rawDataList.get(i)[2].toString().trim().equals(""))) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])
&& (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])] == null || rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])].toString().trim().equals(""))) {
isMainPhoneNull = true; isMainPhoneNull = true;
} else { } else {
if (validateNumberOnly(rawDataList.get(i)[2].toString().trim())) { if (validateNumberOnly(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])].toString().trim())) {
sb.append(validateExistPhone(rawDataList.get(i)[2].toString().trim(), locale)); sb.append(validateExistPhone(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])].toString().trim(), locale));
} else { } else {
sb.append(BundleUtils.getLangString("customer.onlyNumber", locale)); sb.append(BundleUtils.getLangString("customer.onlyNumber", locale));
} }
} }
if (rawDataList.get(i).length > 4 && (rawDataList.get(i)[3] == null || rawDataList.get(i)[3].toString().trim().equals(""))) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0]) && (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])] == null || rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])].toString().trim().equals(""))) {
isSecondPhoneNull = true; isSecondPhoneNull = true;
} else { } else {
if (validateNumberOnly(rawDataList.get(i)[3].toString().trim())) { if (validateNumberOnly(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])].toString().trim())) {
sb.append(validateLength(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0], rawDataList.get(i)[3].toString(), 50, locale)); sb.append(validateLength(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0], rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])].toString(), 50, locale));
} else { } else {
sb.append(BundleUtils.getLangString("customer.onlyNumber", locale)); sb.append(BundleUtils.getLangString("customer.onlyNumber", locale));
} }
} }
if (rawDataList.get(i).length > 4 && (rawDataList.get(i)[4] == null || rawDataList.get(i)[4].toString().trim().equals(""))) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])
&& (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])] == null || rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])].toString().trim().equals(""))) {
isEmailNull = true; isEmailNull = true;
} else { } else {
if (!validateEmail(rawDataList.get(i)[4].toString().trim())) { if (!validateEmail(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])].toString().trim())) {
sb.append(BundleUtils.getLangString("customer.emailInvalid", locale)); sb.append(BundleUtils.getLangString("customer.emailInvalid", locale));
} else { } else {
sb.append(validateDuplicateEmail(rawDataList.get(i)[4].toString().trim(), locale)); sb.append(validateDuplicateEmail(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])].toString().trim(), locale));
sb.append(validateLength(BundleUtils.getLangString("customer.email", locale).split("#")[0], rawDataList.get(i)[4].toString(), 50, locale)); sb.append(validateLength(BundleUtils.getLangString("customer.email", locale).split("#")[0], rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])].toString(), 100, locale));
} }
} }
if (isEmailNull && isMainPhoneNull && isSecondPhoneNull) { if (isEmailNull && isMainPhoneNull && isSecondPhoneNull) {
sb.append(BundleUtils.getLangString("customer.invalidRecord", locale)); sb.append(BundleUtils.getLangString("customer.invalidRecord", locale));
} }
if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0]) && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0])] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.address", locale).split("#")[0], rawDataList.get(i)[5].toString(), 500, locale)); sb.append(validateLength(BundleUtils.getLangString("customer.address", locale).split("#")[0], rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0])].toString(), 500, locale));
} }
if (rawDataList.get(i).length > 6 && rawDataList.get(i)[6] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.cusType", locale))
sb.append(validateCusType(rawDataList.get(i)[6].toString().trim(), locale)); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.cusType", locale))] != null) {
sb.append(validateCusType(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.cusType", locale))].toString().trim(), locale));
} }
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])
sb.append(validateLength(BundleUtils.getLangString("customer.companyName", locale).split("#")[0], rawDataList.get(i)[7].toString(), 100, locale)); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.companyName", locale).split("#")[0], rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])].toString(), 100, locale));
} }
if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])
sb.append(validateLength(BundleUtils.getLangString("customer.description", locale).split("#")[0], rawDataList.get(i)[8].toString(), 2000, locale)); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.description", locale).split("#")[0], rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])].toString(), 2000, locale));
} }
// for (int j = 12; j < header.size(); j++) { // for (int j = 12; j < header.size(); j++) {
// if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) { // if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) {
...@@ -1153,13 +1175,13 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1153,13 +1175,13 @@ public class CustomerServiceImpl implements CustomerService {
// } // }
// } // }
// } // }
Row dataRow = sheet.getRow(4 + i); // Row dataRow = sheet.getRow(4 + i);
Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1); // Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1);
if (sb.length() > 0) { if (sb.length() > 0) {
resultCell.setCellValue(sb.toString()); rawDataList.get(i)[objectSize] = sb.toString();
failedCount++; failedCount++;
} else { } else {
resultCell.setCellValue("Ok"); rawDataList.get(i)[objectSize] = "Ok";
} }
sb = new StringBuilder(); sb = new StringBuilder();
isEmailNull = false; isEmailNull = false;
...@@ -1168,18 +1190,24 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1168,18 +1190,24 @@ public class CustomerServiceImpl implements CustomerService {
} }
//</editor-fold> //</editor-fold>
byte[] content = buildResultTemplate(rawDataList, header, headerMap, row.getLastCellNum());
//<editor-fold desc="Insert dữ liệu nếu validate Ok" defaultstate="collapsed"> //<editor-fold desc="Insert dữ liệu nếu validate Ok" defaultstate="collapsed">
if (failedCount == 0) { if (failedCount == 0) {
for (int i = 0; i < rawDataList.size(); i++) { for (int i = 0; i < rawDataList.size(); i++) {
Customer c = new Customer(); Customer c = new Customer();
c.setName(rawDataList.get(i)[1].toString().trim()); c.setName(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.fullname", locale).split("#")[0])].toString().trim());
c.setSiteId(userSession.getSiteId()); c.setSiteId(userSession.getSiteId());
c.setCode(null); c.setCode(null);
if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null && !rawDataList.get(i)[8].toString().trim().equals("")) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])
c.setDescription(rawDataList.get(i)[8].toString().trim()); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])] != null
&& !rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])].toString().trim().equals("")) {
c.setDescription(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.description", locale).split("#")[0])].toString().trim());
} }
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null && !rawDataList.get(i)[7].toString().trim().equals("")) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])
c.setCompanyName(rawDataList.get(i)[7].toString().trim()); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])] != null
&& !rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])].toString().trim().equals("")) {
c.setCompanyName(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.companyName", locale).split("#")[0])].toString().trim());
} }
c.setCustomerImg(null); c.setCustomerImg(null);
c.setCreateDate(new Date()); c.setCreateDate(new Date());
...@@ -1188,8 +1216,10 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1188,8 +1216,10 @@ public class CustomerServiceImpl implements CustomerService {
c.setCreateBy(userSession.getUserName()); c.setCreateBy(userSession.getUserName());
c.setUpdateBy(null); c.setUpdateBy(null);
c.setGender((short) 1); c.setGender((short) 1);
if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null && !rawDataList.get(i)[5].toString().trim().equals("")) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0])
c.setCurrentAddress(rawDataList.get(i)[5].toString().trim()); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0])] != null
&& !rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0])].toString().trim().equals("")) {
c.setCurrentAddress(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.address", locale).split("#")[0])].toString().trim());
} }
// c.setPlaceOfBirth(); // c.setPlaceOfBirth();
// c.setDateOfBirth(); // c.setDateOfBirth();
...@@ -1197,7 +1227,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1197,7 +1227,7 @@ public class CustomerServiceImpl implements CustomerService {
c.setEmail(null); c.setEmail(null);
c.setUserName(null); c.setUserName(null);
c.setAreaCode(null); c.setAreaCode(null);
switch (rawDataList.get(i)[6].toString().trim()) { switch (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.cusType", locale))].toString().trim()) {
case "VIP": case "VIP":
c.setCustomerType(2L); c.setCustomerType(2L);
break; break;
...@@ -1208,25 +1238,26 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1208,25 +1238,26 @@ public class CustomerServiceImpl implements CustomerService {
c.setCustomerType(1L); c.setCustomerType(1L);
break; break;
} }
if (rawDataList.get(i)[9].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) { if (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.callAllowed", locale))].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) {
c.setCallAllowed(1L); c.setCallAllowed(1L);
} else { } else {
c.setCallAllowed(0L); c.setCallAllowed(0L);
} }
if (rawDataList.get(i)[10].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) { if (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.emailAllowed", locale))].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) {
c.setEmailAllowed(1L); c.setEmailAllowed(1L);
} else { } else {
c.setEmailAllowed(0L); c.setEmailAllowed(0L);
} }
if (rawDataList.get(i)[11].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) { if (rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.smsAllowed", locale))].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) {
c.setSmsAllowed(1L); c.setSmsAllowed(1L);
} else { } else {
c.setSmsAllowed(0L); c.setSmsAllowed(0L);
} }
c.setIpccStatus("active"); c.setIpccStatus("active");
Customer saved = customerRepository.save(c); Customer saved = customerRepository.save(c);
if (rawDataList.get(i).length > 2 && rawDataList.get(i)[2] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])
String[] mainPhone = rawDataList.get(i)[2].toString().trim().split(";"); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])] != null) {
String[] mainPhone = rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.mainPhone", locale).split("#")[0])].toString().trim().split(";");
for (int j = 0; j < mainPhone.length; j++) { for (int j = 0; j < mainPhone.length; j++) {
CustomerContact cc = new CustomerContact(); CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId()); cc.setCustomerId(saved.getCustomerId());
...@@ -1242,8 +1273,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1242,8 +1273,9 @@ public class CustomerServiceImpl implements CustomerService {
customerContactRepository.save(cc); customerContactRepository.save(cc);
} }
} }
if (rawDataList.get(i).length > 3 && rawDataList.get(i)[3] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])
String[] subPhone = rawDataList.get(i)[3].toString().trim().split(";"); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])] != null) {
String[] subPhone = rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0])].toString().trim().split(";");
for (int j = 0; j < subPhone.length; j++) { for (int j = 0; j < subPhone.length; j++) {
CustomerContact cc = new CustomerContact(); CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId()); cc.setCustomerId(saved.getCustomerId());
...@@ -1259,8 +1291,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1259,8 +1291,9 @@ public class CustomerServiceImpl implements CustomerService {
customerContactRepository.save(cc); customerContactRepository.save(cc);
} }
} }
if (rawDataList.get(i).length > 4 && rawDataList.get(i)[4] != null) { if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])
String[] email = rawDataList.get(i)[4].toString().split(";"); && rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])] != null) {
String[] email = rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.email", locale).split("#")[0])].toString().split(";");
for (int j = 0; j < email.length; j++) { for (int j = 0; j < email.length; j++) {
CustomerContact cc = new CustomerContact(); CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId()); cc.setCustomerId(saved.getCustomerId());
...@@ -1280,29 +1313,29 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1280,29 +1313,29 @@ public class CustomerServiceImpl implements CustomerService {
CustomizeFieldObject cfo = new CustomizeFieldObject(); CustomizeFieldObject cfo = new CustomizeFieldObject();
cfo.setObjectId(saved.getCustomerId()); cfo.setObjectId(saved.getCustomerId());
cfo.setCustomizeFieldId(dynamicHeader.get(j).getCustomizeFieldId()); cfo.setCustomizeFieldId(dynamicHeader.get(j).getCustomizeFieldId());
if (rawDataList.get(i).length > (12 + j) && rawDataList.get(i)[12 + j] != null) { if (rawDataList.get(i).length > headerMap.get(dynamicHeader.get(j).getTitle()) && rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle())] != null) {
switch (dynamicHeader.get(j).getType()) { switch (dynamicHeader.get(j).getType()) {
case "combobox": case "combobox":
CustomizeFieldOptionValue cfov = CustomizeFieldOptionValue cfov =
customizeFieldOptionValueRepository.findCustomizeFieldOptionValueByNameEqualsAndStatus(rawDataList.get(i)[12 + j].toString().trim(), 1L); customizeFieldOptionValueRepository.findCustomizeFieldOptionValueByNameEqualsAndStatus(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle())].toString().trim(), 1L);
cfo.setFieldOptionValueId(cfov.getFieldOptionValueId()); cfo.setFieldOptionValueId(cfov.getFieldOptionValueId());
break; break;
case "checkbox": case "checkbox":
if (rawDataList.get(i)[12 + j].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) { if (rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle())].toString().trim().equals(BundleUtils.getLangString("customer.yes", locale))) {
cfo.setValueCheckbox(1L); cfo.setValueCheckbox(1L);
} else { } else {
cfo.setValueCheckbox(0L); cfo.setValueCheckbox(0L);
} }
break; break;
case "date": case "date":
Date date = dateFormat.parse(rawDataList.get(i)[12 + j].toString().trim()); Date date = dateFormat.parse(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle())].toString().trim());
cfo.setValueDate(date); cfo.setValueDate(date);
break; break;
case "number": case "number":
cfo.setValueNumber(Long.parseLong(rawDataList.get(i)[12 + j].toString().trim())); cfo.setValueNumber(Long.parseLong(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle())].toString().trim()));
break; break;
default: default:
cfo.setValueText(rawDataList.get(i)[12 + j].toString().trim()); cfo.setValueText(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle())].toString().trim());
break; break;
} }
} }
...@@ -1319,18 +1352,14 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1319,18 +1352,14 @@ public class CustomerServiceImpl implements CustomerService {
clm.setCustomerListId(customerListId); clm.setCustomerListId(customerListId);
customerListMappingRepository.save(clm); customerListMappingRepository.save(clm);
} }
workbook.write(os); // workbook.write(os);
os.flush();
os.close();
workbook.close(); workbook.close();
result.put("content", os.toByteArray()); result.put("content", content);
result.put("message", "import-success"); result.put("message", "import-success");
} else { } else {
workbook.write(os); // workbook.write(os);
os.flush();
os.close();
workbook.close(); workbook.close();
result.put("content", os.toByteArray()); result.put("content", content);
result.put("message", "import-error"); result.put("message", "import-error");
} }
//</editor-fold> //</editor-fold>
...@@ -1351,12 +1380,23 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1351,12 +1380,23 @@ public class CustomerServiceImpl implements CustomerService {
String[] arr = str.split(";"); String[] arr = str.split(";");
List<CustomerContact> contactList; List<CustomerContact> contactList;
if (str.length() > 50) { if (str.length() > 50) {
result = BundleUtils.getLangString("customer.phoneMax50", locale); result += BundleUtils.getLangString("customer.phoneMax50", locale);
}
if (arr.length > 3) {
result += BundleUtils.getLangString("customer.3phone", locale);
} else {
for (int i = 0; i < arr.length; i++) {
if (arr[i].length() < 8 || arr[i].length() > 15) {
result += BundleUtils.getLangString("customer.phone8to15", locale);
break;
}
}
} }
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]); contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]);
if (contactList.size() != 0) { if (contactList.size() != 0) {
return result.concat(BundleUtils.getLangString("customer.phoneExists", locale)); result += BundleUtils.getLangString("customer.phoneExists", locale);
break;
} }
} }
return result; return result;
...@@ -1376,7 +1416,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1376,7 +1416,7 @@ public class CustomerServiceImpl implements CustomerService {
private String validateDuplicateEmail(String str, Locale locale) { private String validateDuplicateEmail(String str, Locale locale) {
String result = ""; String result = "";
String[] arr = str.split(";"); String[] arr = str.split(",");
List<CustomerContact> contactList; List<CustomerContact> contactList;
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]); contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]);
...@@ -1408,7 +1448,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1408,7 +1448,7 @@ public class CustomerServiceImpl implements CustomerService {
} }
private boolean validateEmail(String str) { private boolean validateEmail(String str) {
String[] arr = str.split(";"); String[] arr = str.split(",");
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
Matcher matcher = EMAIL_REGEXP.matcher(arr[i]); Matcher matcher = EMAIL_REGEXP.matcher(arr[i]);
if (!matcher.matches()) { if (!matcher.matches()) {
...@@ -1448,6 +1488,183 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1448,6 +1488,183 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold> //</editor-fold>
private byte[] buildResultTemplate(List<Object[]> rawData, List<CustomizeFields> header, Map<String, Integer> dataMap, int lastNum) throws IOException {
LOGGER.info("---------------CREATE RESULT FILE--------------");
Locale locale = new Locale("vi", "VN");
XSSFWorkbook workbook = null;
Map<String, Integer> headerMap = new HashMap<>();
try {
workbook = new XSSFWorkbook();
CreationHelper creationHelper = workbook.getCreationHelper();
ByteArrayOutputStream os = new ByteArrayOutputStream();
Sheet sheet = workbook.createSheet("RESULT");
dataMap.put(BundleUtils.getLangString("customer.result", locale), lastNum);
//<editor-fold desc="Tạo style và font" defaultstate="collapsed">
Font headerFont = workbook.createFont();
Font importantFont = workbook.createFont();
importantFont.setColor(IndexedColors.RED.index);
headerFont.setBold(true);
CellStyle headerStyle = workbook.createCellStyle();
CellStyle importantStyle = workbook.createCellStyle();
CellStyle columnStyle = workbook.createCellStyle();
importantStyle.setFont(importantFont);
headerStyle.setAlignment(HorizontalAlignment.CENTER);
headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
headerStyle.setFont(headerFont);
columnStyle.setVerticalAlignment(VerticalAlignment.CENTER);
columnStyle.setAlignment(HorizontalAlignment.CENTER);
columnStyle.setWrapText(true);
//</editor-fold>
//<editor-fold desc="Thêm combobox" defaultstate="collapsed">
//<editor-fold desc="Cho những trường động" defaultstate="collapsed">
DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
for (int i = 12; i < header.size(); i++) {
if (header.get(i).getType().equals("combobox")) {
String[] constraint;
List<CustomizeFieldOptionValue> list =
customizeFieldOptionValueRepository.findCustomizeFieldOptionValuesByFieldOptionIdAndStatus(header.get(i).getFieldOptionsId(), 1L);
constraint = new String[list.size()];
for (int j = 0; j < list.size(); j++) {
constraint[j] = list.get(j).getName();
}
DataValidationConstraint comboboxConstraint = dataValidationHelper.createExplicitListConstraint(constraint);
CellRangeAddressList comboboxCellRange = new CellRangeAddressList(4, 9999, 12 + i, 12 + i);
DataValidation comboboxValidation = dataValidationHelper.createValidation(comboboxConstraint, comboboxCellRange);
comboboxValidation.setSuppressDropDownArrow(true);
comboboxValidation.setShowErrorBox(true);
sheet.addValidationData(comboboxValidation);
} else if (header.get(i).getType().equals("checkbox")) {
DataValidationConstraint yesNoConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{BundleUtils.getLangString("customer.yes", locale), BundleUtils.getLangString("customer.not", locale)});
CellRangeAddressList checkboxCellRange = new CellRangeAddressList(4, 9999, 12 + i, 12 + i);
DataValidation yesNoValidation = dataValidationHelper.createValidation(yesNoConstraint, checkboxCellRange);
yesNoValidation.setShowErrorBox(true);
yesNoValidation.setSuppressDropDownArrow(true);
sheet.addValidationData(yesNoValidation);
}
}
//</editor-fold>
//<editor-fold desc="Cho những trường tĩnh" defaultstate="collapsed">
DataValidationConstraint cusTypeConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{BundleUtils.getLangString("customer.cusType.normal", locale), BundleUtils.getLangString("customer.cusType.vip", locale), BundleUtils.getLangString("customer.cusType.blacklist", locale)});
DataValidationConstraint isAllowConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{BundleUtils.getLangString("customer.yes", locale), BundleUtils.getLangString("customer.not", locale)});
CellRangeAddressList cusTypeCellRangeAddressList = new CellRangeAddressList(4, 9999, 6, 6);
CellRangeAddressList callCellRangeAddressList = new CellRangeAddressList(4, 9999, 9, 9);
CellRangeAddressList emailCellRangeAddressList = new CellRangeAddressList(4, 9999, 10, 10);
CellRangeAddressList smsCellRangeAddressList = new CellRangeAddressList(4, 9999, 11, 11);
DataValidation cusTypeValidation = dataValidationHelper.createValidation(cusTypeConstraint, cusTypeCellRangeAddressList);
DataValidation callValidation = dataValidationHelper.createValidation(isAllowConstraint, callCellRangeAddressList);
DataValidation emailValidation = dataValidationHelper.createValidation(isAllowConstraint, emailCellRangeAddressList);
DataValidation smsValidation = dataValidationHelper.createValidation(isAllowConstraint, smsCellRangeAddressList);
cusTypeValidation.setSuppressDropDownArrow(true);
cusTypeValidation.setShowErrorBox(true);
callValidation.setSuppressDropDownArrow(true);
callValidation.setShowErrorBox(true);
emailValidation.setSuppressDropDownArrow(true);
emailValidation.setShowErrorBox(true);
smsValidation.setSuppressDropDownArrow(true);
smsValidation.setShowErrorBox(true);
sheet.addValidationData(cusTypeValidation);
sheet.addValidationData(callValidation);
sheet.addValidationData(emailValidation);
sheet.addValidationData(smsValidation);
//</editor-fold>
//</editor-fold>
//<editor-fold desc="Ghi header" defaultstate="collapsed">
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = creationHelper.createClientAnchor();
Row row0 = sheet.createRow(0);
Row row2 = sheet.createRow(2);
Row row3 = sheet.createRow(3);
Cell cell0 = row0.createCell(0);
cell0.setCellStyle(headerStyle);
cell0.setCellValue(BundleUtils.getLangString("customer.importCustomer", locale));
Cell cell2 = row2.createCell(0);
cell2.setCellStyle(importantStyle);
cell2.setCellValue(BundleUtils.getLangString("customer.notice", locale));
for (int i = 0; i < header.size(); i++) {
sheet.setDefaultColumnStyle(i, columnStyle);
Cell headerCell = row3.createCell(i);
headerCell.setCellValue(header.get(i).getTitle().split("#")[0]);
headerStyle.setBorderTop(BorderStyle.THIN);
headerStyle.setBorderRight(BorderStyle.THIN);
headerStyle.setBorderBottom(BorderStyle.THIN);
headerStyle.setBorderLeft(BorderStyle.THIN);
headerFont.setFontHeightInPoints((short) 11);
headerCell.setCellStyle(headerStyle);
if (i == 0) {
sheet.setColumnWidth(i, 2500);
} else {
sheet.setColumnWidth(i, 6000);
}
anchor.setCol1(headerCell.getColumnIndex());
anchor.setCol2(headerCell.getColumnIndex() + 2);
anchor.setRow1(row3.getRowNum());
anchor.setRow2(row3.getRowNum() + 4);
if (header.get(i).getTitle().contains("#")) {
Comment comment = drawing.createCellComment(anchor);
RichTextString str = creationHelper.createRichTextString(header.get(i).getTitle().split("#")[1]);
comment.setString(str);
comment.setAuthor("APACHE POI");
headerCell.setCellComment(comment);
}
headerMap.put(header.get(i).getTitle().split("#")[0].trim(), i);
}
sheet.setColumnWidth(header.size(), 8000);
Cell resultCell = row3.createCell(header.size());
resultCell.setCellStyle(headerStyle);
resultCell.setCellValue(BundleUtils.getLangString("customer.result", locale));
headerMap.put(BundleUtils.getLangString("customer.result", locale), headerMap.size());
//</editor-fold>
//<editor-fold desc="Ghi dữ liệu">
for (int i = 0; i < rawData.size(); i++) {
Row dataRow = sheet.createRow(4 + i);
int finalI = i;
headerMap.forEach((k, v) -> {
Cell c = dataRow.createCell(v);
c.setCellType(CellType.STRING);
if (rawData.get(finalI).length > dataMap.get(k)
&& rawData.get(finalI)[dataMap.get(k)] != null
&& !"".equals(rawData.get(finalI)[dataMap.get(k)].toString().trim())) {
c.setCellValue(rawData.get(finalI)[dataMap.get(k)].toString());
}
});
// for (int j = 0; j < header.size(); j++) {
// headerMap.get(header.get(j).getTitle().split("#")[0]);
// if (rawData.get(i).length > header.size() + 1 && rawData.get(i)[j] != null && !"".equals(rawData.get(i)[j].toString().trim())) {
// Cell c = dataRow.createCell(j);
// c.setCellType(CellType.STRING);
// c.setCellValue(rawData.get(i)[j].toString());
// }
// }
}
//</editor-fold>
sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 13));
sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 13));
workbook.write(os);
os.flush();
os.close();
return os.toByteArray();
} catch (Exception e) {
LOGGER.error(e.getMessage());
return null;
} finally {
if (workbook != null) workbook.close();
}
}
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public byte[] buildTemplate(Long companySiteId) throws IOException { public byte[] buildTemplate(Long companySiteId) throws IOException {
...@@ -1459,6 +1676,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1459,6 +1676,7 @@ public class CustomerServiceImpl implements CustomerService {
CreationHelper creationHelper = workbook.getCreationHelper(); CreationHelper creationHelper = workbook.getCreationHelper();
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
Sheet sheet = workbook.createSheet("IMPORT"); Sheet sheet = workbook.createSheet("IMPORT");
DataFormat dataFormat = workbook.createDataFormat();
//<editor-fold desc="Tạo array header" defaultstate="collapsed"> //<editor-fold desc="Tạo array header" defaultstate="collapsed">
List<CustomizeFields> header = new ArrayList<>(); List<CustomizeFields> header = new ArrayList<>();
...@@ -1494,6 +1712,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1494,6 +1712,7 @@ public class CustomerServiceImpl implements CustomerService {
columnStyle.setVerticalAlignment(VerticalAlignment.CENTER); columnStyle.setVerticalAlignment(VerticalAlignment.CENTER);
columnStyle.setAlignment(HorizontalAlignment.CENTER); columnStyle.setAlignment(HorizontalAlignment.CENTER);
columnStyle.setWrapText(true); columnStyle.setWrapText(true);
columnStyle.setDataFormat(dataFormat.getFormat("@"));
//</editor-fold> //</editor-fold>
//<editor-fold desc="Thêm combobox" defaultstate="collapsed"> //<editor-fold desc="Thêm combobox" defaultstate="collapsed">
......
...@@ -7,10 +7,12 @@ public class Constants { ...@@ -7,10 +7,12 @@ public class Constants {
public interface ApiErrorCode { public interface ApiErrorCode {
String ERROR = "01"; String ERROR = "01";
String SUCCESS = "00"; String SUCCESS = "00";
String DELETE_ERROR = "02";
} }
public interface ApiErrorDesc { public interface ApiErrorDesc {
String ERROR = "ERROR"; String ERROR = "ERROR";
String SUCCESS = "SUCCESS"; String SUCCESS = "SUCCESS";
String DELETE_ERROR = "DELETE_ERROR";
} }
public interface FileType { public interface FileType {
String pdf = "pdf"; String pdf = "pdf";
......
...@@ -87,15 +87,13 @@ customer.cusType.vip = VIP ...@@ -87,15 +87,13 @@ customer.cusType.vip = VIP
customer.cusType.blacklist = Blacklist customer.cusType.blacklist = Blacklist
customer.yes = Yes customer.yes = Yes
customer.not = No customer.not = No
customer.noData = Template empty
customer.nameRequired = Full name required; customer.nameRequired = Full name required;
customer.emailMax100=Email must less than 100 character;
customer.invalidRecord=Invalid Record, required one more contact information; customer.invalidRecord=Invalid Record, required one more contact information;
customer.onlyNumber=Phone contain number only; customer.onlyNumber=Phone contain number only;
customer.importSuccess = Import Successful
customer.importFailed = Import Failed
customer.errorValidate = Error while validating customer.errorValidate = Error while validating
customer.phoneMax50 = Mobile phone must less than 50 character; customer.phoneMax50=Mobile phone must less than 50 characters;
customer.phone8to15=Mobile phone from 8 to 15 characters;
customer.3phone=Max 3 mobile phone;
customer.phoneExists = Mobile phone exists; customer.phoneExists = Mobile phone exists;
customer.notMatch = not match regexp validation customer.notMatch = not match regexp validation
customer.notGreaterThan = not greater than customer.notGreaterThan = not greater than
......
...@@ -89,15 +89,13 @@ customer.cusType.vip = VIP ...@@ -89,15 +89,13 @@ customer.cusType.vip = VIP
customer.cusType.blacklist = Blacklist customer.cusType.blacklist = Blacklist
customer.yes = customer.yes =
customer.not = Không customer.not = Không
customer.noData = Template không có dữ liệu
customer.nameRequired = Họ và tên không được để trống; customer.nameRequired = Họ và tên không được để trống;
customer.emailMax100=Email không được quá 100 kí tự;
customer.invalidRecord=Bắt buộc nhập 1 trong 3 thông tin liên lạc(Số điện thoại chính, Số điện thoại phụ, Email); customer.invalidRecord=Bắt buộc nhập 1 trong 3 thông tin liên lạc(Số điện thoại chính, Số điện thoại phụ, Email);
customer.onlyNumber=Số điện thoại chỉ được nhập số; customer.onlyNumber=Số điện thoại chỉ được nhập số;
customer.importSuccess = Import dữ liệu thành công
customer.importFailed = Import dữ liệu thất bại
customer.errorValidate = Validate dữ liệu lỗi customer.errorValidate = Validate dữ liệu lỗi
customer.phoneMax50 = Số điện thoại không được quá 50 kí tự; customer.phoneMax50 = Số điện thoại không được quá 50 kí tự;
customer.phone8to15=Số điện thoại chỉ được từ 8 đến 15 kí tự;
customer.3phone=Tối đa chỉ được nhập 3 số điện thoại;
customer.phoneExists = Số điện thoại chính đã tồn tại; customer.phoneExists = Số điện thoại chính đã tồn tại;
customer.notMatch = không đúng định dạng customer.notMatch = không đúng định dạng
customer.notGreaterThan = không được lớn hơn customer.notGreaterThan = không được lớn hơn
......
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