1、新增工地接口
This commit is contained in:
parent
238e13d98e
commit
d29b05fc32
|
@ -2,7 +2,6 @@ package com.hisense.monitormanage.config;
|
|||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;//
|
||||
import org.springframework.context.annotation.Configuration;//
|
||||
import springfox.documentation.builders.ApiInfoBuilder;//
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package com.hisense.monitormanage.controller;
|
||||
|
||||
import com.hisense.monitormanage.entity.BuildingRecords;
|
||||
import com.hisense.monitormanage.entity.Result;
|
||||
import com.hisense.monitormanage.service.BuildingRecordsService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName BuildingController.java
|
||||
* @Description 工地
|
||||
* @createTime 2022年05月17日 15:26:00
|
||||
*/
|
||||
@Api(tags = "工地")
|
||||
@RequestMapping("api/project/building")
|
||||
@RestController
|
||||
public class BuildingController {
|
||||
@Autowired
|
||||
private BuildingRecordsService buildingRecordsService;
|
||||
|
||||
@GetMapping("/getRecords")
|
||||
@ApiOperation("测试,获取工地实时数据--调用接口")
|
||||
public List<Map> getRecords(){
|
||||
return buildingRecordsService.getRecords();
|
||||
}
|
||||
|
||||
@GetMapping("/getAndSaveRecords")
|
||||
@ApiOperation("获取工地实时数据并保存到表中--调用接口获取")
|
||||
public Result getAndSaveRecords(){
|
||||
boolean result = buildingRecordsService.getAndSaveRecords();
|
||||
if(result){
|
||||
return Result.success();
|
||||
}else{
|
||||
return Result.error(String.valueOf(result));
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/listRecords")
|
||||
@ApiOperation("获取工地实时数据列表-从t_building_records表中查询")
|
||||
@ApiImplicitParam(name="pushTime",value="上传时间",paramType = "query",required = true,dataType = "string",example = "2022-01-01")
|
||||
public List<BuildingRecords> listRecords(
|
||||
@RequestParam(value="pushTime") String pushTime
|
||||
){
|
||||
return buildingRecordsService.listRecords(pushTime);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package com.hisense.monitormanage.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName BuildingRecords.java
|
||||
* @Description 工地实时信息类
|
||||
* @createTime 2022年05月17日 15:28:00
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@TableName("t_building_records")
|
||||
@ApiModel("工地实时数据")
|
||||
public class BuildingRecords {
|
||||
@TableId
|
||||
@ApiModelProperty("id")
|
||||
private Integer id;
|
||||
@ApiModelProperty("项目名称")
|
||||
private String projectName;
|
||||
@ApiModelProperty("项目建筑批准编号")
|
||||
private String buildLicense;
|
||||
@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
|
||||
@ApiModelProperty("数据上传时间")
|
||||
private LocalDateTime pushTime;
|
||||
@ApiModelProperty("appid")
|
||||
private String appid;
|
||||
@ApiModelProperty("pm10值")
|
||||
private double pm10;
|
||||
@ApiModelProperty("噪音值")
|
||||
private double noice;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.hisense.monitormanage.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.hisense.monitormanage.entity.BuildingRecords;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName BuildingRecordsMapper.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年05月17日 15:32:00
|
||||
*/
|
||||
public interface BuildingRecordsMapper extends BaseMapper<BuildingRecords> {
|
||||
public void batchSave(@Param("list") List<Map> list);
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
package com.hisense.monitormanage.service;
|
||||
|
||||
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.entity.BuildingRecords;
|
||||
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.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
* @version 1.0.0
|
||||
* @ClassName BuildingRecordsService.java
|
||||
* @Description TODO
|
||||
* @createTime 2022年05月17日 15:33:00
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class BuildingRecordsService {
|
||||
@Autowired
|
||||
private BuildingRecordsMapper buildingRecordsMapper;
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
private String url = "http://scxjsw.qingdao.gov.cn/monitorData/real-time";
|
||||
|
||||
public List<Map> getRecords(){
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("appid","");
|
||||
map.put("timestamp","");
|
||||
map.put("sign","");
|
||||
map.put("data","");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
List<Map> maps = new ArrayList<>();
|
||||
try{
|
||||
responseEntity = restTemplate.postForEntity(url,map,JSONObject.class);
|
||||
if (responseEntity.getStatusCodeValue() == 200) {
|
||||
JSONObject result = responseEntity.getBody();
|
||||
if(result.getIntValue("code") == 0){
|
||||
JSONArray jsonArray = result.getJSONArray("data");
|
||||
if(jsonArray != null){
|
||||
maps = JSONObject.parseArray(JSONArray.toJSONString(jsonArray),Map.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("[BuildingRecordsService-getRecords] Exception:"+e.getMessage());
|
||||
}
|
||||
|
||||
return maps;
|
||||
}
|
||||
|
||||
public boolean getAndSaveRecords(){
|
||||
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.batchSave(l));
|
||||
result = true;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
log.error("[BuildingRecordsService-getAndSaveRecords] Exception:"+e.getMessage());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<BuildingRecords> listRecords(String pushTime){
|
||||
QueryWrapper<BuildingRecords> wrapper = new QueryWrapper<>();
|
||||
wrapper.like("push_time",pushTime);
|
||||
List<BuildingRecords> list = new ArrayList<>();
|
||||
list = buildingRecordsMapper.selectList(wrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hisense.monitormanage.mapper.BuildingRecordsMapper">
|
||||
|
||||
<insert id="batchSave" parameterType="java.util.List">
|
||||
insert into t_building_records
|
||||
(
|
||||
project_name,build_license,push_time,appid,pm10,noice
|
||||
)
|
||||
values
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(
|
||||
#{item.projectName},#{item.buildLicense},#{item.pushTime},#{item.appid},
|
||||
#{item.pm10},#{item.noice}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue