工单模块
This commit is contained in:
@@ -30,16 +30,6 @@
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MyBatis (用于类型处理器) -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<!-- Spring Boot (用于加密工具) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
package org.xyzh.common.utils.crypto;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* MyBatis 加密字段类型处理器
|
||||
* 自动对数据库字段进行加密/解密
|
||||
*
|
||||
* 使用方式:
|
||||
* 在实体类字段上添加注解:
|
||||
* @TableField(typeHandler = EncryptedStringTypeHandler.class)
|
||||
* private String phone;
|
||||
*
|
||||
* @author yslg
|
||||
* @since 2025-12-05
|
||||
*/
|
||||
@MappedTypes({String.class})
|
||||
public class EncryptedStringTypeHandler extends BaseTypeHandler<String> {
|
||||
|
||||
private static AesEncryptUtil aesEncryptUtil;
|
||||
|
||||
/**
|
||||
* 设置加密工具(由 Spring 注入)
|
||||
*/
|
||||
public static void setAesEncryptUtil(AesEncryptUtil util) {
|
||||
aesEncryptUtil = util;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
|
||||
// 写入数据库时加密
|
||||
if (aesEncryptUtil != null && parameter != null) {
|
||||
ps.setString(i, aesEncryptUtil.encrypt(parameter));
|
||||
} else {
|
||||
ps.setString(i, parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
// 从数据库读取时解密
|
||||
String encrypted = rs.getString(columnName);
|
||||
return decrypt(encrypted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String encrypted = rs.getString(columnIndex);
|
||||
return decrypt(encrypted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String encrypted = cs.getString(columnIndex);
|
||||
return decrypt(encrypted);
|
||||
}
|
||||
|
||||
private String decrypt(String encrypted) {
|
||||
if (aesEncryptUtil != null && encrypted != null && !encrypted.isEmpty()) {
|
||||
try {
|
||||
return aesEncryptUtil.decrypt(encrypted);
|
||||
} catch (Exception e) {
|
||||
// 如果解密失败,可能是旧数据,返回原值
|
||||
return encrypted;
|
||||
}
|
||||
}
|
||||
return encrypted;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package org.xyzh.common.utils.crypto;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* TypeHandler 配置类
|
||||
* 用于初始化 EncryptedStringTypeHandler 中的 AesEncryptUtil
|
||||
*
|
||||
* @author yslg
|
||||
* @since 2025-12-11
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(AesEncryptUtil.class)
|
||||
public class TypeHandlerConfig {
|
||||
|
||||
private final AesEncryptUtil aesEncryptUtil;
|
||||
|
||||
@Autowired(required = false)
|
||||
public TypeHandlerConfig(AesEncryptUtil aesEncryptUtil) {
|
||||
this.aesEncryptUtil = aesEncryptUtil;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// 初始化 TypeHandler 中的静态 AesEncryptUtil 实例
|
||||
if (aesEncryptUtil != null) {
|
||||
EncryptedStringTypeHandler.setAesEncryptUtil(aesEncryptUtil);
|
||||
System.out.println("✓ TypeHandler 已初始化 AES 加密工具");
|
||||
} else {
|
||||
System.err.println("警告: AesEncryptUtil 未能注入,加密功能可能无法正常工作");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package org.xyzh.common.utils.json;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @description FastJSON2 JSONObject 类型处理器
|
||||
* @filename FastJson2TypeHandler.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2025-12-09
|
||||
*/
|
||||
@MappedTypes({JSONObject.class})
|
||||
public class FastJson2TypeHandler extends BaseTypeHandler<JSONObject> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setString(i, parameter.toJSONString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String jsonString = rs.getString(columnName);
|
||||
return parseToJSONObject(jsonString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String jsonString = rs.getString(columnIndex);
|
||||
return parseToJSONObject(jsonString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String jsonString = cs.getString(columnIndex);
|
||||
return parseToJSONObject(jsonString);
|
||||
}
|
||||
|
||||
private JSONObject parseToJSONObject(String jsonString) {
|
||||
if (jsonString == null || jsonString.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return JSON.parseObject(jsonString);
|
||||
} catch (Exception e) {
|
||||
// 如果解析失败,返回一个空的JSONObject
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package org.xyzh.common.utils.json;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description PostgreSQL VARCHAR数组类型处理器
|
||||
* @filename StringArrayTypeHandler.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2025-12-15
|
||||
*/
|
||||
@MappedTypes({List.class})
|
||||
public class StringArrayTypeHandler extends BaseTypeHandler<List<String>> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, List<String> parameter, JdbcType jdbcType) throws SQLException {
|
||||
if (parameter == null || parameter.isEmpty()) {
|
||||
ps.setArray(i, null);
|
||||
} else {
|
||||
ps.setArray(i, ps.getConnection().createArrayOf("varchar", parameter.toArray()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
java.sql.Array array = rs.getArray(columnName);
|
||||
return parseArray(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
java.sql.Array array = rs.getArray(columnIndex);
|
||||
return parseArray(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
java.sql.Array array = cs.getArray(columnIndex);
|
||||
return parseArray(array);
|
||||
}
|
||||
|
||||
private List<String> parseArray(java.sql.Array array) throws SQLException {
|
||||
if (array == null) {
|
||||
return null;
|
||||
}
|
||||
Object[] objects = (Object[]) array.getArray();
|
||||
return new ArrayList<>(Arrays.asList((String[]) objects));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user