forked from github/dataease
Merge pull request #3403 from dataease/pr@dev@feat_report_task_time_condition
feat(定时报告): 视图数据构造时间过滤器条件
This commit is contained in:
commit
96a64d8e45
@ -23,10 +23,10 @@ public abstract class FilterBuildTemplate {
|
||||
|
||||
List<Map<String, Object>> filters = componentsFilter(components, "custom", null, null);
|
||||
|
||||
if(ObjectUtils.isNotEmpty(searchButton)) {
|
||||
if (ObjectUtils.isNotEmpty(searchButton)) {
|
||||
Map<String, Object> options = (Map<String, Object>) searchButton.get("options");
|
||||
Map<String, Object> attrs = (Map<String, Object>) options.get("attrs");
|
||||
Boolean customRange = (Boolean)attrs.get("customRange");
|
||||
Boolean customRange = (Boolean) attrs.get("customRange");
|
||||
Boolean autoTrigger = (Boolean) attrs.get("autoTrigger");
|
||||
List<String> filterIds = (List<String>) attrs.get("filterIds");
|
||||
if (!autoTrigger) { // 不是自动触发 // 需要过滤掉按钮关联的条件组件
|
||||
@ -77,7 +77,7 @@ public abstract class FilterBuildTemplate {
|
||||
return ObjectUtils.isNotEmpty(condition) && CollectionUtils.isNotEmpty(condition.getValue()) && StringUtils.isNotBlank(condition.getValue().get(0));
|
||||
}
|
||||
|
||||
private static Boolean viewIdMatch(List<String> viewIds, String viewId) {
|
||||
private static Boolean viewIdMatch(List<String> viewIds, String viewId) {
|
||||
return CollectionUtils.isEmpty(viewIds) || viewIds.contains(viewId);
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ public abstract class FilterBuildTemplate {
|
||||
Map<String, Object> component = filterParamTO.getComponent();
|
||||
Map<String, Object> attrs = (Map<String, Object>) ((Map<String, Object>) component.get("options")).get("attrs");
|
||||
String fieldId = attrs.get("fieldId").toString();
|
||||
List<String> viewIds = (List<String>)attrs.get("viewIds");
|
||||
List<String> viewIds = (List<String>) attrs.get("viewIds");
|
||||
List<String> parameters = (List<String>) attrs.get("parameters");
|
||||
Boolean multiple = ObjectUtils.isNotEmpty(attrs.get("multiple")) && (Boolean) attrs.get("multiple");
|
||||
if (isTree && !multiple && CollectionUtils.isNotEmpty(value)) {
|
||||
@ -147,9 +147,9 @@ public abstract class FilterBuildTemplate {
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> componentsFilter(List<Map<String, Object>> components, String type,
|
||||
String componentType, String serviceName) {
|
||||
String componentType, String serviceName) {
|
||||
return components.stream().filter(component -> {
|
||||
String ctype = Optional.ofNullable(component.get("type")).orElse("").toString();
|
||||
String ctype = Optional.ofNullable(component.get("type")).orElse("").toString();
|
||||
String cComponentType = Optional.ofNullable(component.get("component")).orElse("").toString();
|
||||
String cServiceName = Optional.ofNullable(component.get("serviceName")).orElse("").toString();
|
||||
|
||||
@ -180,10 +180,20 @@ public abstract class FilterBuildTemplate {
|
||||
beanMapping.put("numberRangeWidget", "numberRangeWidget");
|
||||
beanMapping.put("textSelectTreeWidget", "textSelectTreeWidget");
|
||||
beanMapping.put("textInputWidget", "textInputWidget");
|
||||
beanMapping.put("timeDateWidget", "timeDateWidget");
|
||||
beanMapping.put("timeMonthWidget", "timeMonthWidget");
|
||||
beanMapping.put("timeYearWidget", "timeYearWidget");
|
||||
beanMapping.put("timeDateRangeWidget", "timeDateRangeWidget");
|
||||
String beanName = beanMapping.get(serviceName);
|
||||
if (StringUtils.isBlank(beanName) && StringUtils.containsIgnoreCase(serviceName, "select")) {
|
||||
beanName = "selectWidget";
|
||||
}
|
||||
return (FilterBuildTemplate)CommonBeanFactory.getBean(beanName);
|
||||
|
||||
return (FilterBuildTemplate) CommonBeanFactory.getBean(beanName);
|
||||
}
|
||||
|
||||
protected Map<String, Object> buildAttrs(Map<String, Object> component) {
|
||||
Map<String, Object> attrs = (Map<String, Object>) ((Map<String, Object>) component.get("options")).get("attrs");
|
||||
return attrs;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,209 @@
|
||||
package io.dataease.service.chart.build;
|
||||
|
||||
import io.dataease.commons.exception.DEException;
|
||||
import io.dataease.commons.utils.LogUtil;
|
||||
import io.dataease.dto.chart.FilterParamTO;
|
||||
import io.dataease.service.chart.FilterBuildTemplate;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public abstract class TimeBuild extends FilterBuildTemplate {
|
||||
|
||||
private static final String MULTIPLETYPE = "daterange";
|
||||
|
||||
@Override
|
||||
protected FilterParamTO buildParam(Map<String, Object> component) {
|
||||
FilterParamTO result = new FilterParamTO();
|
||||
result.setComponent(component);
|
||||
result.setValue(null);
|
||||
result.setOperator("between");
|
||||
result.setIsTree(false);
|
||||
|
||||
Map<String, Object> options = (Map<String, Object>) component.get("options");
|
||||
Map<String, Object> attrs = (Map<String, Object>) options.get("attrs");
|
||||
Object valueObj = options.get("value");
|
||||
String defaultValue = "";
|
||||
boolean multiple = attrs.get("type").equals(MULTIPLETYPE);
|
||||
Object defaultObject = attrs.get("default");
|
||||
Boolean isDynamic = false;
|
||||
if (ObjectUtils.isNotEmpty(defaultObject)) {
|
||||
Map<String, Object> defaultMap = (Map<String, Object>) defaultObject;
|
||||
isDynamic = (Boolean) defaultMap.getOrDefault("isDynamic", false);
|
||||
}
|
||||
|
||||
List<String> realValues = null;
|
||||
|
||||
if (!ObjectUtils.isEmpty(valueObj)) {
|
||||
if (valueObj instanceof List) {
|
||||
defaultValue = "";
|
||||
} else {
|
||||
defaultValue = valueObj.toString();
|
||||
}
|
||||
}
|
||||
String componentType = componentType(component);
|
||||
String labelFormat = labelFormat(component);
|
||||
if (isDynamic) {
|
||||
List<Long> dynamicTimes = dynamicDateFromNow(component);
|
||||
if (CollectionUtils.isNotEmpty(dynamicTimes)) {
|
||||
int size = dynamicTimes.size();
|
||||
if (size > 1) {
|
||||
String start = timeSection(String.valueOf(dynamicTimes.get(0)), multiple ? "datetime" : componentType, labelFormat).get(0);
|
||||
String end = timeSection(String.valueOf(dynamicTimes.get(1)), multiple ? "datetime" : componentType, labelFormat).get(1);
|
||||
realValues = add2List(start, end);
|
||||
} else {
|
||||
realValues = timeSection(String.valueOf(dynamicTimes.get(0)), componentType, labelFormat);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if (StringUtils.isBlank(defaultValue)) {
|
||||
realValues = new ArrayList<>();
|
||||
} else {
|
||||
if (multiple) {
|
||||
List<String> realVals = Arrays.asList(defaultValue.split(","));
|
||||
String start = realVals.get(0);
|
||||
String end = realVals.get(1);
|
||||
start = timeSection(start, "datetime", labelFormat).get(0);
|
||||
end = timeSection(end, "datetime", labelFormat).get(1);
|
||||
realValues = add2List(start, end);
|
||||
} else {
|
||||
realValues = Arrays.asList(defaultValue.split(",")).stream().limit(1).collect(Collectors.toList());
|
||||
realValues = timeSection(realValues.get(0), componentType, labelFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setValue(realValues);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<String> timeSection(String sourceTimeStr, String type, String labelFormat) {
|
||||
if (StringUtils.isBlank(sourceTimeStr)) return null;
|
||||
Long sourceTime = Long.parseLong(sourceTimeStr);
|
||||
|
||||
List<String> result = new ArrayList<>();
|
||||
|
||||
List<String> formatArr = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(labelFormat)) {
|
||||
formatArr = Arrays.stream(labelFormat.split(" ")).collect(Collectors.toList());
|
||||
}
|
||||
Integer[] fieldNames = {Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND, Calendar.MILLISECOND};
|
||||
Calendar instance = Calendar.getInstance();
|
||||
instance.setTimeInMillis(sourceTime);
|
||||
int methodsLen = fieldNames.length;
|
||||
int childArrLength = 0;
|
||||
if (StringUtils.equals("datetime", type) && formatArr.size() > 1) {
|
||||
List<String> childArr = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(formatArr.get(1))) {
|
||||
childArr = Arrays.stream(formatArr.get(1).split(":")).collect(Collectors.toList());
|
||||
}
|
||||
childArrLength = childArr.size();
|
||||
while (--methodsLen >= childArrLength) {
|
||||
executeSetFieldValue(instance, fieldNames[methodsLen], 0);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < methodsLen; i++) {
|
||||
executeSetFieldValue(instance, fieldNames[i], 0);
|
||||
}
|
||||
}
|
||||
|
||||
Calendar endInstance = Calendar.getInstance();
|
||||
endInstance.setTimeInMillis(instance.getTimeInMillis());
|
||||
if (StringUtils.equals("year", type)) {
|
||||
instance.set(Calendar.MONTH, 0);
|
||||
instance.set(Calendar.DATE, 1);
|
||||
endInstance.setTimeInMillis(instance.getTimeInMillis());
|
||||
endInstance.set(Calendar.YEAR, endInstance.get(Calendar.YEAR) + 1);
|
||||
endInstance.add(Calendar.SECOND, -1);
|
||||
endInstance.roll(Calendar.MILLISECOND, -1);
|
||||
|
||||
}
|
||||
|
||||
if (StringUtils.equals("month", type)) {
|
||||
instance.set(Calendar.DATE, 1);
|
||||
endInstance.setTimeInMillis(instance.getTimeInMillis());
|
||||
endInstance.set(Calendar.MONTH, endInstance.get(Calendar.MONTH) + 1);
|
||||
endInstance.add(Calendar.SECOND, -1);
|
||||
endInstance.roll(Calendar.MILLISECOND, -1);
|
||||
}
|
||||
|
||||
if (StringUtils.equals("date", type)) {
|
||||
endInstance.set(Calendar.DATE, endInstance.get(Calendar.DATE) + 1);
|
||||
endInstance.add(Calendar.SECOND, -1);
|
||||
endInstance.roll(Calendar.MILLISECOND, -1);
|
||||
}
|
||||
|
||||
if (StringUtils.equals("datetime", type)) {
|
||||
if (childArrLength == 0) {
|
||||
endInstance.set(Calendar.DATE, endInstance.get(Calendar.DATE) + 1);
|
||||
} else {
|
||||
Integer fieldNameFlag = fieldNames[childArrLength - 1];
|
||||
endInstance.set(fieldNameFlag, endInstance.get(fieldNameFlag) + 1);
|
||||
}
|
||||
endInstance.add(Calendar.SECOND, -1);
|
||||
endInstance.roll(Calendar.MILLISECOND, -1);
|
||||
}
|
||||
|
||||
result.add(String.valueOf(instance.getTimeInMillis()));
|
||||
result.add(String.valueOf(endInstance.getTimeInMillis()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private void executeSetFieldValue(Calendar instance, Integer fieldFlag, Object value) {
|
||||
try {
|
||||
Method setMethod = instance.getClass().getMethod("set", int.class, int.class);
|
||||
setMethod.invoke(instance, fieldFlag, value);
|
||||
} catch (Exception e) {
|
||||
DEException.throwException(e);
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isTimeWidget(String serviceName) {
|
||||
if (StringUtils.isBlank(serviceName)) return false;
|
||||
String[] timeWidgets = {"timeDateWidget", "timeDateRangeWidget"};
|
||||
return Arrays.stream(timeWidgets).anyMatch(widget -> StringUtils.equals(widget, serviceName));
|
||||
}
|
||||
|
||||
public Boolean showTime(Map<String, Object> component) {
|
||||
Map attrs = (Map) ((Map) component.get("options")).get("attrs");
|
||||
if (ObjectUtils.isNotEmpty(attrs.get("showTime"))) {
|
||||
return (boolean) attrs.get("showTime");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String componentType(Map<String, Object> component) {
|
||||
Map attrs = (Map) ((Map) component.get("options")).get("attrs");
|
||||
String result = ObjectUtils.isEmpty(attrs.get("type")) ? "date" : attrs.get("type").toString();
|
||||
String serviceName = component.get("serviceName").toString();
|
||||
if (isTimeWidget(serviceName) && showTime(component)) {
|
||||
result = StringUtils.equals("timeDateWidget", serviceName) ? "datetime" : "datetimerange";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public String labelFormat(Map<String, Object> component) {
|
||||
String result = "yyyy-MM-dd";
|
||||
Map attrs = (Map) ((Map) component.get("options")).get("attrs");
|
||||
String serviceName = component.get("serviceName").toString();
|
||||
if (isTimeWidget(serviceName) && showTime(component) && ObjectUtils.isNotEmpty(attrs.get("accuracy"))) {
|
||||
return result + " " + attrs.get("accuracy");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List add2List(Object... elements) {
|
||||
return Arrays.stream(elements).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public abstract List<Long> dynamicDateFromNow(Map<String, Object> component);
|
||||
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package io.dataease.service.chart.build;
|
||||
|
||||
import io.dataease.dto.chart.FilterParamTO;
|
||||
import io.dataease.service.chart.FilterBuildTemplate;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class TimeYearBuild extends FilterBuildTemplate {
|
||||
@Override
|
||||
protected FilterParamTO buildParam(Map<String, Object> component) {
|
||||
List<String> realVals = null;
|
||||
Object valueObj = null;
|
||||
String defaultValue = "";
|
||||
Map<String, Object> options = (Map<String, Object>) component.get("options");
|
||||
Map<String, Object> attrs = (Map<String, Object>) options.get("attrs");
|
||||
Object aDefault = attrs.get("default");
|
||||
Boolean isDynamic = (Boolean) attrs.getOrDefault("isDynamic", false);
|
||||
if (ObjectUtils.isNotEmpty(aDefault) && isDynamic) {
|
||||
Long aLong = dynamicDateFormNow(component);
|
||||
realVals = new ArrayList<>();
|
||||
realVals.add(aLong.toString());
|
||||
}else {
|
||||
if(!ObjectUtils.isEmpty(valueObj)) {
|
||||
if(valueObj instanceof List) {
|
||||
defaultValue = "";
|
||||
}else {
|
||||
defaultValue = valueObj.toString();
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(defaultValue)) {
|
||||
realVals = new ArrayList<>();
|
||||
}else {
|
||||
realVals = Arrays.asList(defaultValue.split(",")).stream().limit(1).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Long dynamicDateFormNow(Map<String, Object> component) {
|
||||
Map<String, Object> attrs = (Map<String, Object>) ((Map<String, Object>) component.get("options")).get("attrs");
|
||||
Object aDefault = attrs.get("default");
|
||||
Boolean isDynamic = (Boolean) attrs.getOrDefault("isDynamic", false);
|
||||
if (ObjectUtils.isEmpty(aDefault) || !isDynamic) return null;
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
int nowYear = now.get(Calendar.YEAR);
|
||||
Map<String, Object> aDefaultMap = (Map<String, Object>) aDefault;
|
||||
if (Integer.parseInt(aDefaultMap.get("dkey").toString()) == 0){
|
||||
now.set(nowYear, 0, 1, 0, 0, 0);
|
||||
return now.getTimeInMillis();
|
||||
}
|
||||
if (Integer.parseInt(aDefaultMap.get("dkey").toString()) == 1){
|
||||
now.set(nowYear - 1, 0, 1, 0, 0, 0);
|
||||
return now.getTimeInMillis();
|
||||
}
|
||||
if (Integer.parseInt(aDefaultMap.get("dkey").toString()) == 2){
|
||||
int dynamicPrefix = Integer.parseInt(aDefaultMap.get("dynamicPrefix").toString());
|
||||
String dynamicSuffix = aDefaultMap.get("dynamicSuffix").toString();
|
||||
now.set(StringUtils.equals("before", dynamicSuffix) ? (nowYear - dynamicPrefix) : (nowYear + dynamicPrefix), 0, 1, 0, 0, 0);
|
||||
return now.getTimeInMillis();
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package io.dataease.service.chart.build.time;
|
||||
|
||||
import io.dataease.service.chart.build.TimeBuild;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("timeDateWidget")
|
||||
public class TimeDateBuild extends TimeBuild {
|
||||
public List<Long> dynamicDateFromNow(Map<String, Object> component) {
|
||||
Map<String, Object> attrs = buildAttrs(component);
|
||||
Object defaultObject = attrs.get("default");
|
||||
|
||||
Boolean isDynamic = false;
|
||||
Map<String, Object> defaultMap = null;
|
||||
if (ObjectUtils.isNotEmpty(defaultObject)) {
|
||||
defaultMap = (Map<String, Object>) defaultObject;
|
||||
isDynamic = (Boolean) defaultMap.getOrDefault("isDynamic", false);
|
||||
}
|
||||
if (ObjectUtils.isEmpty(defaultObject) || !isDynamic) return null;
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
int nowYear = now.get(Calendar.YEAR);
|
||||
int nowMonth = now.get(Calendar.MONTH);
|
||||
int nowDate = now.get(Calendar.DATE);
|
||||
int dkey = (int) Double.parseDouble(defaultMap.get("dkey").toString());
|
||||
if (dkey == 0) {
|
||||
now.set(nowYear, nowMonth, nowDate, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 1) {
|
||||
now.set(nowYear, nowMonth, nowDate - 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
|
||||
if (dkey == 2) {
|
||||
now.set(nowYear, nowMonth, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
|
||||
if (dkey == 4) {
|
||||
now.set(nowYear, 0, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
|
||||
if (dkey == 3) {
|
||||
int dynamicPrefix = (int) Double.parseDouble(defaultMap.get("dynamicPrefix").toString());
|
||||
String dynamicInfill = defaultMap.get("dynamicInfill").toString();
|
||||
String dynamicSuffix = defaultMap.get("dynamicSuffix").toString();
|
||||
now.set(nowYear, nowMonth, nowDate, 0, 0, 0);
|
||||
if (StringUtils.equals("day", dynamicInfill)) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1);
|
||||
now.roll(Calendar.DATE, step);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (StringUtils.equals("week", dynamicInfill)) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1) * 7;
|
||||
now.roll(Calendar.DATE, step);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (StringUtils.equals("month", dynamicInfill)) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1);
|
||||
now.roll(Calendar.MONTH, step);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (StringUtils.equals("year", dynamicInfill)) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1);
|
||||
now.roll(Calendar.YEAR, step);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package io.dataease.service.chart.build.time;
|
||||
|
||||
import io.dataease.service.chart.build.TimeBuild;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("timeDateRangeWidget")
|
||||
public class TimeDateRangeBuild extends TimeBuild {
|
||||
@Override
|
||||
public List<Long> dynamicDateFromNow(Map<String, Object> component) {
|
||||
|
||||
Map<String, Object> attrs = buildAttrs(component);
|
||||
Object defaultObject = null;
|
||||
if ((defaultObject = attrs.get("default")) == null) return null;
|
||||
Map<String, Object> defaultMap = (Map<String, Object>) defaultObject;
|
||||
|
||||
Boolean isDynamic = (Boolean) defaultMap.getOrDefault("isDynamic", false);
|
||||
if (!isDynamic) return null;
|
||||
|
||||
int dkey = (int) Double.parseDouble(defaultMap.get("dkey").toString());
|
||||
Calendar now = Calendar.getInstance();
|
||||
now.set(Calendar.HOUR_OF_DAY, 0);
|
||||
now.set(Calendar.MINUTE, 0);
|
||||
now.set(Calendar.SECOND, 0);
|
||||
now.set(Calendar.MILLISECOND, 0);
|
||||
if (dkey % 5 == 0) {
|
||||
if (dkey == 5) {
|
||||
now.add(Calendar.DATE, -7);
|
||||
}
|
||||
now.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
|
||||
long start = now.getTimeInMillis();
|
||||
now.add(Calendar.DATE, 7);
|
||||
now.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
|
||||
long end = now.getTimeInMillis();
|
||||
return add2List(start, end);
|
||||
}
|
||||
|
||||
if (dkey == 1) {
|
||||
Calendar endBase = (Calendar) now.clone();
|
||||
now.set(Calendar.DAY_OF_MONTH, 1);
|
||||
long start = now.getTimeInMillis();
|
||||
endBase.add(Calendar.MONTH, 1);
|
||||
endBase.set(Calendar.DAY_OF_MONTH, 0);
|
||||
long end = endBase.getTimeInMillis();
|
||||
return add2List(start, end);
|
||||
}
|
||||
if (dkey == 6) {
|
||||
Calendar endBase = (Calendar) now.clone();
|
||||
now.add(Calendar.MONTH, -1);
|
||||
now.set(Calendar.DAY_OF_MONTH, 1);
|
||||
long start = now.getTimeInMillis();
|
||||
endBase.set(Calendar.DAY_OF_MONTH, 0);
|
||||
long end = endBase.getTimeInMillis();
|
||||
return add2List(start, end);
|
||||
}
|
||||
|
||||
if (dkey % 5 == 2) {
|
||||
int step = 0;
|
||||
if (dkey == 7) {
|
||||
step = -1;
|
||||
}
|
||||
Calendar endBase = (Calendar) now.clone();
|
||||
Long start = quarterBegin(now, step);
|
||||
Long end = quarterEnd(endBase, step);
|
||||
return add2List(start, end);
|
||||
}
|
||||
|
||||
if (dkey == 3) {
|
||||
now.set(Calendar.MONTH, 0);
|
||||
now.set(Calendar.DAY_OF_MONTH, 1);
|
||||
long start = now.getTimeInMillis();
|
||||
now.add(Calendar.YEAR, 1);
|
||||
now.add(Calendar.DAY_OF_MONTH, -1);
|
||||
long end = now.getTimeInMillis();
|
||||
return add2List(start, end);
|
||||
}
|
||||
if (dkey == 8) {
|
||||
now.add(Calendar.YEAR, -1);
|
||||
now.set(Calendar.MONTH, 0);
|
||||
now.set(Calendar.DAY_OF_MONTH, 1);
|
||||
long start = now.getTimeInMillis();
|
||||
now.add(Calendar.YEAR, 1);
|
||||
now.add(Calendar.DAY_OF_MONTH, -1);
|
||||
long end = now.getTimeInMillis();
|
||||
return add2List(start, end);
|
||||
}
|
||||
|
||||
if (dkey == 4) {
|
||||
Object startDynamicObject = defaultMap.get("sDynamicPrefix");
|
||||
Object endDynamicObject = defaultMap.get("eDynamicPrefix");
|
||||
if (ObjectUtils.isNotEmpty(startDynamicObject) && ObjectUtils.isNotEmpty(endDynamicObject)) {
|
||||
String startDynamicInfill = defaultMap.get("sDynamicInfill").toString();
|
||||
String endDynamicInfill = defaultMap.get("eDynamicInfill").toString();
|
||||
String startDynamicSuffix = defaultMap.get("sDynamicSuffix").toString();
|
||||
String endDynamicSuffix = defaultMap.get("eDynamicSuffix").toString();
|
||||
int startDynamic = (int) Double.parseDouble(startDynamicObject.toString());
|
||||
int endDynamic = (int) Double.parseDouble(endDynamicObject.toString());
|
||||
Calendar endBase = (Calendar) now.clone();
|
||||
Long start = customTime(now, startDynamic, startDynamicInfill, startDynamicSuffix);
|
||||
Long end = customTime(endBase, endDynamic, endDynamicInfill, endDynamicSuffix);
|
||||
return add2List(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private Long customTime(Calendar now, int dynamicPrefix, String dynamicInfill, String dynamicSuffix) {
|
||||
if (StringUtils.equals(dynamicInfill, "day")) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1);
|
||||
now.add(Calendar.DAY_OF_MONTH, step);
|
||||
}
|
||||
if (StringUtils.equals(dynamicInfill, "week")) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1) * 7;
|
||||
now.add(Calendar.DAY_OF_MONTH, step);
|
||||
}
|
||||
if (StringUtils.equals(dynamicInfill, "month")) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1);
|
||||
now.add(Calendar.MONTH, step);
|
||||
}
|
||||
if (StringUtils.equals("year", dynamicInfill)) {
|
||||
int step = dynamicPrefix * (StringUtils.equals("before", dynamicSuffix) ? -1 : 1);
|
||||
now.add(Calendar.YEAR, step);
|
||||
}
|
||||
return now.getTimeInMillis();
|
||||
}
|
||||
|
||||
private Long quarterBegin(Calendar instance, int step) {
|
||||
int month = instance.get(Calendar.MONTH);
|
||||
int quarterBegin = (int) Math.floor(month / 3) * 3;
|
||||
instance.set(Calendar.MONTH, quarterBegin + (3 * step));
|
||||
instance.set(Calendar.DAY_OF_MONTH, 1);
|
||||
return instance.getTimeInMillis();
|
||||
}
|
||||
|
||||
private Long quarterEnd(Calendar instance, int step) {
|
||||
int month = instance.get(Calendar.MONTH);
|
||||
int quarterBegin = (int) Math.floor(month / 3) * 3;
|
||||
instance.set(Calendar.MONTH, quarterBegin + (3 * (step + 1)));
|
||||
instance.set(Calendar.DAY_OF_MONTH, 1);
|
||||
instance.add(Calendar.DATE, -1);
|
||||
return instance.getTimeInMillis();
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package io.dataease.service.chart.build.time;
|
||||
|
||||
import io.dataease.service.chart.build.TimeBuild;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("timeMonthWidget")
|
||||
public class TimeMonthBuild extends TimeBuild {
|
||||
@Override
|
||||
public List<Long> dynamicDateFromNow(Map<String, Object> component) {
|
||||
Map<String, Object> attrs = buildAttrs(component);
|
||||
|
||||
Object defaultObject = attrs.get("default");
|
||||
|
||||
if (ObjectUtils.isEmpty(defaultObject)) return null;
|
||||
Map<String, Object> defaultMap = (Map<String, Object>) defaultObject;
|
||||
|
||||
Boolean isDynamic = (Boolean) defaultMap.getOrDefault("isDynamic", false);
|
||||
if (!isDynamic) return null;
|
||||
Calendar now = Calendar.getInstance();
|
||||
int nowYear = now.get(Calendar.YEAR);
|
||||
int nowMonth = now.get(Calendar.MONTH);
|
||||
|
||||
int dkey = (int) Double.parseDouble(defaultMap.get("dkey").toString());
|
||||
if (dkey == 0) {
|
||||
now.set(nowYear, nowMonth, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 1) {
|
||||
now.set(nowYear, nowMonth - 1, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 2) {
|
||||
now.set(nowYear, 0, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 4) {
|
||||
now.set(nowYear - 1, nowMonth, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 3) {
|
||||
int dynamicPrefix = (int) Double.parseDouble(defaultMap.get("dynamicPrefix").toString());
|
||||
String dynamicSuffix = defaultMap.get("dynamicSuffix").toString();
|
||||
int targetMonth = StringUtils.equals("before", dynamicSuffix) ? (nowMonth - dynamicPrefix) : (nowMonth + dynamicPrefix);
|
||||
now.set(nowYear, targetMonth, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package io.dataease.service.chart.build.time;
|
||||
|
||||
import io.dataease.service.chart.build.TimeBuild;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("timeYearWidget")
|
||||
public class TimeYearBuild extends TimeBuild {
|
||||
@Override
|
||||
public List<Long> dynamicDateFromNow(Map<String, Object> component) {
|
||||
|
||||
Boolean isDynamic = false;
|
||||
Map<String, Object> defaultMap = null;
|
||||
Map<String, Object> attrs = buildAttrs(component);
|
||||
Object defaultObject = attrs.get("default");
|
||||
if (ObjectUtils.isNotEmpty(defaultObject)) {
|
||||
defaultMap = (Map<String, Object>) defaultObject;
|
||||
isDynamic = (Boolean) defaultMap.getOrDefault("isDynamic", false);
|
||||
}
|
||||
if (ObjectUtils.isEmpty(defaultObject) || !isDynamic) return null;
|
||||
|
||||
Calendar now = Calendar.getInstance();
|
||||
int nowYear = now.get(Calendar.YEAR);
|
||||
int dkey = (int) Double.parseDouble(defaultMap.get("dkey").toString());
|
||||
if (dkey == 0) {
|
||||
now.set(nowYear, 0, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 1) {
|
||||
now.set(nowYear - 1, 0, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
if (dkey == 2) {
|
||||
int dynamicPrefix = (int) Double.parseDouble(defaultMap.get("dynamicPrefix").toString());
|
||||
String dynamicSuffix = defaultMap.get("dynamicSuffix").toString();
|
||||
now.set(StringUtils.equals("before", dynamicSuffix) ? (nowYear - dynamicPrefix) : (nowYear + dynamicPrefix), 0, 1, 0, 0, 0);
|
||||
return add2List(now.getTimeInMillis());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user