Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/feature-2022.07.29' into feature-2022.07.29

sakuya 3 anni fa
parent
commit
ef746e5a76

+ 4 - 0
eladmin-security/src/main/java/me/zhengjie/security/config/bean/SecurityProperties.java

@@ -50,6 +50,10 @@ public class SecurityProperties {
      * 在线用户 key,根据 key 查询 redis 中在线用户的数据
      */
     private String onlineKey;
+    /**
+       * 在线用户 app,根据 key 查询 redis 中在线用户的数据
+     */
+    private String appKey;
 
     /**
      * 验证码 key

+ 0 - 1
eladmin-system/src/main/java/me/zhengjie/AppRun.java

@@ -40,7 +40,6 @@ import org.springframework.web.bind.annotation.RestController;
 @SpringBootApplication
 @EnableTransactionManagement
 @EnableJpaAuditing(auditorAwareRef = "auditorAware")
-//@MapperScan(basePackages = "me.zhengjie.appapi.dao")
 public class AppRun {
     public static void main(String[] args) {
     	

+ 0 - 8
eladmin-system/src/main/java/me/zhengjie/application/admin/service/impl/SmsTemplateServiceImpl.java

@@ -9,13 +9,6 @@ import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.tencentcloudapi.common.Credential;
-import com.tencentcloudapi.common.exception.TencentCloudSDKException;
-import com.tencentcloudapi.common.profile.ClientProfile;
-import com.tencentcloudapi.common.profile.HttpProfile;
-import com.tencentcloudapi.sms.v20210111.SmsClient;
-import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
-import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
 
 import lombok.extern.slf4j.Slf4j;
 import me.zhengjie.application.admin.service.SmsTemplateService;
@@ -24,7 +17,6 @@ import me.zhengjie.base.AppResultData;
 import me.zhengjie.base.ResultCode;
 import me.zhengjie.base.plus.AbstractServiceImpl;
 import me.zhengjie.base.sms.SmsRequest;
-
 import me.zhengjie.base.sms.SmsTemplateVo;
 import me.zhengjie.base.util.BeanCopyUtils;
 import me.zhengjie.dao.mybatis.entity.SmsTemplateEntity;

+ 17 - 0
eladmin-system/src/main/java/me/zhengjie/base/plus/QueryEntity.java

@@ -0,0 +1,17 @@
+package me.zhengjie.base.plus;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
+public class QueryEntity {
+	// 开始时间
+	@TableField(exist = false)
+	private String startDate;
+	// 结束时间
+	@TableField(exist = false)
+	private String endDate;
+}

+ 52 - 17
eladmin-system/src/main/java/me/zhengjie/base/plus/QueryWrapperUtil.java

@@ -1,6 +1,9 @@
 package me.zhengjie.base.plus;
 
+import java.beans.PropertyDescriptor;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -16,6 +19,22 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  * @Description 拼接查询条件工具类
  */
 public class QueryWrapperUtil {
+	/**
+	 * 得到父类的对象
+	 * 
+	 * @param <T>   查询的泛型
+	 * @param clazz
+	 * @return
+	 */
+	public static <T> List<Field> reflectForField(Class<T> clazz) {
+		Class<?> tmpClazz = clazz;
+		List<Field> fieldList = new ArrayList<>();
+		while (tmpClazz != null) {
+			fieldList.addAll(Arrays.asList(tmpClazz.getDeclaredFields()));
+			tmpClazz = tmpClazz.getSuperclass();
+		}
+		return fieldList;
+	}
 
 	/**
 	 * 拼接查询条件
@@ -29,24 +48,29 @@ public class QueryWrapperUtil {
 		if (ArrayUtils.isNotEmpty(jsonObj)) {
 			param = jsonObj[0];
 		}
-
 		QueryWrapper<T> queryWrapper = new QueryWrapper<>();
 		Class<?> clazz = obj.getClass();
 		try {
-			// 反射遍历属性
-			for (Field field : clazz.getDeclaredFields()) {
-				// 获取属性名
-				String fieldname = field.getName();
+			// TODO 这里应该通过共有方法来进行反射
+			for (Field field : reflectForField(clazz)) {
+
 				// 抑制Java对修饰符的检查
-				field.setAccessible(true);
+//				field.setAccessible(true);
 				// 获取属性值
-				Object fieldValue = field.get(obj);
+//				Object fieldValue = field.get(obj);
 //            String fieldValue = getFieldValue(obj ,field.getName()).toString();
 				TableField tableField = AnnotationUtils.getAnnotation(field, TableField.class);
 				// 字段没有TableField这个注解和有这个主机上false的
 				if (ObjectUtils.isEmpty(tableField) || !tableField.exist()) {
 					continue;
 				}
+				// 获取属性名
+				String name = field.getName();
+				// 声明属性描述对象
+				PropertyDescriptor propertyDescriptor = new PropertyDescriptor(name, clazz);
+				// 获取getter方法
+				Method method = propertyDescriptor.getReadMethod();
+				Object fieldValue = method.invoke(obj);
 				String fieldName = tableField.value();
 				// 默认是相等
 				QueryWapper queryWapperAnnotation = AnnotationUtils.getAnnotation(field, QueryWapper.class);
@@ -104,24 +128,35 @@ public class QueryWrapperUtil {
 							// 设置开始的值和结束的值
 							String[] attribute = queryWapperAnnotation.attribute();
 							// 得到开始的属性值,通过反射设置属性值
-							Field startRange = clazz.getDeclaredField(attribute[0]);
-							startRange.setAccessible(true);
-							Object val = startRange.get(obj);
+//							Field startRange = clazz.getDeclaredField(attribute[0]);
+//							startRange.setAccessible(true);
+//							Object val = startRange.get(obj);
+							String startRange = attribute[0];
+							propertyDescriptor = new PropertyDescriptor(startRange, clazz);
+							// 获取getter方法
+							method = propertyDescriptor.getReadMethod();
+							Object val = method.invoke(obj);
 							if (!ObjectUtils.isEmpty(val)) {
 								queryWrapper.ge(fieldName, val);
 							}
+							// 结束的属性值,通过反射设置属性值
+							String endRange = attribute[1];
+							propertyDescriptor = new PropertyDescriptor(endRange, clazz);
+							// 获取getter方法
+							method = propertyDescriptor.getReadMethod();
+							val = method.invoke(obj);
+							if (!ObjectUtils.isEmpty(val)) {
+								queryWrapper.le(fieldName, val);
+							}
+							// ---属性值查询结束的值----
+
+							// 通过传入的参数查询值
 							// 然后通过参数查询
 							val = param.get(attribute[0]);
 							if (!ObjectUtils.isEmpty(val)) {
 								queryWrapper.ge(fieldName, val);
 							}
-							// 结束的属性值,通过反射设置属性值
-							Field endRange = clazz.getDeclaredField(attribute[1]);
-							endRange.setAccessible(true);
-							val = endRange.get(obj);
-							if (!ObjectUtils.isEmpty(val)) {
-								queryWrapper.le(fieldName, val);
-							}
+
 							// 然后通过参数查询
 							val = param.get(attribute[1]);
 							if (!ObjectUtils.isEmpty(val)) {

+ 8 - 0
eladmin-system/src/main/java/me/zhengjie/base/sms/SmsTemplateVo.java

@@ -1,5 +1,7 @@
 package me.zhengjie.base.sms;
 
+import com.baomidou.mybatisplus.annotation.TableField;
+
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import me.zhengjie.base.BaseRequest;
@@ -46,4 +48,10 @@ public class SmsTemplateVo extends BaseRequest{
 	private Integer status;
 	//订单状态,对应订单的状态
 	private Integer orderType;
+	//查询标题和内容
+	private String name;
+	// 开始时间
+	private String startDate;
+	// 结束时间
+	private String endDate;
 }

+ 30 - 3
eladmin-system/src/main/java/me/zhengjie/dao/mybatis/entity/SmsTemplateEntity.java

@@ -1,13 +1,22 @@
 package me.zhengjie.dao.mybatis.entity;
 
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
-import java.time.LocalDateTime;
+
 import lombok.Getter;
 import lombok.Setter;
+import me.zhengjie.base.plus.QueryEntity;
+import me.zhengjie.base.plus.QueryKeyword;
+import me.zhengjie.base.plus.QueryWapper;
 
 /**
  * <p>
@@ -20,7 +29,7 @@ import lombok.Setter;
 @Getter
 @Setter
 @TableName("sms_template")
-public class SmsTemplateEntity implements Serializable {
+public class SmsTemplateEntity extends QueryEntity implements Serializable {
 
 	private static final long serialVersionUID = 1L;
 
@@ -42,6 +51,7 @@ public class SmsTemplateEntity implements Serializable {
 	/**
 	 * 模板内容
 	 */
+	@QueryWapper(value = { QueryKeyword.LIKE }, attribute = { "startDate", "endDate" })
 	@TableField("template_content")
 	private String templateContent;
 
@@ -78,6 +88,7 @@ public class SmsTemplateEntity implements Serializable {
 	/**
 	 * 创建时间
 	 */
+	@QueryWapper(value = { QueryKeyword.RANGE }, attribute = { "startDate", "endDate" })
 	@TableField("create_time")
 	private LocalDateTime createTime;
 
@@ -93,4 +104,20 @@ public class SmsTemplateEntity implements Serializable {
 	private String reason;
 	// 状态:1启用、0禁用
 	private Integer status;
+
+	public static <T> List<Field> reflectForField(Class<T> clazz) {
+		Class<?> tmpClazz = clazz;
+		List<Field> fieldList = new ArrayList<>();
+		while (tmpClazz != null) {
+			if (tmpClazz.equals(Object.class)) {
+				tmpClazz = tmpClazz.getSuperclass();
+				continue;
+			}
+			fieldList.addAll(Arrays.asList(tmpClazz.getDeclaredFields()));
+			tmpClazz = tmpClazz.getSuperclass();
+		}
+
+		return fieldList;
+	}
+
 }