|
@@ -3,10 +3,11 @@ package com.yaoxiang.diagnosis.controller;
|
|
|
|
|
|
import com.yaoxiang.diagnosis.dao.RemarkTemplateRepo;
|
|
|
import com.yaoxiang.diagnosis.entity.RemarkTemplate;
|
|
|
+import com.yaoxiang.diagnosis.model.Result;
|
|
|
import io.swagger.annotations.Api;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.List;
|
|
@@ -20,7 +21,56 @@ public class RemarkTemplateController {
|
|
|
private RemarkTemplateRepo remarkTemplateRepo;
|
|
|
|
|
|
@GetMapping("/list")
|
|
|
- public List<RemarkTemplate> list() {
|
|
|
- return remarkTemplateRepo.findAll();
|
|
|
+ public List<RemarkTemplate> list(@RequestParam(required = false) String name) {
|
|
|
+ if(StringUtils.isBlank(name)){
|
|
|
+ return remarkTemplateRepo.findAll();
|
|
|
+ }
|
|
|
+ RemarkTemplate template = new RemarkTemplate();
|
|
|
+ template.setName(name);
|
|
|
+ return remarkTemplateRepo.findAll(Example.of(template));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("add")
|
|
|
+ public Result add(String name, String remark, Long subjectId) {
|
|
|
+ if (checkName(name)) {
|
|
|
+ return Result.fail("该模板已存在");
|
|
|
+ }
|
|
|
+ RemarkTemplate template = new RemarkTemplate();
|
|
|
+ template.setName(name);
|
|
|
+ template.setRemark(remark);
|
|
|
+ template.setSubjectId(subjectId);
|
|
|
+ remarkTemplateRepo.save(template);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("exists")
|
|
|
+ public Result exists(String name) {
|
|
|
+ return Result.ok(checkName(name));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("update")
|
|
|
+ public Result update(Long id, String name, String remark, Long subjectId) {
|
|
|
+ RemarkTemplate template = remarkTemplateRepo.findById(id).orElse(null);
|
|
|
+ if (template == null) {
|
|
|
+ return Result.fail("未找到模板");
|
|
|
+ }
|
|
|
+ template.setName(name);
|
|
|
+ template.setRemark(remark);
|
|
|
+ template.setSubjectId(subjectId);
|
|
|
+ remarkTemplateRepo.save(template);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("delete")
|
|
|
+ public Result delete(Long id) {
|
|
|
+ remarkTemplateRepo.deleteById(id);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkName(String name) {
|
|
|
+ RemarkTemplate template = new RemarkTemplate();
|
|
|
+ template.setName(name);
|
|
|
+ Example<RemarkTemplate> example = Example.of(template);
|
|
|
+ return remarkTemplateRepo.findOne(example).isPresent();
|
|
|
}
|
|
|
}
|