Commit 70226210 authored by 赵啸非's avatar 赵啸非

Initial commit

parents
Pipeline #2816 failed with stages
*.iml
node_modules/
.idea/
*.class
target/
\ No newline at end of file
# 国产化中间件
国产化系统中间件,提供BS与硬件对接,调用方式为HTTP API方式,常驻后台,实现语言为JAVA。
\ No newline at end of file
{"cutType":0,"roteAngle":0,"cameraIndex":0,"maxPhoto":0,"ratio":"640x480"}
\ No newline at end of file
本中间件方案中采用什么组件或方式实现HTTPAPI服务,参考来源或简单代码
\ No newline at end of file
采用什么组件或方式实现HTTPAPI服务,参考来源或简单代码
成熟方式:
springMVC+sping boot+tomcat
spring系列是目前java基本通用的http服务框架模式,大多网络应用服务都采用ssm框架模式。
优点:
框架帮你完成了路由控制,业务数据转换,调度等等功能,使用会比较简单。
缺点:
体积较大,打包部署大概在70M~100M,针对小型应用有点过重。
样列:略
轻量化:
java servelt + tomcat
比较老旧的java http server 实现方案
优点:
轻量化,只需要加载几个jar包。运行tomcat容器即可。
缺点:
实现都比较老旧,开发方式会比较麻烦,需要重启熟悉路由规则配置等。
样列:https://www.jianshu.com/p/b3bad015020e
轻量化:
httpServer内部服务
优点:
简单,不需要依赖第三方框架,通过java内部实现即可。
缺点:
异常,session,路由控制等等及其它服务器稳定性功能需求都需自己实现。
样列:略
轻量化:
netty异步服务
优点:
速度快,体积小,可异步进行通信。
缺点:
开发难度高,http api也会在内部已异步handle方式进行流转
轻量化:
httpServer内部服务
优点:
简单,不需要依赖第三方框架,通过java内部实现即可。
缺点:
异常,session,路由控制等等及其它服务器稳定性功能需求都需自己实现。
样列:略
样列:
/**
* 根据Java提供的API实现Http服务器
*/
public class MyHttpServer {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// 创建HttpServer服务器,
HttpServer httpServer = HttpServer.create(new InetSocketAddress(8080), 10);
//将请求交给MyHandler处理器处理
httpServer.createContext("/", new MyHandler());
httpServer.start();
}
}
class MyHandler implements HttpHandler {
public void handle(HttpExchange httpExchange) throws IOException {
String content = "hello";
//设置响应头属性及响应信息的长度
httpExchange.sendResponseHeaders(200, content.length());
//获得输出流
OutputStream os = httpExchange.getResponseBody();
os.write(content.getBytes());
os.close();
}
}
本中间件方案中JAVA调用打印机的实现确定(来源或简单代码):
1、JAVA调用打印机方式(如:java1.4以上的awt.print)
2、JAVA打印机状态检测方式(如:snmp检测方式)
\ No newline at end of file
以下代码实现java调用打印服务遍历打印机(采用java1.4版本开始的原生打印服务),已经通过测试。
===========================================================================
--------------------------------------MyPrint.java-------------------------
import java.awt.print.*;
import javax.print.*;
class MyPrint{
public static void main(String[] args){
System.out.println("Hello World!");
//获得本台电脑连接的所有打印机
PrintService[] printServices = PrinterJob.lookupPrintServices();
if(printServices == null || printServices.length == 0) {
System.out.print("打印失败,未找到可用打印机,请检查。");
return ;
}
PrintService printService = null;
String printerName = "xx打印机";
//遍历打印机
for (int i = 0;i < printServices.length; i++) {
System.out.println(printServices[i].getName());
if (printServices[i].getName().contains(printerName)) {
printService = printServices[i];
break;
}
}
}
}
--------------------------------------MyPrint.java-------------------------
javac MyPrint.java
java MyPrint
===========================================================================
以下为网上的JAVA打印资料:
https://www.jianshu.com/p/be0456f5265d
java实现打印功能
https://blog.csdn.net/weixin_39818264/article/details/114032503?spm=1001.2101.3001.6650.5&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-114032503-blog-114158354.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-5-114032503-blog-114158354.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=6
java 打印图片_java打印程序——打印图片(不带对话框)
https://blog.csdn.net/weixin_29266007/article/details/114158354?spm=1001.2101.3001.6650.7&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-7-114158354-blog-79748598.pc_relevant_multi_platform_whitelistv3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-7-114158354-blog-79748598.pc_relevant_multi_platform_whitelistv3&utm_relevant_index=8
java打印图片_java如何调用本地打印机进行图片打印
https://blog.csdn.net/baidu_37366055/article/details/105427208?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-105427208-blog-51754068.pc_relevant_aa2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-1-105427208-blog-51754068.pc_relevant_aa2&utm_relevant_index=2
JAVA调用打印机
https://blog.csdn.net/dailuwen/article/details/51754068#:~:text=PrintService%20%E4%BD%BF%E7%94%A8%20java%20x.%20print%20%E5%8C%85%E4%B8%8B%E7%9A%84%E7%B1%BB%E6%9D%A5%20%E6%89%93%E5%8D%B0%20%EF%BC%8C%E5%8F%AF%E4%BB%A5,print.pdf%22%29%2C%20DocFlavor.BYTE_ARRAY.PDF%2C%20null%29%3B%20PrintService%20ps%20%3D%20Print%20S
JAVA 本地打印 DocFlavor、DocPrintJob job、PrintService
https://blog.csdn.net/m0_46267097/article/details/112609095
Java调用打印机打印(远程、本地皆可用)
中间件安装部署方式:
1、打包方式(如:DEB)
2、开机启动
3、安装
4、卸载
\ No newline at end of file
https://blog.csdn.net/slf_123/article/details/109466720
linux-deb安装包打包
https://blog.csdn.net/wf19930209/article/details/79277091
linux的程序打包deb
https://www.cnblogs.com/wjg123/p/14216803.html
linux软件deb打包及开机管理员自启动
https://cloud.tencent.com/developer/article/1625609
Linux设置开机启动的三种方式
-----------------------------------------------------------------------------
非deb包安装部署:
安装包(deploy.sh+xxxx.tar)
1.复制到任意目录,执行deploy.sh脚本服务部署文件。
2.脚本自动安装jdk环境,与中间件服务自启service。
This diff is collapsed.
{"siteId":21,"windowId":348,"siteName":"四川兴文经济开发区","windowName":"综合窗口(出件)"}
\ No newline at end of file
#! /bin/sh
PORT="8037"
BASEDIR=$(dirname $0)
BASEDIR=$( (
cd "$BASEDIR"
pwd
))
PROJECT_NAME="mid-platform"
MAIN_CLASS="$PROJECT_NAME"
if [ ! -n "$PORT" ]; then
echo $"Usage: $0 {port}"
exit $FAIL
fi
pid=$(ps ax | grep -i "$MAIN_CLASS" | grep java | grep -v grep | awk '{print $1}')
if [ -z "$pid" ]; then
echo "No Server running."
exit 1
fi
echo "stoping application $PROJECT_NAME......"
kill -15 ${pid}
echo "Send shutdown request to Server $PROJECT_NAME OK"
echo off
if not exist "%JAVA_HOME%\bin\java.exe" echo Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! & EXIT /B 1
set "JAVA=%JAVA_HOME%\bin\java.exe"
set BASEDIR=%~dp0
set BASEDIR="%BASEDIR:~0,-5%"
set PROJECT_NAME=@project.artifactId@
set APP_NAME=%PROJECT_NAME%-@project.version@.jar
set LOG_PATH="%BASEDIR%@profiles.log.path@/%PROJECT_NAME%"
if not exist "%LOG_PATH%" md "%LOG_PATH%"
set GC_PATH=%LOG_PATH%/gc.log
set HS_ERR_PATH=%LOG_PATH%PORT%-hs_err.log
set HEAP_DUMP_PATH=%LOG_PATH%/heap_dump.hprof
set TEMP_PATH=%LOG_PATH%/temp/
if not exist "%TEMP_PATH%" md "%TEMP_PATH%"
rem jvm启动参数
set JAVA_OPTS=-Xms512M -Xmx512M -Xss256K -XX:+UseAdaptiveSizePolicy -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:GCTimeRatio=39 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+HeapDumpOnOutOfMemoryError
set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDateStamps -Xloggc:%GC_PATH%
set JAVA_OPTS=%JAVA_OPTS% -XX:ErrorFile=%HS_ERR_PATH%
set JAVA_OPTS=%JAVA_OPTS% -XX:HeapDumpPath=%HEAP_DUMP_PATH%
rem jvm config
set JVM_CONFIG=%JVM_CONFIG% -Dapp.name=%PROJECT_NAME%
set JVM_CONFIG=%JVM_CONFIG% -Dapp.port=%PORT%
set JVM_CONFIG=%JVM_CONFIG% -Djava.io.tmpdir=%TEMP_PATH%
set JVM_CONFIG=%JVM_CONFIG% -Dbasedir=%BASEDIR%
set DEBUG_OPTS=
if ""%1"" == ""debug"" (
set DEBUG_OPTS= -Xloggc:../logs/gc.log -verbose:gc -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs
goto debug
)
set JMX_OPTS=
if ""%1"" == ""jmx"" (
set JMX_OPTS= -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9888 -Dcom.sun.management.jmxremote.ssl=FALSE -Dcom.sun.management.jmxremote.authenticate=FALSE
goto jmx
)
set "LOG_OPTS=--logging.config=%BASEDIR%/conf/logback-spring.xml"
echo "Starting the %APP_NAME%"
"%JAVA%" %JAVA_OPTS% -server %JVM_CONFIG% -jar %BASEDIR%/boot/%APP_NAME%
echo ""%JAVA%" %JAVA_OPTS% -server %JVM_CONFIG% -jar %BASEDIR%/boot/%APP_NAME% "
goto end
:debug
echo "debug"
"%JAVA%" -Xms512m -Xmx512m -server %DEBUG_OPTS% %JVM_CONFIG% -jar ../boot/%APP_NAME%
goto end
:jmx
"%JAVA%" -Xms512m -Xmx512m -server %JMX_OPTS% %JVM_CONFIG% -jar ../boot/%APP_NAME%
goto end
:end
pause
#!/bin/sh
PORT="8037"
BASEDIR=`dirname $0`/..
BASEDIR=`(cd "$BASEDIR"; pwd)`
PROJECT_NAME="mid-platform";
MAIN_CLASS="$PROJECT_NAME-1.0.0-SNAPSHOT.jar";
LOG_PATH="/opt/apps/mid-platform/logs/$PROJECT_NAME"
GC_PATH=$LOG_PATH/PROJECT_NAME"-gc.log"
HS_ERR_PATH=$LOG_PATH/PROJECT_NAME"-hs_err.log"
HEAP_DUMP_PATH=$LOG_PATH/PROJECT_NAME"-heap_dump.hprof"
TEMP_PATH=$LOG_PATH/temp/
SUCCESS=0
FAIL=9
if [ ! -n "$PORT" ]; then
echo $"Usage: $0 {port}"
exit $FAIL
fi
if [ ! -d $LOG_PATH ];
then
mkdir -p $LOG_PATH;
fi
if [ ! -d $TEMP_PATH ];
then
mkdir -p $TEMP_PATH;
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD=`which java > /dev/null 2>&1`
echo "Error: JAVA_HOME is not defined correctly."
exit $ERR_NO_JAVA
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "We cannot execute $JAVACMD"
exit $ERR_NO_JAVA
fi
if [ -e "$BASEDIR" ]
then
JAVA_OPTS="-Xms512M -Xmx1024M -Xss256K -XX:+UseAdaptiveSizePolicy -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:GCTimeRatio=39 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:$GC_PATH -XX:+HeapDumpOnOutOfMemoryError -XX:ErrorFile=$HS_ERR_PATH -XX:HeapDumpPath=$HEAP_DUMP_PATH"
fi
CLASSPATH=$CLASSPATH_PREFIX:
EXTRA_JVM_ARGUMENTS=""
cd "$BASEDIR/boot";
echo "starting application $PROJECT_NAME......"
exec "$JAVACMD" $JAVA_OPTS \
$EXTRA_JVM_ARGUMENTS \
-Dapp.name="$PROJECT_NAME" \
-Dapp.port="$PORT" \
-Dbasedir="$BASEDIR" \
-Djava.io.tmpdir=$TEMP_PATH \
-Dloader.path="file://$BASEDIR/conf,file://$BASEDIR/lib" \
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5514 \
-jar $MAIN_CLASS \
> /dev/null &
for i in {1..60}
do
jcpid=`ps -ef | grep -v "grep" | grep "$MAIN_CLASS" | grep "app.port=$PORT" | sed -n '1P' | awk '{print $2}'`
if [ $jcpid ]; then
echo "The $PROJECT_NAME start finished, PID is $jcpid"
exit $SUCCESS
else
echo "starting the application .. $i"
sleep 1
fi
done
echo "$PROJECT_NAME start failure!"
package com.mortals.xhx;
import com.mortals.framework.springcloud.boot.BaseWebApplication;
import com.mortals.xhx.swing.SwingArea;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;
//@SpringBootApplication(scanBasePackages = {"com.mortals"},exclude= {DataSourceAutoConfiguration.class})
@SpringBootApplication(scanBasePackages = {"com.mortals"},exclude={DataSourceAutoConfiguration.class})
@ServletComponentScan("com.mortals")
//@ImportResource(locations = {"classpath:config/spring-config.xml"})
public class ManagerApplication extends BaseWebApplication {
public static void main(String[] args) {
/* SpringApplication.run(ManagerApplication.class, args);*/
/* SpringApplication.run(ManagerApplication.class, args);*/
ApplicationContext ctx = new SpringApplicationBuilder(ManagerApplication.class)
.headless(false).run(args);
}
}
package com.mortals.xhx.base.framework.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Operlog {
String msg() default "";
String params() default "";
}
package com.mortals.xhx.base.framework.aspect;
import cn.hutool.extra.servlet.ServletUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.MDC;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.util.ContentCachingRequestWrapper;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 打印每个请求的入参、出参等信息
*
* @author: zxfei
* @date: 2022/4/20 9:24
*/
//@Aspect
//@Component
@Slf4j
@Order(1)
//@Profile({"default", "develop", "test"})
public class WebLogAspect {
@Pointcut("execution(public * com.mortals..*Controller.*(..))")
public void webLog() {
}
@Pointcut("execution(public * com.mortals.xhx.base.framework.exception.ExceptionHandle.*(..))")
public void exceptions() {
}
/**
* 只在进入controller时记录请求信息
*/
@Before("webLog()")
public void doBefore(JoinPoint joinPoint) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
// log.debug("请求路径 {} ,进入方法 {}", request.getRequestURI(), joinPoint.getSignature().getDeclaringTypeName() + ":" + joinPoint.getSignature().getName());
MDC.put("req", getRequestInfo(request).toJSONString());
MDC.put("startTime", String.valueOf(System.currentTimeMillis()));
}
/**
* 打印请求日志
*/
@AfterReturning(pointcut = "webLog()|| exceptions()", returning = "result")
public void afterReturning(Object result) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = attributes.getRequest();
Map<String, String> map = MDC.getCopyOfContextMap();
if (map != null&&result!=null) {
String startTime = map.getOrDefault("startTime", String.valueOf(System.currentTimeMillis()));
long takeTime = (System.currentTimeMillis() - Long.parseLong(startTime));
String req = map.getOrDefault("req", "");
if (result instanceof String) {
log.info(" \n 请求路径:{} 耗时:{}ms 客户端IP:{} \n 请求报文:{} \n 响应报文:{}\n cookies:{} "
, request.getRequestURI(), takeTime,ServletUtil.getClientIP(request), req, result);
} else {
log.info(" \n 请求路径:{} 耗时:{}ms 客户端IP:{}\n 请求报文:{} \n 响应报文:{}\n cookies:{}"
, request.getRequestURI(), takeTime,ServletUtil.getClientIP(request), req, JSON.toJSONString(result));
}
}
}
/**
* 读取请求信息,如果是表单则转换为json
*/
private JSONObject getRequestInfo(HttpServletRequest req) {
JSONObject requestInfo = new JSONObject();
try {
StringBuffer requestURL = req.getRequestURL();
requestInfo.put("requestURL", requestURL);
String method = req.getMethod();
requestInfo.put("method", method);
if (req.getQueryString() != null) {
requestInfo.put("queryString", URLDecoder.decode(req.getQueryString(), "UTF-8"));
}
String remoteAddr = req.getRemoteAddr();
requestInfo.put("remoteAddr", remoteAddr);
if (req instanceof ContentCachingRequestWrapper) {
ContentCachingRequestWrapper wrapper = (ContentCachingRequestWrapper) req;
String bodyStr = new String(wrapper.getContentAsByteArray(), StandardCharsets.UTF_8);
if (bodyStr.startsWith("{")) {
JSONObject jsonObject = JSON.parseObject(bodyStr);
requestInfo.put("requestBody", jsonObject);
}
String cookieStr = Arrays.asList(wrapper.getCookies()).stream().map(item -> JSON.toJSONString(item)).collect(Collectors.joining("|"));
requestInfo.put("cookieStr", cookieStr);
}
} catch (Exception e) {
log.error("解析请求失败", e);
requestInfo.put("parseError", e.getMessage());
}
return requestInfo;
}
}
package com.mortals.xhx.base.framework.config;
import com.mortals.framework.springcloud.config.mybatis.AbstractMybatisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
//@Configuration
//@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class MybatisConfiguration extends AbstractMybatisConfiguration {
private static Log logger = LogFactory.getLog(MybatisConfiguration.class);
// 配置类型别名
@Value("${spring.application.name:}")
private String name;
// 配置类型别名
@Value("${mybatis.root-path:}")
private String rootPath;
// 配置类型别名
@Value("${mybatis.type-aliases-package:}")
private String typeAliasesPackage;
// 配置mapper的扫描,找到所有的mapper.xml映射文件
@Value("${mybatis.mapper-locations:}")
private String mapperLocations;
// 加载全局的配置文件
@Value("${mybatis.config-location:}")
private String configLocation;
// 提供SqlSeesion
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("dataSource") DataSource dataSource) {
return super.getSqlSessionFactoryBean(dataSource);
}
@Override
public SqlSessionFactory getSqlSessionFactoryBean(DataSource dataSource) {
return null;
}
@Override
public String getTypeAliasesRootPackage() {
return rootPath;
}
@Override
public String getSqlMappers() {
return mapperLocations;
}
@Override
public String getMybatisConfig() {
return configLocation;
}
@Override
public String getTypeAliasesPackage() {
logger.info("typeAliasesPackage:"+typeAliasesPackage);
return typeAliasesPackage;
}
}
\ No newline at end of file
package com.mortals.xhx.base.framework.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.exception.AppException;
/**
* 统一异常处理
*/
@ControllerAdvice
public class ExceptionHandle {
private final static Logger log = LoggerFactory.getLogger(ExceptionHandle.class);
public static final String KEY_RESULT_CODE = "code";
public static final String KEY_RESULT_MSG = "msg";
public static final String KEY_RESULT_DATA = "data";
public static final int VALUE_RESULT_FAILURE = -1;
@ExceptionHandler(value = Exception.class)
@ResponseBody
public String handle(Exception e) {
JSONObject ret = new JSONObject();
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
if (e instanceof AppException) {
StackTraceElement stack = e.getStackTrace()[0];
log.error("[business error]=========stack message[{}],[{},method:{},line{}][{}]", e.getMessage(),
stack.getClassName(), stack.getMethodName(), stack.getLineNumber(), e.getClass().getName());
AppException ex = (AppException) e;
ret.put(KEY_RESULT_MSG, ex.getMessage());
} else {
log.error("[system error]", e);
ret.put(KEY_RESULT_MSG, "unknown exception!");
}
return ret.toJSONString();
}
}
package com.mortals.xhx.busiz.handler;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.req.ApiReqPdu;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.ApiRespPdu;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
/**
* 骨架类
* @author:
* @date: 2023/1/6 15:38
*/
@Slf4j
public abstract class BaseReqHandler<T, K> implements ReqHandler {
/**
* 处理请求
*
* @param request
* @return
*/
public ApiResp<K> process(T request) {
try {
validData(request);
return handle(request);
} catch (Throwable t) {
log.error("异常:", t);
return null;
}
}
/**
* 业务处理
*
* @param request
* @return
* @throws AppException
*/
protected abstract ApiResp<K> handle(T request) throws AppException;
private ApiRespPdu<K> getApiResponsePdu(ApiRespCodeEnum result, K data, Throwable t) {
ApiRespPdu<K> response = new ApiRespPdu<>();
response.setCode(result.getValue());
response.setMsg(ObjectUtils.isEmpty(t) ? result.getLabel() : t.getMessage());
response.setData(data);
return response;
}
/**
* 校验数据
*
* @param request
* @return
* @throws Exception
*/
protected abstract void validData(T request) throws IllegalArgumentException;
}
package com.mortals.xhx.busiz.handler;
public interface ReqHandler {
}
package com.mortals.xhx.busiz.handler.impl;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* p
*/
@Service
@Slf4j
public class BusizAssessmentReqHandler extends BaseReqHandler<String, Object> {
@Override
protected ApiResp<Object> handle(String request) throws AppException {
//todo
return null;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.CaptureResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.capture.model.File;
import com.mortals.xhx.module.capture.service.CaptureService;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 高拍仪
*
* @author: zxfei
* @date: 2024/1/2 9:51
*/
@Service
@Slf4j
public class BusizCaptureReqHandler extends BaseReqHandler<String, Void> {
@Autowired
private CaptureService captureService;
@Override
protected ApiResp<Void> handle(String waitTime) throws AppException {
Rest<List<File>> rest = captureService.getCapture(waitTime);
CaptureResp captureResp = new CaptureResp();
if (rest.getCode() == YesNoEnum.YES.getValue()) {
captureResp.setStatus(CaptureResp.SUCCESS);
captureResp.setCode(YesNoEnum.YES.getValue());
captureResp.setMessage(rest.getMsg());
captureResp.setData(rest.getData());
//captureResp.setFilelist(rest.getData());
} else {
captureResp.setCode(YesNoEnum.NO.getValue());
captureResp.setStatus(CaptureResp.FAIL);
captureResp.setMessage("高拍仪获取照片失败!");
}
log.info("【高拍仪】【执行响应】-->{}", JSON.toJSONString(captureResp));
return captureResp;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.IdCardResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.module.idCard.model.IdCardCons;
import com.mortals.xhx.module.idCard.service.IdCardService;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 身份证识别
*
* @author:
* @date: 2023/1/5 22:25
*/
@Service
@Slf4j
public class BusizIdcardRecognitionReqHandler extends BaseReqHandler<String, Void> {
@Autowired
private IdCardService idCardService;
@Override
protected ApiResp<Void> handle(String printReq) throws AppException {
IdCardCons idCardCons = new IdCardCons();
IdCardResp idCardResp = idCardService.readIdCardMessage(idCardCons);
log.info("【身份识别】【执行响应】-->{}", JSON.toJSONString(idCardResp));
return idCardResp;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.req.PrintReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.model.PrinterQueue;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 打印机列表
*
* @author:
* @date: 2023/1/5 22:25
*/
@Service
@Slf4j
public class BusizPrintListReqHandler extends BaseReqHandler<String, Void> {
@Autowired
private PrintService printService;
@Override
protected ApiResp<Void> handle(String printerName) throws AppException {
log.info("【打印机队列查询】【请求体】-->{}", printerName);
Rest<List<PrinterQueue>> rest = printService.getPrintQueue(printerName);
PrintQueueResp printQueueResp = new PrintQueueResp();
printQueueResp.setStatus(PrintListResp.SUCCESS);
printQueueResp.setMessage("success");
printQueueResp.setQueueList(rest.getData());
printQueueResp.setQueueNum(rest.getData().size() + "");
log.info("【打印列表】【执行响应】-->{}", JSON.toJSONString(printQueueResp));
return printQueueResp;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 打印机打印队列
*
* @author:
* @date: 2023/1/5 22:25
*/
@Service
@Slf4j
public class BusizPrintQueueReqHandler extends BaseReqHandler<String, Void> {
@Autowired
private PrintService printService;
@Override
protected ApiResp<Void> handle(String printReq) throws AppException {
Rest<List<Printer>> rest = printService.getPrintList();
PrintListResp printListResp = new PrintListResp();
printListResp.setStatus(PrintListResp.SUCCESS);
printListResp.setMessage("success");
printListResp.setPrinterList(rest.getData());
log.info("【打印列表】【执行响应】-->{}", JSON.toJSONString(printListResp));
return printListResp;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.req.ApiReqPdu;
import com.mortals.xhx.busiz.req.PrintReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 打印handler
*
* @author:
* @date: 2023/1/5 22:25
*/
@Service
@Slf4j
public class BusizPrintReqHandler extends BaseReqHandler<PrintReq, Void> {
@Autowired
private PrintService printService;
@Override
protected ApiResp<Void> handle(PrintReq printReq) throws AppException {
log.info("【打印】【请求体】-->{}", JSON.toJSONString(printReq));
Rest<Void> rest = printService.executePrint(printReq);
log.info("【打印】【执行响应】-->{}", JSON.toJSONString(rest));
if (rest.getCode() == Rest.SUCCESS) {
return ApiResp.ok(rest.getMsg());
} else {
return ApiResp.fail(rest.getMsg());
}
}
@Override
protected void validData(PrintReq request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.CaptureResp;
import com.mortals.xhx.busiz.rsp.SignResp;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.module.capture.service.CaptureService;
import com.mortals.xhx.module.sign.modle.File;
import com.mortals.xhx.module.sign.service.SignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 签名板
*
* @author: zhou
* @date: 2024/7/8 9:51
*/
@Service
@Slf4j
public class BusizSignReqHandler extends BaseReqHandler<String, Void> {
@Autowired
private SignService signService;
@Override
protected ApiResp<Void> handle(String waitTime) throws AppException {
SignResp signResp = signService.getSign(waitTime);
log.info("【签名板】【执行响应】-->{}", JSON.toJSONString(signResp));
return signResp;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.handler.impl;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.exception.AppException;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.SignResp;
import com.mortals.xhx.busiz.rsp.SocialResp;
import com.mortals.xhx.module.sign.service.SignService;
import com.mortals.xhx.module.social.service.SocialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 社保卡 T10三合一
*
* @author: zhou
* @date: 2024/7/15 9:51
*/
@Service
@Slf4j
public class BusizSocialReqHandler extends BaseReqHandler<String, Void> {
@Autowired
private SocialService socialService;
@Override
protected ApiResp<Void> handle(String socialType) throws AppException {
SocialResp socialResp = socialService.getSocial(socialType);
log.info("【社保卡T10三合一】【执行响应】-->{}", JSON.toJSONString(socialResp));
return socialResp;
}
@Override
protected void validData(String request) throws IllegalArgumentException {
}
}
package com.mortals.xhx.busiz.req;
import lombok.Data;
@Data
public class ApiReqPdu<T> {
/**
* 透传数据
*/
private T transmission;
}
package com.mortals.xhx.busiz.req;
import com.mortals.xhx.module.print.model.PrintContent;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 打印请求
* @author:
* @date: 2022/12/26 10:24
*/
@Data
public class PrintReq implements Serializable {
/**
* PrinterJson中增加papertype参数,为空则按以前逻辑处理
* ,为ticket、A3、A4则分别设置PrinterJson中打印机名称和宽度(按照中间件的配置来)
* papertype为空则忽略,为ticket则将printername设为小票打印机名称,
* 为a3则将printername设为A3打印机名称,
* 为a4则将printername设为A4打印机名称
*/
private String papertype;
/**
* 打印机名称,为空则为默认打印机
*/
private String printername;
/**
* 打印机纸张宽度
*/
private String printerpaperwidth;
/**
* 打印类型,url/base64/normal,
* url为网络文件打印,base64为串文件打印,normal为普通行打印
*/
private String printertype;
/**
* 打印文件网络地址,当printertype为url时有效,其它参数时可省略,网络文件地址,
* 支持doc、docx、xls、xlsx、pdf、图片文件等,但依靠windows默认对文件的打印支持
*/
private String url;
/**
* 打印base64字符串,当printertype为base64时有效,其它参数时可省略,base64串打印支持,
* 必须依靠【data:application/msword;base64,】前缀指明,支持doc、docx、xls、xlsx、pdf、txt几种格式,
* 对应前缀:【application/msword】、【application/vnd.openxmlformats-officedocument.wordprocessingml.document】、
* 【application/vnd.ms-excel】、【application/vnd.openxmlformats-officedocument.spreadsheetml.sheet】、【application/pdf】
* 、【text/plain】 增加对图片格式的支持 2021-03-09【image/gif】、【image/png】、【image/jpeg】、【image/jpg】、【image/bmp】
*/
private String base64;
/**
* 打印行集合,当printertype为normal时有效,其它参数时可省略
*/
private List<PrintContent> contents;
}
package com.mortals.xhx.busiz.req;
import com.mortals.xhx.module.print.model.PrintContent;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 签名板请求
* @author:
* @date: 2022/12/26 10:24
*/
@Data
public class SignReq implements Serializable {
/**
* HWInitialize 开始签名
* HWFinalize 结束签名
* HWClearSign 清除签名
* HWGetSign 获取签名图片
*/
private String HWPenSign;
/**
* 签名版固定设置参数
*/
private String key = "F7B040A43D80063BEBC1A8C8DC9351D5";
private String title = "请签名";
private int nOrgX = 400;
private int nOrgY = 350;
private int nWidth = 500;
private int nHeight = 300;
private int nImageWidth =250;
private int nImageHeight = 150;
private int nImageType = 3;
private int nFingerCap = 0;
private int nConfirmTimeout = 60;
}
package com.mortals.xhx.busiz.req;
import lombok.Data;
import java.io.Serializable;
/**
* 社保卡请求
* @author:
* @date: 2022/12/26 10:24
*/
@Data
public class SocialReq implements Serializable {
String function;
String pchPhotoAddr;
String iType;
}
package com.mortals.xhx.busiz.rsp;
import lombok.Data;
@Data
public class ApiResp<T> {
/**
* 成功
*/
public static final String SUCCESS = "1";
/**
* 失败
*/
public static final String FAIL = "-1";
/**
* 结果编码
*/
private String status;
/**
* 结果描述
*/
private String message;
private Integer code;
/**
* 响应数据
*/
private T data;
public static <T> ApiResp<T> ok() {
return ApiRespResult(null, SUCCESS, "操作成功");
}
public static <T> ApiResp<T> ok(T data) {
return ApiRespResult(data, SUCCESS, "操作成功");
}
public static <T> ApiResp<T> ok(String msg) {
return ApiRespResult(null, SUCCESS, msg);
}
public static <T> ApiResp<T> ok(String msg, T data) {
return ApiRespResult(data, SUCCESS, msg);
}
public static <T> ApiResp<T> fail() {
return ApiRespResult(null, FAIL, "操作失败");
}
public static <T> ApiResp<T> fail(String msg) {
return ApiRespResult(null, FAIL, msg);
}
public static <T> ApiResp<T> fail(T data) {
return ApiRespResult(data, FAIL, "操作失败");
}
public static <T> ApiResp<T> fail(String msg, T data) {
return ApiRespResult(data, FAIL, msg);
}
public static <T> ApiResp<T> fail(String code, String msg) {
return ApiRespResult(null, code, msg);
}
private static <T> ApiResp<T> ApiRespResult(T data, String code, String msg) {
ApiResp<T> ApiResp = new ApiResp<>();
ApiResp.setStatus(code);
ApiResp.setData(data);
ApiResp.setMessage(msg);
return ApiResp;
}
}
package com.mortals.xhx.busiz.rsp;
import lombok.Data;
/**
* @author karlhoo
*/
@Data
public class ApiRespPdu<T> {
/**
* 结果编码
*/
private int code;
/**
* 结果描述
*/
private String msg;
/**
* 响应数据
*/
private T data;
}
package com.mortals.xhx.busiz.rsp;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.mortals.xhx.module.capture.model.File;
import com.mortals.xhx.module.print.model.Printer;
import lombok.Data;
import java.util.List;
/**
* 高拍仪响应
* @author: zxfei
* @date: 2024/1/2 9:57
*/
@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
public class CaptureResp extends ApiResp {
/**
* 附件列表
*/
private List<File> filelist;
}
package com.mortals.xhx.busiz.rsp;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mortals.xhx.module.print.model.Printer;
import lombok.Data;
import java.util.List;
@Data
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY, getterVisibility=JsonAutoDetect.Visibility.NONE)
public class IdCardResp extends ApiResp {
private String username;
private String idcardno;
private String sex;
private String address;
private String Born;
private String GrantDept;
private String Nation;
private String UserLifeBegin;
private String UserLifeEnd;
private String PhotoFileName;
private String PhotoBase64String;
}
package com.mortals.xhx.busiz.rsp;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mortals.xhx.module.print.model.Printer;
import lombok.Data;
import java.util.List;
@Data
@JsonAutoDetect(fieldVisibility=JsonAutoDetect.Visibility.ANY, getterVisibility=JsonAutoDetect.Visibility.NONE)
public class PrintListResp extends ApiResp {
private List<Printer> PrinterList;
}
package com.mortals.xhx.busiz.rsp;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mortals.xhx.module.print.model.PrinterQueue;
import lombok.Data;
import java.util.List;
@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
public class PrintQueueResp extends ApiResp {
private List<PrinterQueue> QueueList;
private String QueueNum;
}
package com.mortals.xhx.busiz.rsp;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.mortals.xhx.module.sign.modle.File;
import lombok.Data;
import java.util.List;
/**
* 签名板响应
* @author: zhou
* @date: 2024/7/10 9:57
*/
@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
public class SignResp extends ApiResp {
/**
* 操作类型
*/
private String HWPenSign;
/**
* 错误代码
*/
private int msgID;
/**
* 错误信息
*/
private String message;
}
package com.mortals.xhx.busiz.rsp;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import lombok.Data;
/**
* 社保卡响应
* @author: zhou
* @date: 2024/7/10 9:57
*/
@Data
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE)
public class SocialResp extends ApiResp {
/**
* 错误信息
*/
private String message;
}
package com.mortals.xhx.busiz.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.busiz.req.ApiReqPdu;
import com.mortals.xhx.busiz.req.PrintReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.IdCardResp;
import com.mortals.xhx.busiz.rsp.PrintListResp;
import com.mortals.xhx.busiz.rsp.PrintQueueResp;
import com.mortals.xhx.common.code.BusizTypeEnum;
import com.mortals.xhx.module.idCard.model.IdCardCons;
import com.mortals.xhx.module.idCard.service.IdCardService;
import com.mortals.xhx.module.print.model.Printer;
import com.mortals.xhx.module.print.model.PrinterQueue;
import com.mortals.xhx.module.print.service.PrintService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/**
* api controller
*
* @author: zxfei
* @date: 2022/12/26 10:21
*/
@RestController
@Slf4j
public class ApiController extends BaseAbstractApiController {
@Autowired
private PrintService printService;
@Autowired
private IdCardService idCardService;
@RequestMapping(value = "GetHardWareInfo", method = {RequestMethod.POST, RequestMethod.GET})
public Object GetHardWareInfo(@RequestParam Map<String, Object> reqMap) {
String getType = (String) reqMap.getOrDefault("GetType", "");
String reqJson = (String) reqMap.getOrDefault("PrinterJson", "");
String printerName = (String) reqMap.getOrDefault("printerName", "");
String waitTime = (String) reqMap.getOrDefault("waitTime", "120");
String signType = (String) reqMap.getOrDefault("signType", "");
String socialType = (String) reqMap.getOrDefault("socialType", "");
log.info("getType:" + getType);
try {
switch (BusizTypeEnum.getByValue(getType)) {
case BUSIZ_CAPTURE: //高拍仪
ApiResp<Object> captureResp = handle(waitTime, "busizCaptureReqHandler");
return captureResp;
case BUSIZ_ASSESSMENT: //评价
ApiResp<Object> assessResp = handle(JSON.parseObject(reqJson, new TypeReference<PrintReq>() {
}), "busizAssessmentReqHandler");
return assessResp;
case BUSIZ_PRINT: //打印
ApiResp<Object> rest = handle(JSON.parseObject(reqJson, new TypeReference<PrintReq>() {
}), "busizPrintReqHandler");
return rest;
case BUSIZ_PRINTLIST: //打印机列表
//获取打印机列表
ApiResp<Object> printListResp = handle("", "busizPrintListReqHandler");
return printListResp;
case BUSIZ_PRINT_QUEUE: //查看指定打印机打印队列
ApiResp<Object> printQueueResp = handle(printerName, "busizPrintQueueReqHandler");
return printQueueResp;
case BUSIZ_IDCARD_RECOGNITION: //身份证读取
ApiResp<Object> idCardResp = handle("", "busizIdcardRecognitionReqHandler");
return idCardResp;
case BUSIZ_CAMERA: //双目摄像头
log.info("双目摄像头");
return null;
case BUSIZ_SIGN: //签名板
ApiResp<Object> signResp = handle(signType, "busizSignReqHandler");
return signResp;
case BUSIZ_SOCIAL: //社保卡 德卡T10三合一
ApiResp<Object> socialResp = handle(socialType, "busizSocialReqHandler");
return socialResp;
case BUSIZ_FINGER: //指纹
log.info("指纹");
return null;
}
} catch (Exception e) {
log.error("接收数据失败", e);
return ApiResp.fail(e.getMessage());
}
return ApiResp.ok();
}
}
package com.mortals.xhx.busiz.web;
import com.mortals.xhx.busiz.handler.BaseReqHandler;
import com.mortals.xhx.busiz.rsp.ApiResp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ObjectUtils;
import javax.annotation.PostConstruct;
import java.util.Map;
@Slf4j
public class BaseAbstractApiController {
private Map<String, BaseReqHandler> handlers;
@Autowired
private ApplicationContext context;
@SuppressWarnings("unchecked")
protected <T, K> ApiResp<K> handle(T apiReq, String handleName) {
BaseReqHandler reqHandler = handlers.get(handleName);
if (!ObjectUtils.isEmpty(reqHandler)) {
return reqHandler.process(apiReq);
} else {
log.warn(String.format("没有找到业务处理类 handleName:%s", handleName));
return null;
}
}
@PostConstruct
private void init() {
handlers = context.getBeansOfType(BaseReqHandler.class);
}
}
package com.mortals.xhx.common.code;
/**
* @author karlhoo
*/
public enum ApiRespCodeEnum {
/** 接收成功 */
SUCCESS(1, "接收成功"),
/** 执行失败 */
FAILED(2,"执行失败"),
;
private final Integer value;
private final String label;
ApiRespCodeEnum(Integer value, String label) {
this.value = value;
this.label = label;
}
public int getValue() {
return this.value;
}
public String getLabel() {
return this.label;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
public enum Base64TypeEnum {
// 文件类型
BASE64_FILETYPE_DOC("doc", "data:application/msword;base64"),
BASE64_FILETYPE_DOCX("docx", "data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64"),
BASE64_FILETYPE_XLS("xls", "data:application/vnd.ms-excel;base64,"),
BASE64_FILETYPE_XLSX("xlsx", "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64"),
BASE64_FILETYPE_PDF("pdf", "data:application/pdf;base64"),
BASE64_FILETYPE_PPT("ppt", "data:application/vnd.ms-powerpoint;base64"),
BASE64_FILETYPE_PPTX("pptx", "data:application/vnd.openxmlformats-officedocument.presentationml.presentation;base64"),
BASE64_FILETYPE_TXT("txt", "data:text/plain;base64"),
// 图片类型
BASE64_FILETYPE_PNG("png", "data:image/png;base64"),
BASE64_FILETYPE_JPG("jpg", "data:image/jpeg;base64"),
BASE64_FILETYPE_JPEG("jpeg", "data:image/jpeg;base64"),
BASE64_FILETYPE_GIF("gif", "data:image/gif;base64"),
BASE64_FILETYPE_SVG("svg", "data:image/svg+xml;base64"),
BASE64_FILETYPE_ICO("ico", "data:image/x-icon;base64"),
BASE64_FILETYPE_BMP("bmp", "data:image/bmp;base64"),
// 二进制流
BASE64_FILETYPE_OCTET_STREAM("octet-stream", "data:application/octet-stream;base64"),
;
private String value;
private String desc;
Base64TypeEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static Base64TypeEnum getByValue(String value) {
for (Base64TypeEnum BusizTypeEnum : Base64TypeEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (Base64TypeEnum item : Base64TypeEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 接收业务方法类
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum BusizTypeEnum {
BUSIZ_ASSESSMENT("1", "评价"),
BUSIZ_IDCARD_RECOGNITION("2", "身份证读取"),
BUSIZ_PRINT("71", "打印"),
BUSIZ_PRINTLIST("73", "打印机列表"),
BUSIZ_CAPTURE("3", "高拍仪"),
BUSIZ_PRINT_QUEUE("74", "查看指定打印机打印队列"),
BUSIZ_SIGN("61", "签名板"),
BUSIZ_CAMERA("51", "双目摄像头"),
BUSIZ_FINGER("41", "指纹"),
BUSIZ_SOCIAL("31", "社保卡"),
;
private String value;
private String desc;
BusizTypeEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static BusizTypeEnum getByValue(String value) {
for (BusizTypeEnum BusizTypeEnum : BusizTypeEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (BusizTypeEnum item : BusizTypeEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.HashMap;
import java.util.Map;
/**
* Created by chendilin on 2018/3/7.
*/
public enum OperTypeEnum {
SAVE(0,"添加"),
UPDATE(1,"更新"),
DELETE(2,"删除"),
OTHER(-1,"其它");
private int value;
private String msg;
private OperTypeEnum(int value,String msg) {
this.value = value;
this.msg = msg;
}
public int getValue() {
return this.value;
}
public static Map<String,String> getEnumMap(){
Map<String,String> resultMap = new HashMap<>();
OperTypeEnum[] operTypeEnum = OperTypeEnum.values();
for (OperTypeEnum typeEnum : operTypeEnum) {
resultMap.put(String.valueOf(typeEnum.value),typeEnum.msg);
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印纸张类型
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum PaperTypeEnum {
PAPER_TICKET("ticket", "小票"),
PAPER_A3("A3", "A3"),
PAPER_A4("A4", "A4"),
;
private String value;
private String desc;
PaperTypeEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PaperTypeEnum getByValue(String value) {
for (PaperTypeEnum BusizTypeEnum : PaperTypeEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PaperTypeEnum item : PaperTypeEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印内容类型
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum PrintAlignStyleEnum {
PRINT_LEFT("left", "居左"),
PRINT_CENTER("center", "居中"),
PRINT_RIGHT("right", "居右"),
;
private String value;
private String desc;
PrintAlignStyleEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PrintAlignStyleEnum getByValue(String value) {
for (PrintAlignStyleEnum BusizTypeEnum : PrintAlignStyleEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PrintAlignStyleEnum item : PrintAlignStyleEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印内容类型
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum PrintContentTypeEnum {
PRINT_TEXT("text", "文本"),
PRINT_PAGEING("pageing", "分页"),
PRINT_IMG("img", "图片"),
PRINT_BARCODE("barcode", "条形码"),
PRINT_QRCODE("qrcode", "二维码"),
PRINT_SEPARATE("separate", "分隔符"),
;
private String value;
private String desc;
PrintContentTypeEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PrintContentTypeEnum getByValue(String value) {
for (PrintContentTypeEnum BusizTypeEnum : PrintContentTypeEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PrintContentTypeEnum item : PrintContentTypeEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印内容类型
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum PrintFontStyleEnum {
PRINT_REGULAR("regular", "正常"),
PRINT_BOLD("bold", "粗体"),
PRINT_UNDERLINE("underline", "下划线"),
PRINT_ITALIC("italic", "斜体"),
PRINT_STRIKEOUT("strikeout", "二维码"),
;
private String value;
private String desc;
PrintFontStyleEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PrintFontStyleEnum getByValue(String value) {
for (PrintFontStyleEnum BusizTypeEnum : PrintFontStyleEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PrintFontStyleEnum item : PrintFontStyleEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印字体单位
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum PrintFontUnitEnum {
PRINT_WORLD("world", "world"),
PRINT_DISPLAY("display", "display"),
PRINT_PIXEL("pixel", "pixel"),
PRINT_POINT("point", "point"),
PRINT_INCH("inch", "inch"),
PRINT_DOCUMENT("document", "document"),
PRINT_MILLIMETER("millimeter", "millimeter"),
;
private String value;
private String desc;
PrintFontUnitEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PrintFontUnitEnum getByValue(String value) {
for (PrintFontUnitEnum BusizTypeEnum : PrintFontUnitEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PrintFontUnitEnum item : PrintFontUnitEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印类型
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum PrintTypeEnum {
PRINT_URL("url", "网络文件打印"),
PRINT_BASE64("base64", "串文件打印"),
PRINT_NORMAL("normal", "普通行打印"),
;
private String value;
private String desc;
PrintTypeEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static PrintTypeEnum getByValue(String value) {
for (PrintTypeEnum BusizTypeEnum : PrintTypeEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (PrintTypeEnum item : PrintTypeEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
public enum PublishStatusEnum implements IBaseEnum{
PRODUCT_PENDING(0, "待发布"),
PRODUCT_AUDITING(1, "审核中"),
PRODUCT_SUCESS(2, "审核通过"),
PRODUCT_REJECT(3, "审核拒绝");
private int value;
private String desc;
PublishStatusEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public static PublishStatusEnum getByValue(int value) {
for (PublishStatusEnum YesNoEnum : PublishStatusEnum.values()) {
if (YesNoEnum.getValue() == value) {
return YesNoEnum;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (PublishStatusEnum item : PublishStatusEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
/**
* 业务统一返回码
* @author linlc
*
*/
public enum ResultCodeEnum {
CODE_001(156001,"参数类型错误"),
CODE_002(156002,"部分参数为空"),
CODE_003(156003,"参数长度超过限制"),
CODE_004(156004,"日期格式错误"),
CODE_005(156005,"时间区间不合法"),
CODE_006(156006,"远端服务不可用"),
CODE_007(156007,"无效的签名"),
CODE_008(156008,"不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写"),
CODE_009(156009,"请求来源地址不合法"),
CODE_010(156010,"没有相应的用户"),
CODE_011(156011,"不合法的文件类型"),
CODE_012(156012,"不合法的文件大小"),
CODE_013(156013,"上传文件缺失"),
CODE_014(156014,"不支持的图片格式"),
CODE_015(156015,"无效的url"),
CODE_016(156016,"设备编号不合法"),
CODE_017(356017,"设备编号不存在"),
CODE_018(356018,"设备当前在线状态为“离线”,无法使用!"),
CODE_019(356019,"设备当前投放状态为“待重投”,无法使用!"),
CODE_020(356020,"设备当前投放状态为“已报废”,无法使用!"),
CODE_021(356021,"设备当前投放状态为“初始化”,无法使用!"),
CODE_022(356022,"此设备当前启用状态为“禁用”,无法使用!"),
CODE_023(356023,"API 调用太频繁,请稍候再试"),
CODE_024(256024,"用户未授权该 api"),
CODE_025(156025,"解析 JSON/XML 内容错误"),
CODE_FAILUER(-1,"失败");
private int value;
private String desc;
ResultCodeEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return value;
}
public String getDesc() {
return desc;
}
}
package com.mortals.xhx.common.code;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 角色类型
* @author
*
*/
public enum RoleType implements IBaseEnum {
/** 系统内置角色 */
BUILT_IN(0, "系统内置角色", SysConstains.STYLE_DEFAULT),
/** 默认系统角色 */
SYSTEM_DEFAULT(1, "默认系统角色", SysConstains.STYLE_INFO),
/** 企业用户角色 */
CUSTOMER_DEFAULT(2, "企业用户角色", SysConstains.STYLE_PRIMARY),
/** 普通角色 */
NORMAL(4, "普通角色 ", SysConstains.STYLE_SUCCESS),;
//0:系统内置角色(不可删除),1:默认系统角色,2:默认新闻用户角色,3:默认资讯用户角色,4:普通角色,默认4
private int value;
private String desc;
private String style;
RoleType(int value, String desc, String style) {
this.value = value;
this.desc = desc;
this.style = style;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public String getStyle()
{
return style;
}
public static RoleType getByValue(int value) {
for (RoleType examStatus : RoleType.values()) {
if (examStatus.getValue() == value) {
return examStatus;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (RoleType item : RoleType.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 站点状态
* @author
*
*/
public enum SiteSatusEnum {
DISENABLE(0, "禁用"),
ENABLE(1, "启用");
private int value;
private String desc;
SiteSatusEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public static SiteSatusEnum getByValue(int value) {
for (SiteSatusEnum examStatus : SiteSatusEnum.values()) {
if (examStatus.getValue() == value) {
return examStatus;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (SiteSatusEnum item : SiteSatusEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 资源类型
* @author
*
*/
public enum SourceType implements IBaseEnum {
/** 系统资源 */
SYSTEM(0, "系统资源", SysConstains.STYLE_DEFAULT),
/** 开放资源 */
OPEN(1, "开放资源", SysConstains.STYLE_PRIMARY);
private int value;
private String desc;
private String style;
SourceType(int value, String desc, String style) {
this.value = value;
this.desc = desc;
this.style = style;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public String getStyle()
{
return style;
}
public static SourceType getByValue(int value) {
for (SourceType examStatus : SourceType.values()) {
if (examStatus.getValue() == value) {
return examStatus;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (SourceType item : SourceType.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author
* @create 2018/01/12
*/
public enum TaskExcuteStatusEnum {
WAIT_RUN(0, "待执行"),
RUNNING(1, "执行中"),
SUCCESS_RUN(2, "执行成功"),
FAIL_RUN(3, "执行失败"),
CANCEL(4, "取消");
private int value;
private String desc;
TaskExcuteStatusEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static TaskExcuteStatusEnum getByValue(int value) {
for (TaskExcuteStatusEnum taskExcuteStatusEnum : TaskExcuteStatusEnum.values()) {
if (taskExcuteStatusEnum.getValue() == value) {
return taskExcuteStatusEnum;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (TaskExcuteStatusEnum item : TaskExcuteStatusEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
public enum TaskExcuteStrategyEnum{
/** 按日 */
DAY(1, "按日"),
/** 按周 */
WEEK(2, "按周"),
/** 按月 */
MONTH(3, "按月"),
/** 按间隔时间 */
INTERVAL(4, "按间隔时间");
private int value;
private String desc;
TaskExcuteStrategyEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public static TaskExcuteStrategyEnum getByValue(int value) {
for (TaskExcuteStrategyEnum taskExcuteStrategy : TaskExcuteStrategyEnum.values()) {
if (taskExcuteStrategy.getValue() == value) {
return taskExcuteStrategy;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (TaskExcuteStrategyEnum item : TaskExcuteStrategyEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
public enum TaskInterimExcuteStatusEnum{
/** 未启用 */
UNUSE(0, "未启用"),
/** 立即执行并保留 */
IMMEDIATE_EXECUTION(1, "立即执行并保留"),
/** 立即执行并删除 */
IMMEDIATE_EXECUTION_BEFORE_DELETE(2, "立即执行并删除");
private int value;
private String desc;
TaskInterimExcuteStatusEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public static TaskInterimExcuteStatusEnum getByValue(int value) {
for (TaskInterimExcuteStatusEnum taskInterimExcuteStatus : TaskInterimExcuteStatusEnum.values()) {
if (taskInterimExcuteStatus.getValue() == value) {
return taskInterimExcuteStatus;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (TaskInterimExcuteStatusEnum item : TaskInterimExcuteStatusEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 打印内容类型
*
* @author:
* @date: 2022/12/26 11:11
*/
public enum TicketTypeWidthEnum {
TYPE_SMALL("1", "164"),
TYPE_LARGER("2", "227");
private String value;
private String desc;
TicketTypeWidthEnum(String value, String desc) {
this.value = value;
this.desc = desc;
}
public String getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static TicketTypeWidthEnum getByValue(String value) {
for (TicketTypeWidthEnum BusizTypeEnum : TicketTypeWidthEnum.values()) {
if (BusizTypeEnum.getValue().equals(value)) {
return BusizTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(String... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (TicketTypeWidthEnum item : TicketTypeWidthEnum.values()) {
try {
boolean hasE = false;
for (String e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author: finegirl
* @date: 2021/7/16 11:50
* @description: //TODO 请完善注释信息
**/
public enum TopicalTypeEnum {
PERSONAL(1, "个人服务"),
ENTERPRISE(2, "企业服务");
private int value;
private String desc;
private TopicalTypeEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static TopicalTypeEnum getByValue(int value) {
TopicalTypeEnum[] var1 = values();
int var2 = var1.length;
for(int var3 = 0; var3 < var2; ++var3) {
TopicalTypeEnum examStatus = var1[var3];
if (examStatus.getValue() == value) {
return examStatus;
}
}
return null;
}
public static Map<String, String> getEnumMap(int... eItem) {
Map<String, String> resultMap = new LinkedHashMap();
TopicalTypeEnum[] var2 = values();
int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) {
TopicalTypeEnum item = var2[var4];
try {
boolean hasE = false;
int[] var7 = eItem;
int var8 = eItem.length;
for(int var9 = 0; var9 < var8; ++var9) {
int e = var7[var9];
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception var11) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
public enum TreeTypeEnum implements IBaseEnum{
TOPIC(0, "el-icon-folder"),
CLASSIFY (1, "el-icon-document"),
CLASSIFYOPTION(2, "el-icon-s-tools");
private int value;
private String desc;
TreeTypeEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public static TreeTypeEnum getByValue(int value) {
for (TreeTypeEnum YesNoEnum : TreeTypeEnum.values()) {
if (YesNoEnum.getValue() == value) {
return YesNoEnum;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (TreeTypeEnum item : TreeTypeEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import com.mortals.framework.common.IBaseEnum;
/**
* 上传文件类型枚举
*
* @author pengziyuan
*/
public enum UploadFileType implements IBaseEnum {
/** 表格 */
EXCEL(1, "表格", 1024 * 1023 * 100),
/** 图片 */
IMG(2, "图片", 1024 * 1024 * 10),
/** 压缩文件 */
ZIP(3, "压缩文件", 1024 * 1024 * 100),
/** PDF */
PDF(4, "PDF", 1024 * 1024 * 100),
/** 其他 */
OTHER(99, "其他", 1024 * 1024 * 100);
private int value;
private String desc;
private int maxSize;
UploadFileType(int value, String desc, int maxSize) {
this.value = value;
this.desc = desc;
this.maxSize = maxSize;
}
@Override
public int getValue() {
return this.value;
}
@Override
public String getDesc() {
return desc;
}
public int getMaxSize() {
return maxSize;
}
public static UploadFileType getFileType(String extension) {
if ("xls".equalsIgnoreCase(extension) || "xlsx".equalsIgnoreCase(extension)) {
return EXCEL;
}
if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension)
|| "gif".equalsIgnoreCase(extension)) {
return IMG;
}
if ("zip".equalsIgnoreCase(extension)) {
return ZIP;
}
if ("pdf".equalsIgnoreCase(extension)) {
return PDF;
}
return OTHER;
}
}
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* @author: finegirl
* @date: 2021/7/16 11:50
* @description: //TODO 请完善注释信息
**/
public enum UserStatus {
DISABLE(0, "停用"),
NORMAL(1, "正常"),
FROZEN(2, "冻结"),
CACCOUNT(3, "销户"),
QUIT(4, "离职");
private int value;
private String desc;
private UserStatus(int value, String desc) {
this.value = value;
this.desc = desc;
}
public int getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static UserStatus getByValue(int value) {
UserStatus[] var1 = values();
int var2 = var1.length;
for(int var3 = 0; var3 < var2; ++var3) {
UserStatus examStatus = var1[var3];
if (examStatus.getValue() == value) {
return examStatus;
}
}
return null;
}
public static Map<String, String> getEnumMap(int... eItem) {
Map<String, String> resultMap = new LinkedHashMap();
UserStatus[] var2 = values();
int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) {
UserStatus item = var2[var4];
try {
boolean hasE = false;
int[] var7 = eItem;
int var8 = eItem.length;
for(int var9 = 0; var9 < var8; ++var9) {
int e = var7[var9];
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception var11) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import com.mortals.framework.ap.SysConstains;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
public enum ValidCodeType implements IBaseEnum{
IMAGE(0, "图片校验", SysConstains.STYLE_DEFAULT),
MOBILE(1, "手机校验", SysConstains.STYLE_DEFAULT),
EMAIL(2, "邮箱校验", SysConstains.STYLE_DEFAULT);
private int value;
private String desc;
private String style;
ValidCodeType(int value, String desc, String style) {
this.value = value;
this.desc = desc;
this.style = style;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public String getStyle()
{
return style;
}
public static ValidCodeType getByValue(int value) {
for (ValidCodeType validCodeType : ValidCodeType.values()) {
if (validCodeType.getValue() == value) {
return validCodeType;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (ValidCodeType item : ValidCodeType.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.code;
import com.mortals.framework.common.IBaseEnum;
import java.util.LinkedHashMap;
import java.util.Map;
public enum YesNoEnum implements IBaseEnum{
NO(0, "否"),
YES(1, "是");
private int value;
private String desc;
YesNoEnum(int value, String desc) {
this.value = value;
this.desc = desc;
}
@Override
public int getValue() {
return this.value;
}
public String getDesc() {
return desc;
}
public static YesNoEnum getByValue(int value) {
for (YesNoEnum YesNoEnum : YesNoEnum.values()) {
if (YesNoEnum.getValue() == value) {
return YesNoEnum;
}
}
return null;
}
/**
* 获取Map集合
* @param eItem 不包含项
* @return
*/
public static Map<String,String> getEnumMap(int... eItem) {
Map<String,String> resultMap= new LinkedHashMap<String,String>();
for (YesNoEnum item : YesNoEnum.values()) {
try{
boolean hasE = false;
for (int e : eItem){
if(item.getValue()==e){
hasE = true;
break;
}
}
if(!hasE){
resultMap.put(item.getValue()+"", item.getDesc());
}
}catch(Exception ex){
}
}
return resultMap;
}
}
package com.mortals.xhx.common.key;
public final class Constant {
/**
* UTF-8 字符集
*/
public static final String UTF8 = "UTF-8";
/**
* GBK 字符集
*/
public static final String GBK = "GBK";
/**
* http请求
*/
public static final String HTTP = "http://";
}
package com.mortals.xhx.common.key;
/**
* 参数表对应key定义对应
* @author linlc
*
*/
public class ParamKey {
/** 文件访问的地址 */
public static final String FILE_URL = "iot:base:param:fileUrl";
/** 物料编码长度,默认6 */
public static final String MATERIA_CODE_LENGTH = "iot:base:param:materia:length";
}
package com.mortals.xhx.common;
public class osSelect {
public static boolean isLinux() {
return System.getProperty("os.name").toLowerCase().contains("linux");
}
public static boolean isWindows() {
return System.getProperty("os.name").toLowerCase().contains("windows");
}
}
package com.mortals.xhx.common.utils;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import org.apache.commons.codec.binary.Base64;
import com.mortals.xhx.common.code.Base64TypeEnum;
import java.io.*;
public class Base64Util {
// 获取文件转换之后的base64内容
public static String encodeBase64File(String prefix, File file) {
try {
if (file == null || !file.exists() || prefix == null) {
return null;
}
long beginTime = System.currentTimeMillis();
// base64文件前缀
String base64Format = Base64TypeEnum.getByValue(prefix.toLowerCase()).getDesc();
if (base64Format == null || "".equals(base64Format)) {
return null;
}
// 获取文件流
InputStream in = new FileInputStream(file);
BufferedInputStream bufInput = new BufferedInputStream(in); // 缓存流
// 先把二进制流写入到ByteArrayOutputStream中
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
byte[] bt = new byte[4096];
int len;
while ((len = bufInput.read(bt)) != -1) {
byteArray.write(bt, 0, len);
}
byteArray.flush();
long endTime = System.currentTimeMillis();
System.out.println("==>encodeBase64File, 把文件转换成base64编码, 总耗时: " + (endTime - beginTime) + "ms");
// 返回
return base64Format+"," + Base64.encodeBase64String(byteArray.toByteArray());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
// 把base64文件解码
public static void decodeBase64(String destFile, String base64String) {
try {
long beginTime = System.currentTimeMillis();
// 把base64字符串转换成字节
byte[] bytes = Base64.decodeBase64(base64String);
FileUtil.writeBytes(bytes,destFile);
/*
// 转换成字节输入流
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
OutputStream out = new FileOutputStream(destFile);
// 写文件
byte[] buffer = new byte[4096];
int len = 0;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len); // 文件写操作
}
*/
long endTime = System.currentTimeMillis();
System.out.println("==>decodeBase64String, 解析base64编码文件, 总耗时: " + (endTime - beginTime) + "ms");
} catch (IORuntimeException e) {
e.printStackTrace();
}
}
// 把base64文件解码
public static String decodeBase64String(String prefix, String base64String) {
try {
if (prefix == null || base64String == null) {
return null;
}
long beginTime = System.currentTimeMillis();
// 把base64前缀截取掉
// base64文件前缀
String value = Base64TypeEnum.getByValue(prefix.toLowerCase()).getDesc();
if (value == null || "".equals(value)) {
return null;
}
// 替换
String tempBase64String = base64String.replace(value, "");
// 把base64字符串转换成字节
byte[] bytes = Base64.decodeBase64(tempBase64String);
// 转换成字节输入流
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
// 把base64编码文件还原, 并存放到指定磁盘路径中
OutputStream out = new FileOutputStream(new File("D:\\new_test." + prefix));
// 写文件
byte[] buffer = new byte[4096];
int len = 0;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len); // 文件写操作
}
long endTime = System.currentTimeMillis();
System.out.println("==>decodeBase64String, 解析base64编码文件, 总耗时: " + (endTime - beginTime) + "ms");
return "success";
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
// 获取文件, 对文件base64编码
File file = new File("F:\\test.txt");
String prefix = "txt";
// base64文件内容
String base64String = Base64Util.encodeBase64File(prefix, file);
System.out.println("文件base64加密之后的内容(太长, 控制台可能打印不出来): \n" + base64String);
// 获取base64文件, 进行解码
Base64Util.decodeBase64String(prefix, base64String);
}
}
package com.mortals.xhx.common.utils;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
public class BeanUtil {
protected static Logger log = LoggerFactory.getLogger(BeanUtil.class);
public static <SOURCE, TARGET> List<TARGET> covertList(List<SOURCE> srcList, Class<TARGET> clazz) {
List<TARGET> retList = new ArrayList<>();
if (srcList == null || srcList.isEmpty()) {
return retList;
}
for (SOURCE source : srcList) {
TARGET target;
try {
target = clazz.newInstance();
if (source == null) {
continue;
}
BeanUtils.copyProperties(source, target);
retList.add(target);
} catch (InstantiationException | IllegalAccessException e) {
log.error("", e);
}
}
return retList;
}
public static <SOURCE, TARGET> TARGET covert(SOURCE source, Class<TARGET> clazz) {
TARGET target = null;
if (source == null) {
return target;
}
try {
target = clazz.newInstance();
BeanUtils.copyProperties(source, target);
} catch (InstantiationException | IllegalAccessException e) {
log.error("", e);
}
return target;
}
@SuppressWarnings({ "rawtypes", "unused", "unchecked" })
public static final Map entityToMap(Object entity) {
Map map = new HashMap<>();
try {
Class cls = entity.getClass();
BeanInfo beanInfo = Introspector.getBeanInfo(cls);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
if (!propertyName.equals("class") && !propertyName.equals("orderCols")
&& !propertyName.equals("notSelectCols") && !propertyName.equals("symbolCols")
&& !propertyName.equals("vague")) {
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(entity, new Object[0]);
if (result != null) {
String className = result.getClass().getSimpleName();
map.put(propertyName, result);
/*
* if(result instanceof String){
* if(((String)result).trim().length() > 0){
* map.put(propertyName, result); } }else{
* map.put(propertyName, result); }
*/
}
}
}
} catch (Exception e) {
log.warn("将对象转换成Map异常-->" + entity + "-->" + e.getMessage());
}
return map;
}
public static final <T> T mapToEntity(Map<?, ?> map, Class<T> clz) {
T target = null;
try {
target = clz.newInstance();
BeanInfo beanInfo = Introspector.getBeanInfo(clz);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
if (map.containsKey(propertyName)) {
Object value = map.get(propertyName);
Object[] args = new Object[1];
args[0] = value;
descriptor.getWriteMethod().invoke(target, args);
}
}
} catch (Exception e) {
log.warn("将Map转换成对象异常-->" + clz + "-->" + e.getMessage());
}
return target;
}
/**
*
* @Title: getNullPropertyNames
* @Description: 获取一个对象中属性值为null的属性名字符串数组
* @param source
* @return
*/
public static String[] getNullPropertyNames (Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for(java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
/**
*      * 校验特殊字符
*      * @param str
*      * @return
*      
*/
public static boolean isConSpeChar(String str) {
String regEx = "[`~'\"?~?]";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(str);
return m.find();
}
public static void main(String[] args) {
String str="'";
System.out.println(BeanUtil.isConSpeChar(str));
ObjectMapper mapper = new ObjectMapper();
//Map<String, String> map = mapper.readValue(json, Map.class);
}
}
package com.mortals.xhx.common.utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
/**
* 自定义编码、解码
*/
//加密过程:原文->base64->aes(1234567812345678)->des(12345678)->倒序(9位)->base64
//解密:base64->倒序(9位)->des(12345678)->aes(1234567812345678)->base64->原文
@Slf4j
public class EncryptUtil {
public static final String ALGORITHM = "AES/ECB/PKCS5Padding";
/**
* 字符串转换为Base64
*
* @param text
* @return
*/
public static String toBase64(String text) {
Base64 base64 = new Base64();
try {
return base64.encodeToString(text.getBytes("utf-8")).trim().replace("\n", "");
} catch (UnsupportedEncodingException e) {
log.error("字符串转换为Base64[{}]异常", e);
}
return null;
}
/**
* Base64转换为字符串
*
* @param text
* @return
*/
private static String base64ToString(String text) {
Base64 base64 = new Base64();
try {
return new String(base64.decode(text.getBytes("utf-8")), "UTF-8").trim().replace("\n", "");
} catch (UnsupportedEncodingException e) {
log.error("Base64转换为字符串[{}]异常", e);
}
return null;
}
/**
* AES加密+Base64转码
*
* @param data 明文(16进制)
* @param key 密钥
* @return
*/
public static String encrypt(String data, String key) {
try {
byte[] keys = key.getBytes("utf-8");
// 明文
SecretKeySpec sKeySpec = new SecretKeySpec(keys, "AES");
//Cipher cipher = Cipher.getInstance(ALGORITHM, "BC");
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, sKeySpec);
byte[] bjiamihou = cipher.doFinal(data.getBytes("utf-8"));
// byte加密后,密文用base64加密;
String miKey = Base64.encodeBase64String(bjiamihou);
return miKey;
} catch (Exception e) {
e.printStackTrace();
log.error("AES加密[{}]异常", e);
}
return null;
}
/**
* Base64解码 + AES解码
*
* @param data 密文 (16进制)
* @param key 密钥
* @return
*/
public static String decrypt(String data, String key) {
try {
byte[] keys = key.getBytes("utf-8");
byte[] datas = Base64.decodeBase64(data);
SecretKeySpec sKeySpec = new SecretKeySpec(keys, "AES");
//Cipher cipher = Cipher.getInstance(ALGORITHM, "BC");
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, sKeySpec);
byte[] bjiemihou = cipher.doFinal(datas);
// byte加密后
String miKey = new String(bjiemihou, "utf-8");
return miKey;
} catch (Exception e) {
log.error("AES解码[{}]异常", e);
}
return null;
}
/**
* 转化为String
*
* @param buf
* @return
*/
private static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 将16进制转换为二进制
*
* @param hexStr
* @return
*/
private static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
/**
* DES加密(使用DES算法)
*
* @param message 需要加密的文本
* @param key 密钥
* @return 成功加密的文本
*/
public static String toDesString(String key, String message) throws Exception {
try {
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv);
return parseByte2HexStr(cipher.doFinal(message.getBytes("UTF-8")));
} catch (Exception e) {
log.error("DES加密[{}]异常", e);
}
return null;
}
/**
* DES解密(使用DES算法)
*
* @param message 需要解密的文本
* @param key 密钥
* @return 成功加密的文本
*/
public static String desToString(String key, String message) throws Exception {
try {
byte[] bytesrc = parseHexStr2Byte(message);//convertHexString(message);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes("UTF-8"));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
IvParameterSpec iv = new IvParameterSpec(key.getBytes("UTF-8"));
cipher.init(Cipher.DECRYPT_MODE, secretKey, iv);
byte[] retByte = cipher.doFinal(bytesrc);
return new String(retByte);
} catch (Exception e) {
log.error("DES解密[{}]异常", e);
}
return null;
}
public static byte[] convertHexString(String ss) {
byte digest[] = new byte[ss.length() / 2];
for (int i = 0; i < digest.length; i++) {
String byteString = ss.substring(2 * i, 2 * i + 2);
int byteValue = Integer.parseInt(byteString, 16);
digest[i] = (byte) byteValue;
}
return digest;
}
public static String toHexString(byte b[]) {
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < b.length; i++) {
String plainText = Integer.toHexString(0xff & b[i]);
if (plainText.length() < 2)
plainText = "0" + plainText;
hexString.append(plainText);
}
return hexString.toString();
}
/**
* 倒序处理,每orderNum位进行倒序排列
*
* @param sourceString 为需要加密的串
* @param orderNum 为每x位进行倒序排列
* @return
*/
public static String toReverseString(int orderNum, String sourceString) {
String csFive = "", encrypted2 = "";
for (int i = 0; i < sourceString.length(); i++) {
csFive = csFive + sourceString.charAt(i);
if ((i + 1) % orderNum == 0 || (i + 1) >= sourceString.length()) {
String csFive2 = "";
for (int j = 0; j < csFive.length(); j++) {
csFive2 = csFive2 + csFive.charAt(csFive.length() - 1 - j);
}
encrypted2 += csFive2;
csFive = "";
}
}
return encrypted2;
}
/**
* 加密
*
* @return
*/
public static String myEnscrt(String sourceString, int orderNum, String desKey, String aesKey) throws Exception {
//加密过程:原文->base64->aes(1234567812345678)->des(12345678)->倒序(9位)->base64
String base64String = toBase64(sourceString);
String aesString = encrypt(base64String, aesKey);
//System.out.println("aseString==="+aesString);
String desString = toDesString(desKey, aesString);
String reverseString = toReverseString(orderNum, desString);
String result = toBase64(reverseString);
return result;
}
/**
* 解密
*
* @return
*/
public static String myReEnscrt(String targetString, int orderNum, String desKey, String aesKey) throws Exception {
//解密:base64->倒序(9位)->des(12345678)->aes(1234567812345678)->base64->原文
String reverseString = base64ToString(targetString);
//System.out.println("reverseString"+reverseString);
String desString = toReverseString(orderNum, reverseString);
//System.out.println("desString"+desString);
String aesString = desToString(desKey, desString);
// System.out.println("aesString"+aesString);
String base64String = decrypt(aesString, aesKey);
// System.out.println("base64String"+base64String);
String result = base64ToString(base64String);
return result;
}
public static void main(String[] args) {
try {
String s = EncryptUtil.myEnscrt("7E:20:F5:32:60:6A", 9, "FZV1D&tr", "w4*KbUamPdZDnDpG");
System.out.println("a===="+ s);
String sa = EncryptUtil.myReEnscrt(s, 9, "FZV1D&tr", "w4*KbUamPdZDnDpG");
System.out.println("sa===="+sa);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.mortals.xhx.common.utils;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
public class GetRequestJsonUtils {
public static JSONObject getRequestJsonObject(HttpServletRequest request) throws IOException {
String json = getRequestJsonString(request);
return JSONObject.parseObject(json);
}
/***
* 获取 request 中 json 字符串的内容
*
* @param request
* @return : <code>byte[]</code>
* @throws IOException
*/
public static String getRequestJsonString(HttpServletRequest request)
throws IOException {
String submitMehtod = request.getMethod();
// GET
if (submitMehtod.equals("GET")) {
return new String(request.getQueryString().getBytes("iso-8859-1"), "utf-8").replaceAll("%22", "\"");
// POST
} else {
return getRequestPostStr(request);
}
}
/**
* 描述:获取 post 请求的 byte[] 数组
* <pre>
* 举例:
* </pre>
*
* @param request
* @return
* @throws IOException
*/
public static byte[] getRequestPostBytes(HttpServletRequest request)
throws IOException {
int contentLength = request.getContentLength();
if (contentLength < 0) {
return null;
}
byte buffer[] = new byte[contentLength];
for (int i = 0; i < contentLength; ) {
int readlen = request.getInputStream().read(buffer, i,
contentLength - i);
if (readlen == -1) {
break;
}
i += readlen;
}
return buffer;
}
/**
* 描述:获取 post 请求内容
* <pre>
* 举例:
* </pre>
*
* @param request
* @return
* @throws IOException
*/
public static String getRequestPostStr(HttpServletRequest request)
throws IOException {
byte buffer[] = getRequestPostBytes(request);
String charEncoding = request.getCharacterEncoding();
if (charEncoding == null) {
charEncoding = "UTF-8";
}
return new String(buffer, charEncoding);
}
}
package com.mortals.xhx.common.utils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class ImgUtils {
public static void removeBackground(String imgUrl, String resUrl){
//定义一个临界阈值
int threshold = 300;
try{
BufferedImage img = ImageIO.read(new File(imgUrl));
int width = img.getWidth();
int height = img.getHeight();
for(int i = 1;i < width;i++){
for (int x = 0; x < width; x++){
for (int y = 0; y < height; y++){
Color color = new Color(img.getRGB(x, y));
System.out.println("red:"+color.getRed()+" | green:"+color.getGreen()+" | blue:"+color.getBlue());
int num = color.getRed()+color.getGreen()+color.getBlue();
if(num >= threshold){
img.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
}
for(int i = 1;i<width;i++){
Color color1 = new Color(img.getRGB(i, 1));
int num1 = color1.getRed()+color1.getGreen()+color1.getBlue();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
Color color = new Color(img.getRGB(x, y));
int num = color.getRed()+color.getGreen()+color.getBlue();
if(num==num1){
img.setRGB(x, y, Color.BLACK.getRGB());
}else{
img.setRGB(x, y, Color.WHITE.getRGB());
}
}
}
}
File file = new File(resUrl);
if (!file.exists())
{
File dir = file.getParentFile();
if (!dir.exists())
{
dir.mkdirs();
}
try
{
file.createNewFile();
}
catch (IOException e)
{
e.printStackTrace();
}
}
ImageIO.write(img, "jpg", file);
}catch (Exception e){
e.printStackTrace();
}
}
public static void cuttingImg(String imgUrl){
try{
File newfile=new File(imgUrl);
BufferedImage bufferedimage=ImageIO.read(newfile);
int width = bufferedimage.getWidth();
int height = bufferedimage.getHeight();
if (width > 52) {
bufferedimage=ImgUtils.cropImage(bufferedimage,(int) ((width - 52) / 2),0,(int) (width - (width-52) / 2),(int) (height));
if (height > 16) {
bufferedimage=ImgUtils.cropImage(bufferedimage,0,(int) ((height - 16) / 2),52,(int) (height - (height - 16) / 2));
}
}else{
if (height > 16) {
bufferedimage=ImgUtils.cropImage(bufferedimage,0,(int) ((height - 16) / 2),(int) (width),(int) (height - (height - 16) / 2));
}
}
ImageIO.write(bufferedimage, "jpg", new File(imgUrl));
}catch (IOException e){
e.printStackTrace();
}
}
public static BufferedImage cropImage(BufferedImage bufferedImage, int startX, int startY, int endX, int endY) {
int width = bufferedImage.getWidth();
int height = bufferedImage.getHeight();
if (startX == -1) {
startX = 0;
}
if (startY == -1) {
startY = 0;
}
if (endX == -1) {
endX = width - 1;
}
if (endY == -1) {
endY = height - 1;
}
BufferedImage result = new BufferedImage(endX - startX, endY - startY, 4);
for (int x = startX; x < endX; ++x) {
for (int y = startY; y < endY; ++y) {
int rgb = bufferedImage.getRGB(x, y);
result.setRGB(x - startX, y - startY, rgb);
}
}
return result;
}
}
\ No newline at end of file
This diff is collapsed.
package com.mortals.xhx.daemon.applicationservice;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.net.NetUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.springcloud.service.IApplicationStartedService;
import com.mortals.framework.util.ThreadPool;
import com.mortals.xhx.daemon.applicationservice.model.DestInfo;
import lombok.extern.slf4j.Slf4j;
import org.pcap4j.core.PcapAddress;
import org.pcap4j.core.PcapNetworkInterface;
import org.pcap4j.core.Pcaps;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.Set;
//@Component
@Slf4j
public class CaptureStartedService implements IApplicationStartedService {
@Override
public void start() {
log.info("启动抓取网卡数据服务..");
ThreadPool.getInstance().init(20);
List<PcapNetworkInterface> allDevs = null;
try {
allDevs = Pcaps.findAllDevs();
for (final PcapNetworkInterface device : allDevs) {
String localHost = "127.0.0.1";
List<PcapAddress> addresses = device.getAddresses();
Boolean bool=false;
for (PcapAddress pcapAddress : addresses) {
// 获取网卡IP地址
String ip = pcapAddress.getAddress().getHostAddress();
// log.info("device"+JSON.toJSONString(device) + " ip:" + ip+" is local ipw:"+ JSON.toJSONString( NetUtil.localIps()));
//非本地网卡
boolean ipv4 = Validator.isIpv4(ip);
// log.info("deviceName:{},ip:{}, is ipv4:{}",device.getName(),ip ,ipv4);
if (ip != null && ip.contains(localHost)) {
bool=true;
break;
// 返回指定的设备对象
//return networkInterface;
}
if(!ipv4){
bool=true;
break;
}
}
if ("any".indexOf(device.getName()) != -1) {
continue;
}
if(!bool){
log.info("excloud device:{}",device.getName());
continue;
}
//log.info("deviceName:{},ip:{}, is ipv4:{}",device.getName(),ip ,ipv4);
Map<String, Set<String>> filterMap = DestInfo.build();
String redirectUrl = "";
CaptureThread captureThread = new CaptureThread(device, redirectUrl, filterMap);
ThreadPool.getInstance().execute(captureThread);
}
} catch (Exception e) {
log.error("启动抓取网卡服务异常:", e);
}
}
@Override
public void stop() {
log.info("停止服务..");
}
@Override
public int getOrder() {
return 10;
}
}
package com.mortals.xhx.daemon.applicationservice.model;
import cn.hutool.core.util.XmlUtil;
import lombok.Data;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import java.io.InputStream;
import java.util.*;
/**
* 目标服务信息
*
* @author: zxfei
* @date: 2021/11/2 20:12
* @description:
**/
@Data
public class DestInfo {
private String SendServerIp;
private Integer SendServerPort;
private String SendServerPath;
public static Map<String, Set<String>> build() {
Map<String, Set<String>> filterMap = new HashMap<>();
List<DestInfo> destInfos = new ArrayList<>();
ClassLoader classLoader = DestInfo.class.getClassLoader();
InputStream in = classLoader.getResourceAsStream("capture.xml");
//解析
Document document = XmlUtil.readXML(in);
NodeList nodeListByXPath = XmlUtil.getNodeListByXPath("/Captures//Capture//SendServerIp", document);
NodeList nodeListByXPath1 = XmlUtil.getNodeListByXPath("/Captures//Capture//SendServerPort", document);
NodeList nodeListByXPath2 = XmlUtil.getNodeListByXPath("/Captures//Capture//SendServerPath", document);
Set<String> set = new HashSet<>();
Set<String> set1 = new HashSet<>();
Set<String> set2 = new HashSet<>();
for (int i = 0; i < nodeListByXPath.getLength(); i++) {
set.add(nodeListByXPath.item(i).getTextContent());
set1.add(nodeListByXPath1.item(i).getTextContent());
set2.add(nodeListByXPath2.item(i).getTextContent());
}
filterMap.put("SendServerIp", set);
filterMap.put("SendServerPort", set1);
filterMap.put("SendServerPath", set2);
return filterMap;
}
}
package com.mortals.xhx.module.capture;
import com.mortals.xhx.common.osSelect;
import com.mortals.xhx.module.idCard.service.TMZParseSDK;
import com.mortals.xhx.module.idCard.service.TMZSDK;
import com.sun.jna.Native;
import lombok.extern.slf4j.Slf4j;
/**
* 高拍仪初始化
*
* @author: ZYW
* @date: 2024/01/24 09:59
*/
@Slf4j
public class CaptureMain {
}
This diff is collapsed.
package com.mortals.xhx.module.demo;
public interface BackCategoryRepository {
String getBackCategoryDetail(long backCategoryId);
}
package com.mortals.xhx.module.demo;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
@Component
@ConditionalOnProperty(prefix="config",name = "data", havingValue = "one")
public class BackCategoryRepositoryImpl implements BackCategoryRepository {
@Override
public String getBackCategoryDetail(long backCategoryId) {
return "one";
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment