Browse Source

企业组织机构删除接口关联企业用户

liangpeile 1 year ago
parent
commit
d639419e70

+ 9 - 9
crmeb-admin/src/main/java/com/zbkj/admin/controller/platform/NewPlatformApi.java

@@ -542,23 +542,23 @@ public class NewPlatformApi {
 
     @ApiOperation(value = "平台端组织机构删除--企业")
     @RequestMapping(value = "/organizationDelete", method = RequestMethod.POST)
-    public CommonResult<String> organizationDelete(@RequestParam(name = "id") String id) {
-        organizationService.delete(id);
-        return CommonResult.success("操作成功");
+    public CommonResult<?> organizationDelete(@RequestParam(name = "id") String id) {
+        return organizationService.deleteOrgan(id);
+
     }
 
     @ApiOperation(value = "平台端组织机构删除--部门")
     @RequestMapping(value = "/departmentDelete", method = RequestMethod.POST)
-    public CommonResult<String> departmentDelete(@RequestParam(name = "id") String id) {
-        organizationService.deleteDepartment(id);
-        return CommonResult.success("操作成功");
+    public CommonResult<?> departmentDelete(@RequestParam(name = "id") String id) {
+        return  organizationService.deleteDepartment(id);
+
     }
 
     @ApiOperation(value = "平台端组织机构删除--用户")
     @RequestMapping(value = "/userDelete", method = RequestMethod.POST)
-    public CommonResult<String> userDelete(@RequestParam(name = "id") String id) {
-        organizationService.deleteUser(id);
-        return CommonResult.success("操作成功");
+    public CommonResult<?> userDelete(@RequestParam(name = "id") String id) {
+        return  organizationService.deleteUser(id);
+
     }
 
 //    @ApiOperation(value = "平台端组织机构批量删除")

+ 4 - 2
crmeb-service/src/main/java/com/zbkj/service/service/OrganizationService.java

@@ -6,6 +6,7 @@ import com.zbkj.common.model.organization.Organization;
 import com.zbkj.common.model.organization.OrganizationDepartment;
 import com.zbkj.common.model.organization.OrganizationDepartmentUser;
 import com.zbkj.common.model.organization.VO.OrganizationVO;
+import com.zbkj.common.result.CommonResult;
 import com.zbkj.common.vo.CloudVo;
 
 import java.io.File;
@@ -47,10 +48,11 @@ public interface OrganizationService extends IService<Organization> {
      */
     OrganizationVO selectMessageByMainId(String id);
 
-    void deleteDepartment(String id);
-    void deleteUser(String id);
+    CommonResult<?>  deleteDepartment(String id);
+    CommonResult deleteUser(String id);
 
     void saveOrganization(Organization request, SystemAdmin systemAdmin);
 
 
+    CommonResult<?> deleteOrgan(String id);
 }

+ 79 - 15
crmeb-service/src/main/java/com/zbkj/service/service/impl/OrganizationServiceImpl.java

@@ -1,6 +1,7 @@
 package com.zbkj.service.service.impl;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.zbkj.common.model.admin.SystemAdmin;
 import com.zbkj.common.model.organization.Organization;
@@ -8,22 +9,19 @@ import com.zbkj.common.model.organization.OrganizationDepartment;
 import com.zbkj.common.model.organization.OrganizationDepartmentUser;
 import com.zbkj.common.model.organization.VO.OrganizationDepartmentVO;
 import com.zbkj.common.model.organization.VO.OrganizationVO;
+import com.zbkj.common.model.user.UserBypassAccount;
 import com.zbkj.common.model.user.UserEnterprise;
+import com.zbkj.common.result.CommonResult;
 import com.zbkj.service.dao.OrganizationDao;
 import com.zbkj.service.dao.OrganizationDeparementDao;
 import com.zbkj.service.dao.OrganizationDeparementUserDao;
-import com.zbkj.service.service.OrganizationDepartmentService;
-import com.zbkj.service.service.OrganizationDepartmentUserService;
-import com.zbkj.service.service.OrganizationService;
-import com.zbkj.service.service.UserEnterpriseService;
+import com.zbkj.service.service.*;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.UUID;
+import javax.xml.transform.Result;
+import java.util.*;
 
 
 @Service
@@ -41,6 +39,8 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationDao, Organi
     private OrganizationDepartmentUserService organizationDepartmentUserService;
     @Autowired
     private UserEnterpriseService userEnterpriseService;
+    @Autowired
+    private UserBypassAccountService userBypassAccountService;
 
     @Override
     public void saveMain(OrganizationVO request, SystemAdmin systemAdmin) {
@@ -93,8 +93,8 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationDao, Organi
         Organization organization = new Organization();
         BeanUtils.copyProperties(request, organization);
         this.updateById(organization);
-        List<UserEnterprise> userEnterprises= userEnterpriseService.selectByOrganId(id);
-        if (null!=userEnterprises&&userEnterprises.size()>0){
+        List<UserEnterprise> userEnterprises = userEnterpriseService.selectByOrganId(id);
+        if (null != userEnterprises && userEnterprises.size() > 0) {
             for (UserEnterprise userEnterpris : userEnterprises) {
                 String name = request.getName();
                 userEnterpris.setEnterpriseName(name);
@@ -104,7 +104,6 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationDao, Organi
         }
 
 
-
         List<OrganizationDepartmentVO> department = request.getChildren();
         for (OrganizationDepartmentVO departmentVO : department) {
             organizationDepartmentService.removeById(departmentVO.getId());
@@ -175,21 +174,63 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationDao, Organi
     }
 
     @Override
-    public void deleteDepartment(String id) {
+    public CommonResult<?> deleteDepartment(String id) {
+        OrganizationDepartment organizationDepartment = organizationDeparementDao.selectById(id);
+        String departmentName = organizationDepartment.getName();
+        String organizationId = organizationDepartment.getOrganizationId();
+
+        //企业账户
+        LambdaQueryWrapper<UserEnterprise> enterpriseLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        enterpriseLambdaQueryWrapper.eq(UserEnterprise::getOrganizationId,organizationId);
+        enterpriseLambdaQueryWrapper.eq(UserEnterprise::getDepartment,departmentName);
+        List<UserEnterprise> userEnterprises = userEnterpriseService.list(enterpriseLambdaQueryWrapper);
+        if (null != userEnterprises && userEnterprises.size() > 0){
+            return CommonResult.failed("该部门已关联企业账户,请解除关联后进行删除");
+        }
+
+        //企业子账户
+        LambdaQueryWrapper<UserBypassAccount> userBypassAccountLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        userBypassAccountLambdaQueryWrapper.eq(UserBypassAccount::getDepartmentId,id);
+        List<UserBypassAccount> userBypassAccounts = userBypassAccountService.list(userBypassAccountLambdaQueryWrapper);
+        if (null != userBypassAccounts && userBypassAccounts.size() > 0){
+            return CommonResult.failed("该部门已关联企业子账户,请解除关联后进行删除");
+        }
 
         organizationDeparementDao.deleteById(id);
         List<OrganizationDepartmentUser> organizationDepartmentUsers = organizationDeparementUserDao.selectMainBydepartmentId(id);
         for (OrganizationDepartmentUser user : organizationDepartmentUsers) {
             organizationDeparementUserDao.deleteById(user.getId());
         }
+        return CommonResult.success("操作成功");
 
     }
 
     @Override
-    public void deleteUser(String id) {
-
+    public CommonResult deleteUser(String id) {
+        OrganizationDepartmentUser organizationDepartmentUser = organizationDeparementUserDao.selectById(id);
+        String organizationId = organizationDepartmentUser.getOrganizationId();
+        String departmentId = organizationDepartmentUser.getDepartmentId();
+        OrganizationDepartment organizationDepartment = organizationDeparementDao.selectById(departmentId);
+        String departmentName = organizationDepartment.getName();
+        //企业账户
+        LambdaQueryWrapper<UserEnterprise> enterpriseLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        enterpriseLambdaQueryWrapper.eq(UserEnterprise::getOrganizationId,organizationId);
+        enterpriseLambdaQueryWrapper.eq(UserEnterprise::getDepartment,departmentName);
+        enterpriseLambdaQueryWrapper.eq(UserEnterprise::getRealName,organizationDepartmentUser.getName());
+        List<UserEnterprise> userEnterprises = userEnterpriseService.list(enterpriseLambdaQueryWrapper);
+        if (null != userEnterprises && userEnterprises.size() > 0){
+            return CommonResult.failed("该用户已关联企业账户,请解除关联后进行删除");
+        }
+        //企业子账户
+        LambdaQueryWrapper<UserBypassAccount> userBypassAccountLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        userBypassAccountLambdaQueryWrapper.eq(UserBypassAccount::getDepartmentId,departmentId);
+        userBypassAccountLambdaQueryWrapper.eq(UserBypassAccount::getRealName,organizationDepartmentUser.getName());
+        List<UserBypassAccount> userBypassAccounts = userBypassAccountService.list(userBypassAccountLambdaQueryWrapper);
+        if (null != userBypassAccounts && userBypassAccounts.size() > 0){
+            return CommonResult.failed("该用户已关联企业子账户,请解除关联后进行删除");
+        }
         organizationDeparementUserDao.deleteById(id);
-
+        return  CommonResult.success("操作成功");
 
     }
 
@@ -202,5 +243,28 @@ public class OrganizationServiceImpl extends ServiceImpl<OrganizationDao, Organi
         request.setUpdateBy(systemAdmin.getRealName());
         organizationDao.insert(request);
     }
+
+    @Override
+    public CommonResult<?> deleteOrgan(String id) {
+        List<UserEnterprise> userEnterprises = userEnterpriseService.selectByOrganId(id);
+        if (null != userEnterprises && userEnterprises.size() > 0){
+            return CommonResult.failed("该企业已关联企业账户,请解除关联后进行删除");
+        }
+        ArrayList<String> strings = new ArrayList<>();
+        LambdaQueryWrapper<OrganizationDepartment> departmentLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        departmentLambdaQueryWrapper.eq(OrganizationDepartment::getOrganizationId,id);
+        List<OrganizationDepartment> departmentList = organizationDeparementDao.selectList(departmentLambdaQueryWrapper);
+        for (OrganizationDepartment organizationDepartment : departmentList) {
+            strings.add(organizationDepartment.getId());
+        }
+        LambdaQueryWrapper<UserBypassAccount> accountLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        accountLambdaQueryWrapper.in(UserBypassAccount::getDepartmentId,strings);
+        List<UserBypassAccount> userBypassAccounts = userBypassAccountService.list(accountLambdaQueryWrapper);
+        if (null != userBypassAccounts && userBypassAccounts.size() > 0){
+            return CommonResult.failed("该企业已关联企业子账户,请解除关联后进行删除");
+        }
+        return  CommonResult.success("操作成功");
+
+    }
 }