Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
A
annual-performance-indicators
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
王威威
annual-performance-indicators
Commits
fba162d5
提交
fba162d5
authored
7月 09, 2021
作者:
黄承天
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[指标]加分项相关修改
上级
76908ec7
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
47 行增加
和
115 行删除
+47
-115
IndexInfo.java
src/main/java/com/tykj/index/entity/IndexInfo.java
+5
-2
IndexInfoVo.java
src/main/java/com/tykj/index/entity/vo/IndexInfoVo.java
+3
-3
Pluses.java
src/main/java/com/tykj/index/entity/vo/Pluses.java
+19
-0
IndexInfoService.java
src/main/java/com/tykj/index/service/IndexInfoService.java
+20
-110
没有找到文件。
src/main/java/com/tykj/index/entity/IndexInfo.java
浏览文件 @
fba162d5
...
...
@@ -4,12 +4,14 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import
com.tykj.base.entity.BaseEntity
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.NoArgsConstructor
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Table
;
@EqualsAndHashCode
(
callSuper
=
true
)
@AllArgsConstructor
@NoArgsConstructor
@Data
...
...
@@ -27,11 +29,12 @@ public class IndexInfo extends BaseEntity {
private
Integer
level
;
private
Double
weight
;
@Column
(
columnDefinition
=
"text"
)
private
String
ranks
;
@Column
(
columnDefinition
=
"test"
)
private
String
pluses
;
private
Integer
parentId
;
@JsonIgnore
...
...
src/main/java/com/tykj/index/entity/vo/IndexInfoVo.java
浏览文件 @
fba162d5
...
...
@@ -30,12 +30,12 @@ public class IndexInfoVo {
@ApiModelProperty
(
"层级"
)
private
Integer
level
;
@ApiModelProperty
(
"权重"
)
private
Double
weight
;
@ApiModelProperty
(
"范围"
)
private
List
<
Rank
>
ranks
;
@ApiModelProperty
(
"加分项"
)
private
List
<
Pluses
>
pluses
;
@ApiModelProperty
(
"下级子节点"
)
private
List
<
IndexInfoVo
>
children
;
...
...
src/main/java/com/tykj/index/entity/vo/Pluses.java
0 → 100644
浏览文件 @
fba162d5
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
;
}
src/main/java/com/tykj/index/service/IndexInfoService.java
浏览文件 @
fba162d5
...
...
@@ -20,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Service
;
import
java.math.BigDecimal
;
import
java.sql.SQLException
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoField
;
...
...
@@ -56,17 +55,6 @@ public class IndexInfoService {
if
(
isNull
(
indexInfoVo
.
getAlias
()))
{
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
();
//保存信息
...
...
@@ -74,7 +62,6 @@ public class IndexInfoService {
indexInfoRepository
.
save
(
indexInfo
);
//将sql语句查出来的数据插入到指标对应的表
handleData
(
indexInfo
.
getAlias
(),
indexInfo
.
getSqlContent
());
updateDataValue
(
indexInfo
);
}
public
void
update
(
IndexInfoVo
indexInfoVo
)
{
...
...
@@ -82,18 +69,6 @@ public class IndexInfoService {
if
(
isNull
(
indexInfoVo
.
getId
()))
{
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
())
.
map
(
IndexInfo:
:
getTableId
)
...
...
@@ -104,16 +79,6 @@ public class IndexInfoService {
indexInfoRepository
.
save
(
indexInfo
);
//将sql语句查出来的数据插入到指标对应的表
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 {
.
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 {
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
//根据时间划分
List
<
String
>
times
=
MonthUtil
.
getMountListEndNow
(
"2021-01"
);
List
<
Rank
>
ranks
=
indexInfoVo
.
getRanks
();
...
...
@@ -363,60 +318,17 @@ public class IndexInfoService {
}
}
/**
* 根据权重同步计算并更新数据值
*/
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
{
data
=
modelService
.
findAllByName
(
indexInfo
.
getAlias
());
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
if
(
nonNull
(
parent
.
getAlias
()))
{
modelService
.
deleteAllBytableName
(
parent
.
getAlias
());
for
(
Map
<
String
,
Object
>
datum
:
data
)
{
//根据上级数据去匹配下级数据来计算
double
newValue
=
0
D
;
for
(
IndexInfo
child
:
children
)
{
private
IndexInfo
indexInfo
(
IndexInfoVo
indexInfoVo
,
Integer
tableId
)
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
String
ranks
=
"[]"
;
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
(
0
D
);
newValue
+=
childValue
;
}
catch
(
SQLException
e
)
{
ranks
=
objectMapper
.
writeValueAsString
(
indexInfoVo
.
getRanks
());
}
catch
(
JsonProcessingException
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
=
"[]"
;
String
pluses
=
"[]"
;
try
{
ranks
=
new
ObjectMapper
().
writeValueAsString
(
indexInfoVo
.
getRank
s
());
pluses
=
objectMapper
.
writeValueAsString
(
indexInfoVo
.
getPluse
s
());
}
catch
(
JsonProcessingException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -426,17 +338,25 @@ public class IndexInfoService {
indexInfoVo
.
getDescription
(),
indexInfoVo
.
getSql
(),
indexInfoVo
.
getLevel
(),
indexInfoVo
.
getWeight
(),
ranks
,
pluses
,
indexInfoVo
.
getParentId
(),
tableId
);
}
private
IndexInfoVo
indexInfoVo
(
IndexInfo
indexInfo
)
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
List
<
Rank
>
ranks
=
new
ArrayList
<>();
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
)
{
e
.
printStackTrace
();
...
...
@@ -451,8 +371,8 @@ public class IndexInfoService {
indexInfo
.
getDescription
(),
indexInfo
.
getSqlContent
(),
indexInfo
.
getLevel
(),
indexInfo
.
getWeight
(),
ranks
,
pluses
,
children
,
indexInfo
.
getParentId
()
);
...
...
@@ -461,17 +381,6 @@ public class IndexInfoService {
private
TableVO
createTableVo
(
String
name
)
{
ArrayList
<
ColumnVO
>
columns
=
Lists
.
newArrayList
(
new
ColumnVO
(
null
,
1
,
"java.lang.String"
,
"area"
,
Strings
.
EMPTY
,
255
,
new
Rule
(),
Strings
.
EMPTY
,
new
ArrayList
<>()
),
new
ColumnVO
(
null
,
1
,
...
...
@@ -557,3 +466,4 @@ public class IndexInfoService {
.
orElse
(
new
Rank
(
Strings
.
EMPTY
,
null
,
null
,
"#FFFFFF"
));
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论