#2 -- Add inference dtos #22

Merged
romanov73 merged 7 commits from 2-execute-rules into master 2025-03-03 22:28:52 +04:00
10 changed files with 82 additions and 56 deletions
Showing only changes of commit 7339ca4062 - Show all commits

View File

@ -46,8 +46,7 @@ dependencies {
implementation group: 'org.webjars', name: 'jquery', version: '3.6.0' implementation group: 'org.webjars', name: 'jquery', version: '3.6.0'
implementation group: 'org.webjars', name: 'bootstrap', version: '4.6.0' implementation group: 'org.webjars', name: 'bootstrap', version: '4.6.0'
implementation group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8' implementation group: 'org.webjars', name: 'bootstrap-select', version: '1.13.8'
implementation group: 'org.webjars', name: 'font-awesome', version: '4.7.0' implementation 'org.webjars.npm:bootstrap-icons:1.11.3'
implementation group: 'org.webjars', name: 'highcharts', version: '7.0.0'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test' implementation group: 'org.springframework.boot', name: 'spring-boot-starter-test'
} }

View File

@ -24,4 +24,18 @@ public class ProjectVariableService {
} }
return variableRepository.findByProject(projectService.getById(projectId)); return variableRepository.findByProject(projectService.getById(projectId));
} }
public List<Variable> getInputByProjectId(Integer projectId) {
if (projectId == null || projectId == 0) {
return Collections.emptyList();
}
return variableRepository.findInputByProject(projectService.getById(projectId));
}
public List<Variable> getOutputByProjectId(Integer projectId) {
if (projectId == null || projectId == 0) {
return Collections.emptyList();
}
return variableRepository.findOutputByProject(projectService.getById(projectId));
}
} }

View File

@ -7,22 +7,34 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import ru.ulstu.fc.project.service.ProjectRulesService;
import ru.ulstu.fc.rule.model.FuzzyRule; import ru.ulstu.fc.rule.model.FuzzyRule;
import ru.ulstu.fc.rule.model.FuzzyRuleForm; import ru.ulstu.fc.rule.model.FuzzyRuleForm;
import ru.ulstu.fc.rule.service.FuzzyRuleService; import ru.ulstu.fc.rule.service.FuzzyRuleService;
import java.util.List;
@RestController @RestController
@RequestMapping("fuzzyRuleRest") @RequestMapping("fuzzyRuleRest")
public class FuzzyRuleRestController { public class FuzzyRuleRestController {
private final FuzzyRuleService ruleService; private final FuzzyRuleService ruleService;
private final ProjectRulesService projectRulesService;
public FuzzyRuleRestController(FuzzyRuleService ruleService) { public FuzzyRuleRestController(FuzzyRuleService ruleService,
ProjectRulesService projectRulesService) {
this.ruleService = ruleService; this.ruleService = ruleService;
this.projectRulesService = projectRulesService;
} }
@GetMapping("/get/{projectId}/{ruleId}") @GetMapping("/getAll/{projectId}")
public FuzzyRule get(@PathVariable(value = "projectId") Integer projectId, public List<FuzzyRule> getAll(@PathVariable(value = "projectId") Integer projectId) {
@PathVariable(value = "ruleId") Integer id) { //TODO: return dto
return projectRulesService.getByProjectId(projectId);
}
@GetMapping("/get/{ruleId}")
public FuzzyRule get(@PathVariable(value = "ruleId") Integer id) {
//TODO: return dto
return ruleService.getById(id); return ruleService.getById(id);
} }

View File

@ -8,6 +8,7 @@ import java.util.List;
public class VariableDto { public class VariableDto {
private Integer id; private Integer id;
private String name; private String name;
private boolean input;
private List<FuzzyTermDto> terms = new ArrayList<>(); private List<FuzzyTermDto> terms = new ArrayList<>();
public VariableDto() { public VariableDto() {
@ -17,6 +18,7 @@ public class VariableDto {
this.id = variable.getId(); this.id = variable.getId();
this.name = variable.getName(); this.name = variable.getName();
this.terms = variable.getFuzzyTerms().stream().map(FuzzyTermDto::new).toList(); this.terms = variable.getFuzzyTerms().stream().map(FuzzyTermDto::new).toList();
this.input = variable.isInput();
} }
public String getName() { public String getName() {
@ -42,4 +44,12 @@ public class VariableDto {
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
public boolean isInput() {
return input;
}
public void setInput(boolean input) {
this.input = input;
}
} }

View File

@ -1,6 +1,8 @@
package ru.ulstu.fc.rule.repository; package ru.ulstu.fc.rule.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ru.ulstu.fc.project.model.Project; import ru.ulstu.fc.project.model.Project;
import ru.ulstu.fc.rule.model.Variable; import ru.ulstu.fc.rule.model.Variable;
@ -11,4 +13,10 @@ public interface VariableRepository extends JpaRepository<Variable, Integer> {
List<Variable> findByProject(Project project); List<Variable> findByProject(Project project);
List<Variable> getByProject(Project project); List<Variable> getByProject(Project project);
@Query("SELECT v FROM Variable v WHERE v.project = :project AND v.input = true")
List<Variable> findInputByProject(@Param("project") Project project);
@Query("SELECT v FROM Variable v WHERE v.project = :project AND v.input = false")
List<Variable> findOutputByProject(@Param("project") Project project);
} }

View File

@ -11,7 +11,8 @@
<script type="text/javascript" src="/webjars/bootstrap-select/1.13.8/js/bootstrap-select.min.js"></script> <script type="text/javascript" src="/webjars/bootstrap-select/1.13.8/js/bootstrap-select.min.js"></script>
<link rel="stylesheet" href="/webjars/bootstrap/4.6.0/css/bootstrap.min.css"/> <link rel="stylesheet" href="/webjars/bootstrap/4.6.0/css/bootstrap.min.css"/>
<link rel="stylesheet" href="/webjars/bootstrap-select/1.13.8/css/bootstrap-select.min.css"/> <link rel="stylesheet" href="/webjars/bootstrap-select/1.13.8/css/bootstrap-select.min.css"/>
<link rel="stylesheet" href="/webjars/font-awesome/4.7.0/css/font-awesome.min.css"/> <link rel="stylesheet" href="/webjars/bootstrap-icons/1.11.3/font/bootstrap-icons.min.css"/>
</head> </head>
<body> <body>

View File

@ -35,7 +35,13 @@
<div class="row" th:each="v, iter : ${variables}"> <div class="row" th:each="v, iter : ${variables}">
<div class="col col-md-12"> <div class="col col-md-12">
<a th:href="@{'/variable/edit/' + ${projectId}+'/'+${v.id}}"> <a th:href="@{'/variable/edit/' + ${projectId}+'/'+${v.id}}">
<span class="badge badge-light" th:text="${iter.index+1} + '. ' + ${v.name}"></span> <h3>
<span class="badge badge-light">
<span th:text="${iter.index+1} + '. ' + ${v.name}"></span>
<i th:if="${v.input}" class="bi bi-box-arrow-in-right"></i>
<i th:if="! ${v.input}" class="bi bi-box-arrow-right"></i>
</span>
</h3>
</a> </a>
</div> </div>
</div> </div>
@ -48,7 +54,7 @@
<div class="row" th:each="r, iter : ${rules}"> <div class="row" th:each="r, iter : ${rules}">
<div class="col col-md-12"> <div class="col col-md-12">
<a th:href="@{'/rule/edit/' + ${projectId}+'/'+${r.id}}"> <a th:href="@{'/rule/edit/' + ${projectId}+'/'+${r.id}}">
<div class="rule row" th:text="${r.content}"></div> <div class="rule row d-none" th:text="${r.content}"></div>
</a> </a>
</div> </div>
</div> </div>
@ -70,9 +76,9 @@
} else { } else {
ruleHtml += "<div class='col col-md-1'></div>"; ruleHtml += "<div class='col col-md-1'></div>";
} }
ruleHtml += "<div class='col col-md-4'><span class='badge badge-primary'>"+getVariable(a)+"</span></div>"; ruleHtml += "<div class='col col-md-4'><span class='badge badge-primary'>" + getVariable(a) + "</span></div>";
ruleHtml += "<div class='col col-md-3'><span class='badge badge-light'>есть</span></div>"; ruleHtml += "<div class='col col-md-3'><span class='badge badge-light'>есть</span></div>";
ruleHtml += "<div class='col col-md-4'><span class='badge badge-success'>"+getVariableValue(a)+"</span></div>"; ruleHtml += "<div class='col col-md-4'><span class='badge badge-success'>" + getVariableValue(a) + "</span></div>";
} }
ruleHtml += "<div class='col col-md-12'><span class='badge badge-light'>То</span></div>" ruleHtml += "<div class='col col-md-12'><span class='badge badge-light'>То</span></div>"
for (let i = 0; i < consequentComponents.length; i++) { for (let i = 0; i < consequentComponents.length; i++) {
@ -87,11 +93,12 @@
ruleHtml += "<div class='col col-md-4'><span class='badge badge-success'>" + getVariableValue(c) + "</span></div>"; ruleHtml += "<div class='col col-md-4'><span class='badge badge-success'>" + getVariableValue(c) + "</span></div>";
} }
$(el).html(ruleHtml); $(el).html(ruleHtml);
$(el).removeClass('d-none');
} }
$('.rule').each(function(index) {
$('.rule').each(function (index) {
addRule(index, $(this), $(this).text()); addRule(index, $(this), $(this).text());
}); });
</script> </script>
</div> </div>

View File

@ -7,16 +7,19 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head> </head>
<div class="container" layout:fragment="content"> <div class="container" layout:fragment="content">
<div class="form-group">
<a href="/project/edit/0" class="btn btn-outline-dark"> <a href="/project/edit/0" class="btn btn-outline-dark">
<i class="fa fa-plus-square" aria-hidden="true">Добавить проект</i> <i class="bi bi-plus-square" aria-hidden="true"></i> Добавить проект
</a> </a>
</div>
<ul> <div th:each="p : ${projects}">
<li th:each="p : ${projects}">
<a th:href="@{'/project/edit/' + ${p.id}}"> <a th:href="@{'/project/edit/' + ${p.id}}">
<span th:text="${p.name} + ' от ' + ${#dates.format(p.createDate, 'dd.MM.yyyy HH:mm')}"></span> <h3>
<span class="badge badge-light"
th:text="${p.name} + ' от ' + ${#dates.format(p.createDate, 'dd.MM.yyyy HH:mm')}">
</span>
</h3>
</a> </a>
</li> </div>
</ul>
</div> </div>
</html> </html>

View File

@ -1,30 +0,0 @@
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{default}">
<head>
<title>Список правил</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<div class="container" layout:fragment="content">
<h3> Список правил</h3>
<div class="rowд">
<div class="col col-md-12">
<span class="badge badge-light">1. Если</span>
</div>
<div class="col col-md-3">
<span class="badge badge-primary">Переменная</span>
</div>
<div class="col col-md-3">
<span class="badge badge-light">есть</span>
</div>
<div class="col col-md-3">
<span class="badge badge-success">значение</span>
</div>
<div class="col col-md-3">
<span class="badge badge-danger">И / ИЛИ</span>
</div>
</div>
</div>
</html>

View File

@ -39,8 +39,10 @@
<div class="row" th:each="t, iter : ${fuzzyTerms}"> <div class="row" th:each="t, iter : ${fuzzyTerms}">
<div class="col col-md-12"> <div class="col col-md-12">
<a th:href="@{'/fuzzyTerm/edit/' + ${projectId} + '/' + ${variableId}+'/'+${t.id}}"> <a th:href="@{'/fuzzyTerm/edit/' + ${projectId} + '/' + ${variableId}+'/'+${t.id}}">
<h3>
<span class="badge badge-light" <span class="badge badge-light"
th:text="${iter.index+1} + '. ' + ${t.description}"></span> th:text="${iter.index+1} + '. ' + ${t.description}"></span>
</h3>
</a> </a>
</div> </div>
</div> </div>