yuxc
2023-04-14 f2e6e77dc5a984e2fec4416717baa7c47118fcb1
Source/UBCS/ubcs-service-api/ubcs-code-api/src/main/java/com/vci/ubcs/com/vci/starter/web/util/VciBaseUtil.java
@@ -10,6 +10,7 @@
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.vci.ubcs.com.vci.starter.exception.VciBaseException;
import com.vci.ubcs.com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.ubcs.com.vci.starter.web.toolmodel.DateConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.CollectionUtils;
@@ -34,6 +35,7 @@
import java.util.stream.Collectors;
public class VciBaseUtil {
   private static Logger log = LoggerFactory.getLogger(VciBaseUtil.class);
   public static final String NOTIN = "not in";
   private static String localIp = null;
@@ -43,6 +45,15 @@
   public static String getPk() {
      return UUID.randomUUID().toString();
   }
   public static SessionInfo getCurrentUserSessionInfo() throws VciBaseException {
      SessionInfo si = getCurrentUserSessionInfoNotException();
      if (si == null) {
         throw new VciBaseException("noLogin", new String[]{"没有当前用户信息"});
      } else {
         return si;
      }
   }
   public static int getIntForBoolean(boolean b) {
@@ -1094,5 +1105,107 @@
      }
   }
   public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> list) {
      return switchCollectionForOracleIn(list, 500);
   }
   public static <T> Collection<Collection<T>> switchCollectionForOracleIn(Collection<T> collection, int preSize) {
      Collection<Collection<T>> listHasList = new ArrayList();
      if (collection == null) {
         return listHasList;
      } else {
         List<T> newList = new ArrayList();
         Iterator var4 = collection.iterator();
         while(var4.hasNext()) {
            Object obj = var4.next();
            newList.add((T) obj);
         }
         int muti = 1;
         int i;
         if (newList.size() > preSize) {
            i = newList.size() % preSize;
            muti = (newList.size() - i) / preSize + (i == 0 ? 0 : 1);
         }
         for(i = 0; i < muti; ++i) {
            int start = i * preSize;
            int end = start + preSize;
            if (i == muti - 1 || end > newList.size()) {
               end = newList.size();
            }
            List subList = newList.subList(start, end);
            listHasList.add(subList);
         }
         return listHasList;
      }
   }
   public static short getShort(String s) {
//      short i = false;
      if (s == null) {
         return 0;
      } else {
         try {
            short i = Short.parseShort(s);
            return i;
         } catch (Exception var3) {
            return 0;
         }
      }
   }
   public static void setValueForField(Field field, Object obj, String value) {
      try {
         if (field != null && StringUtils.isNotBlank(value)) {
            field.setAccessible(true);
            Method setMethod = getSetmethod(field.getDeclaringClass(), field.getName());
            Class type = field.getType();
            Object valueObj = null;
            if (!type.equals(Integer.TYPE) && !type.equals(Integer.class)) {
               if (!type.equals(Float.TYPE) && !type.equals(Float.class)) {
                  if (!type.equals(Long.TYPE) && !type.equals(Long.class)) {
                     if (!type.equals(Double.class) && !type.equals(Double.TYPE)) {
                        if (type.equals(Date.class)) {
                           DateConverter dateConverter = new DateConverter();
                           dateConverter.setAsText(value);
                           valueObj = dateConverter.getValue();
                        } else if (type.equals(String.class)) {
                           valueObj = value;
                        } else {
                           valueObj = value;
                           if (log.isErrorEnabled()) {
                              log.error("不支持的类型" + type.toString());
                           }
                        }
                     } else {
                        valueObj = getDouble(value);
                     }
                  } else {
                     valueObj = getLong(value);
                  }
               } else {
                  valueObj = getFloat(value);
               }
            } else {
               valueObj = getInt(value);
            }
            if (setMethod != null) {
               setMethod.invoke(obj, valueObj);
            } else {
               field.set(obj, valueObj);
            }
         }
      } catch (Throwable var7) {
         if (log.isErrorEnabled()) {
            log.error("设置属性的值出错了错误", var7);
         }
      }
   }
}