|  |  |  | 
|---|
|  |  |  | import com.moral.util.WebUtils; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.springframework.boot.system.ApplicationHome; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.text.ParseException; | 
|---|
|  |  |  | import java.text.SimpleDateFormat; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @GetMapping("honeycombDiagram") | 
|---|
|  |  |  | public ResultMessage honeycombDiagram (HttpServletRequest httpServletRequest){ | 
|---|
|  |  |  | public ResultMessage honeycombDiagram (HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException { | 
|---|
|  |  |  | Map<String, Object> params = WebUtils.getParametersStartingWith(httpServletRequest, null); | 
|---|
|  |  |  | Object serviceScopeId = params.get("serviceScopeId"); | 
|---|
|  |  |  | Object sensor_code = params.get("sensor_code"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<Map<String, Object>> resultList = servicesScopeService.honeycombDiagram(Integer.parseInt(serviceScopeId.toString()), Integer.parseInt(distance.toString()), type.toString(), time.toString(), sensor_code.toString()); | 
|---|
|  |  |  | //List<Map<String, Object>> resultList = servicesScopeService.honeycombDiagram(6, 40, "monthly", "2022-02", "a34004"); | 
|---|
|  |  |  | return ResultMessage.ok(resultList); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取jar包所在目录 | 
|---|
|  |  |  | ApplicationHome applicationHome = new ApplicationHome(getClass()); | 
|---|
|  |  |  | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 | 
|---|
|  |  |  | String path = applicationHome.getSource().getParentFile().toString() + "/static/tsv"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //File file = File.createTempFile("test",".tsv"); | 
|---|
|  |  |  | /*if (!new File(path).exists()){ | 
|---|
|  |  |  | new File(path).mkdir(); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | File file = null; | 
|---|
|  |  |  | File dir = new File(path); | 
|---|
|  |  |  | file = File.createTempFile("honeycombDiagram",".tsv",dir); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //构建输出流,同时指定编码 | 
|---|
|  |  |  | OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file),"UTF-8"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //tsv文件是空格分隔,除第一个外,每次写入一个单元格数据后需要输入空格 | 
|---|
|  |  |  | ow.write("lng"); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write("lat"); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write("count"); | 
|---|
|  |  |  | //写完文件头换行 | 
|---|
|  |  |  | ow.write("\r\n"); | 
|---|
|  |  |  | //写内容 | 
|---|
|  |  |  | for (Map map:resultList) { | 
|---|
|  |  |  | ow.write(map.get("lon").toString()); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write(map.get("lat").toString()); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write(map.get("value").toString()); | 
|---|
|  |  |  | //写完一行换行 | 
|---|
|  |  |  | ow.write("\r\n"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ow.flush(); | 
|---|
|  |  |  | ow.close(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*String localAddr = httpServletRequest.getLocalAddr(); | 
|---|
|  |  |  | int serverPort = httpServletRequest.getServerPort();*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String,Object> res = new HashMap<>(); | 
|---|
|  |  |  | res.put("path","http://47.99.64.149:8081"+"/static/tsv/"+file.getName()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ResultMessage.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @RequestMapping(value = "returnDataTest", method = RequestMethod.GET) | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public ResultMessage returnDataTest(HttpServletRequest request) throws ParseException { | 
|---|
|  |  |  | List bigList = new ArrayList(); | 
|---|
|  |  |  | Map<String,Object> resultMap = new HashMap<>(); | 
|---|
|  |  |  | List<List> boundList = new ArrayList<>(); | 
|---|
|  |  |  | /*boundList.add(120.70980239181193); | 
|---|
|  |  |  | boundList.add(31.329143000000002); | 
|---|
|  |  |  | boundList.add(120.74077860818807); | 
|---|
|  |  |  | boundList.add(31.356963);*/ | 
|---|
|  |  |  | /*List<Double> boundList1 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList2 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList3 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList4 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList5 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList6 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList7 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList8 = new ArrayList<>(); | 
|---|
|  |  |  | List<Double> boundList9 = new ArrayList<>(); | 
|---|
|  |  |  | boundList1.add(120.975221); | 
|---|
|  |  |  | boundList1.add(31.413145); | 
|---|
|  |  |  | boundList2.add(120.977021); | 
|---|
|  |  |  | boundList2.add(31.411345); | 
|---|
|  |  |  | boundList3.add(120.979174); | 
|---|
|  |  |  | boundList3.add(31.333362); | 
|---|
|  |  |  | boundList4.add(120.977374); | 
|---|
|  |  |  | boundList4.add(31.331562); | 
|---|
|  |  |  | boundList5.add(120.913768); | 
|---|
|  |  |  | boundList5.add(31.347918); | 
|---|
|  |  |  | boundList6.add(120.870665); | 
|---|
|  |  |  | boundList6.add(31.341063); | 
|---|
|  |  |  | boundList7.add(120.868865); | 
|---|
|  |  |  | boundList7.add(31.342863); | 
|---|
|  |  |  | boundList8.add(120.896371); | 
|---|
|  |  |  | boundList8.add(31.409264); | 
|---|
|  |  |  | boundList9.add(120.898171); | 
|---|
|  |  |  | boundList9.add(31.411064); | 
|---|
|  |  |  | List<List> boundList_middle = new ArrayList<>(); | 
|---|
|  |  |  | boundList_middle.add(boundList1); | 
|---|
|  |  |  | boundList_middle.add(boundList2); | 
|---|
|  |  |  | boundList_middle.add(boundList3); | 
|---|
|  |  |  | boundList_middle.add(boundList4); | 
|---|
|  |  |  | boundList_middle.add(boundList5); | 
|---|
|  |  |  | boundList_middle.add(boundList6); | 
|---|
|  |  |  | boundList_middle.add(boundList7); | 
|---|
|  |  |  | boundList_middle.add(boundList8); | 
|---|
|  |  |  | boundList_middle.add(boundList9);*/ | 
|---|
|  |  |  | String boundList_middle = "[[[120.975221,31.413145],[120.977021,31.411345],[120.979174,31.333362],[120.977374,31.331562],[120.913768,31.347918],[120.870665,31.341063],[120.868865,31.342863],[120.896371,31.409264],[120.898171,31.411064]]]"; | 
|---|
|  |  |  | List<String> boundList_middle2 = new ArrayList<>(); | 
|---|
|  |  |  | boundList_middle2.add(boundList_middle); | 
|---|
|  |  |  | resultMap.put("bound",boundList_middle); | 
|---|
|  |  |  | resultMap.put("time","2021-12-10 08:00:00"); | 
|---|
|  |  |  | List<Double> centerPointList = new ArrayList<>(); | 
|---|
|  |  |  | centerPointList.add(120.934824838); | 
|---|
|  |  |  | centerPointList.add(31.37834580); | 
|---|
|  |  |  | resultMap.put("centerPoint",centerPointList); | 
|---|
|  |  |  | List<Double> list1 = new ArrayList<>(); | 
|---|
|  |  |  | list1.add(120.975221); | 
|---|
|  |  |  | list1.add(31.411345); | 
|---|
|  |  |  | list1.add(1.0); | 
|---|
|  |  |  | List<Double> list2 = new ArrayList<>(); | 
|---|
|  |  |  | list2.add(120.870665); | 
|---|
|  |  |  | list2.add(31.342863); | 
|---|
|  |  |  | list2.add(4.0); | 
|---|
|  |  |  | List<Double> list3 = new ArrayList<>(); | 
|---|
|  |  |  | list3.add(120.898171); | 
|---|
|  |  |  | list3.add(31.409264); | 
|---|
|  |  |  | list3.add(2.0); | 
|---|
|  |  |  | List<Double> list4 = new ArrayList<>(); | 
|---|
|  |  |  | list4.add(120.913768); | 
|---|
|  |  |  | list4.add(31.349718); | 
|---|
|  |  |  | list4.add(3.0); | 
|---|
|  |  |  | List<Double> list5 = new ArrayList<>(); | 
|---|
|  |  |  | list5.add(120.977374); | 
|---|
|  |  |  | list5.add(31.333362); | 
|---|
|  |  |  | list5.add(2.0); | 
|---|
|  |  |  | List list12345 = new ArrayList(); | 
|---|
|  |  |  | list12345.add(list1); | 
|---|
|  |  |  | list12345.add(list2); | 
|---|
|  |  |  | list12345.add(list3); | 
|---|
|  |  |  | list12345.add(list4); | 
|---|
|  |  |  | list12345.add(list5); | 
|---|
|  |  |  | resultMap.put("list",list12345); | 
|---|
|  |  |  | for (int i=0;i<10;i++){ | 
|---|
|  |  |  | resultMap.put("time","2021-12-10 0"+i+":00:00"); | 
|---|
|  |  |  | bigList.add(resultMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | public ResultMessage returnDataTest(HttpServletRequest request, HttpServletResponse response) throws ParseException, IOException { | 
|---|
|  |  |  | Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); | 
|---|
|  |  |  | Object serviceScopeId = params.get("serviceScopeId"); | 
|---|
|  |  |  | Object sensor_code = params.get("sensor_code"); | 
|---|
|  |  |  | Object type = params.get("type"); | 
|---|
|  |  |  | Object time = params.get("time"); | 
|---|
|  |  |  | Object distance = params.get("distance"); | 
|---|
|  |  |  | /*if (ObjectUtils.isEmpty(serviceScopeId)){ | 
|---|
|  |  |  | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); | 
|---|
|  |  |  | }*/ | 
|---|
|  |  |  | List<Map<String, Object>> resultList = servicesScopeService.honeycombDiagram(Integer.parseInt(serviceScopeId.toString()), Integer.parseInt(distance.toString()), type.toString(), time.toString(), sensor_code.toString()); | 
|---|
|  |  |  | //List<Map<String, Object>> resultList = servicesScopeService.honeycombDiagram(6, 40, "monthly", "2022-02", "a34004"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return ResultMessage.ok(bigList); | 
|---|
|  |  |  | //获取jar包所在目录 | 
|---|
|  |  |  | ApplicationHome applicationHome = new ApplicationHome(getClass()); | 
|---|
|  |  |  | //在jar包所在目录下生成一个upload文件夹用来存储上传的图片 | 
|---|
|  |  |  | String path = applicationHome.getSource().getParentFile().toString() + "/static/tsv"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //File file = File.createTempFile("test",".tsv"); | 
|---|
|  |  |  | if (!new File(path).exists()){ | 
|---|
|  |  |  | new File(path).mkdir(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | File file = null; | 
|---|
|  |  |  | File dir = new File(path); | 
|---|
|  |  |  | file = File.createTempFile("honeycombDiagram",".tsv",dir); | 
|---|
|  |  |  | //构建输出流,同时指定编码 | 
|---|
|  |  |  | OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file),"UTF-8"); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //tsv文件是空格分隔,除第一个外,每次写入一个单元格数据后需要输入空格 | 
|---|
|  |  |  | ow.write("lon"); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write("lat"); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write("value"); | 
|---|
|  |  |  | //写完文件头换行 | 
|---|
|  |  |  | ow.write("\r\n"); | 
|---|
|  |  |  | //写内容 | 
|---|
|  |  |  | for (Map map:resultList) { | 
|---|
|  |  |  | ow.write(map.get("lon").toString()); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write(map.get("lat").toString()); | 
|---|
|  |  |  | ow.write("  "); | 
|---|
|  |  |  | ow.write(map.get("value").toString()); | 
|---|
|  |  |  | //写完一行换行 | 
|---|
|  |  |  | ow.write("\r\n"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ow.flush(); | 
|---|
|  |  |  | ow.close(); | 
|---|
|  |  |  | /*File file1 = new File(file.getPath()); | 
|---|
|  |  |  | InputStream inputStream = new FileInputStream(file1); | 
|---|
|  |  |  | OutputStream outputStream = new BufferedOutputStream(response.getOutputStream()); | 
|---|
|  |  |  | byte[] bytes = new byte[1024]; | 
|---|
|  |  |  | int len; | 
|---|
|  |  |  | while ((len = inputStream.read(bytes)) != -1){ | 
|---|
|  |  |  | response.getOutputStream().write(bytes,0,len); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | outputStream.flush(); | 
|---|
|  |  |  | outputStream.close(); | 
|---|
|  |  |  | inputStream.close();*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*response.setCharacterEncoding("UTF-8"); | 
|---|
|  |  |  | System.out.println(file.getName()); | 
|---|
|  |  |  | String realFileName = file.getName(); | 
|---|
|  |  |  | response.setHeader("content-type", "application/octet-stream;charset=UTF-8"); | 
|---|
|  |  |  | response.addHeader("Content-Length",String.valueOf(file.length())); | 
|---|
|  |  |  | response.setHeader("Content-Disposition", "attachment;filename=" + java.net.URLEncoder.encode(realFileName.trim(), "UTF-8")); | 
|---|
|  |  |  | byte[] buff = new byte[1024]; | 
|---|
|  |  |  | BufferedInputStream bis = null; | 
|---|
|  |  |  | OutputStream os = null; | 
|---|
|  |  |  | os = response.getOutputStream(); | 
|---|
|  |  |  | bis = new BufferedInputStream(new FileInputStream(file)); | 
|---|
|  |  |  | int i = bis.read(buff); | 
|---|
|  |  |  | while (i != -1) { | 
|---|
|  |  |  | os.write(buff, 0, buff.length); | 
|---|
|  |  |  | os.flush(); | 
|---|
|  |  |  | i = bis.read(buff); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | bis.close();*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /*//1、设置response 响应头 | 
|---|
|  |  |  | response.reset(); //设置页面不缓存,清空buffer | 
|---|
|  |  |  | response.setCharacterEncoding("UTF-8"); //字符编码 | 
|---|
|  |  |  | response.setContentType("multipart/form-data"); //二进制传输数据 | 
|---|
|  |  |  | //设置响应头 | 
|---|
|  |  |  | response.setHeader("Content-Disposition", | 
|---|
|  |  |  | "attachment;fileName="+ URLEncoder.encode(file.getName(), "UTF-8")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | File file1 = new File(file.getParent(),file.getName()); | 
|---|
|  |  |  | System.out.println(file1.getParent()); | 
|---|
|  |  |  | //2、 读取文件--输入流 | 
|---|
|  |  |  | InputStream input=new FileInputStream(file1); | 
|---|
|  |  |  | //3、 写出文件--输出流 | 
|---|
|  |  |  | OutputStream out = response.getOutputStream(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | byte[] buff =new byte[1024]; | 
|---|
|  |  |  | int index=0; | 
|---|
|  |  |  | //4、执行 写出操作 | 
|---|
|  |  |  | while((index= input.read(buff))!= -1){ | 
|---|
|  |  |  | out.write(buff, 0, index); | 
|---|
|  |  |  | out.flush(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | out.close(); | 
|---|
|  |  |  | input.close();*/ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Map<String,Object> res = new HashMap<>(); | 
|---|
|  |  |  | res.put("path",file.getPath()); | 
|---|
|  |  |  | return ResultMessage.ok(res); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|