Commit 2b10bafe authored by duanruiming's avatar duanruiming

Merge remote-tracking branch 'origin/master'

parents 39ac121a 170f2203
...@@ -11,7 +11,10 @@ import net.wanji.common.enums.TurnConvertEnum; ...@@ -11,7 +11,10 @@ import net.wanji.common.enums.TurnConvertEnum;
import net.wanji.common.utils.tool.CrossUtil; import net.wanji.common.utils.tool.CrossUtil;
import net.wanji.common.utils.tool.TimeArrayUtil; import net.wanji.common.utils.tool.TimeArrayUtil;
import net.wanji.databus.bo.CrossIdBO; import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.dao.entity.*; import net.wanji.databus.dao.entity.BaseCrossSchedulesPO;
import net.wanji.databus.dao.entity.BaseCrossSchedulesPlanPO;
import net.wanji.databus.dao.entity.BaseCrossSchemePO;
import net.wanji.databus.dao.entity.CrossSectionPO;
import net.wanji.databus.dao.mapper.*; import net.wanji.databus.dao.mapper.*;
import net.wanji.databus.po.*; import net.wanji.databus.po.*;
import net.wanji.opt.bo.CrossSchemeListBO; import net.wanji.opt.bo.CrossSchemeListBO;
...@@ -33,6 +36,8 @@ import org.springframework.beans.factory.annotation.Qualifier; ...@@ -33,6 +36,8 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
...@@ -396,14 +401,18 @@ public class SchemeEvaluateServiceImpl implements SchemeEvaluateService { ...@@ -396,14 +401,18 @@ public class SchemeEvaluateServiceImpl implements SchemeEvaluateService {
declaredField.setAccessible(true); declaredField.setAccessible(true);
if (CollectionUtil.isNotEmpty(poList)) { if (CollectionUtil.isNotEmpty(poList)) {
int metricSum = 0; double metricSum = 0;
for (CrossDirDataHistPOExt crossDirDataHistPOExt : poList) { for (CrossDirDataHistPOExt crossDirDataHistPOExt : poList) {
Integer intValue = getDirInteger(crossDirDataHistPOExt, declaredField); Double doubleValue = getDirDouble(crossDirDataHistPOExt, declaredField);
metricSum += intValue; metricSum += doubleValue;
} }
int size = poList.size(); int size = poList.size();
vo.setMetricValue(metricSum / size); double v = metricSum / size;
BigDecimal bd = new BigDecimal(v);
bd = bd.setScale(2, RoundingMode.HALF_UP);
double roundedValue = bd.doubleValue();
vo.setMetricValue(roundedValue);
} }
res.add(vo); res.add(vo);
} }
...@@ -446,14 +455,18 @@ public class SchemeEvaluateServiceImpl implements SchemeEvaluateService { ...@@ -446,14 +455,18 @@ public class SchemeEvaluateServiceImpl implements SchemeEvaluateService {
declaredField.setAccessible(true); declaredField.setAccessible(true);
if (CollectionUtil.isNotEmpty(poList)) { if (CollectionUtil.isNotEmpty(poList)) {
int metricSum = 0; double metricSum = 0;
for (CrossTurnDataHistPOExt crossTurnDataHistPOExt : poList) { for (CrossTurnDataHistPOExt crossTurnDataHistPOExt : poList) {
Integer intValue = getTurnInteger(crossTurnDataHistPOExt, declaredField); Double doubleValue = getTurnDouble(crossTurnDataHistPOExt, declaredField);
metricSum += intValue; metricSum += doubleValue;
} }
int size = poList.size(); int size = poList.size();
vo.setMetricValue(metricSum / size); double v = metricSum / size;
BigDecimal bd = new BigDecimal(v);
bd = bd.setScale(2, RoundingMode.HALF_UP);
double roundedValue = bd.doubleValue();
vo.setMetricValue(roundedValue);
} }
res.add(vo); res.add(vo);
} }
...@@ -473,34 +486,34 @@ public class SchemeEvaluateServiceImpl implements SchemeEvaluateService { ...@@ -473,34 +486,34 @@ public class SchemeEvaluateServiceImpl implements SchemeEvaluateService {
SPECIAL_METRICS.add(StrategyAndMetricsEnum.Metrics.CLEAR_RATE.getField()); SPECIAL_METRICS.add(StrategyAndMetricsEnum.Metrics.CLEAR_RATE.getField());
} }
private Integer getIntegerFromObject(Object object, Field declaredField) throws IllegalAccessException { private Double getDoubleFromObject(Object object, Field declaredField) throws IllegalAccessException {
Object objValue = declaredField.get(object); Object objValue = declaredField.get(object);
if (ObjectUtil.isEmpty(objValue)) { if (ObjectUtil.isEmpty(objValue)) {
objValue = 0; objValue = 0;
} }
String fieldName = declaredField.getName(); String fieldName = declaredField.getName();
if (SPECIAL_METRICS.contains(fieldName) && objValue instanceof Double) { if (SPECIAL_METRICS.contains(fieldName) && objValue instanceof Double) {
objValue = (int) Math.round((Double) objValue * 100); objValue = (double) Math.round((Double) objValue * 100);
} }
if (objValue instanceof Integer) { if (objValue instanceof Integer) {
return (Integer) objValue; return (double) objValue;
} else if (objValue instanceof Double) { } else if (objValue instanceof Double) {
return (int) Math.round((Double) objValue); BigDecimal bd = BigDecimal.valueOf((double) objValue);
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.doubleValue();
} else { } else {
throw new IllegalArgumentException("字段值不是 int 或 double"); throw new IllegalArgumentException("字段值不是 int 或 double");
} }
} }
@NotNull private Double getTurnDouble(CrossTurnDataHistPOExt crossTurnDataHistPO, Field declaredField)
private Integer getTurnInteger(CrossTurnDataHistPOExt crossTurnDataHistPO, Field declaredField)
throws IllegalAccessException { throws IllegalAccessException {
return getIntegerFromObject(crossTurnDataHistPO, declaredField); return getDoubleFromObject(crossTurnDataHistPO, declaredField);
} }
@NotNull private Double getDirDouble(CrossDirDataHistPOExt crossDirDataHistPO, Field declaredField)
private Integer getDirInteger(CrossDirDataHistPOExt crossDirDataHistPO, Field declaredField)
throws IllegalAccessException { throws IllegalAccessException {
return getIntegerFromObject(crossDirDataHistPO, declaredField); return getDoubleFromObject(crossDirDataHistPO, declaredField);
} }
private void buildSecurityDetailVO(List<CrossDirDataHistPO> crossDirDataHistPOList, private void buildSecurityDetailVO(List<CrossDirDataHistPO> crossDirDataHistPOList,
......
...@@ -23,5 +23,5 @@ public class SchemeEvaluateCurveChartVO { ...@@ -23,5 +23,5 @@ public class SchemeEvaluateCurveChartVO {
private String metricTime; private String metricTime;
@ApiModelProperty(value = "指标数值") @ApiModelProperty(value = "指标数值")
private Integer metricValue; private Double metricValue;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment