{"id":19476064,"url":"https://github.com/hwywl/business-tools","last_synced_at":"2026-06-15T11:32:34.566Z","repository":{"id":57720127,"uuid":"403813200","full_name":"HWYWL/business-tools","owner":"HWYWL","description":"在开发中积攒下来的业务工具类，方便快速编写业务。","archived":false,"fork":false,"pushed_at":"2021-12-16T08:25:25.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-08T06:35:28.497Z","etag":null,"topics":["html","parquet","parquet-generator","parquet-tools"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HWYWL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-07T02:16:44.000Z","updated_at":"2023-08-25T03:16:03.000Z","dependencies_parsed_at":"2022-09-26T21:41:06.598Z","dependency_job_id":null,"html_url":"https://github.com/HWYWL/business-tools","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HWYWL%2Fbusiness-tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HWYWL%2Fbusiness-tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HWYWL%2Fbusiness-tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HWYWL%2Fbusiness-tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HWYWL","download_url":"https://codeload.github.com/HWYWL/business-tools/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240701157,"owners_count":19843651,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","parquet","parquet-generator","parquet-tools"],"created_at":"2024-11-10T19:36:19.459Z","updated_at":"2026-06-15T11:32:34.536Z","avatar_url":"https://github.com/HWYWL.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# business-tools\n在开发中积攒下来的业务工具类，方便快速编写业务。\n\n[![author](https://img.shields.io/badge/author-HWY-red.svg)](https://github.com/HWYWL) [![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu) \n\n## 安装\n**maven**\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.hwywl\u003c/groupId\u003e\n    \u003cartifactId\u003ebusiness-tools\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.3-RELEASE\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n**Gradle**\n```\nimplementation 'com.github.hwywl:business-tools:1.0.3-RELEASE'\n```\n\n## 一个增强parquet文件方便读写的工具类\n通过反射自动生成MessageType，自动拼装数据结构，遵循简单的原则，你给我数据我给你parquet文件。\n目前支持的数据类型如下：\n- int、Integer\n- long、Long\n- float、Float\n- double、Double\n- String\n\n### 使用\n\n可以查看github中的源码，不看也行，很简单的，使用如下：\n```java\npublic class ParquetUtilTest {\n  String filePath = \"F:\\\\a.parquet\";\n\n  /**\n   * 写入一个数据到parquet文件\n   *\n   * @throws IOException\n   * @throws CustomException\n   */\n  @Test\n  public void ParquetWriteTest() throws IOException, CustomException, IntrospectionException {\n    TestModel model = getModel();\n    ParquetUtil.writerParquet(filePath, model);\n  }\n\n  /**\n   * 写入多个数据到parquet文件\n   *\n   * @throws IOException\n   * @throws CustomException\n   */\n  @Test\n  public void ParquetWriteListTest() throws IOException, CustomException, IntrospectionException {\n    List\u003cTestModel\u003e models = getModels();\n    ParquetUtil.writerParquet(filePath, models);\n  }\n\n  /**\n   * 开放原始API，可以用于非一次性写入\n   *\n   * @throws IOException\n   * @throws CustomException\n   * @throws IntrospectionException\n   */\n  @Test\n  public void ParquetWriteGroupListTest() throws IOException, CustomException, IntrospectionException {\n    ParquetWriter\u003cGroup\u003e writer = ParquetUtil.getParquetWriter(filePath, TestModel.class);\n    Group group = ParquetUtil.getGroup(getModel());\n    writer.write(group);\n\n    // close写出文件\n    writer.close();\n  }\n\n  /**\n   * 将parquet文件转为对象集合\n   *\n   * @throws IOException\n   */\n  @Test\n  public void ParquetReadBeanTest() throws IOException {\n    List\u003cTestModel\u003e models = ParquetUtil.readParquetBean(filePath, TestModel.class);\n    System.out.println(models);\n  }\n\n  /**\n   * 将parquet文件转为Map集合\n   *\n   * @throws IOException\n   */\n  @Test\n  public void ParquetReadMapTest() throws IOException {\n    List\u003cMap\u003cString, Object\u003e\u003e maps = ParquetUtil.readParquetMap(filePath);\n    System.out.println(maps);\n  }\n\n  /**\n   * 将parquet文件转为对象集合,并只拿2条数据\n   *\n   * @throws IOException\n   */\n  @Test\n  public void ParquetReadBeanMaxLineTest() throws IOException {\n    List\u003cTestModel\u003e models = ParquetUtil.readParquetBean(filePath, 2, TestModel.class);\n    System.out.println(models);\n  }\n\n  /**\n   * 测试数据\n   *\n   * @return\n   */\n  private TestModel getModel() {\n    return new TestModel(2, 3, 6L, \"校花\", 10);\n  }\n\n  /**\n   * 测试数据\n   *\n   * @return\n   */\n  private List\u003cTestModel\u003e getModels() {\n    List\u003cTestModel\u003e arrayList = new ArrayList\u003c\u003e();\n\n    for (int i = 0; i \u003c 10; i++) {\n      arrayList.add(new TestModel(2, 3, 6L, \"校花\", 10));\n    }\n\n    return arrayList;\n  }\n}\n```\n\n\n## HTML表格生成，可用于邮件发送或者直接展示前端 \n### 示例1：\n```\npublic class HtmlTest {\n    @Test\n    public void htmlReadTest() {\n        String template = EmailTemplateUtil.htmlMapTemplate(\"测试\", getModels());\n        System.out.println(template);\n    }\n\n    /**\n     * 测试数据\n     *\n     * @return 测试数据\n     */\n    private List\u003cMap\u003cString, Object\u003e\u003e getModels() {\n        List\u003cMap\u003cString, Object\u003e\u003e arrayList = new ArrayList\u003c\u003e();\n\n        for (int i = 0; i \u003c 10; i++) {\n            Map\u003cString, Object\u003e map = new LinkedHashMap\u003c\u003e();\n            map.put(\"校花\", \"张花\");\n            map.put(\"美女\", \"李花\");\n            map.put(\"小萝莉\", \"茉莉花\");\n            map.put(\"御姐\", null);\n            map.put(\"班花\", 111);\n\n            arrayList.add(map);\n        }\n\n        return arrayList;\n    }\n}\n```\n![](https://hwy-figure-bed.oss-cn-hangzhou.aliyuncs.com/blog/image/1630996191028-ceshi2.png)\n\n### 示例2：\n```\npublic class HtmlTest {\n    @Test\n    public void htmlReadBeanTest() {\n        String template = EmailTemplateUtil.htmlBeanTemplate(\"测试\", getBeanModels());\n        System.out.println(template);\n    }\n\n    /**\n     * 测试数据\n     *\n     * @return\n     */\n    private List\u003cHtmlModel\u003e getBeanModels() {\n        List\u003cHtmlModel\u003e arrayList = new ArrayList\u003c\u003e();\n\n        for (int i = 0; i \u003c 10; i++) {\n            arrayList.add(new HtmlModel(2, 3, 6L, \"校花\", 10));\n        }\n\n        return arrayList;\n    }\n}\n```\n\nHtmlModel类\n```\npublic class HtmlModel {\n    @HtmlAnnotation(\"游戏id\")\n    int app_id;\n    @HtmlAnnotation(\"VIP等级\")\n    Integer svip_level;\n    @HtmlAnnotation(\"VIP剩余时间\")\n    Long svip_remain;\n    @HtmlAnnotation(\"游戏名称\")\n    String name;\n    @HtmlAnnotation(\"充值金额\")\n    double money;\n}\n```\n![](https://hwy-figure-bed.oss-cn-hangzhou.aliyuncs.com/blog/image/1630996121533-ceshi.png)\n\n\n## 一个简单封装的多线程并行工具类\n在我们业务中很多场景为了速度是需要多线程并行运算的，最后再把各个结果集合起来返回。\n示例：\n```java\npublic class ParallelThreadTest {\n    /**\n     * 测试并发执行运算\n     */\n    @Test\n    public void parallelTest() throws InterruptedException {\n        List\u003cHtmlModel\u003e list = new ArrayList\u003c\u003e();\n\n        // 模拟四个线程并发执行，最后得到一个结果集\n        Runnable runnable1 = () -\u003e list.addAll(getBeanModels());\n        Runnable runnable2 = () -\u003e list.addAll(getBeanModels());\n        Runnable runnable3 = () -\u003e list.addAll(getBeanModels());\n        Runnable runnable4 = () -\u003e list.addAll(getBeanModels());\n\n        List\u003cRunnable\u003e tasks = Arrays.asList(runnable1, runnable2, runnable3, runnable4);\n\n        int secs = ParallelThread.parallelThreadTask(tasks);\n\n        // 这句代码在正式环境中没有意义，这里是为了防止主线程结束\n        // Junit不支持多线程\n        Thread.sleep(3000);\n\n        System.out.println(\"线程耗时：\" + secs + \"毫秒\");\n        System.out.println(list);\n    }\n\n    /**\n     * 测试数据\n     *\n     * @return\n     */\n    private List\u003cHtmlModel\u003e getBeanModels() {\n        List\u003cHtmlModel\u003e arrayList = new ArrayList\u003c\u003e();\n\n        for (int i = 0; i \u003c 2; i++) {\n            arrayList.add(new HtmlModel(2, 3, 6L, \"校花\", 10));\n        }\n\n        return arrayList;\n    }\n}\n```\n\n## 1.0.3-RELEASE 版本更新\n1. 增加一个简单的多线程并发执行工具\n2. 升级开源工具类\n\n## 1.0.2-RELEASE 版本更新\n1. 开放parquet文件写入的原始API\n2. 修复写入parquet文件乱序问题\n\n## 1.0.1-RELEASE 版本更新\n1. 增加parquet文件的读写\n2. 增加html表格的生成。\n\n### 感谢\n- 工具还有不足之处，请大家Issues ヾ(๑╹◡╹)ﾉ\"\n- 我那么可爱你不点个star吗 φ(\u003eω\u003c*) \n\n\n### 问题建议\n\n- 联系我的邮箱：ilovey_hwy@163.com\n- 我的博客：https://www.hwy.ac.cn\n- GitHub：https://github.com/HWYWL","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwywl%2Fbusiness-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhwywl%2Fbusiness-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhwywl%2Fbusiness-tools/lists"}