| | |
| | | return userService.deleteSpecialInputUser(id); |
| | | } |
| | | |
| | | @ApiOperation(value = "特殊群体 导出特殊群体Excel") |
| | | // @ApiOperation(value = "特殊群体 导出特殊群体Excel") |
| | | // @PostMapping("/special/export") |
| | | // public R exportSpecial(@RequestBody ExportSpecialUserDTO exportSpecialUserDTO) { |
| | | // exportSpecialUserDTO.setCommunityId(this.getCommunityId()); |
| | | // String url = excelUrl; |
| | | // String uuid = UUID.randomUUID().toString().replace("-", ""); |
| | | // String name = uuid + ".xlsx"; |
| | | // String ftpUrl = "/mnt/data/web/excel/"; |
| | | //// 用户搜索了就下载搜索的用户否则下载所有用户 |
| | | // R r = userService.specialUserExport(exportSpecialUserDTO); |
| | | // if (R.isOk(r)) { |
| | | // List<EexcelUserDTO> eexcelUserDTOS = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), EexcelUserDTO.class); |
| | | // try { |
| | | // SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | // sftp.login(); |
| | | // boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | // if (!existDir) { |
| | | // String property = System.getProperty("user.dir"); |
| | | // String fileName = property + File.separator + name; |
| | | // // 这里 需要指定写用哪个class去写 |
| | | // ExcelWriter excelWriter = null; |
| | | // InputStream inputStream = null; |
| | | // try { |
| | | // excelWriter = EasyExcel.write(fileName, EexcelUserDTO.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CustomSheetWriteHandler()).build(); |
| | | // WriteSheet writeSheet = EasyExcel.writerSheet("模板").build(); |
| | | // excelWriter.write(eexcelUserDTOS, 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(url + name); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // log.error("文件传输失败【{}】", e.getMessage()); |
| | | // return R.fail(); |
| | | // } |
| | | // } |
| | | // return R.fail("未查询到用户"); |
| | | // } |
| | | |
| | | @ApiOperation(value = "特殊群体-数据导出") |
| | | @PostMapping("/special/export") |
| | | public R exportSpecial(@RequestBody ExportSpecialUserDTO exportSpecialUserDTO) { |
| | | exportSpecialUserDTO.setCommunityId(this.getCommunityId()); |
| | | String url = excelUrl; |
| | | String uuid = UUID.randomUUID().toString().replace("-", ""); |
| | | String name = uuid + ".xlsx"; |
| | | public R dataExportSpecilPopulation() { |
| | | //获取登陆用户 |
| | | LoginUserInfoVO loginUserInfo = this.getLoginUserInfo(); |
| | | //获取登陆用户绑定社区id |
| | | Long communityId = loginUserInfo.getCommunityId(); |
| | | //生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址 |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | // 用户搜索了就下载搜索的用户否则下载所有用户 |
| | | R r = userService.specialUserExport(exportSpecialUserDTO); |
| | | if (R.isOk(r)) { |
| | | List<EexcelUserDTO> eexcelUserDTOS = JSONArray.parseArray(JSONArray.toJSONString(r.getData()), EexcelUserDTO.class); |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | if (!existDir) { |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + name; |
| | | // 这里 需要指定写用哪个class去写 |
| | | ExcelWriter excelWriter = null; |
| | | InputStream inputStream = null; |
| | | try { |
| | | excelWriter = EasyExcel.write(fileName, EexcelUserDTO.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CustomSheetWriteHandler()).build(); |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("模板").build(); |
| | | excelWriter.write(eexcelUserDTOS, 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(); |
| | | String name = "特殊群体导出数据.xlsx"; |
| | | try { |
| | | SFTPUtil sftp = new SFTPUtil(userName, password, host, port); |
| | | sftp.login(); |
| | | boolean existDir = sftp.isExistDir(ftpUrl + name); |
| | | if (!existDir) { |
| | | String property = System.getProperty("user.dir"); |
| | | String fileName = property + File.separator + name; |
| | | // 这里 需要指定写用哪个class去写 |
| | | ExcelWriter excelWriter = null; |
| | | InputStream inputStream = null; |
| | | try { |
| | | List<ComMngPopulationVO> populList = JSON.parseArray(JSON.toJSONString(communityService.getPopulationListByCommunityId(communityId).getData()),ComMngPopulationVO.class); |
| | | List<ComMngPopulationExcelVo> populationExcelVoList = new ArrayList<>(); |
| | | if(populList != null && populList.size() > 0){ |
| | | for (ComMngPopulationVO popul:populList){ |
| | | if(popul.getLabel() == null){ |
| | | continue; |
| | | } |
| | | ComMngPopulationExcelVo populationExcelVo = new ComMngPopulationExcelVo(); |
| | | BeanUtils.copyProperties(popul,populationExcelVo); |
| | | //设置性别 |
| | | populationExcelVo.setSex(PopulSexEnum.getCnDescByName(popul.getSex())); |
| | | //设置政治面貌 |
| | | populationExcelVo.setPoliticalOutlook(PopulPoliticalOutlookEnum.getCnDescByName(popul.getPoliticalOutlook())); |
| | | //设置是否租住 |
| | | populationExcelVo.setIsRent(PopulIsOkEnum.getCnDescByName(popul.getIsRent())); |
| | | populationExcelVoList.add(populationExcelVo); |
| | | } |
| | | } |
| | | |
| | | excelWriter = EasyExcel.write(fileName, ComMngPopulationExcelVo.class).registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CustomSheetWriteHandler()).build(); |
| | | WriteSheet writeSheet = EasyExcel.writerSheet("特殊群体导出数据").build(); |
| | | excelWriter.write(populationExcelVoList, 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(url + name); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | return R.ok(excelUrl + name); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | return R.fail("未查询到用户"); |
| | | } |
| | | |
| | | @ApiOperation(value = "特殊群体/分页查询标签列表", response = ComMngTagVO.class) |