1
0

CustomerServiceController.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. package com.izouma.awesomeadmin.web;
  2. import java.util.*;
  3. import com.izouma.awesomeadmin.util.ExportExcelUtil;
  4. import com.izouma.awesomeadmin.util.PropertiesFileLoader;
  5. import io.rong.RongCloud;
  6. import io.rong.models.CheckOnlineResult;
  7. import org.apache.commons.lang.StringUtils;
  8. import org.apache.shiro.authz.annotation.RequiresAuthentication;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Controller;
  11. import org.springframework.web.bind.annotation.*;
  12. import com.izouma.awesomeadmin.constant.AppConstant;
  13. import com.izouma.awesomeadmin.dto.Page;
  14. import com.izouma.awesomeadmin.dto.Result;
  15. import com.izouma.awesomeadmin.model.CustomerService;
  16. import com.izouma.awesomeadmin.service.CustomerServiceService;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. /**
  20. * controller类
  21. */
  22. @Controller
  23. @RequestMapping("/customerService")
  24. public class CustomerServiceController {
  25. @Autowired
  26. private CustomerServiceService customerServiceService;
  27. private RongCloud rongCloud = RongCloud.getInstance(PropertiesFileLoader.getProperties("rongyunappkey"), PropertiesFileLoader.getProperties("rongyunappsecret"));
  28. /**
  29. * <p>获取全部记录。</p>
  30. */
  31. @RequiresAuthentication
  32. @RequestMapping(value = "/all", method = RequestMethod.GET)
  33. @ResponseBody
  34. public Result all(CustomerService record) {
  35. List<CustomerService> pp = customerServiceService.getCustomerServiceList(record);
  36. return new Result(true, pp);
  37. }
  38. /**
  39. * <p>根据Id。</p>
  40. */
  41. @RequestMapping(value = "/getCustomerService", method = RequestMethod.GET)
  42. @ResponseBody
  43. public Result getCustomerService(@RequestParam(required = false, value = "id") String id) {
  44. CustomerService data = customerServiceService.getCustomerServiceById(id);
  45. return new Result(true, data);
  46. }
  47. /**
  48. * <p>根据条件获取。</p>
  49. */
  50. @RequestMapping(value = "/getOne", method = RequestMethod.GET)
  51. @ResponseBody
  52. public Result getOne(CustomerService record) {
  53. CustomerService data = customerServiceService.getCustomerService(record);
  54. return new Result(true, data);
  55. }
  56. /**
  57. * <p>分页查询。</p>
  58. */
  59. @RequestMapping(value = "/page", method = RequestMethod.GET)
  60. @ResponseBody
  61. public Result page(Page page, CustomerService record) {
  62. Map<String, Object> result = new HashMap<>();
  63. List<CustomerService> pp = customerServiceService.getCustomerServiceByPage(page, record);
  64. result.put(AppConstant.PAGE, page);
  65. result.put("pp", pp);
  66. return new Result(true, result);
  67. }
  68. /**
  69. * <p>保存。</p>
  70. */
  71. @RequestMapping(value = "/save", method = RequestMethod.POST)
  72. @ResponseBody
  73. public Result save(CustomerService record) {
  74. boolean num = customerServiceService.createCustomerService(record);
  75. if (num) {
  76. return new Result(true, record.getId());
  77. }
  78. return new Result(false, "保存异常");
  79. }
  80. /**
  81. * <p>更新信息。</p>
  82. */
  83. @RequestMapping(value = "/update", method = RequestMethod.POST)
  84. @ResponseBody
  85. public Result updateCustomerService(CustomerService record) {
  86. boolean num = customerServiceService.updateCustomerService(record);
  87. if (num) {
  88. return new Result(true, "保存成功");
  89. }
  90. return new Result(false, "保存异常");
  91. }
  92. /**
  93. * <p>删除。</p>
  94. */
  95. @RequestMapping(value = "/del", method = RequestMethod.POST)
  96. @ResponseBody
  97. public Result deleteCustomerService(CustomerService record) {
  98. boolean num = customerServiceService.deleteCustomerService(record);
  99. if (num) {
  100. return new Result(true, "删除成功");
  101. }
  102. return new Result(false, "删除异常");
  103. }
  104. /**
  105. * 导出Excel
  106. *
  107. * @param request
  108. * @param response
  109. * @param record
  110. * @throws Exception
  111. */
  112. @RequestMapping(value = "/exportExcel", method = RequestMethod.GET)
  113. @ResponseBody
  114. public void exportExcel(HttpServletRequest request, HttpServletResponse response, CustomerService record) throws Exception {
  115. List<CustomerService> customerServices = customerServiceService.getCustomerServiceList(record);
  116. String sheetName = "customer_service";
  117. String titleName = "店铺客服数据表";
  118. String fileName = "店铺客服表";
  119. int columnNumber = 14;
  120. int[] columnWidth = {20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20};
  121. String[] columnName = {"", "删除标识", "更新时间", "更新人", "创建时间", "创建人", "店铺", "客服名", "密码", "登录名", "头像", "可用标识", "状态", "登录时间"};
  122. String[][] dataList = new String[customerServices.size()][14];
  123. for (int i = 0; i < customerServices.size(); i++) {
  124. dataList[i][0] = String.valueOf(customerServices.get(i).getId());
  125. dataList[i][1] = String.valueOf(customerServices.get(i).getDelFlag());
  126. dataList[i][2] = String.valueOf(customerServices.get(i).getUpdateTime());
  127. dataList[i][3] = String.valueOf(customerServices.get(i).getUpdateUser());
  128. dataList[i][4] = String.valueOf(customerServices.get(i).getCreateTime());
  129. dataList[i][5] = String.valueOf(customerServices.get(i).getCreateUser());
  130. dataList[i][6] = String.valueOf(customerServices.get(i).getStoreId());
  131. dataList[i][7] = String.valueOf(customerServices.get(i).getServiceName());
  132. dataList[i][8] = String.valueOf(customerServices.get(i).getPassword());
  133. dataList[i][9] = String.valueOf(customerServices.get(i).getUsername());
  134. dataList[i][10] = String.valueOf(customerServices.get(i).getIcon());
  135. dataList[i][11] = String.valueOf(customerServices.get(i).getUseFlag());
  136. dataList[i][12] = String.valueOf(customerServices.get(i).getStatusFlag());
  137. dataList[i][13] = String.valueOf(customerServices.get(i).getLoginTime());
  138. }
  139. ExportExcelUtil.ExportWithResponse(sheetName, titleName, fileName,
  140. columnNumber, columnWidth, columnName, dataList, response);
  141. }
  142. @RequestMapping(value = "/login", method = RequestMethod.POST)
  143. @ResponseBody
  144. public Result login(HttpServletRequest request,
  145. @RequestParam(required = true, value = "username") String username, @RequestParam(required = true, value = "password") String password) {
  146. CustomerService record = new CustomerService();
  147. record.setUsername(username);
  148. record.setPassword(password);
  149. record = customerServiceService.getCustomerService(record);
  150. if (record != null) {
  151. request.getSession(true).setAttribute("customerServiceName", username);
  152. CustomerService update = new CustomerService();
  153. update.setId(record.getId());
  154. update.setLoginTime(new Date());
  155. customerServiceService.updateCustomerService(update);
  156. return new Result(true, record);
  157. }
  158. return new Result(false, "用户名或密码错误");
  159. }
  160. /**
  161. * 获取最近登录客服
  162. *
  163. * @param record
  164. * @return
  165. */
  166. @RequestMapping(value = "/recently", method = RequestMethod.GET)
  167. @ResponseBody
  168. public Result recently(CustomerService record) {
  169. List<CustomerService> pp = customerServiceService.getRecentlyLoginList(record);
  170. for (CustomerService customerService : pp) {
  171. try {
  172. CheckOnlineResult checkOnlineResult = rongCloud.user.checkOnline(customerService.getUsername());
  173. customerService.setCheckOnlineResult(checkOnlineResult);
  174. } catch (Exception e) {
  175. e.printStackTrace();
  176. }
  177. }
  178. return new Result(true, pp);
  179. }
  180. }