fs-danaus
2024-07-02 dbf53543a56970c7e10b6e274ff682ff4ebdaebe
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
package com.yc.sdk.huaweimap.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.yc.action.BaseAction;
import com.yc.exception.ApplicationException;
import com.yc.exception.CallBackMessage;
import com.yc.factory.FactoryBean;
import com.yc.sdk.huaweimap.entity.CustomerEntity;
import com.yc.sdk.map.entity.SearchEntity;
import com.yc.sdk.map.service.MapService;
import com.yc.service.BaseService;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 华为地图服务
 */
@RestController
public class HuaweiMapController extends BaseAction {
    /**
     * 周边搜索
     *
     * @param request
     * @return 返回结果
     */
    @RequestMapping(value = "/app/map/nearbySearch.do", method = RequestMethod.POST)
    @CrossOrigin
    public @ResponseBody Object nearbySearch(@RequestBody SearchEntity searchEntity,
                                             HttpServletRequest request) {
        CallBackMessage callBackMessage = new CallBackMessage();
        try {
            if (searchEntity == null) {
                throw new ApplicationException("参数不能为空");
            }
            Object result = MapService.getMapFactory().nearbySearch(searchEntity,request);
            callBackMessage.sendSuccessMessageByDefault();
            callBackMessage.setInfo(result);
            return callBackMessage.toJSONObject();
        } catch (Exception ex) {
            callBackMessage.sendErrorMessage(this.getErrorMsg(ex));
            return callBackMessage.toJSONObject();
        }
    }
    /**
     * 更新客户地址和经纬度
     *
     * @param request
     * @return 返回客户列表
     */
    @RequestMapping(value = "/app/map/updateCustomer.do", method = RequestMethod.POST)
    @CrossOrigin
    public @ResponseBody Object updateCustomer(@RequestBody CustomerEntity customerEntity,
                                             HttpServletRequest request) {
        CallBackMessage callBackMessage = new CallBackMessage();
        BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
        Integer result = baseService.getJdbcTemplate().queryForObject("update  a set a.longitude=? ,a.latitude=?,a.fullAddressName=? from t110203 a where a.cltCode=?;select @@rowcount", Integer.class, customerEntity.getLongitude(), customerEntity.getLatitude(), customerEntity.getFullAddressName(), customerEntity.getCltCode());
        if(result==1){
            callBackMessage.sendSuccessMessageByDefault();
        }else {
            callBackMessage.sendErrorMessage("更新失败");
        }
        return callBackMessage.toJSONObject();
    }
    /**
     * 客户列表
     *
     * @param request
     * @return 返回客户列表
     */
    @RequestMapping(value = "/app/map/customerList.do", method = RequestMethod.POST)
    @CrossOrigin
    public @ResponseBody Object customerList(@RequestBody CustomerEntity customerEntity,
                                             HttpServletRequest request) {
        CallBackMessage callBackMessage = new CallBackMessage();
        try {
            if (customerEntity == null) {
                throw new ApplicationException("参数不能为空");
            }
            /*if(customerEntity.getLatitude()==null){
                throw new ApplicationException("纬度不能为空");
            }
            if(customerEntity.getLongitude()==null){
                throw new ApplicationException("经度不能为空");
            }*/
            Object result = MapService.getMapFactory().customerList(customerEntity,request);
            //输出客户分类
            List<Map<String, Object>> cltTypes = new ArrayList<>();
            List<Map<String,Object>> raiduslist=new ArrayList<>();
if(customerEntity.getPageIndex()==1) {
    BaseService baseService = (BaseService) FactoryBean.getBean("BaseService");
    cltTypes = baseService.getJdbcTemplate().queryForList("select cltType as cltTypeId,cltType as cltTypeName from t110201 where isnull(cltType,'')<>''");
    //查找范围数据
    raiduslist =getRaidusList();
}
            Map data=new HashMap();
            data.put("cltTypeList",cltTypes);
            data.put("data",result);
            data.put("radiusList", raiduslist);
            callBackMessage.sendSuccessMessageByDefault();
            callBackMessage.setInfo(data);
            return callBackMessage.toJSONObject();
        } catch (Exception ex) {
            callBackMessage.sendErrorMessage(this.getErrorMsg(ex));
            return callBackMessage.toJSONObject();
        }
    }
 
    private static List<Map<String,Object>> getRaidusList() {
        List<Map<String,Object>> raidusList = new ArrayList<Map<String,Object>>();
 
        String json="[{\"raidusId\":200,\"raidusName\": \"200m\"},{\"raidusId\":500,\"raidusName\": \"500m\"},{\"raidusId\":1000,\"raidusName\": \"1km\"},{\"raidusId\":1500,\"raidusName\": \"1km-1.5km\"},{\"raidusId\":2000,\"raidusName\": \"1.5km-2km\"},{\"raidusId\":2000000,\"raidusName\" :\"2km以上\"}]";
        raidusList= JSON.parseObject(json,new TypeReference<List<Map<String,Object>>>(){});
        return raidusList;
    }
 
    /**
     * 关键字搜索
     *
     * @param request
     * @return 返回结果
     */
    @RequestMapping(value = "/app/map/searchByText.do", method = RequestMethod.POST)
    @CrossOrigin
    public @ResponseBody Object searchByText(@RequestBody SearchEntity searchEntity,
                                             HttpServletRequest request) {
        CallBackMessage callBackMessage = new CallBackMessage();
        try {
            if (searchEntity == null) {
                throw new ApplicationException("参数不能为空");
            }
            Object result = MapService.getMapFactory().searchByText(searchEntity,request);
            callBackMessage.sendSuccessMessageByDefault();
            callBackMessage.setInfo(result);
            return callBackMessage.toJSONObject();
        } catch (Exception ex) {
            callBackMessage.sendErrorMessage(this.getErrorMsg(ex));
            return callBackMessage.toJSONObject();
        }
    }
}