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 page( // @Validated QueryProjectInfoDTO dto // ) { // // IPage iPage=projectInfoService.getProjectInfoPage(dto); // return PageUtil.build(iPage); // } @PostMapping("/page") @PermissionMeta(value = "全部项目",module = "项目管理") @Logger(template = "{user.nickname} 查看了项目管理 ") @LoginRequired @LogParams public PageResponseVO page( @Validated @RequestBody QueryProjectInfoDTO dto ) { IPage iPage=projectInfoService.getProjectInfoPage(dto); return PageUtil.build(iPage); } @PostMapping("/report/list") @PermissionMeta(value = "项目报表",module = "项目报表") @Logger(template = "{user.nickname} 查看了项目报表 ") @LoginRequired @LogParams public List getReportList( @Validated @RequestBody QueryProjectInfoDTO dto ) { List 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 reportList = projectInfoService.getReportList(dto); // 将这个转换成projectInfoExcelVO List 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 list( @Validated QueryProjectInfoDTO dto ) { List 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 confirmedHourStatistics( @Validated QueryProjectInfoDTO dto ) { List list=projectInfoService.getProjectHourStatisticsConfirmed(dto); return list; } @GetMapping("/all/hourStatistics") @PermissionMeta(value = "未确认工时统计", module = "项目管理") @Logger(template = "{user.nickname} 查看了项目管理 ") @LoginRequired @LogParams public List allHourStatistics( @Validated QueryProjectInfoDTO dto ) { List 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("项目时间修改失败!"); } } }