kaiyu
2022-03-14 5236663d1e40ca9ed0cbc0885cbc67a67c47943f
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Organization;
import com.moral.api.entity.ServicesScope;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.mapper.ServicesScopeMapper;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.ServicesScopeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import com.moral.util.RegionCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2022-01-19
 */
@Service
public class ServicesScopeServiceImpl extends ServiceImpl<ServicesScopeMapper, ServicesScope> implements ServicesScopeService {
 
    @Autowired
    private OrganizationMapper organizationMapper;
 
    @Autowired
    private ServicesScopeMapper servicesScopeMapper;
 
    @Autowired
    private OrganizationService organizationService;
 
    @Override
    public List<Map<String, Object>> getDateByOrgIdAndCondition(Map map) {
        int orgId = Integer.parseInt(map.get("organization_id").toString());
        //定义一个集合,存放所有id
        List<Integer> allOrgId = new ArrayList<>();
        allOrgId.add(orgId);
        //循环集合
        //所有子组织
        List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
        if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
            for (Organization organization:allChildrenOrganization) {
                allOrgId.add(organization.getId());
            }
        }
        //集合去重
        List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
        List<Map<String,Object>> resultList = new ArrayList<>();
        for (int organizationId:allOrgIdWithoutDuplicates) {
            Map<String,Object> resultMap = new HashMap<>();
            QueryWrapper<Organization> organizationQueryWrapper = new QueryWrapper<>();
            organizationQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
            organizationQueryWrapper.eq("id",organizationId);
            if (!ObjectUtils.isEmpty(map.get("regionCode"))){
                String region = RegionCodeUtils.regionCodeConvertToName(Integer.parseInt(map.get("regionCode").toString()));
                organizationQueryWrapper.eq(region,Integer.parseInt(map.get("regionCode").toString()));
            }
            Organization organization = new Organization();
            organization = organizationMapper.selectOne(organizationQueryWrapper);
            if (ObjectUtils.isEmpty(organization)){
                continue;
            }
            resultMap.put("id",organization.getId());
            resultMap.put("name",organization.getName());
            QueryWrapper<ServicesScope> servicesScopeQueryWrapper = new QueryWrapper<>();
            servicesScopeQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
            servicesScopeQueryWrapper.eq("organization_id",organizationId);
            if (!ObjectUtils.isEmpty(map.get("name"))){
                servicesScopeQueryWrapper.like("name",map.get("name").toString());
            }
            List<ServicesScope> servicesScopes = new ArrayList<>();
            servicesScopes = servicesScopeMapper.selectList(servicesScopeQueryWrapper);
            if (servicesScopes.size()<1){
                continue;
            }
            List<Map<String,Object>> servicesScopeList= new ArrayList<>();
            for (ServicesScope servicesScope:servicesScopes) {
                Map<String,Object> servicesScopeMap = new HashMap<>();
                servicesScopeMap.put("id",servicesScope.getId());
                servicesScopeMap.put("name",servicesScope.getName());
                servicesScopeMap.put("organizationId",servicesScope.getOrganizationId());
                servicesScopeMap.put("centerLongitude",servicesScope.getCenterLongitude());
                servicesScopeMap.put("centerLatitude",servicesScope.getCenterLatitude());
                servicesScopeList.add(servicesScopeMap);
            }
            resultMap.put("servicesScopes",servicesScopeList);
            resultList.add(resultMap);
        }
        if (resultList.size()<1){
            return null;
        }
        return resultList;
    }
 
    /*private OrganizationServicesScopeVO treeStructure(int orgId){
        OrganizationServicesScopeVO organizationServicesScopeVO = new OrganizationServicesScopeVO();
        Organization organization = organizationMapper.selectById(orgId);
        organizationServicesScopeVO.setOrganization(organization);
        QueryWrapper<Organization> chileOrganizationQueryWrapper = new QueryWrapper<>();
        chileOrganizationQueryWrapper.eq("is_delete",Constants.NOT_DELETE);
        chileOrganizationQueryWrapper.eq("parent_id",orgId);
        List<Organization> childOrganizations = new ArrayList<>();
        childOrganizations = organizationMapper.selectList(chileOrganizationQueryWrapper);
        if (childOrganizations.size()>0){
            List<OrganizationServicesScopeVO> organizationServicesScopeVOS = new ArrayList<>();
            for (Organization childOrganization:childOrganizations) {
                OrganizationServicesScopeVO organizationServicesScopeVO1 = treeStructure(childOrganization.getId());
                if (ObjectUtils.isEmpty(organizationServicesScopeVO1)){
                    organizationServicesScopeVOS.add(organizationServicesScopeVO1);
                }
            }
            organizationServicesScopeVO.setOrganizationServicesScopeVOS(organizationServicesScopeVOS);
        }
        //servicesScopeMapper.selectList()
        return null;
    }*/
}