From e541fba4a02f50b1737805e00c0bc868297cebbe Mon Sep 17 00:00:00 2001 From: wuweida <2918581207@qq.com> Date: Wed, 17 Aug 2022 13:51:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A5=E5=9C=B0=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=917=E5=A4=A9=E8=BF=9130=E5=A4=A9=E6=89=AC?= =?UTF-8?q?=E5=B0=98=20=E5=99=AA=E5=A3=B0=20=E5=92=8C=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=84=9F=E7=9F=A5=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 ++ .../controller/BuildingController.java | 102 ++++++++++++++++++ .../monitormanage/dto/BuildingRecordsDto.java | 17 +++ .../mapper/BuildingRecordsMapper.java | 12 +++ .../service/BuildingRecordsService.java | 102 ++++++++++++------ .../mapper/BuildingRecordsMapper.xml | 76 +++++++++++-- 6 files changed, 279 insertions(+), 41 deletions(-) diff --git a/pom.xml b/pom.xml index 36b7293..ed787f8 100644 --- a/pom.xml +++ b/pom.xml @@ -123,6 +123,17 @@ 1.9.2 + + org.apache.poi + poi-ooxml + 3.11 + + + + com.alibaba + easyexcel + 2.2.6 + diff --git a/src/main/java/com/hisense/monitormanage/controller/BuildingController.java b/src/main/java/com/hisense/monitormanage/controller/BuildingController.java index faafb9b..cd8dd5b 100644 --- a/src/main/java/com/hisense/monitormanage/controller/BuildingController.java +++ b/src/main/java/com/hisense/monitormanage/controller/BuildingController.java @@ -286,5 +286,107 @@ public class BuildingController { return success; } + /*@GetMapping("exportEvent") + public void exportRaiseEvent() throws Exception { + buildingRecordsService.testHSSF(); + }*/ + + /** + * 查询近7天噪声事件 + * @return + */ + @GetMapping("selectByWeekNoice") + @ApiOperation("查询近7天噪声事件") + public Result selectByWeekNoice(){ + List buildingRecordsDtos = buildingRecordsMapper.selectByWeekNoice(); + Map map = new HashMap<>(); + map.put("sum",buildingRecordsDtos.size()); + map.put("data",buildingRecordsDtos); + Result success = Result.success(map); + return success; + } + + /** + * 查询近30天噪声事件 + * @return + */ + @GetMapping("selectByMonthNoice") + @ApiOperation("查询近30天噪声事件") + public Result selectByMonthNoice(){ + List buildingRecordsDtos = buildingRecordsMapper.selectByMonthNoice(); + Map map = new HashMap<>(); + map.put("sum",buildingRecordsDtos.size()); + map.put("data",buildingRecordsDtos); + Result success = Result.success(map); + return success; + } + + /** + * 查询近7天扬尘事件 + * @return + */ + @GetMapping("selectByWeekNaise") + @ApiOperation("查询近7天扬尘事件") + public Result selectByWeekNaise(){ + List buildingRecordsDtos = buildingRecordsMapper.selectByWeekNaise(); + Map map = new HashMap<>(); + map.put("sum",buildingRecordsDtos.size()); + map.put("data",buildingRecordsDtos); + Result success = Result.success(map); + return success; + } + + /** + * 查询近30天扬尘事件 + * @return + */ + @GetMapping("selectByMonthNaise") + @ApiOperation("查询近30天扬尘事件") + public Result selectByMonthNaise(){ + List buildingRecordsDtos = buildingRecordsMapper.selectByMonthNaise(); + Map map = new HashMap<>(); + map.put("sum",buildingRecordsDtos.size()); + map.put("data",buildingRecordsDtos); + Result success = Result.success(map); + return success; + } + + /** + * 查询近7天工地视频感知事件 + * @return + */ + @GetMapping("selectByWeekEvent") + @ApiOperation("查询近7天工地视频感知事件") + public Result selectByWeekEvent(){ + List events = buildingRecordsMapper.selectByWeekEvent(); + events.forEach(eventDto -> { + eventDto.setEventNewName(eventDto.getEventCnName()); + }); + Map map = new HashMap<>(); + map.put("sum",events.size()); + map.put("data",events); + Result success = Result.success(map); + return success; + } + + /** + * 查询近30天工地视频感知事件 + * @return + */ + @GetMapping("selectByMonthEvent") + @ApiOperation("查询近30天工地视频感知事件") + public Result selectByMonthEvent(){ + List events = buildingRecordsMapper.selectByMonthEvent(); + events.forEach(eventDto -> { + eventDto.setEventNewName(eventDto.getEventCnName()); + }); + Map map = new HashMap<>(); + map.put("sum",events.size()); + map.put("data",events); + Result success = Result.success(map); + return success; + } + + } diff --git a/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java b/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java index a8c6d36..b1d4191 100644 --- a/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java +++ b/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java @@ -1,36 +1,53 @@ package com.hisense.monitormanage.dto; +import com.alibaba.excel.annotation.ExcelProperty; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; @Data public class BuildingRecordsDto { + @ExcelProperty(value = {"工地名称"},index = 0) private String projectName;//工地名称 + @ExcelProperty(value = {"建筑编号"},index = 1) private String buildLicense;//建筑编号 + @ExcelProperty(value = {"推送时间"},index = 2) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") private String pushTime;//推送时间 + @ExcelProperty(value = {"appid"},index = 3) private String appid; + @ExcelProperty(value = {"施工位置"},index = 4) private String sgwz;//施工位置 + @ExcelProperty(value = {"经度"},index = 5) private double jd;//经度 + @ExcelProperty(value = {"纬度"},index = 6) private double wd;//纬度 + @ExcelProperty(value = {"所属区域"},index = 7) private String ssdq;//所属区域 + @ExcelProperty(value = {"扬尘"},index = 8) private double pm10;//扬尘 + @ExcelProperty(value = {"噪声"},index = 9) private double noice;//噪声 + @ExcelProperty(value = {"夜间施工"},index = 10) private String yjsg;//夜间施工 + @ExcelProperty(value = {"图片路径"},index = 11) private String picUrl;//图片路径 + @ExcelProperty(value = {"摄像头编号"},index = 12) private String channelCode;//摄像头编号 + @ExcelProperty(value = {"摄像头名称"},index = 13) private String channelName;//摄像头名称 } diff --git a/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java b/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java index 49c79ea..a0f55af 100644 --- a/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java +++ b/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java @@ -74,4 +74,16 @@ public interface BuildingRecordsMapper extends BaseMapper { @Select("select * from t_event te JOIN t_scene_event tse ON te.camera_name = tse.channel_name where te.track_event = 'START' AND TO_DAYS(te.capture_time) = TO_DAYS(NOW())") List selectByEvent(); + List selectByWeekNoice(); + + List selectByMonthNoice(); + + List selectByWeekNaise(); + + List selectByMonthNaise(); + + List selectByWeekEvent(); + + List selectByMonthEvent(); + } diff --git a/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java b/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java index cb2c9a6..54c303b 100644 --- a/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java +++ b/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java @@ -4,19 +4,23 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Lists; +import com.hisense.monitormanage.dto.BuildingRecordsDto; import com.hisense.monitormanage.entity.BuildingRecords; import com.hisense.monitormanage.mapper.BuildingRecordsMapper; import lombok.extern.slf4j.Slf4j; +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.FileOutputStream; +import java.lang.reflect.Field; +import java.util.*; /** * @author admin @@ -35,72 +39,100 @@ public class BuildingRecordsService { @Autowired private RestTemplate restTemplate; - public List getRecords(){ + public List getRecords() { String url = "http://scxjsw.qingdao.gov.cn/monitorData/real-time"; - Map map = new HashMap<>(); - map.put("appid",""); - map.put("timestamp",""); - map.put("sign",""); - map.put("data",""); + Map map = new HashMap<>(); + map.put("appid", ""); + map.put("timestamp", ""); + map.put("sign", ""); + map.put("data", ""); ResponseEntity responseEntity; List maps = new ArrayList<>(); - try{ - responseEntity = restTemplate.postForEntity(url,map,JSONObject.class); + try { + responseEntity = restTemplate.postForEntity(url, map, JSONObject.class); if (responseEntity.getStatusCodeValue() == 200) { JSONObject result = responseEntity.getBody(); - if(result.getIntValue("code") == 0){ + if (result.getIntValue("code") == 0) { JSONArray jsonArray = result.getJSONArray("data"); - if(jsonArray != null){ - maps = JSONObject.parseArray(JSONArray.toJSONString(jsonArray),Map.class); + if (jsonArray != null) { + maps = JSONObject.parseArray(JSONArray.toJSONString(jsonArray), Map.class); } } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); - log.error("[BuildingRecordsService-getRecords] Exception:"+e.getMessage()); + log.error("[BuildingRecordsService-getRecords] Exception:" + e.getMessage()); } return maps; } @Scheduled(cron = "0 0 8/1 * * ?") - public boolean getAndSaveRecords(){ + public boolean getAndSaveRecords() { List maps = this.getRecords(); boolean result = false; - if(maps.size() > 0){ - List> lists = Lists.partition(maps,200); - try{ - lists.forEach(l->buildingRecordsMapper.batchSave(l)); - result = true; - }catch (Exception e){ + if (maps.size() > 0) { + List> lists = Lists.partition(maps, 200); + try { + lists.forEach(l -> buildingRecordsMapper.batchSave(l)); + result = true; + } catch (Exception e) { e.printStackTrace(); - log.error("[BuildingRecordsService-getAndSaveRecords] Exception:"+e.getMessage()); + log.error("[BuildingRecordsService-getAndSaveRecords] Exception:" + e.getMessage()); } } return result; } - public boolean getUpdateRecords(){ + public boolean getUpdateRecords() { List maps = this.getRecords(); boolean result = false; - if(maps.size() > 0){ - List> lists = Lists.partition(maps,200); - try{ - lists.forEach(l->buildingRecordsMapper.batchUpdate(l)); - result = true; - }catch (Exception e){ + if (maps.size() > 0) { + List> lists = Lists.partition(maps, 200); + try { + lists.forEach(l -> buildingRecordsMapper.batchUpdate(l)); + result = true; + } catch (Exception e) { e.printStackTrace(); - log.error("[BuildingRecordsService-getUpdateRecords] Exception:"+e.getMessage()); + log.error("[BuildingRecordsService-getUpdateRecords] Exception:" + e.getMessage()); } } return result; } - public List listRecords(String pushTime){ + public List listRecords(String pushTime) { QueryWrapper wrapper = new QueryWrapper<>(); - wrapper.like("push_time",pushTime); + wrapper.like("push_time", pushTime); List list = new ArrayList<>(); list = buildingRecordsMapper.selectList(wrapper); return list; } + + public void testHSSF() throws Exception { + // 1. 创建一个工作簿 + HSSFWorkbook wb = new HSSFWorkbook(); + // 2. 创建一个工作表 + HSSFSheet sheet = wb.createSheet(); + // 3. 获取数据库数据 + List buildingRecordsDtos = buildingRecordsMapper.selectRaise(null, null); + for (int i = 0; i < buildingRecordsDtos.size(); i++) { + // 4. 创建行 + HSSFRow row = sheet.createRow(i); + // 5. 使用反射获取实体的元素的总量 + Class aClass = buildingRecordsDtos.get(i).getClass(); + Field[] fields = aClass.getDeclaredFields(); + // 6. 行内单元格赋值 + for (int j = 0; j < fields.length; j++) { + Field f = fields[j]; + f.setAccessible(true); + HSSFCell cell = row.createCell(j); + cell.setCellValue(String.valueOf(f.get(buildingRecordsDtos.get(i)))); + } + } + // 7.写文件 + FileOutputStream fos = new FileOutputStream("C:/Users/szkingdom/"+System.currentTimeMillis()+".xls"); + // 8.关闭流 + wb.write(fos); + fos.close(); + } } diff --git a/src/main/resources/mapper/BuildingRecordsMapper.xml b/src/main/resources/mapper/BuildingRecordsMapper.xml index b5b2b64..dc6e899 100644 --- a/src/main/resources/mapper/BuildingRecordsMapper.xml +++ b/src/main/resources/mapper/BuildingRecordsMapper.xml @@ -33,8 +33,10 @@ + + + + + + + + + + + + + + + + \ No newline at end of file