Skip to content

Commit 94928e6

Browse files
committed
code refactor
1 parent 72d9f20 commit 94928e6

30 files changed

+288
-83
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,12 @@ Slightly Framework design to support Spring based java or Bigdata program.
161161
162162
4.Query Configuration XML
163163
4.1 Config Spring Bean
164-
using Config file
165-
<bean id="queryFactory" class="com.robin.core.query.util.QueryFactory" autowire="byName">
166-
<property name="xmlConfigPath" value="classpath:query"></property>
167-
</bean>
164+
using Config file
165+
```xml
166+
<bean id="queryFactory" class="com.robin.core.query.util.QueryFactory" autowire="byName">
167+
<property name="xmlConfigPath" value="classpath:query"></property>
168+
</bean>
169+
```
168170
xmlConfigPath support three input
169171
I.if not assign value,read config xml from classpath:queryConfig
170172
II. classpath:query
@@ -178,14 +180,16 @@ Slightly Framework design to support Spring based java or Bigdata program.
178180
return factory;
179181
}
180182
4.1 config XML File
181-
in xmlConfigPath Path ,add xml file
182-
content
183-
<SQLSCRIPT ID="$_GETCODESET">
184-
<FROMSQL>from t_sys_code a,t_sys_codeset b where a.CS_ID=b.ID and ${queryString}</FROMSQL>
185-
<FIELD>a.ITEM_NAME as ITEMNAME,a.ITEM_VALUE as ITEMVALUE</FIELD>
186-
</SQLSCRIPT>
183+
in xmlConfigPath Path ,add xml file content
184+
```XML
185+
<SQLSCRIPT ID="$_GETCODESET">
186+
<FROMSQL>from t_sys_code a,t_sys_codeset b where a.CS_ID=b.ID and ${queryString}</FROMSQL>
187+
<FIELD>a.ITEM_NAME as ITEMNAME,a.ITEM_VALUE as ITEMVALUE</FIELD>
188+
</SQLSCRIPT>
189+
```
187190
SQLSCRIPT ID refrer to queryBySelectId selectId.example see core test.
188191
5.mybatis like QueryMapper
192+
```xml
189193
<mapper namespace="com.robin.test.query1">
190194
<resultMap id="rsMap1" type="com.robin.core.test.model.TestModel">
191195
<result column="id" property="id" jdbcType="BIGINT" />
@@ -274,6 +278,7 @@ Slightly Framework design to support Spring based java or Bigdata program.
274278

275279
</delete>
276280
</mapper>
281+
```
277282
no need to generate Mapper class,Only need QueryMapper xml file
278283
exmaple: core/src/test/java/com/robin/core/test/db/JdbcDaoTest testQueryAndInsertMapper
279284

common/pom.xml

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,12 @@
325325
<version>2.4.1</version>
326326
<optional>true</optional>
327327
</dependency>
328-
<dependency>
328+
<!--<dependency>
329329
<groupId>com.fasterxml</groupId>
330330
<artifactId>aalto-xml</artifactId>
331331
<version>1.3.3</version>
332332
<optional>true</optional>
333-
</dependency>
333+
</dependency>-->
334334
</dependencies>
335335
<build>
336336
<sourceDirectory>src/main/java</sourceDirectory>
@@ -420,6 +420,63 @@
420420
</dependency>
421421
</dependencies>
422422
</plugin>
423+
<plugin>
424+
<groupId>org.apache.maven.plugins</groupId>
425+
<artifactId>maven-dependency-plugin</artifactId>
426+
<executions>
427+
<execution>
428+
<id>copy</id>
429+
<phase>install</phase>
430+
<goals>
431+
<goal>copy-dependencies</goal>
432+
</goals>
433+
<configuration>
434+
<outputDirectory>
435+
${project.build.directory}/lib
436+
</outputDirectory>
437+
</configuration>
438+
</execution>
439+
</executions>
440+
</plugin>
441+
<plugin>
442+
<artifactId>maven-deploy-plugin</artifactId>
443+
<version>2.8.2</version>
444+
<configuration>
445+
<!-- altDeploymentRepository :指定替代方案应该部署项目工件的存储库(除了指定的工件)。 -->
446+
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo
447+
</altDeploymentRepository>
448+
</configuration>
449+
</plugin>
450+
<plugin>
451+
<groupId>com.github.github</groupId>
452+
<artifactId>site-maven-plugin</artifactId>
453+
<version >0.12</version>
454+
<configuration>
455+
<message >Maven artifacts for ${project.version}</message>
456+
<noJekyll>true</noJekyll>
457+
<!--本地jar相关文件地址,与上方配置储存库位置(altDeploymentRepository)保持一致-->
458+
<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory>
459+
<!--配置上传到github哪个分支,此处配置格式必须以refs/heads/+分支名称-->
460+
<branch>refs/heads/main</branch>
461+
<merge>true</merge>
462+
<includes>
463+
<include>**/*</include>
464+
</includes>
465+
<!--对应github上创建的仓库名称 name-->
466+
<repositoryName>mvn-repo</repositoryName>
467+
<!--github 仓库所有者即登录用户名-->
468+
<repositoryOwner>robinhood-jim</repositoryOwner>
469+
<server>github</server>
470+
</configuration>
471+
<executions>
472+
<execution>
473+
<goals>
474+
<goal>site</goal>
475+
</goals>
476+
<phase>deploy</phase>
477+
</execution>
478+
</executions>
479+
</plugin>
423480
</plugins>
424481
</build>
425482
</project>

common/src/main/java/com/robin/comm/util/xls/ExcelBaseOper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private ExcelBaseOper() {
5656

5757
public static final String TYPE_EXCEL2003 = "xls";
5858
public static final String TYPE_EXCEL2007 = "xlsx";
59-
public static final String defaultFontName = Locale.CHINA.equals(Locale.getDefault()) || Locale.SIMPLIFIED_CHINESE.equals(Locale.getDefault()) ? "宋体" : java.awt.Font.SANS_SERIF;
59+
public static final String defaultFontName = Locale.CHINA.equals(Locale.getDefault()) || Locale.SIMPLIFIED_CHINESE.equals(Locale.getDefault()) ? "宋体" : "Calibri";
6060
private static final Logger logger = LoggerFactory.getLogger(ExcelBaseOper.class);
6161
private static final Pattern paramPattern=Pattern.compile("\\w+(\\{P([\\+|-]?[\\d+])?\\})");
6262

common/src/main/java/com/robin/comm/util/xls/ExcelColumnProp.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ExcelColumnProp {
2525
private String columnCode;
2626
private String columnType;
2727
private String formula;
28+
private String format;
2829
private boolean needMerge;
2930

3031

common/src/main/java/com/robin/comm/util/xls/ExcelSheetProp.java

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public class ExcelSheetProp {
3737
private int sheetNum=0;
3838
private boolean fillHeader=true;
3939
private String templateFile;
40-
public ExcelSheetProp(){
40+
private boolean useOffHeap=false;
41+
private String fontName;
42+
private ExcelSheetProp(){
4143

4244
}
4345
public ExcelSheetProp(String[] headerName,String[] columnName,String fileExt){
@@ -59,7 +61,79 @@ public void addColumnProp(ExcelColumnProp prop){
5961
public List<ExcelColumnProp> getColumnPropList() {
6062
return columnPropList;
6163
}
64+
public static class Builder{
65+
private ExcelSheetProp prop=new ExcelSheetProp();
66+
private Builder(){
6267

68+
}
69+
public static Builder newBuilder(){
70+
Builder builder=new Builder();
71+
return builder;
72+
}
73+
public Builder setFileExt(String fileExt){
74+
prop.setFileExt(fileExt);
75+
return this;
76+
}
77+
public Builder addColumnProp(String columnName,String columnCode,String columnType){
78+
prop.getColumnPropList().add(new ExcelColumnProp(columnName,columnCode,columnType));
79+
return this;
80+
}
81+
public Builder addColumnProp(String columnName,String columnCode,String columnType,String formula){
82+
prop.getColumnPropList().add(new ExcelColumnProp(columnName,columnCode,columnType,formula));
83+
return this;
84+
}
85+
public Builder addColumnProp(ExcelColumnProp columnProp){
86+
prop.getColumnPropList().add(columnProp);
87+
return this;
88+
}
89+
public Builder addColumnProp(String columnName,String columnCode,String columnType,boolean needMerge){
90+
prop.getColumnPropList().add(new ExcelColumnProp(columnName,columnCode,columnType,needMerge));
91+
return this;
92+
}
93+
public Builder setStartRow(int row){
94+
prop.setStartRow(row);
95+
return this;
96+
}
97+
public Builder setStartCol(int col){
98+
prop.setStartCol(col);
99+
return this;
100+
}
101+
public Builder setSheetName(String sheetName){
102+
prop.setSheetName(sheetName);
103+
return this;
104+
}
105+
public Builder setStreamMode(){
106+
prop.setStreamMode(true);
107+
return this;
108+
}
109+
public Builder setStreamRows(int streamRows){
110+
prop.setStreamRows(streamRows);
111+
return this;
112+
}
113+
public Builder setBatchMode(){
114+
prop.setStreamMode(false);
115+
return this;
116+
}
117+
public Builder doNotFillHeader(){
118+
prop.setFillHeader(false);
119+
return this;
120+
}
121+
public Builder useTemplateFile(String templateFile){
122+
prop.setTemplateFile(templateFile);
123+
return this;
124+
}
125+
public Builder dumpUseOffHeap(){
126+
prop.setUseOffHeap(true);
127+
return this;
128+
}
129+
public Builder dumpUseTempFile(){
130+
prop.setUseOffHeap(false);
131+
return this;
132+
}
133+
public ExcelSheetProp build(){
134+
return prop;
135+
}
136+
}
63137

64138

65139
}

common/src/main/java/com/robin/core/fileaccess/iterator/XlsxFileIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public XlsxFileIterator(DataCollectionMeta meta, AbstractFileSystemAccessor acce
5959
public void beforeProcess() {
6060
super.beforeProcess();
6161
try {
62-
factory = new com.fasterxml.aalto.stax.InputFactoryImpl();
62+
factory = XMLInputFactory.newFactory();
6363
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE);
6464
factory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);
6565
opcPackage=OPCPackage.open(instream);

common/src/main/java/com/robin/core/fileaccess/writer/AbstractFileWriter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public abstract class AbstractFileWriter implements IResourceWriter {
4848
protected DateTimeFormatter formatter;
4949
protected AbstractFileSystemAccessor accessUtil;
5050
protected String identifier;
51+
protected boolean useBufferedWriter=false;
5152

5253
public AbstractFileWriter(){
5354

@@ -105,7 +106,9 @@ public void beginWrite() throws IOException{
105106
if(out==null){
106107
checkAccessUtil(colmeta.getPath());
107108
out = accessUtil.getOutResourceByStream(ResourceUtil.getProcessPath(colmeta.getPath()));
108-
writer=new BufferedWriter(new OutputStreamWriter(out));
109+
if(useBufferedWriter) {
110+
writer = new BufferedWriter(new OutputStreamWriter(out));
111+
}
109112
}
110113
logger.info("using Writer {}",getClass().getCanonicalName());
111114
}

common/src/main/java/com/robin/core/fileaccess/writer/JsonFileWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public JsonFileWriter(DataCollectionMeta colmeta) {
3636
public JsonFileWriter(DataCollectionMeta colmeta, AbstractFileSystemAccessor accessor) {
3737
super(colmeta,accessor);
3838
this.identifier= Const.FILEFORMATSTR.JSON.getValue();
39+
this.useBufferedWriter=true;
3940
}
4041

4142
@Override

common/src/main/java/com/robin/core/fileaccess/writer/TextBasedFileWriter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ public TextBasedFileWriter(){
3131

3232
protected TextBasedFileWriter(DataCollectionMeta colmeta) {
3333
super(colmeta);
34+
this.useBufferedWriter=true;
3435
}
3536
protected TextBasedFileWriter(DataCollectionMeta colmeta, AbstractFileSystemAccessor accessor) {
3637
super(colmeta,accessor);
38+
this.useBufferedWriter=true;
3739
}
3840
@Override
3941
public void setOutputStream(OutputStream out) {

common/src/main/java/com/robin/core/fileaccess/writer/XlsxFileWriter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
import java.util.zip.ZipInputStream;
3737
import java.util.zip.ZipOutputStream;
3838

39+
3940
/**
4041
* Xlsx StaX writer,Support divided Sheet write,MAX_LINE max sheet lines
4142
*/
42-
public class XlsxFileWriter extends TextBasedFileWriter{
43+
public class XlsxFileWriter extends AbstractFileWriter{
4344
private XMLStreamWriter streamWriter;
4445
private XSSFWorkbook workbook;
4546
private OPCPackage opcPackage;
@@ -55,6 +56,7 @@ public class XlsxFileWriter extends TextBasedFileWriter{
5556
private ByteArrayOutputStream byteOut;
5657
private FileOutputStream tmpZipFile;
5758
private String tmpFileName;
59+
private XMLOutputFactory factory;
5860
private int MAX_LINE=Double.valueOf(Math.pow(2,18)).intValue();
5961
public XlsxFileWriter(){
6062
this.identifier= Const.FILEFORMATSTR.XLSX.getValue();
@@ -84,7 +86,7 @@ public XlsxFileWriter(DataCollectionMeta colmeta, AbstractFileSystemAccessor acc
8486
public void beginWrite() throws IOException {
8587
super.beginWrite();
8688
try {
87-
XMLOutputFactory factory=new com.fasterxml.aalto.stax.OutputFactoryImpl();
89+
factory=XMLOutputFactory.newFactory();
8890
workbook = new XSSFWorkbook();
8991
Field field = workbook.getClass().getSuperclass().getDeclaredField("pkg");
9092
field.setAccessible(true);
@@ -123,6 +125,7 @@ private void createSheet() throws Exception {
123125
PackagePartName packagePartName = PackagingURIHelper.createPartName("/xl/worksheets/sheet"+sheetNum+".xml");
124126
opcPackage.removePart(packagePartName);
125127
zipOutputStream.putNextEntry(new ZipEntry("xl/worksheets/sheet"+sheetNum+".xml"));
128+
//streamWriter = factory.createXMLStreamWriter(bufferedOutputStream,colmeta.getEncode());
126129
writePrefix();
127130
writeHeader(sheetProp.getColumnPropList().stream().map(ExcelColumnProp::getColumnName).collect(Collectors.toList()),cellStyleMap);
128131
}
@@ -235,6 +238,7 @@ public void writeRecord(Map<String, Object> map) throws IOException, OperationNo
235238
streamWriter.writeEndElement();
236239
streamWriter.writeEndElement();
237240
streamWriter.flush();
241+
//streamWriter.close();
238242
bufferedOutputStream.flush();
239243
zipOutputStream.closeEntry();
240244
createSheet();

0 commit comments

Comments
 (0)