| | |
| | | // (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; |
| | | import com.vci.ubcs.starter.web.enumpck.UserSecretEnum; |
| | | import com.vci.ubcs.starter.web.pagemodel.SessionInfo; |
| | | import com.vci.ubcs.starter.web.toolmodel.DateConverter; |
| | | import com.vci.ubcs.starter.web.wrapper.VciQueryWrapperForDO; |
| | | import com.vci.ubcs.system.cache.NacosConfigCache; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | 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; |
| | |
| | | public VciBaseUtil() { |
| | | } |
| | | |
| | | /** |
| | | * 检查是否为配置的超管租户和用户 |
| | | * @return false不是超管,true是超管 |
| | | */ |
| | | public static Boolean checkAdminTenant(){ |
| | | return NacosConfigCache.getAdminUserInfo().getTenantId().equals(AuthUtil.getTenantId()) |
| | | && NacosConfigCache.getAdminUserInfo().getUserName().equals(AuthUtil.getUserName()); |
| | | } |
| | | |
| | | 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) { |
| | |
| | | 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) { |
| | |
| | | return 0L; |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static Integer getCurrentUserSecret() { |
| | | SessionInfo currentUserSession = getCurrentUserSessionInfoNotException(); |
| | | return currentUserSession != null ? getInt(currentUserSession.getUserSecret()) : UserSecretEnum.NONE.getValue(); |
| | | } |
| | | |
| | | public static float getFloat(String s) { |
| | |
| | | return 0.0D; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | public static boolean getBoolean(String s) { |
| | | return BooleanEnum.TRUE.getValue().equals(s); |
| | | } |
| | | |
| | | public static String removeComma(String s) { |
| | |
| | | return allField; |
| | | } |
| | | |
| | | public static String getTableName(String btmname) { |
| | | return (VciQueryWrapperForDO.USER_TABLE_COMPATIBILITY ? "PLBT_CODE" : "PL_CODE_") + btmname.trim().toLowerCase(); |
| | | } |
| | | |
| | | public static String getTableName(String btmname,Boolean isMdmTable) { |
| | | return (isMdmTable ? "PLBT_CODE_" : "PL_CODE_") + btmname.trim().toUpperCase(Locale.ROOT); |
| | | } |
| | | |
| | | public static Field getTsField(Class c) { |
| | | List<Field> allField = getAllFieldForObj(c); |
| | | if (allField != null && allField.size() > 0) { |
| | |
| | | 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) { |
| | |
| | | |
| | | } |
| | | |
| | | public static void setValueForField(String fieldName, Object obj, String value) { |
| | | try { |
| | | Field field = getFieldForObject(fieldName, obj); |
| | | if (field != null) { |
| | | setValueForField(field, obj, value); |
| | | } |
| | | } catch (Exception var4) { |
| | | if (log.isErrorEnabled()) { |
| | | log.error("设置属性的值出错了错误", var4); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 将 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 = ""; |
| | | if(existFild == null){ |
| | | existFild = new HashSet<>(); |
| | | } |
| | | 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.trim()); |
| | | } |
| | | } |
| | | } |
| | | 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 instanceof String){ |
| | | result=((String) result).trim(); |
| | | } |
| | | |
| | | 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).toLowerCase():propertyName.toLowerCase(), result); |
| | | } |
| | | } 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; |
| | | } |
| | | Object result=mapData.get(o); |
| | | if(result instanceof String){ |
| | | result=((String) result).trim(); |
| | | } |
| | | returnMap.put(String.valueOf(o).toLowerCase(),result); |
| | | } |
| | | } |
| | | 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对应的setter方法 |
| | | Method setter = property.getWriteMethod(); |
| | | Class<?> type = property.getPropertyType(); |
| | | // 强转为字段的类型,不需要时可以去除,依赖commons-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("【Map转换实体异常】", 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(); |
| | | } |
| | | public static String convertArabicToRoman(int num) { |
| | | int[] values={1000,900,500,400,100,90,50,40,10,9,5,4,1}; |
| | | String[] romans={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; |
| | | StringBuilder sb=new StringBuilder(); |
| | | for(int i=0;i<values.length;i++){ |
| | | while(num>=values[i]){ |
| | | num=num-values[i]; |
| | | sb.append(romans[i]); |
| | | } |
| | | } |
| | | return sb.toString(); |
| | | } |
| | | /** |
| | | * 把罗马数字转换为阿拉伯数字 |
| | | * @param m |
| | | * @return |
| | | */ |
| | | public static int convertRomanToArabic(String m) { |
| | | int graph[] = new int[400]; |
| | | graph['I'] = 1; |
| | | graph['V'] = 5; |
| | | graph['X'] = 10; |
| | | graph['L'] = 50; |
| | | graph['C'] = 100; |
| | | graph['D'] = 500; |
| | | graph['M'] = 1000; |
| | | char[] num = m.toCharArray(); |
| | | int sum = graph[num[0]]; |
| | | for (int i = 0; i < num.length - 1; i++) { |
| | | if (graph[num[i]] >= graph[num[i + 1]]) { |
| | | sum += graph[num[i + 1]]; |
| | | } else { |
| | | sum = sum + graph[num[i + 1]] - 2 * graph[num[i]]; |
| | | } |
| | | } |
| | | return sum; |
| | | } |
| | | /*** |
| | | * 校验是否是罗马数字 |
| | | * @param s |
| | | * @return |
| | | */ |
| | | public static boolean isRoman(String s) { |
| | | // 检查输入的字符串是否为空 |
| | | if (s == null || s.length() == 0) { |
| | | return false; |
| | | } |
| | | // 将输入的字符串转换为大写字母 |
| | | s = s.toUpperCase(); |
| | | // 返回结果 |
| | | Pattern pattern = Pattern.compile("^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"); |
| | | return pattern.matcher(s ).matches(); |
| | | } |
| | | |
| | | public static String intToRomanTwo(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]; |
| | | } |
| | | } |
| | | |