From a19d26e88360c9760b2286bac4dfb1710fd2fa21 Mon Sep 17 00:00:00 2001 From: xiejun <xj@2023> Date: 星期六, 12 八月 2023 13:33:58 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java | 182 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 179 insertions(+), 3 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 a4e1111..ca40971 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 @@ -5,8 +5,11 @@ // (powered by FernFlower decompiler) // +import cn.hutool.core.lang.Snowflake; +import cn.hutool.core.util.IdUtil; 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 +22,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; @@ -47,7 +52,12 @@ } public static String getPk() { - return UUID.randomUUID().toString(); + return String.valueOf(getPKLong(1,1)); + } + + public static Long getPKLong(long workerId,long dataCenterId){ + Snowflake snowflake = IdUtil.getSnowflake(workerId,dataCenterId); + return snowflake.nextId(); } public static int getIntForBoolean(boolean b) { @@ -857,7 +867,7 @@ } public static String getTableName(String btmname) { - return (VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY ? "pl_code_" : "vcibt_") + btmname.trim().toLowerCase(); + return (VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY ? "vcibt_" : "pl_code_") + btmname.trim().toLowerCase(); } public static Field getTsField(Class c) { @@ -1131,7 +1141,38 @@ public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> list) { return switchCollectionForOracleIn(list, 500); } - + /** + * oracle in 鏌ヨ涓嶈兘瓒呰繃1000锛岃浆鎹竴涓嬮泦鍚� + * 鐢变簬SQL璇彞1000涓彲鑳藉緢闀匡紝瓒呰繃oracle10g锛屾墍浠ョ壓鐗叉�ц兘鍒嗛厤涓�500涓暟缁� + * @param list 闇�瑕佽浆鎹㈢殑鍒楄〃鍐呭 + * @return 鍒嗙粍鍚庣殑list + */ + public static <T> List<List<T>> switchListForOracleIn(List<T> list) { + List<List<T>> listHasList = new ArrayList<List<T>>(); + if(list == null){ + return listHasList; + } + List<T> newList = new ArrayList<T>(); + for(Object obj : list){ + //涓轰簡璁﹍ist杩樺彲浠ユ坊鍔犲唴瀹癸紝鍥犱负浣跨敤sublist鍚庯紝list涓嶈兘鍐岮dd浜� + newList.add((T)obj); + } + int muti = 1; + if(newList.size() >500){ + int balance = newList.size()%500; + muti = (newList.size() - balance)/500 + (balance == 0?0:1); + } + for(int i = 0 ; i < muti; i ++){ + int start = i*500; + int end = start + 500; + if(i == muti-1 || end >newList.size() ){ + end = newList.size(); + } + List subList = newList.subList(start,end); + listHasList.add(subList); + } + return listHasList; + } public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> collection, int preSize) { Collection<Collection<T>> listHasList = new ArrayList(); if (collection == null) { @@ -1244,5 +1285,140 @@ } + /** + * 灏� JavaBean瀵硅薄杞寲涓� Map + * @author wyply115 + * @param bean 瑕佽浆鍖栫殑绫诲瀷 + * @return Map瀵硅薄 + * @version 2016骞�3鏈�20鏃� 11:03:01 + */ + public static Map convertBean2Map(Object bean,Set<String> existFild) throws Exception { + Class type = bean.getClass(); + Map returnMap = new HashMap(); + BeanInfo beanInfo = Introspector.getBeanInfo(type); + PropertyDescriptor[] propertyDescriptors = beanInfo + .getPropertyDescriptors(); + Field[] declaredFields = type.getDeclaredFields(); + Map<String, String> fieldMap = new HashMap(); + 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()+","; + } + String value = tableField.value(); + if(net.logstash.logback.encoder.org.apache.commons.lang3.StringUtils.isNotBlank(value)){ + fieldMap.put(declaredField.getName(), value); + } + } + } + Map mapData = new HashMap<>(); + 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)){ + mapData = (Map) result; + }else if(existFild.contains((fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName).toLowerCase())){ + returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName, result); + } + } else if(existFild.contains((fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName).toLowerCase())){ + returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName, ""); + } + } + } + //浣滅敤涓昏鐢ㄤ簬宸睲AP涓殑鏁版嵁涓哄噯锛宐ean閲岄潰閬囧埌瀛楁鐩稿悓涔熶細杩涜瑕嗙洊銆� + if(existFild == null){ + returnMap.putAll((Map) mapData); + }else{ + Map resulMapChild = (Map) mapData; + for (Object o : resulMapChild.keySet()) { + if(existFild.contains(String.valueOf(o).toLowerCase())){ + returnMap.put(String.valueOf(o).toLowerCase(),resulMapChild.get(o)); + } + } + } + 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(Locale.ROOT))||map.containsKey(key.toLowerCase(Locale.ROOT))) { + try { + Object value=""; + if (map.containsKey(key.toUpperCase(Locale.ROOT))) { + value = map.get(key.toUpperCase()); + }else if(map.containsKey(key.toLowerCase(Locale.ROOT))){ + value = map.get(key.toLowerCase()); + } + // 寰楀埌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