新增接口医学标签树

This commit is contained in:
wuchunlei
2024-05-29 13:22:51 +08:00
parent 71b8ba6962
commit bffc62cbdd
3 changed files with 40 additions and 2 deletions

View File

@@ -32,8 +32,15 @@ public class HomeController {
//获取医学标签列表
@RequestMapping("/getMedicalLabels")
public R getMedicalLabels(@RequestBody ParamTo param){
List<CourseMedicine> sociologyLabels = medicalService.getMedicalLabels(param.getId());
return R.ok().put("labels",sociologyLabels);
List<CourseMedicine> medicalLabels = medicalService.getMedicalLabels(param.getId());
return R.ok().put("labels",medicalLabels);
}
//获取医学标签树
@RequestMapping("/getCourseMedicalTree")
public R getCourseMedicalTree(){
List<CourseMedicine> labelsTree = medicalService.getCourseMedicalTree();
return R.ok().put("labels",labelsTree);
}
//获取医学标签下的课程列表

View File

@@ -8,4 +8,6 @@ import java.util.List;
public interface CourseMedicalService extends IService<CourseMedicine> {
List<CourseMedicine> getMedicalLabels(Integer id);
List<CourseMedicine> getCourseMedicalTree();
}

View File

@@ -1,6 +1,7 @@
package com.peanut.modules.medical.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.peanut.modules.common.dao.CourseMedicineDao;
import com.peanut.modules.common.entity.CourseMedicine;
@@ -8,6 +9,7 @@ import com.peanut.modules.medical.service.CourseMedicalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service("medicineCourseMedicalService")
@@ -21,4 +23,31 @@ public class CourseMedicalServiceImpl extends ServiceImpl<CourseMedicineDao, Cou
List<CourseMedicine> list = this.list(wrapper);
return list;
}
@Override
public List<CourseMedicine> getCourseMedicalTree() {
List<CourseMedicine> medicines = this.list(new QueryWrapper<>());
List<CourseMedicine> medicinesTree = medicines.stream().filter((courseMarketEntity) ->
courseMarketEntity.getPid() == 0
).map((medicine)->{
medicine.setChildren(getMedicineChildrens(medicine,medicines));
return medicine;
}).sorted((sort1,sort2)->{
return (sort1.getSort() == null? 0 : sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
}).collect(Collectors.toList());
return medicinesTree;
}
private List<CourseMedicine> getMedicineChildrens(CourseMedicine root, List<CourseMedicine> all){
List<CourseMedicine> children = all.stream().filter(courseMedicine -> {
return root.getId().equals(courseMedicine.getPid());
}).map(courseMedicine -> {
courseMedicine.setChildren(getMedicineChildrens(courseMedicine, all));
return courseMedicine;
}).sorted((sort1,sort2)->{
return (sort1.getSort()==null?0:sort1.getSort()) - (sort2.getSort()==null?0:sort2.getSort());
}).collect(Collectors.toList());
return children;
}
}