TCommonfileController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package com.ruoyi.project.common.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.ruoyi.common.thread.TaskThread;
  4. import com.ruoyi.common.utils.file.FileUploadUtils;
  5. import com.ruoyi.common.utils.poi.ExcelUtil;
  6. import com.ruoyi.framework.aspectj.lang.annotation.Log;
  7. import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
  8. import com.ruoyi.framework.config.RuoYiConfig;
  9. import com.ruoyi.framework.web.controller.BaseController;
  10. import com.ruoyi.framework.web.domain.AjaxResult;
  11. import com.ruoyi.framework.web.page.TableDataInfo;
  12. import com.ruoyi.project.common.domain.TCommonfile;
  13. import com.ruoyi.project.common.service.ITCommonfileService;
  14. import com.ruoyi.project.monitor.domain.SysJob;
  15. import com.ruoyi.project.monitor.service.ISysJobService;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.*;
  18. import org.springframework.web.multipart.MultipartFile;
  19. import java.io.IOException;
  20. import java.time.LocalDate;
  21. import java.util.List;
  22. /**
  23. * 通用附件Controller
  24. *
  25. * @author ruoyi
  26. * @date 2020-12-11
  27. */
  28. @RestController
  29. @RequestMapping("/common/commonfile")
  30. public class TCommonfileController extends BaseController
  31. {
  32. @Autowired
  33. private ITCommonfileService tCommonfileService;
  34. @Autowired
  35. private ISysJobService jobService;
  36. /**
  37. * 通用附件上传
  38. */
  39. @Log(title = "通用附件上传", businessType = BusinessType.UPDATE)
  40. @PostMapping("/uploadFile")
  41. public AjaxResult uploadFile(@RequestParam("file") MultipartFile file,String pType,String pId,@RequestParam(value = "pValue",required = false)String pValue) throws IOException
  42. {
  43. if (!file.isEmpty())
  44. {
  45. // 获取当前日期
  46. LocalDate currentDate = LocalDate.now();
  47. // 获取年份
  48. int year = currentDate.getYear();
  49. // 获取月份
  50. int month = currentDate.getMonthValue();
  51. String url = FileUploadUtils.upload(RuoYiConfig.getFilePath("/"+ pType + "/" + year), file);
  52. long size = file.getSize()/1024;
  53. TCommonfile tCommonfile = new TCommonfile();
  54. tCommonfile.setFileUrl(url);
  55. tCommonfile.setFileName(file.getOriginalFilename());
  56. tCommonfile.setCreaterCode(String.valueOf(getUserId()));
  57. tCommonfile.setpId(Long.parseLong(pId));
  58. tCommonfile.setpType(pType);
  59. tCommonfile.setpValue(pValue);
  60. tCommonfile.setFileSize(String.valueOf(size));
  61. tCommonfileService.insertTCommonfile(tCommonfile);
  62. return AjaxResult.success();
  63. }
  64. return AjaxResult.error("上传失败,请联系管理员");
  65. }
  66. /**
  67. * 查询通用附件列表
  68. */
  69. @GetMapping("/list")
  70. public TableDataInfo list(TCommonfile tCommonfile)
  71. {
  72. startPage();
  73. List<TCommonfile> list = tCommonfileService.selectTCommonfileList(tCommonfile);
  74. return getDataTable(list);
  75. }
  76. /**
  77. * 查询通用附件列表(pType模糊查询)
  78. */
  79. @GetMapping("/allFileListFuzzy")
  80. public List<TCommonfile> allFileListFuzzy(TCommonfile tCommonfile)
  81. {
  82. List<TCommonfile> list = tCommonfileService.selectAllFileListFuzzy(tCommonfile);
  83. return list;
  84. }
  85. /**
  86. * 查询通用附件列表
  87. */
  88. @GetMapping("/allFileList")
  89. public List<TCommonfile> allFileList(TCommonfile tCommonfile)
  90. {
  91. List<TCommonfile> list = tCommonfileService.selectAllFileList(tCommonfile);
  92. return list;
  93. }
  94. /**
  95. * 导出通用附件列表
  96. */
  97. @Log(title = "通用附件", businessType = BusinessType.EXPORT)
  98. @GetMapping("/export")
  99. public AjaxResult export(TCommonfile tCommonfile)
  100. {
  101. List<TCommonfile> list = tCommonfileService.selectTCommonfileList(tCommonfile);
  102. ExcelUtil<TCommonfile> util = new ExcelUtil<TCommonfile>(TCommonfile.class);
  103. return util.exportExcel(list, "commonfile");
  104. }
  105. /**
  106. * 获取通用附件详细信息
  107. */
  108. @GetMapping(value = "/{id}")
  109. public AjaxResult getInfo(@PathVariable("id") Long id)
  110. {
  111. return AjaxResult.success(tCommonfileService.selectTCommonfileById(id));
  112. }
  113. /**
  114. * 新增通用附件
  115. */
  116. @Log(title = "通用附件", businessType = BusinessType.INSERT)
  117. @PostMapping
  118. public AjaxResult add(@RequestBody TCommonfile tCommonfile)
  119. {
  120. return toAjax(tCommonfileService.insertTCommonfile(tCommonfile));
  121. }
  122. /**
  123. * 修改通用附件
  124. */
  125. @Log(title = "通用附件", businessType = BusinessType.UPDATE)
  126. @PutMapping
  127. public AjaxResult edit(@RequestBody TCommonfile tCommonfile)
  128. {
  129. logger.info(JSON.toJSONString(tCommonfile));
  130. AjaxResult res = toAjax(tCommonfileService.updateTCommonfile(tCommonfile));
  131. SysJob job = new SysJob();
  132. job.setJobId(10040l);
  133. job.setJobGroup("SYSTEM");
  134. TaskThread thread = new TaskThread(job,jobService);
  135. Thread t = new Thread(thread);
  136. t.start();
  137. return res;
  138. }
  139. /**
  140. * 删除通用附件
  141. */
  142. @Log(title = "通用附件", businessType = BusinessType.DELETE)
  143. @DeleteMapping("/{ids}")
  144. public AjaxResult remove(@PathVariable Long[] ids)
  145. {
  146. return toAjax(tCommonfileService.deleteTCommonfileByIds(ids));
  147. }
  148. }