From d29b05fc323511a211c52e335f7b3d23c542260b Mon Sep 17 00:00:00 2001 From: yitonglei Date: Tue, 17 May 2022 17:04:30 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E5=B7=A5=E5=9C=B0?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitormanage/config/SwaggerConfig.java | 1 - .../controller/BuildingController.java | 58 ++++++++++++ .../monitormanage/entity/BuildingRecords.java | 43 +++++++++ .../mapper/BuildingRecordsMapper.java | 19 ++++ .../service/BuildingRecordsService.java | 91 +++++++++++++++++++ .../mapper/BuildingRecordsMapper.xml | 19 ++++ 6 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/hisense/monitormanage/controller/BuildingController.java create mode 100644 src/main/java/com/hisense/monitormanage/entity/BuildingRecords.java create mode 100644 src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java create mode 100644 src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java create mode 100644 src/main/resources/mapper/BuildingRecordsMapper.xml diff --git a/src/main/java/com/hisense/monitormanage/config/SwaggerConfig.java b/src/main/java/com/hisense/monitormanage/config/SwaggerConfig.java index b479cef..74f95c0 100644 --- a/src/main/java/com/hisense/monitormanage/config/SwaggerConfig.java +++ b/src/main/java/com/hisense/monitormanage/config/SwaggerConfig.java @@ -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;// diff --git a/src/main/java/com/hisense/monitormanage/controller/BuildingController.java b/src/main/java/com/hisense/monitormanage/controller/BuildingController.java new file mode 100644 index 0000000..c75043a --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/controller/BuildingController.java @@ -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 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 listRecords( + @RequestParam(value="pushTime") String pushTime + ){ + return buildingRecordsService.listRecords(pushTime); + } + +} diff --git a/src/main/java/com/hisense/monitormanage/entity/BuildingRecords.java b/src/main/java/com/hisense/monitormanage/entity/BuildingRecords.java new file mode 100644 index 0000000..e052ee5 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/BuildingRecords.java @@ -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; +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java b/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java new file mode 100644 index 0000000..76ac22e --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/BuildingRecordsMapper.java @@ -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 { + public void batchSave(@Param("list") List list); +} diff --git a/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java b/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java new file mode 100644 index 0000000..c753f84 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/service/BuildingRecordsService.java @@ -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 getRecords(){ + 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); + 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 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){ + e.printStackTrace(); + log.error("[BuildingRecordsService-getAndSaveRecords] Exception:"+e.getMessage()); + } + } + return result; + } + + public List listRecords(String pushTime){ + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.like("push_time",pushTime); + List list = new ArrayList<>(); + list = buildingRecordsMapper.selectList(wrapper); + return list; + } +} diff --git a/src/main/resources/mapper/BuildingRecordsMapper.xml b/src/main/resources/mapper/BuildingRecordsMapper.xml new file mode 100644 index 0000000..dfada16 --- /dev/null +++ b/src/main/resources/mapper/BuildingRecordsMapper.xml @@ -0,0 +1,19 @@ + + + + + + insert into t_building_records + ( + project_name,build_license,push_time,appid,pm10,noice + ) + values + + ( + #{item.projectName},#{item.buildLicense},#{item.pushTime},#{item.appid}, + #{item.pm10},#{item.noice} + ) + + + + \ No newline at end of file