package com.sifang.modules.taskdispatch.util;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.customer.Service.CustomerEntryService;
import com.sifang.modules.flowable.service.ItemManageService;
import com.sifang.modules.sunshine.SystemSetting.utils.BusinessException;
import com.sifang.modules.sys.util.SpringUtils;
import org.apache.commons.lang.StringUtils;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class BatchItemPriority {

    private final List<Record> items;
    private final String formKey;

    public BatchItemPriority(List<String> itemIds) {
        List<Record> itemManages = SpringUtils.getBean(ItemManageService.class).findByIds(itemIds);
        this.items = itemManages;
        Set<String> formKeys = itemManages.stream().map(e -> e.getStr("form_key")).collect(Collectors.toSet());
        if (formKeys.size() > 1) {
            throw new BusinessException("待办事项必须为同一审核类型！");
        }
        this.formKey = formKeys.iterator().next();
    }

    public List<Record> getItems() {
        return items;
    }

    public String getFormKey() {
        return formKey;
    }


}
