From e3ea45c5b8a1bf8399c676cd1662bbf7aebdb88e Mon Sep 17 00:00:00 2001 From: bobol Date: Thu, 9 May 2024 16:02:10 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=B7=A1=E6=A3=80=E5=8F=91=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-dev.yml | 42 ++- .../src/main/resources/application-prod.yml | 58 ++++ .../src/main/resources/application-test.yml | 26 ++ .../lzbi/common/config/MessageSendConfig.java | 42 +++ .../common/config/PatrolServerApiConfig.java | 54 ++++ .../lzbi/common/constant/BizConstants.java | 51 +++ .../lzbi/common/constant/CacheConstants.java | 7 + .../common/core/domain/ElementTreeNode.java | 70 +++++ .../core/domain/message/MessageSendReq.java | 58 ++++ .../domain/message/PatrolMessageSendReq.java | 30 ++ .../message/domain/DcMessageTemplate.java | 7 +- .../DcBusiDeptPatrolRouteController.java | 166 ++++++++++ .../controller/PatrolSysController.java | 60 ++++ .../patrol/domain/DcBusiDeptPatrolRoute.java | 29 ++ .../mapper/DcBusiDeptPatrolRouteMapper.java | 63 ++++ .../service/DcBusiDeptPatrolRouteService.java | 112 +++++++ .../patrol/service/PatrolSysApiService.java | 181 +++++++++++ .../lzbi/patrol/service/PatrolSysService.java | 296 ++++++++++++++++++ .../message/DcMessageTemplateMapper.xml | 57 ++-- .../patrol/DcBusiDeptPatrolRouteMapper.xml | 57 ++++ .../com/lzbi/system/mapper/SysDeptMapper.java | 2 + .../com/lzbi/system/mapper/SysUserMapper.java | 3 + .../lzbi/system/service/ISysDeptService.java | 7 + .../lzbi/system/service/ISysUserService.java | 8 + .../service/impl/SysDeptServiceImpl.java | 10 +- .../service/impl/SysUserServiceImpl.java | 13 + .../resources/mapper/system/SysDeptMapper.xml | 24 ++ .../resources/mapper/system/SysUserMapper.xml | 53 ++++ 28 files changed, 1546 insertions(+), 40 deletions(-) create mode 100644 lzbi-common/src/main/java/com/lzbi/common/config/MessageSendConfig.java create mode 100644 lzbi-common/src/main/java/com/lzbi/common/config/PatrolServerApiConfig.java create mode 100644 lzbi-common/src/main/java/com/lzbi/common/core/domain/ElementTreeNode.java create mode 100644 lzbi-common/src/main/java/com/lzbi/common/core/domain/message/MessageSendReq.java create mode 100644 lzbi-common/src/main/java/com/lzbi/common/core/domain/message/PatrolMessageSendReq.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/controller/DcBusiDeptPatrolRouteController.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/controller/PatrolSysController.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/domain/DcBusiDeptPatrolRoute.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/mapper/DcBusiDeptPatrolRouteMapper.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/service/DcBusiDeptPatrolRouteService.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysApiService.java create mode 100644 lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysService.java create mode 100644 lzbi-module/src/main/resources/mapper/patrol/DcBusiDeptPatrolRouteMapper.xml diff --git a/lzbi-admin/src/main/resources/application-dev.yml b/lzbi-admin/src/main/resources/application-dev.yml index 1f8ca3c..bdd9947 100644 --- a/lzbi-admin/src/main/resources/application-dev.yml +++ b/lzbi-admin/src/main/resources/application-dev.yml @@ -148,30 +148,56 @@ wechat: # 外部服务 goal-server: # iot平台服务地址 - iot: http://10.10.10.56:9010 + iot: http://localhost:9010 magic: http://10.10.10.56:9012/magic/api + # 巡检系统服务 + patrol: http://10.10.10.22:16882 + # 消息服务地址 + message-server: http://10.10.10.56:9015 -# 外部服务接口 +# IOT服务接口 iot-server-api: # 获取组织资产参数树形结构 orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree # 获取组织资产参数树形结构 paramsValue: ${goal-server.iot}/biz/common/paramsValue # 新增部门 - addDept: ${goal-server.iot}/system/dept + addDept: ${goal-server.iot}/interior/sign/system/dept # 修改部门 - updateDept: ${goal-server.iot}/system/dept + updateDept: ${goal-server.iot}/interior/sign/system/dept # 删除部门 - deleteDept: ${goal-server.iot}/system/dept + deleteDept: ${goal-server.iot}/interior/sign/system/dept # 新增用户 - addUser: ${goal-server.iot}/system/user + addUser: ${goal-server.iot}/interior/sign/system/user # 修改用户 - updateUser: ${goal-server.iot}/system/user + updateUser: ${goal-server.iot}/interior/sign/system/user # 删除用户 - deleteUser: ${goal-server.iot}/system/user + deleteUser: ${goal-server.iot}/interior/sign/system/user # magic api magic-server-api: # 获取收费系统参数 chargeSystemParams: ${goal-server.magic}/charge/sqaure +# 巡检系统服务API +patrol-server: + # 用户名 + userName: admin + # 密码 + userPwd: admin12345 + # 消息详情访问路径 + messageDetailUrl: www.baidu.com + # API + api: + # 登录 + login: ${goal-server.patrol}/PatrolRestfulApi.svc/SingleLogin?userName={userName}&userPwd={userPwd} + # 验证 Token 值是否有效 + checkToken: ${goal-server.patrol}/PatrolRestfulApi.svc/CheckToken?token={token} + # 获取线路列表 + routeList: ${goal-server.patrol}/PatrolRestfulApi.svc/GetUserRouteInfo?token={token} + # 根据线路ID获取报警信息列表 + alarmList: ${goal-server.patrol}/PatrolRestfulApi.svc/GetAlarmReport?token={token}&startTime={startTime}&endTime={endTime}&routeId={routeId}&pageIndex={pageIndex}&pageSize={pageSize} + +# 消息推送 +message-send: + url: ${goal-server.message-server}/message/send diff --git a/lzbi-admin/src/main/resources/application-prod.yml b/lzbi-admin/src/main/resources/application-prod.yml index 44c5e46..922d6f1 100644 --- a/lzbi-admin/src/main/resources/application-prod.yml +++ b/lzbi-admin/src/main/resources/application-prod.yml @@ -128,3 +128,61 @@ wechat: accessToken: https://api.weixin.qq.com/cgi-bin/token?appid={appid}&secret={secret}&grant_type={grant_type} # 获取手机号 phoneNumber: https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token={access_token} + + +# 外部服务 +goal-server: + # iot平台服务地址 + iot: http://localhost:9010 + magic: http://10.10.10.56:9012/magic/api + # 巡检系统服务 + patrol: http://10.10.10.22:16882 + # 消息服务地址 + message-server: http://10.10.10.56:9015 + +# IOT服务接口 +iot-server-api: + # 获取组织资产参数树形结构 + orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree + # 获取组织资产参数树形结构 + paramsValue: ${goal-server.iot}/biz/common/paramsValue + # 新增部门 + addDept: ${goal-server.iot}/interior/sign/system/dept + # 修改部门 + updateDept: ${goal-server.iot}/interior/sign/system/dept + # 删除部门 + deleteDept: ${goal-server.iot}/interior/sign/system/dept + # 新增用户 + addUser: ${goal-server.iot}/interior/sign/system/user + # 修改用户 + updateUser: ${goal-server.iot}/interior/sign/system/user + # 删除用户 + deleteUser: ${goal-server.iot}/interior/sign/system/user + +# magic api +magic-server-api: + # 获取收费系统参数 + chargeSystemParams: ${goal-server.magic}/charge/sqaure + +# 巡检系统服务API +patrol-server: + # 用户名 + userName: admin + # 密码 + userPwd: admin12345 + # 消息详情访问路径 + messageDetailUrl: www.baidu.com + # API + api: + # 登录 + login: ${goal-server.patrol}/PatrolRestfulApi.svc/SingleLogin?userName={userName}&userPwd={userPwd} + # 验证 Token 值是否有效 + checkToken: ${goal-server.patrol}/PatrolRestfulApi.svc/CheckToken?token={token} + # 获取线路列表 + routeList: ${goal-server.patrol}/PatrolRestfulApi.svc/GetUserRouteInfo?token={token} + # 根据线路ID获取报警信息列表 + alarmList: ${goal-server.patrol}/PatrolRestfulApi.svc/GetAlarmReport?token={token}&startTime={startTime}&endTime={endTime}&routeId={routeId}&pageIndex={pageIndex}&pageSize={pageSize} + +# 消息推送 +message-send: + url: ${goal-server.message-server}/message/send \ No newline at end of file diff --git a/lzbi-admin/src/main/resources/application-test.yml b/lzbi-admin/src/main/resources/application-test.yml index d9359b9..242be73 100644 --- a/lzbi-admin/src/main/resources/application-test.yml +++ b/lzbi-admin/src/main/resources/application-test.yml @@ -148,6 +148,10 @@ goal-server: # iot平台服务地址 iot: http://localhost:9010 magic: http://10.10.10.56:9012/magic/api + # 巡检系统服务 + patrol: http://10.10.10.22:16882 + # 消息服务地址 + message-server: http://10.10.10.56:9015 # IOT服务接口 iot-server-api: @@ -173,3 +177,25 @@ magic-server-api: # 获取收费系统参数 chargeSystemParams: ${goal-server.magic}/charge/sqaure +# 巡检系统服务API +patrol-server: + # 用户名 + userName: admin + # 密码 + userPwd: admin12345 + # 消息详情访问路径 + messageDetailUrl: www.baidu.com + # API + api: + # 登录 + login: ${goal-server.patrol}/PatrolRestfulApi.svc/SingleLogin?userName={userName}&userPwd={userPwd} + # 验证 Token 值是否有效 + checkToken: ${goal-server.patrol}/PatrolRestfulApi.svc/CheckToken?token={token} + # 获取线路列表 + routeList: ${goal-server.patrol}/PatrolRestfulApi.svc/GetUserRouteInfo?token={token} + # 根据线路ID获取报警信息列表 + alarmList: ${goal-server.patrol}/PatrolRestfulApi.svc/GetAlarmReport?token={token}&startTime={startTime}&endTime={endTime}&routeId={routeId}&pageIndex={pageIndex}&pageSize={pageSize} + +# 消息推送 +message-send: + url: ${goal-server.message-server}/message/send \ No newline at end of file diff --git a/lzbi-common/src/main/java/com/lzbi/common/config/MessageSendConfig.java b/lzbi-common/src/main/java/com/lzbi/common/config/MessageSendConfig.java new file mode 100644 index 0000000..59b2aab --- /dev/null +++ b/lzbi-common/src/main/java/com/lzbi/common/config/MessageSendConfig.java @@ -0,0 +1,42 @@ +package com.lzbi.common.config; + +import com.alibaba.fastjson2.JSONObject; +import com.lzbi.common.core.domain.message.MessageSendReq; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +@Slf4j +@Data +@Component +@ConfigurationProperties("message-send") +public class MessageSendConfig { + + @Autowired + private RestTemplate restTemplate; + + /** + * 消息发送地址 + */ + private String url; + + public void send(MessageSendReq messageSendReq) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + String bodyStr = JSONObject.toJSONString(messageSendReq); + HttpEntity entity = new HttpEntity<>(bodyStr, headers); + String result = ""; + try { + result = restTemplate.postForObject(this.url, entity, String.class); + } finally { + log.info("消息体:{},发送结果:{}", bodyStr, result); + } + } + +} diff --git a/lzbi-common/src/main/java/com/lzbi/common/config/PatrolServerApiConfig.java b/lzbi-common/src/main/java/com/lzbi/common/config/PatrolServerApiConfig.java new file mode 100644 index 0000000..21a4193 --- /dev/null +++ b/lzbi-common/src/main/java/com/lzbi/common/config/PatrolServerApiConfig.java @@ -0,0 +1,54 @@ +package com.lzbi.common.config; + + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * 巡检服务API + */ +@Data +@Component +@ConfigurationProperties(prefix = "patrol-server") +public class PatrolServerApiConfig { + /** + * 用户名 + */ + private String userName; + /** + * 密码 + */ + private String userPwd; + /** + * 消息详情访问路径 + */ + private String messageDetailUrl; + /** + * API + */ + private Api api; + + /** + * API + */ + @Data + public static class Api { + /** + * 登录 + */ + private String login; + /** + * 验证 Token 值是否有效 + */ + private String checkToken; + /** + * 获取线路列表 + */ + private String routeList; + /** + * 获取报警列表 + */ + private String alarmList; + } +} diff --git a/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java b/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java index 962fcd7..1b9fd5a 100644 --- a/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java +++ b/lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java @@ -5,6 +5,57 @@ package com.lzbi.common.constant; */ public interface BizConstants { + /** + * 巡检告警类型 + */ + interface PatrolAlarmType { + /** + * 漏检提醒 + */ + String MISSED_REMINDER = "2"; + } + + /** + * 消息平台 + */ + interface MessagePlatform { + /** + * 电话 + */ + String PHONE = "1"; + /** + * 短信 + */ + String SMS = "2"; + /** + * 企业微信 + */ + String WECOM = "3"; + } + + /** + * 角色编码 + */ + interface RoleKey { + /** + * 巡检通知 + */ + String PATROL_NOTIFY = "patrol_notify"; + } + + /** + * 消息类型 + */ + interface MessageType { + /** + * 告警 + */ + String ALARM = "1"; + /** + * 公告 + */ + String AFFICHE = "2"; + } /** * T指标P参数 */ diff --git a/lzbi-common/src/main/java/com/lzbi/common/constant/CacheConstants.java b/lzbi-common/src/main/java/com/lzbi/common/constant/CacheConstants.java index 88763c5..5a8dcc3 100644 --- a/lzbi-common/src/main/java/com/lzbi/common/constant/CacheConstants.java +++ b/lzbi-common/src/main/java/com/lzbi/common/constant/CacheConstants.java @@ -41,4 +41,11 @@ public class CacheConstants * 登录账户密码错误次数 redis key */ public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:"; + + public static final String PATROL_SYS_BASE = "PATROL_SYS:"; + public static final String PATROL_SYS_ROUTE_TREE = "ROUTE_TREE"; + public static final String PATROL_SYS_ALARM_MAP = "ALARM_MAP"; + public static final String PATROL_SYS_TOKEN = "TOKEN:"; + + } diff --git a/lzbi-common/src/main/java/com/lzbi/common/core/domain/ElementTreeNode.java b/lzbi-common/src/main/java/com/lzbi/common/core/domain/ElementTreeNode.java new file mode 100644 index 0000000..c2c26c7 --- /dev/null +++ b/lzbi-common/src/main/java/com/lzbi/common/core/domain/ElementTreeNode.java @@ -0,0 +1,70 @@ +package com.lzbi.common.core.domain; + +import java.util.List; + +/** + * elementUI树形控件节点 + */ +public class ElementTreeNode { + + /** + * 值 + */ + private Object value; + /** + * 标签 + */ + private String label; + /** + * 是否可用 + */ + private boolean disabled; + /** + * 是否叶子节点 + */ + private boolean leaf; + /** + * 子节点 + */ + private List children; + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public boolean isDisabled() { + return disabled; + } + + public void setDisabled(boolean disabled) { + this.disabled = disabled; + } + + public boolean isLeaf() { + return leaf; + } + + public void setLeaf(boolean leaf) { + this.leaf = leaf; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } +} diff --git a/lzbi-common/src/main/java/com/lzbi/common/core/domain/message/MessageSendReq.java b/lzbi-common/src/main/java/com/lzbi/common/core/domain/message/MessageSendReq.java new file mode 100644 index 0000000..451aa5c --- /dev/null +++ b/lzbi-common/src/main/java/com/lzbi/common/core/domain/message/MessageSendReq.java @@ -0,0 +1,58 @@ +package com.lzbi.common.core.domain.message; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import java.util.List; + +/** + * 消息发送请求实体类 + */ +@Data +public class MessageSendReq { + + /** + * 系统 + */ + @NotBlank(message = "系统不能为空") + protected String sys; + /** + * 平台 + */ + @NotBlank(message = "平台不能为空") + protected String platform; + /** + * 消息类型(1、告警,2、公告) + */ + @NotBlank(message = "消息类型不能为空") + protected String type; + /** + * 消息内容 + */ + @NotBlank(message = "消息内容不能为空") + protected String content; + /** + * 告警设备 + */ + @NotBlank(message = "告警设备不能为空") + protected String device; + /** + * 提醒时间 + */ + @NotBlank(message = "提醒时间不能为空") + protected String time; + /** + * 温馨提示 + */ + protected String hint; + /** + * 详情链接 + */ + protected String url; + /** + * 手机号列表 + */ + @NotEmpty(message = "手机号列表不能为空") + protected List phoneList; +} diff --git a/lzbi-common/src/main/java/com/lzbi/common/core/domain/message/PatrolMessageSendReq.java b/lzbi-common/src/main/java/com/lzbi/common/core/domain/message/PatrolMessageSendReq.java new file mode 100644 index 0000000..04e6a83 --- /dev/null +++ b/lzbi-common/src/main/java/com/lzbi/common/core/domain/message/PatrolMessageSendReq.java @@ -0,0 +1,30 @@ +package com.lzbi.common.core.domain.message; + +import com.alibaba.fastjson2.annotation.JSONField; +import com.lzbi.common.config.PatrolServerApiConfig; +import com.lzbi.common.constant.BizConstants; +import com.lzbi.common.utils.spring.SpringUtils; +import lombok.Data; + +import java.util.List; + +/** + * 巡检消息发送请求参数 + */ +@Data +public class PatrolMessageSendReq extends MessageSendReq { + + @JSONField(serialize=false) + private PatrolServerApiConfig patrolServerApiConfig = SpringUtils.getBean(PatrolServerApiConfig.class); + + public PatrolMessageSendReq(String content, String time, List phoneList) { + this.sys = "patrol"; + this.platform = BizConstants.MessagePlatform.WECOM; + this.type = BizConstants.MessageType.ALARM; + this.time = time; + this.phoneList = phoneList; + this.content = content; + this.hint = "请及时处理"; + this.setUrl(patrolServerApiConfig.getMessageDetailUrl()); + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/message/domain/DcMessageTemplate.java b/lzbi-module/src/main/java/com/lzbi/message/domain/DcMessageTemplate.java index a6fd509..d339dcf 100644 --- a/lzbi-module/src/main/java/com/lzbi/message/domain/DcMessageTemplate.java +++ b/lzbi-module/src/main/java/com/lzbi/message/domain/DcMessageTemplate.java @@ -31,9 +31,12 @@ public class DcMessageTemplate extends BaseModuleEntity @ApiModelProperty(name = "模板名称",notes = "templateName") private String templateName; + /** 系统类型(1、IOT大数据平台) */ + @Excel(name = "系统类型", readConverterExp = "1=、IOT大数据平台") + @ApiModelProperty(name = "系统类型",notes = "") + private String systemType; + /** 删除标志(0代表存在 2代表删除) */ private String delFlag; - - } diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/controller/DcBusiDeptPatrolRouteController.java b/lzbi-module/src/main/java/com/lzbi/patrol/controller/DcBusiDeptPatrolRouteController.java new file mode 100644 index 0000000..e0d79a4 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/controller/DcBusiDeptPatrolRouteController.java @@ -0,0 +1,166 @@ +package com.lzbi.patrol.controller; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; +import io.swagger.annotations.ApiOperation; +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import javax.validation.constraints.NotEmpty; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.lzbi.common.annotation.Log; +import com.lzbi.common.core.controller.BaseController; +import com.lzbi.common.core.domain.AjaxResult; +import com.lzbi.common.enums.BusinessType; +import com.lzbi.patrol.domain. DcBusiDeptPatrolRoute; +import com.lzbi.patrol.service.DcBusiDeptPatrolRouteService; +import com.lzbi.common.utils.poi.ExcelUtil; +import com.lzbi.common.core.page.TableDataInfo; + +/** + * 部门与巡检系统线路关系Controller + * + * @author Enbo Li + * @date 2024-05-08 + */ +@Validated +@RestController +@RequestMapping("/lzbi/DcBusiDeptPatrolRoute") +public class DcBusiDeptPatrolRouteController extends BaseController +{ + @Autowired + private DcBusiDeptPatrolRouteService dcBusiDeptPatrolRouteService; + + /** + * 查询部门与巡检系统线路关系列表 + */ + @ApiOperation("查询部门与巡检系统线路关系列表") + @ApiImplicitParams({ + @ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:list')") + @GetMapping("/list") + public TableDataInfo list(DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) + { + startPage(); + List< DcBusiDeptPatrolRoute> list = dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute); + return getDataTable(list); + } + + /** + * 导出部门与巡检系统线路关系列表 + */ + @ApiOperation("导出部门与巡检系统线路关系列表") + @ApiImplicitParams({ + @ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:export')") + @Log(title = "部门与巡检系统线路关系", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response,DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) + { + List list = dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute); + ExcelUtil util = new ExcelUtil(DcBusiDeptPatrolRoute.class); + util.exportExcel(response, list, "部门与巡检系统线路关系数据"); + } + + /** + * 获取部门与巡检系统线路关系详细信息 + */ + @ApiOperation("获取部门与巡检系统线路关系详细信息") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deptId", value = "", dataType = "Long", dataTypeClass = Long.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:query')") + @GetMapping(value = "/{deptId}") + public AjaxResult getInfo(@PathVariable("deptId") Long deptId) + { + return success(dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteByDeptId(deptId)); + } + + /** + * 获取线路ID列表 + */ + @ApiOperation("获取线路ID列表") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deptId", value = "", dataType = "Long", dataTypeClass = Long.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:query')") + @GetMapping(value = "/routeIdList/{deptId}") + public AjaxResult getRouteIdList(@PathVariable("deptId") Long deptId) + { + return success(dcBusiDeptPatrolRouteService.getRouteIdList(deptId)); + } + + /** + * 新增部门与巡检系统线路关系 + */ + @ApiOperation("新增部门与巡检系统线路关系") + @ApiImplicitParams({ + @ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:add')") + @Log(title = "部门与巡检系统线路关系", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) + { + return toAjax(dcBusiDeptPatrolRouteService.insertDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute)); + } + + /** + * 修改部门与巡检系统线路关系 + */ + + @ApiOperation("修改部门与巡检系统线路关系") + @ApiImplicitParams({ + @ApiImplicitParam(name = "DcBusiDeptPatrolRoute", value = "", dataType = "DcBusiDeptPatrolRoute", dataTypeClass = DcBusiDeptPatrolRoute.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:edit')") + @Log(title = "部门与巡检系统线路关系", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody DcBusiDeptPatrolRoute DcBusiDeptPatrolRoute) + { + return toAjax(dcBusiDeptPatrolRouteService.updateDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute)); + } + + /** + * 修改部门与巡检系统线路关系 + */ + + @ApiOperation("更新部门与巡检系统线路关系") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deptId", value = "", dataType = "Long", dataTypeClass = Long.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:edit')") + @Log(title = "更新部门与巡检系统线路关系", businessType = BusinessType.UPDATE) + @PutMapping("/{deptId}") + public AjaxResult update(@PathVariable("deptId") Long deptId, + @NotEmpty(message = "请选择线路") @RequestBody List routeIdList) + { + return toAjax(dcBusiDeptPatrolRouteService.update(deptId, routeIdList)); + } + + /** + * 删除部门与巡检系统线路关系 + */ + @ApiOperation("删除部门与巡检系统线路关系") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deptIds", value = "", dataType = "Long", dataTypeClass =Long.class), + }) + @PreAuthorize("@ss.hasPermi('lzbi:DcBusiDeptPatrolRoute:remove')") + @Log(title = "部门与巡检系统线路关系", businessType = BusinessType.DELETE) + @DeleteMapping("/{deptIds}") + public AjaxResult remove(@PathVariable Long[] deptIds) + { + return toAjax(dcBusiDeptPatrolRouteService.deleteDcBusiDeptPatrolRouteByDeptIds(deptIds)); + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/controller/PatrolSysController.java b/lzbi-module/src/main/java/com/lzbi/patrol/controller/PatrolSysController.java new file mode 100644 index 0000000..034b2e8 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/controller/PatrolSysController.java @@ -0,0 +1,60 @@ +package com.lzbi.patrol.controller; + +import com.lzbi.common.core.domain.AjaxResult; +import com.lzbi.patrol.service.PatrolSysService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Map; + +/** + * 巡检系统 + */ +@RestController +@RequestMapping("/patrol-sys") +public class PatrolSysController { + + @Autowired + private PatrolSysService patrolSysService; + + /** + * 获取线路树形结构 + * @return + */ + @GetMapping("/route-tree") + public AjaxResult getRouteTree() { + return AjaxResult.success(patrolSysService.getRouteTree()); + } + + /** + * 获取告警列表 + * @return + */ + @GetMapping("/alarm-list") + public AjaxResult getAlarmList(@RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime, + @RequestParam("pageIndex") Integer pageIndex, + @RequestParam("pageSize") Integer pageSize) { + return AjaxResult.success(patrolSysService.getAlarmList(startTime, endTime, pageIndex, pageSize)); + } + + /** + * 获取告警列表 + * @return + */ + @GetMapping("/alarm-list/{routeId}") + public AjaxResult getAlarmListByRouteId(@PathVariable("routeId") String routeId) { + return AjaxResult.success(patrolSysService.getAlarmListByRouteId(routeId)); + } + + /** + * 触发告警 + * @return + */ + @PostMapping("/trigger/alarm") + public AjaxResult triggerAlarm(@RequestBody Map routeAlarmCountMap) { + patrolSysService.triggerAlarm(routeAlarmCountMap); + return AjaxResult.success(); + } + +} diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/domain/DcBusiDeptPatrolRoute.java b/lzbi-module/src/main/java/com/lzbi/patrol/domain/DcBusiDeptPatrolRoute.java new file mode 100644 index 0000000..a74a0c3 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/domain/DcBusiDeptPatrolRoute.java @@ -0,0 +1,29 @@ +package com.lzbi.patrol.domain; + +import com.baomidou.mybatisplus.extension.activerecord.Model; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +/** + * 部门与巡检系统线路关系对象 dc_busi_dept_patrol_route + * + * @author Enbo Li + * @date 2024-05-08 + */ +@Data +@Accessors(chain = true) +@AllArgsConstructor +@NoArgsConstructor +public class DcBusiDeptPatrolRoute extends Model +{ + private static final long serialVersionUID = 1L; + + /** 部门id */ + private Long deptId; + + /** 线路id */ + private Long routeId; + +} diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/mapper/DcBusiDeptPatrolRouteMapper.java b/lzbi-module/src/main/java/com/lzbi/patrol/mapper/DcBusiDeptPatrolRouteMapper.java new file mode 100644 index 0000000..0b2a85e --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/mapper/DcBusiDeptPatrolRouteMapper.java @@ -0,0 +1,63 @@ +package com.lzbi.patrol.mapper; + +import java.util.List; +import com.lzbi.patrol.domain.DcBusiDeptPatrolRoute; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +/** + * 部门与巡检系统线路关系Mapper接口 + * + * @author Enbo Li + * @date 2024-05-08 + */ + +public interface DcBusiDeptPatrolRouteMapper extends BaseMapper +{ + /** + * 查询部门与巡检系统线路关系 + * + * @param deptId 部门与巡检系统线路关系主键 + * @return 部门与巡检系统线路关系 + */ + public DcBusiDeptPatrolRoute selectDcBusiDeptPatrolRouteByDeptId(Long deptId); + + /** + * 查询部门与巡检系统线路关系列表 + * + * @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 + * @return 部门与巡检系统线路关系集合 + */ + public List selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute); + + /** + * 新增部门与巡检系统线路关系 + * + * @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 + * @return 结果 + */ + public int insertDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute); + + /** + * 修改部门与巡检系统线路关系 + * + * @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 + * @return 结果 + */ + public int updateDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute); + + /** + * 删除部门与巡检系统线路关系 + * + * @param deptId 部门与巡检系统线路关系主键 + * @return 结果 + */ + public int deleteDcBusiDeptPatrolRouteByDeptId(Long deptId); + + /** + * 批量删除部门与巡检系统线路关系 + * + * @param deptIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteDcBusiDeptPatrolRouteByDeptIds(Long[] deptIds); +} diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/service/DcBusiDeptPatrolRouteService.java b/lzbi-module/src/main/java/com/lzbi/patrol/service/DcBusiDeptPatrolRouteService.java new file mode 100644 index 0000000..91da588 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/service/DcBusiDeptPatrolRouteService.java @@ -0,0 +1,112 @@ +package com.lzbi.patrol.service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import org.springframework.stereotype.Service; +import com.lzbi.patrol.domain.DcBusiDeptPatrolRoute; +import com.lzbi.patrol.mapper.DcBusiDeptPatrolRouteMapper; +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + +/** + * 部门与巡检系统线路关系Service业务层处理 + * + * @author Enbo Li + * @date 2024-05-08 + */ +@Service +public class DcBusiDeptPatrolRouteService extends ServiceImpl implements IService +{ + + /** + * 查询部门与巡检系统线路关系 + * + * @param deptId 部门与巡检系统线路关系主键 + * @return 部门与巡检系统线路关系 + */ + public DcBusiDeptPatrolRoute selectDcBusiDeptPatrolRouteByDeptId(Long deptId) + { + return baseMapper.selectDcBusiDeptPatrolRouteByDeptId(deptId); + } + + /** + * 查询部门与巡检系统线路关系列表 + * + * @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 + * @return 部门与巡检系统线路关系 + */ + public List selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute) + { + return baseMapper.selectDcBusiDeptPatrolRouteList(dcBusiDeptPatrolRoute); + } + + /** + * 新增部门与巡检系统线路关系 + * + * @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 + * @return 结果 + */ + + public int insertDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute) + { + return baseMapper.insertDcBusiDeptPatrolRoute(dcBusiDeptPatrolRoute); + } + + /** + * 修改部门与巡检系统线路关系 + * + * @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系 + * @return 结果 + */ + + public int updateDcBusiDeptPatrolRoute(DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute) + { + return baseMapper.updateDcBusiDeptPatrolRoute(dcBusiDeptPatrolRoute); + } + + /** + * 批量删除部门与巡检系统线路关系 + * + * @param deptIds 需要删除的部门与巡检系统线路关系主键 + * @return 结果 + */ + + public int deleteDcBusiDeptPatrolRouteByDeptIds(Long[] deptIds) + { + return baseMapper.deleteDcBusiDeptPatrolRouteByDeptIds(deptIds); + } + + /** + * 删除部门与巡检系统线路关系信息 + * + * @param deptId 部门与巡检系统线路关系主键 + * @return 结果 + */ + + public int deleteDcBusiDeptPatrolRouteByDeptId(Long deptId) + { + return baseMapper.deleteDcBusiDeptPatrolRouteByDeptId(deptId); + } + + public List getRouteIdList(Long deptId) { + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.eq("dept_id", deptId); + List list = this.list(wrapper); + if (!CollectionUtils.isEmpty(list)) { + return list.stream().map(DcBusiDeptPatrolRoute::getRouteId).collect(Collectors.toList()); + } + return new ArrayList<>(); + } + + @Transactional(rollbackFor = Exception.class) + public boolean update(Long deptId, List routeIdList) { + this.remove(new QueryWrapper().eq("dept_id", deptId)); + List dcBusiDeptPatrolRouteList = routeIdList.stream().map(routeId -> new DcBusiDeptPatrolRoute(deptId, routeId)).collect(Collectors.toList()); + return this.saveBatch(dcBusiDeptPatrolRouteList); + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysApiService.java b/lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysApiService.java new file mode 100644 index 0000000..87b790d --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysApiService.java @@ -0,0 +1,181 @@ +package com.lzbi.patrol.service; + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.lzbi.common.config.PatrolServerApiConfig; +import com.lzbi.common.constant.CacheConstants; +import com.lzbi.common.core.redis.RedisCache; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +/** + * 巡检系统API业务 + */ +@Slf4j +@Service +public class PatrolSysApiService { + + @Autowired + private RestTemplate restTemplate; + + @Autowired + private PatrolServerApiConfig patrolServerApiConfig; + + @Autowired + private RedisCache redisCache; + + /** + * 登录 + * @param userName + * @param userPwd + * @return + */ + public String login(String userName, String userPwd) { + String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_TOKEN + userName; + String token = redisCache.getCacheObject(key); + if (StringUtils.isBlank(token)) { + Map params = new HashMap<>(); + params.put("userName", userName); + params.put("userPwd", userPwd); + String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getLogin(), String.class, params); + log.info("登录返回值:{},参数:{}/{}", result, userName, userPwd); + if (StringUtils.isBlank(result)) { + log.error("登录失败,无返回值"); + throw new RuntimeException("登录失败,无返回值"); + } + JSONObject resultJson = JSONObject.parseObject(result); + JSONObject d = resultJson.getJSONObject("d"); + if (d == null) { + log.error("登录失败,返回值中无d字段"); + throw new RuntimeException("登录失败,返回值中无d字段"); + } + token = d.getString("Token"); + if (StringUtils.isBlank(token)) { + log.error("登录失败,返回值中无token字段"); + throw new RuntimeException("登录失败,返回值中无token字段"); + } + redisCache.setCacheObject(key, token); + } + return token; + } + + /** + * 验证 Token 值是否有效 + * @param token + * @return + */ + public boolean checkToken(String token) { + Map params = new HashMap<>(); + params.put("token", token); + String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getCheckToken(), String.class, params); + log.info("验证 Token 值是否有效返回值:{}, 参数:{}", result, JSONObject.toJSONString(params)); + if (StringUtils.isBlank(result)) { + log.error("验证 Token 值是否有效失败,无返回值"); + throw new RuntimeException("登录失败,无返回值"); + } + JSONObject resultJson = JSONObject.parseObject(result); + String d = resultJson.getString("d"); + if (StringUtils.isBlank(d)) { + log.error("验证 Token 值是否有效失败,返回值中无d字段"); + throw new RuntimeException("登录失败,返回值中无d字段"); + } + if ("\"{success:true}\"".equals(d)) { + return true; + } + return false; + } + + /** + * 获取 Token 值 + * @return + */ + public String getToken() { + String token = this.login(patrolServerApiConfig.getUserName(), patrolServerApiConfig.getUserPwd()); + if (StringUtils.isBlank(token)) { + log.error("获取 Token 值失败"); + throw new RuntimeException("获取 Token 值失败"); + } + // 如果token无效,就清除redis中的token,重新获取 + if (!this.checkToken(token)) { + log.error("第一次获取 Token 值失败,Token 值无效"); + String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_TOKEN + patrolServerApiConfig.getUserName(); + redisCache.deleteObject(key); + token = this.login(patrolServerApiConfig.getUserName(), patrolServerApiConfig.getUserPwd()); + if (!this.checkToken(token)) { + log.error("第二次获取 Token 值失败,Token 值无效"); + throw new RuntimeException("获取 Token 值失败,Token 值无效"); + } + } + return token; + } + + /** + * 获取巡检线路列表 + * @return + */ + public JSONArray getRouteList() { + String token = getToken(); + Map params = new HashMap<>(); + params.put("token", token); + String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getRouteList(), String.class, params); + log.info("获取巡检线路列表返回值:{},参数:{}", result, JSONObject.toJSONString(params)); + if (StringUtils.isBlank(result)) { + log.error("获取巡检线路列表失败,无返回值"); + throw new RuntimeException("获取巡检线路列表失败,无返回值"); + } + JSONObject resultJson = JSONObject.parseObject(result); + JSONArray d = resultJson.getJSONArray("d"); + if (CollectionUtils.isEmpty(d)) { + log.error("获取巡检线路列表失败,返回值中无d字段"); + throw new RuntimeException("获取巡检线路列表失败,返回值中无d字段"); + } + log.info("获取巡检线路列表成功,线路列表:{}", d.toJSONString()); + return d; + } + + /** + * 获取巡检报警列表 + * @param startTime + * @param endTime + * @param routeId + * @param pageIndex + * @param pageSize + * @return + */ + public JSONArray getAlarmList(String startTime, String endTime, Long routeId, int pageIndex, int pageSize) { + String token = getToken(); + JSONObject params = new JSONObject(); + params.put("token", token); + params.put("startTime", startTime); + params.put("endTime", endTime); + params.put("routeId", routeId); + params.put("pageIndex", pageIndex); + params.put("pageSize", pageSize); + String result = restTemplate.getForObject(patrolServerApiConfig.getApi().getAlarmList(), String.class, params); + log.info("获取报警列表返回值:{},参数:{}", result, params.toJSONString()); + if (StringUtils.isBlank(result)) { + log.error("获取报警列表失败,无返回值"); + throw new RuntimeException("获取报警列表失败,无返回值"); + } + JSONObject resultJson = JSONObject.parseObject(result); + JSONObject d = resultJson.getJSONObject("d"); + if (null == d) { + log.error("获取报警列表失败,返回值中无d字段"); + throw new RuntimeException("获取报警列表失败,返回值中无d字段"); + } + JSONArray data = d.getJSONArray("data"); + if (null == data) { + log.error("获取报警列表失败,返回值中无data字段"); + throw new RuntimeException("获取报警列表失败,返回值中无data字段"); + } + log.info("获取报警列表成功,线路列表:{}", data.toJSONString()); + return data; + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysService.java b/lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysService.java new file mode 100644 index 0000000..cb5b6c1 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysService.java @@ -0,0 +1,296 @@ +package com.lzbi.patrol.service; + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.lzbi.common.config.MessageSendConfig; +import com.lzbi.common.constant.BizConstants; +import com.lzbi.common.constant.CacheConstants; +import com.lzbi.common.core.domain.ElementTreeNode; +import com.lzbi.common.core.domain.message.MessageSendReq; +import com.lzbi.common.core.domain.entity.SysDept; +import com.lzbi.common.core.domain.entity.SysUser; +import com.lzbi.common.core.domain.message.PatrolMessageSendReq; +import com.lzbi.common.core.redis.RedisCache; +import com.lzbi.patrol.domain.DcBusiDeptPatrolRoute; +import com.lzbi.system.service.ISysDeptService; +import com.lzbi.system.service.ISysUserService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * 巡检系统业务 + */ +@Slf4j +@Service +public class PatrolSysService { + + @Autowired + private PatrolSysApiService patrolSysApiService; + + @Autowired + private DcBusiDeptPatrolRouteService dcBusiDeptPatrolRouteService; + + @Autowired + private ISysDeptService sysDeptService; + + @Autowired + private ISysUserService sysUserService; + + @Autowired + private ThreadPoolTaskExecutor threadPoolTaskExecutor; + + @Autowired + private MessageSendConfig messageSendConfig; + + @Autowired + private RedisCache redisCache; + + private final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + private final DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + /** + * 获取告警列表 + * + * @param startTime + * @param endTime + * @param pageIndex + * @param pageSize + * @return + */ + public Map> getAlarmList(String startTime, String endTime, Integer pageIndex, Integer pageSize) { + Map> map = new HashMap<>(); + JSONArray routeList = patrolSysApiService.getRouteList(); + if (CollectionUtils.isEmpty(routeList)) { + return new HashMap<>(); + } + LocalDateTime nowTime = LocalDateTime.now(); + if (StringUtils.isBlank(startTime)) { + startTime = nowTime.toLocalDate().format(dateFormat) + "00:00:00"; + } + if (StringUtils.isBlank(endTime)) { + endTime = nowTime.format(dateTimeFormat); + } + if (null == pageIndex) { + pageIndex = 1; + } + if (null == pageSize) { + pageSize = Integer.MAX_VALUE; + } + // 线路报警数量map + Map routeAlarmCountMap = new HashMap<>(); + // 获取告警列表 + for (Object route : routeList) { + JSONObject routeObj = (JSONObject) route; + Long routeId = routeObj.getLong("RouteID"); + // 获取线路的告警列表 + JSONArray alarmList = patrolSysApiService.getAlarmList(startTime, endTime, routeId, pageIndex, pageSize); + if (!CollectionUtils.isEmpty(alarmList)) { + // 过滤出漏检提醒类型的告警列表 + List missedReminderList = alarmList.stream().filter(item -> { + JSONObject alarm = ((JSONObject) item); + String alarmType = alarm.getString("AlarmType"); + if (BizConstants.PatrolAlarmType.MISSED_REMINDER.equals(alarmType)) { + return true; + } + return false; + }).collect(Collectors.toList()); + List list; + String routeIdStr = routeId.toString(); + if (map.containsKey(routeIdStr)) { + list = map.get(routeIdStr); + } else { + list= new ArrayList<>(); + } + missedReminderList.forEach(alarm -> list.add((JSONObject) alarm)); + map.put(routeIdStr, list); + if (routeAlarmCountMap.containsKey(routeId)) { + Integer count = routeAlarmCountMap.get(routeId); + count = count + missedReminderList.size(); + routeAlarmCountMap.put(routeId, count); + } else { + routeAlarmCountMap.put(routeId, missedReminderList.size()); + } + } + } + // 触发报警 + this.triggerAlarm(routeAlarmCountMap); + // 将告警列表添加到缓存 + redisCache.setCacheMap(CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ALARM_MAP, map); + return map; + } + + public List getAlarmListByRouteId(String routeId) { + String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ALARM_MAP; + List list = redisCache.getCacheMapValue(key, routeId); + if (CollectionUtils.isEmpty(list)) { + LocalDateTime nowTime = LocalDateTime.now(); + String startTime = nowTime.toLocalDate().format(dateFormat) + "00:00:00"; + String endTime = nowTime.format(dateTimeFormat); + int pageIndex = 1; + int pageSize = Integer.MAX_VALUE; + // 获取线路的告警列表 + JSONArray alarmList = patrolSysApiService.getAlarmList(startTime, endTime, Long.parseLong(routeId), pageIndex, pageSize); + list = alarmList.toJavaList(JSONObject.class); + redisCache.setCacheMapValue(key, routeId, list); + } + return list; + } + + /** + * 触发告警 + * @param routeAlarmCountMap + */ + public void triggerAlarm(Map routeAlarmCountMap) { + List messageSendReqList = this.buildPatrolAlarmMessage(routeAlarmCountMap); + if (!CollectionUtils.isEmpty(messageSendReqList)) { + messageSendReqList.forEach(messageSendReq -> threadPoolTaskExecutor.execute(() -> messageSendConfig.send(messageSendReq))); + } + } + + /** + * 构建巡检告警消息 + * @param routeAlarmCountMap + * @return + */ + private List buildPatrolAlarmMessage(Map routeAlarmCountMap) { + List list = new ArrayList<>(); + if (!CollectionUtils.isEmpty(routeAlarmCountMap)) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + LocalDateTime now = LocalDateTime.now(); + String time = now.format(dateTimeFormatter); + Set routeIdSet = routeAlarmCountMap.keySet(); + // 根据线路查询部门与线路关系表数据 + List dcBusiDeptPatrolRouteList = dcBusiDeptPatrolRouteService.list(new QueryWrapper().in("route_id", routeIdSet)); + if (CollectionUtils.isEmpty(dcBusiDeptPatrolRouteList)) { + log.error("巡检系统配置中的线路没有对应的部门,线路:{}", JSONArray.toJSONString(routeIdSet)); + } else { + // 按部门id分组 + Map> deptIdRouteIdGroupMap = dcBusiDeptPatrolRouteList.stream().collect(Collectors.groupingBy(DcBusiDeptPatrolRoute::getDeptId)); + // 获取部门id列表 + List deptIdList = dcBusiDeptPatrolRouteList.stream().map(DcBusiDeptPatrolRoute::getDeptId).collect(Collectors.toList()); + // 获取部门列表 + List deptList = sysDeptService.getDeptListByDeptIdList(deptIdList); + if (CollectionUtils.isEmpty(deptList)) { + log.error("巡检系统配置中的部门id不在系统中,部门:{}", JSONArray.toJSONString(deptList)); + } else { + // 部门id: 部门名称 + Map deptNameMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName)); + // 部门id: 部门层级 + Map deptAncestorsMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getAncestors)); + // 遍历部门id分组map,key: 部门id,value: 部门线路列表 + deptIdRouteIdGroupMap.forEach((deptId, deptRouteList) -> { + if (deptNameMap.containsKey(deptId)) { + // 报警部门的报警总数 + int sum = 0; + // 计算总数 + for (DcBusiDeptPatrolRoute dcBusiDeptPatrolRoute : deptRouteList) { + Long routeId = dcBusiDeptPatrolRoute.getRouteId(); + if (routeAlarmCountMap.containsKey(routeId)) { + Integer count = routeAlarmCountMap.get(routeId); + sum += count; + } + } + String ancestors = deptAncestorsMap.get(deptId); + // 拼接需要发送消息的部门 + String deptIds = ancestors + "," + deptId; + // 根据部门和巡检通知角色查询用户 + List sysUserList = sysUserService.selectUserListByDeptIdsStrAndRoleKey(deptIds, BizConstants.RoleKey.PATROL_NOTIFY); + if (CollectionUtils.isEmpty(sysUserList)) { + log.error("系统中未配置相关部门的巡检通知角色的用户,部门id:{}", deptId); + } else { + String deptName = deptNameMap.get(deptId); + List phoneList = sysUserList.stream().map(SysUser::getPhonenumber).collect(Collectors.toList()); + String content = deptName + "发生了 " + sum + " 次漏检告警"; + list.add(new PatrolMessageSendReq(content, time, phoneList)); + } + } + }); + } + } + } + return list; + } + + /** + * 获取线路树形结构 + * + * @return + */ + public List getRouteTree() { + String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ROUTE_TREE; + String routeTreeJsonStr = redisCache.getCacheObject(key); + if (StringUtils.isBlank(routeTreeJsonStr)) { + JSONArray routeList = patrolSysApiService.getRouteList(); + List elementTreeNodes = this.buildRouteTree(routeList); + redisCache.setCacheObject(key, JSONArray.toJSONString(elementTreeNodes), 30, TimeUnit.MINUTES); + return elementTreeNodes; + } else { + return JSONArray.parseArray(routeTreeJsonStr, ElementTreeNode.class); + } + } + + private List buildRouteTree(JSONArray routeList) { + if (CollectionUtils.isEmpty(routeList)) { + return new ArrayList<>(); + } + List list = new ArrayList<>(); + // 根节点线路id + Long rootRouteId = 0L; + // 获取根节点的下级节点 + for (int i = routeList.size() - 1; i > -1; i--) { + JSONObject route = routeList.getJSONObject(i); + Long routeId = route.getLong("ParentID"); + if (routeId.equals(rootRouteId)) { + routeList.remove(i); + list.add(this.buildRouteTreeNode(route)); + break; + } + } + if (!list.isEmpty()) { + for (ElementTreeNode elementTreeNode : list) { + this.recursionTransRouteTree(elementTreeNode, routeList); + } + } + return list; + } + + private void recursionTransRouteTree(ElementTreeNode parentMode, JSONArray routeList) { + if (null != parentMode && !CollectionUtils.isEmpty(routeList)) { + Long parentRouteId = (Long) parentMode.getValue(); + for (Object o : routeList) { + JSONObject route = (JSONObject) o; + Long routeParentId = route.getLong("ParentID"); + if (parentRouteId.equals(routeParentId)) { + ElementTreeNode elementTreeNode = this.buildRouteTreeNode(route); + parentMode.getChildren().add(elementTreeNode); + this.recursionTransRouteTree(elementTreeNode, routeList); + } + } + if (CollectionUtils.isEmpty(parentMode.getChildren())) { + parentMode.setLeaf(true); + } + } + } + + private ElementTreeNode buildRouteTreeNode(JSONObject route) { + if (null == route) { + return null; + } + ElementTreeNode node = new ElementTreeNode(); + node.setValue(route.getLong("RouteID")); + node.setLabel(route.getString("RouteName")); + node.setChildren(new ArrayList<>()); + return node; + } +} diff --git a/lzbi-module/src/main/resources/mapper/message/DcMessageTemplateMapper.xml b/lzbi-module/src/main/resources/mapper/message/DcMessageTemplateMapper.xml index 6fbb857..43b47a5 100644 --- a/lzbi-module/src/main/resources/mapper/message/DcMessageTemplateMapper.xml +++ b/lzbi-module/src/main/resources/mapper/message/DcMessageTemplateMapper.xml @@ -1,59 +1,63 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + - - - - + + + + + - select id, template_id, template_name, created_by, created_time, updated_by, updated_time, del_flag from dc_message_template + select id, template_id, template_name, system_type, created_by, created_time, updated_by, updated_time, del_flag from dc_message_template - + - + insert into dc_message_template id, template_id, template_name, - create_by, - create_time, - update_by, - update_time, + system_type, + created_by, + created_time, + updated_by, + updated_time, del_flag, - + #{id}, #{templateId}, #{templateName}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, + #{systemType}, + #{createdBy}, + #{createdTime}, + #{updatedBy}, + #{updatedTime}, #{delFlag}, - + @@ -61,10 +65,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" template_id = #{templateId}, template_name = #{templateName}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, + system_type = #{systemType}, + created_by = #{createdBy}, + created_time = #{createdTime}, + updated_by = #{updatedBy}, + updated_time = #{updatedTime}, del_flag = #{delFlag}, where id = #{id} @@ -75,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update dc_message_template set del_flag = '2' where id in + delete from dc_message_template where id in #{id} diff --git a/lzbi-module/src/main/resources/mapper/patrol/DcBusiDeptPatrolRouteMapper.xml b/lzbi-module/src/main/resources/mapper/patrol/DcBusiDeptPatrolRouteMapper.xml new file mode 100644 index 0000000..6e3a655 --- /dev/null +++ b/lzbi-module/src/main/resources/mapper/patrol/DcBusiDeptPatrolRouteMapper.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + select dept_id, route_id from dc_busi_dept_patrol_route + + + + + + + + insert into dc_busi_dept_patrol_route + + dept_id, + route_id, + + + #{deptId}, + #{routeId}, + + + + + update dc_busi_dept_patrol_route + + route_id = #{routeId}, + + where dept_id = #{deptId} + + + + delete from dc_busi_dept_patrol_route where dept_id = #{deptId} + + + + delete from dc_busi_dept_patrol_route where dept_id in + + #{deptId} + + + \ No newline at end of file diff --git a/lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java b/lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java index e08dc57..de0912a 100644 --- a/lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java +++ b/lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java @@ -122,4 +122,6 @@ public interface SysDeptMapper public HashMap selectDeptMap(); List selectDeptListByRoleIds(List ids); + + List getDeptListByDeptIdList(@Param("deptIdList") List deptIdList); } diff --git a/lzbi-system/src/main/java/com/lzbi/system/mapper/SysUserMapper.java b/lzbi-system/src/main/java/com/lzbi/system/mapper/SysUserMapper.java index 2616fc5..7e8f749 100644 --- a/lzbi-system/src/main/java/com/lzbi/system/mapper/SysUserMapper.java +++ b/lzbi-system/src/main/java/com/lzbi/system/mapper/SysUserMapper.java @@ -132,4 +132,7 @@ public interface SysUserMapper * @return 结果 */ public SysUser checkEmailUnique(String email); + + List selectUserListByDeptIdListAndRoleKey(@Param("deptIds") String[] deptIds, + @Param("roleKey") String roleKey); } diff --git a/lzbi-system/src/main/java/com/lzbi/system/service/ISysDeptService.java b/lzbi-system/src/main/java/com/lzbi/system/service/ISysDeptService.java index 36e974a..cbd3a32 100644 --- a/lzbi-system/src/main/java/com/lzbi/system/service/ISysDeptService.java +++ b/lzbi-system/src/main/java/com/lzbi/system/service/ISysDeptService.java @@ -22,6 +22,13 @@ public interface ISysDeptService List selecttList(SysDept dept); + /** + * 根据部门ID查询部门列表 + * @param deptIdList + * @return + */ + List getDeptListByDeptIdList(List deptIdList); + /** * 查询部门树结构信息 * diff --git a/lzbi-system/src/main/java/com/lzbi/system/service/ISysUserService.java b/lzbi-system/src/main/java/com/lzbi/system/service/ISysUserService.java index 5f6e14d..db6e631 100644 --- a/lzbi-system/src/main/java/com/lzbi/system/service/ISysUserService.java +++ b/lzbi-system/src/main/java/com/lzbi/system/service/ISysUserService.java @@ -34,6 +34,14 @@ public interface ISysUserService */ public List selectUnallocatedList(SysUser user); + /** + * 根据部门ids字符串和角色key查询用户列表 + * @param deptIdsStr + * @param roleKey + * @return + */ + List selectUserListByDeptIdsStrAndRoleKey(String deptIdsStr, String roleKey); + /** * 通过用户名查询用户 * diff --git a/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java b/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java index 098d8b0..f4f929d 100644 --- a/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java +++ b/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java @@ -27,10 +27,7 @@ import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -73,6 +70,11 @@ public class SysDeptServiceImpl implements ISysDeptService { return deptMapper.selectDeptList(dept); } + @Override + public List getDeptListByDeptIdList(List deptIdList) { + return deptMapper.getDeptListByDeptIdList(deptIdList); + } + /** * 查询部门树结构信息 * diff --git a/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java b/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java index 8d140b7..c27cb7e 100644 --- a/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java +++ b/lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java @@ -1,6 +1,9 @@ package com.lzbi.system.service.impl; +import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import javax.validation.Validator; @@ -117,6 +120,16 @@ public class SysUserServiceImpl implements ISysUserService return userMapper.selectUnallocatedList(user); } + @Override + public List selectUserListByDeptIdsStrAndRoleKey(String deptIdsStr, String roleKey) { + if (StringUtils.isBlank(deptIdsStr) || StringUtils.isBlank(roleKey)) { + log.error("deptIdsStr or roleKey is null"); + return new ArrayList<>(); + } + String[] deptIds = deptIdsStr.split(","); + return userMapper.selectUserListByDeptIdListAndRoleKey(deptIds, roleKey); + } + /** * 通过用户名查询用户 * diff --git a/lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml index c21e4f3..4380064 100644 --- a/lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -125,6 +125,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by d.parent_id, d.order_num + insert into sys_dept( diff --git a/lzbi-system/src/main/resources/mapper/system/SysUserMapper.xml b/lzbi-system/src/main/resources/mapper/system/SysUserMapper.xml index edcd364..e24923f 100644 --- a/lzbi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/lzbi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -4,6 +4,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> + + + + + + + + + + + + + + + + + + + + + @@ -146,6 +167,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + insert into sys_user(