Commit 34663166 authored by ='s avatar =

hungtt-commit add customer to campaign

parent ee4ad316
...@@ -2,9 +2,7 @@ package com.viettel.campaign.service.impl; ...@@ -2,9 +2,7 @@ package com.viettel.campaign.service.impl;
import com.viettel.campaign.config.DataSourceQualify; import com.viettel.campaign.config.DataSourceQualify;
import com.viettel.campaign.model.ccms_full.*; import com.viettel.campaign.model.ccms_full.*;
//import com.viettel.campaign.model.UserActionLog;
import com.viettel.campaign.repository.ccms_full.*; import com.viettel.campaign.repository.ccms_full.*;
//import com.viettel.campaign.repository.UserActionLogRepository;
import com.viettel.campaign.service.CampaignService; import com.viettel.campaign.service.CampaignService;
import com.viettel.campaign.utils.BundleUtils; import com.viettel.campaign.utils.BundleUtils;
import com.viettel.campaign.utils.Constants; import com.viettel.campaign.utils.Constants;
...@@ -14,7 +12,9 @@ import com.viettel.campaign.web.dto.*; ...@@ -14,7 +12,9 @@ import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO; import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.modelmapper.ModelMapper; import org.modelmapper.ModelMapper;
...@@ -22,12 +22,11 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -22,12 +22,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*; import java.util.*;
//import com.viettel.campaign.model.UserActionLog;
//import com.viettel.campaign.repository.UserActionLogRepository;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public class CampaignServiceImpl implements CampaignService { public class CampaignServiceImpl implements CampaignService {
...@@ -637,20 +636,26 @@ public class CampaignServiceImpl implements CampaignService { ...@@ -637,20 +636,26 @@ public class CampaignServiceImpl implements CampaignService {
List<CustomerListDTO> listCustomerDto = dto.getLstCustomerCampaign(); List<CustomerListDTO> listCustomerDto = dto.getLstCustomerCampaign();
try { try {
// Thuc hien them giam khach hang // Thuc hien them giam khach hang
for (CustomerListDTO customerListDTO : listCustomerDto) { for (CustomerListDTO customerListDTO : listCustomerDto) { // Duyet tung customerList
if (customerListDTO.getTotalCusAddRemove() > 0) { // Them khach hang if (customerListDTO.getTotalCusAddRemove() > 0) { // Them khach hang
// Lay ra danh sach khach hang phu hop de them // Lay ra danh sach khach hang phu hop de them
List<Customer> listCustomerToAdd = customerRepository.findAllCutomerNotInCampagin(customerListDTO.getCustomerListId(), campaignId); List<Customer> listCustomerToAdd = customerRepository.findAllCutomerNotInCampagin(customerListDTO.getCustomerListId(), campaignId);
for (int i = 0; i < customerListDTO.getTotalCusAddRemove(); i++) { 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
CampaignCustomer campaignCustomerEntity = new CampaignCustomer(); for (int i = 0, j = 0; (i < customerListDTO.getTotalCusAddRemove() && j < numOfCusInList); j++) {
campaignCustomerEntity.setCampaignId(campaignId); if (campaignCustomerRepository.findCampaignCustomerByCampaignIdAndCompanySiteIdAndCustomerId(campaignId, companySiteId, listCustomerToAdd.get(j).getCustomerId()) != null) { // Khach hang đã đc chèn vào campaign theo individual
campaignCustomerEntity.setCustomerId(listCustomerToAdd.get(i).getCustomerId()); continue;
campaignCustomerEntity.setStatus((short) 0); } else {
campaignCustomerEntity.setRecallCount(0L); CampaignCustomer campaignCustomerEntity = new CampaignCustomer();
campaignCustomerEntity.setCustomerListId(customerListDTO.getCustomerListId()); campaignCustomerEntity.setCampaignId(campaignId);
campaignCustomerEntity.setCompanySiteId(companySiteId); campaignCustomerEntity.setCustomerId(listCustomerToAdd.get(j).getCustomerId());
campaignCustomerEntity.setInCampaignStatus((short) 1); campaignCustomerEntity.setStatus((short) 0);
campaignCustomerRepository.save(campaignCustomerEntity); campaignCustomerEntity.setRecallCount(0L);
campaignCustomerEntity.setCustomerListId(customerListDTO.getCustomerListId());
campaignCustomerEntity.setCompanySiteId(companySiteId);
campaignCustomerEntity.setInCampaignStatus((short) 1);
campaignCustomerRepository.save(campaignCustomerEntity);
i += 1;
}
} }
} else if (customerListDTO.getTotalCusAddRemove() < 0){ // Loai bo khach hang } else if (customerListDTO.getTotalCusAddRemove() < 0){ // Loai bo khach hang
long custToDel = Math.abs(customerListDTO.getTotalCusAddRemove()); long custToDel = Math.abs(customerListDTO.getTotalCusAddRemove());
......
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