| | |
| | | package com.vci.starter.web.util; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | 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.vci.common.exception.VciExceptionTool; |
| | |
| | | * @param e |
| | | * @return |
| | | */ |
| | | public static String getExceptionMessage(Exception e){ |
| | | public static String getExceptionMessage(Throwable e){ |
| | | String exceptionStr = VciExceptionTool.getExceptionStr(e); |
| | | if(exceptionStr.contains("VciBaseException")){ |
| | | return e.getMessage(); |
| | |
| | | */ |
| | | public static String getPk() { |
| | | return UUID.randomUUID().toString(); |
| | | } |
| | | |
| | | /** |
| | | * 雪花ID |
| | | * @return |
| | | */ |
| | | public static String getSnowflakePk() { |
| | | return String.valueOf(getSnowflakePk(1,1)); |
| | | } |
| | | |
| | | public static Long getSnowflakePk(long workerId,long dataCenterId){ |
| | | Snowflake snowflake = IdUtil.getSnowflake(workerId,dataCenterId); |
| | | return snowflake.nextId(); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 去除最前面的spiltFilter,去除后面的spiltFilter |
| | | * @param s 字符串 |
| | | * @param spiltFilter,分隔符 |
| | | * @return 去除末尾逗号 |
| | | */ |
| | | public static String removeComma(String s,String spiltFilter){ |
| | | if(s == null || s.trim().length() == 0) { |
| | | return s; |
| | | } |
| | | else{ |
| | | if(s.startsWith(spiltFilter)) { |
| | | s = s.substring(spiltFilter.length(), s.length()); |
| | | } |
| | | if(s.endsWith(spiltFilter)) { |
| | | s = s.substring(0, s.length() - spiltFilter.length()); |
| | | } |
| | | return s; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 为sql中使用in时,提供转换,注意in里的值不能超过1000 |
| | | * @param s 字符串 |
| | | * @return 返回sql语句 |
| | |
| | | charMap.put(String.valueOf(c), (!charMap.containsKey(String.valueOf(c))? 1 : charMap.get(String.valueOf(c)) + 1)); |
| | | } |
| | | return charMap.get(String.valueOf(findC)); |
| | | } |
| | | |
| | | /** |
| | | * 带逗号的字符串转为list |
| | | * @param s 字符串 |
| | | * @return 字符串列表 |
| | | */ |
| | | public static List<String> str2List(String s,String spilter){ |
| | | if (isNull(s)) { |
| | | return null; |
| | | } else { |
| | | List<String> l = new ArrayList<String>(); |
| | | Collections.addAll(l,removeComma(s,spilter).split(spilter)); |
| | | return l; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 数组转换为String |
| | | * @param array 数组对象 |
| | | * @param spiltFiter 分隔符 |
| | | * @return 逗号链接的字符串 |
| | | */ |
| | | public static String array2String(String[] array,String spiltFiter) { |
| | | if(null == array || array.length == 0) { |
| | | return ""; |
| | | } else{ |
| | | String ss = ""; |
| | | for(String s : array){ |
| | | ss += s + spiltFiter; |
| | | //1.8可以 |
| | | } |
| | | return removeComma(ss,spiltFiter); |
| | | } |
| | | } |
| | | /** |
| | | * 数组转换为String |
| | | * @param array 数组对象 |