fix
Helius
2021-08-05 8bbb027dc36b3f3c7f2d505fc75180261fb4d640
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.xzx.gc.user.service;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.xzx.gc.common.Result;
import com.xzx.gc.common.dto.gdmap.GdReverseGEODto;
import com.xzx.gc.common.exception.RestException;
import com.xzx.gc.common.utils.BusinessUtil;
import com.xzx.gc.common.utils.gdmap.GdMapUtil;
import com.xzx.gc.entity.AddressInfo;
import com.xzx.gc.entity.AddressLevelInfo;
import com.xzx.gc.user.mapper.AddressLevelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
@Service
@Transactional
public class AddressLevelService {
 
    @Autowired
    private AddressLevelMapper addressLevelMapper;
 
    @Autowired
    private BusinessUtil businessUtil;
 
    @Autowired
    private CityPartnerService cityPartnerService;
 
    @Autowired
    private PartnerGaodeService partnerGaodeService;
 
 
    public AddressLevelInfo findByLocation(String lon,String lat){
        GdReverseGEODto gdReverseGEODto = new GdReverseGEODto();
        gdReverseGEODto.setLocation(lon+","+lat);
        Result areaInfo = GdMapUtil.getAreaInfo(gdReverseGEODto, 0);
        if(areaInfo.getCode()==0){
            AddressInfo addressInfo1= (AddressInfo) areaInfo.getData();
            AddressLevelInfo byAdcode = findByAdcode(addressInfo1.getAdcode());
            if(byAdcode!=null){
               return byAdcode;
            }else {
                throw new RestException("定位异常:"+addressInfo1.getAdcode());
            }
        }else {
            throw new RestException("定位异常:"+areaInfo.getMsg());
        }
    }
 
    public List<AddressLevelInfo> findByTownIds(String townIds){
        if(StrUtil.isNotBlank(townIds)) {
            Example example = new Example(AddressLevelInfo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andIn("level3Id", CollUtil.newArrayList(townIds.split(",")));
            List<AddressLevelInfo> addressLevelInfos = addressLevelMapper.selectByExample(example);
            return addressLevelInfos;
        }else {
            return new ArrayList<>();
        }
    }
 
    public AddressLevelInfo find(String level1Id,String level2Id,String level3Id){
        /**
         *   private String level1Id;
         *     @Column(name = "level_1_name")
         *     private String level1Name;
         *     @Column(name = "level_2_id")
         *     private String level2Id;
         *     @Column(name = "level_2_name")
         *     private String level2Name;
         *     @Column(name = "level_3_id")
         *     private String level3Id;
         */
        Example example = new Example(AddressLevelInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("level3Id", level3Id);
        criteria.andEqualTo("level2Id", level2Id);
        criteria.andEqualTo("level1Id", level1Id);
        List<AddressLevelInfo> addressLevelInfos = addressLevelMapper.selectByExample(example);
        if (CollUtil.isNotEmpty(addressLevelInfos)) {
            return addressLevelInfos.get(0);
        }
        return null;
    }
 
    /**
     * 根据任意条件查询
     * @param addressLevelInfo
     * @return
     */
    public List<AddressLevelInfo> findByAny(AddressLevelInfo addressLevelInfo){
        if(StrUtil.isNotBlank(addressLevelInfo.getLevel3Name())){
            addressLevelInfo.setLevel3Name(businessUtil.changeArea(addressLevelInfo.getLevel3Name()));
        }
 
        List<AddressLevelInfo> addressLevelInfos = addressLevelMapper.select(addressLevelInfo);
        if(CollUtil.isNotEmpty(addressLevelInfos)){
            for (AddressLevelInfo levelInfo : addressLevelInfos) {
                levelInfo.setLevel3Name(businessUtil.changeArea(levelInfo.getLevel3Name()));
            }
        }
        return addressLevelInfos;
    }
 
    public AddressLevelInfo findByAdcode(String adcode){
        Example example = new Example(AddressLevelInfo.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("adcode", adcode);
        AddressLevelInfo addressLevelInfos = addressLevelMapper.selectOneByExample(example);
        return addressLevelInfos;
    }
 
    public List<Map<String, Object>>  queryAllProvince(String level){
        List<Map<String, Object>> result;
        result = addressLevelMapper.queryAllProvince();
        for (Map<String, Object> pMap:result) {
            List<Map<String, Object>> cList  = addressLevelMapper.queryAllCity(pMap.get("code").toString());
            for (Map<String, Object> cMap:cList) {
                if(null!=cMap){
                    if(null!=cMap.get("code")){
                        List<Map<String, Object>> tList  = addressLevelMapper.queryAllArea(cMap.get("code").toString());
                        cMap.put("children",tList);
                    }
                }
 
            }
            pMap.put("children",cList);
        }
        return result;
    }
 
    public List<Map<String,Object>> queryApiArea(){
        List<String> partnerIds = cityPartnerService.queryPartnerByCurrent();
        List<String> townModel = new ArrayList<>();
        if(null!=partnerIds&&partnerIds.size()>0){
            String partnerId= partnerIds.get(0);
            townModel =partnerGaodeService.queryAreaByParentner(partnerId);
        }else{
            townModel =partnerGaodeService.queryAreaByParentner(null);
 
        }
        List<Map<String,Object>> areaList = addressLevelMapper.queryApiArea(townModel);
        return areaList;
    }
}