xiejun
2023-09-18 978f74777e10a0531c4413ab36320d2be36f42ea
Source/UBCS/ubcs-service-api/ubcs-util-api/src/main/java/com/vci/ubcs/starter/web/util/VciBaseUtil.java
@@ -19,6 +19,7 @@
import com.vci.ubcs.starter.web.wrapper.VciQueryWrapperForDO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springblade.core.tool.utils.Func;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
@@ -37,8 +38,6 @@
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;
@@ -869,7 +868,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) {
@@ -1143,7 +1142,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){
         //为了让list还可以添加内容,因为使用sublist后,list不能再Add了
         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) {
@@ -1263,14 +1293,18 @@
    * @return Map对象
    * @version 2016年3月20日 11:03:01
    */
   public static Map convertBean2Map(Object bean) throws Exception {
   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 = "";
      if(existFild == null){
         existFild = new HashSet<>();
      }
      for (Field declaredField : declaredFields) {
         declaredField.setAccessible(true);
@@ -1282,9 +1316,13 @@
            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();
@@ -1296,13 +1334,25 @@
            if (result != null) {
               if ("data".equals(propertyName)){
                  returnMap.putAll((Map) result);
               }else {
                  returnMap.put(propertyName, result);
                  mapData = (Map) result;
               }else if(existFild.contains((fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName).toLowerCase())){
                  returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName).toLowerCase():propertyName.toLowerCase(), result);
               }
            } else {
               returnMap.put(propertyName, "");
            } else if(existFild.contains((fieldMap.containsKey(propertyName)?fieldMap.get(propertyName):propertyName).toLowerCase())){
               returnMap.put(fieldMap.containsKey(propertyName)?fieldMap.get(propertyName).toLowerCase():propertyName.toLowerCase(), "");
            }
         }
      }
      //作用主要用于已MAP中的数据为准,bean里面遇到字段相同且map里面数据为空,则使用bean里面的值,
//      Map resulMapChild = (Map) mapData;
      for (Object o : mapData.keySet()) {
         if(existFild == null || existFild.contains(String.valueOf(o).toLowerCase())){
            if((Func.isNotBlank(String.valueOf(returnMap.get(String.valueOf(o).toLowerCase())))
               && returnMap.get(String.valueOf(o).toLowerCase()) !=null)
               && Func.isBlank(String.valueOf(mapData.get(o)))){
               continue;
            }
            returnMap.put(String.valueOf(o).toLowerCase(),mapData.get(o));
         }
      }
      return returnMap;
@@ -1326,9 +1376,14 @@
//                  String sqlField = camelToUnderscore(key);
                  if (map.containsKey(key.toUpperCase())) {
                  if (map.containsKey(key.toUpperCase(Locale.ROOT))||map.containsKey(key.toLowerCase(Locale.ROOT))) {
                     try {
                        Object value = map.get(key.toUpperCase());
                        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对应的setter方法
                        Method setter = property.getWriteMethod();
                        Class<?> type = property.getPropertyType();
@@ -1350,6 +1405,7 @@
      return beanList;
}
   public static String camelToUnderscore(String name) {
      if (name == null && name.length() <= 0) {
         return name;
@@ -1368,6 +1424,12 @@
      return sb.toString();
   }
   public static String intToRomans(int num) {
      String M[] = {"", "M", "MM", "MMM"};
      String C[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
      String X[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
      String I[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
      return M[num/1000]+C[(num%1000)/100]+X[(num%100)/10]+I[num%10];
   }
}