1. 指标子集映射
This commit is contained in:
parent
1cae057f4b
commit
ef50951bb3
|
|
@ -76,8 +76,11 @@ public class AssistantEvaluationProjectController extends BaseController {
|
||||||
if (levelList.isEmpty()) {
|
if (levelList.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
levelList.sort((a, b) -> Integer.compare(Integer.parseInt(b.getGrade()), Integer.parseInt(a.getGrade())));
|
||||||
|
|
||||||
rootResult.setLevelName(levelList.get(levelList.size() - 1).getLevelName());
|
rootResult.setLevelName(levelList.get(levelList.size() - 1).getLevelName());
|
||||||
for (IndicatorTopLevel indicatorTopLevel : levelList) {
|
for (IndicatorTopLevel indicatorTopLevel : levelList) {
|
||||||
|
|
||||||
if (Double.parseDouble(rootResult.getFinalScore()) >= Double.parseDouble(
|
if (Double.parseDouble(rootResult.getFinalScore()) >= Double.parseDouble(
|
||||||
indicatorTopLevel.getGrade())) {
|
indicatorTopLevel.getGrade())) {
|
||||||
rootResult.setLevelName(indicatorTopLevel.getLevelName());
|
rootResult.setLevelName(indicatorTopLevel.getLevelName());
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,14 @@ import com.hshh.model.entity.FormValue;
|
||||||
import com.hshh.model.service.FormFieldConfigService;
|
import com.hshh.model.service.FormFieldConfigService;
|
||||||
import com.hshh.model.service.FormValueService;
|
import com.hshh.model.service.FormValueService;
|
||||||
import com.hshh.system.annotation.LogOperation;
|
import com.hshh.system.annotation.LogOperation;
|
||||||
import com.hshh.system.base.entity.TableRelations;
|
|
||||||
import com.hshh.system.base.service.TableRelationsService;
|
|
||||||
import com.hshh.system.common.bean.OperateResult;
|
import com.hshh.system.common.bean.OperateResult;
|
||||||
import com.hshh.system.common.bean.PaginationBean;
|
import com.hshh.system.common.bean.PaginationBean;
|
||||||
import com.hshh.system.common.enums.ErrorCode;
|
import com.hshh.system.common.enums.ErrorCode;
|
||||||
import com.hshh.system.common.enums.ErrorMessage;
|
import com.hshh.system.common.enums.ErrorMessage;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -75,7 +75,6 @@ public class EvaluationProjectController extends AssistantEvaluationProjectContr
|
||||||
private EvaluationTemplateService evaluationTemplateService;
|
private EvaluationTemplateService evaluationTemplateService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 基础设施服务类.
|
* 基础设施服务类.
|
||||||
*/
|
*/
|
||||||
|
|
@ -453,8 +452,10 @@ public class EvaluationProjectController extends AssistantEvaluationProjectContr
|
||||||
if (membershipMap.get(level.getLevelName()) != null) {
|
if (membershipMap.get(level.getLevelName()) != null) {
|
||||||
replaceMemberShipBuilder.append(level.getLevelName()).append(":")
|
replaceMemberShipBuilder.append(level.getLevelName()).append(":")
|
||||||
.append(membershipMap.get(level.getLevelName())).append(";");
|
.append(membershipMap.get(level.getLevelName())).append(";");
|
||||||
level.setActualValue(
|
;
|
||||||
Double.parseDouble(level.getGrade()) * membershipMap.get(level.getLevelName()));
|
level.setActualValue(new BigDecimal(level.getGrade()).multiply(
|
||||||
|
new BigDecimal(membershipMap.get(level.getLevelName()))).setScale(1,
|
||||||
|
RoundingMode.HALF_UP).doubleValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//按照优先级重新覆盖隶属函数对应的值
|
//按照优先级重新覆盖隶属函数对应的值
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.sql.DataSource;
|
||||||
import org.mybatis.spring.SqlSessionTemplate;
|
import org.mybatis.spring.SqlSessionTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -44,7 +45,7 @@ public class IndicatorServiceImpl extends ServiceImpl<IndicatorMapper, Indicator
|
||||||
IndicatorService {
|
IndicatorService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SqlSessionTemplate sqlSessionTemplate;
|
private DataSource dataSource;
|
||||||
@Resource
|
@Resource
|
||||||
private IndicatorCsvService csvService;
|
private IndicatorCsvService csvService;
|
||||||
@Resource
|
@Resource
|
||||||
|
|
@ -231,16 +232,13 @@ public class IndicatorServiceImpl extends ServiceImpl<IndicatorMapper, Indicator
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
|
||||||
public void deleteIndicator(Integer id) throws SQLException {
|
public void deleteIndicator(Integer id) throws SQLException {
|
||||||
Indicator indicator = getRecursionIndicator(id);
|
Indicator indicator = getRecursionIndicator(id);
|
||||||
Set<Integer> idList = new HashSet<>();
|
Set<Integer> idList = new HashSet<>();
|
||||||
fillIndicatorList(idList, indicator);
|
fillIndicatorList(idList, indicator);
|
||||||
|
|
||||||
Connection connection = sqlSessionTemplate.getConnection();
|
|
||||||
List<String> sqlList = new ArrayList<>();
|
List<String> sqlList = new ArrayList<>();
|
||||||
for (int i = 1; i < idList.size(); i++) {
|
|
||||||
|
|
||||||
}
|
|
||||||
idList.forEach(indicatorId -> {
|
idList.forEach(indicatorId -> {
|
||||||
if (!Objects.equals(indicatorId, id)) {
|
if (!Objects.equals(indicatorId, id)) {
|
||||||
addSql(sqlList, indicatorId);
|
addSql(sqlList, indicatorId);
|
||||||
|
|
@ -248,16 +246,19 @@ public class IndicatorServiceImpl extends ServiceImpl<IndicatorMapper, Indicator
|
||||||
});
|
});
|
||||||
addSql(sqlList, id);
|
addSql(sqlList, id);
|
||||||
|
|
||||||
try (Statement ste = connection.createStatement()) {
|
// 用try-with-resources,事务依然有效
|
||||||
|
try (Connection connection = dataSource.getConnection();
|
||||||
|
Statement statement = connection.createStatement()) {
|
||||||
for (String sql : sqlList) {
|
for (String sql : sqlList) {
|
||||||
ste.addBatch(sql);
|
statement.addBatch(sql);
|
||||||
}
|
}
|
||||||
ste.executeBatch();
|
statement.executeBatch();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw e; // 触发 Spring 事务自动回滚
|
throw e; // 触发Spring事务自动回滚
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addSql(List<String> sqlList, Integer id) {
|
private void addSql(List<String> sqlList, Integer id) {
|
||||||
sqlList.add(
|
sqlList.add(
|
||||||
"delete from m_data_evaluation_indicator_result where indicator_id = " + id);
|
"delete from m_data_evaluation_indicator_result where indicator_id = " + id);
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.hshh.model.entity.FormFieldConfig;
|
import com.hshh.model.entity.FormFieldConfig;
|
||||||
import com.hshh.model.mapper.FormFieldConfigMapper;
|
import com.hshh.model.mapper.FormFieldConfigMapper;
|
||||||
import com.hshh.model.service.FormFieldConfigService;
|
import com.hshh.model.service.FormFieldConfigService;
|
||||||
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -41,8 +41,17 @@ public class FormFieldConfigServiceImpl extends
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getHeaderMap(Integer modelId) {
|
public Map<String, String> getHeaderMap(Integer modelId) {
|
||||||
Map<String, String> headerMap = new HashMap<>();
|
Map<String, String> headerMap = new LinkedHashMap<>();
|
||||||
List<FormFieldConfig> list = getFormFieldConfigByModelId(modelId);
|
List<FormFieldConfig> list = getFormFieldConfigByModelId(modelId);
|
||||||
|
list.sort((a, b) -> {
|
||||||
|
if (a.getSortOrder() == null) {
|
||||||
|
a.setSortOrder(999);
|
||||||
|
}
|
||||||
|
if (b.getSortOrder() == null) {
|
||||||
|
b.setSortOrder(999);
|
||||||
|
}
|
||||||
|
return a.getSortOrder().compareTo(b.getSortOrder());
|
||||||
|
});
|
||||||
list.forEach(formFieldConfig -> {
|
list.forEach(formFieldConfig -> {
|
||||||
headerMap.put(formFieldConfig.getFieldName(), formFieldConfig.getFieldLabel());
|
headerMap.put(formFieldConfig.getFieldName(), formFieldConfig.getFieldLabel());
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -13,14 +13,14 @@ spring:
|
||||||
thymeleaf:
|
thymeleaf:
|
||||||
cache: false
|
cache: false
|
||||||
datasource:
|
datasource:
|
||||||
# url: jdbc:dm://192.168.0.53:5236/MANAGER
|
url: jdbc:dm://127.0.0.1:5236/MANAGER
|
||||||
# username: sysdba
|
username: SYSDBA
|
||||||
# password: Admin123
|
password: SYSDBA001
|
||||||
# driver-class-name: dm.jdbc.driver.DmDriver
|
driver-class-name: dm.jdbc.driver.DmDriver
|
||||||
url: jdbc:mysql://localhost:3306/manager?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
|
# url: jdbc:mysql://localhost:3306/manager?allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
|
||||||
username: root
|
# username: root
|
||||||
password: 123456
|
# password: 123456
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
# driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
hikari:
|
hikari:
|
||||||
minimum-idle: 5
|
minimum-idle: 5
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
|
|
|
||||||
|
|
@ -63,10 +63,13 @@ public class LeafFullTriangularMembershipFunction implements MembershipFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNumber(value.toString())) {
|
if (isNumber(value.toString())) {
|
||||||
|
|
||||||
|
double width = widthMiddle(gradeRanges);
|
||||||
|
|
||||||
for (int i = 0; i < gradeRanges.size(); i++) {
|
for (int i = 0; i < gradeRanges.size(); i++) {
|
||||||
GradeRange range = gradeRanges.get(i);
|
GradeRange range = gradeRanges.get(i);
|
||||||
|
|
||||||
double degree = calculateTriangle(Double.parseDouble(value.toString()) , range, i);
|
double degree = calculateTriangle(Double.parseDouble(value.toString()), range, i, width);
|
||||||
degree = Math.max(0.0, Math.min(1.0, degree));
|
degree = Math.max(0.0, Math.min(1.0, degree));
|
||||||
membership.put(range.getGradeName(), degree);
|
membership.put(range.getGradeName(), degree);
|
||||||
|
|
||||||
|
|
@ -99,7 +102,7 @@ public class LeafFullTriangularMembershipFunction implements MembershipFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修正:三角形计算函数
|
// 修正:三角形计算函数
|
||||||
private double calculateTriangle(double value, GradeRange range, int index) {
|
private double calculateTriangle(double value, GradeRange range, int index, double width) {
|
||||||
double lowerBound = range.getLowerBound();
|
double lowerBound = range.getLowerBound();
|
||||||
double upperBound = range.getUpperBound();
|
double upperBound = range.getUpperBound();
|
||||||
|
|
||||||
|
|
@ -107,31 +110,18 @@ public class LeafFullTriangularMembershipFunction implements MembershipFunction
|
||||||
double peakPoint;
|
double peakPoint;
|
||||||
if (index == gradeRanges.size() - 1) { // 最高等级(优)
|
if (index == gradeRanges.size() - 1) { // 最高等级(优)
|
||||||
peakPoint = upperBound;
|
peakPoint = upperBound;
|
||||||
System.out.println(" 最高等级,峰值设在上边界: " + peakPoint);
|
|
||||||
} else {
|
} else {
|
||||||
peakPoint = lowerBound + (upperBound - lowerBound) * peakRatio;
|
peakPoint = lowerBound + (upperBound - lowerBound) * peakRatio;
|
||||||
System.out.println(" 峰值点: " + peakPoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double rangeWidth = upperBound - lowerBound;
|
double overlap = width * overlapRatio;
|
||||||
double overlap = rangeWidth * overlapRatio;
|
double leftBoundary = lowerBound - overlap;
|
||||||
double leftBoundary = lowerBound - overlap / 2;
|
double rightBoundary = upperBound + overlap;
|
||||||
double rightBoundary = upperBound + overlap / 2;
|
|
||||||
|
|
||||||
// 修正:对于边界等级的特殊处理
|
|
||||||
if (index == 0) {
|
|
||||||
// 第一个等级,左边界延伸
|
|
||||||
leftBoundary = Math.min(leftBoundary, lowerBound - rangeWidth);
|
|
||||||
System.out.println(" 第一个等级,左边界大幅延伸: " + leftBoundary);
|
|
||||||
}
|
|
||||||
if (index == gradeRanges.size() - 1) {
|
|
||||||
// 最后一个等级,右边界大幅延伸
|
|
||||||
rightBoundary = Math.max(rightBoundary, upperBound + rangeWidth * 2);
|
|
||||||
System.out.println(" 最后一个等级,右边界大幅延伸: " + rightBoundary);
|
|
||||||
}
|
|
||||||
|
|
||||||
double result;
|
double result;
|
||||||
if (value <= leftBoundary || value >= rightBoundary) {
|
if (value <= leftBoundary || value > rightBoundary) {
|
||||||
|
|
||||||
result = 0.0;
|
result = 0.0;
|
||||||
} else if (Math.abs(value - peakPoint) < 0.0001) { // 处理浮点数比较
|
} else if (Math.abs(value - peakPoint) < 0.0001) { // 处理浮点数比较
|
||||||
|
|
|
||||||
|
|
@ -153,7 +153,7 @@ public class LeafHybridMembershipFunction implements MembershipFunction {
|
||||||
|
|
||||||
double result;
|
double result;
|
||||||
if (value <= leftExtend) {
|
if (value <= leftExtend) {
|
||||||
System.out.println(" 判断: value <= leftExtend → 返回 0.0");
|
|
||||||
result = 0.0;
|
result = 0.0;
|
||||||
} else if (value <= plateauStart) {
|
} else if (value <= plateauStart) {
|
||||||
double slope = 1.0 / (plateauStart - leftExtend);
|
double slope = 1.0 / (plateauStart - leftExtend);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.hshh.system.algorithm.fuzzy;
|
package com.hshh.system.algorithm.fuzzy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -20,4 +22,14 @@ public interface MembershipFunction {
|
||||||
default boolean isNumber(String str) {
|
default boolean isNumber(String str) {
|
||||||
return str != null && str.matches("^\\d+(\\.\\d+)?$");
|
return str != null && str.matches("^\\d+(\\.\\d+)?$");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default double widthMiddle(List<GradeRange> gradeRanges) {
|
||||||
|
|
||||||
|
List<Double> middleList = new ArrayList<>();
|
||||||
|
for (GradeRange gradeRange : gradeRanges) {
|
||||||
|
middleList.add(gradeRange.getUpperBound() - gradeRange.getLowerBound());
|
||||||
|
}
|
||||||
|
middleList.sort(Double::compareTo);
|
||||||
|
return middleList.get(middleList.size() / 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user