forked from p85126437/datagear
图表可自定义日期类数据格式
This commit is contained in:
parent
5d7e43d2d2
commit
001a0107db
|
@ -1,8 +1,8 @@
|
|||
下一版本:
|
||||
|
||||
图表可自定义日期类数据格式;
|
||||
添加更多内置图表插件;
|
||||
系统添加缓存支持;
|
||||
ok 图表可自定义日期类数据格式;
|
||||
ok 数据集预览时可自动合并页面端编辑的属性;
|
||||
ok 自定义数据集数据格式;
|
||||
ok 升级SpringBoot至2.4.5版本;
|
||||
|
|
|
@ -240,6 +240,7 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da
|
|||
List<DataSetProperty> properties, ResultDataFormat format) throws Throwable
|
||||
{
|
||||
DataSetPropertyValueConverter converter = createDataSetPropertyValueConverter();
|
||||
ResultDataFormatter formatter = (format == null ? null : new ResultDataFormatter(format));
|
||||
|
||||
List<Map<String, Object>> data = new ArrayList<>(rawData.size());
|
||||
|
||||
|
@ -273,6 +274,9 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da
|
|||
value = defaultValues[j];
|
||||
}
|
||||
|
||||
if (formatter != null)
|
||||
value = formatter.format(value);
|
||||
|
||||
row.put(name, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -78,11 +78,11 @@ public class ResultDataFormatter
|
|||
}
|
||||
else if(ResultDataFormat.TYPE_STRING.equals(type))
|
||||
{
|
||||
value = this._timestampFormat.format((java.sql.Timestamp)value);
|
||||
re = this._timestampFormat.format((java.sql.Timestamp) value);
|
||||
}
|
||||
else if(ResultDataFormat.TYPE_NUMBER.equals(type))
|
||||
{
|
||||
((java.sql.Timestamp)value).getTime();
|
||||
re = ((java.sql.Timestamp) value).getTime();
|
||||
}
|
||||
}
|
||||
else if(value instanceof java.sql.Time)
|
||||
|
@ -95,11 +95,11 @@ public class ResultDataFormatter
|
|||
}
|
||||
else if(ResultDataFormat.TYPE_STRING.equals(type))
|
||||
{
|
||||
value = this._timeFormat.format((java.sql.Time)value);
|
||||
re = this._timeFormat.format((java.sql.Time) value);
|
||||
}
|
||||
else if(ResultDataFormat.TYPE_NUMBER.equals(type))
|
||||
{
|
||||
((java.sql.Time)value).getTime();
|
||||
re = ((java.sql.Time) value).getTime();
|
||||
}
|
||||
}
|
||||
else if(value instanceof java.util.Date)
|
||||
|
@ -112,11 +112,11 @@ public class ResultDataFormatter
|
|||
}
|
||||
else if(ResultDataFormat.TYPE_STRING.equals(type))
|
||||
{
|
||||
value = this._dateFormat.format((java.util.Date)value);
|
||||
re = this._dateFormat.format((java.util.Date) value);
|
||||
}
|
||||
else if(ResultDataFormat.TYPE_NUMBER.equals(type))
|
||||
{
|
||||
((java.util.Date)value).getTime();
|
||||
re = ((java.util.Date) value).getTime();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.datagear.analysis.DataSetException;
|
|||
import org.datagear.analysis.DataSetProperty;
|
||||
import org.datagear.analysis.DataSetQuery;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.ResultDataFormat;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +33,7 @@ import org.junit.Test;
|
|||
public class AbstractDataSetTest
|
||||
{
|
||||
@Test
|
||||
public void resolveResultDataTest_defaultDataFormat() throws Throwable
|
||||
public void resolveResultDataTest_dataFormat_default() throws Throwable
|
||||
{
|
||||
TestAbstractDataSet dataSet = new TestAbstractDataSet();
|
||||
|
||||
|
@ -89,7 +90,7 @@ public class AbstractDataSetTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void resolveResultDataTest_customDataFormat() throws Throwable
|
||||
public void resolveResultDataTest_dataFormat_custom() throws Throwable
|
||||
{
|
||||
TestAbstractDataSet dataSet = new TestAbstractDataSet();
|
||||
|
||||
|
@ -152,6 +153,160 @@ public class AbstractDataSetTest
|
|||
assertEquals(raw1.get("timestamp"), timestampFormat.format(((Date) re1.get("timestamp"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResultDataTest_resultDataFormat() throws Throwable
|
||||
{
|
||||
TestAbstractDataSet dataSet = new TestAbstractDataSet();
|
||||
|
||||
List<Map<String, Object>> rawData = new ArrayList<Map<String, Object>>();
|
||||
|
||||
Map<String, Object> raw0 = new HashMap<String, Object>();
|
||||
raw0.put("number", "4.1");
|
||||
raw0.put("date", "2021-01-01");
|
||||
raw0.put("time", "14:41:41");
|
||||
raw0.put("timestamp", "2021-01-01 14:41:41");
|
||||
|
||||
Map<String, Object> raw1 = new HashMap<String, Object>();
|
||||
raw1.put("number", "4.2");
|
||||
raw1.put("date", "2021-01-02");
|
||||
raw1.put("time", "14:41:42");
|
||||
raw1.put("timestamp", "2021-01-01 14:41:42");
|
||||
|
||||
Collections.addAll(rawData, raw0, raw1);
|
||||
|
||||
List<DataSetProperty> properties = new ArrayList<DataSetProperty>();
|
||||
{
|
||||
DataSetProperty p0 = new DataSetProperty("number", DataSetProperty.DataType.NUMBER);
|
||||
DataSetProperty p1 = new DataSetProperty("date", DataSetProperty.DataType.DATE);
|
||||
DataSetProperty p2 = new DataSetProperty("time", DataSetProperty.DataType.TIME);
|
||||
DataSetProperty p3 = new DataSetProperty("timestamp", DataSetProperty.DataType.TIMESTAMP);
|
||||
|
||||
Collections.addAll(properties, p0, p1, p2, p3);
|
||||
}
|
||||
|
||||
// 字符串
|
||||
{
|
||||
ResultDataFormat resultDataFormat = new ResultDataFormat();
|
||||
resultDataFormat.setDateType(ResultDataFormat.TYPE_STRING);
|
||||
resultDataFormat.setTimeType(ResultDataFormat.TYPE_STRING);
|
||||
resultDataFormat.setTimestampType(ResultDataFormat.TYPE_STRING);
|
||||
resultDataFormat.setDateFormat("yyyy年MM月dd日");
|
||||
resultDataFormat.setTimeFormat("HH时mm分ss秒");
|
||||
resultDataFormat.setTimestampFormat("yyyy年MM月dd日HH时mm分ss秒");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> resultData = (List<Map<String, Object>>) dataSet.resolveResultData(rawData,
|
||||
properties, resultDataFormat);
|
||||
|
||||
assertEquals(rawData.size(), resultData.size());
|
||||
|
||||
Map<String, Object> re0 = resultData.get(0);
|
||||
|
||||
assertEquals(raw0.get("number"), ((Double) re0.get("number")).toString());
|
||||
assertEquals("2021年01月01日", re0.get("date"));
|
||||
assertEquals("14时41分41秒", re0.get("time"));
|
||||
assertEquals("2021年01月01日14时41分41秒", re0.get("timestamp"));
|
||||
|
||||
Map<String, Object> re1 = resultData.get(1);
|
||||
|
||||
assertEquals(raw1.get("number"), ((Double) re1.get("number")).toString());
|
||||
assertEquals("2021年01月02日", re1.get("date"));
|
||||
assertEquals("14时41分42秒", re1.get("time"));
|
||||
assertEquals("2021年01月01日14时41分42秒", re1.get("timestamp"));
|
||||
}
|
||||
|
||||
// 数值
|
||||
{
|
||||
ResultDataFormat resultDataFormat = new ResultDataFormat();
|
||||
resultDataFormat.setDateType(ResultDataFormat.TYPE_NUMBER);
|
||||
resultDataFormat.setTimeType(ResultDataFormat.TYPE_NUMBER);
|
||||
resultDataFormat.setTimestampType(ResultDataFormat.TYPE_NUMBER);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> resultData = (List<Map<String, Object>>) dataSet.resolveResultData(rawData,
|
||||
properties, resultDataFormat);
|
||||
|
||||
assertEquals(rawData.size(), resultData.size());
|
||||
|
||||
Map<String, Object> re0 = resultData.get(0);
|
||||
|
||||
assertEquals(raw0.get("number"), ((Double) re0.get("number")).toString());
|
||||
assertEquals(1609430400000L, re0.get("date"));
|
||||
assertEquals(24101000L, re0.get("time"));
|
||||
assertEquals(1609483301000L, re0.get("timestamp"));
|
||||
|
||||
Map<String, Object> re1 = resultData.get(1);
|
||||
|
||||
assertEquals(raw1.get("number"), ((Double) re1.get("number")).toString());
|
||||
assertEquals(1609516800000L, re1.get("date"));
|
||||
assertEquals(24102000L, re1.get("time"));
|
||||
assertEquals(1609483302000L, re1.get("timestamp"));
|
||||
}
|
||||
|
||||
// 无
|
||||
{
|
||||
ResultDataFormat resultDataFormat = new ResultDataFormat();
|
||||
resultDataFormat.setDateType(ResultDataFormat.TYPE_NONE);
|
||||
resultDataFormat.setTimeType(ResultDataFormat.TYPE_NONE);
|
||||
resultDataFormat.setTimestampType(ResultDataFormat.TYPE_NONE);
|
||||
|
||||
DataFormat dataFormat = dataSet.createDataSetPropertyValueConverter().getDataFormat();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(dataFormat.getDateFormat());
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat(dataFormat.getTimeFormat());
|
||||
SimpleDateFormat timestampFormat = new SimpleDateFormat(dataFormat.getTimestampFormat());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> resultData = (List<Map<String, Object>>) dataSet.resolveResultData(rawData,
|
||||
properties, resultDataFormat);
|
||||
|
||||
assertEquals(rawData.size(), resultData.size());
|
||||
|
||||
Map<String, Object> re0 = resultData.get(0);
|
||||
|
||||
assertEquals(raw0.get("number"), ((Double) re0.get("number")).toString());
|
||||
assertEquals(raw0.get("date"), dateFormat.format(((Date) re0.get("date"))));
|
||||
assertEquals(raw0.get("time"), timeFormat.format(((Date) re0.get("time"))));
|
||||
assertEquals(raw0.get("timestamp"), timestampFormat.format(((Date) re0.get("timestamp"))));
|
||||
|
||||
Map<String, Object> re1 = resultData.get(1);
|
||||
|
||||
assertEquals(raw1.get("number"), ((Double) re1.get("number")).toString());
|
||||
assertEquals(raw1.get("date"), dateFormat.format(((Date) re1.get("date"))));
|
||||
assertEquals(raw1.get("time"), timeFormat.format(((Date) re1.get("time"))));
|
||||
assertEquals(raw1.get("timestamp"), timestampFormat.format(((Date) re1.get("timestamp"))));
|
||||
}
|
||||
|
||||
// 无
|
||||
{
|
||||
ResultDataFormat resultDataFormat = new ResultDataFormat();
|
||||
|
||||
DataFormat dataFormat = dataSet.createDataSetPropertyValueConverter().getDataFormat();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(dataFormat.getDateFormat());
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat(dataFormat.getTimeFormat());
|
||||
SimpleDateFormat timestampFormat = new SimpleDateFormat(dataFormat.getTimestampFormat());
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> resultData = (List<Map<String, Object>>) dataSet.resolveResultData(rawData,
|
||||
properties, resultDataFormat);
|
||||
|
||||
assertEquals(rawData.size(), resultData.size());
|
||||
|
||||
Map<String, Object> re0 = resultData.get(0);
|
||||
|
||||
assertEquals(raw0.get("number"), ((Double) re0.get("number")).toString());
|
||||
assertEquals(raw0.get("date"), dateFormat.format(((Date) re0.get("date"))));
|
||||
assertEquals(raw0.get("time"), timeFormat.format(((Date) re0.get("time"))));
|
||||
assertEquals(raw0.get("timestamp"), timestampFormat.format(((Date) re0.get("timestamp"))));
|
||||
|
||||
Map<String, Object> re1 = resultData.get(1);
|
||||
|
||||
assertEquals(raw1.get("number"), ((Double) re1.get("number")).toString());
|
||||
assertEquals(raw1.get("date"), dateFormat.format(((Date) re1.get("date"))));
|
||||
assertEquals(raw1.get("time"), timeFormat.format(((Date) re1.get("time"))));
|
||||
assertEquals(raw1.get("timestamp"), timestampFormat.format(((Date) re1.get("timestamp"))));
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestAbstractDataSet extends AbstractDataSet
|
||||
{
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.management.util.typehandlers;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.datagear.analysis.support.JsonSupport;
|
||||
|
||||
/**
|
||||
* 抽象JSON {@linkplain TypeHandler}。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractJsonTypeHandler<T> extends BaseTypeHandler<T>
|
||||
{
|
||||
public AbstractJsonTypeHandler()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException
|
||||
{
|
||||
String json = JsonSupport.generate(parameter, "");
|
||||
ps.setString(i, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getNullableResult(ResultSet rs, String columnName) throws SQLException
|
||||
{
|
||||
String json = rs.getString(columnName);
|
||||
return fromJson(json, getJsonObjectType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getNullableResult(ResultSet rs, int columnIndex) throws SQLException
|
||||
{
|
||||
String json = rs.getString(columnIndex);
|
||||
return fromJson(json, getJsonObjectType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getNullableResult(CallableStatement cs, int columnIndex) throws SQLException
|
||||
{
|
||||
String json = cs.getString(columnIndex);
|
||||
return fromJson(json, getJsonObjectType());
|
||||
}
|
||||
|
||||
protected <TT> TT fromJson(String json, Class<TT> clazz)
|
||||
{
|
||||
if (json == null || json.isEmpty())
|
||||
return null;
|
||||
|
||||
TT obj = JsonSupport.parse(json, clazz, null);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
protected abstract Class<T> getJsonObjectType();
|
||||
}
|
|
@ -7,16 +7,8 @@
|
|||
|
||||
package org.datagear.management.util.typehandlers;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.datagear.analysis.support.DataFormat;
|
||||
import org.datagear.analysis.support.JsonSupport;
|
||||
|
||||
/**
|
||||
* {@linkplain DataFormat}的Mybatis {@linkplain TypeHandler}。
|
||||
|
@ -24,44 +16,16 @@ import org.datagear.analysis.support.JsonSupport;
|
|||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class DataFormatTypeHandler extends BaseTypeHandler<DataFormat>
|
||||
public class DataFormatTypeHandler extends AbstractJsonTypeHandler<DataFormat>
|
||||
{
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, DataFormat parameter, JdbcType jdbcType)
|
||||
throws SQLException
|
||||
public DataFormatTypeHandler()
|
||||
{
|
||||
String json = JsonSupport.generate(parameter, "");
|
||||
ps.setString(i, json);
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFormat getNullableResult(ResultSet rs, String columnName) throws SQLException
|
||||
protected Class<DataFormat> getJsonObjectType()
|
||||
{
|
||||
String json = rs.getString(columnName);
|
||||
return fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFormat getNullableResult(ResultSet rs, int columnIndex) throws SQLException
|
||||
{
|
||||
String json = rs.getString(columnIndex);
|
||||
return fromJson(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFormat getNullableResult(CallableStatement cs, int columnIndex) throws SQLException
|
||||
{
|
||||
String json = cs.getString(columnIndex);
|
||||
return fromJson(json);
|
||||
}
|
||||
|
||||
protected DataFormat fromJson(String json)
|
||||
{
|
||||
if(json == null || json.isEmpty())
|
||||
return null;
|
||||
|
||||
DataFormat dataFormat = JsonSupport.parse(json, DataFormat.class, null);
|
||||
|
||||
return dataFormat;
|
||||
return DataFormat.class;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright 2018 datagear.tech
|
||||
*
|
||||
* Licensed under the LGPLv3 license:
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.html
|
||||
*/
|
||||
|
||||
package org.datagear.management.util.typehandlers;
|
||||
|
||||
import org.apache.ibatis.type.TypeHandler;
|
||||
import org.datagear.analysis.ResultDataFormat;
|
||||
|
||||
/**
|
||||
* {@linkplain ResultDataFormat}的Mybatis {@linkplain TypeHandler}。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class ResultDataFormatTypeHandler extends AbstractJsonTypeHandler<ResultDataFormat>
|
||||
{
|
||||
public ResultDataFormatTypeHandler()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<ResultDataFormat> getJsonObjectType()
|
||||
{
|
||||
return ResultDataFormat.class;
|
||||
}
|
||||
}
|
|
@ -802,6 +802,9 @@ WHERE DS_PARAM_VALUES IS NOT NULL AND DS_PARAM_VALUES != '';
|
|||
--ALTER TABLE DATAGEAR_HCW_DS DROP COLUMN DS_PARAM_VALUES;
|
||||
|
||||
--2021-05-26
|
||||
--添加数据格式列
|
||||
|
||||
--数据集表添加数据格式列
|
||||
ALTER TABLE DATAGEAR_DATA_SET ADD COLUMN DS_DATA_FORMAT VARCHAR(500);
|
||||
|
||||
--2021-05-29
|
||||
--图表表添加结果数据格式列
|
||||
ALTER TABLE DATAGEAR_HTML_CHART_WIDGET ADD COLUMN HCW_RD_FORMAT VARCHAR(500);
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
INSERT INTO DATAGEAR_HTML_CHART_WIDGET
|
||||
(
|
||||
HCW_ID, HCW_NAME, HCW_PLUGIN_ID, HCW_UPDATE_INTERVAL, HCW_CREATE_USER_ID,
|
||||
HCW_CREATE_TIME, HCW_AP_ID
|
||||
HCW_CREATE_TIME, HCW_AP_ID, HCW_RD_FORMAT
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
#{entity.id}, #{entity.name}, #{entity.htmlChartPlugin.id}, #{entity.updateInterval}, #{entity.createUser.id},
|
||||
#{entity.createTime}, #{entity.analysisProject.id, jdbcType=VARCHAR}
|
||||
#{entity.createTime}, #{entity.analysisProject.id, jdbcType=VARCHAR}, #{entity.resultDataFormat, jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
@ -34,7 +34,8 @@
|
|||
HCW_NAME = #{entity.name},
|
||||
HCW_PLUGIN_ID = #{entity.htmlChartPlugin.id},
|
||||
HCW_UPDATE_INTERVAL = #{entity.updateInterval},
|
||||
HCW_AP_ID = #{entity.analysisProject.id, jdbcType=VARCHAR}
|
||||
HCW_AP_ID = #{entity.analysisProject.id, jdbcType=VARCHAR},
|
||||
HCW_RD_FORMAT = #{entity.resultDataFormat, jdbcType=VARCHAR}
|
||||
WHERE
|
||||
HCW_ID = #{entity.id}
|
||||
</update>
|
||||
|
@ -187,6 +188,7 @@
|
|||
A.HCW_CREATE_USER_ID AS ${_iq_}createUser.id${_iq_},
|
||||
<include refid="common.fieldsForCreateUser" />,
|
||||
A.HCW_CREATE_TIME AS ${_iq_}createTime${_iq_},
|
||||
A.HCW_RD_FORMAT AS ${_iq_}resultDataFormat${_iq_},
|
||||
AP.*
|
||||
FROM
|
||||
DATAGEAR_HTML_CHART_WIDGET A
|
||||
|
|
|
@ -76,6 +76,7 @@ import org.datagear.management.util.dialect.MbSqlDialect;
|
|||
import org.datagear.management.util.dialect.MbSqlDialectBuilder;
|
||||
import org.datagear.management.util.typehandlers.DataFormatTypeHandler;
|
||||
import org.datagear.management.util.typehandlers.LiteralBooleanTypeHandler;
|
||||
import org.datagear.management.util.typehandlers.ResultDataFormatTypeHandler;
|
||||
import org.datagear.meta.resolver.DBMetaResolver;
|
||||
import org.datagear.meta.resolver.GenericDBMetaResolver;
|
||||
import org.datagear.persistence.DialectSource;
|
||||
|
@ -329,7 +330,8 @@ public class CoreConfig implements InitializingBean
|
|||
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
||||
bean.setDataSource(this.dataSourceConfig.dataSource());
|
||||
bean.setMapperLocations(mapperResources);
|
||||
bean.setTypeHandlers(new TypeHandler<?>[] { new LiteralBooleanTypeHandler(), new DataFormatTypeHandler() });
|
||||
bean.setTypeHandlers(new TypeHandler<?>[] { new LiteralBooleanTypeHandler(), new DataFormatTypeHandler(),
|
||||
new ResultDataFormatTypeHandler() });
|
||||
return bean.getObject();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
@ -134,9 +134,9 @@ public class WebMvcConfigurerConfig implements WebMvcConfigurer
|
|||
FreeMarkerConfigurer bean = new FreeMarkerConfigurer();
|
||||
|
||||
Properties settings = new Properties();
|
||||
settings.setProperty("datetime_format", "yyyy-MM-dd HH:mm:ss");
|
||||
settings.setProperty("date_format", "yyyy-MM-dd");
|
||||
settings.setProperty("number_format", "#.##");
|
||||
settings.setProperty("datetime_format", org.datagear.util.DateFormat.DEFAULT_TIMESTAMP_FORMAT);
|
||||
settings.setProperty("date_format", org.datagear.util.DateFormat.DEFAULT_DATE_FORMAT);
|
||||
settings.setProperty("number_format", org.datagear.util.DateNumberFormat.DEFAULT_NUMBER_FORMAT);
|
||||
|
||||
// 开启自动转义功能,并设置默认转义格式为HTML,页面不再需要每个地方都转义
|
||||
// ${content?html}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.datagear.analysis.ChartPluginManager;
|
|||
import org.datagear.analysis.DataSetQuery;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.RenderContext;
|
||||
import org.datagear.analysis.ResultDataFormat;
|
||||
import org.datagear.analysis.TemplateDashboardWidgetResManager;
|
||||
import org.datagear.analysis.support.html.HtmlChartPlugin;
|
||||
import org.datagear.analysis.support.html.HtmlTplDashboard;
|
||||
|
@ -146,6 +147,7 @@ public class ChartController extends AbstractChartPluginAwareController implemen
|
|||
public String add(HttpServletRequest request, HttpServletResponse response, org.springframework.ui.Model model)
|
||||
{
|
||||
HtmlChartWidgetEntity chart = new HtmlChartWidgetEntity();
|
||||
chart.setResultDataFormat(createDefaultResultDataFormat());
|
||||
setCookieAnalysisProject(request, response, chart);
|
||||
|
||||
model.addAttribute("chart", chart);
|
||||
|
@ -169,6 +171,9 @@ public class ChartController extends AbstractChartPluginAwareController implemen
|
|||
|
||||
chart.setPlugin(toHtmlChartPluginVO(request, chart.getPlugin()));
|
||||
|
||||
if (chart.getResultDataFormat() == null)
|
||||
chart.setResultDataFormat(createDefaultResultDataFormat());
|
||||
|
||||
HtmlChartPluginVO chartPluginVO = (chart.getPlugin() != null
|
||||
? getHtmlChartPluginVO(request, chart.getPlugin().getId())
|
||||
: null);
|
||||
|
@ -491,6 +496,16 @@ public class ChartController extends AbstractChartPluginAwareController implemen
|
|||
setCookieAnalysisProjectIfValid(request, response, this.analysisProjectService, entity);
|
||||
}
|
||||
|
||||
protected ResultDataFormat createDefaultResultDataFormat()
|
||||
{
|
||||
ResultDataFormat rdf = new ResultDataFormat();
|
||||
rdf.setDateType(ResultDataFormat.TYPE_STRING);
|
||||
rdf.setTimeType(ResultDataFormat.TYPE_STRING);
|
||||
rdf.setTimestampType(ResultDataFormat.TYPE_STRING);
|
||||
|
||||
return rdf;
|
||||
}
|
||||
|
||||
protected void checkSaveEntity(HtmlChartWidgetEntity chart)
|
||||
{
|
||||
if (isBlank(chart.getName()))
|
||||
|
|
|
@ -650,7 +650,7 @@ dataSet.dataSetType.JsonFile=JSON文件
|
|||
dataSet.dataSetType.Http=HTTP接口
|
||||
dataSet.dataFormat.dateFormat=日期
|
||||
dataSet.dataFormat.timeFormat=时间
|
||||
dataSet.dataFormat.timestampFormat=时间戳
|
||||
dataSet.dataFormat.timestampFormat=日期时间
|
||||
dataSet.dataFormat.numberFormat=数值
|
||||
dataSet.setDataSourceFormat=设置数据源格式
|
||||
dataSet.setDataSourceFormat.desc=设置从数据源中解析日期、数值类属性值时使用的格式
|
||||
|
@ -798,6 +798,19 @@ chart.chartDataSet.attachment.desc=数据集不用作渲染图表,不需设置
|
|||
chart.chartDataSet.paramValue=参数值
|
||||
chart.setDataSetParamValue=设置数据集参数值
|
||||
chart.chartDataSet.clearParamValueTip=清除数据集参数值,可在图表展示时设置
|
||||
chart.resultDataFormat=数据格式
|
||||
chart.resultDataFormat.desc=图表展示时,日期类数据的展示格式
|
||||
chart.resultDataFormat.TYPE_NUMBER=数值
|
||||
chart.resultDataFormat.TYPE_STRING=字符串
|
||||
chart.resultDataFormat.dateType=日期类型
|
||||
chart.resultDataFormat.dateFormat=日期格式
|
||||
chart.resultDataFormat.dateFormat.desc=当日期类型为[字符串]时的日期格式
|
||||
chart.resultDataFormat.timeType=时间类型
|
||||
chart.resultDataFormat.timeFormat=时间格式
|
||||
chart.resultDataFormat.timeFormat.desc=当时间类型为[字符串]时的时间格式
|
||||
chart.resultDataFormat.timestampType=日期时间类型
|
||||
chart.resultDataFormat.timestampFormat=日期时间格式
|
||||
chart.resultDataFormat.timestampFormat.desc=当日期时间类型为[字符串]时的日期时间格式
|
||||
|
||||
#Dashboard
|
||||
dashboard.manageDashboard=管理看板
|
||||
|
|
|
@ -798,6 +798,19 @@ chart.chartDataSet.attachment.desc=Data set is not for rendering chart, only as
|
|||
chart.chartDataSet.paramValue=Parameter
|
||||
chart.setDataSetParamValue=Set parameter value
|
||||
chart.chartDataSet.clearParamValueTip=Clear parameter value, can be set later when chart is shown
|
||||
chart.resultDataFormat=Data format
|
||||
chart.resultDataFormat.desc=The date value format when chart shown
|
||||
chart.resultDataFormat.TYPE_NUMBER=Number
|
||||
chart.resultDataFormat.TYPE_STRING=String
|
||||
chart.resultDataFormat.dateType=Date type
|
||||
chart.resultDataFormat.dateFormat=Date format
|
||||
chart.resultDataFormat.dateFormat.desc=The date format when date type is [STRING]
|
||||
chart.resultDataFormat.timeType=Time type
|
||||
chart.resultDataFormat.timeFormat=Time format
|
||||
chart.resultDataFormat.timeFormat.desc=The time format when time type is [STRING]
|
||||
chart.resultDataFormat.timestampType=Datetime type
|
||||
chart.resultDataFormat.timestampFormat=Datetime format
|
||||
chart.resultDataFormat.timestampFormat.desc=The datetime format when datetime type is [STRING]
|
||||
|
||||
#Dashboard
|
||||
dashboard.manageDashboard=Manage dasboard
|
||||
|
|
|
@ -19,6 +19,10 @@ body{
|
|||
opacity: 0.7;
|
||||
filter: Alpha(Opacity=70);
|
||||
}
|
||||
.transparency{
|
||||
opacity: 0;
|
||||
filter: Alpha(Opacity=0);
|
||||
}
|
||||
|
||||
a.link,
|
||||
a.link:link,
|
||||
|
@ -2630,7 +2634,7 @@ table.dataTable tbody tr td select{
|
|||
display: none;
|
||||
}
|
||||
.page-form-dataSet .workspace .dataformat-panel .form-item .form-item-label{
|
||||
width: 35%
|
||||
width: 35%;
|
||||
}
|
||||
.page-form-dataSet .workspace .dataformat-panel .form-item .form-item-value{
|
||||
width: 65%;
|
||||
|
@ -2865,9 +2869,15 @@ table.dataTable tbody tr td select{
|
|||
margin-bottom: 0.41em;
|
||||
}
|
||||
.page-form-chart .add-data-set-button{
|
||||
vertical-align: top;
|
||||
position: absolute;
|
||||
left: 60%;
|
||||
top: 0;
|
||||
margin-left: 1em;
|
||||
}
|
||||
.page-form-chart .dataformat-button{
|
||||
position: absolute;
|
||||
left: 60%;
|
||||
bottom: 1.4em;
|
||||
margin-left: 1em;
|
||||
}
|
||||
.page-form-chart .data-set-param-value-panel{
|
||||
|
@ -2887,6 +2897,31 @@ table.dataTable tbody tr td select{
|
|||
max-height: 14em;
|
||||
overflow: auto;
|
||||
}
|
||||
.page-form-chart .dataformat-panel{
|
||||
position: absolute;
|
||||
right: 40%;
|
||||
bottom: -0.41em;
|
||||
width: 60%;
|
||||
margin-right: -1rem;
|
||||
display: none;
|
||||
}
|
||||
.page-form-chart .dataformat-panel .form-item{
|
||||
display: block !important;
|
||||
}
|
||||
.page-form-chart .dataformat-panel .form-item .form-item-label{
|
||||
width: 35% !important;
|
||||
}
|
||||
.page-form-chart .dataformat-panel .form-item .form-item-label label{
|
||||
width: 95% !important;
|
||||
}
|
||||
.page-form-chart .dataformat-panel .form-item .form-item-value{
|
||||
width: 65% !important;
|
||||
margin-left: -0.71em !important;
|
||||
padding-left: 0.71em !important;
|
||||
}
|
||||
.page-form-chart .dataformat-panel .form-item .form-item-value input[type=text]{
|
||||
width: 80% !important;
|
||||
}
|
||||
|
||||
.page-grid-chartPlugin{
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ readonly 是否只读操作,允许为null
|
|||
<#assign formAction=(formAction!'#')>
|
||||
<#assign readonly=(readonly!false)>
|
||||
<#assign isAdd=(formAction == 'saveAdd')>
|
||||
<#assign ResultDataFormat=statics['org.datagear.analysis.ResultDataFormat']>
|
||||
<html>
|
||||
<head>
|
||||
<#include "../../include/html_head.ftl">
|
||||
|
@ -62,6 +63,7 @@ readonly 是否只读操作,允许为null
|
|||
<#if !readonly>
|
||||
<button type="button" class="add-data-set-button"><@spring.message code='add' /></button>
|
||||
</#if>
|
||||
<button type="button" class="dataformat-button"><@spring.message code='chart.resultDataFormat' /></button>
|
||||
<div class='data-sign-select-panel ui-widget ui-widget-content ui-corner-all ui-front ui-widget-shadow'>
|
||||
<div class="select-panel-head ui-widget-header ui-corner-all"><@spring.message code='chart.selectDataSign' /></div>
|
||||
<div class="select-panel-content">
|
||||
|
@ -72,6 +74,112 @@ readonly 是否只读操作,允许为null
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="${pageId}-dataFormatPanel" class='dataformat-panel minor-panel ui-widget ui-widget-content ui-corner-all ui-front ui-widget-shadow'>
|
||||
<div class="panel-head ui-widget-header ui-corner-all">
|
||||
<label class="tip-label" title="<@spring.message code='chart.resultDataFormat.desc' />">
|
||||
<@spring.message code='chart.resultDataFormat' />
|
||||
</label>
|
||||
</div>
|
||||
<div class="panel-content">
|
||||
<div class="form">
|
||||
<div class="form-content">
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">
|
||||
<label><@spring.message code='chart.resultDataFormat.dateType' /></label>
|
||||
</div>
|
||||
<div class="form-item-value">
|
||||
<div class="resultDataFormat-dateType-radios">
|
||||
<label for="${pageId}-resultDataFormat-dateType-0" title="">
|
||||
<@spring.message code='chart.resultDataFormat.TYPE_STRING' />
|
||||
</label>
|
||||
<input type="radio" id="${pageId}-resultDataFormat-dateType-0"
|
||||
<#if ResultDataFormat.TYPE_STRING == chart.resultDataFormat.dateType>checked="checked"</#if>
|
||||
name="resultDataFormat.dateType" value="${ResultDataFormat.TYPE_STRING}" />
|
||||
<label for="${pageId}-resultDataFormat-dateType-1" title="">
|
||||
<@spring.message code='chart.resultDataFormat.TYPE_NUMBER' />
|
||||
</label>
|
||||
<input type="radio" id="${pageId}-resultDataFormat-dateType-1"
|
||||
<#if ResultDataFormat.TYPE_NUMBER == chart.resultDataFormat.dateType>checked="checked"</#if>
|
||||
name="resultDataFormat.dateType" value="${ResultDataFormat.TYPE_NUMBER}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">
|
||||
<label title="<@spring.message code='chart.resultDataFormat.dateFormat.desc' />">
|
||||
<@spring.message code='chart.resultDataFormat.dateFormat' />
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-item-value">
|
||||
<input name="resultDataFormat.dateFormat" type="text" value="${(chart.resultDataFormat.dateFormat)!}" class="ui-widget ui-widget-content" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">
|
||||
<label><@spring.message code='chart.resultDataFormat.timeType' /></label>
|
||||
</div>
|
||||
<div class="form-item-value">
|
||||
<div class="resultDataFormat-timeType-radios">
|
||||
<label for="${pageId}-resultDataFormat-timeType-0" title="">
|
||||
<@spring.message code='chart.resultDataFormat.TYPE_STRING' />
|
||||
</label>
|
||||
<input type="radio" id="${pageId}-resultDataFormat-timeType-0"
|
||||
<#if ResultDataFormat.TYPE_STRING == chart.resultDataFormat.timeType>checked="checked"</#if>
|
||||
name="resultDataFormat.timeType" value="${ResultDataFormat.TYPE_STRING}" />
|
||||
<label for="${pageId}-resultDataFormat-timeType-1" title="">
|
||||
<@spring.message code='chart.resultDataFormat.TYPE_NUMBER' />
|
||||
</label>
|
||||
<input type="radio" id="${pageId}-resultDataFormat-timeType-1"
|
||||
<#if ResultDataFormat.TYPE_NUMBER == chart.resultDataFormat.timeType>checked="checked"</#if>
|
||||
name="resultDataFormat.timeType" value="${ResultDataFormat.TYPE_NUMBER}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">
|
||||
<label title="<@spring.message code='chart.resultDataFormat.timeFormat.desc' />">
|
||||
<@spring.message code='chart.resultDataFormat.timeFormat' />
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-item-value">
|
||||
<input name="resultDataFormat.timeFormat" type="text" value="${(chart.resultDataFormat.timeFormat)!}" class="ui-widget ui-widget-content" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">
|
||||
<label><@spring.message code='chart.resultDataFormat.timestampType' /></label>
|
||||
</div>
|
||||
<div class="form-item-value">
|
||||
<div class="resultDataFormat-timestampType-radios">
|
||||
<label for="${pageId}-resultDataFormat-timestampType-0" title="">
|
||||
<@spring.message code='chart.resultDataFormat.TYPE_STRING' />
|
||||
</label>
|
||||
<input type="radio" id="${pageId}-resultDataFormat-timestampType-0"
|
||||
<#if ResultDataFormat.TYPE_STRING == chart.resultDataFormat.timestampType>checked="checked"</#if>
|
||||
name="resultDataFormat.timestampType" value="${ResultDataFormat.TYPE_STRING}" />
|
||||
<label for="${pageId}-resultDataFormat-timestampType-1" title="">
|
||||
<@spring.message code='chart.resultDataFormat.TYPE_NUMBER' />
|
||||
</label>
|
||||
<input type="radio" id="${pageId}-resultDataFormat-timestampType-1"
|
||||
<#if ResultDataFormat.TYPE_NUMBER == chart.resultDataFormat.timestampType>checked="checked"</#if>
|
||||
name="resultDataFormat.timestampType" value="${ResultDataFormat.TYPE_NUMBER}" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-item-label">
|
||||
<label title="<@spring.message code='chart.resultDataFormat.timestampFormat.desc' />">
|
||||
<@spring.message code='chart.resultDataFormat.timestampFormat' />
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-item-value">
|
||||
<input name="resultDataFormat.timestampFormat" type="text" value="${(chart.resultDataFormat.timestampFormat)!}" class="ui-widget ui-widget-content" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-item">
|
||||
|
@ -127,6 +235,16 @@ readonly 是否只读操作,允许为null
|
|||
po.element("input[name='updateIntervalRadio']").checkboxradio({icon:false});
|
||||
po.element(".updateInterval-radios").controlgroup();
|
||||
|
||||
po.element("input[name='resultDataFormat.dateType']").checkboxradio({icon:false});
|
||||
po.element("input[name='resultDataFormat.timeType']").checkboxradio({icon:false});
|
||||
po.element("input[name='resultDataFormat.timestampType']").checkboxradio({icon:false});
|
||||
//隐藏元素设置controlgroup组件没有圆角效果,所以这里先显示设置后再隐藏
|
||||
po.element(".dataformat-panel").addClass("transparency").show();
|
||||
po.element(".resultDataFormat-dateType-radios").controlgroup();
|
||||
po.element(".resultDataFormat-timeType-radios").controlgroup();
|
||||
po.element(".resultDataFormat-timestampType-radios").controlgroup();
|
||||
po.element(".dataformat-panel").removeClass("transparency").hide();
|
||||
|
||||
po.url = function(action)
|
||||
{
|
||||
return "${contextPath}/analysis/chart/" + action;
|
||||
|
@ -509,6 +627,11 @@ readonly 是否只读操作,允许为null
|
|||
</#if>
|
||||
};
|
||||
|
||||
po.element(".dataformat-button").click(function()
|
||||
{
|
||||
po.element("#${pageId}-dataFormatPanel").toggle();
|
||||
});
|
||||
|
||||
po.element(".add-data-set-button").click(function()
|
||||
{
|
||||
var options =
|
||||
|
@ -787,6 +910,13 @@ readonly 是否只读操作,允许为null
|
|||
if($target.closest(".data-sign-select-panel, .sign-add-button").length == 0)
|
||||
$ssp.hide();
|
||||
}
|
||||
|
||||
var $dfp = po.element(".dataformat-panel");
|
||||
if(!$dfp.is(":hidden"))
|
||||
{
|
||||
if($target.closest(".dataformat-panel, .dataformat-button").length == 0)
|
||||
$dfp.hide();
|
||||
}
|
||||
});
|
||||
|
||||
po.initChartPlugin(po.chartPluginVO);
|
||||
|
|
Loading…
Reference in New Issue