xiangpei
2025-01-17 2cf8f4dff8667d54037ab91ded0b1edea9a26d05
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package com.ycl.controller;
 
import com.ycl.common.base.Result;
import com.ycl.common.exception.base.BaseException;
import com.ycl.common.group.Add;
import com.ycl.common.group.Update;
import com.ycl.common.utils.ProjectCodeGenerator;
import com.ycl.common.utils.excel.OutputExcelUtils;
import com.ycl.domain.excel.ProjectExcelTemplate;
import com.ycl.domain.form.DocumentInfoForm;
import com.ycl.domain.form.ProjectForm;
import com.ycl.domain.form.ProjectInfoForm;
import com.ycl.domain.query.ProjectExportQuery;
import com.ycl.domain.query.ProjectInfoQuery;
import com.ycl.service.ProjectInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 项目管理基础信息表 前端控制器
 *
 * @author flq
 * @since 2024-11-22
 */
@Validated
@RequiredArgsConstructor
@Api(value = "项目管理基础信息表", tags = "项目管理基础信息表管理")
@RestController
@RequestMapping("/project/info")
public class ProjectInfoController {
 
    private final ProjectInfoService projectInfoService;
 
    @PostMapping
    @ApiOperation(value = "添加", notes = "添加")
//    @PreAuthorize("hasAuthority('projectInfo:add')")
    public Result add(@RequestBody @Validated(Add.class) ProjectInfoForm form) {
        return projectInfoService.add(form);
    }
 
    @PostMapping("/document")
    @ApiOperation(value = "添加相关文件", notes = "添加相关文件")
//    @PreAuthorize("hasAuthority('projectInfo:add')")
    public Result addDoc(@RequestBody @Validated(Add.class) DocumentInfoForm form) {
        return projectInfoService.addDoc(form);
    }
 
    @PutMapping
    @ApiOperation(value = "修改", notes = "修改")
//    @PreAuthorize("hasAuthority('projectInfo:edit')")
    public Result update(@RequestBody @Validated(Update.class) ProjectInfoForm form) {
        return projectInfoService.update(form);
    }
 
    @DeleteMapping("/{id}")
    @ApiOperation(value = "ID删除", notes = "ID删除")
//    @PreAuthorize("hasAuthority('projectInfo:del')")
    public Result removeById(@PathVariable("id") Long id) {
        return projectInfoService.removeById(id);
    }
 
    @DeleteMapping("/batch")
    @ApiOperation(value = "批量删除", notes = "批量删除")
//    @PreAuthorize("hasAuthority('projectInfo:del:batch')")
    public Result remove(@RequestBody @NotEmpty(message = "请选择数据") List<String> ids) {
        return projectInfoService.remove(ids);
    }
 
    @GetMapping("/page")
    @ApiOperation(value = "分页", notes = "分页")
//    @PreAuthorize("hasAuthority('projectInfo:page')")
    public Result page(ProjectInfoQuery query) {
        return projectInfoService.page(query);
    }
 
    @GetMapping("/{id}")
    @ApiOperation(value = "详情", notes = "详情")
//    @PreAuthorize("hasAuthority('projectInfo:detail')")
    public Result detail(@PathVariable("id") Integer id) {
        return projectInfoService.detail(id);
    }
 
    @GetMapping("/document/{id}")
    @ApiOperation(value = "相关文件详情", notes = "相关文件详情")
//    @PreAuthorize("hasAuthority('projectInfo:detail')")
    public Result docDetail(@PathVariable("id") Integer id) {
        return projectInfoService.docDetail(id);
    }
 
    @GetMapping("/list")
//    @PreAuthorize("hasAuthority('projectInfo:list')")
    @ApiOperation(value = "列表", notes = "列表")
    public Result list() {
        return projectInfoService.all();
    }
 
    /**
     * 生成项目编号
     *
     * @return 项目编号
     */
    @GetMapping("/getProjectCode")
    public Result generateProjectCode() {
        return Result.ok().data(ProjectCodeGenerator.generateProjectCode());
    }
 
    @GetMapping("/searchByKey")
    public Result searchByKey(@RequestParam(required = false) String wordKey) {
        return projectInfoService.searchByKey(wordKey);
    }
 
    @GetMapping("/getManagerFlag/{recordId}")
    public Result getManagerFlag(@PathVariable("recordId") Integer recordId) {
        return projectInfoService.getManagerFlag(recordId);
    }
 
    /**
     * 导出模板
     *
     * @param response
     * @return
     */
    @PostMapping("/export/template")
    public void exportTemplate(HttpServletResponse response) throws IOException {
        List<String> fieldList = new ArrayList<>();
        OutputExcelUtils.export(response, "导入模板", "项目信息", null, ProjectExcelTemplate.class, fieldList);
    }
 
    /**
     * 项目导出
     *
     * @param response
     * @throws IOException
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectExportQuery query) throws IOException {
        projectInfoService.export(response, query);
    }
 
    @PutMapping("usedStatus/{id}/{usedStatus}")
    @ApiOperation(value = "修改使用状态", notes = "修改使用状态")
//    @PreAuthorize("hasAuthority('projectInfo:edit')")
    public Result updateUsedStatus(@PathVariable Integer id, @PathVariable Integer usedStatus) {
        return projectInfoService.updateUsedStatus(id, usedStatus);
    }
 
    /**
     * 项目导入
     * @param file
     * @return
     */
    @PostMapping("/import")
    public Result importProject(MultipartFile file) {
        if (file.getSize() > 100 * 1024 * 1024) {
            throw new BaseException("文件过大,文件不得超过100MB");
        }
        projectInfoService.importProject(file);
        return Result.ok();
    }
 
    @PostMapping("/editProject")
    public Result editProject(@RequestBody ProjectForm form) {
        return projectInfoService.editProject(form);
    }
 
 
 
}