forked from gzzfw/backEnd/gz-dyh

liyj
2024-09-10 76f4b32326c77b6a3b6742ab5d72f0b02320b62f
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
package cn.huge.module.kind.controller.client;
 
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.base.common.utils.ReturnFailUtils;
import cn.huge.base.common.utils.ReturnSucUtils;
import cn.huge.module.kind.domain.po.SyRegion;
import cn.huge.module.kind.service.SyRegionService;
import cn.huge.module.sys.dto.QueAddrBaseDTO;
import cn.huge.module.utils.BaiduMapAddrDTO;
import cn.huge.module.utils.BaiduMapUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * @title: 地域表接口api-web端
 * @description: 地域表接口api-web端
 * @company: hugeinfo
 * @author: wangwh
 * @time: 2024-09-04 16:48:57
 * @version: 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/api/client/syRegion")
public class SyregionClientController {
 
    @Autowired(required = false)
    private HttpServletRequest request;
 
    @Autowired
    private SyRegionService service;
 
    /**
     * 根据百度地图经纬度获取街道
     * @url {ctx}/api/client/syRegion/getQueAddrByBaiduiLngLat
     * @param lng 经度
     * @param lat 维度
     * @return
     */
    @GetMapping("/getQueAddrByBaiduiLngLat")
    public Object getQueAddrByBaiduiLngLat(@RequestParam(value = "lng") String lng, @RequestParam(value = "lat") String lat) {
        try {
            QueAddrBaseDTO syRegionBaseDTO = new QueAddrBaseDTO();
            BaiduMapAddrDTO baiduMapAddrDTO = BaiduMapUtils.getAddrByLngLat(lng, lat, BaiduMapUtils.coordtype_bd09ll);
            if (ObjectUtils.isNotEmpty(baiduMapAddrDTO)) {
                QueryWrapper<SyRegion> syRegionQueryWrapper = new QueryWrapper<>();
                // 查询省
                syRegionQueryWrapper.eq("name", baiduMapAddrDTO.getProvince());
                SyRegion province = service.getOne(syRegionQueryWrapper);
                syRegionBaseDTO.setQueProv(province.getId());
                syRegionBaseDTO.setQueProvName(province.getName());
                // 查询市
                syRegionQueryWrapper.eq("name", baiduMapAddrDTO.getCity());
                SyRegion city = service.getOne(syRegionQueryWrapper);
                syRegionBaseDTO.setQueProv(city.getId());
                syRegionBaseDTO.setQueProvName(city.getName());
                // 查询区
                syRegionQueryWrapper.eq("name", baiduMapAddrDTO.getDistrict());
                SyRegion district = service.getOne(syRegionQueryWrapper);
                syRegionBaseDTO.setQueProv(district.getId());
                syRegionBaseDTO.setQueProvName(district.getName());
                // 查询街道
                syRegionQueryWrapper.eq("name", baiduMapAddrDTO.getTown());
                SyRegion town = service.getOne(syRegionQueryWrapper);
                syRegionBaseDTO.setQueProv(town.getId());
                syRegionBaseDTO.setQueProvName(town.getName());
            }
            return ReturnSucUtils.getRepInfo(syRegionBaseDTO);
        } catch (Exception e) {
            return ReturnFailUtils.getRepInfo();
        }
    }
}