src/main/java/com/se/simu/controller/DbController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/domain/vo/QueryVo.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/service/DbService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/se/simu/service/GedbService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
src/main/java/com/se/simu/controller/DbController.java
@@ -1,14 +1,14 @@ package com.se.simu.controller; import com.se.simu.domain.vo.QueryVo; import com.se.simu.helper.StringHelper; import com.se.simu.helper.WebHelper; import com.se.simu.service.DbService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -32,4 +32,28 @@ WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, ex.getMessage()); } } @ApiOperation(value = "config") @GetMapping(value = "/config") public void config(HttpServletRequest req, HttpServletResponse res) { try { dbService.config(req, res); } catch (Exception ex) { WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, ex.getMessage()); } } @ApiOperation(value = "query") @PostMapping(value = "/query") public void query(@RequestBody QueryVo vo, HttpServletRequest req, HttpServletResponse res) { try { if (null == vo || StringHelper.isEmpty(vo.getLayerid())) throw new Exception("layerid涓嶈兘涓虹┖"); vo.setDefault(); dbService.query(vo, req, res); } catch (Exception ex) { WebHelper.writeJson2Page(res, HttpStatus.BAD_REQUEST, ex.getMessage()); } } } src/main/java/com/se/simu/domain/vo/QueryVo.java
对比新文件 @@ -0,0 +1,119 @@ package com.se.simu.domain.vo; import com.se.simu.helper.StringHelper; @SuppressWarnings("ALL") public class QueryVo { private String token; private Integer start; private Integer count; private String dbid; private String layerid; private Boolean containCount; private String where; private String querytype; private String geometry; public QueryVo() { } public void setDefault() { if (null == start || start < 1) start = 1; if (null == count || count < 0) count = 10; if (count > 10000) count = 10000; if (null == containCount) containCount = false; if (StringHelper.isEmpty(querytype)) querytype = "entity"; } public String getToken() { return token; } public void setToken(String token) { this.token = token; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public String getDbid() { return dbid; } public void setDbid(String dbid) { this.dbid = dbid; } public String getLayerid() { return layerid; } public void setLayerid(String layerid) { this.layerid = layerid; } public boolean isContainCount() { return containCount; } public void setContainCount(boolean containCount) { this.containCount = containCount; } public String getWhere() { return where; } public void setWhere(String where) { this.where = where; } public String getQuerytype() { return querytype; } public void setQuerytype(String querytype) { this.querytype = querytype; } public Integer getStart() { return start; } public void setStart(Integer start) { this.start = start; } public void setCount(Integer count) { this.count = count; } public Boolean getContainCount() { return containCount; } public void setContainCount(Boolean containCount) { this.containCount = containCount; } public String getGeometry() { return geometry; } public void setGeometry(String geometry) { this.geometry = geometry; } } src/main/java/com/se/simu/service/DbService.java
@@ -1,16 +1,21 @@ package com.se.simu.service; import cn.hutool.json.JSONObject; import com.se.simu.config.PropertiesConfig; import com.se.simu.domain.dto.GeDb; import com.se.simu.helper.HttpHelper; import com.se.simu.helper.StringHelper; import com.se.simu.domain.vo.QueryVo; import com.se.simu.helper.*; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Date; import java.util.HashMap; import java.util.Map; @Slf4j @Service @@ -20,13 +25,18 @@ PropertiesConfig config; @Resource RestTemplate restTemplate; @Resource GedbService gedbService; private final static String PUBLIC_KEY = "where_public_key"; private final static long ONE_DAY = 24 * 60 * 60 * 1000; public void info(HttpServletRequest req, HttpServletResponse res) throws Exception { String token = gedbService.getToken(); GeDb db = gedbService.getSeDb(token); GeDb db = gedbService.getGeDb(token); String date = StringHelper.YMD_FORMAT.format(new Date(System.currentTimeMillis() - ONE_DAY)); String uri = String.format("%sgeo-service/statis/layer/data/info?dbid=%s&token=%s&caldate=%s", config.getHost(), db.getDbid(), token, date); @@ -34,4 +44,58 @@ HttpHelper helper = new HttpHelper(); helper.service(req, res, uri); } public void config(HttpServletRequest req, HttpServletResponse res) throws Exception { String token = gedbService.getToken(); GeDb db = gedbService.getGeDb(token); String uri = String.format("%sgeo-service/entitydb/map/config?dbid=%s&token=%s", config.getHost(), db.getDbid(), token); HttpHelper helper = new HttpHelper(); helper.service(req, res, uri); } private String getPublicKey() { Object obj = CaffeineHelper.get(PUBLIC_KEY); if (obj instanceof GeDb) { return (String) obj; } JSONObject jsonObject = restTemplate.getForObject(config.getHost() + "geo-service/setting/publickey", JSONObject.class); String key = jsonObject.getStr("data"); if (!StringHelper.isEmpty(key)) { CaffeineHelper.put(PUBLIC_KEY, key); } return key; } public void query(QueryVo vo, HttpServletRequest req, HttpServletResponse res) throws Exception { String token = gedbService.getToken(); GeDb db = gedbService.getGeDb(token); String url = config.getHost() + "geo-service/entitydbdata/layer/query"; Map<String, Object> map = new HashMap<>(6); map.put("token", token); map.put("dbid", db.getDbid()); map.put("layerid", vo.getLayerid()); //map.put("returnCountOnly", true); //map.put("inSR", 4326); map.put("containCount", vo.getContainCount()); map.put("count", vo.getCount()); map.put("start", vo.getStart()); map.put("querytype", vo.getQuerytype()); if (StringHelper.isEmpty(vo.getWhere())) { RsaHelper.setPublicKey(getPublicKey()); String where = RsaHelper.encrypt(vo.getWhere()); map.put("where", vo.getWhere()); } if (!StringHelper.isEmpty(vo.getGeometry())) { map.put("geometry", vo.getGeometry()); } String rs = restTemplate.postForObject(url, map, String.class); WebHelper.writeStr2Page(res, HttpStatus.OK, rs); } } src/main/java/com/se/simu/service/GedbService.java
@@ -117,14 +117,14 @@ } public GeDb connectGedb(String token, DataPo data) { GeDb db = getSeDb(token); GeDb db = getGeDb(token); db.setBbox(data.getBbox()); data.setEpsg(db.getEpsg()); return db; } public GeDb getSeDb(String token) { public GeDb getGeDb(String token) { Object obj = CaffeineHelper.get(DB_KEY); if (obj instanceof GeDb) { return (GeDb) obj;