Commit 5cbcc652 authored by Phạm Duy Phi's avatar Phạm Duy Phi

phipd commit: commit

parent 00b43f0b
...@@ -6,15 +6,13 @@ import com.viettel.campaign.web.dto.ResultDTO; ...@@ -6,15 +6,13 @@ import com.viettel.campaign.web.dto.ResultDTO;
import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.SearchCustomerRequestDTO;
import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO; import com.viettel.campaign.web.dto.request_dto.CustomerRequestDTO;
import java.util.Map;
public interface CustomerService { public interface CustomerService {
ResultDTO listAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId); ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId);
ResultDTO getCustomerId(Long customerId); ResultDTO getCustomerId(Long customerId);
Map listCustByName(int page, int pageSize, String sort, String name); ResultDTO searchAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId, String name, String mobileNumber, String email);
ResultDTO createCustomer(CustomerDTO customerDTO); ResultDTO createCustomer(CustomerDTO customerDTO);
...@@ -24,7 +22,7 @@ public interface CustomerService { ...@@ -24,7 +22,7 @@ public interface CustomerService {
// ------------ customer list ------------ // // ------------ customer list ------------ //
Map getCustomerList(int page, int pageSize, String sort); ResultDTO getAllCustomerList(int page, int pageSize, String sort, Long companySiteId);
ResultDTO createCustomerList(CustomerListDTO customerListDTO); ResultDTO createCustomerList(CustomerListDTO customerListDTO);
...@@ -34,13 +32,9 @@ public interface CustomerService { ...@@ -34,13 +32,9 @@ public interface CustomerService {
ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO); ResultDTO deleteCustomerListIds(CustomerRequestDTO customerRequestDTO);
<<<<<<< HEAD
ResultDTO searchCustomerList(SearchCustomerRequestDTO searchCustomerRequestDTO); ResultDTO searchCustomerList(SearchCustomerRequestDTO searchCustomerRequestDTO);
=======
ResultDTO searchCustomerList(CampaignCustomerRequestDTO campaignCustomerRequestDTO);
// ------------ customer contact ------------ // // ------------ customer contact ------------ //
ResultDTO getCustomerContact(Long customerId, Short contactType, String contact); ResultDTO getCustomerContact(Long customerId, Short contactType, String contact);
>>>>>>> 34ea2d6ca2abb80539da3dd29437f08fed559e93
} }
...@@ -56,17 +56,7 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -56,17 +56,7 @@ public class CustomerServiceImpl implements CustomerService {
CustomerListMappingRepository customerListMappingRepository; CustomerListMappingRepository customerListMappingRepository;
@Override @Override
public ResultDTO listAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId) { public ResultDTO getAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId) {
// Map result = new HashMap();
// 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(); ResultDTO resultDTO = new ResultDTO();
SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
...@@ -83,6 +73,8 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -83,6 +73,8 @@ public class CustomerServiceImpl implements CustomerService {
StringBuilder sqlStrBuilder = new StringBuilder(); StringBuilder sqlStrBuilder = new StringBuilder();
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-customer-detail-by-params")); sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-customer-detail-by-params"));
sqlStrBuilder.append(" ORDER BY name DESC");
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);
...@@ -102,19 +94,19 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -102,19 +94,19 @@ public class CustomerServiceImpl implements CustomerService {
query.setResultTransformer(Transformers.aliasToBean(CustomerCustomDTO.class)); query.setResultTransformer(Transformers.aliasToBean(CustomerCustomDTO.class));
int count = 0; int count = 0;
List<CustomerListDTO> dtoList = query.list(); List<CustomerCustomDTO> dtoList = query.list();
if (dtoList.size() > 0) { if (dtoList.size() > 0) {
count = query.list().size(); 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));
List<CustomerListDTO> data = query.list(); Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort)));
Page<CustomerListDTO> dataPage = new PageImpl<>(data, pageable, count); if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<CustomerCustomDTO> data = query.list();
Page<CustomerCustomDTO> 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);
...@@ -147,17 +139,71 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -147,17 +139,71 @@ public class CustomerServiceImpl implements CustomerService {
} }
@Override @Override
public Map listCustByName(int page, int pageSize, String sort, String name) { public ResultDTO searchAllCustomer(int page, int pageSize, String sort, long customerListId, long companySiteId, String name, String mobileNumber, String email) {
Map result = new HashMap(); ResultDTO resultDTO = new ResultDTO();
List<Customer> lst = new ArrayList<>(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort)); Session session = sessionFactory.openSession();
lst = customerRepository.findByName(name, pageable); session.beginTransaction();
result.put("totalItem", lst.size()); if (DataUtil.isNullOrZero(companySiteId)) {
result.put("customers", lst); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return resultDTO;
}
return result; try {
StringBuilder sqlStrBuilder = new StringBuilder();
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "campaign-customer-detail-by-params"));
sqlStrBuilder.append(" AND ");
sqlStrBuilder.append(" ORDER BY name DESC");
sqlStrBuilder.append(" ORDER BY name DESC");
sqlStrBuilder.append(" ORDER BY name DESC");
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<CustomerCustomDTO> dtoList = query.list();
if (dtoList.size() > 0) {
count = query.list().size();
}
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort)));
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<CustomerCustomDTO> data = query.list();
Page<CustomerCustomDTO> 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 resultDTO;
} }
@Override @Override
...@@ -255,17 +301,67 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -255,17 +301,67 @@ public class CustomerServiceImpl implements CustomerService {
// ------------- customer list ----------------- // // ------------- customer list ----------------- //
@Override @Override
public Map getCustomerList(int page, int pageSize, String sort) { public ResultDTO getAllCustomerList(int page, int pageSize, String sort, Long companySiteId) {
Map result = new HashMap(); ResultDTO resultDTO = new ResultDTO();
List<CustomerList> list = new ArrayList<>(); SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Pageable pageable = PageRequest.of(page, pageSize, Sort.by(sort)); Session session = sessionFactory.openSession();
Page<CustomerList> pc = customerListRepository.findAll(pageable); session.beginTransaction();
result.put("totalItem", pc.getTotalElements()); if (DataUtil.isNullOrZero(companySiteId)) {
result.put("customerList", pc.iterator()); resultDTO.setErrorCode(Constants.ApiErrorCode.ERROR);
resultDTO.setDescription(Constants.ApiErrorDesc.ERROR);
return resultDTO;
}
return result; try {
StringBuilder sqlStrBuilder = new StringBuilder();
sqlStrBuilder.append(SQLBuilder.getSqlQueryById(SQLBuilder.SQL_MODULE_CAMPAIGN_MNG, "search-campaign-customer-by-params"));
sqlStrBuilder.append(" ORDER BY CREATE_AT DESC");
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
query.setParameter("p_company_site_id", companySiteId);
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 = PageRequest.of(page, pageSize, Sort.by(Sort.Order.desc(sort)));
if (pageable != null) {
query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
query.setMaxResults(pageable.getPageSize());
}
List<CustomerListDTO> data = query.list();
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 resultDTO;
} }
@Override @Override
...@@ -400,6 +496,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -400,6 +496,9 @@ 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"));
sqlStrBuilder.append(" AND CREATE_AT BETWEEN to_date(:p_date_from, 'YYYYMMDD') AND to_date(:p_date_to, 'YYYYMMDD')");
if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.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");
} }
...@@ -409,9 +508,9 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -409,9 +508,9 @@ public class CustomerServiceImpl implements CustomerService {
SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString()); SQLQuery query = session.createSQLQuery(sqlStrBuilder.toString());
query.setParameter("p_company_site_id", searchCustomerRequestDTO.getCompanySiteId());
query.setParameter("p_date_from", searchCustomerRequestDTO.getConvertedDateFrom()); query.setParameter("p_date_from", searchCustomerRequestDTO.getConvertedDateFrom());
query.setParameter("p_date_to", searchCustomerRequestDTO.getConvertedDateTo()); query.setParameter("p_date_to", searchCustomerRequestDTO.getConvertedDateTo());
query.setParameter("p_company_site_id", searchCustomerRequestDTO.getCompanySiteId());
if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCustomerListCode())) { if (!DataUtil.isNullOrEmpty(searchCustomerRequestDTO.getCustomerListCode())) {
query.setParameter("p_list_code", "%" + query.setParameter("p_list_code", "%" +
...@@ -449,12 +548,12 @@ public class CustomerServiceImpl implements CustomerService { ...@@ -449,12 +548,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(searchCustomerRequestDTO);
// if (pageable != null) {
// query.setFirstResult(pageable.getPageNumber() * pageable.getPageSize());
// query.setMaxResults(pageable.getPageSize());
// }
Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort())); Pageable pageable = PageRequest.of(searchCustomerRequestDTO.getPage(), searchCustomerRequestDTO.getPageSize(), Sort.by(searchCustomerRequestDTO.getSort()));
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);
......
...@@ -29,7 +29,7 @@ public class CustomerController { ...@@ -29,7 +29,7 @@ public class CustomerController {
@GetMapping("/findAll") @GetMapping("/findAll")
@ResponseBody @ResponseBody
public ResponseEntity findAllCustomer(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam("customerListId") long customerListId, @RequestParam("companySiteId") long companySiteId) { public ResponseEntity findAllCustomer(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam("customerListId") long customerListId, @RequestParam("companySiteId") long companySiteId) {
ResultDTO result = customerService.listAllCustomer(page, pageSize, sort, customerListId, companySiteId); ResultDTO result = customerService.getAllCustomer(page, pageSize, sort, customerListId, companySiteId);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
...@@ -40,10 +40,10 @@ public class CustomerController { ...@@ -40,10 +40,10 @@ public class CustomerController {
return new ResponseEntity(result, HttpStatus.OK); return new ResponseEntity(result, HttpStatus.OK);
} }
@GetMapping("/findCustomerByName") @GetMapping("/searchAllCustomerByParams")
@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("customerListId") Long customerListId, @RequestParam("companySiteId") Long companySiteId, @RequestParam("name") String name, @RequestParam("mobileNumber") String mobileNumber, @RequestParam("email") String email) {
Map result = customerService.listCustByName(page, pageSize, sort, name); ResultDTO result = customerService.searchAllCustomer(page, pageSize, sort, customerListId, companySiteId, name, mobileNumber, email);
return new ResponseEntity(result, HttpStatus.OK); return new ResponseEntity(result, HttpStatus.OK);
} }
...@@ -87,8 +87,8 @@ public class CustomerController { ...@@ -87,8 +87,8 @@ public class CustomerController {
@GetMapping("/findAlls") @GetMapping("/findAlls")
@ResponseBody @ResponseBody
public ResponseEntity findAllCustomerList(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort) { public ResponseEntity findAllCustomerList(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam("sort") String sort, @RequestParam("companySiteId") Long companySiteId) {
Map result = customerService.getCustomerList(page, pageSize, sort); ResultDTO result = customerService.getAllCustomerList(page, pageSize, sort, companySiteId);
return new ResponseEntity<>(result, HttpStatus.OK); return new ResponseEntity<>(result, HttpStatus.OK);
} }
......
...@@ -12,5 +12,4 @@ SELECT ...@@ -12,5 +12,4 @@ SELECT
DEPT_CREATE deptCreate DEPT_CREATE deptCreate
FROM CUSTOMER_LIST FROM CUSTOMER_LIST
WHERE 1 = 1 WHERE 1 = 1
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 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