|
@@ -4,33 +4,44 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.dto.HospitalInfoDTO;
|
|
|
-import com.diagbot.entity.DiseaseConfig;
|
|
|
+import com.diagbot.dto.HospitalInfoGetDTO;
|
|
|
+import com.diagbot.dto.HospitalInfoPageDTO;
|
|
|
+import com.diagbot.dto.HospitalRelationDTO;
|
|
|
+import com.diagbot.dto.HospitalRelationErrorDTO;
|
|
|
import com.diagbot.entity.HospitalInfo;
|
|
|
import com.diagbot.entity.MappingConfig;
|
|
|
import com.diagbot.entity.Plan;
|
|
|
+import com.diagbot.entity.TranHospitalRelation;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.HospitalInfoService;
|
|
|
+import com.diagbot.service.TranHospitalRelationService;
|
|
|
import com.diagbot.service.impl.HospitalInfoServiceImpl;
|
|
|
import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.Cn2SpellUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.UserUtils;
|
|
|
import com.diagbot.vo.ChangeStatusVO;
|
|
|
+import com.diagbot.vo.HospitalInfoGetVO;
|
|
|
import com.diagbot.vo.HospitalInfoListVO;
|
|
|
import com.diagbot.vo.HospitalInfoPageVO;
|
|
|
+import com.diagbot.vo.HospitalInfoSaveVO;
|
|
|
+import com.diagbot.vo.HospitalRelationVO;
|
|
|
import com.diagbot.vo.HospitalSaveVO;
|
|
|
import com.diagbot.vo.IdListVO;
|
|
|
import com.diagbot.vo.IdVO;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -49,6 +60,9 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
private MappingConfigFacade mappingConfigFacade;
|
|
|
@Autowired
|
|
|
private PlanFacade planFacade;
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("tranHospitalRelationServiceImpl")
|
|
|
+ TranHospitalRelationService tranHospitalRelationService;
|
|
|
|
|
|
public List<HospitalInfoDTO> getHospitalInfo() {
|
|
|
QueryWrapper<HospitalInfo> hospitalInfo = new QueryWrapper<>();
|
|
@@ -59,49 +73,62 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据ID获取医院信息
|
|
|
+ *
|
|
|
+ * @param hospitalInfoGetVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HospitalInfoGetDTO getById(HospitalInfoGetVO hospitalInfoGetVO) {
|
|
|
+ HospitalInfo hospitalInfo = this.getOne(new QueryWrapper<HospitalInfo>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", hospitalInfoGetVO.getId()), false);
|
|
|
+ if (hospitalInfo == null) {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "数据不存在");
|
|
|
+ }
|
|
|
+ HospitalInfoGetDTO hospitalInfoGetDTO = new HospitalInfoGetDTO();
|
|
|
+ BeanUtil.copyProperties(hospitalInfo, hospitalInfoGetDTO);
|
|
|
+
|
|
|
+ List<TranHospitalRelation> relationList = tranHospitalRelationService.list(new QueryWrapper<TranHospitalRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", hospitalInfoGetVO.getId()));
|
|
|
+ List<HospitalRelationDTO> hospitalRelationDTOS = BeanUtil.listCopyTo(relationList, HospitalRelationDTO.class);
|
|
|
+ hospitalInfoGetDTO.setHospitalRelationDTOList(hospitalRelationDTOS);
|
|
|
+ return hospitalInfoGetDTO;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存记录-单条
|
|
|
*
|
|
|
- * @param hospitalInfo
|
|
|
+ * @param hospitalInfoSaveVO
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean saveOrUpdateRecord(HospitalInfo hospitalInfo) {
|
|
|
+ public HospitalRelationErrorDTO saveOrUpdateRecord(HospitalInfoSaveVO hospitalInfoSaveVO) {
|
|
|
String userId = UserUtils.getCurrentPrincipleID();
|
|
|
+ HospitalInfo hospitalInfo = new HospitalInfo();
|
|
|
+ BeanUtil.copyProperties(hospitalInfoSaveVO, hospitalInfo);
|
|
|
Date now = DateUtil.now();
|
|
|
hospitalInfo.setModifier(userId);
|
|
|
hospitalInfo.setGmtModified(now);
|
|
|
- QueryWrapper<HospitalInfo> queryWrapper = new QueryWrapper<>();
|
|
|
if (StringUtil.isNotBlank(hospitalInfo.getName())) {
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- queryWrapper.eq("name", hospitalInfo.getName());
|
|
|
- HospitalInfo oldRecord = this.getOne(queryWrapper, false);
|
|
|
- if (hospitalInfo.getId() == null
|
|
|
- && oldRecord != null) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该医院名称已存在");
|
|
|
- }
|
|
|
- if (hospitalInfo.getId() != null
|
|
|
- && oldRecord != null
|
|
|
- && !hospitalInfo.getId().equals(oldRecord.getId())) {
|
|
|
+ HospitalInfo oldRecord = this.getOne(new QueryWrapper<HospitalInfo>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("name", hospitalInfo.getName())
|
|
|
+ .ne("id", hospitalInfo.getId() == null ? -999 : hospitalInfo.getId()), false);
|
|
|
+ if (oldRecord != null) {
|
|
|
throw new CommonException(CommonErrorCode.IS_EXISTS, "该医院名称已存在");
|
|
|
}
|
|
|
}
|
|
|
- /*if (StringUtil.isNotBlank(hospitalInfo.getCode())) {
|
|
|
- queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey());
|
|
|
- queryWrapper.eq("code", hospitalInfo.getCode());
|
|
|
- HospitalInfo oldRecord = this.getOne(queryWrapper, false);
|
|
|
- if (hospitalInfo.getId() == null
|
|
|
- && oldRecord != null) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该医院编码已存在");
|
|
|
- }
|
|
|
- if (hospitalInfo.getId() != null
|
|
|
- && oldRecord != null
|
|
|
- && !hospitalInfo.getId().equals(oldRecord.getId())) {
|
|
|
- throw new CommonException(CommonErrorCode.IS_EXISTS, "该医院编码已存在");
|
|
|
- }
|
|
|
- }*/
|
|
|
|
|
|
- //新增数据
|
|
|
+ // 获取子医院
|
|
|
+ List<HospitalRelationVO> hospitalRelationVOList = hospitalInfoSaveVO.getHospitalRelationVOList();
|
|
|
+ // 校验子医院
|
|
|
+ HospitalRelationErrorDTO res = checkRelationHospital(hospitalRelationVOList, hospitalInfo.getId());
|
|
|
+ if (res != null) {
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 新增数据
|
|
|
if (hospitalInfo.getId() == null) {
|
|
|
hospitalInfo.setCreator(userId);
|
|
|
hospitalInfo.setGmtCreate(now);
|
|
@@ -110,11 +137,74 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
if (StringUtil.isBlank(hospitalInfo.getSpell())) {
|
|
|
hospitalInfo.setSpell(Cn2SpellUtil.converterToFirstSpell(hospitalInfo.getName()));
|
|
|
}
|
|
|
- if (hospitalInfo.getIsDeleted() == null) {
|
|
|
- hospitalInfo.setIsDeleted(IsDeleteEnum.N.getKey());
|
|
|
- }
|
|
|
this.saveOrUpdate(hospitalInfo);
|
|
|
- return true;
|
|
|
+
|
|
|
+ // 先删除子医院关联表
|
|
|
+ tranHospitalRelationService.remove(new QueryWrapper<TranHospitalRelation>().eq("hospital_id", hospitalInfo.getId()));
|
|
|
+ // 插入子医院关联表
|
|
|
+ List<TranHospitalRelation> saveRelationList = Lists.newArrayList();
|
|
|
+ for (HospitalRelationVO hospitalRelationVO : hospitalRelationVOList) {
|
|
|
+ TranHospitalRelation tranHospitalRelation = new TranHospitalRelation();
|
|
|
+ BeanUtil.copyProperties(hospitalRelationVO, tranHospitalRelation);
|
|
|
+ tranHospitalRelation.setHospitalId(hospitalInfo.getId());
|
|
|
+ tranHospitalRelation.setCreator(userId);
|
|
|
+ tranHospitalRelation.setModifier(userId);
|
|
|
+ tranHospitalRelation.setGmtCreate(now);
|
|
|
+ tranHospitalRelation.setGmtModified(now);
|
|
|
+ saveRelationList.add(tranHospitalRelation);
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(saveRelationList)) {
|
|
|
+ tranHospitalRelationService.saveBatch(saveRelationList);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验子医院
|
|
|
+ *
|
|
|
+ * @param hospitalRelationVOList
|
|
|
+ * @param curHospitalId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HospitalRelationErrorDTO checkRelationHospital(List<HospitalRelationVO> hospitalRelationVOList, Long curHospitalId) {
|
|
|
+ HospitalRelationErrorDTO res = new HospitalRelationErrorDTO();
|
|
|
+ if (ListUtil.isNotEmpty(hospitalRelationVOList)) {
|
|
|
+ // 校验name+code唯一性
|
|
|
+ List<TranHospitalRelation> tranHospitalRelationList = tranHospitalRelationService.list(new QueryWrapper<TranHospitalRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ );
|
|
|
+ Map<String, Long> relationMap = tranHospitalRelationList.stream().collect(
|
|
|
+ Collectors.toMap(k -> k.getName().toUpperCase() + "_" + k.getCode().toUpperCase(), v -> v.getHospitalId(), (v1, v2) -> (v2), LinkedHashMap::new));
|
|
|
+ List<String> keyExist = Lists.newArrayList(); // 避免重复数据返回
|
|
|
+ List<String> keyAll = Lists.newArrayList(); // 当前医院所有key
|
|
|
+ List<HospitalRelationVO> errorOther = Lists.newArrayList(); // 与其他医院重复
|
|
|
+ List<HospitalRelationVO> errorCurrent = Lists.newArrayList(); // 当前医院重复
|
|
|
+
|
|
|
+ for (HospitalRelationVO hospitalRelationVO : hospitalRelationVOList) {
|
|
|
+ // 联合key
|
|
|
+ String unionKey = hospitalRelationVO.getName().toUpperCase() + "_" + hospitalRelationVO.getCode().toUpperCase();
|
|
|
+ // 判断当前医院重复
|
|
|
+ if (keyAll.contains(unionKey)) {
|
|
|
+ errorCurrent.add(hospitalRelationVO);
|
|
|
+ } else {
|
|
|
+ keyAll.add(unionKey);
|
|
|
+ }
|
|
|
+ // 判断与其他医院重复
|
|
|
+ Long hospitalId = relationMap.get(unionKey);
|
|
|
+ if (hospitalId != null && !hospitalId.equals(curHospitalId) && !keyExist.contains(unionKey)) {
|
|
|
+ errorOther.add(hospitalRelationVO);
|
|
|
+ keyExist.add(unionKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 有错误,直接返回
|
|
|
+ if (ListUtil.isNotEmpty(errorOther) || ListUtil.isNotEmpty(errorCurrent)) {
|
|
|
+ res.setErrorOther(errorOther);
|
|
|
+ res.setErrorCurrent(errorCurrent);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -150,7 +240,11 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
public Boolean deleteRecord(IdVO idVO) {
|
|
|
String userId = UserUtils.getCurrentPrincipleID();
|
|
|
Date now = DateUtil.now();
|
|
|
- HospitalInfo hospitalInfo = hospitalInfoService.getById(idVO.getId());
|
|
|
+ Long id = idVO.getId();
|
|
|
+ if (idVO.getId().equals(-1)) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "当前医院不能删除");
|
|
|
+ }
|
|
|
+ HospitalInfo hospitalInfo = hospitalInfoService.getById(id);
|
|
|
if (hospitalInfo == null) {
|
|
|
throw new CommonException(CommonErrorCode.NOT_EXISTS, "数据不存在");
|
|
|
}
|
|
@@ -161,24 +255,34 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
List<MappingConfig> mappingConfigList
|
|
|
= mappingConfigFacade.list(new QueryWrapper<MappingConfig>()
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", idVO.getId()));
|
|
|
+ .eq("hospital_id", id));
|
|
|
if (ListUtil.isNotEmpty(mappingConfigList)) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该医院存在关联数据,无法删除");
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该医院存在映射关联,无法删除");
|
|
|
}
|
|
|
|
|
|
List<Plan> planList
|
|
|
= planFacade.list(new QueryWrapper<Plan>()
|
|
|
.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
- .eq("hospital_id", idVO.getId()));
|
|
|
+ .eq("hospital_id", id));
|
|
|
if (ListUtil.isNotEmpty(planList)) {
|
|
|
- throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该医院存在关联数据,无法删除");
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该医院存在方案配置关联,无法删除");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ int count = tranHospitalRelationService.count(new QueryWrapper<TranHospitalRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("hospital_id", id));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该医院存在子医院关联,无法删除");
|
|
|
+ }
|
|
|
+ // 主表逻辑删除
|
|
|
hospitalInfo.setIsDeleted(IsDeleteEnum.Y.getKey());
|
|
|
hospitalInfo.setModifier(userId);
|
|
|
hospitalInfo.setGmtModified(now);
|
|
|
hospitalInfoService.updateById(hospitalInfo);
|
|
|
+
|
|
|
+ // 关联表物理删除
|
|
|
+ tranHospitalRelationService.remove(new QueryWrapper<TranHospitalRelation>()
|
|
|
+ .eq("hospital_id", id));
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -215,9 +319,24 @@ public class HospitalInfoFacade extends HospitalInfoServiceImpl {
|
|
|
* @param hospitalInfoPageVO
|
|
|
* @return
|
|
|
*/
|
|
|
- @Override
|
|
|
- public IPage<DiseaseConfig> getPage(HospitalInfoPageVO hospitalInfoPageVO) {
|
|
|
- return hospitalInfoService.getPage(hospitalInfoPageVO);
|
|
|
+ public IPage<HospitalInfoPageDTO> getPageFac(HospitalInfoPageVO hospitalInfoPageVO) {
|
|
|
+ IPage<HospitalInfoPageDTO> page = hospitalInfoService.getPage(hospitalInfoPageVO);
|
|
|
+ List<HospitalInfoPageDTO> records = page.getRecords();
|
|
|
+ if (ListUtil.isNotEmpty(records)) {
|
|
|
+ List<Long> idList = records.stream().map(r -> r.getId()).collect(Collectors.toList());
|
|
|
+ List<TranHospitalRelation> relationList = tranHospitalRelationService.list(new QueryWrapper<TranHospitalRelation>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("hospital_id", idList)
|
|
|
+ );
|
|
|
+ Map<Long, List<TranHospitalRelation>> hospitalIdMap = EntityUtil.makeEntityListMap(relationList, "hospitalId");
|
|
|
+ for (HospitalInfoPageDTO hospitalInfoPageDTO : records) {
|
|
|
+ List<TranHospitalRelation> tranHospitalRelationList = hospitalIdMap.get(hospitalInfoPageDTO.getId());
|
|
|
+ if (ListUtil.isNotEmpty(tranHospitalRelationList)) {
|
|
|
+ hospitalInfoPageDTO.setSonHospital(tranHospitalRelationList.stream().map(r -> r.getName()).collect(Collectors.joining(",")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
/**
|