添加查询工地等多个接口

This commit is contained in:
wuweida 2022-06-01 14:27:34 +08:00
parent 7d380dd36b
commit aca1d4925a
5 changed files with 225 additions and 3 deletions

View File

@ -1,10 +1,15 @@
package com.hisense.monitormanage.controller; package com.hisense.monitormanage.controller;
import com.hisense.monitormanage.dto.BuildingRecordsDto;
import com.hisense.monitormanage.entity.BuildingRecords; import com.hisense.monitormanage.entity.BuildingRecords;
import com.hisense.monitormanage.entity.CameraChannel;
import com.hisense.monitormanage.entity.Result; import com.hisense.monitormanage.entity.Result;
import com.hisense.monitormanage.mapper.BuildingRecordsMapper;
import com.hisense.monitormanage.service.BuildingRecordsService; import com.hisense.monitormanage.service.BuildingRecordsService;
import com.hisense.monitormanage.utils.LongLatUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -29,6 +34,9 @@ public class BuildingController {
@Autowired @Autowired
private BuildingRecordsService buildingRecordsService; private BuildingRecordsService buildingRecordsService;
@Autowired
private BuildingRecordsMapper buildingRecordsMapper;
@GetMapping("/getRecords") @GetMapping("/getRecords")
@ApiOperation("测试,获取工地实时数据--调用接口") @ApiOperation("测试,获取工地实时数据--调用接口")
public List<Map> getRecords(){ public List<Map> getRecords(){
@ -55,4 +63,123 @@ public class BuildingController {
return buildingRecordsService.listRecords(pushTime); return buildingRecordsService.listRecords(pushTime);
} }
/**
* 查询所有工地
* @return
*/
@GetMapping("selectAllBuilding")
@ApiOperation("查询所有工地")
public Result selectAllBuilding(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectAllBuilding();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 查询当天工地扬尘并排序
* @return
*/
@GetMapping("selectDayPm10")
@ApiOperation("查询当天工地扬尘并排序")
public Result selectDayPm10(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectDayPm10();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 查询近一周工地扬尘并排序
* @return
*/
@GetMapping("selectWeekPm10")
@ApiOperation("查询近一周工地扬尘并排序")
public Result selectWeekPm10(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectWeekPm10();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 查询近一月工地扬尘并排序
* @return
*/
@GetMapping("selectMonthPm10")
@ApiOperation("查询近一月工地扬尘并排序")
public Result selectMonthPm10(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectMonthPm10();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 查询当天工地噪声并排序
* @return
*/
@GetMapping("selectDayNoice")
@ApiOperation("查询当天工地噪声并排序")
public Result selectDayNoice(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectDayNoice();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 查询近一周工地噪声并排序
* @return
*/
@GetMapping("selectWeekNoice")
@ApiOperation("查询近一周工地噪声并排序")
public Result selectWeekNoice(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectWeekNoice();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 查询近一月工地噪声并排序
* @return
*/
@GetMapping("selectMonthNoice")
@ApiOperation("查询近一月工地噪声并排序")
public Result selectMonthNoice(){
List<BuildingRecordsDto> recordsDtos = buildingRecordsMapper.selectMonthNoice();
Result success = Result.success(recordsDtos);
return success;
}
/**
* 根据工地名称搜索工地
* @param projectName
* @return
*/
@GetMapping("selectByProjectName")
@ApiOperation("根据工地名称搜索工地")
public Result selectByProjectName(String projectName){
List<BuildingRecordsDto> 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<BuildingRecordsDto> c = buildingRecordsMapper.selectByJdWd(around[0], around[2], around[1], around[3]);
Result success = Result.success(c);
return success;
}
} }

View File

@ -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;//噪声
}

View File

@ -1,8 +1,12 @@
package com.hisense.monitormanage.mapper; package com.hisense.monitormanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisense.monitormanage.dto.BuildingRecordsDto;
import com.hisense.monitormanage.entity.BuildingRecords; 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.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -16,4 +20,44 @@ import java.util.Map;
*/ */
public interface BuildingRecordsMapper extends BaseMapper<BuildingRecords> { public interface BuildingRecordsMapper extends BaseMapper<BuildingRecords> {
public void batchSave(@Param("list") List<Map> list); public void batchSave(@Param("list") List<Map> list);
void batchUpdate(@Param("list") List<Map> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> 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<BuildingRecordsDto> selectByJdWd(@Param("jd") Double jd,
@Param("jd1") Double jd1,
@Param("wd") Double wd,
@Param("wd1") Double wd1);
} }

View File

@ -9,6 +9,7 @@ import com.hisense.monitormanage.mapper.BuildingRecordsMapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
@ -34,9 +35,8 @@ public class BuildingRecordsService {
@Autowired @Autowired
private RestTemplate restTemplate; private RestTemplate restTemplate;
private String url = "http://scxjsw.qingdao.gov.cn/monitorData/real-time";
public List<Map> getRecords(){ public List<Map> getRecords(){
String url = "http://scxjsw.qingdao.gov.cn/monitorData/real-time";
Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
map.put("appid",""); map.put("appid","");
map.put("timestamp",""); map.put("timestamp","");
@ -60,10 +60,10 @@ public class BuildingRecordsService {
e.printStackTrace(); e.printStackTrace();
log.error("[BuildingRecordsService-getRecords] Exception:"+e.getMessage()); log.error("[BuildingRecordsService-getRecords] Exception:"+e.getMessage());
} }
return maps; return maps;
} }
@Scheduled(cron = "0 0 7/1 * * ?")
public boolean getAndSaveRecords(){ public boolean getAndSaveRecords(){
List<Map> maps = this.getRecords(); List<Map> maps = this.getRecords();
boolean result = false; boolean result = false;
@ -81,6 +81,24 @@ public class BuildingRecordsService {
return result; return result;
} }
public boolean getUpdateRecords(){
List<Map> maps = this.getRecords();
boolean result = false;
if(maps.size() > 0){
List<List<Map>> 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<BuildingRecords> listRecords(String pushTime){ public List<BuildingRecords> listRecords(String pushTime){
QueryWrapper<BuildingRecords> wrapper = new QueryWrapper<>(); QueryWrapper<BuildingRecords> wrapper = new QueryWrapper<>();
wrapper.like("push_time",pushTime); wrapper.like("push_time",pushTime);
@ -88,4 +106,6 @@ public class BuildingRecordsService {
list = buildingRecordsMapper.selectList(wrapper); list = buildingRecordsMapper.selectList(wrapper);
return list; return list;
} }
} }

View File

@ -16,4 +16,18 @@
</foreach> </foreach>
</insert> </insert>
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" separator=";">
update t_building_records
<set>
project_name = #{item.projectName},
push_time = #{item.pushTime},
appid = #{item.appid},
pm10 = #{item.pm10},
noice = #{item.noice}
</set>
where build_license = #{item.buildLicense}
</foreach>
</update>
</mapper> </mapper>