package com.ruoyi.web.controller.task; import java.util.List; import javax.servlet.http.HttpServletResponse; import com.ruoyi.system.domain.SysTask; 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.DeleteMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; 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.SysTaskAttachment; import com.ruoyi.system.service.ISysTaskService; /** * 任务附件Controller * * @author ruoyi * @date 2024-01-15 */ @RestController @RequestMapping("/task/attachment") public class SysTaskAttachmentController extends BaseController { @Autowired private ISysTaskService sysTaskService; /** * 查询任务附件列表 */ @PreAuthorize("@ss.hasPermi('task:general:query')") @GetMapping("/list/{taskId}") public AjaxResult list(@PathVariable("taskId") Long taskId) { SysTask task = sysTaskService.getTaskDetail(taskId); return success(task.getAttachments()); } /** * 上传任务附件 */ @PreAuthorize("@ss.hasPermi('task:general:edit')") @Log(title = "任务附件", businessType = BusinessType.INSERT) @PostMapping("/upload/{taskId}") public AjaxResult upload(@PathVariable("taskId") Long taskId, @RequestParam("file") MultipartFile file) { try { int result = sysTaskService.uploadAttachment(taskId, file); if (result > 0) { return success("上传成功"); } else { return error("上传失败"); } } catch (Exception e) { return error("上传失败:" + e.getMessage()); } } /** * 删除任务附件 */ @PreAuthorize("@ss.hasPermi('task:general:edit')") @Log(title = "任务附件", businessType = BusinessType.DELETE) @DeleteMapping("/{attachmentId}") public AjaxResult remove(@PathVariable("attachmentId") Long attachmentId) { try { int result = sysTaskService.deleteAttachment(attachmentId); if (result > 0) { return success("删除成功"); } else { return error("删除失败"); } } catch (Exception e) { return error("删除失败:" + e.getMessage()); } } }