SysRepoController.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.file.FileUploadUtils;
  6. import com.ruoyi.system.domain.SysRepoHistory;
  7. import com.ruoyi.common.utils.OfficeCompareUtils;
  8. import com.ruoyi.system.service.ISysRepoHistoryService;
  9. import org.apache.tomcat.util.http.fileupload.FileUpload;
  10. import org.apache.tomcat.util.http.fileupload.FileUtils;
  11. import org.springframework.security.access.prepost.PreAuthorize;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.*;
  14. import com.ruoyi.common.annotation.Log;
  15. import com.ruoyi.common.core.controller.BaseController;
  16. import com.ruoyi.common.core.domain.AjaxResult;
  17. import com.ruoyi.common.enums.BusinessType;
  18. import com.ruoyi.system.domain.SysRepo;
  19. import com.ruoyi.system.service.ISysRepoService;
  20. import org.springframework.web.multipart.MultipartFile;
  21. /**
  22. * 仓库管理Controller
  23. *
  24. * @author lixu
  25. * @date 2025-05-15
  26. */
  27. @RestController
  28. @RequestMapping("/system/repo")
  29. public class SysRepoController extends BaseController
  30. {
  31. @Autowired
  32. private ISysRepoService sysRepoService;
  33. @Autowired
  34. private ISysRepoHistoryService sysRepoHistoryService;
  35. /**
  36. * 查询仓库列表
  37. */
  38. @PreAuthorize("@ss.hasPermi('system:repo:list')")
  39. @GetMapping("/list")
  40. public AjaxResult list(SysRepo sysRepo)
  41. {
  42. startPage();
  43. List<SysRepo> list = sysRepoService.selectSysRepoList(sysRepo);
  44. return AjaxResult.success(getDataTable(list));
  45. }
  46. /**
  47. * 获取仓库详细信息
  48. */
  49. @PreAuthorize("@ss.hasPermi('system:repo:query')")
  50. @GetMapping(value = "/{repoId}")
  51. public AjaxResult getInfo(@PathVariable("repoId") Long repoId)
  52. {
  53. return success(sysRepoService.selectSysRepoByRepoId(repoId));
  54. }
  55. /**
  56. * 新增仓库
  57. */
  58. @PreAuthorize("@ss.hasPermi('system:repo:add')")
  59. @Log(title = "新增仓库", businessType = BusinessType.INSERT)
  60. @PostMapping
  61. public AjaxResult add(@RequestBody SysRepo sysRepo)
  62. {
  63. return toAjax(sysRepoService.insertSysRepo(sysRepo));
  64. }
  65. /**
  66. * 更新文件版本
  67. */
  68. @PreAuthorize("@ss.hasPermi('system:repo:updateFile')")
  69. @Log(title = "更新文件版本", businessType = BusinessType.UPDATE)
  70. @PostMapping(value = "/upload_file")
  71. public AjaxResult upload_file(@RequestBody SysRepo sysRepo_new)
  72. {
  73. if(sysRepo_new.getRepoId()==null || sysRepo_new.getUrl()==null ){
  74. return AjaxResult.error("参数错误");
  75. }else{
  76. Long repoId = sysRepo_new.getRepoId();
  77. SysRepo sysRepo = sysRepoService.selectSysRepoByRepoId(repoId);
  78. SysRepoHistory sysRepoHistory = new SysRepoHistory();
  79. sysRepoHistory.setRepoId(sysRepo.getRepoId());
  80. sysRepoHistory.setUrl(sysRepo.getUrl());
  81. sysRepoHistory.setUploadBy(sysRepo.getUpdateBy());
  82. sysRepoHistory.setFileVersion("v0.0.1");
  83. if(sysRepoHistoryService.insertSysRepoHistory(sysRepoHistory)<1){
  84. return AjaxResult.error("文件插入失败");
  85. }
  86. sysRepo.setUpdateBy(getUsername());
  87. sysRepo.setUrl(sysRepo_new.getUrl());
  88. if(sysRepoService.updateSysRepo(sysRepo)<1){
  89. return AjaxResult.error("文件插入失败");
  90. }
  91. Set<String> set = OfficeCompareUtils.compare(sysRepoHistory.getUrl(),sysRepo.getUrl(),"spire");
  92. return AjaxResult.success(set);
  93. }
  94. }
  95. /**
  96. * 获取文件版本
  97. */
  98. @PreAuthorize("@ss.hasPermi('system:repo:getversion')")
  99. @GetMapping (value = "version/{repoId}")
  100. public AjaxResult getVersion(@PathVariable("repoId") Long repoId)
  101. {
  102. startPage();
  103. SysRepoHistory sysRepoHistory = new SysRepoHistory();
  104. sysRepoHistory.setRepoId(repoId);
  105. return success(getDataTable(sysRepoHistoryService.selectSysRepoHistoryList(sysRepoHistory)));
  106. }
  107. /**
  108. * 修改仓库
  109. */
  110. @PreAuthorize("@ss.hasPermi('system:repo:edit')")
  111. @Log(title = "修改仓库", businessType = BusinessType.UPDATE)
  112. @PutMapping
  113. public AjaxResult edit(@RequestBody SysRepo sysRepo)
  114. {
  115. return toAjax(sysRepoService.updateSysRepo(sysRepo));
  116. }
  117. /**
  118. * 删除仓库
  119. */
  120. @PreAuthorize("@ss.hasPermi('system:repo:remove')")
  121. @Log(title = "删除仓库", businessType = BusinessType.DELETE)
  122. @DeleteMapping("/{repoIds}")
  123. public AjaxResult remove(@PathVariable Long[] repoIds)
  124. {
  125. return toAjax(sysRepoService.deleteSysRepoByRepoIds(repoIds));
  126. }
  127. }