package com.ruoyi.web.controller.project; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; import com.ruoyi.common.utils.file.MimeTypeUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.project.bo.*; import com.ruoyi.project.domain.ProjectStaff; import com.ruoyi.project.domain.ProjectStaffRecord; import com.ruoyi.project.domain.ProjectStaffRecordLog; import com.ruoyi.project.domain.ProjectTask; import com.ruoyi.project.service.ProjectStaffRecordService; import com.ruoyi.project.service.ProjectStaffService; import com.ruoyi.project.service.ProjectTaskService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Date; import java.util.List; /** * 项目管理 */ @Api("项目管理") @RestController @RequestMapping("/api/project") public class ProjectTaskController extends BaseController { @Resource private ProjectTaskService projectTaskService; @Resource private ProjectStaffService projectStaffService; @Resource private ProjectStaffRecordService projectStaffRecordService; /** * 新增项目任务 */ @PostMapping("/add") @ApiOperation("新增项目") @Log(title = "项目管理", businessType = BusinessType.INSERT) public AjaxResult add( @RequestBody ProjectTask projectTask){ if (projectTask.getAid()== null){ return error("负责人不能为空"); } if (projectTaskService.checkProjectNumber(projectTask)){ return error("项目编号已存在"); } return projectTaskService.addProjectTask(projectTask); } /** * 查询项目编号 */ @GetMapping("/checkProjectNumber") @ApiOperation("查询项目编号") public AjaxResult checkProjectNumber( @RequestBody ProjectTask projectTask){ if (projectTaskService.checkProjectNumber(projectTask)){ return error("项目编号已存在"); } return success(1); } /** * 修改项目 */ @PutMapping("/update") @ApiOperation("修改项目") @Log(title = "项目管理", businessType = BusinessType.UPDATE) public AjaxResult update( @RequestBody ProjectTask projectTask){ if (projectTask.getAid()== null){ return error("负责人不能为空"); } if (projectTaskService.checkProjectNumber(projectTask)){ return error("项目编号已存在"); } return projectTaskService.updateProjectTask(projectTask); } /** * 新增项目成员 */ @PostMapping("/addStaff") @ApiOperation("新增项目成员") public AjaxResult addStaff(@Validated @RequestBody ProjectStaff in){ return projectStaffService.addStaff(in); } /** * 新增成员打卡 */ @PostMapping("/addRecord") @ApiOperation("新增项目打卡") @Log(title = "项目管理", businessType = BusinessType.INSERT) public AjaxResult addRecord( @RequestBody ProjectStaffRecord in){ if (in.getRecordTime()==null){ in.setRecordTime(new Date()); } Long userId = SecurityUtils.getUserId(); in.setAid(userId); AjaxResult ajaxResult = projectStaffRecordService.addCheckMaxDuration(in); ajaxResult=projectStaffRecordService.checkRecordTime(ajaxResult,in); if (ajaxResult.isError()){ return ajaxResult; } return projectStaffRecordService.add(in); } /** * 修改成员打卡 */ @PostMapping("/updateRecord") @ApiOperation("修改成员打卡") @Log(title = "项目日志管理", businessType = BusinessType.UPDATE) public AjaxResult updateRecord( @RequestBody ProjectStaffRecord in){ Long userId = SecurityUtils.getUserId(); in.setAid(userId); AjaxResult ajaxResult = projectStaffRecordService.updateCheckMaxDuration(in); projectStaffRecordService.checkRecordTime(ajaxResult,in); if (ajaxResult.isError()){ return ajaxResult; } return projectStaffRecordService.update(in); } /** * 研发打卡日志详情 */ @GetMapping("/recordDetails") @ApiOperation("打卡日志详情") public AjaxResult recordDetails( Long id){ return projectStaffRecordService.recordDetails(id); } /** * 审核成员打卡 */ @PostMapping("/examineRecord") @ApiOperation("审核成员打卡") public AjaxResult examineRecord( @RequestBody ProjectStaffRecord in){ if (in.getProcessStatus()!=2 && in.getProcessStatus()!=3){ return AjaxResult.error("审核状态错误"); } return projectStaffRecordService.examineRecord(in); } /** * 批量审核成员打卡 */ @PostMapping("/batchExamineRecord") @ApiOperation("批量审核成员打卡") public AjaxResult batchExamineRecord( @RequestBody batchExamineRecordInput in){ if (in.getProcessStatus()!=2 && in.getProcessStatus()!=3){ return AjaxResult.error("审核状态错误"); } return projectStaffRecordService.batchExamineRecord(in); } /** * 成员打卡列表 */ @GetMapping("/listRecord") @ApiOperation("成员打卡列表") public TableDataInfo listRecord( ProjectStaffRecordInput in){ startPage(); List list = projectStaffRecordService.listRecord(in); return getDataTable(list); } /** * 成员打卡审核日志 */ @GetMapping("/listRecordLog") @ApiOperation("成员打卡审核日志") public AjaxResult listRecordLog(ProjectStaffRecordLog in){ return projectStaffRecordService.listRecordLog(in); } /** * 导出项目打卡列表 */ @PostMapping("/listRecord/export") @ApiOperation("导出项目打卡列表") @Log(title = "项目日志管理", businessType = BusinessType.EXPORT) public void listRecordExport(HttpServletResponse response, ProjectStaffRecordInput in){ in.setPageSize(999999); List list=projectStaffRecordService.listRecord(in); ExcelUtil util = new ExcelUtil<>(ProjectStaffRecordOut.class); util.exportExcel(response, list, "项目研发日志列表"); } /** * 导入数据 */ @PostMapping("/listRecord/importData") @ApiOperation("导入项目打卡数据") @Log(title = "项目日志管理", businessType = BusinessType.IMPORT) public AjaxResult listRecordImportData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil<>(ProjectStaffRecordOut.class); List list = util.importExcel(file.getInputStream()); String message = projectStaffRecordService.importProject(list, updateSupport); return success(message); } /** * 项目打卡日志导出模版 */ @PostMapping("/listRecord/importTemplate") @ApiOperation("项目打卡日志导出模版") public void listRecordImportTemplate(HttpServletResponse response) { ExcelUtil util = new ExcelUtil(ProjectStaffRecordOut.class); util.importTemplateExcel(response, "项目打卡日志列表"); } /** * 删除项目成员 */ @PostMapping("/deleteStaff") @ApiOperation("删除项目成员") @Log(title = "项目管理", businessType = BusinessType.DELETE) public AjaxResult deleteStaff( @RequestBody ProjectStaff in){ if (in.getId()== null){ return error("项目成员编号不能为空"); } return projectStaffService.deleteStaff(in); } /** * 项目成员列表 */ @GetMapping("/listStaff") @ApiOperation("项目成员列表") public AjaxResult listStaff( ProjectStaff in){ if (in.getPid()== null){ return error("项目编号不能为空"); } return projectStaffService.listStaff(in); } /** * 删除项目 */ @PostMapping("/deleteProject") @ApiOperation("删除项目") @Log(title = "项目管理", businessType = BusinessType.DELETE) public AjaxResult deleteProject( @RequestBody ProjectTask in){ if (in.getId()== null){ return error("项目编号不能为空"); } return projectTaskService.deleteProject(in); } /** * 项目详情 */ @GetMapping ("/details") @ApiOperation("项目详情") public AjaxResult details( Long id){ if (id== null){ return error("项目编号不能为空"); } return projectTaskService.details(id); } /** * 项目列表 */ @GetMapping ("/list") @ApiOperation("项目列表") public TableDataInfo list(ProjectListInput in){ List list=projectTaskService.list(in); return getDataTable(list); } /** * 导出项目列表 */ @PostMapping("/export") @ApiOperation("导出项目列表") @Log(title = "项目管理", businessType = BusinessType.EXPORT) public void export(HttpServletResponse response,ProjectListInput in) { in.setPageSize(999999); List list=projectTaskService.list(in); ExcelUtil util = new ExcelUtil<>(ProjectTaskListOut.class); util.exportExcel(response, list, "项目列表"); } /** * 导入数据 */ @PostMapping("/importData") @Log(title = "项目管理", businessType = BusinessType.IMPORT) @ApiOperation("导入项目列表") public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception { ExcelUtil util = new ExcelUtil<>(ProjectTaskListOut.class); List list = util.importExcel(file.getInputStream()); String operName = getUsername(); String message = projectTaskService.importProject(list, updateSupport, operName); return success(message); } @PostMapping("/importTemplate") @ApiOperation("项目导出模版") public void importTemplate(HttpServletResponse response) { ExcelUtil util = new ExcelUtil(ProjectTaskListOut.class); util.importTemplateExcel(response, "项目列表"); } /** * 上传项目文件 */ @PostMapping("/upload") @ApiOperation("上传文件") public AjaxResult upload(@RequestParam("file") MultipartFile file) throws Exception{ if (!file.isEmpty()){ String avatar = FileUploadUtils.upload(RuoYiConfig.getUploadPath(), file, MimeTypeUtils.DEFAULT_ALLOWED_EXTENSION); AjaxResult ajax = AjaxResult.success(); logger.debug(avatar); ajax.put("imgUrl", avatar); return ajax; } return error("上传图片异常,请联系管理员"); } /** * 查询剩余时间 */ @GetMapping("/myDuration") @ApiOperation("查询剩余打卡时间") public AjaxResult myDuration(Long id,String recordTime){ return projectStaffRecordService.myDuration(id,recordTime); } /** * 查询我的月份数据 */ @GetMapping("/myDurationMonth") @ApiOperation("查询我的月份数据") public AjaxResult myDurationMonth(Long id,Integer year,Integer month){ return projectStaffRecordService.myDurationMonth(id,year,month); } /** * 项目附件目录 */ @GetMapping("/selectProjectImg") public AjaxResult selectProjectImg(Long pid){ if (pid==null){ return AjaxResult.error("项目编号不能为空!"); } return projectTaskService.selectProjectImg(pid); } /** * 下载项目打卡数据包 */ @GetMapping("/download") public void downloadFiles(HttpServletResponse response,String ids) { if (StringUtils.isEmpty(ids)){ throw new ServiceException("编号不能为空"); } projectStaffRecordService.downloadFiles(ids, response); } /** * 打卡数据匹配 */ @PostMapping("/mateUserRecord") public AjaxResult mateUserRecord(ProjectStaffRecordInput in) { projectStaffRecordService.mateUserRecord(in); return AjaxResult.success(); } /** * 项目及日志上传天河链 * @param id * @return */ @GetMapping("/saveProjectTaskTianhe") public AjaxResult saveProjectTaskTianhe(@RequestParam("id") String id){ if (StringUtils.isEmpty(id)){ return AjaxResult.error("项目编号不能为空"); } projectTaskService.saveProjectTaskTianhe(id); return AjaxResult.success(); } /** * 项目日志上传天河链 * @param id * @return */ @GetMapping("/saveProjectStaffRecordTianhe") public AjaxResult saveProjectStaffRecordTianhe(@RequestParam("id") String id){ if (StringUtils.isEmpty(id)){ return AjaxResult.error("项目日志编号不能为空"); } projectTaskService.saveProjectStaffRecordTianhe(id); return AjaxResult.success(); } /** * 文字上传天河链 * @param content * @return */ @GetMapping("/saveText") public AjaxResult saveText(@RequestParam("content") String content){ if (StringUtils.isEmpty(content)){ return AjaxResult.error("内容不能为空"); } projectTaskService.saveText(content); return AjaxResult.success(); } }