JRT监听程序

2024-02-07 13:52
文章标签 程序 监听 jrt

本文主要是介绍JRT监听程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本次设计避免以往设计缺陷,老的主要为了保持兼容性,在用的设计就不好调了。

在这里插入图片描述

首先,接口抽象时候就不在给参数放仪器ID和处理类了,直接放仪器配置实体,接口实现想用什么属性就用什么属性,避免老方式要扩参数时候就波动接口定义,导致不兼容。
在这里插入图片描述

对返回命令取图或者上传文件等不在组串了,直接约定命令,返回查询上传数据或保存数据返回时候直接返回命令的JSON列表,再有监听提供的命令虚拟机执行命令

/*
本框架版权归属于JRT计划,任何单位或个人未经许可,不得以任何方式复制、传播、展示、发布、分发、重新分发、修改、反编译、
反向编译或以其他方式使用本框架的任何部分,包括但不限于源代码、二进制文件、文档、演示文稿、示例代码和API。
使用本框架的用户需遵守以下条款:
用户只能以个人学习和研究为目的使用本框架,不得将其用于商业用途。
用户在使用本框架时,应遵守所有适用的法律和法规,包括但不限于版权法、商标法、专利法和隐私权法。
用户在使用本框架时,应自行承担风险和责任,并确保不会侵犯任何知识产权或个人权利。
本框架的使用仅限于用户自己使用,不得将其分发给其他用户或将其用于任何形式的共享或传播。
在使用本框架时,用户应尊重和保护其他用户的隐私和个人信息,不得将其泄露给任何第三方。
违反以上条款将视为侵权行为,将采取法律手段维护JRT合法权益。*/
package JRTMachineImpl.Cmd;import java.util.List;
import JRTMachineImpl.Base.CmdDto;/*** 构造指令,监听再也不按以前固定拼串方式来实现附加功能了,转而提供一系列指令约定,让后台虚拟M按需要返回指令列表,* 由监听实现的简单指令执行虚拟机执行,从而达到解耦和实现更灵活和强大的功能*/
public class MakeCmd {/*** 添加一个SQL更新或者插入数据的指令到指令列表* @param cmdList 指令列表* @param setStatusKey 设置状态主键,有的话用该注解调用SetQryStatus设置状态* @param sql SQL语句* @param Address 连接串,如果上传要单独指定地址的话就传* @param UserName 用户名,如果上传要单独指定地址的话就传* @param UserPass 密码,如果上传要单独指定地址的话就传* @param Driver 驱动,如果上传要单独指定地址的话就传*/public static void AddSqlCmd(List<CmdDto> cmdList,String setStatusKey,String sql,String Address,String UserName,String UserPass,String Driver){CmdDto dto=new CmdDto();dto.Cmd="SQL";dto.P0=sql;dto.P1=Address;dto.P2=UserName;dto.P3=UserPass;dto.P4=Driver;dto.SetStatusKey=setStatusKey;cmdList.add(dto);}/*** 添加一个SQL更新或者插入数据的指令到指令列表* @param cmdList 指令列表* @param setStatusKey 设置状态主键,有的话用该注解调用SetQryStatus设置状态* @param sql SQL语句*/public static void AddSqlCmd(List<CmdDto> cmdList,String setStatusKey,String sql){AddSqlCmd(cmdList,setStatusKey,sql,"","","","");}/*** 添加一个写文本数据的指令到指令列表* @param cmdList 指令列表* @param setStatusKey 设置状态主键,有的话用该注解调用SetQryStatus设置状态* @param path 文本路径* @param str 写入的串* @param isAppend 是否追加* @param encode 编码 空默认系统编码,可为:UTF-8 UTF-16 ISO-8859-1 US-ASCII GB2312 GBK Big5 Shift-JIS EUC-KR Windows-1252*/public static void AddTxtCmd(List<CmdDto> cmdList,String setStatusKey,String path,String str,String isAppend,String encode){CmdDto dto=new CmdDto();dto.Cmd="TXT";dto.P0=path;dto.P1=str;dto.P2=isAppend;dto.P3=encode;dto.SetStatusKey=setStatusKey;cmdList.add(dto);}/*** 添加一个删除文件或者文件夹的指令到指令列表* @param cmdList 指令列表* @param path 路径*/public static void AddRMCmd(List<CmdDto> cmdList,String path){CmdDto dto=new CmdDto();dto.Cmd="RM";dto.P0=path;dto.SetStatusKey="";cmdList.add(dto);}/*** 添加一个拷贝文件的指令到指令列表* @param cmdList 指令列表* @param filePathOld 源文件路径* @param filePathNew 新文件路径*/public static void AddCPCmd(List<CmdDto> cmdList,String filePathOld,String filePathNew){CmdDto dto=new CmdDto();dto.Cmd="CP";dto.P0=filePathOld;dto.P1=filePathNew;dto.SetStatusKey="";cmdList.add(dto);}/*** 添加一个获取图片的指令到指令列表* @param cmdList 指令列表* @param epis 流水号* @param imgClass 图片类别代码* @param imgPath 图片路径* @param newName 新名称,不给的话就是文件名*/public static void AddGetImageCmd(List<CmdDto> cmdList,String epis,String imgClass,String imgPath,String newName){if(newName==null){newName="";}CmdDto dto=new CmdDto();dto.Cmd="GETIMAGE";dto.P0=epis;dto.P1=imgClass;dto.P2=imgPath;dto.P3=newName;dto.SetStatusKey="";cmdList.add(dto);}
}

命令执行器

/*
本框架版权归属于JRT计划,任何单位或个人未经许可,不得以任何方式复制、传播、展示、发布、分发、重新分发、修改、反编译、
反向编译或以其他方式使用本框架的任何部分,包括但不限于源代码、二进制文件、文档、演示文稿、示例代码和API。
使用本框架的用户需遵守以下条款:
用户只能以个人学习和研究为目的使用本框架,不得将其用于商业用途。
用户在使用本框架时,应遵守所有适用的法律和法规,包括但不限于版权法、商标法、专利法和隐私权法。
用户在使用本框架时,应自行承担风险和责任,并确保不会侵犯任何知识产权或个人权利。
本框架的使用仅限于用户自己使用,不得将其分发给其他用户或将其用于任何形式的共享或传播。
在使用本框架时,用户应尊重和保护其他用户的隐私和个人信息,不得将其泄露给任何第三方。
违反以上条款将视为侵权行为,将采取法律手段维护JRT合法权益。*/
package JRTMachineImpl.Cmd;import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;import JRTMachineImpl.Base.BaseDeal;
import JRTMachineImpl.Base.CmdDto;
import JRTMachineImpl.Base.ConfDto;
import JRTMachineImpl.Util.FileService;
import JRTMachineImpl.Util.LogUtils;
import JRTMachineImpl.WebService.OutValue;
import JRTMachineImpl.WebService.Parameters;
import JRTMachineImpl.WebService.WebGetData;
import JRTMachineImpl.DB.DBHelper;/*** 指令执行的虚拟机,按指令约定执行指令*/
public class CmdVM {/*** 执行指令* @param cmdList 指令列表* @param conf 监听配置* @return 返回值,正常返回空,否则返回错误*/public static String ExeCmd(List<CmdDto> cmdList, JRTMachineImpl.Base.ConfDto conf) throws Exception{//循环执行指令for(CmdDto cmd:cmdList){try {ExeOneCmd(cmd, conf);}catch (Exception ex){StringWriter stringWriter = new StringWriter();ex.printStackTrace(new PrintWriter(stringWriter));LogUtils.WriteDebugLog("执行命令异常:" + stringWriter.toString());LogUtils.WriteExceptionLog("执行命令异常", ex);}}return "";}/*** 执行指令* @param cmd 指令* @param conf 监听配置* @return 返回值,正常返回空,否则返回错误*/public static String ExeOneCmd(CmdDto cmd, JRTMachineImpl.Base.ConfDto conf) throws Exception{//执行SQLif(cmd.Cmd.equals("SQL")){ConfDto confNew=new ConfDto();confNew.Address=conf.Address;confNew.UserName=conf.UserName;confNew.UserPass=conf.UserPass;confNew.Driver=conf.Driver;//命令指定了要换驱动if(cmd.P1!=null&&!cmd.P1.isEmpty()){confNew.Address=cmd.P1;confNew.UserName=cmd.P2;confNew.UserPass=cmd.P3;confNew.Driver=cmd.P4;}JRTMachineImpl.DB.DBHelper dbHelper=new DBHelper(confNew);LogUtils.WriteDebugLog("执行SQL:"+cmd.P0);//执行SQL语句int ret=dbHelper.ExecUpdateSQL(cmd.P0);LogUtils.WriteDebugLog("执行SQL返回:"+ret);//设置状态if(ret==1&&!cmd.SetStatusKey.isEmpty()){Parameters param=new Parameters();param.P0=conf.MachID;param.P1=cmd.SetStatusKey;OutValue session = new OutValue();OutValue out = new OutValue();LogUtils.WriteDebugLog("调用:"+conf.DealProcess+"的:SetQryStatus设置状态");String setStatusRet=WebGetData.GetData(BaseDeal.WebServicAddress,conf.DealProcess,"SetQryStatus",param,session,out);LogUtils.WriteDebugLog("设置状态返回:"+setStatusRet);}}//写文件else if(cmd.Cmd.equals("TXT")){File fi=new File(cmd.P0);boolean isAppend=false;if(cmd.P2.equals("1")){isAppend=true;}String model=",模式:覆盖";if(isAppend==true){model=",模式:追加";}LogUtils.WriteDebugLog("往文件:"+cmd.P0+",写入:"+cmd.P1+model+",编码:"+cmd.P3);JRTMachineImpl.Util.TxtUtil.WriteText2File(fi,cmd.P1,isAppend,cmd.P3);//设置状态if(!cmd.SetStatusKey.isEmpty()){Parameters param=new Parameters();param.P0=conf.MachID;param.P1=cmd.SetStatusKey;OutValue session = new OutValue();OutValue out = new OutValue();LogUtils.WriteDebugLog("调用:"+conf.DealProcess+"的:SetQryStatus设置状态");String setStatusRet=WebGetData.GetData(BaseDeal.WebServicAddress,conf.DealProcess,"SetQryStatus",param,session,out);LogUtils.WriteDebugLog("设置状态返回:"+setStatusRet);}}//删除文件和目录else if(cmd.Cmd.equals("RM")){LogUtils.WriteDebugLog("删除:"+cmd.P0);JRTMachineImpl.Util.DirUtil.DeleteFileOrDir(new File(cmd.P0));}//拷贝文件else if(cmd.Cmd.equals("CP")){Path source = Paths.get(cmd.P0);Path target = Paths.get(cmd.P1);LogUtils.WriteDebugLog("拷贝:"+cmd.P0+"到:"+cmd.P1);Files.copy(source,target, StandardCopyOption.REPLACE_EXISTING);}//得到图片else if(cmd.Cmd.equals("GETIMAGE")){FileService fileService=new FileService();Parameters param=new Parameters();param.P0=conf.MachID;OutValue session = new OutValue();OutValue out = new OutValue();LogUtils.WriteDebugLog("调用:"+conf.DealProcess+"的:GetFileService得到文件服务路径");String fileServerPath=WebGetData.GetData(BaseDeal.WebServicAddress,conf.DealProcess,"GetFileService",param,session,out);LogUtils.WriteDebugLog("文件服务路径:"+fileServerPath);File fi=new File(cmd.P2);if(fi.exists()){String [] arr=fileServerPath.split("\\^");LogUtils.WriteDebugLog("准备上传:"+cmd.P2+",新名称:"+cmd.P3+",相对路径:"+arr[1]+"到:"+arr[0]);String ret=fileService.Upload(arr[0],cmd.P2,cmd.P3,arr[1]);LogUtils.WriteDebugLog("上传返回:"+ret);if(ret.isEmpty()){param=new Parameters();param.P0=conf.MachID;param.P1=cmd.P0;param.P2=cmd.P1;param.P3=fi.getName();param.P4=fi.getAbsolutePath();LogUtils.WriteDebugLog("调用:"+conf.DealProcess+"的:SaveImage保存文件路径");String saveRet=WebGetData.GetData(BaseDeal.WebServicAddress,conf.DealProcess,"SaveImage",param,session,out);LogUtils.WriteDebugLog("保存文件返回:"+saveRet);}else{LogUtils.WriteDebugLog("上传文件服务失败:"+ret);}}else{LogUtils.WriteDebugLog("文件:"+cmd.P2+"不存在");}}return "";}
}

定时上传执行命令
在这里插入图片描述

保存返回执行命令
在这里插入图片描述

仪器业务处理示例

import JRT.Core.Dto.CmdDto;
import JRT.Core.Dto.OutValue;
import JRT.Core.Util.LogUtils;
import JRT.Core.Util.MakeCmdUtil;
import JRT.Core.Util.TimeParser;
import JRTBLLBase.BaseHttpHandlerNoSession;
import JRTBLLBase.Helper;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;/*** 监听模式的仪器测试*/
public class JRTMachineTest extends BaseHttpHandlerNoSession {/*** 记录已经上传的数据*/private static HashMap<String, Boolean> hasUpData = new HashMap();/*** 保存仪器数据** @param mi        仪器主键* @param data      数据* @param epis      流水号* @param fileName  文件全名* @param DBColName 数据库列名* @param index     序号,-1为最后一行* @param P6* @param P7* @param P8* @param P9* @param P10* @param P11* @param P12* @param P13* @param Session* @param Output* @return* @throws Exception*/public String SaveData(String mi, String data, String epis, String fileName, String DBColName, String index, String P6, String P7, String P8, String P9, String P10, String P11, String P12, String P13, OutValue Session, OutValue Output) throws Exception {//先写Log测试LogUtils.WriteDebugLog("mi:" + mi + ",data:" + data + ",epis:" + epis + ",fileName:" + fileName + ",DBColName:" + DBColName);//返回的数据List<CmdDto> cmdList = new ArrayList<>();MakeCmdUtil.AddGetImageCmd(cmdList, "998", "P2", "D:\\OUT\\2.bmp", "");return Helper.Object2Json(cmdList);}/*** 得到文件服务地址供接口上传图片** @param mi* @param P1* @param P2* @param P3* @param P4* @param P5* @param P6* @param P7* @param P8* @param P9* @param P10* @param P11* @param P12* @param P13* @param Session* @param Output* @return* @throws Exception*/public String GetFileService(String mi, String P1, String P2, String P3, String P4, String P5, String P6, String P7, String P8, String P9, String P10, String P11, String P12, String P13, OutValue Session, OutValue Output) throws Exception {//返回文件服务路径return "http://localhost:8080/JRTWeb/FileService/^/zlzmach/" + TimeParser.GetNowDate();}/*** 保存文件到数据库** @param mi* @param epis* @param ImageClass* @param fileName* @param FullName* @param P5* @param P6* @param P7* @param P8* @param P9* @param P10* @param P11* @param P12* @param P13* @param Session* @param Output* @return* @throws Exception*/public String SaveImage(String mi, String epis, String ImageClass, String fileName, String FullName, String P5, String P6, String P7, String P8, String P9, String P10, String P11, String P12, String P13, OutValue Session, OutValue Output) throws Exception {//先写Log测试LogUtils.WriteDebugLog("mi:" + mi + ",epis:" + epis + ",ImageClass:" + ImageClass + ",fileName:" + fileName + ",FullName:" + FullName);return "";}/*** 查询要上传的指令** @param mi      仪器* @param P1* @param P2* @param P3* @param P4* @param P5* @param P6* @param P7* @param P8* @param P9* @param P10* @param P11* @param P12* @param P13* @param Session* @param Output* @return* @throws Exception*/public String QryUpdata(String mi, String P1, String P2, String P3, String P4, String P5, String P6, String P7, String P8, String P9, String P10, String P11, String P12, String P13, OutValue Session, OutValue Output) throws Exception {//先写Log测试LogUtils.WriteDebugLog("mi:" + mi + ",调用上传查询");//返回的数据List<CmdDto> cmdList = new ArrayList<>();//读文本仪器if (mi.equals("1")) {if (!hasUpData.containsKey("0947809")) {MakeCmdUtil.AddTxtCmd(cmdList, "0947809", "D:\\OUT\\uptxt.dttmp", "这是JRT上传的文本串", "0", "");MakeCmdUtil.AddCPCmd(cmdList, "D:\\OUT\\uptxt.dttmp", "D:\\OUT\\uptxt.dt");MakeCmdUtil.AddRMCmd(cmdList, "D:\\OUT\\uptxt.dttmp");}}//读数据库仪器else if (mi.equals("2")) {if (!hasUpData.containsKey("0947810")) {MakeCmdUtil.AddSqlCmd(cmdList, "0947810", "insert into DBUpHistory(DataCode,KeyData,DateStr,Data) values('0947809','1','这是JRT用SQL插入的数据','1')");}}MakeCmdUtil.AddGetImageCmd(cmdList, "999", "P1", "D:\\OUT\\1.bmp", "");return Helper.Object2Json(cmdList);}/*** 设置上传指令执行状态** @param mi           仪器* @param setStatusKey 设置状态的主键* @param P2* @param P3* @param P4* @param P5* @param P6* @param P7* @param P8* @param P9* @param P10* @param P11* @param P12* @param P13* @param Session* @param Output* @return* @throws Exception*/public String SetQryStatus(String mi, String setStatusKey, String P2, String P3, String P4, String P5, String P6, String P7, String P8, String P9, String P10, String P11, String P12, String P13, OutValue Session, OutValue Output) throws Exception {//先写Log测试LogUtils.WriteDebugLog("mi:" + mi + ",setStatusKey:" + setStatusKey + "设置状态");hasUpData.put(setStatusKey, true);return "";}
}

这样,一套超越以前设计的监听架构就出来了。JRT拥有Web、打印导出Client、JRT浏览器、JRTMachine、jrt运维命令、齐全了

这篇关于JRT监听程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/687941

相关文章

JAVA智听未来一站式有声阅读平台听书系统小程序源码

智听未来,一站式有声阅读平台听书系统 🌟&nbsp;开篇:遇见未来,从“智听”开始 在这个快节奏的时代,你是否渴望在忙碌的间隙,找到一片属于自己的宁静角落?是否梦想着能随时随地,沉浸在知识的海洋,或是故事的奇幻世界里?今天,就让我带你一起探索“智听未来”——这一站式有声阅读平台听书系统,它正悄悄改变着我们的阅读方式,让未来触手可及! 📚&nbsp;第一站:海量资源,应有尽有 走进“智听

EMLOG程序单页友链和标签增加美化

单页友联效果图: 标签页面效果图: 源码介绍 EMLOG单页友情链接和TAG标签,友链单页文件代码main{width: 58%;是设置宽度 自己把设置成与您的网站宽度一样,如果自适应就填写100%,TAG文件不用修改 安装方法:把Links.php和tag.php上传到网站根目录即可,访问 域名/Links.php、域名/tag.php 所有模板适用,代码就不粘贴出来,已经打

跨系统环境下LabVIEW程序稳定运行

在LabVIEW开发中,不同电脑的配置和操作系统(如Win11与Win7)可能对程序的稳定运行产生影响。为了确保程序在不同平台上都能正常且稳定运行,需要从兼容性、驱动、以及性能优化等多个方面入手。本文将详细介绍如何在不同系统环境下,使LabVIEW开发的程序保持稳定运行的有效策略。 LabVIEW版本兼容性 LabVIEW各版本对不同操作系统的支持存在差异。因此,在开发程序时,尽量使用

CSP 2023 提高级第一轮 CSP-S 2023初试题 完善程序第二题解析 未完

一、题目阅读 (最大值之和)给定整数序列 a0,⋯,an−1,求该序列所有非空连续子序列的最大值之和。上述参数满足 1≤n≤105 和 1≤ai≤108。 一个序列的非空连续子序列可以用两个下标 ll 和 rr(其中0≤l≤r<n0≤l≤r<n)表示,对应的序列为 al,al+1,⋯,ar​。两个非空连续子序列不同,当且仅当下标不同。 例如,当原序列为 [1,2,1,2] 时,要计算子序列 [

这些心智程序你安装了吗?

原文题目:《为什么聪明人也会做蠢事(四)》 心智程序 大脑有两个特征导致人类不够理性,一个是处理信息方面的缺陷,一个是心智程序出了问题。前者可以称为“认知吝啬鬼”,前几篇文章已经讨论了。本期主要讲心智程序这个方面。 心智程序这一概念由哈佛大学认知科学家大卫•帕金斯提出,指个体可以从记忆中提取出的规则、知识、程序和策略,以辅助我们决策判断和解决问题。如果把人脑比喻成计算机,那心智程序就是人脑的

uniapp设置微信小程序的交互反馈

链接:uni.showToast(OBJECT) | uni-app官网 (dcloud.net.cn) 设置操作成功的弹窗: title是我们弹窗提示的文字 showToast是我们在加载的时候进入就会弹出的提示。 2.设置失败的提示窗口和标签 icon:'error'是设置我们失败的logo 设置的文字上限是7个文字,如果需要设置的提示文字过长就需要设置icon并给

基于SpringBoot的宠物服务系统+uniapp小程序+LW参考示例

系列文章目录 1.基于SSM的洗衣房管理系统+原生微信小程序+LW参考示例 2.基于SpringBoot的宠物摄影网站管理系统+LW参考示例 3.基于SpringBoot+Vue的企业人事管理系统+LW参考示例 4.基于SSM的高校实验室管理系统+LW参考示例 5.基于SpringBoot的二手数码回收系统+原生微信小程序+LW参考示例 6.基于SSM的民宿预订管理系统+LW参考示例 7.基于

Spring Roo 实站( 一 )部署安装 第一个示例程序

转自:http://blog.csdn.net/jun55xiu/article/details/9380213 一:安装 注:可以参与官网spring-roo: static.springsource.org/spring-roo/reference/html/intro.html#intro-exploring-sampleROO_OPTS http://stati

未来工作趋势:零工小程序在共享经济中的作用

经济在不断发展的同时,科技也在飞速发展。零工经济作为一种新兴的工作模式,正在全球范围内迅速崛起。特别是在中国,随着数字经济的蓬勃发展和共享经济模式的深入推广,零工小程序在促进就业、提升资源利用效率方面显示出了巨大的潜力和价值。 一、零工经济的定义及现状 零工经济是指通过临时性、自由职业或项目制的工作形式,利用互联网平台快速匹配供需双方的新型经济模式。这种模式打破了传统全职工作的界限,为劳动

Java程序到CPU上执行 的步骤

相信很多的小伙伴在最初学习编程的时候会容易产生一个疑惑❓,那就是编写的Java代码究竟是怎么一步一步到CPU上去执行的呢?CPU又是如何执行的呢?今天跟随小编的脚步去化解开这个疑惑❓。 在学习这个过程之前,我们需要先讲解一些与本内容相关的知识点 指令 指令是指导CPU运行的命令,主要由操作码+被操作数组成。 其中操作码用来表示要做什么动作,被操作数是本条指令要操作的数据,可能是内存地址,也