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

相关文章

python编写朋克风格的天气查询程序

《python编写朋克风格的天气查询程序》这篇文章主要为大家详细介绍了一个基于Python的桌面应用程序,使用了tkinter库来创建图形用户界面并通过requests库调用Open-MeteoAPI... 目录工具介绍工具使用说明python脚本内容如何运行脚本工具介绍这个天气查询工具是一个基于 Pyt

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Python程序打包exe,单文件和多文件方式

《Python程序打包exe,单文件和多文件方式》:本文主要介绍Python程序打包exe,单文件和多文件方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python 脚本打成exe文件安装Pyinstaller准备一个ico图标打包方式一(适用于文件较少的程

Python程序的文件头部声明小结

《Python程序的文件头部声明小结》在Python文件的顶部声明编码通常是必须的,尤其是在处理非ASCII字符时,下面就来介绍一下两种头部文件声明,具有一定的参考价值,感兴趣的可以了解一下... 目录一、# coding=utf-8二、#!/usr/bin/env python三、运行Python程序四、

Kotlin Compose Button 实现长按监听并实现动画效果(完整代码)

《KotlinComposeButton实现长按监听并实现动画效果(完整代码)》想要实现长按按钮开始录音,松开发送的功能,因此为了实现这些功能就需要自己写一个Button来解决问题,下面小编给大... 目录Button 实现原理1. Surface 的作用(关键)2. InteractionSource3.

无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案

《无法启动此程序因为计算机丢失api-ms-win-core-path-l1-1-0.dll修复方案》:本文主要介绍了无法启动此程序,详细内容请阅读本文,希望能对你有所帮助... 在计算机使用过程中,我们经常会遇到一些错误提示,其中之一就是"api-ms-win-core-path-l1-1-0.dll丢失

SpringBoot后端实现小程序微信登录功能实现

《SpringBoot后端实现小程序微信登录功能实现》微信小程序登录是开发者通过微信提供的身份验证机制,获取用户唯一标识(openid)和会话密钥(session_key)的过程,这篇文章给大家介绍S... 目录SpringBoot实现微信小程序登录简介SpringBoot后端实现微信登录SpringBoo

uniapp小程序中实现无缝衔接滚动效果代码示例

《uniapp小程序中实现无缝衔接滚动效果代码示例》:本文主要介绍uniapp小程序中实现无缝衔接滚动效果的相关资料,该方法可以实现滚动内容中字的不同的颜色更改,并且可以根据需要进行艺术化更改和自... 组件滚动通知只能实现简单的滚动效果,不能实现滚动内容中的字进行不同颜色的更改,下面实现一个无缝衔接的滚动

Java使用WebView实现桌面程序的技术指南

《Java使用WebView实现桌面程序的技术指南》在现代软件开发中,许多应用需要在桌面程序中嵌入Web页面,例如,你可能需要在Java桌面应用中嵌入一部分Web前端,或者加载一个HTML5界面以增强... 目录1、简述2、WebView 特点3、搭建 WebView 示例3.1 添加 JavaFX 依赖3

防止SpringBoot程序崩溃的几种方式汇总

《防止SpringBoot程序崩溃的几种方式汇总》本文总结了8种防止SpringBoot程序崩溃的方法,包括全局异常处理、try-catch、断路器、资源限制、监控、优雅停机、健康检查和数据库连接池配... 目录1. 全局异常处理2. 使用 try-catch 捕获异常3. 使用断路器4. 设置最大内存和线