From 1c5245e6481c416f914abd76c695108c9c6481b2 Mon Sep 17 00:00:00 2001 From: yitonglei Date: Mon, 23 May 2022 08:54:31 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=89=B9=E9=87=8F=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E7=8E=AF=E5=8D=AB=E8=BD=A6=E4=BD=9C=E4=B8=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=B0=83=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SanitationController.java | 1 + .../monitormanage/entity/SanitationTask.java | 3 ++ .../mapper/SanitationTaskMapper.java | 14 +++++++ .../monitormanage/service/MonitorService.java | 31 ++++++++++++--- .../service/RoadDataService.java | 1 + .../service/SanitationService.java | 39 ++++++++++++++++++- .../service/SedimentTrailService.java | 5 ++- .../resources/mapper/SanitationMapper.xml | 4 +- 8 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/hisense/monitormanage/mapper/SanitationTaskMapper.java diff --git a/src/main/java/com/hisense/monitormanage/controller/SanitationController.java b/src/main/java/com/hisense/monitormanage/controller/SanitationController.java index 855dfd7..7f87a8e 100644 --- a/src/main/java/com/hisense/monitormanage/controller/SanitationController.java +++ b/src/main/java/com/hisense/monitormanage/controller/SanitationController.java @@ -30,6 +30,7 @@ public class SanitationController { return null; } + @GetMapping("/saveSanitationRoad") @ApiOperation("测试获取环卫道路数据并保存到表中") public Result saveSanitationRoad(){ diff --git a/src/main/java/com/hisense/monitormanage/entity/SanitationTask.java b/src/main/java/com/hisense/monitormanage/entity/SanitationTask.java index 7ae6d27..6e21be9 100644 --- a/src/main/java/com/hisense/monitormanage/entity/SanitationTask.java +++ b/src/main/java/com/hisense/monitormanage/entity/SanitationTask.java @@ -62,5 +62,8 @@ public class SanitationTask { private double zycsds; @ApiModelProperty("作业GPS点数") private double zygpsds; + @JsonFormat(pattern="yyyy-MM-dd mm:HH:ss",timezone = "GMT+8") + @ApiModelProperty("上传时间") + private LocalDateTime updatetime; } diff --git a/src/main/java/com/hisense/monitormanage/mapper/SanitationTaskMapper.java b/src/main/java/com/hisense/monitormanage/mapper/SanitationTaskMapper.java new file mode 100644 index 0000000..9d5a8d3 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/SanitationTaskMapper.java @@ -0,0 +1,14 @@ +package com.hisense.monitormanage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hisense.monitormanage.entity.SanitationTask; + +/** + * @author admin + * @version 1.0.0 + * @ClassName sanitationTaskMapper.java + * @Description TODO + * @createTime 2022年05月20日 17:54:00 + */ +public interface SanitationTaskMapper extends BaseMapper { +} diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index 2407167..8e6101f 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -713,10 +713,10 @@ public class MonitorService { } } - //环卫车辆数据2,作业 + //环卫车辆数据2,作业,5月20号已经把能查到的都保存到表中了(忘了保存updatetime) public List resCatalogApplyHJWSZY () { String token = this.qidiToken(); - String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1"; //String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); @@ -726,15 +726,13 @@ public class MonitorService { // search.put("opt","LIKE"); // search.put("key","ZYRQ"); // search.put("val",this.dateStr()); - search.put("opt","EQ"); - search.put("key","SSQS"); - search.put("val","市北区"); map.put("json",search); HttpEntity> request = new HttpEntity<>(null, headers); ResponseEntity responseEntity; try { responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + //responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); JSONObject jsonObject = responseEntity.getBody(); JSONArray jsonArray = jsonObject.getJSONArray("list"); return JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); @@ -744,6 +742,29 @@ public class MonitorService { } } + public List resCatalogApplyHJWSZY(String updatetime) throws Exception{ + String token = this.qidiToken(); + String url = "http://120.221.95.13:9090/catalog/resCatalogApply/getData/UC_QUERY_HJWS_307013400000000363_1?search=[{json}]"; + HttpHeaders headers = new HttpHeaders(); + headers.add("Authorization", "Bearer " + token); + + List maps = new ArrayList<>(); + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); + search.put("opt","GT"); + search.put("key","updatetime"); + search.put("val",updatetime); + map.put("json",search); + + HttpEntity> request = new HttpEntity<>(null, headers); + ResponseEntity responseEntity; + responseEntity = restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class,map); + JSONObject jsonObject = responseEntity.getBody(); + JSONArray jsonArray = jsonObject.getJSONArray("list"); + maps = JSONObject.parseArray(JSONObject.toJSONString(jsonArray), Map.class); + + return maps; + } //环卫道路明细数据 public List resCatalogApplyHJWSRoad () { String token = this.qidiToken(); diff --git a/src/main/java/com/hisense/monitormanage/service/RoadDataService.java b/src/main/java/com/hisense/monitormanage/service/RoadDataService.java index 91f3f30..381483f 100644 --- a/src/main/java/com/hisense/monitormanage/service/RoadDataService.java +++ b/src/main/java/com/hisense/monitormanage/service/RoadDataService.java @@ -92,6 +92,7 @@ public class RoadDataService { LocalDateTime dateTime = LocalDateTime.of(yestDay.getYear(),yestDay.getMonth(),yestDay.getDayOfMonth(),0,0,0); return dateTime.format(formatter); } + //获取当前日期的时间串,2022-05-08 private String dateStr(){ LocalDate localDate = LocalDate.now(); diff --git a/src/main/java/com/hisense/monitormanage/service/SanitationService.java b/src/main/java/com/hisense/monitormanage/service/SanitationService.java index 2d303b3..b98cefd 100644 --- a/src/main/java/com/hisense/monitormanage/service/SanitationService.java +++ b/src/main/java/com/hisense/monitormanage/service/SanitationService.java @@ -1,14 +1,18 @@ package com.hisense.monitormanage.service; -import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Lists; import com.hisense.monitormanage.entity.Result; +import com.hisense.monitormanage.entity.SanitationTask; import com.hisense.monitormanage.mapper.SanitationMapper; +import com.hisense.monitormanage.mapper.SanitationTaskMapper; +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.web.client.RestTemplate; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -20,6 +24,7 @@ import java.util.Map; * @createTime 2022年05月19日 11:23:00 */ @Service +@Slf4j public class SanitationService { @Autowired private SanitationMapper sanitationMapper; @@ -27,6 +32,8 @@ public class SanitationService { private RestTemplate restTemplate; @Autowired private MonitorService monitorService; + @Autowired + private SanitationTaskMapper sanitationTaskMapper; public Result saveSantation(){ @@ -49,6 +56,7 @@ public class SanitationService { return Result.success(); }catch (Exception e){ e.printStackTrace(); + log.error("[SanitationService saveSanitationRoad] Exception:"+e.getMessage()); return Result.error(e.getMessage()); } } @@ -63,8 +71,35 @@ public class SanitationService { return Result.success(); }catch (Exception e){ e.printStackTrace(); + log.error("[SanitationService saveSanitationTask] Exception:"+e.getMessage()); return Result.error(e.getMessage()); } } + //批量查询环卫车作业数据并保存, + @Scheduled(cron = "0 0 8 * * ?") + public void saveSanitationTaskScheduled(){ + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.orderByDesc("updatetime"); + SanitationTask sanitationTask = sanitationTaskMapper.selectOne(wrapper); + List maps = new ArrayList<>(); + + try{ + if(sanitationTask != null){ + maps = monitorService.resCatalogApplyHJWSZY(String.valueOf(sanitationTask.getUpdatetime())); + + }else{ + maps = monitorService.resCatalogApplyHJWSZY(); + } + + if(maps.size() > 0){ + List> lists = Lists.partition(maps,100); + lists.forEach(list->sanitationMapper.batchSaveSanitationTask(list)); + } + }catch (Exception e){ + e.printStackTrace(); + log.error("[SanitationService saveSanitationTaskScheduled] Exception:"+e.getMessage()); + } + } + } diff --git a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java index 44ae754..8cc3432 100644 --- a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java +++ b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java @@ -6,6 +6,7 @@ import com.hisense.monitormanage.entity.SedimentTrail; import com.hisense.monitormanage.mapper.SedimentTrailMapper; import com.hisense.monitormanage.utils.LongLatUtil; import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,11 +23,11 @@ import java.util.stream.Collectors; * @author admin * @version 1.0.0 * @ClassName SedimentTrailService.java - * @Description TODO + * @Description 渣土车service * @createTime 2022年05月09日 14:01:00 */ @Service -@Log4j2 +@Slf4j public class SedimentTrailService { @Autowired private SedimentTrailMapper sedimentTrailMapper; diff --git a/src/main/resources/mapper/SanitationMapper.xml b/src/main/resources/mapper/SanitationMapper.xml index d608096..f6c6f54 100644 --- a/src/main/resources/mapper/SanitationMapper.xml +++ b/src/main/resources/mapper/SanitationMapper.xml @@ -39,14 +39,14 @@ insert into t_sanitation_task (dlmc,ksdl,zzdl,ssqs,cph,zywcl,zyrq,zylx,zysj,zyts,zypc,zyzd, - zykd,zymj,wzyds,zycsds,zygpsds + zykd,zymj,wzyds,zycsds,zygpsds,updatetime ) values ( #{item.DLMC},#{item.KSDL},#{item.ZZDL},#{item.SSQS},#{item.CPH},#{item.ZYWCL}, #{item.ZYRQ},#{item.ZYLX},#{item.ZYSJ},#{item.ZYTS},#{item.ZYPC},#{item.ZYZD}, - #{item.ZYKD},#{item.ZYMJ},#{item.WZYDS},#{item.ZYCSDS},#{item.ZYGPSDS} + #{item.ZYKD},#{item.ZYMJ},#{item.WZYDS},#{item.ZYCSDS},#{item.ZYGPSDS},#{item.updatetime} )