Commit 34663166 authored by ='s avatar =

hungtt-commit add customer to campaign

parent ee4ad316
......@@ -2,9 +2,7 @@ package com.viettel.campaign.service.impl;
import com.viettel.campaign.config.DataSourceQualify;
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.UserActionLogRepository;
import com.viettel.campaign.service.CampaignService;
import com.viettel.campaign.utils.BundleUtils;
import com.viettel.campaign.utils.Constants;
......@@ -14,7 +12,9 @@ import com.viettel.campaign.web.dto.*;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.apache.logging.log4j.LogManager;
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.xssf.usermodel.XSSFWorkbook;
import org.modelmapper.ModelMapper;
......@@ -22,12 +22,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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 com.viettel.campaign.model.UserActionLog;
//import com.viettel.campaign.repository.UserActionLogRepository;
@Service
@Transactional(rollbackFor = Exception.class)
public class CampaignServiceImpl implements CampaignService {
......@@ -637,20 +636,26 @@ public class CampaignServiceImpl implements CampaignService {
List<CustomerListDTO> listCustomerDto = dto.getLstCustomerCampaign();
try {
// Thuc hien them giam khach hang
for (CustomerListDTO customerListDTO : listCustomerDto) {
for (CustomerListDTO customerListDTO : listCustomerDto) { // Duyet tung customerList
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);
for (int i = 0; i < customerListDTO.getTotalCusAddRemove(); i++) {
CampaignCustomer campaignCustomerEntity = new CampaignCustomer();
campaignCustomerEntity.setCampaignId(campaignId);
campaignCustomerEntity.setCustomerId(listCustomerToAdd.get(i).getCustomerId());
campaignCustomerEntity.setStatus((short) 0);
campaignCustomerEntity.setRecallCount(0L);
campaignCustomerEntity.setCustomerListId(customerListDTO.getCustomerListId());
campaignCustomerEntity.setCompanySiteId(companySiteId);
campaignCustomerEntity.setInCampaignStatus((short) 1);
campaignCustomerRepository.save(campaignCustomerEntity);
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
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
continue;
} else {
CampaignCustomer campaignCustomerEntity = new CampaignCustomer();
campaignCustomerEntity.setCampaignId(campaignId);
campaignCustomerEntity.setCustomerId(listCustomerToAdd.get(j).getCustomerId());
campaignCustomerEntity.setStatus((short) 0);
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
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