增加在线状态
This commit is contained in:
parent
0fbf18ab21
commit
b5c7bbbeb8
|
|
@ -14,7 +14,7 @@ db:
|
|||
password:
|
||||
'0': ${MYSQL-PWD:user_fx}
|
||||
url:
|
||||
'0': jdbc:mysql://${MYSQL-HOST:jeecg-boot-mysql}:${MYSQL-PORT:3306}/${MYSQL-DB:fx_nacos}?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||
'0': jdbc:mysql://${MYSQL-HOST:jeecg-boot-mysql}:${MYSQL-PORT:13306}/${MYSQL-DB:fx_nacos}?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
|
||||
user:
|
||||
'0': ${MYSQL-USER:user_fx}
|
||||
management:
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import org.jeecg.common.util.R;
|
|||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.common.vo.*;
|
||||
import org.jeecg.modules.appmana.service.*;
|
||||
import org.jeecg.modules.appmana.utils.Iotutils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
|
@ -888,6 +889,8 @@ public class BigScreenController {
|
|||
}
|
||||
//移除非摄像头设备
|
||||
survStationInfo.getDeviceList().retainAll(remainList);
|
||||
//补充在线状态
|
||||
survStationInfo.setDeviceList(Iotutils.addOnlineStatus(survStationInfo.getDeviceList()));
|
||||
}
|
||||
survStationInfo.setLatestData(returnArrs);
|
||||
survStationInfo.setLatestSoilData(returnSoilArrs);
|
||||
|
|
@ -1035,6 +1038,7 @@ public class BigScreenController {
|
|||
ent.setIotReverseUrl(deploy.getDeviceReverseIotUrl());
|
||||
ent.setMapIcon(deploy.getMapIcon());
|
||||
ent.setIds(deploy.getId());
|
||||
ent.setIsOnline(Iotutils.addOnlineStatus(deploy).getIsOnline());
|
||||
returnList.add(ent);
|
||||
}
|
||||
}
|
||||
|
|
@ -1051,6 +1055,15 @@ public class BigScreenController {
|
|||
//萤石云token
|
||||
String token = getYsToken();
|
||||
List<SurvStationInfo> stationList = survStationInfoService.getAllStationAndDevice(stationCode,PollutionConstants.CAMERA,token);
|
||||
//补充在线状态
|
||||
if(!stationList.isEmpty()){
|
||||
for (SurvStationInfo survStationInfo : stationList) {
|
||||
if(survStationInfo.getDeviceList()!=null && !survStationInfo.getDeviceList().isEmpty()){
|
||||
List<SurvDeviceDeploy> deploys = Iotutils.addOnlineStatus(survStationInfo.getDeviceList());
|
||||
survStationInfo.setDeviceList(deploys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Result.ok(stationList);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
<result property="deployCate" column="DEPLOY_CATE" jdbcType="VARCHAR"/>
|
||||
<result property="deploySecondaryType" column="DEPLOY_SECONDARY_TYPE" jdbcType="VARCHAR"/>
|
||||
<result property="cateId" column="CATE_ID" jdbcType="VARCHAR"/>
|
||||
<result property="survConfigId" column="SURV_CONFIG_ID" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="extMap" type="org.jeecg.common.entity.SurvDeviceDeploy" extends="baseResultMap">
|
||||
|
|
@ -48,7 +49,7 @@
|
|||
</resultMap>
|
||||
|
||||
<sql id="basesql" >
|
||||
ID,DEPLOY_CODE,STATION_CODE,RUN_STATUS,POWER_STATUS,LASTSYNC_TIME,DEVICE_CODE,DEPLOY_DES,DEPLOY_PIC,DEVICE_URL,SORT_NO,TENANT_ID,RE_VISION,CREATED_BY,CREATE_TIME,UPDATED_BY,IS_DEL,UPDATED_TIME,DEPLOY_TYPE,DEVICE_LATITUDE,DEVICE_LONGITUDE,GROUP_ID,IZ_BAOJING,IP_ADDR,PORT,SEND_INFO,MAP_ICON,DEVICE_IOT_URL,DEVICE_REVERSE_IOT_URL,DEVICE_LONGLAT,PROTOCOL_CODE,PROTOCOL_TYPE,DEPLOY_CATE,DEPLOY_SECONDARY_TYPE,CATE_ID
|
||||
ID,DEPLOY_CODE,STATION_CODE,RUN_STATUS,POWER_STATUS,LASTSYNC_TIME,DEVICE_CODE,DEPLOY_DES,DEPLOY_PIC,DEVICE_URL,SORT_NO,TENANT_ID,RE_VISION,CREATED_BY,CREATE_TIME,UPDATED_BY,IS_DEL,UPDATED_TIME,DEPLOY_TYPE,DEVICE_LATITUDE,DEVICE_LONGITUDE,GROUP_ID,IZ_BAOJING,IP_ADDR,PORT,SEND_INFO,MAP_ICON,DEVICE_IOT_URL,DEVICE_REVERSE_IOT_URL,DEVICE_LONGLAT,PROTOCOL_CODE,PROTOCOL_TYPE,DEPLOY_CATE,DEPLOY_SECONDARY_TYPE,CATE_ID,SURV_CONFIG_ID
|
||||
</sql>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,4 +18,8 @@ public interface ISurvConfigService extends IService<SurvConfig> {
|
|||
|
||||
|
||||
SurvConfig getOneByTypeWithTenant(String tenantId, String type);
|
||||
|
||||
SurvConfig getConfigById(String survConfigId);
|
||||
|
||||
long getOfflineConfig(String tenantId,String deployType);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package org.jeecg.modules.appmana.service.impl;
|
|||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.constant.IotConstants;
|
||||
import org.jeecg.common.constant.PollutionConstants;
|
||||
import org.jeecg.common.entity.SurvConfig;
|
||||
import org.jeecg.modules.appmana.mapper.SurvConfigMapper;
|
||||
import org.jeecg.modules.appmana.service.ISurvConfigService;
|
||||
|
|
@ -32,4 +33,55 @@ public class SurvConfigServiceImpl extends ServiceImpl<SurvConfigMapper, SurvCon
|
|||
}
|
||||
return baseMapper.getOneByTypeWithTenant(tenantId, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE, key = "#survConfigId", unless = "#result == null ")
|
||||
public SurvConfig getConfigById(String survConfigId) {
|
||||
return baseMapper.selectById(survConfigId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getOfflineConfig(String tenantId,String deployType) {
|
||||
if(StringUtils.isBlank(tenantId)){
|
||||
tenantId = "0";
|
||||
}
|
||||
//默认时间 分钟
|
||||
long defaultTime = 5;
|
||||
//获取租户自定义的设备离线判定时限,无配置则走默认值
|
||||
// if (IotConstants.gcszxc_standard.equals(protocolCode) || IotConstants.qwxgwl_standard.equals(protocolCode)) {
|
||||
// if(!IotConstants.xph_v2.equals(protocolCode)
|
||||
// && !IotConstants.xph_v1.equals(protocolCode)
|
||||
// && !IotConstants.ysy_standard.equals(protocolCode)
|
||||
// && !IotConstants.yf_standard.equals(protocolCode)
|
||||
// && !IotConstants.okq_v1.equals(protocolCode)
|
||||
// && !IotConstants.okq_v2.equals(protocolCode)
|
||||
// ) {//非新浦惠v2、非萤云,非欧克奇 等,走自定义
|
||||
//系统默认未配置,则使用本层逻辑
|
||||
SurvConfig fSurvConfig = getOneByTypeWithTenant(tenantId, IotConstants.device_offline_time);
|
||||
//未配置使用系统默认
|
||||
if(fSurvConfig ==null){
|
||||
fSurvConfig = getOneByTypeWithTenant("0", IotConstants.device_offline_time);
|
||||
}
|
||||
|
||||
if(fSurvConfig != null){
|
||||
cn.hutool.json.JSONObject configs = null;
|
||||
configs = fSurvConfig.getConfigJson();
|
||||
if (configs != null) {
|
||||
Integer setTimes = configs.getInt(deployType);
|
||||
if (setTimes != null) {
|
||||
return setTimes;
|
||||
}
|
||||
}
|
||||
}else{//依然未配置则使用 代码默认
|
||||
if (PollutionConstants.CONTROL_CAB.equals(deployType) || PollutionConstants.CAMERA.equals(deployType) ||
|
||||
PollutionConstants.BUG_SURV.equals(deployType) || PollutionConstants.SPORE_SURV.equals(deployType) ||
|
||||
PollutionConstants.PEST_LIGHT.equals(deployType) || PollutionConstants.INTEGRATED_CONTROL.equals(deployType)
|
||||
|| PollutionConstants.INTEGRATED_MACHINE.equals(deployType)) {//每小时同步一次的设备
|
||||
defaultTime = 70;
|
||||
}
|
||||
}
|
||||
return defaultTime;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,59 @@
|
|||
package org.jeecg.modules.appmana.utils;
|
||||
|
||||
import org.jeecg.common.entity.SurvDeviceDeploy;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.modules.appmana.service.ISurvConfigService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Iotutils {
|
||||
|
||||
private static ISurvConfigService survConfigService = SpringContextUtils.getBean(ISurvConfigService.class);
|
||||
|
||||
public static Integer checkIsOnline(String tenantId, String protocolCode, Date lastSyncTime, String deployType) {
|
||||
|
||||
long limitTime = survConfigService.getOfflineConfig(tenantId,deployType);
|
||||
if (lastSyncTime != null) {
|
||||
return timeCompare(limitTime, lastSyncTime.getTime());
|
||||
} else {
|
||||
return 2;//未知情况,设备未返回正确的在线状态
|
||||
}
|
||||
}
|
||||
|
||||
private static int timeCompare(long standardTime, long checkTime) {
|
||||
Date nowDate = new Date();
|
||||
long diffInMillies = Math.abs(nowDate.getTime() - checkTime);
|
||||
long diffInMinutes = TimeUnit.MINUTES.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
if (diffInMinutes < standardTime) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getDeviceOnlineStatus(SurvDeviceDeploy deploy) {
|
||||
return checkIsOnline(deploy.getTenantId(),deploy.getProtocolCode(),deploy.getLastsyncTime(),deploy.getDeployType());
|
||||
}
|
||||
|
||||
|
||||
public static List<SurvDeviceDeploy> addOnlineStatus(List<SurvDeviceDeploy> deploys){
|
||||
List<SurvDeviceDeploy> deps = new ArrayList<>();
|
||||
if(deploys!=null && !deploys.isEmpty()){
|
||||
for (SurvDeviceDeploy deploy : deploys) {
|
||||
deploy.setIsOnline(getDeviceOnlineStatus(deploy));
|
||||
deps.add(deploy);
|
||||
}
|
||||
}
|
||||
return deps;
|
||||
}
|
||||
|
||||
public static SurvDeviceDeploy addOnlineStatus(SurvDeviceDeploy deploy){
|
||||
if(deploy!=null){
|
||||
deploy.setIsOnline(getDeviceOnlineStatus(deploy));
|
||||
}
|
||||
return deploy;
|
||||
}
|
||||
}
|
||||
|
|
@ -135,11 +135,11 @@ public class SdrkUtils {
|
|||
VOIotAccess voIotAccess = null;
|
||||
//优先使用设备配置的密钥
|
||||
SurvConfig survConfig = null;
|
||||
// if(StringUtils.isNotBlank(deploy.getSurvConfigId())){
|
||||
// survConfig = configService.getConfigById(deploy.getSurvConfigId());
|
||||
// }else{
|
||||
if(StringUtils.isNotBlank(deploy.getSurvConfigId())){
|
||||
survConfig = configService.getConfigById(deploy.getSurvConfigId());
|
||||
}else{
|
||||
survConfig = configService.getOneByTypeWithTenant(deploy.getTenantId(), IotConstants.renke_access);
|
||||
// }
|
||||
}
|
||||
if(survConfig!=null){
|
||||
voIotAccess = new VOIotAccess();
|
||||
voIotAccess.setAppSecret(survConfig.getConfigValue());
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import org.jeecg.system.applet.service.*;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecg.system.applet.util.Iotutils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.Api;
|
||||
|
|
@ -100,7 +101,7 @@ public class SurvStationInfoController {
|
|||
// QueryWrapper<SurvStationInfo> queryWrapper = Wrappers.query(survStationInfo);
|
||||
Page<SurvStationInfo> page = new Page<SurvStationInfo>(pageNo, pageSize);
|
||||
IPage<SurvStationInfo> pageList = survStationInfoService.pages(page, survStationInfo);
|
||||
if(pageList.getRecords().size()>0) {
|
||||
if(!pageList.getRecords().isEmpty()) {
|
||||
for (SurvStationInfo record : pageList.getRecords()) {
|
||||
List<String> airList = new ArrayList<>();
|
||||
List<String> soilList = new ArrayList<>();
|
||||
|
|
@ -125,31 +126,36 @@ public class SurvStationInfoController {
|
|||
|
||||
Integer finalDataCounts = 0;
|
||||
//水实时
|
||||
if(orientList.size()>0) {
|
||||
if(!orientList.isEmpty()) {
|
||||
//计算历史数据量
|
||||
Integer dataCounts = hisdataOrientwaterService.getHisDataCount(orientList);
|
||||
finalDataCounts=finalDataCounts+dataCounts;
|
||||
}
|
||||
if(liveList.size()>0) {
|
||||
if(!liveList.isEmpty()) {
|
||||
//计算历史数据量
|
||||
Integer dataCounts = hisdataLivestockwaterService.getHisDataCount(liveList);
|
||||
finalDataCounts=finalDataCounts+dataCounts;
|
||||
}
|
||||
//气实时
|
||||
if(airList.size()>0) {
|
||||
if(!airList.isEmpty()) {
|
||||
|
||||
//计算历史数据量
|
||||
Integer dataCounts = hisdataAirService.getHisDataCount(airList);
|
||||
finalDataCounts=finalDataCounts+dataCounts;
|
||||
}
|
||||
//土壤实时
|
||||
if(soilList.size()>0){
|
||||
if(!soilList.isEmpty()){
|
||||
//计算历史数据量
|
||||
Integer dataCounts = hisdataSoilService.getHisDataCount(soilList);
|
||||
finalDataCounts=finalDataCounts+dataCounts;
|
||||
}
|
||||
//获取数据量
|
||||
record.setSurvDataCount(finalDataCounts);
|
||||
//补充设备在线状态
|
||||
if(record.getDeviceList()!=null && !record.getDeviceList().isEmpty()){
|
||||
List<SurvDeviceDeploy> deploys = Iotutils.addOnlineStatus(record.getDeviceList());
|
||||
record.setDeviceList(deploys);
|
||||
}
|
||||
}
|
||||
}
|
||||
return R.ok(pageList);
|
||||
|
|
@ -224,7 +230,8 @@ public class SurvStationInfoController {
|
|||
jsonObject.put("survItemList",allSurv);
|
||||
//监控摄像头
|
||||
List<SurvDeviceDeploy> camList = survDeviceDeployService.list(Wrappers.<SurvDeviceDeploy>lambdaQuery().eq(SurvDeviceDeploy::getStationCode,stationCode).eq(SurvDeviceDeploy::getDeployType,PollutionConstants.CAMERA).orderByAsc(SurvDeviceDeploy::getSortNo));
|
||||
jsonObject.put("survCamera",camList);
|
||||
List<SurvDeviceDeploy> adds = Iotutils.addOnlineStatus(camList);
|
||||
jsonObject.put("survCamera",adds);
|
||||
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
Integer finalDataCounts = 0;
|
||||
|
|
@ -393,7 +400,8 @@ public class SurvStationInfoController {
|
|||
List<SurvStationInfo> stationList = survStationInfoService.listALlStation();
|
||||
for (SurvStationInfo survStationInfo : stationList) {
|
||||
List<SurvDeviceDeploy> pageList = survDeviceDeployService.getDeviceByStationNoCam(survStationInfo.getStationCode(),null);
|
||||
joa.add(pageList);
|
||||
List<SurvDeviceDeploy> adds = Iotutils.addOnlineStatus(pageList);
|
||||
joa.add(adds);
|
||||
count++;
|
||||
}
|
||||
return R.ok(joa);
|
||||
|
|
@ -472,6 +480,7 @@ public class SurvStationInfoController {
|
|||
ent.setIotReverseUrl(deploy.getDeviceReverseIotUrl());
|
||||
ent.setMapIcon(deploy.getMapIcon());
|
||||
ent.setIds(deploy.getId());
|
||||
ent.setIsOnline(Iotutils.addOnlineStatus(deploy).getIsOnline());
|
||||
returnList.add(ent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package org.jeecg.system.applet.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.jeecg.common.entity.SurvConfig;
|
||||
|
||||
/**
|
||||
* @Description: 业务参数配置表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2023-07-21
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface SurvConfigMapper extends BaseMapper<SurvConfig> {
|
||||
|
||||
String getValueByKey(String key);
|
||||
|
||||
|
||||
SurvConfig getOneByTypeWithTenant(@Param("tenantId") String tenantId, @Param("type") String type);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<?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="org.jeecg.system.applet.mapper.SurvConfigMapper">
|
||||
|
||||
<select id="getValueByKey" resultType="java.lang.String">
|
||||
select CONFIG_VALUE from surv_config where CONFIG_KEY = #{key}
|
||||
</select>
|
||||
|
||||
<select id="getOneByTypeWithTenant" resultType="org.jeecg.common.entity.SurvConfig">
|
||||
select *
|
||||
from surv_config
|
||||
where CONFIG_TYPE = #{type}
|
||||
AND TENANT_ID = #{tenantId} limit 1
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
<result property="deployCate" column="DEPLOY_CATE" jdbcType="VARCHAR"/>
|
||||
<result property="deploySecondaryType" column="DEPLOY_SECONDARY_TYPE" jdbcType="VARCHAR"/>
|
||||
<result property="cateId" column="CATE_ID" jdbcType="VARCHAR"/>
|
||||
<result property="survConfigId" column="SURV_CONFIG_ID" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
<resultMap id="adResultMap" type="org.jeecg.common.entity.SurvDeviceDeploy" extends="baseResultMap">
|
||||
<association property="stationName" javaType="java.lang.String" select="getStationName" column="STATION_CODE"></association>
|
||||
|
|
@ -57,7 +58,7 @@
|
|||
</select>
|
||||
|
||||
<sql id="baseSql" >
|
||||
ID,DEPLOY_CODE,STATION_CODE,RUN_STATUS,POWER_STATUS,LASTSYNC_TIME,DEVICE_CODE,DEPLOY_DES,DEPLOY_PIC,DEVICE_URL,SORT_NO,TENANT_ID,RE_VISION,CREATED_BY,CREATE_TIME,UPDATED_BY,IS_DEL,UPDATED_TIME,DEPLOY_TYPE,DEVICE_LATITUDE,DEVICE_LONGITUDE,GROUP_ID,IZ_BAOJING,IP_ADDR,PORT,SEND_INFO,MAP_ICON,DEVICE_IOT_URL,DEVICE_REVERSE_IOT_URL,DEVICE_LONGLAT,PROTOCOL_CODE,PROTOCOL_TYPE,DEPLOY_CATE,DEPLOY_SECONDARY_TYPE,CATE_ID
|
||||
ID,DEPLOY_CODE,STATION_CODE,RUN_STATUS,POWER_STATUS,LASTSYNC_TIME,DEVICE_CODE,DEPLOY_DES,DEPLOY_PIC,DEVICE_URL,SORT_NO,TENANT_ID,RE_VISION,CREATED_BY,CREATE_TIME,UPDATED_BY,IS_DEL,UPDATED_TIME,DEPLOY_TYPE,DEVICE_LATITUDE,DEVICE_LONGITUDE,GROUP_ID,IZ_BAOJING,IP_ADDR,PORT,SEND_INFO,MAP_ICON,DEVICE_IOT_URL,DEVICE_REVERSE_IOT_URL,DEVICE_LONGLAT,PROTOCOL_CODE,PROTOCOL_TYPE,DEPLOY_CATE,DEPLOY_SECONDARY_TYPE,CATE_ID,SURV_CONFIG_ID
|
||||
</sql>
|
||||
|
||||
<select id="getCameraGroupByStation" resultType="org.jeecg.common.entity.SurvDeviceDeploy">
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package org.jeecg.system.applet.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.jeecg.common.entity.SurvConfig;
|
||||
|
||||
/**
|
||||
* @Description: 业务参数配置表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2023-07-21
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ISurvConfigService extends IService<SurvConfig> {
|
||||
|
||||
String getValueByKey(String key);
|
||||
|
||||
|
||||
|
||||
SurvConfig getOneByTypeWithTenant(String tenantId, String type);
|
||||
|
||||
SurvConfig getConfigById(String survConfigId);
|
||||
|
||||
long getOfflineConfig(String tenantId,String deployType);
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package org.jeecg.system.applet.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jeecg.common.constant.IotConstants;
|
||||
import org.jeecg.common.constant.PollutionConstants;
|
||||
import org.jeecg.common.entity.SurvConfig;
|
||||
import org.jeecg.system.applet.mapper.SurvConfigMapper;
|
||||
import org.jeecg.system.applet.service.ISurvConfigService;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @Description: 业务参数配置表
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2023-07-21
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class SurvConfigServiceImpl extends ServiceImpl<SurvConfigMapper, SurvConfig> implements ISurvConfigService {
|
||||
|
||||
@Override
|
||||
public String getValueByKey(String key) {
|
||||
return baseMapper.getValueByKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE, key = "#tenantId+':'+#type", unless = "#result == null ")
|
||||
public SurvConfig getOneByTypeWithTenant(String tenantId, String type) {
|
||||
if(StringUtils.isBlank(tenantId)){
|
||||
tenantId = "0";
|
||||
}
|
||||
return baseMapper.getOneByTypeWithTenant(tenantId, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(value = IotConstants.IOT_SURVCONFIG_CACHE, key = "#survConfigId", unless = "#result == null ")
|
||||
public SurvConfig getConfigById(String survConfigId) {
|
||||
return baseMapper.selectById(survConfigId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getOfflineConfig(String tenantId,String deployType) {
|
||||
if(StringUtils.isBlank(tenantId)){
|
||||
tenantId = "0";
|
||||
}
|
||||
//默认时间 分钟
|
||||
long defaultTime = 5;
|
||||
//获取租户自定义的设备离线判定时限,无配置则走默认值
|
||||
// if (IotConstants.gcszxc_standard.equals(protocolCode) || IotConstants.qwxgwl_standard.equals(protocolCode)) {
|
||||
// if(!IotConstants.xph_v2.equals(protocolCode)
|
||||
// && !IotConstants.xph_v1.equals(protocolCode)
|
||||
// && !IotConstants.ysy_standard.equals(protocolCode)
|
||||
// && !IotConstants.yf_standard.equals(protocolCode)
|
||||
// && !IotConstants.okq_v1.equals(protocolCode)
|
||||
// && !IotConstants.okq_v2.equals(protocolCode)
|
||||
// ) {//非新浦惠v2、非萤云,非欧克奇 等,走自定义
|
||||
//系统默认未配置,则使用本层逻辑
|
||||
SurvConfig fSurvConfig = getOneByTypeWithTenant(tenantId, IotConstants.device_offline_time);
|
||||
//未配置使用系统默认
|
||||
if(fSurvConfig ==null){
|
||||
fSurvConfig = getOneByTypeWithTenant("0", IotConstants.device_offline_time);
|
||||
}
|
||||
|
||||
if(fSurvConfig != null){
|
||||
cn.hutool.json.JSONObject configs = null;
|
||||
configs = fSurvConfig.getConfigJson();
|
||||
if (configs != null) {
|
||||
Integer setTimes = configs.getInt(deployType);
|
||||
if (setTimes != null) {
|
||||
return setTimes;
|
||||
}
|
||||
}
|
||||
}else{//依然未配置则使用 代码默认
|
||||
if (PollutionConstants.CONTROL_CAB.equals(deployType) || PollutionConstants.CAMERA.equals(deployType) ||
|
||||
PollutionConstants.BUG_SURV.equals(deployType) || PollutionConstants.SPORE_SURV.equals(deployType) ||
|
||||
PollutionConstants.PEST_LIGHT.equals(deployType) || PollutionConstants.INTEGRATED_CONTROL.equals(deployType)
|
||||
|| PollutionConstants.INTEGRATED_MACHINE.equals(deployType)) {//每小时同步一次的设备
|
||||
defaultTime = 70;
|
||||
}
|
||||
}
|
||||
return defaultTime;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.jeecg.system.applet.util;
|
||||
|
||||
import org.jeecg.common.entity.SurvDeviceDeploy;
|
||||
import org.jeecg.system.applet.service.ISurvConfigService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
public class Iotutils {
|
||||
@Autowired
|
||||
private static ISurvConfigService survConfigService;
|
||||
|
||||
public static Integer checkIsOnline(String tenantId, String protocolCode, Date lastSyncTime, String deployType) {
|
||||
|
||||
long limitTime = survConfigService.getOfflineConfig(tenantId,deployType);
|
||||
if (lastSyncTime != null) {
|
||||
return timeCompare(limitTime, lastSyncTime.getTime());
|
||||
} else {
|
||||
return 2;//未知情况,设备未返回正确的在线状态
|
||||
}
|
||||
}
|
||||
|
||||
private static int timeCompare(long standardTime, long checkTime) {
|
||||
Date nowDate = new Date();
|
||||
long diffInMillies = Math.abs(nowDate.getTime() - checkTime);
|
||||
long diffInMinutes = TimeUnit.MINUTES.convert(diffInMillies, TimeUnit.MILLISECONDS);
|
||||
if (diffInMinutes < standardTime) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static Integer getDeviceOnlineStatus(SurvDeviceDeploy deploy) {
|
||||
return checkIsOnline(deploy.getTenantId(),deploy.getProtocolCode(),deploy.getLastsyncTime(),deploy.getDeployType());
|
||||
}
|
||||
|
||||
|
||||
public static List<SurvDeviceDeploy> addOnlineStatus(List<SurvDeviceDeploy> deploys){
|
||||
List<SurvDeviceDeploy> deps = new ArrayList<>();
|
||||
if(deploys!=null && !deploys.isEmpty()){
|
||||
for (SurvDeviceDeploy deploy : deploys) {
|
||||
deploy.setIsOnline(getDeviceOnlineStatus(deploy));
|
||||
deps.add(deploy);
|
||||
}
|
||||
}
|
||||
return deps;
|
||||
}
|
||||
|
||||
public static SurvDeviceDeploy addOnlineStatus(SurvDeviceDeploy deploy){
|
||||
if(deploy!=null){
|
||||
deploy.setIsOnline(getDeviceOnlineStatus(deploy));
|
||||
}
|
||||
return deploy;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,10 @@ public interface PollutionConstants {
|
|||
* 水污染物
|
||||
*/
|
||||
String WATER_LIVE = "water_live";
|
||||
/**
|
||||
* 水质监测
|
||||
*/
|
||||
String WATER_QULITY = "6_water";
|
||||
|
||||
/**
|
||||
* 气项监测
|
||||
|
|
@ -23,9 +27,51 @@ public interface PollutionConstants {
|
|||
String SOIL_SURV = "soil";
|
||||
|
||||
|
||||
String STINK = "stink";
|
||||
String STINK = "stink";
|
||||
|
||||
String CAMERA = "camera";
|
||||
|
||||
String SURV = "surv";
|
||||
|
||||
/**
|
||||
* 虫情监测
|
||||
*/
|
||||
String BUG_SURV = "7_bugsurv";
|
||||
|
||||
/**
|
||||
* 水肥机
|
||||
*/
|
||||
String INTEGRATED_MACHINE = "integrated_machine";
|
||||
|
||||
/**
|
||||
* 灌溉器
|
||||
*/
|
||||
String INTEGRATED_CONTROL = "integrated_control";
|
||||
/**
|
||||
* 控制柜
|
||||
*/
|
||||
String CONTROL_CAB = "control_cab";
|
||||
|
||||
String CONTROL_UP = "up";
|
||||
|
||||
String CONTROL_DOWN = "down";
|
||||
|
||||
String TABLE_AIR = "f_hisdata_air";
|
||||
|
||||
String TABLE_SOIL = "f_hisdata_soil";
|
||||
|
||||
String TABLE_PEST = "f_prevent_pestlight";
|
||||
|
||||
/**
|
||||
* 孢子监测
|
||||
*/
|
||||
String SPORE_SURV = "8_sporesurv";
|
||||
|
||||
/**
|
||||
* 孢子监测
|
||||
*/
|
||||
String PEST_LIGHT = "9_pestlight";
|
||||
|
||||
String CAMERA = "camera";
|
||||
|
||||
/**
|
||||
* 数据生成间隔 单位秒
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import java.io.Serializable;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.jeecg.common.mybatis.typehandler.JsonTypeHandler;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
|
|
@ -47,6 +48,36 @@ public class SurvConfig implements Serializable {
|
|||
@Excel(name = "参数键值", width = 15)
|
||||
@ApiModelProperty(value = "参数键值")
|
||||
private java.lang.String configValue;
|
||||
|
||||
/**
|
||||
* 参数次级键值
|
||||
*/
|
||||
@Excel(name = "参数次级键值", width = 15)
|
||||
@ApiModelProperty(value = "参数次级键值")
|
||||
private String configValueSe;
|
||||
/**
|
||||
* 参数次级键值
|
||||
*/
|
||||
@Excel(name = "参数次级键值", width = 15)
|
||||
@ApiModelProperty(value = "参数次级键值")
|
||||
private String configValueSe2;
|
||||
/**
|
||||
* 参数次级键值
|
||||
*/
|
||||
@Excel(name = "参数次级键值", width = 15)
|
||||
@ApiModelProperty(value = "参数次级键值")
|
||||
private String configValueSe3;
|
||||
/**
|
||||
* 参数次级键值
|
||||
*/
|
||||
@Excel(name = "参数次级键值", width = 15)
|
||||
@ApiModelProperty(value = "参数次级键值")
|
||||
private String configValueSe4;
|
||||
|
||||
@Excel(name = "参数json配置", width = 15)
|
||||
@ApiModelProperty(value = "参数json配置")
|
||||
@TableField(typeHandler = JsonTypeHandler.class, jdbcType = JdbcType.VARCHAR, value = "CONFIG_JSON")
|
||||
private JSONObject configJson;
|
||||
/**系统内置*/
|
||||
@Excel(name = "系统内置", width = 15)
|
||||
@ApiModelProperty(value = "系统内置")
|
||||
|
|
|
|||
|
|
@ -187,6 +187,14 @@ public class SurvDeviceDeploy implements Serializable {
|
|||
@ApiModelProperty(value = "设备经纬度")
|
||||
private String deviceLonglat;
|
||||
|
||||
/**
|
||||
* 设备配置id
|
||||
*/
|
||||
@TableField("SURV_CONFIG_ID")
|
||||
@Excel(name = "物联网配置ID", width = 15)
|
||||
@ApiModelProperty(value = "物联网配置ID")
|
||||
private String survConfigId;
|
||||
|
||||
@ApiModelProperty("1#球阀状态")
|
||||
@TableField(exist = false)
|
||||
private String valveStatus1;
|
||||
|
|
@ -247,6 +255,9 @@ public class SurvDeviceDeploy implements Serializable {
|
|||
@TableField(exist = false)
|
||||
private String[] depUrlArr;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer isOnline;
|
||||
|
||||
public String[] getDepCodeArr() {
|
||||
if(StringUtils.isNotBlank(depCodes)) {
|
||||
return depCodes.split(",");
|
||||
|
|
@ -291,4 +302,8 @@ public class SurvDeviceDeploy implements Serializable {
|
|||
}
|
||||
return protocolDetail;
|
||||
}
|
||||
|
||||
// public Integer getIsOnline() {
|
||||
// return Iotutils.checkIsOnline(tenantId, protocolCode, lastsyncTime, deployType);
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,10 @@ public class SurvMaintainRecord implements Serializable {
|
|||
@Excel(name = "预留项2", width = 15)
|
||||
@ApiModelProperty(value = "预留项2")
|
||||
private java.lang.String maintainData2;
|
||||
/**预留项2*/
|
||||
@Excel(name = "预留项3", width = 15)
|
||||
@ApiModelProperty(value = "预留项3")
|
||||
private java.lang.String maintainData3;
|
||||
/**租户号*/
|
||||
@Excel(name = "租户号", width = 15)
|
||||
@ApiModelProperty(value = "租户号")
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ public class CommonLocationTrans {
|
|||
private String mapIcon;
|
||||
private String iotUrl;
|
||||
private String iotReverseUrl;
|
||||
private Integer isOnline;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue