tj
2025-06-05 2d549a04870d1315868a7cf19952b64e8071e711
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package com.cloudroam.controller.v1;
 
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cloudroam.bo.ProjectInfoBO;
import com.cloudroam.bo.ProjectUserStatisticsBO;
import com.cloudroam.bo.project.ProjectBoardColumnsDataBO;
import com.cloudroam.common.annotation.LogParams;
import com.cloudroam.common.util.PageUtil;
import com.cloudroam.dto.projectInfo.*;
import com.cloudroam.service.ProjectInfoService;
import com.cloudroam.vo.projectInfo.ProjectInfoExcelVO;
import io.github.talelin.autoconfigure.exception.NotFoundException;
import io.github.talelin.core.annotation.Logger;
import io.github.talelin.core.annotation.LoginRequired;
import io.github.talelin.core.annotation.PermissionMeta;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.cloudroam.model.ProjectInfoDO;
import com.cloudroam.vo.CreatedVO;
import com.cloudroam.vo.DeletedVO;
import com.cloudroam.vo.PageResponseVO;
import com.cloudroam.vo.UpdatedVO;
 
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
 
import com.alibaba.excel.EasyExcel;
 
/**
* @author generator@TaoJie
* @since 2023-08-08
*/
@RestController
@RequestMapping("/v1/projectInfo")
public class ProjectInfoController {
 
    @Autowired
    private ProjectInfoService projectInfoService;
 
 
    @PostMapping("")
    @PermissionMeta(value = "创建项目", module = "项目管理",mount =false)
    @Logger(template = "{user.nickname} 创建了项目 ")
    @LoginRequired
    @LogParams
    public CreatedVO create(@RequestBody @Validated CreateOrUpdateProjectInfoDTO validator) {
        projectInfoService.createProjectInfo(validator);
        return new CreatedVO();
    }
 
    @PutMapping("/{id}")
    @PermissionMeta(value = "更新项目", module = "项目管理",mount =false)
    @Logger(template = "{user.nickname} 更新了项目 ")
    @LoginRequired
    @LogParams
    public UpdatedVO update(@PathVariable String id,@RequestBody @Validated CreateOrUpdateProjectInfoDTO validator) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        projectInfoService.updateProjectInfo(validator);
        return new UpdatedVO();
    }
 
    @DeleteMapping("/{id}")
    @PermissionMeta(value = "删除项目", module = "项目管理",mount =false)
    @Logger(template = "{user.nickname} 删除了项目 ")
    @LoginRequired
    @LogParams
    public DeletedVO delete(@PathVariable String id) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        projectInfoService.removeByIdLogic(id);
        return new DeletedVO();
    }
 
    @GetMapping("/{id}")
    @LogParams
    public ProjectInfoDO get(@PathVariable(value = "id") String id) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        return projectInfoDO;
    }
 
    @GetMapping("/detail/{id}")
    @LogParams
    public ProjectInfoBO getDetail(@PathVariable(value = "id") String id) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoBO projectInfoBO = projectInfoService.getDetailById(id);
        return projectInfoBO;
    }
 
//    @GetMapping("/page")
//    @PermissionMeta(value = "全部项目",module = "项目管理")
//    @Logger(template = "{user.nickname} 查看了项目管理 ")
//    @LoginRequired
//    @LogParams
//    public PageResponseVO<ProjectInfoBO> page(
//            @Validated QueryProjectInfoDTO dto
//    ) {
//
//        IPage<ProjectInfoBO> iPage=projectInfoService.getProjectInfoPage(dto);
//        return PageUtil.build(iPage);
//    }
 
    @PostMapping("/page")
    @PermissionMeta(value = "全部项目",module = "项目管理")
    @Logger(template = "{user.nickname} 查看了项目管理 ")
    @LoginRequired
    @LogParams
    public PageResponseVO<ProjectInfoBO> page(
            @Validated @RequestBody QueryProjectInfoDTO dto
    ) {
 
        IPage<ProjectInfoBO> iPage=projectInfoService.getProjectInfoPage(dto);
        return PageUtil.build(iPage);
    }
 
 
    @PostMapping("/report/list")
    @PermissionMeta(value = "项目报表",module = "项目报表")
    @Logger(template = "{user.nickname} 查看了项目报表 ")
    @LoginRequired
    @LogParams
    public List<ProjectInfoBO> getReportList(
            @Validated @RequestBody QueryProjectInfoDTO dto
    ) {
 
        List<ProjectInfoBO> reportList=projectInfoService.getReportList(dto);
        return reportList;
    }
 
    @PostMapping("/report/list/export")
    @PermissionMeta(value = "项目报表导出", module = "项目报表")
    @Logger(template = "{user.nickname} 项目报表-导出")
    @LoginRequired
    @LogParams
    public void exportReportList(
            @Validated @RequestBody QueryProjectInfoDTO dto,
            HttpServletResponse response
    ) {
-        List<ProjectInfoBO> reportList = projectInfoService.getReportList(dto);
        // 将这个转换成projectInfoExcelVO
        List<ProjectInfoExcelVO> projectInfoExcelVOList = reportList.stream().map(projectInfoBO -> {
            ProjectInfoExcelVO vo = new ProjectInfoExcelVO();
            BeanUtils.copyProperties(projectInfoBO, vo);
            return vo;
        }).collect(Collectors.toList());
 
 
        try {
            // 设置响应头信息
            String baseName = "项目报表";
            String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
            String fileName = URLEncoder.encode(baseName + "_" + timestamp, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20");
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Pragma", "public");
            response.setHeader("Cache-Control", "no-store, max-age=0, no-cache, must-revalidate");
            response.setHeader("Expires", "0");
            response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + fileName + ".xlsx");
            // 写入 Excel
            EasyExcel.write(response.getOutputStream(), ProjectInfoExcelVO.class)
                    .sheet("项目报表")
                    .doWrite(projectInfoExcelVOList);
 
        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw new RuntimeException("导出失败:" + e.getMessage(), e);
        }
    }
 
 
    @GetMapping("/list")
    public List<ProjectInfoDO> list(
            @Validated QueryProjectInfoDTO dto
    ) {
        List<ProjectInfoDO> list=projectInfoService.getProjectInfoList(dto);
        return list;
    }
 
 
    @PutMapping("/projectSetUp/{id}")
    @PermissionMeta(value = "立项", module = "项目管理",mount =true)
    @Logger(template = "{user.nickname} 项目立项 ")
    @LoginRequired
    @LogParams
    public UpdatedVO projectSetUp(@PathVariable String id,@RequestBody @Validated UpdateProjectSetUpDTO validator) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        boolean result = projectInfoService.updateProjectInfoSetUp(validator);
        if(result){
            return new UpdatedVO("项目立项成功!");
        }else{
            return new UpdatedVO("项目立项失败!");
        }
 
    }
 
 
    @PutMapping("/projectStart/{id}")
    @PermissionMeta(value = "启动", module = "项目管理",mount =true)
    @Logger(template = "{user.nickname} 项目启动 ")
    @LoginRequired
    @LogParams
    public UpdatedVO projectStart(@PathVariable String id) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        boolean result = projectInfoService.updateProjectInfoStart(id);
        if(result){
            return new UpdatedVO("项目启动成功!");
        }else{
            return new UpdatedVO("项目启动失败!");
        }
 
    }
 
 
    @PutMapping("/projectComplete/{id}")
    @PermissionMeta(value = "完成", module = "项目管理",mount =true)
    @Logger(template = "{user.nickname} 项目完成 ")
    @LoginRequired
    @LogParams
    public UpdatedVO projectComplete(@PathVariable String id) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        boolean result = projectInfoService.updateProjectInfoComplete(id);
        if(result){
            return new UpdatedVO("项目完成成功!");
        }else{
            return new UpdatedVO("项目完成失败!");
        }
 
    }
 
    @PutMapping("/projectTermination/{id}")
    @PermissionMeta(value = "终止", module = "项目管理",mount =true)
    @Logger(template = "{user.nickname} 项目终止 ")
    @LoginRequired
    @LogParams
    public UpdatedVO projectTermination(@PathVariable String id) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        boolean result = projectInfoService.updateProjectInfoTermination(id);
        if(result){
            return new UpdatedVO("项目终止成功!");
        }else{
            return new UpdatedVO("项目终止失败!");
        }
 
    }
 
    @PutMapping("/projectHours/{id}")
    @PermissionMeta(value = "工时", module = "项目管理",mount =true)
    @Logger(template = "{user.nickname} 修改了项目工时 ")
    @LoginRequired
    @LogParams
    public UpdatedVO projectHours(@PathVariable String id,@RequestBody @Validated UpdateProjectHoursDTO validator) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        boolean result = projectInfoService.updateProjectInfoHours(validator);
        if(result){
            return new UpdatedVO("项目工时修改成功!");
        }else{
            return new UpdatedVO("项目工时修改失败!");
        }
 
    }
 
 
    @GetMapping("/hourStatistics")
    @PermissionMeta(value = "确认工时统计", module = "项目管理")
    @Logger(template = "{user.nickname} 查看了项目管理 ")
    @LoginRequired
    @LogParams
    public  List<ProjectUserStatisticsBO> confirmedHourStatistics(
            @Validated QueryProjectInfoDTO dto
    ) {
 
        List<ProjectUserStatisticsBO> list=projectInfoService.getProjectHourStatisticsConfirmed(dto);
        return list;
    }
 
    @GetMapping("/all/hourStatistics")
    @PermissionMeta(value = "未确认工时统计", module = "项目管理")
    @Logger(template = "{user.nickname} 查看了项目管理 ")
    @LoginRequired
    @LogParams
    public  List<ProjectUserStatisticsBO> allHourStatistics(
            @Validated QueryProjectInfoDTO dto
    ) {
 
        List<ProjectUserStatisticsBO> list=projectInfoService.getProjectHourStatisticsAll(dto);
        return list;
    }
 
 
    @PostMapping("/board/month")
    @PermissionMeta(value = "项目看板", module = "项目看板")
    @Logger(template = "{user.nickname} 查看了项目看板 ")
    @LoginRequired
    @LogParams
    public ProjectBoardColumnsDataBO getProjectBoardMonth(
            @RequestBody @Validated QueryProjectInfoDTO dto
    ) {
 
        ProjectBoardColumnsDataBO projectBoardColumnsDataBO=projectInfoService.getProjectBoardMonth(dto);
        return projectBoardColumnsDataBO;
    }
 
    @PostMapping("/board")
    @PermissionMeta(value = "项目看板", module = "项目看板")
    @Logger(template = "{user.nickname} 查看了项目看板 ")
    @LoginRequired
    @LogParams
    public ProjectBoardColumnsDataBO getProjectBoard2(
            @RequestBody @Validated QueryProjectInfoDTO dto
    ) {
 
        ProjectBoardColumnsDataBO projectBoardColumnsDataBO=projectInfoService.getProjectBoard2(dto);
        return projectBoardColumnsDataBO;
    }
 
 
 
 
    @PutMapping("/projectProBusDate/{id}")
    @PermissionMeta(value = "项目商务时间修改", module = "项目管理",mount =false)
    @Logger(template = "{user.nickname} 项目商务时间修改 ")
    @LoginRequired
    @LogParams
    public UpdatedVO updateProjectProBusDate(@PathVariable String id,@RequestBody @Validated UpdateProjectProBusDateDTO validator) {
        if(StrUtil.isBlank(id)){
            throw new NotFoundException("传入的Id不能为空");
        }
        ProjectInfoDO projectInfoDO = projectInfoService.getById(id);
        if(projectInfoDO == null){
            throw new NotFoundException("项目不存在");
        }
        boolean result = projectInfoService.updateProjectProBusDate(validator);
        if(result){
            return new UpdatedVO("项目时间修改成功!");
        }else{
            return new UpdatedVO("项目时间修改失败!");
        }
 
    }
 
}