From 04808c7566a048e31f53f50909e7bd8f3836bcdb Mon Sep 17 00:00:00 2001 From: guo Date: Wed, 2 Aug 2023 17:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=BA=E7=A8=B3=E8=8E=B7=E5=8F=96=E6=89=AC?= =?UTF-8?q?=E5=B0=98=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vo/TowerCurrentCountVo.java | 4 +- .../modules/bigdevice/mapper/TowerMapper.java | 3 +- .../bigdevice/mapper/xml/LifterMapper.xml | 2 +- .../mapper/xml/LifterWorkCycleMapper.xml | 2 +- .../bigdevice/mapper/xml/TowerMapper.xml | 9 +- .../service/impl/TowerServiceImpl.java | 8 +- .../environment/entity/DustNoiseData.java | 37 +++--- .../mapper/xml/DustNoiseDataMapper.xml | 3 +- .../impl/DustNoiseDataServiceImpl.java | 37 +++--- .../impl/EnvironmentAlarmServiceImpl.java | 75 ------------ ...kwWireRopeInspectionDamageRecordMapper.xml | 3 + .../com/zhgd/xmgl/task/DevTestDataTask.java | 12 +- .../zhgd/xmgl/task/EnvironmentDevTask.java | 110 +++++++++++++++--- .../xmgl/task/dto/EnvironmentDustDataDto.java | 27 +++++ .../java/com/zhgd/xmgl/util/TimeUtil.java | 15 ++- .../java/com/zhgd/xmgl/util/XiwonUtil.java | 4 +- .../application-gsx-other-env-show.properties | 4 + 17 files changed, 205 insertions(+), 150 deletions(-) create mode 100644 src/main/java/com/zhgd/xmgl/task/dto/EnvironmentDustDataDto.java diff --git a/src/main/java/com/zhgd/xmgl/modules/bigdevice/entity/vo/TowerCurrentCountVo.java b/src/main/java/com/zhgd/xmgl/modules/bigdevice/entity/vo/TowerCurrentCountVo.java index d410f5f78..ebb0882ce 100644 --- a/src/main/java/com/zhgd/xmgl/modules/bigdevice/entity/vo/TowerCurrentCountVo.java +++ b/src/main/java/com/zhgd/xmgl/modules/bigdevice/entity/vo/TowerCurrentCountVo.java @@ -20,6 +20,8 @@ public class TowerCurrentCountVo { private Integer weightSet; @ApiModelProperty(value = "今日吊重") private Double totalLoading; - @ApiModelProperty(value = "工作时长(运行时间,塔吊工作循环时长)") + @ApiModelProperty(value = "工作时长(秒,运行时间,塔吊工作循环时长)") private Integer runMinuteTime; + @ApiModelProperty(value = "工作时长(时分秒)") + private String runMinuteTimeName; } diff --git a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/TowerMapper.java b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/TowerMapper.java index 85ba6fbc5..b1a1a4fa3 100644 --- a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/TowerMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/TowerMapper.java @@ -3,6 +3,7 @@ package com.zhgd.xmgl.modules.bigdevice.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.zhgd.jeecg.common.mybatis.EntityMap; import com.zhgd.xmgl.modules.bigdevice.entity.Tower; +import com.zhgd.xmgl.modules.bigdevice.entity.vo.TowerCurrentCountVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -44,7 +45,7 @@ public interface TowerMapper extends BaseMapper { Map selectTowerOnLineCount(Map map); - List> selectTowerCurrentCount(Map map); + List selectTowerCurrentCount(Map map); List> selectTowerAlarmRankingList(Map map); diff --git a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterMapper.xml b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterMapper.xml index 021e72ac6..1e789769b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterMapper.xml @@ -194,7 +194,7 @@ TIMESTAMPDIFF(YEAR, wi.enter_date, CURDATE()) as workYear, (SELECT IFNULL(a.work_time, 0) continuous_working_time FROM lifter_work_cycle a - WHERE a.driver_id_card = wi.id_card + WHERE a.dev_sn = l.dev_sn ORDER BY a.add_time DESC LIMIT 1) continuous_working_time, wi.id_card driverIdCard diff --git a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterWorkCycleMapper.xml b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterWorkCycleMapper.xml index 79a44a355..7b4f3bdae 100644 --- a/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterWorkCycleMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/bigdevice/mapper/xml/LifterWorkCycleMapper.xml @@ -32,7 +32,7 @@ - SELECT de.weight_set weightSet, de.dev_sn devSn, de.dev_name devName, @@ -257,11 +257,12 @@ IFNULL(tp.totalLoading, 0) totalLoading, IFNULL(tp2.faultNum, 0) faultNum, IFNULL(tp3.alarmNum, 0) alarmNum, - IFNULL(tp3.warningNum, 0) warningNum + IFNULL(tp3.warningNum, 0) warningNum, + IFNULL(tp.runMinuteTime,0) runMinuteTime FROM tower de LEFT JOIN (select a.dev_sn, count(1) cycleNum, - IFNULL(SUM(TIMESTAMPDIFF(MINUTE, a.start_time, a.end_time)), 0) runMinuteTime, + SUM(a.work_time) runMinuteTime, IFNULL(SUM(loading), 0) totalLoading FROM tower_work_cycle a WHERE a.project_sn = #{projectSn} @@ -702,7 +703,7 @@ TIMESTAMPDIFF(YEAR, wi.birthday, CURDATE()) as age, (select IFNULL(a.work_time, 0) continuous_working_time from tower_work_cycle a - where a.driver_id_card = wi.id_card + where a.dev_sn = t.dev_sn order by a.add_time desc limit 1) continuous_working_time, wi.id_card driverIdCard diff --git a/src/main/java/com/zhgd/xmgl/modules/bigdevice/service/impl/TowerServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/bigdevice/service/impl/TowerServiceImpl.java index fecdf9090..409e65381 100644 --- a/src/main/java/com/zhgd/xmgl/modules/bigdevice/service/impl/TowerServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/bigdevice/service/impl/TowerServiceImpl.java @@ -315,9 +315,11 @@ public class TowerServiceImpl extends ServiceImpl implements @Override public List selectTowerCurrentCount(Map map) { - List> maps = towerMapper.selectTowerCurrentCount(map); - List countVoList = maps.stream().map(e -> BeanUtil.toBeanIgnoreCase(e, TowerCurrentCountVo.class, true)).collect(Collectors.toList()); - return countVoList; + List towerCurrentCountVos = towerMapper.selectTowerCurrentCount(map); + for (TowerCurrentCountVo vo : towerCurrentCountVos) { + vo.setRunMinuteTimeName(TimeUtil.toHourMinSecond(vo.getRunMinuteTime())); + } + return towerCurrentCountVos; } @Override diff --git a/src/main/java/com/zhgd/xmgl/modules/environment/entity/DustNoiseData.java b/src/main/java/com/zhgd/xmgl/modules/environment/entity/DustNoiseData.java index 9d19a28b2..273c97b78 100644 --- a/src/main/java/com/zhgd/xmgl/modules/environment/entity/DustNoiseData.java +++ b/src/main/java/com/zhgd/xmgl/modules/environment/entity/DustNoiseData.java @@ -58,41 +58,41 @@ public class DustNoiseData implements Serializable { */ @Excel(name = "PM10(ug/m3)", width = 15) @ApiModelProperty(value = "扬尘") - private java.lang.Float pm10; + private java.lang.Double pm10; /** * pm25 */ @Excel(name = "PM2.5(ug/m3)", width = 15) @ApiModelProperty(value = "pm25") - private java.lang.Float pm25; + private java.lang.Double pm25; - @Excel(name = "白天噪音(dB)", width = 15) - @ApiModelProperty(value = "白天噪音") - private java.lang.Float noise; + @Excel(name = "噪音(dB)", width = 15) + @ApiModelProperty(value = "噪音") + private java.lang.Double noise; /** * tsp测试值 */ @Excel(name = "TSP(ug/m3)", width = 15) @ApiModelProperty(value = "tsp测试值") - private java.lang.Float tsp; + private java.lang.Double tsp; /** * 温度 */ @Excel(name = "温度(℃)", width = 15) @ApiModelProperty(value = "温度") - private java.lang.Float temperature; + private java.lang.Double temperature; /** * 湿度 */ @Excel(name = "湿度(%RH)", width = 15) @ApiModelProperty(value = "湿度") - private java.lang.Float humidity; + private java.lang.Double humidity; /** * 风速 */ @Excel(name = "风速(m/s)", width = 15) @ApiModelProperty(value = "风速") - private java.lang.Float windspeed; + private java.lang.Double windspeed; /** * 风向 */ @@ -104,28 +104,28 @@ public class DustNoiseData implements Serializable { */ @Excel(name = "大气压", width = 15) @ApiModelProperty(value = "大气压") - private java.lang.Float pressure; + private java.lang.Double pressure; /** * 电压 */ @Excel(name = "电压", width = 15) @ApiModelProperty(value = "电压") - private java.lang.Float voltage; + private java.lang.Double voltage; /** * 板载温度 */ @Excel(name = "板载温度", width = 15) @ApiModelProperty(value = "板载温度") - private java.lang.Float plateTemperature; + private java.lang.Double plateTemperature; /** * 板载湿度 */ @Excel(name = "板载湿度", width = 15) @ApiModelProperty(value = "板载湿度") - private java.lang.Float plateHumidity; - @Excel(name = "夜晚噪音", width = 15) - @ApiModelProperty(value = "夜晚噪音") - private java.lang.Float nightNoise; + private java.lang.Double plateHumidity; + + @ApiModelProperty(value = "携稳id") + private Long xiewenId; @ApiModelProperty(value = "风向名称") @TableField(exist = false) @@ -144,9 +144,6 @@ public class DustNoiseData implements Serializable { @ApiModelProperty(value = "噪音是否报警,0否,1是") private java.lang.Integer noiseAlarmType; @TableField(exist = false) - @ApiModelProperty(value = "夜晚噪音是否报警,0否,1是") - private java.lang.Integer nightNoiseAlarmType; - @TableField(exist = false) @ApiModelProperty(value = "湿度是否报警,0否,1是") private java.lang.Integer humidityAlarmType; @TableField(exist = false) @@ -165,4 +162,6 @@ public class DustNoiseData implements Serializable { @TableField(exist = false) @ApiModelProperty(value = "时间") private java.lang.String time; + + } diff --git a/src/main/java/com/zhgd/xmgl/modules/environment/mapper/xml/DustNoiseDataMapper.xml b/src/main/java/com/zhgd/xmgl/modules/environment/mapper/xml/DustNoiseDataMapper.xml index d598b43dd..6890dca7c 100644 --- a/src/main/java/com/zhgd/xmgl/modules/environment/mapper/xml/DustNoiseDataMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/environment/mapper/xml/DustNoiseDataMapper.xml @@ -133,8 +133,7 @@ avg(pressure) pressure, avg(voltage) voltage, avg(plate_temperature) plate_temperature, - avg(plate_humidity) plate_humidity, - avg(night_noise) night_noise + avg(plate_humidity) plate_humidity FROM dust_noise_data WHERE diff --git a/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java index 8a088e017..721a9ae9b 100644 --- a/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/environment/service/impl/DustNoiseDataServiceImpl.java @@ -84,13 +84,13 @@ public class DustNoiseDataServiceImpl extends ServiceImpl= alarmMap.getNoiseWarning()) { - //if () { - EnvironmentAlarm environmentAlarm = new EnvironmentAlarm(); - environmentAlarm.setAlarmTypeId(4L); - environmentAlarm.setAlarmTime(new Timestamp(System.currentTimeMillis())); - environmentAlarm.setAvgData(dustNoiseData.getNoise().doubleValue()); - environmentAlarm.setDeviceId(dustNoiseData.getDeviceId()); - environmentAlarm.setAlarmValue(alarmMap.getNoiseWarning().doubleValue()); - if (alarmMap.getNoiseWarning().doubleValue() != 0d) { - environmentAlarm.setExceed( - (dustNoiseData.getNoise().doubleValue() - alarmMap.getNoiseWarning().doubleValue()) - / alarmMap.getNoiseWarning().doubleValue()); - } else { - environmentAlarm.setExceed(0d); - } - environmentAlarm.setType(0); - environmentAlarm.setProjectSn(environmentDev.getProjectSn()); - environmentAlarmMapper.insert(environmentAlarm); - alarmIdList.add(environmentAlarm.getId()); - if (pushPerson != null && pushPerson.length() > 0) { - int size = pushPerson.split(",").length; - String title = devname + "扬尘监测设备报警"; - String msg = devname + " 扬尘监测设备检测到夜晚噪音值异常,噪音实时数值" + dustNoiseData.getNoise() + " 请及时处理"; - for (int i = 0; i < size; i++) { - Notice notice = new Notice(); - notice.setAccountId(Long.valueOf(pushPerson.split(",")[i])); - notice.setMsg(msg); - notice.setTitle(title); - notice.setSendTime(format1.format(new Date())); - notice.setType("7"); - noticeService.addNotice(notice, true); - } - //jpushClientUtil.sendToAliases(String.valueOf(pushPerson),"扬尘监测设备报警",title ,msg, null); - } - - } else { - if (Objects.equals(dustNoiseData.getNightNoiseAlarmType(), 1) && warningMap != null && warningMap.getNoiseWarning() != null && dustNoiseData.getNoise() != null - && dustNoiseData.getNoise().doubleValue() >= warningMap.getNoiseWarning().doubleValue()) { - //if (dustNoiseData.getNoise().doubleValue() > Double.valueOf(warningMap.get("noiseWarning").toString())) { - EnvironmentAlarm environmentAlarm = new EnvironmentAlarm(); - environmentAlarm.setAlarmTypeId(4L); - environmentAlarm.setAlarmTime(new Timestamp(System.currentTimeMillis())); - environmentAlarm.setAvgData(dustNoiseData.getNoise().doubleValue()); - environmentAlarm.setDeviceId(dustNoiseData.getDeviceId()); - environmentAlarm.setAlarmValue(warningMap.getNoiseWarning().doubleValue()); - if (warningMap.getNoiseWarning().doubleValue() != 0d) { - environmentAlarm.setExceed( - (dustNoiseData.getNoise().doubleValue() - warningMap.getNoiseWarning().doubleValue()) - / warningMap.getNoiseWarning().doubleValue()); - } else { - environmentAlarm.setExceed(0d); - } - environmentAlarm.setType(1); - environmentAlarm.setProjectSn(environmentDev.getProjectSn()); - environmentAlarmMapper.insert(environmentAlarm); - if (pushPerson != null && pushPerson.length() > 0) { - int size = pushPerson.split(",").length; - String title = devname + "扬尘监测设备预警"; - String msg = devname + " 扬尘监测设备检测到夜晚噪音值异常,噪音实时数值" + dustNoiseData.getNoise() + " 请及时处理"; - for (int i = 0; i < size; i++) { - Notice notice = new Notice(); - notice.setAccountId(Long.valueOf(pushPerson.split(",")[i])); - notice.setMsg(msg); - notice.setTitle(title); - notice.setSendTime(format1.format(new Date())); - notice.setType("7"); - noticeService.addNotice(notice, true); - } - //jpushClientUtil.sendToAliases(String.valueOf(pushPerson),"扬尘监测设备预警",title ,msg, null); - } - - } - } - // 需要24小时监测数据 // 比较实时 PM2.5 if (Objects.equals(dustNoiseData.getPm25AlarmType(), 1) && alarmMap != null && alarmMap.getPm25Warning() != null && dustNoiseData.getPm25() != null diff --git a/src/main/java/com/zhgd/xmgl/modules/tckw/mapper/xml/TckwWireRopeInspectionDamageRecordMapper.xml b/src/main/java/com/zhgd/xmgl/modules/tckw/mapper/xml/TckwWireRopeInspectionDamageRecordMapper.xml index 53e158778..b3d18b71e 100644 --- a/src/main/java/com/zhgd/xmgl/modules/tckw/mapper/xml/TckwWireRopeInspectionDamageRecordMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/tckw/mapper/xml/TckwWireRopeInspectionDamageRecordMapper.xml @@ -2,11 +2,14 @@ diff --git a/src/main/java/com/zhgd/xmgl/task/DevTestDataTask.java b/src/main/java/com/zhgd/xmgl/task/DevTestDataTask.java index 3ca8f1802..318e2e092 100644 --- a/src/main/java/com/zhgd/xmgl/task/DevTestDataTask.java +++ b/src/main/java/com/zhgd/xmgl/task/DevTestDataTask.java @@ -213,16 +213,16 @@ public class DevTestDataTask { } } - public static Float getRandomNum(int startNum, int randomNum) { + public static Double getRandomNum(int startNum, int randomNum) { Random random = new Random(); DecimalFormat df = new DecimalFormat("0.00"); - return Float.valueOf(df.format(startNum + random.nextInt(randomNum) + random.nextDouble())); + return Double.valueOf(df.format(startNum + random.nextInt(randomNum) + random.nextDouble())); } - public static Float getRandomNum() { + public static Double getRandomNum() { Random random = new Random(); DecimalFormat df = new DecimalFormat("0.00"); - return Float.valueOf(df.format(20 + random.nextInt(30) + random.nextDouble())); + return Double.valueOf(df.format(20 + random.nextInt(30) + random.nextDouble())); } public static Double getDoubleRandomNum(int num) { @@ -235,10 +235,10 @@ public class DevTestDataTask { } } - public static Float getFloatRandomNum() { + public static Double getFloatRandomNum() { Random random = new Random(); DecimalFormat df = new DecimalFormat("0.0"); - return Float.valueOf(df.format(random.nextDouble())); + return Double.valueOf(df.format(random.nextDouble())); } public static void main(String[] args) { diff --git a/src/main/java/com/zhgd/xmgl/task/EnvironmentDevTask.java b/src/main/java/com/zhgd/xmgl/task/EnvironmentDevTask.java index 77af62459..a81a0b58f 100644 --- a/src/main/java/com/zhgd/xmgl/task/EnvironmentDevTask.java +++ b/src/main/java/com/zhgd/xmgl/task/EnvironmentDevTask.java @@ -1,26 +1,35 @@ package com.zhgd.xmgl.task; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.gexin.fastjson.JSON; import com.zhgd.xmgl.modules.environment.entity.DustNoiseData; import com.zhgd.xmgl.modules.environment.entity.EnvironmentDev; import com.zhgd.xmgl.modules.environment.mapper.DustNoiseDataMapper; import com.zhgd.xmgl.modules.environment.mapper.EnvironmentDevMapper; +import com.zhgd.xmgl.task.dto.EnvironmentDustDataDto; import com.zhgd.xmgl.util.EnvironmentUtils; -import lombok.extern.log4j.Log4j; +import com.zhgd.xmgl.util.WindDirectionUtils; +import com.zhgd.xmgl.util.XiwonUtil; +import lombok.extern.slf4j.Slf4j; import net.javacrumbs.shedlock.core.SchedulerLock; +import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; +import javax.annotation.Resource; import java.text.DecimalFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; +import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; /** @@ -29,7 +38,7 @@ import java.util.stream.Collectors; * @author: Mr.Peng * @create: 2021-07-12 13:41 **/ -@Log4j +@Slf4j @Component public class EnvironmentDevTask { @Autowired @@ -40,12 +49,18 @@ public class EnvironmentDevTask { @Value("${isGetEnvironmentData}") private boolean isGetEnvironmentData; + @Value("${xiwon.postEnvironmentDustData:}") + private String postEnvironmentDustData; + + @Resource + private XiwonUtil xiwonUtil; + /** * 定时调用外部接口拉取设备实时数据 */ @Scheduled(cron = "0 0/2 * * * ?") - @SchedulerLock(name = "getEnvironmentData", lockAtMostFor = 1000*60*2, lockAtLeastFor = 1000*60*1) - public void getStandardData(){ + @SchedulerLock(name = "getEnvironmentData", lockAtMostFor = 1000 * 60 * 2, lockAtLeastFor = 1000 * 60 * 1) + public void getStandardData() { if (isGetEnvironmentData) { try { QueryWrapper queryWrapper = new QueryWrapper<>(); @@ -58,7 +73,7 @@ public class EnvironmentDevTask { if (array != null && array.size() > 0) { for (int i = 0; i < array.size(); i++) { JSONObject obj = array.getJSONObject(i); - if(dev.getDeviceId().equals(obj.getString("deviceAddr"))) { + if (dev.getDeviceId().equals(obj.getString("deviceAddr"))) { //判断设备是否在线 if ("2".equals(obj.getString("deviceStatus"))) { JSONArray jsonArray = obj.getJSONArray("realTimeData"); @@ -66,11 +81,11 @@ public class EnvironmentDevTask { for (int a = 0; a < jsonArray.size(); a++) { JSONObject obj2 = jsonArray.getJSONObject(a); if (obj2.getString("dataName").indexOf("PM10") >= 0) { - if (StringUtils.isNotEmpty(obj2.getString("dataValue"))&&obj2.getDouble("dataValue")!=0d) { + if (StringUtils.isNotEmpty(obj2.getString("dataValue")) && obj2.getDouble("dataValue") != 0d) { pm10List.add(Double.valueOf(obj2.getString("dataValue"))); } } else if (obj2.getString("dataName").indexOf("PM2.5") >= 0) { - if (StringUtils.isNotEmpty(obj2.getString("dataValue"))&&obj2.getDouble("dataValue")!=0d) { + if (StringUtils.isNotEmpty(obj2.getString("dataValue")) && obj2.getDouble("dataValue") != 0d) { pm25List.add(Double.valueOf(obj2.getString("dataValue"))); } } @@ -90,12 +105,12 @@ public class EnvironmentDevTask { if (pm10List.size() > 0) { //计算pm10平均值 double avg = pm10List.stream().collect(Collectors.averagingDouble(n -> n)); - dustNoiseData.setPm10(Float.valueOf(df.format(avg))); + dustNoiseData.setPm10(Double.valueOf(df.format(avg))); } if (pm25List.size() > 0) { //计算pm2.5平均值 double avg = pm25List.stream().collect(Collectors.averagingDouble(n -> n)); - dustNoiseData.setPm25(Float.valueOf(df.format(avg))); + dustNoiseData.setPm25(Double.valueOf(df.format(avg))); } dustNoiseDataMapper.insert(dustNoiseData); EnvironmentDev tempEnvironmentDev = new EnvironmentDev(); @@ -106,9 +121,78 @@ public class EnvironmentDevTask { } } } - }catch(Exception e){ + } catch (Exception e) { e.printStackTrace(); } } } + + + /** + * 获取扬尘数据(携稳) 每5分钟触发任务 + */ + @SchedulerLock(name = "getEnvironmentDustData", lockAtMostFor = 1000 * 60 * 5, lockAtLeastFor = 1000 * 60 * 3) + @Scheduled(cron = "0 0/5 * * * ?") + public void getEnvironmentDustData() { + if (StringUtils.isNotBlank(postEnvironmentDustData)) { + // 获取所有 + List devList = environmentDevMapper.selectList(null); + devList.forEach(dev -> CompletableFuture.runAsync(() -> { + doGetEnvironmentDustData(dev); + }).exceptionally(throwable -> { + log.error("err", throwable); + return null; + }) + ); + } + } + + private void doGetEnvironmentDustData(EnvironmentDev dev) { + // 设备sn + String devSn = dev.getDeviceId(); + log.info("doGetEnvironmentDustData设备sn:{}", devSn); + DustNoiseData newestData = dustNoiseDataMapper.selectOne(new LambdaQueryWrapper().eq(DustNoiseData::getDeviceId, devSn).orderByDesc(DustNoiseData::getXiewenId).last("limit 1")); + // 请求参数 + Map map = new HashMap<>(4); + map.put("pageSize", "10"); + map.put("pageNum", "1"); + JSONObject realTimeData = xiwonUtil.postForm(postEnvironmentDustData, map, JSONObject.class, (() -> { + map.put("deviceSn", devSn); + if (newestData != null && newestData.getXiewenId() != null) { + map.put("dataId", newestData.getXiewenId()); + } + return map; + })); + log.info("携稳接口响应数据(扬尘):devSn:{},rs:{}", devSn, JSON.toJSONString(realTimeData)); + Integer code = realTimeData.getInteger("code"); + // code校验是否成功请求 + if (code == HttpStatus.OK.value()) { + JSONArray dataArray = realTimeData.getJSONArray("data"); + if (CollUtil.isNotEmpty(dataArray)) { + // 解析请求到的参数,保存到我们的数据库 + for (Object o : dataArray) { + EnvironmentDustDataDto dto = BeanUtil.toBean(o, EnvironmentDustDataDto.class); + DustNoiseData data = new DustNoiseData(); + data.setProjectSn(dev.getProjectSn()); + data.setDeviceId(devSn); + data.setUploadDate(dto.getTime()); + data.setPm10(dto.getPmTen() != null ? Double.valueOf(dto.getPmTen()) : null); + data.setPm25(dto.getPmTah() != null ? Double.valueOf(dto.getPmTah()) : null); + data.setNoise(dto.getNoise() != null ? Double.valueOf(dto.getNoise()) : null); + data.setTsp(dto.getTsp() != null ? Double.valueOf(dto.getTsp()) : null); + data.setTemperature(dto.getTemperature() != null ? Double.valueOf(dto.getTemperature()) : null); + data.setHumidity(dto.getHumidity() != null ? Double.valueOf(dto.getHumidity()) : null); + data.setWindspeed(dto.getWindSpeed() != null ? Double.valueOf(dto.getWindSpeed()) : null); + data.setWinddirection(dto.getWindDirection() != null ? WindDirectionUtils.getWindDirectionName(String.valueOf(dto.getWindDirection())) : null); + data.setPressure(StringUtils.isNotBlank(dto.getPressure()) ? NumberUtils.toDouble(dto.getPressure()) : null); + data.setXiewenId(Long.valueOf(dto.getId())); + dustNoiseDataMapper.insert(data); + } + } else { + log.info("设备sn:{},当前无数据!", devSn); + } + } else { + log.error("设备sn:{},请求失败!当前code:{},msg:{}", devSn, code, realTimeData.getString("msg")); + } + } } diff --git a/src/main/java/com/zhgd/xmgl/task/dto/EnvironmentDustDataDto.java b/src/main/java/com/zhgd/xmgl/task/dto/EnvironmentDustDataDto.java new file mode 100644 index 000000000..c1b59cb40 --- /dev/null +++ b/src/main/java/com/zhgd/xmgl/task/dto/EnvironmentDustDataDto.java @@ -0,0 +1,27 @@ +package com.zhgd.xmgl.task.dto; + +import lombok.Data; + +@Data +public class EnvironmentDustDataDto { + + private String id; + private String monitoringId; + private String etime; + private String time; + private String pmTah; + private String pmTen; + private String noise; + private String temperature; + private String humidity; + private String windDirection; + private String windSpeed; + private String meanValueType; + private String pressure; + private String o3; + private String so2; + private String no2; + private String co; + private String aqi; + private String tsp; +} diff --git a/src/main/java/com/zhgd/xmgl/util/TimeUtil.java b/src/main/java/com/zhgd/xmgl/util/TimeUtil.java index 6b7160afa..a4626e32c 100644 --- a/src/main/java/com/zhgd/xmgl/util/TimeUtil.java +++ b/src/main/java/com/zhgd/xmgl/util/TimeUtil.java @@ -1,7 +1,5 @@ package com.zhgd.xmgl.util; -import io.swagger.models.auth.In; - public class TimeUtil { public static String toHourMinSecond(Integer second) { if (second == null) { @@ -10,10 +8,19 @@ public class TimeUtil { int h = second / 3600; int min = (second % 3600) / 60; int s = (second % 3600) % 60; - return h + "h" + min + "min" + s + "s"; + String rs = ""; + if (second >= 3600) { + rs = h + "h"; + } + if (second >= 60) { + rs += min + "min"; + } + return rs + s + "s"; } public static void main(String[] args) { - System.out.println(toHourMinSecond(3601)); + System.out.println(toHourMinSecond(1)); + System.out.println(toHourMinSecond(70)); + System.out.println(toHourMinSecond(1000)); } } diff --git a/src/main/java/com/zhgd/xmgl/util/XiwonUtil.java b/src/main/java/com/zhgd/xmgl/util/XiwonUtil.java index 01ede8ffb..00ec61ddf 100644 --- a/src/main/java/com/zhgd/xmgl/util/XiwonUtil.java +++ b/src/main/java/com/zhgd/xmgl/util/XiwonUtil.java @@ -15,6 +15,8 @@ import java.util.Map; import java.util.function.Supplier; /** + * 携稳Util + * * @author 邱平毅 * @ClassName XiwonUtil * @date 2022/11/15 14:05 @@ -38,7 +40,7 @@ public class XiwonUtil { return SecureUtil.md5(appId + appSecret + requestTime); } - public synchronized T postForm(String url, Map map, Class returnClass, Supplier supplier) { + public T postForm(String url, Map map, Class returnClass, Supplier supplier) { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("appId", appId); long currentTimeMillis = System.currentTimeMillis(); diff --git a/src/main/resources/application-gsx-other-env-show.properties b/src/main/resources/application-gsx-other-env-show.properties index 9b2a8f5db..dba21cec8 100644 --- a/src/main/resources/application-gsx-other-env-show.properties +++ b/src/main/resources/application-gsx-other-env-show.properties @@ -95,3 +95,7 @@ sj.business.gateway.api.key=nDmkHCxlQzCqE-xfYteXMw #\u4E09\u6C5F\u56FE\u7247\u8BBF\u95EE\u8DEF\u5F84\uFF08\u7528\u4E8E\u63A8\u9001\u4E1A\u52A1\u4E2D\u53F0\uFF09 sj.upload.image.url.prefix=http://192.168.34.221:11111/image/ active.environment.name=gsx-other-env-show-dev +xiwon.postEnvironmentDustData=http://openapi.xiwon588.com/dust/realTimeData +#携稳的appId和appSecret +xiwon.appId=1690940695416 +xiwon.appSecret=b6162078-6f1c-4f2c-8cd5-0873f45199b2