Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV
| | |
| | | StringBuilder str = new StringBuilder() ; |
| | | str.append(" 报警:\n"); |
| | | str.append(" 蓄电池电压:"); |
| | | str.append(batteryVolt==null?"":(batteryVolt==1?"报警":"正常")); |
| | | str.append(batteryVolt==null?"":(batteryVolt==1?"报警(1)":"正常(0)")); |
| | | str.append("\n"); |
| | | str.append(" 漏损: "); |
| | | str.append(loss==null?"":(loss==1?"报警":"正常")); |
| | | str.append(loss==null?"":(loss==1?"报警(1)":"正常(0)")); |
| | | str.append("\n"); |
| | | str.append(" 流量计故障:"); |
| | | str.append(meter==null?"":(meter==1?"报警":"正常")); |
| | | str.append(meter==null?"":(meter==1?"报警(1)":"正常(0)")); |
| | | str.append("\n"); |
| | | str.append(" 阀门: "); |
| | | str.append(valve==null?"":(valve==1?"报警":"正常")); |
| | | str.append(valve==null?"":(valve==1?"报警(1)":"正常(0)")); |
| | | return str.toString() ; |
| | | } |
| | | } |
| | |
| | | <artifactId>alibaba-dingtalk-service-sdk</artifactId> |
| | | <version>2.0.0</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>commons-codec</groupId> |
| | | <artifactId>commons-codec</artifactId> |
| | |
| | | import com.dingtalk.api.request.OapiRobotSendRequest; |
| | | import com.dingtalk.api.response.OapiRobotSendResponse; |
| | | import com.taobao.api.ApiException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | * @LastEditTime 2024-07-31 9:20 |
| | | * @Description 钉钉客户端工具类 |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class DingTalk { |
| | | @Value("${dingtalk.robot.url}") |
| | |
| | | req.setText(text); |
| | | req.setAt(at); |
| | | OapiRobotSendResponse rsp = client.execute(req, CUSTOM_ROBOT_TOKEN); |
| | | System.out.println(rsp.getBody()); |
| | | log.info(rsp.getBody()); |
| | | } catch (ApiException e) { |
| | | e.printStackTrace(); |
| | | log.error("钉钉发送消息异常", e); |
| | | //e.printStackTrace(); |
| | | } catch (UnsupportedEncodingException e) { |
| | | throw new RuntimeException(e); |
| | | log.error("钉钉发送消息异常", e); |
| | | //e.printStackTrace(); |
| | | } catch (NoSuchAlgorithmException e) { |
| | | throw new RuntimeException(e); |
| | | log.error("钉钉发送消息异常", e); |
| | | //e.printStackTrace(); |
| | | } catch (InvalidKeyException e) { |
| | | throw new RuntimeException(e); |
| | | log.error("钉钉发送消息异常", e); |
| | | //e.printStackTrace(); |
| | | } catch (Exception e){ |
| | | log.error("钉钉发送消息异常", e); |
| | | //e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | |
| | | tb.intakeId intakeId, |
| | | itb.name intakeName |
| | | FROM pr_controller tb |
| | | INNER JOIN pr_intake itb on tb.intakeId=itb.id |
| | | WHERE deleted = 0 AND intakeId is not null AND rtuAddr=#{rtuAddr,jdbcType=VARCHAR} |
| | | INNER JOIN pr_intake itb on tb.intakeId = itb.id |
| | | WHERE tb.deleted = 0 AND tb.intakeId is not null AND tb.rtuAddr=#{rtuAddr,jdbcType=VARCHAR} |
| | | </select> |
| | | |
| | | <!--根据控制器编号逻辑删除控制--> |
| | |
| | | alarm_battery_volt = #{alarmBatteryVolt,jdbcType=TINYINT}, |
| | | alarm_valve = #{alarmValve,jdbcType=TINYINT}, |
| | | power_type = #{powerType,jdbcType=TINYINT}, |
| | | send_ms_time = #{powerType,jdbcType=BIGINT} |
| | | send_ms_time = #{sendMsTime,jdbcType=BIGINT} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | <!--根据指定条件获取记录总数--> |
| | |
| | | <version>2.0.7</version> |
| | | </dependency> |
| | | |
| | | <!--钉钉消息推送--> |
| | | <dependency> |
| | | <groupId>com.aliyun</groupId> |
| | | <artifactId>alibaba-dingtalk-service-sdk</artifactId> |
| | | <version>2.0.0</version> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-codec</groupId> |
| | | <artifactId>commons-codec</artifactId> |
| | | <version>1.15</version> |
| | | </dependency> |
| | | |
| | | <!-- 测试 --> |
| | | <dependency> |
| | | <groupId>org.springframework.boot</groupId> |
| | |
| | | import com.dy.common.mw.protocol.ProtocolUnit; |
| | | import com.dy.common.mw.support.SupportUnit; |
| | | import com.dy.common.mw.support.SupportUnitConfigVo; |
| | | import com.dy.rtuMw.server.tasks.SendMsConstantTask; |
| | | import com.dy.rtuMw.server.tasks.ToRtuConstantTask; |
| | | import com.dy.rtuMw.resource.ResourceUnit; |
| | | import com.dy.rtuMw.resource.ResourceUnitConfigVo; |
| | |
| | | CoreUnit.addConstantTask(new ToRtuConstantTask()); |
| | | CoreUnit.addConstantTask(new FromRtuDataConstantTask()); |
| | | CoreUnit.addConstantTask(new FromRtuComResultConstantTask()); |
| | | CoreUnit.addConstantTask(new SendMsConstantTask()); |
| | | coreUnit.start(obj -> { |
| | | }); |
| | | units.add(coreUnit) ; |
New file |
| | |
| | | package com.dy.rtuMw.server.forMs; |
| | | |
| | | import com.dy.common.queue.NodeObj; |
| | | import com.dy.common.springUtil.SpringContextUtil; |
| | | import com.dy.pipIrrGlobal.config.DingTalk; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/7/31 18:50 |
| | | * @Description |
| | | */ |
| | | public class MsObj4Ding implements NodeObj { |
| | | |
| | | private static Logger log = LogManager.getLogger(MsObj4Ding.class.getName()); |
| | | |
| | | public String ms ; |
| | | |
| | | public MsObj4Ding(String ms){ |
| | | this.ms = ms ; |
| | | } |
| | | |
| | | /** |
| | | * 自己处理自己 |
| | | * @return |
| | | */ |
| | | public boolean dealSelf(){ |
| | | DingTalk dingTalk = SpringContextUtil.getBean(DingTalk.class) ; |
| | | dingTalk.sendMessage(ms); |
| | | return true ; |
| | | } |
| | | } |
New file |
| | |
| | | package com.dy.rtuMw.server.forMs; |
| | | |
| | | import com.dy.common.queue.Node; |
| | | import com.dy.common.queue.Queue; |
| | | import com.dy.rtuMw.server.ServerProperties; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/7/31 18:47 |
| | | * @Description |
| | | */ |
| | | public class SendMsCache { |
| | | |
| | | //TCP下行命令缓存队列 |
| | | private static Queue cacheQueue = new Queue("SendMsCache") ; |
| | | |
| | | private static SendMsCache instance = new SendMsCache() ; |
| | | |
| | | private SendMsCache(){ |
| | | cacheQueue.setLimit(ServerProperties.cacheUpDownDataWarnCount, ServerProperties.cacheUpDownDataMaxCount); |
| | | } |
| | | |
| | | public static SendMsCache getInstance(){ |
| | | return instance ; |
| | | } |
| | | |
| | | /** |
| | | * 缓存命令 |
| | | * @param ms |
| | | * @throws Exception |
| | | */ |
| | | public static void cacheMs(String ms) throws Exception{ |
| | | cacheQueue.pushTail(new MsObj4Ding(ms)); |
| | | } |
| | | |
| | | /** |
| | | * 得到第一个节点 |
| | | * @return |
| | | */ |
| | | public static Node getFirstQueueNode(){ |
| | | return cacheQueue.getFirstNode() ; |
| | | } |
| | | |
| | | /** |
| | | * 得到最后一个节点 |
| | | * @return |
| | | */ |
| | | public static Node getLastQueueNode(){ |
| | | return cacheQueue.getLastNode() ; |
| | | } |
| | | |
| | | /** |
| | | * 移除节点 |
| | | * @param node |
| | | */ |
| | | public static void removeNode(Node node){ |
| | | cacheQueue.remove(node); |
| | | } |
| | | |
| | | /** |
| | | * 缓存的节点数 |
| | | * @Return 缓存节点数 |
| | | */ |
| | | public static Integer size(){ |
| | | return cacheQueue.size() ; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.dy.rtuMw.server.rtuData.p206V1_0_0; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.upVos.*; |
| | | import com.dy.common.springUtil.SpringContextUtil; |
| | | import com.dy.common.util.DateTime; |
| | | import com.dy.pipIrrGlobal.config.DingTalk; |
| | | import com.dy.pipIrrGlobal.pojoRm.RmAlarmStateHistory; |
| | | import com.dy.rtuMw.server.ServerProperties; |
| | | import com.dy.rtuMw.server.forMs.SendMsCache; |
| | | import com.dy.rtuMw.server.rtuData.TaskSurpport; |
| | | import com.dy.rtuMw.server.rtuData.dbSv.DbSv; |
| | | import com.dy.common.mw.protocol.Data; |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 向钉钉发送消息 |
| | | * @param controller |
| | | * @param alarmVo |
| | | */ |
| | | private void sendMessage(PrController controller, DataAlarmVo alarmVo){ |
| | | String ms = "取水口" + controller.getIntakeName() + "产生报警:" + alarmVo.alarmContent() ; |
| | | String ms = "取水口“" + controller.getIntakeName() + "”产生报警:" + alarmVo.alarmContent() ; |
| | | try{ |
| | | SendMsCache.cacheMs(ms); |
| | | }catch (Exception e){ |
| | | log.error("缓存钉钉消息异常:", e); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | alarmVo==null?null:alarmVo.stateIcEnable, |
| | | (byte)0,//电池电压(1:报警,0:正常) |
| | | (byte)0,//阀门报警(1:报警,0:正常) |
| | | (byte)0//供电方式(0: 220V,1:蓄电池) |
| | | (byte)0,//供电方式(0: 220V,1:蓄电池) |
| | | System.currentTimeMillis() |
| | | ) ; |
| | | sv.saveRmAlarmStateLast(po) ; |
| | | }else{ |
New file |
| | |
| | | package com.dy.rtuMw.server.tasks; |
| | | |
| | | import com.dy.common.mw.core.CoreTask; |
| | | import com.dy.common.queue.Node; |
| | | import com.dy.rtuMw.server.forMs.MsObj4Ding; |
| | | import com.dy.rtuMw.server.forMs.SendMsCache; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/7/31 18:45 |
| | | * @Description |
| | | */ |
| | | public class SendMsConstantTask extends CoreTask { |
| | | |
| | | private static final Logger log = LogManager.getLogger(SendMsConstantTask.class.getName()); |
| | | |
| | | /** |
| | | * 在单线程环境中运行 |
| | | */ |
| | | @Override |
| | | public Integer execute() { |
| | | try{ |
| | | //log.info("当前消息队列中还有结点数量:" + SendMsCache.size()); |
| | | dealMs() ; |
| | | }catch(Exception e){ |
| | | log.error(e); |
| | | } |
| | | return SendMsCache.size()>0?0:1 ; |
| | | } |
| | | |
| | | /** |
| | | * 处理下行命令 |
| | | */ |
| | | public void dealMs() { |
| | | Node first = SendMsCache.getFirstQueueNode() ; |
| | | if(first != null){ |
| | | Node last = SendMsCache.getLastQueueNode() ; |
| | | while (last != null){ |
| | | last = this.doDealMs(first, last); |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * 处理缓存的下行节点 |
| | | * @param first 第一个节点 |
| | | * @param last 最后一个节点 |
| | | */ |
| | | private Node doDealMs(Node first, Node last){ |
| | | if(last != null){ |
| | | //在dealNode方法中,可能要把last从队列中移除,这时last.pre为空,所以提前把last.pre取出来 |
| | | Node pre = last.pre ; |
| | | dealNode(last) ; |
| | | if(first != last){ |
| | | return pre ; |
| | | }else{ |
| | | //停止 |
| | | return null ; |
| | | } |
| | | }else{ |
| | | return null ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 处理一个节点 |
| | | * @param node 节点 |
| | | */ |
| | | private void dealNode(Node node){ |
| | | if(node != null && node.obj != null){ |
| | | MsObj4Ding obj = (MsObj4Ding)node.obj ; |
| | | boolean removeNode = obj.dealSelf() ; |
| | | if(removeNode){ |
| | | SendMsCache.removeNode(node); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.dy.pipIrrMwTestRtu.tcpClient.upData; |
| | | |
| | | import com.dy.common.mw.protocol.p206V1_0_0.parse.global.GlCreate; |
| | | import com.dy.common.util.ByteUtil; |
| | | import com.dy.pipIrrMwTestRtu.ServerProperties; |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * @Author: liurunyu |
| | | * @Date: 2024/7/31 16:29 |
| | | * @Description |
| | | */ |
| | | public class UpCd81 extends UpData { |
| | | |
| | | private static final Logger log = LogManager.getLogger(UpCd81.class); |
| | | |
| | | public static void upData() { |
| | | try { |
| | | if (UpData.session != null && UpData.session.isConnected()) { |
| | | byte[] bs = createData(ServerProperties.rtuAddr); |
| | | UpData.upSend(bs); |
| | | } else { |
| | | log.error("未连接通信中间件,不能发送数据"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("向通信中间件发送数据产生异常", e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构造数据 |
| | | * |
| | | * @return 字节数组 |
| | | * @throws Exception 异常 |
| | | */ |
| | | private static byte[] createData(String rtuAddr) throws Exception { |
| | | byte[] bytes = creatHead(rtuAddr, "81", (byte)0xB0); |
| | | |
| | | byte[] bs = new byte[2] ; |
| | | bs[0] = (byte)0xDF ;//报警 |
| | | bs[1] = (byte)0xF9 ;//报警 |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | bs = new byte[2] ; |
| | | bs[0] = (byte)0x00 ;//状态 |
| | | bs[1] = (byte)0x00 ;//状态 |
| | | bytes = ByteUtil.bytesMerge(bytes, bs) ; |
| | | |
| | | GlCreate.createLen(bytes);//长度放字节数组中 |
| | | |
| | | byte[] bsTail = GlCreate.createCrcTail(bytes) ;//CRC和尾叠加字节数组中 |
| | | |
| | | bytes = ByteUtil.bytesMerge(bytes, bsTail) ; |
| | | |
| | | return bytes ; |
| | | } |
| | | } |
| | |
| | | @ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.pipIrrMwTestWeb"}, |
| | | excludeFilters = { |
| | | @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = { |
| | | com.dy.common.apiDoc.SpringApiConfig.class //一种排除类的方式 |
| | | //一种排除类的方式 |
| | | com.dy.common.apiDoc.SpringApiConfig.class, |
| | | com.dy.pipIrrGlobal.config.DingTalk.class |
| | | }), |
| | | @ComponentScan.Filter(type = FilterType.REGEX, pattern = { |
| | | //二种排除类的方式,写正则表达式,需要对目标类的完全限定名完全匹配,否则不生效 |
| | |
| | | comVo.moneyRemain = 234.56 ; |
| | | comVo.waterPrice = 1.2 ; |
| | | comVo.minutes = 3 ; |
| | | String nextDtStr = DateTime.nextXMinute_yyyy_MM_dd_HH_mm_ss(DateTime.yyyy_MM_dd_HH_mm_ss(), 5) ;//将来5分钟 |
| | | String nextDtStr = DateTime.nextXMinute_yyyy_MM_dd_HH_mm_ss(DateTime.yyyy_MM_dd_HH_mm_ss(), comVo.minutes) ;//将来X分钟 |
| | | int[] nextDt = DateTime.yyyy_MM_dd_HH_MM_SS_2_ymdhmsGroup(nextDtStr) ; |
| | | comVo.year = nextDt[0] ; |
| | | comVo.month = nextDt[1] ; |
| | |
| | | <groupId>org.apache.rocketmq</groupId> |
| | | <artifactId>rocketmq-client</artifactId> |
| | | <version>4.9.7</version> |
| | | <type>pom</type> |
| | | <scope>import</scope> |
| | | </dependency> |
| | | |
| | | <!--钉钉消息推送--> |
| | | <dependency> |
| | | <groupId>com.aliyun</groupId> |
| | | <artifactId>alibaba-dingtalk-service-sdk</artifactId> |
| | | <version>2.0.0</version> |
| | | <type>pom</type> |
| | | <scope>import</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>commons-codec</groupId> |
| | | <artifactId>commons-codec</artifactId> |
| | | <version>1.15</version> |
| | | <type>pom</type> |
| | | <scope>import</scope> |
| | | </dependency> |
| | | |
| | | <!-- 测试 --> |