Commit 21d7b924 authored by ='s avatar =

hungtt-commit fix bug search individual customer

parent ac82f96a
...@@ -800,74 +800,74 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -800,74 +800,74 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
// StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-customer-list-choosen"); // String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-customer-list-choosen");
String sql = "with campaign_customer_id as (\n" + sb.append(" with campaign_customer_id as (");
" select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl\n" + sb.append(" select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl");
" where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id\n" + sb.append(" where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id");
"),\n" + sb.append(" ),");
"customer_table as (\n" + sb.append(" customer_table as (");
" select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a\n" + sb.append(" select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a");
" left join customer b on a.customer_id = b.customer_id\n" + sb.append(" left join customer b on a.customer_id = b.customer_id");
" where b.status = 1\n" + sb.append(" where b.status = 1");
" group by a.customer_list_id\n" + sb.append(" group by a.customer_list_id");
"),\n" + sb.append(" ),");
"customer_active_table as (\n" + sb.append(" customer_active_table as (");
" select count(a.customer_id) customerActive, a.customer_list_id customerListId from customer_list_mapping a\n" + sb.append(" select count(a.customer_id) customerActive, a.customer_list_id customerListId from customer_list_mapping a");
" left join customer b on a.customer_id = b.customer_id\n" + sb.append(" left join customer b on a.customer_id = b.customer_id");
" where b.status = 1 and b.ipcc_status = 'active'\n" + sb.append(" where b.status = 1 and b.ipcc_status = 'active'");
" group by a.customer_list_id\n" + sb.append(" group by a.customer_list_id");
"),\n" + sb.append(" ),");
"customer_lock_table as (\n" + sb.append(" customer_lock_table as (");
" select count(a.customer_id) customerLock, a.customer_list_id customerListId from customer_list_mapping a\n" + sb.append(" select count(a.customer_id) customerLock, a.customer_list_id customerListId from customer_list_mapping a");
" left join customer b on a.customer_id = b.customer_id\n" + sb.append(" left join customer b on a.customer_id = b.customer_id");
" where b.status = 1 and b.ipcc_status = 'locked'\n" + sb.append(" where b.status = 1 and b.ipcc_status = 'locked'");
" group by a.customer_list_id\n" + sb.append(" group by a.customer_list_id");
"),\n" + sb.append(" ),");
"customer_dnc_table as (\n" + sb.append(" customer_dnc_table as (");
" select count(a.customer_id) customerDnc, a.customer_list_id customerListId from customer_list_mapping a\n" + sb.append(" select count(a.customer_id) customerDnc, a.customer_list_id customerListId from customer_list_mapping a");
" left join customer b on a.customer_id = b.customer_id\n" + sb.append(" left join customer b on a.customer_id = b.customer_id");
" where b.status = 1 and b.call_allowed = 0\n" + sb.append(" where b.status = 1 and b.call_allowed = 0");
" group by a.customer_list_id\n" + sb.append(" group by a.customer_list_id");
"),\n" + sb.append(" ),");
"customer_filter_table as (\n" + sb.append(" customer_filter_table as (");
" select count(a.customer_id) customerFilter, a.customer_list_id customerListId from campaign_customer a\n" + sb.append(" select count(a.customer_id) customerFilter, a.customer_list_id customerListId from campaign_customer a");
" where a.campaign_id = :p_campaign_id and a.in_campaign_status = 1\n" + sb.append(" where a.campaign_id = :p_campaign_id and a.in_campaign_status = 1");
" group by a.customer_list_id\n" + sb.append(" group by a.customer_list_id");
"),\n" + sb.append(" ),");
"data_temp as (\n" + sb.append(" data_temp as (");
"select a.customer_list_id customerListId,\n" + sb.append(" select a.customer_list_id customerListId,");
" a.customer_list_code customerListCode,\n" + sb.append(" a.customer_list_code customerListCode,");
" a.customer_list_name customerListName,\n" + sb.append(" a.customer_list_name customerListName,");
" nvl(b.totalCustomer, 0) totalCusList,\n" + sb.append(" nvl(b.totalCustomer, 0) totalCusList,");
" nvl(c.customerActive, 0) totalCusActive,\n" + sb.append(" nvl(c.customerActive, 0) totalCusActive,");
" nvl(d.customerLock, 0) totalCusLock,\n" + sb.append(" nvl(d.customerLock, 0) totalCusLock,");
" nvl(e.customerDnc, 0) totalCusDnc,\n" + sb.append(" nvl(e.customerDnc, 0) totalCusDnc,");
" nvl(null, 0) totalCusAddRemove,\n" + sb.append(" nvl(null, 0) totalCusAddRemove,");
" nvl(f.customerFilter, 0) totalCusFilter\n" + sb.append(" nvl(f.customerFilter, 0) totalCusFilter");
"from customer_list a\n" + sb.append(" from customer_list a");
"left join customer_table b on a.customer_list_id = b.customerListId\n" + sb.append(" left join customer_table b on a.customer_list_id = b.customerListId");
"left join customer_active_table c on a.customer_list_id = c.customerListId\n" + sb.append(" left join customer_active_table c on a.customer_list_id = c.customerListId");
"left join customer_lock_table d on a.customer_list_id = d.customerListId\n" + sb.append(" left join customer_lock_table d on a.customer_list_id = d.customerListId");
"left join customer_dnc_table e on a.customer_list_id = e.customerListId\n" + sb.append(" left join customer_dnc_table e on a.customer_list_id = e.customerListId");
"left join customer_filter_table f on a.customer_list_id = f.customerListId\n" + sb.append(" left join customer_filter_table f on a.customer_list_id = f.customerListId");
"where a.customer_list_id in (select CUSTOMER_LIST_ID from campaign_customer_id)\n" + sb.append(" where a.customer_list_id in (select CUSTOMER_LIST_ID from campaign_customer_id)");
"),\n" + sb.append(" ),");
"data as (\n" + sb.append(" data as (");
"select a.*, rownum row_ from data_temp a\n" + sb.append(" select a.*, rownum row_ from data_temp a");
"),\n" + sb.append(" ),");
"count_data as (\n" + sb.append(" count_data as (");
"select count(*) totalRow from data_temp\n" + sb.append(" select count(*) totalRow from data_temp");
")\n" + sb.append(" )");
"select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusActive, a.totalCusLock, a.totalCusDnc, a.totalCusAddRemove, a.totalCusFilter, totalRow from data a, count_data\n" + sb.append(" select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusActive, a.totalCusLock, a.totalCusDnc, a.totalCusAddRemove, a.totalCusFilter, totalRow from data a, count_data");
"where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)\n" + sb.append(" where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)");
"order by a.customerListName"; sb.append(" order by a.customerListName");
params.put("p_campaign_id", dto.getCampaignId()); params.put("p_campaign_id", dto.getCampaignId());
params.put("p_company_site_id", dto.getCompanySiteId()); params.put("p_company_site_id", dto.getCompanySiteId());
params.put("p_page_number", dto.getPage().toString()); params.put("p_page_number", dto.getPage().toString());
params.put("p_page_size", dto.getPageSize().toString()); params.put("p_page_size", dto.getPageSize().toString());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(CustomerListDTO.class)); list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CustomerListDTO.class));
int total = 0; int total = 0;
if (list.size() > 0) { if (list.size() > 0) {
total = list.get(0).getTotalRow(); total = list.get(0).getTotalRow();
......
...@@ -1924,8 +1924,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1924,8 +1924,8 @@ public class CustomerServiceImpl implements CustomerService {
{"-5", "Địa chỉ", "text"}, {"-5", "Địa chỉ", "text"},
{"-6", "Nơi sinh", "text"}, {"-6", "Nơi sinh", "text"},
{"-7", "Ngày sinh", "date"}, {"-7", "Ngày sinh", "date"},
{"-8", "Số điện thoại", "number"}, {"-8", "Số điện thoại", "text"},
{"-9", "email", "text"}, {"-9", "Email", "text"},
{"-10", "Tên đăng nhập", "text"}, {"-10", "Tên đăng nhập", "text"},
{"-11", "Loại Khách hàng", "combobox"}, {"-11", "Loại Khách hàng", "combobox"},
}; };
...@@ -1978,7 +1978,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1978,7 +1978,7 @@ public class CustomerServiceImpl implements CustomerService {
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("select c.customer_id customerId,"); sb.append("select distinct c.customer_id customerId,");
sb.append(" C.NAME name,"); sb.append(" C.NAME name,");
sb.append(" cc.CONTACT mobileNumber,"); sb.append(" cc.CONTACT mobileNumber,");
sb.append(" cc2.CONTACT email,"); sb.append(" cc2.CONTACT email,");
...@@ -2001,18 +2001,19 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2001,18 +2001,19 @@ public class CustomerServiceImpl implements CustomerService {
sb.append("inner join customize_field_object cfo on c.customer_id = cfo.object_id and cfo.status = 1"); sb.append("inner join customize_field_object cfo on c.customer_id = cfo.object_id and cfo.status = 1");
sb.append(" AND C.STATUS = 1"); sb.append(" AND C.STATUS = 1");
sb.append(" AND C.customer_id not in (select customer_id from campaign_customer where campaign_id = :p_campaign_id) "); sb.append(" AND C.customer_id not in (select customer_id from campaign_customer where campaign_id = :p_campaign_id) ");
sb.append(" where 1 = 1 ");
List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery(); List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery();
if (customerDTOList.get(0).getField() > 0) {// field dong if (customerDTOList.get(0).getField() > 0) {// field dong
switch (customerDTOList.get(0).getType()) { switch (customerDTOList.get(0).getType()) {
case "combobox": case "combobox":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.field_option_value_id " + customerDTOList.get(0).getOperator() + "" + customerDTOList.get(0).getCondition() + ")"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.field_option_value_id " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
break; break;
case "text": case "text":
if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) { if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim() + "%')"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%')");
} else { } else {
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim() + "')"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "')");
} }
break; break;
case "date": case "date":
...@@ -2027,7 +2028,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2027,7 +2028,9 @@ public class CustomerServiceImpl implements CustomerService {
} }
} else {// field tinh } else {// field tinh
if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) { if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition() + "%')"); sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%')");
} else if (customerDTOList.get(0).getField() == -8 || customerDTOList.get(0).getField() == -9) {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + ("=".equals(customerDTOList.get(0).getOperator()) ? "like " : "not like") + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%')");
} else { } else {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")"); sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
} }
...@@ -2036,15 +2039,20 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2036,15 +2039,20 @@ public class CustomerServiceImpl implements CustomerService {
if (customerDTOList.get(i).getField() < 0) { if (customerDTOList.get(i).getField() < 0) {
if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) { if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) {
// sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " '%" + customerDTOList.get(i).getCondition() + "%')"); // sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " '%" + customerDTOList.get(i).getCondition() + "%')");
sb.append(" " + customerDTOList.get(i).getJoin() + " " sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " " + requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getOperator() + " "
+ "'%" + customerDTOList.get(i).getCondition().trim() + "%' "); + "'%" + customerDTOList.get(i).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%' )");
} else if (customerDTOList.get(i).getField() == -8 || customerDTOList.get(i).getField() == -9) {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ ("=".equals(customerDTOList.get(i).getOperator()) ? "like" : "not like") + " '%"
+ customerDTOList.get(i).getCondition().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%' )");
} else { } else {
sb.append(" " + customerDTOList.get(i).getJoin() + " " sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " " + requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getOperator() + " "
+ customerDTOList.get(i).getCondition() + " "); + customerDTOList.get(i).getCondition() + " )");
} }
} else { } else {
switch (customerDTOList.get(i).getType()) { switch (customerDTOList.get(i).getType()) {
...@@ -2053,9 +2061,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2053,9 +2061,9 @@ public class CustomerServiceImpl implements CustomerService {
break; break;
case "text": case "text":
if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) { if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) {
sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim() + "%')"); sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%')");
} else { } else {
sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim() + "')"); sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "')");
} }
// sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " %'" + customerDTOList.get(i).getCondition() + "%')"); // sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " %'" + customerDTOList.get(i).getCondition() + "%')");
break; break;
......
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