Commit da62dfac authored by ='s avatar =

hungtt-commit add customer to campaign theo case moi cua ba linhbd

parent ad46b6ea
......@@ -39,6 +39,6 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
@Query(value = "select * from customer a\n" +
"left join customer_list_mapping b on a.customer_id = b.customer_id\n" +
"where b.customer_list_id = :p_customer_list_id\n" +
" and a.customer_id not in (select cc.customer_id from campaign_customer cc where cc.campaign_id = :p_campaign_id and cc.customer_list_id = :p_customer_list_id)", nativeQuery = true)
" and a.customer_id not in (select cc.customer_id from campaign_customer cc where cc.campaign_id = :p_campaign_id and cc.customer_list_id = :p_customer_list_id and cc.in_campaign_status <> 0)", nativeQuery = true)
List<Customer> findAllCutomerNotInCampagin(@Param("p_customer_list_id") Long customerListId, @Param("p_campaign_id") Long campaignId);
}
......@@ -621,12 +621,12 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
"),\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" +
" where a.campaign_id = :p_campaign_id and in_campaign_status = 1\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" +
" where a.status <> 0 and a.campaign_id = :p_campaign_id and in_campaign_status = 1\n" +
" group by a.customer_list_id, a.campaign_id\n" +
"),\n" +
"customer_not_interactive_table as (\n" +
......
......@@ -640,9 +640,15 @@ public class CampaignServiceImpl implements CampaignService {
if (customerListDTO.getTotalCusAddRemove() > 0) { // Them khach hang
// Lay ra danh sach khach hang phu hop de them
List<Customer> listCustomerToAdd = customerRepository.findAllCutomerNotInCampagin(customerListDTO.getCustomerListId(), campaignId);
int numOfCusInList = listCustomerToAdd.size(); // Số khách hàng còn lại của chiến dịch chưa đc add vào campaign
int numOfCusInList = listCustomerToAdd.size(); // Số khách hàng còn lại của chiến dịch chưa đc add vào campaign hoặc đã add nhưng in_campaign_status = 0
for (int i = 0, j = 0; (i < customerListDTO.getTotalCusAddRemove() && j < numOfCusInList); j++) {
if (campaignCustomerRepository.findCampaignCustomerByCampaignIdAndCompanySiteIdAndCustomerId(campaignId, companySiteId, listCustomerToAdd.get(j).getCustomerId()) != null) { // Khach hang đã đc chèn vào campaign theo individual
CampaignCustomer tempEntity = campaignCustomerRepository.findCampaignCustomerByCampaignIdAndCompanySiteIdAndCustomerId(campaignId, companySiteId, listCustomerToAdd.get(j).getCustomerId());
if (tempEntity != null) { // Khach hang đã đc chèn vào campaign theo individual / hoặc in_campaign_status = 0
if ((tempEntity.getCustomerListId() == customerListDTO.getCustomerListId()) && tempEntity.getInCampaignStatus() == 0) {
tempEntity.setInCampaignStatus((short) 1);
campaignCustomerRepository.save(tempEntity);
i+=1;
}
continue;
} else {
CampaignCustomer campaignCustomerEntity = new CampaignCustomer();
......
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