diff --git a/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/RemoteBasicService.java b/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/RemoteBasicService.java index d9f5aa3..c399e7e 100644 --- a/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/RemoteBasicService.java +++ b/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/RemoteBasicService.java @@ -2,10 +2,12 @@ package com.ruoyi.basic.api; import com.ruoyi.basic.api.domain.HwTenant; import com.ruoyi.basic.api.factory.RemoteBasicFallbackFactory; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; import java.util.List; @@ -21,5 +23,5 @@ import java.util.List; public interface RemoteBasicService { @GetMapping("/tenant/getTenants") - R> getTenants(); + R> getTenants(@RequestHeader(SecurityConstants.FROM_SOURCE) String source); } diff --git a/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/factory/RemoteBasicFallbackFactory.java b/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/factory/RemoteBasicFallbackFactory.java index 45023cb..f6fd8bb 100644 --- a/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/factory/RemoteBasicFallbackFactory.java +++ b/ruoyi-api/hw-api-basic/src/main/java/com/ruoyi/basic/api/factory/RemoteBasicFallbackFactory.java @@ -22,7 +22,7 @@ public class RemoteBasicFallbackFactory implements FallbackFactory> getTenants() { + public R> getTenants(String source) { return R.fail("获取租户信息失败:" + throwable.getMessage()); } }; diff --git a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java index 073d200..8421fac 100644 --- a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java +++ b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/RemoteBusinessService.java @@ -1,11 +1,13 @@ package com.ruoyi.business.api; import com.ruoyi.business.api.factory.RemoteBusinessFallbackFactory; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestHeader; @FeignClient(contextId = "remoteBusinessService", value = ServiceNameConstants.BUSINESS_SERVICE, fallbackFactory = RemoteBusinessFallbackFactory.class) public interface RemoteBusinessService { @@ -17,5 +19,5 @@ public interface RemoteBusinessService { * @return 结果 */ @GetMapping("/device/computeOnlineDevicecCount/{days}") - public R computeOnlineDevicecCount(@PathVariable("days") int days); + public R computeOnlineDevicecCount(@PathVariable("days") int days, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); } diff --git a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java index f4bbc62..cb97dd6 100644 --- a/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java +++ b/ruoyi-api/hw-api-business/src/main/java/com/ruoyi/business/api/factory/RemoteBusinessFallbackFactory.java @@ -18,7 +18,7 @@ public class RemoteBusinessFallbackFactory implements FallbackFactory computeOnlineDevicecCount(int days) { + public R computeOnlineDevicecCount(int days, String source) { return R.fail("获取租户信息失败:" + throwable.getMessage()); } }; diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java index 1e853c7..23c204f 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java @@ -19,10 +19,13 @@ public class TdEngineConstants { public static final String PAYLOAD_PARAM = "param";//协议上传的param key + public static final String PAYLOAD_DATATYPE = "datatype";//协议上传数据数据类型的key public static final String PAYLOAD_DATAVALUE = "datavalue";//协议上传数据的key public static final String PAYLOAD_DEVICE_CODE = "uid";//协议上传设备编号的key + public static final String PAYLOAD_DEVICE_DATA_TYPE_IMAGE = "image";//协议上传图片类型的key + // public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀 public static final String DEFAULT_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀 diff --git a/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java b/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java index e54738d..1f814b6 100644 --- a/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java +++ b/ruoyi-modules/hw-basic/src/main/java/com/ruoyi/basic/controller/HwTenantController.java @@ -10,6 +10,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; +import com.ruoyi.common.security.annotation.InnerAuth; import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysUser; @@ -115,6 +116,7 @@ public class HwTenantController extends BaseController /** * 查询租户信息列表 */ + @InnerAuth @GetMapping("/getTenants") public R> getTenants(HwTenant hwTenant) { diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java index ceac203..7c110a6 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java @@ -13,6 +13,7 @@ import com.ruoyi.business.service.IHwDeviceModeService; import com.ruoyi.business.service.IHwMonitorUnitService; import com.ruoyi.business.service.IHwSceneService; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.security.annotation.InnerAuth; import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.system.api.domain.SysDept; import com.ruoyi.system.api.domain.SysRole; @@ -191,10 +192,6 @@ public class HwDeviceController extends BaseController { return success(); } - @GetMapping("/computeOnlineDevicecCount/{days}") - public void computeOnlineDevicecCount(@PathVariable("days") int days) { - hwDeviceService.computeOnlineDevicecCount(days); - } @RequiresPermissions("business:device:rebuild") @Log(title = "设备信息", businessType = BusinessType.REBUILD) @@ -203,4 +200,11 @@ public class HwDeviceController extends BaseController { hwDeviceService.rebuildTdTables(); } + + @InnerAuth + @GetMapping("/computeOnlineDevicecCount/{days}") + public void computeOnlineDevicecCount(@PathVariable("days") int days) { + hwDeviceService.computeOnlineDevicecCount(days); + } + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java index 5aeb495..2182993 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java @@ -102,6 +102,7 @@ public class HwMonitorPlatformController extends BaseController { @RequiresPermissions("business:monitor:index") @GetMapping("/getDeviceOperations/{sceneId}") public AjaxResult selectDeviceStatus(@PathVariable("sceneId") Long sceneId) { + System.out.println(("sceneid:" + sceneId)); return AjaxResult.success(hwDeviceService.getOnlineDevicesCount(sceneId)); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java index fa9d457..59b84ab 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java @@ -680,6 +680,15 @@ public class HwDeviceServiceImpl implements IHwDeviceService { }); } + public String getDeviceTslJson(Long deviceId) { + HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); + String deviceCode = device.getDeviceCode(); + String devideType = device.getDeviceType(); + + return ""; + } + + /** * @param: hwDevice 前端传的对象 * @param: dbDevice 目前数据库的对象 @@ -771,7 +780,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { List> lastDeviceStatuMapList = (List>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus, SecurityConstants.INNER).getData(); if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) { - onlineDeviceCountByDay.put(startTime, 0); + onlineDeviceCountByDay.put(startTime, 0);//当天的在线设备数量为0 } else { for (Map groupDeviceStatuMap : lastDeviceStatuMapList) { DeviceStatus ds = new DeviceStatus(); @@ -791,14 +800,14 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } } - List dss = groupDeviceStatuMapList.get(ds.getDeviceId()); + List dss = groupDeviceStatuMapList.get(ds.getDeviceId());//获取此设备是否有状态信息 int count = 0; - if (dss == null) { + if (dss == null) {//如果没有获取则按照此设备最近的状态信息进行计算 if (String.valueOf(ds.getOnlineStatus()) .equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) { count = this.getDeviceCount(ds); } - } else { + } else {//如果获取到就按最近的设备状态信息进行计算 count = this.getDeviceCount(dss.get(0)); } @@ -818,6 +827,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE)) { HwDevice queryDevice = new HwDevice(); queryDevice.setReleatedDeviceId(ds.getDeviceId()); + queryDevice.setDeviceStatus(HwDictConstants.DEVICE_STATUS_PUBLISH); List deviceList = hwDeviceMapper.selectHwDeviceList(queryDevice); return deviceList == null ? 0 : deviceList.size(); } else { diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml index f1c0434..14a0fdc 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml @@ -231,8 +231,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java index 523fd65..680f01c 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/common/ImageUtils.java @@ -25,6 +25,23 @@ public class ImageUtils { public static final String BASE64_PREFIX = "data:image/";//base64图片前缀 public static final String BASE64_SUFFIX = ";base64";//base64图片后缀 + /** + * @param: base64Str + * @description 校验是否是图片 + * @author xins + * @date 2023-10-16 13:31 + * @return boolean + */ + public static boolean checkIsBase64(String base64Str){ + try { + Base64.getDecoder().decode(base64Str); + return true; + } catch (IllegalArgumentException e) { + return false; + } + } + + /** * @param imagePatternArr * @return String diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java index 4254397..61eb97f 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java @@ -22,10 +22,10 @@ import com.ruoyi.dataprocess.mapper.HwDeviceMapper; import com.ruoyi.dataprocess.mapper.HwElectronicFenceMapper; import com.ruoyi.dataprocess.mapper.HwFenceAreaMapper; import com.ruoyi.dataprocess.service.IDataProcessService; -import com.ruoyi.system.api.RemoteFileService; import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.domain.TdField; import com.ruoyi.tdengine.api.domain.TdTableVo; +import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -92,6 +92,7 @@ public class DataProcessServiceImpl implements IDataProcessService { for (int i = 0; i < paramArr.size(); i++) { try { JSONObject paramJson = paramArr.getJSONObject(i); + String dataType = paramJson.getString(TdEngineConstants.PAYLOAD_DATATYPE); JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE); deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase(); HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode); @@ -144,17 +145,12 @@ public class DataProcessServiceImpl implements IDataProcessService { String extension = ImageUtils.getImageType(valueStr, imagePatternArr); if (StringUtils.isNotBlank(extension)) { //保存图片,并返回图片详细地址进行赋值保存 - String imageFileName = null; - try { - imageFileName = ImageUtils.convertBase64ToImage(imagePath, - valueStr, "device" + deviceId, extension); - if (StringUtils.isNotBlank(imageFileName)) { - value = imageDomain + imagePrefix + imageFileName; - } else { - continue; - } - } catch (IOException e) { - logger.error("转换图片错误:" + e.getMessage(), e); + value = getImageFileName(imagePath, imageDomain, imagePrefix, valueStr, deviceId, extension); + if (value == null) continue; + } else if (dataType.equalsIgnoreCase(TdEngineConstants.PAYLOAD_DEVICE_DATA_TYPE_IMAGE)) { + if (ImageUtils.checkIsBase64(valueStr)) {//判断没有加前缀的情况 + value = getImageFileName(imagePath, imageDomain, imagePrefix, valueStr, deviceId, "jpg"); + if (value == null) continue; } } @@ -201,6 +197,19 @@ public class DataProcessServiceImpl implements IDataProcessService { return paramArr.size(); } + private static String getImageFileName(String imagePath, String imageDomain, String imagePrefix, String valueStr, Long deviceId, String extension) { + try { + String imageFileName = ImageUtils.convertBase64ToImage(imagePath, + valueStr, "device" + deviceId, extension); + return imageDomain + imagePrefix + imageFileName; + + } catch (IOException e) { + logger.error("转换图片错误:" + e.getMessage(), e); + } + return null; + } + + /** * @param: deviceId * @param: monitorUnitId @@ -304,7 +313,9 @@ public class DataProcessServiceImpl implements IDataProcessService { JSONObject json = JSON.parseObject(jsonData); Object value = json.get("base64"); if (value instanceof String) { + String valueStr = (String) value; + System.out.println(Base64.isBase64(valueStr)); if (StringUtils.isNotBlank(valueStr)) { /** * 先判读是否是图片,并获取图片名称, 获取到证明是图片 diff --git a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java index 5be23aa..542e243 100644 --- a/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java +++ b/ruoyi-modules/ruoyi-file/src/main/java/com/ruoyi/file/utils/FileUploadUtils.java @@ -182,7 +182,7 @@ public class FileUploadUtils { String fileName = extractFilename(originalFileName, imagePath, extension); String absPath = getAbsoluteFile(baseDir, fileName).getAbsolutePath(); - // 去掉base64前缀 data:image/jpeg;base64, + // 去掉base64前缀 例如:data:image/jpeg;base64, base64Str = base64Str.substring(base64Str.indexOf(",", 1) + 1); // 解密,解密的结果是一个byte数组 Base64.Decoder decoder = Base64.getDecoder(); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java index 731f292..2722bf4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDeptController.java @@ -4,6 +4,7 @@ import java.util.List; import com.ruoyi.basic.api.RemoteBasicService; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.model.LoginUser; import org.apache.commons.lang3.ArrayUtils; @@ -150,7 +151,7 @@ public class SysDeptController extends BaseController { public AjaxResult getTenants() { Long tenantId = SecurityUtils.getTenantId(); if (tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)) { - return success(remoteBasicService.getTenants().getData()); + return success(remoteBasicService.getTenants(SecurityConstants.INNER).getData()); } else { return success(); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysPostController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysPostController.java index 68095ba..ad93749 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysPostController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysPostController.java @@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse; import com.ruoyi.basic.api.RemoteBasicService; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; @@ -149,7 +150,7 @@ public class SysPostController extends BaseController public AjaxResult getTenants() { Long tenantId = SecurityUtils.getTenantId(); if (tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)) { - return success(remoteBasicService.getTenants().getData()); + return success(remoteBasicService.getTenants(SecurityConstants.INNER).getData()); } else { return success(); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java index e7f6319..33b7145 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java @@ -2,6 +2,7 @@ package com.ruoyi.system.controller; import com.ruoyi.basic.api.RemoteBasicService; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.poi.ExcelUtil; @@ -323,7 +324,7 @@ public class SysUserController extends BaseController { public AjaxResult getTenants() { Long tenantId = SecurityUtils.getTenantId(); if (tenantId.equals(HwDictConstants.ADMINISTRATOR_TENANT_ID)) { - return success(remoteBasicService.getTenants().getData()); + return success(remoteBasicService.getTenants(SecurityConstants.INNER).getData()); } else { return success(); } diff --git a/ruoyi-ui/src/api/board/index.js b/ruoyi-ui/src/api/board/index.js index 685fdbd..564433c 100644 --- a/ruoyi-ui/src/api/board/index.js +++ b/ruoyi-ui/src/api/board/index.js @@ -40,7 +40,7 @@ export function getAlarmInfos(query) { export function getDeviceOperations(query) { return request({ // baseURL:'/monitoring-api', - url: '/business/monitorPlatform/getDeviceOperations/1', + url: '/business/monitorPlatform/getDeviceOperations/0', method: 'get', }) } diff --git a/ruoyi-ui/src/views/board/equipment/index.vue b/ruoyi-ui/src/views/board/equipment/index.vue index 1b3cb8d..f06ecd1 100644 --- a/ruoyi-ui/src/views/board/equipment/index.vue +++ b/ruoyi-ui/src/views/board/equipment/index.vue @@ -26,7 +26,7 @@

状态: - {{ MonitorInfo.monitorUnitStatus === 1 ? '正常' : '异常' }} + {{ MonitorInfo.monitorUnitStatus === '1' ? '正常' : '异常' }}

类型: