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