package com.cf.imes.module.executor.util.fileConversion.admin.files.excel;

import cn.hutool.json.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRemark;
import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
import com.cf.imes.module.executor.dal.dataobject.orderGroup.OrderGroupDO;
import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO;
import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
import com.cf.imes.module.executor.enums.OrderItemTypeEnum;
import com.cf.imes.module.executor.util.deviseData.structure.FieldConstants;
import com.cf.imes.module.executor.util.deviseData.structure.PlateDetail;
import com.cf.imes.module.system.api.dict.DictDataApi;
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
import com.cf.imes.module.executor.enums.DictTypeConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 实现数据格式转换
 * 使用自带id
 */
@Slf4j
@Component
public class ExcelTypeRealize {

    @Resource
    private SnowFlakeGenerator snowFlakeGenerator;

    @Resource
    private SnowflakeIdWorker3rd idWorker;

    @Resource
    private DictDataApi dictDataApi;


    final String NOT_ASSIGNED = "未命名";
    final String PLATE = "plate";
    final String PARTS = "parts";
    final String NO_CODE = "no_code_1132589&";

    // 数据转换 + 错误验证
    public Map<String, Object> changeDate(List<OrderPlateImportExcelVO> excelVOS, Long orderId) {
        if (excelVOS.isEmpty()) {
            return null;
        }

        long startTime = System.currentTimeMillis();

        Map<String, Object> map = new HashMap<>();

        Long organId = OrganContextHolder.getOrganId();
        ArrayList<RawGoodsDO> rawGoodsDOS = new ArrayList<>();
        ArrayList<GoodsDO> goodsDOS = new ArrayList<>();
        ArrayList<OrderBodyDO> orderBodyDOS = new ArrayList<>();
        ArrayList<OrderGroupDO> orderGroupDOS = new ArrayList<>();
        ArrayList<PlateDO> plateDOS = new ArrayList<>();
        ArrayList<OrderPartsDO> orderPartsDOS = new ArrayList<>();
        ArrayList<OrderItemDO> orderItemDOS = new ArrayList<>();
        ArrayList<PlateDetail> plateDetail = new ArrayList<>();
        ArrayList<OrderPartsRemark> orderPartsRemarks = new ArrayList<>();

        HashMap<String, List<OrderPlateImportExcelVO>> checkMap = classifyGoods(excelVOS);

        Map<String, List<OrderPlateImportExcelVO>> goodsIdMap = checkMap.get(PLATE).stream().collect(
                Collectors.groupingBy(
                        excelVO -> excelVO.getGoodsId() != null && !StringUtils.isEmpty(excelVO.getGoodsId())? excelVO.getGoodsId() : NO_CODE,
                        Collectors.toList()
                ));
        goodsIdMap.forEach((key, value) -> {
            if (NO_CODE.equals(key)) { // 没有商品编号的 value.get(0).getGoodsId() == null
//                将相同条件的元素归为一个集合
                Map<List<Object>, List<OrderPlateImportExcelVO>> goodsMap = value.stream()
                        .collect(Collectors.groupingBy(
                                p -> Arrays.asList(p.getGoodsName(),
                                        p.getMaterial(),
//                                        p.getWave(), // 纹理
                                        p.getColor(),
//                                        p.getSpec(),
//                                        p.getGoodsHeight(),
//                                        p.getGoodsWidth(),
                                        p.getGoodsThickness(),
                                        p.getBrand()),
                                Collectors.toList()
                        ));

                goodsMap.forEach((goodKey, goodValue) -> {
//                    板材信息合集，添加订单id，添加订单板材设计端商品编码，板材信息写入order_raw_goods
                    RawGoodsDO rawGoodsDO = setRawGoodsDO(goodValue.get(0)).setId((Long) snowFlakeGenerator.nextId(null)).setOrderId(orderId);
                    rawGoodsDOS.add(rawGoodsDO);
                    Long goodId = (Long) snowFlakeGenerator.nextId(null);
                    GoodsDO plateDO = setGoodsDO(goodValue.get(0)).setId(goodId).setOrderId(orderId)
                            .setRawGoodsId(String.valueOf(rawGoodsDO.getId()))
                            .setHeight(BigDecimal.valueOf(Double.parseDouble(goodValue.get(0).getGoodsHeight())))
                            .setWidth(BigDecimal.valueOf(Double.parseDouble(goodValue.get(0).getGoodsWidth())))
                            .setThickness(BigDecimal.valueOf(Double.parseDouble(goodValue.get(0).getGoodsThickness()))); // 在good_id为空的时候，首先赋值为空值
                    goodsDOS.add(plateDO);
//                  赋值给板件未对应前order_raw_goods的id
                    for (OrderPlateImportExcelVO reqVO : goodValue) {
                        reqVO.setGoodId(goodId);
                    }
                });
            } else { // 商品编码有的
//              板材信息合集，添加订单id，添加订单板材设计端商品编码，板材信息写入order_raw_goods
                RawGoodsDO rawGoodsDO = setRawGoodsDO(value.get(0)).setId((Long) snowFlakeGenerator.nextId(null)).setOrderId(orderId);
                rawGoodsDOS.add(rawGoodsDO);
                Long goodId = (Long) snowFlakeGenerator.nextId(null);
                GoodsDO goodsDO = setGoodsDO(value.get(0)).setId(goodId).setOrderId(orderId)
                        .setRawGoodsId(String.valueOf(rawGoodsDO.getId())).setGoodsId(String.valueOf(rawGoodsDO.getRawGoodsId()))
                        .setHeight(BigDecimal.valueOf(Double.parseDouble(value.get(0).getGoodsHeight())))
                        .setWidth(BigDecimal.valueOf(Double.parseDouble(value.get(0).getGoodsWidth())))
                        .setThickness(BigDecimal.valueOf(Double.parseDouble(value.get(0).getGoodsThickness())));
                goodsDOS.add(goodsDO);
//              赋值给板件未对应前order_raw_goods的id
                for (OrderPlateImportExcelVO reqVO : value) {
                    reqVO.setGoodId(goodId);
                }
            }
        });

        // 配件信息合集，添加订单id，添加订单配件设计端商品编码，配件信息写入order_parts
        Map<String, List<OrderPlateImportExcelVO>> partsIdMap = checkMap.get(PARTS).stream().collect(
                Collectors.groupingBy(
                        excelVO -> excelVO.getGoodsId() != null && !StringUtils.isEmpty(excelVO.getGoodsId())? excelVO.getGoodsId() : " ",
                        Collectors.toList()
                ));
        partsIdMap.forEach((key, value) -> {
            if (key.equals(" ")) { // 没有商品编号的 value.get(0).getGoodsId() == null
//                将相同条件的元素归为一个集合
                Map<List<Object>, List<OrderPlateImportExcelVO>> partsMap = value.stream()
                        .collect(Collectors.groupingBy(
                                p -> Arrays.asList(p.getGoodsName(),
                                        p.getMaterial(),
                                        p.getColor(),
                                        p.getIsComposite(),
                                        p.getCategory(),
                                        p.getType(),
                                        p.getFactory(),
                                        p.getModel(),
                                        p.getSpec(),
                                        p.getGoodsHeight(),
                                        p.getGoodsWidth(),
                                        p.getGoodsThickness(),
                                        p.getUnit(),
                                        p.getBrand()),
                                Collectors.toList()
                        ));

                partsMap.forEach((partKey, partValue) -> {
//                    配件信息集合，key不同，生成不同的id，写入order_parts表中
                    Long partId = (Long) snowFlakeGenerator.nextId(null);
                    OrderPlateImportExcelVO part = partValue.get(0);
                    OrderPartsDO orderPartsDO = OrderPartsDO.builder().id(partId).orderId(orderId)
                            .color(part.getColor()).category(part.getCategory()).type(part.getType())
                            .length(Double.valueOf(StringUtils.isEmpty(part.getGoodsHeight()) ? "0" : part.getGoodsHeight()))
                            .width(Double.valueOf(StringUtils.isEmpty(part.getGoodsWidth()) ? "0" : part.getGoodsWidth()))
                            .thickness(Double.valueOf(StringUtils.isEmpty(part.getGoodsThickness()) ? "0" : part.getGoodsThickness()))
                            .isComposite(Boolean.valueOf(part.getIsComposite()))
                            .name(part.getGoodsName()).material(part.getMaterial())
                            .model(part.getModel()).spec(part.getSpec()).brand(part.getBrand()).factory(part.getFactory())
                            .unit(part.getUnit()).price(0.0).isComposite(false).remark(remarkExtract(part.remarkJSON())).isComposite(false).build();
                    orderPartsDOS.add(orderPartsDO);
//                  赋值给板件未对应前order_raw_goods的id
                    StringBuilder remark = new StringBuilder();
                    for (OrderPlateImportExcelVO reqVO : partValue) {
                        reqVO.setGoodId(partId);
                        String extractedRemark = remarkExtract(reqVO.remarkJSON());
                        if (extractedRemark != null) {
                            remark.append(extractedRemark);
                        }
                    }
                    // 配件备注信息存储
                    OrderPartsRemark orderPartsRemark = OrderPartsRemark.builder().partsId(partId).orderId(orderId)
                            .remark(String.valueOf(remark)).build();
                    orderPartsRemarks.add(orderPartsRemark);
                });
            } else { // 商品编码有的
//              板材信息合集，添加订单id，添加订单板材设计端商品编码，板材信息写入order_raw_goods
                Long partId = (Long) snowFlakeGenerator.nextId(null);
                OrderPlateImportExcelVO part = value.get(0);
                OrderPartsDO orderPartsDO = OrderPartsDO.builder().id(partId).orderId(orderId)
                        .color(part.getColor()).category(part.getCategory()).type(part.getType()).goodsId(part.getGoodsId())
                        .length(Double.valueOf(StringUtils.isEmpty(part.getGoodsHeight()) ? "0" : part.getGoodsHeight()))
                        .width(Double.valueOf(StringUtils.isEmpty(part.getGoodsWidth()) ? "0" : part.getGoodsWidth()))
                        .thickness(Double.valueOf(StringUtils.isEmpty(part.getGoodsThickness()) ? "0" : part.getGoodsThickness()))
                        .isComposite(Boolean.valueOf(part.getIsComposite()))
                        .name(part.getGoodsName()).material(part.getMaterial())
                        .model(part.getModel()).spec(part.getSpec()).brand(part.getBrand()).factory(part.getFactory())
                        .unit(part.getUnit()).price(0.0).isComposite(false).remark(remarkExtract(part.remarkJSON())).isComposite(false).build();
                orderPartsDOS.add(orderPartsDO);
//              赋值给板件未对应前order_raw_goods的id
                StringBuilder remark = new StringBuilder();
                for (OrderPlateImportExcelVO reqVO : value) {
                    reqVO.setGoodId(partId);
                    String extractedRemark = remarkExtract(reqVO.remarkJSON());
                    if (extractedRemark != null) {
                        remark.append(extractedRemark);
                    }
                }
                // 配件备注信息存储
                OrderPartsRemark orderPartsRemark = OrderPartsRemark.builder().partsId(partId).orderId(orderId)
                        .remark(String.valueOf(remark)).build();
                orderPartsRemarks.add(orderPartsRemark);
            }
        });


        // 房间名称为条件进行分组
        Map<String, List<OrderPlateImportExcelVO>> roomCollect = excelVOS.stream().collect(
                Collectors.groupingBy(
                        excelVO -> excelVO.getRoomsName() != null && !StringUtils.isEmpty(excelVO.getRoomsName())? excelVO.getRoomsName() : NOT_ASSIGNED,
                        Collectors.toList()
                ));

        roomCollect.forEach((roomName, listRoom) -> {
            Long roomId = (Long) snowFlakeGenerator.nextId(null);
            // 柜体名称为条件进行分组
            Map<String, List<OrderPlateImportExcelVO>> bodyCollect = listRoom.stream()
                    .collect(Collectors.groupingBy(
                            excelVO -> excelVO.getCabinetsName() != null && !StringUtils.isEmpty(excelVO.getCabinetsName())? excelVO.getCabinetsName() : NOT_ASSIGNED,
                            Collectors.toList()
                    ));

            bodyCollect.forEach((bodyName, listBody) -> {
                Long bodyId = (Long) snowFlakeGenerator.nextId(null);
                final Double[] plateCountByCabinetName = {0.0};
                OrderBodyDO orderBodyDO = OrderBodyDO.builder().id(bodyId).orderId(orderId).organId(organId)
                        .roomId(roomId).roomName(roomName).name(bodyName).width(0.0).height(0.0)
                        .depth(0.0).multiNum(0).plateNum(0).unregularNum(0).filename("无").remark("无").build(); //没有获取柜体的长宽高


                // 加工组类型为条件进行分组
                Map<String, List<OrderPlateImportExcelVO>> synthesisCollect = listBody.stream()
                        .collect(Collectors.groupingBy(
                                excelVO -> excelVO.getSynthesisTypeName() != null && !StringUtils.isEmpty(excelVO.getSynthesisTypeName()) ? excelVO.getSynthesisTypeName() : " ",
                                Collectors.toList()
                        ));

                synthesisCollect.forEach((synthesisTypeName, listSynthesis) -> {
                    Long groupTypeId = (Long) snowFlakeGenerator.nextId(null);
                    // 加工组名称为条件进行分组
                    Map<String, List<OrderPlateImportExcelVO>> combinationNameCollect = listSynthesis.stream()
                            .collect(Collectors.groupingBy(
                                    excelVO -> excelVO.getCombinationName() != null && !StringUtils.isEmpty(excelVO.getCombinationName())? excelVO.getCombinationName() : " ",
                                    Collectors.toList()
                            ));
                    combinationNameCollect.forEach((combinationName, listCombinationName) -> {
//                            板数量
                        final Double[] plateCountByCombination = {0.0};
                        Long groupId = (Long) snowFlakeGenerator.nextId(null);
                        OrderGroupDO orderGroupDO = OrderGroupDO.builder().id(groupId).orderId(orderId).organId(organId).bodyId(bodyId)
                                .groupTypeId(groupTypeId).groupTypeName(synthesisTypeName).name(!Objects.equals(combinationName, " ") ? combinationName : synthesisTypeName).width(0.0).height(0.0)
                                .depth(0.0).multiNum(0).plateNum(0).unregularNum(0).filename("无").remark("无").build();

                        listCombinationName.forEach(combination -> {

                            if (combination.getGoodType().equals("板材")) {
                                //板材
                                plateCountByCombination[0] = plateCountByCombination[0] + Double.parseDouble(combination.getGoodsNumber());
//                                System.out.println(" 房间名0 " + combination.getRoomsName() + " 柜体名0 " + combination.getCabinetsName() + " 柜体板数量0 " + plateCountByCabinetName[0] + " 加工组板数量0 " + plateCountByCombination[0]);

                                for (int i = 0; i < Integer.parseInt(combination.getGoodsNumber()); i++) {
                                    long plateNo = idWorker.nextId();
                                    long obtainingTime = idWorker.obtainingTime();

                                    // 计算面积
                                    BigDecimal area = BigDecimal.valueOf(Double.parseDouble(combination.getWidth()))
                                            .multiply(BigDecimal.valueOf(Double.parseDouble(combination.getHeight())))
                                            .movePointLeft(6)
                                            .setScale(2, RoundingMode.HALF_UP);
                                    Long plateId = (Long) snowFlakeGenerator.nextId(null);
                                    // 排版面 纹路 开门方向转换
                                    DictDataRespDTO typographyDTO = dictDataApi.parseDictData(DictTypeConstants.TYPOGRAPHY_TYPE, combination.getTypographicFace()).getData();// 排版面
                                    DictDataRespDTO grainDTO = dictDataApi.parseDictData(DictTypeConstants.GRAIN_TYPE, combination.getTexture()).getData();// 纹路
                                    DictDataRespDTO doorDTO = dictDataApi.parseDictData(DictTypeConstants.DOOR_OPENING_DIRECTIONS, combination.getOpenDoorType()).getData();

                                    PlateDO plateDO = PlateDO.builder()
                                            .id(plateId).orderId(orderId)
                                            .name(combination.getName())
                                            .plateNo(combination.getPlateNo())
                                            .goodsId(combination.getGoodId())
                                            .width(BigDecimal.valueOf(Double.parseDouble(combination.getWidth())))
                                            .plateNo(((obtainingTime) + Long.toString(plateNo).substring(2)))
                                            .height(BigDecimal.valueOf(Double.parseDouble(combination.getHeight())))
                                            .thickness(BigDecimal.valueOf(Double.parseDouble(combination.getThickness())))
                                            .splitWidth(BigDecimal.valueOf(Double.parseDouble(combination.getSplitWidth())))
                                            .splitHeight(BigDecimal.valueOf(Double.parseDouble(combination.getSplitHeight())))
                                            .splitThickness(BigDecimal.valueOf(Double.parseDouble(combination.getThickness())))
                                            .sealLeft(BigDecimal.valueOf(Double.parseDouble(combination.getSealLeft())))
                                            .sealRight(BigDecimal.valueOf(Double.parseDouble(combination.getSealRight())))
                                            .sealUp(BigDecimal.valueOf(Double.parseDouble(combination.getSealUp())))
                                            .sealDown(BigDecimal.valueOf(Double.parseDouble(combination.getSealDown())))
                                            .holeFace(Integer.valueOf(typographyDTO.getValue()))
                                            .texture(Integer.valueOf(grainDTO.getValue()))
                                            .area(area)
                                            .openDoorType(Integer.valueOf(doorDTO.getValue()))
                                            .isSpecialShaped(false)
                                            .isSculpt(false)
                                            .remark(remarkExtract(combination.remarkJSON()))
                                            .roomName(roomName)
                                            .bodyName(bodyName)
                                            .customPlateNoBuilder(new StringBuilder())
                                            .build();
                                    plateDOS.add(plateDO);

                                    OrderItemDO orderItemDO = OrderItemDO.builder().orderId(orderId).type(OrderItemTypeEnum.PLATE_ITEM.getStatus())
                                            .roomId(roomId).bodyId(bodyId).plateId(plateId)
                                            .num(1.0).groupId(synthesisTypeName != " " ? groupId : null).build();
                                    orderItemDOS.add(orderItemDO);
                                    plateDetail.add(PlateDetail.builder().orderId(orderId).plateId(plateId)
                                            .typographicFace(Integer.valueOf(typographyDTO.getValue()))
                                            .texture(plateDO.getTexture()).openDoorType(plateDO.getOpenDoorType()).build());
                                }


                            } else {
                                //配件
                                OrderItemDO orderItemDO = OrderItemDO.builder().orderId(orderId).type(OrderItemTypeEnum.PARTS_ITEM.getStatus())
                                        .roomId(roomName != " " ? roomId : null).bodyId(bodyName != " " ? bodyId : null).partsId(combination.getGoodId()).groupId(synthesisTypeName != " " ? groupId : null)
                                        .num(Double.valueOf(combination.getGoodsNumber())).build();
                                orderItemDOS.add(orderItemDO);
                            }

                        });
                        orderGroupDO.setPlateNum(plateCountByCombination[0].intValue());
                        plateCountByCabinetName[0] = plateCountByCabinetName[0] + plateCountByCombination[0];
                        if (orderGroupDO.getGroupTypeName() != null && !orderGroupDO.getGroupTypeName().trim().isEmpty()) {
                            orderGroupDOS.add(orderGroupDO);
                        }
                    });
                });
                orderBodyDO.setPlateNum(Integer.valueOf(plateCountByCabinetName[0].intValue()));
                orderBodyDOS.add(orderBodyDO);
            });
        });

        map.put(FieldConstants.RAW_GOODS, rawGoodsDOS);
        map.put(FieldConstants.GOODS, goodsDOS);
        map.put(FieldConstants.BODY, orderBodyDOS);
        map.put(FieldConstants.GROUP, orderGroupDOS);
        map.put(FieldConstants.PLATE, plateDOS);
        map.put(FieldConstants.PARTS, orderPartsDOS);
        map.put(FieldConstants.ITEM, orderItemDOS);
        map.put(FieldConstants.PLATE_DETAIL, plateDetail);
        map.put(FieldConstants.PARTS_REMARK, orderPartsRemarks);
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;

        System.out.println("方法运行耗时 excel 转换: " + duration + " 毫秒");
        return map;
    }

    private String remarkExtract(String remark) {
        JSONObject jsonObject = new JSONObject(remark);
        List<Object> nonNullValues = new ArrayList<>();

        for (String key : jsonObject.keySet()) {
            Object value = jsonObject.get(key);
            if (value != null && !value.toString().trim().isEmpty()) {
                nonNullValues.add(value);
            }

        }

        return nonNullValues.size() == 0 ? "" : nonNullValues.toString().replace("[", "").replace("]", "");
    }


    // RawGoodsDO数据
    private RawGoodsDO setRawGoodsDO(OrderPlateImportExcelVO excelVO) {
        if (StringUtils.equals(excelVO.getWave().trim(), "无")) {
            excelVO.setWave("false");
        } else if (StringUtils.equals(excelVO.getWave().trim(), "有")) {
            excelVO.setWave("true");
        }
        return RawGoodsDO.builder()
//                .id(rawGoodsId)
//                .orderId(orderId)
                .rawGoodsId(excelVO.getGoodsId())
                .goodsName(excelVO.getGoodsName())
                .material(excelVO.getMaterial())
                .texture(Boolean.valueOf(excelVO.getWave()))
                .color(excelVO.getColor())
                .thickness(Double.valueOf(excelVO.getThickness()))
                .spec(excelVO.getSpec())
                .brand(excelVO.getBrand())
                .build();
    }

    // GoodsDO数据
    private GoodsDO setGoodsDO(OrderPlateImportExcelVO excelVO) {
        if (StringUtils.equals(excelVO.getWave().trim(), "无")) {
            excelVO.setWave("false");
        } else if (StringUtils.equals(excelVO.getWave().trim(), "有")) {
            excelVO.setWave("true");
        }
        return GoodsDO.builder()
//                .id(goodId)
//                .orderId(orderId)
//                .rawGoodsId(rawGoodsId)
//                .goodsId(plateGoodId)
                .goodsName(excelVO.getGoodsName())
                .material(excelVO.getMaterial())
                .texture(Boolean.valueOf(excelVO.getWave()))
                .color(excelVO.getColor())
                .width(BigDecimal.valueOf(Double.valueOf(excelVO.getWidth())))
                .height(BigDecimal.valueOf(Double.valueOf(excelVO.getHeight())))
                .thickness(BigDecimal.valueOf(Double.valueOf(excelVO.getThickness())))
                .spec(excelVO.getSpec())
                .brand(excelVO.getBrand())
                .build();
    }

    // spec分离数据
    public List<Double> spec(String spec) {
        List<Double> list = new ArrayList<>();

        String[] parts = spec.split("\\×");
        if (parts.length <= 1) {
            return null;
        }
        for (int i = 0; i < 3; i++) {
            Double num = 0.0;
            try {
                if (i < parts.length)
                    num = Double.parseDouble(parts[i]);
            } catch (NumberFormatException e) {
                // 转换失败，保持num为0
            }
            list.add(num);
        }
        return list;
    }

    //    对数据进行分类
    private HashMap<String, List<OrderPlateImportExcelVO>> classifyGoods(List<OrderPlateImportExcelVO> list) {
        HashMap<String, List<OrderPlateImportExcelVO>> map = new HashMap<>();
        List<OrderPlateImportExcelVO> plateLists = new ArrayList<>();
        List<OrderPlateImportExcelVO> partsLists = new ArrayList<>();
        for (OrderPlateImportExcelVO detail : list) {
            //判断是板材还是配件
            if (detail.getGoodType().equals("板材")) {
                plateLists.add(detail);
            } else {
                partsLists.add(detail);
            }
        }
        map.put(PLATE, plateLists);
        map.put(PARTS, partsLists);
        return map;
    }
}
