fix(图表): 修复组合图插件不支持周环比的问题
This commit is contained in:
parent
d8d4f9b72e
commit
d3e5919a8f
@ -1179,7 +1179,7 @@ public class ChartViewService {
|
||||
data = resultCustomSort(xAxis, data);
|
||||
|
||||
// 插件同环比
|
||||
data = pluginViewYOY(pluginViewParam, view, data);
|
||||
data = pluginViewYOY(pluginViewParam, view, data, ds);
|
||||
|
||||
// 请求正确的数据,然后取值
|
||||
if (isYOY) {
|
||||
@ -2035,9 +2035,9 @@ public class ChartViewService {
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<String[]> pluginViewYOY(PluginViewParam param, ChartViewDTO view, List<String[]> args) {
|
||||
private List<String[]> pluginViewYOY(PluginViewParam param, ChartViewDTO view, List<String[]> args, Datasource ds) {
|
||||
ViewPluginService viewPluginService = getPluginService(view.getType());
|
||||
return viewPluginService.yoy(param, args);
|
||||
return viewPluginService.yoy(param, args, ds);
|
||||
}
|
||||
|
||||
private ChartViewDTO emptyChartViewDTO(ChartViewDTO view) {
|
||||
|
||||
@ -10,5 +10,6 @@ public class ChartConstants {
|
||||
public static final String YEAR_YOY = "year_yoy";
|
||||
public static final String DAY_MOM = "day_mom";
|
||||
public static final String MONTH_YOY = "month_yoy";
|
||||
public static final String[] M_Y = {YEAR_MOM, MONTH_MOM, YEAR_YOY, DAY_MOM, MONTH_YOY};
|
||||
public static final String WEEK_MOM = "week_mom";
|
||||
public static final String[] M_Y = {YEAR_MOM, MONTH_MOM, YEAR_YOY, DAY_MOM, MONTH_YOY, WEEK_MOM};
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package io.dataease.plugins.view.official.impl;
|
||||
|
||||
import io.dataease.plugins.common.base.domain.Datasource;
|
||||
import io.dataease.plugins.common.dto.StaticResource;
|
||||
import io.dataease.plugins.common.dto.chart.ChartFieldCompareDTO;
|
||||
import io.dataease.plugins.view.entity.*;
|
||||
@ -119,7 +120,7 @@ public class ChartMixService extends ViewPluginService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String[]> yoy(PluginViewParam pluginViewParam, List<String[]> data) {
|
||||
public List<String[]> yoy(PluginViewParam pluginViewParam, List<String[]> data, Datasource ds) {
|
||||
List<PluginViewField> xAxis = new ArrayList<>();
|
||||
List<PluginViewField> yAxis = new ArrayList<>();
|
||||
|
||||
@ -183,7 +184,7 @@ public class ChartMixService extends ViewPluginService {
|
||||
String cValue = item[dataIndex];
|
||||
|
||||
// 获取计算后的时间,并且与所有维度拼接
|
||||
String lastTime = calcLastTime(cTime, compareCalc.getType(), timeField.getDateStyle(), timeField.getDatePattern());
|
||||
String lastTime = calcLastTime(cTime, compareCalc.getType(), timeField.getDateStyle(), timeField.getDatePattern(), ds);
|
||||
String[] dimension = Arrays.copyOfRange(item, 0, checkedField.size());
|
||||
dimension[timeIndex] = lastTime;
|
||||
|
||||
@ -321,7 +322,7 @@ public class ChartMixService extends ViewPluginService {
|
||||
return false;
|
||||
}
|
||||
|
||||
private String calcLastTime(String cTime, String type, String dateStyle, String datePattern) {
|
||||
private String calcLastTime(String cTime, String type, String dateStyle, String datePattern, Datasource ds) {
|
||||
try {
|
||||
String lastTime = null;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
@ -356,6 +357,12 @@ public class ChartMixService extends ViewPluginService {
|
||||
} else {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
} else if (StringUtils.equalsIgnoreCase(dateStyle, "y_W")) {
|
||||
if (StringUtils.equalsIgnoreCase(datePattern, "date_split")) {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy/'W'w");
|
||||
} else {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy-'W'w");
|
||||
}
|
||||
}
|
||||
Date date = simpleDateFormat.parse(cTime);
|
||||
calendar.setTime(date);
|
||||
@ -391,6 +398,26 @@ public class ChartMixService extends ViewPluginService {
|
||||
calendar.setTime(date);
|
||||
calendar.add(Calendar.MONTH, -1);
|
||||
lastTime = simpleDateFormat.format(calendar.getTime());
|
||||
} else if (StringUtils.equalsIgnoreCase(type, ChartConstants.WEEK_MOM)) {
|
||||
SimpleDateFormat simpleDateFormat = null;
|
||||
if (StringUtils.equalsIgnoreCase(datePattern, "date_split")) {
|
||||
if (StringUtils.equalsIgnoreCase(ds.getType(), "ck")) {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy/'W'w");
|
||||
} else {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy/'W'ww");
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.equalsIgnoreCase(ds.getType(), "ck")) {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy-'W'w");
|
||||
} else {
|
||||
simpleDateFormat = new SimpleDateFormat("yyyy-'W'ww");
|
||||
}
|
||||
}
|
||||
Date date = simpleDateFormat.parse(cTime);
|
||||
calendar.setTime(date);
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 6);// 加6天用一周最后一天计算周,可避免跨年的问题
|
||||
calendar.add(Calendar.WEEK_OF_YEAR, -1);
|
||||
lastTime = simpleDateFormat.format(calendar.getTime());
|
||||
}
|
||||
return lastTime;
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package io.dataease.plugins.view.service;
|
||||
|
||||
import io.dataease.plugins.common.base.domain.Datasource;
|
||||
import io.dataease.plugins.common.service.PluginComponentService;
|
||||
import io.dataease.plugins.common.util.PluginSpringContextUtil;
|
||||
import io.dataease.plugins.view.entity.PluginViewParam;
|
||||
@ -40,7 +41,7 @@ public abstract class ViewPluginService extends PluginComponentService {
|
||||
return rsHandler.format(param, lists, isDrill);
|
||||
}
|
||||
|
||||
public List<String[]> yoy(PluginViewParam param, List<String[]> lists) {
|
||||
public List<String[]> yoy(PluginViewParam param, List<String[]> lists, Datasource ds) {
|
||||
yoyHandler = new DefaultViewYOYHandler();
|
||||
return yoyHandler.yoy(param, lists);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user