|
@@ -12,17 +12,26 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-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.*;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.servlet.RequestDispatcher;
|
|
|
import javax.servlet.ServletException;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.net.URI;
|
|
|
+import java.net.URISyntaxException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Controller
|
|
@@ -32,6 +41,12 @@ public class DeviceController {
|
|
|
@Autowired
|
|
|
private DeviceService deviceService;
|
|
|
|
|
|
+ @Value("${iot.server}")
|
|
|
+ private String server;
|
|
|
+ @Value("${iot.port}")
|
|
|
+ private int port;
|
|
|
+
|
|
|
+
|
|
|
@ResponseBody
|
|
|
@GetMapping("/pageList")
|
|
|
@ApiOperation(value = "获取设备分页")
|
|
@@ -106,8 +121,8 @@ public class DeviceController {
|
|
|
return new AjaxMessage<>(ResultStatus.OK, list);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /*@GetMapping("/getData")
|
|
|
+ @ResponseBody
|
|
|
+ @GetMapping("/getData")
|
|
|
@ApiOperation(value = "获取设备数据")
|
|
|
public void getData(
|
|
|
@ApiParam(value = "设备id", required = true) @RequestParam(required = true) Long deviceId,
|
|
@@ -115,22 +130,58 @@ public class DeviceController {
|
|
|
@ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer endDate,
|
|
|
HttpServletRequest httpServletRequest,
|
|
|
HttpServletResponse httpServletResponse
|
|
|
- ) throws IOException, ServletException {
|
|
|
- //RequestDispatcher dispatcher = httpServletRequest.getRequestDispatcher("http://114.135.61.188:58088/api/device/getData");
|
|
|
- //dispatcher.forward(httpServletRequest,httpServletResponse);
|
|
|
- httpServletResponse.sendRedirect("http://114.135.61.188:58088/api/device/getData");
|
|
|
+ ) throws URISyntaxException, IOException {
|
|
|
+ //http://114.135.61.188:58088/api/device/getData
|
|
|
+ RestTemplate restTemplate=new RestTemplate();
|
|
|
+ URI uri = new URI("http", null, server, port, httpServletRequest.getRequestURI(), httpServletRequest.getQueryString(), null);
|
|
|
+ ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, null, String.class);
|
|
|
+
|
|
|
+ httpServletResponse.setCharacterEncoding("UTF-8");
|
|
|
+ httpServletResponse.setContentType("application/json;charset=utf-8");
|
|
|
+ httpServletResponse.getWriter().write(responseEntity.getBody());
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@GetMapping("/getDataExcel")
|
|
|
@ApiOperation(value = "导出设备数据excel")
|
|
|
public void getDataExcel(
|
|
|
@ApiParam(value = "设备id", required = true) @RequestParam(required = true) Long deviceId,
|
|
|
@ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer startDate,
|
|
|
@ApiParam(value = "查询日期,YYYYMMDD格式", required = true) @RequestParam Integer endDate,
|
|
|
+ HttpServletRequest httpServletRequest,
|
|
|
HttpServletResponse httpServletResponse
|
|
|
- ) throws IOException {
|
|
|
- httpServletResponse.sendRedirect("/ceng/hello.html");
|
|
|
+ ) throws URISyntaxException, IOException {
|
|
|
+ RestTemplate restTemplate=new RestTemplate();
|
|
|
+ URI uri = new URI("http", null, server, port, httpServletRequest.getRequestURI(), httpServletRequest.getQueryString(), null);
|
|
|
+ ResponseEntity<byte[]> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, null, byte[].class);
|
|
|
+
|
|
|
+
|
|
|
+ byte[] b=new byte[100];
|
|
|
+ int len;
|
|
|
+
|
|
|
+ ByteArrayInputStream bais=new ByteArrayInputStream(responseEntity.getBody());
|
|
|
+ DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+ LocalDateTime date = LocalDateTime.now();
|
|
|
+ String fileName = "历史数据" + "-" + date.format(f) + ".xls";
|
|
|
|
|
|
- }*/
|
|
|
+ String headStr = "attachment;filename*=UTF-8''" + URLEncoder.encode(fileName, "UTF-8");
|
|
|
+
|
|
|
+ httpServletResponse.setContentType("APPLICATION/OCTET-STREAM");
|
|
|
+ httpServletResponse.setHeader("Content-Disposition", headStr);
|
|
|
+ ServletOutputStream out=httpServletResponse.getOutputStream();
|
|
|
+ while((len=bais.read(b))>0){
|
|
|
+ out.write(b,0,len);
|
|
|
+ }
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ bais.close();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
}
|