wlzboy
2025-09-24 62a079a15b46925283581f6caaf631b5a4558927
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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());
        }
    }
}