Commit b3b96cc4 authored by Phạm Duy Phi's avatar Phạm Duy Phi

phipd commit merge

parent bc43ea80
No preview for this file type
......@@ -4,3 +4,4 @@ logs/
out/
/campaign.iml
/lib
/log
package com.viettel.campaign.job;
import com.viettel.campaign.model.ccms_full.Campaign;
import com.viettel.campaign.model.ccms_full.Customer;
import com.viettel.campaign.model.ccms_full.CustomerTime;
import com.viettel.campaign.model.ccms_full.ProcessConfig;
import com.viettel.campaign.service.CampaignService;
import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.service.CustomerTimeService;
import com.viettel.campaign.service.ProcessConfigService;
import com.viettel.campaign.model.ccms_full.*;
import com.viettel.campaign.service.*;
import com.viettel.campaign.utils.DateTimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -42,68 +36,75 @@ public class CampaignJob {
@Autowired
private CustomerService customerService;
@Autowired
private UserActionLogService userActionLogService;
// @Scheduled(fixedRate = 5000)
// @Transactional( propagation = Propagation.REQUIRED)
public void process() {
log.info(Thread.currentThread().getName() + " The Task executed at " + dateFormat.format(new Date()));
List<ProcessConfig> list = processConfigService.findAll();
list.parallelStream().forEach(p -> {
boolean isExecute = DateTimeUtil.isRun(p.getConfigValue(), p.getLastProcess());
switch (p.getConfigCode()){
case CUSTOMER_INACTIVE_DUARATION:
if(isExecute){
List<Customer> customers = customerService.findAllByCondition(p.getSiteId(), new Date());
updateCustomer(customers);
updateCustomerTime(customers);
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
p.setLastProcess(new Date());
processConfigService.update(p);
}
break;
case CRON_EXPRESSION_CHECK_START:
// process
if(isExecute){
List<Long> status = new ArrayList<>();
status.add(1L);
status.add(1L);
List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
campaigns.parallelStream().forEach(campaign -> {
log.info("Chuyen trang thai chien dich ... #{} ... tu Du thao sang Trien khai", campaign.getCampaignId());
campaign.setProcessStatus(1);
campaign.setStatus(2L);
campaign.setCampaignStart(new Date());
campaignService.updateProcess(campaign);
});
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
p.setLastProcess(new Date());
processConfigService.update(p);
}
break;
case CRON_EXPRESSION_CHECK_END:
// process
if(isExecute){
List<Long> status = new ArrayList<>();
status.add(2L);
status.add(3L);
List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
campaigns.parallelStream().forEach(campaign -> {
log.info("Chuyen trang thai chien dich ... #{} ... sang Ket thuc", campaign.getCampaignId());
campaign.setStatus(4L);
campaign.setCampaignEnd(new Date());
campaignService.updateProcess(campaign);
});
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
p.setLastProcess(new Date());
processConfigService.update(p);
}
break;
default:
// update last check time
}
});
// log.info(Thread.currentThread().getName() + " The Task executed at " + dateFormat.format(new Date()));
// List<ProcessConfig> list = processConfigService.findAll();
//
// list.parallelStream().forEach(p -> {
// boolean isExecute = DateTimeUtil.isRun(p.getConfigValue(), p.getLastProcess());
// switch (p.getConfigCode()){
// case CUSTOMER_INACTIVE_DUARATION:
// if(isExecute){
// List<Customer> customers = customerService.findAllByCondition(p.getSiteId(), new Date());
// updateCustomer(customers);
// updateCustomerTime(customers);
// log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
// p.setLastProcess(new Date());
// processConfigService.update(p);
// }
// break;
// case CRON_EXPRESSION_CHECK_START:
// // process
// if(isExecute){
// List<Long> status = new ArrayList<>();
// status.add(1L);
// status.add(1L);
// List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
// campaigns.parallelStream().forEach(campaign -> {
// log.info("Chuyen trang thai chien dich ... #{} ... tu Du thao sang Trien khai", campaign.getCampaignId());
// campaign.setProcessStatus(1);
// campaign.setStatus(2L);
// campaign.setCampaignStart(new Date());
// campaignService.updateProcess(campaign);
// //write log
// saveLog(campaign, 1);
// });
//
// log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
// p.setLastProcess(new Date());
// processConfigService.update(p);
// }
// break;
// case CRON_EXPRESSION_CHECK_END:
// // process
// if(isExecute){
// List<Long> status = new ArrayList<>();
// status.add(2L);
// status.add(3L);
// List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
// campaigns.parallelStream().forEach(campaign -> {
// log.info("Chuyen trang thai chien dich ... #{} ... sang Ket thuc", campaign.getCampaignId());
// campaign.setStatus(4L);
// campaign.setCampaignEnd(new Date());
// campaignService.updateProcess(campaign);
// //write log
// saveLog(campaign, 2);
// });
//
// log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
// p.setLastProcess(new Date());
// processConfigService.update(p);
// }
// break;
// default:
// // update last check time
// }
// });
}
......@@ -129,5 +130,16 @@ public class CampaignJob {
});
}
private void saveLog(Campaign c, int t){
UserActionLog log = new UserActionLog();
log.setAgentId(1L);
log.setSessionId("-1");
log.setStartTime(new Date());
log.setActionType(t == 1 ? 13L : 14L);
log.setObjectId(c.getCampaignId());
log.setCompanySiteId(c.getCompanySiteId());
userActionLogService.save(log);
}
}
......@@ -5,15 +5,18 @@ import lombok.Setter;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name = "CUSTOMER_CONTACT")
@Getter
@Setter
public class CustomerContact {
public class CustomerContact implements Serializable {
@Id
@Basic(optional = false)
@GeneratedValue(generator = "customer_contact_seq", strategy = GenerationType.IDENTITY)
@SequenceGenerator(name = "customer_contact_seq", sequenceName = "customer_contact_seq", allocationSize = 1)
@NotNull
@Column(name = "CONTACT_ID")
private Long contactId;
......
package com.viettel.campaign.model.ccms_full;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* @author hanv_itsol
* @project campaign
*/
@Entity
@Table(name = "USER_ACTION_LOG")
@Data
public class UserActionLog implements Serializable {
@Id
@NotNull
@Column(name = "AGENT_ID")
private Long agentId;
@Column(name = "COMPANY_SITE_ID")
private Long companySiteId;
@Column(name = "SESSION_ID")
private String sessionId;
@Column(name = "START_TIME")
private Date startTime;
@Column(name = "END_TIME")
private Date endTime;
@Column(name = "ACTION_TYPE")
private Long actionType;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "OBJECT_ID")
private Long objectId;
}
......@@ -17,5 +17,5 @@ public interface AgentsRepository extends JpaRepository<Agents, String> {
@Modifying
@Query(value = "UPDATE Agents SET campaignSystemStatus = :campaignSystemStatus WHERE agentId = :agentId")
void updateAgentLogoutFromCampaign(@Param("agentId") Long agentId, @Param("campaignSystemStatus") String campaignSystemStatus);
void updateAgentLogoutFromCampaign(@Param("agentId") String agentId, @Param("campaignSystemStatus") String campaignSystemStatus);
}
package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignCustomerListColumn;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Repository
@Transactional(DataSourceQualify.CCMS_FULL)
public interface CampaignCustomerListColumnRepository extends JpaRepository<CampaignCustomerListColumn, Long> {
List<CampaignCustomerListColumn> findByCampaignIdAndCompanySiteId(Long campaignId, Long companaySiteId);
CampaignCustomerListColumn findByCampaignCusListColId(Long campaignCusListColId);
}
......@@ -14,4 +14,6 @@ public interface CampaignCustomerListRepository extends JpaRepository<CampaignCu
@Query("select count (c.campaignId) from CampaignCustomerList c where c.customerListId in (:ids)")
Long campaignIdsCount(@Param("ids") List<Long> ids);
void deleteCampaignCustomerListByCampaignIdAndCustomerListIdAndCompanySiteId(Long campaignId, Long customerListId, Long companySiteId);
}
......@@ -35,4 +35,20 @@ public interface CampaignCustomerRepository extends JpaRepository<CampaignCustom
Long getCustomerRecall(@Param("campaignId") Long campaignId, @Param("customerId") Long customerId);
CampaignCustomer findCampaignCustomerByCampaignCustomerId(Long id);
@Query(value = "SELECT * FROM CAMPAIGN_CUSTOMER CC " +
"WHERE CC.STATUS = 0 " +
"AND CC.CAMPAIGN_ID = :campaignId " +
"AND CC.COMPANY_SITE_ID = :companySiteId " +
"AND CC.CUSTOMER_LIST_ID = :customerListId", nativeQuery = true)
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)" +
"AND CC.CAMPAIGN_ID = :campaignId " +
"AND CC.COMPANY_SITE_ID = :companySiteId " +
"AND CC.CUSTOMER_LIST_ID = :customerListId", nativeQuery = true)
List<CampaignCustomer> findCustomerContacted(@Param("campaignId") Long campaignId, @Param("companySiteId") Long companySiteId, @Param("customerListId") Long customerListId);
}
......@@ -18,14 +18,19 @@ public interface CampaignRepositoryCustom {
ResultDTO checkAllowStatusToPrepare(Long campaignId);
//hungtt
//<editor-fold: hungtt>
ResultDTO findCustomerListReallocation(CampaignRequestDTO dto);
//hungtt
ResultDTO reallocationCustomer(CampaignRequestDTO dto);
//hungtt
ResultDTO getListFieldsNotShow(CampaignRequestDTO dto);
//hungtt
ResultDTO getListFieldsToShow(CampaignRequestDTO dto);
//hungtt
ResultDTO getCampaignCustomerList(CampaignRequestDTO dto);
ResultDTO getCustomerList(CampaignRequestDTO dto);
ResultDTO getCustomerChoosenList(CampaignRequestDTO dto);
//</editor-fold>
}
......@@ -12,5 +12,5 @@ public interface CustomerContactRepository extends JpaRepository<CustomerContact
@Query("FROM CustomerContact WHERE status = 1 AND customerId = :customerId AND contactType = :contactType AND (contact IS NULL OR UPPER(contact) LIKE UPPER(concat('%', :contact, '%')))")
List<CustomerContact> findByCustomerIdAndAndContactTypeAndContact(@Param("customerId") Long customerId, @Param("contactType") Short contactType, @Param("contact") String contact, Pageable pageable);
CustomerContact findCustomerContactByContactTypeAndContactAndIsDirectLine(Short contactType, String contact, Short isDirectLine);
CustomerContact findCustomerContactByContactEquals(String contact);
}
......@@ -24,4 +24,7 @@ public interface ScenarioAnswerRepository extends JpaRepository<ScenarioAnswer,
Integer deleteScenarioAnswersByScenarioQuestionId(Long scenarioQuestionId);
ScenarioAnswer findScenarioAnswerByScenarioAnswerId(Long scenarioAnswerId);
@Query(value = "SELECT COUNT(1) FROM ScenarioAnswer WHERE 1 = 1 AND code = :code AND scenarioQuestionId = :scenarioQuestionId AND scenarioAnswerId <> :scenarioAnswerId")
Integer countDuplicateScenarioCode(@Param("code") String code, @Param("scenarioQuestionId") Long scenarioQuestionId, @Param("scenarioAnswerId") Long scenarioAnswerId);
}
......@@ -9,4 +9,6 @@ import com.viettel.campaign.web.dto.ScenarioQuestionDTO;
public interface ScenarioQuestionRepositoryCustom {
Integer countDuplicateQuestionCode(ScenarioQuestionDTO questionDTO);
Integer countDuplicateOrderIndex(ScenarioQuestionDTO questionDTO);
}
......@@ -2,7 +2,9 @@ package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.model.ccms_full.Scenario;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.data.repository.query.Param;
/**
* @author anhvd_itsol
......@@ -11,4 +13,7 @@ import org.springframework.stereotype.Repository;
@Repository
public interface ScenarioRepository extends JpaRepository<Scenario, Long> {
Scenario findScenarioByCampaignIdAndCompanySiteId(Long campaignId, Long companySiteId);
@Query(value = "SELECT COUNT(1) FROM Scenario WHERE 1 = 1 AND companySiteId = :companySiteId AND code = :code AND scenarioId <> :scenarioId")
Integer countDuplicateScenarioCode(@Param("companySiteId") Long companySiteId, @Param("code") String code, @Param("scenarioId") Long scenarioId);
}
package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.model.ccms_full.UserActionLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/**
* @author hanv_itsol
* @project campaign
*/
@Repository
public interface UserActionLogRepository extends JpaRepository<UserActionLog, Long> {
//
}
......@@ -92,7 +92,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
sb.append(" FROM CAMPAIGN a");
sb.append(" LEFT JOIN (SELECT campaign_id, COUNT (*) AS SLKHThamgiaCD");
sb.append(" FROM campaign_customer cc INNER JOIN CUSTOMER cus ON cc.CUSTOMER_ID = cus.CUSTOMER_ID");
sb.append(" WHERE 1 = 1 AND cc.IN_CAMPAIGN_STATUS = 1 AND cus.STATUS = 1");
sb.append(" WHERE 1 = 1 AND cus.STATUS = 1");
sb.append(" group by campaign_id) b");
sb.append(" ON a.CAMPAIGN_ID = b.CAMPAIGN_ID");
sb.append(" LEFT JOIN (SELECT campaign_id, COUNT (*) AS SLKHChuaTuongTac");
......@@ -511,23 +511,19 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
StringBuilder stringBuilder = new StringBuilder();
try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-not-show");
stringBuilder.append(" with column_name_temp as (");
stringBuilder.append(" select column_name columnName, 1 isFix from user_tab_columns, dual");
stringBuilder.append(" where table_name = 'CUSTOMER'");
stringBuilder.append(" )");
stringBuilder.append(" select * from column_name_temp");
stringBuilder.append(" where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)");
stringBuilder.append(" union all");
stringBuilder.append(" select title columnName, 0 isFix ");
stringBuilder.append(" from customize_fields, dual");
stringBuilder.append(" where function_code = 'CUSTOMER'");
stringBuilder.append(" and site_id = :p_company_site_id");
stringBuilder.append(" and customize_field_id not in (select customize_field_id");
stringBuilder.append(" from campaign_customerlist_column");
stringBuilder.append(" where campaign_customerlist_column.campaign_id = :p_campaign_id)");
String sql = "with column_name_temp as (\n" +
" select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual\n" +
" where table_name = 'CUSTOMER'\n" +
")\n" +
"select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)\n" +
"union all\n" +
"select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual\n" +
"where function_code = 'CUSTOMER'\n" +
" and site_id = :p_company_site_id\n" +
" and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id)\n";
params.put("p_company_site_id", dto.getCompanySiteId());
params.put("p_campaign_id", dto.getCampaignId());
list = namedParameterJdbcTemplate.query(stringBuilder.toString(), params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(list);
......@@ -548,15 +544,22 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
StringBuilder sqlBuilder = new StringBuilder();
try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-fields-to-show");
sqlBuilder.append(" select to_char(column_name) columnName, 1 isFix");
sqlBuilder.append(" from campaign_customerlist_column, dual");
sqlBuilder.append(" where campaign_id = :p_campaign_id and column_name is not null");
sqlBuilder.append(" union all");
sqlBuilder.append(" select customize_field_title columnName, 0 isFix");
sqlBuilder.append(" from campaign_customerlist_column");
sqlBuilder.append(" where campaign_id = :p_campaign_id");
String sql = "with field_name as (\n" +
"select a.campaign_cus_list_column_id id, to_char(a.column_name) columnName, a.order_index, a.customize_field_id customizeFieldId, 1 isFix\n" +
"from campaign_customerlist_column a, dual\n" +
"where a.campaign_id = :p_campaign_id\n" +
" and a.company_site_id = :p_company_site_id\n" +
" and column_name is not null\n" +
"union all\n" +
"select a.campaign_cus_list_column_id id, a.customize_field_title columnName, a.order_index, a.customize_field_id customizeFieldId, 0 isFix\n" +
"from campaign_customerlist_column a\n" +
"where a.campaign_id = :p_campaign_id\n" +
" and a.company_site_id = :p_company_site_id\n" +
")\n" +
"select id, columnName, customizeFieldId, isFix from field_name where columnName is not null order by order_index\n";
params.put("p_campaign_id", dto.getCampaignId());
list = namedParameterJdbcTemplate.query(sqlBuilder.toString(), params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
params.put("p_company_site_id", dto.getCompanySiteId());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(FieldsToShowDTO.class));
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
resultDTO.setListData(list);
......@@ -577,10 +580,280 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
// StringBuilder sb = new StringBuilder();
try {
String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-campaign-customer");
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-campaign-customer");
String sql = "with campaign_customer_id as (\n" +
" 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" +
"campaign_customer_table as (\n" +
" select count(a.customer_id) campaignCustomer, a.customer_list_id customerListId, a.campaign_id from campaign_customer a\n" +
" where a.campaign_id = :p_campaign_id\n" +
" group by a.customer_list_id, a.campaign_id\n" +
"),\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\n" +
" group by a.customer_list_id, a.campaign_id\n" +
"),\n" +
"customer_not_interactive_table as (\n" +
" select count(a.customer_id) cusNotInteractive, 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 a.in_campaign_status = 1\n" +
" group by a.customer_list_id, a.campaign_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.campaignCustomer, 0) totalCusCampaign,\n" +
" nvl(d.campaignCustomerCalled, 0) totalCusCalled,\n" +
" nvl(e.cusNotInteractive, 0) totalCusNotInteract\n" +
"from customer_list a\n" +
"left join customer_table b on a.customer_list_id = b.customerListId\n" +
"left join campaign_customer_table c on a.customer_list_id = c.customerListId\n" +
"left join customer_interactive_table d on a.customer_list_id = d.customerListId\n" +
"left join customer_not_interactive_table e on a.customer_list_id = e.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.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";
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));
int total = 0;
if (list.size() > 0) {
total = list.get(0).getTotalRow();
}
resultDTO.setListData(list);
resultDTO.setTotalRow(total);
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 ResultDTO getCustomerList(CampaignRequestDTO dto) {
List<CustomerListDTO> list = new ArrayList();
ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
// Map<String, String> params = new HashMap<>();
StringBuilder sb = new StringBuilder();
try {
// String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-customer-list");
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(" 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(" a.create_at createAt,");
sb.append(" a.company_site_id companySiteId,");
sb.append(" a.status status");
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(" 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 (a.create_at <= to_date(:p_to_date, 'DD/MM/YYYY'))");
sb.append(" and (a.create_at >= 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(" ),");
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, 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)");
// params.put("p_campaign_id", dto.getCampaignId());
// params.put("p_cus_list_code", DataUtil.isNullOrEmpty(dto.getCustListCode()) ? null : dto.getCustListCode().toUpperCase());
// params.put("p_cus_list_name", DataUtil.isNullOrEmpty(dto.getCustListName()) ? null : dto.getCustListName().toUpperCase());
// params.put("p_to_date", dto.getCreateTimeTo());
// params.put("p_from_date", dto.getCreateTimeFr());
// 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(sb.toString(), params, BeanPropertyRowMapper.newInstance(CustomerListDTO.class));
SQLQuery query = session.createSQLQuery(sb.toString());
query.setParameter("p_company_site_id", dto.getCompanySiteId());
query.setParameter("p_campaign_id", dto.getCampaignId());
query.setParameter("p_cus_list_code", DataUtil.isNullOrEmpty(dto.getCustListCode()) ? null : dto.getCustListCode().toUpperCase());
query.setParameter("p_cus_list_name", DataUtil.isNullOrEmpty(dto.getCustListName()) ? null : dto.getCustListName().toUpperCase());
query.setParameter("p_to_date", dto.getCreateTimeTo());
query.setParameter("p_from_date", dto.getCreateTimeFr());
query.setParameter("p_page_number", dto.getPage());
query.setParameter("p_page_size", dto.getPageSize());
query.addScalar("customerListId", new LongType());
query.addScalar("customerListCode", new StringType());
query.addScalar("customerListName", new StringType());
query.addScalar("totalCusList", new LongType());
query.addScalar("totalCusActive", new LongType());
query.addScalar("totalCusLock", new LongType());
query.addScalar("totalCusDnc", new LongType());
query.addScalar("totalRow", new IntegerType());
query.setResultTransformer(Transformers.aliasToBean(CustomerListDTO.class));
int total = 0;
list = query.list();
if (list.size() > 0) {
total = list.get(0).getTotalRow();
}
resultDTO.setListData(list);
resultDTO.setTotalRow(total);
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);
} finally {
session.close();
return resultDTO;
}
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCustomerChoosenList(CampaignRequestDTO dto) {
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-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";
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));
int total = 0;
if (list.size() > 0) {
total = list.get(0).getTotalRow();
}
resultDTO.setListData(list);
resultDTO.setTotalRow(total);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
......
......@@ -68,6 +68,61 @@ public class ScenarioQuestionRepositoryImpl implements ScenarioQuestionRepositor
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
} finally {
session.close();
}
return count;
}
@Override
public Integer countDuplicateOrderIndex(ScenarioQuestionDTO questionDTO) {
logger.info("Start search duplicate order index::");
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Integer count = null;
try {
StringBuilder sb = new StringBuilder();
sb.append("SELECT COUNT(1) FROM SCENARIO_QUESTION WHERE 1 = 1 AND STATUS = 1 ");
if (questionDTO.getScenarioQuestionId() != null) {
sb.append(" AND SCENARIO_QUESTION_ID <> :p_question_id ");
}
if (questionDTO.getOrderIndex() != null) {
sb.append(" AND ORDER_INDEX = :p_orderIndex ");
}
if (questionDTO.getCampaignId() != null) {
sb.append(" AND CAMPAIGN_ID = :p_campaign_id");
}
if (questionDTO.getCompanySiteId() != null) {
sb.append(" AND COMPANY_SITE_ID = :p_site_id");
}
SQLQuery query = session.createSQLQuery(sb.toString());
if (questionDTO.getScenarioQuestionId() != null) {
query.setParameter("p_question_id", questionDTO.getScenarioQuestionId());
}
if (questionDTO.getOrderIndex() != null) {
query.setParameter("p_orderIndex", questionDTO.getOrderIndex());
}
if (questionDTO.getCampaignId() != null) {
query.setParameter("p_campaign_id", questionDTO.getCampaignId());
}
if (questionDTO.getCompanySiteId() != null) {
query.setParameter("p_site_id", questionDTO.getCompanySiteId());
}
final List<BigDecimal> obj = query.list();
for (BigDecimal i : obj) {
if (i != null) {
count = i.intValue();
}
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
} finally {
session.close();
}
return count;
}
......
......@@ -56,6 +56,16 @@ public interface CampaignService {
ResultDTO getListFieldsToShow(CampaignRequestDTO dto);
ResultDTO getCampaignCustomerList(CampaignRequestDTO dto);
ResultDTO getCustomerList(CampaignRequestDTO dto);
ResultDTO getCustomerChoosenList(CampaignRequestDTO dto);
ResultDTO addCustomerListToCampaign(CampaignRequestDTO dto);
ResultDTO deleteCustomerListFromCampaign(CampaignRequestDTO dto);
ResultDTO saveFieldCustomer(CampaignRequestDTO dto);
//</editor-fold>
}
......@@ -33,7 +33,7 @@ public interface CustomerService {
ResultDTO getAllCustomerList(int page, int pageSize, String sort, Long companySiteId);
ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName);
CustomerList createCustomerList(CustomerListDTO customerListDTO, String userName);
ResultDTO updateCustomerList(CustomerListDTO customerListDTO);
......
......@@ -13,4 +13,6 @@ public interface ScenarioAnswerService {
Long getMaxAnswerOrderId(Long scenarioQuestionId, Long companySiteId);
ResultDTO delete(ScenarioAnswerDTO scenarioAnswerDTO);
Integer countDuplicateScenarioCode(String code, Long scenarioQuestionId, Long scenarioAnswerId);
}
......@@ -20,4 +20,6 @@ public interface ScenarioQuestionService {
ResultDTO update(ScenarioQuestionDTO scenarioQuestionDTO);
Integer countDuplicateOrderIndex(ScenarioQuestionDTO questionDTO);
}
......@@ -16,5 +16,7 @@ public interface ScenarioService {
ResultDTO sortQuestionAndAnswer(ScenarioDTO scenarioDTO);
Integer countDuplicateScenarioCode(Long companySiteId, String code, Long scenarioId);
ResultDTO saveContacQuestResult(ContactQuestResultDTO dto);
}
package com.viettel.campaign.service;
import com.viettel.campaign.model.ccms_full.UserActionLog;
/**
* @author anhvd_itsol
* @author hanv_itsol
* @project campaign
*/
public interface UserActionLogService {
void save(UserActionLog log);
}
......@@ -61,6 +61,15 @@ public class CampaignServiceImpl implements CampaignService {
@Autowired
ScenarioRepository scenarioRepository;
@Autowired
CampaignCustomerListRepository campaignCustomerListRepository;
@Autowired
CampaignCustomerRepository campaignCustomerRepository;
@Autowired
CampaignCustomerListColumnRepository campaignCustomerListColumnRepository;
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO search(CampaignRequestDTO requestDto) {
......@@ -364,14 +373,15 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO updateCampaign(CampaignDTO dto) {
ResultDTO resultDTO = new ResultDTO();
List<TimeZoneDialModeDTO> lstTimeZone = dto.getLstTimeZone();
List<TimeRangeDialModeDTO> lstTimeRange = dto.getLstTimeRange();
Campaign campaignEntity = new Campaign();
campaignEntity.setCampaignId(dto.getCampaignId());
Campaign campaignEntity = campaignRepository.findByCampaignId(dto.getCampaignId());
campaignEntity.setCampaignName(dto.getCampaignName());
campaignEntity.setCampaignCode(dto.getCampaignCode());
campaignEntity.setContent(dto.getContent());
campaignEntity.setCustomerNumber(dto.getCustomerNumber());
......@@ -487,6 +497,122 @@ public class CampaignServiceImpl implements CampaignService {
return campaignRepositoryCustom.getCampaignCustomerList(dto);
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCustomerList(CampaignRequestDTO dto) {
return campaignRepositoryCustom.getCustomerList(dto);
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getCustomerChoosenList(CampaignRequestDTO dto) {
return campaignRepositoryCustom.getCustomerChoosenList(dto);
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO addCustomerListToCampaign(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
String[] lstCusListId = dto.getLstCustomerListId().split(",");
try {
for(String cusListId : lstCusListId) {
CampaignCustomerList entity = new CampaignCustomerList();
entity.setCampaignId(Long.parseLong(dto.getCampaignId()));
entity.setCompanySiteId(Long.parseLong(dto.getCompanySiteId()));
entity.setCustomerListId(Long.parseLong(cusListId));
campaignCustomerListRepository.save(entity);
}
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 ResultDTO deleteCustomerListFromCampaign(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
String[] lstCusListId = dto.getLstCustomerListId().split(",");
long campaignId = Long.parseLong(dto.getCampaignId());
long companySiteId = Long.parseLong(dto.getCompanySiteId());
try {
for(String cusListId : lstCusListId) {
// Xoa danh sach khach hang khoi campaign_customerList
campaignCustomerListRepository.deleteCampaignCustomerListByCampaignIdAndCustomerListIdAndCompanySiteId(campaignId, Long.parseLong(cusListId), companySiteId);
// Thuc hien xoa cac khach hang chua lien lac tai bang campaign_customer
List<CampaignCustomer> listCampaignCustomer = campaignCustomerRepository.findCustomerNoContact(campaignId, companySiteId, Long.parseLong(cusListId));
for (CampaignCustomer entity : listCampaignCustomer) {
campaignCustomerRepository.delete(entity);
}
// Thuc hien update cac khach hang da lien lac
List<CampaignCustomer> list = campaignCustomerRepository.findCustomerContacted(campaignId, companySiteId, Long.parseLong(cusListId));
for (CampaignCustomer campaignCustomer: list) {
campaignCustomer.setInCampaignStatus((short) 0);
}
}
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 ResultDTO saveFieldCustomer(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
List<FieldsToShowDTO> list = dto.getLstFiedCustomer();
long campaignId = Long.parseLong(dto.getCampaignId());
long companySiteId = Long.parseLong(dto.getCompanySiteId());
List<CampaignCustomerListColumn> listColumns = campaignCustomerListColumnRepository.findByCampaignIdAndCompanySiteId(campaignId, companySiteId);
try {
// Them moi cac truong hien thi
for (FieldsToShowDTO fieldsToShowDTO : list) {
if (fieldsToShowDTO.getId() == null) {
CampaignCustomerListColumn entity = new CampaignCustomerListColumn();
entity.setCampaignId(campaignId);
entity.setCompanySiteId(companySiteId);
if (fieldsToShowDTO.getIsFix()) {
entity.setColumnName(fieldsToShowDTO.getColumnName());
} else {
entity.setCustomizeFieldId(fieldsToShowDTO.getCustomizeFieldId());
entity.setCustomizeFieldTitle(fieldsToShowDTO.getColumnTitle());
}
entity.setOrderIndex((long) (list.indexOf(fieldsToShowDTO) + 1));
campaignCustomerListColumnRepository.save(entity);
}
}
// Cap nhat cac truong da co san
for (FieldsToShowDTO fieldsToShowDTO : list) {
if (fieldsToShowDTO.getId() != null) {
listColumns.removeIf(p -> p.getCampaignCusListColId() == fieldsToShowDTO.getId());
CampaignCustomerListColumn entity = campaignCustomerListColumnRepository.findByCampaignCusListColId(fieldsToShowDTO.getId());
entity.setOrderIndex((long) (list.indexOf(fieldsToShowDTO) + 1));
campaignCustomerListColumnRepository.save(entity);
}
}
// Xoa cac truong khong con hien thi nua
for (CampaignCustomerListColumn entity : listColumns) {
campaignCustomerListColumnRepository.delete(entity);
}
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;
}
// hungtt
private Map<String, String> setMapData(Map<String, String> mapColumn, Locale locale) {
mapColumn.put("CUSTOMER_ID", BundleUtils.getLangString("CUSTOMER_ID", locale));
......
......@@ -50,7 +50,7 @@ public class CustomerServiceImpl implements CustomerService {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerServiceImpl.class);
@Autowired
@PersistenceContext( unitName= DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
@PersistenceContext(unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
EntityManager entityManager;
@Autowired
......@@ -595,37 +595,30 @@ public class CustomerServiceImpl implements CustomerService {
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO createCustomerList(CustomerListDTO customerListDTO, String userName) {
ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
CustomerList customerList = new CustomerList();
public CustomerList createCustomerList(CustomerListDTO customerListDTO, String userName) {
LOGGER.info("-----------CREATE CUSTOMER LIST--------------");
try {
if (customerListDTO != null) {
// insert
CustomerList findCustomer = customerListRepository.findByCustomerListCode(customerListDTO.getCustomerListCode());
if (findCustomer == null) {
customerListDTO.setCreateBy(userName);
customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerListRepository.save(customerList);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
CustomerList cl = customerListRepository.findByCustomerListCode(customerListDTO.getCustomerListCode());
if (cl == null) {
cl = new CustomerList();
cl.setCustomerListCode(customerListDTO.getCustomerListCode());
cl.setCustomerListName(customerListDTO.getCustomerListName());
cl.setStatus((short) 1);
cl.setCreateBy(userName);
cl.setCreateAt(new Date());
cl.setUpdateBy(null);
cl.setUpdateAt(null);
cl.setSource(null);
cl.setDeptCreate(null);
cl.setCompanySiteId(customerListDTO.getCompanySiteId());
return customerListRepository.save(cl);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return null;
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.error(e.getMessage());
return null;
}
return resultDTO;
}
@Override
......@@ -894,7 +887,8 @@ public class CustomerServiceImpl implements CustomerService {
public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) {
LOGGER.info("------------READ AND VALIDATE--------------");
Locale locale = new Locale("vi", "VN");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DataFormatter dataFormat = new DataFormatter();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Map<String, Object> result = new HashMap<>();
StringBuilder sb = new StringBuilder();
boolean validateOk = false;
......@@ -970,14 +964,7 @@ public class CustomerServiceImpl implements CustomerService {
for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) {
Cell dataCell = dataRow.getCell(j);
if (dataCell != null) {
switch (dataCell.getCellTypeEnum()) {
case NUMERIC:
obj[j] = dataCell.getNumericCellValue();
break;
default:
obj[j] = dataCell.getStringCellValue();
break;
}
obj[j] = dataFormat.formatCellValue(dataCell);
} else {
Cell headerCell = row.getCell(j);
if (headerCell.getStringCellValue().equals(BundleUtils.getLangString("customer.cusType", locale))) {
......@@ -1014,9 +1001,12 @@ public class CustomerServiceImpl implements CustomerService {
&& !rawDataList.get(i)[4].toString().trim().equals("")) {
String str = validatePhone(rawDataList.get(i)[2].toString().trim(), locale);
str.concat(validateLength(BundleUtils.getLangString("customer.secondPhone", locale).split("#")[0], rawDataList.get(i)[3].toString(), 50, locale));
if (validateEmail(rawDataList.get(i)[4].toString().trim())) {
str.concat(BundleUtils.getLangString("customer.emailMax50", locale));
if (!validateEmail(rawDataList.get(i)[4].toString().trim())) {
str.concat(BundleUtils.getLangString("customer.emailInvalid", locale));
} else {
str.concat(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));
sb.append(str);
} else {
sb.append(BundleUtils.getLangString("customer.invalidCustomer", locale));
......@@ -1030,17 +1020,17 @@ public class CustomerServiceImpl implements CustomerService {
if (rawDataList.get(i).length > 8 && rawDataList.get(i)[8] != null) {
sb.append(validateLength(BundleUtils.getLangString("customer.description", locale).split("#")[0], rawDataList.get(i)[8].toString(), 2000, locale));
}
for (int j = 12; j < header.size(); j++) {
if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) {
if (header.get(j).getType().equals("text")) {
sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMinLength(), header.get(j).getMaxLength(), locale));
} else if (header.get(j).getType().equals("date")) {
sb.append(validateUsingRegexp(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getRegexpForValidation(), locale));
} else if (header.get(j).getType().equals("number")) {
sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMin(), header.get(j).getMax(), locale));
}
}
}
// for (int j = 12; j < header.size(); j++) {
// if (rawDataList.get(i).length > j && rawDataList.get(i)[j] != null) {
// if (header.get(j).getType().equals("text")) {
// sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMinLength(), header.get(j).getMaxLength(), locale));
// } else if (header.get(j).getType().equals("date")) {
// sb.append(validateUsingRegexp(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getRegexpForValidation(), locale));
// } else if (header.get(j).getType().equals("number")) {
// sb.append(validateDynamicLength(header.get(j).getTitle(), rawDataList.get(i)[j].toString(), header.get(j).getMin(), header.get(j).getMax(), locale));
// }
// }
// }
Row dataRow = sheet.getRow(4 + i);
Cell resultCell = dataRow.createCell(row.getPhysicalNumberOfCells() - 1);
if (sb.length() > 0) {
......@@ -1105,11 +1095,12 @@ public class CustomerServiceImpl implements CustomerService {
}
c.setIpccStatus("active");
Customer saved = customerRepository.save(c);
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
if (rawDataList.get(i).length > 2 && rawDataList.get(i)[2] != null) {
String[] mainPhone = rawDataList.get(i)[2].toString().split(";");
for (int j = 0; j < mainPhone.length; j++) {
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
cc.setSiteId(userSession.getSiteId());
cc.setContactType((short) 5);
cc.setContact(mainPhone[j]);
cc.setIsDirectLine((short) 1);
......@@ -1124,6 +1115,9 @@ public class CustomerServiceImpl implements CustomerService {
if (rawDataList.get(i).length > 3 && rawDataList.get(i)[3] != null) {
String[] subPhone = rawDataList.get(i)[3].toString().split(";");
for (int j = 0; j < subPhone.length; j++) {
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
cc.setSiteId(userSession.getSiteId());
cc.setContactType((short) 5);
cc.setContact(subPhone[j]);
cc.setIsDirectLine((short) 0);
......@@ -1136,8 +1130,11 @@ public class CustomerServiceImpl implements CustomerService {
}
}
if (rawDataList.get(i).length > 4 && rawDataList.get(i)[4] != null) {
String[] email = rawDataList.get(i)[3].toString().split(";");
String[] email = rawDataList.get(i)[4].toString().split(";");
for (int j = 0; j < email.length; j++) {
CustomerContact cc = new CustomerContact();
cc.setCustomerId(saved.getCustomerId());
cc.setSiteId(userSession.getSiteId());
cc.setContactType((short) 2);
cc.setContact(email[j]);
cc.setIsDirectLine((short) 1);
......@@ -1154,7 +1151,7 @@ public class CustomerServiceImpl implements CustomerService {
for (int j = 0; j < dynamicHeader.size(); j++) {
cfo.setCustomizeFieldId(dynamicHeader.get(j).getCustomizeFieldId());
if (rawDataList.get(i).length > (12 + j) && rawDataList.get(i)[12 + j] != null) {
switch (dynamicHeader.get(i).getType()) {
switch (dynamicHeader.get(j).getType()) {
case "combobox":
CustomizeFieldOptionValue cfov =
customizeFieldOptionValueRepository.findCustomizeFieldOptionValueByNameEqualsAndStatus(rawDataList.get(i)[12 + j].toString(), 1L);
......@@ -1219,8 +1216,8 @@ public class CustomerServiceImpl implements CustomerService {
if (str.length() > 50) {
result = BundleUtils.getLangString("customer.phoneMax50", locale);
}
for (int i = 0; i < str.length(); i++) {
CustomerContact cc = customerContactRepository.findCustomerContactByContactTypeAndContactAndIsDirectLine((short)5, arr[i], (short)1);
for (int i = 0; i < arr.length; i++) {
CustomerContact cc = customerContactRepository.findCustomerContactByContactEquals(arr[i]);
if (cc != null) {
return result.concat(BundleUtils.getLangString("customer.phoneExists", locale));
}
......@@ -1228,6 +1225,18 @@ public class CustomerServiceImpl implements CustomerService {
return result;
}
private String validateDuplicateEmail(String str, Locale locale) {
String result = "";
String[] arr = str.split(";");
for (int i = 0; i < arr.length; i++) {
CustomerContact cc = customerContactRepository.findCustomerContactByContactEquals(arr[i]);
if (cc != null) {
return result.concat(BundleUtils.getLangString("customer.emailExists", locale));
}
}
return result;
}
private String validateUsingRegexp(String header, String data, String regexp, Locale locale) {
if (data.matches(regexp)) {
return header + " " + BundleUtils.getLangString("customer.notMatch", locale);
......@@ -1249,8 +1258,14 @@ public class CustomerServiceImpl implements CustomerService {
}
private boolean validateEmail(String str) {
String[] arr = str.split(";");
String regexp = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
return str.matches(regexp);
for (int i = 0; i < arr.length; i++) {
if (!arr[i].matches(regexp)) {
return false;
}
}
return true;
}
private boolean validateLetter(String str) {
......@@ -1315,14 +1330,14 @@ public class CustomerServiceImpl implements CustomerService {
constraint[j] = list.get(j).getName();
}
DataValidationConstraint comboboxConstraint = dataValidationHelper.createExplicitListConstraint(constraint);
CellRangeAddressList comboboxCellRange = new CellRangeAddressList(4,9999,12 + i, 12 + i);
DataValidation comboboxValidation = dataValidationHelper.createValidation(comboboxConstraint,comboboxCellRange);
CellRangeAddressList comboboxCellRange = new CellRangeAddressList(4, 9999, 12 + i, 12 + i);
DataValidation comboboxValidation = dataValidationHelper.createValidation(comboboxConstraint, comboboxCellRange);
comboboxValidation.setSuppressDropDownArrow(true);
comboboxValidation.setShowErrorBox(true);
sheet.addValidationData(comboboxValidation);
} else if (dynamicHeader.get(i).getType().equals("checkbox")) {
DataValidationConstraint yesNoConstraint = dataValidationHelper.createExplicitListConstraint(new String[]{BundleUtils.getLangString("customer.yes", locale), BundleUtils.getLangString("customer.not", locale)});
CellRangeAddressList checkboxCellRange = new CellRangeAddressList(4,9999,12 + i,12 + i);
CellRangeAddressList checkboxCellRange = new CellRangeAddressList(4, 9999, 12 + i, 12 + i);
DataValidation yesNoValidation = dataValidationHelper.createValidation(yesNoConstraint, checkboxCellRange);
yesNoValidation.setShowErrorBox(true);
yesNoValidation.setSuppressDropDownArrow(true);
......
......@@ -113,4 +113,15 @@ public class ScenarioAnswerServiceImpl implements ScenarioAnswerService {
}
return resultDTO;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public Integer countDuplicateScenarioCode(String code, Long scenarioQuestionId, Long scenarioAnswerId) {
try {
return scenarioAnswerRepository.countDuplicateScenarioCode(code, scenarioQuestionId, scenarioAnswerId);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
return null;
}
}
......@@ -302,4 +302,15 @@ public class ScenarioQuestionServiceImpl implements ScenarioQuestionService {
return resultDTO;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public Integer countDuplicateOrderIndex(ScenarioQuestionDTO questionDTO) {
try {
return questionRepositoryCustom.countDuplicateOrderIndex(questionDTO);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
return null;
}
}
......@@ -117,6 +117,16 @@ public class ScenarioServiceImpl implements ScenarioService {
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public Integer countDuplicateScenarioCode(Long companySiteId, String code, Long scenarioId) {
try {
return scenarioRepository.countDuplicateScenarioCode(companySiteId, code, scenarioId);
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
}
return null;
}
public ResultDTO saveContacQuestResult(ContactQuestResultDTO dto) {
ResultDTO resultDTO = new ResultDTO();
......
package com.viettel.campaign.service.impl;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.UserActionLog;
import com.viettel.campaign.repository.ccms_full.UserActionLogRepository;
import com.viettel.campaign.service.UserActionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -11,4 +15,13 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(rollbackFor = Exception.class)
public class UserActionLogServiceImpl implements UserActionLogService {
@Autowired
UserActionLogRepository userActionLogRepository;
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public void save(UserActionLog log) {
userActionLogRepository.save(log);
}
}
......@@ -10,7 +10,7 @@ import java.util.Date;
@Getter
@Setter
@NoArgsConstructor
public class ContactCustResultDTO extends BaseDTO{
public class ContactCustResultDTO extends BaseDTO {
private Long contactCustResultId;
private Long companySiteId;
private Short callStatus;
......
......@@ -28,4 +28,10 @@ public class CustomerListDTO extends BaseDTO {
private Long totalCusList;
private Long totalCusCampaign;
private Long totalCusCalled;
private Long totalCusActive;
private Long totalCusLock;
private Long totalCusDnc;
private Long totalCusAddRemove;
private Long totalCusFilter;
private Integer totalRow;
}
......@@ -13,21 +13,13 @@ import java.io.Serializable;
@AllArgsConstructor
public class FieldsToShowDTO implements Serializable {
// private Long campaignCusListColId;
// private Long companySiteId;
// private Long campaignId;
private Long id;
private String columnName;
private String columnTitle;
// private Long orderIndex;
// private Long customizeFieldId;
// private String customizeFieldTitle;
private Boolean isFix;
private Long customizeFieldId;
}
......@@ -2,6 +2,7 @@ package com.viettel.campaign.web.dto.request_dto;
import com.viettel.campaign.web.dto.BaseDTO;
import com.viettel.campaign.web.dto.CustomerCustomDTO;
import com.viettel.campaign.web.dto.FieldsToShowDTO;
import lombok.Getter;
import lombok.Setter;
......
package com.viettel.campaign.web.rest;
import com.viettel.campaign.model.ccms_full.CustomerList;
import com.viettel.campaign.model.ccms_full.CustomizeFieldObject;
import com.viettel.campaign.model.ccms_full.CustomizeFields;
import com.viettel.campaign.service.CustomerService;
......@@ -103,15 +104,15 @@ public class CustomerController {
}
@PostMapping("/createCustomerList")
@ResponseBody
public ResultDTO createCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO, HttpServletRequest request) {
ResultDTO result = new ResultDTO();
public ResponseEntity<?> createCustomerList(@RequestBody @Valid CustomerListDTO customerListDTO, HttpServletRequest request) {
String xAuthToken = request.getHeader("X-Auth-Token");
UserSession userSession = (UserSession) RedisUtil.getInstance().get(xAuthToken);
result = customerService.createCustomerList(customerListDTO, userSession.getUserName());
return result;
CustomerList cl = customerService.createCustomerList(customerListDTO, userSession.getUserName());
if (cl == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(cl, HttpStatus.OK);
}
@PostMapping("/updateCustomerList")
......@@ -185,11 +186,11 @@ public class CustomerController {
@PostMapping(value = "/importFile")
public ResponseEntity<?> importFile(@RequestParam("file") MultipartFile file,
@RequestParam("customerListId") Long customerListId,
@RequestHeader("X-Auth-Token") String authToken) {
HttpServletRequest request) {
LOGGER.info("------------IMPORT FILE TEMPLATE--------------");
Locale locale = new Locale("vi", "VN");
try {
UserSession userSession = (UserSession) RedisUtil.getInstance().get(authToken);
UserSession userSession = (UserSession) RedisUtil.getInstance().get(request.getHeader("X-Auth-Token"));
if (file.isEmpty()) {
return new ResponseEntity<>(BundleUtils.getLangString("customer.fileNotSelected"), HttpStatus.OK);
}
......
......@@ -37,4 +37,10 @@ public class ScenarioAnswerController {
ResultDTO resultDTO = scenarioAnswerService.delete(answerDTO);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@RequestMapping(value = "/count-duplicate-code", method = RequestMethod.GET)
ResponseEntity<Integer> countDuplicateCode(@RequestParam String code, @RequestParam Long scenarioQuestionId, @RequestParam Long scenarioAnswerId) {
Integer count = scenarioAnswerService.countDuplicateScenarioCode(code, scenarioQuestionId, scenarioAnswerId);
return new ResponseEntity<>(count, HttpStatus.OK);
}
}
......@@ -43,6 +43,12 @@ public class ScenarioController {
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@RequestMapping(value = "/count-duplicate-code", method = RequestMethod.GET)
ResponseEntity<Integer> countDuplicateCode(@RequestParam String code, @RequestParam Long scenarioId, @RequestParam Long companySiteId) {
Integer count = scenarioService.countDuplicateScenarioCode(companySiteId, code, scenarioId);
return new ResponseEntity<>(count, HttpStatus.OK);
}
@RequestMapping(value = "/saveContactQuestResult", method = RequestMethod.POST)
ResponseEntity<ResultDTO> saveContactQuestResult(@RequestBody ContactQuestResultDTO dto) {
ResultDTO resultDTO = scenarioService.saveContacQuestResult(dto);
......
......@@ -56,4 +56,9 @@ public class ScenarioQuestionController {
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@RequestMapping(value = "/count-duplicate-order-index", method = RequestMethod.POST)
public Integer countDuplicateOrderIndex(@RequestBody ScenarioQuestionDTO questionDTO) {
return scenarioQuestionService.countDuplicateOrderIndex(questionDTO);
}
}
server:
port: 9999
port: 1111
spring:
application:
name: campaign
......
......@@ -103,3 +103,8 @@ customer.notLessThan = not less than
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.fileNotSelected=Please select a file
customer.emailInvalid=Invalid email;
customer.emailExists=Email exists;
common.fileNotSelected=Please select a file
common.fileInvalidFormat=File invalid
......@@ -105,3 +105,8 @@ customer.notLessThan = không được nhỏ hơn
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.fileNotSelected=Bạn chưa chọn file
customer.emailInvalid=Email không đúng định dạng;
customer.emailExists=Email đã tồn tại;
common.fileNotSelected=Bạn chưa chọn file
common.fileInvalidFormat=File không hợp lệ
with campaign_customer_id as (
select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl
where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id
),
customer_table as (
select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1
group by a.customer_list_id
),
customer_active_table as (
select count(a.customer_id) customerActive, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1 and b.ipcc_status = 'active'
group by a.customer_list_id
),
customer_lock_table as (
select count(a.customer_id) customerLock, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1 and b.ipcc_status = 'locked'
group by a.customer_list_id
),
customer_dnc_table as (
select count(a.customer_id) customerDnc, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1 and b.call_allowed = 0
group by a.customer_list_id
),
customer_filter_table as (
select count(a.customer_id) customerFilter, a.customer_list_id customerListId from campaign_customer a
where a.campaign_id = :p_campaign_id
group by a.customer_list_id
),
data_temp as (
select a.customer_list_id customerListId,
a.customer_list_code customerListCode,
a.customer_list_name customerListName,
nvl(b.totalCustomer, 0) totalCusList,
nvl(c.customerActive, 0) totalCusActive,
nvl(d.customerLock, 0) totalCusLock,
nvl(e.customerDnc, 0) totalCusDnc,
nvl(null, 0) totalCusAddRemove,
nvl(f.customerFilter, 0) totalCusFilter
from customer_list a
left join customer_table b on a.customer_list_id = b.customerListId
left join customer_active_table c on a.customer_list_id = c.customerListId
left join customer_lock_table d on a.customer_list_id = d.customerListId
left join customer_dnc_table e on a.customer_list_id = e.customerListId
left join customer_filter_table f on a.customer_list_id = f.customerListId
where a.customer_list_id in (select CUSTOMER_LIST_ID from campaign_customer_id)
),
data as (
select a.*, rownum row_ from data_temp a
),
count_data as (
select count(*) totalRow from data_temp
)
select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusActive, a.totalCusLock, a.totalCusDnc, a.totalCusAddRemove, a.totalCusFilter, totalRow from data a, count_data
where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)
with campaign_customer_id as (
select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl
where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id
),
customer_table as (
select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1
group by a.customer_list_id
),
customer_active_table as (
select count(a.customer_id) customerActive, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1 and b.ipcc_status = 'active'
group by a.customer_list_id
),
customer_lock_table as (
select count(a.customer_id) customerLock, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1 and b.ipcc_status = 'locked'
group by a.customer_list_id
),
customer_dnc_table as (
select count(a.customer_id) customerDnc, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1 and b.call_allowed = 0
group by a.customer_list_id
),
data_temp as (
select a.customer_list_id customerListId,
a.customer_list_code customerListCode,
a.customer_list_name customerListName,
nvl(b.totalCustomer, 0) totalCusList,
nvl(c.customerActive, 0) totalCusActive,
nvl(d.customerLock, 0) totalCusLock,
nvl(e.customerDnc, 0) totalCusDnc,
a.create_at createAt,
a.company_site_id companySiteId,
a.status status
from customer_list a
left join customer_table b on a.customer_list_id = b.customerListId
left join customer_active_table c on a.customer_list_id = c.customerListId
left join customer_lock_table d on a.customer_list_id = d.customerListId
left join customer_dnc_table e on a.customer_list_id = e.customerListId
where a.status = 1
and (:p_cus_list_code is null or upper(a.customer_list_code) like '%'||:p_cus_list_code||'%')
and (:p_cus_list_name is null or upper(a.customer_list_name) like '%'||:p_cus_list_name||'%')
and (a.create_at <= to_date(:p_to_date, 'DD/MM/YYYY'))
and (a.create_at >= to_date(:p_from_date, 'DD/MM/YYYY'))
and (a.company_site_id = :p_company_site_id)
and (a.customer_list_id not in (select CUSTOMER_LIST_ID from campaign_customer_id))
),
data as (
select a.*, rownum row_ from data_temp a
),
count_data as (
select count(*) totalRow from data_temp
)
select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusActive, a.totalCusLock, a.totalCusDnc, totalRow from data a, count_data
where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)
with customer_table as (
with campaign_customer_id as (
select ccl.CUSTOMER_LIST_ID from campaign_customerlist ccl
where ccl.campaign_id = :p_campaign_id and ccl.company_site_id = :p_company_site_id
),
customer_table as (
select count(a.customer_id) totalCustomer, a.customer_list_id customerListId from customer_list_mapping a
left join customer b on a.customer_id = b.customer_id
where b.status = 1
......@@ -18,7 +22,8 @@ customer_not_interactive_table as (
select count(a.customer_id) cusNotInteractive, a.customer_list_id customerListId, a.campaign_id from campaign_customer a
where a.status = 0 and a.campaign_id = :p_campaign_id and a.in_campaign_status = 1
group by a.customer_list_id, a.campaign_id
)
),
data_temp as (
select a.customer_list_id customerListId,
a.customer_list_code customerListCode,
a.customer_list_name customerListName,
......@@ -31,3 +36,13 @@ left join customer_table b on a.customer_list_id = b.customerListId
left join campaign_customer_table c on a.customer_list_id = c.customerListId
left join customer_interactive_table d on a.customer_list_id = d.customerListId
left join customer_not_interactive_table e on a.customer_list_id = e.customerListId
where a.customer_list_id in (select CUSTOMER_LIST_ID from campaign_customer_id)
),
data as (
select a.*, rownum row_ from data_temp a
),
count_data as (
select count(*) totalRow from data_temp
)
select a.customerListId, a.customerListCode, a.customerListName, a.totalCusList, a.totalCusCampaign, a.totalCusCalled, a.totalCusNotInteract, totalRow from data a, count_data
where row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1)
with column_name_temp as (
select column_name columnName, 1 isFix from user_tab_columns, dual
select column_name columnName, null customizeFieldId, 1 isFix from user_tab_columns, dual
where table_name = 'CUSTOMER'
)
select * from column_name_temp where columnName not in (select column_name from campaign_customerlist_column where column_name is not null)
union all
select title columnName, 0 isFix from customize_fields, dual
select title columnName, customize_field_id customizeFieldId, 0 isFix from customize_fields, dual
where function_code = 'CUSTOMER'
and site_id = :p_company_site_id
and customize_field_id not in (select customize_field_id from campaign_customerlist_column where campaign_customerlist_column.campaign_id = :p_campaign_id)
select to_char(column_name) columnName, 1 isFix from campaign_customerlist_column, dual where campaign_id = :p_campaign_id and column_name is not null
with field_name as (
select a.campaign_cus_list_column_id id, to_char(a.column_name) columnName, a.order_index, a.customize_field_id customizeFieldId, 1 isFix
from campaign_customerlist_column a, dual
where a.campaign_id = :p_campaign_id
and a.company_site_id = :p_company_site_id
and column_name is not null
union all
select customize_field_title columnName, 0 isFix from campaign_customerlist_column where campaign_id = :p_campaign_id
select a.campaign_cus_list_column_id id, a.customize_field_title columnName, a.order_index, a.customize_field_id customizeFieldId, 0 isFix
from campaign_customerlist_column a
where a.campaign_id = :p_campaign_id
and a.company_site_id = :p_company_site_id
)
select id, columnName, customizeFieldId, isFix from field_name where columnName is not null order by order_index
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