敏捷工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.8 KiB

2 years ago
  1. package com.whn.hellospring.service;
  2. import com.whn.hellospring.model.CustomerDO;
  3. import com.whn.hellospring.repository.CustomerRepository;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import java.util.List;
  8. @Slf4j
  9. @Service
  10. public class CustomerService {
  11. @Autowired
  12. CustomerRepository customerRepository;
  13. /**
  14. * 获取一个顾客详情
  15. */
  16. public CustomerDO getCustomerDetail(long id){
  17. return customerRepository.getOne(id);
  18. }
  19. /**
  20. * 新增一个顾客
  21. */
  22. public CustomerDO createCustomer(CustomerDO customerDO) {
  23. customerRepository.save(customerDO);
  24. return customerDO;
  25. }
  26. /**
  27. * 删除一个顾客
  28. */
  29. public int deleteCustomer(Long id) {
  30. customerRepository.deleteById(id);
  31. return 1;
  32. }
  33. /**
  34. * 编辑客户
  35. */
  36. public CustomerDO updateCustomer(CustomerDO customerDO) {
  37. customerRepository.save(customerDO);
  38. return customerDO;
  39. }
  40. /**
  41. * 获取顾客列表
  42. */
  43. public List<CustomerDO> getCustomerList() {
  44. return customerRepository.findAll();
  45. }
  46. /**
  47. * 登录
  48. */
  49. public String login(String phone, String password) {
  50. //判断是否存在该手机号
  51. List<CustomerDO> list = customerRepository.isHaveThisPhone(phone);
  52. if (list == null || list.size() == 0) {
  53. return "该手机号不存在";
  54. } else {
  55. String msg = "请检查密码";
  56. for (CustomerDO customerDo : list) {
  57. if (password.equals(customerDo.getPass_word())) {
  58. msg = customerDo.getId().toString();
  59. break;
  60. }
  61. }
  62. return msg;
  63. }
  64. }
  65. }