package com.jkcredit.invoice.hub.util;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @description:
 * @author: xusonglin
 * @create: 2020/1/9 21:01
 * @version: V1.0
 **/
public class CommonUtil {
    // bigDecimal转double
    public static Double parseDouble(BigDecimal bigDecimal) {
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    // 生成requestId
    public static String getRequestId() {
        return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) + ","
                + UUID.randomUUID().toString();
    }

    // 获取差集
    public static List<Long> getSubtraction(Set<Long> primary, Set<Long> secondary) {
        primary.removeAll(secondary);
        return new ArrayList<>(primary);
    }

    // 获取交集
    public static List<Long> getIntersection(Set<Long> primary, Set<Long> secondary) {
        primary.retainAll(secondary);
        return new ArrayList<>(primary);
    }

    public static String dateFormat(Date time) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        return formatter.format(time);
    }
}
