CustomerServiceImpl.java 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.loan.system.service.Impl;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.loan.system.domain.entity.Customer;
  4. import com.loan.system.domain.vo.CustomerVO;
  5. import com.loan.system.repository.CustomerRepository;
  6. import com.loan.system.service.CustomerService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.data.domain.Page;
  9. import org.springframework.data.domain.PageRequest;
  10. import org.springframework.data.domain.Pageable;
  11. import org.springframework.stereotype.Service;
  12. import java.util.List;
  13. @Service
  14. public class CustomerServiceImpl implements CustomerService {
  15. @Autowired
  16. private CustomerRepository customerRepository;
  17. @Override
  18. public Customer addCustomer(Customer customer) {
  19. // 可以在这里添加业务逻辑,如校验等
  20. return customerRepository.save(customer);
  21. }
  22. @Override
  23. public void updateMarriedStatusById(Long customerId, String marriedStatus) {
  24. customerRepository.updateMarriedStatusById(customerId,marriedStatus);
  25. }
  26. @Override
  27. public CustomerVO findByCustomerIdAndIsDelete(Long customerId, Boolean isDelete) {
  28. return BeanUtil.copyProperties(customerRepository.findByCustomerId(customerId,isDelete),CustomerVO.class);
  29. }
  30. @Override
  31. public List<CustomerVO> getAllCustomers(Integer pageNum,Integer pageSize,boolean isDelete) {
  32. Pageable pageable = PageRequest.of(pageNum, pageSize);
  33. Page<Customer> customerPage = customerRepository.findByIsDelete(isDelete,pageable);
  34. List<Customer> customerList = customerPage.getContent();
  35. return BeanUtil.copyToList(customerList,CustomerVO.class);
  36. }
  37. @Override
  38. public List<CustomerVO> getCustomerByKey(String key, boolean isDelete,Integer pageNum, Integer pageSize) {
  39. Pageable pageable = PageRequest.of(pageNum, pageSize);
  40. key ="%"+key+"%";
  41. Page<Customer> customerPage=customerRepository.findByKey(key,isDelete,pageable);
  42. return BeanUtil.copyToList(customerPage.getContent(),CustomerVO.class);
  43. }
  44. @Override
  45. public CustomerVO getCustomerByMobile(String tel) {
  46. return BeanUtil.copyProperties(customerRepository.findByMobile(tel, false),CustomerVO.class);
  47. }
  48. @Override
  49. public boolean existsBymobileAndIsDelete(String phoneNumber){
  50. return customerRepository.existsByMobileAndIsDelete(phoneNumber,false);
  51. }
  52. @Override
  53. public Customer findBymobileAndIsDelete(String phoneNumber){
  54. return customerRepository.findByMobile(phoneNumber,false);
  55. }
  56. @Override
  57. public Customer findByIdAndIsDelete(Long id){
  58. return customerRepository.findByIdAndIsDelete(id,false);
  59. }
  60. @Override
  61. public boolean existsByIdAndIsDelete(Long customerId) {
  62. return customerRepository.existsByIdAndIsDelete(customerId,false);
  63. }
  64. }