Commit f20a6bab authored by Tu Bach's avatar Tu Bach
parents 017b7bd8 bc521952
......@@ -18,8 +18,8 @@ public class ServiceCampaignApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceCampaignApplication.class, args);
// RedisUtil redis = new RedisUtil(Config.redisAddress,Config.redisTimeout);
// redis.setup();
RedisUtil redis = new RedisUtil(Config.redisAddress,Config.redisTimeout);
redis.setup();
}
}
......@@ -26,19 +26,19 @@ import java.util.concurrent.ScheduledFuture;
* @project campaign
*/
//@Slf4j
//@EnableScheduling
//@Configuration
//public class JobConfig implements SchedulingConfigurer {
//
// TaskScheduler taskScheduler;
// private ScheduledFuture<?> job1;
// private ScheduledFuture<?> job2;
//
// @Bean
// public CampaignJob campaignJob(){
// return new CampaignJob();
// }
@Slf4j
@EnableScheduling
@Configuration
public class JobConfig implements SchedulingConfigurer {
TaskScheduler taskScheduler;
private ScheduledFuture<?> job1;
private ScheduledFuture<?> job2;
@Bean
public CampaignJob campaignJob(){
return new CampaignJob();
}
// @Override
// public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
......@@ -53,47 +53,47 @@ import java.util.concurrent.ScheduledFuture;
// taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
// }
// private void job1(TaskScheduler scheduler) {
// job1 = scheduler.schedule(() -> {
// log.info("processing job1 ...");
// log.info(Thread.currentThread().getName() + " The Task1 executed at " + new Date());
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }, triggerContext -> {
//
// String cronExp = "0/5 * * * * ?";// Can be pulled from a db .
// return new CronTrigger(cronExp).nextExecutionTime(triggerContext);
// });
// }
//
// private void job2(TaskScheduler scheduler) {
// job2 = scheduler.schedule(() -> {
// 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
// return new CronTrigger(cronExp).nextExecutionTime(triggerContext);
// });
// }
//
//
//
// @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);
// });
// }
//}
private void job1(TaskScheduler scheduler) {
job1 = scheduler.schedule(() -> {
log.info("processing job1 ...");
log.info(Thread.currentThread().getName() + " The Task1 executed at " + new Date());
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}, triggerContext -> {
String cronExp = "0/5 * * * * ?";// Can be pulled from a db .
return new CronTrigger(cronExp).nextExecutionTime(triggerContext);
});
}
private void job2(TaskScheduler scheduler) {
job2 = scheduler.schedule(() -> {
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
return new CronTrigger(cronExp).nextExecutionTime(triggerContext);
});
}
@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);
});
}
}
......@@ -13,7 +13,7 @@ import java.io.IOException;
@Component
public class CorsFilter implements Filter {
private Logger logger = Logger.getLogger(CorsFilter.class);
// private Logger logger = Logger.getLogger(CorsFilter.class);
@Override
public void init(FilterConfig filterConfig){
......@@ -31,28 +31,27 @@ public class CorsFilter implements Filter {
HttpServletRequest request = (HttpServletRequest) req;
chain.doFilter(req, resp);
// if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
// chain.doFilter(req, resp);
// return;
// }
// logger.info("uri: "+ request.getRequestURI());
// if ("/".equals(request.getRequestURI())) {
// chain.doFilter(req, resp);
// return;
// }
// String xAuthToken = request.getHeader("X-Auth-Token");
// if (xAuthToken == null || "".equals(xAuthToken)) {
// response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is null.");
// return;
// }
// Object obj = RedisUtil.getInstance().get(xAuthToken);
// if (obj instanceof UserSession) {
// chain.doFilter(req, resp);
// } else {
// response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is invalid.");
// }
// chain.doFilter(req, resp);
if ("OPTIONS".equalsIgnoreCase(request.getMethod())) {
chain.doFilter(req, resp);
return;
}
if ("/".equals(request.getRequestURI())) {
chain.doFilter(req, resp);
return;
}
String xAuthToken = request.getHeader("X-Auth-Token");
if (xAuthToken == null || "".equals(xAuthToken)) {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is null.");
return;
}
Object obj = RedisUtil.getInstance().get(xAuthToken);
if (obj instanceof UserSession) {
chain.doFilter(req, resp);
} else {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "The token is invalid.");
}
}
@Override
......
......@@ -17,4 +17,9 @@ public interface CampaignRepositoryCustom {
String getMaxCampaignIndex();
ResultDTO checkAllowStatusToPrepare(Long campaignId);
//hungtt
ResultDTO findCustomerListReallocation(CampaignRequestDTO dto);
//hungtt
ResultDTO reallocationCustomer(CampaignRequestDTO dto);
}
package com.viettel.campaign.repository.ccms_full.impl;
import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.CampaignCustomer;
import com.viettel.campaign.repository.ccms_full.CampaignRepositoryCustom;
import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.DataUtil;
import com.viettel.campaign.utils.HibernateUtil;
import com.viettel.campaign.utils.SQLBuilder;
import com.viettel.campaign.web.dto.CampaignDTO;
import com.viettel.campaign.web.dto.CustomerCustomDTO;
import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.apache.logging.log4j.LogManager;
......@@ -17,16 +19,18 @@ import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.hibernate.type.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.*;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
@Repository
public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
......@@ -37,6 +41,10 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
@PersistenceContext( unitName= DataSourceQualify.JPA_UNIT_NAME_CCMS_FULL)
EntityManager entityManager;
@Autowired
@Qualifier(DataSourceQualify.NAMED_JDBC_PARAMETER_TEMPLATE_CCMS_FULL)
NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Override
public ResultDTO search(CampaignRequestDTO requestDto) {
logger.info("Start search campaign::");
......@@ -322,4 +330,51 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
return result;
}
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO findCustomerListReallocation(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
List<CustomerCustomDTO> list = new ArrayList<>();
Map<String, String> params = new HashMap<>();
try {
String sql = SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "get-list-customer-reallocation");
params.put("p_company_site_id", dto.getCompanySiteId());
params.put("p_campaign_id", dto.getCampaignId());
params.put("p_list_connect_status", dto.getConnectStatus());
params.put("p_page_size", dto.getPageSize().toString());
params.put("p_page_number", dto.getPage().toString());
list = namedParameterJdbcTemplate.query(sql, params, BeanPropertyRowMapper.newInstance(CustomerCustomDTO.class));
resultDTO.setListData(list);
resultDTO.setTotalRow(list.size());
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
public ResultDTO reallocationCustomer(CampaignRequestDTO dto) {
ResultDTO resultDTO = new ResultDTO();
try {
List<CustomerCustomDTO> list = dto.getCustomerCustomDTOList();
for (CustomerCustomDTO customerCustomDTO: list) {
CampaignCustomer campaignCustomer = entityManager.find(CampaignCustomer.class, customerCustomDTO.getCampaignCustomerId());
campaignCustomer.setStatus((short) 0);
campaignCustomer.setCallStatus(null);
campaignCustomer.setRedistribute((short) 1);
}
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;
}
}
......@@ -49,4 +49,10 @@ public interface CampaignService {
ResultDTO renewCampaign(CampaignDTO campaignDTO);
ResultDTO updateCampaign(CampaignDTO dto);
//<editor-fold: hungtt>
ResultDTO findCustomerListReallocation(CampaignRequestDTO dto);
ResultDTO reallocationCustomer(CampaignRequestDTO dto);
//</editor-fold>
}
......@@ -452,6 +452,20 @@ public class CampaignServiceImpl implements CampaignService {
return resultDTO;
}
// hungtt
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO findCustomerListReallocation(CampaignRequestDTO dto) {
return campaignRepositoryCustom.findCustomerListReallocation(dto);
}
// hungtt
@Override
@Transactional(DataSourceQualify.CCMS_FULL)
public ResultDTO reallocationCustomer(CampaignRequestDTO dto) {
return campaignRepositoryCustom.reallocationCustomer(dto);
}
private String generateCampaignCode(String campaignType, Short chanel) {
int year = Calendar.getInstance().get(Calendar.YEAR);
String maxIndexStr = campaignRepositoryCustom.getMaxCampaignIndex();
......
package com.viettel.campaign.utils;
//import com.viettel.security.PassTranformer;
import com.viettel.security.PassTranformer;
import org.apache.log4j.Logger;
import java.io.File;
......@@ -60,7 +60,7 @@ public class Config {
} catch (IOException ex) {
Logger.getLogger(Config.class.getName()).error(ex.getMessage(), ex);
}
// PassTranformer.setInputKey("Ipcc#987654321#@!");
PassTranformer.setInputKey("Ipcc#987654321#@!");
// rabbitConnection = properties.getProperty("rabbit_connection_string");
// fbGatewayUser = PassTranformer.decrypt(properties.getProperty("rabbit_user", "").trim());
......
......@@ -105,7 +105,7 @@ public class RedisUtil {
JedisCluster jedis = getRedis();
byte[] value = jedis.get(key.getBytes());
if (value != null && value.length > 0) {
object = SerializationUtils.deserialize(value);
object = (Object) SerializationUtils.deserialize(value);
}
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
......
......@@ -23,4 +23,8 @@ public class CustomerCustomDTO {
String ipccStatus;
String mobileNumber;
String email;
String connectStatus;
String connectTime;
String customerName;
Long campaignCustomerId;
}
package com.viettel.campaign.web.dto.request_dto;
import com.viettel.campaign.web.dto.BaseDTO;
import com.viettel.campaign.web.dto.CustomerCustomDTO;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* @author anhvd_itsol
*/
......@@ -42,4 +45,5 @@ public class CampaignRequestDTO extends BaseDTO {
String surveyStatus;
String roleUser;
String contactCustId;
List<CustomerCustomDTO> customerCustomDTOList;
}
......@@ -21,6 +21,8 @@ public class ApParamController {
private static final String CONNECT_STATUS = "CONNECT_STATUS";
private static final String CONNECT_STATUS_TYPE = "1";
private static final String CONNECT_STATUS_RE = "CONNECT_STATUS_RE";
private static final String CONNECT_STATUS_TYPE_RE = "3";
private static final String SURVEY_STATUS = "SURVEY_STATUS";
private static final String SURVEY_STATUS_TYPE = "2";
private static final String CAMPAIGN_TYPE = "CAMPAIGN_TYPE";
......@@ -74,6 +76,8 @@ public class ApParamController {
return new ResponseEntity<>(campaignExecuteService.getComboBoxStatus(companySiteId, CONNECT_STATUS_TYPE), HttpStatus.OK);
} else if (SURVEY_STATUS.equals(parType)){
return new ResponseEntity<>(campaignExecuteService.getComboBoxStatus(companySiteId, SURVEY_STATUS_TYPE), HttpStatus.OK);
} else if (CONNECT_STATUS_RE.equals(parType)) {
return new ResponseEntity<>(campaignExecuteService.getComboBoxStatus(companySiteId, CONNECT_STATUS_TYPE_RE), HttpStatus.OK);
} else {
return new ResponseEntity<>(campaignExecuteService.getComboCampaignType(companySiteId), HttpStatus.OK);
}
......
......@@ -219,4 +219,18 @@ public class CampaignController {
ResultDTO resultDTO = campaignService.updateCampaign(dto);
return new ResponseEntity<>(resultDTO, HttpStatus.OK);
}
@PostMapping("/findCustomerListReallocation")
@ResponseBody
public ResponseEntity<?> findCustomerListReallocation(@RequestBody CampaignRequestDTO dto) {
ResultDTO result = campaignService.findCustomerListReallocation(dto);
return new ResponseEntity<>(result, HttpStatus.OK);
}
@PostMapping("/reallocationCustomer")
@ResponseBody
public ResponseEntity<?> reallocationCustomer(@RequestBody CampaignRequestDTO dto) {
ResultDTO result = campaignService.reallocationCustomer(dto);
return new ResponseEntity<>(result, HttpStatus.OK);
}
}
package com.viettel.econtact.filter;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.Serializable;
/**
* @author hanv_itsol
* @project service-campaign
*
* @author ThaoNT19
*/
public class UserSession implements Serializable{
String authToken;
String ownserId;
String accountId;
......@@ -20,28 +24,20 @@ public class UserSession implements Serializable{
Long companySiteId;
long expTime;
public String getAuthToken() {
return authToken;
}
public void setAuthToken(String authToken) {
this.authToken = authToken;
}
public String getOwnserId() {
return ownserId;
public long getExpTime() {
return expTime;
}
public void setOwnserId(String ownserId) {
this.ownserId = ownserId;
public void setExpTime(long expTime) {
this.expTime = expTime;
}
public String getAccountId() {
return accountId;
public String getAuthToken() {
return authToken;
}
public void setAccountId(String accountId) {
this.accountId = accountId;
public void setAuthToken(String authToken) {
this.authToken = authToken;
}
public Long getUserId() {
......@@ -60,6 +56,22 @@ public class UserSession implements Serializable{
this.userName = userName;
}
public String getOwnserId() {
return ownserId;
}
public void setOwnserId(String ownserId) {
this.ownserId = ownserId;
}
public String getAccountId() {
return accountId;
}
public void setAccountId(String accountId) {
this.accountId = accountId;
}
public String getRole() {
return role;
}
......@@ -83,12 +95,5 @@ public class UserSession implements Serializable{
public void setCompanySiteId(Long companySiteId) {
this.companySiteId = companySiteId;
}
public long getExpTime() {
return expTime;
}
public void setExpTime(long expTime) {
this.expTime = expTime;
}
}
select b.campaign_code campaignCode,
b.campaign_name campaignName,
c.user_name userName,
a.phone_number phoneNumber,
d.name customerName,
to_date(a.start_call, 'DD/MM/YYYY') startCall,
e.complete_name contactStatus,
f.complete_name surveyStatus,
g.status status,
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
left join customer d on a.customer_id = d.customer_id
left join campaign_complete_code e on a.contact_status = e.complete_value
left join campaign_complete_code f on a.call_status = e.complete_value
left join campaign g on a.campaign_id = g.campaign_id
where a.status <> 0
and a.company_site_id = :p_company_site_id
and a.create_time >= to_date(:p_date_from, 'DD/MM/YYYY')
and a.create_time <= to_date(:p_date_to, 'DD/MM/YYYY')
and a.duration_call >= :p_call_time_from
and a.duration_call <= :p_call_time_to
with campaign_type_list as (
select trim (regexp_substr(:p_list_compaign_type, '[^,]+', 1, level)) campaign_type
from dual
connect by level <= regexp_count(:p_list_compaign_type, ',') +1
),
contact_status_list as (
select trim (regexp_substr(:p_list_contact_status, '[^,]+', 1, level)) contact_status
from dual
connect by level <= regexp_count(:p_list_contact_status, ',') +1
),
survey_status_list as (
select trim (regexp_substr(:p_list_survey_status, '[^,]+', 1, level)) survey_status
from dual
connect by level <= regexp_count(:p_list_survey_status, ',') +1
),
record_status_list as (
select trim (regexp_substr(:p_list_record_status, '[^,]+', 1, level)) record_status
from dual
connect by level <= regexp_count(:p_list_record_status, ',') +1
),
campaign_id_list as (
select trim (regexp_substr(:p_list_campaign_id, '[^,]+', 1, level)) campaign_id
from dual
connect by level <= regexp_count(:p_list_campaign_id, ',') +1
),
data_temp as (
select b.campaign_code campaignCode,
b.campaign_name campaignName,
c.user_name userName,
a.phone_number phoneNumber,
d.name customerName,
to_date(a.start_call, 'DD/MM/YYYY') startCall,
e.complete_name contactStatus,
f.complete_name surveyStatus,
g.status status,
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
left join customer d on a.customer_id = d.customer_id
left join campaign_complete_code e on a.contact_status = e.complete_value
left join campaign_complete_code f on a.call_status = e.complete_value
left join campaign g on a.campaign_id = g.campaign_id
where a.status <> 0
and a.company_site_id = :p_company_site_id
and a.create_time >= to_date(:p_date_from, 'DD/MM/YYYY')
and a.create_time <= to_date(:p_date_to, 'DD/MM/YYYY')
and a.duration_call >= :p_call_time_from
and a.duration_call <= :p_call_time_to
and to_char(a.customer_id) like '%'||:p_customer_id||'%'
and b.campaign_type in (select campaign_type from campaign_type_list)
and to_char(a.contact_status) in (select contact_status from contact_status_list)
and to_char(a.call_status) in (select survey_status from survey_status_list)
and to_char(a.status) in (select record_status from record_status_list)
and (:p_phone_number is null or to_char(a.phone_number) like '%'||:p_phone_number||'%')
and (:p_list_campaign_id is null or b.campaign_code in (select campaign_id from campaign_id_list))
and (:p_campaign_name is null or upper(b.campaign_name) like '%'||:p_campaign_name||'%')
and (:p_user_name is null or upper(c.user_name) like '%'||:p_user_name||'%')
),
data as (
select a.*, rownum row_ from data_temp a
)
select * from data
where :p_page_size = 0 or (row_ >= ((:p_page_number - 1) * :p_page_size + 1) and row_ < (:p_page_number * :p_page_size + 1))
with contact as (
select customer_id, contact
from (
select * from customer_contact
where status = 1
and contact_type = 5
and is_direct_line = 1
order by create_date desc
)
where rownum = 1
),
connect_status as (
select complete_value, complete_name
from campaign_complete_code
where company_site_id = :p_company_site_id
and complete_type = 1
and complete_value <> 1
),
connect_status_list as (
select trim (regexp_substr(:p_list_connect_status, '[^,]+', 1, level)) connect_status
from dual
connect by level <= regexp_count(:p_list_connect_status, ',') +1
),
data as (
select a.campaign_customer_id campaignCustomerId,
b.name customerName,
c.contact mobileNumber,
to_char(a.call_time, 'DD/MM/YYYY HH24:MI:SS') connectTime,
d.complete_name connectStatus
from campaign_customer a
left join customer b on a.customer_id = b.customer_id
left join contact c on a.customer_id = c.customer_id
left join connect_status d on d.complete_value = a.status
where a.campaign_id = :p_campaign_id
and a.in_campaign_status = 1
and a.status in (select connect_status from connect_status_list)
order by connectTime desc, customerName
),
final_data as (
select a.*, rownum row_ from data a
)
select * from final_data
where row_ >= ((:p_page_number - 1) * :p_page_size + 1)
and row_ < (:p_page_number * :p_page_size + 1)
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