diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/src/main/java/com/casic/util/RedisCommon.java b/src/main/java/com/casic/util/RedisCommon.java new file mode 100644 index 0000000..617d73b --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommon.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommon { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/src/main/java/com/casic/util/RedisCommon.java b/src/main/java/com/casic/util/RedisCommon.java new file mode 100644 index 0000000..617d73b --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommon.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommon { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java deleted file mode 100644 index a6ce9cf..0000000 --- a/src/main/java/com/casic/util/RedisCommonUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.casic.util; - -import com.alibaba.fastjson.JSON; -import com.casic.model.CommConfigDTO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class RedisCommonUtil { - - @Value("${casic.device.redis.invalid-time}") - private String invalidTime; - @Value("${casic.device.redis.config-prefix}") - private String configPrefix; - - @Autowired - private RedisTemplate redisTemplate; - - public void send(CommConfigDTO commConfigDTO,String devCode) { - redisTemplate.opsForValue().set(configPrefix+ devCode, - JSON.toJSONString(commConfigDTO), - Integer.valueOf(invalidTime), - TimeUnit.SECONDS); - } -} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/src/main/java/com/casic/util/RedisCommon.java b/src/main/java/com/casic/util/RedisCommon.java new file mode 100644 index 0000000..617d73b --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommon.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommon { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java deleted file mode 100644 index a6ce9cf..0000000 --- a/src/main/java/com/casic/util/RedisCommonUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.casic.util; - -import com.alibaba.fastjson.JSON; -import com.casic.model.CommConfigDTO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class RedisCommonUtil { - - @Value("${casic.device.redis.invalid-time}") - private String invalidTime; - @Value("${casic.device.redis.config-prefix}") - private String configPrefix; - - @Autowired - private RedisTemplate redisTemplate; - - public void send(CommConfigDTO commConfigDTO,String devCode) { - redisTemplate.opsForValue().set(configPrefix+ devCode, - JSON.toJSONString(commConfigDTO), - Integer.valueOf(invalidTime), - TimeUnit.SECONDS); - } -} diff --git a/src/main/java/com/casic/util/SendBatchSmsUtil.java b/src/main/java/com/casic/util/SendBatchSmsUtil.java new file mode 100644 index 0000000..ed043a4 --- /dev/null +++ b/src/main/java/com/casic/util/SendBatchSmsUtil.java @@ -0,0 +1,89 @@ +package com.casic.util; +// This file is auto-generated, don't edit it. Thanks. + +import com.aliyun.auth.credentials.Credential; +import com.aliyun.auth.credentials.provider.StaticCredentialProvider; +import com.aliyun.sdk.service.dysmsapi20170525.models.*; +import com.aliyun.sdk.service.dysmsapi20170525.*; +import com.casic.config.AliYunConfig; +import com.google.gson.Gson; +import darabonba.core.client.ClientOverrideConfiguration; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +@AllArgsConstructor +@Component +@Slf4j +public class SendBatchSmsUtil { + + private AliYunConfig aliYunConfig; + + public void sendMsg(String phoneJson, String msgJson) { + StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() + .accessKeyId(aliYunConfig.getKey()) + .accessKeySecret(aliYunConfig.getScrect()) + .build()); + + AsyncClient client = AsyncClient.builder() + .region("cn-shanghai") // Region ID + .credentialsProvider(provider) + .overrideConfiguration( + ClientOverrideConfiguration.create() + .setEndpointOverride(aliYunConfig.getUrl()) + ) + .build(); + + SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() + .phoneNumberJson(phoneJson) + .signNameJson(aliYunConfig.getSignNameJson()) + .templateCode(aliYunConfig.getTemplateCode()) + .templateParamJson(msgJson) + .build(); + + CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); + try { + SendBatchSmsResponse resp = response.get(); + System.out.println(new Gson().toJson(resp)); + } catch (Exception ex) { + log.error("发送消息出现异常,手机号内容为{},信息内容为{}",phoneJson,msgJson,ex.getMessage()); + }finally { + client.close(); + } + } + + +// public static void main(String [] args) throws Exception { +// +// StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() +// .accessKeyId("LTAI5tDFNucQF2Bdy4fHgzrN") +// .accessKeySecret("hZ22QQPxQue1G0R8Ty2bo6GimrLdoB") +// .build()); +// +// AsyncClient client = AsyncClient.builder() +// .region("cn-shanghai") // Region ID +// .credentialsProvider(provider) +// .overrideConfiguration( +// ClientOverrideConfiguration.create() +// .setEndpointOverride("dysmsapi.aliyuncs.com") +// ) +// .build(); +// +// SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() +// .phoneNumberJson("[\"13651065090\"]") +// .signNameJson("[\"阿里云短信测试\"]") +// .templateCode("SMS_154950909") +// .templateParamJson("[{\"code\":\"123456\"}]") +// // Request-level configuration rewrite, can set Http request parameters, etc. +// // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) +// .build(); +// +// CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); +// SendBatchSmsResponse resp = response.get(); +// System.out.println(new Gson().toJson(resp)); +// client.close(); +// } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/src/main/java/com/casic/util/RedisCommon.java b/src/main/java/com/casic/util/RedisCommon.java new file mode 100644 index 0000000..617d73b --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommon.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommon { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java deleted file mode 100644 index a6ce9cf..0000000 --- a/src/main/java/com/casic/util/RedisCommonUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.casic.util; - -import com.alibaba.fastjson.JSON; -import com.casic.model.CommConfigDTO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class RedisCommonUtil { - - @Value("${casic.device.redis.invalid-time}") - private String invalidTime; - @Value("${casic.device.redis.config-prefix}") - private String configPrefix; - - @Autowired - private RedisTemplate redisTemplate; - - public void send(CommConfigDTO commConfigDTO,String devCode) { - redisTemplate.opsForValue().set(configPrefix+ devCode, - JSON.toJSONString(commConfigDTO), - Integer.valueOf(invalidTime), - TimeUnit.SECONDS); - } -} diff --git a/src/main/java/com/casic/util/SendBatchSmsUtil.java b/src/main/java/com/casic/util/SendBatchSmsUtil.java new file mode 100644 index 0000000..ed043a4 --- /dev/null +++ b/src/main/java/com/casic/util/SendBatchSmsUtil.java @@ -0,0 +1,89 @@ +package com.casic.util; +// This file is auto-generated, don't edit it. Thanks. + +import com.aliyun.auth.credentials.Credential; +import com.aliyun.auth.credentials.provider.StaticCredentialProvider; +import com.aliyun.sdk.service.dysmsapi20170525.models.*; +import com.aliyun.sdk.service.dysmsapi20170525.*; +import com.casic.config.AliYunConfig; +import com.google.gson.Gson; +import darabonba.core.client.ClientOverrideConfiguration; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +@AllArgsConstructor +@Component +@Slf4j +public class SendBatchSmsUtil { + + private AliYunConfig aliYunConfig; + + public void sendMsg(String phoneJson, String msgJson) { + StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() + .accessKeyId(aliYunConfig.getKey()) + .accessKeySecret(aliYunConfig.getScrect()) + .build()); + + AsyncClient client = AsyncClient.builder() + .region("cn-shanghai") // Region ID + .credentialsProvider(provider) + .overrideConfiguration( + ClientOverrideConfiguration.create() + .setEndpointOverride(aliYunConfig.getUrl()) + ) + .build(); + + SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() + .phoneNumberJson(phoneJson) + .signNameJson(aliYunConfig.getSignNameJson()) + .templateCode(aliYunConfig.getTemplateCode()) + .templateParamJson(msgJson) + .build(); + + CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); + try { + SendBatchSmsResponse resp = response.get(); + System.out.println(new Gson().toJson(resp)); + } catch (Exception ex) { + log.error("发送消息出现异常,手机号内容为{},信息内容为{}",phoneJson,msgJson,ex.getMessage()); + }finally { + client.close(); + } + } + + +// public static void main(String [] args) throws Exception { +// +// StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() +// .accessKeyId("LTAI5tDFNucQF2Bdy4fHgzrN") +// .accessKeySecret("hZ22QQPxQue1G0R8Ty2bo6GimrLdoB") +// .build()); +// +// AsyncClient client = AsyncClient.builder() +// .region("cn-shanghai") // Region ID +// .credentialsProvider(provider) +// .overrideConfiguration( +// ClientOverrideConfiguration.create() +// .setEndpointOverride("dysmsapi.aliyuncs.com") +// ) +// .build(); +// +// SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() +// .phoneNumberJson("[\"13651065090\"]") +// .signNameJson("[\"阿里云短信测试\"]") +// .templateCode("SMS_154950909") +// .templateParamJson("[{\"code\":\"123456\"}]") +// // Request-level configuration rewrite, can set Http request parameters, etc. +// // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) +// .build(); +// +// CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); +// SendBatchSmsResponse resp = response.get(); +// System.out.println(new Gson().toJson(resp)); +// client.close(); +// } + +} \ No newline at end of file diff --git a/src/main/java/com/casic/util/WebSocket.java b/src/main/java/com/casic/util/WebSocket.java new file mode 100644 index 0000000..1ee283f --- /dev/null +++ b/src/main/java/com/casic/util/WebSocket.java @@ -0,0 +1,103 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArraySet; + +/** + * 此注解相当于设置访问URL + */ +@Component +@ServerEndpoint("/websocket/{userId}") +public class WebSocket { + private Session session; + + private static CopyOnWriteArraySet webSockets = new CopyOnWriteArraySet<>(); + private static Map sessionPool = new HashMap(); + + @OnOpen + public void onOpen(Session session, @PathParam(value = "userId") String userId) { + this.session = session; + webSockets.add(this); + sessionPool.put(userId, session); + System.out.println(userId + "【websocket消息】有新的连接,总数为:" + webSockets.size()); + } + + @OnClose + public void onClose() { + webSockets.remove(this); + System.out.println("【websocket消息】连接断开,总数为:" + webSockets.size()); + } + + @OnMessage + public void onMessage(String message) { + System.out.println("【websocket消息】收到客户端消息:" + message); + } + + // 此为广播消息 + public void sendAllMessage(String message) { + for (WebSocket webSocket : webSockets) { + System.out.println("【websocket消息】广播消息:" + message); + try { + webSocket.session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + // 发送列表消息 + public void sendListMessage(List userIds, String message) { + System.out.println("【websocket消息】列表消息:" + message); + for (String userId : userIds) { + Session session = sessionPool.get(userId); + if (session != null) { + try { + session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + // 发送列表消息 + +// public void sendListMessage(List userIds, Object data){ +// System.out.println("【websocket消息】列表消息:"+data); +// for (String userId : userIds) { +// Session session = sessionPool.get(userId); +// if (session != null) { +// try { +//// session.getAsyncRemote().sendText(message); +// session.getAsyncRemote().sendObject(data); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// } + + // 此为单点消息 + public void sendOneMessage(String userId, String message) { + System.out.println("【websocket消息】单点消息:" + message); + Session session = sessionPool.get(userId); + if (session != null) { + try { + session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +} diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/src/main/java/com/casic/util/RedisCommon.java b/src/main/java/com/casic/util/RedisCommon.java new file mode 100644 index 0000000..617d73b --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommon.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommon { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java deleted file mode 100644 index a6ce9cf..0000000 --- a/src/main/java/com/casic/util/RedisCommonUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.casic.util; - -import com.alibaba.fastjson.JSON; -import com.casic.model.CommConfigDTO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class RedisCommonUtil { - - @Value("${casic.device.redis.invalid-time}") - private String invalidTime; - @Value("${casic.device.redis.config-prefix}") - private String configPrefix; - - @Autowired - private RedisTemplate redisTemplate; - - public void send(CommConfigDTO commConfigDTO,String devCode) { - redisTemplate.opsForValue().set(configPrefix+ devCode, - JSON.toJSONString(commConfigDTO), - Integer.valueOf(invalidTime), - TimeUnit.SECONDS); - } -} diff --git a/src/main/java/com/casic/util/SendBatchSmsUtil.java b/src/main/java/com/casic/util/SendBatchSmsUtil.java new file mode 100644 index 0000000..ed043a4 --- /dev/null +++ b/src/main/java/com/casic/util/SendBatchSmsUtil.java @@ -0,0 +1,89 @@ +package com.casic.util; +// This file is auto-generated, don't edit it. Thanks. + +import com.aliyun.auth.credentials.Credential; +import com.aliyun.auth.credentials.provider.StaticCredentialProvider; +import com.aliyun.sdk.service.dysmsapi20170525.models.*; +import com.aliyun.sdk.service.dysmsapi20170525.*; +import com.casic.config.AliYunConfig; +import com.google.gson.Gson; +import darabonba.core.client.ClientOverrideConfiguration; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +@AllArgsConstructor +@Component +@Slf4j +public class SendBatchSmsUtil { + + private AliYunConfig aliYunConfig; + + public void sendMsg(String phoneJson, String msgJson) { + StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() + .accessKeyId(aliYunConfig.getKey()) + .accessKeySecret(aliYunConfig.getScrect()) + .build()); + + AsyncClient client = AsyncClient.builder() + .region("cn-shanghai") // Region ID + .credentialsProvider(provider) + .overrideConfiguration( + ClientOverrideConfiguration.create() + .setEndpointOverride(aliYunConfig.getUrl()) + ) + .build(); + + SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() + .phoneNumberJson(phoneJson) + .signNameJson(aliYunConfig.getSignNameJson()) + .templateCode(aliYunConfig.getTemplateCode()) + .templateParamJson(msgJson) + .build(); + + CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); + try { + SendBatchSmsResponse resp = response.get(); + System.out.println(new Gson().toJson(resp)); + } catch (Exception ex) { + log.error("发送消息出现异常,手机号内容为{},信息内容为{}",phoneJson,msgJson,ex.getMessage()); + }finally { + client.close(); + } + } + + +// public static void main(String [] args) throws Exception { +// +// StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() +// .accessKeyId("LTAI5tDFNucQF2Bdy4fHgzrN") +// .accessKeySecret("hZ22QQPxQue1G0R8Ty2bo6GimrLdoB") +// .build()); +// +// AsyncClient client = AsyncClient.builder() +// .region("cn-shanghai") // Region ID +// .credentialsProvider(provider) +// .overrideConfiguration( +// ClientOverrideConfiguration.create() +// .setEndpointOverride("dysmsapi.aliyuncs.com") +// ) +// .build(); +// +// SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() +// .phoneNumberJson("[\"13651065090\"]") +// .signNameJson("[\"阿里云短信测试\"]") +// .templateCode("SMS_154950909") +// .templateParamJson("[{\"code\":\"123456\"}]") +// // Request-level configuration rewrite, can set Http request parameters, etc. +// // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) +// .build(); +// +// CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); +// SendBatchSmsResponse resp = response.get(); +// System.out.println(new Gson().toJson(resp)); +// client.close(); +// } + +} \ No newline at end of file diff --git a/src/main/java/com/casic/util/WebSocket.java b/src/main/java/com/casic/util/WebSocket.java new file mode 100644 index 0000000..1ee283f --- /dev/null +++ b/src/main/java/com/casic/util/WebSocket.java @@ -0,0 +1,103 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArraySet; + +/** + * 此注解相当于设置访问URL + */ +@Component +@ServerEndpoint("/websocket/{userId}") +public class WebSocket { + private Session session; + + private static CopyOnWriteArraySet webSockets = new CopyOnWriteArraySet<>(); + private static Map sessionPool = new HashMap(); + + @OnOpen + public void onOpen(Session session, @PathParam(value = "userId") String userId) { + this.session = session; + webSockets.add(this); + sessionPool.put(userId, session); + System.out.println(userId + "【websocket消息】有新的连接,总数为:" + webSockets.size()); + } + + @OnClose + public void onClose() { + webSockets.remove(this); + System.out.println("【websocket消息】连接断开,总数为:" + webSockets.size()); + } + + @OnMessage + public void onMessage(String message) { + System.out.println("【websocket消息】收到客户端消息:" + message); + } + + // 此为广播消息 + public void sendAllMessage(String message) { + for (WebSocket webSocket : webSockets) { + System.out.println("【websocket消息】广播消息:" + message); + try { + webSocket.session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + // 发送列表消息 + public void sendListMessage(List userIds, String message) { + System.out.println("【websocket消息】列表消息:" + message); + for (String userId : userIds) { + Session session = sessionPool.get(userId); + if (session != null) { + try { + session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + // 发送列表消息 + +// public void sendListMessage(List userIds, Object data){ +// System.out.println("【websocket消息】列表消息:"+data); +// for (String userId : userIds) { +// Session session = sessionPool.get(userId); +// if (session != null) { +// try { +//// session.getAsyncRemote().sendText(message); +// session.getAsyncRemote().sendObject(data); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// } + + // 此为单点消息 + public void sendOneMessage(String userId, String message) { + System.out.println("【websocket消息】单点消息:" + message); + Session session = sessionPool.get(userId); + if (session != null) { + try { + session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index e948b83..da34a49 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -14,6 +14,7 @@ port: 11412 password: ew5T4K3#203lwh redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: # store-type: redis #flowable数据源和多数据源配置 diff --git a/pom.xml b/pom.xml index eb09e10..c45d3ad 100644 --- a/pom.xml +++ b/pom.xml @@ -140,6 +140,33 @@ 2.4.8 + + com.aliyun + alibabacloud-dysmsapi20170525 + 2.0.22 + + + + com.gexin.platform + gexin-rp-fastjson + 1.0.0.3 + + + com.gexin.platform + gexin-rp-sdk-base + 4.0.0.30 + + + com.gexin.platform + gexin-rp-sdk-http + 4.1.0.5 + + + com.gexin.platform + gexin-rp-sdk-template + 4.0.0.24 + + diff --git a/src/main/java/com/casic/config/AliYunConfig.java b/src/main/java/com/casic/config/AliYunConfig.java new file mode 100644 index 0000000..090b6ab --- /dev/null +++ b/src/main/java/com/casic/config/AliYunConfig.java @@ -0,0 +1,21 @@ +package com.casic.config; + +import lombok.Data; +import lombok.Value; +import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Slf4j +@Configuration +@ConfigurationProperties(prefix = "casic.ali") +@Data +public class AliYunConfig { + + private String key; + private String screct; + private String url; + private String signNameJson; + private String templateCode; + +} diff --git a/src/main/java/com/casic/controller/AlarmPushController.java b/src/main/java/com/casic/controller/AlarmPushController.java new file mode 100644 index 0000000..ac0e58e --- /dev/null +++ b/src/main/java/com/casic/controller/AlarmPushController.java @@ -0,0 +1,27 @@ +package com.casic.controller; + +import com.casic.model.AlarmPushConfig; +import com.casic.service.AlarmPushService; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@AllArgsConstructor +public class AlarmPushController { + + private AlarmPushService alarmPushService; + + @RequestMapping("/push/config") + public Object alarmPushConfig(@RequestBody AlarmPushConfig alarmSwitchConfig) { + return alarmPushService.alarmPushConfig(alarmSwitchConfig); + } + + @RequestMapping("/push/query") + public Object alarmPushQuery(@RequestParam(value = "secene", required = true) String secene) { + return alarmPushService.getAlarmPush(secene); + } + +} diff --git a/src/main/java/com/casic/controller/ArtemisValidController.java b/src/main/java/com/casic/controller/ArtemisValidController.java index fcf634a..1d52576 100644 --- a/src/main/java/com/casic/controller/ArtemisValidController.java +++ b/src/main/java/com/casic/controller/ArtemisValidController.java @@ -8,6 +8,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +/** + * 海康接口 + */ @AllArgsConstructor @RestController public class ArtemisValidController { @@ -16,7 +19,7 @@ @RequestMapping("/hkvideo/getVideoUrl") public ResponseData getVideoUrl(@RequestBody HkvideoValidParam hkvideoValidParam) { - return artemisPostUtill.artemisPost(hkvideoValidParam); + return artemisPostUtill.artemisPost(hkvideoValidParam); } } diff --git a/src/main/java/com/casic/controller/MessagePusherController.java b/src/main/java/com/casic/controller/MessagePusherController.java new file mode 100644 index 0000000..d447c05 --- /dev/null +++ b/src/main/java/com/casic/controller/MessagePusherController.java @@ -0,0 +1,41 @@ +package com.casic.controller; + +import com.casic.service.MessagePusherService; +import org.springframework.web.bind.annotation.*; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class MessagePusherController { + + + private final MessagePusherService messagePusherService; + + public MessagePusherController(MessagePusherService messagePusherService) { + this.messagePusherService = messagePusherService; + } + + + /*** + * 更新sink生成工单的接单时间,及建立超期未接工单的处理任务 + * @return + */ + @RequestMapping(value = "/job/updateSinkJob") + @ResponseBody + public Map updateSinkJob(@RequestParam(value = "msg", required = true) String msg) { + Map retMap = new HashMap<>(); + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return retMap; + } + //报警开关按钮 + // + + +} diff --git a/src/main/java/com/casic/dao/AlarmPushMapper.java b/src/main/java/com/casic/dao/AlarmPushMapper.java new file mode 100644 index 0000000..346e9f0 --- /dev/null +++ b/src/main/java/com/casic/dao/AlarmPushMapper.java @@ -0,0 +1,7 @@ +package com.casic.dao; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushMapper extends BaseMapper { +} diff --git a/src/main/java/com/casic/model/AlarmPushConfig.java b/src/main/java/com/casic/model/AlarmPushConfig.java new file mode 100644 index 0000000..60d548c --- /dev/null +++ b/src/main/java/com/casic/model/AlarmPushConfig.java @@ -0,0 +1,19 @@ +package com.casic.model; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +@Data +@TableName("alarm_switch_config") +public class AlarmPushConfig { + + @TableId(value = "ID", type = IdType.ASSIGN_ID) + private Long id; + private Integer websocketAlarm; + private Integer shortMessageAlarm; + private String secene; + private Integer enable; + private String phoneArray; +} diff --git a/src/main/java/com/casic/model/DeviceTypeEnum.java b/src/main/java/com/casic/model/DeviceTypeEnum.java new file mode 100644 index 0000000..26c685f --- /dev/null +++ b/src/main/java/com/casic/model/DeviceTypeEnum.java @@ -0,0 +1,64 @@ +package com.casic.model; + + +public enum DeviceTypeEnum { + Well("井盖状态监测仪", 1), + Liquid("液位监测仪", 2), + WasteGas("有害气体监测仪", 3), + Methane("燃气智能监测终端", 4), + TempHumi("温湿度监测仪", 5), + Dig("开挖监测仪", 6), + WellLocator("井盖定位监测仪", 7), + Noise("噪声记录仪", 8), + TempPressure("温度压力监测仪", 9), + FireHydrant("消防栓防盗水监测仪", 11), + Tube("管盯", 12), + LG("井盖液位一体机", 13), + H2s("硫化氢检测终端", 14); + + // 成员变量 + private String name; + private int index; + + // 构造方法 + private DeviceTypeEnum(String name, int index) { + this.name = name; + this.index = index; + } + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public static DeviceTypeEnum getByIndex(String index) { + try { + for (DeviceTypeEnum deviceTypeEnum : values()) { + if (deviceTypeEnum.index == Integer.parseInt(index)) { + return deviceTypeEnum; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + //覆盖方法 + @Override + public String toString() { + return this.name; + } +} \ No newline at end of file diff --git a/src/main/java/com/casic/service/AlarmPushService.java b/src/main/java/com/casic/service/AlarmPushService.java new file mode 100644 index 0000000..20cd2e7 --- /dev/null +++ b/src/main/java/com/casic/service/AlarmPushService.java @@ -0,0 +1,14 @@ +package com.casic.service; + +import com.casic.model.AlarmPushConfig; + +public interface AlarmPushService { + + Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig); + + Object getAlarmPush(String secene); + +} + + + diff --git a/src/main/java/com/casic/service/AlarmService.java b/src/main/java/com/casic/service/AlarmService.java index 8516b41..4f41038 100644 --- a/src/main/java/com/casic/service/AlarmService.java +++ b/src/main/java/com/casic/service/AlarmService.java @@ -4,9 +4,10 @@ public interface AlarmService { - Object getAlarmRecord(String deviceType,Integer currentIndex,Integer pageSize,String devcode); + Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode); - Object excuteAlramBatchCancel(String deviceType,String devcode); + Object excuteAlramBatchCancel(String deviceType, String devcode); Object addAlarmConfig(AlarmConfigParam alarmConfig); + } diff --git a/src/main/java/com/casic/service/MessagePusherService.java b/src/main/java/com/casic/service/MessagePusherService.java new file mode 100644 index 0000000..2daa7cc --- /dev/null +++ b/src/main/java/com/casic/service/MessagePusherService.java @@ -0,0 +1,6 @@ +package com.casic.service; + +public interface MessagePusherService { + + void updateSinkJob(String id, String msg); +} diff --git a/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java new file mode 100644 index 0000000..e453316 --- /dev/null +++ b/src/main/java/com/casic/service/impl/AlarmPushServiceImpl.java @@ -0,0 +1,56 @@ +package com.casic.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.casic.dao.AlarmPushMapper; +import com.casic.model.AlarmPushConfig; +import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@Slf4j +public class AlarmPushServiceImpl extends ServiceImpl implements AlarmPushService { + + @Override + public Object alarmPushConfig(AlarmPushConfig alarmSwitchConfig) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", alarmSwitchConfig.getSecene()); +// this.baseMapper.delete(deleteWrapper); + this.baseMapper.update(alarmSwitchConfig, queryWrapper); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置新增异常,场景{},异常信息{}", alarmSwitchConfig.getSecene(), dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } + + @Override + public Object getAlarmPush(String secene) { + ResponseData responseData = new ResponseData(); + try { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("sence", secene); + List alarmPushConfigList = this.baseMapper.selectList(queryWrapper); + Optional alarmPushConfigOptional = alarmPushConfigList.stream().findFirst(); + responseData.setData(alarmPushConfigOptional.isPresent() ? alarmPushConfigOptional.get() : new Object()); + responseData.setMessage(ResponseData.DEFAULT_SUCCESS_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_SUCCESS_CODE); + } catch (DataAccessException dae) { + log.error("报警推送配置查询异常,场景{},异常信息{}", secene, dae.getMessage()); + responseData.setMessage(ResponseData.DEFAULT_ERROR_MESSAGE); + responseData.setCode(ResponseData.DEFAULT_ERROR_CODE); + } + return responseData; + } +} diff --git a/src/main/java/com/casic/service/impl/AlarmServiceImple.java b/src/main/java/com/casic/service/impl/AlarmServiceImple.java index 0808c47..8a29af9 100644 --- a/src/main/java/com/casic/service/impl/AlarmServiceImple.java +++ b/src/main/java/com/casic/service/impl/AlarmServiceImple.java @@ -7,7 +7,7 @@ import com.casic.model.*; import com.casic.service.AlarmService; import com.casic.util.DeviceDataTableEnum; -import com.casic.util.RedisCommonUtil; +import com.casic.util.RedisCommon; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; @@ -26,8 +26,9 @@ @Resource private BusConfigMapper busConfigMapper; @Resource - private RedisCommonUtil redisCommonUtil; + private RedisCommon redisCommonUtil; + @Override public Object getAlarmRecord(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); try { @@ -46,6 +47,7 @@ return responseData; } + @Override @Transactional public Object excuteAlramBatchCancel(String deviceType, String devcode) { ResponseData responseData = new ResponseData(); @@ -62,7 +64,7 @@ return responseData; } - + @Override @Transactional public Object addAlarmConfig(AlarmConfigParam alarmConfigParam) { ResponseData responseData = new ResponseData(); @@ -114,12 +116,12 @@ CommConfigDTO commConfigDTO = new CommConfigDTO(); commConfigDTO.setInterval(StringUtils.isEmpty(alarmConfigParam.getCollectInterval()) ? 300 : Long.valueOf(alarmConfigParam.getCollectInterval())); commConfigDTO.setRepeat(StringUtils.isEmpty(alarmConfigParam.getRetryNum()) ? 300 : Long.valueOf(alarmConfigParam.getRetryNum())); - commConfigDTO.setTimes(Long.valueOf(1)); +// commConfigDTO.setTimes(Long.valueOf(1)); // commConfigDTO.setIp(alarmConfigParam.getIp()); // commConfigDTO.setPort(StringUtils.isEmpty(alarmConfigParam.getPort()) ? 8080 : Long.valueOf(alarmConfigParam.getPort())); commConfigDTO.setPeriod(StringUtils.isEmpty(alarmConfigParam.getUploadCycle()) ? 300 : Long.valueOf(alarmConfigParam.getUploadCycle())); // commConfigDTO.setThresh(); - commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50: Float.valueOf(alarmConfigParam.getThresholdVol())); + commConfigDTO.setThresh(StringUtils.isEmpty(alarmConfigParam.getThresholdVol()) ? 50 : Float.valueOf(alarmConfigParam.getThresholdVol())); redisCommonUtil.send(commConfigDTO, devcode); } diff --git a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java index 3de704b..e35daef 100644 --- a/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/DeviceDataServiceImpl.java @@ -23,6 +23,7 @@ this.deviceDataMapper = deviceDataMapper; } + @Override public Object getDeviceRecentData(String deviceType, String recentNum, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -41,6 +42,7 @@ return responseData; } + @Override public Object getDeviceListPage(String deviceType, Integer currentIndex, Integer pageSize, String devcode) { ResponseData responseData = new ResponseData(); DeviceDataTableEnum deviceDataTableEnum = DeviceDataTableEnum.DEVICE_TYPE_TABLE.getTableNameMap().get(Integer.valueOf(deviceType)); @@ -62,6 +64,7 @@ return responseData; } + @Override public Object getLevel(String deviceType) { ResponseData responseData = new ResponseData(); try { diff --git a/src/main/java/com/casic/service/impl/MessagePusherImpl.java b/src/main/java/com/casic/service/impl/MessagePusherImpl.java new file mode 100644 index 0000000..850f939 --- /dev/null +++ b/src/main/java/com/casic/service/impl/MessagePusherImpl.java @@ -0,0 +1,42 @@ +package com.casic.service.impl; + +import com.alibaba.druid.util.StringUtils; +import com.alibaba.fastjson.JSON; +import com.casic.service.MessagePusherService; +import com.casic.util.WebSocket; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; + +@Slf4j +@Service +public class MessagePusherImpl implements MessagePusherService { + + @Resource + private WebSocket webSocket; + + @Override + public void updateSinkJob(String id, String msg) { + if (!(StringUtils.isEmpty(msg))) { + sendAlarm(msg);//推送告警至app和pc端 + } + } + + private void sendAlarm(String msg) { + List userIds = new ArrayList<>(); +// String appMsg = "设备编号[" + devcode + "]发生" + msg + ",工单编号为[" + jobId + "]"; + // PC推送 + userIds.add("123456"); + if (userIds.size() > 0) { + Map map = new HashMap(); + map.put("message", msg); + map.put("type", "alarm"); + webSocket.sendListMessage(userIds, JSON.toJSONString(map)); + } else { + log.info("告警消息找不到责任人,pc端未推送:" + msg); + } + } + +} diff --git a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java index 1e6f08a..21ad102 100644 --- a/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java +++ b/src/main/java/com/casic/service/impl/ThirdDataServiceImpl.java @@ -2,17 +2,24 @@ import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.casic.dao.DataPressureMapper; +import com.casic.model.AlarmPushConfig; import com.casic.model.DataPressure; import com.casic.model.PressureDataParam; import com.casic.model.ResponseData; +import com.casic.service.AlarmPushService; +import com.casic.service.MessagePusherService; import com.casic.service.ThirdDataService; -import com.casic.util.CacheUtil; +import com.casic.util.SendBatchSmsUtil; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -24,6 +31,17 @@ private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA); + @Autowired + private AlarmPushService alarmPushService; + + @Autowired + private MessagePusherService messagePusherService; + + @Autowired + private SendBatchSmsUtil sendBatchSmsUtil; + + + @Override public Object getDeviceRecentData(PressureDataParam pressureDataParam) { ResponseData responseData = new ResponseData(); try { @@ -81,12 +99,52 @@ private void checkAlarm(DataPressure dataPressure) { final Float ruleValue = this.baseMapper.getRuleValue("24"); - if (ruleValue == null) return; + if (ruleValue == null) { + return; + } if (!StringUtils.isEmpty(dataPressure.getPress()) && !dataPressure.getPress().equals("null")) { if (Float.valueOf(dataPressure.getPress()) > ruleValue) { this.baseMapper.saveRecords(dataPressure.getPress(), new Date()); + alarmPushBuilder(dataPressure.getDevcode(), dataPressure.getPress()); } } } + // "在2023年1月12号 16时43分23秒,设备41232561发生了压力超标/浓度超限,数值为20" + // + "设备" + devcode + "发生了压力超标,压力值为" + presss + // + + private void alarmPushBuilder(String devcode, String presss) { + ResponseData responseData = (ResponseData) alarmPushService.getAlarmPush("H2S"); + AlarmPushConfig alarmPushConfig = (AlarmPushConfig) responseData.getData(); + if (alarmPushConfig.getEnable().equals(1)) { + if (alarmPushConfig.getWebsocketAlarm().equals(1)) { + String msg = "在" + new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date()) + "," + + "设备" + devcode + "发生了压力超标,压力值为" + presss; + try { + messagePusherService.updateSinkJob("", URLDecoder.decode(msg, "UTF-8")); + } catch (UnsupportedEncodingException uee) { + log.error("websocket推送,内容转码出现异常,异常信息为{}", uee.getMessage()); + } + } + if (alarmPushConfig.getShortMessageAlarm().equals(1)) { + Map msgMap = new HashMap<>(); + msgMap.put("time", new SimpleDateFormat("yyyyMMdd HH:mm:ss").format(new Date())); + msgMap.put("devcode", devcode); + msgMap.put("value", presss); + msgMap.put("content", "压力超标"); + String phoneJson = ""; + if (StringUtils.isEmpty(alarmPushConfig.getPhoneArray())) { + String[] phones = alarmPushConfig.getPhoneArray().split(","); + List phoneList = new ArrayList<>(); + for (String phone : phones) { + phoneList.add(phone); + } + phoneJson = JSONObject.toJSONString(phoneList); + } + sendBatchSmsUtil.sendMsg(phoneJson, JSON.toJSONString(msgMap)); + } + } + } + } diff --git a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java index 085c7c3..06d489a 100644 --- a/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java +++ b/src/main/java/com/casic/util/DeviceDataFieldTableEnum.java @@ -23,7 +23,7 @@ put("data_pantilt", "concentration AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellcover_loca", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_wellplus", "0 AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); - put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(LOGTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); + put("data_h2s", "strength AS dataValue,devcode AS devcode,CELL AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); put("data_pressure", "re_val AS dataValue,devcode AS devcode,'' AS cell,DATE_FORMAT(UPTIME,'%Y-%m-%d %H:%i:%s') AS uptime"); } }); diff --git a/src/main/java/com/casic/util/RedisCommon.java b/src/main/java/com/casic/util/RedisCommon.java new file mode 100644 index 0000000..617d73b --- /dev/null +++ b/src/main/java/com/casic/util/RedisCommon.java @@ -0,0 +1,29 @@ +package com.casic.util; + +import com.alibaba.fastjson.JSON; +import com.casic.model.CommConfigDTO; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.concurrent.TimeUnit; + +@Component +public class RedisCommon { + + @Value("${casic.device.redis.invalid-time}") + private String invalidTime; + @Value("${casic.device.redis.config-prefix}") + private String configPrefix; + + @Autowired + private RedisTemplate redisTemplate; + + public void send(CommConfigDTO commConfigDTO,String devCode) { + redisTemplate.opsForValue().set(configPrefix+ devCode, + JSON.toJSONString(commConfigDTO), + Integer.valueOf(invalidTime), + TimeUnit.SECONDS); + } +} diff --git a/src/main/java/com/casic/util/RedisCommonUtil.java b/src/main/java/com/casic/util/RedisCommonUtil.java deleted file mode 100644 index a6ce9cf..0000000 --- a/src/main/java/com/casic/util/RedisCommonUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.casic.util; - -import com.alibaba.fastjson.JSON; -import com.casic.model.CommConfigDTO; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; - -@Component -public class RedisCommonUtil { - - @Value("${casic.device.redis.invalid-time}") - private String invalidTime; - @Value("${casic.device.redis.config-prefix}") - private String configPrefix; - - @Autowired - private RedisTemplate redisTemplate; - - public void send(CommConfigDTO commConfigDTO,String devCode) { - redisTemplate.opsForValue().set(configPrefix+ devCode, - JSON.toJSONString(commConfigDTO), - Integer.valueOf(invalidTime), - TimeUnit.SECONDS); - } -} diff --git a/src/main/java/com/casic/util/SendBatchSmsUtil.java b/src/main/java/com/casic/util/SendBatchSmsUtil.java new file mode 100644 index 0000000..ed043a4 --- /dev/null +++ b/src/main/java/com/casic/util/SendBatchSmsUtil.java @@ -0,0 +1,89 @@ +package com.casic.util; +// This file is auto-generated, don't edit it. Thanks. + +import com.aliyun.auth.credentials.Credential; +import com.aliyun.auth.credentials.provider.StaticCredentialProvider; +import com.aliyun.sdk.service.dysmsapi20170525.models.*; +import com.aliyun.sdk.service.dysmsapi20170525.*; +import com.casic.config.AliYunConfig; +import com.google.gson.Gson; +import darabonba.core.client.ClientOverrideConfiguration; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.concurrent.CompletableFuture; + +@AllArgsConstructor +@Component +@Slf4j +public class SendBatchSmsUtil { + + private AliYunConfig aliYunConfig; + + public void sendMsg(String phoneJson, String msgJson) { + StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() + .accessKeyId(aliYunConfig.getKey()) + .accessKeySecret(aliYunConfig.getScrect()) + .build()); + + AsyncClient client = AsyncClient.builder() + .region("cn-shanghai") // Region ID + .credentialsProvider(provider) + .overrideConfiguration( + ClientOverrideConfiguration.create() + .setEndpointOverride(aliYunConfig.getUrl()) + ) + .build(); + + SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() + .phoneNumberJson(phoneJson) + .signNameJson(aliYunConfig.getSignNameJson()) + .templateCode(aliYunConfig.getTemplateCode()) + .templateParamJson(msgJson) + .build(); + + CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); + try { + SendBatchSmsResponse resp = response.get(); + System.out.println(new Gson().toJson(resp)); + } catch (Exception ex) { + log.error("发送消息出现异常,手机号内容为{},信息内容为{}",phoneJson,msgJson,ex.getMessage()); + }finally { + client.close(); + } + } + + +// public static void main(String [] args) throws Exception { +// +// StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder() +// .accessKeyId("LTAI5tDFNucQF2Bdy4fHgzrN") +// .accessKeySecret("hZ22QQPxQue1G0R8Ty2bo6GimrLdoB") +// .build()); +// +// AsyncClient client = AsyncClient.builder() +// .region("cn-shanghai") // Region ID +// .credentialsProvider(provider) +// .overrideConfiguration( +// ClientOverrideConfiguration.create() +// .setEndpointOverride("dysmsapi.aliyuncs.com") +// ) +// .build(); +// +// SendBatchSmsRequest sendBatchSmsRequest = SendBatchSmsRequest.builder() +// .phoneNumberJson("[\"13651065090\"]") +// .signNameJson("[\"阿里云短信测试\"]") +// .templateCode("SMS_154950909") +// .templateParamJson("[{\"code\":\"123456\"}]") +// // Request-level configuration rewrite, can set Http request parameters, etc. +// // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders())) +// .build(); +// +// CompletableFuture response = client.sendBatchSms(sendBatchSmsRequest); +// SendBatchSmsResponse resp = response.get(); +// System.out.println(new Gson().toJson(resp)); +// client.close(); +// } + +} \ No newline at end of file diff --git a/src/main/java/com/casic/util/WebSocket.java b/src/main/java/com/casic/util/WebSocket.java new file mode 100644 index 0000000..1ee283f --- /dev/null +++ b/src/main/java/com/casic/util/WebSocket.java @@ -0,0 +1,103 @@ +package com.casic.util; + +import org.springframework.stereotype.Component; + +import javax.websocket.OnClose; +import javax.websocket.OnMessage; +import javax.websocket.OnOpen; +import javax.websocket.Session; +import javax.websocket.server.PathParam; +import javax.websocket.server.ServerEndpoint; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArraySet; + +/** + * 此注解相当于设置访问URL + */ +@Component +@ServerEndpoint("/websocket/{userId}") +public class WebSocket { + private Session session; + + private static CopyOnWriteArraySet webSockets = new CopyOnWriteArraySet<>(); + private static Map sessionPool = new HashMap(); + + @OnOpen + public void onOpen(Session session, @PathParam(value = "userId") String userId) { + this.session = session; + webSockets.add(this); + sessionPool.put(userId, session); + System.out.println(userId + "【websocket消息】有新的连接,总数为:" + webSockets.size()); + } + + @OnClose + public void onClose() { + webSockets.remove(this); + System.out.println("【websocket消息】连接断开,总数为:" + webSockets.size()); + } + + @OnMessage + public void onMessage(String message) { + System.out.println("【websocket消息】收到客户端消息:" + message); + } + + // 此为广播消息 + public void sendAllMessage(String message) { + for (WebSocket webSocket : webSockets) { + System.out.println("【websocket消息】广播消息:" + message); + try { + webSocket.session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + // 发送列表消息 + public void sendListMessage(List userIds, String message) { + System.out.println("【websocket消息】列表消息:" + message); + for (String userId : userIds) { + Session session = sessionPool.get(userId); + if (session != null) { + try { + session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + // 发送列表消息 + +// public void sendListMessage(List userIds, Object data){ +// System.out.println("【websocket消息】列表消息:"+data); +// for (String userId : userIds) { +// Session session = sessionPool.get(userId); +// if (session != null) { +// try { +//// session.getAsyncRemote().sendText(message); +// session.getAsyncRemote().sendObject(data); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } +// } +// } + + // 此为单点消息 + public void sendOneMessage(String userId, String message) { + System.out.println("【websocket消息】单点消息:" + message); + Session session = sessionPool.get(userId); + if (session != null) { + try { + session.getAsyncRemote().sendText(message); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + +} diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index e948b83..da34a49 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -14,6 +14,7 @@ port: 11412 password: ew5T4K3#203lwh redisValueSerializer: org.springframework.data.redis.serializer.JdkSerializationRedisSerializer + # session: # store-type: redis #flowable数据源和多数据源配置 diff --git a/src/main/resources/config/application.yml b/src/main/resources/config/application.yml index c21dc60..0e2b972 100644 --- a/src/main/resources/config/application.yml +++ b/src/main/resources/config/application.yml @@ -35,6 +35,12 @@ hikom: url: /artemis/api/video/v1/cameras/previewURLs host: 118.122.17.165:1443/ + ali: + key: LTAI5tDFNucQF2Bdy4fHgzrN + secret: hZ22QQPxQue1G0R8Ty2bo6GimrLdoB + url: dysmsapi.aliyuncs.com + signNameJson: 阿里云短信测试 + templateCode: SMS_154950909 swagger: enable: true groupName: "硫化氢课题" \ No newline at end of file