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

quangdn

parent 4b201f38
......@@ -7,6 +7,7 @@ import com.viettel.campaign.model.ccms_full.CustomizeFields;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import java.util.Date;
import java.util.List;
......@@ -66,7 +67,7 @@ public interface CustomerService {
byte[] buildTemplate(Long companySiteId);
Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> headerDTOS, Long companySiteId);
Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> headerDTOS, UserSession userSession, Long customerListId);
List<CustomizeFieldObject> getCustomizeField(Long customerId);
}
......@@ -6,14 +6,12 @@ import com.viettel.campaign.mapper.CustomerMapper;
import com.viettel.campaign.model.ccms_full.*;
import com.viettel.campaign.repository.ccms_full.*;
import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.DataUtil;
import com.viettel.campaign.utils.HibernateUtil;
import com.viettel.campaign.utils.SQLBuilder;
import com.viettel.campaign.utils.*;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerDetailRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
......@@ -888,8 +886,9 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, Long companySiteId) {
public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) {
LOGGER.info("------------READ AND VALIDATE--------------");
Locale locale = new Locale("vi", "VN");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Map<String, Object> result = new HashMap<>();
StringBuilder sb = new StringBuilder();
......@@ -897,33 +896,32 @@ public class CustomerServiceImpl implements CustomerService {
try {
//<editor-fold desc="Khởi tạo mảng header tĩnh" defaultstate="collapsed">
// List<String> staticHeader = new ArrayList<>();
// staticHeader.add("STT");
// staticHeader.add("Họ và tên#Bắt buộc\nĐịnh dạng chữ\ntối đa 1000 ký tự");
// staticHeader.add("Số điện thoại chính#Định dạng số\ncho phép nhập nhiều số điện thoại chính\ncác số cách nhau bởi dấu chấm phấy\ntối đa 50 ký tự");
// staticHeader.add("Số điện thoại phụ#Định dạng số\ncho phép nhập nhiều số điện thoại phụ\ncác số cách nhau bởi dấu chấm phấy\ntối đa 50 ký tự");
// staticHeader.add("Email chính#Cho phép nhập nhiều email\nmỗi email cách nhau bởi dấu \";\"\ntối đa 100 ký tự");
// staticHeader.add("Địa chỉ#Tối đa 500 ký tự");
// staticHeader.add("Loại khách hàng");
// staticHeader.add("Công ty#Tối đa 100 ký tự");
// staticHeader.add("Ghi chú#Tối đa 2000 ký tự");
// staticHeader.add("Cho phép gọi ra");
// staticHeader.add("Cho phép gửi email");
// staticHeader.add("Cho phép gửi sms");
List<CustomizeFields> header = new ArrayList<>();
header.add(new CustomizeFields("text", "STT"));
header.add(new CustomizeFields("text", "Họ và tên#Bắt buộc\nĐịnh dạng chữ\ntối đa 1000 ký tự"));
header.add(new CustomizeFields("text", "Số điện thoại chính#Định dạng số\ncho phép nhập nhiều số điện thoại chính\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
header.add(new CustomizeFields("text", "Số điện thoại phụ#Định dạng số\ncho phép nhập nhiều số điện thoại phụ\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
header.add(new CustomizeFields("text", "Email chính#Cho phép nhập nhiều email\nmỗi email cách nhau bởi dấu \",\"\ntối đa 100 ký tự"));
header.add(new CustomizeFields("text", "Địa chỉ#Tối đa 500 ký tự"));
header.add(new CustomizeFields("combobox", "Loại khách hàng"));
header.add(new CustomizeFields("text", "Công ty#Tối đa 100 ký tự"));
header.add(new CustomizeFields("text", "Ghi chú#Tối đa 2000 ký tự"));
header.add(new CustomizeFields("combobox", "Cho phép gọi ra"));
header.add(new CustomizeFields("combobox", "Cho phép gửi email"));
header.add(new CustomizeFields("combobox", "Cho phép gửi sms"));
// header.add(new CustomizeFields("text", "STT"));
// header.add(new CustomizeFields("text", "Họ và tên#Bắt buộc\nĐịnh dạng chữ\ntối đa 1000 ký tự"));
// header.add(new CustomizeFields("text", "Số điện thoại chính#Định dạng số\ncho phép nhập nhiều số điện thoại chính\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
// header.add(new CustomizeFields("text", "Số điện thoại phụ#Định dạng số\ncho phép nhập nhiều số điện thoại phụ\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
// header.add(new CustomizeFields("text", "Email chính#Cho phép nhập nhiều email\nmỗi email cách nhau bởi dấu \",\"\ntối đa 100 ký tự"));
// header.add(new CustomizeFields("text", "Địa chỉ#Tối đa 500 ký tự"));
// header.add(new CustomizeFields("combobox", "Loại khách hàng"));
// header.add(new CustomizeFields("text", "Công ty#Tối đa 100 ký tự"));
// header.add(new CustomizeFields("text", "Ghi chú#Tối đa 2000 ký tự"));
// header.add(new CustomizeFields("combobox", "Cho phép gọi ra"));
// header.add(new CustomizeFields("combobox", "Cho phép gửi email"));
// header.add(new CustomizeFields("combobox", "Cho phép gửi sms"));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.no", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.fullname", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.mainPhone", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.secondPhone", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.email", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.address", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.cusType", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.companyName", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.description", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.callAllowed", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.emailAllowed", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.smsAllowed", locale)));
header.addAll(dynamicHeader);
//</editor-fold>
......@@ -951,7 +949,7 @@ public class CustomerServiceImpl implements CustomerService {
Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) {
result.put("file", file);
result.put("message", "Template sai dinh dang");
result.put("message", BundleUtils.getLangString("customer.invalidTemplate", locale));
return result;
}
}
......@@ -961,12 +959,12 @@ public class CustomerServiceImpl implements CustomerService {
//<editor-fold desc="Kiểm tra file dữ liệu rỗng" defaultstate="collapsed">
if (sheet.getPhysicalNumberOfRows() == 3) {
result.put("message", "File khong co du lieu");
result.put("message", BundleUtils.getLangString("customer.noData", locale));
result.put("file", file);
return result;
} else {
Cell resultCell = sheet.getRow(3).createCell(sheet.getRow(3).getPhysicalNumberOfCells());
resultCell.setCellValue("Kết quả");
resultCell.setCellValue(BundleUtils.getLangString("customer.result", locale));
resultCell.setCellStyle(resultStyle);
}
//</editor-fold>
......@@ -989,11 +987,11 @@ public class CustomerServiceImpl implements CustomerService {
}
} else {
Cell headerCell = row.getCell(j);
if (headerCell.getStringCellValue().equals("Loại khách hàng")) {
obj[j] = "Thường";
} else if (headerCell.getStringCellValue().equals("Cho phép gọi ra") || headerCell.getStringCellValue().equals("Cho phép gửi email")
|| headerCell.getStringCellValue().equals("Cho phép gửi sms")) {
obj[j] = "Có";
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);
break;
} else {
obj[j] = null;
......@@ -1006,56 +1004,14 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold>
//<editor-fold desc="Validate dữ liệu" defaultstate="collapsed">
// for (int i = 0; i < rawDataList.size(); i++) {
// sb.append(validateRecord(rawDataList.get(i)));
// sb.append(validateLength(row.getCell(1).getStringCellValue(), rawDataList.get(i)[1].toString(), 1000));
// if (rawDataList.get(i).length > 12 && rawDataList.get(i)[2] != null) {
// sb.append(validateLength(row.getCell(2).getStringCellValue(), rawDataList.get(i)[2].toString(), 50));
// }
// if (rawDataList.get(i).length > 12 && rawDataList.get(i)[3] != null) {
// sb.append(validateLength(row.getCell(3).getStringCellValue(), rawDataList.get(i)[3].toString(), 50));
// }
// if (rawDataList.get(i).length > 12 && rawDataList.get(i)[4] != null) {
// sb.append(validateLength(row.getCell(4).getStringCellValue(), rawDataList.get(i)[4].toString(), 100));
// String[] emails = rawDataList.get(i)[4].toString().split(";");
// boolean email = false;
// for (int j = 0; j < emails.length; j++) {
// if (!validateEmail(emails[j])) {
// email = true;
// }
// }
// if (email) {
// sb.append("Email khong dung dinh dang;");
// }
// }
// if (rawDataList.get(i).length > 12 && rawDataList.get(i)[5] != null) {
// sb.append(validateLength(row.getCell(5).getStringCellValue(), rawDataList.get(i)[5].toString(), 500));
// }
// if (rawDataList.get(i).length > 12 && rawDataList.get(i)[7] != null) {
// sb.append(validateLength(row.getCell(7).getStringCellValue(), rawDataList.get(i)[7].toString(), 100));
// }
// if (rawDataList.get(i).length > 12 && rawDataList.get(i)[8] != null) {
// sb.append(validateLength(row.getCell(8).getStringCellValue(), rawDataList.get(i)[8].toString(), 2000));
// }
// Row dataRow = sheet.getRow(4 + i);
// Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1);
// if (sb.length() > 0) {
// resultCell.setCellValue(sb.toString());
// validateOk = false;
// } else {
// validateOk = true;
// resultCell.setCellValue("Ok");
// }
// sb = new StringBuilder();
// }
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("")) {
String str = validateLength("Họ và tên", rawDataList.get(i)[1].toString(), 1000);
String str = validateLength(BundleUtils.getLangString("customer.fullname", locale).split("#")[0], rawDataList.get(i)[1].toString(), 1000, locale);
if (!str.equals("")) {
sb.append(str);
}
} else sb.append("Họ và tên không được để trống;");
} else sb.append(BundleUtils.getLangString("customer.nameRequired"));
if (rawDataList.get(i).length > 4
&& rawDataList.get(i)[2] != null
&& !rawDataList.get(i)[2].toString().trim().equals("")
......@@ -1063,32 +1019,32 @@ public class CustomerServiceImpl implements CustomerService {
&& !rawDataList.get(i)[3].toString().trim().equals("")
&& rawDataList.get(i)[4] != null
&& !rawDataList.get(i)[4].toString().trim().equals("")) {
String str = validatePhone(rawDataList.get(i)[2].toString().trim());
str.concat(validateLength("Số điện thoại phụ", rawDataList.get(i)[3].toString(), 50));
String str = validatePhone(rawDataList.get(i)[2].toString().trim(), locale);
str.concat(validateLength(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0], rawDataList.get(i)[3].toString(), 50, locale));
if (validateEmail(rawDataList.get(i)[4].toString().trim())) {
str.concat("Email không được quá 50 kí tự");
str.concat(BundleUtils.getLangString("customer.emailMax50", locale));
}
sb.append(str);
} else {
sb.append("Cả 3 thông tin liên lạc không được để trống;");
sb.append(BundleUtils.getLangString("customer.invalidCustomer", locale));
}
if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null) {
sb.append(validateLength("Địa chỉ", rawDataList.get(i)[5].toString(), 500));
sb.append(validateLength(BundleUtils.getLangString("customer.address", locale).split("#")[0], rawDataList.get(i)[5].toString(), 500, locale));
}
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null) {
sb.append(validateLength("Công ty", rawDataList.get(i)[7].toString(), 100));
sb.append(validateLength(BundleUtils.getLangString("customer.companyName", locale).split("#")[0], rawDataList.get(i)[7].toString(), 100, locale));
}
if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null) {
sb.append(validateLength("Ghi chú", rawDataList.get(i)[8].toString(), 2000));
sb.append(validateLength(BundleUtils.getLangString("customer.description", locale).split("#")[0], rawDataList.get(i)[8].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()));
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()));
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()));
sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMin(), header.get(j).getMax(), locale));
}
}
}
......@@ -1110,7 +1066,7 @@ public class CustomerServiceImpl implements CustomerService {
for (int i = 0; i < rawDataList.size(); i++) {
Customer c = new Customer();
c.setName(rawDataList.get(i)[1].toString());
c.setSiteId(companySiteId);
c.setSiteId(userSession.getCompanySiteId());
c.setCode(null);
c.setDescription(rawDataList.get(i)[8].toString());
c.setCompanyName(rawDataList.get(i)[7].toString());
......@@ -1118,7 +1074,7 @@ public class CustomerServiceImpl implements CustomerService {
c.setCreateDate(new Date());
c.setUpdateDate(null);
c.setStatus(1L);
// c.setCreateBy();
c.setCreateBy(userSession.getUserName());
c.setUpdateBy(null);
c.setGender((short) 1);
c.setCurrentAddress(rawDataList.get(i)[5].toString());
......@@ -1129,39 +1085,30 @@ public class CustomerServiceImpl implements CustomerService {
c.setUserName(null);
c.setAreaCode(null);
switch (rawDataList.get(i)[6].toString()) {
case "Thường":
c.setCustomerType(1L);
break;
case "VIP":
c.setCustomerType(2L);
break;
case "Blacklist":
c.setCustomerType(3L);
break;
default:
c.setCustomerType(1L);
break;
}
switch (rawDataList.get(i)[9].toString()) {
case "Có":
if (rawDataList.get(i)[9].toString().equals(BundleUtils.getLangString("customer.yes", locale))) {
c.setCallAllowed(1L);
break;
case "Không":
} else {
c.setCallAllowed(0L);
break;
}
switch (rawDataList.get(i)[10].toString()) {
case "Có":
if (rawDataList.get(i)[10].toString().equals(BundleUtils.getLangString("customer.yes", locale))) {
c.setEmailAllowed(1L);
break;
case "Không":
} else {
c.setEmailAllowed(0L);
break;
}
switch (rawDataList.get(i)[11].toString()) {
case "Có":
if (rawDataList.get(i)[11].toString().equals(BundleUtils.getLangString("customer.yes", locale))) {
c.setSmsAllowed(1L);
break;
case "Không":
} else {
c.setSmsAllowed(0L);
break;
}
c.setIpccStatus("active");
Customer saved = customerRepository.save(c);
......@@ -1176,8 +1123,8 @@ public class CustomerServiceImpl implements CustomerService {
cc.setStatus((short) 1);
cc.setCreateDate(new Date());
cc.setUpdateDate(new Date());
// cc.setCreateBy();
// cc.setUpdateBy();
cc.setCreateBy(userSession.getUserName());
cc.setUpdateBy(userSession.getUserName());
customerContactRepository.save(cc);
}
}
......@@ -1190,8 +1137,8 @@ public class CustomerServiceImpl implements CustomerService {
cc.setStatus((short) 1);
cc.setCreateDate(new Date());
cc.setUpdateDate(new Date());
// cc.setCreateBy();
// cc.setUpdateBy();
cc.setCreateBy(userSession.getUserName());
cc.setUpdateBy(userSession.getUserName());
customerContactRepository.save(cc);
}
}
......@@ -1204,8 +1151,8 @@ public class CustomerServiceImpl implements CustomerService {
cc.setStatus((short) 1);
cc.setCreateDate(new Date());
cc.setUpdateDate(new Date());
// cc.setCreateBy();
// cc.setUpdateBy();
cc.setCreateBy(userSession.getUserName());
cc.setUpdateBy(userSession.getUserName());
customerContactRepository.save(cc);
}
}
......@@ -1221,7 +1168,7 @@ public class CustomerServiceImpl implements CustomerService {
cfo.setFieldOptionValueId(cfov.getFieldOptionValueId());
break;
case "checkbox":
if (rawDataList.get(i)[12 + j].toString().equals("có")) {
if (rawDataList.get(i)[12 + j].toString().equals(BundleUtils.getLangString("customer.yes", locale))) {
cfo.setValueCheckbox(1L);
} else {
cfo.setValueCheckbox(0L);
......@@ -1239,7 +1186,7 @@ public class CustomerServiceImpl implements CustomerService {
break;
}
}
// cfo.setCreateBy();
cfo.setCreateBy(userSession.getUserName());
cfo.setCreateDate(new Date());
cfo.setStatus(1L);
cfo.setFunctionCode("CUSTOMER");
......@@ -1248,62 +1195,62 @@ public class CustomerServiceImpl implements CustomerService {
}
CustomerListMapping clm = new CustomerListMapping();
clm.setCustomerId(saved.getCustomerId());
clm.setCompanySiteId(companySiteId);
// clm.setCustomerListId();
clm.setCompanySiteId(userSession.getCompanySiteId());
clm.setCustomerListId(customerListId);
customerListMappingRepository.save(clm);
}
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", "Import thanh cong");
result.put("message", BundleUtils.getLangString("customer.importSuccess", locale));
} else {
FileOutputStream fos = new FileOutputStream(file);
workbook.write(fos);
result.put("file", file);
result.put("message", "Import du lieu loi");
result.put("message", BundleUtils.getLangString("customer.importFailed", locale));
}
//</editor-fold>
return result;
} catch (Exception e) {
LOGGER.info(e.getMessage());
result.put("message", "Error validate file");
result.put("message", BundleUtils.getLangString("customer.errorValidate", locale));
return result;
}
}
//<editor-fold desc="Validate Methods" defaultstate="collapsed">
private String validatePhone(String str) {
private String validatePhone(String str, Locale locale) {
String result = "";
String[] arr = str.split(";");
if (str.length() > 50) {
result = "Số điện thoại chính không được quá 50 kí tự;";
result = BundleUtils.getLangString("customer.phoneMax50", locale);
}
for (int i = 0; i < str.length(); i++) {
CustomerContact cc = customerContactRepository.findCustomerContactByContactTypeAndContactAndIsDirectLine((short)5, arr[i], (short)1);
if (cc != null) {
return result.concat("Số điện thoại chính đã tồn tại");
return result.concat(BundleUtils.getLangString("customer.phoneExists", locale));
}
}
return result;
}
private String validateUsingRegexp(String header, String data, String regexp) {
private String validateUsingRegexp(String header, String data, String regexp, Locale locale) {
if (data.matches(regexp)) {
return header + " khong dung dinh dang";
}else return "";
return header + " " + BundleUtils.getLangString("customer.notMatch", locale);
} else return "";
}
private String validateLength(String header, String str, int length) {
private String validateLength(String header, String str, int length, Locale locale) {
if (str.trim().length() > length) {
return header + " khong duoc vuot qua " + length + " ki tu;";
return header + " " + BundleUtils.getLangString("customer.notGreaterThan", locale) + " " + length;
}
return "";
}
private String validateDynamicLength(String header, String str, Long min, Long max) {
private String validateDynamicLength(String header, String str, Long min, Long max, Locale locale) {
if (str.trim().length() < min || str.trim().length() > max) {
return header + " khong duoc lon hon " + max + " hoac nho hon " + min;
return header + " " + BundleUtils.getLangString("customer.notGreaterThan", locale) + " " + max + " " + BundleUtils.getLangString("customer.notLessThan", locale) + " " + min;
}
return "";
}
......@@ -1312,11 +1259,17 @@ public class CustomerServiceImpl implements CustomerService {
String regexp = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
return str.matches(regexp);
}
private boolean validateLetter(String str) {
String regexp = "@\"^\\p{L}+$\"";
return str.matches(regexp);
}
//</editor-fold>
@Override
public byte[] buildTemplate(Long companySiteId) {
LOGGER.info("-----------BUILD TEMPLATE-----------");
Locale locale = new Locale("vi", "VN");
try {
XSSFWorkbook workbook = new XSSFWorkbook();
CreationHelper creationHelper = workbook.getCreationHelper();
......@@ -1325,18 +1278,30 @@ public class CustomerServiceImpl implements CustomerService {
//<editor-fold desc="Tạo array header" defaultstate="collapsed">
List<CustomizeFields> header = new ArrayList<>();
header.add(new CustomizeFields("text", "STT"));
header.add(new CustomizeFields("text", "Họ và tên#Bắt buộc\nĐịnh dạng chữ\ntối đa 1000 ký tự"));
header.add(new CustomizeFields("text", "Số điện thoại chính#Định dạng số\ncho phép nhập nhiều số điện thoại chính\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
header.add(new CustomizeFields("text", "Số điện thoại phụ#Định dạng số\ncho phép nhập nhiều số điện thoại phụ\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
header.add(new CustomizeFields("text", "Email chính#Cho phép nhập nhiều email\nmỗi email cách nhau bởi dấu \",\"\ntối đa 100 ký tự"));
header.add(new CustomizeFields("text", "Địa chỉ#Tối đa 500 ký tự"));
header.add(new CustomizeFields("combobox", "Loại khách hàng"));
header.add(new CustomizeFields("text", "Công ty#Tối đa 100 ký tự"));
header.add(new CustomizeFields("text", "Ghi chú#Tối đa 2000 ký tự"));
header.add(new CustomizeFields("combobox", "Cho phép gọi ra"));
header.add(new CustomizeFields("combobox", "Cho phép gửi email"));
header.add(new CustomizeFields("combobox", "Cho phép gửi sms"));
// header.add(new CustomizeFields("text", "STT"));
// header.add(new CustomizeFields("text", "Họ và tên#Bắt buộc\nĐịnh dạng chữ\ntối đa 1000 ký tự"));
// header.add(new CustomizeFields("text", "Số điện thoại chính#Định dạng số\ncho phép nhập nhiều số điện thoại chính\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
// header.add(new CustomizeFields("text", "Số điện thoại phụ#Định dạng số\ncho phép nhập nhiều số điện thoại phụ\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự"));
// header.add(new CustomizeFields("text", "Email chính#Cho phép nhập nhiều email\nmỗi email cách nhau bởi dấu \",\"\ntối đa 100 ký tự"));
// header.add(new CustomizeFields("text", "Địa chỉ#Tối đa 500 ký tự"));
// header.add(new CustomizeFields("combobox", "Loại khách hàng"));
// header.add(new CustomizeFields("text", "Công ty#Tối đa 100 ký tự"));
// header.add(new CustomizeFields("text", "Ghi chú#Tối đa 2000 ký tự"));
// header.add(new CustomizeFields("combobox", "Cho phép gọi ra"));
// header.add(new CustomizeFields("combobox", "Cho phép gửi email"));
// header.add(new CustomizeFields("combobox", "Cho phép gửi sms"));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.no", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.fullname", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.mainPhone", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.secondPhone", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.email", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.address", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.cusType", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.companyName", locale)));
header.add(new CustomizeFields("text", BundleUtils.getLangString("customer.description", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.callAllowed", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.emailAllowed", locale)));
header.add(new CustomizeFields("combobox", BundleUtils.getLangString("customer.smsAllowed", locale)));
List<CustomizeFields> dynamicHeader = getDynamicHeader(companySiteId);
header.addAll(dynamicHeader);
......@@ -1375,7 +1340,7 @@ public class CustomerServiceImpl implements CustomerService {
comboboxValidation.setShowErrorBox(true);
sheet.addValidationData(comboboxValidation);
} else if (dynamicHeader.get(i).getType().equals("checkbox")) {
DataValidationConstraint yesNoConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{"Có", "Không"});
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);
......@@ -1386,8 +1351,8 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold>
//<editor-fold desc="Cho những trường tĩnh" defaultstate="collapsed">
DataValidationConstraint cusTypeConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{"Thường", "VIP", "Blacklist"});
DataValidationConstraint isAllowConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{"Có", "Không"});
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(3, 9999, 6, 6);
CellRangeAddressList callCellRangeAddressList = new CellRangeAddressList(3, 9999, 9, 9);
CellRangeAddressList emailCellRangeAddressList = new CellRangeAddressList(3, 9999, 10, 10);
......@@ -1420,11 +1385,10 @@ public class CustomerServiceImpl implements CustomerService {
Row row3 = sheet.createRow(3);
Cell cell0 = row0.createCell(0);
cell0.setCellStyle(headerStyle);
cell0.setCellValue("IMPORT KHÁCH HÀNG");
cell0.setCellValue(BundleUtils.getLangString("customer.importCustomer", locale));
Cell cell2 = row2.createCell(0);
cell2.setCellStyle(importantStyle);
cell2.setCellValue("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)");
cell2.setCellValue(BundleUtils.getLangString("customer.notice", locale));
for (int i = 0; i < header.size(); i++) {
Cell headerCell = row3.createCell(i);
headerCell.setCellValue(header.get(i).getTitle().split("#")[0]);
......
......@@ -11,6 +11,7 @@ import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import org.apache.commons.io.FilenameUtils;
import org.eclipse.jetty.server.Authentication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -187,11 +188,11 @@ public class CustomerController {
@PostMapping(value = "/importFile")
public ResponseEntity<?> importFile(@RequestParam("file") MultipartFile file,
@RequestParam("companySiteId") Long companySiteId,
@RequestParam("customerListId") Long customerListId,
@RequestHeader("X-Auth-Token") String authToken) {
LOGGER.info("------------IMPORT FILE TEMPLATE--------------");
try {
// UserSession userSession = (UserSession) RedisUtil.getInstance().get(authToken);
UserSession userSession = (UserSession) RedisUtil.getInstance().get(authToken);
if (file.isEmpty()) {
return new ResponseEntity<>("Please select a file", HttpStatus.OK);
}
......@@ -199,8 +200,8 @@ public class CustomerController {
return new ResponseEntity<>("File khong dung dinh dang", HttpStatus.OK);
}
String path = saveUploadFile(file);
List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(companySiteId);
Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, companySiteId);
List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId());
Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, customerListId);
File fileExport = (File) map.get("file");
String message = (String) map.get("message");
return ResponseEntity.ok()
......
......@@ -67,3 +67,38 @@ IPCC_STATUS = IPCC_STATUS
EMAIL = EMAIL
CUSTOMER_TYPE = CUSTOMER_TYPE
AVATAR_LINK = AVATAR_LINK
#Customer Excel Header
customer.no = No
customer.fullname = Full Name#Required\nLetters only\nmaximum 1000 characters
customer.mainPhone = Main mobile phone#Number only\nmultiple numbers allowed\neach seperate by semicolon\nmaximum 50 characters
customer.secondPhone = Secondary phone#Number only\nmultiple numbers allowed\neach seperate by semicolon\nmaximum 50 characters
customer.email = Email#multiple emails allowed\neach seperate by semicolon\nmaximum 100 characters
customer.address = Address#maximum 500 characters
customer.cusType = Customer Type
customer.companyName = Company#maximum 100 characters
customer.description = Description#maximum 2000 characters
customer.callAllowed = Call Allowed
customer.emailAllowed = Email Allowed
customer.smsAllowed = Sms Allowed
customer.result = Result
customer.cusType.normal = Normal
customer.cusType.vip = VIP
customer.cusType.blacklist = Blacklist
customer.yes = Yes
customer.not = No
customer.invalidTemplate = Invalid Template
customer.noData = Template empty
customer.nameRequired = Full name required;
customer.emailMax50 = Email must less than 50 character;
customer.invalidCustomer = All 3 fields Main phone, second phone and email must not null;
customer.importSuccess = Import Successful
customer.importFailed = Import Failed
customer.errorValidate = Error while validating
customer.phoneMax50 = Mobile phone must less than 50 character;
customer.phoneExists = Mobile phone exists;
customer.notMatch = not match regexp validation
customer.notGreaterThan = not greater than
customer.notLessThan = not less than
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
......@@ -69,3 +69,38 @@ IPCC_STATUS = IPCC_STATUS
EMAIL = EMAIL
CUSTOMER_TYPE = CUSTOMER_TYPE
AVATAR_LINK = AVATAR_LINK
#Customer Excel Header
customer.no = STT
customer.fullname = Họ và tên#Bắt buộc\nĐịnh dạng chữ\ntối đa 1000 kí tự
customer.mainPhone = Số điện thoại chính#Định dạng số\ncho phép nhập nhiều số điện thoại chính\ncác số cách nhau bởi dấu chấm phấy\ntối đa 50 ký tự
customer.secondPhone = Số điện thoại phụ#Định dạng số\ncho phép nhập nhiều số điện thoại phụ\ncác số cách nhau bởi dấu chấm phấy hoặc dấu phẩy\ntối đa 50 ký tự
customer.email = Email chính#Cho phép nhập nhiều email\nmỗi email cách nhau bởi dấu \";\"\ntối đa 100 ký tự
customer.address = Địa chỉ#Tối đa 500 ký tự
customer.cusType = Loại khách hàng
customer.companyName = Công ty#Tối đa 100 ký tự
customer.description = Ghi chú#Tối đa 2000 ký tự
customer.callAllowed = Cho phép gọi ra
customer.emailAllowed = Cho phép gửi email
customer.smsAllowed = Cho phép gửi sms
customer.result = Kết quả
customer.cusType.normal = Thường
customer.cusType.vip = VIP
customer.cusType.blacklist = Blacklist
customer.yes =
customer.not = Không
customer.invalidTemplate = Template sai định dạng
customer.noData = Template không có dữ liệu
customer.nameRequired = Họ và tên không được để trống;
customer.emailMax50 = Email không được quá 50 kí tự;
customer.invalidCustomer = Cả 3 thông tin số điện thoại chính, số điện phụ và email không được để trống;
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.phoneMax50 = Số điện thoại không được quá 50 kí tự;
customer.phoneExists = Số điện thoại chính đã tồn tại;
customer.notMatch = không đúng định dạng
customer.notGreaterThan = không được lớn hơn
customer.notLessThan = không được nhỏ hơn
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)
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