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

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

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