CustomerDataControlle.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package lingtao.net.controller;
  2. import java.util.List;
  3. import org.apache.shiro.SecurityUtils;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.RequestMapping;
  6. import org.springframework.web.bind.annotation.RequestParam;
  7. import org.springframework.web.bind.annotation.RestController;
  8. import com.github.pagehelper.PageHelper;
  9. import com.github.pagehelper.PageInfo;
  10. import lingtao.net.bean.CustomerData;
  11. import lingtao.net.bean.Msg;
  12. import lingtao.net.bean.SysUser;
  13. import lingtao.net.service.CustomerDataService;
  14. @RestController
  15. public class CustomerDataControlle {
  16. @Autowired
  17. private CustomerDataService customerDataService;
  18. @RequestMapping("/getCustomerDatas")
  19. public Msg getCustomerDatas(@RequestParam(value = "page", defaultValue = "1") Integer page,
  20. @RequestParam(value = "limit", defaultValue = "10") Integer limit, CustomerData customerData) {
  21. PageHelper.startPage(page, limit);
  22. List<CustomerData> customerDatalist = customerDataService.getCustomerDatas(customerData);
  23. PageInfo<CustomerData> pageInfo = new PageInfo<CustomerData>(customerDatalist);
  24. return Msg.success().add("list", pageInfo);
  25. }
  26. /**
  27. * 添加数据
  28. *
  29. * @throws Exception
  30. */
  31. @RequestMapping("/addCustomerData")
  32. public Msg addCustomerData(CustomerData customerData) throws Exception {
  33. // 把字符串转为日期格式
  34. customerDataService.addCustomerData(customerData);
  35. return Msg.success();
  36. }
  37. /**
  38. * 修改数据
  39. */
  40. @RequestMapping("/updateCustomerData")
  41. public Msg updateCustomerData(CustomerData customerData) {
  42. customerDataService.updateCustomerDataById(customerData);
  43. return Msg.success();
  44. }
  45. /**
  46. * 删除数据
  47. */
  48. @RequestMapping("/deleteCustomerData")
  49. public Msg deleteCustomerData(@RequestParam("id") Integer id) {
  50. customerDataService.deleteCustomerDataById(id);
  51. return Msg.success();
  52. }
  53. /**
  54. * 店长修改说明数据
  55. *
  56. * @param customerData
  57. */
  58. @RequestMapping("/updateRemarkById")
  59. public Msg updateRemarkById(@RequestParam(value = "id") int id, @RequestParam(value = "field") String field,
  60. @RequestParam(value = "value") String value) {
  61. // 超管、组长身份才允许修改comment
  62. boolean flag = isSuperOrManager();
  63. if (!flag) {
  64. return Msg.fail();
  65. }
  66. customerDataService.updateRemarkById(id, field, value);
  67. return Msg.success();
  68. }
  69. /**
  70. * 修改完成状态
  71. *
  72. * @param id
  73. * @return
  74. */
  75. @RequestMapping("/changeIsBuy")
  76. public Msg changeIsBuy(@RequestParam(value = "id") Integer id, @RequestParam(value = "username") String username) {
  77. // 超管、组长身份才允许修改【成交状态】
  78. boolean flag = isSuperOrManager();
  79. if (!flag) {
  80. return Msg.fail();
  81. }
  82. return customerDataService.changeIsBuy(id);
  83. // 只有自己创建的数据才能更改【完成状态】
  84. /*
  85. * if (username.equals(user.getUsername())) { }
  86. */
  87. // return Msg.fail();
  88. }
  89. // 是否有超管或者组长身份
  90. public boolean isSuperOrManager() {
  91. SysUser user = (SysUser) SecurityUtils.getSubject().getPrincipal();
  92. String role = user.getRole();
  93. boolean flag = false;
  94. if (role.contains(",")) {
  95. String[] split = role.split(",");
  96. for (int i = 0; i < split.length; i++) {
  97. if ("1011".equals(split[i]) || "1".equals(split[i])) {
  98. flag = true;
  99. break;
  100. }
  101. }
  102. } else {
  103. if ("1011".equals(role) || "1".equals(role)) {
  104. flag = true;
  105. }
  106. }
  107. return flag;
  108. }
  109. // 获取摘要
  110. @RequestMapping("/getProductExplain")
  111. public List<String> getProductExplain(@RequestParam("productExplain") String productExplain) {
  112. List<String> name = customerDataService.getProductExplain(productExplain);
  113. return name;
  114. }
  115. }