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

quangdn - add download template and import template

parent 6c12fe26
......@@ -58,7 +58,8 @@ import java.util.regex.Pattern;
public class CustomerServiceImpl implements CustomerService {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class);
private static final Pattern EMAIL_REGEXP = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
// private static final Pattern EMAIL_REGEXP = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
private static final Pattern EMAIL_REGEXP = Pattern.compile("^(.+)@(.+)$", Pattern.CASE_INSENSITIVE);
@Autowired
@PersistenceContext(unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
......@@ -1088,6 +1089,9 @@ public class CustomerServiceImpl implements CustomerService {
if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.address", locale).split("#")[0], rawDataList.get(i)[5].toString(), 500, locale));
}
if (rawDataList.get(i).length > 6 && rawDataList.get(i)[6] != null) {
sb.append(validateCusType(rawDataList.get(i)[6].toString().trim(), locale));
}
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.companyName", locale).split("#")[0], rawDataList.get(i)[7].toString(), 100, locale));
}
......@@ -1114,6 +1118,9 @@ public class CustomerServiceImpl implements CustomerService {
resultCell.setCellValue("Ok");
}
sb = new StringBuilder();
isEmailNull = false;
isMainPhoneNull = false;
isSecondPhoneNull = false;
}
//</editor-fold>
......@@ -1124,8 +1131,12 @@ public class CustomerServiceImpl implements CustomerService {
c.setName(rawDataList.get(i)[1].toString().trim());
c.setSiteId(userSession.getSiteId());
c.setCode(null);
c.setDescription(rawDataList.get(i)[8].toString().trim());
c.setCompanyName(rawDataList.get(i)[7].toString().trim());
if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null && !rawDataList.get(i)[8].toString().trim().equals("")) {
c.setDescription(rawDataList.get(i)[8].toString().trim());
}
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null && !rawDataList.get(i)[7].toString().trim().equals("")) {
c.setCompanyName(rawDataList.get(i)[7].toString().trim());
}
c.setCustomerImg(null);
c.setCreateDate(new Date());
c.setUpdateDate(null);
......@@ -1133,7 +1144,9 @@ public class CustomerServiceImpl implements CustomerService {
c.setCreateBy(userSession.getUserName());
c.setUpdateBy(null);
c.setGender((short) 1);
c.setCurrentAddress(rawDataList.get(i)[5].toString().trim());
if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null && !rawDataList.get(i)[5].toString().trim().equals("")) {
c.setCurrentAddress(rawDataList.get(i)[5].toString().trim());
}
// c.setPlaceOfBirth();
// c.setDateOfBirth();
c.setMobileNumber(null);
......@@ -1354,13 +1367,25 @@ public class CustomerServiceImpl implements CustomerService {
String[] arr = str.split(";");
for (int i = 0; i < arr.length; i++) {
Matcher matcher = EMAIL_REGEXP.matcher(arr[i]);
if (!matcher.find()) {
if (!matcher.matches()) {
return false;
}
}
return true;
}
private String validateCusType(String str, Locale locale) {
String[] arr = {BundleUtils.getLangString("customer.cusType.normal", locale),
BundleUtils.getLangString("customer.cusType.vip", locale),
BundleUtils.getLangString("customer.cusType.blacklist", locale)};
List<String> cusTypes = Arrays.asList(arr);
if (cusTypes.contains(str.trim())) {
return "";
} else {
return BundleUtils.getLangString("customer.cusTypeInvalid", locale);
}
}
private boolean validateLetter(String str) {
String regexp = "@\"^\\p{L}+$\"";
return str.matches(regexp);
......
......@@ -104,6 +104,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;
common.fileNotSelected=Please select a file
common.fileInvalidFormat=File invalid
......
......@@ -106,6 +106,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ệ;
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