1
13693261870
2022-09-16 fee60c3e25fac0982f3b8cb8feea7225c4ed22f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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;
    }
 
 
 
}