From 70584075b3953045342a513bf3372efb204c9d5c Mon Sep 17 00:00:00 2001
From: luodangjia <luodangjia>
Date: 星期三, 25 十二月 2024 10:36:42 +0800
Subject: [PATCH] merge

---
 medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java |   78 ++++++++++++++++++++++++---------------
 1 files changed, 48 insertions(+), 30 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 a1a5eed..b796fc1 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
@@ -29,6 +29,7 @@
 import com.sinata.system.service.SysUserDepartmentService;
 import lombok.RequiredArgsConstructor;
 import org.jetbrains.annotations.NotNull;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -52,7 +53,7 @@
  * @since 2024-12-02
  */
 @Service
-@RequiredArgsConstructor
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class SysDepartmentServiceImpl extends ServiceImpl<SysDepartmentMapper, SysDepartment> implements SysDepartmentService {
     private final SysUserDepartmentService sysUserDepartmentService;
     private final RedisTemplate<Object, Object> redisTemplate;
@@ -222,7 +223,7 @@
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
         //获取部门树编码
         department.setOrgType(DepartmentEnum.REGION.getCode());
-        department.setTreeCode(getTreeCode(dto.getParentId()));
+        department.setTreeCode(generateTreeCode(dto.getParentId()));
         department.setOrgCode(getOrgCode(dto.getParentId(), DepartmentEnum.REGION.getCode()));
         save(department);
     }
@@ -257,7 +258,7 @@
         SysDepartment sysDepartment = getById(dto.getId());
         if (!dto.getParentId().equals(sysDepartment.getParentId())) {
             //获取部门树编码
-            department.setTreeCode(getTreeCode(dto.getParentId()));
+            department.setTreeCode(generateTreeCode(dto.getParentId()));
         }
         updateById(department);
     }
@@ -269,7 +270,7 @@
      * @return
      */
     @Override
-    public String getTreeCode(Long parentId) {
+    public String generateTreeCode(Long parentId) {
 
         String treeId;
         String preTreeCode = "";
@@ -362,14 +363,11 @@
      */
     @Override
     public PageDTO<MedicalInstitutionVO> pageMedicalList(DepartmentQuery query) {
-        String treeCode = "";
-        if (Objects.isNull(query.getDepartmentId())) {
-            SysDepartment myDepartment = getMyDepartment();
-            if (Objects.nonNull(myDepartment)) {
-                treeCode = myDepartment.getTreeCode();
-            }
+        String treeCode = getTreeCodeByDepartmentId(query.getDepartmentId());
+        if (StringUtils.isBlank(treeCode)) {
+            return PageDTO.empty(0L, 0L);
         }
-        Page<MedicalInstitutionVO> page = baseMapper.pageMedicalList(new Page<>(query.getPageCurr(), query.getPageSize()), query.getDepartmentId(), query.getDepartmentName(), query.getContactPerson(), query.getContactPhone(), treeCode);
+        Page<MedicalInstitutionVO> page = baseMapper.pageMedicalList(new Page<>(query.getPageCurr(), query.getPageSize()), query.getDepartmentName(), query.getContactPerson(), query.getContactPhone(), treeCode);
         return PageDTO.of(page);
     }
 
@@ -399,7 +397,7 @@
             throw new ServiceException("医疗机构已存在");
         }
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
-        department.setTreeCode(getTreeCode(parent.getId()));
+        department.setTreeCode(generateTreeCode(parent.getId()));
         department.setOrgCode(getOrgCode(parent.getId(), DepartmentEnum.MEDICAL_INSTITUTION.getCode()));
         department.setOrgType(DepartmentEnum.MEDICAL_INSTITUTION.getCode());
         //查询父级完整区域
@@ -411,6 +409,12 @@
         sysDepartmentInfoService.save(sysDepartmentInfo);
     }
 
+    /**
+     * 根据父级区域id查询处置单位列表
+     *
+     * @param id
+     * @return
+     */
     @Override
     public List<DisposalUnitVO> getDisposalUnitListByParentId(Long id) {
         List<DisposalUnitVO> disposalUnitList = null;
@@ -423,7 +427,7 @@
     }
 
     /**
-     * 获取完成区域
+     * 获取完整区域
      *
      * @param department
      * @return
@@ -473,7 +477,7 @@
         }
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
         if (!department.getParentId().equals(sysDepartment.getParentId())) {
-            department.setTreeCode(getTreeCode(parent.getId()));
+            department.setTreeCode(generateTreeCode(parent.getId()));
             //查询父级完整区域
             String region = getRegionName(parent);
             department.setRegion(region);
@@ -522,12 +526,9 @@
      */
     @Override
     public PageDTO<DisposalUnitVO> pageDisposalUnitList(DepartmentQuery query) {
-        String treeCode = "";
-        if (Objects.isNull(query.getDepartmentId())) {
-            SysDepartment myDepartment = getMyDepartment();
-            if (Objects.nonNull(myDepartment)) {
-                treeCode = myDepartment.getTreeCode();
-            }
+        String treeCode = getTreeCodeByDepartmentId(query.getDepartmentId());
+        if (StringUtils.isBlank(treeCode)) {
+            return PageDTO.empty(0L, 0L);
         }
         Page<DisposalUnitVO> page = baseMapper.pageRegulatoryUnitList(new Page<>(query.getPageCurr(), query.getPageSize()), query.getDepartmentId(), query.getDepartmentName(), query.getContactPerson(), query.getContactPhone(), treeCode);
         return PageDTO.of(page);
@@ -559,7 +560,7 @@
             throw new ServiceException("处置单位已存在");
         }
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
-        department.setTreeCode(getTreeCode(parent.getId()));
+        department.setTreeCode(generateTreeCode(parent.getId()));
         department.setOrgCode(getOrgCode(parent.getId(), DepartmentEnum.DISPOSAL_UNIT.getCode()));
         department.setOrgType(DepartmentEnum.DISPOSAL_UNIT.getCode());
         //查询父级完整区域
@@ -606,7 +607,7 @@
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
 
         if (!department.getParentId().equals(sysDepartment.getParentId())) {
-            department.setTreeCode(getTreeCode(parent.getId()));
+            department.setTreeCode(generateTreeCode(parent.getId()));
             //查询父级完整区域
             String region = getRegionName(parent);
             department.setRegion(region);
@@ -647,12 +648,9 @@
      */
     @Override
     public PageDTO<RegulatoryUnitVO> pageRegulatoryUnitList(DepartmentQuery query) {
-        String treeCode = "";
-        if (Objects.isNull(query.getDepartmentId())) {
-            SysDepartment myDepartment = getMyDepartment();
-            if (Objects.nonNull(myDepartment)) {
-                treeCode = myDepartment.getTreeCode();
-            }
+        String treeCode = getTreeCodeByDepartmentId(query.getDepartmentId());
+        if (StringUtils.isBlank(treeCode)) {
+            return PageDTO.empty(0L, 0L);
         }
         Page<SysDepartment> page = this.lambdaQuery().eq(Objects.nonNull(query.getDepartmentId()), SysDepartment::getParentId, query.getDepartmentId())
                 .likeRight(StringUtils.isNotBlank(treeCode), SysDepartment::getTreeCode, treeCode)
@@ -688,7 +686,7 @@
             throw new ServiceException("监管单位已存在");
         }
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
-        department.setTreeCode(getTreeCode(parent.getId()));
+        department.setTreeCode(generateTreeCode(parent.getId()));
         department.setOrgCode(getOrgCode(parent.getId(), DepartmentEnum.REGULATORY_UNIT.getCode()));
         department.setOrgType(DepartmentEnum.REGULATORY_UNIT.getCode());
         //查询父级完整区域
@@ -732,7 +730,7 @@
         SysDepartment department = BeanUtils.copyBean(dto, SysDepartment.class);
 
         if (!department.getParentId().equals(sysDepartment.getParentId())) {
-            department.setTreeCode(getTreeCode(parent.getId()));
+            department.setTreeCode(generateTreeCode(parent.getId()));
             //查询父级完整区域
             String region = getRegionName(parent);
             department.setRegion(region);
@@ -768,4 +766,24 @@
         }
         removeById(id);
     }
+
+    /**
+     * 根据部门id获取树编码,如果为空则获取当前登录用户所在区域树编码
+     *
+     * @param departmentId
+     * @return
+     */
+    @Override
+    public String getTreeCodeByDepartmentId(Long departmentId) {
+        SysDepartment department;
+        if (Objects.isNull(departmentId)) {
+            department = getMyDepartment();
+        } else {
+            department = getById(departmentId);
+        }
+        if (Objects.nonNull(department)) {
+            return department.getTreeCode();
+        }
+        return null;
+    }
 }

--
Gitblit v1.7.1