Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: date variable parse error #314

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bin/datart-demo.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@echo off

REM Datart
REM <p>
REM Copyright 2021
REM <p>
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM <p>
REM http://www.apache.org/licenses/LICENSE-2.0
REM <p>
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.


if "%1"=="start" goto START


:START

cd /d %~dp0

cd ..

java -server -Xms2G -Xmx2G -Dspring.profiles.active=demo -Dfile.encoding=UTF-8 -cp ".\lib\*" datart.DatartServerApplication
29 changes: 29 additions & 0 deletions bin/datart-demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Datart
# <p>
# Copyright 2021
# <p>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# http://www.apache.org/licenses/LICENSE-2.0
# <p>
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

BASE_DIR=$(cd "$(dirname "$0")/.."; pwd -P)

echo "working dir ${BASE_DIR}"

cd "${BASE_DIR}"

CLASS_PATH="${BASE_DIR}/lib/*"

START_CLASS="datart.DatartServerApplication"

java -server -Xms2G -Xmx2G -Dspring.profiles.active=demo -Dfile.encoding=UTF-8 -cp "${CLASS_PATH}" datart.DatartServerApplication
2 changes: 1 addition & 1 deletion bin/datart-server.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ cd /d %~dp0

cd ..

java -server -Xms2G -Xmx2G -Dfile.encoding=UTF-8 -cp ".\lib\*" datart.DatartServerApplication
java -server -Xms2G -Xmx2G -Dspring.profiles.active=config -Dfile.encoding=UTF-8 -cp ".\lib\*" datart.DatartServerApplication
2 changes: 1 addition & 1 deletion bin/datart-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ CLASS_PATH="${BASE_DIR}/lib/*"

START_CLASS="datart.DatartServerApplication"

java -server -Xms2G -Xmx2G -Dfile.encoding=UTF-8 -cp "${CLASS_PATH}" datart.DatartServerApplication
java -server -Xms2G -Xmx2G -Dspring.profiles.active=config -Dfile.encoding=UTF-8 -cp "${CLASS_PATH}" datart.DatartServerApplication
29 changes: 7 additions & 22 deletions bin/datart.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/*
Navicat Premium Data Transfer

Source Server Type : MySQL
Source Server Version : 50732
Source Schema : datart

Target Server Type : MySQL
Target Server Version : 50732
File Encoding : 65001

Date: 15/10/2021 10:29:53
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

Expand Down Expand Up @@ -265,13 +251,13 @@ CREATE TABLE `download` (
-- ----------------------------
DROP TABLE IF EXISTS `folder`;
CREATE TABLE `folder` (
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`name` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`org_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_type` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
`parent_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
`index` double(255, 0) NULL DEFAULT NULL,
`index` double(16, 8) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `name_unique`(`name`, `org_id`, `parent_id`) USING BTREE,
INDEX `org_id`(`org_id`) USING BTREE,
Expand All @@ -284,7 +270,7 @@ CREATE TABLE `folder` (
-- ----------------------------
DROP TABLE IF EXISTS `link`;
CREATE TABLE `link` (
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`rel_type` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`url` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
Expand All @@ -299,7 +285,7 @@ CREATE TABLE `link` (
-- ----------------------------
DROP TABLE IF EXISTS `org_settings`;
CREATE TABLE `org_settings` (
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`org_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
`type` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
`config` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL,
Expand Down Expand Up @@ -533,7 +519,6 @@ CREATE TABLE `source` (
`update_time` timestamp(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
`status` tinyint(6) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `prj_name`(`name`) USING BTREE,
UNIQUE INDEX `org_name`(`name`, `org_id`) USING BTREE,
INDEX `org_id`(`org_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
Expand Down Expand Up @@ -561,7 +546,7 @@ CREATE TABLE `storyboard` (
-- ----------------------------
DROP TABLE IF EXISTS `storypage`;
CREATE TABLE `storypage` (
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`storyboard_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_type` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
Expand Down Expand Up @@ -599,7 +584,7 @@ CREATE TABLE `user` (
-- ----------------------------
DROP TABLE IF EXISTS `user_settings`;
CREATE TABLE `user_settings` (
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`user_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_type` varchar(128) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`rel_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL,
Expand Down Expand Up @@ -653,7 +638,7 @@ CREATE TABLE `view` (
`update_time` timestamp(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0),
`parent_id` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`is_folder` tinyint(1) NULL DEFAULT NULL,
`index` double NULL DEFAULT NULL,
`index` double(16, 8) NULL DEFAULT NULL,
`status` tinyint(6) NOT NULL DEFAULT 1,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `unique_name`(`name`, `org_id`, `parent_id`) USING BTREE,
Expand Down
Binary file added bin/h2/datart.demo.mv.db
Binary file not shown.
Empty file added bin/h2/datart.demo.trace.db
Empty file.
2 changes: 2 additions & 0 deletions bin/migrations/folder.1.0.0-alpha.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `folder`
MODIFY COLUMN `index` double(16, 8) NULL DEFAULT NULL AFTER `parent_id`;
2 changes: 2 additions & 0 deletions bin/migrations/view.1.0.0-alpha.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `view`
MODIFY COLUMN `index` double(16, 8) NULL DEFAULT NULL AFTER `is_folder`;
38 changes: 38 additions & 0 deletions config/application-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
spring:
datasource:
driver-class-name: org.h2.Driver
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:h2:file:./bin/h2/datart.demo;MODE=MYSQL;DATABASE_TO_UPPER=false
username:
password:

server:
port: 8080
address: 0.0.0.0

# 开启 gzip 压缩,加快请求和响应速度
compression:
enabled: true
mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/*


datart:
server:
address: http://127.0.0.1:8080

user:
active:
send-mail: false # 注册用户时是否需要邮件验证激活

security:
token:
secret: "d@a$t%a^r&a*t" #加密密钥
timeout-min: 30 # 登录会话有效时长,单位:分钟。

env:
file-path: ${user.dir}/files # 服务端文件保存位置

screenshot:
timeout-seconds: 60
webdriver-type: CHROME
webdriver-path:
2 changes: 1 addition & 1 deletion core/src/main/java/datart/core/common/CSVParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static CSVParse create(String path) {
public List<List<Object>> parse() throws IOException {
File file = new File(path);
if (!file.exists()) {
Exceptions.tr(BaseException.class, "message.file.notfound", path);
Exceptions.notFound(path);
}
List<CSVRecord> records = CSVParser.parse(file, StandardCharsets.UTF_8, CSVFormat.DEFAULT).getRecords();
if (CollectionUtils.isEmpty(records)) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/datart/core/common/JavascriptUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class JavascriptUtils {
public static Object invoke(String path, String functionName, Object... args) throws Exception {
InputStream stream = JavascriptUtils.class.getClassLoader().getResourceAsStream(path);
if (stream == null) {
Exceptions.tr(BaseException.class, "message.file.notfound", path);
Exceptions.notFound(path);
}
try (InputStreamReader reader = new InputStreamReader(stream)) {
ScriptEngine engine = engineFactory.getScriptEngine();
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/datart/core/common/POIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static List<List<Object>> loadExcel(String path) throws IOException {
} else if (path.toLowerCase().endsWith(FileFormat.XLSX.getFormat())) {
workbook = new XSSFWorkbook(inputStream);
} else {
Exceptions.tr(BaseException.class, "message.unsupported.format", path);
Exceptions.msg("message.unsupported.format", path);
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/datart/core/common/WebUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static WebDriver createWebDriver() throws Exception {
String driverPath = Application.getProperty("datart.screenshot.webdriver-path");

if (StringUtils.isEmpty(driverPath)) {
Exceptions.tr(BaseException.class, "message.not.found.webdriver");
Exceptions.msg("message.not.found.webdriver");
}

String driverType = Application.getProperty("datart.screenshot.webdriver-type");
Expand All @@ -54,7 +54,7 @@ private static WebDriver createWebDriver() throws Exception {
case "CHROME":
return createChromeWebDriver(driverPath);
default:
Exceptions.tr(BaseException.class, "message.unsupported.webdriver", driverType);
Exceptions.msg("message.unsupported.webdriver", driverType);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface DownloadMapperExt extends DownloadMapper {
"FROM " +
" download " +
"WHERE" +
" create_by = #{userId} and create_time > DATE_FORMAT((NOW() - INTERVAL 7 DAY),'%Y%m%d') order by create_time desc"
" create_by = #{userId} and create_time > (NOW() - INTERVAL 7 DAY) order by create_time desc"
})
List<Download> selectByCreator(String userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public class DataSourceFactoryDruidImpl implements DataSourceFactory<DruidDataSo
public DruidDataSource createDataSource(JdbcProperties jdbcProperties) throws Exception {
Properties properties = configDataSource(jdbcProperties);
DruidDataSource druidDataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);

druidDataSource.setBreakAfterAcquireFailure(true);
druidDataSource.setConnectionErrorRetryAttempts(0);

log.info("druid data source created ({})", druidDataSource.getName());
return druidDataSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected List<List<Object>> parseValues(List<List<Object>> values, List<Column>
return values;
}
if (values.get(0).size() != columns.size()) {
Exceptions.tr(DataProviderException.class, "message.provider.default.schema", values.get(0).size() + ":" + columns.size());
Exceptions.msg( "message.provider.default.schema", values.get(0).size() + ":" + columns.size());
}
values.parallelStream().forEach(vals -> {
for (int i = 0; i < vals.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ private SqlNode filterSqlNode(FilterOperator operator) {
sqlNodes = nodes.toArray(new SqlNode[0]);
break;
default:
Exceptions.tr(DataProviderException.class, "message.provider.sql.type.unsupported", operator.getSqlOperator().name());
Exceptions.msg("message.provider.sql.type.unsupported", operator.getSqlOperator().name());
}
return new SqlBasicCall(sqlOp, sqlNodes, SqlParserPos.ZERO);
}
Expand Down Expand Up @@ -436,7 +436,7 @@ private SqlAggFunction mappingSqlAggFunction(AggregateOperator.SqlOperator sqlOp
case COUNT_DISTINCT:
return SqlStdOperatorTable.COUNT;
default:
Exceptions.tr(DataProviderException.class, "message.provider.sql.type.unsupported", sqlOperator.name());
Exceptions.msg( "message.provider.sql.type.unsupported", sqlOperator.name());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
import datart.core.base.exception.Exceptions;
import datart.core.data.provider.ScriptVariable;
import datart.core.data.provider.SingleTypedValue;
import datart.data.provider.base.DataProviderException;
import datart.data.provider.calcite.custom.SqlSimpleStringLiteral;
import org.apache.calcite.sql.*;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.util.DateString;
import org.apache.calcite.util.TimestampString;

import java.util.ArrayList;
Expand Down Expand Up @@ -85,7 +83,8 @@ public static List<SqlNode> createSqlNodes(ScriptVariable variable, SqlParserPos
SqlLiteral.createBoolean(Boolean.parseBoolean(v), sqlParserPos)).collect(Collectors.toList());
case DATE:
return variable.getValues().stream().map(v ->
SqlLiteral.createDate(new DateString(v), sqlParserPos)).collect(Collectors.toList());
SqlLiteral.createTimestamp(new TimestampString(v), 0, sqlParserPos))
.collect(Collectors.toList());
case FRAGMENT:
return variable.getValues().stream().map(SqlFragment::new).collect(Collectors.toList());
default:
Expand All @@ -109,7 +108,7 @@ public static SqlNode createSqlNode(SingleTypedValue value, String... names) {
case IDENTIFIER:
return createSqlIdentifier(value.getValue().toString(), names);
default:
Exceptions.tr(DataProviderException.class, "message.provider.sql.variable", value.getValueType().name());
Exceptions.msg("message.provider.sql.variable", value.getValueType().name());
}
return null;
}
Expand Down
12 changes: 0 additions & 12 deletions server/src/main/java/datart/DatartServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,4 @@ public static void main(String[] args) {
SpringApplication.run(DatartServerApplication.class, args);
}

// @Bean
// public ServletRegistrationBean<StatViewServlet> druidStatViewServlet() {
// ServletRegistrationBean<StatViewServlet> registrationBean = new ServletRegistrationBean<>(new StatViewServlet(), "/druid/*");
// registrationBean.addInitParameter("allow", "127.0.0.1");
// registrationBean.addInitParameter("deny", "");
// registrationBean.addInitParameter("loginUsername", "root");
// registrationBean.addInitParameter("loginPassword", "1234");
// registrationBean.addInitParameter("resetEnable", "false");
// return registrationBean;
// }


}