From f8fe13b6f7d8ad1ae53e7bf6a6cf83f584d52a4d Mon Sep 17 00:00:00 2001
From: fujunling <2984387807@qq.com>
Date: 星期二, 06 六月 2023 17:39:24 +0800
Subject: [PATCH] 动态表单组件重构
---
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java | 134 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 133 insertions(+), 1 deletions(-)
diff --git a/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java b/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
index 4cb289a..7bf4b8b 100644
--- a/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
+++ b/Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
@@ -7,6 +7,7 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.vci.ubcs.starter.exception.VciBaseException;
import com.vci.ubcs.starter.web.enumpck.BooleanEnum;
@@ -19,7 +20,9 @@
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
+import java.beans.BeanInfo;
import java.beans.IntrospectionException;
+import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.IOException;
@@ -32,6 +35,8 @@
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.NetworkInterface;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -79,7 +84,21 @@
return 0;
}
}
-
+ public static SessionInfo getCurrentUserSessionInfo() throws VciBaseException {
+ SessionInfo si = getCurrentUserSessionInfoNotException();
+ if (si == null) {
+ throw new VciBaseException("noLogin", new String[]{"娌℃湁褰撳墠鐢ㄦ埛淇℃伅"});
+ } else {
+ return si;
+ }
+ }
+ /**
+ * 璁剧疆褰撳墠绾跨▼涓殑鐢ㄦ埛瀵硅薄
+ * @param sessionInfo 鐢ㄦ埛瀵硅薄
+ */
+ public static void setCurrentUserSessionInfo(SessionInfo sessionInfo){
+ WebThreadLocalUtil.getCurrentUserSessionInfoInThread().set(sessionInfo);
+ }
public static long getLong(String s) {
long l = 0L;
if (s == null) {
@@ -1230,5 +1249,118 @@
}
+ /**
+ * 灏� JavaBean瀵硅薄杞寲涓� Map
+ * @author wyply115
+ * @param bean 瑕佽浆鍖栫殑绫诲瀷
+ * @return Map瀵硅薄
+ * @version 2016骞�3鏈�20鏃� 11:03:01
+ */
+ public static Map convertBean2Map(Object bean) throws Exception {
+ Class type = bean.getClass();
+ Map returnMap = new HashMap();
+ BeanInfo beanInfo = Introspector.getBeanInfo(type);
+ PropertyDescriptor[] propertyDescriptors = beanInfo
+ .getPropertyDescriptors();
+ Field[] declaredFields = type.getDeclaredFields();
+ String existField = "";
+ for (Field declaredField : declaredFields) {
+ declaredField.setAccessible(true);
+
+ // 鑾峰彇瀛楁鐨勫��
+ boolean isTableField = declaredField.isAnnotationPresent(TableField.class);
+ if (isTableField) {
+ TableField tableField = declaredField.getAnnotation(TableField.class);
+ Boolean fieldValue = tableField.exist();
+ if(fieldValue == false){
+ existField += declaredField.getName().toLowerCase()+",";
+ }
+ }
+ }
+
+ for (int i = 0, n = propertyDescriptors.length; i <n ; i++) {
+ PropertyDescriptor descriptor = propertyDescriptors[i];
+ String propertyName = descriptor.getName();
+
+ if (!propertyName.equals("class") &&
+ ((!"".equals(existField) && !existField.contains(propertyName.toLowerCase()+","))||"data".equals(propertyName))) {
+ Method readMethod = descriptor.getReadMethod();
+ Object result = readMethod.invoke(bean, new Object[0]);
+
+ if (result != null) {
+ if ("data".equals(propertyName)){
+ returnMap.putAll((Map) result);
+ }else {
+ returnMap.put(propertyName, result);
+ }
+ } else {
+ returnMap.put(propertyName, "");
+ }
+ }
+ }
+ return returnMap;
+ }
+
+ public static <T> List<T> mapToBean(List<Map> maps, Class<T> tClass) {
+ List<T> beanList = new ArrayList<>();
+ try {
+ for (Map map : maps) {
+ T t = tClass.newInstance();
+ BeanInfo beanInfo = Introspector.getBeanInfo(tClass);
+ PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
+
+ for (PropertyDescriptor property : propertyDescriptors) {
+
+ String key = property.getName();
+ if ("class".equals(key)) {
+ continue;
+ }
+
+// String sqlField = camelToUnderscore(key);
+
+
+ if (map.containsKey(key.toUpperCase())) {
+ try {
+ Object value = map.get(key.toUpperCase());
+ // 寰楀埌property瀵瑰簲鐨剆etter鏂规硶
+ Method setter = property.getWriteMethod();
+ Class<?> type = property.getPropertyType();
+ // 寮鸿浆涓哄瓧娈电殑绫诲瀷锛屼笉闇�瑕佹椂鍙互鍘婚櫎锛屼緷璧朿ommons-beanutilss-beanutils
+ //Object convert = ConvertUtils.convert(String.valueOf(value), type);
+ //setter.invoke(t, convert);
+ setter.invoke(t, value);
+ } catch (Exception e) {
+ throw new RuntimeException("銆愯祴鍊煎紓甯搞��", e);
+ }
+ }
+
+ }
+ beanList.add(t);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("銆怣ap杞崲瀹炰綋寮傚父銆�", e);
+ }
+ return beanList;
+}
+
+ public static String camelToUnderscore(String name) {
+ if (name == null && name.length() <= 0) {
+ return name;
+ }
+ StringBuilder sb = new StringBuilder();
+ String lowerName = name.toLowerCase();
+ for (int i = 0; i < lowerName.length(); i++) {
+ String nameChar = name.substring(i, i + 1);
+ String lowerChar = lowerName.substring(i, i + 1);
+ if (!nameChar.equals(lowerChar)) {
+ sb.append("_").append(lowerChar);
+ } else {
+ sb.append(nameChar);
+ }
+ }
+
+ return sb.toString();
+ }
+
}
--
Gitblit v1.9.3