├── vagary-sql ├── src │ └── main │ │ └── java │ │ └── com │ │ └── horrific │ │ └── sqlbuilder │ │ ├── Database.java │ │ ├── select │ │ ├── OrderByType.java │ │ ├── OrCondition.java │ │ ├── AndCondition.java │ │ ├── CountRowMapper.java │ │ ├── InnerJoin.java │ │ ├── LeftOuterJoin.java │ │ ├── RightOuterJoin.java │ │ ├── RowMapper.java │ │ ├── Select.java │ │ ├── Join.java │ │ ├── Condition.java │ │ ├── Having.java │ │ ├── OrderBy.java │ │ ├── GroupBy.java │ │ ├── From.java │ │ ├── Limit.java │ │ └── Where.java │ │ ├── TerminalExpression.java │ │ ├── builder │ │ ├── QueryBuilderHSQLDB.java │ │ ├── QueryBuilderOracle.java │ │ └── QueryBuilder.java │ │ ├── IllegalQueryException.java │ │ ├── delete │ │ └── Delete.java │ │ ├── update │ │ └── Update.java │ │ ├── insert │ │ └── Insert.java │ │ └── Context.java └── pom.xml ├── README.md ├── out └── artifacts │ ├── vagary_core_Web_exploded │ ├── META-INF │ │ └── MANIFEST.MF │ └── WEB-INF │ │ ├── lib │ │ ├── lombok-1.16.6.jar │ │ ├── commons-lang3-3.4.jar │ │ ├── commons-logging-1.1.3.jar │ │ ├── commons-beanutils-1.9.2.jar │ │ └── commons-collections-3.2.2.jar │ │ ├── classes │ │ ├── properties │ │ │ └── system.properties │ │ ├── logback.xml │ │ └── springconfig │ │ │ ├── spring-mvc.xml │ │ │ └── spring-context.xml │ │ └── web.xml │ └── vagary_core_war_exploded │ ├── META-INF │ └── MANIFEST.MF │ └── WEB-INF │ └── lib │ ├── log4j-1.2.13.jar │ ├── logback-access-1.1.7.jar │ ├── logback-core-1.1.7.jar │ └── logback-classic-1.1.7.jar ├── vagary-core ├── src │ ├── main │ │ ├── resources │ │ │ ├── properties │ │ │ │ └── system.properties │ │ │ ├── logback.xml │ │ │ └── springconfig │ │ │ │ ├── spring-mvc.xml │ │ │ │ └── spring-context.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── horrific │ │ │ │ ├── service │ │ │ │ └── QueryService.java │ │ │ │ ├── chartconvert │ │ │ │ ├── ChartConvert.java │ │ │ │ ├── ChartConvertFactory.java │ │ │ │ ├── impl │ │ │ │ │ ├── Top2MapConvert.java │ │ │ │ │ ├── TableChartConvert.java │ │ │ │ │ └── TendencyChartConvert.java │ │ │ │ └── AbstractChartConvert.java │ │ │ │ ├── query │ │ │ │ ├── MySqlQuery.java │ │ │ │ └── AbstractQuery.java │ │ │ │ ├── Param.java │ │ │ │ ├── buildsql │ │ │ │ ├── MysqlBuilder.java │ │ │ │ └── AbstractSqlBuilder.java │ │ │ │ └── controller │ │ │ │ └── QueryController.java │ │ └── webapp │ │ │ └── WEB-INF │ │ │ └── web.xml │ └── test │ │ └── java │ │ └── com │ │ └── horrific │ │ └── AppTest.java ├── .gitignore └── pom.xml ├── .gitignore ├── vagary-base ├── src │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── horrific │ │ │ └── common │ │ │ ├── response │ │ │ ├── ResponseCode.java │ │ │ └── ServiceResponse.java │ │ │ ├── dto │ │ │ ├── chart │ │ │ │ ├── ChartDTO.java │ │ │ │ ├── Point.java │ │ │ │ ├── ChartVO.java │ │ │ │ ├── Points.java │ │ │ │ ├── ValueChartDTO.java │ │ │ │ ├── RadarDimensionDTO.java │ │ │ │ ├── ListChartDTO.java │ │ │ │ ├── Select.java │ │ │ │ └── DefaultChartVO.java │ │ │ ├── table │ │ │ │ ├── TableHeadVO.java │ │ │ │ ├── HeadCell.java │ │ │ │ └── TableViewVO.java │ │ │ ├── Field.java │ │ │ └── ChartInfo.java │ │ │ ├── enums │ │ │ ├── DatePatternEnum.java │ │ │ ├── BaseResponseEnum.java │ │ │ ├── CharTypeEnum.java │ │ │ └── DataTypeEnum.java │ │ │ ├── tools │ │ │ └── downloadexcel │ │ │ │ └── local │ │ │ │ ├── ExcelTemplate.java │ │ │ │ ├── ColumnInfo.java │ │ │ │ └── DownloadTable.java │ │ │ └── utils │ │ │ ├── DateUtil.java │ │ │ ├── POIComponentUtil.java │ │ │ ├── ReflectUtils.java │ │ │ ├── DateFormatUtil.java │ │ │ ├── CollectionUtils.java │ │ │ ├── NumberUtil.java │ │ │ ├── BeanUtil.java │ │ │ ├── FormatUtil.java │ │ │ └── DownloadExcelUtil.java │ └── test │ │ └── java │ │ └── com │ │ └── horrific │ │ └── AppTest.java ├── .gitignore └── pom.xml └── pom.xml /vagary-sql/src/main/java/com/horrific/sqlbuilder/Database.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder; 2 | 3 | public enum Database { 4 | ORACLE, HSQLDB 5 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/OrderByType.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | public enum OrderByType { 4 | ASC, DESC 5 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vagary 2 | 数据库访问中间件,统一的标准sql查询,底层可以是不同的数据库包括mysql、ElasticSearch、kylin、presto等。 3 | 4 | 统一的访问请求参数,通过buildsql将请求参数转化为标准sql,当前只写了对mysql的标准实现,其他数据源还有待提升。 5 | 6 | -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: wanghong12 3 | Created-By: IntelliJ IDEA 4 | Build-Jdk: 1.8.0_31 5 | 6 | -------------------------------------------------------------------------------- /out/artifacts/vagary_core_war_exploded/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: wanghong12 3 | Created-By: IntelliJ IDEA 4 | Build-Jdk: 1.8.0_31 5 | 6 | -------------------------------------------------------------------------------- /vagary-core/src/main/resources/properties/system.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/vagary-core/src/main/resources/properties/system.properties -------------------------------------------------------------------------------- /out/artifacts/vagary_core_war_exploded/WEB-INF/lib/log4j-1.2.13.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_war_exploded/WEB-INF/lib/log4j-1.2.13.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/lombok-1.16.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/lombok-1.16.6.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-lang3-3.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-lang3-3.4.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_war_exploded/WEB-INF/lib/logback-access-1.1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_war_exploded/WEB-INF/lib/logback-access-1.1.7.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_war_exploded/WEB-INF/lib/logback-core-1.1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_war_exploded/WEB-INF/lib/logback-core-1.1.7.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-logging-1.1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-logging-1.1.3.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_war_exploded/WEB-INF/lib/logback-classic-1.1.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_war_exploded/WEB-INF/lib/logback-classic-1.1.7.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-beanutils-1.9.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-beanutils-1.9.2.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-collections-3.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_Web_exploded/WEB-INF/lib/commons-collections-3.2.2.jar -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/classes/properties/system.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/horrificer/vagary/HEAD/out/artifacts/vagary_core_Web_exploded/WEB-INF/classes/properties/system.properties -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Libraries 2 | # Libraries 3 | /lib/*.jar 4 | 5 | # Eclipse files 6 | .classpath 7 | .project 8 | .settings/ 9 | 10 | # Maven files 11 | target/ 12 | 13 | # Intellij IDEA files 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # config_center_log 20 | config_center_client.log 21 | 22 | ### Java template 23 | *.class 24 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/response/ResponseCode.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.response; 2 | 3 | /** 4 | * @Description com.jd.xtl.common.response 5 | * @Author horrific 6 | * @Create 2016-10-18 10:42 7 | */ 8 | public interface ResponseCode { 9 | 10 | int getCode(); 11 | 12 | String getMsg(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /vagary-base/.gitignore: -------------------------------------------------------------------------------- 1 | # Libraries 2 | # Libraries 3 | /lib/*.jar 4 | 5 | # Eclipse files 6 | .classpath 7 | .project 8 | .settings/ 9 | 10 | # Maven files 11 | target/ 12 | 13 | # Intellij IDEA files 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # config_center_log 20 | config_center_client.log 21 | 22 | ### Java template 23 | *.class 24 | -------------------------------------------------------------------------------- /vagary-core/.gitignore: -------------------------------------------------------------------------------- 1 | # Libraries 2 | # Libraries 3 | /lib/*.jar 4 | 5 | # Eclipse files 6 | .classpath 7 | .project 8 | .settings/ 9 | 10 | # Maven files 11 | target/ 12 | 13 | # Intellij IDEA files 14 | *.iml 15 | *.ipr 16 | *.iws 17 | .idea/ 18 | 19 | # config_center_log 20 | config_center_client.log 21 | 22 | ### Java template 23 | *.class 24 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/OrCondition.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | 6 | class OrCondition extends Condition { 7 | 8 | OrCondition(Context context) { 9 | super(context); 10 | } 11 | 12 | @Override 13 | protected String getPrefix() { 14 | return " OR"; 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/AndCondition.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | 6 | class AndCondition extends Condition { 7 | 8 | AndCondition(Context context) { 9 | super(context); 10 | } 11 | 12 | @Override 13 | protected String getPrefix() { 14 | return " AND"; 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/CountRowMapper.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | public class CountRowMapper extends RowMapper { 7 | 8 | @Override 9 | public Integer convert(ResultSet resultSet, int rowNum) throws SQLException { 10 | return resultSet.getInt(1); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/TerminalExpression.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder; 2 | 3 | 4 | import com.horrific.sqlbuilder.select.RowMapper; 5 | 6 | import java.sql.SQLException; 7 | import java.util.List; 8 | 9 | public interface TerminalExpression { 10 | 11 | List list(RowMapper rowMapper) throws SQLException; 12 | 13 | E single(RowMapper rowMapper) throws SQLException; 14 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/InnerJoin.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | 6 | class InnerJoin extends Join { 7 | 8 | InnerJoin(Context context, String condition) { 9 | super(context, condition); 10 | } 11 | 12 | InnerJoin(Context context) { 13 | super(context); 14 | } 15 | 16 | @Override 17 | protected String expression() { 18 | return "INNER JOIN"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/LeftOuterJoin.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | 6 | class LeftOuterJoin extends Join { 7 | 8 | LeftOuterJoin(Context context) { 9 | super(context); 10 | } 11 | 12 | LeftOuterJoin(Context context, String condition) { 13 | super(context, condition); 14 | } 15 | 16 | @Override 17 | protected String expression() { 18 | return "LEFT OUTER JOIN"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/RightOuterJoin.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | 6 | class RightOuterJoin extends Join { 7 | 8 | RightOuterJoin(Context context, String condition) { 9 | super(context, condition); 10 | } 11 | 12 | RightOuterJoin(Context context) { 13 | super(context); 14 | } 15 | 16 | @Override 17 | protected String expression() { 18 | return "RIGHT OUTER JOIN"; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/ChartDTO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * Created by duanzhiying on 2017/10/15. 12 | * 图表转换DTO的基本属性 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @ToString 18 | public class ChartDTO implements Serializable { 19 | /** 20 | * 值Caption 21 | */ 22 | private String name; 23 | } 24 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/Point.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | @ToString 14 | public class Point extends ChartDTO implements Serializable { 15 | private Object value; 16 | 17 | public Point(String name, Object value){ 18 | super(name); 19 | this.value = value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/builder/QueryBuilderHSQLDB.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.builder; 2 | 3 | 4 | import com.horrific.sqlbuilder.Database; 5 | 6 | import javax.sql.DataSource; 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | 10 | public class QueryBuilderHSQLDB extends QueryBuilder { 11 | 12 | public QueryBuilderHSQLDB(Connection connection) { 13 | super(Database.HSQLDB, connection); 14 | } 15 | 16 | public QueryBuilderHSQLDB(DataSource dataSource) throws SQLException { 17 | super(Database.HSQLDB, dataSource); 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/builder/QueryBuilderOracle.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.builder; 2 | 3 | 4 | import com.horrific.sqlbuilder.Database; 5 | 6 | import javax.sql.DataSource; 7 | import java.sql.Connection; 8 | import java.sql.SQLException; 9 | 10 | public class QueryBuilderOracle extends QueryBuilder { 11 | 12 | public QueryBuilderOracle(Connection connection) { 13 | super(Database.ORACLE, connection); 14 | } 15 | 16 | public QueryBuilderOracle(DataSource dataSource) throws SQLException { 17 | super(Database.ORACLE, dataSource); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/IllegalQueryException.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder; 2 | 3 | public class IllegalQueryException extends RuntimeException { 4 | 5 | private static final long serialVersionUID = -4847411495350655382L; 6 | 7 | public IllegalQueryException() { 8 | } 9 | 10 | public IllegalQueryException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | 14 | public IllegalQueryException(String message) { 15 | super(message); 16 | } 17 | 18 | public IllegalQueryException(Throwable cause) { 19 | super(cause); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/ChartVO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * Created by duanzhiying on 2017/10/15. 12 | * 图表转换VO的基本属性 13 | */ 14 | @Data 15 | @NoArgsConstructor 16 | @AllArgsConstructor 17 | @ToString 18 | public class ChartVO implements Serializable { 19 | /** 20 | * 图表类型,见:{@link: com.jd.jdp.common.enums.DrawEnum} 21 | */ 22 | private Integer chartType; 23 | } 24 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/Points.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | @ToString 15 | public class Points extends ChartDTO implements Serializable { 16 | private List value; 17 | 18 | public Points(String name, List value){ 19 | super(name); 20 | this.value = value; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/table/TableHeadVO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.table; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * @author wanghong12 9 | * @since 2018-3-13 10 | */ 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class TableHeadVO { 15 | 16 | /** 17 | * 表头名称 18 | */ 19 | private String title; 20 | 21 | /** 22 | * 表头key 23 | */ 24 | private String data; 25 | 26 | /** 27 | * 标识 28 | */ 29 | private Integer id; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/ValueChartDTO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | /** 8 | * Created by duanzhiying on 2017/10/15. 9 | * 图表转换DTO:value类型是一个值 10 | */ 11 | @Data 12 | @NoArgsConstructor 13 | @ToString(callSuper = true) 14 | public class ValueChartDTO extends ChartDTO { 15 | /** 16 | * 具体的值,通用返回String 17 | */ 18 | private String value; 19 | 20 | public ValueChartDTO(String legend, String value){ 21 | super(legend); 22 | this.value = value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/RadarDimensionDTO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | /** 8 | * Created by duanzhiying on 2017/10/17. 9 | */ 10 | @Data 11 | @NoArgsConstructor 12 | @ToString(callSuper = true) 13 | public class RadarDimensionDTO extends ChartDTO { 14 | public Double max; 15 | 16 | public RadarDimensionDTO(String name,Double max){ 17 | super(name); 18 | this.max = max; 19 | } 20 | 21 | public RadarDimensionDTO(String name){ 22 | super(name); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/ListChartDTO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by duanzhiying on 2017/10/15. 11 | * 图表转换DTO:value类型是list 12 | */ 13 | @Data 14 | @NoArgsConstructor 15 | @ToString(callSuper = true) 16 | public class ListChartDTO extends ChartDTO { 17 | /** 18 | * 具体的值 19 | */ 20 | private List data; 21 | 22 | public ListChartDTO(String name, List data){ 23 | super(name); 24 | this.data = data; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/Field.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * @Description: 12 | * @author duanmenghua 13 | * @date 2017年8月7日 下午5:39:35 14 | */ 15 | @Data 16 | @NoArgsConstructor 17 | @AllArgsConstructor 18 | @ToString 19 | public class Field implements Serializable{ 20 | /** 21 | * 字段名称 22 | */ 23 | private String field; 24 | 25 | /** 26 | * 字段显示名称/别名 27 | */ 28 | private String caption; 29 | 30 | 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/Select.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | /** 8 | * Created by duanzhiying on 2017/10/22. 9 | */ 10 | @Data 11 | @NoArgsConstructor 12 | @ToString(callSuper = true) 13 | public class Select extends ValueChartDTO { 14 | String label; 15 | 16 | public Select(String name, String value, String label) { 17 | super(name, value); 18 | this.label = label; 19 | } 20 | 21 | public Select(String value, String label){ 22 | setValue(value); 23 | this.label = label; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/enums/DatePatternEnum.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.enums; 2 | 3 | public enum DatePatternEnum { 4 | DATE_FORMAT("yyyy-MM-dd"), 5 | DATE_FORMAT_SHORT("yyyyMMdd"), 6 | MONTH_FORMAT("MM-dd"), 7 | DATE_FORMAT_24H("yyyy-MM-dd HH:mm:ss"), 8 | DATE_FORMAT_12H("yyyy-MM-dd hh:mm:ss"), 9 | DATE_FORMAT_WEEK("yyyy-ww"), 10 | DATE_FORMAT_MONTH("yyyy-MM"), 11 | DATE_FORMAT_00H("yyyy-MM-dd 00:00:00"), 12 | DATE_FORMAT_23H("yyyy-MM-dd 23:59:59"), 13 | DATE_FORMAT_CHIAN("yyyy年MM月dd日HH点"); 14 | 15 | public String pattern; 16 | 17 | private DatePatternEnum(String pattern) { 18 | this.pattern = pattern; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/tools/downloadexcel/local/ExcelTemplate.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.tools.downloadexcel.local; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * excel模板 9 | *

10 | * @author wanghong12 11 | * @date 2018-3-28 12 | */ 13 | @Data 14 | public class ExcelTemplate { 15 | 16 | /** 17 | * Excel模板名字 18 | */ 19 | private String templateName; 20 | 21 | /** 22 | * 生成的excel的名字 23 | */ 24 | private String excelName; 25 | 26 | /** 27 | * Excel 数据体描述信息 28 | */ 29 | private Map bodyInfo; 30 | 31 | /** 32 | * Excel 数据体开始的位置 33 | */ 34 | private int bodyStartIndex; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/RowMapper.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.ResultSetMetaData; 5 | import java.sql.SQLException; 6 | 7 | public abstract class RowMapper { 8 | 9 | public abstract E convert(ResultSet resultSet, int rowNum) throws SQLException; 10 | 11 | protected boolean contains(ResultSet resultSet, String columnName) throws SQLException { 12 | ResultSetMetaData metaData = resultSet.getMetaData(); 13 | for (int i = 1; i <= metaData.getColumnCount(); i++) { 14 | String metaDataColumnName = metaData.getColumnLabel(i); 15 | if (columnName.equalsIgnoreCase(metaDataColumnName)) { 16 | return true; 17 | } 18 | } 19 | return false; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/table/HeadCell.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.table; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | 10 | @Data 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | @ToString 14 | public class HeadCell implements Serializable{ 15 | 16 | 17 | /** 18 | * 隱藏 19 | */ 20 | private String hidden; 21 | 22 | /** 23 | * 中文名 24 | */ 25 | private String title; 26 | 27 | /** 28 | * 英文名 29 | */ 30 | private String key; 31 | 32 | public HeadCell(String title, String key) { 33 | this.title = title; 34 | this.key = key; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/ChartInfo.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import lombok.ToString; 7 | 8 | import java.io.Serializable; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author wanghong12 14 | * @since 2018-3-13 15 | */ 16 | @Data 17 | @AllArgsConstructor 18 | @NoArgsConstructor 19 | @ToString 20 | public class ChartInfo implements Serializable { 21 | 22 | private Integer chartType; 23 | 24 | private List> dataList; 25 | 26 | private List dims; 27 | 28 | private List measures; 29 | 30 | private String dim; 31 | 32 | private String measure; 33 | 34 | private String total; 35 | 36 | private String divide; 37 | } 38 | -------------------------------------------------------------------------------- /vagary-base/src/test/java/com/horrific/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.horrific; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/table/TableViewVO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.table; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | import java.io.Serializable; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | @Data 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class TableViewVO implements Serializable { 15 | 16 | private Integer chartType; 17 | 18 | private List titleName; 19 | 20 | private List> titleList; 21 | 22 | private Integer total ; 23 | 24 | public TableViewVO(Integer chartType, List titleName, List> titleList) { 25 | this.chartType = chartType; 26 | this.titleName = titleName; 27 | this.titleList = titleList; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/DateUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | 4 | import java.sql.Time; 5 | import java.sql.Timestamp; 6 | 7 | /** 8 | * @author wanghong12 9 | * @since 2018-3-13 10 | */ 11 | public final class DateUtil { 12 | 13 | /** 14 | * 将时间格式转成时间戳 15 | * @param o 16 | * @return 17 | */ 18 | public static Object toValue(Object o){ 19 | if (o instanceof java.util.Date){ 20 | return ((java.util.Date) o).getTime(); 21 | }else if (o instanceof java.sql.Date){ 22 | return ((java.sql.Date) o).getTime(); 23 | }else if (o instanceof Timestamp){ 24 | return ((Timestamp) o).getTime(); 25 | }else if(o instanceof Time){ 26 | return ((Time) o).getTime(); 27 | }else { 28 | return o; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/service/QueryService.java: -------------------------------------------------------------------------------- 1 | package com.horrific.service; 2 | 3 | import com.horrific.Param; 4 | import com.horrific.common.response.ServiceResponse; 5 | import com.horrific.query.MySqlQuery; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author wanghong12 11 | * @since 2018-3-13 12 | */ 13 | 14 | @Component 15 | public class QueryService { 16 | 17 | @Autowired 18 | private MySqlQuery query; 19 | 20 | public ServiceResponse query(Param params) { 21 | T data = query.query(params); 22 | if (data == null) { 23 | return ServiceResponse.failure("暂无数据"); 24 | } 25 | return ServiceResponse.ok(data); 26 | } 27 | 28 | public void update(String sql) { 29 | query.doUpdate(sql); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/chartconvert/ChartConvert.java: -------------------------------------------------------------------------------- 1 | package com.horrific.chartconvert; 2 | 3 | import com.horrific.Param; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | /** 9 | * ChartConvert List> to VO 10 | * 11 | * @author wanghong12 2017-09-29 12 | * @param 13 | */ 14 | public interface ChartConvert { 15 | 16 | /** 17 | * According to the queryParams chart types, change the information 18 | * through the handle method into the front data format 19 | * 20 | * @param data query information 21 | * @param params query information 22 | * @return VO needed by web application 23 | */ 24 | T handle(List> data, Param params); 25 | 26 | 27 | /** 28 | * Identification of the current bean via chartType 29 | * 30 | * @param chartType chart type 31 | * @return true or false 32 | */ 33 | boolean beanIndicate(Integer chartType); 34 | } 35 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/enums/BaseResponseEnum.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.enums; 2 | 3 | /** 4 | * @author wanghong12 5 | * @since 2018-3-13 6 | */ 7 | public enum BaseResponseEnum { 8 | 9 | 10 | SUCCESS(200, "成功"), 11 | FAILURE(201, "失败"), 12 | USER_NOT_LOGIN(202, "用户未登录"), 13 | FAILURE_BUSSINES(203, "业务级别报错"), 14 | NO_PERMISSION(401, "无此操作权限"), 15 | NO_RECORD(402, "查询无记录"), 16 | OBJECT_EXISTED(409, "对象已经存在"), 17 | PARAM_ERROR(501, "参数错误"), 18 | BUSINESS_ILLEGAL_OP(502, "非法的操作"), 19 | SESSION_EXPIRED(503, "session失效"), 20 | UNKNOWN_ERROR(504, "未知错误"), 21 | UNKNOWN_REQUEST(505, "未知请求"); 22 | 23 | private int code; 24 | private String msg; 25 | 26 | private BaseResponseEnum(int code, String msg) { 27 | this.code = code; 28 | this.msg = msg; 29 | } 30 | 31 | public int getCode() { 32 | return code; 33 | } 34 | 35 | public String getMsg() { 36 | return msg; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/dto/chart/DefaultChartVO.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.dto.chart; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | /** 11 | * @author duanzhiying 12 | * @version 创建时间:2017/10/15 13 | * 图表转换的默认VO:可覆盖TendencyVO/TreeMapVO 14 | */ 15 | @Data 16 | @NoArgsConstructor 17 | @ToString(callSuper = true) 18 | public class DefaultChartVO extends ChartVO{ 19 | /** 20 | * 维度列表 21 | */ 22 | private List dimension; 23 | /** 24 | * 度量列表 25 | */ 26 | private List measure; 27 | 28 | /** 29 | * 构造函数 30 | * @param chartType 图表类型 31 | * @param dimension 维度列表 32 | * @param measure 度量列表 33 | */ 34 | public DefaultChartVO(Integer chartType, List dimension, List measure){ 35 | super(chartType); 36 | this.dimension = dimension; 37 | this.measure = measure; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /vagary-core/src/test/java/com/horrific/AppTest.java: -------------------------------------------------------------------------------- 1 | package com.horrific; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.horrific.buildsql.MysqlBuilder; 5 | import junit.framework.TestCase; 6 | import org.junit.Test; 7 | 8 | /** 9 | * Unit test for simple App. 10 | */ 11 | public class AppTest extends TestCase { 12 | 13 | @Test 14 | public void testSql() { 15 | 16 | String json = "{\n" + 17 | "\t\"columns\":\"sum(a), b, c\",\t\n" + 18 | "\t\"whereOn\":\"b=1,c=2\",\n" + 19 | "\t\"whereOr\":\"b=2,c=3\",\n" + 20 | "\t\"groupBy\":\"d\",\n" + 21 | //"\t\"orderBy\":\"b asc,c desc\",\n" + 22 | //"\t\"having\":\"a>100\",\n" + 23 | //"\t\"size\":1,\n" + 24 | "\t\"table\":\"sys_role\",\n" + 25 | "\t\"chartType\":1\n" + 26 | "}"; 27 | Param param = JSONObject.parseObject(json, Param.class); 28 | System.out.println(new MysqlBuilder().buildSql(param)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/chartconvert/ChartConvertFactory.java: -------------------------------------------------------------------------------- 1 | package com.horrific.chartconvert; 2 | 3 | import com.horrific.Param; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * A factory, provide a convert bean by chartType for each search. 11 | * 12 | * @author wanghong12 2017-09-29 13 | */ 14 | @Component 15 | public class ChartConvertFactory { 16 | 17 | private List convertList; 18 | 19 | @Autowired 20 | public void setConvertList(List convertList) { 21 | this.convertList = convertList; 22 | } 23 | 24 | /** 25 | * get convert instance 26 | * 27 | * @param params 28 | * @return 29 | */ 30 | public ChartConvert getInstance(final Param params) { 31 | 32 | int chartType = params.getChartType(); 33 | 34 | for (ChartConvert convert : convertList) { 35 | if (convert.beanIndicate(chartType)) { 36 | return convert; 37 | } 38 | } 39 | 40 | return null; 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/enums/CharTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.enums; 2 | 3 | /** 4 | * 【图形枚举类】 5 | * 6 | * @author wanghong12 7 | * @create 2017-08-22 16:50 8 | **/ 9 | 10 | public enum CharTypeEnum { 11 | TABLE(0, "表格"), 12 | LIST(1, "明细表"), 13 | LINE(10, "线图"), 14 | BAR(20, "柱状图"), 15 | STRIP(21, "条形图"), 16 | PIE(30, "饼图"), 17 | SELECT(4, "下拉"), 18 | TREE_MAP(5, "矩形树图"), 19 | SCATTER(60, "散点图"), 20 | RADAR(70, "雷达图"), 21 | GAUGE(80, "计量图"), 22 | INDEX_CARD(81, "指标卡"), 23 | MAP(90,"地图"), 24 | DEFAULT(-1, "默认"); 25 | 26 | public int code; 27 | public String desc; 28 | 29 | CharTypeEnum(int code, String desc) { 30 | this.code = code; 31 | this.desc = desc; 32 | } 33 | 34 | public static CharTypeEnum getDrawEnumByCode(Integer code) { 35 | if (code == null) { 36 | return LINE; 37 | } 38 | for (CharTypeEnum charTypeEnum : CharTypeEnum.values()) { 39 | if (code == charTypeEnum.code) { 40 | return charTypeEnum; 41 | } 42 | } 43 | return LINE; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/query/MySqlQuery.java: -------------------------------------------------------------------------------- 1 | package com.horrific.query; 2 | 3 | 4 | import com.horrific.Param; 5 | import com.horrific.chartconvert.ChartConvert; 6 | import com.horrific.chartconvert.ChartConvertFactory; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * @author wanghong12 16 | * @since 2017-3-13 17 | */ 18 | @Slf4j 19 | @Component 20 | public class MySqlQuery extends AbstractQuery { 21 | 22 | @Autowired 23 | private ChartConvertFactory convertFactory; 24 | 25 | @Override 26 | public T query(Param param) { 27 | 28 | List> data = doQuery(param); 29 | 30 | Map count = null; 31 | if (param.getPage()) { 32 | countQuery(param); 33 | } 34 | 35 | ChartConvert convert = convertFactory.getInstance(param); 36 | 37 | return convert.handle(data, param); 38 | } 39 | 40 | @Override 41 | void validate(String sql) { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/enums/DataTypeEnum.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.enums; 2 | 3 | /** 4 | * @author wanghong12 5 | * @date 2018-3-28 6 | */ 7 | public enum DataTypeEnum { 8 | THOUSANDS("THOUSANDS", "千分位"), 9 | THOUSANDSZERO("THOUSANDSZERO", "千分位,取整"), 10 | THOUSANDSZEROTWO("THOUSANDSZEROTWO", "千分位保留两位小数"), 11 | THOUSANDSZEROTHREE("THOUSANDSZEROTHREE", "千分位保留三位小数"), 12 | THOUSANDSZEROFOUR("THOUSANDSZEROFOUR", "千分位保留四位小数"), 13 | INTEGER("INTEGER", "整数"), 14 | PERCENT("PERCENT", "百分数,保留两位小数"), 15 | PERCENTONE("PERCENTONE", "百分数,保留一位小数"), 16 | PERCENTZERO("PERCENTZERO", "百分数,取整"), 17 | SCALETOTWO("SCALETOTWO", "保留两位有效数字"), 18 | SCALETOONE("SCALETOONE", "保留一位有效数字"), 19 | SCALETOTHREE("SCALETOTHIRD", "保留三位有效数字"), 20 | SCALETOFOUR("SCALETOFOUR", "保留四位有效数字"), 21 | NUMBER("NUMBER", "数字"), 22 | DATE("DATE", "日期"); 23 | 24 | public String desc; 25 | public String code; 26 | 27 | private DataTypeEnum(String code, String desc) { 28 | this.code = code; 29 | this.desc = desc; 30 | } 31 | 32 | public String toString() { 33 | return "DataTypeEnum{desc='" + this.desc + '\'' + ", code='" + this.code + '\'' + '}'; 34 | } 35 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/Param.java: -------------------------------------------------------------------------------- 1 | package com.horrific; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.NoArgsConstructor; 5 | import lombok.ToString; 6 | 7 | /** 8 | * @author wanghong12 9 | * @since 2018-3-12 10 | */ 11 | 12 | @lombok.Data 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | @ToString 16 | public class Param { 17 | 18 | /** 19 | * 需要查询的字段 20 | */ 21 | private String columns; 22 | 23 | /** 24 | * 过滤条件 25 | */ 26 | private String whereOn; 27 | 28 | private String whereOr; 29 | 30 | /** 31 | * 聚合字段 32 | */ 33 | private String groupBy; 34 | 35 | /** 36 | * 聚合条件 37 | */ 38 | private String having; 39 | 40 | /** 41 | * 排序 42 | */ 43 | private String orderBy; 44 | 45 | /** 46 | * 长度 47 | */ 48 | private Integer size; 49 | 50 | /** 51 | * 偏移 52 | */ 53 | private Integer offset; 54 | 55 | /** 56 | * 图表类型 57 | */ 58 | private Integer chartType = -1; 59 | 60 | private String table; 61 | 62 | private String joinTable; 63 | 64 | private String total; 65 | 66 | private Boolean page = false; 67 | 68 | private String title = "明细表"; 69 | 70 | private String divide; 71 | } 72 | -------------------------------------------------------------------------------- /vagary-core/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %date{HH:mm:ss.SSS} %-5level %logger{50} - %msg%n 11 | UTF-8 12 | 13 | 14 | 15 | 17 | ${USER_HOME}/warth.log 18 | 19 | ${USER_HOME}/vagary/%i.log 20 | 1 21 | 100 22 | 23 | 24 | %date{HH:mm:ss.SSS} %-5level %logger{40} - %msg%n 25 | UTF-8 26 | 27 | 28 | 100MB 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/Select.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | import com.horrific.sqlbuilder.Context; 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | 9 | public class Select { 10 | 11 | private Context context; 12 | 13 | private final List columns; 14 | 15 | public Select(Context context) { 16 | this.context = context; 17 | this.context.appendLine("SELECT "); 18 | columns = new LinkedList<>(); 19 | } 20 | 21 | public From from() { 22 | this.context.appendLine(StringUtils.join(columns, ",")); 23 | return new From(context); 24 | } 25 | 26 | public Select all() { 27 | append("*"); 28 | return this; 29 | } 30 | 31 | public Select column(String column) { 32 | append(column); 33 | return this; 34 | } 35 | 36 | public Select columns(String... columns) { 37 | for (String column : columns) { 38 | append(column); 39 | } 40 | 41 | return this; 42 | } 43 | 44 | public Select count(String column) { 45 | append("COUNT(" + column + ")"); 46 | return this; 47 | } 48 | 49 | private void append(String expression) { 50 | columns.add(expression); 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return context.toString(); 56 | } 57 | } -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/tools/downloadexcel/local/ColumnInfo.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.tools.downloadexcel.local; 2 | 3 | import com.horrific.common.enums.DataTypeEnum; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 列信息 10 | *

11 | * Created by huyong on 2017/6/22. 12 | */ 13 | @Data 14 | @NoArgsConstructor 15 | @AllArgsConstructor 16 | public class ColumnInfo { 17 | 18 | /** 19 | * 列位置 20 | */ 21 | private int columnIndex; 22 | 23 | /** 24 | * 存储字段名字 25 | */ 26 | private String columnName; 27 | 28 | /** 29 | * 列的默认值 30 | */ 31 | private String columnDefaultValue = ""; 32 | 33 | /** 34 | * 数据格式类型:NUMBER 、 DATE 35 | */ 36 | private DataTypeEnum formatType; 37 | 38 | /** 39 | * 数据格式 40 | */ 41 | private String formatPattern; 42 | 43 | public ColumnInfo(int columnIndex, String columnName) { 44 | this.columnIndex = columnIndex; 45 | this.columnName = columnName; 46 | } 47 | 48 | public ColumnInfo(int columnIndex, String columnName, String columnDefaultValue) { 49 | this.columnIndex = columnIndex; 50 | this.columnName = columnName; 51 | this.columnDefaultValue = columnDefaultValue; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/Join.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.TerminalExpression; 6 | 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | public abstract class Join implements TerminalExpression { 11 | 12 | private Context context; 13 | 14 | Join(Context context) { 15 | this.context = context; 16 | context.appendLine(expression()); 17 | } 18 | 19 | Join(Context context, String condition) { 20 | this(context); 21 | context.appendLine(condition); 22 | } 23 | 24 | public OrderBy orderBy() { 25 | return new OrderBy(context); 26 | } 27 | 28 | public Where where() { 29 | return new Where(context); 30 | } 31 | 32 | public Where where(String condition) { 33 | return new Where(context, condition); 34 | } 35 | 36 | public Limit limit(int start, int size) { 37 | return new Limit(context, start, size); 38 | } 39 | 40 | @Override 41 | public List list(RowMapper rowMapper) throws SQLException { 42 | return context.list(rowMapper); 43 | } 44 | 45 | @Override 46 | public E single(RowMapper rowMapper) throws SQLException { 47 | return context.single(rowMapper); 48 | } 49 | 50 | protected abstract String expression(); 51 | 52 | @Override 53 | public String toString() { 54 | return context.toString(); 55 | } 56 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/chartconvert/impl/Top2MapConvert.java: -------------------------------------------------------------------------------- 1 | package com.horrific.chartconvert.impl; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.google.common.collect.Maps; 5 | import com.horrific.chartconvert.AbstractChartConvert; 6 | import com.horrific.common.dto.ChartInfo; 7 | import com.horrific.common.enums.CharTypeEnum; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * 对查询结果不做任何处理 16 | * 17 | * @author wanghong12 18 | * @since 2018-3-16 19 | */ 20 | @Component 21 | public class Top2MapConvert extends AbstractChartConvert> { 22 | @Override 23 | public Map convert(ChartInfo chartInfo) { 24 | 25 | Map listMap = Maps.newHashMap(); 26 | 27 | if (StringUtils.isNotEmpty(chartInfo.getTotal())) { 28 | listMap.put("total", Lists.newArrayList(chartInfo.getTotal())); 29 | } 30 | 31 | String dimensionValue = chartInfo.getDivide(); 32 | listMap.put(dimensionValue, chartInfo.getDataList()); 33 | return listMap; 34 | } 35 | 36 | @Override 37 | public boolean beanIndicate(Integer chartType) { 38 | if (chartType == CharTypeEnum.DEFAULT.code) { 39 | return true; 40 | } 41 | return false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/Condition.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import org.apache.commons.lang3.ArrayUtils; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | abstract class Condition { 9 | 10 | protected final Context context; 11 | 12 | Condition(Context context) { 13 | this.context = context; 14 | } 15 | 16 | void add(Object condition) { 17 | context.appendLine(getPrefix() + " " + condition); 18 | } 19 | 20 | void add(Object condition, Object parameter) { 21 | if (parameter != null) { 22 | add(condition, new Object[]{parameter}); 23 | } 24 | } 25 | 26 | void add(String condition, String parameter) { 27 | if (StringUtils.isNotBlank(parameter)) { 28 | add(condition, new Object[]{parameter}); 29 | } 30 | } 31 | 32 | void add(Object condition, Object... parameters) { 33 | if (ArrayUtils.isNotEmpty(parameters)) { 34 | context.addParameters(parameters); 35 | add(condition); 36 | } 37 | } 38 | 39 | void between(String columnName, Object start, Object end) { 40 | if (start == null) { 41 | if (end != null) { 42 | add(columnName + " <= ?", end); 43 | } 44 | } else { 45 | if (end == null) { 46 | add(columnName + " >= ?", start); 47 | } else { 48 | add(columnName + " BETWEEN ? AND ?", start, end); 49 | } 50 | } 51 | } 52 | 53 | protected abstract String getPrefix(); 54 | 55 | } -------------------------------------------------------------------------------- /vagary-sql/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | vagary 5 | com.horrific 6 | 1.3-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | vagary-sql 11 | jar 12 | 13 | vagary-sql 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | org.apache.commons 23 | commons-lang3 24 | 25 | 26 | commons-beanutils 27 | commons-beanutils 28 | 29 | 30 | commons-logging 31 | commons-logging 32 | 33 | 34 | 35 | 36 | commons-collections 37 | commons-collections 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/classes/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | %date{HH:mm:ss.SSS} %-5level %logger{50} - %msg%n 11 | UTF-8 12 | 13 | 14 | 15 | 17 | ${USER_HOME}/warth.log 18 | 19 | ${USER_HOME}/vagary/%i.log 20 | 1 21 | 100 22 | 23 | 24 | %date{HH:mm:ss.SSS} %-5level %logger{40} - %msg%n 25 | UTF-8 26 | 27 | 28 | 100MB 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/POIComponentUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | import org.apache.poi.xssf.streaming.SXSSFCell; 4 | import org.apache.poi.xssf.streaming.SXSSFRow; 5 | import org.apache.poi.xssf.streaming.SXSSFSheet; 6 | import org.apache.poi.xssf.streaming.SXSSFWorkbook; 7 | 8 | /** 9 | * POI组件生成工具类 10 | * 11 | * @author: huyong 12 | * @since: 2017/8/16 12:30 13 | */ 14 | public class POIComponentUtil { 15 | 16 | /** 17 | * 生成Excel对象 18 | * 19 | * @param lineNum 生成Excel时,超过该条数,把内存数据写入到磁盘 20 | * @return 21 | */ 22 | public static SXSSFWorkbook makeSXSSFWorkbook(int lineNum) { 23 | return new SXSSFWorkbook(lineNum); 24 | } 25 | 26 | /** 27 | * 生成sheet 28 | * 29 | * @param book excel对象 30 | * @param sheetName sheet名字 31 | * @return 32 | */ 33 | public static SXSSFSheet makeSXSSFSheet(SXSSFWorkbook book, String sheetName) { 34 | return (SXSSFSheet) book.createSheet(sheetName); 35 | } 36 | 37 | /** 38 | * 生成row 39 | * 40 | * @param sheet 41 | * @param rowNum 行的索引(即:第几行) 42 | * @return 43 | */ 44 | public static SXSSFRow makeSXSSFRow(SXSSFSheet sheet, int rowNum) { 45 | return (SXSSFRow) sheet.createRow(rowNum); 46 | } 47 | 48 | /** 49 | * 生成一行的一个单元格 50 | * 51 | * @param row 52 | * @param columnNum 列索引 53 | * @return 54 | */ 55 | public static SXSSFCell makeSXSSFCell(SXSSFRow row, int columnNum) { 56 | return (SXSSFCell) row.createCell(columnNum); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/builder/QueryBuilder.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.builder; 2 | 3 | import com.horrific.sqlbuilder.Context; 4 | import com.horrific.sqlbuilder.Database; 5 | import com.horrific.sqlbuilder.delete.Delete; 6 | import com.horrific.sqlbuilder.insert.Insert; 7 | import com.horrific.sqlbuilder.select.Select; 8 | import com.horrific.sqlbuilder.update.Update; 9 | 10 | import javax.sql.DataSource; 11 | import java.sql.Connection; 12 | import java.sql.SQLException; 13 | 14 | public class QueryBuilder { 15 | 16 | private Context context; 17 | 18 | public QueryBuilder() { 19 | this.context = new Context(null, null); 20 | } 21 | 22 | public QueryBuilder(Database database, DataSource dataSource) throws SQLException { 23 | this(database, dataSource.getConnection()); 24 | } 25 | 26 | public QueryBuilder(Database database, Connection connection) { 27 | this.context = new Context(database, connection); 28 | } 29 | 30 | public Select select() { 31 | return new Select(context); 32 | } 33 | 34 | public Update update() { 35 | return new Update(context); 36 | } 37 | 38 | public Update update(String table) { 39 | return new Update(context, table); 40 | } 41 | 42 | public Delete delete() { 43 | return new Delete(context); 44 | } 45 | 46 | public Delete delete(String table) { 47 | return new Delete(context, table); 48 | } 49 | 50 | public Insert insert() { 51 | return new Insert(context); 52 | } 53 | 54 | public Insert insert(String table) { 55 | return new Insert(context, table); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return context.toString(); 61 | } 62 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/chartconvert/impl/TableChartConvert.java: -------------------------------------------------------------------------------- 1 | package com.horrific.chartconvert.impl; 2 | 3 | 4 | import com.google.common.collect.Lists; 5 | import com.horrific.chartconvert.AbstractChartConvert; 6 | import com.horrific.common.dto.ChartInfo; 7 | import com.horrific.common.dto.Field; 8 | import com.horrific.common.dto.table.HeadCell; 9 | import com.horrific.common.dto.table.TableViewVO; 10 | import com.horrific.common.enums.CharTypeEnum; 11 | import org.springframework.stereotype.Component; 12 | 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | /** 17 | * ChartConvert Object to TableViewVO 18 | * 19 | * @author wanghong12 2017-09-29 20 | */ 21 | @Component 22 | public class TableChartConvert extends AbstractChartConvert { 23 | 24 | @Override 25 | public TableViewVO convert(ChartInfo chartInfo) { 26 | List dimAndMeas = Lists.newArrayList(); 27 | 28 | dimAndMeas.addAll(chartInfo.getDims());dimAndMeas.addAll(chartInfo.getMeasures()); 29 | 30 | List> list = chartInfo.getDataList(); 31 | 32 | List headCellList = Lists.newArrayList(); 33 | 34 | dimAndMeas.forEach(each -> headCellList.add(new HeadCell(each.getCaption(), each.getCaption()))); 35 | 36 | TableViewVO tableViewVO = new TableViewVO(chartInfo.getChartType(), headCellList, list); 37 | 38 | //tableViewVO.setTotal(chartInfo.getDataList().getTotal()); 39 | 40 | return tableViewVO; 41 | } 42 | 43 | @Override 44 | public boolean beanIndicate(final Integer chartType) { 45 | if (chartType == CharTypeEnum.TABLE.code || chartType == CharTypeEnum.LIST.code) { 46 | return true; 47 | } 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/ReflectUtils.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.google.common.collect.Sets; 5 | 6 | import java.lang.reflect.Field; 7 | import java.lang.reflect.Modifier; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Set; 11 | 12 | /** 13 | * Created by zhaojun12 on 2017/3/26. 14 | */ 15 | public class ReflectUtils { 16 | 17 | public static Field[] getAllFields(Class targetClz) { 18 | return getAllFieldsAsList(targetClz).toArray(new Field[]{}); 19 | } 20 | 21 | public static boolean isJavaClass(Class clz) { 22 | return clz != null && clz.getClassLoader() == null; 23 | } 24 | 25 | public static List getAllFieldHasAnno(Class clazz, Class anno) { 26 | 27 | List result = new ArrayList<>(); 28 | 29 | List fields = getAllFieldsAsList(clazz); 30 | for (Field field : fields) { 31 | if (field.getAnnotation(anno) != null) { 32 | result.add(field); 33 | } 34 | } 35 | 36 | return result; 37 | 38 | } 39 | 40 | public static List getAllFieldsAsList(Class targetClz) { 41 | List fields = Lists.newArrayList(); 42 | Set nameSet = Sets.newHashSet(); 43 | 44 | while (targetClz != null) { 45 | for (Field field : targetClz.getDeclaredFields()) { 46 | if (nameSet.contains(field.getName()) || Modifier.isFinal(field.getModifiers())) continue; 47 | nameSet.add(field.getName()); 48 | fields.add(field); 49 | } 50 | 51 | targetClz = targetClz.getSuperclass(); 52 | } 53 | return fields; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/delete/Delete.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.delete; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.IllegalQueryException; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.util.Collection; 9 | import java.util.Iterator; 10 | import java.util.LinkedList; 11 | 12 | 13 | public class Delete { 14 | 15 | private String table; 16 | private final Context context; 17 | private final Collection conditions; 18 | private boolean terminated = false; 19 | 20 | public Delete(Context context) { 21 | this.context = context; 22 | this.context.append("DELETE FROM "); 23 | conditions = new LinkedList<>(); 24 | } 25 | 26 | public Delete(Context context, String table) { 27 | this(context); 28 | this.table = table; 29 | } 30 | 31 | public Delete where(String condition) { 32 | conditions.add(condition); 33 | return this; 34 | } 35 | 36 | public Delete and(String condition) { 37 | conditions.add(condition); 38 | return this; 39 | } 40 | 41 | private void terminate() { 42 | if (StringUtils.isBlank(table)) throw new IllegalQueryException("No table specified!"); 43 | 44 | if (!terminated) { 45 | context.append(table); 46 | 47 | if (!conditions.isEmpty()) { 48 | context.newLine().append("WHERE "); 49 | 50 | Iterator conditionIter = conditions.iterator(); 51 | 52 | while (conditionIter.hasNext()) { 53 | String condition = conditionIter.next(); 54 | context.append(condition); 55 | 56 | if (conditionIter.hasNext()) { 57 | context.newLine().append("AND "); 58 | } 59 | } 60 | } 61 | 62 | terminated = true; 63 | } 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | terminate(); 69 | return context.toString(); 70 | } 71 | } -------------------------------------------------------------------------------- /vagary-core/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | vagary 8 | 9 | 10 | 11 | contextConfigLocation 12 | classpath*:springconfig/spring-context.xml 13 | 14 | 15 | org.springframework.web.context.ContextLoaderListener 16 | 17 | 18 | 19 | 20 | encodingFilter 21 | org.springframework.web.filter.CharacterEncodingFilter 22 | 23 | encoding 24 | UTF-8 25 | 26 | 27 | forceEncoding 28 | true 29 | 30 | 31 | 32 | encodingFilter 33 | /* 34 | 35 | 36 | 37 | 38 | springServlet 39 | org.springframework.web.servlet.DispatcherServlet 40 | 41 | contextConfigLocation 42 | classpath*:springconfig/spring-mvc.xml 43 | 44 | 1 45 | 46 | 47 | springServlet 48 | / 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/DateFormatUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | 4 | import com.horrific.common.enums.DatePatternEnum; 5 | 6 | import java.text.ParseException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * 线程安全日期格式化工具 14 | * @author wanghong12 15 | * @date 2018-3-28 16 | */ 17 | public class DateFormatUtil { 18 | 19 | /** 20 | * 初始化ThreadLocal数据 21 | */ 22 | private static ThreadLocal> sdfMap = new ThreadLocal>(){ 23 | @Override 24 | protected Map initialValue() { 25 | return new HashMap<>(); 26 | } 27 | }; 28 | 29 | /** 30 | * 根据pattern(yyyy-MM-dd)获取simpleDateFormat 31 | * @param pattern 32 | * @return 33 | */ 34 | private static SimpleDateFormat getLocalSdf(String pattern) { 35 | Map formatMap = sdfMap.get(); 36 | SimpleDateFormat simpleDateFormat = formatMap.get(pattern); 37 | 38 | if (simpleDateFormat == null) { 39 | simpleDateFormat = new SimpleDateFormat(pattern); 40 | formatMap.put(pattern, simpleDateFormat); 41 | } 42 | return simpleDateFormat; 43 | } 44 | 45 | /** 46 | * 根据pattern(yyyy-MM-dd)格式化日期数据 47 | * @param date 48 | * @param datePatternEnum 49 | * @return 50 | */ 51 | public static String format(Date date, DatePatternEnum datePatternEnum) { 52 | return getLocalSdf(datePatternEnum.pattern).format(date); 53 | } 54 | 55 | /** 56 | * 根据pattern(yyyy-MM-dd)将String转为Date 57 | * @param dateStr 58 | * @param datePatternEnum 59 | * @return 60 | * @throws ParseException 61 | */ 62 | public static Date parse(String dateStr, DatePatternEnum datePatternEnum) throws ParseException { 63 | return getLocalSdf(datePatternEnum.pattern).parse(dateStr); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | vagary 8 | 9 | 10 | 11 | contextConfigLocation 12 | classpath*:springconfig/spring-context.xml 13 | 14 | 15 | org.springframework.web.context.ContextLoaderListener 16 | 17 | 18 | 19 | 20 | encodingFilter 21 | org.springframework.web.filter.CharacterEncodingFilter 22 | 23 | encoding 24 | UTF-8 25 | 26 | 27 | forceEncoding 28 | true 29 | 30 | 31 | 32 | encodingFilter 33 | /* 34 | 35 | 36 | 37 | 38 | springServlet 39 | org.springframework.web.servlet.DispatcherServlet 40 | 41 | contextConfigLocation 42 | classpath*:springconfig/spring-mvc.xml 43 | 44 | 1 45 | 46 | 47 | springServlet 48 | / 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/Having.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.TerminalExpression; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.sql.SQLException; 9 | import java.util.Arrays; 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | 13 | public class Having implements TerminalExpression { 14 | 15 | private final Context context; 16 | 17 | private boolean terminated = false; 18 | 19 | private final List conditions; 20 | 21 | Having(Context context) { 22 | this.context = context; 23 | this.context.appendLine("HAVING"); 24 | conditions = new LinkedList<>(); 25 | } 26 | 27 | Having(Context context, String... conditions) { 28 | this(context); 29 | this.conditions.addAll(Arrays.asList(conditions)); 30 | } 31 | 32 | public Having condition(String condition) { 33 | conditions.add(condition); 34 | return this; 35 | } 36 | 37 | public Having conditions(String... conditions) { 38 | this.conditions.addAll(Arrays.asList(conditions)); 39 | return this; 40 | } 41 | 42 | public OrderBy orderBy(String... columns) { 43 | terminate(); 44 | return new OrderBy(context, columns); 45 | } 46 | 47 | public OrderBy orderBy(OrderByType order, String... columns) { 48 | terminate(); 49 | return new OrderBy(context, order, columns); 50 | } 51 | 52 | public OrderBy orderBy(String column, OrderByType order) { 53 | terminate(); 54 | return new OrderBy(context, order, column); 55 | } 56 | 57 | public Limit limit(int start, int size) { 58 | terminate(); 59 | return new Limit(context, start, size); 60 | } 61 | 62 | @Override 63 | public List list(RowMapper rowMapper) throws SQLException { 64 | terminate(); 65 | return context.list(rowMapper); 66 | } 67 | 68 | @Override 69 | public E single(RowMapper rowMapper) throws SQLException { 70 | terminate(); 71 | return context.single(rowMapper); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | terminate(); 77 | return context.toString(); 78 | } 79 | 80 | private void terminate() { 81 | if (!terminated) { 82 | context.appendLine(StringUtils.join(conditions, ", ")); 83 | terminated = true; 84 | } 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /vagary-core/src/main/resources/springconfig/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | Spring MVC Configuration 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ALWAYS 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/classes/springconfig/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | Spring MVC Configuration 10 | 11 | 12 | 13 | 14 | 15 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ALWAYS 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /vagary-base/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | vagary 5 | com.horrific 6 | 1.3-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | vagary-base 11 | jar 12 | 13 | vagary-base 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | junit 23 | junit 24 | 3.8.1 25 | test 26 | 27 | 28 | com.google.guava 29 | guava 30 | 31 | 32 | 33 | org.projectlombok 34 | lombok 35 | 36 | 37 | 38 | org.apache.poi 39 | poi-ooxml 40 | 41 | 42 | 43 | org.apache.poi 44 | poi 45 | 46 | 47 | commons-beanutils 48 | commons-beanutils 49 | 50 | 51 | org.slf4j 52 | slf4j-api 53 | 1.8.0-alpha2 54 | 55 | 56 | javax.servlet 57 | javax.servlet-api 58 | 59 | 60 | com.fasterxml.jackson.core 61 | jackson-core 62 | 63 | 64 | com.fasterxml.jackson.core 65 | jackson-databind 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/OrderBy.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.TerminalExpression; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.sql.SQLException; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class OrderBy implements TerminalExpression { 14 | 15 | private Context context; 16 | 17 | private OrderByType order; 18 | 19 | private boolean terminated = false; 20 | 21 | private final List columns = new ArrayList<>(); 22 | 23 | OrderBy(Context context) { 24 | this.context = context; 25 | this.order = OrderByType.ASC; 26 | context.appendLine("ORDER BY"); 27 | } 28 | 29 | OrderBy(Context context, String... columns) { 30 | this(context); 31 | this.columns.addAll(Arrays.asList(columns)); 32 | } 33 | 34 | OrderBy(Context context, OrderByType order, String... columns) { 35 | this(context, columns); 36 | this.order = order; 37 | } 38 | 39 | public OrderBy column(String column) { 40 | return column(column, OrderByType.ASC); 41 | } 42 | 43 | public OrderBy columns(String... columns) { 44 | this.columns.addAll(Arrays.asList(columns)); 45 | this.order = OrderByType.ASC; 46 | return this; 47 | } 48 | 49 | public OrderBy columns(OrderByType order, String... columns) { 50 | columns(columns); 51 | this.order = order; 52 | return this; 53 | } 54 | 55 | public OrderBy column(String column, OrderByType order) { 56 | if (order == null) { 57 | return column(column); 58 | } 59 | 60 | columns.add(column); 61 | this.order = order; 62 | return this; 63 | } 64 | 65 | public Limit limit(Integer start, Integer size) { 66 | terminate(); 67 | return new Limit(context, start, size); 68 | } 69 | 70 | @Override 71 | public List list(RowMapper rowMapper) throws SQLException { 72 | terminate(); 73 | return context.list(rowMapper); 74 | } 75 | 76 | @Override 77 | public E single(RowMapper rowMapper) throws SQLException { 78 | terminate(); 79 | return context.single(rowMapper); 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | terminate(); 85 | return context.toString(); 86 | } 87 | 88 | private void terminate() { 89 | if (!terminated) { 90 | context.appendLine(" "); 91 | context.appendLine(StringUtils.join(columns, ", ")); 92 | //context.appendLine(" " + order.name()); 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/buildsql/MysqlBuilder.java: -------------------------------------------------------------------------------- 1 | package com.horrific.buildsql; 2 | 3 | import com.horrific.Param; 4 | import com.horrific.sqlbuilder.select.From; 5 | import com.horrific.sqlbuilder.select.GroupBy; 6 | import com.horrific.sqlbuilder.select.Having; 7 | import com.horrific.sqlbuilder.select.Join; 8 | import org.apache.commons.lang3.StringUtils; 9 | import org.springframework.stereotype.Component; 10 | 11 | /** 12 | * @author wanghong12 13 | * @version 2018-3-12 14 | */ 15 | @Component 16 | public class MysqlBuilder extends AbstractSqlBuilder { 17 | 18 | public String buildSql(Param param) { 19 | 20 | String table = param.getTable(); 21 | if (param.getPage()) { 22 | table = param.getTable() + COMMA + String.format(WHERE_NUM, param.getSize() * param.getOffset()); 23 | } 24 | 25 | From from = select(param).from().table(table); 26 | 27 | Join join = null; 28 | if (StringUtils.isNotEmpty(param.getJoinTable())) { 29 | join = from.innerJoin(param.getJoinTable()); 30 | } 31 | 32 | if (StringUtils.isEmpty(param.getGroupBy()) && StringUtils.isEmpty(param.getOrderBy())) { 33 | return where(param, from, join).limit(param.getOffset(), param.getSize()).toString(); 34 | } 35 | 36 | if (StringUtils.isEmpty(param.getGroupBy()) && StringUtils.isNotEmpty(param.getOrderBy())) { 37 | return where(param, from, join).orderBy(param.getOrderBy().split(COMMA)).limit(param.getOffset(), param.getSize()).toString(); 38 | } 39 | 40 | GroupBy groupBy = groupBy(param, where(param, from, join).groupBy()); 41 | 42 | if (StringUtils.isEmpty(param.getHaving()) && StringUtils.isEmpty(param.getOrderBy())) { 43 | return groupBy.limit(param.getOffset(), param.getSize()).toString(); 44 | } 45 | 46 | if (StringUtils.isEmpty(param.getHaving()) && StringUtils.isNotEmpty(param.getOrderBy())) { 47 | return groupBy.orderBy(param.getOrderBy().split(COMMA)).limit(param.getOffset(), param.getSize()).toString(); 48 | } 49 | 50 | Having having = having(param, groupBy); 51 | 52 | if (StringUtils.isEmpty(param.getOrderBy())) { 53 | return having.limit(param.getOffset(), param.getSize()).toString(); 54 | } 55 | 56 | if (StringUtils.isNotEmpty(param.getOrderBy())) { 57 | return having.orderBy(param.getOrderBy().split(COMMA)).limit(param.getOffset(), param.getSize()).toString(); 58 | } 59 | 60 | return null; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/update/Update.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.update; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.IllegalQueryException; 6 | 7 | import java.util.*; 8 | import java.util.Map.Entry; 9 | 10 | public class Update { 11 | 12 | private Context context; 13 | 14 | private boolean terminated = false; 15 | 16 | private String table; 17 | 18 | private Map assignments; 19 | 20 | private Collection conditions; 21 | 22 | public Update(Context context) { 23 | this.context = context; 24 | this.context.append("UPDATE "); 25 | this.assignments = new LinkedHashMap<>(); 26 | this.conditions = new LinkedList<>(); 27 | } 28 | 29 | public Update(Context context, String table) { 30 | this(context); 31 | this.table = table; 32 | } 33 | 34 | public Update table(String table) { 35 | this.table = table; 36 | return this; 37 | } 38 | 39 | public Update set(String column, String value) { 40 | assignments.put(column, value); 41 | return this; 42 | } 43 | 44 | public Update where(String condition) { 45 | conditions.add(condition); 46 | return this; 47 | } 48 | 49 | public Update and(String condition) { 50 | conditions.add(condition); 51 | return this; 52 | } 53 | 54 | private void terminate() { 55 | if (assignments.isEmpty()) throw new IllegalQueryException("Not contains SET statements!"); 56 | 57 | if (!terminated) { 58 | context.append(table).appendLine(" SET"); 59 | 60 | Iterator> iter = assignments.entrySet().iterator(); 61 | 62 | while (iter.hasNext()) { 63 | Entry assignment = iter.next(); 64 | context.append(assignment.getKey()) 65 | .append(" = ") 66 | .append("'") 67 | .append(assignment.getValue()) 68 | .append("'"); 69 | 70 | if (iter.hasNext()) { 71 | context.append(",").newLine(); 72 | } 73 | } 74 | 75 | if (!conditions.isEmpty()) { 76 | context.newLine().append("WHERE "); 77 | 78 | Iterator conditionIter = conditions.iterator(); 79 | 80 | while (conditionIter.hasNext()) { 81 | String condition = conditionIter.next(); 82 | context.append(condition); 83 | 84 | if (conditionIter.hasNext()) { 85 | context.newLine().append("AND "); 86 | } 87 | } 88 | } 89 | 90 | terminated = true; 91 | } 92 | } 93 | 94 | @Override 95 | public String toString() { 96 | terminate(); 97 | return context.toString(); 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/insert/Insert.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.insert; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.IllegalQueryException; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.util.Collections; 9 | import java.util.LinkedList; 10 | import java.util.List; 11 | 12 | public class Insert { 13 | 14 | private String table; 15 | private final List columns; 16 | private final List values; 17 | private final Context context; 18 | private boolean terminated = false; 19 | 20 | public Insert(Context context) { 21 | this.context = context; 22 | this.context.append("INSERT INTO "); 23 | this.columns = new LinkedList<>(); 24 | this.values = new LinkedList<>(); 25 | } 26 | 27 | public Insert(Context context, String table) { 28 | this(context); 29 | this.table = table; 30 | } 31 | 32 | public Insert table(String table) { 33 | this.table = table; 34 | return this; 35 | } 36 | 37 | public Insert columns(String... columns) { 38 | Collections.addAll(this.columns, columns); 39 | return this; 40 | } 41 | 42 | public Insert values(Object... values) { 43 | this.values.add(values); 44 | return this; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | terminate(); 50 | return context.toString(); 51 | } 52 | 53 | private void terminate() { 54 | if (columns.isEmpty()) throw new IllegalQueryException("No columns informed!"); 55 | if (values.isEmpty()) throw new IllegalQueryException("No values informed!"); 56 | 57 | for (Object[] valueSet : values) { 58 | if (valueSet.length != columns.size()) { 59 | throw new IllegalQueryException("Value size different from column size!"); 60 | } 61 | } 62 | 63 | if (!terminated) { 64 | context.appendLine(table) 65 | .append(" ( ") 66 | .append(StringUtils.join(columns, ", ")) 67 | .appendLine(" )") 68 | .append("VALUES ") 69 | .append(StringUtils.join(getValues(), ", ")); 70 | } 71 | } 72 | 73 | private String[] getValues() { 74 | String[] result = new String[values.size()]; 75 | 76 | for (int i = 0; i < result.length; i++) { 77 | Object[] objs = values.get(i); 78 | result[i] = toValue(objs); 79 | } 80 | 81 | return result; 82 | } 83 | 84 | private String toValue(Object[] objs) { 85 | String[] result = new String[objs.length]; 86 | 87 | for (int i = 0; i < result.length; i++) { 88 | if (objs[i] instanceof String) { 89 | result[i] = "'" + objs[i].toString() + "'"; 90 | } else { 91 | result[i] = objs[i].toString(); 92 | } 93 | } 94 | 95 | return "(" + StringUtils.join(result, ", ") + ")"; 96 | } 97 | } -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/GroupBy.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.TerminalExpression; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.sql.SQLException; 9 | import java.util.Arrays; 10 | import java.util.LinkedList; 11 | import java.util.List; 12 | 13 | public class GroupBy implements TerminalExpression { 14 | 15 | private final Context context; 16 | 17 | private final List columns; 18 | 19 | private boolean terminated = false; 20 | 21 | GroupBy(Context context) { 22 | this.context = context; 23 | context.appendLine("GROUP BY"); 24 | columns = new LinkedList<>(); 25 | } 26 | 27 | GroupBy(Context context, String... columns) { 28 | this(context); 29 | this.columns.addAll(Arrays.asList(columns)); 30 | } 31 | 32 | public GroupBy column(String column) { 33 | columns.add(column); 34 | return this; 35 | } 36 | 37 | public GroupBy columns(String... columns) { 38 | this.columns.addAll(Arrays.asList(columns)); 39 | return this; 40 | } 41 | 42 | public Having having() { 43 | terminate(); 44 | return new Having(context); 45 | } 46 | 47 | public Having having(String condition) { 48 | terminate(); 49 | return new Having(context, condition); 50 | } 51 | 52 | public OrderBy orderBy() { 53 | terminate(); 54 | return new OrderBy(context); 55 | } 56 | 57 | public OrderBy orderBy(String... columns) { 58 | terminate(); 59 | return new OrderBy(context, columns); 60 | } 61 | 62 | public Limit limit(Integer start, Integer size) { 63 | terminate(); 64 | return new Limit(context, start, size); 65 | } 66 | 67 | public OrderBy orderBy(OrderByType order, String... columns) { 68 | terminate(); 69 | return new OrderBy(context, order, columns); 70 | } 71 | 72 | public OrderBy orderBy(String column, OrderByType order) { 73 | terminate(); 74 | return new OrderBy(context, order, column); 75 | } 76 | 77 | @Override 78 | public List list(RowMapper rowMapper) throws SQLException { 79 | terminate(); 80 | return context.list(rowMapper); 81 | } 82 | 83 | @Override 84 | public E single(RowMapper rowMapper) throws SQLException { 85 | terminate(); 86 | return context.single(rowMapper); 87 | } 88 | 89 | @Override 90 | public String toString() { 91 | terminate(); 92 | return context.toString(); 93 | } 94 | 95 | private void terminate() { 96 | if (!terminated) { 97 | context.appendLine(StringUtils.join(columns, ", ")); 98 | terminated = true; 99 | } 100 | } 101 | 102 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/controller/QueryController.java: -------------------------------------------------------------------------------- 1 | package com.horrific.controller; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.horrific.Param; 5 | import com.horrific.common.dto.table.TableViewVO; 6 | import com.horrific.common.response.ServiceResponse; 7 | import com.horrific.common.tools.downloadexcel.local.DownloadTable; 8 | import com.horrific.service.QueryService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.web.bind.annotation.*; 13 | 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | /** 17 | * 所有查询请求统一入口 18 | * 19 | * @author wanghong12 20 | * @since 2018-3-13 21 | */ 22 | @Slf4j 23 | @Controller 24 | @RequestMapping("/toplife/{table_name}") 25 | public class QueryController { 26 | 27 | @Autowired 28 | private QueryService queryService; 29 | 30 | /** 31 | * 查询 32 | * @param param 33 | * @param tableName 34 | * @return 35 | */ 36 | @RequestMapping(value = "/_search", method = RequestMethod.POST, produces = "application/json; charset=UTF-8") 37 | @ResponseBody 38 | public ServiceResponse query(@RequestBody Param param, @PathVariable("table_name") String tableName) { 39 | 40 | param.setTable(tableName); 41 | 42 | try { 43 | return queryService.query(param); 44 | } catch (Exception e) { 45 | return ServiceResponse.failure("查询失败"); 46 | } 47 | 48 | } 49 | 50 | /** 51 | * 下载 52 | * @param param 53 | * @param tableName 54 | * @param response 55 | * @throws Exception 56 | */ 57 | @RequestMapping(value = "/_download", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json; charset=UTF-8") 58 | public void download(@RequestParam("param") String param, @PathVariable("table_name") String tableName, HttpServletResponse response) throws Exception { 59 | Param param1 = JSONObject.parseObject(param, Param.class); 60 | param1.setTable(tableName); 61 | param1.setChartType(1); 62 | ServiceResponse viewVO = queryService.query(param1); 63 | DownloadTable.writeContentToPage(viewVO.getData(), param1.getTitle(), response); 64 | } 65 | 66 | /** 67 | * 更新 68 | * @param sql 69 | * @return 70 | */ 71 | @RequestMapping(value = "/_update", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") 72 | @ResponseBody 73 | public ServiceResponse update(String sql) { 74 | try { 75 | queryService.update(sql); 76 | } catch (Exception e) { 77 | return ServiceResponse.failure("查询失败"); 78 | } 79 | return ServiceResponse.ok("更新成功!"); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/From.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.TerminalExpression; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.sql.SQLException; 9 | import java.util.ArrayList; 10 | import java.util.Arrays; 11 | import java.util.List; 12 | 13 | public class From implements TerminalExpression { 14 | 15 | private Context context; 16 | 17 | private boolean terminated = false; 18 | 19 | private final List tables = new ArrayList<>(); 20 | 21 | From(Context context) { 22 | this.context = context; 23 | this.context.appendLine(" FROM "); 24 | } 25 | 26 | public From table(String table) { 27 | tables.add(table); 28 | return this; 29 | } 30 | 31 | public From tables(String... tables) { 32 | this.tables.addAll(Arrays.asList(tables)); 33 | return this; 34 | } 35 | 36 | public From select(String selectQuery, String alias) { 37 | this.tables.add("(" + selectQuery + ") " + alias); 38 | return this; 39 | } 40 | 41 | public Where where() { 42 | terminate(); 43 | return new Where(context); 44 | } 45 | 46 | public Where where(String condition) { 47 | terminate(); 48 | return new Where(context, condition); 49 | } 50 | 51 | public GroupBy groupBy() { 52 | terminate(); 53 | return new GroupBy(context); 54 | } 55 | 56 | public GroupBy groupBy(String... columns) { 57 | terminate(); 58 | return new GroupBy(context, columns); 59 | } 60 | 61 | public Join leftOuterJoin(String condition) { 62 | terminate(); 63 | return new LeftOuterJoin(context, condition); 64 | } 65 | 66 | public Join rightOuterJoin(String condition) { 67 | terminate(); 68 | return new RightOuterJoin(context, condition); 69 | } 70 | 71 | public Join innerJoin(String condition) { 72 | terminate(); 73 | return new InnerJoin(context, condition); 74 | } 75 | 76 | public OrderBy orderBy() { 77 | terminate(); 78 | return new OrderBy(context); 79 | } 80 | 81 | public Limit limit(int start, int size) { 82 | terminate(); 83 | return new Limit(context, start, size); 84 | } 85 | 86 | @Override 87 | public List list(RowMapper rowMapper) throws SQLException { 88 | terminate(); 89 | return context.list(rowMapper); 90 | } 91 | 92 | @Override 93 | public E single(RowMapper rowMapper) throws SQLException { 94 | terminate(); 95 | return context.single(rowMapper); 96 | } 97 | 98 | @Override 99 | public String toString() { 100 | terminate(); 101 | return context.toString(); 102 | } 103 | 104 | private void terminate() { 105 | if (!terminated) { 106 | final String newLine = System.getProperty("line.separator"); 107 | this.context.appendLine(StringUtils.join(tables, ",")); 108 | //this.context.appendLine(newLine); 109 | terminated = true; 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/chartconvert/impl/TendencyChartConvert.java: -------------------------------------------------------------------------------- 1 | package com.horrific.chartconvert.impl; 2 | 3 | import com.google.common.collect.Lists; 4 | import com.google.common.collect.Maps; 5 | import com.horrific.chartconvert.AbstractChartConvert; 6 | import com.horrific.common.dto.ChartInfo; 7 | import com.horrific.common.dto.Field; 8 | import com.horrific.common.dto.chart.DefaultChartVO; 9 | import com.horrific.common.dto.chart.ListChartDTO; 10 | import com.horrific.common.dto.chart.Point; 11 | import com.horrific.common.enums.CharTypeEnum; 12 | import com.horrific.common.utils.DateUtil; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.List; 16 | import java.util.Map; 17 | 18 | 19 | /** 20 | * 可视化组件:线图、柱图、柱线图、条状图 21 | * @author wanghong12 22 | * @version 创建时间:2017/10/15 23 | */ 24 | @Component 25 | public class TendencyChartConvert extends AbstractChartConvert>> { 26 | 27 | @Override 28 | public DefaultChartVO> convert(ChartInfo chartInfo) { 29 | List dimension = Lists.newArrayList(); 30 | Map> pointMap = Maps.newHashMap(); 31 | List> measure = Lists.newArrayList(); 32 | if(chartInfo.getDataList() == null) { 33 | return new DefaultChartVO(chartInfo.getChartType(), dimension, measure); 34 | } 35 | 36 | chartInfo.getDataList().forEach(map -> { 37 | String dimensionValue = map.get(chartInfo.getDim()) == null ? null : DateUtil.toValue(map.get(chartInfo.getDim())).toString(); 38 | dimension.add(dimensionValue); 39 | map.forEach((String key, Object value) -> { 40 | if (isBelong(chartInfo.getMeasures(), key)) { 41 | List points = pointMap.get(key); 42 | if (points != null) { 43 | points.add(new Point(dimensionValue, value)); 44 | } else { 45 | pointMap.put(key, Lists.newArrayList(new Point(dimensionValue, value))); 46 | } 47 | } 48 | }); 49 | }); 50 | 51 | pointMap.forEach((key, value) -> measure.add(new ListChartDTO(key, value))); 52 | return new DefaultChartVO(chartInfo.getChartType(), dimension, measure); 53 | } 54 | 55 | @Override 56 | public boolean beanIndicate(Integer chartType) { 57 | return chartType == CharTypeEnum.LINE.code || chartType == CharTypeEnum.BAR.code || chartType == CharTypeEnum.STRIP.code; 58 | } 59 | 60 | private boolean isBelong(final List measures, final String measure) { 61 | if (measures == null) { 62 | return false; 63 | } 64 | for (Field field : measures) { 65 | if (field.getCaption().equals(measure)) { 66 | return true; 67 | } 68 | } 69 | return false; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/Limit.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.Database; 6 | import com.horrific.sqlbuilder.TerminalExpression; 7 | import org.omg.PortableInterceptor.INACTIVE; 8 | 9 | import java.sql.SQLException; 10 | import java.util.List; 11 | 12 | public class Limit implements TerminalExpression { 13 | 14 | private final Context context; 15 | 16 | public Limit(Context context, Integer start, Integer size) { 17 | this.context = limit(context, start, size); 18 | } 19 | 20 | @Override 21 | public List list(RowMapper rowMapper) throws SQLException { 22 | return context.list(rowMapper); 23 | } 24 | 25 | @Override 26 | public E single(RowMapper rowMapper) throws SQLException { 27 | return context.single(rowMapper); 28 | } 29 | 30 | private Context limit(Context context, Integer start, Integer size) { 31 | return new LimiterFactory().create(context.getDatabase()).limit(context, start, size); 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return context.toString(); 37 | } 38 | } 39 | 40 | interface Limiter { 41 | Context limit(Context context, Integer start, Integer size); 42 | } 43 | 44 | class HSQLDBLimiter implements Limiter { 45 | 46 | @Override 47 | public Context limit(Context context, Integer start, Integer size) { 48 | if (size != null) { 49 | context.appendLine(" LIMIT " + size); 50 | context.addParameters(size); 51 | } 52 | if (start != null) { 53 | context.appendLine(" OFFSET " + start); 54 | context.addParameters(start); 55 | } 56 | 57 | return context; 58 | } 59 | 60 | } 61 | 62 | class OracleLimiter implements Limiter { 63 | 64 | @Override 65 | public Context limit(Context context, Integer start, Integer size) { 66 | Context c = new Context(context); 67 | c.appendLine("SELECT"); 68 | c.appendLine("data.*"); 69 | c.appendLine("FROM"); 70 | c.appendLine("("); 71 | c.appendLine("SELECT"); 72 | c.appendLine("ord_data.*,"); 73 | c.appendLine("rownum AS rnum"); 74 | c.appendLine("FROM"); 75 | c.appendLine("("); 76 | c.appendLine(context.toString()); 77 | c.appendLine(")"); 78 | c.appendLine("ord_data"); 79 | c.appendLine(")"); 80 | c.appendLine("data"); 81 | c.appendLine("WHERE"); 82 | c.appendLine("rnum BETWEEN ? AND ?"); 83 | c.addParameters(start); 84 | c.addParameters(start + size); 85 | return c; 86 | } 87 | 88 | } 89 | 90 | class DefaultLimiter implements Limiter { 91 | @Override 92 | public Context limit(Context context, Integer start, Integer size) { 93 | return context; 94 | } 95 | } 96 | 97 | class LimiterFactory { 98 | Limiter create(Database database) { 99 | /*switch (database) { 100 | case HSQLDB: 101 | return new HSQLDBLimiter(); 102 | case ORACLE: 103 | return new OracleLimiter(); 104 | default: 105 | return new DefaultLimiter(); 106 | }*/ 107 | return new HSQLDBLimiter(); 108 | } 109 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/query/AbstractQuery.java: -------------------------------------------------------------------------------- 1 | package com.horrific.query; 2 | 3 | import com.alibaba.druid.pool.DruidDataSource; 4 | import com.alibaba.druid.pool.ElasticSearchDruidDataSourceFactory; 5 | import com.google.common.collect.Maps; 6 | import com.horrific.Param; 7 | import com.horrific.buildsql.MysqlBuilder; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.jdbc.core.JdbcTemplate; 11 | import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; 12 | 13 | import javax.sql.DataSource; 14 | import java.util.HashMap; 15 | import java.util.List; 16 | import java.util.Map; 17 | import java.util.Properties; 18 | 19 | /** 20 | * @author wanghong12 21 | * @since 2018-3-13 22 | */ 23 | @Slf4j 24 | public abstract class AbstractQuery { 25 | 26 | public static final String COUNT_SQL = "SELECT count(*) num FROM (%s) t"; 27 | 28 | @Autowired 29 | private MysqlBuilder builder; 30 | 31 | @Autowired 32 | private DataSource dataSource; 33 | 34 | abstract T query(Param param); 35 | 36 | /*static { 37 | Properties properties = new Properties(); 38 | properties.put("url", "jdbc:elasticsearch://192.168.200.122:20300"); 39 | try { 40 | dataSource = (DruidDataSource) ElasticSearchDruidDataSourceFactory.createDataSource(properties); 41 | } catch (Exception e) { 42 | e.printStackTrace(); 43 | } 44 | }*/ 45 | 46 | /** 47 | * 查询操作 48 | * 49 | * @param param 50 | * @return 51 | */ 52 | public List> doQuery(Param param) { 53 | 54 | String sql = builder.buildSql(param); 55 | 56 | log.info("sql:{}", sql); 57 | 58 | NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource); 59 | 60 | //todo validate sql 61 | 62 | return template.queryForList(sql, Maps.newHashMap()); 63 | } 64 | 65 | /** 66 | * 分页时候做求和运算 67 | * 68 | * @param param 69 | */ 70 | public void countQuery(Param param) { 71 | param.setPage(false); 72 | param.setOrderBy(null); 73 | param.setSize(null); 74 | param.setOffset(null); 75 | String sql = builder.buildSql(param); 76 | sql = String.format(COUNT_SQL, sql); 77 | log.info("sql:{}", sql); 78 | JdbcTemplate template = new JdbcTemplate(dataSource); 79 | Map map = template.queryForMap(sql); 80 | param.setTotal(String.valueOf(map.get("num"))); 81 | } 82 | 83 | /** 84 | * 对sql进行验证 85 | * 86 | * @param sql 87 | */ 88 | abstract void validate(String sql); 89 | 90 | /** 91 | * 更新操作 92 | * 93 | * @param sql 94 | */ 95 | public void doUpdate(String sql) { 96 | NamedParameterJdbcTemplate template = new NamedParameterJdbcTemplate(dataSource); 97 | template.update(sql, new HashMap<>()); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /out/artifacts/vagary_core_Web_exploded/WEB-INF/classes/springconfig/spring-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | Spring Configuration 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/select/Where.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder.select; 2 | 3 | 4 | import com.horrific.sqlbuilder.Context; 5 | import com.horrific.sqlbuilder.TerminalExpression; 6 | 7 | import java.sql.SQLException; 8 | import java.util.List; 9 | 10 | public class Where extends Condition implements TerminalExpression { 11 | 12 | Where(Context context) { 13 | super(context); 14 | add("1 = 1"); 15 | } 16 | 17 | Where(Context context, String condition) { 18 | super(context); 19 | add(condition); 20 | } 21 | 22 | public GroupBy groupBy() { 23 | return new GroupBy(context); 24 | } 25 | 26 | public GroupBy groupBy(String... columns) { 27 | return new GroupBy(context, columns); 28 | } 29 | 30 | public OrderBy orderBy() { 31 | return new OrderBy(context); 32 | } 33 | 34 | public OrderBy orderBy(String... columns) { 35 | return new OrderBy(context, columns); 36 | } 37 | 38 | public OrderBy orderBy(OrderByType order, String... columns) { 39 | return new OrderBy(context, order, columns); 40 | } 41 | 42 | public Where and(Object condition) { 43 | new AndCondition(context).add(condition); 44 | return this; 45 | } 46 | 47 | public Where and(Object condition, Object parameter) { 48 | new AndCondition(context).add(condition, parameter); 49 | return this; 50 | } 51 | 52 | public Where and(String condition, String parameter) { 53 | new AndCondition(context).add(condition, parameter); 54 | return this; 55 | } 56 | 57 | public Where and(Object condition, Object... parameters) { 58 | new AndCondition(context).add(condition, parameters); 59 | return this; 60 | } 61 | 62 | public Where andBetween(String columnName, Object start, Object end) { 63 | new AndCondition(context).between(columnName, start, end); 64 | return this; 65 | } 66 | 67 | public Where or(Object condition) { 68 | new OrCondition(context).add(condition); 69 | return this; 70 | } 71 | 72 | public Where or(Object condition, Object parameter) { 73 | new OrCondition(context).add(condition, parameter); 74 | return this; 75 | } 76 | 77 | public Where or(String condition, String parameter) { 78 | new OrCondition(context).add(condition, parameter); 79 | return this; 80 | } 81 | 82 | public Where or(Object condition, Object... parameters) { 83 | new OrCondition(context).add(condition, parameters); 84 | return this; 85 | } 86 | 87 | public Where orBetween(String columnName, Object start, Object end) { 88 | new OrCondition(context).between(columnName, start, end); 89 | return this; 90 | } 91 | 92 | public Limit limit(Integer start, Integer size) { 93 | return new Limit(context, start, size); 94 | } 95 | 96 | @Override 97 | public List list(RowMapper rowMapper) throws SQLException { 98 | return context.list(rowMapper); 99 | } 100 | 101 | @Override 102 | public E single(RowMapper rowMapper) throws SQLException { 103 | return context.single(rowMapper); 104 | } 105 | 106 | @Override 107 | protected String getPrefix() { 108 | return " WHERE"; 109 | } 110 | 111 | @Override 112 | public String toString() { 113 | return context.toString(); 114 | } 115 | } -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | import com.google.common.collect.Maps; 4 | 5 | import java.util.Collection; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.stream.Collectors; 9 | 10 | /** 11 | * Created by hongshuai1 on 2017/2/10. 12 | */ 13 | public final class CollectionUtils { 14 | public CollectionUtils() { 15 | } 16 | 17 | public static boolean isEmpty(Collection collection) { 18 | return collection == null || collection.isEmpty(); 19 | } 20 | 21 | public static boolean isEmpty(Map map) { 22 | return map == null || map.isEmpty(); 23 | } 24 | 25 | public static String[] toArray(List values) { 26 | String[] valuesAsArray = new String[values.size()]; 27 | return values.toArray(valuesAsArray); 28 | } 29 | 30 | /** 31 | * 把List转换Map结构,Map值的为V类型的POJO 32 | * 33 | * @param datas list集合的数据 34 | * @param joiner key的拼接符号 35 | * @param fieldNames 单条数据中哪些字段的值作为key 36 | * @param List中单条数据的数据类型 37 | * @return 38 | */ 39 | public static Map listToMap(List datas, String joiner, String... fieldNames) { 40 | 41 | Map map = Maps.newHashMap(); 42 | 43 | datas.forEach(data -> { 44 | 45 | StringBuilder sb = new StringBuilder(); 46 | 47 | for (int i = 0; i < fieldNames.length; i++) { 48 | sb.append(BeanUtil.getProperty(fieldNames[i], data)); 49 | if (i != fieldNames.length - 1) { 50 | sb.append(joiner); 51 | } 52 | } 53 | map.put(sb.toString(), data); 54 | 55 | }); 56 | 57 | return map; 58 | 59 | } 60 | 61 | 62 | /** 63 | * 对集合按指定的字段进行排序 64 | * 65 | * @param datas 待排序的集合 66 | * @param sortFieldName 排序时,使用的比较字段的字段名 67 | * @param asc true-升序 false-降序 68 | * @param 69 | * @return 70 | */ 71 | public static List sort(List datas, final String sortFieldName, boolean asc) { 72 | datas = datas.stream() 73 | .sorted((o1, o2) -> { 74 | String first = first = BeanUtil.getProperty(sortFieldName, o1); 75 | String second = second = BeanUtil.getProperty(sortFieldName, o2); 76 | if (asc) { 77 | return first.compareTo(second); 78 | } else { 79 | return second.compareTo(first); 80 | } 81 | }).collect(Collectors.toList()); 82 | return datas; 83 | } 84 | 85 | /** 86 | * 类型转换 87 | * 88 | * @param subs 89 | * @param parents 90 | * @param 91 | * @param 92 | * @return 93 | */ 94 | public static List convertType(List subs, List parents) { 95 | if (subs == null) { 96 | return null; 97 | } 98 | subs.stream().forEach(sub -> { 99 | parents.add(sub); 100 | }); 101 | return parents; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /vagary-sql/src/main/java/com/horrific/sqlbuilder/Context.java: -------------------------------------------------------------------------------- 1 | package com.horrific.sqlbuilder; 2 | 3 | 4 | import com.horrific.sqlbuilder.select.RowMapper; 5 | 6 | import java.sql.Connection; 7 | import java.sql.PreparedStatement; 8 | import java.sql.ResultSet; 9 | import java.sql.SQLException; 10 | import java.util.Arrays; 11 | import java.util.LinkedList; 12 | import java.util.List; 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | public class Context { 17 | 18 | private static final String NEW_LINE = System.getProperty("line.separator"); 19 | 20 | private final Connection connection; 21 | 22 | private final StringBuilder sql; 23 | 24 | private final List parameters; 25 | 26 | private final Database database; 27 | 28 | private transient final Logger log; 29 | 30 | { 31 | this.log = Logger.getLogger(getClass().getName()); 32 | } 33 | 34 | public Context(Context clone) { 35 | this.connection = clone.connection; 36 | this.parameters = new LinkedList(clone.parameters); 37 | this.sql = new StringBuilder(); 38 | this.database = clone.database; 39 | } 40 | 41 | public Context(Database database, Connection connection) { 42 | this.connection = connection; 43 | this.database = database; 44 | sql = new StringBuilder(); 45 | parameters = new LinkedList<>(); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return sql.toString(); 51 | } 52 | 53 | public List list(RowMapper rowMapper) throws SQLException { 54 | List result = new LinkedList<>(); 55 | 56 | try (ResultSet resultSet = execute(toString())) { 57 | int rowNum = 0; 58 | while (resultSet.next()) { 59 | E obj = rowMapper.convert(resultSet, rowNum++); 60 | result.add(obj); 61 | } 62 | } 63 | 64 | return result; 65 | } 66 | 67 | public E single(RowMapper rowMapper) throws SQLException { 68 | E result = null; 69 | 70 | try (ResultSet resultSet = execute(toString())) { 71 | if (resultSet.next()) { 72 | result = rowMapper.convert(resultSet, 1); 73 | 74 | if (resultSet.next()) { 75 | throw new SQLException("The query returned more than one result"); 76 | } 77 | } 78 | } 79 | 80 | return result; 81 | } 82 | 83 | public Context append(String expression) { 84 | sql.append(expression); 85 | return this; 86 | } 87 | 88 | public Context appendLine(String expression) { 89 | sql.append(expression); 90 | //sql.append(NEW_LINE); 91 | return this; 92 | } 93 | 94 | public Context newLine() { 95 | //sql.append(NEW_LINE); 96 | return this; 97 | } 98 | 99 | public void addParameters(Object... parameters) { 100 | this.parameters.addAll(Arrays.asList(parameters)); 101 | } 102 | 103 | public Database getDatabase() { 104 | return database; 105 | } 106 | 107 | private ResultSet execute(String sql) throws SQLException { 108 | log.log(Level.INFO, "\n" + sql); 109 | try (PreparedStatement statement = prepareStatement(sql)) { 110 | return statement.executeQuery(); 111 | } 112 | } 113 | 114 | private PreparedStatement prepareStatement(String sql) throws SQLException { 115 | PreparedStatement statement = connection.prepareStatement(sql); 116 | 117 | int i = 1; 118 | for (Object parameter : parameters) { 119 | statement.setObject(i++, parameter); 120 | } 121 | 122 | return statement; 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/chartconvert/AbstractChartConvert.java: -------------------------------------------------------------------------------- 1 | package com.horrific.chartconvert; 2 | 3 | 4 | import com.google.common.collect.Lists; 5 | import com.horrific.Param; 6 | import com.horrific.common.dto.ChartInfo; 7 | import com.horrific.common.dto.Field; 8 | import org.apache.commons.lang3.StringUtils; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | /** 14 | * @param 15 | * @author wanghong12 16 | * @since 2018-3-13 17 | */ 18 | 19 | public abstract class AbstractChartConvert implements ChartConvert { 20 | 21 | public static final String DEFAULT_DIMENSION = "bs"; 22 | public static final String DEFAULT_MEASURE = "gmv"; 23 | public static final String DEFAULT_DIVIDE_VALUE = "#ALL"; 24 | 25 | /** 26 | * @param data query information 27 | * @param params query information 28 | * @return 29 | */ 30 | @Override 31 | public T handle(List> data, Param params) { 32 | ChartInfo chartInfo = argumentParse(data, params); 33 | return convert(chartInfo); 34 | } 35 | 36 | /** 37 | * 根据chartInfo转换成可视化组件所需格式 38 | * 39 | * @param chartInfo 40 | * @return 41 | */ 42 | public abstract T convert(ChartInfo chartInfo); 43 | 44 | /** 45 | * @param chartType chart type 46 | * @return 47 | */ 48 | @Override 49 | public abstract boolean beanIndicate(Integer chartType); 50 | 51 | /** 52 | * @param data query information 53 | * @param params queryParams 54 | * @return 55 | */ 56 | public ChartInfo argumentParse(List> data, Param params) { 57 | //获取图表类型 58 | Integer chartType = params.getChartType(); 59 | 60 | String divide = getDivideValue(params); 61 | 62 | //获取维度 63 | List dims = toField(params.getGroupBy()); 64 | //获取度量 65 | List measures = toField(params.getColumns()); 66 | //获取第一个维度caption 67 | String dim = dims.size() == 0 ? DEFAULT_DIMENSION : dims.get(0).getCaption(); 68 | //获取第一个度量caption 69 | String measure = measures.size() == 0 ? DEFAULT_MEASURE : measures.get(0).getCaption(); 70 | return new ChartInfo(chartType, data, dims, measures, dim, measure, params.getTotal(), divide); 71 | } 72 | 73 | /** 74 | * 将参数转化为维度和指标 75 | * 76 | * @param str 77 | * @return 78 | */ 79 | private static List toField(String str) { 80 | List fields = Lists.newArrayList(); 81 | if (StringUtils.isEmpty(str)) { 82 | return fields; 83 | } 84 | String[] split = str.split(","); 85 | String[][] array = new String[split.length][]; 86 | for (int i = 0; i < split.length; i++) { 87 | array[i] = split[i].trim().split("\\s+"); 88 | if (array[i].length == 1) { 89 | fields.add(new Field(array[i][0], array[i][0])); 90 | } else { 91 | fields.add(new Field(array[i][0], array[i][1])); 92 | } 93 | 94 | } 95 | 96 | return fields; 97 | } 98 | 99 | public static String getDivideValue(Param params) { 100 | String divide = params.getDivide() == null ? DEFAULT_DIMENSION : params.getDivide(); 101 | if (StringUtils.isEmpty(params.getWhereOn())) { 102 | return DEFAULT_DIVIDE_VALUE; 103 | } 104 | String[] split = params.getWhereOn().split(","); 105 | for(String e : split) { 106 | if (e.contains(divide.trim())) { 107 | return e.substring(e.indexOf("\'") + 1, e.length() - 1); 108 | } 109 | } 110 | return DEFAULT_DIVIDE_VALUE; 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /vagary-core/src/main/java/com/horrific/buildsql/AbstractSqlBuilder.java: -------------------------------------------------------------------------------- 1 | package com.horrific.buildsql; 2 | 3 | import com.horrific.Param; 4 | import com.horrific.sqlbuilder.builder.QueryBuilder; 5 | import com.horrific.sqlbuilder.select.*; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | import java.util.Arrays; 9 | 10 | /** 11 | * @author wanghong12 12 | */ 13 | public abstract class AbstractSqlBuilder { 14 | 15 | public static final String COMMA = ","; 16 | 17 | public static final String OIL = "#"; 18 | 19 | public static final String SELECT_NUM = "@rownum:=@rownum+1 as num"; 20 | 21 | public static final String WHERE_NUM = "(select @rownum:=%s) t"; 22 | 23 | public static final String SUBTRING = "SUBSTRING_INDEX(data_value, '_', 1) %sId, SUBSTRING_INDEX(data_value, '_', -1) %sValue"; 24 | 25 | public static final String SPECIAL_VALUE = "data_value"; 26 | 27 | public Select select(Param param) { 28 | QueryBuilder builder = new QueryBuilder(); 29 | Select select = builder.select(); 30 | 31 | if (param.getPage()) { 32 | select.column(SELECT_NUM); 33 | } 34 | 35 | if (StringUtils.isEmpty(param.getColumns())) { 36 | select.all(); 37 | } else { 38 | String[] clumns = param.getColumns().split(COMMA); 39 | Arrays.stream(clumns).forEach(s -> { 40 | if (s.contains(SPECIAL_VALUE)) { 41 | String replace = getAlise(s); 42 | select.column(String.format(SUBTRING, replace, replace)); 43 | } 44 | select.column(s); 45 | }); 46 | } 47 | 48 | if (StringUtils.isNotEmpty(param.getGroupBy())) { 49 | String[] dims = param.getGroupBy().split(COMMA); 50 | Arrays.stream(dims).forEach(s -> select.column(s)); 51 | } 52 | return select; 53 | } 54 | 55 | public Where where(Param param, From from, Join join) { 56 | final Where[] where = new Where[1]; 57 | if (join != null) { 58 | where[0] = join.where(); 59 | } else { 60 | where[0] = from.where(); 61 | } 62 | 63 | if (StringUtils.isNotEmpty(param.getWhereOn())) { 64 | String[] wheres = param.getWhereOn().split(COMMA); 65 | Arrays.stream(wheres).forEach(w -> { 66 | if (!w.contains(OIL)) { 67 | where[0].and(w); 68 | } 69 | }); 70 | } 71 | if (StringUtils.isNotEmpty(param.getWhereOr())) { 72 | String[] wheres = param.getWhereOr().split(COMMA); 73 | Arrays.stream(wheres).forEach(w -> { 74 | if (!w.contains(OIL)) { 75 | where[0].or(w); 76 | } 77 | }); 78 | } 79 | return where[0]; 80 | } 81 | 82 | public GroupBy groupBy(Param param, GroupBy groupBy) { 83 | if (StringUtils.isNotEmpty(param.getGroupBy())) { 84 | String[] groupBys = param.getGroupBy().split(COMMA); 85 | Arrays.stream(groupBys).forEach(g -> groupBy.column(g)); 86 | } 87 | return groupBy; 88 | } 89 | 90 | public Having having(Param param, GroupBy groupBy) { 91 | if (StringUtils.isNotEmpty(param.getHaving())) { 92 | Having having = groupBy.having(); 93 | String[] hs = param.getHaving().split(COMMA); 94 | Arrays.stream(hs).forEach(h -> having.condition(h)); 95 | return having; 96 | } 97 | return null; 98 | } 99 | 100 | public String getAlise(String column) { 101 | String[] alises = column.split("\\s+"); 102 | if (alises.length == 1) { 103 | return alises[0]; 104 | } else { 105 | return alises[1]; 106 | } 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/tools/downloadexcel/local/DownloadTable.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.tools.downloadexcel.local; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import com.fasterxml.jackson.core.JsonFactory; 5 | import com.fasterxml.jackson.core.JsonGenerator; 6 | import com.fasterxml.jackson.databind.ObjectMapper; 7 | import com.fasterxml.jackson.databind.SerializationFeature; 8 | import com.horrific.common.dto.table.TableViewVO; 9 | import com.horrific.common.response.ServiceResponse; 10 | import com.horrific.common.utils.DownloadExcelUtil; 11 | import lombok.extern.slf4j.Slf4j; 12 | import org.apache.poi.xssf.streaming.SXSSFWorkbook; 13 | 14 | import javax.servlet.ServletOutputStream; 15 | import javax.servlet.http.HttpServletResponse; 16 | import java.io.ByteArrayOutputStream; 17 | import java.net.URLEncoder; 18 | import java.time.LocalDate; 19 | import java.time.format.DateTimeFormatter; 20 | 21 | /** 22 | * @author wanghong12 23 | * @date 2018-3-28 24 | */ 25 | 26 | @Slf4j 27 | public class DownloadTable { 28 | 29 | private static final String DEFAULT_CONTENT_TYPE = "application/json;charset=UTF-8"; 30 | 31 | private static final String EXCELSUFFIX_XLSX = ".xlsx"; 32 | 33 | private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd"); 34 | 35 | /** 36 | * return json to webPage 37 | * @param o 38 | * @param response 39 | * @throws Exception 40 | */ 41 | public static void writeContentToPage(TableViewVO o, String title, HttpServletResponse response) throws Exception { 42 | if (o == null){ 43 | byte[] data = toJson(ServiceResponse.failure("下载失败")); 44 | response.setContentType(DEFAULT_CONTENT_TYPE); 45 | ServletOutputStream out = response.getOutputStream(); 46 | out.write(data); 47 | out.flush(); 48 | out.close(); 49 | }else { 50 | TableViewVO tableVo = o; 51 | response.setContentType("application/vnd.ms-excel;charset=utf-8"); 52 | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(getTitle(title), "UTF-8")); 53 | 54 | try (ServletOutputStream os = response.getOutputStream()) { 55 | SXSSFWorkbook workbook = DownloadExcelUtil.download(title, tableVo); 56 | workbook.write(os); 57 | os.flush(); 58 | os.close(); 59 | workbook.dispose(); 60 | log.info("文件下载成功!-{}", title); 61 | } catch (Exception e) { 62 | log.error("Excel下载异常:错误信息-{}", e); 63 | throw e; 64 | } 65 | } 66 | 67 | } 68 | 69 | /** 70 | * 拼接excel标题 71 | * 72 | * @param title 73 | * @return 74 | */ 75 | private static String getTitle(String title) { 76 | 77 | title = title.replace(EXCELSUFFIX_XLSX, ""); 78 | 79 | return new StringBuilder(title) 80 | .append("-") 81 | .append(LocalDate.now().format(FORMATTER)) 82 | .append(EXCELSUFFIX_XLSX) 83 | .toString(); 84 | 85 | } 86 | 87 | /** 88 | * convert object to json via jackson 89 | * @param data 90 | * @return 91 | * @throws Exception 92 | */ 93 | private static byte[] toJson(Object data) throws Exception { 94 | 95 | JsonFactory jsonFactory = new JsonFactory(); 96 | 97 | jsonFactory.configure(JsonGenerator.Feature.WRITE_BIGDECIMAL_AS_PLAIN, true); 98 | 99 | ObjectMapper mapper = new ObjectMapper(jsonFactory); 100 | 101 | mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); 102 | mapper.configure(SerializationFeature.INDENT_OUTPUT, false); 103 | 104 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 105 | 106 | mapper.writeValue(bos, data); 107 | 108 | return bos.toByteArray(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/NumberUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class NumberUtil { 6 | 7 | 8 | /** 9 | * 判断是否为数字 10 | * 11 | * @param data 数据 12 | * @return 13 | */ 14 | public static boolean isNumberOfValue(Object data) { 15 | 16 | if (data == null) { 17 | return false; 18 | } 19 | 20 | Class fieldType = data.getClass(); 21 | 22 | //如果是包装类型或基本类型 23 | return Number.class.isAssignableFrom(fieldType) 24 | || fieldType == short.class 25 | || fieldType == int.class 26 | || fieldType == float.class 27 | || fieldType == double.class 28 | || fieldType == long.class; 29 | 30 | } 31 | 32 | /** 33 | * 判断是否为字符串类型的数字 34 | * 35 | * @param data 数据 36 | * @return 37 | */ 38 | public static boolean isStringNumber(Object data) { 39 | 40 | if (data == null || !(data instanceof String)) { 41 | return false; 42 | } 43 | try{ 44 | new BigDecimal(data.toString()); 45 | return true; 46 | }catch (Exception e){ 47 | return false; 48 | } 49 | } 50 | 51 | 52 | 53 | /** 54 | * 两个数相除,如果存在不是数字,或除法异常,返回默认值 55 | * 56 | * @param dataA 被除数 57 | * @param dataB 除数 58 | * @param defaultValue 默认值 59 | * @return 60 | */ 61 | public static Object divide(Object dataA, Object dataB, Object defaultValue) { 62 | return divide(dataA, dataB, 20, defaultValue); 63 | } 64 | 65 | /** 66 | * 两个数相除,如果存在不是数字,或除法异常,返回默认值 67 | * 68 | * @param dataA 被除数 69 | * @param dataB 除数 70 | * @return 71 | */ 72 | 73 | /** 74 | * 把数据转换为BigDecimal类型 75 | * 76 | * @param data 77 | * @return 78 | */ 79 | public static BigDecimal toBigDecimal(Object data) { 80 | if (isNumber(data)) { 81 | return new BigDecimal(data.toString()); 82 | } 83 | return BigDecimal.ZERO; 84 | } 85 | 86 | /** 87 | * 两个数相除,如果存在不是数字,或除法异常,返回默认值 88 | * 89 | * @param dataA 被除数 90 | * @param dataB 除数 91 | * @param scale 精度 92 | * @param defaultValue 默认值 93 | * @return 94 | */ 95 | public static Object divide(Object dataA, Object dataB, int scale, Object defaultValue) { 96 | 97 | if (isNumber(dataA) && isNumber(dataB)) { 98 | 99 | try { 100 | //注意循环小数的出现,因此设置保留小数位数,四舍五入的方式 101 | return toBigDecimal(dataA).divide(toBigDecimal(dataB), scale, BigDecimal.ROUND_HALF_UP).toString(); 102 | } catch (Exception e) { 103 | return defaultValue; 104 | } 105 | 106 | } 107 | 108 | return defaultValue; 109 | 110 | } 111 | 112 | /** 113 | * 判断是否为数字 114 | * 115 | * @param data 116 | * @return 117 | */ 118 | public static boolean isNumber(Object data) { 119 | return isNumberOfValue(data) || isStringNumber(data); 120 | } 121 | 122 | /** 123 | * 科学计数法转化 124 | * 125 | * @param value 126 | * @return 127 | */ 128 | public static Object fetchConvertScientificNotationNum(Object value){ 129 | if(FormatUtil.isScientificNotation(value.toString())){ 130 | return new BigDecimal(value.toString()).toPlainString(); 131 | } 132 | return value; 133 | } 134 | 135 | /** 136 | * 处理NaN数据 137 | * 138 | * @param value 139 | * @return 140 | */ 141 | public static Object fetchConvertNaN(Object value){ 142 | if(isNaN(value)){ 143 | return 0; 144 | } 145 | return value; 146 | } 147 | 148 | /** 149 | * 判断是否是NaN 150 | * 151 | * @param value 152 | * @return 153 | */ 154 | public static boolean isNaN(Object value){ 155 | String strvalue = value.toString(); 156 | return Float.isNaN(Float.valueOf(strvalue)) 157 | || Double.isNaN(Double.valueOf(strvalue)); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/response/ServiceResponse.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.response; 2 | 3 | 4 | 5 | import com.horrific.common.enums.BaseResponseEnum; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * 返回json统一格式 11 | * @author horrific 12 | * @version 2017-12-23 13 | * @param 14 | */ 15 | public class ServiceResponse implements Serializable { 16 | 17 | private static final long serialVersionUID = 2488663702267110932L; 18 | private int code; 19 | private String msg; 20 | private String detail; 21 | private T data; 22 | 23 | public static ServiceResponse successResponse() { 24 | return new ServiceResponse(BaseResponseEnum.SUCCESS); 25 | } 26 | 27 | public static ServiceResponse failureResponse() { 28 | return new ServiceResponse(BaseResponseEnum.FAILURE); 29 | } 30 | 31 | public ServiceResponse() { 32 | this.code = BaseResponseEnum.SUCCESS.getCode(); 33 | this.msg = BaseResponseEnum.SUCCESS.getMsg(); 34 | } 35 | 36 | public ServiceResponse(T data) { 37 | this.code = BaseResponseEnum.SUCCESS.getCode(); 38 | this.msg = BaseResponseEnum.SUCCESS.getMsg(); 39 | this.data = data; 40 | } 41 | 42 | public ServiceResponse(T data, String msg) { 43 | this.data = data; 44 | this.msg = msg; 45 | } 46 | 47 | public ServiceResponse(T data, int code, String msg) { 48 | this.data = data; 49 | this.code = code; 50 | this.msg = msg; 51 | } 52 | 53 | public ServiceResponse(int code, String msg) { 54 | this.code = code; 55 | this.msg = msg; 56 | } 57 | 58 | public ServiceResponse(int code, String msg, String detail) { 59 | this.code = code; 60 | this.msg = msg; 61 | this.detail = detail; 62 | } 63 | 64 | public ServiceResponse(ResponseCode ResponseCode, String detail) { 65 | this.code = ResponseCode.getCode(); 66 | this.msg = ResponseCode.getMsg(); 67 | this.detail = detail; 68 | } 69 | 70 | public ServiceResponse(ResponseCode ResponseCode) { 71 | this.code = ResponseCode.getCode(); 72 | this.msg = ResponseCode.getMsg(); 73 | } 74 | 75 | public static ServiceResponse illegalArg(T data) { 76 | return new ServiceResponse(data, BaseResponseEnum.FAILURE.getCode(), BaseResponseEnum.PARAM_ERROR.getMsg()); 77 | } 78 | 79 | public static ServiceResponse ok(T data) { 80 | return new ServiceResponse(data, BaseResponseEnum.SUCCESS.getCode(), BaseResponseEnum.SUCCESS.getMsg()); 81 | } 82 | 83 | public static ServiceResponse failure() { 84 | return failure(BaseResponseEnum.FAILURE.getMsg()); 85 | } 86 | 87 | public static ServiceResponse failure(String msg) { 88 | return failure(null, BaseResponseEnum.FAILURE.getCode(), msg); 89 | } 90 | 91 | public static ServiceResponse failureBusiness(String msg) { 92 | return failure(null, BaseResponseEnum.FAILURE_BUSSINES.getCode(), msg); 93 | } 94 | 95 | public static ServiceResponse failure(int code, String msg) { 96 | return failure(null, code, msg); 97 | } 98 | 99 | public static ServiceResponse failure(T data, int code, String msg) { 100 | return new ServiceResponse<>(null, code, msg); 101 | } 102 | 103 | 104 | public int getCode() { 105 | return this.code; 106 | } 107 | 108 | public void setCode(int code) { 109 | this.code = code; 110 | } 111 | 112 | public String getMsg() { 113 | return this.msg; 114 | } 115 | 116 | public void setMsg(String msg) { 117 | this.msg = msg; 118 | } 119 | 120 | public void setDetail(String detail) { 121 | this.detail = detail; 122 | } 123 | 124 | public String getDetail() { 125 | return this.detail; 126 | } 127 | 128 | public T addDetail(String detail) { 129 | this.setDetail(detail); 130 | return (T) this; 131 | } 132 | 133 | public T getData() { 134 | return this.data; 135 | } 136 | 137 | public void setData(T data) { 138 | this.data = data; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /vagary-core/src/main/resources/springconfig/spring-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | Spring Configuration 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /vagary-core/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | vagary 5 | com.horrific 6 | 1.3-SNAPSHOT 7 | 8 | 4.0.0 9 | 10 | vagary-core 11 | war 12 | 13 | vagary-core 14 | http://maven.apache.org 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | junit 23 | junit 24 | 25 | 26 | com.horrific 27 | vagary-sql 28 | 29 | 30 | commons-logging 31 | commons-logging 32 | 33 | 34 | 35 | 36 | com.horrific 37 | vagary-base 38 | 39 | 40 | 41 | javax.servlet 42 | javax.servlet-api 43 | 44 | 45 | com.alibaba 46 | fastjson 47 | 48 | 49 | 50 | mysql 51 | mysql-connector-java 52 | 53 | 54 | 55 | org.springframework 56 | spring-core 57 | 58 | 59 | commons-logging 60 | commons-logging 61 | 62 | 63 | 64 | 65 | org.springframework 66 | spring-beans 67 | 68 | 69 | org.springframework 70 | spring-context 71 | 72 | 73 | org.springframework 74 | spring-context-support 75 | 76 | 77 | org.springframework 78 | spring-web 79 | 80 | 81 | org.springframework 82 | spring-webmvc 83 | 84 | 85 | org.springframework 86 | spring-jdbc 87 | 88 | 89 | org.springframework 90 | spring-test 91 | 92 | 93 | org.springframework 94 | spring-context-support 95 | 96 | 97 | org.springframework 98 | spring-jdbc 99 | 100 | 101 | org.springframework 102 | spring-test 103 | 104 | 105 | org.springframework 106 | spring-aspects 107 | 108 | 109 | 110 | com.google.guava 111 | guava 112 | 113 | 114 | 115 | 116 | com.fasterxml.jackson.core 117 | jackson-core 118 | 119 | 120 | com.fasterxml.jackson.core 121 | jackson-databind 122 | 123 | 124 | com.fasterxml.jackson.core 125 | jackson-annotations 126 | 127 | 128 | 129 | org.nlpcn 130 | elasticsearch-sql 131 | 132 | 133 | 134 | org.elasticsearch 135 | elasticsearch 136 | 137 | 138 | org.elasticsearch.client 139 | transport 140 | 141 | 142 | org.apache.logging.log4j 143 | log4j-1.2-api 144 | 145 | 146 | org.slf4j 147 | slf4j-log4j12 148 | 149 | 150 | org.slf4j 151 | slf4j-api 152 | 153 | 154 | ch.qos.logback 155 | logback-classic 156 | 157 | 158 | ch.qos.logback 159 | logback-access 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/BeanUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | import com.google.common.collect.Maps; 4 | import org.apache.commons.beanutils.BeanUtils; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.lang.reflect.Field; 9 | import java.lang.reflect.Method; 10 | import java.math.BigDecimal; 11 | import java.util.List; 12 | import java.util.Map; 13 | import java.util.concurrent.ConcurrentHashMap; 14 | 15 | import static jdk.nashorn.api.scripting.ScriptUtils.convert; 16 | 17 | 18 | /** 19 | * 操作实体工具类 20 | * Created by shenhaonan on 2017/4/24. 21 | */ 22 | public class BeanUtil { 23 | 24 | private static final Logger logger = LoggerFactory.getLogger(BeanUtil.class); 25 | 26 | /** 27 | * 类和该类所有字段的映射缓存map 28 | */ 29 | private static final Map> fieldMapCache = new ConcurrentHashMap<>(); 30 | 31 | /** 32 | * getClass方法 33 | */ 34 | public static final String GETCLASS_METHOD = "getClass"; 35 | 36 | /** 37 | * get方法的前缀 38 | */ 39 | public static final String PREFIX_GET_METHOD = "get"; 40 | 41 | /** 42 | * 从数据对象中获取指定fieldName对应的属性字段 43 | * 44 | * @param data 数据对象 45 | * @param fieldName 属性名 46 | * @param 47 | * @return 48 | */ 49 | public static Field getField(T data, String fieldName) { 50 | 51 | for (Field field : getFields(data)) { 52 | if (field.getName().equals(fieldName)) { 53 | return field; 54 | } 55 | } 56 | return null; 57 | } 58 | 59 | /** 60 | * 获取数据对象中所有属性字段 61 | * 62 | * @param data 数据对象 63 | * @param 64 | * @return 65 | */ 66 | public static List getFields(T data) { 67 | 68 | Class clazz = data.getClass(); 69 | 70 | List fields = fieldMapCache.get(clazz.getCanonicalName()); 71 | if (fields == null) { 72 | fields = ReflectUtils.getAllFieldsAsList(clazz); 73 | fieldMapCache.put(clazz.getCanonicalName(), fields); 74 | } 75 | 76 | return fields; 77 | 78 | } 79 | 80 | 81 | /** 82 | * 通过反射从数据中获取指定属性的值 83 | * 84 | * @param fieldName 85 | * @param data 86 | * @param 87 | * @return 88 | */ 89 | public static String getProperty(String fieldName, T data) { 90 | 91 | try { 92 | return BeanUtils.getProperty(data, fieldName); 93 | 94 | } catch (Exception e) { 95 | try { 96 | Field field = getField(data, fieldName); 97 | field.setAccessible(true); 98 | return toString(field.get(data)); 99 | } catch (Exception e2) { 100 | logger.error("使用反射获取变量-[{}]的值,报错了!{}", fieldName, e2); 101 | } 102 | } 103 | 104 | return ""; 105 | 106 | } 107 | 108 | /** 109 | * 把一个对象的数据转换为Map结构 110 | * 111 | * @param data 112 | * @param 113 | * @return 114 | * @throws IllegalAccessException 115 | */ 116 | public static Map convertObjectToMap(T data) { 117 | return convertObjectToMap(data, true); 118 | } 119 | 120 | public static Map convertObjectToMap(T data, boolean isConvert) { 121 | 122 | Map map = Maps.newHashMap(); 123 | 124 | if (data == null) { 125 | return map; 126 | } 127 | 128 | try { 129 | for (Field field : getFields(data)) { 130 | field.setAccessible(true); 131 | //把等于空对象和Map的数据过滤掉 132 | Object fieldValue = field.get(data); 133 | if (fieldValue != null 134 | && !Map.class.isInstance(fieldValue)) { 135 | if (isConvert) { 136 | map.put(field.getName(), convert(fieldValue, BigDecimal.class)); 137 | } else { 138 | map.put(field.getName(), fieldValue); 139 | } 140 | } 141 | } 142 | } catch (Exception e) { 143 | logger.error("java 简单对象转换为map结构异常!", e); 144 | } 145 | 146 | return map; 147 | 148 | } 149 | 150 | 151 | /** 152 | * clone一个对象 153 | * 154 | * @param data 155 | * @param 156 | * @return 157 | */ 158 | public static T cloneBean(T data) { 159 | 160 | try { 161 | Object clone = BeanUtils.cloneBean(data); 162 | return (T) clone; 163 | } catch (Exception e) { 164 | 165 | } 166 | 167 | return data; 168 | 169 | } 170 | 171 | public static String toString(Object data) { 172 | return data == null ? "" : data.toString(); 173 | } 174 | 175 | /** 176 | * 通过反射创建实例 177 | * 178 | * @param clazz 179 | * @param 180 | * @return 181 | */ 182 | public static T newInstance(Class clazz) { 183 | try { 184 | return clazz.newInstance(); 185 | } catch (Exception e) { 186 | logger.error("", e); 187 | } 188 | return null; 189 | } 190 | 191 | 192 | /** 193 | * 反射调用函数 194 | * 195 | * @param method 196 | * @param target 197 | * @param args 198 | * @return 199 | */ 200 | public static Object invokeMethod(Method method, Object target, Object... args) { 201 | 202 | try { 203 | method.setAccessible(true); 204 | return method.invoke(target, args); 205 | } catch (Exception e) { 206 | logger.error("method invoke error:{}", e.getMessage()); 207 | } 208 | 209 | return null; 210 | 211 | } 212 | 213 | /** 214 | * 获取异常信息 215 | * 216 | * @param e 217 | * @return 218 | */ 219 | public static String getErrMsg(Exception e) { 220 | StringBuilder sb = new StringBuilder("error message:").append(e.toString()); 221 | Throwable cause = e.getCause(); 222 | if (cause != null) { 223 | sb.append(", cause:").append(cause.toString()); 224 | } 225 | return sb.toString(); 226 | } 227 | 228 | } 229 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/FormatUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | 4 | import com.horrific.common.enums.DataTypeEnum; 5 | 6 | import java.math.BigDecimal; 7 | import java.math.RoundingMode; 8 | import java.text.DecimalFormat; 9 | import java.text.SimpleDateFormat; 10 | import java.util.Date; 11 | import java.util.Locale; 12 | 13 | import static com.horrific.common.utils.NumberUtil.*; 14 | 15 | 16 | /** 17 | * 格式化工具类 18 | * author:huyong 19 | * date:2017/4/26 20 | * time:12:23 21 | */ 22 | public class FormatUtil { 23 | 24 | /** 25 | * 科学计数法的表示符号 26 | */ 27 | private final static String SCIENTIFIC_NOTATION_SYMBOL = "E"; 28 | 29 | /** 30 | * 对数值类型的数据进行格式化 31 | * 32 | * @param data 待格式化的数据 33 | * @param pattern 格式化模型 34 | * @param locale 本地化 35 | * @return 36 | */ 37 | public static String formatNumber(Object data, String pattern, Locale locale) { 38 | 39 | boolean isNum = NumberUtil.isNumberOfValue(data) || NumberUtil.isStringNumber(data); 40 | 41 | if (!isNum) { 42 | return data == null ? "" : data.toString(); 43 | } 44 | 45 | if (data instanceof String) { 46 | data = new BigDecimal((String) data); 47 | } 48 | 49 | if (isScientificNotation(pattern)) { 50 | return formatNumberScientificNotation(data, pattern, locale); 51 | 52 | } else { 53 | return formatNumberCommon(data, pattern, locale); 54 | } 55 | 56 | } 57 | 58 | /** 59 | * 日期格式化 60 | * 61 | * @param data 带格式化的日期 62 | * @param pattern 日期模板 63 | * @param locale 本地化 64 | * @return 65 | */ 66 | public static String formatDate(Object data, String pattern, Locale locale) { 67 | 68 | if (String.class.isInstance(data) 69 | && isNumber(data)) { 70 | data = Long.parseLong((String) data); 71 | } 72 | 73 | //只有日期类型或数字类型才允许格式化 74 | boolean allowType = (data instanceof Date) || (data instanceof Number); 75 | 76 | if (allowType == false) { 77 | return (String) data; 78 | } 79 | 80 | SimpleDateFormat sdf = new SimpleDateFormat(pattern, locale); 81 | return sdf.format(data); 82 | 83 | } 84 | 85 | 86 | /** 87 | * 对数据使用pattern进行格式化 88 | * 89 | * @param dataType 待格式化数据的数据类型 90 | * @param data 待格式化的数据 91 | * @param pattern 格式化之后的模式:如:#,###.00% 、yyyy-MM-dd HH:mm:ss.SSS 92 | * @return 93 | */ 94 | public static String formatByDataType(DataTypeEnum dataType, Object data, String pattern) { 95 | return formatByDataType(dataType, data, pattern, Locale.getDefault()); 96 | } 97 | 98 | /** 99 | * 对数据使用pattern进行格式化 100 | * 101 | * @param dataType 待格式化数据的数据类型 102 | * @param data 待格式化的数据 103 | * @param pattern 格式化之后的模式:如:#,###.00% 、yyyy-MM-dd HH:mm:ss.SSS 104 | * @param locale 本地化 105 | * @return 106 | */ 107 | public static String formatByDataType(DataTypeEnum dataType, Object data, String pattern, Locale locale) { 108 | 109 | if (pattern != null) { 110 | 111 | switch (dataType) { 112 | 113 | case NUMBER://对数字使用模板进行格式化 114 | return formatNumber(data, pattern, locale); 115 | 116 | case DATE://对日期使用模板进行格式化 117 | return formatDate(data, pattern, locale); 118 | 119 | } 120 | 121 | } 122 | 123 | return data == null ? "" : data.toString(); 124 | 125 | } 126 | 127 | 128 | /** 129 | * 普通数字格式化(非科学计数法) 130 | * 131 | * @param data 待格式化的数据 132 | * @param pattern 格式化模型 133 | * @param locale 本地化 134 | * @return 135 | */ 136 | private static String formatNumberCommon(Object data, String pattern, Locale locale) { 137 | 138 | DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(locale); 139 | 140 | format.setRoundingMode(RoundingMode.HALF_UP); 141 | format.applyPattern(pattern); 142 | 143 | return format.format(data); 144 | 145 | } 146 | 147 | /** 148 | * 使用科学计数法的模板进行格式化(对JDK的科学计数法进行了扩展) 149 | * 150 | * @param data 待格式化的数据 151 | * @param pattern 格式化模型 152 | * @param locale 本地化 153 | * @return 154 | */ 155 | private static String formatNumberScientificNotation(Object data, String pattern, Locale locale) { 156 | 157 | //按科学计数法的方式进行除法运算 158 | int scientificNotationNum = fetchScientificNotationNum(pattern); 159 | data = toBigDecimal(divide(data, Math.pow(10, scientificNotationNum),"")); 160 | 161 | DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance(locale); 162 | 163 | format.setRoundingMode(RoundingMode.HALF_UP); 164 | format.applyPattern(assemblePattern(pattern)); 165 | 166 | if (scientificNotationNum == 0) {//表示E0 167 | return format.format(data); 168 | 169 | } else { 170 | return new StringBuilder(format.format(data)).append(SCIENTIFIC_NOTATION_SYMBOL).append(scientificNotationNum).toString(); 171 | } 172 | 173 | } 174 | 175 | /** 176 | * 对科学计数法做处理,科学计数法,会使用‘E’来表示,如#0.00E0 177 | * 178 | * @param pattern 格式化模板 179 | * @return 180 | */ 181 | private static String assemblePattern(String pattern) { 182 | 183 | //E字符后面的数据:如0E3,这里的数字就是3 184 | int num = fetchScientificNotationNum(pattern); 185 | 186 | switch (num) { 187 | 188 | case 0://相当于E0,JDK 原生支持的科学计数法 189 | return pattern; 190 | 191 | default://比如#.00E3,其中E3,JDK不支持,直接返回#.00 192 | return pattern.substring(0, fetchScientificNotationIndex(pattern)); 193 | 194 | } 195 | 196 | } 197 | 198 | /** 199 | * 获取科学计数法E所在的位置 200 | * 201 | * @param pattern 格式化模板 202 | * @return 203 | */ 204 | private static int fetchScientificNotationIndex(String pattern) { 205 | return pattern.indexOf(SCIENTIFIC_NOTATION_SYMBOL); 206 | } 207 | 208 | /** 209 | * 判断数字模型是否含有科学计数法 210 | * 211 | * @param pattern 格式化模板 212 | * @return 213 | */ 214 | public static boolean isScientificNotation(String pattern) { 215 | return fetchScientificNotationIndex(pattern) > -1; 216 | } 217 | 218 | /** 219 | * 获取科学计数法后面的数字,如#0.00E4, 获取得到结果为:4 220 | * 221 | * @param pattern 格式化模板 222 | * @return 223 | */ 224 | private static int fetchScientificNotationNum(String pattern) { 225 | 226 | int index = fetchScientificNotationIndex(pattern); 227 | 228 | if (index == -1) { 229 | return 0; 230 | } 231 | 232 | return Integer.parseInt(pattern.substring(index + 1)); 233 | 234 | } 235 | 236 | } 237 | -------------------------------------------------------------------------------- /vagary-base/src/main/java/com/horrific/common/utils/DownloadExcelUtil.java: -------------------------------------------------------------------------------- 1 | package com.horrific.common.utils; 2 | 3 | import com.horrific.common.dto.table.HeadCell; 4 | import com.horrific.common.dto.table.TableViewVO; 5 | import com.horrific.common.enums.DatePatternEnum; 6 | import com.horrific.common.tools.downloadexcel.local.ColumnInfo; 7 | import com.horrific.common.tools.downloadexcel.local.ExcelTemplate; 8 | import lombok.extern.slf4j.Slf4j; 9 | import org.apache.poi.ss.usermodel.*; 10 | import org.apache.poi.ss.util.CellRangeAddress; 11 | import org.apache.poi.xssf.streaming.SXSSFCell; 12 | import org.apache.poi.xssf.streaming.SXSSFRow; 13 | import org.apache.poi.xssf.streaming.SXSSFSheet; 14 | import org.apache.poi.xssf.streaming.SXSSFWorkbook; 15 | 16 | import java.io.File; 17 | import java.io.FileOutputStream; 18 | import java.util.*; 19 | 20 | 21 | /** 22 | * @author wanghong12 23 | * @date 2018-3-28 24 | */ 25 | 26 | @Slf4j 27 | public class DownloadExcelUtil { 28 | 29 | public static final String EXCELSUFFIX_XLSX = ".xlsx"; 30 | 31 | /** 32 | * excel临时文件路径 33 | */ 34 | private static final String EXCELTMPPATH = "/tmp/"; 35 | 36 | /** 37 | * 生成Excel时,超过限制条数后,把内存数据写入到磁盘 38 | */ 39 | private static final int excelSize = 10000; 40 | 41 | /** 42 | * 下载 43 | * 44 | * @param data 待拼装的数据 45 | * @param template Excel模板 46 | * @return 临时存储的文件名 47 | */ 48 | public static String download(List data, ExcelTemplate template) throws Exception { 49 | 50 | if (data == null) { 51 | return null; 52 | } 53 | 54 | return downloadAccordingToTemplate("sheet", data, template); 55 | 56 | } 57 | 58 | /** 59 | * 根据表格VO进行Excel下载 60 | * 61 | * @param title 标题名 62 | * @param tableVo 表格VO 63 | * @return Excel的名字 64 | */ 65 | public static SXSSFWorkbook download(String title, TableViewVO tableVo) throws Exception { 66 | 67 | SXSSFWorkbook workbook = POIComponentUtil.makeSXSSFWorkbook(excelSize); 68 | 69 | if (tableVo == null) { 70 | return workbook; 71 | } 72 | 73 | SXSSFSheet sheet = POIComponentUtil.makeSXSSFSheet(workbook, "sheet1"); 74 | 75 | //当前行数 76 | Integer currRow = 0; 77 | 78 | //根据表头的标记(是否下载[download]),来过滤出需要下载的字段 79 | List downloadFieldList = getExcludeIndex(tableVo.getTitleName()); 80 | 81 | //构建Excel的标题 82 | currRow = doBuildExcelTitle(sheet, currRow, title, tableVo.getTitleName(), downloadFieldList, getCellStyleTitle(workbook)); 83 | 84 | //构建Excel的表头 85 | currRow = doBuildExcelHead(sheet, currRow, tableVo.getTitleName(), downloadFieldList, getCellStyleHead(workbook)); 86 | 87 | //构建Excel的表体 88 | doBuildExcelBody(sheet, currRow, tableVo.getTitleList(), downloadFieldList, getCellStyleBody(workbook)); 89 | 90 | return workbook; 91 | 92 | } 93 | 94 | /** 95 | * 获取需要下载的字段的名字 96 | * 97 | * @param head 表头 98 | * @return 99 | */ 100 | private static List getExcludeIndex(List head) { 101 | 102 | List list = new ArrayList<>(); 103 | 104 | for (int i = 0; i < head.size(); i++) { 105 | 106 | HeadCell headCell = head.get(i); 107 | //if (Boolean.valueOf(headCell.getDownload())) { 108 | list.add(headCell.getKey()); 109 | //} 110 | } 111 | 112 | return list; 113 | 114 | } 115 | 116 | /** 117 | * 构建Excel的标题 118 | * 119 | * @param sheet excel某个sheet 120 | * @param currRow 当前行数 121 | * @param title 标题 122 | * @param head 表头 123 | * @param downloadFieldList 需要下载字段名字集合 124 | * @param titleCellStyle 标题样式 125 | */ 126 | private static int doBuildExcelTitle(SXSSFSheet sheet, int currRow, String title, List head, List downloadFieldList, CellStyle titleCellStyle) { 127 | 128 | log.info("生成标题-{},标题开始行数:{},列数:{}", title, currRow, downloadFieldList.size()); 129 | 130 | SXSSFRow row = POIComponentUtil.makeSXSSFRow(sheet, currRow++); 131 | row.setHeightInPoints(30); 132 | 133 | SXSSFCell cell = POIComponentUtil.makeSXSSFCell(row, 0); 134 | cell.setCellValue(title.replace(".xlsx", "")); 135 | cell.setCellStyle(titleCellStyle); 136 | sheet.addMergedRegion(new CellRangeAddress(row.getRowNum(), row.getRowNum(), row.getRowNum(), downloadFieldList.size() - 1)); 137 | 138 | return currRow; 139 | 140 | } 141 | 142 | /** 143 | * 构建Excel的表头 144 | * 145 | * @param sheet excel某个sheet 146 | * @param currRow 当前行数 147 | * @param head 表头 148 | * @param downloadFieldList 需要下载字段名字集合 149 | * @param headCellStyle 表头样式 150 | */ 151 | private static int doBuildExcelHead(SXSSFSheet sheet, int currRow, List head, List downloadFieldList, CellStyle headCellStyle) { 152 | 153 | log.info("生成表头,表头列数:{},表头开始行数:{}", downloadFieldList.size(), currRow); 154 | 155 | SXSSFRow row = POIComponentUtil.makeSXSSFRow(sheet, currRow++); 156 | 157 | Map map = CollectionUtils.listToMap(head, "", "key"); 158 | 159 | //写入数据的单元格的位置 160 | int cellIndex = 0; 161 | for (int i = 0; i < downloadFieldList.size(); i++) { 162 | HeadCell headCell = map.get(downloadFieldList.get(i)); 163 | SXSSFCell cell = POIComponentUtil.makeSXSSFCell(row, cellIndex++); 164 | cell.setCellStyle(headCellStyle); 165 | cell.setCellValue(headCell.getTitle()); 166 | int colWidth = sheet.getColumnWidth(i) * 2; 167 | sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); 168 | } 169 | 170 | return currRow; 171 | 172 | } 173 | 174 | /** 175 | * 构建Excel的表体 176 | * 177 | * @param sheet excel某个sheet 178 | * @param currRow 当前行数 179 | * @param datas 数据集合,数据为自定义类型 180 | * @param downloadFieldList 需要下载字段名字集合 181 | * @param bodyCellStyle 数据单元格样式 182 | */ 183 | private static int doBuildExcelBody(SXSSFSheet sheet, int currRow, List datas, List downloadFieldList, CellStyle bodyCellStyle) { 184 | 185 | log.info("生成表体,表体数量-{},表体开始行数:{},列数:{}", datas.size(), currRow, downloadFieldList.size()); 186 | 187 | long start = System.currentTimeMillis(); 188 | for (int i = 0; i < datas.size(); i++) { 189 | SXSSFRow row = POIComponentUtil.makeSXSSFRow(sheet, currRow++); 190 | makeRow(row, datas.get(i), downloadFieldList, bodyCellStyle); 191 | } 192 | 193 | log.info("生成表体,耗时:{}", (System.currentTimeMillis() - start)); 194 | 195 | return currRow; 196 | 197 | } 198 | 199 | /** 200 | * 创建一行的数据 201 | * 202 | * @param row Excel的行对象 203 | * @param data 一条数据 204 | * @param downloadFieldList 需要下载字段名字集合 205 | */ 206 | private static void makeRow(SXSSFRow row, Object data, List downloadFieldList, CellStyle cellStyle) { 207 | 208 | Map map = (Map) data; 209 | 210 | //写入数据的单元格的位置 211 | int cellIndex = 0; 212 | for (int i = 0; i < downloadFieldList.size(); i++) { 213 | Object cellValue = map.get(downloadFieldList.get(i)); 214 | SXSSFCell cell = POIComponentUtil.makeSXSSFCell(row, cellIndex++); 215 | cell.setCellStyle(cellStyle); 216 | cell.setCellValue(convertAttrMember(cellValue)); 217 | } 218 | } 219 | 220 | 221 | /** 222 | * 把值转换为字符串格式 223 | * 224 | * @param data 待转换的数据 225 | * @return 226 | */ 227 | private static String convertValue(Object data) { 228 | 229 | if (data == null) { 230 | return ""; 231 | } 232 | 233 | if (data instanceof Date) { 234 | return DateFormatUtil.format((Date) data, DatePatternEnum.DATE_FORMAT); 235 | } 236 | 237 | return data.toString(); 238 | 239 | } 240 | 241 | /** 242 | * 根据Excel模板进行下载(适合下载数据不大的情况,因为生成的Excel,是存放在内存中的) 243 | * 244 | * @param sheetName excel sheet的名字 245 | * @param data 待拼装的数据 246 | * @param template Excel模板 247 | * @return 临时存储的文件名 248 | */ 249 | private static String downloadAccordingToTemplate(String sheetName, List data, ExcelTemplate template) throws Exception { 250 | 251 | SXSSFWorkbook book = (SXSSFWorkbook) WorkbookFactory.create(new File(template.getTemplateName())); 252 | 253 | Sheet sheet = getSheet(book, sheetName); 254 | 255 | for (int i = 0; i < data.size(); i++) { 256 | makeRow(sheet, data.get(i), template, i); 257 | } 258 | 259 | //把Excel写入临时文件中 260 | String tmpPath = new StringBuilder(EXCELTMPPATH).append(UUID.randomUUID()).append(EXCELSUFFIX_XLSX).toString(); 261 | log.debug("生成的临时文件为:{}", tmpPath); 262 | try (FileOutputStream fos = new FileOutputStream(new File(tmpPath))) { 263 | book.write(fos); 264 | return tmpPath; 265 | } 266 | 267 | } 268 | 269 | /** 270 | * 获取Excel的sheet 271 | * 272 | * @param book Excel对象 273 | * @param sheetName sheet名字 274 | * @return 275 | */ 276 | private static Sheet getSheet(Workbook book, String sheetName) { 277 | 278 | Sheet sheet = book.getSheet(sheetName); 279 | 280 | if (sheet == null) { 281 | sheet = book.getSheetAt(0); 282 | book.setSheetName(0, sheetName); 283 | } 284 | 285 | return sheet; 286 | 287 | } 288 | 289 | /** 290 | * 创建一行 291 | * 292 | * @param sheet Excel的sheet 293 | * @param data 待写入Excel一行的数据 294 | * @param template 数据行第一行每个单元格的坐标信息 295 | * @param currentRowIndex 处理到第几行的索引 296 | * @param 297 | */ 298 | private static void makeRow(Sheet sheet, T data, ExcelTemplate template, int currentRowIndex) { 299 | 300 | Map dataMap; 301 | 302 | if (data instanceof Map) { 303 | dataMap = (Map) data; 304 | } else { 305 | dataMap = BeanUtil.convertObjectToMap(data); 306 | 307 | } 308 | 309 | Map columnInfoMap = template.getBodyInfo(); 310 | 311 | Set> entries = columnInfoMap.entrySet(); 312 | 313 | Row row = getRow(sheet, template, currentRowIndex); 314 | 315 | for (Map.Entry entry : entries) { 316 | makeCell(row, dataMap, entry.getValue(), sheet, template); 317 | } 318 | 319 | } 320 | 321 | 322 | /** 323 | * 获取sheet中的一行,如果模板Excel文件有那一行,直接返回该行,否者创建新行 324 | * 325 | * @param sheet Excel中的一个sheet 326 | * @param template Excel模板 327 | * @param currentRowIndex 当前处理的第几条数据 328 | * @return 329 | */ 330 | private static Row getRow(Sheet sheet, ExcelTemplate template, int currentRowIndex) { 331 | 332 | //当前待写数据行的索引 333 | int rowIndex = template.getBodyStartIndex() + currentRowIndex; 334 | 335 | Row row = sheet.getRow(rowIndex); 336 | 337 | if (row == null) { 338 | row = sheet.createRow(rowIndex); 339 | } 340 | 341 | return row; 342 | 343 | } 344 | 345 | /** 346 | * 创建一个单元格 347 | * 348 | * @param row 一行 349 | * @param dataMap 待填充一行的数据 350 | * @param columnInfo 填充一行 351 | * @param sheet excel的sheet 352 | * @param template excel模板 353 | * @param sheet 354 | */ 355 | private static void makeCell(Row row, Map dataMap, ColumnInfo columnInfo, Sheet sheet, ExcelTemplate template) { 356 | 357 | Cell cell = getCell(row, columnInfo); 358 | cell.setCellValue(fetchValue(dataMap, columnInfo)); 359 | cell.setCellStyle(getCellStypeFirstDataRowReferColumn(sheet, template, columnInfo)); 360 | sheet.autoSizeColumn(columnInfo.getColumnIndex()); 361 | 362 | } 363 | 364 | /** 365 | * 获取一个单元格,如果模板Excel文件指定行单元格存在,返回该单元格,否者新创建一个单元格 366 | * 367 | * @param row Excel中第一行 368 | * @param columnInfo 单元格信息 369 | * @return 370 | */ 371 | private static Cell getCell(Row row, ColumnInfo columnInfo) { 372 | 373 | Cell cell = row.getCell(columnInfo.getColumnIndex()); 374 | 375 | if (cell == null) { 376 | cell = row.createCell(columnInfo.getColumnIndex()); 377 | } 378 | 379 | return cell; 380 | 381 | } 382 | 383 | /** 384 | * 转换数据对象的成员属性的值 385 | * 386 | * @param data 387 | * @return 388 | */ 389 | private static String convertAttrMember(Object data) { 390 | 391 | if (data == null) { 392 | return ""; 393 | } 394 | 395 | return convertValue(data); 396 | 397 | } 398 | 399 | /** 400 | * 获取指定名字的值 401 | * 402 | * @param dataMap Excel的一行数据 403 | * @param columnInfo 单元格信息描述 404 | * @return 405 | */ 406 | private static String fetchValue(Map dataMap, ColumnInfo columnInfo) { 407 | 408 | Object value = dataMap.get(columnInfo.getColumnName()); 409 | 410 | if (value == null) { 411 | return columnInfo.getColumnDefaultValue(); 412 | } 413 | 414 | if (columnInfo.getFormatType() == null) { 415 | return value.toString(); 416 | } 417 | 418 | return FormatUtil.formatByDataType(columnInfo.getFormatType(), value, columnInfo.getFormatPattern()); 419 | 420 | } 421 | 422 | /** 423 | * 获取单元格样式 424 | * 425 | * @param sheet Excel的sheet 426 | * @param template Excel模板 427 | * @param columnInfo 单元格描述信息 428 | * @return 429 | */ 430 | private static CellStyle getCellStypeFirstDataRowReferColumn(Sheet sheet, ExcelTemplate template, ColumnInfo columnInfo) { 431 | 432 | CellStyle cellStyle = sheet.getRow(template.getBodyStartIndex()).getCell(columnInfo.getColumnIndex()).getCellStyle(); 433 | 434 | if (cellStyle == null) { 435 | return makeDefaultCellStyle(); 436 | } 437 | 438 | return cellStyle; 439 | 440 | } 441 | 442 | /** 443 | * 创建默认的单元格样式 444 | * 445 | * @return 446 | */ 447 | private static CellStyle makeDefaultCellStyle() { 448 | 449 | //todo 450 | 451 | return null; 452 | 453 | } 454 | 455 | /** 456 | * 标题样式 457 | * 458 | * @param workbook Excel对象 459 | * @return 460 | */ 461 | private static CellStyle getCellStyleTitle(Workbook workbook) { 462 | 463 | CellStyle style = workbook.createCellStyle(); 464 | style.setAlignment(HorizontalAlignment.LEFT); 465 | style.setVerticalAlignment(VerticalAlignment.CENTER); 466 | 467 | Font titleFont = workbook.createFont(); 468 | titleFont.setFontName("宋体"); 469 | titleFont.setFontHeightInPoints((short) 16); 470 | titleFont.setBold(true); 471 | style.setFont(titleFont); 472 | 473 | return style; 474 | 475 | } 476 | 477 | /** 478 | * 表头样式 479 | * 480 | * @param workbook Excel对象 481 | * @return 482 | */ 483 | private static CellStyle getCellStyleHead(Workbook workbook) { 484 | 485 | CellStyle style = workbook.createCellStyle(); 486 | 487 | style.setVerticalAlignment(VerticalAlignment.CENTER); 488 | style.setBorderRight(BorderStyle.THIN); 489 | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 490 | style.setBorderLeft(BorderStyle.THIN); 491 | style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 492 | style.setBorderTop(BorderStyle.THIN); 493 | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 494 | style.setBorderBottom(BorderStyle.THIN); 495 | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 496 | style.setAlignment(HorizontalAlignment.CENTER); 497 | style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); 498 | style.setFillPattern(FillPatternType.SOLID_FOREGROUND); 499 | 500 | Font headerFont = workbook.createFont(); 501 | headerFont.setFontName("宋体"); 502 | headerFont.setFontHeightInPoints((short) 10); 503 | headerFont.setColor(IndexedColors.WHITE.getIndex()); 504 | style.setFont(headerFont); 505 | 506 | return style; 507 | 508 | } 509 | 510 | 511 | /** 512 | * 表体样式 513 | * 514 | * @param workbook Excel对象 515 | * @return 516 | */ 517 | private static CellStyle getCellStyleBody(Workbook workbook) { 518 | 519 | CellStyle style = workbook.createCellStyle(); 520 | 521 | style.setVerticalAlignment(VerticalAlignment.CENTER); 522 | style.setBorderRight(BorderStyle.THIN); 523 | style.setRightBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 524 | style.setBorderLeft(BorderStyle.THIN); 525 | style.setLeftBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 526 | style.setBorderTop(BorderStyle.THIN); 527 | style.setTopBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 528 | style.setBorderBottom(BorderStyle.THIN); 529 | style.setBottomBorderColor(IndexedColors.GREY_50_PERCENT.getIndex()); 530 | 531 | Font dataFont = workbook.createFont(); 532 | dataFont.setFontName("宋体"); 533 | dataFont.setFontHeightInPoints((short) 10); 534 | style.setFont(dataFont); 535 | 536 | return style; 537 | 538 | } 539 | 540 | } 541 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.horrific 6 | vagary 7 | 1.3-SNAPSHOT 8 | 9 | 10 | vagary-core 11 | vagary-sql 12 | vagary-base 13 | 14 | pom 15 | 16 | vagary 17 | http://maven.apache.org 18 | 19 | 20 | UTF-8 21 | 1.8 22 | 23 | 4.3.13.RELEASE 24 | 3.1.0.RELEASE 25 | 1.4 26 | 5.1.38 27 | 4.5.2 28 | 4.4.5 29 | 1.1.9 30 | 31 | 3.2.2 32 | 1.1.3 33 | 1.3.2 34 | 1.9.2 35 | 3.4 36 | 1.3.1 37 | 19.0 38 | 1.2.28 39 | 20160212 40 | 2.4 41 | 1.8.1 42 | 2.7.9.1 43 | 2.7.4 44 | 2.7.4 45 | 2.8.1 46 | 1.0.6 47 | 1.7.12 48 | 1.1.7 49 | 1.1.7 50 | 1.7.9 51 | 1.7.6 52 | 2.6.2 53 | 9.2.22.v20170606 54 | 3.0 55 | 4.12 56 | 1.16.6 57 | 3.1 58 | 2.9.0 59 | 60 | 3.17 61 | 4.1 62 | 4.0.5 63 | 4.0.7 64 | 65 | 66 | 5.1.30 67 | 68 | 1.3-SNAPSHOT 69 | 3.1.0 70 | 5.4.3.0-bdp-SNAPSHOT 71 | 5.4.3 72 | 73 | 74 | 75 | 76 | 77 | 78 | com.horrific 79 | vagary-sql 80 | ${vagary-sql.version} 81 | 82 | 83 | 84 | com.horrific 85 | vagary-base 86 | ${vagary-sql.version} 87 | 88 | 89 | 90 | javax.servlet 91 | javax.servlet-api 92 | ${servlet-api.version} 93 | 94 | 95 | 96 | org.nlpcn 97 | elasticsearch-sql 98 | ${elasticsearch-sql.version} 99 | 100 | 101 | 102 | org.elasticsearch 103 | elasticsearch 104 | ${elasticsearch.version} 105 | 106 | 107 | org.elasticsearch.client 108 | transport 109 | ${elasticsearch.version} 110 | 111 | 112 | 113 | 114 | mysql 115 | mysql-connector-java 116 | ${mysql.driver.version} 117 | 118 | 119 | 120 | org.apache.ibatis 121 | ibatis-core 122 | ${ibatis-core-version} 123 | 124 | 125 | 126 | 127 | org.springframework 128 | spring-context 129 | ${org.springframework.version} 130 | 131 | 132 | 133 | commons-logging 134 | commons-logging 135 | 136 | 137 | 138 | 139 | org.springframework 140 | spring-context-support 141 | ${org.springframework.version} 142 | 143 | 144 | org.springframework 145 | spring-web 146 | ${org.springframework.version} 147 | 148 | 149 | org.springframework 150 | spring-webmvc 151 | ${org.springframework.version} 152 | 153 | 154 | org.springframework 155 | spring-jdbc 156 | ${org.springframework.version} 157 | 158 | 159 | org.springframework 160 | spring-test 161 | ${org.springframework.version} 162 | 163 | 164 | org.springframework 165 | spring-aspects 166 | ${org.springframework.version} 167 | 168 | 169 | org.springframework.security 170 | spring-security-crypto 171 | ${spring-security-crypto.version} 172 | 173 | 174 | org.springframework 175 | spring-core 176 | 177 | 178 | commons-logging 179 | commons-logging 180 | 181 | 182 | ${org.springframework.version} 183 | 184 | 185 | org.springframework 186 | spring-beans 187 | ${org.springframework.version} 188 | 189 | 190 | 195 | 196 | 197 | 198 | net.sf.ehcache 199 | ehcache 200 | ${ehcache.version} 201 | 202 | 203 | 204 | net.sf.ehcache 205 | ehcache-core 206 | ${ehcache.core.version} 207 | 208 | 209 | 210 | 211 | org.eclipse.jetty 212 | jetty-webapp 213 | ${jetty.version} 214 | 215 | 216 | org.eclipse.jetty 217 | jetty-server 218 | ${jetty.version} 219 | 220 | 221 | org.eclipse.jetty 222 | jetty-jsp 223 | ${jetty.version} 224 | 225 | 226 | org.eclipse.jetty 227 | jetty-servlet 228 | ${jetty.version} 229 | 230 | 231 | 232 | com.google.guava 233 | guava 234 | ${guava.version} 235 | 236 | 237 | commons-collections 238 | commons-collections 239 | ${commons-collections.version} 240 | 241 | 242 | commons-logging 243 | commons-logging 244 | ${commons-logging.version} 245 | 246 | 247 | 248 | commons-beanutils 249 | commons-beanutils 250 | ${commons-beanutils.version} 251 | 252 | 253 | jd-omdm-client 254 | jd-omdm-client 255 | ${jd-omdm-client.version} 256 | 257 | 258 | org.apache.commons 259 | commons-lang3 260 | ${commons-lang3.version} 261 | 262 | 263 | commons-cli 264 | commons-cli 265 | ${commons-cli.version} 266 | 267 | 268 | 269 | org.json 270 | json 271 | ${org.json.version} 272 | 273 | 274 | 275 | 276 | com.fasterxml.jackson.core 277 | jackson-core 278 | ${jackson.version} 279 | 280 | 281 | com.fasterxml.jackson.core 282 | jackson-annotations 283 | ${jackson-annotations.version} 284 | 285 | 286 | net.sf.json-lib 287 | json-lib 288 | ${json-lib.version} 289 | 290 | 291 | 292 | org.codehaus.jackson 293 | jackson-mapper-asl 294 | ${jackson-mapper-asl.version} 295 | 296 | 297 | org.springframework 298 | spring 299 | 300 | 301 | log4j 302 | log4j 303 | 304 | 305 | 306 | 307 | com.fasterxml.jackson.core 308 | jackson-databind 309 | ${jackson-databind.version} 310 | 311 | 312 | com.fasterxml.jackson.dataformat 313 | jackson-dataformat-xml 314 | ${jackson-dataformat-xml.version} 315 | 316 | 317 | joda-time 318 | joda-time 319 | ${joda-time.version} 320 | 321 | 322 | org.slf4j 323 | slf4j-api 324 | ${slf4j-api.version} 325 | 326 | 327 | ch.qos.logback 328 | logback-classic 329 | ${logback-classic.version} 330 | 331 | 332 | ch.qos.logback 333 | logback-access 334 | ${logback-access.version} 335 | 336 | 337 | org.slf4j 338 | log4j-over-slf4j 339 | ${log4j-over-slf4j.version} 340 | 341 | 342 | org.slf4j 343 | slf4j-log4j12 344 | ${slf4j-log4j12.version} 345 | 346 | 347 | org.apache.logging.log4j 348 | log4j-1.2-api 349 | ${log4j.version} 350 | 351 | 352 | 353 | io.netty 354 | netty-all 355 | 4.1.11.Final 356 | 357 | 358 | 359 | junit 360 | junit 361 | ${junit.version} 362 | 363 | 364 | org.mockito 365 | mockito-all 366 | ${mockito-all.version} 367 | 368 | 369 | 370 | org.mybatis 371 | mybatis 372 | ${mybatis.version} 373 | 374 | 375 | org.mybatis 376 | mybatis-spring 377 | ${mybatis-spring.version} 378 | 379 | 380 | commons-dbcp 381 | commons-dbcp 382 | ${commons-dbcp.version} 383 | 384 | 385 | mysql 386 | mysql-connector-java 387 | ${mysql-connector-java.version} 388 | 389 | 390 | commons-fileupload 391 | commons-fileupload 392 | ${commons-fileupload.version} 393 | 394 | 395 | 396 | org.apache.httpcomponents 397 | httpcore 398 | ${httpcore.version} 399 | 400 | 401 | org.apache.httpcomponents 402 | httpclient 403 | ${httpclient.version} 404 | 405 | 406 | 407 | com.alibaba 408 | fastjson 409 | ${fastjson.version} 410 | 411 | 412 | net.sf.ezmorph 413 | ezmorph 414 | ${ezmorph.version} 415 | 416 | 417 | commons-lang 418 | commons-lang 419 | 420 | 421 | 422 | 423 | 424 | org.apache.kylin 425 | kylin-jdbc 426 | ${kylin-jdbc.version} 427 | 428 | 429 | 430 | presto-jdbc-jd 431 | presto-jdbc-jd 432 | ${presto-jdbc.jd.version} 433 | 434 | 435 | 436 | com.jd 437 | hive-jdbc-bdp 438 | ${hive-jdbc.version} 439 | 440 | 441 | 442 | org.xerial 443 | sqlite-jdbc 444 | ${sqlite-jdbc.version} 445 | 446 | 447 | 448 | org.projectlombok 449 | lombok 450 | ${lombok.version} 451 | 452 | 453 | 454 | org.nlpcn 455 | elasticsearch-sql 456 | ${elasticsearch-sql.version} 457 | 458 | 459 | 460 | org.elasticsearch.client 461 | transport 462 | ${elasticsearch.version} 463 | 464 | 465 | 466 | org.nlpcn 467 | elasticsearch-sql 468 | ${elasticsearch-sql.version} 469 | 470 | 471 | 472 | org.apache.poi 473 | poi-ooxml 474 | ${poi.ooxml.version} 475 | 476 | 477 | 478 | org.apache.poi 479 | poi 480 | ${poi.ooxml.version} 481 | 482 | 483 | 484 | org.apache.commons 485 | commons-collections4 486 | ${commons.collections4.version} 487 | 488 | 489 | 490 | com.googlecode.aviator 491 | aviator 492 | ${aviator.version} 493 | 494 | 495 | 496 | com.caucho 497 | hessian 498 | ${hession.version} 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | org.apache.maven.plugins 508 | maven-compiler-plugin 509 | ${maven-compiler-plugin.version} 510 | 511 | ${java.version} 512 | ${java.version} 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | --------------------------------------------------------------------------------