新增接口医学标签树
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
//获取医学标签下的课程列表
|
||||
|
||||
@@ -8,4 +8,6 @@ import java.util.List;
|
||||
public interface CourseMedicalService extends IService<CourseMedicine> {
|
||||
|
||||
List<CourseMedicine> getMedicalLabels(Integer id);
|
||||
|
||||
List<CourseMedicine> getCourseMedicalTree();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user