Commit f6139454 authored by Vu Duy Anh's avatar Vu Duy Anh

anhvd commit change

parents 9810d9f3 34ea2d6c
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="ExternalSystem" externalSystem="Maven" />
<component name="FacetManager"> <component name="FacetManager">
<facet type="Spring" name="Spring"> <facet type="Spring" name="Spring">
<configuration /> <configuration />
......
package com.viettel.campaign.model;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;
@Entity
@Table(name = "CUSTOMER_CONTACT")
@Getter
@Setter
public class CustomerContact {
@Id
@Basic(optional = false)
@NotNull
@Column(name = "CONTACT_ID")
private Long contactId;
@Column(name = "CUSTOMER_ID")
private Long customerId;
@Column(name = "CONTACT_TYPE")
private Short contactType;
@Column(name = "CONTACT")
private String contact;
@Column(name = "IS_DIRECT_LINE")
private Short isDirectLine;
@Column(name = "STATUS")
private Short status;
@Column(name = "CREATE_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Column(name = "UPDATE_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date updateDate;
@Column(name = "CREATE_BY")
private String createBy;
@Column(name = "UPDATE_BY")
private String updateBy;
@Column(name = "START_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date startDate;
@Column(name = "END_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date endDate;
}
package com.viettel.campaign.repository;
import com.viettel.campaign.model.CustomerContact;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface CustomerContactRepository extends JpaRepository<CustomerContact, Long> {
List<CustomerContact> findByCustomerIdAndAndContactTypeAndContact(Long customerId, Short contactType, String contact);
}
...@@ -6,9 +6,27 @@ import org.springframework.data.jpa.repository.Modifying; ...@@ -6,9 +6,27 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.List;
public interface CustomerListMappingRepository extends JpaRepository<CustomerListMapping, Long> { public interface CustomerListMappingRepository extends JpaRepository<CustomerListMapping, Long> {
// ----------- customer ------------ //
@Modifying
@Query("delete from CustomerListMapping c where c.customerId=:p_customer_id and c.customerListId=:p_customer_list_id")
int deleteMappingByCustomerId(@Param("p_customer_id") Long p_customer_id, @Param("p_customer_list_id") Long p_customer_list_id);
@Modifying
@Query("delete from CustomerListMapping c where c.customerId in (:p_id) and c.customerListId =:p_customer_list_id")
int deleteMappingByCustomerIds(@Param("p_id") List<Long> p_id, @Param("p_customer_list_id") Long p_customer_list_id);
// ----------- customer list --------------- //
@Modifying
@Query("delete from CustomerListMapping c where c.customerListId=:p_customerListId")
int deleteMappingByCustomerListId(@Param("p_customerListId") Long p_customerListId);
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerListId=:customerListId") @Query("delete from CustomerListMapping c where c.customerListId in (:p_ids)")
int deleteMappingByCustomerListId(@Param("customerListId") Long customerListId); int deleteMappingByCustomerListIds(@Param("p_ids") List<Long> p_ids);
} }
...@@ -15,6 +15,10 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long ...@@ -15,6 +15,10 @@ public interface CustomerListRepository extends JpaRepository<CustomerList, Long
CustomerList findByCustomerListCode(String customerListCode); CustomerList findByCustomerListCode(String customerListCode);
@Modifying @Modifying
@Query("delete from CustomerList c where c.customerListId in (:ids)") @Query("update CustomerList c set c.status = 0 where c.customerListId=:p_customerListId")
int deleteCustomerListIds(@Param("ids") List<Long> ids); int deleteCustomerList(@Param("p_customerListId") Long p_customerListId);
@Modifying
@Query("update CustomerList c set c.status = 0 where c.customerListId in (:p_ids)")
int deleteCustomerListIds(@Param("p_ids") List<Long> p_ids);
} }
...@@ -16,6 +16,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> { ...@@ -16,6 +16,8 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {
Page<Customer> findAll(Pageable pageable); Page<Customer> findAll(Pageable pageable);
List<Customer> findByCustomerId(Long customerId);
@Query("FROM Customer WHERE name = ?1") @Query("FROM Customer WHERE name = ?1")
List<Customer> findByName(String firstName, Pageable pageable); List<Customer> findByName(String firstName, Pageable pageable);
......
...@@ -21,6 +21,7 @@ import org.springframework.stereotype.Repository; ...@@ -21,6 +21,7 @@ import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.Query; import javax.persistence.Query;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -37,18 +38,17 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -37,18 +38,17 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
List<CampaignDTO> lst = new ArrayList<>(); List<CampaignDTO> lst = new ArrayList<>();
StringBuilder expression = new StringBuilder() StringBuilder expression = new StringBuilder()
.append(" SELECT C.CAMPAIGN_CODE, C.CAMPAIGN_NAME, C.CONTENT, C.START_TIME, C.END_TIME, C.STATUS ") .append(" SELECT C.CAMPAIGN_CODE, C.CAMPAIGN_NAME, C.CONTENT, C.START_TIME, C.END_TIME, C.STATUS, CA.STATUS AS AGENT_STATUS ")
.append(" FROM CAMPAIGN C INNER JOIN CAMPAIGN_AGENT CA ON C.CAMPAIGN_ID = CA.CAMPAIGN_ID ") .append(" FROM CAMPAIGN C INNER JOIN CAMPAIGN_AGENT CA ON C.CAMPAIGN_ID = CA.CAMPAIGN_ID ")
.append(" WHERE 1 = 1 ") .append(" WHERE 1 = 1 ");
//.append(" AND CA.AGENT_ID = :pAgentId ") //.append(" AND CA.AGENT_ID = :pAgentId ")
.append(" AND C.STATUS IN (2,3) ");
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) {
expression.append(" AND C.CAMPAIGN_ID IN (:pCampaingId) "); expression.append(" AND C.CAMPAIGN_CODE IN (:pCampaignCode) ");
} }
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignName())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignName())) {
expression.append(" AND UPPER(C.CAMPAIGN_NAME) LIKE CONCAT('%',:pCampaignName,'%') "); expression.append(" AND UPPER(C.CAMPAIGN_NAME) LIKE :pCampaignName ");
} }
if (!DataUtil.isNullOrZero(campaignRequestDto.getStatus().longValue())) { if (!DataUtil.isNullOrZero(campaignRequestDto.getStatus().longValue())) {
...@@ -88,40 +88,45 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -88,40 +88,45 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignCode())) {
String[] lstCode = campaignRequestDto.getCampaignCode().split(","); String[] lstCode = campaignRequestDto.getCampaignCode().split(",");
query.setParameter(":pCampaingId", lstCode); query.setParameter("pCampaignCode", lstCode);
} }
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignName())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getCampaignName())) {
query.setParameter(":pCampaignName", campaignRequestDto.getCampaignName().toUpperCase()); query.setParameter("pCampaignName", "%" +
campaignRequestDto.getCampaignName().toUpperCase()
.replace("\\", "\\\\")
.replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_")
+ "%");
} }
if (!DataUtil.isNullOrZero(campaignRequestDto.getStatus().longValue())) { if (!DataUtil.isNullOrZero(campaignRequestDto.getStatus().longValue())) {
if (campaignRequestDto.getStatus() != 0) if (campaignRequestDto.getStatus() != 0)
query.setParameter(":pStatus", campaignRequestDto.getStatus()); query.setParameter("pStatus", campaignRequestDto.getStatus());
} }
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getFromDateFr())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getFromDateFr())) {
query.setParameter(":pStartTimeFr", campaignRequestDto.getFromDateFr()); query.setParameter("pStartTimeFr", campaignRequestDto.getFromDateFr());
} }
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getFromDateTo())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getFromDateTo())) {
query.setParameter(":pStartTimeTo", campaignRequestDto.getFromDateTo()); query.setParameter("pStartTimeTo", campaignRequestDto.getFromDateTo());
} }
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getToDateFr())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getToDateFr())) {
query.setParameter(":pEndTimeFr", campaignRequestDto.getToDateFr()); query.setParameter("pEndTimeFr", campaignRequestDto.getToDateFr());
} }
if (!DataUtil.isNullOrEmpty(campaignRequestDto.getToDateTo())) { if (!DataUtil.isNullOrEmpty(campaignRequestDto.getToDateTo())) {
query.setParameter(":pEndTimeTo", campaignRequestDto.getToDateTo()); query.setParameter("pEndTimeTo", campaignRequestDto.getToDateTo());
} }
if (!DataUtil.isNullOrZero(campaignRequestDto.getNumOfCusFr())) { if (!DataUtil.isNullOrZero(campaignRequestDto.getNumOfCusFr())) {
query.setParameter(":pCustNumFr", campaignRequestDto.getNumOfCusFr()); query.setParameter("pCustNumFr", campaignRequestDto.getNumOfCusFr());
} }
if (!DataUtil.isNullOrZero(campaignRequestDto.getNumOfCusTo())) { if (!DataUtil.isNullOrZero(campaignRequestDto.getNumOfCusTo())) {
query.setParameter(":pCustNumTo", campaignRequestDto.getNumOfCusTo()); query.setParameter("pCustNumTo", campaignRequestDto.getNumOfCusTo());
} }
result.setTotalRow(query.getResultList().size()); result.setTotalRow(query.getResultList().size());
...@@ -144,7 +149,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom { ...@@ -144,7 +149,8 @@ public class CampaignRepositoryImpl implements CampaignRepositoryCustom {
item.setContent((String) obj[2]); item.setContent((String) obj[2]);
item.setStartTime((Date) obj[3]); item.setStartTime((Date) obj[3]);
item.setEndTime((Date) obj[4]); item.setEndTime((Date) obj[4]);
item.setStatus(((Short) obj[5])); item.setStatus(((BigDecimal) obj[5]).shortValueExact());
item.setAgentStatus(((BigDecimal) obj[6]).shortValueExact());
lst.add(item); lst.add(item);
} }
......
...@@ -3,6 +3,8 @@ package com.viettel.campaign.service; ...@@ -3,6 +3,8 @@ package com.viettel.campaign.service;
import com.viettel.campaign.web.dto.CustomerDTO; import com.viettel.campaign.web.dto.CustomerDTO;
import com.viettel.campaign.web.dto.CustomerListDTO; import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.DeleteCustomerRequestDTO;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -12,13 +14,15 @@ public interface CustomerService { ...@@ -12,13 +14,15 @@ public interface CustomerService {
Map listAllCustomer(int page, int pageSize, String sort); Map listAllCustomer(int page, int pageSize, String sort);
ResultDTO getCustomerId(Long customerId);
Map listCustByName(int page, int pageSize, String sort, String name); Map listCustByName(int page, int pageSize, String sort, String name);
ResultDTO createCustomer(CustomerDTO customerDTO); ResultDTO createCustomer(CustomerDTO customerDTO);
ResultDTO deleteCustomer(CustomerDTO customerDTO); ResultDTO deleteCustomer(DeleteCustomerRequestDTO deleteCustomerRequestDTO);
ResultDTO deleteIds(List<Long> ids); ResultDTO deleteIds(DeleteCustomerRequestDTO deleteCustomerRequestDTO);
// ------------ customer list ------------ // // ------------ customer list ------------ //
...@@ -32,5 +36,9 @@ public interface CustomerService { ...@@ -32,5 +36,9 @@ public interface CustomerService {
ResultDTO deleteCustomerListIds(List<Long> ids); ResultDTO deleteCustomerListIds(List<Long> ids);
ResultDTO searchCustomerList(String customerListCode, String customerListName, Date dateFrom, Date dateTo, int page, int pageSize, String sort); ResultDTO searchCustomerList(CampaignCustomerRequestDTO campaignCustomerRequestDTO);
// ------------ customer contact ------------ //
ResultDTO getCustomerContact(Long customerId, Short contactType, String contact);
} }
package com.viettel.campaign.service; package com.viettel.campaign.service.impl;
import com.viettel.campaign.service.CampaignCompleteCodeService;
import com.viettel.campaign.utils.Constants; import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.web.dto.CampaignCompleteCodeDTO; import com.viettel.campaign.web.dto.CampaignCompleteCodeDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
......
package com.viettel.campaign.service.impl; package com.viettel.campaign.service.impl;
import com.viettel.campaign.mapper.CustomerListMapper; import com.viettel.campaign.mapper.CustomerListMapper;
import com.viettel.campaign.model.CustomerContact;
import com.viettel.campaign.model.CustomerList; import com.viettel.campaign.model.CustomerList;
import com.viettel.campaign.repository.CampaignCustomerListRepository; import com.viettel.campaign.repository.*;
import com.viettel.campaign.repository.CustomerListMappingRepository;
import com.viettel.campaign.repository.CustomerListRepository;
import com.viettel.campaign.service.CustomerService; import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.utils.Constants; import com.viettel.campaign.utils.Constants;
import com.viettel.campaign.utils.HibernateUtil; import com.viettel.campaign.utils.HibernateUtil;
...@@ -14,12 +13,17 @@ import com.viettel.campaign.web.dto.CustomerListDTO; ...@@ -14,12 +13,17 @@ import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.mapper.CustomerMapper; import com.viettel.campaign.mapper.CustomerMapper;
import com.viettel.campaign.model.Customer; import com.viettel.campaign.model.Customer;
import com.viettel.campaign.repository.CustomerRepository;
import com.viettel.campaign.utils.DataUtil; import com.viettel.campaign.utils.DataUtil;
import com.viettel.campaign.web.dto.request_dto.CampaignCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.DeleteCustomerRequestDTO;
import org.hibernate.SQLQuery; import org.hibernate.SQLQuery;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers; import org.hibernate.transform.Transformers;
import org.hibernate.type.DateType;
import org.hibernate.type.LongType;
import org.hibernate.type.ShortType;
import org.hibernate.type.StringType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*; import org.springframework.data.domain.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -41,6 +45,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -41,6 +45,9 @@ public class CustomerServiceImpl implements CustomerService {
@Autowired @Autowired
CustomerListRepository customerListRepository; CustomerListRepository customerListRepository;
@Autowired
CustomerContactRepository customerContactRepository;
@Autowired @Autowired
CampaignCustomerListRepository campaignCustomerListRepository; CampaignCustomerListRepository campaignCustomerListRepository;
...@@ -61,6 +68,24 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -61,6 +68,24 @@ public class CustomerServiceImpl implements CustomerService {
return result; return result;
} }
@Override
public ResultDTO getCustomerId(Long customerId) {
ResultDTO resultDTO = new ResultDTO();
List<Customer> customer = customerRepository.findByCustomerId(customerId);
if (customer != null) {
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription("customer data");
resultDTO.setListData(customer);
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription("customer data null");
}
return resultDTO;
}
@Override @Override
public Map listCustByName(int page, int pageSize, String sort, String name) { public Map listCustByName(int page, int pageSize, String sort, String name) {
Map result = new HashMap(); Map result = new HashMap();
...@@ -111,12 +136,13 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -111,12 +136,13 @@ public class CustomerServiceImpl implements CustomerService {
} }
@Override @Override
public ResultDTO deleteCustomer(CustomerDTO customerDTO) { public ResultDTO deleteCustomer(DeleteCustomerRequestDTO deleteCustomerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
if (customerDTO != null) { if (deleteCustomerRequestDTO != null) {
// delete // delete
customerRepository.deleteById(customerDTO.getCustomerId()); // customerRepository.deleteById(customerDTO.getCustomerId());
customerListMappingRepository.deleteMappingByCustomerId(deleteCustomerRequestDTO.getCustomerId(), deleteCustomerRequestDTO.getCustomerListId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
...@@ -133,11 +159,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -133,11 +159,12 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional @Transactional
@Override @Override
public ResultDTO deleteIds(List<Long> ids) { public ResultDTO deleteIds(DeleteCustomerRequestDTO deleteCustomerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
if (ids != null) { if (deleteCustomerRequestDTO != null) {
customerRepository.deleteIds(ids); // customerRepository.deleteIds(ids);
customerListMappingRepository.deleteMappingByCustomerIds(deleteCustomerRequestDTO.getCustomerIds(), deleteCustomerRequestDTO.getCustomerListId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else { } else {
...@@ -220,7 +247,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -220,7 +247,7 @@ public class CustomerServiceImpl implements CustomerService {
if (customerListDTO != null) { if (customerListDTO != null) {
// update // update
customerList = customerListMapper.toPersistenceBean(customerListDTO); customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerList = customerListRepository.save(customerList); customerListRepository.save(customerList);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
...@@ -239,14 +266,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -239,14 +266,12 @@ public class CustomerServiceImpl implements CustomerService {
@Override @Override
public ResultDTO deleteCustomerList(CustomerListDTO customerListDTO) { public ResultDTO deleteCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper();
CustomerList customerList = customerListRepository.findCustomerListByCustomerListId(customerListDTO.getCustomerListId());
try { try {
// delete // delete
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) { if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) {
customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerList = customerListRepository.save(customerList); customerListRepository.deleteCustomerList(customerListDTO.getCustomerListId());
customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId()); customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId());
...@@ -272,6 +297,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -272,6 +297,9 @@ public class CustomerServiceImpl implements CustomerService {
if (ids != null) { if (ids != null) {
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignIdsCount(ids))) { if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignIdsCount(ids))) {
customerListRepository.deleteCustomerListIds(ids); customerListRepository.deleteCustomerListIds(ids);
customerListMappingRepository.deleteMappingByCustomerListIds(ids);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else { } else {
...@@ -289,71 +317,106 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -289,71 +317,106 @@ public class CustomerServiceImpl implements CustomerService {
} }
@Override @Override
public ResultDTO searchCustomerList(String customerListCode, String customerListName, Date dateFrom, Date dateTo, int page, int pageSize, String sort) { public ResultDTO searchCustomerList(CampaignCustomerRequestDTO campaignCustomerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession(); Session session = sessionFactory.openSession();
session.beginTransaction(); session.beginTransaction();
StringBuilder sqlStrBuilder = new StringBuilder(); if (DataUtil.isNullOrEmpty(campaignCustomerRequestDTO.getCompanySiteId())) {
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params")); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
if (!customerListCode.equals("undefined")) { resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
sqlStrBuilder.append(" AND CUSTOMER_LIST_CODE LIKE :p_list_code"); return resultDTO;
}
if (!customerListName.equals("undefined")) {
sqlStrBuilder.append(" AND CUSTOMER_LIST_NAME LIKE :p_list_name");
} }
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString()); try {
StringBuilder sqlStrBuilder = new StringBuilder();
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params"));
if (DataUtil.isNullOrEmpty(campaignCustomerRequestDTO.getCustomerListCode())) {
sqlStrBuilder.append(" AND CUSTOMER_LIST_CODE LIKE :p_list_code");
}
if (DataUtil.isNullOrEmpty(campaignCustomerRequestDTO.getCustomerListName())) {
sqlStrBuilder.append(" AND CUSTOMER_LIST_NAME LIKE :p_list_name");
}
query.setParameter("p_date_from", dateFrom); SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
query.setParameter("p_date_to", dateTo);
if (!customerListCode.equals("undefined")) { query.setParameter("p_date_from", campaignCustomerRequestDTO.getConvertedDateFrom());
query.setParameter("p_list_code", "%" + query.setParameter("p_date_to", campaignCustomerRequestDTO.getConvertedDateTo());
customerListCode
.replace("\\", "\\\\")
.replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_")
+ "%");
}
if (!customerListName.equals("undefined")) { if (!campaignCustomerRequestDTO.getCustomerListCode().equals("undefined")) {
query.setParameter("p_list_name", "%" + query.setParameter("p_list_code", "%" +
customerListName campaignCustomerRequestDTO.getCustomerListCode()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\\\%") .replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_") .replaceAll("_", "\\\\_")
+ "%"); + "%");
} }
// Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort)); if (!campaignCustomerRequestDTO.getCustomerListName().equals("undefined")) {
// Page<CustomerList> pc = customerListRepository.search(); query.setParameter("p_list_name", "%" +
// campaignCustomerRequestDTO.getCustomerListName()
// result.put("totalItem", pc.getTotalElements()); .replace("\\", "\\\\")
// result.put("searchList", pc.iterator()); .replaceAll("%", "\\\\%")
query.setResultTransformer(Transformers.aliasToBean(CustomerListDTO.class)); .replaceAll("_", "\\\\_")
int count = 0; + "%");
List<CustomerListDTO> dtoList = query.list(); }
if (dtoList.size() > 0) {
count = query.list().size();
}
// Pageable pageable = buildPageable();
// if (pageable != null) {
// query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
// query.setMaxResults(pageable.getPageSize());
// }
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort)); query.addScalar("customerListId", new LongType());
query.addScalar("companySiteId", new LongType());
query.addScalar("customerListCode", new StringType());
query.addScalar("customerListName", new StringType());
query.addScalar("status", new ShortType());
query.addScalar("createBy", new StringType());
query.addScalar("createAt", new DateType());
query.addScalar("updateBy", new StringType());
query.addScalar("updateAt", new DateType());
query.addScalar("source", new StringType());
query.addScalar("deptCreate", new StringType());
query.setResultTransformer(Transformers.aliasToBean(CustomerListDTO.class));
int count = 0;
List<CustomerListDTO> dtoList = query.list();
if (dtoList.size() > 0) {
count = query.list().size();
}
Pageable pageable = SQLBuilder.buildPageable(campaignCustomerRequestDTO);
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<CustomerListDTO> data = query.list(); List<CustomerListDTO> data = query.list();
Page<CustomerListDTO> dataPage = new PageImpl<>(data, pageable, count); Page<CustomerListDTO> dataPage = new PageImpl<>(data, pageable, count);
resultDTO.setData(dataPage); resultDTO.setData(dataPage);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
session.close(); } catch (Exception e) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally {
session.close();
}
return resultDTO; return resultDTO;
} }
@Override
public ResultDTO getCustomerContact(Long customerId, Short contactType, String contact) {
ResultDTO result = new ResultDTO();
List<CustomerContact> customer = customerContactRepository.findByCustomerIdAndAndContactTypeAndContact(customerId, contactType, contact);
if (customer != null) {
result.setErrorCode(Constants.ApiErrorCode.SUCCESS);
result.setDescription("customer contact data");
result.setListData(customer);
} else {
result.setErrorCode(Constants.ApiErrorCode.ERROR);
result.setDescription("customer contact data null");
}
return result;
}
} }
...@@ -17,7 +17,6 @@ import org.springframework.data.domain.Sort; ...@@ -17,7 +17,6 @@ import org.springframework.data.domain.Sort;
public class SQLBuilder { public class SQLBuilder {
public static final String SQL_MODULE_CAMPAIGN_MNG = "campaign-mng"; public static final String SQL_MODULE_CAMPAIGN_MNG = "campaign-mng";
public static final String SQL_MODULE_CAMPAIGN_STATUS_MNG = "campaign-status-mng"; public static final String SQL_MODULE_CAMPAIGN_STATUS_MNG = "campaign-status-mng";
public static final String SQL_MODULE_CAMPAIGN_CUSTOMER = "campaign-customer";
public static String getSqlQueryById(String module, public static String getSqlQueryById(String module,
String queryId) { String queryId) {
......
...@@ -63,5 +63,5 @@ public class CampaignDTO extends BaseDTO { ...@@ -63,5 +63,5 @@ public class CampaignDTO extends BaseDTO {
private String timeZoneMinute; private String timeZoneMinute;
private List<TimeRangeDialModeDTO> lstTimeRange; private List<TimeRangeDialModeDTO> lstTimeRange;
private List<TimeZoneDialModeDTO> lstTimeZone; private List<TimeZoneDialModeDTO> lstTimeZone;
private Short agentStatus;
} }
package com.viettel.campaign.web.dto;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
@Getter
@Setter
public class CustomerContactDTO {
private Long contactId;
private Long customerId;
private Short contactType;
private String contact;
private Short isDirectLine;
private Short status;
private Date createDate;
private Date updateDate;
private String createBy;
private String updateBy;
private Date startDate;
private Date endDate;
}
package com.viettel.campaign.web.dto.request_dto;
import com.viettel.campaign.web.dto.BaseDTO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CampaignCustomerRequestDTO extends BaseDTO {
String customerListCode;
String customerListName;
String convertedDateFrom;
String convertedDateTo;
String companySiteId;
}
package com.viettel.campaign.web.dto.request_dto;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class DeleteCustomerRequestDTO {
Long customerId;
Long customerListId;
List<Long> customerIds;
}
...@@ -4,6 +4,8 @@ import com.viettel.campaign.web.dto.CustomerDTO; ...@@ -4,6 +4,8 @@ import com.viettel.campaign.web.dto.CustomerDTO;
import com.viettel.campaign.web.dto.CustomerListDTO; import com.viettel.campaign.web.dto.CustomerListDTO;
import com.viettel.campaign.web.dto.ResultDTO; import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.service.CustomerService; import com.viettel.campaign.service.CustomerService;
import com.viettel.campaign.web.dto.request_dto.CampaignCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.DeleteCustomerRequestDTO;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -12,7 +14,6 @@ import org.springframework.stereotype.Controller; ...@@ -12,7 +14,6 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -33,6 +34,13 @@ public class CustomerController { ...@@ -33,6 +34,13 @@ public class CustomerController {
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
@GetMapping("/findCustomerId")
@ResponseBody
public ResponseEntity<ResultDTO> findAllCustomerName(@RequestParam("customerId") Long customerId) {
ResultDTO result = customerService.getCustomerId(customerId);
return new ResponseEntity(result, HttpStatus.OK);
}
@GetMapping("/findCustomerByName") @GetMapping("/findCustomerByName")
@ResponseBody @ResponseBody
public ResponseEntity findAllCustomerName(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam("name") String name) { public ResponseEntity findAllCustomerName(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam("name") String name) {
...@@ -61,17 +69,17 @@ public class CustomerController { ...@@ -61,17 +69,17 @@ public class CustomerController {
@PostMapping("/delete") @PostMapping("/delete")
@ResponseBody @ResponseBody
public ResultDTO deleteCustomer(@RequestBody @Valid CustomerDTO customerDTO) { public ResultDTO deleteCustomer(@RequestBody @Valid DeleteCustomerRequestDTO deleteCustomerRequestDTO) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
result = customerService.deleteCustomer(customerDTO); result = customerService.deleteCustomer(deleteCustomerRequestDTO);
return result; return result;
} }
@PostMapping("/deleteIds") @PostMapping("/deleteIds")
@ResponseBody @ResponseBody
public ResultDTO deleteIds(@RequestBody @Valid List<Long> ids) { public ResultDTO deleteIds(@RequestBody @Valid DeleteCustomerRequestDTO deleteCustomerRequestDTO) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
result = customerService.deleteIds(ids); result = customerService.deleteIds(deleteCustomerRequestDTO);
return result; return result;
} }
...@@ -140,10 +148,16 @@ public class CustomerController { ...@@ -140,10 +148,16 @@ public class CustomerController {
return result; return result;
} }
@GetMapping("/searchCustomerList") @RequestMapping(value = "/searchCustomerList", method = RequestMethod.POST)
@ResponseBody public ResponseEntity searchCustomerList(@RequestBody CampaignCustomerRequestDTO campaignCustomerRequestDTO) {
public ResponseEntity searchCustomerList(@RequestParam("customerListCode") String customerListCode, @RequestParam("customerListName") String customerListName, @RequestParam("dateFrom") Date dateFrom, @RequestParam("dateTo") Date dateTo, @RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort) { ResultDTO result = customerService.searchCustomerList(campaignCustomerRequestDTO);
ResultDTO result = customerService.searchCustomerList(customerListCode, customerListName, dateFrom, dateTo, page, pageSize, sort);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
@GetMapping("/findCustomerContact")
@ResponseBody
public ResponseEntity<ResultDTO> findAllCustomerContact(@RequestParam("customerId") Long customerId, @RequestParam("contactType") Short contactType, @RequestParam("contact") String contact) {
ResultDTO result = customerService.getCustomerContact(customerId, contactType, contact);
return new ResponseEntity(result, HttpStatus.OK);
}
} }
SELECT SELECT
CUSTOMER_LIST_ID, CUSTOMER_LIST_ID customerListId,
COMPANY_SITE_ID, COMPANY_SITE_ID companySiteId,
CUSTOMER_LIST_CODE, CUSTOMER_LIST_CODE customerListCode,
CUSTOMER_LIST_NAME, CUSTOMER_LIST_NAME customerListName,
STATUS, STATUS status,
CREATE_BY, CREATE_BY createBy,
CREATE_AT, CREATE_AT createAt,
UPDATE_BY, UPDATE_BY updateBy,
UPDATE_AT, UPDATE_AT updateAt,
SOURCE, SOURCE source,
DEPT_CREATE DEPT_CREATE deptCreate
FROM CUSTOMER_LIST FROM CUSTOMER_LIST
WHERE 1 = 1 WHERE 1 = 1
AND CREATE_AT BETWEEN :p_date_from AND :p_date_to AND CREATE_AT BETWEEN :p_date_from AND :p_date_to
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