From aca1d4925a7aca63cece12c5fa190057f0d046fc Mon Sep 17 00:00:00 2001 From: wuweida <2918581207@qq.com> Date: Wed, 1 Jun 2022 14:27:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=B7=A5?= =?UTF-8?q?=E5=9C=B0=E7=AD=89=E5=A4=9A=E4=B8=AA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BuildingController.java | 127 ++++++++++++++++++ .../monitormanage/dto/BuildingRecordsDto.java | 17 +++ .../mapper/BuildingRecordsMapper.java | 44 ++++++ .../service/BuildingRecordsService.java | 26 +++- .../mapper/BuildingRecordsMapper.xml | 14 ++ 5 files changed, 225 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java diff --git a/src/main/java/com/hisense/monitormanage/controller/BuildingController.java b/src/main/java/com/hisense/monitormanage/controller/BuildingController.java index c75043a..c6b0ea3 100644 --- a/src/main/java/com/hisense/monitormanage/controller/BuildingController.java +++ b/src/main/java/com/hisense/monitormanage/controller/BuildingController.java @@ -1,10 +1,15 @@ package com.hisense.monitormanage.controller; +import com.hisense.monitormanage.dto.BuildingRecordsDto; import com.hisense.monitormanage.entity.BuildingRecords; +import com.hisense.monitormanage.entity.CameraChannel; import com.hisense.monitormanage.entity.Result; +import com.hisense.monitormanage.mapper.BuildingRecordsMapper; import com.hisense.monitormanage.service.BuildingRecordsService; +import com.hisense.monitormanage.utils.LongLatUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -29,6 +34,9 @@ public class BuildingController { @Autowired private BuildingRecordsService buildingRecordsService; + @Autowired + private BuildingRecordsMapper buildingRecordsMapper; + @GetMapping("/getRecords") @ApiOperation("测试,获取工地实时数据--调用接口") public List getRecords(){ @@ -55,4 +63,123 @@ public class BuildingController { return buildingRecordsService.listRecords(pushTime); } + + /** + * 查询所有工地 + * @return + */ + @GetMapping("selectAllBuilding") + @ApiOperation("查询所有工地") + public Result selectAllBuilding(){ + List recordsDtos = buildingRecordsMapper.selectAllBuilding(); + Result success = Result.success(recordsDtos); + return success; + } + /** + * 查询当天工地扬尘并排序 + * @return + */ + @GetMapping("selectDayPm10") + @ApiOperation("查询当天工地扬尘并排序") + public Result selectDayPm10(){ + List recordsDtos = buildingRecordsMapper.selectDayPm10(); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 查询近一周工地扬尘并排序 + * @return + */ + @GetMapping("selectWeekPm10") + @ApiOperation("查询近一周工地扬尘并排序") + public Result selectWeekPm10(){ + List recordsDtos = buildingRecordsMapper.selectWeekPm10(); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 查询近一月工地扬尘并排序 + * @return + */ + @GetMapping("selectMonthPm10") + @ApiOperation("查询近一月工地扬尘并排序") + public Result selectMonthPm10(){ + List recordsDtos = buildingRecordsMapper.selectMonthPm10(); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 查询当天工地噪声并排序 + * @return + */ + @GetMapping("selectDayNoice") + @ApiOperation("查询当天工地噪声并排序") + public Result selectDayNoice(){ + List recordsDtos = buildingRecordsMapper.selectDayNoice(); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 查询近一周工地噪声并排序 + * @return + */ + @GetMapping("selectWeekNoice") + @ApiOperation("查询近一周工地噪声并排序") + public Result selectWeekNoice(){ + List recordsDtos = buildingRecordsMapper.selectWeekNoice(); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 查询近一月工地噪声并排序 + * @return + */ + @GetMapping("selectMonthNoice") + @ApiOperation("查询近一月工地噪声并排序") + public Result selectMonthNoice(){ + List recordsDtos = buildingRecordsMapper.selectMonthNoice(); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 根据工地名称搜索工地 + * @param projectName + * @return + */ + @GetMapping("selectByProjectName") + @ApiOperation("根据工地名称搜索工地") + public Result selectByProjectName(String projectName){ + List recordsDtos = buildingRecordsMapper.selectByProjectName(projectName); + Result success = Result.success(recordsDtos); + return success; + } + + /** + * 根据经纬度查询半径内所有的工地 + * @param jd + * @param wd + * @param radius + * @return + */ + @GetMapping ("selectByJdWd") + @ApiOperation("根据经纬度查询半径内所有的工地") + @ApiImplicitParams({ + @ApiImplicitParam(name = "jd", value = "经度",required = true,dataType ="Double"), + @ApiImplicitParam(name = "wd", value = "纬度",required = true,dataType ="Double"), + @ApiImplicitParam(name = "radius", value = "半径,米",required = true,dataType ="Integer"),} + ) + public Result selectByJdWd(Double jd,Double wd,Integer radius){ + double[] around = LongLatUtil.getAround(jd, wd, radius); + List c = buildingRecordsMapper.selectByJdWd(around[0], around[2], around[1], around[3]); + Result success = Result.success(c); + return success; + } + + } diff --git a/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java b/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java new file mode 100644 index 0000000..b7e803e --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/dto/BuildingRecordsDto.java @@ -0,0 +1,17 @@ +package com.hisense.monitormanage.dto; + +import lombok.Data; + +@Data +public class BuildingRecordsDto { + private String projectName;//工地名称 + private String buildLicense;//建筑编号 + private String pushTime;//推送时间 + private String appid; + private String sgwz;//施工位置 + private double jd;//经度 + private double wd;//纬度 + private String ssdq;//所属区域 + private double pm10;//扬尘 + private double noice;//噪声 +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java b/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java index 76ac22e..1cf0d41 100644 --- a/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java +++ b/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java @@ -1,8 +1,12 @@ package com.hisense.monitormanage.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hisense.monitormanage.dto.BuildingRecordsDto; import com.hisense.monitormanage.entity.BuildingRecords; +import com.hisense.monitormanage.entity.CameraChannel; +import com.hisense.monitormanage.entity.Label; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.Map; @@ -16,4 +20,44 @@ import java.util.Map; */ public interface BuildingRecordsMapper extends BaseMapper { public void batchSave(@Param("list") List list); + + void batchUpdate(@Param("list") List list); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc") + List selectAllBuilding(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc " + + " where to_days(br.push_time) = to_days(now()) order by br.pm10 desc") + List selectDayPm10(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc" + + " where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(br.push_time) order by br.pm10 desc") + List selectWeekPm10(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc" + + " where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(br.push_time) order by br.pm10 desc") + List selectMonthPm10(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc " + + " where to_days(br.push_time) = to_days(now()) order by br.noice desc") + List selectDayNoice(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc" + + " where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(br.push_time) order by br.noice desc") + List selectWeekNoice(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc" + + " where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(br.push_time) order by br.noice desc") + List selectMonthNoice(); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc" + + " where br.project_name like concat('%',#{projectName},'%')") + List selectByProjectName(String projectName); + + @Select("select br.*,bs.sgwz,bs.jd,bs.wd,bs.ssdq from t_building_records br JOIN t_building_site bs on br.project_name = bs.gdmc" + + " where (bs.jd between #{jd} and #{jd1}) and (bs.wd between #{wd} and #{wd1} )") + List selectByJdWd(@Param("jd") Double jd, + @Param("jd1") Double jd1, + @Param("wd") Double wd, + @Param("wd1") Double wd1); } diff --git a/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java b/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java index c753f84..a62c4a7 100644 --- a/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java +++ b/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java @@ -9,6 +9,7 @@ import com.hisense.monitormanage.mapper.BuildingRecordsMapper; import lombok.extern.slf4j.Slf4j; 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.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -34,9 +35,8 @@ public class BuildingRecordsService { @Autowired private RestTemplate restTemplate; - private String url = "http://scxjsw.qingdao.gov.cn/monitorData/real-time"; - public List getRecords(){ + String url = "http://scxjsw.qingdao.gov.cn/monitorData/real-time"; Map map = new HashMap<>(); map.put("appid",""); map.put("timestamp",""); @@ -60,10 +60,10 @@ public class BuildingRecordsService { e.printStackTrace(); log.error("[BuildingRecordsService-getRecords] Exception:"+e.getMessage()); } - return maps; } + @Scheduled(cron = "0 0 7/1 * * ?") public boolean getAndSaveRecords(){ List maps = this.getRecords(); boolean result = false; @@ -81,6 +81,24 @@ public class BuildingRecordsService { return result; } + + 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){ + e.printStackTrace(); + log.error("[BuildingRecordsService-getUpdateRecords] Exception:"+e.getMessage()); + } + } + return result; + } + public List listRecords(String pushTime){ QueryWrapper wrapper = new QueryWrapper<>(); wrapper.like("push_time",pushTime); @@ -88,4 +106,6 @@ public class BuildingRecordsService { list = buildingRecordsMapper.selectList(wrapper); return list; } + + } diff --git a/src/main/resources/mapper/BuildingRecordsMapper.xml b/src/main/resources/mapper/BuildingRecordsMapper.xml index dfada16..b033cbf 100644 --- a/src/main/resources/mapper/BuildingRecordsMapper.xml +++ b/src/main/resources/mapper/BuildingRecordsMapper.xml @@ -16,4 +16,18 @@ + + + update t_building_records + + project_name = #{item.projectName}, + push_time = #{item.pushTime}, + appid = #{item.appid}, + pm10 = #{item.pm10}, + noice = #{item.noice} + + where build_license = #{item.buildLicense} + + + \ No newline at end of file