From ae7f04be9321ddbe17c46fae8ab05d34e7493f9f Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期三, 19 二月 2025 13:40:06 +0800
Subject: [PATCH] 管理后台bug修改

---
 medicalWaste-system/src/main/java/com/sinata/system/service/impl/SysDepartmentServiceImpl.java |   48 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 37 insertions(+), 11 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 5a457eb..3ce68a4 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
@@ -1,7 +1,6 @@
 package com.sinata.system.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.sinata.common.constant.CacheConstants;
@@ -12,9 +11,9 @@
 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;
 import com.sinata.system.domain.dto.DisposalUnitDTO;
 import com.sinata.system.domain.dto.MedicalInstitutionDTO;
 import com.sinata.system.domain.dto.RegulatoryUnitDTO;
@@ -26,6 +25,7 @@
 import com.sinata.system.domain.vo.SysDepartmentVO;
 import com.sinata.system.enums.DepartmentEnum;
 import com.sinata.system.mapper.SysDepartmentMapper;
+import com.sinata.system.service.ISysUserService;
 import com.sinata.system.service.SysDepartmentInfoService;
 import com.sinata.system.service.SysDepartmentService;
 import com.sinata.system.service.SysUserDepartmentService;
@@ -60,6 +60,7 @@
     private final SysUserDepartmentService sysUserDepartmentService;
     private final RedisTemplate<Object, Object> redisTemplate;
     private final SysDepartmentInfoService sysDepartmentInfoService;
+    private final ISysUserService sysUserService;
     /**
      * 获取区域树
      * @return
@@ -420,9 +421,9 @@
                 .orderByDesc(SysDepartment::getCreateTime)
                 .list();
         List<Long> departmentIds = sysDepartmentList.stream().map(SysDepartment::getId).collect(Collectors.toList());
-        Long count = sysUserDepartmentService.lambdaQuery().in(SysUserDepartment::getDepartmentId, departmentIds).count();
+        Long count = sysUserService.lambdaQuery().in(SysUser::getDepartmentId, departmentIds).count();
         if (count > 0) {
-            throw new ServiceException("该区域已存在用户,无法删除");
+            throw new ServiceException("该区域已关联用户,无法删除");
         }
         removeById(id);
     }
@@ -515,7 +516,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)) {
@@ -594,9 +596,9 @@
      */
     @Override
     public void deleteMedical(Long id) {
-        Long count = sysUserDepartmentService.lambdaQuery().eq(SysUserDepartment::getDepartmentId, id).count();
+        Long count = sysUserService.lambdaQuery().eq(SysUser::getDepartmentId, id).count();
         if (count > 0) {
-            throw new ServiceException("该医疗机构已存在用户,无法删除");
+            throw new ServiceException("该医疗机构已关联用户,无法删除");
         }
         removeById(id);
     }
@@ -716,9 +718,9 @@
 
     @Override
     public void deleteDisposalUnit(Long id) {
-        Long count = sysUserDepartmentService.lambdaQuery().eq(SysUserDepartment::getDepartmentId, id).count();
+        Long count = sysUserService.lambdaQuery().eq(SysUser::getDepartmentId, id).count();
         if (count > 0) {
-            throw new ServiceException("该处置单位构已存在用户,无法删除");
+            throw new ServiceException("该处置单位构已关联用户,无法删除");
         }
         removeById(id);
     }
@@ -844,9 +846,9 @@
      */
     @Override
     public void deleteRegulatoryUnit(Long id) {
-        Long count = sysUserDepartmentService.lambdaQuery().eq(SysUserDepartment::getDepartmentId, id).count();
+        Long count = sysUserService.lambdaQuery().eq(SysUser::getDepartmentId, id).count();
         if (count > 0) {
-            throw new ServiceException("该监管单位构已存在用户,无法删除");
+            throw new ServiceException("该监管单位构已关联用户,无法删除");
         }
         removeById(id);
     }
@@ -881,4 +883,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