#4 -- Read rule string #20
@ -8,16 +8,29 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.ulstu.fc.rule.model.FuzzyRuleForm;
|
||||
import ru.ulstu.fc.rule.model.FuzzyTerm;
|
||||
import ru.ulstu.fc.rule.model.Variable;
|
||||
import ru.ulstu.fc.rule.service.FuzzyRuleService;
|
||||
import ru.ulstu.fc.rule.service.FuzzyTermService;
|
||||
import ru.ulstu.fc.rule.service.VariableService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("rule")
|
||||
public class FuzzyRuleController {
|
||||
private final FuzzyRuleService ruleService;
|
||||
private final FuzzyRuleService fuzzyRuleService;
|
||||
private final VariableService variableService;
|
||||
private final FuzzyTermService fuzzyTermService;
|
||||
|
||||
public FuzzyRuleController(FuzzyRuleService ruleService) {
|
||||
this.ruleService = ruleService;
|
||||
public FuzzyRuleController(FuzzyRuleService fuzzyRuleService,
|
||||
VariableService variableService,
|
||||
FuzzyTermService fuzzyTermService) {
|
||||
this.fuzzyRuleService = fuzzyRuleService;
|
||||
this.variableService = variableService;
|
||||
this.fuzzyTermService = fuzzyTermService;
|
||||
}
|
||||
|
||||
@GetMapping("/edit/{projectId}/{ruleId}")
|
||||
@ -26,7 +39,7 @@ public class FuzzyRuleController {
|
||||
model.addAttribute("projectId", projectId);
|
||||
model.addAttribute("fuzzyRuleForm",
|
||||
(id != null && id != 0)
|
||||
? new FuzzyRuleForm(id, ruleService.getById(id))
|
||||
? new FuzzyRuleForm(id, fuzzyRuleService.getById(id))
|
||||
: new FuzzyRuleForm(id, projectId));
|
||||
return "rule/edit";
|
||||
}
|
||||
@ -37,15 +50,27 @@ public class FuzzyRuleController {
|
||||
model.addAttribute("projectId", fuzzyRuleForm.getProjectId());
|
||||
return "rule/edit";
|
||||
}
|
||||
ruleService.save(fuzzyRuleForm);
|
||||
fuzzyRuleService.save(fuzzyRuleForm);
|
||||
return "redirect:/project/edit/" + fuzzyRuleForm.getProjectId();
|
||||
}
|
||||
|
||||
@PostMapping(value = "save", params = "delete")
|
||||
public String delete(FuzzyRuleForm fuzzyRuleForm) {
|
||||
if (fuzzyRuleForm != null && fuzzyRuleForm.getId() != null) {
|
||||
ruleService.delete(fuzzyRuleForm);
|
||||
fuzzyRuleService.delete(fuzzyRuleForm);
|
||||
}
|
||||
return "redirect:/project/edit/" + fuzzyRuleForm.getProjectId();
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/getVariables/{projectId}")
|
||||
public List<Variable> getVariables(@PathVariable("projectId") Integer projectId) {
|
||||
return variableService.getAllByProject(projectId);
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping("/getFuzzyTerms/{variableId}")
|
||||
public List<FuzzyTerm> getTerms(@PathVariable("variableId") Integer variableId) {
|
||||
return fuzzyTermService.getByVariableId(variableId);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user