package com.landtool.lanbase.modules.api.controller; import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSONObject; import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; import com.landtool.lanbase.modules.terra.GisService; import com.landtool.lanbase.modules.terra.GisServiceListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.util.*; import java.util.function.Consumer; @RestController @RequestMapping("/manage") @CrossOrigin public class ManagerController { @Autowired ResExtMapUrlService ResExtMapUrlService; // http://www.nmsmp.com:8082/res/ziYuanInsert @RequestMapping(value="/batchRegister",method = RequestMethod.GET) public @ResponseBody void batchRegister(HttpServletRequest request,HttpServletResponse httpresponse) throws IOException, URISyntaxException { } @RequestMapping(value="/test",method = RequestMethod.POST) public @ResponseBody String batchimportUser(@RequestParam(value="file") MultipartFile uploadfile,String tgc,String jsession) throws Exception { if(uploadfile.isEmpty()){ return "file is empty"; } String filename=uploadfile.getOriginalFilename(); String suffixname=filename.substring(filename.lastIndexOf(".")); filename=UUID.randomUUID()+suffixname; File file =new File("D:/upload/"+filename); uploadfile.transferTo(file); EasyExcel.read(file, GisService.class,new GisServiceListener(tgc,jsession)).doReadAll(); return "操作成功" ; } @RequestMapping(value="/ok",method = RequestMethod.GET) public @ResponseBody String ok(HttpServletResponse httpresponse,String tgc,String jsession) throws Exception { Cookie cookie=new Cookie("TGC", tgc); cookie.setPath("/cas/"); cookie.setMaxAge(86400); httpresponse.addCookie(cookie); Cookie cookie1=new Cookie("JSESSIONID", jsession); cookie.setMaxAge(86400); httpresponse.addCookie(cookie1); return "操作成功" ; } @RequestMapping(value="/batchProxyUpdate",method = RequestMethod.GET) public @ResponseBody String updateResource(HttpServletResponse httpresponse,String resids) throws Exception { //获取数据库数据 List list=new ArrayList<>(); List urls=new ArrayList<>(); String[] resarray=resids.split(","); for (String str : resarray) { list.add(Integer.valueOf(str)); } if(!list.isEmpty()){ urls=ResExtMapUrlService.selectBatchUrl(list); urls.forEach(new Consumer() { @Override public void accept(Map t) { layersProxy( t); } }); } return "操作成功" ; } public void layersProxy(Map t){ Map map=new HashMap<>(); map.put("zyid", Integer.valueOf(t.get("RESOURCEID").toString())); map.put("serverUrl", t.get("SERVERURL")); map.put("contextPath", ""); map.put("urlid",t.get("URLID") ); map.put("isPublic", 1); map.put("suffix", 0); map.put("fromsys", "HYJGPT"); map.put("servername", t.get("TITLE")); JSONObject json= getProxyUrl(map); Res_ExtMapUrl res=new Res_ExtMapUrl(); res.setUrlid(Integer.valueOf(t.get("URLID").toString())); res.setEsbid( json.getInteger("id")); res.setResourceid(Integer.valueOf(t.get("RESOURCEID").toString())); res.setServerurl(json.getString("proxyurl")); ResExtMapUrlService.updateByPrimaryKey(res); } public JSONObject getProxyUrl(Map map){ JSONObject json=new JSONObject(); try { String res=com.landtool.lanbase.common.utils.HttpUtils.get("http://71.3.21.232:8066"+"/serverRegister/addArcGisServer",map); json=JSONObject.parseObject(res); } catch (Exception e) { e.printStackTrace(); } return json; } }