Commit 00df32e5 authored by Nguyen Ha's avatar Nguyen Ha

Merge remote-tracking branch 'origin/master'

parents bd05e47b 2f4944a3
...@@ -11,23 +11,16 @@ import java.util.List; ...@@ -11,23 +11,16 @@ import java.util.List;
public interface CustomerListMappingRepository extends JpaRepository<CustomerListMapping, Long> { public interface CustomerListMappingRepository extends JpaRepository<CustomerListMapping, Long> {
// ----------- customer ------------ // // ----------- customer ------------ //
@Query("select c from CustomerListMapping c where c.customerId in (:p_ids) and c.customerListId =:p_customer_list_id and c.companySiteId=:p_company_site_id") @Query("select c from CustomerListMapping c where c.customerId in (:p_ids) and c.customerListId =:p_customer_list_id and c.companySiteId=:p_company_site_id")
List<CustomerListMapping> findAllCustomerListMapping(@Param("p_ids") List<Long> p_ids, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id); List<CustomerListMapping> findAllCustomerListMapping(@Param("p_ids") List<Long> p_ids, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying
@Query("delete from CustomerListMapping c where c.customerId=:p_customer_id and c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerId(@Param("p_customer_id") Long p_customer_id, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerId in (:p_ids) and c.customerListId =:p_customer_list_id and c.companySiteId=:p_company_site_id") @Query("delete from CustomerListMapping c where c.customerId in (:p_ids) and c.customerListId =:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerIds(@Param("p_ids") List<Long> p_ids, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id); int deleteMappingByCustomerIds(@Param("p_ids") List<Long> p_ids, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
// ----------- customer list --------------- // // ----------- customer list --------------- //
@Modifying
@Query("delete from CustomerListMapping c where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerListId(@Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id") @Query("delete from CustomerListMapping c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerListIds(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id); int deleteMappingByCustomerListIds(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
......
...@@ -17,14 +17,7 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long ...@@ -17,14 +17,7 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long
@Query("select c from CustomerList c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id and c.status = 1") @Query("select c from CustomerList c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id and c.status = 1")
List<CustomerList> findAllCustomerList(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id); List<CustomerList> findAllCustomerList(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
@Modifying
@Query("update CustomerList c set c.status = 0 where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteCustomerList(@Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("update CustomerList c set c.status = 0 where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id") @Query("update CustomerList c set c.status = 0 where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id")
int deleteCustomerListIds(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id); int deleteCustomerListIds(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
@Query(value = "SELECT * FROM (SELECT c.*, MAX(c.CREATE_AT) OVER() AS LATEST_CREATED FROM CUSTOMER_LIST c) WHERE CREATE_AT = LATEST_CREATED AND COMPANY_SITE_ID =:p_company_site_id", nativeQuery = true)
CustomerList latestCreated(@Param("p_company_site_id") Long p_company_site_id);
} }
...@@ -19,6 +19,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long>, Custo ...@@ -19,6 +19,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long>, Custo
Page<Customer> findAll(Pageable pageable); Page<Customer> findAll(Pageable pageable);
Customer getByCustomerId(Long customerId);
List<Customer> findByCustomerId(Long customerId); List<Customer> findByCustomerId(Long customerId);
@Query("FROM Customer WHERE name = ?1") @Query("FROM Customer WHERE name = ?1")
......
package com.viettel.campaign.repository.ccms_full; package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.web.dto.CustomerCustomDTO; import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerDetailRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerDetailRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import java.util.List; import java.util.List;
...@@ -12,4 +13,12 @@ public interface CustomerRepositoryCustom { ...@@ -12,4 +13,12 @@ public interface CustomerRepositoryCustom {
List<CustomerDetailRequestDTO> getCustomerDetailById(Long companySiteId, Long customerListId, Long customerId); List<CustomerDetailRequestDTO> getCustomerDetailById(Long companySiteId, Long customerListId, Long customerId);
List<CustomerCustomDTO> getAllCustomerByParams(SearchCustomerRequestDTO searchCustomerRequestDTO, Pageable pageable); List<CustomerCustomDTO> getAllCustomerByParams(SearchCustomerRequestDTO searchCustomerRequestDTO, Pageable pageable);
List<CampaignInformationDTO> getCampaignInformation(CampaignCustomerDTO campaignCustomerDTO);
List<CustomerDTO> getIndividualCustomerInfo(CampaignCustomerDTO campaignCustomerDTO);
List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO);
List<CustomerDTO> getCustomizeFields(CampaignCustomerDTO campaignCustomerDTO, UserSession userSession, Pageable pageable);
} }
...@@ -15,4 +15,6 @@ import java.util.List; ...@@ -15,4 +15,6 @@ import java.util.List;
public interface CustomerTimeRepository extends JpaRepository<CustomerTime, Long> { public interface CustomerTimeRepository extends JpaRepository<CustomerTime, Long> {
List<CustomerTime> findByCustomerId(Long customerId); List<CustomerTime> findByCustomerId(Long customerId);
CustomerTime findByCompanySiteIdAndCustomerId(Long companySiteId, Long customerId);
} }
...@@ -4,4 +4,5 @@ import com.viettel.campaign.model.ccms_full.ReceiveCustLog; ...@@ -4,4 +4,5 @@ import com.viettel.campaign.model.ccms_full.ReceiveCustLog;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
public interface ReceiveCustLogRepository extends JpaRepository<ReceiveCustLog, Long> { public interface ReceiveCustLogRepository extends JpaRepository<ReceiveCustLog, Long> {
ReceiveCustLog getByReceiveCustLogId(Long receiveCustLogId);
} }
...@@ -105,6 +105,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository { ...@@ -105,6 +105,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
public List<ContactCustResultDTO> getInteractiveResult(CampaignRequestDTO dto, Pageable pageable) { public List<ContactCustResultDTO> getInteractiveResult(CampaignRequestDTO dto, Pageable pageable) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
List<ContactCustResultDTO> list = new ArrayList<>(); List<ContactCustResultDTO> list = new ArrayList<>();
TimeZone tzClient = TimeZoneUtils.getZoneMinutes(dto.getTimezone());
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession(); Session session = sessionFactory.openSession();
...@@ -125,7 +126,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository { ...@@ -125,7 +126,7 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
sql.append(" CC2.COMPLETE_NAME AS surveyStatus, "); sql.append(" CC2.COMPLETE_NAME AS surveyStatus, ");
sql.append(" C.STATUS AS status, "); sql.append(" C.STATUS AS status, ");
sql.append(" CCR.STATUS AS recordStatus, "); sql.append(" CCR.STATUS AS recordStatus, ");
sql.append(" (( CCR.END_TIME - CCR.START_CALL ) * 24 * 60 * 60) AS callTime, "); sql.append(" ROUND(( CCR.END_TIME - CCR.START_CALL ) * 24 * 60 * 60) AS callTime, ");
sql.append(" C.CAMPAIGN_ID AS campaignId, "); sql.append(" C.CAMPAIGN_ID AS campaignId, ");
sql.append(" CUS.CUSTOMER_ID AS customerId "); sql.append(" CUS.CUSTOMER_ID AS customerId ");
sql.append("FROM CONTACT_CUST_RESULT CCR "); sql.append("FROM CONTACT_CUST_RESULT CCR ");
...@@ -133,11 +134,11 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository { ...@@ -133,11 +134,11 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
sql.append(" INNER JOIN VSA_USERS VU ON CCR.AGENT_ID = VU.USER_ID "); sql.append(" INNER JOIN VSA_USERS VU ON CCR.AGENT_ID = VU.USER_ID ");
sql.append(" INNER JOIN CUSTOMER CUS ON CCR.CUSTOMER_ID = CUS.CUSTOMER_ID "); sql.append(" INNER JOIN CUSTOMER CUS ON CCR.CUSTOMER_ID = CUS.CUSTOMER_ID ");
sql.append(" INNER JOIN CAMPAIGN_COMPLETE_CODE CC1 ON CCR.CONTACT_STATUS = CC1.COMPLETE_VALUE "); sql.append(" INNER JOIN CAMPAIGN_COMPLETE_CODE CC1 ON CCR.CONTACT_STATUS = CC1.COMPLETE_VALUE ");
sql.append(" LEFT JOIN CAMPAIGN_COMPLETE_CODE CC2 ON CCR.CALL_STATUS = CC2.COMPLETE_VALUE "); sql.append(" LEFT JOIN CAMPAIGN_COMPLETE_CODE CC2 ON CCR.CALL_STATUS = CC2.COMPLETE_VALUE ");
sql.append("WHERE CCR.STATUS <> 0 "); sql.append("WHERE CCR.STATUS <> 0 ");
sql.append(" AND CCR.COMPANY_SITE_ID = :p_company_site_id "); sql.append(" AND CCR.COMPANY_SITE_ID = :p_company_site_id ");
sql.append(" AND to_date(CCR.CREATE_TIME, 'DD/MM/RR') >= to_date(:p_date_from, 'DD/MM/RR') "); sql.append(" AND to_date(CCR.CREATE_TIME, 'DD/MM/RR') >= to_date(:p_date_from, 'DD/MM/YYYY HH24:MI:SS') ");
sql.append(" AND to_date(CCR.CREATE_TIME, 'DD/MM/RR') <= to_date(:p_date_to, 'DD/MM/RR') "); sql.append(" AND to_date(CCR.CREATE_TIME, 'DD/MM/RR') <= to_date(:p_date_to, 'DD/MM/YYYY HH24:MI:SS') ");
if (!DataUtil.isNullOrEmpty(dto.getCustomerId())) { if (!DataUtil.isNullOrEmpty(dto.getCustomerId())) {
sql.append(" AND CCR.CUSTOMER_ID LIKE (:p_customer_id) "); sql.append(" AND CCR.CUSTOMER_ID LIKE (:p_customer_id) ");
...@@ -185,8 +186,10 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository { ...@@ -185,8 +186,10 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
SQLQuery query = session.createSQLQuery(sql.toString()); SQLQuery query = session.createSQLQuery(sql.toString());
query.setParameter("p_company_site_id", dto.getCompanySiteId()); query.setParameter("p_company_site_id", dto.getCompanySiteId());
query.setParameter("p_date_from", dto.getFromDate()); //query.setParameter("p_date_from", dto.getFromDate());
query.setParameter("p_date_to", dto.getToDate()); query.setParameter("p_date_from", TimeZoneUtils.toDateStringWithTimeZone(DateTimeUtil.parseDate("dd/MM/yyyy", dto.getFromDate()), tzClient));
//query.setParameter("p_date_to", dto.getToDate());
query.setParameter("p_date_to", TimeZoneUtils.toDateStringWithTimeZone(DateTimeUtil.parseDate("dd/MM/yyyy", dto.getToDate()), tzClient));
if (!DataUtil.isNullOrEmpty(dto.getCustomerId())) { if (!DataUtil.isNullOrEmpty(dto.getCustomerId())) {
query.setParameter("p_customer_id", "%" + query.setParameter("p_customer_id", "%" +
...@@ -523,8 +526,8 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository { ...@@ -523,8 +526,8 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
query.setParameter("pCampaignName", "%" + query.setParameter("pCampaignName", "%" +
campaignRequestDto.getCampaignName().toUpperCase() campaignRequestDto.getCampaignName().toUpperCase()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\\\%") .replaceAll("%", "\\%")
.replaceAll("_", "\\\\_") .replaceAll("_", "\\_")
+ "%"); + "%");
} }
......
package com.viettel.campaign.repository.ccms_full.impl; package com.viettel.campaign.repository.ccms_full.impl;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.repository.ccms_full.CustomerRepositoryCustom; import com.viettel.campaign.repository.ccms_full.CustomerRepositoryCustom;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.DataUtil; import com.viettel.campaign.utils.DataUtil;
import com.viettel.campaign.utils.HibernateUtil; import com.viettel.campaign.utils.HibernateUtil;
import com.viettel.campaign.web.dto.CustomerCustomDTO; import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerDetailRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerDetailRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerQueryDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.econtact.filter.UserSession;
import org.hibernate.SQLQuery; import org.hibernate.SQLQuery;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
...@@ -16,14 +17,25 @@ import org.hibernate.type.DateType; ...@@ -16,14 +17,25 @@ import org.hibernate.type.DateType;
import org.hibernate.type.LongType; import org.hibernate.type.LongType;
import org.hibernate.type.ShortType; import org.hibernate.type.ShortType;
import org.hibernate.type.StringType; import org.hibernate.type.StringType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.*; import org.springframework.data.domain.*;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
@Repository @Repository
public class CustomerRepositoryImpl implements CustomerRepositoryCustom { public class CustomerRepositoryImpl implements CustomerRepositoryCustom {
@Autowired
@Qualifier(DataSourceQualify.NAMED_JDBC_PARAMETER_TEMPLATE_CCMS_FULL)
NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Override @Override
public List<CustomerDetailRequestDTO> getCustomerDetailById(Long companySiteId, Long customerListId, Long customerId) { public List<CustomerDetailRequestDTO> getCustomerDetailById(Long companySiteId, Long customerListId, Long customerId) {
List<CustomerDetailRequestDTO> data = new ArrayList<>(); List<CustomerDetailRequestDTO> data = new ArrayList<>();
...@@ -194,4 +206,366 @@ public class CustomerRepositoryImpl implements CustomerRepositoryCustom { ...@@ -194,4 +206,366 @@ public class CustomerRepositoryImpl implements CustomerRepositoryCustom {
return data; return data;
} }
@Override
public List<CampaignInformationDTO> getCampaignInformation(CampaignCustomerDTO campaignCustomerDTO) {
List<CampaignInformationDTO> list = new ArrayList<>();
Map<String, Object> params = new HashMap<>();
try {
StringBuilder sb = new StringBuilder();
sb.append(" with count_customer as (");
sb.append(" select campaign_id campaignId,");
sb.append(" sum(case");
sb.append(" when customer_list_id is null then 1");
sb.append(" else 0");
sb.append(" end) totalIndividual,");
sb.append(" sum(case");
sb.append(" when customer_list_id is not null then 1");
sb.append(" else 0");
sb.append(" end) totalCusInList");
sb.append(" from campaign_customer");
sb.append(" group by campaign_id");
sb.append(" )");
sb.append(" select b.campaign_id campaignId, nvl(totalIndividual, 0) totalIndividual, nvl(totalCusInList, 0) totalCusInList, b.customer_number campaignCustomer");
sb.append(" from campaign b");
sb.append(" left join count_customer a on a.campaignId = b.campaign_id");
sb.append(" where b.campaign_id = :p_campaign_id");
params.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
params.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CampaignInformationDTO.class));
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
@Override
public List<CustomerDTO> getIndividualCustomerInfo(CampaignCustomerDTO campaignCustomerDTO) {
List<CustomerDTO> customerList = new ArrayList<>();
try {
//String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-individual-customer");
// BuildMyString.com generated code. Please enjoy your string responsibly.
StringBuilder sb = new StringBuilder();
sb.append("with cusPhone as (");
sb.append(" select customer_id cusId,");
sb.append(" listagg(contact, ', ') within group (order by create_date desc) phone");
sb.append(" from customer_contact cc");
sb.append(" where cc.contact_type = 5");
sb.append(" and status = 1 ");
sb.append(" group by customer_id");
sb.append(" ), cusEmail as (");
sb.append(" select customer_id cusId,");
sb.append(" listagg(contact , ', ') within group(order by create_date desc) email");
sb.append(" from customer_contact cc");
sb.append(" where cc.contact_type = 2");
sb.append(" and status = 1 ");
sb.append(" group by customer_id");
sb.append(" )," +
"cusInCampaign as (" +
"select * from campaign_customer " +
"where campaign_id = :p_campaign_id " +
"and company_site_id = :p_company_site_id " +
"and customer_list_id is null " +
"and in_campaign_status = 1");
sb.append(" ), datas as (");
sb.append(" select c.customer_id customerId,");
sb.append(" c.name,");
sb.append(" cP.phone mobileNumber,");
sb.append(" cE.email,");
sb.append(" c.customer_type customerType,");
sb.append(" c.company_name companyName,");
sb.append(" c.current_address currentAddress,");
sb.append(" c.description,");
sb.append(" c.ipcc_status ipccStatus,");
sb.append(" c.call_allowed customerDnc");
sb.append(" from customer c");
sb.append(" inner join cusInCampaign cc on c.customer_id = cc.customer_id");
sb.append(" left join cusPhone cP on c.customer_id = cP.cusId");
sb.append(" left join cusEmail cE on c.customer_id = cE.cusId");
sb.append(" )");
sb.append(" select * from");
sb.append(" (");
sb.append(" select a.*, rownum r__");
sb.append(" from");
sb.append(" (");
sb.append(" select * from datas");
sb.append(" order by UPPER(datas.name)");
sb.append(" ) a");
sb.append(" where rownum < ((:p_page_number * :p_page_size) + 1 )");
sb.append(" )");
sb.append(" where r__ >= (((:p_page_number-1) * :p_page_size) + 1)");
Map<String, Object> param = new HashMap<>();
param.put("p_page_number", campaignCustomerDTO.getPage());
param.put("p_page_size", campaignCustomerDTO.getPageSize());
param.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
param.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
customerList = namedParameterJdbcTemplate.query(sb.toString(), param, new BeanPropertyRowMapper<>(CustomerDTO.class));
} catch (Exception e) {
e.printStackTrace();
}
return customerList;
}
@Override
public List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO) {
List<CustomerListDTO> customerList = new ArrayList<>();
try {
//String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-customer-list-info-from-customer-list");
// BuildMyString.com generated code. Please enjoy your string responsibly.
StringBuilder sb = new StringBuilder();
sb.append(" with totalCustomer as (");
sb.append(" select clm.customer_list_id,");
sb.append(" clm.company_site_id,");
sb.append(" count(clm.customer_id) total");
sb.append(" from customer_list_mapping clm");
sb.append(" inner join customer c on clm.customer_id = c.customer_id");
sb.append(" where c.status = 1");
sb.append(" group by clm.customer_list_id,clm.company_site_id");
sb.append(" ), customerInteractive as (");
sb.append(" select customer_list_id,");
sb.append(" company_site_id,");
sb.append(" count(customer_id) tt");
sb.append(" from campaign_customer where campaign_id = :p_campaign_id and status <> 0");
sb.append(" group by customer_list_id, company_site_id");
sb.append(" ), customerNotInteractive as (");
sb.append(" select customer_list_id,");
sb.append(" company_site_id,");
sb.append(" count(customer_id) ktt");
sb.append(" from campaign_customer where campaign_id = :p_campaign_id and status = 0");
sb.append(" and in_campaign_status = 1");
sb.append(" group by customer_list_id, company_site_id");
sb.append(" ), datas as (");
sb.append(" select customer_list_code customerListCode,");
sb.append(" customer_list_name customerListName,");
sb.append(" nvl(total, 0) totalCusInList,");
sb.append(" nvl(tt, 0) totalCusInteract,");
sb.append(" nvl(ktt, 0) totalCusNotInteract");
sb.append(" from customer_list cl");
sb.append(" left join totalCustomer tc on (cl.customer_list_id = tc.customer_list_id and cl.company_site_id = tc.company_site_id)");
sb.append(" left join customerInteractive ci on (cl.customer_list_id = ci.customer_list_id and cl.company_site_id = ci.company_site_id)");
sb.append(" left join customerNotInteractive cni on (cl.customer_list_id = cni.customer_list_id and cl.company_site_id = cni.company_site_id)");
sb.append(" where cl.company_site_id = :p_company_site_id");
sb.append(" )");
sb.append(" select * from");
sb.append(" (");
sb.append(" select a.*, rownum r__");
sb.append(" from");
sb.append(" (");
sb.append(" select * from datas");
sb.append(" order by customerListCode");
sb.append(" ) a");
sb.append(" where rownum < ((:p_page_number * :p_page_size) + 1 )");
sb.append(" )");
sb.append(" where r__ >= (((:p_page_number-1) * :p_page_size) + 1)");
Map<String, Object> param = new HashMap<>();
param.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
param.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
param.put("p_page_number", campaignCustomerDTO.getPage());
param.put("p_page_size", campaignCustomerDTO.getPageSize());
customerList = namedParameterJdbcTemplate.query(sb.toString(), param, new BeanPropertyRowMapper<>(CustomerListDTO.class));
} catch (Exception e) {
e.printStackTrace();
}
return customerList;
}
@Override
public List<CustomerDTO> getCustomizeFields(CampaignCustomerDTO campaignCustomerDTO, UserSession userSession, Pageable pageable) {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
List<CustomerDTO> data = new ArrayList<>();
Session session = sessionFactory.openSession();
session.beginTransaction();
Map<String, String> requestCustomer = new HashMap<>();
requestCustomer.put("-1", "c.code");
requestCustomer.put("-2", "c.name");
requestCustomer.put("-3", "c.company_name");
requestCustomer.put("-4", "c.gender");
requestCustomer.put("-5", "c.current_address");
requestCustomer.put("-6", "c.place_of_birth");
requestCustomer.put("-7", "c.date_of_birth");
requestCustomer.put("-8", "cc.contact");
requestCustomer.put("-9", "cc2.contact");
requestCustomer.put("-10", "c.username");
requestCustomer.put("-11", "c.customer_type");
requestCustomer.put("-12", "c.area_code");
requestCustomer.put("-13", "c.call_allowed");
requestCustomer.put("-14", "c.email_allowed");
requestCustomer.put("-15", "c.sms_allowed");
requestCustomer.put("-16", "c.ipcc_status");
try {
StringBuilder sb = new StringBuilder();
sb.append("select distinct c.customer_id customerId,");
sb.append(" C.NAME name,");
sb.append(" cc.CONTACT mobileNumber,");
sb.append(" cc2.CONTACT email,");
sb.append(" c.customer_type customerType,");
sb.append(" C.COMPANY_NAME companyName,");
sb.append(" c.current_address currentAddress,");
sb.append(" c.Description description");
sb.append(" FROM CUSTOMER C");
sb.append(" left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY ");
sb.append(" NULL) AS CONTACT");
sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 AND STATUS = 1 GROUP BY ");
sb.append(" CUSTOMER_ID) cc on c.CUSTOMER_ID = cc.CUSTOMER_ID");
sb.append(" left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY ");
sb.append(" NULL) AS CONTACT");
sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 AND STATUS = 1 GROUP BY ");
sb.append(" CUSTOMER_ID) cc2 on cc2.CUSTOMER_ID = c.CUSTOMER_ID ");
sb.append(" left 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.customer_id not in (select customer_id from campaign_customer where campaign_id = :p_campaign_id) ");
sb.append(" where 1 = 1 AND C.STATUS = 1 AND C.SITE_ID = :p_site_id ");
List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery();
if (customerDTOList.get(0).getField() > 0) {// field dong
switch (customerDTOList.get(0).getType()) {
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() + ")");
break;
case "text":
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 upper(cfo.value_text) " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
} else {
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "'");
}
if ("not like".equals(customerDTOList.get(0).getOperator()) || "<>".equals(customerDTOList.get(0).getOperator())) {
sb.append(" or cfo.value_text is null");
}
sb.append(" )");
break;
case "date":
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;
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() + ")");
break;
case "checkbox":
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;
}
} else {// field tinh
if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
sb.append("and (upper(" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + ") " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
} 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 if ("text".equals(customerDTOList.get(0).getType())) {
if ("=".equals(customerDTOList.get(0).getOperator()) || "<>".equals(customerDTOList.get(0).getOperator())) {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "'");
} else {
sb.append("and (upper(" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + ") " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
}
} else {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition());
}
if ("<>".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
sb.append(" or " + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " is null ");
}
sb.append(" )");
}
for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) {
if (customerDTOList.get(i).getField() < 0) { //Field tinh
if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ "upper(" + requestCustomer.get(customerDTOList.get(i).getField().toString()) + ") "
+ customerDTOList.get(i).getOperator() + " "
+ "'%" + customerDTOList.get(i).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%' ");
} 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("_", "\\_").toUpperCase() + "%' ");
} else if ("text".equals(customerDTOList.get(i).getType())) {
if ("=".equals(customerDTOList.get(i).getOperator()) || "<>".equals(customerDTOList.get(i).getOperator())) {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " '"
+ customerDTOList.get(i).getCondition().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "' ");
} else {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ "upper(" + requestCustomer.get(customerDTOList.get(i).getField().toString()) + ") "
+ customerDTOList.get(i).getOperator() + " '%"
+ customerDTOList.get(i).getCondition().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%' ");
}
} else {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " "
+ customerDTOList.get(i).getCondition());
}
if ("not like".equals(customerDTOList.get(i).getOperator()) || "<>".equals(customerDTOList.get(i).getOperator())) {
sb.append(" or " + requestCustomer.get(customerDTOList.get(i).getField().toString()) + " is null");
}
sb.append(" )");
} else { // Field dong
switch (customerDTOList.get(i).getType()) {
case "combobox":
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;
case "text":
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 upper(cfo.value_text) " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
} 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("_", "\\_") + "'");
}
if ("not like".equals(customerDTOList.get(i).getOperator()) || "<>".equals(customerDTOList.get(i).getOperator())) {
sb.append(" or cfo.value_text is null ");
}
sb.append(" )");
break;
case "date":
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;
case "number":
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;
case "checkbox":
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;
}
}
}
SQLQuery query = session.createSQLQuery(sb.toString());
query.addScalar("name", new StringType());
query.addScalar("customerId", new LongType());
query.addScalar("mobileNumber", new StringType());
query.addScalar("email", new StringType());
query.addScalar("customerType", new LongType());
query.addScalar("companyName", new StringType());
query.addScalar("currentAddress", new StringType());
query.addScalar("description", new StringType());
query.setParameter("p_campaign_id", campaignCustomerDTO.getCampaignId());
query.setParameter("p_site_id", userSession.getSiteId());
query.setResultTransformer(Transformers.aliasToBean(CustomerDTO.class));
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
data = query.list();
} catch (Exception e) {
e.printStackTrace();
} finally {
session.close();
}
return data;
}
} }
...@@ -35,14 +35,10 @@ public interface CustomerService { ...@@ -35,14 +35,10 @@ public interface CustomerService {
ResultDTO updateCustomerList(CustomerListDTO customerListDTO, String userName); ResultDTO updateCustomerList(CustomerListDTO customerListDTO, String userName);
ResultDTO deleteCustomerList(CustomerListDTO customerListDTO);
ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO); ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO);
ResultDTO searchCustomerList(SearchCustomerListRequestDTO searchCustomerListRequestDTO); ResultDTO searchCustomerList(SearchCustomerListRequestDTO searchCustomerListRequestDTO);
CustomerList getLatestCreated(Long companySiteId);
// ------------ customer contact ------------ // // ------------ customer contact ------------ //
ResultDTO getCustomerContact(CustomerContactDTO customer); ResultDTO getCustomerContact(CustomerContactDTO customer);
......
...@@ -28,7 +28,7 @@ public interface ScenarioService { ...@@ -28,7 +28,7 @@ public interface ScenarioService {
XSSFWorkbook buildTemplate() throws IOException; XSSFWorkbook buildTemplate() throws IOException;
Map<String, Object> readAndValidateCustomer(String path, Long scenarioId, Long campaignId, Long companySiteId) throws IOException; Map<String, Object> readAndValidateScenario(String path, Long scenarioId, Long campaignId, Long companySiteId) throws IOException;
List<ContactQuestResult> getContactQuestResult(Long companySiteId, Long campaignId, Long customerId); List<ContactQuestResult> getContactQuestResult(Long companySiteId, Long campaignId, Long customerId);
} }
...@@ -383,14 +383,18 @@ public class CampaignCfgServiceImpl implements CampaignCfgService { ...@@ -383,14 +383,18 @@ public class CampaignCfgServiceImpl implements CampaignCfgService {
public ResultDTO getListStatus(String completeValue, Short completeType, Long companySiteId) { public ResultDTO getListStatus(String completeValue, Short completeType, Long companySiteId) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
List<CampaignCfg> list = new ArrayList<>(); List<CampaignCfg> list = new ArrayList<>();
CampaignCfg cfg = new CampaignCfg();
try { try {
if (completeValue == null || completeValue.equalsIgnoreCase("null")) if (completeValue == null || completeValue.equalsIgnoreCase("null"))
list = completeCodeRepository.getCustomerStatusByType(completeType, companySiteId); list = completeCodeRepository.getCustomerStatusByType(completeType, companySiteId);
else if (completeType == null)
cfg = completeCodeRepository.findByCompanySiteIdAndCompleteValue(companySiteId, completeValue);
else else
list = completeCodeRepository.getCustomerStatus(completeValue, completeType, companySiteId); list = completeCodeRepository.getCustomerStatus(completeValue, completeType, companySiteId);
resultDTO.setListData(list); resultDTO.setListData(list);
resultDTO.setData(cfg);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
......
...@@ -6,10 +6,7 @@ import com.viettel.campaign.model.ccms_full.*; ...@@ -6,10 +6,7 @@ import com.viettel.campaign.model.ccms_full.*;
import com.viettel.campaign.repository.acd_full.AgentsRepository; import com.viettel.campaign.repository.acd_full.AgentsRepository;
import com.viettel.campaign.repository.ccms_full.*; import com.viettel.campaign.repository.ccms_full.*;
import com.viettel.campaign.service.CampaignExecuteService; import com.viettel.campaign.service.CampaignExecuteService;
import com.viettel.campaign.utils.BundleUtils; import com.viettel.campaign.utils.*;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.DataUtil;
import com.viettel.campaign.utils.SQLBuilder;
import com.viettel.campaign.web.dto.*; import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CampaignCustomerListColumnRequestDTO; import com.viettel.campaign.web.dto.request_dto.CampaignCustomerListColumnRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO; import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
...@@ -88,6 +85,9 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -88,6 +85,9 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Autowired @Autowired
VSAUsersRepository vsaUsersRepository; VSAUsersRepository vsaUsersRepository;
@Autowired
CustomerTimeRepository customerTimeRepository;
public CampaignExecuteServiceImp() throws NoSuchAlgorithmException { public CampaignExecuteServiceImp() throws NoSuchAlgorithmException {
} }
...@@ -102,6 +102,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -102,6 +102,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(lst); resultDTO.setData(lst);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
return resultDTO; return resultDTO;
...@@ -117,6 +118,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -117,6 +118,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(lst); resultDTO.setData(lst);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
return resultDTO; return resultDTO;
...@@ -134,6 +136,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -134,6 +136,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
...@@ -241,7 +244,9 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -241,7 +244,9 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
++rowIndex; ++rowIndex;
++count; ++count;
} }
return workbook; return workbook;
} }
private void writeCellContent(Row row, CellStyle rowStyle, int colNo, Object content) { private void writeCellContent(Row row, CellStyle rowStyle, int colNo, Object content) {
...@@ -293,6 +298,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -293,6 +298,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setData(data); result.setData(data);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -327,7 +333,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -327,7 +333,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
} }
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -364,7 +370,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -364,7 +370,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS); result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -536,7 +542,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -536,7 +542,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setData(rclResult); result.setData(rclResult);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -570,7 +576,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -570,7 +576,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS); result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -585,14 +591,14 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -585,14 +591,14 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
try { try {
agentsRepository.updateAgentLogoutFromCampaign(dto.getAgentId().toString(), "AVAILABLE"); agentsRepository.updateAgentLogoutFromCampaign(dto.getAgentId().toString(), "AVAILABLE");
// update receive customer log // update receive customer log
ReceiveCustLog rcl = custLogRepository.getOne(dto.getReceiveCustLogId()); ReceiveCustLog rcl = custLogRepository.getByReceiveCustLogId(dto.getReceiveCustLogId());
rcl.setEndTime(new Date()); rcl.setEndTime(new Date());
rcl = custLogRepository.save(rcl); rcl = custLogRepository.save(rcl);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS); result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -604,10 +610,23 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -604,10 +610,23 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
public ResultDTO updateContactCustResult(ContactCustResultDTO dto, UserSession userSession) { public ResultDTO updateContactCustResult(ContactCustResultDTO dto, UserSession userSession) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
ContactCustResult ccr = new ContactCustResult(); ContactCustResult ccr = new ContactCustResult();
TimeZone tzClient = TimeZoneUtils.getZoneMinutes(dto.getTimezone());
try { try {
if (dto.getEventCall().equalsIgnoreCase("call")) { if (dto.getEventCall().equalsIgnoreCase("call")) {
ccr = ccResultRepository.save(modelMapper.map(dto, ContactCustResult.class)); ccr.setCompanySiteId(dto.getCompanySiteId());
ccr.setContactStatus((short) 2);
ccr.setStatus((short) 2);
ccr.setCreateTime(new Date());
ccr.setAgentId(dto.getAgentId());
ccr.setCampaignId(dto.getCampaignId());
ccr.setCustomerId(dto.getCustomerId());
ccr.setReceiveCustLogId(dto.getReceiveCustLogId());
ccr.setPhoneNumber(dto.getPhoneNumber());
ccr.setReceiveTime(new Date());
ccr.setIsFinalRecall((short) 1);
ccr.setDialMode("MANUAL");
ccr = ccResultRepository.save(ccr);
} }
if (dto.getContactCustResultId() != null) { if (dto.getContactCustResultId() != null) {
...@@ -622,17 +641,17 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -622,17 +641,17 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
if (dto.getEventCall().equalsIgnoreCase("ended")) { if (dto.getEventCall().equalsIgnoreCase("ended")) {
ccr.setDurationCall(dto.getDurationCall()); ccr.setDurationCall(dto.getDurationCall());
ccr.setStartCall(new Date(dto.getStartCallL() * 1000)); ccr.setStartCall(dto.getStartCallL() == null ? null : DateTimeUtil.parseDate("dd/MM/yyyy HH:mm:ss", TimeZoneUtils.toDateStringWithTimeZone(new Date(dto.getStartCallL() * 1000), tzClient)));
ccr.setReceiveTime(dto.getReceiveTime()); ccr.setReceiveTime(DateTimeUtil.parseDate("dd/MM/yyyy HH:mm:ss", TimeZoneUtils.toDateStringWithTimeZone(dto.getReceiveTime(), tzClient)));
ccr.setPreEndTime(ccResultRepository.getMaxCreateTime(dto.getCampaignId(), dto.getAgentId())); ccr.setPreEndTime(ccResultRepository.getMaxCreateTime(dto.getCampaignId(), dto.getAgentId()));
ccr.setEndTime(new Date(dto.getEndTime() * 1000)); ccr.setEndTime(dto.getEndTimeL() == null ? null : DateTimeUtil.parseDate("dd/MM/yyyy HH:mm:ss", TimeZoneUtils.toDateStringWithTimeZone(new Date(dto.getEndTimeL() * 1000), tzClient)));
ccr.setWaitTime(dto.getWaitTime()); ccr.setWaitTime(dto.getWaitTime());
ccr.setCallId(dto.getCallId()); ccr.setCallId(dto.getCallId());
ccr.setUpdateBy(userSession.getUserId()); ccr.setUpdateBy(userSession.getUserId());
ccr.setUpdateTime(new Date()); ccr.setUpdateTime(new Date());
ccr = ccResultRepository.save(ccr); ccr = ccResultRepository.save(ccr);
CampaignCustomer cc = campaignCustomerRepository.findCampaignCustomersByCampaignIdAndCustomerId(dto.getCampaignId(), dto.getCustomerId()); CampaignCustomer cc = campaignCustomerRepository.findCampaignCustomersByCampaignIdAndCustomerId(dto.getCampaignId(), dto.getCustomerId());
cc.setCallTime(new Date(dto.getStartCallL() * 1000)); cc.setCallTime(dto.getStartCallL() == null ? null : DateTimeUtil.parseDate("dd/MM/yyyy HH:mm:ss", TimeZoneUtils.toDateStringWithTimeZone(new Date(dto.getStartCallL() * 1000), tzClient)));
cc = campaignCustomerRepository.save(cc); cc = campaignCustomerRepository.save(cc);
Agents ag = agentsRepository.findByAgentId(dto.getAgentId().toString()); Agents ag = agentsRepository.findByAgentId(dto.getAgentId().toString());
ag.setSystemStatus("AVAILABLE"); ag.setSystemStatus("AVAILABLE");
...@@ -641,12 +660,37 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -641,12 +660,37 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
} }
if (dto.getEventCall().equalsIgnoreCase("endedBeforeTen") || dto.getEventCall().equalsIgnoreCase("endedAfterTen")) { if (dto.getEventCall().equalsIgnoreCase("endedBeforeTen") || dto.getEventCall().equalsIgnoreCase("endedAfterTen")) {
// update old contact customer result
ccr = ccResultRepository.findByContactCustResultId(dto.getOldContactCustResultId()); ccr = ccResultRepository.findByContactCustResultId(dto.getOldContactCustResultId());
ccr.setStatus(Short.parseShort("0")); ccr.setStatus(Short.parseShort("0"));
ccr.setUpdateBy(userSession.getUserId()); ccr.setUpdateBy(userSession.getUserId());
ccr.setUpdateTime(new Date()); ccr.setUpdateTime(new Date());
ccResultRepository.save(ccr); ccResultRepository.save(ccr);
ccr = ccResultRepository.save(modelMapper.map(dto, ContactCustResult.class)); // insert new contact customer result
ccr = new ContactCustResult();
ccr.setCompanySiteId(dto.getCompanySiteId());
ccr.setCallStatus(dto.getCallStatus());
ccr.setContactStatus(dto.getContactStatus());
ccr.setStatus((short) 1);
ccr.setDescription(dto.getDescription());
ccr.setAgentId(dto.getAgentId());
ccr.setCreateTime(new Date());
ccr.setOldContactCustResultId(dto.getOldContactCustResultId());
ccr.setCampaignId(dto.getCampaignId());
ccr.setCustomerId(dto.getCustomerId());
ccr.setDurationCall(dto.getDurationCall());
ccr.setStartCall(dto.getStartCallL() == null ? null : TimeZoneUtils.changeTimeZone(new Date(dto.getStartCallL() * 1000), 0L));
ccr.setCallId(dto.getCallId());
ccr.setEndTime(dto.getEndTimeL() == null ? null : TimeZoneUtils.changeTimeZone(new Date(dto.getEndTimeL() * 1000), 0L));
ccr.setWaitTime(dto.getWaitTime());
ccr.setReceiveCustLogId(dto.getReceiveCustLogId());
ccr.setPhoneNumber(dto.getPhoneNumber());
ccr.setReceiveTime(dto.getReceiveTime() == null ? null : TimeZoneUtils.changeTimeZone(dto.getReceiveTime(), 0L));
ccr.setRecallTime(dto.getRecallTime() == null ? null : TimeZoneUtils.changeTimeZone(dto.getRecallTime(), 0L));
ccr.setIsFinalRecall((short) 1);
ccr.setIsSendEmail((short) 0);
ccr.setDialMode("MANUAL");
ccr = ccResultRepository.save(ccr);
} }
/*if (dto.getEventCall().equalsIgnoreCase("endedAfterTen")) { /*if (dto.getEventCall().equalsIgnoreCase("endedAfterTen")) {
...@@ -659,7 +703,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -659,7 +703,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setData(ccr); result.setData(ccr);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -671,6 +715,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -671,6 +715,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
public ResultDTO draftAtTen(ContactCustResultDTO dto, UserSession userSession) { public ResultDTO draftAtTen(ContactCustResultDTO dto, UserSession userSession) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
ContactCustResult ccr = new ContactCustResult(); ContactCustResult ccr = new ContactCustResult();
TimeZone tzClient = TimeZoneUtils.getZoneMinutes(dto.getTimezone());
try { try {
ccResultRepository.deleteById(dto.getContactCustResultId()); ccResultRepository.deleteById(dto.getContactCustResultId());
...@@ -678,7 +723,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -678,7 +723,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
ccr.setCompanySiteId(dto.getCompanySiteId()); ccr.setCompanySiteId(dto.getCompanySiteId());
ccr.setCallStatus(dto.getCallStatus()); ccr.setCallStatus(dto.getCallStatus());
ccr.setContactStatus(dto.getContactStatus()); ccr.setContactStatus(dto.getContactStatus());
ccr.setStatus(dto.getStatus()); ccr.setStatus((short) 2);
ccr.setDescription(dto.getDescription()); ccr.setDescription(dto.getDescription());
ccr.setCreateTime(new Date()); ccr.setCreateTime(new Date());
ccr.setAgentId(dto.getAgentId()); ccr.setAgentId(dto.getAgentId());
...@@ -686,18 +731,18 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -686,18 +731,18 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
ccr.setUpdateBy(userSession.getUserId()); ccr.setUpdateBy(userSession.getUserId());
ccr.setCustomerId(dto.getCustomerId()); ccr.setCustomerId(dto.getCustomerId());
ccr.setDurationCall(dto.getDurationCall()); ccr.setDurationCall(dto.getDurationCall());
ccr.setStartCall(new Date(dto.getStartCallL() * 1000)); ccr.setStartCall(dto.getStartCallL() == null ? null : TimeZoneUtils.changeTimeZone(new Date(dto.getStartCallL() * 1000), 0L));
ccr.setReceiveCustLogId(dto.getReceiveCustLogId()); ccr.setReceiveCustLogId(dto.getReceiveCustLogId());
ccr.setCallId(dto.getCallId()); ccr.setCallId(dto.getCallId());
ccr.setPhoneNumber(dto.getPhoneNumber()); ccr.setPhoneNumber(dto.getPhoneNumber());
ccr.setReceiveTime(dto.getReceiveTime()); ccr.setReceiveTime(dto.getReceiveTime() == null ? null : TimeZoneUtils.changeTimeZone(dto.getReceiveTime(), 0L));
ccr.setPreEndTime(ccResultRepository.getMaxCreateTime(dto.getCampaignId(), dto.getAgentId())); ccr.setPreEndTime(ccResultRepository.getMaxCreateTime(dto.getCampaignId(), dto.getAgentId()));
ccr.setRecallTime(dto.getRecallTime()); ccr.setRecallTime(dto.getRecallTime() == null ? null : TimeZoneUtils.changeTimeZone(dto.getRecallTime(), 0L));
ccr.setIsFinalRecall(dto.getIsFinalRecall()); ccr.setIsFinalRecall((short) 1);
ccr.setIsSendEmail(dto.getIsSendEmail()); ccr.setIsSendEmail((short) 0);
ccr.setEndTime(new Date(dto.getEndTime() * 1000)); ccr.setEndTime(dto.getEndTimeL() == null ? null : TimeZoneUtils.changeTimeZone(new Date(dto.getEndTimeL() * 1000), 0L));
ccr.setWaitTime(dto.getWaitTime()); ccr.setWaitTime(dto.getWaitTime());
ccr.setDialMode(dto.getDialMode()); ccr.setDialMode("MANUAL");
ccr = ccResultRepository.save(ccr); ccr = ccResultRepository.save(ccr);
result.setErrorCode(Constants.ApiErrorCode.SUCCESS); result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
...@@ -705,7 +750,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -705,7 +750,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setData(ccr); result.setData(ccr);
System.out.println("remove:" + dto.getContactCustResultId() + "|new:" + ccr.getContactCustResultId()); System.out.println("remove:" + dto.getContactCustResultId() + "|new:" + ccr.getContactCustResultId());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -726,7 +771,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -726,7 +771,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setData(ccr); result.setData(ccr);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -740,13 +785,13 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -740,13 +785,13 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
ContactCustResult ccr = new ContactCustResult(); ContactCustResult ccr = new ContactCustResult();
try { try {
ccr = ccResultRepository.getOne(dto.getContactCustResultId()); ccr = ccResultRepository.findByContactCustResultId(dto.getContactCustResultId());
result.setErrorCode(Constants.ApiErrorCode.SUCCESS); result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setData(ccr); result.setData(ccr);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -759,7 +804,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -759,7 +804,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
try { try {
ContactCustResult ccr = ccResultRepository.getOne(dto.getContactCustResultId()); ContactCustResult ccr = ccResultRepository.findByContactCustResultId(dto.getContactCustResultId());
ccr.setDurationCall(0L); ccr.setDurationCall(0L);
ccr.setStartCall(new Date()); ccr.setStartCall(new Date());
ccr.setReceiveTime(new Date()); ccr.setReceiveTime(new Date());
...@@ -772,7 +817,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -772,7 +817,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
result.setDescription(Constants.ApiErrorDesc.SUCCESS); result.setDescription(Constants.ApiErrorDesc.SUCCESS);
result.setData(resultUpdate); result.setData(resultUpdate);
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace(); logger.error(e.getMessage());
result.setErrorCode(Constants.ApiErrorCode.ERROR); result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription(Constants.ApiErrorDesc.ERROR); result.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -833,6 +878,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -833,6 +878,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(data); resultDTO.setData(data);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -856,6 +902,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -856,6 +902,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(dataReturn); resultDTO.setListData(dataReturn);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -879,6 +926,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -879,6 +926,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(lstContactQuestResult); resultDTO.setListData(lstContactQuestResult);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -899,7 +947,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -899,7 +947,7 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
return lstTimeZone.getDialMode().toString(); return lstTimeZone.getDialMode().toString();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage());
} }
return "-1"; return "-1";
...@@ -910,10 +958,16 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -910,10 +958,16 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
ContactCustResult ccr = ccResultRepository.findByContactCustResultId(contactCustResultId);
ContactCustResultDTO dtoCCR = modelMapper.map(ccr, ContactCustResultDTO.class);
// if (dtoCCR.getCreateTime().)
// dtoCCR.setCheckUpdate(true);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(ccResultRepository.findById(contactCustResultId)); resultDTO.setData(ccr);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -924,18 +978,23 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -924,18 +978,23 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
@Override @Override
public ResultDTO updateCampaignCustomer(CampaignCustomerDTO dto) { public ResultDTO updateCampaignCustomer(CampaignCustomerDTO dto) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
TimeZone tzClient = TimeZoneUtils.getZoneMinutes(dto.getTimezone());
try { try {
CampaignCustomer cc = campaignCustomerRepository.findCampaignCustomersByCampaignIdAndCustomerId(dto.getCampaignId(), dto.getCustomerId()); CampaignCustomer cc = campaignCustomerRepository.findCampaignCustomersByCampaignIdAndCustomerId(dto.getCampaignId(), dto.getCustomerId());
cc.setStatus(dto.getStatus()); cc.setStatus(dto.getStatus());
cc.setAgentId(dto.getAgentId()); cc.setAgentId(dto.getAgentId());
cc.setRecallTime(dto.getRecallTime()); if (dto.getRecallTime() != null) {
cc.setRecallCount(cc.getRecallCount() + 1); cc.setRecallTime(dto.getRecallTime() == null ? null : TimeZoneUtils.changeTimeZone(dto.getRecallTime(), 0L));
cc.setCallTime(dto.getCallTime()); cc.setRecallCount(cc.getRecallCount() + 1);
}
cc.setCallTime(dto.getCallTimeL() == null ? null : TimeZoneUtils.changeTimeZone(new Date(dto.getCallTimeL() * 1000), 0L));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(cc); resultDTO.setData(cc);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
...@@ -948,29 +1007,42 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService { ...@@ -948,29 +1007,42 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
try { try {
CampaignCfg cfg = cfgRepository.findByCompanySiteIdAndCompleteValue(dto.getCompanySiteId(), dto.getCompleteValue()); CampaignCfg cfg = cfgRepository.findByCompanySiteIdAndCompleteValue(dto.getCompanySiteId(), dto.getCompleteValue());
if (cfg.getIsLock() == 1) { if (cfg != null && cfg.getIsLock() == 1) {
Customer c = customerRepository.getOne(dto.getCustomerId()); Customer c = customerRepository.getByCustomerId(dto.getCustomerId());
c.setIpccStatus("locked"); c.setIpccStatus("locked");
c = customerRepository.save(c); c = customerRepository.save(c);
} else { // insert CustomerTime
CustomerTime c = new CustomerTime(); CustomerTime ct = new CustomerTime();
c.setCompanySiteId(dto.getCompanySiteId()); ct.setCompanySiteId(dto.getCompanySiteId());
c.setCustomerId(dto.getCustomerId()); ct.setCustomerId(dto.getCustomerId());
c.setStartTime(dto.getStartTime()); ct.setStartTime(dto.getStartTime());
LocalDateTime ldt = dto.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().plusDays(cfg.getDurationLock()); LocalDateTime ldt = dto.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime().plusDays(cfg.getDurationLock());
c.setEndTime(Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant())); ct.setEndTime(Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()));
c.setStatus((short) 1); ct.setStatus((short) 1);
c.setCreateTime(new Date()); ct.setCreateTime(new Date());
c.setCreateBy(userSession.getUserId()); ct.setCreateBy(userSession.getUserId());
c.setUpdateTime(new Date()); ct.setUpdateTime(new Date());
c.setUpdateBy(userSession.getUserId()); ct.setUpdateBy(userSession.getUserId());
c.setContactCustResultId(dto.getContactCustResultId()); ct.setContactCustResultId(dto.getContactCustResultId());
customerTimeRepository.save(ct);
}
if (cfg != null && cfg.getIsLock() == 0) {
Customer c = customerRepository.getByCustomerId(dto.getCustomerId());
c.setIpccStatus("active");
c = customerRepository.save(c);
// insert CustomerTime
CustomerTime ct = customerTimeRepository.findByCompanySiteIdAndCustomerId(dto.getCompanySiteId(), dto.getCustomerId());
ct.setStatus((short) 0);
ct.setUpdateTime(new Date());
ct.setUpdateBy(userSession.getUserId());
customerTimeRepository.save(ct);
} }
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setData(null); resultDTO.setData(null);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage());
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} }
......
...@@ -342,39 +342,6 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -342,39 +342,6 @@ public class CustomerServiceImpl implements CustomerService {
return resultDTO; return resultDTO;
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO deleteCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO();
List<Long> ids = new ArrayList<>();
ids.add(customerListDTO.getCustomerListId());
try {
// delete
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) {
if (customerListRepository.findAllCustomerList(ids, customerListDTO.getCompanySiteId()).size() > 0) {
customerListRepository.deleteCustomerList(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.DELETE_ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.DELETE_ERROR);
}
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) {
// e.printStackTrace();
}
return resultDTO;
}
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO) { public ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO) {
...@@ -437,12 +404,6 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -437,12 +404,6 @@ public class CustomerServiceImpl implements CustomerService {
return resultDTO; return resultDTO;
} }
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public CustomerList getLatestCreated(Long companySiteId) {
return customerListRepository.latestCreated(companySiteId);
}
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCustomerContact(CustomerContactDTO customer) { public ResultDTO getCustomerContact(CustomerContactDTO customer) {
...@@ -1421,63 +1382,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1421,63 +1382,7 @@ public class CustomerServiceImpl implements CustomerService {
public List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO) { public List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO) {
List<CustomerListDTO> customerList; List<CustomerListDTO> customerList;
try { try {
//String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-customer-list-info-from-customer-list"); customerList = customerRepository.getCustomerListInfo(campaignCustomerDTO);
// BuildMyString.com generated code. Please enjoy your string responsibly.
StringBuilder sb = new StringBuilder();
sb.append(" with totalCustomer as (");
sb.append(" select clm.customer_list_id,");
sb.append(" clm.company_site_id,");
sb.append(" count(clm.customer_id) total");
sb.append(" from customer_list_mapping clm");
sb.append(" inner join customer c on clm.customer_id = c.customer_id");
sb.append(" where c.status = 1");
sb.append(" group by clm.customer_list_id,clm.company_site_id");
sb.append(" ), customerInteractive as (");
sb.append(" select customer_list_id,");
sb.append(" company_site_id,");
sb.append(" count(customer_id) tt");
sb.append(" from campaign_customer where campaign_id = :p_campaign_id and status <> 0");
sb.append(" group by customer_list_id, company_site_id");
sb.append(" ), customerNotInteractive as (");
sb.append(" select customer_list_id,");
sb.append(" company_site_id,");
sb.append(" count(customer_id) ktt");
sb.append(" from campaign_customer where campaign_id = :p_campaign_id and status = 0");
sb.append(" and in_campaign_status = 1");
sb.append(" group by customer_list_id, company_site_id");
sb.append(" ), datas as (");
sb.append(" select customer_list_code customerListCode,");
sb.append(" customer_list_name customerListName,");
sb.append(" nvl(total, 0) totalCusInList,");
sb.append(" nvl(tt, 0) totalCusInteract,");
sb.append(" nvl(ktt, 0) totalCusNotInteract");
sb.append(" from customer_list cl");
sb.append(" left join totalCustomer tc on (cl.customer_list_id = tc.customer_list_id and cl.company_site_id = tc.company_site_id)");
sb.append(" left join customerInteractive ci on (cl.customer_list_id = ci.customer_list_id and cl.company_site_id = ci.company_site_id)");
sb.append(" left join customerNotInteractive cni on (cl.customer_list_id = cni.customer_list_id and cl.company_site_id = cni.company_site_id)");
sb.append(" where cl.company_site_id = :p_company_site_id");
sb.append(" )");
sb.append(" select * from");
sb.append(" (");
sb.append(" select a.*, rownum r__");
sb.append(" from");
sb.append(" (");
sb.append(" select * from datas");
sb.append(" order by customerListCode");
sb.append(" ) a");
sb.append(" where rownum < ((:p_page_number * :p_page_size) + 1 )");
sb.append(" )");
sb.append(" where r__ >= (((:p_page_number-1) * :p_page_size) + 1)");
Map<String, Object> param = new HashMap<>();
param.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
param.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
param.put("p_page_number", campaignCustomerDTO.getPage());
param.put("p_page_size", campaignCustomerDTO.getPageSize());
customerList = namedParameterJdbcTemplate.query(sb.toString(), param, new BeanPropertyRowMapper<>(CustomerListDTO.class));
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
...@@ -1487,69 +1392,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1487,69 +1392,9 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public List<CustomerDTO> getIndividualCustomerInfo(CampaignCustomerDTO campaignCustomerDTO) { public List<CustomerDTO> getIndividualCustomerInfo(CampaignCustomerDTO campaignCustomerDTO) {
List<CustomerDTO> customerList; List<CustomerDTO> customerList = new ArrayList<>();
try { try {
//String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-individual-customer"); customerList = customerRepository.getIndividualCustomerInfo(campaignCustomerDTO);
// BuildMyString.com generated code. Please enjoy your string responsibly.
StringBuilder sb = new StringBuilder();
sb.append("with cusPhone as (");
sb.append(" select customer_id cusId,");
sb.append(" listagg(contact, ', ') within group (order by create_date desc) phone");
sb.append(" from customer_contact cc");
sb.append(" where cc.contact_type = 5");
sb.append(" and status = 1 ");
sb.append(" group by customer_id");
sb.append(" ), cusEmail as (");
sb.append(" select customer_id cusId,");
sb.append(" listagg(contact , ', ') within group(order by create_date desc) email");
sb.append(" from customer_contact cc");
sb.append(" where cc.contact_type = 2");
sb.append(" and status = 1 ");
sb.append(" group by customer_id");
sb.append(" )," +
"cusInCampaign as (" +
"select * from campaign_customer " +
"where campaign_id = :p_campaign_id " +
"and company_site_id = :p_company_site_id " +
"and customer_list_id is null " +
"and in_campaign_status = 1");
sb.append(" ), datas as (");
sb.append(" select c.customer_id customerId,");
sb.append(" c.name,");
sb.append(" cP.phone mobileNumber,");
sb.append(" cE.email,");
sb.append(" c.customer_type customerType,");
sb.append(" c.company_name companyName,");
sb.append(" c.current_address currentAddress,");
sb.append(" c.description,");
sb.append(" c.ipcc_status ipccStatus,");
sb.append(" c.call_allowed customerDnc");
sb.append(" from customer c");
sb.append(" inner join cusInCampaign cc on c.customer_id = cc.customer_id");
sb.append(" left join cusPhone cP on c.customer_id = cP.cusId");
sb.append(" left join cusEmail cE on c.customer_id = cE.cusId");
sb.append(" )");
sb.append(" select * from");
sb.append(" (");
sb.append(" select a.*, rownum r__");
sb.append(" from");
sb.append(" (");
sb.append(" select * from datas");
sb.append(" order by UPPER(datas.name)");
sb.append(" ) a");
sb.append(" where rownum < ((:p_page_number * :p_page_size) + 1 )");
sb.append(" )");
sb.append(" where r__ >= (((:p_page_number-1) * :p_page_size) + 1)");
Map<String, Object> param = new HashMap<>();
param.put("p_page_number", campaignCustomerDTO.getPage());
param.put("p_page_size", campaignCustomerDTO.getPageSize());
param.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
param.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
customerList = namedParameterJdbcTemplate.query(sb.toString(), param, new BeanPropertyRowMapper<>(CustomerDTO.class));
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
return null; return null;
...@@ -1591,30 +1436,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1591,30 +1436,8 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO searchCampaignInformation(CampaignCustomerDTO campaignCustomerDTO) { public ResultDTO searchCampaignInformation(CampaignCustomerDTO campaignCustomerDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
List<CampaignInformationDTO> list = new ArrayList<>(); List<CampaignInformationDTO> list = customerRepository.getCampaignInformation(campaignCustomerDTO);
Map<String, Object> params = new HashMap<>();
try { try {
StringBuilder sb = new StringBuilder();
sb.append(" with count_customer as (");
sb.append(" select campaign_id campaignId,");
sb.append(" sum(case");
sb.append(" when customer_list_id is null then 1");
sb.append(" else 0");
sb.append(" end) totalIndividual,");
sb.append(" sum(case");
sb.append(" when customer_list_id is not null then 1");
sb.append(" else 0");
sb.append(" end) totalCusInList");
sb.append(" from campaign_customer");
sb.append(" group by campaign_id");
sb.append(" )");
sb.append(" select b.campaign_id campaignId, nvl(totalIndividual, 0) totalIndividual, nvl(totalCusInList, 0) totalCusInList, b.customer_number campaignCustomer");
sb.append(" from campaign b");
sb.append(" left join count_customer a on a.campaignId = b.campaign_id");
sb.append(" where b.campaign_id = :p_campaign_id");
params.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
params.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sb.toString(), params, BeanPropertyRowMapper.newInstance(CampaignInformationDTO.class));
if (list.size() > 0) { if (list.size() > 0) {
resultDTO.setData(list.get(0)); resultDTO.setData(list.get(0));
} else { } else {
...@@ -1797,195 +1620,10 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1797,195 +1620,10 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO searchCustomizeFields(CampaignCustomerDTO campaignCustomerDTO, UserSession userSession) { public ResultDTO searchCustomizeFields(CampaignCustomerDTO campaignCustomerDTO, UserSession userSession) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Map<String, String> requestCustomer = new HashMap<>();
requestCustomer.put("-1", "c.code");
requestCustomer.put("-2", "c.name");
requestCustomer.put("-3", "c.company_name");
requestCustomer.put("-4", "c.gender");
requestCustomer.put("-5", "c.current_address");
requestCustomer.put("-6", "c.place_of_birth");
requestCustomer.put("-7", "c.date_of_birth");
requestCustomer.put("-8", "cc.contact");
requestCustomer.put("-9", "cc2.contact");
requestCustomer.put("-10", "c.username");
requestCustomer.put("-11", "c.customer_type");
requestCustomer.put("-12", "c.area_code");
requestCustomer.put("-13", "c.call_allowed");
requestCustomer.put("-14", "c.email_allowed");
requestCustomer.put("-15", "c.sms_allowed");
requestCustomer.put("-16", "c.ipcc_status");
try { try {
StringBuilder sb = new StringBuilder(); int count = customerRepository.getCustomizeFields(campaignCustomerDTO, userSession, null).size();
List<CustomerDTO> data = customerRepository.getCustomizeFields(campaignCustomerDTO, userSession, SQLBuilder.buildPageable(campaignCustomerDTO));
sb.append("select distinct c.customer_id customerId,"); resultDTO.setListData(data);
sb.append(" C.NAME name,");
sb.append(" cc.CONTACT mobileNumber,");
sb.append(" cc2.CONTACT email,");
sb.append(" c.customer_type customerType,");
sb.append(" C.COMPANY_NAME companyName,");
sb.append(" c.current_address currentAddress,");
sb.append(" c.Description description");
sb.append(" FROM CUSTOMER C");
sb.append(" left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY ");
sb.append(" NULL) AS CONTACT");
sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 AND STATUS = 1 GROUP BY ");
sb.append(" CUSTOMER_ID) cc on c.CUSTOMER_ID = cc.CUSTOMER_ID");
sb.append(" left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY ");
sb.append(" NULL) AS CONTACT");
sb.append(" FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 AND STATUS = 1 GROUP BY ");
sb.append(" CUSTOMER_ID) cc2 on cc2.CUSTOMER_ID = c.CUSTOMER_ID ");
sb.append(" left 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.customer_id not in (select customer_id from campaign_customer where campaign_id = :p_campaign_id) ");
sb.append(" where 1 = 1 AND C.STATUS = 1 AND C.SITE_ID = :p_site_id ");
List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery();
if (customerDTOList.get(0).getField() > 0) {// field dong
switch (customerDTOList.get(0).getType()) {
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() + ")");
break;
case "text":
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 upper(cfo.value_text) " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
} else {
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "'");
}
if ("not like".equals(customerDTOList.get(0).getOperator()) || "<>".equals(customerDTOList.get(0).getOperator())) {
sb.append(" or cfo.value_text is null");
}
sb.append(" )");
break;
case "date":
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;
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() + ")");
break;
case "checkbox":
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;
}
} else {// field tinh
if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
sb.append("and (upper(" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + ") " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
} 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 if ("text".equals(customerDTOList.get(0).getType())) {
if ("=".equals(customerDTOList.get(0).getOperator()) || "<>".equals(customerDTOList.get(0).getOperator())) {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " '" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "'");
} else {
sb.append("and (upper(" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + ") " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
}
} else {
sb.append("and (" + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition());
}
if ("<>".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
sb.append(" or " + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " is null ");
}
sb.append(" )");
}
for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) {
if (customerDTOList.get(i).getField() < 0) { //Field tinh
if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ "upper(" + requestCustomer.get(customerDTOList.get(i).getField().toString()) + ") "
+ customerDTOList.get(i).getOperator() + " "
+ "'%" + customerDTOList.get(i).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%' ");
} 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("_", "\\_").toUpperCase() + "%' ");
} else if ("text".equals(customerDTOList.get(i).getType())) {
if ("=".equals(customerDTOList.get(i).getOperator()) || "<>".equals(customerDTOList.get(i).getOperator())) {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " '"
+ customerDTOList.get(i).getCondition().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_") + "' ");
} else {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ "upper(" + requestCustomer.get(customerDTOList.get(i).getField().toString()) + ") "
+ customerDTOList.get(i).getOperator() + " '%"
+ customerDTOList.get(i).getCondition().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%' ");
}
} else {
sb.append(" " + customerDTOList.get(i).getJoin() + " ("
+ requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
+ customerDTOList.get(i).getOperator() + " "
+ customerDTOList.get(i).getCondition());
}
if ("not like".equals(customerDTOList.get(i).getOperator()) || "<>".equals(customerDTOList.get(i).getOperator())) {
sb.append(" or " + requestCustomer.get(customerDTOList.get(i).getField().toString()) + " is null");
}
sb.append(" )");
} else { // Field dong
switch (customerDTOList.get(i).getType()) {
case "combobox":
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;
case "text":
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 upper(cfo.value_text) " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition().trim().replace("\\", "\\\\").replaceAll("%", "\\%").replaceAll("_", "\\_").toUpperCase() + "%'");
} 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("_", "\\_") + "'");
}
if ("not like".equals(customerDTOList.get(i).getOperator()) || "<>".equals(customerDTOList.get(i).getOperator())) {
sb.append(" or cfo.value_text is null ");
}
sb.append(" )");
break;
case "date":
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;
case "number":
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;
case "checkbox":
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;
}
}
}
SQLQuery query = session.createSQLQuery(sb.toString());
query.addScalar("name", new StringType());
query.addScalar("customerId", new LongType());
query.addScalar("mobileNumber", new StringType());
query.addScalar("email", new StringType());
query.addScalar("customerType", new LongType());
query.addScalar("companyName", new StringType());
query.addScalar("currentAddress", new StringType());
query.addScalar("description", new StringType());
query.setParameter("p_campaign_id", campaignCustomerDTO.getCampaignId());
query.setParameter("p_site_id", userSession.getSiteId());
query.setResultTransformer(Transformers.aliasToBean(CustomerDTO.class));
int count = 0;
List<CustomerDTO> dtoList = query.list();
if (dtoList.size() > 0) {
count = query.list().size();
}
Pageable pageable = PageRequest.of(campaignCustomerDTO.getPage(), campaignCustomerDTO.getPageSize());
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<CustomerDTO> data = query.list();
Page<CustomerDTO> dataPage = new PageImpl<>(data, pageable, count);
resultDTO.setData(dataPage);
resultDTO.setTotalRow(count); resultDTO.setTotalRow(count);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
...@@ -1993,10 +1631,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1993,10 +1631,7 @@ public class CustomerServiceImpl implements CustomerService {
LOGGER.error(e.getMessage(), e); LOGGER.error(e.getMessage(), e);
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally {
session.close();
} }
return resultDTO; return resultDTO;
} }
......
...@@ -80,7 +80,6 @@ public class ScenarioQuestionServiceImpl implements ScenarioQuestionService { ...@@ -80,7 +80,6 @@ public class ScenarioQuestionServiceImpl implements ScenarioQuestionService {
if (scenarioQuestionDTO.getLstAnswers().size() > 0) { if (scenarioQuestionDTO.getLstAnswers().size() > 0) {
lstAnswers = scenarioQuestionDTO.getLstAnswers(); lstAnswers = scenarioQuestionDTO.getLstAnswers();
lstAnswers.forEach(item -> { lstAnswers.forEach(item -> {
item.setCode(scenarioQuestion.getCode() + "_" + item.getOrderIndex());
item.setScenarioQuestionId(scenarioQuestion.getScenarioQuestionId()); item.setScenarioQuestionId(scenarioQuestion.getScenarioQuestionId());
item.setCreateTime(new Date()); item.setCreateTime(new Date());
item.setStatus((short) 1); item.setStatus((short) 1);
......
...@@ -254,7 +254,7 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -254,7 +254,7 @@ public class ScenarioServiceImpl implements ScenarioService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public Map<String, Object> readAndValidateCustomer (String path, Long scenarioId, Long campaignId, Long companySiteId) throws IOException{ public Map<String, Object> readAndValidateScenario (String path, Long scenarioId, Long campaignId, Long companySiteId) throws IOException{
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
...@@ -551,6 +551,7 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -551,6 +551,7 @@ public class ScenarioServiceImpl implements ScenarioService {
lstQuestions.forEach(q2 -> { lstQuestions.forEach(q2 -> {
List<ScenarioAnswerDTO> lstAnswers = q2.getLstAnswers(); List<ScenarioAnswerDTO> lstAnswers = q2.getLstAnswers();
lstAnswers.forEach(a2 -> { lstAnswers.forEach(a2 -> {
a2.setCode(q2.getCode() + "_" + a2.getOrderIndex());
ScenarioQuestionDTO mappingQuestion = lstQuestions.stream().filter(mq -> mq.getImportCode().equals(a2.getMappingQuestionCode())).findFirst().orElse(null); ScenarioQuestionDTO mappingQuestion = lstQuestions.stream().filter(mq -> mq.getImportCode().equals(a2.getMappingQuestionCode())).findFirst().orElse(null);
if (mappingQuestion != null) { if (mappingQuestion != null) {
a2.setMappingQuestionCode(mappingQuestion.getCode()); a2.setMappingQuestionCode(mappingQuestion.getCode());
......
...@@ -18,6 +18,7 @@ public class CampaignCustomerDTO extends BaseDTO{ ...@@ -18,6 +18,7 @@ public class CampaignCustomerDTO extends BaseDTO{
private Date recallTime; private Date recallTime;
private Long recallCount = 0L; private Long recallCount = 0L;
private Date callTime; private Date callTime;
private Long callTimeL;
private Long customerListId; private Long customerListId;
private Short inCampaignStatus; private Short inCampaignStatus;
private Date sendTime; private Date sendTime;
......
...@@ -40,7 +40,8 @@ public class ContactCustResultDTO extends BaseDTO { ...@@ -40,7 +40,8 @@ public class ContactCustResultDTO extends BaseDTO {
private Short isFinalRecall; private Short isFinalRecall;
private Short isSendEmail = 0; private Short isSendEmail = 0;
private Long saledOnTpin; private Long saledOnTpin;
private Long endTime; // api get call return Long private Long endTimeL; // api get call return Long
private Date endTime;
// private Date endTime; // private Date endTime;
private Long waitTime; private Long waitTime;
private String dialMode; private String dialMode;
...@@ -59,4 +60,5 @@ public class ContactCustResultDTO extends BaseDTO { ...@@ -59,4 +60,5 @@ public class ContactCustResultDTO extends BaseDTO {
private Integer totalRow; private Integer totalRow;
private String eventCall; private String eventCall;
private Boolean checkUpdate = false;
} }
...@@ -107,14 +107,6 @@ public class CustomerController { ...@@ -107,14 +107,6 @@ public class CustomerController {
return customerService.updateCustomerList(customerListDTO, userSession.getUserName()); return customerService.updateCustomerList(customerListDTO, userSession.getUserName());
} }
@PostMapping("/deleteCustomerList")
@ResponseBody
public ResultDTO deleteCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO) {
ResultDTO result = new ResultDTO();
result = customerService.deleteCustomerList(customerListDTO);
return result;
}
@PostMapping("/deleteCustomerListIds") @PostMapping("/deleteCustomerListIds")
@ResponseBody @ResponseBody
public ResultDTO deleteCustomerListIds(@RequestBody @Valid CustomerRequestDTO customerRequestDTO) { public ResultDTO deleteCustomerListIds(@RequestBody @Valid CustomerRequestDTO customerRequestDTO) {
...@@ -129,14 +121,6 @@ public class CustomerController { ...@@ -129,14 +121,6 @@ public class CustomerController {
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
@GetMapping("/latestCreated")
@ResponseBody
public ResponseEntity getLatestCreated(@RequestParam("companySiteId") Long companySiteId) {
ResultDTO result = new ResultDTO();
result.setData(customerService.getLatestCreated(companySiteId));
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/findCustomerContact") @PostMapping("/findCustomerContact")
@ResponseBody @ResponseBody
public ResponseEntity<ResultDTO> findAllCustomerContact(@RequestBody CustomerContactDTO customerContactDTO) { public ResponseEntity<ResultDTO> findAllCustomerContact(@RequestBody CustomerContactDTO customerContactDTO) {
......
...@@ -118,7 +118,7 @@ public class ScenarioController { ...@@ -118,7 +118,7 @@ public class ScenarioController {
return new ResponseEntity<>(BundleUtils.getLangString("common.fileInvalidFormat", locale), HttpStatus.OK); return new ResponseEntity<>(BundleUtils.getLangString("common.fileInvalidFormat", locale), HttpStatus.OK);
} }
String path = saveUploadFile(file); String path = saveUploadFile(file);
Map<String, Object> map = scenarioService.readAndValidateCustomer(path, scenarioId, campaignId, userSession.getCompanySiteId()); Map<String, Object> map = scenarioService.readAndValidateScenario(path, scenarioId, campaignId, userSession.getCompanySiteId());
String code = (String) map.get("code"); String code = (String) map.get("code");
byte[] content = (byte[]) map.get("content"); byte[] content = (byte[]) map.get("content");
return ResponseEntity.ok() return ResponseEntity.ok()
......
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