From a7150dec0516c4bb1d1dfaf2150b62a499ff7682 Mon Sep 17 00:00:00 2001 From: Kane Wang Date: Fri, 8 Aug 2025 19:26:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=BF=9B=E5=BA=A6=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/east-datafile-spliter/.mvn/jvm.config | 0 code/east-datafile-spliter/.mvn/maven.config | 0 .../.vscode/fileheader.template.js | 87 ++++++++++ .../.vscode/settings.json | 3 + code/east-datafile-spliter/pom.xml | 152 ++++++++++++++++++ .../src/main/java/com/cpic/xim/App.java | 33 ++++ .../cpic/xim/east/utils/DataFileSpliter.java | 85 ++++++++++ 7 files changed, 360 insertions(+) create mode 100644 code/east-datafile-spliter/.mvn/jvm.config create mode 100644 code/east-datafile-spliter/.mvn/maven.config create mode 100644 code/east-datafile-spliter/.vscode/fileheader.template.js create mode 100644 code/east-datafile-spliter/.vscode/settings.json create mode 100644 code/east-datafile-spliter/pom.xml create mode 100644 code/east-datafile-spliter/src/main/java/com/cpic/xim/App.java create mode 100644 code/east-datafile-spliter/src/main/java/com/cpic/xim/east/utils/DataFileSpliter.java diff --git a/code/east-datafile-spliter/.mvn/jvm.config b/code/east-datafile-spliter/.mvn/jvm.config new file mode 100644 index 0000000..e69de29 diff --git a/code/east-datafile-spliter/.mvn/maven.config b/code/east-datafile-spliter/.mvn/maven.config new file mode 100644 index 0000000..e69de29 diff --git a/code/east-datafile-spliter/.vscode/fileheader.template.js b/code/east-datafile-spliter/.vscode/fileheader.template.js new file mode 100644 index 0000000..aa2379f --- /dev/null +++ b/code/east-datafile-spliter/.vscode/fileheader.template.js @@ -0,0 +1,87 @@ +/* + * @Author: Kane + * @Date: 2025-03-16 00:35:09 + * @LastEditors: Kane + * @FilePath: /cpicxim-huixiabao/.vscode/fileheader.template.js + * @Description: + * + * Copyright (c) ${2023} by Kane, All Rights Reserved. + */ +/** + * This file is generated by VSCode extension: Fileheader Pro + */ + +/** + * These comments can help you write your own template with type hint + * @typedef {Object} FileheaderVariable Fileheader variables + * @property {string} birthtime file birth time. will get it from VCS or fallback to filesystem when it is not available + * @property {string} mtime file modification time. will get it from VCS or fallback to filesystem when it is not available + * @property {string} authorName if the file is tracked by VCS, it will get the author name from VCS. else it will get it from current user name + * @property {string} authorEmail if the file is tracked by VCS, it will get the author email from VCS. else it will get it from current user email + * @property {string} userName else it will get it from current user name + * @property {string} userEmail user email is from VSCode config, and fallback to VCS config + * @property {string} companyName + * @property {string} projectName name of current project + * @property {string} filePath the file path, relative to project root with POSIX path separator + * @property {string} dirPath the directory path, relative to project root with POSIX path separator + * @property {string} fileName filename with extension + */ + + /** + * @typedef {string | number | null | undefined | Template | boolean} TemplateInterpolation NOTE: boolean or falsy value will render empty string + * + * @typedef {{ strings: TemplateStringsArray; interpolations: TemplateInterpolation[]; }} Template + * @typedef {(strings: TemplateStringsArray, ...values: any[]) => string} ITemplateFunction + * + */ + +/** + * Please confirm your provider extends from globalThis.FileheaderLanguageProvider + */ +class CustomLanguageProvider extends globalThis.FileheaderLanguageProvider { + /** + * @type {string[]} + */ + languages = [ + "java", + "javascript", + "typescript", + "javascriptreact", + "typescriptreact", + ]; + + /** + * @type {string=} the language block comment start string. + * this is for future feature: support detect old custom template when custom template changes + */ + blockCommentStart = "/**"; + + /** + * @type {string=} + */ + blockCommentEnd = "*/"; + + /** + * get your template when document language matched + * @param {ITemplateFunction} tpl template function, it is a tagged function, support nested interpolation + * @param {FileheaderVariable} variables template variables + * @returns {Template} + */ + getTemplate(tpl, variables) { + // prettier-ignore + return tpl +`/** + * @Author: ${variables.authorName} <${variables.authorEmail}> + * @Date: ${variables.birthtime} + * @LastEditors: ${variables.userName} + * @LastModified: ${variables.mtime} + * @FilePath: ${variables.filePath} + * @Description: + * + * Copyright (c) ${2025} by Kane All rights reserved + */`; + } +} + +// export your provider classes +module.exports = [CustomLanguageProvider]; diff --git a/code/east-datafile-spliter/.vscode/settings.json b/code/east-datafile-spliter/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/code/east-datafile-spliter/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/code/east-datafile-spliter/pom.xml b/code/east-datafile-spliter/pom.xml new file mode 100644 index 0000000..839250e --- /dev/null +++ b/code/east-datafile-spliter/pom.xml @@ -0,0 +1,152 @@ + + + 4.0.0 + + com.cpic.xim + east-utils + 20250808.1921 + + east + + http://www.example.com + + + UTF-8 + 17 + 2.24.3 + 2.19.2 + + + + + + org.junit + junit-bom + 5.11.0 + pom + import + + + + + + + org.junit.jupiter + junit-jupiter-api + test + + + + org.junit.jupiter + junit-jupiter-params + test + + + + org.apache.poi + poi + 5.4.1 + + + org.apache.poi + poi-ooxml + 5.4.1 + + + org.apache.xmlbeans + xmlbeans + 5.3.0 + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + + + compile + + + maven-surefire-plugin + 3.5.2 + + true + + + + maven-compiler-plugin + 3.14.0 + + 1.8 + 1.8 + UTF-8 + + ${project.basedir}/lib + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.7.1 + + + jar-with-dependencies + + + + com.cpic.xim.huixiabao.AppMain + + + + + + make-assembly + package + + single + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.6.0 + + com.cpic.xim.huixiabao.AppMain + true + + + + repackage + + repackage + + + + + + + \ No newline at end of file diff --git a/code/east-datafile-spliter/src/main/java/com/cpic/xim/App.java b/code/east-datafile-spliter/src/main/java/com/cpic/xim/App.java new file mode 100644 index 0000000..a64cad6 --- /dev/null +++ b/code/east-datafile-spliter/src/main/java/com/cpic/xim/App.java @@ -0,0 +1,33 @@ +/** + * @Author: Kane Wang + * @Date: 2025-08-08 17:21:32 + * @LastEditors: Kane Wang + * @LastModified: 2025-08-08 19:05:06 + * @FilePath: src/main/java/com/cpic/xim/App.java + * @Description: + * + * Copyright (c) 2025 by Kane All rights reserved + */ +package com.cpic.xim; + +import java.io.File; + +/** + * Hello world! + */ +public class App +{ + private static final int MAX_LINE_COUNT_PER_FILE = 250000; + private static final String TITLE_BDJBXXB = "流水号$保险机构代码$保险机构名称$采集日期$保单编号$虚拟单标志$保单件数$险类$保单团个性质$监管辖区$司法管辖$业务性质$续保标志$被续保保单编号$保单状态$保单终止原因$核保类型$联共保类型$涉农标志$分保标志$统保标志$投保单申请日期$签单日期$核保通过时间$保费收费确认时间$保单生成时间$保单起始日期$保单终止日期$保单中止日期$保单效力恢复日期$保单满期日期$约定分期交费次数$累计保费$交费方式$被保险人数量$保险金额$保险金额币种$保险金额人民币金额$保险费率$基准保费$签单保费$税额$政府补贴保费金额$保费币种$保费人民币金额$管理机构代码$管理机构名称$核保机构代码$核保机构名称$承保地区$争议解决方式$佣金比例$佣金$佣金币种$佣金人民币金额$特别约定标志$特别约定$经办业务标志$经办管理费$医保个人账户购买标志"; + + public static void main( String[] args ) + { + String fileNameBDJBXXB = "L:\\east\\MD5_BDJCXX_BDJBXXB_RESULT_3080100.txt"; + + com.cpic.xim.east.utils.DataFileSpliter.splitFile( new File( fileNameBDJBXXB ), + MAX_LINE_COUNT_PER_FILE, + TITLE_BDJBXXB ); + + System.out.println( "拆完了!" ); + } +} diff --git a/code/east-datafile-spliter/src/main/java/com/cpic/xim/east/utils/DataFileSpliter.java b/code/east-datafile-spliter/src/main/java/com/cpic/xim/east/utils/DataFileSpliter.java new file mode 100644 index 0000000..80cf652 --- /dev/null +++ b/code/east-datafile-spliter/src/main/java/com/cpic/xim/east/utils/DataFileSpliter.java @@ -0,0 +1,85 @@ +/** + * @Author: Kane Wang + * @Date: 2025-08-08 17:23:44 + * @LastEditors: Kane Wang + * @LastModified: 2025-08-08 17:25:07 + * @FilePath: src/main/java/com/cpic/xim/east/utils/DataFileSpliter.java + * @Description: + * + * Copyright (c) 2025 by Kane All rights reserved + */ +package com.cpic.xim.east.utils; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; + +/** + * @author Kane + * @description 用于拆分大文件。 + */ +public class DataFileSpliter +{ + + public static void splitFile( File inputFile, int lineCountPerFile , String titleString ) + { + try ( + BufferedReader reader = new BufferedReader( new FileReader( inputFile ) ) + ) + { + String line; + int lineCount = 0; + int fileCount = 1; + + BufferedWriter writer = createWriterForFile( inputFile, fileCount ); + + while ( (line = reader.readLine()) != null ) + { + if ( lineCount >= lineCountPerFile ) + { + writer.close(); + + fileCount++; + lineCount = 0; + + writer = createWriterForFile( inputFile, fileCount ); + } + + // 如果是第一行,则写入标题 + if ( lineCount == 0 && !titleString.isEmpty() ) + { + writer.write( titleString ); + writer.newLine(); + } + + writer.write( line ); + writer.newLine(); + lineCount++; + } + writer.close(); + } + catch ( IOException e ) + { + e.printStackTrace(); + } + } + + private static BufferedWriter createWriterForFile( File inputFile, int fileCount ) + { + try + { + String outputFileName = String.format( "%s_part%d.txt", inputFile.getName(), fileCount ); + FileWriter fileWriter = new FileWriter( new File( inputFile.getParent(), outputFileName ) ); + + return new BufferedWriter( fileWriter ); + } + catch ( IOException e ) + { + e.printStackTrace(); + return null; + } + } +}