JSD-6602 热力图
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

198 lines
5.7 KiB

package com.fr.plugin.third.party.jsdggac;
import com.fanruan.api.util.StringKit;
import com.fr.general.GeneralUtils;
import com.fr.plugin.third.party.jsdggac.data.CustomGanttColumnFieldCollection;
import java.awt.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
public class CustomGanttDataFactory {
public static synchronized List<String> createProjectNames(CustomGanttColumnFieldCollection dataSource) {
List<String> projectList = new ArrayList<>();
if (dataSource == null) {
return projectList;
}
//List<Object> projectNames = dataSource.getProjectName().getValues();
List<Object> projectNames = null;
int size = projectNames.size();
if (size <= 0) {
return projectList;
}
String tempValue;
Object tempObj;
for (int i = 0, max = size - 1; i <= max; i++) {
tempObj = projectNames.get(i);
if (tempObj == null) {
tempValue = "";
addNotRepeatingObj(tempValue, projectList);
continue;
}
tempValue = GeneralUtils.objectToString(tempObj);
addNotRepeatingObj(tempValue, projectList);
}
Collections.reverse(projectList);
return projectList;
}
/**
* 针对echarts的bug处理,若系列名称有数字,有中文,会默认按数字处理,有中文会显示NaN,故在前面加中文处理
*
* @param name
* @return
*/
private static String createSeriesName(String name) {
String tempName = name;
if (StringKit.isEmpty(name)) {
tempName = "";
}
return "甘特图" + tempName;
}
private static synchronized String objectToString(Object obj) {
String tempValue = GeneralUtils.objectToString(obj);
return tempValue;
}
private static ThreadLocal<SimpleDateFormat> threadLocalFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd");
}
};
private static ThreadLocal<SimpleDateFormat> threadLocalFormat1 = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
}
};
/**
* 转为时间戳
*
* @param obj
* @return
*/
private static synchronized long objectToTimestamp(Object obj) {
if (obj == null) {
return 0;
}
Date tempDate = null;
if (obj instanceof Date) {
tempDate = (Date) obj;
return tempDate.getTime();
}
String tempValue = GeneralUtils.objectToString(obj);
if (StringKit.isEmpty(tempValue)) {
return 0;
}
int length = tempValue.length();
try {
if (length == 10) {
tempDate = threadLocalFormat.get().parse(tempValue);
} else if (length == 19) {
tempDate = threadLocalFormat1.get().parse(tempValue);
}
} catch (Exception e) {
return 0;
}
if (tempDate != null) {
return tempDate.getTime();
}
return 0;
}
/**
* 转为0-1的四位小数
*
* @param obj
* @return
*/
private static synchronized double objectToRate(Object obj) {
if (obj == null) {
return 0;
}
double tempValue = 0;
if (obj instanceof Double) {
tempValue = (Double) obj;
} else {
String tempContent = objectToString(obj);
if (StringKit.isEmpty(tempContent)) {
return 0;
}
tempContent = tempContent.trim();
if (StringKit.isEmpty(tempContent)) {
return 0;
}
tempValue = Double.valueOf(tempContent);
}
if (tempValue <= 0) {
return 0;
}
if (tempValue >= 1) {
return 1;
}
BigDecimal bigDecimal = new BigDecimal(String.valueOf(tempValue));
tempValue = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
return tempValue;
}
private static synchronized String objectToRateShow(double value) {
BigDecimal bigDecimal = new BigDecimal(String.valueOf(value));
BigDecimal bigDecimal1 = new BigDecimal("100");
String tempValue = bigDecimal.multiply(bigDecimal1).doubleValue() + "%";
return tempValue;
}
private static synchronized void addNotRepeatingObj(String value, List<String> values) {
String tempValue = value;
if (StringKit.isEmpty(tempValue)) {
tempValue = "";
}
if (values.contains(tempValue)) {
return;
}
values.add(tempValue);
}
private static synchronized int getIndex(String value, List<String> values) {
int index = values.indexOf(value);
return index;
}
public static String rgbToHex(Color color) {
if (color == null) {
return "#000000";
}
String value = "#" + String.format("%02X", color.getRed()) + String.format("%02X", color.getGreen()) + String.format("%02X", color.getBlue());
return value;
}
public static Color colorToGray(Color color) {
if (color == null) {
return new Color(0);
}
int gray = (int) ((color.getRed() * 30 + color.getGreen() * 59 + color.getBlue() * 11 + 50) * 0.01);
return new Color(gray);
}
}