Commit e32be465 authored by Phạm Duy Phi's avatar Phạm Duy Phi

phi pd commit: commit

parent 3dd1723b
...@@ -13,20 +13,20 @@ public interface CustomerListMappingRepository extends JpaRepository<CustomerLis ...@@ -13,20 +13,20 @@ public interface CustomerListMappingRepository extends JpaRepository<CustomerLis
// ----------- customer ------------ // // ----------- customer ------------ //
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerId=:p_customer_id and c.customerListId=:p_customer_list_id") @Query("delete from CustomerListMapping c where c.customerId=:p_customer_id and c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerId(@Param("p_customer_id") Long p_customer_id, @Param("p_customer_list_id") Long p_customer_list_id); int deleteMappingByCustomerId(@Param("p_customer_id") Long p_customer_id, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerId in (:p_id) and c.customerListId =:p_customer_list_id") @Query("delete from CustomerListMapping c where c.customerId in (:p_ids) and c.customerListId =:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerIds(@Param("p_id") List<Long> p_id, @Param("p_customer_list_id") Long p_customer_list_id); int deleteMappingByCustomerIds(@Param("p_ids") List<Long> p_ids, @Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
// ----------- customer list --------------- // // ----------- customer list --------------- //
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerListId=:p_customerListId") @Query("delete from CustomerListMapping c where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerListId(@Param("p_customerListId") Long p_customerListId); int deleteMappingByCustomerListId(@Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("delete from CustomerListMapping c where c.customerListId in (:p_ids)") @Query("delete from CustomerListMapping c where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id")
int deleteMappingByCustomerListIds(@Param("p_ids") List<Long> p_ids); int deleteMappingByCustomerListIds(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
} }
...@@ -10,15 +10,15 @@ import java.util.List; ...@@ -10,15 +10,15 @@ import java.util.List;
public interface CustomerListRepository extends JpaRepository<CustomerList, Long> { public interface CustomerListRepository extends JpaRepository<CustomerList, Long> {
CustomerList findCustomerListByCustomerListId(long customerListId); CustomerList findByCustomerListIdAndCompanySiteId(long customerListId, long companySiteId);
CustomerList findByCustomerListCode(String customerListCode); CustomerList findByCustomerListCode(String customerListCode);
@Modifying @Modifying
@Query("update CustomerList c set c.status = 0 where c.customerListId=:p_customerListId") @Query("update CustomerList c set c.status = 0 where c.customerListId=:p_customer_list_id and c.companySiteId=:p_company_site_id")
int deleteCustomerList(@Param("p_customerListId") Long p_customerListId); int deleteCustomerList(@Param("p_customer_list_id") Long p_customer_list_id, @Param("p_company_site_id") Long p_company_site_id);
@Modifying @Modifying
@Query("update CustomerList c set c.status = 0 where c.customerListId in (:p_ids)") @Query("update CustomerList c set c.status = 0 where c.customerListId in (:p_ids) and c.companySiteId=:p_company_site_id")
int deleteCustomerListIds(@Param("p_ids") List<Long> p_ids); int deleteCustomerListIds(@Param("p_ids") List<Long> p_ids, @Param("p_company_site_id") Long p_company_site_id);
} }
...@@ -3,24 +3,22 @@ package com.viettel.campaign.service; ...@@ -3,24 +3,22 @@ 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.SearchCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.DeleteCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
public interface CustomerService { public interface CustomerService {
Map listAllCustomer(int page, int pageSize, String sort); ResultDTO listAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId);
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(DeleteCustomerRequestDTO deleteCustomerRequestDTO); ResultDTO deleteCustomer(CustomerRequestDTO customerRequestDTO);
ResultDTO deleteIds(DeleteCustomerRequestDTO deleteCustomerRequestDTO); ResultDTO deleteIds(CustomerRequestDTO customerRequestDTO);
// ------------ customer list ------------ // // ------------ customer list ------------ //
...@@ -32,7 +30,7 @@ public interface CustomerService { ...@@ -32,7 +30,7 @@ public interface CustomerService {
ResultDTO deleteCustomerList(CustomerListDTO customerListDTO); ResultDTO deleteCustomerList(CustomerListDTO customerListDTO);
ResultDTO deleteCustomerListIds(List<Long> ids); ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO);
ResultDTO searchCustomerList(CampaignCustomerRequestDTO campaignCustomerRequestDTO); ResultDTO searchCustomerList(SearchCustomerRequestDTO searchCustomerRequestDTO);
} }
...@@ -9,6 +9,7 @@ import com.viettel.campaign.service.CustomerService; ...@@ -9,6 +9,7 @@ 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;
import com.viettel.campaign.utils.SQLBuilder; import com.viettel.campaign.utils.SQLBuilder;
import com.viettel.campaign.web.dto.CustomerCustomDTO;
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;
...@@ -16,8 +17,8 @@ import com.viettel.campaign.mapper.CustomerMapper; ...@@ -16,8 +17,8 @@ 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.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.SearchCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.DeleteCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import org.hibernate.SQLQuery; import org.hibernate.SQLQuery;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
...@@ -54,17 +55,76 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -54,17 +55,76 @@ public class CustomerServiceImpl implements CustomerService {
CustomerListMappingRepository customerListMappingRepository; CustomerListMappingRepository customerListMappingRepository;
@Override @Override
public Map listAllCustomer(int page, int pageSize, String sort) { public ResultDTO listAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId) {
Map result = new HashMap(); // Map result = new HashMap();
List<Customer> lst = new ArrayList<>(); // List<Customer> lst = new ArrayList<>();
//
// Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
// Page<Customer> pc = customerRepository.findAll(pageable);
//
// result.put("totalItem", pc.getTotalElements());
// result.put("customers", pc.iterator());
//
// return result;
ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
if (DataUtil.isNullOrZero(companySiteId)) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return resultDTO;
}
try {
StringBuilder sqlStrBuilder = new StringBuilder();
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-customer-detail-by-params"));
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
query.setParameter("p_company_site_id", companySiteId);
query.setParameter("p_customer_list_id", customerListId);
query.addScalar("customerListMappingId", new LongType());
query.addScalar("companySiteId", new LongType());
query.addScalar("customerListId", new LongType());
query.addScalar("customerId", new LongType());
query.addScalar("name", new StringType());
query.addScalar("description", new StringType());
query.addScalar("companyName", new StringType());
query.addScalar("customerType", new StringType());
query.addScalar("currentAddress", new StringType());
query.addScalar("mobileNumber", new StringType());
query.addScalar("email", new StringType());
query.setResultTransformer(Transformers.aliasToBean(CustomerCustomDTO.class));
int count = 0;
List<CustomerListDTO> dtoList = query.list();
if (dtoList.size() > 0) {
count = query.list().size();
}
// Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
// if (pageable != null) {
// query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
// query.setMaxResults(pageable.getPageSize());
// }
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort)); Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort));
Page<Customer> pc = customerRepository.findAll(pageable);
result.put("totalItem", pc.getTotalElements()); List<CustomerListDTO> data = query.list();
result.put("customers", pc.iterator()); Page<CustomerListDTO> dataPage = new PageImpl<>(data, pageable, count);
resultDTO.setData(dataPage);
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} catch (Exception e) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
} finally {
session.close();
}
return result; return resultDTO;
} }
@Override @Override
...@@ -116,14 +176,15 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -116,14 +176,15 @@ public class CustomerServiceImpl implements CustomerService {
return resultDTO; return resultDTO;
} }
@Transactional
@Override @Override
public ResultDTO deleteCustomer(DeleteCustomerRequestDTO deleteCustomerRequestDTO) { public ResultDTO deleteCustomer(CustomerRequestDTO customerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
if (deleteCustomerRequestDTO != null) { if (customerRequestDTO != null) {
// delete // delete
// customerRepository.deleteById(customerDTO.getCustomerId()); // customerRepository.deleteById(customerDTO.getCustomerId());
customerListMappingRepository.deleteMappingByCustomerId(deleteCustomerRequestDTO.getCustomerId(), deleteCustomerRequestDTO.getCustomerListId()); customerListMappingRepository.deleteMappingByCustomerId(customerRequestDTO.getCustomerId(), customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
...@@ -140,12 +201,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -140,12 +201,12 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional @Transactional
@Override @Override
public ResultDTO deleteIds(DeleteCustomerRequestDTO deleteCustomerRequestDTO) { public ResultDTO deleteIds(CustomerRequestDTO customerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
if (deleteCustomerRequestDTO != null) { if (customerRequestDTO != null) {
// customerRepository.deleteIds(ids); // customerRepository.deleteIds(ids);
customerListMappingRepository.deleteMappingByCustomerIds(deleteCustomerRequestDTO.getCustomerIds(), deleteCustomerRequestDTO.getCustomerListId()); customerListMappingRepository.deleteMappingByCustomerIds(customerRequestDTO.getIds(), customerRequestDTO.getCustomerListId(), customerRequestDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
} else { } else {
...@@ -222,11 +283,13 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -222,11 +283,13 @@ public class CustomerServiceImpl implements CustomerService {
public ResultDTO updateCustomerList(CustomerListDTO customerListDTO) { public ResultDTO updateCustomerList(CustomerListDTO customerListDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
CustomerListMapper customerListMapper = new CustomerListMapper(); CustomerListMapper customerListMapper = new CustomerListMapper();
CustomerList customerList = customerListRepository.findCustomerListByCustomerListId(customerListDTO.getCustomerListId());
try { try {
if (customerListDTO != null) { if (customerListDTO != null) {
// update // update
CustomerList customerList = customerListRepository.findByCustomerListIdAndCompanySiteId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
if (customerList != null) {
customerList = customerListMapper.toPersistenceBean(customerListDTO); customerList = customerListMapper.toPersistenceBean(customerListDTO);
customerListRepository.save(customerList); customerListRepository.save(customerList);
...@@ -236,6 +299,10 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -236,6 +299,10 @@ 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);
} }
} else {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -252,9 +319,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -252,9 +319,9 @@ public class CustomerServiceImpl implements CustomerService {
// delete // delete
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) { if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignCount(customerListDTO.getCustomerListId()))) {
customerListRepository.deleteCustomerList(customerListDTO.getCustomerListId()); customerListRepository.deleteCustomerList(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId()); customerListMappingRepository.deleteMappingByCustomerListId(customerListDTO.getCustomerListId(), customerListDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
...@@ -272,14 +339,14 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -272,14 +339,14 @@ public class CustomerServiceImpl implements CustomerService {
@Transactional @Transactional
@Override @Override
public ResultDTO deleteCustomerListIds(List<Long> ids) { public ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO) {
ResultDTO resultDTO = new ResultDTO(); ResultDTO resultDTO = new ResultDTO();
try { try {
if (ids != null) { if (customerRequestDTO != null) {
if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignIdsCount(ids))) { if (DataUtil.isNullOrZero(campaignCustomerListRepository.campaignIdsCount(customerRequestDTO.getIds()))) {
customerListRepository.deleteCustomerListIds(ids); customerListRepository.deleteCustomerListIds(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId());
customerListMappingRepository.deleteMappingByCustomerListIds(ids); customerListMappingRepository.deleteMappingByCustomerListIds(customerRequestDTO.getIds(), customerRequestDTO.getCompanySiteId());
resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS); resultDTO.setErrorCode(Constants.ApiErrorCode.SUCCESS);
resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS); resultDTO.setDescription(Constants.ApiErrorDesc.SUCCESS);
...@@ -298,14 +365,14 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -298,14 +365,14 @@ public class CustomerServiceImpl implements CustomerService {
} }
@Override @Override
public ResultDTO searchCustomerList(CampaignCustomerRequestDTO campaignCustomerRequestDTO) { public ResultDTO searchCustomerList(SearchCustomerRequestDTO searchCustomerRequestDTO) {
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();
if (DataUtil.isNullOrEmpty(campaignCustomerRequestDTO.getCompanySiteId())) { if (DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCompanySiteId())) {
resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR); resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return resultDTO; return resultDTO;
...@@ -314,33 +381,34 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -314,33 +381,34 @@ public class CustomerServiceImpl implements CustomerService {
try { try {
StringBuilder sqlStrBuilder = new StringBuilder(); StringBuilder sqlStrBuilder = new StringBuilder();
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params")); sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params"));
if (DataUtil.isNullOrEmpty(campaignCustomerRequestDTO.getCustomerListCode())) { if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCustomerListCode())) {
sqlStrBuilder.append(" AND CUSTOMER_LIST_CODE LIKE :p_list_code"); sqlStrBuilder.append(" AND CUSTOMER_LIST_CODE LIKE :p_list_code");
} }
if (DataUtil.isNullOrEmpty(campaignCustomerRequestDTO.getCustomerListName())) { if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCustomerListName())) {
sqlStrBuilder.append(" AND CUSTOMER_LIST_NAME LIKE :p_list_name"); sqlStrBuilder.append(" AND CUSTOMER_LIST_NAME LIKE :p_list_name");
} }
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString()); SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
query.setParameter("p_date_from", campaignCustomerRequestDTO.getConvertedDateFrom()); query.setParameter("p_date_from", searchCustomerRequestDTO.getConvertedDateFrom());
query.setParameter("p_date_to", campaignCustomerRequestDTO.getConvertedDateTo()); query.setParameter("p_date_to", searchCustomerRequestDTO.getConvertedDateTo());
query.setParameter("p_company_site_id", searchCustomerRequestDTO.getCompanySiteId());
if (!campaignCustomerRequestDTO.getCustomerListCode().equals("undefined")) { if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCustomerListCode())) {
query.setParameter("p_list_code", "%" + query.setParameter("p_list_code", "%" +
campaignCustomerRequestDTO.getCustomerListCode() searchCustomerRequestDTO.getCustomerListCode()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\\\%") .replaceAll("%", "\\%")
.replaceAll("_", "\\\\_") .replaceAll("_", "\\_")
+ "%"); + "%");
} }
if (!campaignCustomerRequestDTO.getCustomerListName().equals("undefined")) { if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCustomerListName())) {
query.setParameter("p_list_name", "%" + query.setParameter("p_list_name", "%" +
campaignCustomerRequestDTO.getCustomerListName() searchCustomerRequestDTO.getCustomerListName()
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replaceAll("%", "\\\\%") .replaceAll("%", "\\%")
.replaceAll("_", "\\\\_") .replaceAll("_", "\\_")
+ "%"); + "%");
} }
...@@ -362,11 +430,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -362,11 +430,12 @@ public class CustomerServiceImpl implements CustomerService {
if (dtoList.size() > 0) { if (dtoList.size() > 0) {
count = query.list().size(); count = query.list().size();
} }
Pageable pageable = SQLBuilder.buildPageable(campaignCustomerRequestDTO); // Pageable pageable = SQLBuilder.buildPageable(searchCustomerRequestDTO);
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());
} // }
Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort()));
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);
......
...@@ -5,7 +5,6 @@ import java.nio.file.Paths; ...@@ -5,7 +5,6 @@ import java.nio.file.Paths;
import java.io.IOException; import java.io.IOException;
import com.viettel.campaign.web.dto.BaseDTO; import com.viettel.campaign.web.dto.BaseDTO;
import com.viettel.campaign.web.dto.request_dto.CampaignRequestDTO;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
......
package com.viettel.campaign.web.dto;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CustomerCustomDTO {
Long customerListMappingId;
Long companySiteId;
Long customerListId;
Long customerId;
String name;
String description;
String companyName;
String customerType;
String currentAddress;
String mobileNumber;
String email;
}
...@@ -7,8 +7,9 @@ import java.util.List; ...@@ -7,8 +7,9 @@ import java.util.List;
@Getter @Getter
@Setter @Setter
public class DeleteCustomerRequestDTO { public class CustomerRequestDTO {
Long customerId; Long customerId;
Long customerListId; Long customerListId;
List<Long> customerIds; List<Long> ids;
Long companySiteId;
} }
...@@ -6,7 +6,7 @@ import lombok.Setter; ...@@ -6,7 +6,7 @@ import lombok.Setter;
@Getter @Getter
@Setter @Setter
public class CampaignCustomerRequestDTO extends BaseDTO { public class SearchCustomerRequestDTO extends BaseDTO {
String customerListCode; String customerListCode;
String customerListName; String customerListName;
String convertedDateFrom; String convertedDateFrom;
......
...@@ -4,8 +4,8 @@ import com.viettel.campaign.web.dto.CustomerDTO; ...@@ -4,8 +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.SearchCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.DeleteCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
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;
...@@ -14,12 +14,11 @@ import org.springframework.stereotype.Controller; ...@@ -14,12 +14,11 @@ 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.List;
import java.util.Map; import java.util.Map;
@Controller @Controller
@RequestMapping("/ipcc/customer") @RequestMapping("/ipcc/customer")
@CrossOrigin("*") @CrossOrigin(origins = "*")
public class CustomerController { public class CustomerController {
private static final Logger LOGGER = Logger.getLogger(CustomerController.class); private static final Logger LOGGER = Logger.getLogger(CustomerController.class);
...@@ -29,8 +28,8 @@ public class CustomerController { ...@@ -29,8 +28,8 @@ public class CustomerController {
@GetMapping("/findAll") @GetMapping("/findAll")
@ResponseBody @ResponseBody
public ResponseEntity findAllCustomer(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort) { public ResponseEntity findAllCustomer(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam("customerListId") long customerListId, @RequestParam("companySiteId") long companySiteId) {
Map result = customerService.listAllCustomer(page, pageSize, sort); ResultDTO result = customerService.listAllCustomer(page, pageSize, sort, customerListId, companySiteId);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
...@@ -62,17 +61,17 @@ public class CustomerController { ...@@ -62,17 +61,17 @@ public class CustomerController {
@PostMapping("/delete") @PostMapping("/delete")
@ResponseBody @ResponseBody
public ResultDTO deleteCustomer(@RequestBody @Valid DeleteCustomerRequestDTO deleteCustomerRequestDTO) { public ResultDTO deleteCustomer(@RequestBody @Valid CustomerRequestDTO customerRequestDTO) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
result = customerService.deleteCustomer(deleteCustomerRequestDTO); result = customerService.deleteCustomer(customerRequestDTO);
return result; return result;
} }
@PostMapping("/deleteIds") @PostMapping("/deleteIds")
@ResponseBody @ResponseBody
public ResultDTO deleteIds(@RequestBody @Valid DeleteCustomerRequestDTO deleteCustomerRequestDTO) { public ResultDTO deleteIds(@RequestBody @Valid CustomerRequestDTO customerRequestDTO) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
result = customerService.deleteIds(deleteCustomerRequestDTO); result = customerService.deleteIds(customerRequestDTO);
return result; return result;
} }
...@@ -135,15 +134,15 @@ public class CustomerController { ...@@ -135,15 +134,15 @@ public class CustomerController {
@PostMapping("/deleteCustomerListIds") @PostMapping("/deleteCustomerListIds")
@ResponseBody @ResponseBody
public ResultDTO deleteCustomerListIds(@RequestBody @Valid List<Long> ids) { public ResultDTO deleteCustomerListIds(@RequestBody @Valid CustomerRequestDTO customerRequestDTO) {
ResultDTO result = new ResultDTO(); ResultDTO result = new ResultDTO();
result = customerService.deleteCustomerListIds(ids); result = customerService.deleteCustomerListIds(customerRequestDTO);
return result; return result;
} }
@RequestMapping(value = "/searchCustomerList", method = RequestMethod.POST) @RequestMapping(value = "/searchCustomerList", method = RequestMethod.POST)
public ResponseEntity searchCustomerList(@RequestBody CampaignCustomerRequestDTO campaignCustomerRequestDTO) { public ResponseEntity searchCustomerList(@RequestBody SearchCustomerRequestDTO searchCustomerRequestDTO) {
ResultDTO result = customerService.searchCustomerList(campaignCustomerRequestDTO); ResultDTO result = customerService.searchCustomerList(searchCustomerRequestDTO);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
} }
select
a.CUSTOMER_LIST_MAPPING_ID customerListMappingId,
a.COMPANY_SITE_ID companySiteId,
a.CUSTOMER_LIST_ID customerListId,
a.CUSTOMER_ID customerId,
b.NAME name,
b.DESCRIPTION description,
b.COMPANY_NAME companyName,
b.CUSTOMER_TYPE customerType,
b.CURRENT_ADDRESS currentAddress,
c.MOBILE mobileNumber,
d.EMAIL email
from CUSTOMER_LIST_MAPPING a
join CUSTOMER b on a.CUSTOMER_ID = b.CUSTOMER_ID
left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY NULL) AS MOBILE
FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 5 GROUP BY CUSTOMER_ID) c on b.CUSTOMER_ID = c.CUSTOMER_ID
left join (SELECT CUSTOMER_ID, LISTAGG(CONTACT, ', ') WITHIN GROUP (ORDER BY NULL) AS EMAIL
FROM CUSTOMER_CONTACT WHERE CONTACT_TYPE = 2 GROUP BY CUSTOMER_ID) d on b.CUSTOMER_ID = d.CUSTOMER_ID
where 1 = 1
and COMPANY_SITE_ID = :p_company_site_id
and CUSTOMER_LIST_ID = :p_customer_list_id
...@@ -12,4 +12,5 @@ SELECT ...@@ -12,4 +12,5 @@ SELECT
DEPT_CREATE deptCreate 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 to_date(:p_date_from, 'YYYYMMDD') AND to_date(:p_date_to, 'YYYYMMDD')
AND COMPANY_SITE_ID = :p_company_site_id
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