1)在页面定义一个按钮,当点击按钮时,把设备id,时间范围传递到后台

2)后天接收到请求及参数,进行处理

3)使用easypoi导出数据

/*** 默认查询最近一个月的数据进行下载* 要按设备类型不同分别下载* 可以根据传入的时间范围进行下载* @param map* @param request* @param response* @param pageTableRequest*/
@RequestMapping("load")
@ApiOperation(value = "历史数据下载")
public void downloadByPoiBaseView(ModelMap map, HttpServletRequest request,HttpServletResponse response,PageTableRequest pageTableRequest) {FarmDto farmDto=new FarmDto();User user = (User) SecurityUtils.getSubject().getPrincipal();user.setPassword(null);farmDto.setUser(user);//设备信息//基地id默认就是当前拥有的第一个基地,如有多个,在切换的时候动态更新数据//如果用户没有基地,那么farmId就为null,数据库也不会返回数据Long farmId = null;//根据用户获取拥有的农场List<Farm> farmList = farmDao.getFarmListByUserId(user.getId());List<DeviceGather> deviceGatherList=null;String createTimeRangeStr ="";if (farmList != null && farmList.size() > 0) {Farm farm = farmList.get(0);//将用户拥有的第一个农场查询出来,这里是有问题的,需要优化farmId=farm.getId();List<Device> deviceList = deviceDao.getByFarmId(farmId);//封装查询条件createTimeRangeStr = (String) pageTableRequest.getParams().get("createTimeRange");if (StringUtils.isNotEmpty(createTimeRangeStr)) {//2019-01-11 - 2019-02-03String[] createTimeRangeStrS = createTimeRangeStr.split(" - ");pageTableRequest.getParams().put("startTime", createTimeRangeStrS[0]);pageTableRequest.getParams().put("endTime", createTimeRangeStrS[1]);}else {//如果没有传时间,就显示最近一个月的String startTime=DateUtil.dateToString(DateUtil.getBeforeByMonth(1));String endTime=DateUtil.dateToString(new Date());pageTableRequest.getParams().put("startTime",startTime);pageTableRequest.getParams().put("endTime", endTime);createTimeRangeStr=startTime+" - "+endTime;}//将分页参数设置为空pageTableRequest.setLimit(null);pageTableRequest.setOffset(null);deviceGatherList=deviceService.getHistoryDataByFarmId(pageTableRequest,farmId);}ExportParams params = new ExportParams("采集数据显示", "概览", ExcelType.XSSF);params.setFreezeCol(2);map.put(NormalExcelConstants.DATA_LIST, deviceGatherList);map.put(NormalExcelConstants.CLASS, DeviceGather.class);map.put(NormalExcelConstants.PARAMS, params);map.put(NormalExcelConstants.FILE_NAME, createTimeRangeStr);PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);}

得到历史数据的service

/*** 得到历史采集数据* @param pageTableRequest* @param farmId* @return*/
@Override
public List<DeviceGather> getHistoryDataByFarmId(PageTableRequest pageTableRequest,Long farmId) {List<DeviceGather> deviceGathers = new ArrayList<>();//如果设备id直接传递过来了,那就按设备id直接查询Object deviceIdObj = pageTableRequest.getParams().get("deviceId");if (deviceIdObj != null) {Long deviceId= (Long) deviceIdObj;deviceGathers = deviceGatherDao.list(pageTableRequest.getParams(), null, null);return deviceGathers;}//没有设备id的情况下,根据农场id获取该农场的所有设备,并全部返回List<Device> deviceList = deviceDao.getByFarmId(farmId);for (Device device : deviceList) {//不需要分页参数,并且设置设备idpageTableRequest.getParams().put("deviceId",device.getId());List<DeviceGather> deviceGatherList = deviceGatherDao.list(pageTableRequest.getParams(),null,null);if (deviceGatherList!=null&&deviceGatherList.size()>0){//封装数据返回for (DeviceGather deviceGather : deviceGatherList) {deviceGathers.add(deviceGather);}}}return deviceGathers;
}

实体类

public class DeviceGather extends BaseEntity<Long> {@Excel(name = "设备id")private Integer deviceId;@Excel(name = "设备序列号",width = 20)private String deviceSn;@Excel(name = "设备名称",width = 30)private String deviceName;private String deviceType;@Excel(name = "数据")private Float basicData;private Integer measurementUnitId;@Excel(name = "数据单位")private String measurementUnitName;private String measureUnitType;@Excel(name = "采集时间",format = "yyyy-MM-dd HH:mm:ss", width = 35)private Date gatherTime;

生成excel的代码

ExportParams params = new ExportParams("采集数据显示", "概览", ExcelType.XSSF);
params.setFreezeCol(2);
map.put(NormalExcelConstants.DATA_LIST, deviceGatherList);
map.put(NormalExcelConstants.CLASS, DeviceGather.class);
map.put(NormalExcelConstants.PARAMS, params);
map.put(NormalExcelConstants.FILE_NAME, createTimeRangeStr);
PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);

项目中使用EasyPOI完成监控设备历史数据的导出相关推荐

  1. vue2项目中如何接入视频监控

    前言 想必各位作为开发者的程序员,有时候公司会给你安排在项目中实现视频实时监控 视频实时监控功能,在很多领域都广泛应用,能帮我们在各行各业都解决很多事情,像智慧工地中AI识别(安全帽.在离岗等).国标 ...

  2. hibernate+servlet+mysql 实现easypoi_在Maven项目中使用easypoi完成Excel文件上传下载(示例代码)...

    导包: 1 2 3 cn.afterturn 4 easypoi-base 5 3.2.0 6 7 8 cn.afterturn 9 easypoi-web 10 3.2.0 11 12 13 cn. ...

  3. WEB端项目中接入海康监控视频播放监控画面

    需求: 以树形结构展示组织以及组织下的摄像头列表,点击单个摄像头进行预览 效果图: 该博客基于 海康开放平台API开发 准备工作 1. APPkey.APPsecret.服务器ip地址.端口号 2. ...

  4. 微服务项目中引入全链路监控平台:Pinpoint、SkyWalking、Zipkin怎么选?

    来源:www.jianshu.com/p/92a12de11f18 0 问题背景 随着微服务架构的流行,服务按照不同的维度进行拆分,一次请求往往需要涉及到多个服务.互联网应用构建在不同的软件模块集上, ...

  5. java项目中使用oshi搭建监控系统

    官网地址:https://github.com/oshi/oshi 首先引入jar包 <dependency><groupId>com.github.oshi</grou ...

  6. 在监控网络项目中该如何选择光纤交换机?

    现在,随着网络技术的发展,在安防监控项目中,尤其是在远距离点位的监控中,我们经常会用到光纤收发器.光纤交换机.那么,我们在监控网络中该如何选择光纤交换机呢?接下来就跟随飞畅科技的小编一起来详细看看吧! ...

  7. 存储服务器在监控中的作用,监控项目中存储服务器IPSAN云存储方案的优劣势对比...

    <监控项目中存储服务器IPSAN云存储方案的优劣势对比>由会员分享,可在线阅读,更多相关<监控项目中存储服务器IPSAN云存储方案的优劣势对比(4页珍藏版)>请在人人文库网上搜 ...

  8. 企业升级改造项目中的电力监控系统的研究与应用

    摘要:采用微机保护和多功能电力仪表采集变电所内10KV高压柜配电回路的各种电参量和开关信号.系统采用现场就地组网的方式,组网后通过现场总线通讯并远传至后台,通过Acrel-2000型电力监控系统实现配 ...

  9. AFPM100消防设备电源监控系统在国航重庆分公司维修基地项目中的应用-安科瑞华楠

    [摘要]:AFPM100消防设备电源状态监控器是AFPM消防设备电源监控系统的核心,监控设备通过RS485总线与多台传感器相连,构成集散式消防设备电源监控系统,实时监控消防设备电源的工作状态.本文通过 ...

最新文章

  1. Html Agility Pack基础类介绍及运用
  2. ContextAttribute类
  3. DXUT扩展之摄像机
  4. 0基础学python做什么工作好-零基础自学Python多久可以找工作?
  5. build shop
  6. ToolsOh第4批收录
  7. vue导出Excel
  8. PreferenceScreen
  9. de4dot反混淆脱壳工具可使用的包
  10. 笔记本电脑插入耳机仍然外放(亲测有效)
  11. 桌面快捷方式小箭头隐藏与还原(亲测有效)
  12. 剖析KCP以及KCP在游戏中是如何使用的
  13. CoolProp函数输入表
  14. uniapp 在h5 模式下扫码
  15. android nohttp百度百科,百度百科宣布取消扩展阅读并给外链添加nofollow标签
  16. css扇子展开,CSS3 绝妙的扇形折叠展开加载动画
  17. tensorflow 1.14 ssd_mobilenet_v1 模型训练
  18. 微信直播平台解决方案已准备好,请查收!
  19. linux如何运行windows游戏,用Steam Play在Linux系统中玩Windows游戏的方法
  20. 【字符串比较函数】strcmp,stricmp,strcmpi区别

热门文章

  1. 【第一届“文翁杯”现场竞技赛】(校内“欢乐”赛)T1—洗刷刷(dp)
  2. Linux脚本中$#、$0、$1、$@、$*、$$、$?
  3. Python 动态添加类方法
  4. 系统调用syscall---用户态切换到内核态的唯一途径
  5. 算法竞赛入门经典_6数据结构基础
  6. HTTP 302报文
  7. 通过配置文件启动odoo-10.0
  8. 浅谈async、await关键字 = 深谈async、await关键字
  9. Combobox 控件绑定数据
  10. 如何停止一个正在运行的java线程