package com.terra.proxy.controller;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
import com.alibaba.excel.EasyExcel;
|
import com.alibaba.fastjson.JSONObject;
|
import com.google.gson.Gson;
|
import com.google.gson.internal.LinkedTreeMap;
|
import com.terra.proxy.bean.Content;
|
import com.terra.proxy.bean.E;
|
import com.terra.proxy.bean.ServerExcelApplyEntity;
|
import com.terra.proxy.intercepter.ServiceExcelListener;
|
import com.terra.proxy.mapper.ApproveDao;
|
import com.terra.proxy.service.Impl.LogServiceImpl;
|
import com.terra.proxy.service.Impl.ServerRegisterServiceImpl;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpMethod;
|
import org.springframework.http.ResponseEntity;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.client.RestTemplate;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.File;
|
import java.io.FileNotFoundException;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.net.URI;
|
import java.net.URISyntaxException;
|
import java.nio.charset.StandardCharsets;
|
import java.util.*;
|
|
@RestController
|
public class TestController {
|
|
@Autowired
|
private ServerRegisterServiceImpl registerService;
|
|
@Autowired
|
private LogServiceImpl logService;
|
|
@Autowired
|
private ApproveDao approveDao;
|
|
@RequestMapping(value="/test")
|
@ResponseBody
|
public String test(@RequestParam Map<String,Object> str) throws InterruptedException {
|
System.out.println(JSONObject.toJSONString(str));
|
return JSONObject.toJSONString(str);
|
}
|
|
@RequestMapping("/sde")
|
public String sde( ) throws FileNotFoundException {
|
List<E> list=approveDao.selectAll();
|
List<E> data = new ArrayList<>();
|
for (E e : list) {
|
Object content = e.getContent();
|
if(null!=content){
|
String c = (String) content;
|
List<Content> content1 = JSONObject.parseArray(c, Content.class);
|
for (Content content2 : content1) {
|
E e1 = new E();
|
BeanUtil.copyProperties(e,e1);
|
e1.setLgtd(content2.getLgtd());
|
e1.setLttd(content2.getLttd());
|
e1.setText(content2.getText());
|
data.add(e1);
|
}
|
}else{
|
data.add(e);
|
}
|
}
|
File file = new File("D:\\2345\\0924\\test.xlsx");
|
EasyExcel.write(new FileOutputStream(file),E.class).sheet().doWrite(data);
|
return null;
|
}
|
|
|
@RequestMapping("/testPaath")
|
public String testPath(HttpServletRequest request) {
|
return null;
|
}
|
|
@RequestMapping("/test/addList")
|
public String addList() {
|
RestTemplate restTemplate = new RestTemplate();
|
HttpHeaders httpHeader = new HttpHeaders();
|
String cookieStr="sid=4433a513-3e75-4d9e-831d-98b041108003; JSESSIONID=648F33D259FAD5EF49338EAF516691AF; rememberMe=/zfA7SyRVnGeU4vZZqxwjBGYuYV9qj2xZ3oQoPxXkBba2BrrMAmZSovam/kn3uV2WF3cvloVY5Xcti4nueHPjcN6JWXuMbsdbq+w4eKoyz46GitbVxO3MAJcJRvuIdQ5JBU/v2z68vnuXLLghK4nho+2MSsHgMRQKPJsTaqhuvNdtsno6tWzBq00/DkT/idDzUMwuHfSI0P4C8O+sUcYxVtdfKXg2L4PzctREvOgsSKR2EMHOoGj0E/T7pFIq3qGpnDrKa/V+mcYkSwGMFxbvBZLsWpPmFleJRRt60gpHeVaPA4R+aTVVzvWPKGf0sEKh4FggfPhS80WjCsYqBhoBsIWWqukO0lJkGnJSHchJgNCqbU9jDxLohICqssQAn6T2zTeqHJtcj+adWHXanhtHe1+g9CPPmWxHS7r1J/nszdrHos1PgLUCoUKLXfFTM5dyaCYL4ficggm4q0MXny7SH41UTF3hOAeZ/LOqvhauT7ggm+dT0s0VGCWYMXLeviV";
|
ArrayList<String> arrayList = new ArrayList<>();
|
arrayList.add(cookieStr);
|
httpHeader.put("Cookie",arrayList);
|
String urlForList="http://71.3.251.65:8080/hdhj/approve/base/page/list";
|
String urlForId="http://71.3.251.65:8080/hdhj/approve/base/list/";
|
HttpEntity<String> request = new HttpEntity<>(null, httpHeader);
|
ResponseEntity<JSONObject> exchange = restTemplate.exchange(urlForList, HttpMethod.GET, request, JSONObject.class);
|
JSONObject body = exchange.getBody();
|
Object data=null;
|
List<Map<String,Object>> dataMap= (List<Map<String,Object>>) body.get("data");
|
for (Map map : dataMap) {
|
HashMap<String, Object> param = new HashMap<>();
|
param.put("seaArea",(String)map.get("seaArea"));
|
param.put("id",(String)map.get("id"));
|
approveDao.updateSeaArea(param);
|
}
|
return null;
|
}
|
|
|
|
public static void main(String[] args) {
|
String excel="D:\\2345\\0812\\excel\\newExcel.xlsx";
|
String newExcel="D:\\2345\\0812\\excel\\广东服务注册源模版20210812.xlsx";
|
File file = new File(excel);
|
File newFile = new File(newExcel);
|
int i=0;
|
Map<String,String> param= new HashMap<>();
|
List<ServerExcelApplyEntity> lists = EasyExcel.read(file, ServerExcelApplyEntity.class,new ServiceExcelListener()).doReadAllSync();
|
List<ServerExcelApplyEntity> oldLists = EasyExcel.read(newFile,ServerExcelApplyEntity.class,new ServiceExcelListener()).sheet("服务注册表").doReadSync();
|
for (ServerExcelApplyEntity list : lists) {
|
String serverUrl = list.getServerUrl();
|
if(serverUrl.contains("MapServer")){
|
String[] mapServers = serverUrl.split("MapServer/");
|
String substring = mapServers[1];
|
param.put(list.getZyId().toString(),substring);
|
}
|
}
|
for (Map.Entry<String, String> entry : param.entrySet()) {
|
String key = entry.getKey();
|
String value = entry.getValue();
|
oldLists.stream().forEach(
|
s->{
|
if(StringUtils.equals(key,s.getZyId().toString())){
|
String[] split = s.getServerUrl().split("=");
|
s.setServerUrl(split[0]+"=show:"+value);
|
}
|
}
|
);
|
}
|
String path="D:\\2345\\0812\\excel\\0812\\newExce.xlsx";
|
EasyExcel.write(path, ServerExcelApplyEntity.class).sheet("服务注册表").doWrite(oldLists);
|
}
|
|
|
|
|
@RequestMapping("/test/excelUpdate")
|
public String getUser() {
|
String path="D:\\2345\\0812\\excel\\0812\\newExce.xlsx";
|
Map<String,Object> map =new HashMap<>();
|
List<ServerExcelApplyEntity> oldLists = EasyExcel.read(path,ServerExcelApplyEntity.class,new ServiceExcelListener()).doReadAllSync();
|
oldLists.forEach(s->{
|
String serverUrl = s.getServerUrl();
|
System.out.println("serverUrl = " + serverUrl);
|
Integer zyId = s.getZyId();
|
System.out.println("resourceid = " + zyId);
|
map.put("serverurl",serverUrl);
|
map.put("resourceid",zyId);
|
map.clear();
|
});
|
|
return null;
|
}
|
|
@RequestMapping("/testMap")
|
public String testMap(HttpServletResponse response) {
|
RestTemplate restTemplate = new RestTemplate();
|
String url="http://71.3.251.50:6080/arcgis/rest/services/HYQY/HYQY_GD_CGCS2000/MapServer/export?bbox=90%2C0%2C135%2C45&size=256%2C256&format=png&transparent=true&f=image&bboxSR=4326&imageSR=4326";
|
HttpHeaders httpHeader = new HttpHeaders();
|
HttpEntity<String> request = new HttpEntity<>(null, httpHeader);
|
Boolean htmlFlag=true;
|
try {
|
URI uri = new URI(url);
|
ResponseEntity<byte[]> exchange = restTemplate.exchange(uri, HttpMethod.GET, request, byte[].class);
|
HttpHeaders headers = exchange.getHeaders();
|
Set<Map.Entry<String, List<String>>> entries = headers.entrySet();
|
for (Map.Entry<String, List<String>> next : entries) {
|
String key = next.getKey();
|
List<String> value = next.getValue();
|
for (String s : value) {
|
if (s.toUpperCase().contains("IMAGE")) htmlFlag = false;
|
System.out.println(key + " =" + s);
|
response.setHeader(key, s);
|
}
|
}
|
byte[] body = exchange.getBody();
|
if(htmlFlag){
|
String string = new String(body);
|
String regx="<a[^>]+>([^<]+</a>)";//a标签过滤
|
string=string.replaceAll(regx,"");
|
response.getOutputStream().write(string.getBytes(StandardCharsets.UTF_8));
|
}else {
|
response.getOutputStream().write(body);
|
}
|
|
|
} catch (IOException | URISyntaxException e) {
|
e.printStackTrace();
|
}
|
return null;
|
}
|
|
|
@RequestMapping("/sde/1012")
|
public String updateGemo() {
|
List<E> list = approveDao.selectEXTENDFILESPOINT();
|
Gson gson = new Gson();
|
|
for (E e : list) {
|
String wkt = e.getContent();
|
int count = StringUtils.countMatches(wkt, "text");
|
if(count==1){
|
//点
|
|
StringBuilder geom= new StringBuilder();
|
|
ArrayList arrayList = gson.fromJson(wkt, ArrayList.class);
|
|
LinkedTreeMap map = (LinkedTreeMap) arrayList.get(0);
|
|
geom.append("").append(map.get("lgtd")).append(" ").append(map.get("lttd")).append("");
|
|
HashMap<String, Object> param = new HashMap<>();
|
|
param.put("geom","'POLYGON("+geom+","+geom+")'");
|
|
param.put("id",e.getId());
|
continue;
|
}else {
|
//多点
|
StringBuilder geom= new StringBuilder();
|
ArrayList arrayList = gson.fromJson(wkt, ArrayList.class);
|
String index="";
|
for (int i = 0; i <arrayList.size() ; i++) {
|
LinkedTreeMap map = (LinkedTreeMap) arrayList.get(i);
|
if(i==arrayList.size()-1){
|
geom.append("").append(map.get("lgtd")).append(" ").append(map.get("lttd")).append("");
|
geom.append(index);
|
}else {
|
if(i==0){ index=","+map.get("lgtd")+" "+map.get("lttd"); }
|
geom.append(map.get("lgtd")).append(" ").append(map.get("lttd")).append(",");
|
}
|
}
|
HashMap<String, Object> param = new HashMap<>();
|
param.put("geom","'POLYGON(("+geom+"))'");
|
param.put("id",e.getId());
|
try{
|
approveDao.updateEXTENDFILESPOINTS(param);
|
}catch (Exception ex){
|
ex.printStackTrace();
|
}
|
}
|
e.setGeom("");
|
}
|
|
return null;
|
}
|
|
|
|
}
|