ludc
2024-07-09 5acc490fa6f77a9ed7b5976ee6a2e22b070df5bf
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/util/VciBaseUtil.java
@@ -1,8 +1,12 @@
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;
import com.vci.corba.common.PLException;
import com.vci.starter.web.annotation.Id;
import com.vci.starter.web.annotation.VciBtmType;
import com.vci.starter.web.annotation.VciLinkType;
@@ -48,6 +52,23 @@
public class VciBaseUtil {
    /**
     * 获取异常信息,因为抛出的异常不同,获取错误信息的方式存在差异所以无法统一获取
     * 后续有其他异常需要获取,自行添加处理逻辑,
     * @param e
     * @return
     */
    public static String getExceptionMessage(Exception e){
        String exceptionStr = VciExceptionTool.getExceptionStr(e);
        if(exceptionStr.contains("VciBaseException")){
            return e.getMessage();
        }else if(exceptionStr.contains("PLException")){
            return Arrays.stream(((PLException) e).messages).collect(Collectors.joining("\n"));
        }else {
            return e.getMessage();
        }
    }
    /**
     * 日志对象
     */
    private static Logger log = LoggerFactory.getLogger(VciBaseUtil.class);
@@ -59,6 +80,19 @@
     */
    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();
    }
    /**
@@ -1929,4 +1963,15 @@
        }
        return new String(c);
    }
    /**
     * 将string集合转为stirng数组
     * @param strCollection string集合
     * @return string数组
     */
    public static String[] collection2StrArr(Collection<String> strCollection){
        String[] strArr = new String[strCollection.size()];
        strCollection.toArray(strArr);
        return strArr;
    }
}