提交 fba162d5 authored 作者: 黄承天's avatar 黄承天

[指标]加分项相关修改

上级 76908ec7
...@@ -4,12 +4,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore; ...@@ -4,12 +4,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.tykj.base.entity.BaseEntity; import com.tykj.base.entity.BaseEntity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Data @Data
...@@ -27,11 +29,12 @@ public class IndexInfo extends BaseEntity { ...@@ -27,11 +29,12 @@ public class IndexInfo extends BaseEntity {
private Integer level; private Integer level;
private Double weight;
@Column(columnDefinition = "text") @Column(columnDefinition = "text")
private String ranks; private String ranks;
@Column(columnDefinition = "test")
private String pluses;
private Integer parentId; private Integer parentId;
@JsonIgnore @JsonIgnore
......
...@@ -30,12 +30,12 @@ public class IndexInfoVo { ...@@ -30,12 +30,12 @@ public class IndexInfoVo {
@ApiModelProperty("层级") @ApiModelProperty("层级")
private Integer level; private Integer level;
@ApiModelProperty("权重")
private Double weight;
@ApiModelProperty("范围") @ApiModelProperty("范围")
private List<Rank> ranks; private List<Rank> ranks;
@ApiModelProperty("加分项")
private List<Pluses> pluses;
@ApiModelProperty("下级子节点") @ApiModelProperty("下级子节点")
private List<IndexInfoVo> children; private List<IndexInfoVo> children;
......
package com.tykj.index.entity.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Pluses {
private String name;
private Double score;
private Integer tableId;
}
...@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.sql.SQLException; import java.sql.SQLException;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField; import java.time.temporal.ChronoField;
...@@ -56,17 +55,6 @@ public class IndexInfoService { ...@@ -56,17 +55,6 @@ public class IndexInfoService {
if (isNull(indexInfoVo.getAlias())) { if (isNull(indexInfoVo.getAlias())) {
throw new RuntimeException("别名不能为空"); throw new RuntimeException("别名不能为空");
} }
if (nonNull(indexInfoVo.getParentId())) {
Double weight = indexInfoVo.getWeight();
//查出其他同parentId指标的权重合
List<IndexInfo> indexInfos = indexInfoRepository.findAllByParentId(indexInfoVo.getParentId());
double sum = indexInfos.stream()
.mapToDouble(IndexInfo::getWeight)
.sum();
if (weight == null || weight < 0 || sum + weight > 1) {
throw new RuntimeException("权重值非法");
}
}
//新增时建立模型实体 //新增时建立模型实体
Integer tableId = modelService.newTable(createTableVo(indexInfoVo.getAlias())).getId(); Integer tableId = modelService.newTable(createTableVo(indexInfoVo.getAlias())).getId();
//保存信息 //保存信息
...@@ -74,7 +62,6 @@ public class IndexInfoService { ...@@ -74,7 +62,6 @@ public class IndexInfoService {
indexInfoRepository.save(indexInfo); indexInfoRepository.save(indexInfo);
//将sql语句查出来的数据插入到指标对应的表 //将sql语句查出来的数据插入到指标对应的表
handleData(indexInfo.getAlias(), indexInfo.getSqlContent()); handleData(indexInfo.getAlias(), indexInfo.getSqlContent());
updateDataValue(indexInfo);
} }
public void update(IndexInfoVo indexInfoVo) { public void update(IndexInfoVo indexInfoVo) {
...@@ -82,18 +69,6 @@ public class IndexInfoService { ...@@ -82,18 +69,6 @@ public class IndexInfoService {
if (isNull(indexInfoVo.getId())) { if (isNull(indexInfoVo.getId())) {
throw new RuntimeException("修改操作必须附带id"); throw new RuntimeException("修改操作必须附带id");
} }
if (nonNull(indexInfoVo.getParentId())) {
Double weight = indexInfoVo.getWeight();
//查出其他同parentId指标的权重合
List<IndexInfo> indexInfos = indexInfoRepository.findAllByParentId(indexInfoVo.getParentId());
double sum = indexInfos.stream()
.filter(indexInfo -> !Objects.equals(indexInfo.getId(), indexInfoVo.getId()))
.mapToDouble(IndexInfo::getWeight)
.sum();
if (weight == null || weight < 0 || sum + weight > 1) {
throw new RuntimeException("权重值非法");
}
}
//重新对应已建立的模型实体 //重新对应已建立的模型实体
Integer tableId = indexInfoRepository.findById(indexInfoVo.getId()) Integer tableId = indexInfoRepository.findById(indexInfoVo.getId())
.map(IndexInfo::getTableId) .map(IndexInfo::getTableId)
...@@ -104,16 +79,6 @@ public class IndexInfoService { ...@@ -104,16 +79,6 @@ public class IndexInfoService {
indexInfoRepository.save(indexInfo); indexInfoRepository.save(indexInfo);
//将sql语句查出来的数据插入到指标对应的表 //将sql语句查出来的数据插入到指标对应的表
handleData(indexInfo.getAlias(), indexInfo.getSqlContent()); handleData(indexInfo.getAlias(), indexInfo.getSqlContent());
updateDataValue(indexInfo);
}
/**
* 根据id更新其上级节点数据的值
*/
public void updateValue(Integer id) {
IndexInfo indexInfo = indexInfoRepository.findById(id)
.orElseThrow(() -> new RuntimeException("id为[" + id + "]的数据不存在"));
updateDataValue(indexInfo);
} }
/** /**
...@@ -128,17 +93,6 @@ public class IndexInfoService { ...@@ -128,17 +93,6 @@ public class IndexInfoService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* 根据parentId查询剩余可用的权重值
*/
public Double checkRemainWeight(Integer parentId) {
double sum = indexInfoRepository.findAllByParentId(parentId).stream()
.mapToDouble(IndexInfo::getWeight)
.sum();
BigDecimal result = BigDecimal.valueOf(1).add(BigDecimal.valueOf(sum).negate());
return result.doubleValue();
}
/** /**
* 查询图表数据 * 查询图表数据
*/ */
...@@ -162,6 +116,7 @@ public class IndexInfoService { ...@@ -162,6 +116,7 @@ public class IndexInfoService {
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
//根据时间划分 //根据时间划分
List<String> times = MonthUtil.getMountListEndNow("2021-01"); List<String> times = MonthUtil.getMountListEndNow("2021-01");
List<Rank> ranks = indexInfoVo.getRanks(); List<Rank> ranks = indexInfoVo.getRanks();
...@@ -363,60 +318,17 @@ public class IndexInfoService { ...@@ -363,60 +318,17 @@ public class IndexInfoService {
} }
} }
/** private IndexInfo indexInfo(IndexInfoVo indexInfoVo, Integer tableId) {
* 根据权重同步计算并更新数据值 ObjectMapper objectMapper = new ObjectMapper();
*/ String ranks = "[]";
private void updateDataValue(IndexInfo indexInfo) {
IndexInfo parent = indexInfoRepository.findById(indexInfo.getParentId())
.orElseThrow(() -> new RuntimeException("id为[" + indexInfo.getParentId() + "]的上级数据不存在"));
//其他子节点
List<IndexInfo> children = indexInfoRepository.findAllByParentId(indexInfo.getParentId()).stream()
.filter(indexInfo1 -> !Objects.equals(indexInfo1.getId(), indexInfo.getId()))
.collect(Collectors.toList());
List<Map<String, Object>> data = new ArrayList<>();
try { try {
data = modelService.findAllByName(indexInfo.getAlias()); ranks = objectMapper.writeValueAsString(indexInfoVo.getRanks());
} catch (SQLException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
} }
if (nonNull(parent.getAlias())) { String pluses = "[]";
modelService.deleteAllBytableName(parent.getAlias());
for (Map<String, Object> datum : data) {
//根据上级数据去匹配下级数据来计算
double newValue = 0D;
for (IndexInfo child : children) {
try {
double childValue = modelService.findAllByName(child.getAlias()).stream()
.filter(entity -> Objects.equals(entity.get("area"), datum.get("area")) && Objects.equals(entity.get("time"), datum.get("time")))
.filter(entity -> nonNull(entity.get("value")))
.findAny()
.map(entity -> (double) entity.get("value"))
.map(value -> value * child.getWeight())
.orElse(0D);
newValue += childValue;
} catch (SQLException e) {
e.printStackTrace();
}
}
double selfValue = (double) datum.get("value");
newValue += (selfValue * indexInfo.getWeight());
datum.put("value", newValue);
datum.remove("id");
//更新重新计算后的数据
Map<String, Object> map = new HashMap<>();
map.put(parent.getAlias(), datum);
modelService.operationValueByEntityName(map, (SessionImpl) sessionUtil.getSession(), null, null);
}
}
if (nonNull(parent.getParentId())) {
updateDataValue(parent);
}
}
private IndexInfo indexInfo(IndexInfoVo indexInfoVo, Integer tableId) {
String ranks = "[]";
try { try {
ranks = new ObjectMapper().writeValueAsString(indexInfoVo.getRanks()); pluses = objectMapper.writeValueAsString(indexInfoVo.getPluses());
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -426,17 +338,25 @@ public class IndexInfoService { ...@@ -426,17 +338,25 @@ public class IndexInfoService {
indexInfoVo.getDescription(), indexInfoVo.getDescription(),
indexInfoVo.getSql(), indexInfoVo.getSql(),
indexInfoVo.getLevel(), indexInfoVo.getLevel(),
indexInfoVo.getWeight(),
ranks, ranks,
pluses,
indexInfoVo.getParentId(), indexInfoVo.getParentId(),
tableId tableId
); );
} }
private IndexInfoVo indexInfoVo(IndexInfo indexInfo) { private IndexInfoVo indexInfoVo(IndexInfo indexInfo) {
ObjectMapper objectMapper = new ObjectMapper();
List<Rank> ranks = new ArrayList<>(); List<Rank> ranks = new ArrayList<>();
try { try {
ranks = new ObjectMapper().readValue(indexInfo.getRanks(), new TypeReference<List<Rank>>() { ranks = objectMapper.readValue(indexInfo.getRanks(), new TypeReference<List<Rank>>() {
});
} catch (JsonProcessingException e) {
e.printStackTrace();
}
List<Pluses> pluses = new ArrayList<>();
try {
pluses = objectMapper.readValue(indexInfo.getPluses(), new TypeReference<List<Pluses>>() {
}); });
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -451,8 +371,8 @@ public class IndexInfoService { ...@@ -451,8 +371,8 @@ public class IndexInfoService {
indexInfo.getDescription(), indexInfo.getDescription(),
indexInfo.getSqlContent(), indexInfo.getSqlContent(),
indexInfo.getLevel(), indexInfo.getLevel(),
indexInfo.getWeight(),
ranks, ranks,
pluses,
children, children,
indexInfo.getParentId() indexInfo.getParentId()
); );
...@@ -461,17 +381,6 @@ public class IndexInfoService { ...@@ -461,17 +381,6 @@ public class IndexInfoService {
private TableVO createTableVo(String name) { private TableVO createTableVo(String name) {
ArrayList<ColumnVO> columns = Lists.newArrayList( ArrayList<ColumnVO> columns = Lists.newArrayList(
new ColumnVO(
null,
1,
"java.lang.String",
"area",
Strings.EMPTY,
255,
new Rule(),
Strings.EMPTY,
new ArrayList<>()
),
new ColumnVO( new ColumnVO(
null, null,
1, 1,
...@@ -557,3 +466,4 @@ public class IndexInfoService { ...@@ -557,3 +466,4 @@ public class IndexInfoService {
.orElse(new Rank(Strings.EMPTY, null, null, "#FFFFFF")); .orElse(new Rank(Strings.EMPTY, null, null, "#FFFFFF"));
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论