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();
|
}
|
}
|
}
|