敏捷工具
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.

110 lines
3.2 KiB

2 years ago
  1. package com.whn.hellospring.controller;
  2. import com.whn.hellospring.common.StateMessage;
  3. import com.whn.hellospring.common.Status;
  4. import com.whn.hellospring.common.StatusException;
  5. import com.whn.hellospring.model.CustomerDO;
  6. import com.whn.hellospring.request.CustomerDetailRequest;
  7. import com.whn.hellospring.request.CustomerLoginRequest;
  8. import com.whn.hellospring.request.DeleteCustomerRequest;
  9. import com.whn.hellospring.service.CustomerService;
  10. import org.hibernate.annotations.common.util.impl.Log;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import javax.validation.Valid;
  14. import java.util.List;
  15. import java.util.logging.Logger;
  16. @RestController //处理http请求,默认返回json格式数据
  17. @RequestMapping(value = "/customer") //配置映射在/customer
  18. public class CustomerController {
  19. @Autowired
  20. CustomerService service;
  21. /**
  22. * 创建客户
  23. */
  24. @PostMapping(value = "/create")
  25. public String postCustomer(@Valid @RequestBody CustomerDO customerDO) {
  26. service.createCustomer(customerDO);
  27. return "success";
  28. }
  29. /**
  30. * 编辑客户
  31. */
  32. @PostMapping(value = "/update")
  33. public String updateCustomer(@Valid @RequestBody CustomerDO customerDO) {
  34. service.updateCustomer(customerDO);
  35. return "success";
  36. }
  37. /**
  38. * 获取顾客列表
  39. */
  40. @GetMapping(value = "/list")
  41. public List<CustomerDO> getCustomerList() {
  42. List<CustomerDO> customerList = service.getCustomerList();
  43. return customerList;
  44. }
  45. /**
  46. * 删除顾客1
  47. */
  48. @DeleteMapping(value = "/delete/{id}")
  49. public String deleteCustomer(@PathVariable Long id) {
  50. if (service.deleteCustomer(id) == 1) {
  51. return "success";
  52. } else {
  53. return "error";
  54. }
  55. }
  56. /**
  57. * 删除顾客2
  58. */
  59. @PostMapping(value = "/delete")
  60. public String postDeleteCustomer(@RequestBody DeleteCustomerRequest request) {
  61. if (service.deleteCustomer(request.getId()) == 1) {
  62. return "success";
  63. } else {
  64. return "error";
  65. }
  66. }
  67. /**
  68. * 客户详情
  69. */
  70. @PostMapping(value = "/detail")
  71. public Status detail(@RequestBody CustomerDetailRequest request) {
  72. try {
  73. CustomerDO customerDetail = service.getCustomerDetail(request.getCustomer_id());
  74. return new Status(StateMessage.SUCCESS, customerDetail);
  75. } catch (Exception e) {
  76. return new Status(StateMessage.UN_KNOW_REASON);
  77. }
  78. }
  79. /**
  80. * 客户登录
  81. */
  82. @PostMapping(value = "/login")
  83. public Status login(@RequestBody CustomerLoginRequest request) {
  84. try {
  85. String phone = request.getPhone();
  86. String password = request.getPassword();
  87. String loginMsg = service.login(phone, password);
  88. Status status = new Status(StateMessage.SUCCESS, loginMsg);
  89. return status;
  90. } catch (Exception e) {
  91. return new Status(StateMessage.UN_KNOW_REASON);
  92. }
  93. }
  94. @GetMapping(value = "/test")
  95. public String test() {
  96. return "hello";
  97. }
  98. }