---初始化项目

This commit is contained in:
2025-10-10 09:20:48 +08:00
parent a8e0f1c377
commit 7f74c186da
203 changed files with 14674 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package com.pictc.annotations.datalog;
public enum JoinCaseType {
FULL,NONE
}

View File

@ -0,0 +1,13 @@
package com.pictc.annotations.datalog;
/**
* @author 张福财
* @date 2025年8月28日 下午6:00:10
* @Description: 关联类型 ONE_ONE ONE_MANY
*/
public enum JoinType {
ONE,
MANY
}

View File

@ -0,0 +1,13 @@
package com.pictc.annotations.datalog;
/**
* @author 张福财
* @date 2025年8月26日 上午9:18:35
* @Description: 关联值类型
*/
public enum JoinValueType {
FEILD, //字段关联
STATIC //字段等于静态值
}

View File

@ -0,0 +1,41 @@
package com.pictc.annotations.datalog;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
/**
* @author 张福财
* @date 2025年8月26日 下午5:33:01
* @Description: 数据日志属性配置
*/
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface LogField {
@AliasFor("name")
String value() default "";
/**
* @Description: 业务名称
* @return String 返回类型
*/
@AliasFor("value")
String name() default "";
/**
* @Description: 数据库字段
* @return String 返回类型
*/
String column() default "";
/**
* @Description: 位置
* @return int 返回类型
*/
int index() default 0;
}

View File

@ -0,0 +1,63 @@
package com.pictc.annotations.datalog;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 张福财
* @date 2025年8月26日 上午9:37:23
* @Description: 关联关系
*/
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface LogJoin {
/**
* @Description: 业务名称
* @return String 返回类型
*/
String name();
/**
* @Description: 关联对象
* @return Class<?> 返回类型
*/
Class<?> target();
/**
* @Description: 关联类型
* @return JoinType 返回类型
*/
JoinType type();
/**
* @Description: 级联类型DEL(删除)、UPD(修改)、FULL(全部);
* @return JoinType 返回类型
*/
JoinCaseType caseType() default JoinCaseType.FULL;
/**
* @Description: 关联列
* @return DataLogJoinColumn[] 返回类型
*/
LogJoinColumn[] columns() default {};
/**
* @Description: 数据来源默认通过target配置的表名去关联查询如果sourceType = TQ 时配置查询ID
* @return String 返回类型
*/
String source() default "";
/**
* @Description: TODO(这里用一句话描述这个方法的作用)
* @return
* @return QJoinSource 返回类型
*/
SourceType sourceType() default SourceType.TABLE;
}

View File

@ -0,0 +1,48 @@
package com.pictc.annotations.datalog;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 张福财
* @date 2025年8月26日 上午9:37:45
* @Description: 关联属性配置
*/
@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface LogJoinColumn {
/**
* @Description: 属性
* @return String 返回类型
*/
String field() default "";
/**
* @Description: 关联属性
* @return String 返回类型
*/
String relatedField() default "";
/**
* @Description: 赋值方向
* @return ValueDirectionType 返回类型
*/
ValueDirectionType valueDirection() default ValueDirectionType.LEFT;
/**
* @Description: 关联值类型JoinValueType FEILD【字段关联】、STATIC【字段等于静态值】
* @return String 返回类型
*/
JoinValueType valueType() default JoinValueType.FEILD;
String staticValue() default "";
Class<?> staticType() default String.class;
}

View File

@ -0,0 +1,48 @@
package com.pictc.annotations.datalog;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.core.annotation.AliasFor;
/**
* @author 张福财
* @date 2025年8月25日 下午6:09:03
* @Description: TODO(这里用一句话描述这个类的作用)
*/
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface LogTable {
/**
* @Description: 业务名称
* @return String 返回类型
*/
@AliasFor("name")
String value() default "";
/**
* @Description: 业务名称
* @return String 返回类型
*/
@AliasFor("value")
String name() default "";
/**
* @Description: 表名或者查询ID
* @return String 返回类型
*/
String source();
/**
* @Description:
* @return QJoinSource 返回类型
*/
SourceType sourceType() default SourceType.TABLE;
}

View File

@ -0,0 +1,13 @@
package com.pictc.annotations.datalog;
/**
* @author 张福财
* @date 2025年8月28日 下午4:24:27
* @Description: 数据来源默认从关联表获取从SQL配置表
*/
public enum SourceType {
TABLE,
TSQL
}

View File

@ -0,0 +1,13 @@
package com.pictc.annotations.datalog;
/**
* @author 张福财
* @date 2025年8月28日 下午2:40:03
* @Description: 赋值方向
* 左边为主表
* 右边为子表
*/
public enum ValueDirectionType {
LEFT, //向左
RIGHT
}

View File

@ -0,0 +1,115 @@
package com.pictc.common.mybatis;
import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.List;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
@MappedTypes({Object.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class JsonTypeHandler<T> extends AbstractJsonTypeHandler<Object> {
private boolean list;
private Class<?> entityClass;
public JsonTypeHandler(Class<?> type) {
list = isList(type);
}
public JsonTypeHandler(Class<?> type, Field field) {
list = isList(type);
try {
entityClass = getFeildFanClass(field, 0);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
public Object parse(String json) {
if(list) {
return JSON.parseArray(json,entityClass);
}
return JSON.parseObject(json,entityClass);
}
@Override
public String toJson(Object obj) {
if(obj==null) return null;
return JSON.toJSONString(obj, SerializerFeature.WriteMapNullValue,
SerializerFeature.WriteNullListAsEmpty, SerializerFeature.WriteNullStringAsEmpty);
}
/**
* 是否是list集合
* */
private boolean isList(Class<?> klass) {
return hashClass(klass, List.class);
}
/**
* klass是否实现了face类或接口
* @author tanuki
* @param klass 要判断的类型
* @param face 指定的类型
* */
private boolean hashClass(Class<?> klass, Class<?> face) {
if (klass.equals(face)) {
return true;
} else {
if (Object.class.equals(klass)) {
return false;
}
Class<?>[] cls = klass.getInterfaces();
for (int i = 0; i < cls.length; i++) {
if (hashClass(cls[i], face)) {
return true;
}
}
if (!klass.isInterface()) {
if (hashClass(klass.getSuperclass(), face)) {
return true;
}
}
}
return false;
}
private Class<?> getFeildFanClass(Field field,int index) throws ClassNotFoundException {
return getClass(getFeildFan(field, index));
}
/**
* Type 类型转 class
* */
private Class<?> getClass(Type type) throws ClassNotFoundException{
String cStr=type.toString();
if(cStr.indexOf("class ")==0){
return Class.forName(cStr.substring(6, cStr.length()));
}else if(cStr.indexOf("interface ")==0){
return Class.forName(cStr.substring(10, cStr.length()));
}else{
if(cStr.indexOf("<")!=-1){
return Class.forName(cStr.substring(0, cStr.indexOf("<")));
}
return Class.forName(cStr.substring(0, cStr.length()));
}
}
private Type getFeildFan(Field field,int index) {
Type type = field.getGenericType();
if(type instanceof ParameterizedType){
return ((ParameterizedType)type).getActualTypeArguments()[index];
}
return field.getType();
}
}