123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.ruoyi.web.controller.system;
- import java.io.IOException;
- import java.util.List;
- import java.util.Set;
- import com.ruoyi.common.utils.file.FileUploadUtils;
- import com.ruoyi.system.domain.SysRepoHistory;
- import com.ruoyi.common.utils.OfficeCompareUtils;
- import com.ruoyi.system.service.ISysRepoHistoryService;
- import org.apache.tomcat.util.http.fileupload.FileUpload;
- import org.apache.tomcat.util.http.fileupload.FileUtils;
- 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 org.springframework.web.multipart.MultipartFile;
- /**
- * 仓库管理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)
- {
- return toAjax(sysRepoService.insertSysRepo(sysRepo));
- }
- /**
- * 更新文件版本
- */
- @PreAuthorize("@ss.hasPermi('system:repo:updateFile')")
- @Log(title = "更新文件版本", businessType = BusinessType.UPDATE)
- @PostMapping(value = "/upload_file")
- public AjaxResult upload_file(@RequestBody SysRepo sysRepo_new)
- {
- if(sysRepo_new.getRepoId()==null || sysRepo_new.getUrl()==null ){
- return AjaxResult.error("参数错误");
- }else{
- Long repoId = sysRepo_new.getRepoId();
- SysRepo sysRepo = sysRepoService.selectSysRepoByRepoId(repoId);
- SysRepoHistory sysRepoHistory = new SysRepoHistory();
- sysRepoHistory.setRepoId(sysRepo.getRepoId());
- sysRepoHistory.setUrl(sysRepo.getUrl());
- sysRepoHistory.setUploadBy(sysRepo.getUpdateBy());
- sysRepoHistory.setFileVersion("v0.0.1");
- if(sysRepoHistoryService.insertSysRepoHistory(sysRepoHistory)<1){
- return AjaxResult.error("文件插入失败");
- }
- sysRepo.setUpdateBy(getUsername());
- sysRepo.setUrl(sysRepo_new.getUrl());
- if(sysRepoService.updateSysRepo(sysRepo)<1){
- return AjaxResult.error("文件插入失败");
- }
- Set<String> set = OfficeCompareUtils.compare(sysRepoHistory.getUrl(),sysRepo.getUrl(),"spire");
- return AjaxResult.success(set);
- }
- }
- /**
- * 获取文件版本
- */
- @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: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));
- }
- }
|