工单模块
This commit is contained in:
@@ -44,6 +44,10 @@
|
||||
<groupId>org.xyzh.common</groupId>
|
||||
<artifactId>common-utils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xyzh.common</groupId>
|
||||
<artifactId>common-jdbc</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -2,6 +2,8 @@ package org.xyzh.common.dto;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -41,4 +43,19 @@ public class BaseDTO implements Serializable {
|
||||
|
||||
@Schema(description = "是否已删除", defaultValue = "false")
|
||||
private Boolean deleted = false;
|
||||
|
||||
|
||||
// =============== 下方为筛选字段,非数据库字段 ================
|
||||
|
||||
@Schema(description = "数量限制")
|
||||
private Integer limit;
|
||||
|
||||
@Schema(description = "开始时间")
|
||||
private Date startTime;
|
||||
|
||||
@Schema(description = "结束时间")
|
||||
private Date endTime;
|
||||
|
||||
@Schema(description = "排序字段")
|
||||
private List<OrderField> orderFields;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.xyzh.common.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Schema(description = "排序方式对象")
|
||||
public class OrderField {
|
||||
public static final String ASC = "ASC";
|
||||
public static final String DESC = "DESC";
|
||||
|
||||
@Schema(description = "排序字段")
|
||||
private String field;
|
||||
|
||||
@Schema(description = "排序方式")
|
||||
private String order;
|
||||
|
||||
public OrderField(String field, String order) {
|
||||
this.field = field;
|
||||
this.order = order;
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.xyzh.common.dto.BaseDTO;
|
||||
import org.xyzh.common.utils.crypto.AesEncryptUtil;
|
||||
import org.xyzh.common.utils.crypto.EncryptedStringTypeHandler;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@@ -33,7 +31,6 @@ public class TbSysUserDTO extends BaseDTO {
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
|
||||
@TableField(typeHandler = EncryptedStringTypeHandler.class)
|
||||
@Schema(description = "手机(加密)")
|
||||
private String phone;
|
||||
|
||||
|
||||
44
urbanLifelineServ/common/common-jdbc/pom.xml
Normal file
44
urbanLifelineServ/common/common-jdbc/pom.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.xyzh</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.xyzh.common</groupId>
|
||||
<artifactId>common-jdbc</artifactId>
|
||||
<version>${urban-lifeline.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
<description>JDBC相关工具:MyBatis类型处理器</description>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- MyBatis -->
|
||||
<dependency>
|
||||
<groupId>org.mybatis</groupId>
|
||||
<artifactId>mybatis</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- FastJson2 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension-spring6</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- common-utils (用于 AesEncryptUtil) -->
|
||||
<dependency>
|
||||
<groupId>org.xyzh.common</groupId>
|
||||
<artifactId>common-utils</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.xyzh.common.utils.crypto;
|
||||
package org.xyzh.common.jdbc.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.xyzh.common.jdbc.handler.EncryptedStringTypeHandler;
|
||||
import org.xyzh.common.utils.crypto.AesEncryptUtil;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package org.xyzh.common.utils.crypto;
|
||||
package org.xyzh.common.jdbc.handler;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
import org.xyzh.common.utils.crypto.AesEncryptUtil;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -0,0 +1,103 @@
|
||||
package org.xyzh.common.jdbc.handler;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* @description 通用枚举类型处理器,支持枚举类中定义 getName() 方法
|
||||
* 将枚举的 name 属性(自定义字符串)存储到数据库
|
||||
* @filename EnumNameTypeHandler.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-12-18
|
||||
*/
|
||||
public class EnumNameTypeHandler<E extends Enum<E>> extends BaseTypeHandler<E> {
|
||||
|
||||
private final Class<E> type;
|
||||
|
||||
public EnumNameTypeHandler(Class<E> type) {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Type argument cannot be null");
|
||||
}
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, E parameter, JdbcType jdbcType) throws SQLException {
|
||||
String value = getEnumName(parameter);
|
||||
ps.setString(i, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String name = rs.getString(columnName);
|
||||
return fromName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String name = rs.getString(columnIndex);
|
||||
return fromName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public E getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String name = cs.getString(columnIndex);
|
||||
return fromName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取枚举的 name 属性值
|
||||
* 优先调用 getName() 方法,如果不存在则使用 name()
|
||||
*/
|
||||
private String getEnumName(E enumValue) {
|
||||
try {
|
||||
java.lang.reflect.Method getNameMethod = type.getMethod("getName");
|
||||
return (String) getNameMethod.invoke(enumValue);
|
||||
} catch (NoSuchMethodException e) {
|
||||
return enumValue.name();
|
||||
} catch (Exception e) {
|
||||
return enumValue.name();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 name 属性值查找枚举
|
||||
* 优先匹配 getName(),如果不存在则匹配 name()
|
||||
*/
|
||||
private E fromName(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
E[] enumConstants = type.getEnumConstants();
|
||||
|
||||
// 先尝试匹配 getName()
|
||||
try {
|
||||
java.lang.reflect.Method getNameMethod = type.getMethod("getName");
|
||||
for (E enumConstant : enumConstants) {
|
||||
String enumName = (String) getNameMethod.invoke(enumConstant);
|
||||
if (name.equals(enumName)) {
|
||||
return enumConstant;
|
||||
}
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
// 没有 getName 方法,使用 name()
|
||||
} catch (Exception e) {
|
||||
// 其他异常,使用 name()
|
||||
}
|
||||
|
||||
// 回退到 name() 匹配
|
||||
for (E enumConstant : enumConstants) {
|
||||
if (name.equals(enumConstant.name())) {
|
||||
return enumConstant;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.xyzh.common.utils.json;
|
||||
package org.xyzh.common.jdbc.handler;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
@@ -15,7 +15,7 @@ import java.sql.SQLException;
|
||||
* @description FastJSON2 JSONObject 类型处理器
|
||||
* @filename FastJson2TypeHandler.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-12-09
|
||||
*/
|
||||
@MappedTypes({JSONObject.class})
|
||||
@@ -51,7 +51,6 @@ public class FastJson2TypeHandler extends BaseTypeHandler<JSONObject> {
|
||||
try {
|
||||
return JSON.parseObject(jsonString);
|
||||
} catch (Exception e) {
|
||||
// 如果解析失败,返回一个空的JSONObject
|
||||
return new JSONObject();
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.xyzh.common.utils.json;
|
||||
package org.xyzh.common.jdbc.handler;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
* @description PostgreSQL VARCHAR数组类型处理器
|
||||
* @filename StringArrayTypeHandler.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-12-15
|
||||
*/
|
||||
@MappedTypes({List.class})
|
||||
@@ -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>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<module>common-auth</module>
|
||||
<module>common-redis</module>
|
||||
<module>common-utils</module>
|
||||
<module>common-jdbc</module>
|
||||
<module>common-all</module>
|
||||
<module>common-exception</module>
|
||||
</modules>
|
||||
@@ -65,6 +66,11 @@
|
||||
<artifactId>common-exception</artifactId>
|
||||
<version>${urban-lifeline.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xyzh.common</groupId>
|
||||
<artifactId>common-jdbc</artifactId>
|
||||
<version>${urban-lifeline.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
Reference in New Issue
Block a user