package com.unis.rotationPlan.info.modular.businessrpreport.util;

import com.unis.rotationPlan.info.modular.businessrpreport.entity.BusinessRpInbound;
import com.unis.rotationPlan.info.modular.businessrpreport.entity.BusinessRpOutbound;
import com.unis.rotationPlan.info.modular.businessrpreport.enums.BusinessRpItem;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataConverter {

    public static List<Map<String, Object>> convertData(List<BusinessRpOutbound> outboundList, List<BusinessRpInbound> inboundList) {
        Map<String, Map<String, List<BusinessRpItem>>> dataMap = new HashMap<>();

        // 处理出库数据
        for (BusinessRpOutbound outbound : outboundList) {
            dataMap.computeIfAbsent(outbound.getOrgName(), k -> new HashMap<>())
                    .computeIfAbsent("businessRpOutboundList", k -> new ArrayList<>())
                    .add(outbound);
        }

        // 处理入库数据
        for (BusinessRpInbound inbound : inboundList) {
            dataMap.computeIfAbsent(inbound.getOrgName(), k -> new HashMap<>())
                    .computeIfAbsent("businessRpInboundList", k -> new ArrayList<>())
                    .add(inbound);
        }

        // 构建最终结果
        List<Map<String, Object>> result = new ArrayList<>();
        for (Map.Entry<String, Map<String, List<BusinessRpItem>>> entry : dataMap.entrySet()) {
            Map<String, Object> orgEntry = new HashMap<>();
            orgEntry.put("orgName", entry.getKey());
            orgEntry.putAll(entry.getValue());
            result.add(orgEntry);
        }

        return result;
    }

    public static void main(String[] args) {

//        List<BusinessRpOutbound> outboundList = ...; // 初始化您的出库数据列表
//        List<BusinessRpInbound> inboundList = ...; // 初始化您的入库数据列表
//
//         转换数据
//        List<Map<String, Object>> convertedData = convertData(outboundList, inboundList);
//
//        // 输出或进一步处理转换后的数据
//        for (Map<String, Object> data : convertedData) {
//            System.out.println(data);
//        }
    }
}
