jinpengyong
2023-10-31 69790994b403a61e92a20cef7451b7f087b50ad2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.config.Interceptor.UserHelper;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.entity.Organization;
import com.moral.api.mapper.MonitorPointMapper;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.pojo.vo.user.QxUser;
import com.moral.api.service.DeviceService;
import com.moral.api.service.MonitorPointService;
import com.moral.api.service.OrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 组织表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-04-06
 */
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService {
 
    @Autowired
    OrganizationMapper organizationMapper;
 
 
 
    @Override
    public List<Organization> getChildrenOrganizationsById(Integer id) {
        List<Organization> childrenOrganization = new ArrayList<>();
        recursionQueryChildren(id,childrenOrganization);
        return childrenOrganization;
    }
 
    @Override
    public Organization getOrganizationById(Integer id) {
        return organizationMapper.selectById(id);
    }
 
 
 
    /**
    * @Description: 通过父组织查询下面所有的子组织放到children中
            * @Param: [parentId, children]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/7/1
            */
    private void recursionQueryChildren(Integer parentId, List<Organization> children) {
        QueryWrapper<Organization> queryWrapper = new QueryWrapper();
        queryWrapper.select("id");
        queryWrapper.eq("is_delete", Constants.NOT_DELETE);
        queryWrapper.eq("parent_id", parentId);
        List<Organization> organizations = organizationMapper.selectList(queryWrapper);
        if (!ObjectUtils.isEmpty(organizations)) {
            children.addAll(organizations);
            for (Organization organization : organizations) {
                recursionQueryChildren(organization.getId(), children);
            }
        } else {
            return;
        }
    }
}