From 1631a9cd06a9272dbc808551ce7f0682cde2ba71 Mon Sep 17 00:00:00 2001 From: luoyisheng <yangdongji@argo-ai.cn> Date: 星期五, 21 三月 2025 17:01:07 +0800 Subject: [PATCH] bug --- medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java | 129 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 127 insertions(+), 2 deletions(-) diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java index bd1c738..0ade275 100644 --- a/medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java +++ b/medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java @@ -4,12 +4,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.sinata.common.constant.CacheConstants; +import com.sinata.common.core.domain.entity.SysUser; import com.sinata.common.entity.PageDTO; import com.sinata.common.exception.ServiceException; import com.sinata.common.utils.BeanUtils; import com.sinata.common.utils.CollUtils; import com.sinata.common.utils.SecurityUtils; import com.sinata.common.utils.StringUtils; +import com.sinata.system.domain.MwApplication; import com.sinata.system.domain.SysDepartment; import com.sinata.system.domain.SysDepartmentInfo; import com.sinata.system.domain.SysUserDepartment; @@ -90,8 +92,39 @@ childrenMap = getChildrenDepartmentByOrgType(myDepartment, null); } SysDepartmentVO sysDepartmentVO = fillChildrenTreeModel(myDepartment, childrenMap); + switch (type) { + case 2: + case 3: + case 4: + filterEmptyChildren(sysDepartmentVO.getChildren()); + break; + } root.add(sysDepartmentVO); return root; + } + + /** + * 移除子节点为空的区域 + * + * @param departments + */ + private void filterEmptyChildren(List<SysDepartmentVO> departments) { + if (departments == null) { + return; + } + + Iterator<SysDepartmentVO> iterator = departments.iterator(); + while (iterator.hasNext()) { + SysDepartmentVO department = iterator.next(); + + // 递归过滤子节点 + filterEmptyChildren(department.getChildren()); + + // 如果 orgType == 1 且 children 为空,则移除当前节点 + if (department.getOrgType() == 1 && department.getChildren().isEmpty()) { + iterator.remove(); + } + } } /** @@ -103,7 +136,6 @@ private Map<Long, List<SysDepartment>> getChildrenDepartmentByOrgType(SysDepartment myDepartment, List<Integer> orgTypes) { List<SysDepartment> sysDepartmentList = this.lambdaQuery() .likeRight(SysDepartment::getTreeCode, myDepartment.getTreeCode()) - .in(CollUtils.isNotEmpty(orgTypes), SysDepartment::getOrgType, orgTypes) .orderByDesc(SysDepartment::getCreateTime) .list(); return sysDepartmentList.stream() @@ -132,6 +164,73 @@ } Map<Long, List<SysDepartment>> childrenMap = getChildrenDepartmentByOrgType(currentDepartment, Collections.singletonList(DepartmentEnum.REGION.getCode())); SysDepartmentVO sysDepartmentVO = fillChildrenTreeModel(currentDepartment, childrenMap); + root.add(sysDepartmentVO); + if (StringUtils.isNotBlank(keyword)) { + treeMatch(root, keyword); + } + return root; + } + @Override + public List<SysDepartmentVO> getRegionTree1(String keyword) { + SysUser sysUser = SecurityUtils.getLoginUser().getUser(); + + List<SysDepartmentVO> root = new ArrayList<>(); + SysDepartment sysDepartment = this.baseMapper.selectById(sysUser.getDepartmentId()); + SysDepartment currentDepartment = this.baseMapper.selectById(sysDepartment.getParentId()); + if (Objects.isNull(currentDepartment)) { + return root; + } + if (!currentDepartment.getOrgType().equals(DepartmentEnum.REGION.getCode())) { + return root; + } + Map<Long, List<SysDepartment>> childrenMap = getChildrenDepartmentByOrgType(currentDepartment, Collections.singletonList(DepartmentEnum.REGION.getCode())); + SysDepartmentVO sysDepartmentVO = fillChildrenTreeModel(currentDepartment, childrenMap); + root.add(sysDepartmentVO); + if (StringUtils.isNotBlank(keyword)) { + treeMatch(root, keyword); + } + return root; + } + public List<SysDepartmentVO> getRegionTree2(String keyword) { + +// SysDepartment currentDepartment = getMyDepartment(); + + List<SysDepartmentVO> root = new ArrayList<>(); + SysDepartment currentDepartment = getMyDepartment(); + if (Objects.isNull(currentDepartment)) { + return root; + } +// if (!currentDepartment.getOrgType().equals(DepartmentEnum.REGION.getCode())) { +// return root; +// } + Map<Long, List<SysDepartment>> childrenMap = getChildrenDepartmentByOrgType(currentDepartment, Collections.singletonList(DepartmentEnum.REGION.getCode())); + SysDepartmentVO sysDepartmentVO = fillChildrenTreeModel(currentDepartment, childrenMap); + if (sysDepartmentVO.getTreeCode().length()==10){ + SysDepartment sysDepartment = this.baseMapper.selectById(sysDepartmentVO.getParentId()); + SysDepartmentVO sysDepartmentVO1 = new SysDepartmentVO(); + BeanUtils.copyProperties(sysDepartment,sysDepartmentVO1); + List<SysDepartmentVO> root1 = new ArrayList<>(); + root1.add(sysDepartmentVO); + sysDepartmentVO1.setChildren(root1); + sysDepartmentVO = sysDepartmentVO1; + } + if (sysDepartmentVO.getTreeCode().length()==14){ + SysDepartment sysDepartment = this.baseMapper.selectById(sysDepartmentVO.getParentId()); + SysDepartmentVO sysDepartmentVO1 = new SysDepartmentVO(); + BeanUtils.copyProperties(sysDepartment,sysDepartmentVO1); + List<SysDepartmentVO> root1 = new ArrayList<>(); + root1.add(sysDepartmentVO); + sysDepartmentVO1.setChildren(root1); + + + SysDepartment sysDepartment2 = this.baseMapper.selectById(sysDepartment.getParentId()); + SysDepartmentVO sysDepartmentVO2 = new SysDepartmentVO(); + BeanUtils.copyProperties(sysDepartment2,sysDepartmentVO2); + List<SysDepartmentVO> root2 = new ArrayList<>(); + root2.add(sysDepartmentVO1); + sysDepartmentVO2.setChildren(root2); + sysDepartmentVO = sysDepartmentVO2; + } root.add(sysDepartmentVO); if (StringUtils.isNotBlank(keyword)) { treeMatch(root, keyword); @@ -443,7 +542,8 @@ * @param department * @return */ - private String getRegionName(SysDepartment department) { + @Override + public String getRegionName(SysDepartment department) { String region = department.getDepartmentName(); SysDepartment sysDepartment = this.lambdaQuery().eq(SysDepartment::getId, department.getParentId()).ne(SysDepartment::getId, -1).one(); if (Objects.nonNull(sysDepartment)) { @@ -668,6 +768,7 @@ .like(StringUtils.isNotEmpty(query.getDepartmentName()), SysDepartment::getDepartmentName, query.getDepartmentName()) .like(StringUtils.isNotBlank(query.getContactPerson()), SysDepartment::getContactPerson, query.getContactPerson()) .like(StringUtils.isNotBlank(query.getContactPhone()), SysDepartment::getContactPhone, query.getContactPhone()) + .eq(SysDepartment::getOrgType, DepartmentEnum.REGULATORY_UNIT.getCode()) .page(new Page<>(query.getPageCurr(), query.getPageSize())); return PageDTO.of(page, RegulatoryUnitVO.class); } @@ -808,4 +909,28 @@ public List<MedicalInstitutionVO> getHospitalListByRouteId(Long id) { return baseMapper.getHospitalListByRouteId(id); } + + /** + * 创建机构 + * + * @param mwApplication + */ + @Override + public void createDepartment(MwApplication mwApplication) { + SysDepartment parent = this.getById(mwApplication.getDepartmentId()); + if (Objects.isNull(parent)) { + throw new ServiceException("找不到对应父级组织"); + } + SysDepartment department = new SysDepartment(); + department.setParentId(mwApplication.getDepartmentId()); + department.setDepartmentName(mwApplication.getUnitName()); + department.setContactPerson(mwApplication.getConcat()); + department.setContactPhone(mwApplication.getPhone()); + department.setOrgType(mwApplication.getUnitType().equals(1) ? DepartmentEnum.MEDICAL_INSTITUTION.getCode() : DepartmentEnum.DISPOSAL_UNIT.getCode()); + department.setRegion(mwApplication.getRegion()); + department.setRelation(mwApplication.getRelation()); + department.setTreeCode(generateTreeCode(parent.getId())); + department.setOrgCode(getOrgCode(parent.getId(), department.getOrgType())); + save(department); + } } -- Gitblit v1.7.1