Files
RuoYi-Vue/ruoyi-office/src/main/java/com/ruoyi/office/controller/TtProjectInfoController.java

196 lines
7.2 KiB
Java
Raw Normal View History

2025-08-14 14:57:00 +08:00
package com.ruoyi.office.controller;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.utils.CoverGenerator;
import com.ruoyi.office.domain.TtCode;
import com.ruoyi.office.service.ITtCodeService;
import com.ruoyi.office.service.IProjectLinkCheckService;
2025-08-14 14:57:00 +08:00
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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.office.domain.TtProjectInfo;
import com.ruoyi.office.service.ITtProjectInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 项目清单Controller
*
* @author ruoyi
* @date 2024-06-07
*/
@RestController
@RequestMapping("/office/project")
public class TtProjectInfoController extends BaseController {
@Autowired
private ITtProjectInfoService ttProjectInfoService;
@Autowired
private ITtCodeService ttCodeService;
@Autowired
private IProjectLinkCheckService projectLinkCheckService;
2025-08-14 14:57:00 +08:00
/**
* 查询项目清单列表
*/
@PreAuthorize("@ss.hasPermi('office:project:list')")
@GetMapping("/list")
public TableDataInfo list(TtProjectInfo ttProjectInfo) {
startPage();
List<TtProjectInfo> list = ttProjectInfoService.selectTtProjectInfoList(ttProjectInfo);
return getDataTable(list);
}
/**
* 导出项目清单列表
*/
@PreAuthorize("@ss.hasPermi('office:project:export')")
@Log(title = "项目清单", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, TtProjectInfo ttProjectInfo) {
List<TtProjectInfo> list = ttProjectInfoService.selectTtProjectInfoList(ttProjectInfo);
ExcelUtil<TtProjectInfo> util = new ExcelUtil<TtProjectInfo>(TtProjectInfo.class);
util.exportExcel(response, list, "项目清单数据");
}
/**
* 获取项目清单详细信息
*/
@PreAuthorize("@ss.hasPermi('office:project:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Integer id) {
return success(ttProjectInfoService.selectTtProjectInfoById(id));
}
/**
* 检测单个项目的网盘链接
*/
@PreAuthorize("@ss.hasPermi('office:project:edit')")
@Log(title = "检测项目网盘链接", businessType = BusinessType.OTHER)
@PostMapping("/link-check/single/{id}")
public AjaxResult checkProjectLink(@PathVariable("id") Integer id) {
return success(projectLinkCheckService.checkProject(id));
}
/**
* 检测选中项目的网盘链接
*/
@PreAuthorize("@ss.hasPermi('office:project:edit')")
@Log(title = "批量检测项目网盘链接", businessType = BusinessType.OTHER)
@PostMapping("/link-check/batch")
public AjaxResult checkProjectLinks(@RequestBody Integer[] ids) {
return success(projectLinkCheckService.checkProjects(ids));
}
2025-08-14 14:57:00 +08:00
/**
* 新增项目清单
*/
@PreAuthorize("@ss.hasPermi('office:project:add')")
@Log(title = "项目清单", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody TtProjectInfo ttProjectInfo) {
return toAjax(ttProjectInfoService.insertTtProjectInfo(ttProjectInfo));
}
/**
* 修改项目清单
*/
@PreAuthorize("@ss.hasPermi('office:project:edit')")
@Log(title = "项目清单", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TtProjectInfo ttProjectInfo) {
return toAjax(ttProjectInfoService.updateTtProjectInfo(ttProjectInfo));
}
/**
* 删除项目清单
*/
@PreAuthorize("@ss.hasPermi('office:project:remove')")
@Log(title = "项目清单", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Integer[] ids) {
return toAjax(ttProjectInfoService.deleteTtProjectInfoByIds(ids));
}
/**
* 匹配已整理源码
*/
@PreAuthorize("@ss.hasPermi('office:project:edit')")
@Log(title = "匹配已整理源码", businessType = BusinessType.UPDATE)
@GetMapping("/matchCode/{id}")
public AjaxResult matchCode(@PathVariable Integer id) {
String msg = ttProjectInfoService.matchCode(id);
return success(msg);
}
/**
* 生成项目封面图
*
* @throws IOException
*/
@PreAuthorize("@ss.hasPermi('office:project:edit')")
@Log(title = "生成封面图", businessType = BusinessType.UPDATE)
@GetMapping("/cover/{id}")
public void generateCover(@PathVariable Long id, HttpServletResponse response) throws IOException {
try {
TtCode ttCode = ttCodeService.selectTtCodeByCodeId(id);
TtProjectInfo projectInfo = ttProjectInfoService.selectTtProjectInfoByName(ttCode.getCodeName());
String projectName = projectInfo.getProjectName1() == null ? projectInfo.getProjectName() : projectInfo.getProjectName1();
// 将项目名称按"的"分割,取后半部分作为副标题
String title = projectInfo.getProjectNum1();
String subtitle = projectName;
if (projectName != null && projectName.contains("")) {
String[] parts = projectName.split("");
if (parts.length > 1) {
subtitle = parts[parts.length - 1].trim();
}
}
String tag = projectInfo.getProjectDesc();
int titleSize = 120;
if (subtitle.length() > 8) {
titleSize = 80;
}
// 使用CoverGenerator生成图片
BufferedImage cover = CoverGenerator.createCover(
title,
subtitle,
tag,
titleSize // 副标题字体大小
);
// 设置响应头
response.setContentType("application/octet-stream");
String fileName = new String((projectInfo.getProjectName() + "_cover.png").getBytes("UTF-8"), "ISO-8859-1");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
// 将图片写入响应流
ImageIO.write(cover, "PNG", response.getOutputStream());
response.getOutputStream().flush();
} catch (Exception e) {
throw new RuntimeException("生成封面图片失败", e);
}
}
}