123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package com.ruoyi.web.controller.system;
- import java.io.IOException;
- import java.util.List;
- import java.util.Set;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.system.domain.SysRepoHistory;
- import com.ruoyi.common.utils.VersionUtils;
- import com.ruoyi.common.utils.OfficeCompareUtils;
- import com.ruoyi.system.service.ISysRepoHistoryService;
- import com.ruoyi.common.utils.file.FileUtils;
- import org.springframework.http.MediaType;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import com.ruoyi.common.annotation.Log;
- import com.ruoyi.common.core.controller.BaseController;
- import com.ruoyi.common.core.domain.AjaxResult;
- import com.ruoyi.common.enums.BusinessType;
- import com.ruoyi.system.domain.SysRepo;
- import com.ruoyi.system.service.ISysRepoService;
- import javax.servlet.http.HttpServletResponse;
- /**
- * 仓库管理Controller
- *
- * @author lixu
- * @date 2025-05-15
- */
- @RestController
- @RequestMapping("/system/repo")
- public class SysRepoController extends BaseController
- {
- @Autowired
- private ISysRepoService sysRepoService;
- @Autowired
- private ISysRepoHistoryService sysRepoHistoryService;
- /**
- * 查询仓库列表
- */
- @PreAuthorize("@ss.hasPermi('system:repo:list')")
- @GetMapping("/list")
- public AjaxResult list(SysRepo sysRepo)
- {
- startPage();
- List<SysRepo> list = sysRepoService.selectSysRepoList(sysRepo);
- return AjaxResult.success(getDataTable(list));
- }
- /**
- * 获取仓库详细信息
- */
- @PreAuthorize("@ss.hasPermi('system:repo:query')")
- @GetMapping(value = "/{repoId}")
- public AjaxResult getInfo(@PathVariable("repoId") Long repoId)
- {
- return success(sysRepoService.selectSysRepoByRepoId(repoId));
- }
- /**
- * 新增仓库
- */
- @PreAuthorize("@ss.hasPermi('system:repo:add')")
- @Log(title = "新增仓库", businessType = BusinessType.INSERT)
- @PostMapping
- public AjaxResult add(@RequestBody SysRepo sysRepo)
- {
- sysRepo.setCreateBy(getUsername());
- sysRepo.setUpdateBy(getUsername());
- return toAjax(sysRepoService.insertSysRepo(sysRepoService.createSysRepo(sysRepo)));
- }
- /**
- * 更新文件版本
- */
- @PreAuthorize("@ss.hasPermi('system:repo:updateFile')")
- @Log(title = "更新文件版本", businessType = BusinessType.UPDATE)
- @PostMapping(value = "/upload_file")
- public AjaxResult upload_file(@RequestBody SysRepo sysRepo)
- {
- if(sysRepo.getRepoId()==null || sysRepo.getUrl()==null ){
- return AjaxResult.error("参数错误");
- }else{
- SysRepo sysRepo_old = sysRepoService.selectSysRepoByRepoId(sysRepo.getRepoId());
- sysRepo.setUpdateBy(getUsername());
- sysRepo.setVersion(sysRepo_old.getVersion());
- SysRepoHistory sysRepoHistory = sysRepoHistoryService.createSysRepoHistory(sysRepo_old);
- SysRepo sysRepo_new = sysRepoService.createSysRepo(sysRepo);
- if(!sysRepo_old.getRepoType().equals(sysRepo_new.getRepoType())){
- return error("新旧文件类型不一致,请重试");
- }
- return toAjax(sysRepoService.insertSysRepoAndSysRepoHistory(sysRepo_new,sysRepoHistory));
- }
- }
- /**
- * 对比接口
- */
- @PreAuthorize("@ss.hasPermi('system:repo:compare')")
- @PostMapping("/compare")
- public AjaxResult compare(@RequestBody SysRepo sysRepo)
- {
- SysRepo sysRepo_old = sysRepoService.selectSysRepoByRepoId(sysRepo.getRepoId());
- if(FileUtils.getFileExtension(sysRepo_old.getUrl()).equals(".docx") ||
- FileUtils.getFileExtension(sysRepo_old.getUrl()).equals(".doc" )){
- return AjaxResult.success(OfficeCompareUtils.compare(FileUtils.getUploadPath(sysRepo_old.getUrl()),FileUtils.getUploadPath(sysRepo.getUrl()),"spire"));
- }
- return AjaxResult.error("对比失败");
- }
- /**
- * 获取文件版本
- */
- @PreAuthorize("@ss.hasPermi('system:repo:getversion')")
- @GetMapping (value = "version/{repoId}")
- public AjaxResult getVersion(@PathVariable("repoId") Long repoId)
- {
- startPage();
- SysRepoHistory sysRepoHistory = new SysRepoHistory();
- sysRepoHistory.setRepoId(repoId);
- return success(getDataTable(sysRepoHistoryService.selectSysRepoHistoryList(sysRepoHistory)));
- }
- /**
- * 回滚文件版本
- */
- @PreAuthorize("@ss.hasPermi('system:repo:backFile')")
- @Log(title = "回滚文件版本", businessType = BusinessType.UPDATE)
- @PostMapping(value = "/back_file")
- public AjaxResult upload_file(@RequestBody SysRepoHistory sysRepoHistory)
- {
- SysRepo sysRepo = sysRepoService.selectSysRepoByRepoId(sysRepoHistory.getRepoId());
- SysRepoHistory sysRepoHistory_repo = sysRepoHistoryService.createSysRepoHistory(sysRepo);
- sysRepo.setUpdateBy(getUsername());
- sysRepo.setUrl(sysRepoHistory.getUrl());
- sysRepo.setVersion(VersionUtils.incrementVersion(sysRepo.getVersion()));
- sysRepo.setFileName(sysRepoHistory.getFileName());
- sysRepo.setRemark("回滚版本"+sysRepoHistory.getVersion());
- return toAjax(sysRepoService.insertSysRepoAndSysRepoHistory(sysRepo,sysRepoHistory_repo));
- }
- /**
- * 文件下载
- */
- @GetMapping("/download")
- public void Download(String url ,String fileName, HttpServletResponse response)
- {
- try
- {
- if (!FileUtils.checkAllowDownload(fileName))
- {
- throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", url));
- }
- String filePath = FileUtils.getUploadPath(url);
- response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
- FileUtils.setAttachmentResponseHeader(response, fileName);
- FileUtils.writeBytes(filePath, response.getOutputStream());
- }
- catch (Exception e)
- {
- AjaxResult.error("下载文件失败", e);
- }
- }
- /**
- * 修改仓库
- */
- @PreAuthorize("@ss.hasPermi('system:repo:edit')")
- @Log(title = "修改仓库", businessType = BusinessType.UPDATE)
- @PutMapping
- public AjaxResult edit(@RequestBody SysRepo sysRepo)
- {
- return toAjax(sysRepoService.updateSysRepo(sysRepo));
- }
- /**
- * 删除仓库
- */
- @PreAuthorize("@ss.hasPermi('system:repo:remove')")
- @Log(title = "删除仓库", businessType = BusinessType.DELETE)
- @DeleteMapping("/{repoIds}")
- public AjaxResult remove(@PathVariable Long[] repoIds)
- {
- return toAjax(sysRepoService.deleteSysRepoByRepoIds(repoIds));
- }
- }
|