lizijie
2021-05-31 5bacbb17debde58d6ff2581e4a03a866ca009c02
screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -91,26 +91,10 @@
            organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST.getMsg());
            return organizationDTO;
        }
        //查询父组织是否存在
        Integer parentId = organization.getParentId();
        Organization parentOrganization = new Organization();
        if (!ObjectUtils.isEmpty(parentId)) {
            parentOrganization.setId(parentId);
            parentOrganization.setIsDelete(Constants.NOT_DELETE);
            queryWrapper.setEntity(parentOrganization);
            parentOrganization = organizationMapper.selectOne(queryWrapper);
            if (ObjectUtils.isEmpty(parentOrganization)) {
                organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getCode());
                organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getMsg());
                return organizationDTO;
            }
        }
        //插入组织
        organizationMapper.insert(organization);
        //封装DTO信息
        organizationDTO.setParentOrganization(parentOrganization);
        organizationDTO.setOrganization(organization);
        organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
@@ -149,21 +133,6 @@
            return organizationDTO;
        }
        //如果更改了父组织,查询父组织是否存在
        Integer parentId = organization.getParentId();
        Organization parentOrganization = new Organization();
        if (!ObjectUtils.isEmpty(parentId) && parentId != 0) {
            QueryWrapper<Organization> existParentWrapper = new QueryWrapper<>();
            parentOrganization.setId(parentId);
            parentOrganization.setIsDelete(Constants.NOT_DELETE);
            existParentWrapper.setEntity(parentOrganization);
            parentOrganization = organizationMapper.selectOne(existParentWrapper);
            if (ObjectUtils.isEmpty(parentOrganization)) {
                organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getCode());
                organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getMsg());
                return organizationDTO;
            }
        }
        //更新组织
        organizationMapper.updateById(organization);
@@ -172,8 +141,6 @@
        organization = organizationMapper.selectById(organization.getId());
        //封装DTO信息
        organizationDTO.setParentOrganization(parentOrganization);
        organizationDTO.setOrganization(organization);
        organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
        organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
@@ -182,6 +149,8 @@
        return organizationDTO;
    }
    /**
     * @Description: 删除客户组织
@@ -197,7 +166,7 @@
        //取参
        Integer id = form.getOrganizationId();
        //查询组织是否存在
        //查询要删除的组织用于插入日志
        Organization existOrganization = new Organization();
        existOrganization.setIsDelete(Constants.NOT_DELETE);
        existOrganization.setId(id);
@@ -217,7 +186,7 @@
        organizationMapper.update(null, deleteWrapper);
        //删除组织账号
        userService.deleteUserByOrganizationId(id);
        userService.deleteUsersByOrganizationId(id);
        //判断是否含有子组织
        List<Organization> children = getAllChildrenOrganization(existOrganization.getId());
@@ -235,7 +204,7 @@
                updateWrapper.set("is_delete", Constants.DELETE);
                organizationMapper.update(null, updateWrapper);
                //删除所有子组织账号
                childrenId.forEach(value->userService.deleteUserByOrganizationId(value));
                childrenId.forEach(value->userService.deleteUsersByOrganizationId(value));
            } else {//不删除
                //提取所有直属子组织id
@@ -252,7 +221,6 @@
        }
        //封装返回结果
        dto.setOrganization(existOrganization);
        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        //操作插入日志
@@ -355,7 +323,7 @@
        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
        dto.setOrganizationDTOS(organizationDTOS);
        dto.setCurrent(page.getCurrent());
        dto.setPage(page.getPages());
        dto.setPages(page.getPages());
        dto.setSize(page.getSize());
        dto.setTotal(page.getTotal());
        return dto;
@@ -379,7 +347,7 @@
        queryWrapper.eq("is_delete", Constants.NOT_DELETE);
        //查询所有组织
        List<Organization> organizations = organizationMapper.selectList(queryWrapper);
        //判断form是否含有id,如果有则对所有组织进行过滤
        //判断form是否含有id,如果有则对其所有子组织进行过滤
        if(!ObjectUtils.isEmpty(id)){
            List<Organization> children = getAllChildrenOrganization(id);
            List<Integer> thisAndchildrenIds = new ArrayList<>();//该id以及其所有子组织的id集合