Commit d484f885 authored by Vu Duy Anh's avatar Vu Duy Anh

anhvd commit

parents e2f94b2d d9859bbd
......@@ -71,9 +71,8 @@ public class JobConfig implements SchedulingConfigurer {
private void job2(TaskScheduler scheduler) {
job2 = scheduler.schedule(() -> {
// log.info("processing job2 ...");
// log.info(Thread.currentThread().getName() + " The Task2 executed at " + new Date());
// campaignJob().process();
log.info(Thread.currentThread().getName() + " The Job executed at " + new Date());
campaignJob().process();
}, triggerContext -> {
String cronExp = "0/1 * * * * ?";// Can be pulled from a db . This will run every minute
......@@ -85,15 +84,15 @@ public class JobConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
// ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
// threadPoolTaskScheduler.setPoolSize(10);
// threadPoolTaskScheduler.setThreadNamePrefix("scheduler-thread");
// threadPoolTaskScheduler.initialize();
// scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
//// scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process(), (TriggerContext triggerContext) -> yourService.getCron());
// scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process(), triggerContext -> {
// CronTrigger trigger = new CronTrigger("0/5 * * * * ?");
// return trigger.nextExecutionTime(triggerContext);
// });
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(10);
threadPoolTaskScheduler.setThreadNamePrefix("scheduler-thread");
threadPoolTaskScheduler.initialize();
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
// scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process(), (TriggerContext triggerContext) -> yourService.getCron());
scheduledTaskRegistrar.addTriggerTask(() -> campaignJob().process(), triggerContext -> {
CronTrigger trigger = new CronTrigger("0/5 * * * * ?");
return trigger.nextExecutionTime(triggerContext);
});
}
}
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.utils.DateTimeUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
......@@ -34,8 +36,14 @@ public class CampaignJob {
@Autowired
private CampaignService campaignService;
@Autowired
private CustomerTimeService customerTimeService;
@Autowired
private CustomerService customerService;
// @Scheduled(fixedRate = 5000)
@Transactional( propagation = Propagation.REQUIRED)
// @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();
......@@ -45,26 +53,30 @@ public class CampaignJob {
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){
// chuyen trang thai Du thao sang Trien khai
log.info("thay doi trang thai");
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);
});
// update last check
log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
p.setLastProcess(new Date());
processConfigService.update(p);
}
......@@ -72,25 +84,50 @@ public class CampaignJob {
case CRON_EXPRESSION_CHECK_END:
// process
if(isExecute){
// chuyen trang thai sang ket thuc
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
}
});
}
private void updateCustomer(List<Customer> customers){
customers.parallelStream().forEach(c -> {
log.info("Cap nhat trang thai khoa cua KH ... #{}", c.getCustomerId());
c.setIpccStatus("active");
customerService.update(c);
});
}
private void updateCustomerTime(List<Customer> customers){
customers.parallelStream().forEach(customer -> {
// find all customer_time by customerId
List<CustomerTime> customerTimes = customerTimeService.findByCustomerId(customer.getCustomerId());
customerTimes.parallelStream().forEach(customerTime -> {
log.info("Cap nhat Customer time cua KH ... #{}", customerTime.getCustomerId());
customerTime.setStatus(2);
customerTime.setUpdateTime(new Date());
customerTimeService.update(customerTime);
});
});
}
}
package com.viettel.campaign.model.acd_full;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.Date;
@Entity
@Table(name = "Agents")
@Getter
@Setter
public class Agents {
@Id
@Basic(optional = false)
@Column(name = "AGENT_ID")
private String agentId;
@Column(name = "DESCRIPTION")
private String description;
@Column(name = "SYSTEM_STATUS")
private String systemStatus;
@Column(name = "USER_STATUS")
private String userStatus;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_START_WORK")
private Date lastStartWork;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_FINISH_WORK")
private Date lastFinishWork;
@Column(name = "LOGIN_TYPE")
private String loginType;
@Column(name = "VSA_USER_LOGIN")
private String vsaUserLogin;
@Column(name = "CALL_STATUS")
private String callStatus;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_STATUS")
private Date lastChangeStatus;
@Column(name = "IP_LOGIN")
private String ipLogin;
@Column(name = "NUM_REJECTCALL")
private String numRejectcall;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LOGIN_TIME")
private Date loginTime;
@Column(name = "GROUP_NAME")
private String groupName;
@Column(name = "TOTAL_ANSWER_CALL")
private String totalAnswerCall;
@Column(name = "TOTAL_ANSWER_TIME")
private String totalAnswerTime;
@Column(name = "CALLOUT_ID")
private Integer calloutId;
@Column(name = "LAST_QUEUE_ANSWER")
private String lastQueueAnswer;
@Column(name = "EMAIL_USER_STATUS")
private String emailUserAnswer;
@Column(name = "CHAT_USER_STATUS")
private String chatUserStatus;
@Column(name = "SMS_USER_STATUS")
private String smsUserStatus;
@Column(name = "MULTI_CHANNEL_USER_STATUS")
private String multiChannelUserStatus;
@Column(name = "MAX_TRANSACTION_EMAIL")
private Integer maxTransactionEmail = 1;
@Column(name = "MAX_TRANSACTION_CHAT")
private Integer maxTransactionChat = 1;
@Column(name = "MAX_CURRENT_TRANSACTION")
private Integer maxCurrentTransaction = 6;
@Column(name = "TOTAL_TRANSACTION")
private Integer totalTransaction = 0;
@Column(name = "EMAIL_SYSTEM_STATUS")
private Integer emailSystemStatus = 0;
@Column(name = "CHAT_SYSTEM_STATUS")
private Integer chatSystemStatus = 0;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_CHAT_STATUS")
private Date lastChangeChatStatus;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_EMAIL_STATUS")
private Date lastChangeEmailStatus;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_MULTI_STATUS")
private Date lastChangeMultiStatus;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_START_WORK_CHAT")
private Date lastStartWorkChat;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_START_WORK_EMAIL")
private Date lastStartWorkEmail;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_FINISH_WORK_CHAT")
private Date lastFinishWorkChat;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_FINISH_WORK_EMAIL")
private Date lastFinishWorkEmail;
@Column(name = "TOTAL_ANSWER_CHAT")
private Long totalAnswerChat;
@Column(name = "TOTAL_ANSWER_EMAIL")
private Long totalAnswerEmail;
@Column(name = "TOTAL_ANSWER_TIME_EMAIL")
private Long totalAnswerTimeEmail;
@Column(name = "TOTAL_ANSWER_TIME_CHAT")
private Long totalAnswerTimeChat;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_ASSIGN_TIME_SMS")
private Date lastAssignTimeSms;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_SMS_STATUS")
private Date lastChangeSmsStatus;
@Column(name = "MAX_TRANSACTION_SMS")
private Integer maxTransactionSms = 1;
@Column(name = "SMS_SYSTEM_STATUS")
private Integer smsSystemStatus = 0;
@Column(name = "FACEBOOK_SYSTEM_STATUS")
private Integer facebookSystemStatus = 0;
@Column(name = "FACEBOOK_USER_STATUS")
private String facebookUserStatus;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_START_WORK_SMS")
private Date lastStartWorkSms;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_START_WORK_FACEBOOK")
private Date lastStartWorkFacebook;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_FINISH_WORK_SMS")
private Date lastFinishWorkSms;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_FINISH_WORK_FACEBOOK")
private Date lastFinishWorkFacebook;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_FACEBOOK_STATUS")
private Date lastChangeFacebookStatus;
@Column(name = "MAX_TRANSACTION_FACEBOOK")
private Integer maxTransactionFacebook = 1;
@Column(name = "TICKET_USER_STATUS")
private String ticketUserStatus;
@Column(name = "TICKET_SYSTEM_STATUS")
private Integer ticketSystemStatus;
@Column(name = "MAX_TRANSACTION_TICKET")
private Integer maxTransactionTicket;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_START_WORK_TICKET")
private Date lastStartWorkTicket;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_FINISH_WORK_TICKET")
private Date lastFinishWorkTicket;
@Column(name = "COMPANY_SITE_ID")
private Long companySiteId;
@Column(name = "SITE_ID")
private Long siteId;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "LAST_CHANGE_TICKET_STATUS")
private Date lastChangeTicketStatus;
@Column(name = "AGENT_TYPE")
private Short agentType;
@Column(name = "STATUS")
private Long status = 1L;
@Column(name = "CREATE_BY")
private String createBy;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATE_DATE")
private Date createDate;
@Column(name = "UPDATE_BY")
private String updateBy;
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "UPDATE_DATE")
private Date updateDate;
@Column(name = "USER_KAZOO_ID")
private String userKazooId;
@Column(name = "CAMPAIGN_SYSTEM_STATUS")
private String campaignSystemStatus;
@Column(name = "CURRENT_CAMPAIGN_ID")
private Long currentCampaignId;
}
......@@ -12,8 +12,8 @@ import javax.validation.constraints.NotNull;
@Setter
public class CampaignCustomerList {
@Id
@GeneratedValue(generator = "campaign_customerlist_seq")
@SequenceGenerator(name = "campaign_customerlist_seq", sequenceName = "campaign_customerlist_seq", allocationSize = 1)
@GeneratedValue(generator = "campaign_customer_seq")
@SequenceGenerator(name = "campaign_customer_seq", sequenceName = "campaign_customer_seq", allocationSize = 1)
@Basic(optional = false)
@NotNull
@Column(name = "CAMPAIGN_CUSTOMERLIST_ID")
......
package com.viettel.campaign.model.ccms_full;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
/**
* @author hanv_itsol
* @project campaign
*/
@Entity
@Table(name = "CUSTOMER_TIME")
@Getter
@Setter
public class CustomerTime {
@Id
@NotNull
@Column(name = "CUSTOMER_TIME_ID")
private Long customerTimeId;
@Column(name = "COMPANY_SITE_ID")
private String companySiteId;
@Column(name = "CUSTOMER_ID")
private String customerId;
@Column(name = "START_TIME")
private Date startTime;
@Column(name = "END_TIME")
private Date endTime;
@Column(name = "STATUS")
private Integer status;
@Column(name = "CREATE_TIME")
private Date createTime;
@Column(name = "UPDATE_TIME")
private Date updateTime;
@Column(name = "CREATE_BY")
private String createBy;
@Column(name = "UPDATE_BY")
private String updateBy;
@Column(name = "CONTACT_CUST_RESULT_ID")
private Long contactCustResultId;
}
package com.viettel.campaign.repository.acd_full;
import com.viettel.campaign.model.acd_full.Agents;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AgentsRepository extends JpaRepository<Agents, String> {
Agents getByAgentId(String agentId);
}
......@@ -20,5 +20,7 @@ public interface CampaignExecuteRepository {
ResultDTO getInteractiveResult(CampaignRequestDTO dto);
List<ContactCustResultDTO> getExcelInteractiveResult(CampaignRequestDTO dto);
List<ContactCustResultDTO> getContactCustById(CampaignRequestDTO dto);
//</editor-fold: hungtt>
}
......@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
@Repository
......@@ -27,4 +28,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Modifying
@Query("delete from Customer c where c.customerId in (:ids)")
int deleteIds(@Param("ids") List<Long> ids);
@Query("select c from Customer c left join com.viettel.campaign.model.ccms_full.CustomerTime ct on c.customerId = ct.customerId " +
"where c.ipccStatus = 'locked' and c.siteId =?1 and ct.endTime <= ?2")
List<Customer> findAllByCondition(Long siteId, Date endTime);
}
package com.viettel.campaign.repository.ccms_full;
import com.viettel.campaign.model.ccms_full.CustomerTime;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author hanv_itsol
* @project campaign
*/
@Repository
public interface CustomerTimeRepository extends JpaRepository<CustomerTime, Long> {
List<CustomerTime> findByCustomerId(Long customerId);
}
......@@ -34,26 +34,25 @@ import java.util.concurrent.TimeUnit;
@Repository
public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
private static final Logger logger = LoggerFactory.getLogger(CampaignRepositoryImpl.class);
private static final Logger logger = LoggerFactory.getLogger(CampaignExecuteRepositoryImp.class);
@Autowired
@Qualifier(DataSourceQualify.NAMED_JDBC_PARAMETER_TEMPLATE_CCMS_FULL)
NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Autowired
@PersistenceContext( unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
@PersistenceContext (unitName = DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
EntityManager entityManager;
@Override
public List<ApParamDTO> getComboBoxStatus(String companySiteId, String completeType) {
List<ApParamDTO> list = new ArrayList<>();
Map<String, String> params = new HashMap<>();
String sql = SQLBuilder.getSqlQueryById(Constants.SQL_MODULES.MODULE_EXECUTE, "get-combo-connect-status");
String sql = SQLBuilder.getSqlQueryById(Constants.SQL_MODULES.MODULE_EXECUTE, "get-combo-status");
try {
params.put("p_company_site_id", companySiteId);
params.put("p_complete_type", completeType);
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(ApParamDTO.class));
// list = namedParameterJdbcTemplate.getJdbcTemplate().query(sql, (PreparedStatementSetter) params, BeanPropertyRowMapper.newInstance(ComboBoxDTO.class));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
......@@ -87,43 +86,78 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
String sql = SQLBuilder.getSqlQueryById(Constants.SQL_MODULES.MODULE_EXECUTE, "get-execute-interactive");
sqlBuilder.append(sql);
sqlBuilder.append(" and b.campaign_type in (:p_list_compaign_type)");
sqlBuilder.append(" and to_char(a.customer_id) like :p_customer_id");
sqlBuilder.append(" and to_char(a.contact_status) in (:p_list_contact_status)");
sqlBuilder.append(" and to_char(a.call_status) in (:p_list_survey_status)");
sqlBuilder.append(" and to_char(a.status) in (:p_list_record_status)");
if (!DataUtil.isNullOrEmpty(dto.getPhoneNumber())) {
sqlBuilder.append(" and a.phone_number like :p_phone_number");
}
if (!DataUtil.isNullOrEmpty(dto.getCampaignId())) {
sqlBuilder.append(" and b.campaign_code in (:p_list_campaign_id) ");
}
if (!DataUtil.isNullOrEmpty(dto.getCampaignName())) {
sqlBuilder.append(" and upper(campaignName) like upper(:p_campaign_name)");
sqlBuilder.append(" and upper(b.campaign_name) like :p_campaign_name");
}
if (!DataUtil.isNullOrEmpty(dto.getAgentId())) {
sqlBuilder.append(" and upper(userName) like upper(:p_user_name)");
sqlBuilder.append(" and upper(c.user_name) like :p_user_name");
}
SQLQuery query = session.createSQLQuery(sqlBuilder.toString());
query.setParameterList("p_list_campaign_id", dto.getCampaignId().split(","));
query.setParameter("p_customer_id", dto.getCustomerId());
query.setParameter("p_company_site_id", dto.getCompanySiteId());
query.setParameter("p_customer_id", "%" + dto.getCustomerId()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
query.setParameter("p_date_from", dto.getFromDate());
query.setParameter("p_date_to", dto.getToDate());
query.setParameterList("p_list_compaign_type", dto.getCampaignType().split(","));
query.setParameterList("p_list_contact_status", dto.getContactStatus().split(","));
query.setParameterList("p_list_survey_status", dto.getSurveyStatus().split(","));
query.setParameterList("p_list_record_status", dto.getRecordStatus().split(","));
query.setParameter("p_phone_number", dto.getPhoneNumber());
query.setParameter("p_call_time_from", dto.getCallTimeFrom());
query.setParameter("p_call_time_to", dto.getCallTimeTo());
if (!DataUtil.isNullOrEmpty(dto.getCampaignId())) {
query.setParameterList("p_list_campaign_id", dto.getCampaignId().split(","));
}
if (!DataUtil.isNullOrEmpty(dto.getPhoneNumber())) {
query.setParameter("p_phone_number", "%" + dto.getPhoneNumber()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
if (!DataUtil.isNullOrEmpty(dto.getCampaignName())) {
query.setParameter("p_campaign_name", dto.getCampaignName().trim());
query.setParameter("p_campaign_name", "%" + dto.getCampaignName().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
if (!DataUtil.isNullOrEmpty(dto.getAgentId())) {
query.setParameter("p_user_name", dto.getAgentId().trim());
query.setParameter("p_user_name", "%" + dto.getAgentId().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
query.addScalar("campaignCode", new StringType());
query.addScalar("campaignName", new StringType());
query.addScalar("userName", new StringType());
query.addScalar("phoneNumber", new LongType());
query.addScalar("phoneNumber", new StringType());
query.addScalar("customerName", new StringType());
query.addScalar("createTime", new DateType());
query.addScalar("contactStatus", new StringType());
query.addScalar("surveyStatus", new StringType());
query.addScalar("status", new ShortType());
query.addScalar("recordStatus", new ShortType());
query.addScalar("callTime", new LongType());
query.setResultTransformer(Transformers.aliasToBean(ContactCustResultDTO.class));
......@@ -161,9 +195,9 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
logger.error(e.getMessage(), e);
} finally {
session.close();
}
return resultDTO;
}
}
@Override
public List<ContactCustResultDTO> getExcelInteractiveResult(CampaignRequestDTO dto) {
......@@ -177,43 +211,78 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
String sql = SQLBuilder.getSqlQueryById(Constants.SQL_MODULES.MODULE_EXECUTE, "get-execute-interactive");
sqlBuilder.append(sql);
sqlBuilder.append(" and b.campaign_type in (:p_list_compaign_type)");
sqlBuilder.append(" and to_char(a.customer_id) like :p_customer_id");
sqlBuilder.append(" and to_char(a.contact_status) in (:p_list_contact_status)");
sqlBuilder.append(" and to_char(a.call_status) in (:p_list_survey_status)");
sqlBuilder.append(" and to_char(a.status) in (:p_list_record_status)");
if (!DataUtil.isNullOrEmpty(dto.getPhoneNumber())) {
sqlBuilder.append(" and a.phone_number like :p_phone_number");
}
if (!DataUtil.isNullOrEmpty(dto.getCampaignId())) {
sqlBuilder.append(" and b.campaign_code in (:p_list_campaign_id) ");
}
if (!DataUtil.isNullOrEmpty(dto.getCampaignName())) {
sqlBuilder.append(" and upper(campaignName) like upper(:p_campaign_name)");
sqlBuilder.append(" and upper(b.campaign_name) like :p_campaign_name");
}
if (!DataUtil.isNullOrEmpty(dto.getAgentId())) {
sqlBuilder.append(" and upper(userName) like upper(:p_user_name)");
sqlBuilder.append(" and upper(c.user_name) like :p_user_name");
}
SQLQuery query = session.createSQLQuery(sqlBuilder.toString());
query.setParameterList("p_list_campaign_id", dto.getCampaignId().split(","));
query.setParameter("p_customer_id", dto.getCustomerId());
query.setParameter("p_company_site_id", dto.getCompanySiteId());
query.setParameter("p_customer_id", "%" + dto.getCustomerId()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
query.setParameter("p_date_from", dto.getFromDate());
query.setParameter("p_date_to", dto.getToDate());
query.setParameterList("p_list_compaign_type", dto.getCampaignType().split(","));
query.setParameterList("p_list_contact_status", dto.getContactStatus().split(","));
query.setParameterList("p_list_survey_status", dto.getSurveyStatus().split(","));
query.setParameterList("p_list_record_status", dto.getRecordStatus().split(","));
query.setParameter("p_phone_number", dto.getPhoneNumber());
query.setParameter("p_call_time_from", dto.getCallTimeFrom());
query.setParameter("p_call_time_to", dto.getCallTimeTo());
if (!DataUtil.isNullOrEmpty(dto.getCampaignId())) {
query.setParameterList("p_list_campaign_id", dto.getCampaignId().split(","));
}
if (!DataUtil.isNullOrEmpty(dto.getPhoneNumber())) {
query.setParameter("p_phone_number", "%" + dto.getPhoneNumber()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
if (!DataUtil.isNullOrEmpty(dto.getCampaignName())) {
query.setParameter("p_campaign_name", dto.getCampaignName().trim());
query.setParameter("p_campaign_name", "%" + dto.getCampaignName().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
if (!DataUtil.isNullOrEmpty(dto.getAgentId())) {
query.setParameter("p_user_name", dto.getAgentId().trim());
query.setParameter("p_user_name", "%" + dto.getAgentId().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\%")
.replaceAll("_", "\\_")
+ "%");
}
query.addScalar("campaignCode", new StringType());
query.addScalar("campaignName", new StringType());
query.addScalar("userName", new StringType());
query.addScalar("phoneNumber", new LongType());
query.addScalar("phoneNumber", new StringType());
query.addScalar("customerName", new StringType());
query.addScalar("createTime", new DateType());
query.addScalar("contactStatus", new StringType());
query.addScalar("surveyStatus", new StringType());
query.addScalar("status", new ShortType());
query.addScalar("recordStatus", new ShortType());
query.addScalar("callTime", new LongType());
query.setResultTransformer(Transformers.aliasToBean(ContactCustResultDTO.class));
......@@ -226,6 +295,11 @@ public class CampaignExecuteRepositoryImp implements CampaignExecuteRepository {
}
}
@Override
public List<ContactCustResultDTO> getContactCustById(CampaignRequestDTO dto) {
return null;
}
private boolean isLower24Hour(Date createTime) {
Date currTime = new Date();
long diffMilSec = currTime.getTime() - createTime.getTime();
......
......@@ -42,10 +42,10 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO result = new ResultDTO();
List<CampaignDTO> lst = new ArrayList<>();
StringBuilder expression = new StringBuilder()
.append(" SELECT C.CAMPAIGN_CODE, C.CAMPAIGN_NAME, C.CONTENT, C.START_TIME, C.END_TIME, C.STATUS, CA.STATUS AS AGENT_STATUS ")
.append(" SELECT C.CAMPAIGN_CODE, C.CAMPAIGN_NAME, C.CONTENT, C.START_TIME, C.END_TIME, C.STATUS, CA.STATUS AS AGENT_STATUS, C.CAMPAIGN_ID ")
.append(" FROM CAMPAIGN C INNER JOIN CAMPAIGN_AGENT CA ON C.CAMPAIGN_ID = CA.CAMPAIGN_ID ")
.append(" WHERE 1 = 1 ");
//.append(" AND CA.AGENT_ID = :pAgentId ")
.append(" WHERE 1 = 1 ")
.append(" AND CA.AGENT_ID = :pAgentId ");
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) {
expression.append(" AND C.CAMPAIGN_CODE IN (:pCampaignCode) ");
......@@ -59,7 +59,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
if (campaignRequestDto.getStatus() != 0)
expression.append(" AND C.STATUS = :pStatus ");
else
expression.append(" AND C.STATUS IN (1, 2, 3) ");
expression.append(" AND C.STATUS IN (2, 3) ");
}
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getFromDateFr())) {
......@@ -88,7 +88,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
try {
Query query = entityManager.createNativeQuery(expression.toString());
//query.setParameter("pAgentId", campaignRequestDto.getAgentId());
query.setParameter("pAgentId", campaignRequestDto.getAgentId());
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) {
String[] lstCode = campaignRequestDto.getCampaignCode().split(",");
......@@ -155,6 +155,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
item.setEndTime((Date) obj[4]);
item.setStatus(((BigDecimal) obj[5]).shortValueExact());
item.setAgentStatus(((BigDecimal) obj[6]).shortValueExact());
item.setCampaignId(((BigDecimal) obj[7]).longValueExact());
lst.add(item);
}
......
package com.viettel.campaign.service;
import com.viettel.campaign.web.dto.ResultDTO;
public interface AgentsService {
ResultDTO getAgentsByAgentId(String agentId);
}
package com.viettel.campaign.service;
import com.viettel.campaign.web.dto.ContactCustResultDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface CampaignExecuteService {
//<editor-fold: hungtt>
......@@ -15,5 +18,7 @@ public interface CampaignExecuteService {
ResultDTO searchInteractiveResult(CampaignRequestDTO dto);
XSSFWorkbook exportInteractiveResult(CampaignRequestDTO dto);
List<ContactCustResultDTO> getContactCustById(CampaignRequestDTO dto);
//</editor-fold>
}
package com.viettel.campaign.service;
import com.viettel.campaign.model.ccms_full.Customer;
import com.viettel.campaign.model.ccms_full.CustomerList;
import com.viettel.campaign.web.dto.CustomerContactDTO;
import com.viettel.campaign.web.dto.CustomerDTO;
import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import java.util.Date;
import java.util.List;
import java.util.List;
public interface CustomerService {
ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId);
......@@ -44,12 +47,18 @@ public interface CustomerService {
// danh sach khach hang cua chien dich //
ResultDTO searchCustomerListInfoFromCustomerList(int page, int pageSize, String sort, Long campaignId, Long companySiteId);
List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO);
List<CustomerDTO> getIndividualCustomerInfo(CampaignCustomerDTO campaignCustomerDTO);
// ------------ customer ------------ //
ResultDTO getCustomerRecall(Long campaignId, Long customerId);
List<Customer> findAllByCondition(Long siteId, Date endTime);
Customer update(Customer c);
}
package com.viettel.campaign.service;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CustomerTime;
import com.viettel.campaign.repository.ccms_full.CustomerTimeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* @author hanv_itsol
* @project campaign
*/
@Service
@Transactional
public class CustomerTimeService {
@Autowired
private CustomerTimeRepository customerTimeRepository;
@Transactional(DataSourceQualify.CCMS_FULL)
public CustomerTime update(CustomerTime customerTime){
return customerTimeRepository.save(customerTime);
}
@Transactional(DataSourceQualify.CCMS_FULL)
public List<CustomerTime> findByCustomerId(Long customerId){
return customerTimeRepository.findByCustomerId(customerId);
}
}
package com.viettel.campaign.service;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.ProcessConfig;
import com.viettel.campaign.repository.ccms_full.ProcessConfigRepository;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -20,17 +21,18 @@ public class ProcessConfigService {
@Autowired
private ProcessConfigRepository processConfigRepository;
@Transactional(readOnly = true)
@Transactional(DataSourceQualify.CCMS_FULL)
public List<ProcessConfig> findAll(){
return processConfigRepository.findAll();
}
@Transactional(readOnly = true)
@Transactional(DataSourceQualify.CCMS_FULL)
public List<ProcessConfig> findAllByCode(String configCode){
return processConfigRepository.findAllByConfigCode(configCode);
}
@Transactional(DataSourceQualify.CCMS_FULL)
public void update(ProcessConfig pc){
processConfigRepository.save(pc);
}
......
package com.viettel.campaign.service.impl;
import com.viettel.campaign.model.acd_full.Agents;
import com.viettel.campaign.repository.acd_full.AgentsRepository;
import com.viettel.campaign.service.AgentsService;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.web.dto.ResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class AgentsServiceImpl implements AgentsService {
@Autowired
AgentsRepository agentsRepository;
@Override
public ResultDTO getAgentsByAgentId(String agentId) {
ResultDTO result = new ResultDTO();
Agents data = agentsRepository.getByAgentId(agentId);
if (data != null) {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription("agents data");
result.setData(data);
} else {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription("agents data null");
}
return result;
}
}
......@@ -178,6 +178,12 @@ public class CampaignExecuteServiceImp implements CampaignExecuteService {
return workbook;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public List<ContactCustResultDTO> getContactCustById(CampaignRequestDTO dto) {
return campaignExecuteRepository.getContactCustById(dto);
}
private void writeCellContent(Row row, CellStyle rowStyle, int colNo, Object content) {
Cell cell = row.createCell(colNo);
if (content == null) {
......
......@@ -168,6 +168,7 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO;
}
@Transactional(DataSourceQualify.CCMS_FULL)
public Map countRecallCustomer(Long companySiteId, Long agentId) {
Map result = new HashMap();
Long count = campaignRepository.countRecallCustomer(companySiteId, agentId);
......
package com.viettel.campaign.service.impl;
import com.viettel.campaign.config.CCMSFullDatasourceConfig;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.mapper.CustomerListMapper;
import com.viettel.campaign.mapper.CustomerMapper;
......@@ -24,15 +25,20 @@ import org.hibernate.type.LongType;
import org.hibernate.type.ShortType;
import org.hibernate.type.StringType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.*;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.Date;
import java.util.List;
import javax.sql.DataSource;
import java.util.*;
@Service
public class CustomerServiceImpl implements CustomerService {
......@@ -59,6 +65,10 @@ public class CustomerServiceImpl implements CustomerService {
@Autowired
CustomerListMappingRepository customerListMappingRepository;
@Autowired
@Qualifier(DataSourceQualify.NAMED_JDBC_PARAMETER_TEMPLATE_CCMS_FULL)
NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId) {
......@@ -94,8 +104,19 @@ public class CustomerServiceImpl implements CustomerService {
query.addScalar("companyName", new StringType());
query.addScalar("customerType", new StringType());
query.addScalar("currentAddress", new StringType());
query.addScalar("callAllowed", new ShortType());
query.addScalar("emailAllowed", new ShortType());
query.addScalar("smsAllowed", new ShortType());
query.addScalar("ipccStatus", new StringType());
query.addScalar("mobileNumber", new StringType());
query.addScalar("email", new StringType());
query.addScalar("title", new StringType());
query.addScalar("type", new StringType());
query.addScalar("valueCombobox", new StringType());
query.addScalar("valueCheckbox", new ShortType());
query.addScalar("valueDate", new DateType());
query.addScalar("valueNumber", new LongType());
query.addScalar("valueText", new StringType());
query.setResultTransformer(Transformers.aliasToBean(CustomerCustomDTO.class));
int count = 0;
......@@ -666,20 +687,46 @@ public class CustomerServiceImpl implements CustomerService {
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO searchCustomerListInfoFromCustomerList(int page, int pageSize, String sort, Long campaignId, Long companySiteId) {
ResultDTO resultDTO = new ResultDTO();
public List<CustomerListDTO> getCustomerListInfo(CampaignCustomerDTO campaignCustomerDTO) {
List<CustomerListDTO> customerList;
try {
String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-customer-list-info-from-customer-list");
Query query = entityManager.createNativeQuery(sql);
query.setParameter("p_campaign_id", campaignId);
query.setParameter("p_company_site_id", companySiteId);
resultDTO.setListData(query.getResultList());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
Map<String, Object> param = new HashMap<>();
param.put("p_campaign_id", campaignCustomerDTO.getCampaignId());
param.put("p_company_site_id", campaignCustomerDTO.getCompanySiteId());
param.put("p_page_number", campaignCustomerDTO.getPage());
param.put("p_page_size", campaignCustomerDTO.getPageSize());
customerList = namedParameterJdbcTemplate.query(sql, param, new BeanPropertyRowMapper<>(CustomerListDTO.class));
} catch (Exception e) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(e.getMessage());
return null;
}
return resultDTO;
return customerList;
}
@Override
public List<CustomerDTO> getIndividualCustomerInfo(CampaignCustomerDTO campaignCustomerDTO) {
List<CustomerDTO> customerList;
try {
String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-individual-customer");
Map<String, Object> param = new HashMap<>();
param.put("p_page_number", campaignCustomerDTO.getPage());
param.put("p_page_size", campaignCustomerDTO.getPageSize());
customerList = namedParameterJdbcTemplate.query(sql, param, new BeanPropertyRowMapper<>(CustomerDTO.class));
} catch (Exception e) {
return null;
}
return customerList;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public List<Customer> findAllByCondition(Long siteId, Date endTime) {
return customerRepository.findAllByCondition(siteId, endTime);
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public Customer update(Customer c) {
return customerRepository.save(c);
}
}
......@@ -7,7 +7,7 @@ import java.util.Date;
@Getter
@Setter
public class CampaignCustomerDTO {
public class CampaignCustomerDTO extends BaseDTO{
private Long campaignCustomerListId;
private Long campaignId;
private Long customerId;
......
......@@ -19,7 +19,7 @@ public class ContactCustResultDTO extends BaseDTO{
private Short recordStatus;
private String description;
private Date createTime;
private String callTime;
private Long callTime;
private Long agentId;
private Long campaignId;
private String campaignName;
......
......@@ -3,6 +3,8 @@ package com.viettel.campaign.web.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
public class CustomerCustomDTO {
......@@ -15,6 +17,17 @@ public class CustomerCustomDTO {
String companyName;
String customerType;
String currentAddress;
Short callAllowed;
Short emailAllowed;
Short smsAllowed;
String ipccStatus;
String mobileNumber;
String email;
String title;
String type;
String valueCombobox;
Short valueCheckbox;
Date valueDate;
Long valueNumber;
String valueText;
}
......@@ -21,4 +21,7 @@ public class CustomerListDTO extends BaseDTO {
private Date updateAt;
private String source;
private String deptCreate;
private Long totalCusInList;
private Long totalCusInteract;
private Long totalCusNotInteract;
}
......@@ -41,4 +41,5 @@ public class CampaignRequestDTO extends BaseDTO {
String campaignId;
String surveyStatus;
String roleUser;
String contactCustId;
}
package com.viettel.campaign.web.rest;
import com.viettel.campaign.service.AgentsService;
import com.viettel.campaign.web.dto.ResultDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/ipcc/agents")
@CrossOrigin
public class AgentsController {
private static final Logger logger = LoggerFactory.getLogger(CampaignController.class);
@Autowired
AgentsService agentsService;
@GetMapping("/getAgentsById")
@ResponseBody
public ResponseEntity<ResultDTO> getAgentsById(@RequestParam("agentId") String agentId) {
ResultDTO result = agentsService.getAgentsByAgentId(agentId);
return new ResponseEntity<>(result, HttpStatus.OK);
}
}
......@@ -77,12 +77,14 @@ public class CampaignCompleteCodeController {
result = completeCodeService.deleteCompleteCode(completeCodeDTO);
return result;
}
@PostMapping("/listDelete")
@ResponseBody
public ResponseEntity<ResultDTO> deleteList(@RequestBody @Valid List<Long>completeCodeDtos ){
ResultDTO resultDTO = completeCodeService.deleteList(completeCodeDtos);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@PostMapping("/deleteById")
@ResponseBody
public ResultDTO deleteById(@RequestParam("id") Long id){
......
......@@ -13,6 +13,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.instrument.reactor.ReactorSleuth;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
......@@ -164,7 +165,6 @@ public class CampaignController {
headers.setContentType(MediaType.parseMediaType("application/vnd.ms-excel"));
return new ResponseEntity<byte[]>(contentReturn, headers, HttpStatus.OK);
}
@RequestMapping(value = "/findCampaignTimeRangeMode", method = RequestMethod.GET)
public List<TimeRangeDialMode> findCampaignTimeRangeMode(@RequestParam Long campaignId, @RequestParam Long companySiteId) {
return timeRangeDialModeRepository.findTimeRangeDialModeByCampaignIdAndCompanySiteId(campaignId, companySiteId);
......
......@@ -179,7 +179,7 @@ public class CustomerController {
return new ResponseEntity(result, HttpStatus.OK);
}
@GetMapping("/getCustomerRecall")
@PostMapping("/getCustomerRecall")
@ResponseBody
public ResponseEntity<ResultDTO> getCustomerRecall(@RequestParam("campaignId") Long campaignId, @RequestParam("customerId") Long customerId) {
ResultDTO result = customerService.getCustomerRecall(campaignId, customerId);
......@@ -248,6 +248,6 @@ public class CustomerController {
@RequestParam("sort") String sort,
@RequestParam("campaignId") Long campaignId,
@RequestParam("companySiteId") Long companySiteId) {
return customerService.searchCustomerListInfoFromCustomerList(page, pageSize, sort, campaignId, companySiteId);
return null;//customerService.searchCustomerListInfoFromCustomerList(page, pageSize, sort, campaignId, companySiteId);
}
}
select PAR_VALUE apParamId,
PAR_NAME parName
from AP_PARAM
where PAR_TYPE = 'CAMPAIGN_TYPE' and COMPANY_SITE_ID = :p_company_site_id
where PAR_TYPE = 'CAMPAIGN_TYPE'
and COMPANY_SITE_ID = :p_company_site_id
and IS_DELETE = 0
select COMPLETE_VALUE apParamId,
select distinct COMPLETE_VALUE apParamId,
COMPLETE_NAME parName
from CAMPAIGN_COMPLETE_CODE
where to_char(COMPLETE_TYPE) = :p_complete_type and STATUS = 1 and COMPANY_SITE_ID = :p_company_site_id
......@@ -3,11 +3,12 @@ select b.campaign_code campaignCode,
c.user_name userName,
a.phone_number phoneNumber,
d.name customerName,
a.create_time createTime,
to_date(a.start_call, 'DD/MM/YYYY') startCall,
e.complete_name contactStatus,
f.complete_name surveyStatus,
g.status status,
a.status recordStatus
a.status recordStatus,
(a.end_time - a.start_call)*24*60 callTime
from contact_cust_result a
left join campaign b on a.campaign_id = b.campaign_id
left join vsa_users c on a.agent_id = c.user_id
......
-- select
-- a.CUSTOMER_LIST_MAPPING_ID customerListMappingId,
-- a.COMPANY_SITE_ID companySiteId,
-- a.CUSTOMER_LIST_ID customerListId,
-- a.CUSTOMER_ID customerId,
-- b.NAME name,
-- b.DESCRIPTION description,
-- b.COMPANY_NAME companyName,
-- b.CUSTOMER_TYPE customerType,
-- b.CURRENT_ADDRESS currentAddress,
-- b.CALL_ALLOWED callAllowed,
-- b.EMAIL_ALLOWED emailAllowed,
-- b.SMS_ALLOWED smsAllowed,
-- b.IPCC_STATUS ipccStatus,
-- c.MOBILE mobileNumber,
-- d.EMAIL email
-- from CUSTOMER_LIST_MAPPING a
-- join CUSTOMER b on a.CUSTOMER_ID = b.CUSTOMER_ID
-- left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY NULL) AS MOBILE
-- FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 GROUP BY CUSTOMER_ID) c on b.CUSTOMER_ID = c.CUSTOMER_ID
-- left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY NULL) AS EMAIL
-- FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 GROUP BY CUSTOMER_ID) d on b.CUSTOMER_ID = d.CUSTOMER_ID
-- where 1 = 1
-- and COMPANY_SITE_ID = :p_company_site_id
-- and CUSTOMER_LIST_ID = :p_customer_list_id
-- test dynamic field
select
a.CUSTOMER_LIST_MAPPING_ID customerListMappingId,
a.COMPANY_SITE_ID companySiteId,
......@@ -8,14 +36,31 @@ select
b.COMPANY_NAME companyName,
b.CUSTOMER_TYPE customerType,
b.CURRENT_ADDRESS currentAddress,
b.CALL_ALLOWED callAllowed,
b.EMAIL_ALLOWED emailAllowed,
b.SMS_ALLOWED smsAllowed,
b.IPCC_STATUS ipccStatus,
c.MOBILE mobileNumber,
d.EMAIL email
d.EMAIL email,
e.TITLE title,
f.TYPE type,
h.VALUE_COMBOBOX valueCombobox,
e.VALUE_CHECKBOX valueCheckbox,
e.VALUE_DATE valueDate,
e.VALUE_NUMBER valueNumber,
e.VALUE_TEXT valueText
from CUSTOMER_LIST_MAPPING a
join CUSTOMER b on a.CUSTOMER_ID = b.CUSTOMER_ID
left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY NULL) AS MOBILE
FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 GROUP BY CUSTOMER_ID) c on b.CUSTOMER_ID = c.CUSTOMER_ID
left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY NULL) AS EMAIL
FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 GROUP BY CUSTOMER_ID) d on b.CUSTOMER_ID = d.CUSTOMER_ID
left join CUSTOMIZE_FIELD_OBJECT e on b.CUSTOMER_ID = e.OBJECT_ID
left join CUSTOMIZE_FIELDS f on e.CUSTOMIZE_FIELDS_ID = f.CUSTOMIZE_FIELD_ID
left join (SELECT FIELD_OPTION_VALUE_ID, NAME AS VALUE_COMBOBOX
FROM CUSTOMIZE_FIELD_OPTION_VALUE) h on h.FIELD_OPTION_VALUE_ID = e.FIELD_OPTION_VALUE_ID
where 1 = 1
and COMPANY_SITE_ID = :p_company_site_id
and CUSTOMER_LIST_ID = :p_customer_list_id
and a.COMPANY_SITE_ID = :p_company_site_id
and a.CUSTOMER_LIST_ID = :p_customer_list_id
and e.FUNCTION_CODE = 'CUSTOMER'
order by a.CUSTOMER_ID
......@@ -19,16 +19,26 @@ count(customer_id) ktt
from campaign_customer where campaign_id = :p_campaign_id and status = 0
and in_campaign_status = 1
group by customer_list_id, company_site_id
)
select customer_list_code ma,
customer_list_name ten,
cl.company_site_id,
nvl(total, 0) tong,
nvl(tt, 0) tongtt,
nvl(ktt, 0) tongktt
), datas as (
select customer_list_code customerListCode,
customer_list_name customerListName,
nvl(total, 0) totalCusInList,
nvl(tt, 0) totalCusInteract,
nvl(ktt, 0) totalCusNotInteract
from customer_list cl
left join totalCustomer tc on (cl.customer_list_id = tc.customer_list_id and cl.company_site_id = tc.company_site_id)
left join customerInteractive ci on (cl.customer_list_id = ci.customer_list_id and cl.company_site_id = ci.company_site_id)
left join customerNotInteractive cni on (cl.customer_list_id = cni.customer_list_id and cl.company_site_id = cni.company_site_id)
where cl.company_site_id = :p_company_site_id
order by customer_list_code
\ No newline at end of file
)
select * from
(
select a.*, rownum r__
from
(
select * from datas
order by customerListCode
) a
where rownum < ((:p_page_number * :p_page_size) + 1 )
)
where r__ >= (((:p_page_number-1) * :p_page_size) + 1)
\ No newline at end of file
with cusPhone as (
select customer_id cusId,
contact phone
from customer_contact cc
where cc.contact_type = 5
and status = 1
), cusEmail as (
select customer_id cusId,
contact email
from customer_contact cc
where cc.contact_type = 2
and status = 1
), datas as (
select c.name,
cP.phone,
cE.email,
c.customer_type cusType,
c.company_name compName,
c.current_address currentAddress,
c.description
from customer c
left join cusPhone cP on c.customer_id = cP.cusId
left join cusEmail cE on c.customer_id = cE.cusId
)
select * from
(
select a.*, rownum r__
from
(
select * from datas
order by datas.name
) a
where rownum < ((:p_page_number * :p_page_size) + 1 )
)
where r__ >= (((:p_page_number-1) * :p_page_size) + 1)
\ No newline at end of file
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