From 5d20ff6f480926d74447022a16ace61e6b51583c Mon Sep 17 00:00:00 2001 From: xins Date: Sun, 8 Oct 2023 08:37:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?4.0=201=E3=80=81=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E9=87=8D=E5=90=AF=EF=BC=8C=E5=B9=B6=E4=B8=94=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E7=BD=91=E5=85=B3=E5=92=8C=E7=9B=B4=E8=BF=9E=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=8F=AF=E4=BB=A5=E6=8E=A7=E5=88=B6=202=E3=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E5=AE=8C=E5=96=84=E5=AF=B9?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=9A=84=E5=A4=84=E7=90=86=203=E3=80=81?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=8B=E6=9C=BA=E7=AB=AF=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=204=E3=80=81tenantId=E5=86=99=E5=88=B0header=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E4=BB=A5=E4=BE=BF=E5=9C=A8=E4=BF=9D=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E8=8E=B7=E5=8F=96=205=E3=80=81=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=AE=A1=E7=90=86=E7=A7=9F=E6=88=B7=E5=8F=AF=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/system/api/RemoteFileService.java | 16 + .../ruoyi/system/api/domain/Base64FileVo.java | 19 ++ .../factory/RemoteFileFallbackFactory.java | 6 + .../com/ruoyi/system/api/model/LoginUser.java | 10 + .../core/constant/SecurityConstants.java | 5 + .../core/context/SecurityContextHolder.java | 11 + .../com/ruoyi/common/core/utils/JwtUtils.java | 11 + .../interceptor/HeaderInterceptor.java | 1 + .../common/security/service/TokenService.java | 55 ++- .../common/security/utils/SecurityUtils.java | 8 + .../com/ruoyi/gateway/filter/AuthFilter.java | 2 + .../business/controller/HwAppController.java | 162 ++++++++- .../HwMonitorPlatformController.java | 8 +- .../business/domain/VO/DevicesInfoVo.java | 21 ++ .../business/mapper/HwAlarmInfoMapper.java | 8 + .../ruoyi/business/mapper/HwDeviceMapper.java | 10 + .../business/service/IHwDeviceService.java | 32 +- .../service/impl/HwDeviceServiceImpl.java | 322 ++++++++++-------- .../impl/HwMonitorUnitServiceImpl.java | 1 + .../mapper/business/HwAlarmInfoMapper.xml | 8 +- .../mapper/business/HwDeviceMapper.xml | 7 +- .../mapper/business/HwMonitorUnitMapper.xml | 2 +- .../mqtt/client/config/MqttConfiguration.java | 11 +- .../service/IDataProcessService.java | 13 +- .../service/impl/DataProcessServiceImpl.java | 68 +++- .../file/controller/SysFileController.java | 35 +- .../service/FastDfsSysFileServiceImpl.java | 7 + .../ruoyi/file/service/ISysFileService.java | 17 +- .../file/service/LocalSysFileServiceImpl.java | 34 +- .../file/service/MinioSysFileServiceImpl.java | 7 + .../com/ruoyi/file/utils/FileUploadUtils.java | 145 ++++---- .../ruoyi/system/RuoYiSystemApplication.java | 6 +- .../system/controller/SysRoleController.java | 2 + .../service/impl/SysRoleServiceImpl.java | 2 +- .../resources/mapper/system/SysRoleMapper.xml | 4 + ruoyi-ui/src/views/business/device/index.vue | 28 +- 36 files changed, 792 insertions(+), 312 deletions(-) create mode 100644 ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/Base64FileVo.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DevicesInfoVo.java diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java index ed49e2c..c9896f7 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/RemoteFileService.java @@ -1,8 +1,13 @@ package com.ruoyi.system.api; +import com.ruoyi.common.core.constant.SecurityConstants; +import com.ruoyi.system.api.domain.Base64FileVo; +import com.ruoyi.system.api.domain.SysOperLog; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.core.constant.ServiceNameConstants; @@ -26,4 +31,15 @@ public interface RemoteFileService */ @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public R upload(@RequestPart(value = "file") MultipartFile file); + + /** + * @param: base64FileVo + * @description 上传base64图片 + * @author xins + * @date 2023-10-07 9:43 + * @return R + */ + @PostMapping("/uploadBase64File") + public R uploadBase64File(@RequestBody Base64FileVo base64FileVo); + } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/Base64FileVo.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/Base64FileVo.java new file mode 100644 index 0000000..b9ed561 --- /dev/null +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/Base64FileVo.java @@ -0,0 +1,19 @@ +package com.ruoyi.system.api.domain; + +import lombok.Data; + +/** + * @Description: base64图片实体对象 + * @ClassName: Base64FileVo + * @Author : xins + * @Date :2023-10-07 9:36 + * @Version :1.0 + */ +@Data +public class Base64FileVo { + private String base64Str;//base64图片字符串 + + private String imagePath;//保存图片的前缀地址 + + private String extension;//图片后缀 +} diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java index 41def87..b2c1ce4 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/factory/RemoteFileFallbackFactory.java @@ -1,5 +1,6 @@ package com.ruoyi.system.api.factory; +import com.ruoyi.system.api.domain.Base64FileVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.cloud.openfeign.FallbackFactory; @@ -30,6 +31,11 @@ public class RemoteFileFallbackFactory implements FallbackFactory uploadBase64File(Base64FileVo base64FileVo) { + return R.fail("上传base64图片失败:" + throwable.getMessage()); + } }; } } diff --git a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java index ef266a0..647cbc6 100644 --- a/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java +++ b/ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/model/LoginUser.java @@ -58,6 +58,8 @@ public class LoginUser implements Serializable */ private SysUser sysUser; + private Long tenantId; + public String getToken() { return token; @@ -147,4 +149,12 @@ public class LoginUser implements Serializable { this.sysUser = sysUser; } + + public Long getTenantId() { + return tenantId; + } + + public void setTenantId(Long tenantId) { + this.tenantId = tenantId; + } } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/SecurityConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/SecurityConstants.java index 75a6090..f80a17d 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/SecurityConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/SecurityConstants.java @@ -46,4 +46,9 @@ public class SecurityConstants * 角色权限 */ public static final String ROLE_PERMISSION = "role_permission"; + + /** + * 租户ID字段 + */ + public static final String DETAILS_TENANTID = "tenantid"; } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/context/SecurityContextHolder.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/context/SecurityContextHolder.java index d7e94ec..db06321 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/context/SecurityContextHolder.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/context/SecurityContextHolder.java @@ -95,4 +95,15 @@ public class SecurityContextHolder { THREAD_LOCAL.remove(); } + + public static Long getTenantId() + { + return Convert.toLong(get(SecurityConstants.DETAILS_TENANTID), 0L); + } + + public static void setTenantId(String tenantIdStr) + { + set(SecurityConstants.DETAILS_TENANTID, tenantIdStr); + } + } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/JwtUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/JwtUtils.java index d984892..afb1db5 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/JwtUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/JwtUtils.java @@ -109,6 +109,17 @@ public class JwtUtils return getValue(claims, SecurityConstants.DETAILS_USERNAME); } + /** + * 根据身份信息获取用户名 + * + * @param claims 身份信息 + * @return 用户名 + */ + public static String getTenantId(Claims claims) + { + return getValue(claims, SecurityConstants.DETAILS_TENANTID); + } + /** * 根据身份信息获取键值 * diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/interceptor/HeaderInterceptor.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/interceptor/HeaderInterceptor.java index 18c8d2b..816e78b 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/interceptor/HeaderInterceptor.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/interceptor/HeaderInterceptor.java @@ -31,6 +31,7 @@ public class HeaderInterceptor implements AsyncHandlerInterceptor SecurityContextHolder.setUserId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USER_ID)); SecurityContextHolder.setUserName(ServletUtils.getHeader(request, SecurityConstants.DETAILS_USERNAME)); SecurityContextHolder.setUserKey(ServletUtils.getHeader(request, SecurityConstants.USER_KEY)); + SecurityContextHolder.setTenantId(ServletUtils.getHeader(request, SecurityConstants.DETAILS_TENANTID)); String token = SecurityUtils.getToken(); if (StringUtils.isNotEmpty(token)) diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java index 139ee8b..1ce76b5 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.ruoyi.common.core.constant.CacheConstants; @@ -19,12 +20,11 @@ import com.ruoyi.system.api.model.LoginUser; /** * token验证处理 - * + * * @author ruoyi */ @Component -public class TokenService -{ +public class TokenService { @Autowired private RedisService redisService; @@ -41,15 +41,16 @@ public class TokenService /** * 创建令牌 */ - public Map createToken(LoginUser loginUser) - { + public Map createToken(LoginUser loginUser) { String token = IdUtils.fastUUID(); Long userId = loginUser.getSysUser().getUserId(); String userName = loginUser.getSysUser().getUserName(); + Long tenantId = loginUser.getSysUser().getTenantId(); loginUser.setToken(token); loginUser.setUserid(userId); loginUser.setUsername(userName); loginUser.setIpaddr(IpUtils.getIpAddr()); + loginUser.setTenantId(tenantId); refreshToken(loginUser); // Jwt存储信息 @@ -57,6 +58,7 @@ public class TokenService claimsMap.put(SecurityConstants.USER_KEY, token); claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId); claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); + claimsMap.put(SecurityConstants.DETAILS_TENANTID, tenantId); // 接口返回信息 Map rspMap = new HashMap(); @@ -70,8 +72,7 @@ public class TokenService * * @return 用户信息 */ - public LoginUser getLoginUser() - { + public LoginUser getLoginUser() { return getLoginUser(ServletUtils.getRequest()); } @@ -80,8 +81,7 @@ public class TokenService * * @return 用户信息 */ - public LoginUser getLoginUser(HttpServletRequest request) - { + public LoginUser getLoginUser(HttpServletRequest request) { // 获取请求携带的令牌 String token = SecurityUtils.getToken(request); return getLoginUser(token); @@ -92,20 +92,15 @@ public class TokenService * * @return 用户信息 */ - public LoginUser getLoginUser(String token) - { + public LoginUser getLoginUser(String token) { LoginUser user = null; - try - { - if (StringUtils.isNotEmpty(token)) - { + try { + if (StringUtils.isNotEmpty(token)) { String userkey = JwtUtils.getUserKey(token); user = redisService.getCacheObject(getTokenKey(userkey)); return user; } - } - catch (Exception e) - { + } catch (Exception e) { } return user; } @@ -113,10 +108,8 @@ public class TokenService /** * 设置用户身份信息 */ - public void setLoginUser(LoginUser loginUser) - { - if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) - { + public void setLoginUser(LoginUser loginUser) { + if (StringUtils.isNotNull(loginUser) && StringUtils.isNotEmpty(loginUser.getToken())) { refreshToken(loginUser); } } @@ -124,10 +117,8 @@ public class TokenService /** * 删除用户缓存信息 */ - public void delLoginUser(String token) - { - if (StringUtils.isNotEmpty(token)) - { + public void delLoginUser(String token) { + if (StringUtils.isNotEmpty(token)) { String userkey = JwtUtils.getUserKey(token); redisService.deleteObject(getTokenKey(userkey)); } @@ -138,12 +129,10 @@ public class TokenService * * @param loginUser */ - public void verifyToken(LoginUser loginUser) - { + public void verifyToken(LoginUser loginUser) { long expireTime = loginUser.getExpireTime(); long currentTime = System.currentTimeMillis(); - if (expireTime - currentTime <= MILLIS_MINUTE_TEN) - { + if (expireTime - currentTime <= MILLIS_MINUTE_TEN) { refreshToken(loginUser); } } @@ -153,8 +142,7 @@ public class TokenService * * @param loginUser 登录信息 */ - public void refreshToken(LoginUser loginUser) - { + public void refreshToken(LoginUser loginUser) { loginUser.setLoginTime(System.currentTimeMillis()); loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); // 根据uuid将loginUser缓存 @@ -162,8 +150,7 @@ public class TokenService redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); } - private String getTokenKey(String token) - { + private String getTokenKey(String token) { return ACCESS_TOKEN + token; } } \ No newline at end of file diff --git a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java index 78a5393..1f49d79 100644 --- a/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java +++ b/ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/SecurityUtils.java @@ -114,4 +114,12 @@ public class SecurityUtils BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); return passwordEncoder.matches(rawPassword, encodedPassword); } + + /** + * 获取租户ID + */ + public static Long getTenantId() + { + return SecurityContextHolder.getTenantId(); + } } diff --git a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java index 101de63..b770f5c 100644 --- a/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java +++ b/ruoyi-gateway/src/main/java/com/ruoyi/gateway/filter/AuthFilter.java @@ -69,6 +69,7 @@ public class AuthFilter implements GlobalFilter, Ordered } String userid = JwtUtils.getUserId(claims); String username = JwtUtils.getUserName(claims); + String tenantId = JwtUtils.getTenantId(claims); if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) { return unauthorizedResponse(exchange, "令牌验证失败"); @@ -78,6 +79,7 @@ public class AuthFilter implements GlobalFilter, Ordered addHeader(mutate, SecurityConstants.USER_KEY, userkey); addHeader(mutate, SecurityConstants.DETAILS_USER_ID, userid); addHeader(mutate, SecurityConstants.DETAILS_USERNAME, username); + addHeader(mutate, SecurityConstants.DETAILS_TENANTID, tenantId); // 内部请求来源参数清除 removeHeader(mutate, SecurityConstants.FROM_SOURCE); return chain.filter(exchange.mutate().request(mutate.build()).build()); diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java index e0b64bb..a3a3048 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAppController.java @@ -1,14 +1,26 @@ package com.ruoyi.business.controller; +import com.ruoyi.business.domain.HwAlarmInfo; +import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.HwMonitorUnit; +import com.ruoyi.business.domain.HwScene; +import com.ruoyi.business.domain.VO.AllNumsVo; +import com.ruoyi.business.service.IHwAlarmInfoService; +import com.ruoyi.business.service.IHwDeviceService; import com.ruoyi.business.service.IHwMonitorUnitService; +import com.ruoyi.business.service.IHwSceneService; +import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.web.controller.BaseController; +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.RequiresPermissions; +import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.system.api.domain.SysUser; +import com.ruoyi.system.api.model.LoginUser; 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.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -25,16 +37,146 @@ public class HwAppController extends BaseController { @Autowired private IHwMonitorUnitService hwMonitorUnitService; + @Autowired + private IHwSceneService hwSceneService; + + @Autowired + private IHwAlarmInfoService hwAlarmInfoService; + + @Autowired + private IHwDeviceService hwDeviceService; + + /** + * 获取场景,如果是管理员,则可以获取所有场景 + */ + @GetMapping("/selectSecnes") + public AjaxResult selectSecnes(HwScene scene) { + List hwScenes = hwSceneService.selectHwSceneList(scene); + return success(hwScenes); + } + + /** + *  按场景展示总的设备数量和总的最子级监控单元数量(app首页上方) + */ + @RequiresPermissions("business:monitor:standard") + @GetMapping("/sceneAllNums/{sceneId}") + public AllNumsVo sceneAllNums(@PathVariable("sceneId") Long sceneId) { + return hwMonitorUnitService.selectAllNums(sceneId); + } + /** - * 查询监控单元列表 + * 分页获取最子集监控单元列表(首页) */ - @RequiresPermissions("business:monitorUnit:list") - @GetMapping("/monitorUnit/list") - public TableDataInfo monitorUnitList(HwMonitorUnit hwMonitorUnit) - { + @RequiresPermissions("business:monitor:standard") + @GetMapping("/limitSubMonitorUnit/{sceneId}") + public TableDataInfo limitSubMonitorUnit(@PathVariable("sceneId") Long sceneId) { + HwMonitorUnit hwMonitorUnit = new HwMonitorUnit(); + hwMonitorUnit.setSceneId(sceneId); startPage(); - List list = hwMonitorUnitService.selectHwMonitorUnitList(hwMonitorUnit); - return getDataTable(list); + List hwMonitorUnits = hwMonitorUnitService.selectLimitSubMonitorUnit(hwMonitorUnit); + return getDataTable(hwMonitorUnits); + } + + /** + * @return TableDataInfo + * @param: hwAlarmInfo + * @description 获取报警信息(手机首页) + * @author xins + * @date 2023-09-15 11:03 + */ + @GetMapping("/getAlarmInfos") + @RequiresPermissions("business:monitor:alarm") + public TableDataInfo getAlarmInfos(HwAlarmInfo hwAlarmInfo) { + hwAlarmInfo.setHandleStatus(HwDictConstants.ALARM_HANDLE_STATUS_NO); + List alarmInfos = hwAlarmInfoService.selectHwAlarmInfoList(hwAlarmInfo); + return getDataTable(alarmInfos); } + /** + * @param: hwAlarmInfo + * @description 处理报警信息 + * @author xins + * @date 2023-09-28 9:59 + * @return AjaxResult + */ + @PutMapping("/handleAlarmInfo") + @RequiresPermissions("business:monitor:alarm") + public AjaxResult handleAlarmInfo(@RequestBody HwAlarmInfo hwAlarmInfo) { + hwAlarmInfo.setUpdateBy(SecurityUtils.getUsername()); + return toAjax(hwAlarmInfoService.updateHwAlarmInfo(hwAlarmInfo)); + } + + + /** + * 树状获取监控单元列表(手机端监控单元页面) + * + * @param sceneId 场景ID + * @return list + * @throws + */ + @RequiresPermissions("business:monitor:deviceMonitor") + @GetMapping("/treeList/{sceneId}") + public AjaxResult monitorUnitTree(@PathVariable("sceneId") Long sceneId) { + HwMonitorUnit queryMonitorUnit = new HwMonitorUnit(); + queryMonitorUnit.setSceneId(sceneId); + return success(hwMonitorUnitService.selectMonitorTreeList(queryMonitorUnit)); + } + + /** + * @param: monitorUnitId + * @description 根据监控单元ID获取在线和离线设备数量,正常和告警设备数量 + * @author xins + * @date 2023-09-28 13:31 + * @return AjaxResult + */ + @RequiresPermissions("business:monitor:deviceMonitor") + @GetMapping("/getDevicesInfoByMonitorUnitId/{monitorUnitId}") + public AjaxResult getDevicesInfoByMonitorUnitId(@PathVariable("monitorUnitId") Long monitorUnitId){ + + return success(); + } + + /** + * 根据监控单元ID获取设备信息,分可控制设备和上传数据设备(手机监控单元页面) + * + * @param monitorUnitId 监控单元id + */ + @RequiresPermissions("business:monitor:deviceMonitor") + @GetMapping("/selectDevicesByMonitorUnitId/{monitorUnitId}/{sceneId}") + public AjaxResult selectDeviceByDeviceModeByMonitorUnitId(@PathVariable("monitorUnitId") Long monitorUnitId, + @PathVariable("sceneId") Long sceneId) { + HwDevice queryHwDevice = new HwDevice(); + queryHwDevice.setMonitorUnitId(monitorUnitId); + queryHwDevice.setSceneId(sceneId); + + return success(hwDeviceService.getDevicesByMonitor(queryHwDevice)); + } + + + /** + * 新增设备信息 + */ + @RequiresPermissions("business:device:add") + @Log(title = "设备信息(手机端)", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody HwDevice hwDevice) { + LoginUser loginUser = SecurityUtils.getLoginUser(); + SysUser user = loginUser.getSysUser(); + hwDevice.setTenantId(user.getTenantId()); + hwDevice.setCreateBy(user.getUserName()); + return toAjax(hwDeviceService.insertHwDevice(hwDevice)); + } + + /** + * 根据监设备编号获取设备信息,(手机扫一扫) + * + * @param deviceCode 设备编号 + */ + @RequiresPermissions("business:monitor:deviceMonitor") + @GetMapping("/getDeviceByDeviceCode/{deviceCode}") + public AjaxResult getDeviceByDeviceCode(@PathVariable("deviceCode") String deviceCode){ + return success(hwDeviceService.selectHwDeviceByDeviceCode(deviceCode)); + } + + } 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 062663c..b3fef1a 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 @@ -169,10 +169,7 @@ public class HwMonitorPlatformController extends BaseController { @RequiresPermissions("business:monitor:gps") @GetMapping("/subDevice/{sceneId}") public SubDeviceSumVo subDevice(@PathVariable("sceneId") Long sceneId) { - - SubDeviceSumVo subDeviceSumVos = hwMonitorUnitService.selectSubDeviceSum(sceneId); - - return subDeviceSumVos; + return hwMonitorUnitService.selectSubDeviceSum(sceneId); } @@ -305,8 +302,7 @@ public class HwMonitorPlatformController extends BaseController { /** - * 场景选择 - * ,id=0 可以返回所有,其他根据id过滤,默认标识 + * 获取场景,如果是管理员,则可以获取所有场景 */ @GetMapping("/selectSecnes") public AjaxResult selectSecnes(HwScene scene) { diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DevicesInfoVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DevicesInfoVo.java new file mode 100644 index 0000000..523bbc4 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DevicesInfoVo.java @@ -0,0 +1,21 @@ +package com.ruoyi.business.domain.VO; + +import lombok.Data; + +/** + * @Description: 设备情况实体对象 + * @ClassName: DevicesInfoVo + * @Author : xins + * @Date :2023-09-28 14:21 + * @Version :1.0 + */ +@Data +public class DevicesInfoVo { + public int onlineDevicesCount;//设备在线数量 + + public int offlineDevicesCount;//设备离线数量 + + public int normalDevicesCount;//正常设备数量(无报警) + + public int alarmDevicesCount;//报警设备数量 +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java index 20d16b5..a6c834e 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmInfoMapper.java @@ -66,4 +66,12 @@ public interface HwAlarmInfoMapper public AlarmInfoVo selectAlarmCountByFenceArea(Long fenceAreaId); + /** + * @param: monitorUnitId + * @description 根据监控单元ID获取报警的设备数量 + * @author xins + * @date 2023-09-28 14:17 + * @return int + */ + public int selectAlarmCountByMonitorUnitId(Long monitorUnitId); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java index f0801ac..1cb31cd 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwDeviceMapper.java @@ -76,6 +76,7 @@ public interface HwDeviceMapper public int getOnlineDeviceNum(Long sceneId); + public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId); public List selectLinkedDevices(Long deviceId); @@ -98,4 +99,13 @@ public interface HwDeviceMapper * @return int */ public int checkExistSubDevice(Long releatedDeviceId); + + /** + * @param: deviceCode + * @description 根据设备编号获取设备信息 + * @author xins + * @date 2023-09-28 13:23 + * @return HwDevice + */ + public HwDevice selectHwDeviceByDeviceCode(String deviceCode); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java index 5ef469b..af125dd 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java @@ -5,10 +5,7 @@ import java.util.Map; import com.alibaba.fastjson.JSONObject; import com.ruoyi.business.domain.HwDevice; -import com.ruoyi.business.domain.VO.DeviceControlVo; -import com.ruoyi.business.domain.VO.DeviceModeVo; -import com.ruoyi.business.domain.VO.HwDeviceVo; -import com.ruoyi.business.domain.VO.HwMonitorUnitVo; +import com.ruoyi.business.domain.VO.*; import com.ruoyi.common.datascope.annotation.DataScope; @@ -130,6 +127,24 @@ public interface IHwDeviceService */ public void computeOnlineDevicecCount(int days); + + /** + * @param: deviceControlVo + * @description 下发当网关,主题带设备编号 + * @author xins + * @date 2023-09-25 14:56 + */ + public void publishControlCommand(DeviceControlVo deviceControlVo); + + /** + * @param: deviceCode + * @description 根据设备编号获取设备信息 + * @author xins + * @date 2023-09-28 13:24 + * @return HwDevice + */ + public HwDevice selectHwDeviceByDeviceCode(String deviceCode); + /** * @param: sceneId * @description 获取最近几天在线设备数量 @@ -140,10 +155,11 @@ public interface IHwDeviceService public JSONObject getOnlineDevicesCount(Long sceneId); /** - * @param: deviceControlVo - * @description 下发当网关,主题带设备编号 + * @param: monitorUnitId + * @description 根据监控单元ID获取设备情况(包括在线和离线设备数量,正常的设备数量和报警的设备数量) * @author xins - * @date 2023-09-25 14:56 + * @date 2023-09-28 14:25 + * @return DevicesInfoVo */ - public void publishControlCommand(DeviceControlVo deviceControlVo); + public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId); } 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 98ff80f..6213f20 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 @@ -3,18 +3,12 @@ package com.ruoyi.business.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.alibaba.nacos.shaded.com.google.gson.JsonObject; -import com.ruoyi.business.domain.HwDevice; -import com.ruoyi.business.domain.HwDeviceMode; -import com.ruoyi.business.domain.HwDeviceModeFunction; -import com.ruoyi.business.domain.HwScene; +import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.VO.DeviceControlVo; import com.ruoyi.business.domain.VO.DeviceModeVo; +import com.ruoyi.business.domain.VO.DevicesInfoVo; import com.ruoyi.business.domain.VO.HwDeviceVo; -import com.ruoyi.business.mapper.HwDeviceMapper; -import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper; -import com.ruoyi.business.mapper.HwDeviceModeMapper; -import com.ruoyi.business.mapper.HwSceneMapper; +import com.ruoyi.business.mapper.*; import com.ruoyi.business.service.IHwDeviceService; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.HwDictConstants; @@ -35,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -57,6 +52,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService { private RemoteTdEngineService remoteTdEngineService; @Autowired private StringRedisTemplate redisTemplate; + @Autowired + private HwAlarmInfoMapper hwAlarmInfoMapper; /** * 查询设备信息 @@ -294,7 +291,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } for (int i = 0; i < list.size(); i++) { list.get(i).setPercentage(NumberUtils.getPercentage(list.get(i).getSum(), sums)); - System.out.println(list.get(i).toString()); } @@ -343,97 +339,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return hwDeviceMapper.updateHwDevice(hwDevice); } - /** - * @param: deviceControlVo - * @description 下发当网关,主题带设备编号 - * @author xins - * @date 2023-09-25 14:56 - */ - @Override - public void publishControlCommand(DeviceControlVo deviceControlVo) { - JSONObject controlCommandJson = new JSONObject(); - StringBuilder controlCommandTopic = new StringBuilder(); - Long deviceId = deviceControlVo.getDeviceId(); - HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); - String deviceType = device.getDeviceType(); - if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) { - Long gatewayDeviceId = device.getReleatedDeviceId(); - HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId); - controlCommandTopic.append(StringUtils - .format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, gatewayDevice.getDeviceCode())); - } else { - controlCommandTopic.append(StringUtils - .format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, device.getDeviceCode())); - } - JSONObject payloadJson = new JSONObject(); - payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, device.getDeviceCode()); - payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位:s - payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, deviceControlVo.getType()); - payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, "{}"); - - controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic.toString()); - controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString()); - - System.out.println("---" + controlCommandJson.toString()); - redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString()); - } - - - /** - * @param: hwDevice 前端传的对象 - * @param: dbDevice 目前数据库的对象 - * @description 更新TdEngine数据库tag - * @author xins - * @date 2023-09-19 10:55 - */ - private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) { - String deviceType = hwDevice.getDeviceType(); - String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId()); - String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId()); - AlterTagVo alterTagVo = new AlterTagVo(); - alterTagVo.setDatabaseName(databaseName); - alterTagVo.setTableName(tableName); - R tdReturnMsg; - if (deviceType.equals(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE) - || deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) { - if (!hwDevice.getDeviceCode().equals(dbDevice.getDeviceCode())) { - alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE); - alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'"); - - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); - if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 - throw new RuntimeException(tdReturnMsg.getMsg()); - } - } - if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) { - alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME); - alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'"); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); - if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 - throw new RuntimeException(tdReturnMsg.getMsg()); - } - } - - if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) { - alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID); - alterTagVo.setTagValue(hwDevice.getMonitorUnitId()); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); - if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 - throw new RuntimeException(tdReturnMsg.getMsg()); - } - } - - if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) { - alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID); - alterTagVo.setTagValue(hwDevice.getDeviceModeId()); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); - if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 - throw new RuntimeException(tdReturnMsg.getMsg()); - } - } - } - } - /** * 批量删除设备信息 * @@ -452,8 +357,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { * @return 结果 true 存在 false 不存在 */ @Override - public boolean checkExistSubDevice(Long releatedDeviceId) - { + public boolean checkExistSubDevice(Long releatedDeviceId) { int result = hwDeviceMapper.checkExistSubDevice(releatedDeviceId); return result > 0; } @@ -580,7 +484,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return devicesMap; } - /** * 查询设备信息列表,join监控单元、设备模型等表 * @@ -593,7 +496,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return hwDeviceMapper.selectHwDeviceJoinList(hwDevice); } - /** * @param: days * @description 计算前几天的设备在线数量 @@ -626,6 +528,185 @@ public class HwDeviceServiceImpl implements IHwDeviceService { redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO, jsonObject.toString()); } + + /** + * @param: deviceControlVo + * @description 下发当网关,主题带设备编号 + * @author xins + * @date 2023-09-25 14:56 + */ + @Override + public void publishControlCommand(DeviceControlVo deviceControlVo) { + JSONObject controlCommandJson = new JSONObject(); + StringBuilder controlCommandTopic = new StringBuilder(); + Long deviceId = deviceControlVo.getDeviceId(); + HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); + String deviceType = device.getDeviceType(); + if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) { + Long gatewayDeviceId = device.getReleatedDeviceId(); + HwDevice gatewayDevice = hwDeviceMapper.selectHwDeviceByDeviceId(gatewayDeviceId); + controlCommandTopic.append(StringUtils + .format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, gatewayDevice.getDeviceCode())); + } else { + controlCommandTopic.append(StringUtils + .format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, device.getDeviceCode())); + } + JSONObject payloadJson = new JSONObject(); + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, device.getDeviceCode()); + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位:s + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, deviceControlVo.getType()); + payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, "{}"); + + controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic.toString()); + controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString()); + + redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString()); + } + + /** + * @return HwDevice + * @param: deviceCode + * @description 根据设备编号获取设备信息 + * @author xins + * @date 2023-09-28 13:24 + */ + @Override + public HwDevice selectHwDeviceByDeviceCode(String deviceCode) { + return hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode); + } + + /** + * @return String + * @param: sceneId + * @description 获取最近几天在线设备数量 + * @author xins + * @date 2023-09-21 9:09 + */ + @Override + public JSONObject getOnlineDevicesCount(Long sceneId) { + JSONObject returnObj = new JSONObject(); + int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId); + + JSONObject sortedJsonObject = new JSONObject(); + + String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO); + if (onlineDeviceCountJsonStr != null) { + JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr); + + jsonObject.forEach((key, value) -> { + String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD, new Date(Long.parseLong(key))); + sortedJsonObject.put(dateStrKey, value); + }); + } + + returnObj.put("onlineDevicesTrend", sortedJsonObject); + returnObj.put("onlineDevicesCount", onlineDevicesCount); + return returnObj; + } + + /** + * @param: monitorUnitId + * @description 根据监控单元ID获取设备情况(包括在线和离线设备数量,正常的设备数量和报警的设备数量) + * @author xins + * @date 2023-09-28 14:25 + * @return DevicesInfoVo + */ + @Override + public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId) { + HwDevice queryDevice = new HwDevice(); + queryDevice.setMonitorUnitId(monitorUnitId); + queryDevice.setDeviceStatus(HwDictConstants.DEVICE_STATUS_PUBLISH); + List devices = this.selectHwDeviceList(queryDevice); + Map> hwDevicesMap = devices.stream() + .collect(Collectors.groupingBy(HwDevice::getDeviceType)); + List gatewayDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE); + List subDevices = hwDevicesMap.get(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT); + //根据关联网关设备ID进行分组 + Map> releatedDeviceIdDevicesMap = subDevices.stream() + .collect(Collectors.groupingBy(HwDevice::getReleatedDeviceId)); + int onlineDevicesCount = 0; + int offlineDevicesCount = 0; + for (HwDevice gatewayDevice : gatewayDevices) { + String onlineStatus = gatewayDevice.getOnlineStatus(); + //获取关联子设备的数量 + int gatewaySubPublishedDevicesCount = + releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()) == null ? + 0 : releatedDeviceIdDevicesMap.get(gatewayDevice.getDeviceId()).size(); + if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_ONLINE)) { + onlineDevicesCount += gatewaySubPublishedDevicesCount; + } else if (onlineStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_OFFLINE)) { + offlineDevicesCount += gatewaySubPublishedDevicesCount; + } + } + + int alarmDevicesCount = hwAlarmInfoMapper.selectAlarmCountByMonitorUnitId(monitorUnitId); + int normalDevicesCount = onlineDevicesCount + offlineDevicesCount - alarmDevicesCount; + + DevicesInfoVo devicesInfoVo = new DevicesInfoVo(); + devicesInfoVo.setOnlineDevicesCount(onlineDevicesCount); + devicesInfoVo.setOfflineDevicesCount(offlineDevicesCount); + devicesInfoVo.setNormalDevicesCount(normalDevicesCount); + devicesInfoVo.setAlarmDevicesCount(alarmDevicesCount); + + return devicesInfoVo; + } + + /** + * @param: hwDevice 前端传的对象 + * @param: dbDevice 目前数据库的对象 + * @description 更新TdEngine数据库tag + * @author xins + * @date 2023-09-19 10:55 + */ + private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) { + String deviceType = hwDevice.getDeviceType(); + String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId()); + String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId()); + AlterTagVo alterTagVo = new AlterTagVo(); + alterTagVo.setDatabaseName(databaseName); + alterTagVo.setTableName(tableName); + R tdReturnMsg; + if (deviceType.equals(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE) + || deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) { + if (!hwDevice.getDeviceCode().equals(dbDevice.getDeviceCode())) { + alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE); + alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'"); + + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) { + alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME); + alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'"); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + + if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) { + alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID); + alterTagVo.setTagValue(hwDevice.getMonitorUnitId()); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + + if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) { + alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID); + alterTagVo.setTagValue(hwDevice.getDeviceModeId()); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + } + } + + private Map computeDeviceCountPerDay(Long startTime, Long endTime) { //先增加需要查询的字段名称(由于tdengine用last和last_row查询时字段显示有bug,所以需要设置要查询的字段) List schemaFields = new ArrayList(); @@ -715,35 +796,4 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } } - - /** - * @return String - * @param: sceneId - * @description 获取最近几天在线设备数量 - * @author xins - * @date 2023-09-21 9:09 - */ - @Override - public JSONObject getOnlineDevicesCount(Long sceneId) { - JSONObject returnObj = new JSONObject(); - int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId); - - JSONObject sortedJsonObject = new JSONObject(); - - String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO); - if (onlineDeviceCountJsonStr != null) { - JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr); - - jsonObject.forEach((key, value) -> { - String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD, new Date(Long.parseLong(key))); - sortedJsonObject.put(dateStrKey, value); - }); - } - - returnObj.put("onlineDevicesTrend", sortedJsonObject); - returnObj.put("onlineDevicesCount", onlineDevicesCount); - return returnObj; - } - - } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java index f792dd7..f4efe06 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorUnitServiceImpl.java @@ -180,6 +180,7 @@ public class HwMonitorUnitServiceImpl implements IHwMonitorUnitService { @Override public SubDeviceSumVo selectSubDeviceSum(Long sceneId) { AllNumsVo numsVo = selectAllNums(sceneId); + //获取在线设备数量,获取已发布状态子设备并且关联网关为在线的数量 int onlineDeviceNum = hwDeviceMapper.getOnlineDeviceNum(sceneId); SubDeviceSumVo subDeviceSumVo = new SubDeviceSumVo(); diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml index a596d1b..0d5c386 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml @@ -76,7 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ${params.tenantDataScope} - order by alarm_info_id desc + order by alarm_info_id desc,hal.level_number desc + + \ No newline at end of file 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 a619e5f..354c641 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 @@ -229,7 +229,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -281,4 +281,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select count(1) from hw_device where releated_device_id = #{releatedDeviceId} and device_status != '9' + + \ No newline at end of file diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml index f4580e5..a8c3d04 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml @@ -157,7 +157,7 @@ @@ -109,6 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" status, remark, create_by, + tenant_id, create_time )values( #{roleId}, @@ -121,6 +124,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{status}, #{remark}, #{createBy}, + #{tenantId}, sysdate() ) diff --git a/ruoyi-ui/src/views/business/device/index.vue b/ruoyi-ui/src/views/business/device/index.vue index 502f662..86eecb4 100644 --- a/ruoyi-ui/src/views/business/device/index.vue +++ b/ruoyi-ui/src/views/business/device/index.vue @@ -152,15 +152,15 @@ - -