| | |
| | | package com.whyc.controller; |
| | | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.whyc.config.MyProps; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.ProjectArchiveManage; |
| | | import com.whyc.pojo.ProjectManage; |
| | | import com.whyc.service.ProjectArchiveManageService; |
| | | import com.whyc.service.ProjectProcessManageService; |
| | | import com.whyc.util.FileUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import org.apache.ibatis.annotations.Delete; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import javax.validation.Valid; |
| | | import java.io.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | |
| | | /** |
| | |
| | | public class ProjectManageController { |
| | | |
| | | @Autowired |
| | | private MyProps myProps; |
| | | |
| | | @Autowired |
| | | private ProjectProcessManageService service; |
| | | |
| | | |
| | |
| | | private ProjectArchiveManageService archiveManageService; |
| | | |
| | | |
| | | @GetMapping("all") |
| | | @ApiOperation(value = "项目过程管理-查询所有") |
| | | public Response<List<ProjectManage>> searchAll() { |
| | | |
| | | return service.searchAll(); |
| | | } |
| | | |
| | | |
| | | @GetMapping("byCondition") |
| | | @ApiOperation(notes = "项目过程管理",value = "项目过程管理-条件查询") |
| | | public Response<List<ProjectManage>> searchByCondition(@ApiParam(value = "申报日期 格式 2021/01/28",required = true) @RequestParam Date proCreatedate, |
| | | @ApiParam(value = "项目类型",required = true)@RequestParam int proSort, |
| | | @ApiParam(value = "项目状态",required = true)@RequestParam int proState, |
| | | @ApiParam(value = "项目编号",required = true)@RequestParam String proNum) { |
| | | ProjectManage projectManage = new ProjectManage(); |
| | | projectManage.setProCreatedate(proCreatedate); |
| | | projectManage.setProSort(proSort); |
| | | projectManage.setProState(proState); |
| | | projectManage.setProNum(proNum); |
| | | return service.searchByCondition(projectManage); |
| | | @PostMapping("progressByCondition") |
| | | @ApiOperation(notes = "项目过程管理", value = "项目过程管理-查询分页-根据筛选条件") |
| | | public Response<PageInfo<ProjectManage>> searchByCondition(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ProjectManage projectManage) { |
| | | return service.searchByCondition(pageNum, pageSize, projectManage); |
| | | } |
| | | |
| | | @PostMapping("add") |
| | | @ApiOperation(value = "新建项目",notes = "notes中存文件地址用 ; 分隔 {\n" + |
| | | " \"proNum\": S0900033,\n" + |
| | | " \"proName\": \"\",\n" + |
| | | " \"proNameCode\": \"yyyyMMddHHmmss格式字符串\",\n" + |
| | | @ApiOperation(value = "项目过程管理-新建项目",notes = "fileList 存文件地址 {\n" + |
| | | " \"fileList\": [\n" + |
| | | " \n" + |
| | | " ],\n" + |
| | | " \"proNum\": \"S0900033\",\n" + |
| | | " \"proName\": \"舰船电气动力试验\",\n" + |
| | | " \"proSort\": 0,\n" + |
| | | " \"proAdmin\": \"张三\",\n" + |
| | | " \"proTel\": 13800003131,\n" + |
| | | " \"proDepartment\": \"xxxx\",\n" + |
| | | " \"proTel\": \"13800003131\",\n" + |
| | | " \"proCreatedate\": \"2021-03-27 08:18:27\",\n" + |
| | | " \"proExecutionDate\": \"2021-03-27 08:18:27\",\n" + |
| | | " \"proExecutionDate1\": \"2021-03-27 08:18:27\",\n" + |
| | |
| | | " \"proFundingSource\": \"经费来源\",\n" + |
| | | " \"proContent\": \" \",\n" + |
| | | " \"proState\": 0,\n" + |
| | | " \"note\": \"拼接多个文件地址\"\n" + |
| | | " \"proProgress\": 0\n" + |
| | | "}") |
| | | public Response add(@RequestBody ProjectManage projectManage) { |
| | | |
| | | public Response add(@RequestBody @Valid ProjectManage projectManage) { |
| | | Response response = service.add(projectManage); |
| | | return response; |
| | | } |
| | |
| | | /** |
| | | * 文件存储后地址更新到对应项目编号的地址,一个项目对应多个文件 db_experiment.tb_project_archive_manage |
| | | * 是否需要将word转pdf/预览文件pdf |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @PostMapping("upload") |
| | | @ApiOperation(notes = "返回文件地址,确认时提交保存到字段",value = "文档材料添加(选择文件)") |
| | | @ApiOperation(notes = "返回文件地址,确认时提交保存到字段", value = "项目过程管理-文档材料添加(选择文件)") |
| | | public Response upload(@RequestParam("file") MultipartFile file) { |
| | | // 获取原始名字 |
| | | String fileName = file.getOriginalFilename(); |
| | | String originalFilename = file.getOriginalFilename(); |
| | | // 获取后缀名 |
| | | // String suffixName = fileName.substring(fileName.lastIndexOf(".")); |
| | | // 文件保存路径、后期考虑按日期或者月份建dir |
| | | String filePath = "c:/upload/"; |
| | | String filePath = myProps.getFilePath(); |
| | | // 文件重命名,防止重复,预览时需要显示原文件名 _ 切割 |
| | | fileName = filePath + UUID.randomUUID() + "_" + fileName; |
| | | String fileName = filePath + UUID.randomUUID() + "_" + originalFilename; |
| | | // 文件对象 |
| | | File dest = new File(fileName); |
| | | // 判断路径是否存在,如果不存在则创建 |
| | | if (!dest.getParentFile().exists()) { |
| | | dest.getParentFile().mkdirs(); |
| | | } |
| | | Response<Object> response = new Response<>(); |
| | | HashMap<Object, Object> map = new HashMap<>(); |
| | | try { |
| | | // 保存到服务器中 |
| | | file.transferTo(dest); |
| | | map.put("fileType", file.getContentType()); |
| | | map.put("name", originalFilename); |
| | | Double size = file.getSize() * 0.01 / 1024 / 1024 * 100; |
| | | String douStr = String.format("%.2f", size); |
| | | map.put("fileSize", douStr+" M"); |
| | | map.put("url",fileName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return new Response().setCode(0); |
| | | return response.setMsg(0, "上传失败"); |
| | | } |
| | | Response<Object> response = new Response<>(); |
| | | response.setMsg(1, fileName); |
| | | response.setCode(1); |
| | | response.setData(map); |
| | | return response; |
| | | } |
| | | |
| | | |
| | | |
| | | @PostMapping("/uploads") |
| | | @ApiOperation(notes = "返回文件地址,确认时提交保存到字段", value = "项目过程管理-文档材料添加(多选)") |
| | | public Response uploads(MultipartFile[] file) throws IOException { |
| | | Response<Object> response = new Response<>(); |
| | | if (file.length == 0) { |
| | | return response.setMsg(0, "请选择要上传的文件"); |
| | | } |
| | | |
| | | ArrayList<Object> list = new ArrayList<>(); |
| | | for (MultipartFile multipartFile : file) { |
| | | if (multipartFile.isEmpty()) { |
| | | return response.setMsg(0, "请选择要上传的文件"); |
| | | } |
| | | byte[] fileBytes = multipartFile.getBytes(); |
| | | String filePath = myProps.getFilePath(); |
| | | //取得当前上传文件的文件名称 |
| | | String originalFilename = multipartFile.getOriginalFilename(); |
| | | //生成文件名 |
| | | String fileName = UUID.randomUUID() + "_" + originalFilename; |
| | | |
| | | HashMap<Object, Object> map = new HashMap<>(); |
| | | try { |
| | | FileUtils.uploadFile(fileBytes, filePath, fileName); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | return response.setMsg(0, "上传失败"); |
| | | } |
| | | map.put("fileName", originalFilename); |
| | | map.put("url", filePath + fileName); |
| | | list.add(map); |
| | | |
| | | } |
| | | response.setData(list); |
| | | return response.setMsg(1, "上传成功"); |
| | | } |
| | | |
| | | |
| | | @GetMapping("/download") |
| | | @ApiOperation(notes = "需要在地址栏测试",value = "项目过程管理-文档材料下载") |
| | | public Object download(HttpServletResponse response, @RequestParam String filePath,@RequestParam String fileName) { |
| | | Response<Object> result = new Response<>(); |
| | | File file = new File( filePath); |
| | | if (file.exists()) { |
| | | try { |
| | | fileName= new String(fileName.getBytes("gbk"), "ISO8859-1"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | response.setContentType("application/force-download"); |
| | | // 设置强制下载不打开 |
| | | response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); |
| | | byte[] buffer = new byte[1024]; |
| | | FileInputStream fis = null; |
| | | BufferedInputStream bis = null; |
| | | try { |
| | | fis = new FileInputStream(file); |
| | | bis = new BufferedInputStream(fis); |
| | | OutputStream outputStream = response.getOutputStream(); |
| | | int i = bis.read(buffer); |
| | | while (i != -1) { |
| | | outputStream.write(buffer, 0, i); |
| | | i = bis.read(buffer); |
| | | } |
| | | return result.setMsg(1,"下载成功"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return result.setMsg(0,"下载失败"); |
| | | } finally { |
| | | if (bis != null) { |
| | | try { |
| | | bis.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (fis != null) { |
| | | try { |
| | | fis.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return result.setMsg(0,"文件不存在"); |
| | | } |
| | | |
| | | |
| | | |
| | | @GetMapping("managesState") |
| | | @ApiOperation(notes = "项目管理-己确认阶段", value = "项目管理-己确认阶段查询") |
| | | @ApiOperation(notes = "", value = "项目过程管理-己确认/未确认阶段查询") |
| | | public Response<Object> searchManageStateByCondition(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum, |
| | | @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode) { |
| | | ProjectManage projectManage = new ProjectManage(); |
| | |
| | | |
| | | |
| | | /** |
| | | * 项目进度确认 pro_progress |
| | | * 项目进度确认 pro_progress,未归档可以修改更新,归档后不能修改 |
| | | * @return |
| | | */ |
| | | @PutMapping("updateManageState") |
| | | @ApiOperation(notes = "项目管理-己确认阶段",value = "项目管理-己确认阶段更新") |
| | | public Response updateManageState(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum, |
| | | @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode, |
| | | @ApiParam(value = "项目进度确认0-6",required = true)@RequestParam int proProgress, |
| | | @ApiParam(value = "文档上传保存地址(如果无传空字符串)",required = true)@RequestParam String proFilePath) { |
| | | ProjectManage projectManage = new ProjectManage(); |
| | | projectManage.setProNum(proNum); |
| | | projectManage.setProNameCode(proNameCode); |
| | | projectManage.setProProgress(proProgress); |
| | | projectManage.setNote(proFilePath); |
| | | @ApiOperation(notes = "项目进度确认1-6 对应 立项-审批-研究-结题-验收-归档",value = "项目过程管理-未确认阶段更新") |
| | | public Response updateManageState(@RequestBody ProjectManage projectManage) { |
| | | |
| | | return service.updateManageState(projectManage); |
| | | } |
| | | |
| | | @PutMapping("updateArchive") |
| | | @ApiOperation(notes = "",value = "项目过程管理-归档") |
| | | public Response updateArchive(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum, |
| | | @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode) { |
| | | ProjectManage projectManage = new ProjectManage(); |
| | | projectManage.setProNum(proNum); |
| | | projectManage.setProNameCode(proNameCode); |
| | | projectManage.setProProgress(6); |
| | | return service.updateProjectProgress(projectManage); |
| | | } |
| | | |
| | | @PutMapping("searchDoc") |
| | | @ApiOperation(notes = "项目管理-己确认阶段",value = "文档材料查询") |
| | | |
| | | |
| | | |
| | | @GetMapping("searchDoc") |
| | | @ApiOperation(notes = "项目过程管理-项目管理",value = "项目过程管理-文档材料查询") |
| | | public Response searchDocumentation(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum, |
| | | @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode){ |
| | | ProjectArchiveManage projectArchiveManage = new ProjectArchiveManage(); |
| | |
| | | |
| | | } |
| | | |
| | | @PutMapping("delDoc") |
| | | @ApiOperation(notes = "项目管理-己确认阶段",value = "文档材料删除") |
| | | @DeleteMapping("delDoc") |
| | | @ApiOperation(notes = "项目过程管理-项目管理",value = "项目过程管理-文档材料删除") |
| | | public Response delDocumentation(@ApiParam(value = "项目编号", required = true) @RequestParam String proNum, |
| | | @ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode, |
| | | @ApiParam(value = "文档路径", required = true) @RequestParam String proFilePath){ |
| | |
| | | return archiveManageService.delDocumentation(projectArchiveManage); |
| | | } |
| | | |
| | | @GetMapping("archiveAll") |
| | | @ApiOperation(value = "项目归档管理-查询所有") |
| | | public Response<List<ProjectManage>> searchArchiveAll() { |
| | | |
| | | return archiveManageService.searchAll(); |
| | | } |
| | | @GetMapping("archiveByCondition") |
| | | @ApiOperation(value = "项目归档管理-条件查询") |
| | | public Response searchArchiveByCondition(@ApiParam(value = "开始日期 格式 2021/01/28",required = true) @RequestParam Date gainDate, |
| | | @ApiParam(value = "归档日期",required = true)@RequestParam Date proArchiveDate, |
| | | @ApiParam(value = "项目类型",required = true)@RequestParam int proSort, |
| | | @ApiParam(value = "项目编号",required = true)@RequestParam String proNum) { |
| | | @PostMapping("archiveByCondition") |
| | | @ApiOperation(value = "项目归档管理-查询分页-根据筛选条件") |
| | | public Response<PageInfo<ProjectManage>> searchArchiveByCondition(@RequestParam int pageNum, @RequestParam int pageSize, @RequestBody ProjectManage projectManage) { |
| | | |
| | | ProjectArchiveManage pam = new ProjectArchiveManage(); |
| | | pam.setGainDate(gainDate); |
| | | pam.setProArchiveDate(proArchiveDate); |
| | | pam.setProSort(proSort); |
| | | pam.setProNum(proNum); |
| | | |
| | | return archiveManageService.searchArchiveByCondition(pam); |
| | | return archiveManageService.searchArchiveByCondition(pageNum,pageSize,projectManage); |
| | | } |
| | | |
| | | @GetMapping("archiveProjectInfo") |
| | | @ApiOperation(value = "项目归档管理-项目概况信息") |
| | | public Response searchArchiveProjectInfo(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode, |
| | | @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) { |
| | | |
| | | ProjectManage pm = new ProjectManage(); |
| | | pm.setProNameCode(proNameCode); |
| | | pm.setProNum(proNum); |
| | | |
| | | return archiveManageService.searchArchiveProjectInfo(pm); |
| | | } |
| | | |
| | | /** |
| | | * 文件上传 |
| | | * achievement_name 成果类型 |
| | | * @param proNameCode |
| | | * @param proNum |
| | | * @return 文档格式、文档名称、归档日期、下载路径 |
| | | */ |
| | | /* |
| | | @RequestMapping("/upload") |
| | | public Response upload(MultipartFile file) { |
| | | try { |
| | | if (file != null) { |
| | | File parentFile = createParentFile(); |
| | | String fileName = file.getOriginalFilename(); |
| | | String suffix = fileName.substring(fileName.lastIndexOf(".")); |
| | | String uuid = IdUtil.simpleUUID(); |
| | | fileName = uuid + suffix; |
| | | File imageFile = new File(parentFile, fileName); |
| | | FileUtil.writeFromStream(file.getInputStream(), imageFile); |
| | | */ |
| | | /** |
| | | * 年月日目录 |
| | | *//* |
| | | @GetMapping("archiveDocManager") |
| | | @ApiOperation(value = "项目归档管理-文档管理") |
| | | public Response searchProjectDocByCondition(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode, |
| | | @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) { |
| | | ProjectArchiveManage pam = new ProjectArchiveManage(); |
| | | pam.setProNum(proNum); |
| | | pam.setProNameCode(proNameCode); |
| | | |
| | | String fileDay = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/" |
| | | + DateUtil.thisDayOfMonth(); |
| | | String imagePath = SystemConstant.FILE + "/document/" + fileDay + "/" + fileName; |
| | | */ |
| | | /** |
| | | * 实时转换 |
| | | *//* |
| | | |
| | | File toFile = new File(parentFile, uuid + ".pdf"); |
| | | documentConverter.convert(imageFile).to(toFile).execute(); |
| | | return Result.ok(imagePath); |
| | | } else { |
| | | return Result.error(); |
| | | } |
| | | } catch (Exception e) { |
| | | LOGGER.error("转换异常{}",e); |
| | | return Result.error(); |
| | | } |
| | | return archiveManageService.searchProjectDocByCondition(pam); |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * @param proNameCode |
| | | * @param proNum |
| | | * @return 实验名称、上传日期、归档日期 (操作TODO) |
| | | */ |
| | | @GetMapping("archiveExperimentData") |
| | | @ApiOperation(notes = "(操作TODO)",value = "项目归档管理-试验数据") |
| | | public Response searchArchiveExperimentData(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode, |
| | | @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) { |
| | | ProjectArchiveManage pam = new ProjectArchiveManage(); |
| | | pam.setProNum(proNum); |
| | | pam.setProNameCode(proNameCode); |
| | | return archiveManageService.searchArchiveExperimentData(pam); |
| | | } |
| | | |
| | | @GetMapping("archiveTechnologicalAchievements") |
| | | @ApiOperation(notes = "(操作TODO)", value = "项目归档管理-科技成果") |
| | | public Response searchArchiveTechnologicalAchievements(@ApiParam(value = "项目名称代码", required = true) @RequestParam String proNameCode, |
| | | @ApiParam(value = "项目编号", required = true) @RequestParam String proNum) { |
| | | ProjectArchiveManage pam = new ProjectArchiveManage(); |
| | | pam.setProNum(proNum); |
| | | pam.setProNameCode(proNameCode); |
| | | return archiveManageService.searchArchiveTechnologicalAchievements(pam); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |