Commit 5ad1ac01 authored by Nguyen Ha's avatar Nguyen Ha

add job

parent e3d1e236
package com.viettel.campaign.job; package com.viettel.campaign.job;
import com.viettel.campaign.model.ccms_full.Campaign; 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.model.ccms_full.ProcessConfig;
import com.viettel.campaign.service.CampaignService; 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.service.ProcessConfigService;
import com.viettel.campaign.utils.DateTimeUtil; import com.viettel.campaign.utils.DateTimeUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; 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.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -34,6 +36,12 @@ public class CampaignJob { ...@@ -34,6 +36,12 @@ public class CampaignJob {
@Autowired @Autowired
private CampaignService campaignService; private CampaignService campaignService;
@Autowired
private CustomerTimeService customerTimeService;
@Autowired
private CustomerService customerService;
// @Scheduled(fixedRate = 5000) // @Scheduled(fixedRate = 5000)
// @Transactional( propagation = Propagation.REQUIRED) // @Transactional( propagation = Propagation.REQUIRED)
public void process() { public void process() {
...@@ -45,26 +53,30 @@ public class CampaignJob { ...@@ -45,26 +53,30 @@ public class CampaignJob {
switch (p.getConfigCode()){ switch (p.getConfigCode()){
case CUSTOMER_INACTIVE_DUARATION: case CUSTOMER_INACTIVE_DUARATION:
if(isExecute){ 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; break;
case CRON_EXPRESSION_CHECK_START: case CRON_EXPRESSION_CHECK_START:
// process // process
if(isExecute){ if(isExecute){
// chuyen trang thai Du thao sang Trien khai
log.info("thay doi trang thai");
List<Long> status = new ArrayList<>(); List<Long> status = new ArrayList<>();
status.add(1L); status.add(1L);
status.add(1L); status.add(1L);
List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status); List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndStartTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
campaigns.parallelStream().forEach(campaign -> { campaigns.parallelStream().forEach(campaign -> {
log.info("Chuyen trang thai chien dich ... #{} ... tu Du thao sang Trien khai", campaign.getCampaignId());
campaign.setProcessStatus(1); campaign.setProcessStatus(1);
campaign.setStatus(2L); campaign.setStatus(2L);
campaign.setCampaignStart(new Date()); campaign.setCampaignStart(new Date());
campaignService.updateProcess(campaign); campaignService.updateProcess(campaign);
}); });
// update last check log.info("Cap nhat thoi gian thuc hien tien trinh cho siteId ... #{}", p.getSiteId());
p.setLastProcess(new Date()); p.setLastProcess(new Date());
processConfigService.update(p); processConfigService.update(p);
} }
...@@ -72,25 +84,50 @@ public class CampaignJob { ...@@ -72,25 +84,50 @@ public class CampaignJob {
case CRON_EXPRESSION_CHECK_END: case CRON_EXPRESSION_CHECK_END:
// process // process
if(isExecute){ if(isExecute){
// chuyen trang thai sang ket thuc
List<Long> status = new ArrayList<>(); List<Long> status = new ArrayList<>();
status.add(2L); status.add(2L);
status.add(3L); status.add(3L);
List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status); List<Campaign> campaigns = campaignService.findCampaignByCompanySiteIdAndEndTimeIsLessThanEqualAndStatusIn(p.getSiteId(), new Date(), status);
campaigns.parallelStream().forEach(campaign -> { campaigns.parallelStream().forEach(campaign -> {
log.info("Chuyen trang thai chien dich ... #{} ... sang Ket thuc", campaign.getCampaignId());
campaign.setStatus(4L); campaign.setStatus(4L);
campaign.setCampaignEnd(new Date()); campaign.setCampaignEnd(new Date());
campaignService.updateProcess(campaign); 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; break;
default: 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.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;
}
...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query; ...@@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List; import java.util.List;
@Repository @Repository
...@@ -27,4 +28,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> { ...@@ -27,4 +28,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Modifying @Modifying
@Query("delete from Customer c where c.customerId in (:ids)") @Query("delete from Customer c where c.customerId in (:ids)")
int deleteIds(@Param("ids") List<Long> 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);
}
package com.viettel.campaign.service; 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.model.ccms_full.CustomerList;
import com.viettel.campaign.web.dto.CustomerContactDTO; import com.viettel.campaign.web.dto.CustomerContactDTO;
import com.viettel.campaign.web.dto.CustomerDTO; import com.viettel.campaign.web.dto.CustomerDTO;
...@@ -8,6 +9,9 @@ import com.viettel.campaign.web.dto.ResultDTO; ...@@ -8,6 +9,9 @@ import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import java.util.Date;
import java.util.List;
public interface CustomerService { public interface CustomerService {
ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId); ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId);
...@@ -51,5 +55,9 @@ public interface CustomerService { ...@@ -51,5 +55,9 @@ public interface CustomerService {
ResultDTO getCustomerRecall(Long campaignId, Long customerId); 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);
}
}
...@@ -682,4 +682,16 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -682,4 +682,16 @@ public class CustomerServiceImpl implements CustomerService {
} }
return resultDTO; return resultDTO;
} }
@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);
}
} }
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