| | |
| | | import com.panzhihua.common.model.vos.community.reserve.*; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.utlis.AssemblyUtils; |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import com.panzhihua.common.utlis.SFTPUtil; |
| | | import com.panzhihua.common.utlis.StringUtils; |
| | | import com.panzhihua.common.utlis.*; |
| | | import com.panzhihua.community_backstage.config.SFTPConfig; |
| | | import com.panzhihua.community_backstage.excel.Custemhandler; |
| | | import com.panzhihua.community_backstage.excel.CustomSheetWriteHandler; |
| | |
| | | import java.net.URL; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @description: 预约登记接口 |
| | |
| | | @ApiOperation(value = "导出登记明细") |
| | | @PostMapping("/register/list/export") |
| | | public R exportRegister(@RequestBody PageReserveRegisterDetailedAdminDTO pageReserveRegisterDetailedAdminDTO) { |
| | | |
| | | String name=""; |
| | | R r=communityService.detailReserveAdmin(pageReserveRegisterDetailedAdminDTO.getReserveId()); |
| | | ComActReserveDetailAdminVO comActReserveDetailAdminVO=JSON.parseObject(JSON.toJSONString(r.getData()),ComActReserveDetailAdminVO.class); |
| | | if(comActReserveDetailAdminVO.getTitle().contains("居家隔离")){ |
| | | name = "居家隔离导出数据.xlsx"; |
| | | } |
| | | else { |
| | | name = "登记明细导出数据.xlsx"; |
| | | } |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | String name = "登记明细导出数据.xlsx"; |
| | | String noHaed = "承诺"; |
| | | List<List<Object>> datalist=new ArrayList<>(); |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(sftpConfig.getUserName(), sftpConfig.getPassword(), sftpConfig.getHost(), sftpConfig.getPort()); |
| | | sftp.login(); |
| | |
| | | */ |
| | | R QuestnaireAnswersDTOR = communityService.exportRegisterAdmin(pageReserveRegisterDetailedAdminDTO); |
| | | QuestnaireAnswersDTO questnaireAnswersDTOS = JSON.parseObject(JSON.toJSONString(QuestnaireAnswersDTOR.getData()), QuestnaireAnswersDTO.class); |
| | | |
| | | List<ComActQuestnaireSubVO> subVOList = questnaireAnswersDTOS.getSubs(); |
| | | //构造表头 |
| | | List<List<String>> headList = new ArrayList<List<String>>(); |
| | | String firstRowContent = "登记明细"; |
| | | List<String> head0 = new ArrayList<>(); |
| | | head0.add(firstRowContent); |
| | | head0.add("登记人昵称"); |
| | | headList.add(head0); |
| | | List<String> head1 = new ArrayList<>(); |
| | | head1.add(firstRowContent); |
| | | head1.add("登记时间"); |
| | | headList.add(head1); |
| | | subVOList.forEach(sub -> { |
| | | if (sub.getType() != 5 && sub.getType() != 11) { |
| | | List<String> headn = new ArrayList<>(); |
| | | headn.add(firstRowContent); |
| | | if(!sub.getContent().equals(noHaed)){ |
| | | if(sub.getType() == 11){ |
| | | headn.add(sub.getContent().substring(0, sub.getContent().indexOf("("))); |
| | | }else{ |
| | | headn.add(sub.getContent()); |
| | | if(comActReserveDetailAdminVO.getTitle().contains("居家隔离")){ |
| | | String firstRowContent = "重点地区或高风险地区来攀返攀人员信息统计表(居家隔离表)"; |
| | | List<String> head0 = new ArrayList<>(); |
| | | head0.add(firstRowContent); |
| | | head0.add("登记人昵称"); |
| | | headList.add(head0); |
| | | List<String> head1 = new ArrayList<>(); |
| | | head1.add(firstRowContent); |
| | | head1.add("登记时间"); |
| | | headList.add(head1); |
| | | subVOList.forEach(sub -> { |
| | | if (sub.getType() != 5 && sub.getType() != 11&&!sub.getContent().contains("今日上午")&&!sub.getContent().contains("今日下午")&&!sub.getContent().contains("今日隔离情况")) { |
| | | List<String> headn = new ArrayList<>(); |
| | | headn.add(firstRowContent); |
| | | if(!sub.getContent().equals(noHaed)){ |
| | | if(sub.getType() == 11){ |
| | | headn.add(sub.getContent().substring(0, sub.getContent().indexOf("("))); |
| | | }else{ |
| | | headn.add(sub.getContent()); |
| | | } |
| | | headList.add(headn); |
| | | } |
| | | headList.add(headn); |
| | | } |
| | | } |
| | | }); |
| | | //数据转换 |
| | | List<List<Object>> datalist = AssemblyUtils.ReserveData(questnaireAnswersDTOS.getAnswers()); |
| | | }); |
| | | List<String> head2 = new ArrayList<>(); |
| | | head2.add(firstRowContent); |
| | | head2.add("隔离体温情况"); |
| | | headList.add(head2); |
| | | //数据转换 |
| | | datalist = HomeQuarantineUtil.ReserveData(questnaireAnswersDTOS.getAnswers()); |
| | | } |
| | | else { |
| | | String firstRowContent = "登记明细"; |
| | | List<String> head0 = new ArrayList<>(); |
| | | head0.add(firstRowContent); |
| | | head0.add("登记人昵称"); |
| | | headList.add(head0); |
| | | List<String> head1 = new ArrayList<>(); |
| | | head1.add(firstRowContent); |
| | | head1.add("登记时间"); |
| | | headList.add(head1); |
| | | subVOList.forEach(sub -> { |
| | | if (sub.getType() != 5 && sub.getType() != 11) { |
| | | List<String> headn = new ArrayList<>(); |
| | | headn.add(firstRowContent); |
| | | if(!sub.getContent().equals(noHaed)){ |
| | | if(sub.getType() == 11){ |
| | | headn.add(sub.getContent().substring(0, sub.getContent().indexOf("("))); |
| | | }else{ |
| | | headn.add(sub.getContent()); |
| | | } |
| | | headList.add(headn); |
| | | } |
| | | } |
| | | }); |
| | | //数据转换 |
| | | datalist = AssemblyUtils.ReserveData(questnaireAnswersDTOS.getAnswers()); |
| | | } |
| | | |
| | | |
| | | WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
| | | //设置头居中 |
| | |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "导出登记明细") |
| | | @PostMapping("/register/list/export/homeQuarantine") |
| | | public R exportRegisterHomeQuarantine(@RequestBody PageReserveRegisterDetailedAdminDTO pageReserveRegisterDetailedAdminDTO) { |
| | | |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | String name = "登记明细导出数据.xlsx"; |
| | | String noHaed = "承诺"; |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(sftpConfig.getUserName(), sftpConfig.getPassword(), sftpConfig.getHost(), sftpConfig.getPort()); |
| | | sftp.login(); |
| | | boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | if (!existDir) { |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + name; |
| | | ExcelWriter excelWriter = null; |
| | | InputStream inputStream = null; |
| | | try { |
| | | /** |
| | | * 组合导出数据 |
| | | * 用户问卷答案 |
| | | */ |
| | | R QuestnaireAnswersDTOR = communityService.exportRegisterAdmin(pageReserveRegisterDetailedAdminDTO); |
| | | QuestnaireAnswersDTO questnaireAnswersDTOS = JSON.parseObject(JSON.toJSONString(QuestnaireAnswersDTOR.getData()), QuestnaireAnswersDTO.class); |
| | | |
| | | List<ComActQuestnaireSubVO> subVOList = questnaireAnswersDTOS.getSubs(); |
| | | //构造表头 |
| | | List<List<String>> headList = new ArrayList<List<String>>(); |
| | | String firstRowContent = "重点地区或高风险地区来攀返攀人员信息统计表(居家隔离表)"; |
| | | List<String> head0 = new ArrayList<>(); |
| | | head0.add(firstRowContent); |
| | | head0.add("登记人昵称"); |
| | | headList.add(head0); |
| | | List<String> head1 = new ArrayList<>(); |
| | | head1.add(firstRowContent); |
| | | head1.add("登记时间"); |
| | | headList.add(head1); |
| | | subVOList.forEach(sub -> { |
| | | if (sub.getType() != 5 && sub.getType() != 11&&!sub.getContent().contains("今日上午")&&!sub.getContent().contains("今日下午")&&!sub.getContent().contains("今日隔离情况")) { |
| | | List<String> headn = new ArrayList<>(); |
| | | headn.add(firstRowContent); |
| | | if(!sub.getContent().equals(noHaed)){ |
| | | if(sub.getType() == 11){ |
| | | headn.add(sub.getContent().substring(0, sub.getContent().indexOf("("))); |
| | | }else{ |
| | | headn.add(sub.getContent()); |
| | | } |
| | | headList.add(headn); |
| | | } |
| | | } |
| | | }); |
| | | List<String> head2 = new ArrayList<>(); |
| | | head2.add(firstRowContent); |
| | | head2.add("隔离体温情况"); |
| | | headList.add(head2); |
| | | //数据转换 |
| | | List<List<Object>> datalist = HomeQuarantineUtil.ReserveData(questnaireAnswersDTOS.getAnswers()); |
| | | |
| | | WriteCellStyle headWriteCellStyle = new WriteCellStyle(); |
| | | //设置头居中 |
| | | headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); |
| | | //设置头字体 |
| | | WriteFont headWriteFont = new WriteFont(); |
| | | headWriteFont.setFontHeightInPoints((short)6); |
| | | headWriteFont.setBold(true); |
| | | headWriteCellStyle.setWriteFont(headWriteFont); |
| | | |
| | | |
| | | WriteCellStyle contentWriteCellStyle = new WriteCellStyle(); |
| | | //设置表格内容字体 |
| | | WriteFont writeFont = new WriteFont(); |
| | | writeFont.setFontHeightInPoints((short)6); |
| | | //设置 水平居中 |
| | | contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); |
| | | //设置 垂直居中 |
| | | contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); |
| | | contentWriteCellStyle.setWriteFont(writeFont); |
| | | |
| | | contentWriteCellStyle.setWrapped(true); |
| | | HorizontalCellStyleStrategy horizontalCellStyleStrategy = |
| | | new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle); |
| | | |
| | | |
| | | excelWriter = EasyExcel.write(fileName) |
| | | .registerWriteHandler(horizontalCellStyleStrategy).registerWriteHandler(new Custemhandler()) |
| | | .build(); |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("登记明细导出数据").head(headList).build(); |
| | | excelWriter.write(datalist, writeSheet); |
| | | excelWriter.finish(); |
| | | File file = new File(fileName); |
| | | inputStream = new FileInputStream(file); |
| | | sftp.uploadMore(ftpUrl, name, inputStream); |
| | | sftp.logout(); |
| | | inputStream.close(); |
| | | String absolutePath = file.getAbsolutePath(); |
| | | boolean delete = file.delete(); |
| | | log.info("删除excel【{}】结果【{}】", absolutePath, delete); |
| | | } finally { |
| | | // 千万别忘记finish 会帮忙关闭流 |
| | | if (inputStream != null) { |
| | | inputStream.close(); |
| | | } |
| | | if (excelWriter != null) { |
| | | excelWriter.finish(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(sftpConfig.getExcelUrl() + name); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "查询题目列表", response = ComActReserveSubListVO.class) |
| | | @GetMapping("/subject/list") |
| | | public R subjectList(@RequestParam("reserveId") Long reserveId) { |