Commit 56267616 authored by Tu Bach's avatar Tu Bach

Merge branch 'master' into tubn

parents 62da5898 c22b9114
...@@ -28,5 +28,5 @@ public interface ScenarioAnswerRepository extends JpaRepository<ScenarioAnswer, ...@@ -28,5 +28,5 @@ public interface ScenarioAnswerRepository extends JpaRepository<ScenarioAnswer,
@Query(value = "SELECT COUNT(1) FROM ScenarioAnswer WHERE 1 = 1 AND code = :code AND scenarioQuestionId = :scenarioQuestionId AND scenarioAnswerId <> :scenarioAnswerId") @Query(value = "SELECT COUNT(1) FROM ScenarioAnswer WHERE 1 = 1 AND code = :code AND scenarioQuestionId = :scenarioQuestionId AND scenarioAnswerId <> :scenarioAnswerId")
Integer countDuplicateScenarioCode(@Param("code") String code, @Param("scenarioQuestionId") Long scenarioQuestionId, @Param("scenarioAnswerId") Long scenarioAnswerId); Integer countDuplicateScenarioCode(@Param("code") String code, @Param("scenarioQuestionId") Long scenarioQuestionId, @Param("scenarioAnswerId") Long scenarioAnswerId);
ScenarioAnswer findScenarioAnswerByScenarioQuestionIdAndCode(Long questionId, String code); ScenarioAnswer findScenarioAnswerByCode(String code);
} }
...@@ -171,7 +171,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -171,7 +171,7 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) { if (!DataUtil.isNullOrEmpty(requestDto.getCampaignName())) {
query.setParameter("p_name", "%" + query.setParameter("p_name", "%" +
requestDto.getCampaignName().toUpperCase() requestDto.getCampaignName().trim().toUpperCase()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\\\%") .replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_") .replaceAll("_", "\\\\_")
......
...@@ -9,7 +9,7 @@ import java.util.List; ...@@ -9,7 +9,7 @@ import java.util.List;
public interface AgentsService { public interface AgentsService {
ResultDTO getAgentsByAgentId(String agentId); ResultDTO getAgentsByAgentId(String agentId);
ResultDTO getAllAgentByCompanySiteId(int page, int pageSize, Long companySiteId); ResultDTO getAllAgentByCompanySiteId(int page, int pageSize, Long companySiteId, Long campaignId);
ResultDTO getAllAgentSelectedByCompanySiteId(int page, int pageSize, Long companySiteId, Long campaignId); ResultDTO getAllAgentSelectedByCompanySiteId(int page, int pageSize, Long companySiteId, Long campaignId);
...@@ -17,7 +17,7 @@ public interface AgentsService { ...@@ -17,7 +17,7 @@ public interface AgentsService {
ResultDTO deleteCampaignAgentById(List<Long> campaignAgentId); ResultDTO deleteCampaignAgentById(List<Long> campaignAgentId);
ResultDTO searchCampaignAgentByName(int page, int pageSize, Long companySiteId, String userName, String fullName); ResultDTO searchCampaignAgentByName(int page, int pageSize, Long campaignId, Long companySiteId, String userName, String fullName);
ResultDTO searchCampaignAgentSelectByName(int page, int pageSize, Long companySiteId, Long campaignId, String userName, String fullName); ResultDTO searchCampaignAgentSelectByName(int page, int pageSize, Long companySiteId, Long campaignId, String userName, String fullName);
......
...@@ -62,7 +62,7 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -62,7 +62,7 @@ public class AgentsServiceImpl implements AgentsService {
@Override @Override
@Transactional(DataSourceQualify.ACD_FULL) @Transactional(DataSourceQualify.ACD_FULL)
public ResultDTO getAllAgentByCompanySiteId(int page, int pageSize, Long companySiteId) { public ResultDTO getAllAgentByCompanySiteId(int page, int pageSize, Long companySiteId, Long campaignId) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
...@@ -83,36 +83,41 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -83,36 +83,41 @@ public class AgentsServiceImpl implements AgentsService {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("SELECT"); sb.append("SELECT");
sb.append(" a.USER_ID userId,"); sb.append(" vu.USER_ID userId,");
sb.append(" a.USER_NAME userName,"); sb.append(" vu.USER_NAME userName,");
sb.append(" a.STATUS status,"); sb.append(" vu.STATUS status,");
sb.append(" a.FULL_NAME fullName,"); sb.append(" vu.FULL_NAME fullName,");
sb.append(" a.COMPANY_SITE_ID companySiteId,"); sb.append(" vu.COMPANY_SITE_ID companySiteId,");
sb.append(" b.FILTER_TYPE filterType,"); sb.append(" r.ROLE_CODE roleCode");
sb.append(" b.CAMPAIGN_AGENT_ID campaignAgentId,"); sb.append(" FROM VSA_USERS vu");
sb.append(" d.ROLE_CODE roleCode"); sb.append(" INNER JOIN USER_ROLE ur on vu.USER_ID = ur.USER_ID");
sb.append(" FROM VSA_USERS a"); sb.append(" INNER JOIN ROLE r on ur.ROLE_ID = r.ROLE_ID");
sb.append(" LEFT JOIN CAMPAIGN_AGENT b on a.USER_ID = b.AGENT_ID");
sb.append(" INNER JOIN USER_ROLE c on a.USER_ID = c.USER_ID");
sb.append(" INNER JOIN ROLE d on c.ROLE_ID = d.ROLE_ID");
sb.append(" WHERE 1 = 1"); sb.append(" WHERE 1 = 1");
sb.append(" AND a.COMPANY_SITE_ID = :p_company_site_id"); sb.append(" AND vu.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND a.STATUS = 1"); sb.append(" AND vu.STATUS = 1");
sb.append(" AND b.AGENT_ID IS NULL"); sb.append(" AND r.ROLE_CODE IN ('AGENT', 'SUPERVISOR')");
sb.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')"); sb.append(" AND vu.USER_ID NOT IN (SELECT vu.USER_ID userId");
sb.append(" ORDER BY UPPER(a.FULL_NAME)"); sb.append(" FROM VSA_USERS vu");
sb.append(" LEFT JOIN CAMPAIGN_AGENT ca on vu.USER_ID = ca.AGENT_ID");
sb.append(" INNER JOIN USER_ROLE ur on vu.USER_ID = ur.USER_ID");
sb.append(" INNER JOIN ROLE r on ur.ROLE_ID = r.ROLE_ID");
sb.append(" WHERE 1 = 1");
sb.append(" AND vu.COMPANY_SITE_ID = :p_company_site_id");
sb.append(" AND vu.STATUS = 1");
sb.append(" AND ca.CAMPAIGN_ID = :p_campaign_id");
sb.append(" AND r.ROLE_CODE IN ('AGENT', 'SUPERVISOR'))");
sb.append(" ORDER BY UPPER(vu.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sb.toString()); SQLQuery query = session.createSQLQuery(sb.toString());
query.setParameter("p_company_site_id", companySiteId); query.setParameter("p_company_site_id", companySiteId);
query.setParameter("p_campaign_id", campaignId);
query.addScalar("userId", new LongType()); query.addScalar("userId", new LongType());
query.addScalar("userName", new StringType()); query.addScalar("userName", new StringType());
query.addScalar("status", new ShortType()); query.addScalar("status", new ShortType());
query.addScalar("fullName", new StringType()); query.addScalar("fullName", new StringType());
query.addScalar("companySiteId", new LongType()); query.addScalar("companySiteId", new LongType());
query.addScalar("filterType", new ShortType());
query.addScalar("campaignAgentId", new LongType());
query.addScalar("roleCode", new StringType()); query.addScalar("roleCode", new StringType());
query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class)); query.setResultTransformer(Transformers.aliasToBean(VSAUsersDTO.class));
...@@ -276,7 +281,7 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -276,7 +281,7 @@ public class AgentsServiceImpl implements AgentsService {
} }
@Override @Override
public ResultDTO searchCampaignAgentByName(int page, int pageSize, Long companySiteId, String userName, String fullName) { public ResultDTO searchCampaignAgentByName(int page, int pageSize, Long campaignId, Long companySiteId, String userName, String fullName) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
...@@ -320,12 +325,13 @@ public class AgentsServiceImpl implements AgentsService { ...@@ -320,12 +325,13 @@ public class AgentsServiceImpl implements AgentsService {
sqlStrBuilder.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')"); sqlStrBuilder.append(" AND d.ROLE_CODE IN ('AGENT', 'SUPERVISOR')");
sqlStrBuilder.append(" AND a.STATUS = 1"); sqlStrBuilder.append(" AND a.STATUS = 1");
sqlStrBuilder.append(" AND b.AGENT_ID IS NULL"); sqlStrBuilder.append(" AND (b.CAMPAIGN_ID IS NULL OR b.CAMPAIGN_ID <> :p_campaign_id)");
sqlStrBuilder.append(" ORDER BY UPPER(a.FULL_NAME)"); sqlStrBuilder.append(" ORDER BY UPPER(a.FULL_NAME)");
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString()); SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
query.setParameter("p_company_site_id", companySiteId); query.setParameter("p_company_site_id", companySiteId);
query.setParameter("p_campaign_id", campaignId);
if (!DataUtil.isNullOrEmpty(userName)) { if (!DataUtil.isNullOrEmpty(userName)) {
query.setParameter("p_user_name", "%" + query.setParameter("p_user_name", "%" +
......
...@@ -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());
......
...@@ -181,7 +181,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -181,7 +181,7 @@ public class CustomerServiceImpl implements CustomerService {
} }
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort))); Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort)));
if (pageable != null) { if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize()); query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize()); query.setMaxResults(pageable.getPageSize());
} }
...@@ -195,7 +195,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -195,7 +195,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -342,7 +342,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -342,7 +342,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -498,7 +498,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -498,7 +498,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -599,7 +599,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -599,7 +599,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -871,7 +871,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -871,7 +871,7 @@ public class CustomerServiceImpl implements CustomerService {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally { } finally {
if(session != null) session.close(); if (session != null) session.close();
} }
return resultDTO; return resultDTO;
...@@ -941,7 +941,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -941,7 +941,7 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
@Transactional(DataSourceQualify.CCMS_FULL) @Transactional(DataSourceQualify.CCMS_FULL)
public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) throws IOException{ public Map<String, Object> readAndValidateCustomer(String path, List<CustomizeFields> dynamicHeader, UserSession userSession, Long customerListId) throws IOException {
LOGGER.info("------------READ AND VALIDATE--------------"); LOGGER.info("------------READ AND VALIDATE--------------");
Locale locale = new Locale("vi", "VN"); Locale locale = new Locale("vi", "VN");
DataFormatter dataFormat = new DataFormatter(); DataFormatter dataFormat = new DataFormatter();
...@@ -1267,7 +1267,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1267,7 +1267,7 @@ public class CustomerServiceImpl implements CustomerService {
LOGGER.info(e.getMessage()); LOGGER.info(e.getMessage());
result.put("message", "validate-error"); result.put("message", "validate-error");
return result; return result;
}finally { } finally {
if (workbook != null) workbook.close(); if (workbook != null) workbook.close();
} }
} }
...@@ -1487,7 +1487,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1487,7 +1487,7 @@ public class CustomerServiceImpl implements CustomerService {
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getMessage()); LOGGER.error(e.getMessage());
return null; return null;
}finally { } finally {
if (workbook != null) workbook.close(); if (workbook != null) workbook.close();
} }
} }
...@@ -1758,7 +1758,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1758,7 +1758,7 @@ public class CustomerServiceImpl implements CustomerService {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(" select distinct name, field_option_value_id key from customize_field_option_value"); sb.append(" select distinct name value, field_option_value_id key from customize_field_option_value");
sb.append(" where field_option_id = :p_field_id"); sb.append(" where field_option_id = :p_field_id");
params.put("p_field_id", campaignCustomerDTO.getField()); params.put("p_field_id", campaignCustomerDTO.getField());
...@@ -1892,152 +1892,120 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -1892,152 +1892,120 @@ public class CustomerServiceImpl implements CustomerService {
Session session = sessionFactory.openSession(); Session session = sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();
Map<String, String> requestCustomer = new HashMap<>();
requestCustomer.put("-1", "c.code");
requestCustomer.put("-2", "c.name");
requestCustomer.put("-3", "c.company_name");
requestCustomer.put("-4", "c.gender");
requestCustomer.put("-5", "c.current_address");
requestCustomer.put("-6", "c.place_of_birth");
requestCustomer.put("-7", "c.date_of_birth");
requestCustomer.put("-8", "cc.contact");
requestCustomer.put("-9", "cc2.contact");
requestCustomer.put("-10", "c.username");
requestCustomer.put("-11", "c.area_code");
requestCustomer.put("-12", "c.customer_type");
requestCustomer.put("-13", "c.call_allowed");
requestCustomer.put("-14", "c.email_allowed");
requestCustomer.put("-15", "c.sms_allowed");
requestCustomer.put("-16", "c.ipcc_status");
try { try {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("select"); sb.append("select c.customer_id customerId,");
sb.append(" C.NAME name,"); sb.append(" C.NAME name,");
sb.append(" C.CUSTOMER_ID customerID,"); sb.append(" cc.contact mobile_phone,");
sb.append(" C.USERNAME username,"); sb.append(" cc2.contact email,");
sb.append(" C.GENDER gender,"); sb.append(" c.customer_type customerType,");
sb.append(" C.COMPANY_NAME companyName,");
sb.append(" C.DATE_OF_BIRTH dateOfBirth,");
sb.append(" C.CUSTOMER_TYPE customerType,");
sb.append(" C.COMPANY_NAME companyName,"); sb.append(" C.COMPANY_NAME companyName,");
sb.append(" C.PLACE_OF_BIRTH placeOfBirth,"); sb.append(" c.current_address currentAddress,");
sb.append(" C.EMAIL email,"); sb.append(" c.Description description");
sb.append(" C.MOBILE_NUMBER mobileNumber,");
sb.append(" C.STATUS status,");
sb.append(" C.SITE_ID siteId,");
sb.append(" CF.FUNCTION_CODE functionCode,");
sb.append(" CF.ACTIVE active,");
sb.append(" CFO.*");
sb.append(" FROM CUSTOMER C"); sb.append(" FROM CUSTOMER C");
sb.append(" INNER JOIN CUSTOMIZE_FIELD_OBJECT CFO ON C.CUSTOMER_ID = CFO.OBJECT_ID"); sb.append(" INNER JOIN CUSTOMER_contact cc ON (C.CUSTOMER_ID = Cc.customer_id " +
sb.append(" INNER JOIN CUSTOMIZE_FIELDS CF ON CF.CUSTOMIZE_FIELD_ID = CFO.CUSTOMIZE_FIELDS_ID\n" + "and cc.status = 1 and cc.contact_type = 5)");
" WHERE "); sb.append(" INNER JOIN CUSTOMER_contact Cc2 ON (C.CUSTOMER_ID = Cc2.customer_id and cc2.status = 1 and cc2.contact_type = 2)");
sb.append(" CFO.STATUS = 1"); sb.append("inner join customize_field_object cfo on c.customer_id = cfo.object_id and cfo.status = 1");
sb.append(" AND CF.ACTIVE = 1 "); sb.append(" AND C.STATUS = 1");
sb.append(" AND CF.FUNCTION_CODE = 'CUSTOMER' "); sb.append(" AND C.customer_id not in (select customer_id from campaign_customer where campaign_id = :p_campaign_id) ");
List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery(); List<CustomerQueryDTO> customerDTOList = campaignCustomerDTO.getListQuery();
// sb.append( if (customerDTOList.get(0).getField() > 0) {
// customerDTOList.get(0).getField() + " " switch (customerDTOList.get(0).getType()) {
// + customerDTOList.get(0).getOperator() + " " case "combobox":
// + customerDTOList.get(0).getCondition() + " "); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.field_option_value_id " + customerDTOList.get(0).getOperator() + "" + customerDTOList.get(0).getCondition() + ")");
// for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) {
// sb.append(campaignCustomerDTO.getListQuery().get(i).getJoin() + " "
// + campaignCustomerDTO.getListQuery().get(i).getField() + " "
// + campaignCustomerDTO.getListQuery().get(i).getOperator() + " "
// + campaignCustomerDTO.getListQuery().get(i).getCondition() + " ");
// Map<String, String> requestCustomer = new HashMap<>();
// requestCustomer.put("-1" ,"Mã Khách Hàng");
// requestCustomer.put("-2" ,"Tên khách hàng");
// requestCustomer.put("-3" ,"Tên công ty");
// requestCustomer.put("-4" ,"Giới tính");
// requestCustomer.put("-5" ,"Địa chỉ");
// requestCustomer.put("-6" ,"Nơi sinh");
// requestCustomer.put("-7" ,"Ngày sinh");
// requestCustomer.put("-8" ,"Số điện thoại");
// requestCustomer.put("-9" ,"email");
// requestCustomer.put("-10" ,"Tên đăng nhập");
// requestCustomer.put("-11" ,"Loại Khách hàng");
// sb.append("and "+customerDTOList.get(0).getField());
// for (int i = 1; i < customerDTOList.size(); i++) {
//
// }
for (CustomerQueryDTO query : customerDTOList) {
if (query.getJoin() == null) {
sb.append("AND ");
} else {
sb.append(query.getJoin() + " ");
// if ("like".equals(query.getOperator()) || "not like".equals(query.getOperator())) {
// sb.append("%"+ query.getCondition() + "% ");
// } else {
// sb.append(query.getCondition());
// }
}
switch (query.getField() + "") {
case "-1":
sb.append(" C.CUSTOMER_ID " + query.getOperator() + " '%" + query.getCondition() + "%' ");
break;
case "-2":
sb.append(" C.NAME " + query.getOperator() + " '%" + query.getCondition() + "%' ");
break;
case "-3":
sb.append(" C.COMPANY_NAME " + query.getOperator() + " '%" + query.getCondition() + "%' ");
break;
case "-4":
sb.append(" C.GENDER " + query.getOperator() + " '%" + query.getCondition() + "%' ");
break;
case "-5":
sb.append(" C.CURRENT_ADDRESS " + query.getOperator() + " '%" + query.getCondition() + "%' ");
break; break;
case "-6": case "text":
sb.append( " C.PLACE_OF_BIRTH " + query.getOperator() + "to_date(" + query.getCondition() + ", 'dd/mm/yyyy')"); if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
break; sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition() + "%')");
case "-7": } else {
sb.append(" C.DATE_OF_BIRTH " + query.getOperator() + "to_date(" + query.getCondition() + ", 'dd/mm/yyyy')"); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
break; }
case "-8":
sb.append(" C.MOBILE_NUMBER " + query.getOperator() + " '%" + query.getCondition() + "%' ");
break; break;
case "-9": case "date":
sb.append(" C.EMAIL " + query.getOperator() + " '%" + query.getCondition() + "%' "); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_date " + customerDTOList.get(0).getOperator() + " to_date(" + customerDTOList.get(0).getCondition() + ", 'DD/MM/YYYY'))");
break; break;
case "-10": case "number":
sb.append(" C.USER_NAME " + query.getOperator() + " '%" + query.getCondition() + "%' "); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_number " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
break; break;
case "-11": case "checkbox":
sb.append(" C.CUSTOMER_TYPE " + query.getOperator() + " '%" + query.getCondition() + "%' "); sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_checkbox " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition() + ")");
break; break;
} }
} else {
if ("like".equals(customerDTOList.get(0).getOperator()) || "not like".equals(customerDTOList.get(0).getOperator())) {
// if (query.getField() == -1) { sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(0).getField() + " and cfo.value_text " + customerDTOList.get(0).getOperator() + " '%" + customerDTOList.get(0).getCondition() + "%')");
// sb.append(query.getJoin() + " C.CUSTOMER_ID " + query.getOperator() + " %" + query.getCondition() + "% "); } else {
// } else if (query.getField() == -2) { sb.append("and " + requestCustomer.get(customerDTOList.get(0).getField().toString()) + " " + customerDTOList.get(0).getOperator() + " " + customerDTOList.get(0).getCondition());
// sb.append(query.getJoin() + "C.NAME " + query.getOperator() + " %" + query.getCondition() + "% "); }
// } else if (query.getField() == -3) { }
// sb.append(query.getJoin() + " C.COMPANY_NAME " + query.getOperator() + " %" + query.getCondition() + "% "); for (int i = 1; i < campaignCustomerDTO.getListQuery().size(); i++) {
// } else if (query.getField() == -4) { if (customerDTOList.get(i).getField() < 0) {
// sb.append(query.getJoin() + " C.GENDER " + query.getOperator() + " %" + query.getCondition() + "% "); if ("like".equals(customerDTOList.get(i).getOperator()) || "not like".equals(customerDTOList.get(i).getOperator())) {
// } else if (query.getField() == -5) { sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " '%" + customerDTOList.get(i).getCondition() + "%')");
// sb.append(query.getJoin() + " C.CURRENT_ADDRESS " + query.getOperator() + " %" + query.getCondition() + "% "); sb.append(" " + customerDTOList.get(i).getJoin() + " "
// } else if (query.getField() == -6) { + requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
// sb.append(query.getJoin() + " C.PLACE_OF_BIRTH " + query.getOperator() + " %" + query.getCondition() + "% "); + customerDTOList.get(i).getOperator() + " "
// } else if (query.getField() == -7) { + "'%"+customerDTOList.get(i).getCondition() + "%' ");
// sb.append(query.getJoin() + " C.DATE_OF_BIRTH " + query.getOperator() + " %" + query.getCondition() + "% "); } else {
// } else if (query.getField() == -8) { sb.append(" " + customerDTOList.get(i).getJoin() + " "
// sb.append(query.getJoin() + " C.MOBILE_NUMBER " + query.getOperator() + " %" + query.getCondition() + "% "); + requestCustomer.get(customerDTOList.get(i).getField().toString()) + " "
// } else if (query.getField() == -9) { + customerDTOList.get(i).getOperator() + " "
// sb.append(query.getJoin() + " C.EMAIL " + query.getOperator() + " %" + query.getCondition() + "% "); + customerDTOList.get(i).getCondition() + " ");
// } else if (query.getField() == -10) { }
// sb.append(query.getJoin() + " C.USER_NAME " + query.getOperator() + " %" + query.getCondition() + "% "); } else {
// } else if (query.getField() == -11) { switch (customerDTOList.get(i).getType()) {
// sb.append(query.getJoin() + " C.CUSTOMER_TYPE " + query.getOperator() + " %" + query.getCondition() + "% "); case "combobox":
// } sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.field_option_value_id " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
case "text":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_text " + customerDTOList.get(i).getOperator() + " %'" + customerDTOList.get(i).getCondition() + "%')");
break;
case "date":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_date " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
case "number":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_number " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
case "checkbox":
sb.append("and (cfo.customize_fields_id =" + customerDTOList.get(i).getField() + " and cfo.value_checkbox " + customerDTOList.get(i).getOperator() + " " + customerDTOList.get(i).getCondition() + ")");
break;
}
}
} }
SQLQuery query = session.createSQLQuery(sb.toString()); SQLQuery query = session.createSQLQuery(sb.toString());
query.addScalar("customerId", new LongType());
query.addScalar("name", new StringType()); query.addScalar("name", new StringType());
query.addScalar("userName", new StringType()); query.addScalar("customerId", new LongType());
query.addScalar("companyName", new StringType()); query.addScalar("mobile_phone", new StringType());
query.addScalar("email", new StringType());
query.addScalar("customerType", new LongType()); query.addScalar("customerType", new LongType());
query.addScalar("companyName", new StringType());
query.addScalar("currentAddress", new StringType()); query.addScalar("currentAddress", new StringType());
query.addScalar("mobileNumber", new StringType()); query.addScalar("description", new StringType());
query.addScalar("email", new StringType());
query.addScalar("placeOfBirth", new StringType()); query.setParameter("p_campaign_id", campaignCustomerDTO.getCampaignId());
query.addScalar("dateOfBirth", new DateType());
query.addScalar("status", new ShortType());
query.addScalar("siteId", new LongType());
query.addScalar("active", new StringType());
query.setResultTransformer(Transformers.aliasToBean(CampaignCustomerDTO.class)); query.setResultTransformer(Transformers.aliasToBean(CampaignCustomerDTO.class));
...@@ -2069,11 +2037,4 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -2069,11 +2037,4 @@ public class CustomerServiceImpl implements CustomerService {
return resultDTO; return resultDTO;
} }
private String getCodition(String join, String operator, String codition) {
// if (operator.equalsIgnoreCase("LIKE") || operator.equalsIgnoreCase("NOT_LIKE")) {
// } else {
// return " " + join + " " + operator + " " + codition + " ";
// }
return null;
}
} }
...@@ -388,7 +388,7 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -388,7 +388,7 @@ public class ScenarioServiceImpl implements ScenarioService {
} }
if ((rawDataList.get(i)[7] != null && !rawDataList.get(i)[7].toString().trim().equals(""))) { if ((rawDataList.get(i)[7] != null && !rawDataList.get(i)[7].toString().trim().equals(""))) {
if ((rawDataList.get(i)[7].toString().trim().equals(tmpCurrentQuestionCode)) || if ((rawDataList.get(i)[7].toString().trim().equals(tmpCurrentQuestionCode)) ||
validateMappingQuestion(rawDataList.get(i)[7].toString().trim(), tmpCurrentQuestionCode, lstImportQuestionCodes)) !validateMappingQuestion(rawDataList.get(i)[7].toString().trim(), tmpCurrentQuestionCode, lstImportQuestionCodes))
sb.append(BundleUtils.getLangString("scenario.mappingQuestion.invalid")); sb.append(BundleUtils.getLangString("scenario.mappingQuestion.invalid"));
} }
...@@ -399,7 +399,6 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -399,7 +399,6 @@ public class ScenarioServiceImpl implements ScenarioService {
resultCell.setCellValue(sb.toString()); resultCell.setCellValue(sb.toString());
isValid = false; isValid = false;
} else { } else {
// isValid = true;
resultCell.setCellValue(BundleUtils.getLangString("ok")); resultCell.setCellValue(BundleUtils.getLangString("ok"));
} }
sb = new StringBuilder(); sb = new StringBuilder();
...@@ -416,18 +415,18 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -416,18 +415,18 @@ public class ScenarioServiceImpl implements ScenarioService {
}); });
//for import mapping question from xls: update mapping question id for answer //for import mapping question from xls: update mapping question id for answer
// lstAnswerTmp.forEach(item -> { lstAnswerTmp.forEach(item -> {
// if (item.getMappingQuestionCode() != null && item.getMappingQuestionId() == null) { if (item.getMappingQuestionCode() != null && item.getMappingQuestionId() == null) {
// ScenarioQuestion question = questionRepository.findScenarioQuestionByCodeAndCompanySiteId(item.getMappingQuestionCode(), item.getCompanySiteId()); ScenarioQuestion question = questionRepository.findScenarioQuestionByCodeAndCompanySiteId(item.getMappingQuestionCode(), item.getCompanySiteId());
// if (question != null) { if (question != null) {
// ScenarioAnswer answerForUpdate = answerRepository.findScenarioAnswerByScenarioQuestionIdAndCode(question.getScenarioQuestionId(), item.code); ScenarioAnswer answerForUpdate = answerRepository.findScenarioAnswerByCode(item.code);
// if(answerForUpdate != null) { if(answerForUpdate != null) {
// answerForUpdate.setMappingQuestionId(question.getScenarioQuestionId()); answerForUpdate.setMappingQuestionId(question.getScenarioQuestionId());
// answerRepository.save(answerForUpdate); answerRepository.save(answerForUpdate);
// } }
// } }
// } }
// }); });
workbook.write(os); workbook.write(os);
os.flush(); os.flush();
...@@ -448,7 +447,6 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -448,7 +447,6 @@ public class ScenarioServiceImpl implements ScenarioService {
result.put("message", BundleUtils.getLangString("customer.errorValidate", locale)); result.put("message", BundleUtils.getLangString("customer.errorValidate", locale));
}finally { }finally {
if (workbook != null) workbook.close(); if (workbook != null) workbook.close();
//result.put("code", Constants.FILE_UPLOAD_RESP_CODE.ERROR);
} }
return result; return result;
} }
...@@ -456,13 +454,11 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -456,13 +454,11 @@ public class ScenarioServiceImpl implements ScenarioService {
private boolean validateMappingQuestion(String mappingQuestion, String currentQuestionCode, List<String> lstQuestionCode) { private boolean validateMappingQuestion(String mappingQuestion, String currentQuestionCode, List<String> lstQuestionCode) {
if (mappingQuestion != null && mappingQuestion.equals(currentQuestionCode)) return false; if (mappingQuestion != null && mappingQuestion.equals(currentQuestionCode)) return false;
String duplicateCode = lstQuestionCode.stream(). String existMappingQuestionCode = lstQuestionCode.stream().
filter(p -> (p.equals(mappingQuestion) && p.equals(currentQuestionCode))). filter(p -> (p.equals(mappingQuestion) && !p.equals(currentQuestionCode))).
findAny().orElse(null); findAny().orElse(null);
if (duplicateCode == null) return false; if (existMappingQuestionCode == null) return false;
String notMappedCode = lstQuestionCode.stream().filter(p -> (!p.equals(mappingQuestion))).findAny().orElse(null);
if (notMappedCode != null) return false;
return true; return true;
} }
...@@ -534,6 +530,8 @@ public class ScenarioServiceImpl implements ScenarioService { ...@@ -534,6 +530,8 @@ public class ScenarioServiceImpl implements ScenarioService {
q.setLstAnswers(answers); q.setLstAnswers(answers);
}); });
questionOrderIndex = null;
lstQuestions.forEach(q2 -> { lstQuestions.forEach(q2 -> {
List<ScenarioAnswerDTO> lstAnswers = q2.getLstAnswers(); List<ScenarioAnswerDTO> lstAnswers = q2.getLstAnswers();
lstAnswers.forEach(a2 -> { lstAnswers.forEach(a2 -> {
......
package com.viettel.campaign.web.dto.request_dto; package com.viettel.campaign.web.dto.request_dto;
import com.viettel.campaign.web.dto.BaseDTO; import com.viettel.campaign.web.dto.BaseDTO;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@Getter @Getter
@Setter @Setter
@AllArgsConstructor
@NoArgsConstructor
public class CustomerQueryDTO extends BaseDTO { public class CustomerQueryDTO extends BaseDTO {
String join ; String join ;
Long field; Long field;
String operator; String operator;
String condition; String condition;
String type;
} }
...@@ -33,8 +33,8 @@ public class AgentsController { ...@@ -33,8 +33,8 @@ public class AgentsController {
@GetMapping("/findAll") @GetMapping("/findAll")
@ResponseBody @ResponseBody
public ResponseEntity<ResultDTO> listAgentByCompanySiteId(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId) { public ResponseEntity<ResultDTO> listAgentByCompanySiteId(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId, @RequestParam("campaignId") Long campaignId) {
ResultDTO result = agentsService.getAllAgentByCompanySiteId(page, pageSize, companySiteId); ResultDTO result = agentsService.getAllAgentByCompanySiteId(page, pageSize, companySiteId, campaignId);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
...@@ -63,8 +63,8 @@ public class AgentsController { ...@@ -63,8 +63,8 @@ public class AgentsController {
@GetMapping("/searchCampaignAgent") @GetMapping("/searchCampaignAgent")
@ResponseBody @ResponseBody
public ResponseEntity<ResultDTO> searchCampaignAgent(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("companySiteId") Long companySiteId, @RequestParam("userName") String userName, @RequestParam("fullName") String fullName) { public ResponseEntity<ResultDTO> searchCampaignAgent(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("campaignId") Long campaignId, @RequestParam("companySiteId") Long companySiteId, @RequestParam("userName") String userName, @RequestParam("fullName") String fullName) {
ResultDTO result = agentsService.searchCampaignAgentByName(page, pageSize, companySiteId, userName, fullName); ResultDTO result = agentsService.searchCampaignAgentByName(page, pageSize, campaignId, companySiteId, userName, fullName);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
......
...@@ -316,7 +316,7 @@ public class CustomerController { ...@@ -316,7 +316,7 @@ public class CustomerController {
return new ResponseEntity<>(resultDTO, HttpStatus.OK); return new ResponseEntity<>(resultDTO, HttpStatus.OK);
} }
@PostMapping("/searchCustomizeFields") @PostMapping("/searchIndividualCustomer")
@ResponseBody @ResponseBody
public ResponseEntity searchCustomizeFields(@RequestBody CampaignCustomerDTO campaignCustomerDTO ) { public ResponseEntity searchCustomizeFields(@RequestBody CampaignCustomerDTO campaignCustomerDTO ) {
ResultDTO result = customerService.searchCustomizeFields(campaignCustomerDTO); ResultDTO result = customerService.searchCustomizeFields(campaignCustomerDTO);
......
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