Commit 19b464e1 authored by Tu Bach's avatar Tu Bach

Merge branch 'master' into tubn

parents 888819be 085e1809
...@@ -49,8 +49,8 @@ ...@@ -49,8 +49,8 @@
<dependency> <dependency>
<groupId>com.oracle</groupId> <groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId> <artifactId>ojdbc7</artifactId>
<!-- <scope>system</scope>--> <scope>system</scope>
<!-- <systemPath>${project.basedir}/lib/ojdbc7.jar</systemPath>--> <systemPath>${project.basedir}/lib/ojdbc7.jar</systemPath>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -5,15 +5,18 @@ import lombok.Setter; ...@@ -5,15 +5,18 @@ import lombok.Setter;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
@Entity @Entity
@Table(name = "CUSTOMER_CONTACT") @Table(name = "CUSTOMER_CONTACT")
@Getter @Getter
@Setter @Setter
public class CustomerContact { public class CustomerContact implements Serializable {
@Id @Id
@Basic(optional = false) @Basic(optional = false)
@GeneratedValue(generator = "customer_contact_seq", strategy = GenerationType.IDENTITY)
@SequenceGenerator(name = "customer_contact_seq", sequenceName = "customer_contact_seq", allocationSize = 1)
@NotNull @NotNull
@Column(name = "CONTACT_ID") @Column(name = "CONTACT_ID")
private Long contactId; private Long contactId;
......
package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignCustomerListColumn;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
@Transactional(DataSourceQualify.CCMS_FULL)
public interface CampaignCustomerListColumnRepository extends JpaRepository<CampaignCustomerListColumn, Long> {
List<CampaignCustomerListColumn> findByCampaignIdAndCompanySiteId(Long campaignId, Long companaySiteId);
CampaignCustomerListColumn findByCampaignCusListColId(Long campaignCusListColId);
}
...@@ -12,5 +12,5 @@ public interface CustomerContactRepository extends JpaRepository<CustomerContact ...@@ -12,5 +12,5 @@ public interface CustomerContactRepository extends JpaRepository<CustomerContact
@Query("FROM CustomerContact WHERE status = 1 AND customerId = :customerId AND contactType = :contactType AND (contact IS NULL OR UPPER(contact) LIKE UPPER(concat('%', :contact, '%')))") @Query("FROM CustomerContact WHERE status = 1 AND customerId = :customerId AND contactType = :contactType AND (contact IS NULL OR UPPER(contact) LIKE UPPER(concat('%', :contact, '%')))")
List<CustomerContact> findByCustomerIdAndAndContactTypeAndContact(@Param("customerId") Long customerId, @Param("contactType") Short contactType, @Param("contact") String contact, Pageable pageable); List<CustomerContact> findByCustomerIdAndAndContactTypeAndContact(@Param("customerId") Long customerId, @Param("contactType") Short contactType, @Param("contact") String contact, Pageable pageable);
CustomerContact findCustomerContactByContactTypeAndContactAndIsDirectLine(Short contactType, String contact, Short isDirectLine); CustomerContact findCustomerContactByContactEquals(String contact);
} }
...@@ -511,23 +511,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -511,23 +511,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
try { try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-not-show"); // String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-not-show");
stringBuilder.append(" with column_name_temp as ("); String sql = "with column_name_temp as (\n" +
stringBuilder.append(" select column_name columnName, 1 isFix from user_tab_columns, dual"); " select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual\n" +
stringBuilder.append(" where table_name = 'CUSTOMER'"); " where table_name = 'CUSTOMER'\n" +
stringBuilder.append(" )"); ")\n" +
stringBuilder.append(" select * from column_name_temp"); "select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)\n" +
stringBuilder.append(" where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)"); "union all\n" +
stringBuilder.append(" union all"); "select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual\n" +
stringBuilder.append(" select title columnName, 0 isFix "); "where function_code = 'CUSTOMER'\n" +
stringBuilder.append(" from customize_fields, dual"); " and site_id = :p_company_site_id\n" +
stringBuilder.append(" where function_code = 'CUSTOMER'"); " and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id)\n";
stringBuilder.append(" and site_id = :p_company_site_id");
stringBuilder.append(" and customize_field_id not in (select customize_field_id");
stringBuilder.append(" from campaign_customerlist_column");
stringBuilder.append(" where campaign_customerlist_column.campaign_id = :p_campaign_id)");
params.put("p_company_site_id", dto.getCompanySiteId()); params.put("p_company_site_id", dto.getCompanySiteId());
params.put("p_campaign_id", dto.getCampaignId()); params.put("p_campaign_id", dto.getCampaignId());
list = namedParameterJdbcTemplate.query(stringBuilder.toString(), params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class)); list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(list); resultDTO.setListData(list);
...@@ -548,15 +544,22 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -548,15 +544,22 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
StringBuilder sqlBuilder = new StringBuilder(); StringBuilder sqlBuilder = new StringBuilder();
try { try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-to-show"); // String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-to-show");
sqlBuilder.append(" select to_char(column_name) columnName, 1 isFix"); String sql = "with field_name as (\n" +
sqlBuilder.append(" from campaign_customerlist_column, dual"); "select a.campaign_cus_list_column_id id, to_char(a.column_name) columnName, a.order_index, a.customize_field_id customizeFieldId, 1 isFix\n" +
sqlBuilder.append(" where campaign_id = :p_campaign_id and column_name is not null"); "from campaign_customerlist_column a, dual\n" +
sqlBuilder.append(" union all"); "where a.campaign_id = :p_campaign_id\n" +
sqlBuilder.append(" select customize_field_title columnName, 0 isFix"); " and a.company_site_id = :p_company_site_id\n" +
sqlBuilder.append(" from campaign_customerlist_column"); " and column_name is not null\n" +
sqlBuilder.append(" where campaign_id = :p_campaign_id"); "union all\n" +
"select a.campaign_cus_list_column_id id, a.customize_field_title columnName, a.order_index, a.customize_field_id customizeFieldId, 0 isFix\n" +
"from campaign_customerlist_column a\n" +
"where a.campaign_id = :p_campaign_id\n" +
" and a.company_site_id = :p_company_site_id\n" +
")\n" +
"select id, columnName, customizeFieldId, isFix from field_name where columnName is not null order by order_index\n";
params.put("p_campaign_id", dto.getCampaignId()); params.put("p_campaign_id", dto.getCampaignId());
list = namedParameterJdbcTemplate.query(sqlBuilder.toString(), params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class)); params.put("p_company_site_id", dto.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(list); resultDTO.setListData(list);
......
...@@ -64,6 +64,8 @@ public interface CampaignService { ...@@ -64,6 +64,8 @@ public interface CampaignService {
ResultDTO addCustomerListToCampaign(CampaignRequestDTO dto); ResultDTO addCustomerListToCampaign(CampaignRequestDTO dto);
ResultDTO deleteCustomerListFromCampaign(CampaignRequestDTO dto); ResultDTO deleteCustomerListFromCampaign(CampaignRequestDTO dto);
ResultDTO saveFieldCustomer(CampaignRequestDTO dto);
//</editor-fold> //</editor-fold>
} }
...@@ -33,7 +33,7 @@ public interface CustomerService { ...@@ -33,7 +33,7 @@ public interface CustomerService {
ResultDTO getAllCustomerList(int page, int pageSize, String sort, Long companySiteId); ResultDTO getAllCustomerList(int page, int pageSize, String sort, Long companySiteId);
ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName); CustomerList createCustomerList(CustomerListDTO customerListDTO, String userName);
ResultDTO updateCustomerList(CustomerListDTO customerListDTO); ResultDTO updateCustomerList(CustomerListDTO customerListDTO);
......
...@@ -67,6 +67,9 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -67,6 +67,9 @@ public class CampaignServiceImpl implements CampaignService {
@Autowired @Autowired
CampaignCustomerRepository campaignCustomerRepository; CampaignCustomerRepository campaignCustomerRepository;
@Autowired
CampaignCustomerListColumnRepository campaignCustomerListColumnRepository;
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO search(CampaignRequestDTO requestDto) { public ResultDTO search(CampaignRequestDTO requestDto) {
...@@ -370,6 +373,7 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -370,6 +373,7 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO; return resultDTO;
} }
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO updateCampaign(CampaignDTO dto) { public ResultDTO updateCampaign(CampaignDTO dto) {
...@@ -561,6 +565,54 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -561,6 +565,54 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO; return resultDTO;
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO saveFieldCustomer(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
List<FieldsToShowDTO> list = dto.getLstFiedCustomer();
long campaignId = Long.parseLong(dto.getCampaignId());
long companySiteId = Long.parseLong(dto.getCompanySiteId());
List<CampaignCustomerListColumn> listColumns = campaignCustomerListColumnRepository.findByCampaignIdAndCompanySiteId(campaignId, companySiteId);
try {
// Them moi cac truong hien thi
for (FieldsToShowDTO fieldsToShowDTO : list) {
if (fieldsToShowDTO.getId() == null) {
CampaignCustomerListColumn entity = new CampaignCustomerListColumn();
entity.setCampaignId(campaignId);
entity.setCompanySiteId(companySiteId);
if (fieldsToShowDTO.getIsFix()) {
entity.setColumnName(fieldsToShowDTO.getColumnName());
} else {
entity.setCustomizeFieldId(fieldsToShowDTO.getCustomizeFieldId());
entity.setCustomizeFieldTitle(fieldsToShowDTO.getColumnTitle());
}
entity.setOrderIndex((long) (list.indexOf(fieldsToShowDTO) + 1));
campaignCustomerListColumnRepository.save(entity);
}
}
// Cap nhat cac truong da co san
for (FieldsToShowDTO fieldsToShowDTO : list) {
if (fieldsToShowDTO.getId() != null) {
listColumns.removeIf(p -> p.getCampaignCusListColId() == fieldsToShowDTO.getId());
CampaignCustomerListColumn entity = campaignCustomerListColumnRepository.findByCampaignCusListColId(fieldsToShowDTO.getId());
entity.setOrderIndex((long) (list.indexOf(fieldsToShowDTO) + 1));
campaignCustomerListColumnRepository.save(entity);
}
}
// Xoa cac truong khong con hien thi nua
for (CampaignCustomerListColumn entity : listColumns) {
campaignCustomerListColumnRepository.delete(entity);
}
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
logger.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
return resultDTO;
}
// hungtt // hungtt
private Map<String, String> setMapData(Map<String, String> mapColumn, Locale locale) { private Map<String, String> setMapData(Map<String, String> mapColumn, Locale locale) {
mapColumn.put("CUSTOMER_ID", BundleUtils.getLangString("CUSTOMER_ID", locale)); mapColumn.put("CUSTOMER_ID", BundleUtils.getLangString("CUSTOMER_ID", locale));
......
...@@ -50,7 +50,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -50,7 +50,7 @@ public class CustomerServiceImpl implements CustomerService {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class);
@Autowired @Autowired
@PersistenceContext( unitName= DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL) @PersistenceContext(unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
EntityManager entityManager; EntityManager entityManager;
@Autowired @Autowired
...@@ -595,37 +595,30 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -595,37 +595,30 @@ public class CustomerServiceImpl implements CustomerService {
} }
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) public CustomerList createCustomerList(CustomerListDTO customerListDTO, String userName) {
public ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName) { LOGGER.info("-----------CREATE CUSTOMER LIST--------------");
ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
CustomerList customerList = new CustomerList();
try { try {
if (customerListDTO != null) { CustomerList cl = customerListRepository.findByCustomerListCode(customerListDTO.getCustomerListCode());
// insert if (cl == null) {
CustomerList findCustomer = customerListRepository.findByCustomerListCode(customerListDTO.getCustomerListCode()); cl = new CustomerList();
if (findCustomer == null) { cl.setCustomerListCode(customerListDTO.getCustomerListCode());
customerListDTO.setCreateBy(userName); cl.setCustomerListName(customerListDTO.getCustomerListName());
cl.setStatus((short) 1);
customerList = customerListMapper.toPersistenceBean(customerListDTO); cl.setCreateBy(userName);
customerListRepository.save(customerList); cl.setCreateAt(new Date());
cl.setUpdateBy(null);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); cl.setUpdateAt(null);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); cl.setSource(null);
} else { cl.setDeptCreate(null);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); cl.setCompanySiteId(customerListDTO.getCompanySiteId());
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); return customerListRepository.save(cl);
}
} else { } else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); return null;
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOGGER.error(e.getMessage());
return null;
} }
return resultDTO;
} }
@Override @Override
...@@ -894,7 +887,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -894,7 +887,8 @@ public class CustomerServiceImpl implements CustomerService {
public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) { public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) {
LOGGER.info("------------READ AND VALIDATE--------------"); LOGGER.info("------------READ AND VALIDATE--------------");
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); DataFormatter dataFormat = new DataFormatter();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
boolean validateOk = false; boolean validateOk = false;
...@@ -970,14 +964,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -970,14 +964,7 @@ public class CustomerServiceImpl implements CustomerService {
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) { for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
Cell dataCell = dataRow.getCell(j); Cell dataCell = dataRow.getCell(j);
if (dataCell != null) { if (dataCell != null) {
switch (dataCell.getCellTypeEnum()) { obj[j] = dataFormat.formatCellValue(dataCell);
case NUMERIC:
obj[j] = dataCell.getNumericCellValue();
break;
default:
obj[j] = dataCell.getStringCellValue();
break;
}
} else { } else {
Cell headerCell = row.getCell(j); Cell headerCell = row.getCell(j);
if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.cusType", locale))) { if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.cusType", locale))) {
...@@ -1014,9 +1001,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1014,9 +1001,12 @@ public class CustomerServiceImpl implements CustomerService {
&& !rawDataList.get(i)[4].toString().trim().equals("")) { && !rawDataList.get(i)[4].toString().trim().equals("")) {
String str = validatePhone(rawDataList.get(i)[2].toString().trim(), locale); 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)); 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())) { if (!validateEmail(rawDataList.get(i)[4].toString().trim())) {
str.concat(BundleUtils.getLangString("customer.emailMax50", locale)); str.concat(BundleUtils.getLangString("customer.emailInvalid", locale));
} else {
str.concat(validateDuplicateEmail(rawDataList.get(i)[4].toString().trim(), locale));
} }
sb.append(validateLength(BundleUtils.getLangString("customer.email", locale).split("#")[0], rawDataList.get(i)[4].toString(), 50, locale));
sb.append(str); sb.append(str);
} else { } else {
sb.append(BundleUtils.getLangString("customer.invalidCustomer", locale)); sb.append(BundleUtils.getLangString("customer.invalidCustomer", locale));
...@@ -1030,17 +1020,17 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1030,17 +1020,17 @@ public class CustomerServiceImpl implements CustomerService {
if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null) { if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.description", locale).split("#")[0], rawDataList.get(i)[8].toString(), 2000, locale)); 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++) { // 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) {
if (header.get(j).getType().equals("text")) { // 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)); // 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")) { // } 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)); // 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")) { // } 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)); // sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMin(), header.get(j).getMax(), locale));
} // }
} // }
} // }
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) {
...@@ -1105,11 +1095,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1105,11 +1095,12 @@ public class CustomerServiceImpl implements CustomerService {
} }
c.setIpccStatus("active"); c.setIpccStatus("active");
Customer saved = customerRepository.save(c); Customer saved = customerRepository.save(c);
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
if (rawDataList.get(i).length > 2 && rawDataList.get(i)[2] != null) { if (rawDataList.get(i).length > 2 && rawDataList.get(i)[2] != null) {
String[] mainPhone = rawDataList.get(i)[2].toString().split(";"); String[] mainPhone = rawDataList.get(i)[2].toString().split(";");
for (int j = 0; j < mainPhone.length; j++) { for (int j = 0; j < mainPhone.length; j++) {
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
cc.setSiteId(userSession.getSiteId());
cc.setContactType((short) 5); cc.setContactType((short) 5);
cc.setContact(mainPhone[j]); cc.setContact(mainPhone[j]);
cc.setIsDirectLine((short) 1); cc.setIsDirectLine((short) 1);
...@@ -1124,6 +1115,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1124,6 +1115,9 @@ public class CustomerServiceImpl implements CustomerService {
if (rawDataList.get(i).length > 3 && rawDataList.get(i)[3] != null) { if (rawDataList.get(i).length > 3 && rawDataList.get(i)[3] != null) {
String[] subPhone = rawDataList.get(i)[3].toString().split(";"); String[] subPhone = rawDataList.get(i)[3].toString().split(";");
for (int j = 0; j < subPhone.length; j++) { for (int j = 0; j < subPhone.length; j++) {
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
cc.setSiteId(userSession.getSiteId());
cc.setContactType((short) 5); cc.setContactType((short) 5);
cc.setContact(subPhone[j]); cc.setContact(subPhone[j]);
cc.setIsDirectLine((short) 0); cc.setIsDirectLine((short) 0);
...@@ -1136,8 +1130,11 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1136,8 +1130,11 @@ public class CustomerServiceImpl implements CustomerService {
} }
} }
if (rawDataList.get(i).length > 4 && rawDataList.get(i)[4] != null) { if (rawDataList.get(i).length > 4 && rawDataList.get(i)[4] != null) {
String[] email = rawDataList.get(i)[3].toString().split(";"); String[] email = rawDataList.get(i)[4].toString().split(";");
for (int j = 0; j < email.length; j++) { for (int j = 0; j < email.length; j++) {
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
cc.setSiteId(userSession.getSiteId());
cc.setContactType((short) 2); cc.setContactType((short) 2);
cc.setContact(email[j]); cc.setContact(email[j]);
cc.setIsDirectLine((short) 1); cc.setIsDirectLine((short) 1);
...@@ -1154,11 +1151,11 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1154,11 +1151,11 @@ public class CustomerServiceImpl implements CustomerService {
for (int j = 0; j < dynamicHeader.size(); j++) { for (int j = 0; j < dynamicHeader.size(); j++) {
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 > (12 + j) && rawDataList.get(i)[12 + j] != null) {
switch (dynamicHeader.get(i).getType()) { switch (dynamicHeader.get(j).getType()) {
case "combobox": case "combobox":
CustomizeFieldOptionValue cfov = CustomizeFieldOptionValue cfov =
customizeFieldOptionValueRepository.findCustomizeFieldOptionValueByNameEqualsAndStatus(rawDataList.get(i)[12 + j].toString(), 1L); customizeFieldOptionValueRepository.findCustomizeFieldOptionValueByNameEqualsAndStatus(rawDataList.get(i)[12 + j].toString(), 1L);
cfo.setFieldOptionValueId(cfov.getFieldOptionValueId()); cfo.setFieldOptionValueId(cfov.getFieldOptionValueId());
break; break;
case "checkbox": case "checkbox":
if (rawDataList.get(i)[12 + j].toString().equals(BundleUtils.getLangString("customer.yes", locale))) { if (rawDataList.get(i)[12 + j].toString().equals(BundleUtils.getLangString("customer.yes", locale))) {
...@@ -1219,8 +1216,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1219,8 +1216,8 @@ public class CustomerServiceImpl implements CustomerService {
if (str.length() > 50) { if (str.length() > 50) {
result = BundleUtils.getLangString("customer.phoneMax50", locale); result = BundleUtils.getLangString("customer.phoneMax50", locale);
} }
for (int i = 0; i < str.length(); i++) { for (int i = 0; i < arr.length; i++) {
CustomerContact cc = customerContactRepository.findCustomerContactByContactTypeAndContactAndIsDirectLine((short)5, arr[i], (short)1); CustomerContact cc = customerContactRepository.findCustomerContactByContactEquals(arr[i]);
if (cc != null) { if (cc != null) {
return result.concat(BundleUtils.getLangString("customer.phoneExists", locale)); return result.concat(BundleUtils.getLangString("customer.phoneExists", locale));
} }
...@@ -1228,6 +1225,18 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1228,6 +1225,18 @@ public class CustomerServiceImpl implements CustomerService {
return result; return result;
} }
private String validateDuplicateEmail(String str, Locale locale) {
String result = "";
String[] arr = str.split(";");
for (int i = 0; i < arr.length; i++) {
CustomerContact cc = customerContactRepository.findCustomerContactByContactEquals(arr[i]);
if (cc != null) {
return result.concat(BundleUtils.getLangString("customer.emailExists", locale));
}
}
return result;
}
private String validateUsingRegexp(String header, String data, String regexp, Locale locale) { private String validateUsingRegexp(String header, String data, String regexp, Locale locale) {
if (data.matches(regexp)) { if (data.matches(regexp)) {
return header + " " + BundleUtils.getLangString("customer.notMatch", locale); return header + " " + BundleUtils.getLangString("customer.notMatch", locale);
...@@ -1249,8 +1258,14 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1249,8 +1258,14 @@ public class CustomerServiceImpl implements CustomerService {
} }
private boolean validateEmail(String str) { private boolean validateEmail(String str) {
String[] arr = str.split(";");
String regexp = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$"; String regexp = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
return str.matches(regexp); for (int i = 0; i < arr.length; i++) {
if (!arr[i].matches(regexp)) {
return false;
}
}
return true;
} }
private boolean validateLetter(String str) { private boolean validateLetter(String str) {
...@@ -1315,14 +1330,14 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1315,14 +1330,14 @@ public class CustomerServiceImpl implements CustomerService {
constraint[j] = list.get(j).getName(); constraint[j] = list.get(j).getName();
} }
DataValidationConstraint comboboxConstraint = dataValidationHelper.createExplicitListConstraint(constraint); DataValidationConstraint comboboxConstraint = dataValidationHelper.createExplicitListConstraint(constraint);
CellRangeAddressList comboboxCellRange = new CellRangeAddressList(4,9999,12 + i, 12 + i); CellRangeAddressList comboboxCellRange = new CellRangeAddressList(4, 9999, 12 + i, 12 + i);
DataValidation comboboxValidation = dataValidationHelper.createValidation(comboboxConstraint,comboboxCellRange); DataValidation comboboxValidation = dataValidationHelper.createValidation(comboboxConstraint, comboboxCellRange);
comboboxValidation.setSuppressDropDownArrow(true); comboboxValidation.setSuppressDropDownArrow(true);
comboboxValidation.setShowErrorBox(true); comboboxValidation.setShowErrorBox(true);
sheet.addValidationData(comboboxValidation); sheet.addValidationData(comboboxValidation);
} else if (dynamicHeader.get(i).getType().equals("checkbox")) { } else if (dynamicHeader.get(i).getType().equals("checkbox")) {
DataValidationConstraint yesNoConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{BundleUtils.getLangString("customer.yes", locale), BundleUtils.getLangString("customer.not", locale)}); 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); CellRangeAddressList checkboxCellRange = new CellRangeAddressList(4, 9999, 12 + i, 12 + i);
DataValidation yesNoValidation = dataValidationHelper.createValidation(yesNoConstraint, checkboxCellRange); DataValidation yesNoValidation = dataValidationHelper.createValidation(yesNoConstraint, checkboxCellRange);
yesNoValidation.setShowErrorBox(true); yesNoValidation.setShowErrorBox(true);
yesNoValidation.setSuppressDropDownArrow(true); yesNoValidation.setSuppressDropDownArrow(true);
......
...@@ -13,21 +13,13 @@ import java.io.Serializable; ...@@ -13,21 +13,13 @@ import java.io.Serializable;
@AllArgsConstructor @AllArgsConstructor
public class FieldsToShowDTO implements Serializable { public class FieldsToShowDTO implements Serializable {
// private Long campaignCusListColId; private Long id;
// private Long companySiteId;
// private Long campaignId;
private String columnName; private String columnName;
private String columnTitle; private String columnTitle;
// private Long orderIndex;
// private Long customizeFieldId;
// private String customizeFieldTitle;
private Boolean isFix; private Boolean isFix;
private Long customizeFieldId;
} }
...@@ -2,6 +2,7 @@ package com.viettel.campaign.web.dto.request_dto; ...@@ -2,6 +2,7 @@ package com.viettel.campaign.web.dto.request_dto;
import com.viettel.campaign.web.dto.BaseDTO; import com.viettel.campaign.web.dto.BaseDTO;
import com.viettel.campaign.web.dto.CustomerCustomDTO; import com.viettel.campaign.web.dto.CustomerCustomDTO;
import com.viettel.campaign.web.dto.FieldsToShowDTO;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -51,5 +52,5 @@ public class CampaignRequestDTO extends BaseDTO { ...@@ -51,5 +52,5 @@ public class CampaignRequestDTO extends BaseDTO {
String createTimeTo; String createTimeTo;
String createTimeFr; String createTimeFr;
String lstCustomerListId; String lstCustomerListId;
List<FieldsToShowDTO> lstFiedCustomer;
} }
...@@ -298,6 +298,13 @@ public class CampaignController { ...@@ -298,6 +298,13 @@ public class CampaignController {
return new ResponseEntity<>(resultDTO, HttpStatus.OK); return new ResponseEntity<>(resultDTO, HttpStatus.OK);
} }
@PostMapping("/saveFieldCustomer")
@ResponseBody
public ResponseEntity saveFieldCustomer(@RequestBody CampaignRequestDTO campaignRequestDTO) {
ResultDTO resultDTO = campaignService.saveFieldCustomer(campaignRequestDTO);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@RequestMapping(value = "/renewCampaign", method = RequestMethod.PUT) @RequestMapping(value = "/renewCampaign", method = RequestMethod.PUT)
public ResponseEntity<ResultDTO> renewCampaign(@RequestBody CampaignDTO campaignDTO) { public ResponseEntity<ResultDTO> renewCampaign(@RequestBody CampaignDTO campaignDTO) {
ResultDTO result = campaignService.renewCampaign(campaignDTO); ResultDTO result = campaignService.renewCampaign(campaignDTO);
......
package com.viettel.campaign.web.rest; package com.viettel.campaign.web.rest;
import com.viettel.campaign.model.ccms_full.CustomerList;
import com.viettel.campaign.model.ccms_full.CustomizeFieldObject; import com.viettel.campaign.model.ccms_full.CustomizeFieldObject;
import com.viettel.campaign.model.ccms_full.CustomizeFields; import com.viettel.campaign.model.ccms_full.CustomizeFields;
import com.viettel.campaign.service.CustomerService; import com.viettel.campaign.service.CustomerService;
...@@ -103,15 +104,15 @@ public class CustomerController { ...@@ -103,15 +104,15 @@ public class CustomerController {
} }
@PostMapping("/createCustomerList") @PostMapping("/createCustomerList")
@ResponseBody public ResponseEntity<?> createCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO, HttpServletRequest request) {
public ResultDTO createCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO, HttpServletRequest request) {
ResultDTO result = new ResultDTO();
String xAuthToken = request.getHeader("X-Auth-Token"); String xAuthToken = request.getHeader("X-Auth-Token");
UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken); UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
result = customerService.createCustomerList(customerListDTO, userSession.getUserName()); CustomerList cl = customerService.createCustomerList(customerListDTO, userSession.getUserName());
return result; if (cl == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(cl, HttpStatus.OK);
} }
@PostMapping("/updateCustomerList") @PostMapping("/updateCustomerList")
...@@ -185,11 +186,11 @@ public class CustomerController { ...@@ -185,11 +186,11 @@ public class CustomerController {
@PostMapping(value = "/importFile") @PostMapping(value = "/importFile")
public ResponseEntity<?> importFile(@RequestParam("file") MultipartFile file, public ResponseEntity<?> importFile(@RequestParam("file") MultipartFile file,
@RequestParam("customerListId") Long customerListId, @RequestParam("customerListId") Long customerListId,
@RequestHeader("X-Auth-Token") String authToken) { HttpServletRequest request) {
LOGGER.info("------------IMPORT FILE TEMPLATE--------------"); LOGGER.info("------------IMPORT FILE TEMPLATE--------------");
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
try { try {
UserSession userSession = (UserSession) RedisUtil.getInstance().get(authToken); UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token"));
if (file.isEmpty()) { if (file.isEmpty()) {
return new ResponseEntity<>(BundleUtils.getLangString("customer.fileNotSelected"), HttpStatus.OK); return new ResponseEntity<>(BundleUtils.getLangString("customer.fileNotSelected"), HttpStatus.OK);
} }
......
...@@ -103,6 +103,8 @@ customer.notLessThan = not less than ...@@ -103,6 +103,8 @@ customer.notLessThan = not less than
customer.importCustomer = IMPORT CUSTOMER 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.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.fileNotSelected=Please select a file customer.fileNotSelected=Please select a file
customer.emailInvalid=Invalid email;
customer.emailExists=Email exists;
common.fileNotSelected=Please select a file common.fileNotSelected=Please select a file
common.fileInvalidFormat=File invalid common.fileInvalidFormat=File invalid
...@@ -105,6 +105,8 @@ customer.notLessThan = không được nhỏ hơn ...@@ -105,6 +105,8 @@ customer.notLessThan = không được nhỏ hơn
customer.importCustomer = IMPORT KHÁCH HÀNG 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.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.fileNotSelected=Bạn chưa chọn file customer.fileNotSelected=Bạn chưa chọn file
customer.emailInvalid=Email không đúng định dạng;
customer.emailExists=Email đã tồn tại;
common.fileNotSelected=Bạn chưa chọn file common.fileNotSelected=Bạn chưa chọn file
common.fileInvalidFormat=File không hợp lệ common.fileInvalidFormat=File không hợp lệ
with column_name_temp as ( with column_name_temp as (
select column_name columnName, 1 isFix from user_tab_columns, dual select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual
where table_name = 'CUSTOMER' where table_name = 'CUSTOMER'
) )
select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null) select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)
union all union all
select title columnName, 0 isFix from customize_fields, dual select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual
where function_code = 'CUSTOMER' where function_code = 'CUSTOMER'
and site_id = :p_company_site_id and site_id = :p_company_site_id
and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id) and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id)
select to_char(column_name) columnName, 1 isFix from campaign_customerlist_column, dual where campaign_id = :p_campaign_id and column_name is not null with field_name as (
select a.campaign_cus_list_column_id id, to_char(a.column_name) columnName, a.order_index, a.customize_field_id customizeFieldId, 1 isFix
from campaign_customerlist_column a, dual
where a.campaign_id = :p_campaign_id
and a.company_site_id = :p_company_site_id
and column_name is not null
union all union all
select customize_field_title columnName, 0 isFix from campaign_customerlist_column where campaign_id = :p_campaign_id select a.campaign_cus_list_column_id id, a.customize_field_title columnName, a.order_index, a.customize_field_id customizeFieldId, 0 isFix
from campaign_customerlist_column a
where a.campaign_id = :p_campaign_id
and a.company_site_id = :p_company_site_id
)
select id, columnName, customizeFieldId, isFix from field_name where columnName is not null order by order_index
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