| | |
| | | package com.se.simu.service; |
| | | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.se.simu.config.PropertiesConfig; |
| | | import com.se.simu.domain.dto.GeDb; |
| | | import com.se.simu.domain.vo.QueryVo; |
| | |
| | | @Resource |
| | | GedbService gedbService; |
| | | |
| | | private final static String PUBLIC_KEY = "where_public_key"; |
| | | private final static String INFO_KEY = "db_info_key"; |
| | | |
| | | private final static String CONFIG_KEY = "db_config_key"; |
| | | |
| | | private final static String PUBLIC_KEY = "db_public_key"; |
| | | |
| | | private final static long ONE_DAY = 24 * 60 * 60 * 1000; |
| | | |
| | | public void info(HttpServletRequest req, HttpServletResponse res) throws Exception { |
| | | // helper.service(req, res, uri); |
| | | public String info() throws Exception { |
| | | Object obj = CaffeineHelper.get(INFO_KEY); |
| | | if (obj instanceof String) { |
| | | return (String) obj; |
| | | } |
| | | |
| | | String token = gedbService.getToken(); |
| | | GeDb db = gedbService.getGeDb(token); |
| | | String date = StringHelper.YMD_FORMAT.format(new Date(System.currentTimeMillis() - ONE_DAY)); |
| | | String url = String.format("%sgeo-service/statis/layer/data/info?dbid=%s&token=%s&caldate=%s", config.getHost(), db.getDbid(), token, date); |
| | | |
| | | String uri = String.format("%sgeo-service/statis/layer/data/info?dbid=%s&token=%s&caldate=%s", config.getHost(), db.getDbid(), token, date); |
| | | String rs = restTemplate.getForObject(url, String.class); |
| | | if (!StringHelper.isEmpty(rs)) { |
| | | CaffeineHelper.put(INFO_KEY, rs); |
| | | } |
| | | |
| | | HttpHelper helper = new HttpHelper(); |
| | | helper.service(req, res, uri); |
| | | return rs; |
| | | } |
| | | |
| | | public void config(HttpServletRequest req, HttpServletResponse res) throws Exception { |
| | | public String getConfig() throws Exception { |
| | | Object obj = CaffeineHelper.get(CONFIG_KEY); |
| | | if (obj instanceof String) { |
| | | return (String) obj; |
| | | } |
| | | |
| | | String token = gedbService.getToken(); |
| | | GeDb db = gedbService.getGeDb(token); |
| | | String url = String.format("%sgeo-service/entitydb/map/getConfig?dbid=%s&token=%s", config.getHost(), db.getDbid(), token); |
| | | |
| | | String uri = String.format("%sgeo-service/entitydb/map/config?dbid=%s&token=%s", config.getHost(), db.getDbid(), token); |
| | | String rs = restTemplate.getForObject(url, String.class); |
| | | if (!StringHelper.isEmpty(rs)) { |
| | | CaffeineHelper.put(CONFIG_KEY, rs); |
| | | } |
| | | |
| | | HttpHelper helper = new HttpHelper(); |
| | | helper.service(req, res, uri); |
| | | return rs; |
| | | } |
| | | |
| | | 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.getReturnGeom() ? getQueryType(vo.getLayerid()) : "entity"); |
| | | if (!StringHelper.isEmpty(vo.getWhere())) { |
| | | String where = RsaHelper.encrypt(getPublicKey(), vo.getWhere()); |
| | | map.put("where", where); |
| | | } |
| | | if (!StringHelper.isEmpty(vo.getGeometry())) { |
| | | Geometry g = Geometry.CreateFromWkt(vo.getGeometry()); |
| | | if (null != vo.getBuffer()) { |
| | | // 别问这个数怎么来的,凭本事猜的 |
| | | g = g.Buffer(vo.getBuffer() * 0.00000899928); |
| | | } |
| | | |
| | | map.put("geometry", g.ExportToWkt()); |
| | | map.put("inSR", 4326); |
| | | } |
| | | |
| | | String rs = restTemplate.postForObject(url, map, String.class); |
| | | WebHelper.writeStr2Page(res, HttpStatus.OK, rs); |
| | | } |
| | | |
| | | private String getPublicKey() { |
| | |
| | | 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"; |
| | | private String getQueryType(String layerid) { |
| | | try { |
| | | String json = getConfig(); |
| | | JSONObject obj = JSONUtil.parseObj(json); |
| | | |
| | | 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", "entity"); |
| | | if (!StringHelper.isEmpty(vo.getWhere())) { |
| | | String where = RsaHelper.encrypt(getPublicKey(), vo.getWhere()); |
| | | map.put("where", where); |
| | | } |
| | | if (!StringHelper.isEmpty(vo.getGeometry())) { |
| | | Geometry g = Geometry.CreateFromWkt(vo.getGeometry()); |
| | | if (null != vo.getBuffer()) { |
| | | // 别问这个数怎么来的,凭本事猜的 |
| | | g = g.Buffer(vo.getBuffer() * 0.00000899928); |
| | | JSONArray layers = obj.getJSONObject("data").getJSONArray("layers"); |
| | | for (int i = 0, c = layers.size(); i < c; i++) { |
| | | JSONObject layer = layers.getJSONObject(i); |
| | | if (layerid.equals(layer.getStr("id"))) { |
| | | return GedbService.getQueryType(layer); |
| | | } |
| | | } |
| | | |
| | | map.put("geometry", g.ExportToWkt()); |
| | | map.put("inSR", 4326); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | String rs = restTemplate.postForObject(url, map, String.class); |
| | | WebHelper.writeStr2Page(res, HttpStatus.OK, rs); |
| | | return "entity"; |
| | | } |
| | | } |