Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

100 wiersze
3.7 KiB

  1. package com.simple.controller;
  2. import com.github.pagehelper.PageInfo;
  3. import com.simple.common.Result;
  4. import com.simple.common.ResultData;
  5. import com.simple.domain.po.WxMsg;
  6. import com.simple.service.WxMsgService;
  7. import com.simple.utils.Constant;
  8. import io.swagger.annotations.ApiImplicitParam;
  9. import io.swagger.annotations.ApiImplicitParams;
  10. import io.swagger.annotations.ApiOperation;
  11. import org.apache.commons.io.IOUtils;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.*;
  16. import org.springframework.web.multipart.MultipartFile;
  17. import java.io.File;
  18. import java.io.FileOutputStream;
  19. import java.util.UUID;
  20. @RestController
  21. @RequestMapping("wxMsg")
  22. public class WxMsgController extends BaseController {
  23. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  24. @Autowired
  25. private WxMsgService wxMsgService;
  26. @ApiOperation("分页列表接口")
  27. @GetMapping("list")
  28. @ApiImplicitParams({
  29. @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
  30. @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)})
  31. public ResultData list(@ModelAttribute WxMsg wxMsg, Integer pageNum, Integer pageSize) {
  32. if (null == wxMsg) wxMsg = new WxMsg();
  33. wxMsg.setTenantId(getTenantId());
  34. final PageInfo<WxMsg> page = wxMsgService.listAsPage(wxMsg, pageNum, pageSize);
  35. return new ResultData(page);
  36. }
  37. @ApiOperation("新增接口")
  38. @PostMapping("add")
  39. public ResultData add(@RequestBody WxMsg wxMsg) {
  40. //Assert.notNull(wxMsg.getName(), "角色名不能为空");
  41. //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名");
  42. wxMsg.setTenantId(getTenantId());
  43. wxMsgService.saveOrUpdate(wxMsg);
  44. return new ResultData();
  45. }
  46. @ApiOperation("根据id更新接口")
  47. @PostMapping("update")
  48. public ResultData update(@RequestBody WxMsg wxMsg) {
  49. wxMsgService.saveOrUpdate(wxMsg);
  50. return new ResultData();
  51. }
  52. @ApiOperation("根据id删除接口")
  53. @GetMapping("/del")
  54. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  55. public ResultData delete(Long id) {
  56. wxMsgService.deleteById(id);
  57. return new ResultData(Result.SUCCESS, "删除成功", null);
  58. }
  59. @ApiOperation("根据id查询接口")
  60. @GetMapping("/findById")
  61. @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
  62. public ResultData findById(Long id) {
  63. return new ResultData(Result.SUCCESS, "查询成功", wxMsgService.getById(id));
  64. }
  65. @RequestMapping("/excleupload")
  66. public ResultData excleupload(@RequestParam("file") MultipartFile file) {
  67. if (file.isEmpty()) {
  68. return new ResultData(Result.SUCCESS, "上传文件不能为空");
  69. }
  70. String filename = UUID.randomUUID() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
  71. File path = new File(Constant.fileDirectory);
  72. if (!path.exists()) {
  73. path.mkdirs();
  74. }
  75. String filepath = Constant.fileDirectory + File.separator + filename;
  76. try {
  77. FileOutputStream out = new FileOutputStream(new File(filepath));
  78. IOUtils.write(file.getBytes(), out);
  79. IOUtils.closeQuietly(out);
  80. } catch (Exception e) {
  81. return new ResultData(Result.ERROR, "上传失败");
  82. }
  83. return new ResultData(Result.SUCCESS, "上传成功", filepath);
  84. }
  85. }