CustomerTrainController.java 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. package lingtao.net.controller;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import javax.management.RuntimeErrorException;
  10. import javax.servlet.http.HttpSession;
  11. import org.apache.commons.io.FileUtils;
  12. import org.apache.commons.io.FilenameUtils;
  13. import org.apache.http.client.utils.DateUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RequestParam;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import com.github.pagehelper.PageHelper;
  20. import com.github.pagehelper.PageInfo;
  21. import lingtao.net.bean.CustomerTrainContent;
  22. import lingtao.net.bean.CustomerTrainKindLabel;
  23. import lingtao.net.bean.CustomerTrainProType;
  24. import lingtao.net.bean.Msg;
  25. import lingtao.net.service.CustomerTrainService;
  26. @RestController
  27. public class CustomerTrainController {
  28. @Autowired
  29. private CustomerTrainService customerTrainService;
  30. private String localPrefix = "abc\\train";
  31. private String localPath = "C:\\lingtao\\upload";
  32. private String localDomain = "http://47.114.150.226:80/erp";
  33. // 图片上传及新增
  34. @RequestMapping("/imgUpload")
  35. public Object upload(@RequestParam("file") MultipartFile file) throws Exception {
  36. if (file.isEmpty()) {
  37. return Msg.fail("文件不能为空");
  38. }
  39. // 获取文件名后缀
  40. String extension = FilenameUtils.getExtension(file.getOriginalFilename());
  41. // 获取path
  42. String path = getPath(extension, FilenameUtils.getBaseName(file.getOriginalFilename()));
  43. // 保存文件信息
  44. File newFile = new File(localPath + File.separator + path);
  45. try {
  46. FileUtils.copyInputStreamToFile(new ByteArrayInputStream(file.getBytes()), newFile);
  47. } catch (IOException e) {
  48. throw new RuntimeErrorException(null, "");
  49. }
  50. String serverPath = localDomain + "/" + path;
  51. Map<String, Object> map = new HashMap<String, Object>();
  52. Map<String, Object> map2 = new HashMap<String, Object>();
  53. map.put("code", 0); // 0表示上传成功
  54. map.put("msg", "上传成功"); // 提示消息
  55. // src返回图片上传成功后的下载路径,这里直接给绝对路径
  56. map2.put("src", serverPath);
  57. map.put("data", map2);
  58. return map;
  59. }
  60. /**
  61. *
  62. * @param prefixSelf 根据上传的接口存入自己的文件夹
  63. * @param suffix 文件的后缀
  64. * @param fileName 文件名
  65. * @return
  66. */
  67. public String getPath(String suffix, String fileName) {
  68. // 生成uuid
  69. // String uuid = UUID.randomUUID().toString().replaceAll("-", "");
  70. String path = null;
  71. // 文件路径
  72. path = DateUtils.formatDate(new Date(), "yyyyMMdd") + File.separator + fileName;
  73. path = localPrefix + File.separator + File.separator + path;
  74. return path + "." + suffix;
  75. }
  76. /* =============产品知识内容================ */
  77. /**
  78. * 查询
  79. *
  80. * @param page
  81. * @param limit
  82. * @param customerTrainContent
  83. * @return
  84. */
  85. @RequestMapping("/getCustomerTrainContents")
  86. public PageInfo<CustomerTrainContent> getCustomerTrainContents(
  87. @RequestParam(value = "page", defaultValue = "1") Integer page,
  88. @RequestParam(value = "limit", defaultValue = "10") Integer limit,
  89. CustomerTrainContent customerTrainContent) {
  90. PageHelper.startPage(page, limit);
  91. List<CustomerTrainContent> customerTrainContentList = customerTrainService
  92. .getCustomerTrainContents(customerTrainContent);
  93. PageInfo<CustomerTrainContent> pageInfo = new PageInfo<CustomerTrainContent>(customerTrainContentList);
  94. return pageInfo;
  95. }
  96. /**
  97. * 添加
  98. *
  99. */
  100. @RequestMapping("/addCustomerTrainContent")
  101. public Msg addCustomerTrainContent(CustomerTrainContent customerTrainContent, HttpSession session) {
  102. return customerTrainService.addCustomerTrainContent(customerTrainContent, session);
  103. }
  104. /**
  105. * 修改
  106. */
  107. @RequestMapping("/updateCustomerTrainContent")
  108. public Msg updateCustomerTrainContent(CustomerTrainContent customerTrainContent, HttpSession session) {
  109. return customerTrainService.updateCustomerTrainContentById(customerTrainContent, session);
  110. }
  111. /**
  112. * 修改
  113. */
  114. @RequestMapping("/updateCustomerTrainContentSort")
  115. public Msg updateById(@RequestParam(value = "id") int id, @RequestParam(value = "value") String value) {
  116. return customerTrainService.updateCustomerTrainContentSort(id, value);
  117. }
  118. /**
  119. * 删除
  120. */
  121. @RequestMapping("/deleteCustomerTrainContent")
  122. public Msg deleteCustomerTrainContent(@RequestParam("id") Integer id) {
  123. return customerTrainService.deleteCustomerTrainContentById(id);
  124. }
  125. /* =============产品种类================ */
  126. /**
  127. * 查询
  128. *
  129. * @param page
  130. * @param limit
  131. * @param customerTrainProType
  132. * @return
  133. */
  134. @RequestMapping("/getCustomerTrainProTypes")
  135. public PageInfo<CustomerTrainProType> getCustomerTrainProTypes(
  136. @RequestParam(value = "page", defaultValue = "1") Integer page,
  137. @RequestParam(value = "limit", defaultValue = "10") Integer limit,
  138. CustomerTrainProType customerTrainProType) {
  139. PageHelper.startPage(page, limit);
  140. List<CustomerTrainProType> customerTrainProTypeList = customerTrainService
  141. .getCustomerTrainProTypes(customerTrainProType);
  142. PageInfo<CustomerTrainProType> pageInfo = new PageInfo<CustomerTrainProType>(customerTrainProTypeList);
  143. return pageInfo;
  144. }
  145. /**
  146. * 添加
  147. *
  148. */
  149. @RequestMapping("/addCustomerTrainProType")
  150. public Msg addCustomerTrainProType(CustomerTrainProType customerTrainProType, HttpSession session) {
  151. return customerTrainService.addCustomerTrainProType(customerTrainProType, session);
  152. }
  153. /**
  154. * 修改
  155. */
  156. @RequestMapping("/updateCustomerTrainProType")
  157. public Msg updateCustomerTrainProType(CustomerTrainProType customerTrainProType, HttpSession session) {
  158. return customerTrainService.updateCustomerTrainProTypeById(customerTrainProType, session);
  159. }
  160. /**
  161. * 删除
  162. */
  163. @RequestMapping("/deleteCustomerTrainProType")
  164. public Msg deleteCustomerTrainProType(@RequestParam("id") Integer id) {
  165. return customerTrainService.deleteCustomerTrainProTypeById(id);
  166. }
  167. /* =============产品类型================ */
  168. /**
  169. * 查询
  170. *
  171. * @param page
  172. * @param limit
  173. * @param customerTrainKindLabel
  174. * @return
  175. */
  176. @RequestMapping("/getCustomerTrainKindLabelsByProType")
  177. public PageInfo<CustomerTrainKindLabel> getCustomerTrainKindLabelsByProType(
  178. @RequestParam(value = "page", defaultValue = "1") Integer page,
  179. @RequestParam(value = "limit", defaultValue = "10") Integer limit,
  180. @RequestParam(value = "needPage") String needPage, CustomerTrainKindLabel customerTrainKindLabel) {
  181. // 0:不要分页 1:要分页
  182. if ("1".equals(needPage))
  183. PageHelper.startPage(page, limit);
  184. List<CustomerTrainKindLabel> customerTrainKindLabelList = customerTrainService
  185. .getCustomerTrainKindLabelsByProType(customerTrainKindLabel);
  186. PageInfo<CustomerTrainKindLabel> pageInfo = new PageInfo<CustomerTrainKindLabel>(customerTrainKindLabelList);
  187. return pageInfo;
  188. }
  189. /**
  190. * 添加
  191. *
  192. */
  193. @RequestMapping("/addCustomerTrainKindLabel")
  194. public Msg addCustomerTrainKindLabel(CustomerTrainKindLabel customerTrainKindLabel, HttpSession session) {
  195. return customerTrainService.addCustomerTrainKindLabel(customerTrainKindLabel, session);
  196. }
  197. /**
  198. * 修改
  199. */
  200. @RequestMapping("/updateCustomerTrainKindLabel")
  201. public Msg updateCustomerTrainKindLabel(CustomerTrainKindLabel customerTrainKindLabel, HttpSession session) {
  202. return customerTrainService.updateCustomerTrainKindLabelById(customerTrainKindLabel, session);
  203. }
  204. /**
  205. * 删除
  206. */
  207. @RequestMapping("/deleteCustomerTrainKindLabel")
  208. public Msg deleteCustomerTrainKindLabel(@RequestParam("id") Integer id) {
  209. return customerTrainService.deleteCustomerTrainKindLabelById(id);
  210. }
  211. }