Commit b5de5747 authored by Đào Nhật Quang's avatar Đào Nhật Quang

quangdn

parent e70d70c7
......@@ -1074,7 +1074,7 @@ public class CustomerServiceImpl implements CustomerService {
//<editor-fold desc="Đọc dữ liệu từng dòng 1" defaultstate="collapsed">
for (int i = 4; i <= sheet.getPhysicalNumberOfRows(); i++) {
Row dataRow = sheet.getRow(i);
if (dataRow != null) {
if (!isRowEmpty(dataRow)) {
Object[] obj = new Object[objectSize + 1];
// for (int j = 0; j < header.size(); j++) {
// Cell dataCell = dataRow.getCell(j);
......@@ -1106,7 +1106,7 @@ public class CustomerServiceImpl implements CustomerService {
}
});
rawDataList.add(obj);
}
} else break;
}
//</editor-fold>
......@@ -1169,19 +1169,57 @@ public class CustomerServiceImpl implements CustomerService {
&& 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++) {
// if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) {
// if (header.get(j).getType().equals("text")) {
// sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMinLength(), header.get(j).getMaxLength(), locale));
// } else if (header.get(j).getType().equals("date")) {
// sb.append(validateUsingRegexp(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getRegexpForValidation(), locale));
// } else if (header.get(j).getType().equals("number")) {
// sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMin(), header.get(j).getMax(), locale));
if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.callAllowed", locale).split("#")[0])
&& rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.callAllowed", locale).split("#")[0])] != null) {
sb.append(validateYesNo(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.callAllowed"))].toString().trim(), locale));
}
if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.emailAllowed", locale).split("#")[0])
&& rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.emailAllowed", locale).split("#")[0])] != null) {
sb.append(validateYesNo(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.emailAllowed"))].toString().trim(), locale));
}
if (rawDataList.get(i).length > headerMap.get(BundleUtils.getLangString("customer.smsAllowed", locale).split("#")[0])
&& rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.smsAllowed", locale).split("#")[0])] != null) {
sb.append(validateYesNo(rawDataList.get(i)[headerMap.get(BundleUtils.getLangString("customer.smsAllowed"))].toString().trim(), locale));
}
//<editor-fold desc="Validate những trường động, chỉ cần uncomment và fix bug là có thể dùng :v">
// for (int j = 0; j < dynamicHeader.size(); j++) {
// if (rawDataList.get(i).length > headerMap.get(dynamicHeader.get(j).getTitle().trim())
// && rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())] != null
// && !"".equals(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())]))
// switch (dynamicHeader.get(j).getType()) {
// case "combobox":
// List<CustomizeFieldOptionValue> optionValues =
// customizeFieldOptionValueRepository.findCustomizeFieldOptionValuesByFieldOptionIdAndStatus(dynamicHeader.get(j).getFieldOptionsId(), 1L);
// String[] arr = new String[optionValues.size()];
// int s = 0;
// for (CustomizeFieldOptionValue c: optionValues) {
// arr[s] = c.getName().trim();
// s++;
// }
// sb.append(validateCombobox(arr, rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString(), locale));
// break;
// case "number":
// if (validateNumberOnly(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString())) {
// sb.append(validateDynamicLength(dynamicHeader.get(j).getTitle(), rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString(), dynamicHeader.get(j).getMin(), dynamicHeader.get(j).getMax(), locale));
// sb.append(validateUsingRegexp(dynamicHeader.get(j).getTitle(), rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString(), dynamicHeader.get(j).getRegexpForValidation(), locale));
// } else {
// sb.append(BundleUtils.getLangString("customer.onlyNumber", locale));
// }
// break;
// case "date":
// sb.append(validateUsingRegexp(dynamicHeader.get(j).getTitle(), rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString(), dynamicHeader.get(j).getRegexpForValidation(), locale));
// break;
// case "checkbox":
// sb.append(validateYesNo(rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString(), locale));
// break;
// default:
// sb.append(validateDynamicLength(dynamicHeader.get(j).getTitle(), rawDataList.get(i)[headerMap.get(dynamicHeader.get(j).getTitle().trim())].toString(), dynamicHeader.get(j).getMinLength(), dynamicHeader.get(j).getMaxLength(), locale));
// break;
// }
// }
// Row dataRow = sheet.getRow(4 + i);
// Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1);
//</editor-fold>
if (sb.length() > 0) {
rawDataList.get(i)[objectSize] = sb.toString();
failedCount++;
......@@ -1380,6 +1418,16 @@ public class CustomerServiceImpl implements CustomerService {
}
//<editor-fold desc="Validate Methods" defaultstate="collapsed">
private boolean isRowEmpty(Row row) {
for (int i = 0; i <= row.getLastCellNum(); i++) {
Cell cell = row.getCell(i);
if (cell != null && cell.getCellType() != CellType.BLANK) {
return false;
}
}
return true;
}
private String validateExistPhone(String str, Locale locale, boolean isCheckDuplicate) {
String result = "";
String[] arr = str.split("[;,]");
......@@ -1477,20 +1525,29 @@ public class CustomerServiceImpl implements CustomerService {
}
}
private String validateYesNo(String str, Locale locale) {
String[] arr = {BundleUtils.getLangString("customer.yes", locale),
BundleUtils.getLangString("customer.not", locale)};
List<String> cusTypes = Arrays.asList(arr);
if (cusTypes.contains(str.trim())) {
return "";
} else {
return BundleUtils.getLangString("customer.comboboxInvalid", locale);
}
}
private boolean validateLetter(String str) {
String regexp = "@\"^\\p{L}+$\"";
return str.matches(regexp);
}
private boolean isColumnNullOrBlank(Sheet sheet, int columnIndex) {
for (Row row : sheet) {
if (row.getRowNum() < 3) continue;
Cell cell = row.getCell(columnIndex, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
if (cell != null) {
return false;
}
private String validateCombobox(String[] optionValue, String str, Locale locale) {
List<String> arr = Arrays.asList(optionValue);
if (!arr.contains(str)) {
return BundleUtils.getLangString("customer.comboboxInvalid", locale);
} else {
return "";
}
return true;
}
//</editor-fold>
......
......@@ -102,7 +102,7 @@ customer.importCustomer = IMPORT CUSTOMER
customer.notice = Attention: A record is valid when Full Name is not null and one of three fields Main phone, secondary phone or email is not null
customer.emailInvalid=Invalid email;
customer.emailExists=Email exists;
customer.cusTypeInvalid=Customer type Invalid;
customer.comboboxInvalid=Combobox option invalid;
common.fileNotSelected=Please select a file
common.fileInvalidFormat=File invalid
......
......@@ -104,7 +104,7 @@ customer.importCustomer = IMPORT KHÁCH HÀNG
customer.notice = Chú ý: 1 bản ghi được coi là hợp lệ bắt buộc phải có thông tin Họ và Tên và 1 trong 3 thông tin liên lạc (số điện thoại chính, số điện thoại phụ hoặc email)
customer.emailInvalid=Email không đúng định dạng;
customer.emailExists=Email đã tồn tại;
customer.cusTypeInvalid=Loại khách hàng không hợp lệ;
customer.comboboxInvalid=Dữ liệu trong combobox không hợp lệ;
common.fileNotSelected=Bạn chưa chọn file
common.fileInvalidFormat=File không hợp lệ
......
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