新增医案收集标签管理

This commit is contained in:
wuchunlei
2025-07-11 10:21:52 +08:00
parent 40ba3636d7
commit 5cdc3b0e69

View File

@@ -0,0 +1,154 @@
package com.peanut.modules.master.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.peanut.common.utils.R;
import com.peanut.modules.common.entity.*;
import com.peanut.modules.common.service.MedicalRecordsLabelService;
import com.peanut.modules.common.service.MedicalRecordsService;
import com.peanut.modules.common.service.MedicalRecordsToLabelService;
import com.peanut.modules.common.to.ParamTo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RestController("masterMedicalRecordsController")
@RequestMapping("master/medicalRecords")
public class MedicalRecordsController {
@Autowired
private MedicalRecordsService medicalRecordsService;
@Autowired
private MedicalRecordsLabelService medicalRecordsLabelService;
@Autowired
private MedicalRecordsToLabelService toLabelService;
@RequestMapping("/getMedicalRecordsLabelList")
public R getMedicalRecordsLabelList(){
return R.ok().put("Medicals", medicalRecordsLabels(0));
}
private List<MedicalRecordsLabel> medicalRecordsLabels(int id){
List<MedicalRecordsLabel> medicalRecordsLabelList = medicalRecordsLabelService.list(new LambdaQueryWrapper<MedicalRecordsLabel>()
.eq(MedicalRecordsLabel::getPid, 0));
for (MedicalRecordsLabel m : medicalRecordsLabelList){
if(m.getIsLast()!=1){
List<MedicalRecordsLabel> so = this.medicalRecordsLabels(m.getId());
m.setChildren(so);
}
}
return medicalRecordsLabelList;
}
@RequestMapping("/addMedicalRecordsLabel")
public R addMedicalRecordsLabel(@RequestBody MedicalRecordsLabel medicalRecordsLabel){
medicalRecordsLabelService.save(medicalRecordsLabel);
return R.ok().put("medicalRecordsLabel", medicalRecordsLabel);
}
@RequestMapping("/delMedicalRecordsLabel")
public R delMedicalRecordsLabel(@RequestBody ParamTo param){
//查看下一级是否存在
long count = medicalRecordsLabelService.count(new LambdaQueryWrapper<MedicalRecordsLabel>()
.eq(MedicalRecordsLabel::getPid, param.getId()));
if(count>0){
return R.error(501,"删除失败,请先删除子项目后再尝试");
}
//查看绑定关系是否存在
List<MedicalRecordsToLabel> toLabels = toLabelService.list(new LambdaQueryWrapper<MedicalRecordsToLabel>()
.eq(MedicalRecordsToLabel::getLabelId, param.getId()));
for (MedicalRecordsToLabel toLabel:toLabels){
MedicalRecords c = medicalRecordsService.getById(toLabel.getRecordId());
if (c!=null){
return R.error(502,"删除失败,请先解绑医案与标签的绑定关系");
}else {
toLabelService.removeById(toLabel.getId());
}
}
medicalRecordsLabelService.removeById(param.getId());
return R.ok();
}
@RequestMapping("/editMedicalRecordsLabel")
public R editMedicalRecordsLabel(@RequestBody MedicalRecordsLabel medicalRecordsLabel){
MedicalRecordsLabel old = medicalRecordsLabelService.getById(medicalRecordsLabel.getId());
if(old.getIsLast()==0&& medicalRecordsLabel.getIsLast()==1){
MedicalRecordsLabel one = medicalRecordsLabelService.getOne(new LambdaQueryWrapper<MedicalRecordsLabel>()
.eq(MedicalRecordsLabel::getPid, medicalRecordsLabel.getId()));
if(one!=null){
return R.error(501,"更新失败,请先清空此项的下级标签,才能将此标签变成终极标签");
}
}
if(old.getIsLast()==1&& medicalRecordsLabel.getIsLast()==0){
long c = toLabelService.count(new LambdaQueryWrapper<MedicalRecordsToLabel>()
.eq(MedicalRecordsToLabel::getLabelId, medicalRecordsLabel.getId()));
if(c>0){
return R.error(502,"更新失败,请先把此项与医案的关联关系清空后才可把此标签变成普通标签");
}
}
medicalRecordsLabelService.updateById(medicalRecordsLabel);
return R.ok().put("medicalRecordsLabel", medicalRecordsLabel);
}
@RequestMapping("/getMedicalRecordsListForLabel")
public R getMedicalRecordsListForLabel(@RequestBody ParamTo param){
MPJLambdaWrapper<MedicalRecords> wrapper = new MPJLambdaWrapper<>();
wrapper.rightJoin(MedicalRecordsToLabel.class,MedicalRecordsToLabel::getRecordId, MedicalRecords::getId);
wrapper.selectAll(MedicalRecords.class);
wrapper.eq(MedicalRecordsToLabel::getLabelId,param.getId());
wrapper.orderByAsc(MedicalRecordsToLabel::getSort);
List<MedicalRecords> medicalRecordsList = medicalRecordsService.list(wrapper);
return R.ok().put("medicalRecordsList",medicalRecordsList);
}
@RequestMapping("/getMedicalRecordsListCanLabel")
public R getMedicalRecordsListCanLabel(@RequestBody ParamTo param){
List<Integer> collect = toLabelService.list(new LambdaQueryWrapper<MedicalRecordsToLabel>()
.eq(MedicalRecordsToLabel::getLabelId, param.getId()))
.stream().map(MedicalRecordsToLabel::getRecordId).collect(Collectors.toList());
LambdaQueryWrapper<MedicalRecords> wrapper = new LambdaQueryWrapper<>();
if (collect.size() != 0){
wrapper.notIn(MedicalRecords::getId,collect);
}
wrapper.like(StringUtils.isNotBlank(param.getKeywords()),MedicalRecords::getTitle,param.getKeywords());
Page<MedicalRecords> page = medicalRecordsService.page(new Page<>(param.getPage(), param.getLimit()), wrapper);
return R.ok().put("page",page);
}
@RequestMapping("/bindMedicalRecordsAndLabel")
public R bindMedicalRecordsAndLabel(@RequestBody MedicalRecordsToLabel toLabel){
//去重
MedicalRecordsToLabel one = toLabelService.getOne(new LambdaQueryWrapper<MedicalRecordsToLabel>()
.eq(MedicalRecordsToLabel::getRecordId, toLabel.getRecordId())
.eq(MedicalRecordsToLabel::getLabelId, toLabel.getLabelId()));
if(one != null){
return R.error(501,"绑定失败,绑定关系已将存在");
}
toLabelService.save(toLabel);
return R.ok();
}
@RequestMapping("/unbindCourseAndMedical")
public R unbindCourseAndMedical(@RequestBody MedicalRecordsToLabel toLabel){
boolean b = toLabelService.removeById(toLabel.getId());
if(b){
return R.ok();
}else {
return R.error("error");
}
}
@RequestMapping("/updateCourseToMedicalSort")
public R updateCourseToMedicalSort(@RequestBody MedicalRecordsToLabel toLabel){
toLabelService.updateById(toLabel);
return R.ok();
}
}