|
|
|
@ -1,23 +1,28 @@
|
|
|
|
|
package com.supervision.manage.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.lang.Assert;
|
|
|
|
|
import cn.hutool.core.lang.UUID;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.supervision.exception.BusinessException;
|
|
|
|
|
import com.supervision.manage.service.*;
|
|
|
|
|
import com.supervision.model.Disease;
|
|
|
|
|
import com.supervision.model.DiseaseAncillary;
|
|
|
|
|
import com.supervision.service.DiseaseAncillaryService;
|
|
|
|
|
import com.supervision.service.DiseaseService;
|
|
|
|
|
import com.supervision.vo.manage.DiseaseVo;
|
|
|
|
|
import com.supervision.vo.manage.DiseaseReqVo;
|
|
|
|
|
import com.supervision.vo.manage.DiseaseResVo;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class DiseaseManageServiceImpl implements DiseaseManageService {
|
|
|
|
@ -36,6 +41,13 @@ public class DiseaseManageServiceImpl implements DiseaseManageService {
|
|
|
|
|
|
|
|
|
|
assertDisease(disease);
|
|
|
|
|
|
|
|
|
|
// 如果包含疾病id不为空,则为复合疾病
|
|
|
|
|
if (CollUtil.isNotEmpty(disease.getContainDiseaseIds())){
|
|
|
|
|
disease.setDiseaseType(1);
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(disease.getCode())){
|
|
|
|
|
disease.setCode(UUID.fastUUID().toString());
|
|
|
|
|
}
|
|
|
|
|
disease.setStatus(0);
|
|
|
|
|
diseaseService.save(disease);
|
|
|
|
|
|
|
|
|
@ -56,6 +68,12 @@ public class DiseaseManageServiceImpl implements DiseaseManageService {
|
|
|
|
|
@Transactional
|
|
|
|
|
public boolean deleteDisease(String id) {
|
|
|
|
|
|
|
|
|
|
Disease disease = diseaseService.getById(id);
|
|
|
|
|
if (Objects.isNull(disease)){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
Assert.isFalse(disease.getDiseaseType()==0,"单一疾病不允许被删除");
|
|
|
|
|
|
|
|
|
|
// 1. 删除疾病信息
|
|
|
|
|
diseaseService.removeById(id);
|
|
|
|
|
|
|
|
|
@ -75,13 +93,40 @@ public class DiseaseManageServiceImpl implements DiseaseManageService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Page<Disease> queryPageList(Integer pageNum, Integer pageSize, DiseaseVo diseaseVo) {
|
|
|
|
|
public IPage<? extends Disease> queryPageList(Integer pageNum, Integer pageSize, DiseaseReqVo diseaseReqVo) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (null == diseaseReqVo.getDiseaseType()){
|
|
|
|
|
diseaseReqVo.setDiseaseType(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LambdaQueryChainWrapper<Disease> wrapper = diseaseService.lambdaQuery()
|
|
|
|
|
.like(StrUtil.isNotEmpty(diseaseVo.getDiseaseName()), Disease::getDiseaseName, diseaseVo.getDiseaseName());
|
|
|
|
|
.eq(Disease::getDiseaseType, diseaseReqVo.getDiseaseType())
|
|
|
|
|
.like(StrUtil.isNotEmpty(diseaseReqVo.getDiseaseName()), Disease::getDiseaseName, diseaseReqVo.getDiseaseName());
|
|
|
|
|
Page<Disease> page = wrapper.page(new Page<>(pageNum, pageSize));
|
|
|
|
|
|
|
|
|
|
return wrapper.page(new Page<>(pageNum, pageSize));
|
|
|
|
|
if (page.getSize() == 0) {
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
// 根据diseaseIds查询疾病信息
|
|
|
|
|
List<String> containDiseaseIds = page.getRecords().stream()
|
|
|
|
|
.filter(disease -> CollUtil.isNotEmpty(disease.getContainDiseaseIds()))
|
|
|
|
|
.flatMap(disease -> disease.getContainDiseaseIds().stream()).distinct().collect(Collectors.toList());
|
|
|
|
|
if (CollUtil.isEmpty(containDiseaseIds)) {
|
|
|
|
|
return page;
|
|
|
|
|
}
|
|
|
|
|
Map<String, Disease> diseaseMap = diseaseService.listByIds(containDiseaseIds)
|
|
|
|
|
.stream().collect(Collectors.toMap(Disease::getId, disease -> disease, (v1, v2) -> v1));
|
|
|
|
|
|
|
|
|
|
// 把疾病名映射到DiseaseResVo中
|
|
|
|
|
return page.convert(record -> {
|
|
|
|
|
DiseaseResVo bean = BeanUtil.toBean(record, DiseaseResVo.class);
|
|
|
|
|
if (CollUtil.isNotEmpty(bean.getContainDiseaseIds())){
|
|
|
|
|
bean.setContainDiseaseNames(bean.getContainDiseaseIds().stream()
|
|
|
|
|
.map(diseaseMap::get).filter(Objects::nonNull).map(Disease::getDiseaseName).collect(Collectors.toList()));
|
|
|
|
|
}
|
|
|
|
|
return bean;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -109,11 +154,15 @@ public class DiseaseManageServiceImpl implements DiseaseManageService {
|
|
|
|
|
|
|
|
|
|
Assert.isTrue(StrUtil.isNotEmpty(disease.getDiseaseNameAlias()),"疾病别名不能为空");
|
|
|
|
|
|
|
|
|
|
Assert.isTrue(StrUtil.isNotEmpty(disease.getCode()),"疾病编码不能为空");
|
|
|
|
|
if (CollUtil.isEmpty(disease.getContainDiseaseIds())){
|
|
|
|
|
// 如果包含疾病为空,则疾病code不能为空
|
|
|
|
|
Assert.isTrue(StrUtil.isNotEmpty(disease.getCode()),"疾病编码不能为空");
|
|
|
|
|
|
|
|
|
|
List<Disease> diseases = this.queryByAnyCondition(disease.getCode(), disease.getDiseaseName(), disease.getDiseaseNameAlias());
|
|
|
|
|
Assert.isTrue(CollUtil.isEmpty(diseases),"类目编码: {},或疾病名称: {},或疾病分类别名: {} 已存在",
|
|
|
|
|
disease.getCode(),disease.getDiseaseName(),disease.getDiseaseNameAlias());
|
|
|
|
|
// 判断类目编码是否已存在
|
|
|
|
|
List<Disease> diseases = this.queryByAnyCondition(disease.getCode(), disease.getDiseaseName(), disease.getDiseaseNameAlias());
|
|
|
|
|
Assert.isTrue(CollUtil.isEmpty(diseases),"类目编码: {},或疾病名称: {},或疾病分类别名: {} 已存在",
|
|
|
|
|
disease.getCode(),disease.getDiseaseName(),disease.getDiseaseNameAlias());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|