Browse Source

1、巡检发消息功能

develop
bobol 7 months ago
parent
commit
e3ea45c5b8
  1. 42
      lzbi-admin/src/main/resources/application-dev.yml
  2. 58
      lzbi-admin/src/main/resources/application-prod.yml
  3. 26
      lzbi-admin/src/main/resources/application-test.yml
  4. 42
      lzbi-common/src/main/java/com/lzbi/common/config/MessageSendConfig.java
  5. 54
      lzbi-common/src/main/java/com/lzbi/common/config/PatrolServerApiConfig.java
  6. 51
      lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java
  7. 7
      lzbi-common/src/main/java/com/lzbi/common/constant/CacheConstants.java
  8. 70
      lzbi-common/src/main/java/com/lzbi/common/core/domain/ElementTreeNode.java
  9. 58
      lzbi-common/src/main/java/com/lzbi/common/core/domain/message/MessageSendReq.java
  10. 30
      lzbi-common/src/main/java/com/lzbi/common/core/domain/message/PatrolMessageSendReq.java
  11. 7
      lzbi-module/src/main/java/com/lzbi/message/domain/DcMessageTemplate.java
  12. 166
      lzbi-module/src/main/java/com/lzbi/patrol/controller/DcBusiDeptPatrolRouteController.java
  13. 60
      lzbi-module/src/main/java/com/lzbi/patrol/controller/PatrolSysController.java
  14. 29
      lzbi-module/src/main/java/com/lzbi/patrol/domain/DcBusiDeptPatrolRoute.java
  15. 63
      lzbi-module/src/main/java/com/lzbi/patrol/mapper/DcBusiDeptPatrolRouteMapper.java
  16. 112
      lzbi-module/src/main/java/com/lzbi/patrol/service/DcBusiDeptPatrolRouteService.java
  17. 181
      lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysApiService.java
  18. 296
      lzbi-module/src/main/java/com/lzbi/patrol/service/PatrolSysService.java
  19. 57
      lzbi-module/src/main/resources/mapper/message/DcMessageTemplateMapper.xml
  20. 57
      lzbi-module/src/main/resources/mapper/patrol/DcBusiDeptPatrolRouteMapper.xml
  21. 2
      lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java
  22. 3
      lzbi-system/src/main/java/com/lzbi/system/mapper/SysUserMapper.java
  23. 7
      lzbi-system/src/main/java/com/lzbi/system/service/ISysDeptService.java
  24. 8
      lzbi-system/src/main/java/com/lzbi/system/service/ISysUserService.java
  25. 10
      lzbi-system/src/main/java/com/lzbi/system/service/impl/SysDeptServiceImpl.java
  26. 13
      lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java
  27. 24
      lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml
  28. 53
      lzbi-system/src/main/resources/mapper/system/SysUserMapper.xml

42
lzbi-admin/src/main/resources/application-dev.yml

@ -148,30 +148,56 @@ wechat:
# 外部服务 # 外部服务
goal-server: goal-server:
# iot平台服务地址 # iot平台服务地址
iot: http://10.10.10.56:9010 iot: http://localhost:9010
magic: http://10.10.10.56:9012/magic/api 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: iot-server-api:
# 获取组织资产参数树形结构 # 获取组织资产参数树形结构
orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree orgAssetParamsTree: ${goal-server.iot}/biz/common/orgAssetParamsTree
# 获取组织资产参数树形结构 # 获取组织资产参数树形结构
paramsValue: ${goal-server.iot}/biz/common/paramsValue 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 api
magic-server-api: magic-server-api:
# 获取收费系统参数 # 获取收费系统参数
chargeSystemParams: ${goal-server.magic}/charge/sqaure 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

58
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} 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} 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

26
lzbi-admin/src/main/resources/application-test.yml

@ -148,6 +148,10 @@ goal-server:
# iot平台服务地址 # iot平台服务地址
iot: http://localhost:9010 iot: http://localhost:9010
magic: http://10.10.10.56:9012/magic/api 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服务接口
iot-server-api: iot-server-api:
@ -173,3 +177,25 @@ magic-server-api:
# 获取收费系统参数 # 获取收费系统参数
chargeSystemParams: ${goal-server.magic}/charge/sqaure 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

42
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<String> entity = new HttpEntity<>(bodyStr, headers);
String result = "";
try {
result = restTemplate.postForObject(this.url, entity, String.class);
} finally {
log.info("消息体:{},发送结果:{}", bodyStr, result);
}
}
}

54
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;
}
}

51
lzbi-common/src/main/java/com/lzbi/common/constant/BizConstants.java

@ -5,6 +5,57 @@ package com.lzbi.common.constant;
*/ */
public interface BizConstants { 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参数 * T指标P参数
*/ */

7
lzbi-common/src/main/java/com/lzbi/common/constant/CacheConstants.java

@ -41,4 +41,11 @@ public class CacheConstants
* 登录账户密码错误次数 redis key * 登录账户密码错误次数 redis key
*/ */
public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:"; 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:";
} }

70
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<ElementTreeNode> 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<ElementTreeNode> getChildren() {
return children;
}
public void setChildren(List<ElementTreeNode> children) {
this.children = children;
}
}

58
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<String> phoneList;
}

30
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<String> 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());
}
}

7
lzbi-module/src/main/java/com/lzbi/message/domain/DcMessageTemplate.java

@ -31,9 +31,12 @@ public class DcMessageTemplate extends BaseModuleEntity
@ApiModelProperty(name = "模板名称",notes = "templateName") @ApiModelProperty(name = "模板名称",notes = "templateName")
private String templateName; private String templateName;
/** 系统类型(1、IOT大数据平台) */
@Excel(name = "系统类型", readConverterExp = "1=、IOT大数据平台")
@ApiModelProperty(name = "系统类型",notes = "")
private String systemType;
/** 删除标志(0代表存在 2代表删除) */ /** 删除标志(0代表存在 2代表删除) */
private String delFlag; private String delFlag;
} }

166
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<DcBusiDeptPatrolRoute> list = dcBusiDeptPatrolRouteService.selectDcBusiDeptPatrolRouteList(DcBusiDeptPatrolRoute);
ExcelUtil<DcBusiDeptPatrolRoute> util = new ExcelUtil<DcBusiDeptPatrolRoute>(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<Long> 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));
}
}

60
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<Long, Integer> routeAlarmCountMap) {
patrolSysService.triggerAlarm(routeAlarmCountMap);
return AjaxResult.success();
}
}

29
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<DcBusiDeptPatrolRoute>
{
private static final long serialVersionUID = 1L;
/** 部门id */
private Long deptId;
/** 线路id */
private Long routeId;
}

63
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<DcBusiDeptPatrolRoute>
{
/**
* 查询部门与巡检系统线路关系
*
* @param deptId 部门与巡检系统线路关系主键
* @return 部门与巡检系统线路关系
*/
public DcBusiDeptPatrolRoute selectDcBusiDeptPatrolRouteByDeptId(Long deptId);
/**
* 查询部门与巡检系统线路关系列表
*
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系
* @return 部门与巡检系统线路关系集合
*/
public List<DcBusiDeptPatrolRoute> 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);
}

112
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<DcBusiDeptPatrolRouteMapper, DcBusiDeptPatrolRoute> implements IService<DcBusiDeptPatrolRoute>
{
/**
* 查询部门与巡检系统线路关系
*
* @param deptId 部门与巡检系统线路关系主键
* @return 部门与巡检系统线路关系
*/
public DcBusiDeptPatrolRoute selectDcBusiDeptPatrolRouteByDeptId(Long deptId)
{
return baseMapper.selectDcBusiDeptPatrolRouteByDeptId(deptId);
}
/**
* 查询部门与巡检系统线路关系列表
*
* @param dcBusiDeptPatrolRoute 部门与巡检系统线路关系
* @return 部门与巡检系统线路关系
*/
public List<DcBusiDeptPatrolRoute> 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<Long> getRouteIdList(Long deptId) {
QueryWrapper<DcBusiDeptPatrolRoute> wrapper = new QueryWrapper<>();
wrapper.eq("dept_id", deptId);
List<DcBusiDeptPatrolRoute> 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<Long> routeIdList) {
this.remove(new QueryWrapper<DcBusiDeptPatrolRoute>().eq("dept_id", deptId));
List<DcBusiDeptPatrolRoute> dcBusiDeptPatrolRouteList = routeIdList.stream().map(routeId -> new DcBusiDeptPatrolRoute(deptId, routeId)).collect(Collectors.toList());
return this.saveBatch(dcBusiDeptPatrolRouteList);
}
}

181
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<String, String> 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<String, String> 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<String, String> 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;
}
}

296
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<String, List<JSONObject>> getAlarmList(String startTime, String endTime, Integer pageIndex, Integer pageSize) {
Map<String, List<JSONObject>> 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<Long, Integer> 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<Object> 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<JSONObject> 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<JSONObject> getAlarmListByRouteId(String routeId) {
String key = CacheConstants.PATROL_SYS_BASE + CacheConstants.PATROL_SYS_ALARM_MAP;
List<JSONObject> 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<Long, Integer> routeAlarmCountMap) {
List<MessageSendReq> messageSendReqList = this.buildPatrolAlarmMessage(routeAlarmCountMap);
if (!CollectionUtils.isEmpty(messageSendReqList)) {
messageSendReqList.forEach(messageSendReq -> threadPoolTaskExecutor.execute(() -> messageSendConfig.send(messageSendReq)));
}
}
/**
* 构建巡检告警消息
* @param routeAlarmCountMap
* @return
*/
private List<MessageSendReq> buildPatrolAlarmMessage(Map<Long, Integer> routeAlarmCountMap) {
List<MessageSendReq> 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<Long> routeIdSet = routeAlarmCountMap.keySet();
// 根据线路查询部门与线路关系表数据
List<DcBusiDeptPatrolRoute> dcBusiDeptPatrolRouteList = dcBusiDeptPatrolRouteService.list(new QueryWrapper<DcBusiDeptPatrolRoute>().in("route_id", routeIdSet));
if (CollectionUtils.isEmpty(dcBusiDeptPatrolRouteList)) {
log.error("巡检系统配置中的线路没有对应的部门,线路:{}", JSONArray.toJSONString(routeIdSet));
} else {
// 按部门id分组
Map<Long, List<DcBusiDeptPatrolRoute>> deptIdRouteIdGroupMap = dcBusiDeptPatrolRouteList.stream().collect(Collectors.groupingBy(DcBusiDeptPatrolRoute::getDeptId));
// 获取部门id列表
List<Long> deptIdList = dcBusiDeptPatrolRouteList.stream().map(DcBusiDeptPatrolRoute::getDeptId).collect(Collectors.toList());
// 获取部门列表
List<SysDept> deptList = sysDeptService.getDeptListByDeptIdList(deptIdList);
if (CollectionUtils.isEmpty(deptList)) {
log.error("巡检系统配置中的部门id不在系统中,部门:{}", JSONArray.toJSONString(deptList));
} else {
// 部门id: 部门名称
Map<Long, String> deptNameMap = deptList.stream().collect(Collectors.toMap(SysDept::getDeptId, SysDept::getDeptName));
// 部门id: 部门层级
Map<Long, String> 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<SysUser> sysUserList = sysUserService.selectUserListByDeptIdsStrAndRoleKey(deptIds, BizConstants.RoleKey.PATROL_NOTIFY);
if (CollectionUtils.isEmpty(sysUserList)) {
log.error("系统中未配置相关部门的巡检通知角色的用户,部门id:{}", deptId);
} else {
String deptName = deptNameMap.get(deptId);
List<String> 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<ElementTreeNode> 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<ElementTreeNode> elementTreeNodes = this.buildRouteTree(routeList);
redisCache.setCacheObject(key, JSONArray.toJSONString(elementTreeNodes), 30, TimeUnit.MINUTES);
return elementTreeNodes;
} else {
return JSONArray.parseArray(routeTreeJsonStr, ElementTreeNode.class);
}
}
private List<ElementTreeNode> buildRouteTree(JSONArray routeList) {
if (CollectionUtils.isEmpty(routeList)) {
return new ArrayList<>();
}
List<ElementTreeNode> 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;
}
}

57
lzbi-module/src/main/resources/mapper/message/DcMessageTemplateMapper.xml

@ -1,59 +1,63 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lzbi.message.mapper.DcMessageTemplateMapper"> <mapper namespace="com.lzbi.message.mapper.DcMessageTemplateMapper">
<resultMap type="com.lzbi.message.domain.DcMessageTemplate" id="DcMessageTemplateResult"> <resultMap type="com.lzbi.message.domain.DcMessageTemplate" id="DcMessageTemplateResult">
<result property="id" column="id" /> <result property="id" column="id" />
<result property="templateId" column="template_id" /> <result property="templateId" column="template_id" />
<result property="templateName" column="template_name" /> <result property="templateName" column="template_name" />
<result property="createdBy" column="create_by" /> <result property="systemType" column="system_type" />
<result property="createdTime" column="create_time" /> <result property="createdBy" column="created_by" />
<result property="updatedBy" column="update_by" /> <result property="createdTime" column="created_time" />
<result property="updatedTime" column="update_time" /> <result property="updatedBy" column="updated_by" />
<result property="updatedTime" column="updated_time" />
<result property="delFlag" column="del_flag" /> <result property="delFlag" column="del_flag" />
</resultMap> </resultMap>
<sql id="selectDcMessageTemplateVo"> <sql id="selectDcMessageTemplateVo">
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
</sql> </sql>
<select id="selectDcMessageTemplateList" parameterType="DcMessageTemplate" resultMap="DcMessageTemplateResult"> <select id="selectDcMessageTemplateList" parameterType="DcMessageTemplate" resultMap="DcMessageTemplateResult">
<include refid="selectDcMessageTemplateVo"/> <include refid="selectDcMessageTemplateVo"/>
<where> <where>
<if test="templateId != null and templateId != ''"> and template_id = #{templateId}</if> <if test="templateId != null and templateId != ''"> and template_id = #{templateId}</if>
<if test="templateName != null and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if> <if test="templateName != null and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if>
<if test="systemType != null and systemType != ''"> and system_type = #{systemType}</if>
</where> </where>
</select> </select>
<select id="selectDcMessageTemplateById" parameterType="Long" resultMap="DcMessageTemplateResult"> <select id="selectDcMessageTemplateById" parameterType="Long" resultMap="DcMessageTemplateResult">
<include refid="selectDcMessageTemplateVo"/> <include refid="selectDcMessageTemplateVo"/>
where id = #{id} where id = #{id}
</select> </select>
<insert id="insertDcMessageTemplate" parameterType="DcMessageTemplate"> <insert id="insertDcMessageTemplate" parameterType="DcMessageTemplate">
insert into dc_message_template insert into dc_message_template
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if> <if test="id != null">id,</if>
<if test="templateId != null and templateId != ''">template_id,</if> <if test="templateId != null and templateId != ''">template_id,</if>
<if test="templateName != null and templateName != ''">template_name,</if> <if test="templateName != null and templateName != ''">template_name,</if>
<if test="createdBy != null">create_by,</if> <if test="systemType != null and systemType != ''">system_type,</if>
<if test="createdTime != null">create_time,</if> <if test="createdBy != null">created_by,</if>
<if test="updatedBy != null">update_by,</if> <if test="createdTime != null">created_time,</if>
<if test="updatedTime != null">update_time,</if> <if test="updatedBy != null">updated_by,</if>
<if test="updatedTime != null">updated_time,</if>
<if test="delFlag != null">del_flag,</if> <if test="delFlag != null">del_flag,</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if> <if test="id != null">#{id},</if>
<if test="templateId != null and templateId != ''">#{templateId},</if> <if test="templateId != null and templateId != ''">#{templateId},</if>
<if test="templateName != null and templateName != ''">#{templateName},</if> <if test="templateName != null and templateName != ''">#{templateName},</if>
<if test="createdBy != null">#{createBy},</if> <if test="systemType != null and systemType != ''">#{systemType},</if>
<if test="createdTime != null">#{createTime},</if> <if test="createdBy != null">#{createdBy},</if>
<if test="updatedBy != null">#{updateBy},</if> <if test="createdTime != null">#{createdTime},</if>
<if test="updatedTime != null">#{updateTime},</if> <if test="updatedBy != null">#{updatedBy},</if>
<if test="updatedTime != null">#{updatedTime},</if>
<if test="delFlag != null">#{delFlag},</if> <if test="delFlag != null">#{delFlag},</if>
</trim> </trim>
</insert> </insert>
<update id="updateDcMessageTemplate" parameterType="DcMessageTemplate"> <update id="updateDcMessageTemplate" parameterType="DcMessageTemplate">
@ -61,10 +65,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<trim prefix="SET" suffixOverrides=","> <trim prefix="SET" suffixOverrides=",">
<if test="templateId != null and templateId != ''">template_id = #{templateId},</if> <if test="templateId != null and templateId != ''">template_id = #{templateId},</if>
<if test="templateName != null and templateName != ''">template_name = #{templateName},</if> <if test="templateName != null and templateName != ''">template_name = #{templateName},</if>
<if test="createdBy != null">create_by = #{createBy},</if> <if test="systemType != null and systemType != ''">system_type = #{systemType},</if>
<if test="createdTime != null">create_time = #{createTime},</if> <if test="createdBy != null">created_by = #{createdBy},</if>
<if test="updatedBy != null">update_by = #{updateBy},</if> <if test="createdTime != null">created_time = #{createdTime},</if>
<if test="updatedTime != null">update_time = #{updateTime},</if> <if test="updatedBy != null">updated_by = #{updatedBy},</if>
<if test="updatedTime != null">updated_time = #{updatedTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if> <if test="delFlag != null">del_flag = #{delFlag},</if>
</trim> </trim>
where id = #{id} where id = #{id}
@ -75,7 +80,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete> </delete>
<delete id="deleteDcMessageTemplateByIds" parameterType="String"> <delete id="deleteDcMessageTemplateByIds" parameterType="String">
update dc_message_template set del_flag = '2' where id in delete from dc_message_template where id in
<foreach item="id" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">
#{id} #{id}
</foreach> </foreach>

57
lzbi-module/src/main/resources/mapper/patrol/DcBusiDeptPatrolRouteMapper.xml

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lzbi.patrol.mapper.DcBusiDeptPatrolRouteMapper">
<resultMap type="com.lzbi.patrol.domain.DcBusiDeptPatrolRoute" id="DcBusiDeptPatrolRouteResult">
<result property="deptId" column="dept_id" />
<result property="routeId" column="route_id" />
</resultMap>
<sql id="selectDcBusiDeptPatrolRouteVo">
select dept_id, route_id from dc_busi_dept_patrol_route
</sql>
<select id="selectDcBusiDeptPatrolRouteList" parameterType="DcBusiDeptPatrolRoute" resultMap="DcBusiDeptPatrolRouteResult">
<include refid="selectDcBusiDeptPatrolRouteVo"/>
<where>
</where>
</select>
<select id="selectDcBusiDeptPatrolRouteByDeptId" parameterType="Long" resultMap="DcBusiDeptPatrolRouteResult">
<include refid="selectDcBusiDeptPatrolRouteVo"/>
where dept_id = #{deptId}
</select>
<insert id="insertDcBusiDeptPatrolRoute" parameterType="DcBusiDeptPatrolRoute">
insert into dc_busi_dept_patrol_route
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="deptId != null">dept_id,</if>
<if test="routeId != null">route_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="deptId != null">#{deptId},</if>
<if test="routeId != null">#{routeId},</if>
</trim>
</insert>
<update id="updateDcBusiDeptPatrolRoute" parameterType="DcBusiDeptPatrolRoute">
update dc_busi_dept_patrol_route
<trim prefix="SET" suffixOverrides=",">
<if test="routeId != null">route_id = #{routeId},</if>
</trim>
where dept_id = #{deptId}
</update>
<delete id="deleteDcBusiDeptPatrolRouteByDeptId" parameterType="Long">
delete from dc_busi_dept_patrol_route where dept_id = #{deptId}
</delete>
<delete id="deleteDcBusiDeptPatrolRouteByDeptIds" parameterType="String">
delete from dc_busi_dept_patrol_route where dept_id in
<foreach item="deptId" collection="array" open="(" separator="," close=")">
#{deptId}
</foreach>
</delete>
</mapper>

2
lzbi-system/src/main/java/com/lzbi/system/mapper/SysDeptMapper.java

@ -122,4 +122,6 @@ public interface SysDeptMapper
public HashMap<Long,String> selectDeptMap(); public HashMap<Long,String> selectDeptMap();
List<SysDept> selectDeptListByRoleIds(List<Long> ids); List<SysDept> selectDeptListByRoleIds(List<Long> ids);
List<SysDept> getDeptListByDeptIdList(@Param("deptIdList") List<Long> deptIdList);
} }

3
lzbi-system/src/main/java/com/lzbi/system/mapper/SysUserMapper.java

@ -132,4 +132,7 @@ public interface SysUserMapper
* @return 结果 * @return 结果
*/ */
public SysUser checkEmailUnique(String email); public SysUser checkEmailUnique(String email);
List<SysUser> selectUserListByDeptIdListAndRoleKey(@Param("deptIds") String[] deptIds,
@Param("roleKey") String roleKey);
} }

7
lzbi-system/src/main/java/com/lzbi/system/service/ISysDeptService.java

@ -22,6 +22,13 @@ public interface ISysDeptService
List<SysDept> selecttList(SysDept dept); List<SysDept> selecttList(SysDept dept);
/**
* 根据部门ID查询部门列表
* @param deptIdList
* @return
*/
List<SysDept> getDeptListByDeptIdList(List<Long> deptIdList);
/** /**
* 查询部门树结构信息 * 查询部门树结构信息
* *

8
lzbi-system/src/main/java/com/lzbi/system/service/ISysUserService.java

@ -34,6 +34,14 @@ public interface ISysUserService
*/ */
public List<SysUser> selectUnallocatedList(SysUser user); public List<SysUser> selectUnallocatedList(SysUser user);
/**
* 根据部门ids字符串和角色key查询用户列表
* @param deptIdsStr
* @param roleKey
* @return
*/
List<SysUser> selectUserListByDeptIdsStrAndRoleKey(String deptIdsStr, String roleKey);
/** /**
* 通过用户名查询用户 * 通过用户名查询用户
* *

10
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.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -73,6 +70,11 @@ public class SysDeptServiceImpl implements ISysDeptService {
return deptMapper.selectDeptList(dept); return deptMapper.selectDeptList(dept);
} }
@Override
public List<SysDept> getDeptListByDeptIdList(List<Long> deptIdList) {
return deptMapper.getDeptListByDeptIdList(deptIdList);
}
/** /**
* 查询部门树结构信息 * 查询部门树结构信息
* *

13
lzbi-system/src/main/java/com/lzbi/system/service/impl/SysUserServiceImpl.java

@ -1,6 +1,9 @@
package com.lzbi.system.service.impl; package com.lzbi.system.service.impl;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.validation.Validator; import javax.validation.Validator;
@ -117,6 +120,16 @@ public class SysUserServiceImpl implements ISysUserService
return userMapper.selectUnallocatedList(user); return userMapper.selectUnallocatedList(user);
} }
@Override
public List<SysUser> 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);
}
/** /**
* 通过用户名查询用户 * 通过用户名查询用户
* *

24
lzbi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@ -125,6 +125,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach> </foreach>
order by d.parent_id, d.order_num order by d.parent_id, d.order_num
</select> </select>
<select id="getDeptListByDeptIdList" resultMap="SysDeptResult">
select
dept_id,
parent_id,
ancestors,
dept_name,
order_num,
leader,
phone,
email,
status,
del_flag,
create_by,
create_time,
update_by,
update_time,
all_name,
short_name,
org_type
from sys_dept where dept_id in
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
</select>
<insert id="insertDept" parameterType="SysDept"> <insert id="insertDept" parameterType="SysDept">
insert into sys_dept( insert into sys_dept(

53
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"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lzbi.system.mapper.SysUserMapper"> <mapper namespace="com.lzbi.system.mapper.SysUserMapper">
<resultMap type="SysUser" id="UserResult">
<id property="userId" column="user_id" />
<result property="deptId" column="dept_id" />
<result property="userName" column="user_name" />
<result property="nickName" column="nick_name" />
<result property="email" column="email" />
<result property="phonenumber" column="phonenumber" />
<result property="sex" column="sex" />
<result property="avatar" column="avatar" />
<result property="password" column="password" />
<result property="status" column="status" />
<result property="delFlag" column="del_flag" />
<result property="loginIp" column="login_ip" />
<result property="loginDate" column="login_date" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<resultMap type="SysUser" id="SysUserResult"> <resultMap type="SysUser" id="SysUserResult">
<id property="userId" column="user_id" /> <id property="userId" column="user_id" />
<result property="deptId" column="dept_id" /> <result property="deptId" column="dept_id" />
@ -146,6 +167,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult"> <select id="checkEmailUnique" parameterType="String" resultMap="SysUserResult">
select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1 select user_id, email from sys_user where email = #{email} and del_flag = '0' limit 1
</select> </select>
<select id="selectUserListByDeptIdListAndRoleKey" resultMap="UserResult">
SELECT
t1.user_id,
t1.dept_id,
t1.user_name,
t1.nick_name,
t1.user_type,
t1.email,
t1.phonenumber,
t1.sex,
t1.avatar,
t1.password,
t1.status,
t1.del_flag,
t1.login_ip,
t1.login_date,
t1.create_by,
t1.create_time,
t1.update_by,
t1.update_time,
t1.remark
FROM
sys_user t1
inner join sys_user_role t2 on t1.user_id = t2.user_id
inner join sys_role t3 on t2.role_id = t3.role_id
where
t1.dept_id in
<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
#{deptId, jdbcType=BIGINT}
</foreach>
and t3.role_key = #{roleKey}
</select>
<insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId"> <insert id="insertUser" parameterType="SysUser" useGeneratedKeys="true" keyProperty="userId">
insert into sys_user( insert into sys_user(

Loading…
Cancel
Save