SysRepoController.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package com.ruoyi.web.controller.system;
  2. import java.io.IOException;
  3. import java.util.List;
  4. import java.util.Set;
  5. import com.ruoyi.common.utils.StringUtils;
  6. import com.ruoyi.system.domain.SysRepoHistory;
  7. import com.ruoyi.common.utils.VersionUtils;
  8. import com.ruoyi.common.utils.OfficeCompareUtils;
  9. import com.ruoyi.system.service.ISysRepoHistoryService;
  10. import com.ruoyi.common.utils.file.FileUtils;
  11. import org.springframework.http.MediaType;
  12. import org.springframework.security.access.prepost.PreAuthorize;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import com.ruoyi.common.annotation.Log;
  16. import com.ruoyi.common.core.controller.BaseController;
  17. import com.ruoyi.common.core.domain.AjaxResult;
  18. import com.ruoyi.common.enums.BusinessType;
  19. import com.ruoyi.system.domain.SysRepo;
  20. import com.ruoyi.system.service.ISysRepoService;
  21. import javax.servlet.http.HttpServletResponse;
  22. /**
  23. * 仓库管理Controller
  24. *
  25. * @author lixu
  26. * @date 2025-05-15
  27. */
  28. @RestController
  29. @RequestMapping("/system/repo")
  30. public class SysRepoController extends BaseController
  31. {
  32. @Autowired
  33. private ISysRepoService sysRepoService;
  34. @Autowired
  35. private ISysRepoHistoryService sysRepoHistoryService;
  36. /**
  37. * 查询仓库列表
  38. */
  39. @PreAuthorize("@ss.hasPermi('system:repo:list')")
  40. @GetMapping("/list")
  41. public AjaxResult list(SysRepo sysRepo)
  42. {
  43. startPage();
  44. List<SysRepo> list = sysRepoService.selectSysRepoList(sysRepo);
  45. return AjaxResult.success(getDataTable(list));
  46. }
  47. /**
  48. * 获取仓库详细信息
  49. */
  50. @PreAuthorize("@ss.hasPermi('system:repo:query')")
  51. @GetMapping(value = "/{repoId}")
  52. public AjaxResult getInfo(@PathVariable("repoId") Long repoId)
  53. {
  54. return success(sysRepoService.selectSysRepoByRepoId(repoId));
  55. }
  56. /**
  57. * 新增仓库
  58. */
  59. @PreAuthorize("@ss.hasPermi('system:repo:add')")
  60. @Log(title = "新增仓库", businessType = BusinessType.INSERT)
  61. @PostMapping
  62. public AjaxResult add(@RequestBody SysRepo sysRepo)
  63. {
  64. sysRepo.setCreateBy(getUsername());
  65. sysRepo.setUpdateBy(getUsername());
  66. return toAjax(sysRepoService.insertSysRepo(sysRepoService.createSysRepo(sysRepo)));
  67. }
  68. /**
  69. * 更新文件版本
  70. */
  71. @PreAuthorize("@ss.hasPermi('system:repo:updateFile')")
  72. @Log(title = "更新文件版本", businessType = BusinessType.UPDATE)
  73. @PostMapping(value = "/upload_file")
  74. public AjaxResult upload_file(@RequestBody SysRepo sysRepo)
  75. {
  76. if(sysRepo.getRepoId()==null || sysRepo.getUrl()==null ){
  77. return AjaxResult.error("参数错误");
  78. }else{
  79. SysRepo sysRepo_old = sysRepoService.selectSysRepoByRepoId(sysRepo.getRepoId());
  80. sysRepo.setUpdateBy(getUsername());
  81. sysRepo.setVersion(sysRepo_old.getVersion());
  82. SysRepoHistory sysRepoHistory = sysRepoHistoryService.createSysRepoHistory(sysRepo_old);
  83. SysRepo sysRepo_new = sysRepoService.createSysRepo(sysRepo);
  84. if(!sysRepo_old.getRepoType().equals(sysRepo_new.getRepoType())){
  85. return error("新旧文件类型不一致,请重试");
  86. }
  87. return toAjax(sysRepoService.insertSysRepoAndSysRepoHistory(sysRepo_new,sysRepoHistory));
  88. }
  89. }
  90. /**
  91. * 对比接口
  92. */
  93. @PreAuthorize("@ss.hasPermi('system:repo:compare')")
  94. @PostMapping("/compare")
  95. public AjaxResult compare(@RequestBody SysRepo sysRepo)
  96. {
  97. SysRepo sysRepo_old = sysRepoService.selectSysRepoByRepoId(sysRepo.getRepoId());
  98. if(FileUtils.getFileExtension(sysRepo_old.getUrl()).equals(".docx") ||
  99. FileUtils.getFileExtension(sysRepo_old.getUrl()).equals(".doc" )){
  100. return AjaxResult.success(OfficeCompareUtils.compare(FileUtils.getUploadPath(sysRepo_old.getUrl()),FileUtils.getUploadPath(sysRepo.getUrl()),"spire"));
  101. }
  102. return AjaxResult.error("对比失败");
  103. }
  104. /**
  105. * 获取文件版本
  106. */
  107. @PreAuthorize("@ss.hasPermi('system:repo:getversion')")
  108. @GetMapping (value = "version/{repoId}")
  109. public AjaxResult getVersion(@PathVariable("repoId") Long repoId)
  110. {
  111. startPage();
  112. SysRepoHistory sysRepoHistory = new SysRepoHistory();
  113. sysRepoHistory.setRepoId(repoId);
  114. return success(getDataTable(sysRepoHistoryService.selectSysRepoHistoryList(sysRepoHistory)));
  115. }
  116. /**
  117. * 回滚文件版本
  118. */
  119. @PreAuthorize("@ss.hasPermi('system:repo:backFile')")
  120. @Log(title = "回滚文件版本", businessType = BusinessType.UPDATE)
  121. @PostMapping(value = "/back_file")
  122. public AjaxResult upload_file(@RequestBody SysRepoHistory sysRepoHistory)
  123. {
  124. SysRepo sysRepo = sysRepoService.selectSysRepoByRepoId(sysRepoHistory.getRepoId());
  125. SysRepoHistory sysRepoHistory_repo = sysRepoHistoryService.createSysRepoHistory(sysRepo);
  126. sysRepo.setUpdateBy(getUsername());
  127. sysRepo.setUrl(sysRepoHistory.getUrl());
  128. sysRepo.setVersion(VersionUtils.incrementVersion(sysRepo.getVersion()));
  129. sysRepo.setFileName(sysRepoHistory.getFileName());
  130. sysRepo.setRemark("回滚版本"+sysRepoHistory.getVersion());
  131. return toAjax(sysRepoService.insertSysRepoAndSysRepoHistory(sysRepo,sysRepoHistory_repo));
  132. }
  133. /**
  134. * 文件下载
  135. */
  136. @GetMapping("/download")
  137. public void Download(String url ,String fileName, HttpServletResponse response)
  138. {
  139. try
  140. {
  141. if (!FileUtils.checkAllowDownload(fileName))
  142. {
  143. throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", url));
  144. }
  145. String filePath = FileUtils.getUploadPath(url);
  146. response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
  147. FileUtils.setAttachmentResponseHeader(response, fileName);
  148. FileUtils.writeBytes(filePath, response.getOutputStream());
  149. }
  150. catch (Exception e)
  151. {
  152. AjaxResult.error("下载文件失败", e);
  153. }
  154. }
  155. /**
  156. * 修改仓库
  157. */
  158. @PreAuthorize("@ss.hasPermi('system:repo:edit')")
  159. @Log(title = "修改仓库", businessType = BusinessType.UPDATE)
  160. @PutMapping
  161. public AjaxResult edit(@RequestBody SysRepo sysRepo)
  162. {
  163. return toAjax(sysRepoService.updateSysRepo(sysRepo));
  164. }
  165. /**
  166. * 删除仓库
  167. */
  168. @PreAuthorize("@ss.hasPermi('system:repo:remove')")
  169. @Log(title = "删除仓库", businessType = BusinessType.DELETE)
  170. @DeleteMapping("/{repoIds}")
  171. public AjaxResult remove(@PathVariable Long[] repoIds)
  172. {
  173. return toAjax(sysRepoService.deleteSysRepoByRepoIds(repoIds));
  174. }
  175. }