package cn.superdesk.uniorder.dao.utils;

import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceType;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Description: Java类作用描述
 * @Author: linjinyu
 * @CreateDate: 2022/4/27 11:35 上午
 * @UpdateUser: linjinyu
 * @UpdateDate: 2022/4/27 11:35 上午
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@NoArgsConstructor
@Slf4j
public class AnEntitySortedListUtils {

    /**
     * 根据orderList顺序排序,orderList不存在的元素放置在targetList最后面
     *
     * @param orderList
     * @param targetList
     */
    public static void sortInvoiceTypeTargetList1(List<Long> orderList, List<InvoiceType> targetList) {

        targetList.sort(((o1, o2) -> {

            int io1 = orderList.indexOf(o1.getId());
            int io2 = orderList.indexOf(o2.getId());

            if (io1 != -1) {
                io1 = targetList.size() - io1;
            }

            if (io2 != -1) {
                io2 = targetList.size() - io2;
            }

            return io2 - io1;
        }));
    }

    /**
     * 根据orderList顺序排序,orderList不存在的元素放置在targetList最前面
     *
     * @param orderList
     * @param targetList
     */
    public static void sortInvoiceTypeTargetList2(List<Long> orderList, List<InvoiceType> targetList) {

        targetList.sort(((o1, o2) -> {

            int io1 = orderList.indexOf(o1.getId());
            int io2 = orderList.indexOf(o2.getId());

            return io1 - io2;
        }));
    }
}
