Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ Slightly Framework design to support Spring based java or Bigdata program.

4.Query Configuration XML
4.1 Config Spring Bean
using Config file
<bean id="queryFactory" class="com.robin.core.query.util.QueryFactory" autowire="byName">
<property name="xmlConfigPath" value="classpath:query"></property>
</bean>
using Config file
```xml
<bean id="queryFactory" class="com.robin.core.query.util.QueryFactory" autowire="byName">
<property name="xmlConfigPath" value="classpath:query"></property>
</bean>
```
xmlConfigPath support three input
I.if not assign value,read config xml from classpath:queryConfig
II. classpath:query
Expand All @@ -178,14 +180,16 @@ Slightly Framework design to support Spring based java or Bigdata program.
return factory;
}
4.1 config XML File
in xmlConfigPath Path ,add xml file
content
<SQLSCRIPT ID="$_GETCODESET">
<FROMSQL>from t_sys_code a,t_sys_codeset b where a.CS_ID=b.ID and ${queryString}</FROMSQL>
<FIELD>a.ITEM_NAME as ITEMNAME,a.ITEM_VALUE as ITEMVALUE</FIELD>
</SQLSCRIPT>
in xmlConfigPath Path ,add xml file content
```XML
<SQLSCRIPT ID="$_GETCODESET">
<FROMSQL>from t_sys_code a,t_sys_codeset b where a.CS_ID=b.ID and ${queryString}</FROMSQL>
<FIELD>a.ITEM_NAME as ITEMNAME,a.ITEM_VALUE as ITEMVALUE</FIELD>
</SQLSCRIPT>
```
SQLSCRIPT ID refrer to queryBySelectId selectId.example see core test.
5.mybatis like QueryMapper
```xml
<mapper namespace="com.robin.test.query1">
<resultMap id="rsMap1" type="com.robin.core.test.model.TestModel">
<result column="id" property="id" jdbcType="BIGINT" />
Expand Down Expand Up @@ -274,6 +278,7 @@ Slightly Framework design to support Spring based java or Bigdata program.

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

Expand Down
64 changes: 64 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,14 @@
<groupId>com.github.chrisvest</groupId>
<artifactId>stormpot</artifactId>
<version>2.4.1</version>
<optional>true</optional>
</dependency>
<!--<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>aalto-xml</artifactId>
<version>1.3.3</version>
<optional>true</optional>
</dependency>-->
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -413,6 +420,63 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<!-- altDeploymentRepository :指定替代方案应该部署项目工件的存储库(除了指定的工件)。 -->
<altDeploymentRepository>internal.repo::default::file://${project.build.directory}/mvn-repo
</altDeploymentRepository>
</configuration>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version >0.12</version>
<configuration>
<message >Maven artifacts for ${project.version}</message>
<noJekyll>true</noJekyll>
<!--本地jar相关文件地址,与上方配置储存库位置(altDeploymentRepository)保持一致-->
<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory>
<!--配置上传到github哪个分支,此处配置格式必须以refs/heads/+分支名称-->
<branch>refs/heads/main</branch>
<merge>true</merge>
<includes>
<include>**/*</include>
</includes>
<!--对应github上创建的仓库名称 name-->
<repositoryName>mvn-repo</repositoryName>
<!--github 仓库所有者即登录用户名-->
<repositoryOwner>robinhood-jim</repositoryOwner>
<server>github</server>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
12 changes: 8 additions & 4 deletions common/src/main/java/com/robin/comm/util/config/YamlUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.*;
import java.util.Map;


Expand All @@ -16,7 +14,10 @@ public static Map<String,Object> parseYamlFileWithClasspath(String classPathFile
Map<String,Object> map= yaml.load(clazz.getClassLoader().getResourceAsStream(classPathFile));
return map;
}
public static Map<String,Object> parseYamlFileWithStream(InputStream in){
public static Map<String,Object> parseYamlFromFile(String filePath) throws IOException {
return parseYamlFromStream(new FileInputStream(filePath));
}
public static Map<String,Object> parseYamlFromStream(InputStream in){
Map<String,Object> map= yaml.load(in);
return map;
}
Expand All @@ -31,5 +32,8 @@ public static <T> T loadFromStream(InputStream inputStream,Class<T> clazz){
Yaml tyaml=new Yaml(new Constructor(clazz.getClass()));
return tyaml.load(inputStream);
}
public static <T> T loadFromClassPath(String classPath,Class<T> clazz){
return loadFromStream(clazz.getClassLoader().getResourceAsStream(classPath),clazz);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import javax.annotation.concurrent.ThreadSafe;
import java.io.*;
import java.lang.invoke.MethodHandle;
import java.lang.reflect.Method;
import java.util.*;

Expand Down Expand Up @@ -151,17 +152,17 @@ public void putPlainSet(String key, String... value) {

public byte[] putSetWithSchema(Schema schema, Schema nestedSchema, List<? extends Serializable> valueObject) throws Exception {
Assert.notEmpty(valueObject, "array is null");
Map<String, Method> getMethods = ReflectUtils.returnGetMethods(valueObject.get(0).getClass());
Map<String, MethodHandle> getMethods = ReflectUtils.returnGetMethodHandle(valueObject.get(0).getClass());

try {
GenericRecord rd = new GenericData.Record(nestedSchema);
List<GenericRecord> retList = new ArrayList<>();
for (Serializable obj : valueObject) {
GenericRecord genericRecord = new GenericData.Record(schema);
Iterator<Map.Entry<String, Method>> iter = getMethods.entrySet().iterator();
Iterator<Map.Entry<String, MethodHandle>> iter = getMethods.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, Method> entry = iter.next();
genericRecord.put(entry.getKey(), AvroUtils.acquireGenericRecord(entry.getKey(), entry.getValue().invoke(obj, null), schema));
Map.Entry<String, MethodHandle> entry = iter.next();
genericRecord.put(entry.getKey(), AvroUtils.acquireGenericRecord(entry.getKey(), entry.getValue().bindTo(obj).invoke(), schema));
}
retList.add(genericRecord);
}
Expand All @@ -174,8 +175,8 @@ public byte[] putSetWithSchema(Schema schema, Schema nestedSchema, List<? extend
System.out.println(record);
return bytes;
//getJedis().sadd(key.getBytes(),AvroUtils.dataToByteWithBijection(nestedSchema,))
} catch (Exception ex) {
throw ex;
} catch (Throwable ex) {
throw new IllegalAccessException(ex.getMessage());
}
}

Expand Down
25 changes: 13 additions & 12 deletions common/src/main/java/com/robin/comm/util/xls/ExcelBaseOper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.springframework.util.CollectionUtils;

import java.awt.Color;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -57,7 +56,7 @@ private ExcelBaseOper() {

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

Expand All @@ -76,7 +75,7 @@ public static Workbook createWorkBook(ExcelSheetProp prop) {
})
.orElseGet(HSSFWorkbook::new);
} else {
wb = Optional.of(prop.isStreamInsert()).map(f -> {
wb = Optional.of(prop.isStreamMode()).map(f -> {
Workbook wb1 = Optional.ofNullable(prop.getTemplateFile()).map(p1 -> {
try {
SXSSFWorkbook wb3 = new SXSSFWorkbook(new XSSFWorkbook(getTemplateInputStream(prop)), prop.getStreamRows());
Expand Down Expand Up @@ -333,6 +332,14 @@ private static short getAlignment(int align) {
return (short) align;
}

private static Cell createCell(Row row, int column, CellStyle cellStyle, CreationHelper helper, String objvalue) {
Cell cell = row.createCell(column);

cell.setCellValue(objvalue);
cell.setCellStyle(cellStyle);
return cell;
}

public static Cell createCell(Row row1,int j, String value, String colType, CellStyle cellStyle, CreationHelper helper) {
Cell cell;
if (colType.equals(Const.META_TYPE_STRING)) {
Expand Down Expand Up @@ -363,14 +370,6 @@ public static Cell createCell(Row row1,int j, String value, String colType, Cell
return cell;
}

private static Cell createCell(Row row, int column, CellStyle cellStyle, CreationHelper helper, String objvalue) {
Cell cell = row.createCell(column);

cell.setCellValue(objvalue);
cell.setCellStyle(cellStyle);
return cell;
}

private static Cell createCell(Row row, int column, CellStyle cellStyle, CreationHelper helper, double value) {
Cell cell = row.createCell(column);

Expand All @@ -383,8 +382,10 @@ private static Cell createCell(Row row, int column, CellStyle cellStyle, Creatio

private static Cell createFormulaCell(Row row, int column, CellStyle cellStyle, String formula) {
Cell cell = row.createCell(column);
FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
cell.setCellFormula(formula);
cell.setCellStyle(cellStyle);
cell.setCellValue(evaluator.evaluate(cell).getNumberValue());
return cell;
}

Expand All @@ -400,7 +401,7 @@ private static Cell createCell(Row row, int column, CellStyle cellStyle, Creatio

private static Cell createCellDate(Row row, int column, CellStyle cellStyle, CreationHelper helper, String value) {
Cell cell = row.createCell(column);
cellStyle.setDataFormat(helper.createDataFormat().getFormat("yyyy-MM-dd hh:mm:ss"));
//cellStyle.setDataFormat(helper.createDataFormat().getFormat("yyyy-MM-dd hh:mm:ss"));

cell.setCellValue(new Date(Long.parseLong(value)));
cell.setCellStyle(cellStyle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Map;

import com.robin.core.base.util.DateTimeFormatHolder;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.ss.usermodel.*;

Expand All @@ -30,6 +31,7 @@ private ExcelCellStyleUtil() {

}


public static CellStyle getNoBorderCellType(Workbook wb, String metaType) {
CellStyle cs = wb.createCellStyle();
cs.setAlignment(HorizontalAlignment.CENTER);
Expand All @@ -39,19 +41,20 @@ public static CellStyle getNoBorderCellType(Workbook wb, String metaType) {
cs.setFillForegroundColor(IndexedColors.WHITE.getIndex());
cs.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cs.setWrapText(true);
extractMeta(metaType, cs);
extractMeta(wb,metaType, cs);
return cs;
}

private static void extractMeta(String metaType, CellStyle cs) {
private static void extractMeta(Workbook wb,String metaType, CellStyle cs) {
switch (metaType) {
case Const.META_TYPE_NUMERIC:
case Const.META_TYPE_DOUBLE:
case Const.META_TYPE_FLOAT:
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
break;
case Const.META_TYPE_DATE:
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("yyyy-MM-dd hh:mm:ss"));
case Const.META_TYPE_TIMESTAMP:
cs.setDataFormat(wb.getCreationHelper().createDataFormat().getFormat(DateTimeFormatHolder.getTimestampFormatter().toString()));
break;
case Const.META_TYPE_INTEGER:
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));
Expand All @@ -76,10 +79,36 @@ public static CellStyle getBorderCellType(Workbook wb, String metaType) {
Font font = wb.createFont();
font.setFontName(ExcelBaseOper.defaultFontName);
cs.setFont(font);
extractMeta(metaType, cs);
extractMeta(wb,metaType, cs);
return cs;

}
public static CellStyle getCellStyle(Workbook wb,String metaType,Map<String, CellStyle> cellMap){
if(cellMap.containsKey(metaType)){
return cellMap.get(metaType);
}else{
CellStyle cs = wb.createCellStyle();
cs.setVerticalAlignment(VerticalAlignment.CENTER);
cs.setAlignment(HorizontalAlignment.CENTER);
cs.setBorderBottom(BorderStyle.THIN);
cs.setBottomBorderColor(IndexedColors.BLACK.getIndex());
cs.setBorderLeft(BorderStyle.THIN);
cs.setLeftBorderColor(IndexedColors.BLACK.getIndex());
cs.setBorderRight(BorderStyle.THIN);
cs.setRightBorderColor(IndexedColors.BLACK.getIndex());
cs.setBorderTop(BorderStyle.THIN);
cs.setTopBorderColor(IndexedColors.BLACK.getIndex());
cs.setFillForegroundColor(IndexedColors.WHITE.getIndex());
Font font = wb.createFont();
font.setFontName(ExcelBaseOper.defaultFontName);
cs.setFont(font);
cs.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cs.setWrapText(true);
extractMeta(wb,metaType,cs);
cellMap.put(metaType,cs);
return cs;
}
}

public static CellStyle getCellStyle(Workbook wb, int rowspan, int colspan, String metaType, TableConfigProp header, Map<String, CellStyle> cellMap) {
CellStyle cs = null;
Expand Down Expand Up @@ -114,7 +143,7 @@ public static CellStyle getCellStyle(Workbook wb, int rowspan, int colspan, Stri
cs.setFont(font);
cs.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cs.setWrapText(true);
extractMeta(metaType,cs);
extractMeta(wb,metaType,cs);
cellMap.put("C_" + rowspan + "_" + colspan + "_" + metaType, cs);
}
return cs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class ExcelColumnProp {
private String columnCode;
private String columnType;
private String formula;
private String format;
private boolean needMerge;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public static Workbook generateExcelFile(ExcelSheetProp prop, TableConfigProp he
while (iterator.hasNext()) {
Map<String, Object> map = iterator.next();
processSingleLine(map, wb, sheet, row, prop, header, helper, cellMap);
if (prop.isStreamInsert() && (row + 1) % prop.getStreamRows() == 0) {
if (prop.isStreamMode() && (row + 1) % prop.getStreamRows() == 0) {
((SXSSFSheet) sheet).flushRows(prop.getStreamRows());
}
row++;
Expand Down Expand Up @@ -688,7 +688,7 @@ private static void fillColumns(Workbook wb, Sheet targetsheet, ExcelSheetProp p
Map<String, CellStyle> cellMap = new HashMap<>();
for (int i = 0; i < list.size(); i++) {
processSingleLine(list.get(i), wb, targetsheet, i, prop, header, helper, cellMap);
if (prop.isStreamInsert() && (i + 1) % prop.getStreamRows() == 0) {
if (prop.isStreamMode() && (i + 1) % prop.getStreamRows() == 0) {
((SXSSFSheet) targetsheet).flushRows(prop.getStreamRows());
}
}
Expand Down Expand Up @@ -817,7 +817,7 @@ public static void processSingleLine(Map<String, ?> map, Workbook wb, Sheet targ

private static void autoSizeSheet(ExcelSheetProp prop, Sheet sheet, int count) {
for (int i = 0; i < count; i++) {
if (!prop.isStreamInsert()) {
if (!prop.isStreamMode()) {
sheet.autoSizeColumn(i);
} else {
if (i == 0) {
Expand Down
Loading