Commit 53925bbf authored by Tu Bach's avatar Tu Bach

Merge branch 'master' of https://git.myitsol.com/hanv/service-campaign

# Conflicts:
#	src/main/java/com/viettel/campaign/repository/ccms_full/CampaignCustomerRepository.java
parents 43b6327c 21d7b924
...@@ -69,7 +69,7 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom ...@@ -69,7 +69,7 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
List<CampaignCustomer> findCustomerNoContact(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId, @Param("customerListId") Long customerListId); List<CampaignCustomer> findCustomerNoContact(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId, @Param("customerListId") Long customerListId);
@Query(value = "SELECT * FROM CAMPAIGN_CUSTOMER CC " + @Query(value = "SELECT * FROM CAMPAIGN_CUSTOMER CC " +
"WHERE CC.STATUS IN (SELECT COMPLETE_VALUE from CAMPAIGN_COMPLETE_CODE where STATUS = 1 and IS_FINISH = 0 and IS_RECALL = 0)" + "WHERE CC.STATUS IN (SELECT COMPLETE_VALUE from CAMPAIGN_COMPLETE_CODE where STATUS = 1 and COMPLETE_TYPE=1)" +
"AND CC.CAMPAIGN_ID = :campaignId " + "AND CC.CAMPAIGN_ID = :campaignId " +
"AND CC.COMPANY_SITE_ID = :companySiteId " + "AND CC.COMPANY_SITE_ID = :companySiteId " +
"AND CC.CUSTOMER_LIST_ID = :customerListId", nativeQuery = true) "AND CC.CUSTOMER_LIST_ID = :customerListId", nativeQuery = true)
...@@ -88,6 +88,6 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom ...@@ -88,6 +88,6 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
" and (status = 0 or status in (select * from status_customer))", nativeQuery = true) " and (status = 0 or status in (select * from status_customer))", nativeQuery = true)
List<CampaignCustomer> findListCustomerToDel(@Param("p_company_site_id") Long companySiteId, @Param("p_campaign_id") Long campaignId, @Param("p_cus_list_id") Long customerListId); List<CampaignCustomer> findListCustomerToDel(@Param("p_company_site_id") Long companySiteId, @Param("p_campaign_id") Long campaignId, @Param("p_cus_list_id") Long customerListId);
@Query(value = "SELECT COMPLETE_VALUE FROM CAMPAIGN_COMPLETE_CODE WHERE STATUS = 1 AND IS_FINISH = 0 AND IS_RECALL = 0", nativeQuery = true) @Query(value = "select complete_value from campaign_complete_code where status = 1 and complete_type = 1", nativeQuery = true)
List<Short> getStatus(); List<Short> getStatus();
} }
...@@ -37,6 +37,8 @@ public interface CampaignRepositoryCustom { ...@@ -37,6 +37,8 @@ public interface CampaignRepositoryCustom {
ResultDTO getCustomerListInformation(CampaignRequestDTO dto); ResultDTO getCustomerListInformation(CampaignRequestDTO dto);
ResultDTO getCountIndividualOnList(CampaignRequestDTO dto);
List<ApParamDTO> getConnectStatus(Long companySiteId); List<ApParamDTO> getConnectStatus(Long companySiteId);
//</editor-fold> //</editor-fold>
} }
...@@ -40,7 +40,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -40,7 +40,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
private static final Logger logger = LogManager.getLogger(CampaignRepositoryImpl.class); private static final Logger logger = LogManager.getLogger(CampaignRepositoryImpl.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
...@@ -121,7 +121,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -121,7 +121,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" AND a.STATUS <> -1"); sb.append(" AND a.STATUS <> -1");
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode()) && !DataUtil.isNullOrEmpty(requestDto.getCampaignCode().trim())) {
sb.append(" AND a.CAMPAIGN_CODE IN (:p_code) "); sb.append(" AND a.CAMPAIGN_CODE IN (:p_code) ");
} }
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) {
...@@ -164,7 +164,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -164,7 +164,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" ORDER BY a.CREATE_TIME DESC "); sb.append(" ORDER BY a.CREATE_TIME DESC ");
SQLQuery query = session.createSQLQuery(sb.toString()); SQLQuery query = session.createSQLQuery(sb.toString());
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignCode()) && !DataUtil.isNullOrEmpty(requestDto.getCampaignCode().trim())) {
String[] lstCode = requestDto.getCampaignCode().trim().split(","); String[] lstCode = requestDto.getCampaignCode().trim().split(",");
query.setParameterList("p_code", lstCode); query.setParameterList("p_code", lstCode);
} }
...@@ -260,7 +260,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -260,7 +260,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
logger.error(ex.getMessage(), ex); logger.error(ex.getMessage(), ex);
} finally { } finally {
if(null != session) { if (null != session) {
session.close(); session.close();
} }
} }
...@@ -350,7 +350,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -350,7 +350,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return result; return result;
} }
...@@ -381,8 +381,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -381,8 +381,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
} }
} catch (Exception ex) { } catch (Exception ex) {
logger.error(ex.getMessage(), ex); logger.error(ex.getMessage(), ex);
}finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return null; return null;
} }
...@@ -514,7 +514,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -514,7 +514,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
List<CustomerCustomDTO> list = dto.getCustomerCustomDTOList(); List<CustomerCustomDTO> list = dto.getCustomerCustomDTOList();
for (CustomerCustomDTO customerCustomDTO: list) { for (CustomerCustomDTO customerCustomDTO : list) {
CampaignCustomer campaignCustomer = campaignCustomerRepository.findCampaignCustomerByCampaignCustomerId(customerCustomDTO.getCampaignCustomerId()); CampaignCustomer campaignCustomer = campaignCustomerRepository.findCampaignCustomerByCampaignCustomerId(customerCustomDTO.getCampaignCustomerId());
campaignCustomer.setStatus((short) 0); campaignCustomer.setStatus((short) 0);
campaignCustomer.setCallStatus(null); campaignCustomer.setCallStatus(null);
...@@ -605,8 +605,6 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -605,8 +605,6 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
List<CustomerListDTO> list = new ArrayList(); List<CustomerListDTO> list = new ArrayList();
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
// StringBuilder sb = new StringBuilder();
try { try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-campaign-customer"); // String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-campaign-customer");
String sql = "with campaign_customer_id as (\n" + String sql = "with campaign_customer_id as (\n" +
...@@ -626,7 +624,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -626,7 +624,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
"),\n" + "),\n" +
"customer_interactive_table as (\n" + "customer_interactive_table as (\n" +
" select count(a.customer_id) campaignCustomerCalled, a.customer_list_id customerListId, a.campaign_id from campaign_customer a\n" + " select count(a.customer_id) campaignCustomerCalled, a.customer_list_id customerListId, a.campaign_id from campaign_customer a\n" +
" where a.status <> 0 and a.campaign_id = :p_campaign_id and in_campaign_status = 1\n" + " where a.status <> 0 and a.campaign_id = :p_campaign_id\n" +
" group by a.customer_list_id, a.campaign_id\n" + " group by a.customer_list_id, a.campaign_id\n" +
"),\n" + "),\n" +
"customer_not_interactive_table as (\n" + "customer_not_interactive_table as (\n" +
...@@ -657,7 +655,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -657,7 +655,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
"select count(*) totalRow from data\n" + "select count(*) totalRow from data\n" +
")\n" + ")\n" +
"select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusCampaign, a.totalCusCalled, a.totalCusNotInteract, totalRow from data a, count_data\n" + "select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusCampaign, a.totalCusCalled, a.totalCusNotInteract, totalRow from data a, count_data\n" +
"where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)\n"; "where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)\n" +
"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());
...@@ -740,8 +739,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -740,8 +739,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" where a.status = 1"); sb.append(" where a.status = 1");
sb.append(" and (:p_cus_list_code is null or upper(a.customer_list_code) like '%'||:p_cus_list_code||'%')"); sb.append(" and (:p_cus_list_code is null or upper(a.customer_list_code) like '%'||:p_cus_list_code||'%')");
sb.append(" and (:p_cus_list_name is null or upper(a.customer_list_name) like '%'||:p_cus_list_name||'%')"); sb.append(" and (:p_cus_list_name is null or upper(a.customer_list_name) like '%'||:p_cus_list_name||'%')");
sb.append(" and (:p_to_date is null or (a.create_at <= to_date(:p_to_date, 'DD/MM/YYYY')))"); sb.append(" and (:p_to_date is null or ((a.create_at + :p_time_zone_offset/24) <= to_date(:p_to_date, 'DD/MM/YYYY')))");
sb.append(" and (:p_from_date is null or (a.create_at >= to_date(:p_from_date, 'DD/MM/YYYY')))"); sb.append(" and (:p_from_date is null or ((a.create_at + :p_time_zone_offset/24) >= to_date(:p_from_date, 'DD/MM/YYYY')))");
sb.append(" and (a.company_site_id = :p_company_site_id)"); sb.append(" and (a.company_site_id = :p_company_site_id)");
sb.append(" and (a.customer_list_id not in (select CUSTOMER_LIST_ID from campaign_customer_id))"); sb.append(" and (a.customer_list_id not in (select CUSTOMER_LIST_ID from campaign_customer_id))");
sb.append(" ),"); sb.append(" ),");
...@@ -762,6 +761,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -762,6 +761,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
query.setParameter("p_from_date", DataUtil.isNullOrEmpty(dto.getCreateTimeFr()) ? null : dto.getCreateTimeFr()); query.setParameter("p_from_date", DataUtil.isNullOrEmpty(dto.getCreateTimeFr()) ? null : dto.getCreateTimeFr());
query.setParameter("p_page_number", dto.getPage()); query.setParameter("p_page_number", dto.getPage());
query.setParameter("p_page_size", dto.getPageSize()); query.setParameter("p_page_size", dto.getPageSize());
query.setParameter("p_time_zone_offset", dto.getTimezoneOffset());
query.addScalar("customerListId", new LongType()); query.addScalar("customerListId", new LongType());
query.addScalar("customerListCode", new StringType()); query.addScalar("customerListCode", new StringType());
...@@ -800,73 +800,74 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -800,73 +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\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)");
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();
...@@ -884,7 +885,6 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -884,7 +885,6 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
} }
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCampaignCustomerInformation(CampaignRequestDTO dto) { public ResultDTO getCampaignCustomerInformation(CampaignRequestDTO dto) {
...@@ -893,12 +893,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -893,12 +893,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
// sb.append(" with status_customer as (");
// sb.append(" select complete_value");
// sb.append(" from campaign_complete_code");
// sb.append(" where complete_value <> 4");
// sb.append(" and is_finish <> 1");
// sb.append(" and campaign_type = 1");
// sb.append(" and company_site_id = :p_company_site_id");
// sb.append(" ),");
sb.append(" with status_customer as ("); sb.append(" with status_customer as (");
sb.append(" select complete_value"); sb.append(" select complete_value");
sb.append(" from campaign_complete_code"); sb.append(" from campaign_complete_code");
sb.append(" where complete_value <> 4"); sb.append(" where status = 1");
sb.append(" and is_finish <> 1"); sb.append(" and complete_type = 1");
sb.append(" and campaign_type = 1");
sb.append(" and company_site_id = :p_company_site_id"); sb.append(" and company_site_id = :p_company_site_id");
sb.append(" ),"); sb.append(" ),");
sb.append(" count_customer as ("); sb.append(" count_customer as (");
...@@ -908,11 +915,11 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -908,11 +915,11 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" else 0"); sb.append(" else 0");
sb.append(" end) totalIndividual,"); sb.append(" end) totalIndividual,");
sb.append(" sum(case"); sb.append(" sum(case");
sb.append(" when status = 0 then 1"); sb.append(" when status = 0 and in_campaign_status = 1 then 1");
sb.append(" else 0"); sb.append(" else 0");
sb.append(" end) totalNotInteractive,"); sb.append(" end) totalNotInteractive,");
sb.append(" sum(case"); sb.append(" sum(case");
sb.append(" when status in (select * from status_customer) then 1"); sb.append(" when status in (select * from status_customer) and in_campaign_status = 1 then 1");
sb.append(" else 0"); sb.append(" else 0");
sb.append(" end) totalNotCall,"); sb.append(" end) totalNotCall,");
sb.append(" sum(case"); sb.append(" sum(case");
...@@ -951,12 +958,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -951,12 +958,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
try { try {
// sb.append(" with status_customer as (");
// sb.append(" select complete_value");
// sb.append(" from campaign_complete_code");
// sb.append(" where complete_value <> 4");
// sb.append(" and is_finish <> 1");
// sb.append(" and campaign_type = 1");
// sb.append(" and company_site_id = :p_company_site_id");
// sb.append(" ),");
sb.append(" with status_customer as ("); sb.append(" with status_customer as (");
sb.append(" select complete_value"); sb.append(" select complete_value");
sb.append(" from campaign_complete_code"); sb.append(" from campaign_complete_code");
sb.append(" where complete_value <> 4"); sb.append(" where status =1");
sb.append(" and is_finish <> 1"); sb.append(" and complete_type = 1");
sb.append(" and campaign_type = 1");
sb.append(" and company_site_id = :p_company_site_id"); sb.append(" and company_site_id = :p_company_site_id");
sb.append(" ),"); sb.append(" ),");
sb.append(" count_customer as ("); sb.append(" count_customer as (");
...@@ -967,11 +981,11 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -967,11 +981,11 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" else 0"); sb.append(" else 0");
sb.append(" end) totalIndividual,"); sb.append(" end) totalIndividual,");
sb.append(" sum(case"); sb.append(" sum(case");
sb.append(" when status = 0 then 1"); sb.append(" when status = 0 and in_campaign_status = 1 then 1");
sb.append(" else 0"); sb.append(" else 0");
sb.append(" end) totalNotInteractive,"); sb.append(" end) totalNotInteractive,");
sb.append(" sum(case"); sb.append(" sum(case");
sb.append(" when status in (select * from status_customer) then 1"); sb.append(" when status in (select * from status_customer) and in_campaign_status = 1 then 1");
sb.append(" else 0"); sb.append(" else 0");
sb.append(" end) totalNotCall"); sb.append(" end) totalNotCall");
sb.append(" from campaign_customer"); sb.append(" from campaign_customer");
...@@ -996,6 +1010,42 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -996,6 +1010,42 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
return resultDTO; return resultDTO;
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCountIndividualOnList(CampaignRequestDTO dto) {
List<CampaignInformationDTO> list = new ArrayList();
ResultDTO resultDTO = new ResultDTO();
Map<String, String> params = new HashMap<>();
StringBuilder sb = new StringBuilder();
try {
sb.append(" with customer_temp as (");
sb.append(" select c.customer_id, clm.customer_list_id");
sb.append(" from customer c");
sb.append(" inner join customer_list_mapping clm on c.customer_id = clm.customer_id");
sb.append(" where clm.customer_list_id in (select distinct cc.customer_list_id from campaign_customerlist cc where cc.campaign_id = :p_campaign_id and cc.company_site_id = :p_company_site_id)");
sb.append(" )");
sb.append(" select count(cc.customer_id) totalIndividual, c.customer_list_id customerListId");
sb.append(" from campaign_customer cc");
sb.append(" inner join customer_temp c on c.customer_id = cc.customer_id");
sb.append(" where campaign_id = :p_campaign_id");
sb.append(" and cc.customer_list_id is null");
sb.append(" and cc.in_campaign_status = 1");
sb.append(" and cc.customer_id in (select customer_id from customer_temp)");
sb.append(" group by c.customer_list_id");
params.put("p_campaign_id", dto.getCampaignId());
params.put("p_company_site_id", dto.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CampaignInformationDTO.class));
resultDTO.setListData(list);
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;
}
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public List<ApParamDTO> getConnectStatus(Long companySiteId) { public List<ApParamDTO> getConnectStatus(Long companySiteId) {
......
...@@ -12,7 +12,7 @@ public interface CampaignCfgService { ...@@ -12,7 +12,7 @@ public interface CampaignCfgService {
Map listCompleteCodeByName(int page, int pageSize, String sort, String name); Map listCompleteCodeByName(int page, int pageSize, String sort, String name);
ResultDTO createCompleteCode(CampaignCfgDTO completeCodeDTO); ResultDTO createCompleteCode(CampaignCfgDTO completeCodeDTO, Long userId);
ResultDTO updateCompleteCode(CampaignCfgDTO completeCodeDTO); ResultDTO updateCompleteCode(CampaignCfgDTO completeCodeDTO);
......
...@@ -70,6 +70,8 @@ public interface CampaignService { ...@@ -70,6 +70,8 @@ public interface CampaignService {
ResultDTO getCustomerListInformation(CampaignRequestDTO dto); ResultDTO getCustomerListInformation(CampaignRequestDTO dto);
ResultDTO getCountIndividualOnList(CampaignRequestDTO dto);
ResultDTO saveCustomerCampaign(CampaignRequestDTO dto); ResultDTO saveCustomerCampaign(CampaignRequestDTO dto);
ResultDTO getConnectStatus(Long companySiteId); ResultDTO getConnectStatus(Long companySiteId);
......
...@@ -5,6 +5,7 @@ import com.viettel.campaign.mapper.CampaignCompleteCodeMapper; ...@@ -5,6 +5,7 @@ import com.viettel.campaign.mapper.CampaignCompleteCodeMapper;
import com.viettel.campaign.model.ccms_full.CampaignCfg; import com.viettel.campaign.model.ccms_full.CampaignCfg;
import com.viettel.campaign.repository.ccms_full.CampaignCfgRepository; import com.viettel.campaign.repository.ccms_full.CampaignCfgRepository;
import com.viettel.campaign.repository.ccms_full.CampaignRepository;
import com.viettel.campaign.service.CampaignCfgService; import com.viettel.campaign.service.CampaignCfgService;
import com.viettel.campaign.utils.Constants; import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.DataUtil; import com.viettel.campaign.utils.DataUtil;
...@@ -157,7 +158,7 @@ public class CampaignCfgServiceImpl implements CampaignCfgService { ...@@ -157,7 +158,7 @@ public class CampaignCfgServiceImpl implements CampaignCfgService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO createCompleteCode(CampaignCfgDTO completeCodeDTO) { public ResultDTO createCompleteCode(CampaignCfgDTO completeCodeDTO, Long userId) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
CampaignCompleteCodeMapper compCodeMapper = new CampaignCompleteCodeMapper(); CampaignCompleteCodeMapper compCodeMapper = new CampaignCompleteCodeMapper();
Date today = new Date(); Date today = new Date();
...@@ -165,12 +166,37 @@ public class CampaignCfgServiceImpl implements CampaignCfgService { ...@@ -165,12 +166,37 @@ public class CampaignCfgServiceImpl implements CampaignCfgService {
try { try {
if (completeCodeDTO != null) { if (completeCodeDTO != null) {
// insert // insert
compCode = compCodeMapper.toPersistenceBean(completeCodeDTO); // compCode = compCodeMapper.toPersistenceBean(completeCodeDTO);
compCode = completeCodeRepository.save(compCode); // compCode = completeCodeRepository.save(compCode);
//
// resultDTO.setErrorCode("0");
// resultDTO.setDescription("Complete Code: " + compCode.getCampaignCompleteCodeId() + " created!");
CampaignCfg cl = new CampaignCfg();
cl.setStatus((short) 1);
cl.setCreateBy(String.valueOf(userId));
cl.setCreateAt(new Date());
cl.setUpdateBy(null);
cl.setUpdateAt(null);
cl.setChanel(completeCodeDTO.getChanel());
cl.setCompleteName(completeCodeDTO.getCompleteName().trim());
cl.setCompleteValue(completeCodeDTO.getCompleteValue());
cl.setCampaignType(completeCodeDTO.getCampaignType());
cl.setDescription(completeCodeDTO.getDescription().trim());
cl.setCompleteType(completeCodeDTO.getCompleteType());
cl.setCompanySiteId(completeCodeDTO.getCompanySiteId());
cl.setCampaignCompleteCodeId(completeCodeDTO.getCampaignCompleteCodeId());
cl.setCampaignId(completeCodeDTO.getCampaignId());
cl.setDurationLock(completeCodeDTO.getDurationLock());
cl.setIsFinish(completeCodeDTO.getIsFinish());
cl.setIsLock(completeCodeDTO.getIsLock());
cl.setIsRecall(completeCodeDTO.getIsRecall());
resultDTO.setErrorCode("0"); resultDTO.setErrorCode("0");
resultDTO.setDescription("Complete Code: " + compCode.getCampaignCompleteCodeId() + " created!"); resultDTO.setDescription("Complete Code: " + compCode.getCampaignCompleteCodeId() + " created!");
resultDTO.setData(completeCodeRepository.save(cl));
return resultDTO;
} else { } else {
resultDTO.setErrorCode("-2"); resultDTO.setErrorCode("-2");
resultDTO.setDescription("CompleteCodeDTO null"); resultDTO.setDescription("CompleteCodeDTO null");
......
...@@ -627,6 +627,12 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -627,6 +627,12 @@ public class CampaignServiceImpl implements CampaignService {
return campaignRepositoryCustom.getCustomerListInformation(dto); return campaignRepositoryCustom.getCustomerListInformation(dto);
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCountIndividualOnList(CampaignRequestDTO dto) {
return campaignRepositoryCustom.getCountIndividualOnList(dto);
}
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO saveCustomerCampaign(CampaignRequestDTO dto) { public ResultDTO saveCustomerCampaign(CampaignRequestDTO dto) {
...@@ -668,7 +674,12 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -668,7 +674,12 @@ public class CampaignServiceImpl implements CampaignService {
// Lay ra danh sach khach hang can loai bo // Lay ra danh sach khach hang can loai bo
List<CampaignCustomer> listCustomerToDelete = campaignCustomerRepository.findListCustomerToDel(companySiteId, campaignId, customerListDTO.getCustomerListId()); List<CampaignCustomer> listCustomerToDelete = campaignCustomerRepository.findListCustomerToDel(companySiteId, campaignId, customerListDTO.getCustomerListId());
for (int j = 0; j < custToDel; j++) { for (int j = 0; j < custToDel; j++) {
campaignCustomerRepository.delete(listCustomerToDelete.get(j)); if (listCustomerToDelete.get(j).getStatus() == 0) {
campaignCustomerRepository.delete(listCustomerToDelete.get(j));
} else {
listCustomerToDelete.get(j).setInCampaignStatus((short) 0);
campaignCustomerRepository.save(listCustomerToDelete.get(j));
}
} }
} }
} }
......
...@@ -51,11 +51,15 @@ import java.nio.file.Files; ...@@ -51,11 +51,15 @@ import java.nio.file.Files;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service @Service
public class CustomerServiceImpl implements CustomerService { public class CustomerServiceImpl implements CustomerService {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class); private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class);
// private static final Pattern EMAIL_REGEXP = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
private static final Pattern EMAIL_REGEXP = Pattern.compile("^(.+)@(.+)$", Pattern.CASE_INSENSITIVE);
@Autowired @Autowired
@PersistenceContext(unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL) @PersistenceContext(unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
...@@ -950,6 +954,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -950,6 +954,7 @@ public class CustomerServiceImpl implements CustomerService {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int failedCount = 0; int failedCount = 0;
XSSFWorkbook workbook = null; XSSFWorkbook workbook = null;
boolean isMainPhoneNull = false, isSecondPhoneNull = false, isEmailNull = false;
try { try {
//<editor-fold desc="Khởi tạo mảng header tĩnh" defaultstate="collapsed"> //<editor-fold desc="Khởi tạo mảng header tĩnh" defaultstate="collapsed">
...@@ -991,12 +996,18 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -991,12 +996,18 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold> //</editor-fold>
//<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed"> //<editor-fold desc="Kiểm tra header của template" defaultstate="collapsed">
for (int i = 0; i < header.size(); i++) { if (row.getPhysicalNumberOfCells() != header.size()) {
Cell cell = row.getCell(i); result.put("content", Files.readAllBytes(file.toPath()));
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) { result.put("message", "template-invalid");
result.put("content", Files.readAllBytes(file.toPath())); return result;
result.put("message", "template-invalid"); } else {
return result; for (int i = 0; i < header.size(); i++) {
Cell cell = row.getCell(i);
if (!cell.getStringCellValue().equals(header.get(i).getTitle().split("#")[0])) {
result.put("content", Files.readAllBytes(file.toPath()));
result.put("message", "template-invalid");
return result;
}
} }
} }
//</editor-fold> //</editor-fold>
...@@ -1016,7 +1027,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1016,7 +1027,7 @@ public class CustomerServiceImpl implements CustomerService {
//</editor-fold> //</editor-fold>
//<editor-fold desc="Đọc dữ liệu từng dòng 1" defaultstate="collapsed"> //<editor-fold desc="Đọc dữ liệu từng dòng 1" defaultstate="collapsed">
for (int i = 4; i < sheet.getPhysicalNumberOfRows(); i++) { for (int i = 4; i <= sheet.getPhysicalNumberOfRows(); i++) {
Row dataRow = sheet.getRow(i); Row dataRow = sheet.getRow(i);
if (dataRow != null) { if (dataRow != null) {
Object[] obj = new Object[row.getPhysicalNumberOfCells() - 1]; Object[] obj = new Object[row.getPhysicalNumberOfCells() - 1];
...@@ -1050,34 +1061,43 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1050,34 +1061,43 @@ public class CustomerServiceImpl implements CustomerService {
sb.append(str); sb.append(str);
} }
} else sb.append(BundleUtils.getLangString("customer.nameRequired", locale)); } else sb.append(BundleUtils.getLangString("customer.nameRequired", locale));
if (rawDataList.get(i).length > 4 if (rawDataList.get(i).length > 4 && (rawDataList.get(i)[2] == null || rawDataList.get(i)[2].toString().trim().equals(""))) {
&& rawDataList.get(i)[2] != null isMainPhoneNull = true;
&& !rawDataList.get(i)[2].toString().trim().equals("") } else {
&& rawDataList.get(i)[3] != null if (validateNumberOnly(rawDataList.get(i)[2].toString().trim())) {
&& !rawDataList.get(i)[3].toString().trim().equals("") sb.append(validateExistPhone(rawDataList.get(i)[2].toString().trim(), locale));
&& rawDataList.get(i)[4] != null
&& !rawDataList.get(i)[4].toString().trim().equals("")) {
String str = validatePhone(rawDataList.get(i)[2].toString().trim(), locale);
str += (validateLength(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0], rawDataList.get(i)[3].toString(), 50, locale));
if (!validateEmail(rawDataList.get(i)[4].toString().trim())) {
str += (BundleUtils.getLangString("customer.emailInvalid", locale));
} else { } else {
str += (validateDuplicateEmail(rawDataList.get(i)[4].toString().trim(), locale)); sb.append(BundleUtils.getLangString("customer.onlyNumber", locale));
} }
sb.append(validateLength(BundleUtils.getLangString("customer.email", locale).split("#")[0], rawDataList.get(i)[4].toString(), 50, locale)); }
sb.append(str); if (rawDataList.get(i).length > 4 && (rawDataList.get(i)[3] == null || rawDataList.get(i)[3].toString().trim().equals(""))) {
isSecondPhoneNull = true;
} else { } else {
if (rawDataList.get(i).length > 2 && rawDataList.get(i)[2] == null) { if (validateNumberOnly(rawDataList.get(i)[3].toString().trim())) {
sb.append(BundleUtils.getLangString("customer.mainPhoneRequired", locale)); sb.append(validateLength(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0], rawDataList.get(i)[3].toString(), 50, locale));
} else if (rawDataList.get(i).length > 3 && rawDataList.get(i)[3] == null) { } else {
sb.append(BundleUtils.getLangString("customer.secondPhoneRequired", locale)); sb.append(BundleUtils.getLangString("customer.onlyNumber", locale));
} else if (rawDataList.get(i).length > 4 && rawDataList.get(i)[4] == null) {
sb.append(BundleUtils.getLangString("customer.emailRequired", locale));
} }
} }
if (rawDataList.get(i).length > 4 && (rawDataList.get(i)[4] == null || rawDataList.get(i)[4].toString().trim().equals(""))) {
isEmailNull = true;
} else {
if (!validateEmail(rawDataList.get(i)[4].toString().trim())) {
sb.append(BundleUtils.getLangString("customer.emailInvalid", locale));
} else {
sb.append(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));
}
}
if (isEmailNull && isMainPhoneNull && isSecondPhoneNull) {
sb.append(BundleUtils.getLangString("customer.invalidRecord", locale));
}
if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null) { if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.address", locale).split("#")[0], rawDataList.get(i)[5].toString(), 500, locale)); sb.append(validateLength(BundleUtils.getLangString("customer.address", locale).split("#")[0], rawDataList.get(i)[5].toString(), 500, locale));
} }
if (rawDataList.get(i).length > 6 && rawDataList.get(i)[6] != null) {
sb.append(validateCusType(rawDataList.get(i)[6].toString().trim(), locale));
}
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null) { if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.companyName", locale).split("#")[0], rawDataList.get(i)[7].toString(), 100, locale)); sb.append(validateLength(BundleUtils.getLangString("customer.companyName", locale).split("#")[0], rawDataList.get(i)[7].toString(), 100, locale));
} }
...@@ -1104,6 +1124,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1104,6 +1124,9 @@ public class CustomerServiceImpl implements CustomerService {
resultCell.setCellValue("Ok"); resultCell.setCellValue("Ok");
} }
sb = new StringBuilder(); sb = new StringBuilder();
isEmailNull = false;
isMainPhoneNull = false;
isSecondPhoneNull = false;
} }
//</editor-fold> //</editor-fold>
...@@ -1114,8 +1137,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1114,8 +1137,12 @@ public class CustomerServiceImpl implements CustomerService {
c.setName(rawDataList.get(i)[1].toString().trim()); c.setName(rawDataList.get(i)[1].toString().trim());
c.setSiteId(userSession.getSiteId()); c.setSiteId(userSession.getSiteId());
c.setCode(null); c.setCode(null);
c.setDescription(rawDataList.get(i)[8].toString().trim()); if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null && !rawDataList.get(i)[8].toString().trim().equals("")) {
c.setCompanyName(rawDataList.get(i)[7].toString().trim()); c.setDescription(rawDataList.get(i)[8].toString().trim());
}
if (rawDataList.get(i).length > 7 && rawDataList.get(i)[7] != null && !rawDataList.get(i)[7].toString().trim().equals("")) {
c.setCompanyName(rawDataList.get(i)[7].toString().trim());
}
c.setCustomerImg(null); c.setCustomerImg(null);
c.setCreateDate(new Date()); c.setCreateDate(new Date());
c.setUpdateDate(null); c.setUpdateDate(null);
...@@ -1123,7 +1150,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1123,7 +1150,9 @@ public class CustomerServiceImpl implements CustomerService {
c.setCreateBy(userSession.getUserName()); c.setCreateBy(userSession.getUserName());
c.setUpdateBy(null); c.setUpdateBy(null);
c.setGender((short) 1); c.setGender((short) 1);
c.setCurrentAddress(rawDataList.get(i)[5].toString().trim()); if (rawDataList.get(i).length > 5 && rawDataList.get(i)[5] != null && !rawDataList.get(i)[5].toString().trim().equals("")) {
c.setCurrentAddress(rawDataList.get(i)[5].toString().trim());
}
// c.setPlaceOfBirth(); // c.setPlaceOfBirth();
// c.setDateOfBirth(); // c.setDateOfBirth();
c.setMobileNumber(null); c.setMobileNumber(null);
...@@ -1279,14 +1308,15 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1279,14 +1308,15 @@ public class CustomerServiceImpl implements CustomerService {
} }
//<editor-fold desc="Validate Methods" defaultstate="collapsed"> //<editor-fold desc="Validate Methods" defaultstate="collapsed">
private String validatePhone(String str, Locale locale) { private String validateExistPhone(String str, Locale locale) {
String result = ""; String result = "";
String[] arr = str.split(";"); String[] arr = str.split(";");
List<CustomerContact> contactList;
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 < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
List<CustomerContact> contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]); contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]);
if (contactList.size() != 0) { if (contactList.size() != 0) {
return result.concat(BundleUtils.getLangString("customer.phoneExists", locale)); return result.concat(BundleUtils.getLangString("customer.phoneExists", locale));
} }
...@@ -1294,11 +1324,24 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1294,11 +1324,24 @@ public class CustomerServiceImpl implements CustomerService {
return result; return result;
} }
private boolean validateNumberOnly(String str) {
String regexp = "\\b\\d+\\b";
String[] arr = str.split(";");
int count = 0;
for (int i = 0; i < arr.length; i++) {
if (!arr[i].matches(regexp)) {
count++;
}
}
return count == 0;
}
private String validateDuplicateEmail(String str, Locale locale) { private String validateDuplicateEmail(String str, Locale locale) {
String result = ""; String result = "";
String[] arr = str.split(";"); String[] arr = str.split(";");
List<CustomerContact> contactList;
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
List<CustomerContact> contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]); contactList = customerContactRepository.findCustomerContactsByContactEquals(arr[i]);
if (contactList.size() != 0) { if (contactList.size() != 0) {
return result.concat(BundleUtils.getLangString("customer.emailExists", locale)); return result.concat(BundleUtils.getLangString("customer.emailExists", locale));
} }
...@@ -1328,15 +1371,27 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1328,15 +1371,27 @@ public class CustomerServiceImpl implements CustomerService {
private boolean validateEmail(String str) { private boolean validateEmail(String str) {
String[] arr = str.split(";"); String[] arr = str.split(";");
String regexp = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
for (int i = 0; i < arr.length; i++) { for (int i = 0; i < arr.length; i++) {
if (!arr[i].matches(regexp)) { Matcher matcher = EMAIL_REGEXP.matcher(arr[i]);
if (!matcher.matches()) {
return false; return false;
} }
} }
return true; return true;
} }
private String validateCusType(String str, Locale locale) {
String[] arr = {BundleUtils.getLangString("customer.cusType.normal", locale),
BundleUtils.getLangString("customer.cusType.vip", locale),
BundleUtils.getLangString("customer.cusType.blacklist", locale)};
List<String> cusTypes = Arrays.asList(arr);
if (cusTypes.contains(str.trim())) {
return "";
} else {
return BundleUtils.getLangString("customer.cusTypeInvalid", locale);
}
}
private boolean validateLetter(String str) { private boolean validateLetter(String str) {
String regexp = "@\"^\\p{L}+$\""; String regexp = "@\"^\\p{L}+$\"";
return str.matches(regexp); return str.matches(regexp);
...@@ -1869,8 +1924,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1869,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"},
}; };
...@@ -1923,90 +1978,103 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1923,90 +1978,103 @@ 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(" a.mobile mobileNumber,"); sb.append(" cc.CONTACT mobileNumber,");
sb.append(" b.Email email,"); sb.append(" cc2.CONTACT email,");
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 (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY "); sb.append(" inner join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY ");
sb.append(" NULL) AS MOBILE"); sb.append(" NULL) AS CONTACT");
sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 AND STATUS = 1 GROUP BY "); sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 AND STATUS = 1 GROUP BY ");
sb.append(" CUSTOMER_ID) a on c.CUSTOMER_ID = a.CUSTOMER_ID"); sb.append(" CUSTOMER_ID) cc on c.CUSTOMER_ID = cc.CUSTOMER_ID");
sb.append(" inner join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY "); sb.append(" inner join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY ");
sb.append(" NULL) AS EMAIL"); sb.append(" NULL) AS CONTACT");
sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 AND STATUS = 1 GROUP BY "); sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 AND STATUS = 1 GROUP BY ");
sb.append(" CUSTOMER_ID) b on b.CUSTOMER_ID = c.CUSTOMER_ID "); sb.append(" CUSTOMER_ID) cc2 on cc2.CUSTOMER_ID = c.CUSTOMER_ID ");
// 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)");
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) { 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() + "%')"); 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() + ")"); 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":
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'))"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and (cfo.value_date +" + campaignCustomerDTO.getTimezoneOffset() + "/24)" + customerDTOList.get(0).getOperator() + " to_date('" + customerDTOList.get(0).getCondition().trim() + "', 'DD/MM/YYYY'))");
break; break;
case "number": case "number":
sb.append("and (cfo.customize_fields_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_fields_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() + " " + ("true".equals(customerDTOList.get(0).getCondition()) ? "1" : "0") + ")");
break; break;
} }
} else { } 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 (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + 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() + ")");
} }
} }
for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) { for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) {
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() + "%' "); + "'%" + 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()) {
case "combobox": 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() + ")"); sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.field_option_value_id " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break; break;
case "text": 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() + "%')"); 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().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "%')");
} 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().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() + "%')");
break; break;
case "date": 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() + ")"); sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and (cfo.value_date + " + campaignCustomerDTO.getTimezoneOffset() + "/24)" + customerDTOList.get(i).getOperator() + " to_date('" + customerDTOList.get(i).getCondition().trim() + "', 'DD/MM/YYYY'))");
break; break;
case "number": 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() + ")"); sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_number " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break; break;
case "checkbox": 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() + ")"); sb.append(customerDTOList.get(i).getJoin() + " (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_checkbox " + customerDTOList.get(i).getOperator() + " " + ("true".equals(customerDTOList.get(i).getCondition()) ? "1" : "0") + ")");
break; break;
} }
} }
...@@ -2040,7 +2108,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2040,7 +2108,7 @@ public class CustomerServiceImpl implements CustomerService {
query.setMaxResults(pageable.getPageSize()); query.setMaxResults(pageable.getPageSize());
} }
List<CustomerDTO>data = query.list(); List<CustomerDTO> data = query.list();
Page<CustomerDTO> dataPage = new PageImpl<>(data, pageable, count); Page<CustomerDTO> dataPage = new PageImpl<>(data, pageable, count);
resultDTO.setData(dataPage); resultDTO.setData(dataPage);
resultDTO.setTotalRow(count); resultDTO.setTotalRow(count);
......
...@@ -31,5 +31,5 @@ public class CampaignCustomerDTO extends BaseDTO{ ...@@ -31,5 +31,5 @@ public class CampaignCustomerDTO extends BaseDTO{
private String lstCustomerId; private String lstCustomerId;
private List<CustomerQueryDTO> listQuery; private List<CustomerQueryDTO> listQuery;
private Long field; private Long field;
private Integer timezoneOffset;
} }
...@@ -58,4 +58,5 @@ public class CampaignRequestDTO extends BaseDTO { ...@@ -58,4 +58,5 @@ public class CampaignRequestDTO extends BaseDTO {
String customerListId; String customerListId;
String statuses; String statuses;
String channels; String channels;
Integer timezoneOffset;
} }
package com.viettel.campaign.web.rest; package com.viettel.campaign.web.rest;
import com.viettel.campaign.utils.RedisUtil;
import com.viettel.campaign.web.dto.CampaignCfgDTO; import com.viettel.campaign.web.dto.CampaignCfgDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.service.CampaignCfgService; import com.viettel.campaign.service.CampaignCfgService;
import com.viettel.campaign.web.dto.request_dto.CampaignCfgRequestDTO; import com.viettel.campaign.web.dto.request_dto.CampaignCfgRequestDTO;
import com.viettel.econtact.filter.UserSession;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Map; import java.util.Map;
...@@ -38,13 +41,16 @@ public class CampaignCfgController { ...@@ -38,13 +41,16 @@ public class CampaignCfgController {
@PostMapping("/create") @PostMapping("/create")
@ResponseBody @ResponseBody
public ResultDTO createCompleteCode(@RequestBody @Valid CampaignCfgDTO completeCodeDTO) { public ResultDTO createCompleteCode(@RequestBody @Valid CampaignCfgDTO completeCodeDTO , HttpServletRequest httpServletRequest) {
String xAuthToken = httpServletRequest.getHeader("X-Auth-Token");
UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
//LogUtil logUtil = new LogUtil(); //LogUtil logUtil = new LogUtil();
//logUtil.initKpiLog("createCust") //logUtil.initKpiLog("createCust")
try { try {
//LOGGER.info("Returning createCustomer: start"); //LOGGER.info("Returning createCustomer: start");
result = completeCodeService.createCompleteCode(completeCodeDTO); result = completeCodeService.createCompleteCode(completeCodeDTO, userSession.getUserId());
//LOGGER.info("Returning createCustomer:" + result.getErrorCode()); //LOGGER.info("Returning createCustomer:" + result.getErrorCode());
//logUtil.endKpiLog(customerDTO, 0, result.getErrorCode(), result.getDetail(), CustomerController.class, customerDTO.getAgentProcess(), this.serverPort); //logUtil.endKpiLog(customerDTO, 0, result.getErrorCode(), result.getDetail(), CustomerController.class, customerDTO.getAgentProcess(), this.serverPort);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -15,6 +15,7 @@ import org.springframework.http.HttpStatus; ...@@ -15,6 +15,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -205,6 +206,13 @@ public class CampaignController { ...@@ -205,6 +206,13 @@ public class CampaignController {
return new ResponseEntity<>(resultDTO, HttpStatus.OK); return new ResponseEntity<>(resultDTO, HttpStatus.OK);
} }
@PostMapping("/getCountIndividualOnList")
@ResponseBody
public ResponseEntity getCountIndividualOnList(@RequestBody CampaignRequestDTO campaignRequestDTO) {
ResultDTO resultDTO = campaignService.getCountIndividualOnList(campaignRequestDTO);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@PostMapping("/saveCustomerCampaign") @PostMapping("/saveCustomerCampaign")
@ResponseBody @ResponseBody
public ResponseEntity saveCustomerCampaign(@RequestBody CampaignRequestDTO campaignRequestDTO) { public ResponseEntity saveCustomerCampaign(@RequestBody CampaignRequestDTO campaignRequestDTO) {
......
...@@ -37,7 +37,7 @@ import java.util.Map; ...@@ -37,7 +37,7 @@ import java.util.Map;
@RequestMapping("/ipcc/customer") @RequestMapping("/ipcc/customer")
@CrossOrigin(origins = "*") @CrossOrigin(origins = "*")
public class CustomerController { public class CustomerController {
private CustomerQueryRepository customerQueryRepo; private CustomerQueryRepository customerQueryRepo;
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerController.class); private static final Logger LOGGER = LoggerFactory.getLogger(CustomerController.class);
...@@ -198,11 +198,8 @@ public class CustomerController { ...@@ -198,11 +198,8 @@ public class CustomerController {
try { try {
UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token")); UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token"));
if (file.isEmpty()) { if (file.isEmpty()) {
return new ResponseEntity<>("file-empty", HttpStatus.OK); return new ResponseEntity<>("file-empty", HttpStatus.NO_CONTENT);
} }
// if (!Objects.equals(FilenameUtils.getExtension(file.getOriginalFilename()), Constants.FileType.xlsx)) {
// return new ResponseEntity<>("template-invalid", HttpStatus.OK);
// }
String path = saveUploadFile(file); String path = saveUploadFile(file);
List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId()); List<CustomizeFields> dynamicHeaders = customerService.getDynamicHeader(userSession.getCompanySiteId());
Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, Long.parseLong(customerListId)); Map<String, Object> map = customerService.readAndValidateCustomer(path, dynamicHeaders, userSession, Long.parseLong(customerListId));
...@@ -265,18 +262,15 @@ public class CustomerController { ...@@ -265,18 +262,15 @@ public class CustomerController {
} }
private String saveUploadFile(MultipartFile file) { private String saveUploadFile(MultipartFile file) {
try { try {
String currentTime = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss").format(new Date()); String currentTime = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss").format(new Date());
String fileName = FilenameUtils.getBaseName(file.getOriginalFilename()) + "_" + currentTime + "." + FilenameUtils.getExtension(file.getOriginalFilename()); String fileName = FilenameUtils.getBaseName(file.getOriginalFilename()) + "_" + currentTime + "." + FilenameUtils.getExtension(file.getOriginalFilename());
byte[] content = file.getBytes(); byte[] content = file.getBytes();
// File uploadFolder = new File(BundleUtils.getGlobalConfig("import.uploadFolder"));
File uploadFolder = new File(Config.EXCEL_DIR); File uploadFolder = new File(Config.EXCEL_DIR);
if (!uploadFolder.exists()) { if (!uploadFolder.exists()) {
uploadFolder.mkdir(); uploadFolder.mkdir();
} }
// Path path = Paths.get(BundleUtils.getGlobalConfig("import.uploadFolder"), fileName);
Path path = Paths.get(Config.EXCEL_DIR, fileName); Path path = Paths.get(Config.EXCEL_DIR, fileName);
Files.write(path, content); Files.write(path, content);
return path.toString(); return path.toString();
...@@ -286,7 +280,7 @@ public class CustomerController { ...@@ -286,7 +280,7 @@ public class CustomerController {
return null; return null;
} }
// @GetMapping("/query") // @GetMapping("/query")
// public ResponseEntity<List<Customer>> query(@RequestParam(value = "search") String query) { // public ResponseEntity<List<Customer>> query(@RequestParam(value = "search") String query) {
// List<Customer> things = customerQueryRepo.findAll(query); // List<Customer> things = customerQueryRepo.findAll(query);
// if (things.isEmpty()) { // if (things.isEmpty()) {
...@@ -294,16 +288,16 @@ public class CustomerController { ...@@ -294,16 +288,16 @@ public class CustomerController {
// } // }
// return ResponseEntity.ok(things); // return ResponseEntity.ok(things);
// } // }
@GetMapping(path = "", produces = { MediaType.APPLICATION_JSON_VALUE }) @GetMapping(path = "", produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<List<Customer>> query(@RequestParam(value = "search") String query) { public ResponseEntity<List<Customer>> query(@RequestParam(value = "search") String query) {
List<Customer> result = null; List<Customer> result = null;
try { try {
result= customerService.searchByQuery(query); result = customerService.searchByQuery(query);
}catch (IllegalArgumentException iae){ } catch (IllegalArgumentException iae) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST) return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(result); .body(result);
} }
return ResponseEntity.status(HttpStatus.OK) return ResponseEntity.status(HttpStatus.OK)
.body(result); .body(result);
} }
...@@ -316,7 +310,7 @@ public class CustomerController { ...@@ -316,7 +310,7 @@ public class CustomerController {
@PostMapping("/searchIndividualCustomer") @PostMapping("/searchIndividualCustomer")
@ResponseBody @ResponseBody
public ResponseEntity searchCustomizeFields(@RequestBody CampaignCustomerDTO campaignCustomerDTO ) { public ResponseEntity searchCustomizeFields(@RequestBody CampaignCustomerDTO campaignCustomerDTO) {
ResultDTO result = customerService.searchCustomizeFields(campaignCustomerDTO); ResultDTO result = customerService.searchCustomizeFields(campaignCustomerDTO);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
......
...@@ -89,7 +89,9 @@ customer.yes = Yes ...@@ -89,7 +89,9 @@ customer.yes = Yes
customer.not = No customer.not = No
customer.noData = Template empty customer.noData = Template empty
customer.nameRequired = Full name required; customer.nameRequired = Full name required;
customer.emailMax50 = Email must less than 50 character; customer.emailMax100=Email must less than 100 character;
customer.invalidRecord=Invalid Record, required one more contact information;
customer.onlyNumber=Phone contain number only;
customer.importSuccess = Import Successful customer.importSuccess = Import Successful
customer.importFailed = Import Failed customer.importFailed = Import Failed
customer.errorValidate = Error while validating customer.errorValidate = Error while validating
...@@ -102,6 +104,7 @@ customer.importCustomer = IMPORT CUSTOMER ...@@ -102,6 +104,7 @@ customer.importCustomer = IMPORT CUSTOMER
customer.notice = Attention: A record is valid when Full Name is not null and one of three fields Main phone, secondary phone or email is not null customer.notice = Attention: A record is valid when Full Name is not null and one of three fields Main phone, secondary phone or email is not null
customer.emailInvalid=Invalid email; customer.emailInvalid=Invalid email;
customer.emailExists=Email exists; customer.emailExists=Email exists;
customer.cusTypeInvalid=Customer type Invalid;
common.fileNotSelected=Please select a file common.fileNotSelected=Please select a file
common.fileInvalidFormat=File invalid common.fileInvalidFormat=File invalid
......
...@@ -91,10 +91,9 @@ customer.yes = Có ...@@ -91,10 +91,9 @@ customer.yes = Có
customer.not = Không customer.not = Không
customer.noData = Template không có dữ liệu customer.noData = Template không có dữ liệu
customer.nameRequired = Họ và tên không được để trống; customer.nameRequired = Họ và tên không được để trống;
customer.emailMax50 = Email không được quá 50 kí tự; customer.emailMax100=Email không được quá 100 kí tự;
customer.mainPhoneRequired=Số điện thoại chính không được để trống customer.invalidRecord=Bắt buộc nhập 1 trong 3 thông tin liên lạc(Số điện thoại chính, Số điện thoại phụ, Email);
customer.secondPhoneRequired=Số điện thoại phụ không được để trống customer.onlyNumber=Số điện thoại chỉ được nhập số;
customer.emailRequired=Số điện thoại email không được để trống
customer.importSuccess = Import dữ liệu thành công customer.importSuccess = Import dữ liệu thành công
customer.importFailed = Import dữ liệu thất bại customer.importFailed = Import dữ liệu thất bại
customer.errorValidate = Validate dữ liệu lỗi customer.errorValidate = Validate dữ liệu lỗi
...@@ -107,6 +106,7 @@ customer.importCustomer = IMPORT KHÁCH HÀNG ...@@ -107,6 +106,7 @@ customer.importCustomer = IMPORT KHÁCH HÀNG
customer.notice = Chú ý: 1 bản ghi được coi là hợp lệ bắt buộc phải có thông tin Họ và Tên và 1 trong 3 thông tin liên lạc (số điện thoại chính, số điện thoại phụ hoặc email) customer.notice = Chú ý: 1 bản ghi được coi là hợp lệ bắt buộc phải có thông tin Họ và Tên và 1 trong 3 thông tin liên lạc (số điện thoại chính, số điện thoại phụ hoặc email)
customer.emailInvalid=Email không đúng định dạng; customer.emailInvalid=Email không đúng định dạng;
customer.emailExists=Email đã tồn tại; customer.emailExists=Email đã tồn tại;
customer.cusTypeInvalid=Loại khách hàng không hợp lệ;
common.fileNotSelected=Bạn chưa chọn file common.fileNotSelected=Bạn chưa chọn file
common.fileInvalidFormat=File không hợp lệ common.fileInvalidFormat=File không hợp lệ
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment