Commit a81e76b0 authored by đinh thị đầm's avatar đinh thị đầm

search customer

parent 99ff98b1
...@@ -181,7 +181,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -181,7 +181,7 @@ public class CustomerServiceImpl implements CustomerService {
} }
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort))); Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort)));
if (pageable != null) { if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize()); query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize()); query.setMaxResults(pageable.getPageSize());
} }
...@@ -195,7 +195,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -195,7 +195,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -342,7 +342,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -342,7 +342,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -498,7 +498,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -498,7 +498,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -599,7 +599,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -599,7 +599,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -871,7 +871,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -871,7 +871,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -941,7 +941,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -941,7 +941,7 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) throws IOException{ public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) throws IOException {
LOGGER.info("------------READ AND VALIDATE--------------"); LOGGER.info("------------READ AND VALIDATE--------------");
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
DataFormatter dataFormat = new DataFormatter(); DataFormatter dataFormat = new DataFormatter();
...@@ -1267,7 +1267,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1267,7 +1267,7 @@ public class CustomerServiceImpl implements CustomerService {
LOGGER.info(e.getMessage()); LOGGER.info(e.getMessage());
result.put("message", "validate-error"); result.put("message", "validate-error");
return result; return result;
}finally { } finally {
if (workbook != null) workbook.close(); if (workbook != null) workbook.close();
} }
} }
...@@ -1487,7 +1487,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1487,7 +1487,7 @@ public class CustomerServiceImpl implements CustomerService {
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());
return null; return null;
}finally { } finally {
if (workbook != null) workbook.close(); if (workbook != null) workbook.close();
} }
} }
...@@ -1893,22 +1893,22 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1893,22 +1893,22 @@ public class CustomerServiceImpl implements CustomerService {
Session session = sessionFactory.openSession(); Session session = sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();
Map<String, String> requestCustomer = new HashMap<>(); Map<String, String> requestCustomer = new HashMap<>();
requestCustomer.put("-1" ,"c.code"); requestCustomer.put("-1", "c.code");
requestCustomer.put("-2" ,"c.name"); requestCustomer.put("-2", "c.name");
requestCustomer.put("-3" ,"c.company_name"); requestCustomer.put("-3", "c.company_name");
requestCustomer.put("-4" ,"c.gender"); requestCustomer.put("-4", "c.gender");
requestCustomer.put("-5" ,"c.current_address"); requestCustomer.put("-5", "c.current_address");
requestCustomer.put("-6" ,"c.place_of_birth"); requestCustomer.put("-6", "c.place_of_birth");
requestCustomer.put("-7" ,"c.date_of_birth"); requestCustomer.put("-7", "c.date_of_birth");
requestCustomer.put("-8" ,"cc.contact"); requestCustomer.put("-8", "cc.contact");
requestCustomer.put("-9" ,"cc2.contact"); requestCustomer.put("-9", "cc2.contact");
requestCustomer.put("-10" ,"c.username"); requestCustomer.put("-10", "c.username");
requestCustomer.put("-11" ,"c.area_code"); requestCustomer.put("-11", "c.area_code");
requestCustomer.put("-12" ,"c.customer_type"); requestCustomer.put("-12", "c.customer_type");
requestCustomer.put("-13" ,"c.call_allowed"); requestCustomer.put("-13", "c.call_allowed");
requestCustomer.put("-14" ,"c.email_allowed"); requestCustomer.put("-14", "c.email_allowed");
requestCustomer.put("-15" ,"c.sms_allowed"); requestCustomer.put("-15", "c.sms_allowed");
requestCustomer.put("-16" ,"c.ipcc_status"); requestCustomer.put("-16", "c.ipcc_status");
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
...@@ -1920,42 +1920,78 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1920,42 +1920,78 @@ public class CustomerServiceImpl implements CustomerService {
sb.append(" c.customer_type customerType,"); sb.append(" c.customer_type customerType,");
sb.append(" C.COMPANY_NAME companyName,"); sb.append(" C.COMPANY_NAME companyName,");
sb.append(" c.current_address currentAddress,"); sb.append(" c.current_address currentAddress,");
sb.append(" c.Description description,"); sb.append(" c.Description description");
sb.append(" FROM CUSTOMER C"); sb.append(" FROM CUSTOMER C");
sb.append(" INNER JOIN CUSTOMER_contact cc ON (C.CUSTOMER_ID = Cc.customer_id " + sb.append(" INNER JOIN CUSTOMER_contact cc ON (C.CUSTOMER_ID = Cc.customer_id " +
"and cc.status = 1 and cc.contact_type = 5)"); "and cc.status = 1 and cc.contact_type = 5)");
sb.append(" INNER JOIN CUSTOMER_contact Cc2 ON (C.CUSTOMER_ID = Cc2.customer_id and cc2.status = 1 and cc2.contact_type = 2)" + sb.append(" INNER JOIN CUSTOMER_contact Cc2 ON (C.CUSTOMER_ID = Cc2.customer_id and cc2.status = 1 and cc2.contact_type = 2)");
" WHERE ");
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(" 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) ");
List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery(); List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery();
if (customerDTOList.get(0).getField() > 0) { if (customerDTOList.get(0).getField() > 0) {
switch (customerDTOList.get(0).getType()) { switch (customerDTOList.get(0).getType()) {
case "combobox": case "combobox":
sb.append("and (cfo.customize_field_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":
sb.append("and (cfo.customize_field_id ="+customerDTOList.get(0).getField()+" and cfo.value_text"+customerDTOList.get(0).getOperator()+""+customerDTOList.get(0).getCondition()+")"); 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() + "%')");
} else {
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
}
break; break;
case "date": case "date":
sb.append("and (cfo.customize_field_id ="+customerDTOList.get(0).getField()+" and cfo.value_date"+customerDTOList.get(0).getOperator()+""+customerDTOList.get(0).getCondition()+")"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_date " + customerDTOList.get(0).getOperator() + " to_date(" + customerDTOList.get(0).getCondition() + ", 'DD/MM/YYYY'))");
break; break;
case "number": case "number":
sb.append("and (cfo.customize_field_id ="+customerDTOList.get(0).getField()+" and cfo.value_number"+customerDTOList.get(0).getOperator()+""+customerDTOList.get(0).getCondition()+")"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_number " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
break; break;
case "checkbox": case "checkbox":
sb.append("and (cfo.customize_field_id ="+customerDTOList.get(0).getField()+" and cfo.value_checkbox"+customerDTOList.get(0).getOperator()+""+customerDTOList.get(0).getCondition()+")"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_checkbox " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
break; break;
}} else { }
sb.append("and "+requestCustomer.get(customerDTOList.get(0).getField())+""+customerDTOList.get(0).getOperator()+""+customerDTOList.get(0).getCondition()); } else {
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() + "%')");
} else {
sb.append("and " + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition());
}
} }
for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) { for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) {
sb.append(" " + customerDTOList.get(i).getJoin() + " " if (customerDTOList.get(i).getField() < 0) {
+ requestCustomer.get(customerDTOList.get(i).getField()) + " " if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) {
+ 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() + "%')");
+ customerDTOList.get(i).getCondition() + " "); sb.append(" " + customerDTOList.get(i).getJoin() + " "
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " "
+ "'%"+customerDTOList.get(i).getCondition() + "%' ");
} else {
sb.append(" " + customerDTOList.get(i).getJoin() + " "
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " "
+ customerDTOList.get(i).getCondition() + " ");
}
} else {
switch (customerDTOList.get(i).getType()) {
case "combobox":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.field_option_value_id " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
case "text":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " %'" + customerDTOList.get(i).getCondition() + "%')");
break;
case "date":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_date " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
case "number":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_number " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
case "checkbox":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_checkbox " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
}
}
// for (CustomerQueryDTO query : customerDTOList) { // for (CustomerQueryDTO query : customerDTOList) {
...@@ -2043,6 +2079,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2043,6 +2079,8 @@ public class CustomerServiceImpl implements CustomerService {
query.addScalar("currentAddress", new StringType()); query.addScalar("currentAddress", new StringType());
query.addScalar("description", new StringType()); query.addScalar("description", new StringType());
query.setParameter("p_campaign_id", campaignCustomerDTO.getCampaignId());
query.setResultTransformer(Transformers.aliasToBean(CampaignCustomerDTO.class)); query.setResultTransformer(Transformers.aliasToBean(CampaignCustomerDTO.class));
int count = 0; int count = 0;
......
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