You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.4 KiB
Java
88 lines
3.4 KiB
Java
package com.xydl.cac.controller;
|
|
|
|
import com.xydl.cac.entity.NiecSensor;
|
|
import com.xydl.cac.model.ConditionModel;
|
|
import com.xydl.cac.model.Response;
|
|
import com.xydl.cac.model.SensorDetail;
|
|
import com.xydl.cac.service.NiecSensorService;
|
|
import com.xydl.cac.service.ReportService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiParam;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.validation.annotation.Validated;
|
|
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.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import java.net.URLEncoder;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@Api(tags = {"装置表相关接口"})
|
|
@RequestMapping("sensor")
|
|
@Slf4j
|
|
public class NiecSensorController extends BasicController {
|
|
|
|
@Resource
|
|
NiecSensorService service;
|
|
@Resource
|
|
ReportService reportService;
|
|
|
|
@GetMapping("list")
|
|
@ApiOperation("查询列表")
|
|
public Response<Page<NiecSensor>> list(@ApiParam("页码") @RequestParam(value = "pageNum", required = false) Integer pageNum,
|
|
@ApiParam("每页数量") @RequestParam(value = "pageSize", required = false) Integer pageSize) {
|
|
pageNum = this.initPageNum(pageNum);
|
|
pageSize = this.initPageSize(pageSize);
|
|
Page<NiecSensor> result = service.list(pageNum, pageSize);
|
|
return Response.success(result);
|
|
}
|
|
|
|
@GetMapping("listAll")
|
|
@ApiOperation("查询全部列表")
|
|
public Response<List<NiecSensor>> listAll() {
|
|
List<NiecSensor> result = service.listAll();
|
|
return Response.success(result);
|
|
}
|
|
|
|
@GetMapping("getTree")
|
|
@ApiOperation("查询树")
|
|
public Response<List<NiecSensor>> getTree() {
|
|
List<NiecSensor> result = service.getTree();
|
|
return Response.success(result);
|
|
}
|
|
|
|
@GetMapping("detail")
|
|
@ApiOperation("查询单个装置采集到的数据")
|
|
public Response<SensorDetail> getDetail(@Validated ConditionModel model) throws Exception {
|
|
if (model.getPageNum() != null || model.getPageSize() != null) {
|
|
model.setPageNum(this.initPageNum(model.getPageNum()));
|
|
model.setPageSize(this.initPageSize(model.getPageSize()));
|
|
}
|
|
SensorDetail result = service.getDetail(model);
|
|
return Response.success(result);
|
|
}
|
|
|
|
@GetMapping("export")
|
|
@ApiOperation("导出单个装置采集到的数据")
|
|
public void export(@Validated ConditionModel model, HttpServletResponse response) throws Exception {
|
|
if (model.getPageNum() != null || model.getPageSize() != null) {
|
|
model.setPageNum(this.initPageNum(model.getPageNum()));
|
|
model.setPageSize(this.initPageSize(model.getPageSize()));
|
|
}
|
|
SensorDetail<Map<String, Object>> detail = service.getDetail(model);
|
|
response.setHeader("Content-Disposition", "attachment; filename="
|
|
+ URLEncoder.encode(detail.getSensor().getName() + ".xlsx", "UTF-8"));
|
|
response.setContentType("application/vnd.ms-excel");
|
|
response.setCharacterEncoding("utf-8");
|
|
reportService.exportSensor(detail, response.getOutputStream());
|
|
}
|
|
|
|
}
|