Commit fabbc708 authored by fanjr's avatar fanjr

合作医院接口提交

parent 7e23423e
...@@ -5,9 +5,17 @@ import lombok.Data; ...@@ -5,9 +5,17 @@ import lombok.Data;
@Data @Data
public class HospitalVo { public class HospitalVo {
/* 主键id */
private Long id;
/* 医院名称 */ /* 医院名称 */
@ExportConfig(value = "name", width = 100, showLevel = 1) @ExportConfig(value = "name", width = 100, showLevel = 1)
private String name; private String name;
/* 经度 */
@ExportConfig(value = "经度", width = 100, showLevel = 1)
private String longitude;
/* 纬度 */
@ExportConfig(value = "纬度", width = 100, showLevel = 1)
private String latitude;
private Long page; private Long page;
private Long pageSize; private Long pageSize;
} }
...@@ -19,4 +19,12 @@ public interface HospitalService extends GenericService<Hospital> { ...@@ -19,4 +19,12 @@ public interface HospitalService extends GenericService<Hospital> {
*/ */
JSONObject hospitalList(HospitalVo vo); JSONObject hospitalList(HospitalVo vo);
/**
* 2021年2月18日
* 合作医院详情
* @param vo
* @return
*/
public JSONObject getHospitalDetailsById(HospitalVo vo);
} }
...@@ -14,8 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,8 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.*;
import java.util.Map;
/** /**
* 合作医院信息ServiceImpl * 合作医院信息ServiceImpl
...@@ -37,12 +36,32 @@ return hospitalMapper; ...@@ -37,12 +36,32 @@ return hospitalMapper;
@Override @Override
public JSONObject hospitalList(HospitalVo vo){ public JSONObject hospitalList(HospitalVo vo){
JSONObject rtnJson = new JSONObject(); JSONObject rtnJson = new JSONObject();
String lat = vo.getLatitude();
String lng = vo.getLongitude();
double lattarget = Double.valueOf(lat);
double lngtarget = Double.valueOf(lng);
// double lattarget = Double.valueOf("32.0572355");
// double lngtarget = Double.valueOf("118.77807441");
try { try {
List<Map<String,Object>> list = hospitalMapper.hospitalList(vo); List<Map<String,Object>> list = hospitalMapper.hospitalList(vo);
// CloseableHttpEntity che = TxMapUtils.sendHttpGet("上海市徐汇区漕河泾新兴技术开发区钦州北路1198号智慧园88号楼5层");
if (list != null&&list.size()>0) { if (list != null&&list.size()>0) {
Map<Double,Map> resultMap = new HashMap<Double,Map>();
double [] a=new double [list.size()];
for (Map<String,Object> map : list) {
double lat2 = Double.valueOf(map.get("latitude")+"");
double lng2 = Double.valueOf(map.get("longitude")+"");
double distance= TxMapUtils. getDistance(lattarget,lngtarget,lat2,lng2);
a[list.indexOf(map)]=distance;
map.put("distance",(double)Math.round(distance*100)/100);
resultMap.put(distance,map);
}
Arrays.sort(a);
List<Map<String,Object>> reltlist = new ArrayList<Map<String,Object>>();
for (int i=0;i<a.length;i++){
reltlist.add(resultMap.get(a[i]));
}
rtnJson.put("errorCode", 0); rtnJson.put("errorCode", 0);
rtnJson.put("data", list); rtnJson.put("data", reltlist);
} else { } else {
rtnJson.put("errorCode", 1); rtnJson.put("errorCode", 1);
rtnJson.put("errorMsg", "暂无数据"); rtnJson.put("errorMsg", "暂无数据");
...@@ -54,4 +73,24 @@ return hospitalMapper; ...@@ -54,4 +73,24 @@ return hospitalMapper;
} }
return rtnJson; return rtnJson;
} }
@Override
public JSONObject getHospitalDetailsById(HospitalVo vo){
JSONObject rtnJson = new JSONObject();
try {
Hospital info = hospitalMapper.fetchById(vo.getId());
if (info != null) {
rtnJson.put("errorCode", 0);
rtnJson.put("data", info);
} else {
rtnJson.put("errorCode", 1);
rtnJson.put("errorMsg", "暂无数据");
}
} catch (Exception e) {
e.printStackTrace();
rtnJson.put("errorCode", 1);
rtnJson.put("errorMsg", "合作医院详情" + e.getMessage());
}
return rtnJson;
}
} }
\ No newline at end of file
...@@ -32,6 +32,8 @@ public class TxMapUtils { ...@@ -32,6 +32,8 @@ public class TxMapUtils {
private static RequestConfig requestConfig = null; private static RequestConfig requestConfig = null;
private static double EARTH_RADIUS = 6378.137;
static { static {
requestConfig = RequestConfig.custom() requestConfig = RequestConfig.custom()
.setSocketTimeout(60000)//连接时间 .setSocketTimeout(60000)//连接时间
...@@ -55,6 +57,10 @@ public class TxMapUtils { ...@@ -55,6 +57,10 @@ public class TxMapUtils {
private static String SECERT_KEY = SystemConfig.p.getProperty("map.secret_key"); private static String SECERT_KEY = SystemConfig.p.getProperty("map.secret_key");
//private static String SECERT_KEY = "W1je0RfMuDsfxCy73M0b3iEfZRF5cAcU"; //private static String SECERT_KEY = "W1je0RfMuDsfxCy73M0b3iEfZRF5cAcU";
private static double rad(double d) {
return d * Math.PI / 180.0;
}
private static String getParamsSort(String url) { private static String getParamsSort(String url) {
if (!url.contains("?") || !url.contains("=")) { if (!url.contains("?") || !url.contains("=")) {
return null; return null;
...@@ -153,6 +159,30 @@ public class TxMapUtils { ...@@ -153,6 +159,30 @@ public class TxMapUtils {
return null; return null;
} }
/**
* 通过经纬度获取距离(单位:km)
*
* @param lat1 维度1
* @param lng1 经度1
* @param lat2 维度2
* @param lng2 经度2
* @return 距离
*/
public static double getDistance(double lat1, double lng1, double lat2,
double lng2) {
double radLat1 = rad(lat1);
double radLat2 = rad(lat2);
double a = radLat1 - radLat2;
double b = rad(lng1) - rad(lng2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(radLat1) * Math.cos(radLat2)
* Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000d) / 10000d;
return s;
}
public static void main(String[] args) { public static void main(String[] args) {
sendHttpGet("上海市徐汇区漕河泾新兴技术开发区钦州北路1198号智慧园88号楼5层"); sendHttpGet("上海市徐汇区漕河泾新兴技术开发区钦州北路1198号智慧园88号楼5层");
} }
......
...@@ -33,4 +33,20 @@ public class MobileHospitalController { ...@@ -33,4 +33,20 @@ public class MobileHospitalController {
public JSONObject hospitalList(HospitalVo vo) { public JSONObject hospitalList(HospitalVo vo) {
return hospitalService.hospitalList(vo); return hospitalService.hospitalList(vo);
} }
/**
* @Author Fanjr
* @Description 医院详情
* @Date 2021年2月18日
* @Param
* @return
**/
@RequestMapping(value = "/getHospitalDetailsById",
method = {RequestMethod.GET, RequestMethod.POST},
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JSONObject getHospitalDetailsById(HospitalVo vo) {
return hospitalService.getHospitalDetailsById(vo);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment