| | |
| | | @Value("${excel.userurl}") |
| | | private String excelUrl; |
| | | @Value("${excel.carUrl}") |
| | | private String carUrl = "http://panzhihua.nhys.cdnhxx.com/web/%e8%bd%a6%e8%be%86%e5%af%bc%e5%85%a5%e6%a8%a1%e6%9d%bf.xlsx"; |
| | | private String carUrl; |
| | | // = "http://panzhihua.nhys.cdnhxx.com/web/%e8%bd%a6%e8%be%86%e5%af%bc%e5%85%a5%e6%a8%a1%e6%9d%bf.xlsx"; |
| | | @Value("${excel.companyUrl}") |
| | | private String companyUrl = "http://panzhihua.nhys.cdnhxx.com/web/%e5%ae%9e%e6%9c%89%e5%8d%95%e4%bd%8d%e5%af%bc%e5%85%a5%e6%a8%a1%e6%9d%bf.xlsx"; |
| | | @Value("${excel.assetsUrl}") |
| | |
| | | @ApiOperation(value = "下载模板-车辆管理") |
| | | @GetMapping(value = "/car/download/template") |
| | | public R downloadTemplate(HttpServletResponse response) throws IOException, SftpException { |
| | | // //获取登陆用户绑定社区id |
| | | // Long communityId = 2L;//this.getCommunityId(); |
| | | // //生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址 |
| | | // String ftpUrl = "/mnt/data/web/excel/"; |
| | | // 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("car.dir"); |
| | | // String fileName = property + File.separator + name; |
| | | // // 这里 需要指定写用哪个class去写 |
| | | // ExcelWriter excelWriter = null; |
| | | // InputStream inputStream = null; |
| | | // try { |
| | | // List<List<String>> list = new ArrayList<>(); |
| | | // List<String> head0 = new ArrayList<String>(); |
| | | // head0.add("小区名称"); |
| | | // List<String> head1 = new ArrayList<String>(); |
| | | // head1.add("车主姓名"); |
| | | // List<String> head2 = new ArrayList<String>(); |
| | | // head2.add("身份证号码"); |
| | | // List<String> head3 = new ArrayList<String>(); |
| | | // head3.add("联系方式"); |
| | | // List<String> head4 = new ArrayList<String>(); |
| | | // head4.add("车牌号"); |
| | | // List<String> head5 = new ArrayList<String>(); |
| | | // head5.add("品牌型号"); |
| | | // List<String> head6 = new ArrayList<String>(); |
| | | // head6.add("车身颜色"); |
| | | // list.add(head0); |
| | | // list.add(head1); |
| | | // list.add(head2); |
| | | // list.add(head3); |
| | | // list.add(head4); |
| | | // list.add(head5); |
| | | // list.add(head6); |
| | | // |
| | | // EasyExcel.write(fileName).head(list).sheet("车辆导入模板"); |
| | | // 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(); |
| | | // } |
| | | // } |
| | | // } |
| | | // return R.ok(carUrl + "车辆导入模板.xlsx"); |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // log.error("文件传输失败【{}】", e.getMessage()); |
| | | // return R.fail(); |
| | | // } |
| | | return R.ok(carUrl); |
| | | //获取登陆用户绑定社区id |
| | | Long communityId = 2L;//this.getCommunityId(); |
| | | //生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址 |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | 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<List<String>> list = new ArrayList<>(); |
| | | List<String> head0 = new ArrayList<String>(); |
| | | head0.add("小区名称"); |
| | | List<String> head1 = new ArrayList<String>(); |
| | | head1.add("车主姓名"); |
| | | List<String> head2 = new ArrayList<String>(); |
| | | head2.add("身份证号码"); |
| | | List<String> head3 = new ArrayList<String>(); |
| | | head3.add("联系方式"); |
| | | List<String> head4 = new ArrayList<String>(); |
| | | head4.add("车牌号"); |
| | | List<String> head5 = new ArrayList<String>(); |
| | | head5.add("品牌型号"); |
| | | List<String> head6 = new ArrayList<String>(); |
| | | head6.add("车身颜色"); |
| | | list.add(head0); |
| | | list.add(head1); |
| | | list.add(head2); |
| | | list.add(head3); |
| | | list.add(head4); |
| | | list.add(head5); |
| | | list.add(head6); |
| | | List<List<Object>> dataList = new ArrayList<>(); |
| | | List<Object> data = new ArrayList<>(); |
| | | data.add("蓝湖国际"); |
| | | data.add("张三"); |
| | | data.add("510802199205054112"); |
| | | data.add("13888000088"); |
| | | data.add("川A66666"); |
| | | data.add("大众s9"); |
| | | data.add("黑色"); |
| | | dataList.add(data); |
| | | |
| | | EasyExcel.write(fileName).head(list).sheet("车辆导入模板").doWrite(dataList); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(excelUrl + "车辆导入模板.xlsx"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "excel导入车辆信息") |
| | |
| | | return communityService.detailComMngRealAssets(id); |
| | | } |
| | | |
| | | @ApiOperation(value = "下载模板-实有资产导入模板") |
| | | @ApiOperation(value = "下载模板-社区资产导入模板") |
| | | @GetMapping(value = "/assets/download/template") |
| | | public R downloadRealAssetsTemplate(HttpServletResponse response) throws IOException, SftpException { |
| | | return R.ok(assetsUrl); |
| | | //获取登陆用户绑定社区id |
| | | Long communityId = 2L;//this.getCommunityId(); |
| | | //生成动态模板excel通过ftp工具上传到主节点,然后返回模板下载地址 |
| | | String ftpUrl = "/mnt/data/web/excel/"; |
| | | 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<List<String>> list = new ArrayList<>(); |
| | | List<String> head0 = new ArrayList<String>(); |
| | | head0.add("资产名称"); |
| | | List<String> head1 = new ArrayList<String>(); |
| | | head1.add("位置"); |
| | | List<String> head2 = new ArrayList<String>(); |
| | | head2.add("分类"); |
| | | List<String> head3 = new ArrayList<String>(); |
| | | head3.add("占地面积"); |
| | | List<String> head4 = new ArrayList<String>(); |
| | | head4.add("数量"); |
| | | List<String> head5 = new ArrayList<String>(); |
| | | head5.add("建筑类型"); |
| | | List<String> head6 = new ArrayList<String>(); |
| | | head6.add("楼层类型"); |
| | | list.add(head0); |
| | | list.add(head1); |
| | | list.add(head2); |
| | | list.add(head3); |
| | | list.add(head4); |
| | | list.add(head5); |
| | | list.add(head6); |
| | | List<List<Object>> dataList = new ArrayList<>(); |
| | | List<Object> data = new ArrayList<>(); |
| | | data.add("张三"); |
| | | data.add("位置"); |
| | | data.add("公共设施"); |
| | | data.add("500"); |
| | | data.add("100"); |
| | | data.add("社区"); |
| | | data.add("高层"); |
| | | dataList.add(data); |
| | | |
| | | EasyExcel.write(fileName).head(list).sheet("社区资产导入模板").doWrite(dataList); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(excelUrl + "社区资产导入模板.xlsx"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("文件传输失败【{}】", e.getMessage()); |
| | | return R.fail(); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation(value = "excel导入实有资产信息") |