package com.rongwei.bscommon.sys.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.StopWatch;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rongwei.bscommon.sys.dao.ApsProcessOperationProcessEquDao;
import com.rongwei.bscommon.sys.dao.ApsReportRecordsDao;
import com.rongwei.bscommon.sys.service.ApsProcessOperationBackupService;
import com.rongwei.bscommon.sys.service.ApsProcessOperationService;
import com.rongwei.bscommon.sys.service.GanttService;
import com.rongwei.bsentity.domain.ApsProcessOperationDo;
import com.rongwei.bsentity.vo.GanttVos;
import com.rongwei.bsentity.vo.ProcessOutputAndInputNumber;
import com.rongwei.bsentity.vo.ScheduleGanttVo;
import com.rongwei.commonservice.service.RedisService;
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
import com.rongwei.rwcommon.base.R;
import com.rongwei.rwcommon.base.exception.CustomException;
import com.rongwei.safecommon.utils.CXCommonUtils;
import org.apache.commons.lang.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

import static com.rongwei.safecommon.utils.SaveConstans.JobStatus.*;
import static com.rongwei.safecommon.utils.SaveConstans.ProcessWay.PROCESS_WAY_MERGE;
import static com.rongwei.safecommon.utils.SaveConstans.ProductionStatus.*;

/**
 * GanttServiceImpl class
 *
 * @author XH
 * @date 2024/03/25
 */
@Service
public class GanttServiceImpl implements GanttService {
    public static final String GANTT_ITEM_NAME = "%s %d卷 %s %s %tF";
    //    public static final String GANTT_ITEM_NAME_PREFIX = "%s %s";
//    public static final String GANTT_DESC_PREFIX = " 计划时间：%s-%s </br>" +
//            "实际时间：%s-%s </br>" +
//            "加工设备：%s/%s </br>";
//    public static final String GANTT_DESC =
//            "输入物料：%s %d卷</br>" +
//                    "工序：%s </br>" +
//                    "作业状态：%s </br>" +
//                    "完成情况：已开工 %d/已报工 %d/已检验 %d/未完工 %d </br>" +
//                    "客户订单号：%s </br>" +
//                    "客户名称：%s </br>" +
//                    "交货期：%tF </br>" +
//                    "订单产品：%s </br>";
    public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static final String DEFAULT_TYPE = "project";
    public static final String DEFAULT_RENDER = "split";
    public static final String SCHEDULING_STR = "%s-%s %s";
    public static final String DEFAULT_SPLIT = "-;-";
    public static final Map<String, String> GANTT_PROCESS_STATUS_MAP = new HashMap<String, String>() {{
        put(JOBSTATUS_TO_BE_START, TO_BE_STARTED);
        put(JOBSTATUS_TO_BE_STARTING, PROCESSING);
        put(JOBSTATUS_TO_BE_END, COMPLETED);
    }};
    public static final Map<String, Integer> NUM_MAP = new HashMap<String, Integer>() {{
        put("一", 1);
        put("二", 2);
        put("三", 3);
        put("四", 4);
        put("五", 5);
        put("六", 6);
        put("七", 7);
        put("八", 8);
        put("九", 9);
        put("十", 10);
    }};


    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    private ApsProcessOperationProcessEquDao apsProcessOperationProcessEquDao;
    @Autowired
    private ApsProcessOperationService apsProcessOperationService;
    @Autowired
    private RedissonClient redissonClient;
    @Autowired
    private RedisService redisService;
    @Autowired
    private ApsProcessOperationBackupService apsProcessOperationBackupService;
    @Autowired
    private ApsReportRecordsDao apsReportRecordsDao;

    /**
     * 根据条件获取gantt
     *
     * @param factoryId
     * @param workShopIdList
     * @param orderNoList
     * @param productionLineId
     * @param equId
     * @return
     */
    @Override
    public R getListByCondition(Date startDate, Date endDate, String factoryId,
                                List<String> workShopIdList, List<String> orderNoList,
                                List<String> productionLineId, List<String> equId,
                                String productionLineName, String equName, String blankNumber) {
        if (endDate == null && startDate != null) {
            List<Date> searchDateList = getSearchDate(startDate);
            startDate = searchDateList.get(0);
            endDate = searchDateList.get(1);
        }
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        List<GanttVos> apsProcessOperationProcessEquDos = apsProcessOperationProcessEquDao.getGanttDataList(
                startDate, endDate, factoryId, workShopIdList, orderNoList,
                null, productionLineId, equId, null, productionLineName, equName, blankNumber);
        stopWatch.stop();
        log.error("甘特图查询用时:{}", stopWatch.getTotalTimeSeconds());
        StopWatch stopWatch1 = new StopWatch();
        stopWatch1.start();
        List<ScheduleGanttVo> scheduleGanttVos = assembleGanttData(apsProcessOperationProcessEquDos);
        stopWatch1.stop();
        log.error("甘特图组装数据用时:{}", stopWatch1.getTotalTimeSeconds());
        return R.ok(scheduleGanttVos);
    }

    @Override
    public List<ScheduleGanttVo> getListById(List<String> ids) {
        List<GanttVos> apsProcessOperationProcessEquDos = apsProcessOperationProcessEquDao.getGanttDataList(
                null, null, null, null, null,
                null, null, null, ids, null, null,
                null);
        return assembleGanttData(apsProcessOperationProcessEquDos);
    }

    /**
     * 获取排程状态信息
     *
     * @return
     */
    @Override
    public R getSchedulingState(String factoryId) {
        log.info("开始获取排程状态");
        if (StringUtils.isBlank(factoryId)) {
            SysUserVo currentUser = CXCommonUtils.getCurrentUser();
            factoryId = CXCommonUtils.getCurrentUserFactoryId(currentUser);
        }
        log.debug("判断工厂:{}是否正在排程", factoryId);
        RLock rLock = redissonClient.getLock(factoryId);
        log.debug("是否正在排程：{}", rLock.isLocked());
        SysUserVo sysUserVo;
        try {
            sysUserVo = (SysUserVo) redisService.getRedisCatchObj("apsUser-" + factoryId);
        } catch (Exception e) {
            log.error("获取当前排程用户失败,原因：{}", e.toString());
            return R.error("获取排程用户失败,请联系管理员");
        }
        if (sysUserVo == null) {
            log.error("无法获取当前排程用户信息");
            return R.ok("");
        }
        String returnMsg="";
        //正在排程直接返回
        if (rLock.isLocked()) {
            returnMsg = String.format(SCHEDULING_STR, sysUserVo.getName(), "正在排程", "");
        } else {
            if (StringUtils.isNotBlank(sysUserVo.getRoption())) {
                returnMsg = String.format(SCHEDULING_STR, sysUserVo.getName(),"排程异常" ,":" + sysUserVo.getRoption());
            } else {
                returnMsg = String.format(SCHEDULING_STR, sysUserVo.getName(), "排程结束", "");
            }
        }
        return R.ok(returnMsg);
    }

    /**
     * 获取设备和车间信息
     *
     * @param factoryId
     * @return
     */
    @Override
    public R getWorkshopAndDevice(String factoryId) {
        if (StringUtils.isBlank(factoryId)) {
            log.error("工厂信息为空");
            return R.error("请选择需要获取排程信息的工厂");
        }
        List<GanttVos> workshopAndDeviceByFactoryId = apsProcessOperationProcessEquDao.getWorkshopAndDeviceByFactoryId(factoryId);
        // 需要返回给前端的数据
        List<ScheduleGanttVo> resultVo = new ArrayList<>();

        // 对数据按照加工车间分组
        LinkedHashMap<String, List<GanttVos>> dataMap = workshopAndDeviceByFactoryId.stream()
                .collect(Collectors.groupingBy(GanttVos::getProcessworkshop,
                        LinkedHashMap::new, Collectors.toList()));
        // 对于加工车间重新排序
        List<String> linkedHashMapKey = dataMap.keySet().stream().sorted((o1, o2) -> {
            try {
                String d1 = NUM_MAP.entrySet().stream()
                        .reduce(o1, (s, entry) -> s.replaceAll(entry.getKey(), String.valueOf(entry.getValue())), String::concat);
                String d2 = NUM_MAP.entrySet().stream()
                        .reduce(o2, (s, entry) -> s.replaceAll(entry.getKey(), String.valueOf(entry.getValue())), String::concat);
                return d1.compareTo(d2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return 0;
        }).collect(Collectors.toList());

        /**
         * 工序的对象
         */
        ScheduleGanttVo workShopVo;
        // 设备的对象
        ScheduleGanttVo deviceVo;
        List<GanttVos> ganttVoList;
        for (String mapKey : linkedHashMapKey) {
            ganttVoList = dataMap.get(mapKey);
            workShopVo = new ScheduleGanttVo();
            workShopVo.setId(ganttVoList.get(0).getProcessworkshopid());
            workShopVo.setText(ganttVoList.get(0).getProcessworkshop());
            workShopVo.setOpen(true);
            workShopVo.setType(DEFAULT_TYPE);
            workShopVo.setStart_date(ganttVoList.get(0).getPlanstartdate());
            resultVo.add(workShopVo);
            // 对数据按照设备进行分组
            LinkedHashMap<String, List<GanttVos>> processMap = ganttVoList.stream().collect(Collectors.groupingBy(GanttVos::getProcessdeviceid,
                    LinkedHashMap::new, Collectors.toList()));
            // 循环设备数据
            for (GanttVos ganttVos : ganttVoList) {
                deviceVo = new ScheduleGanttVo();
                deviceVo.setId(ganttVos.getProcessdeviceid());
                deviceVo.setText(ganttVos.getProcessdevice());
                deviceVo.setOpen(true);
                deviceVo.setType(DEFAULT_TYPE);
                deviceVo.setParent(workShopVo.getId());
                deviceVo.setRender(DEFAULT_RENDER);
                deviceVo.setProductlineid(ganttVos.getProductlineid());
                deviceVo.setProductlinename(ganttVos.getProductlinename());
                resultVo.add(deviceVo);
            }
        }


        return R.ok(resultVo);
    }

    public String dateFormat(Date date) {
        if (date == null) {
            return "";
        }
        return dateFormat.format(date);
    }

    /**
     * 根据传入日期获取 该日期的前6天和后6天
     *
     * @param date
     * @return
     */
    private List<Date> getSearchDate(Date date) {
        if (date == null) {
            return null;
        }
        LocalDateTime now = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
        // 获取前6天的0点0分01秒
        LocalDateTime sixDaysAgoStart = now.minusDays(6).truncatedTo(ChronoUnit.DAYS).plusSeconds(1);


        // 获取后6天的23点59分59秒
        LocalDateTime sixDaysLaterEnd = now.plusDays(6).truncatedTo(ChronoUnit.DAYS).plusHours(23).plusMinutes(59).plusSeconds(59);
        List<Date> returnDate = new ArrayList();
        returnDate.add(Date.from(sixDaysAgoStart.atZone(ZoneId.systemDefault()).toInstant()));
        returnDate.add(Date.from(sixDaysLaterEnd.atZone(ZoneId.systemDefault()).toInstant()));
        return returnDate;
    }

    /**
     * 查找上一个或者下一个工序节点
     *
     * @param ganttVosList
     * @param operatorType next：下一节点，pre：上一节点
     * @return
     */
    public List<GanttVos> getNextProcess(List<GanttVos> ganttVosList, String operatorType) {
        List<GanttVos> retGantvos = null;
        // 获取下一个或者上一个工序
        if (ganttVosList != null && ganttVosList.size() > 0) {
            List<String> processids = ganttVosList.stream().map(v -> v.getProcessid()).collect(Collectors.toList());
            // 获取上一节点或者下一节点
            List<ApsProcessOperationDo> processOperations = apsProcessOperationService.list(new LambdaQueryWrapper<ApsProcessOperationDo>()
                    .in(ApsProcessOperationDo::getId, processids));
            List<String> queryProcessids = new ArrayList<>();
            if (processOperations != null && processOperations.size() > 0) {
                for (ApsProcessOperationDo processOperation : processOperations) {
                    if ("next".equals(operatorType)) {
                        if (processOperation.getNextprocessid() != null) {
                            queryProcessids.addAll(Arrays.asList(processOperation.getNextprocessid().split(",")));
                        }
                    } else {
                        if (processOperation.getPreviousprocessid() != null) {
                            queryProcessids.addAll(Arrays.asList(processOperation.getPreviousprocessid().split(",")));
                        }
                    }
                }
                if (queryProcessids != null && queryProcessids.size() > 0) {
                    String joinids = "'" + CollUtil.join(queryProcessids, "','") + "'";
                    retGantvos = apsProcessOperationProcessEquDao.getGanttDataList(
                            null, null, null, null, null,
                            joinids, null, null, null, null,
                            null, null);
                }
            }

        } else {
            if ("next".equals(operatorType)) {
                throw new CustomException("没有下一工序");
            } else {
                throw new CustomException("没有上一工序");
            }
        }
        return retGantvos;
    }

    /**
     * 工序名为 成退和中退 的清空下 加工时间相同的才可以合并
     *
     * @param apsProcessOperationProcessEquDos
     * @return
     */
    public List<ScheduleGanttVo> assembleGanttData(List<GanttVos> apsProcessOperationProcessEquDos) {
        // 修改工序作业的生产状态
        apsProcessOperationProcessEquDos.parallelStream().forEach(data -> {
            /**
             * 作业生产状态不是待发布 ——>作业明细的作业状态
             * 作业生产状态是待发-> 待发布
             */
            if (TO_BE_PUBLISHED.equals(data.getProcessstatus())) {
                data.setGanttprocessstatus(TO_BE_PUBLISHED);
            } else {
                data.setGanttprocessstatus(GANTT_PROCESS_STATUS_MAP.getOrDefault(data.getWorkstatus(), ""));
            }
        });
        // 需要返回给前端的数据
        List<ScheduleGanttVo> resultVo = new ArrayList<>();
        if (apsProcessOperationProcessEquDos.isEmpty()) {
            return resultVo;
        }
        // 获取工序对应的 输入输出批次号
        List<String> processId = apsProcessOperationProcessEquDos.stream().map(GanttVos::getProcessid).distinct().collect(Collectors.toList());
        // 工序作业对应的输入和输出批次号
        Map<String, String> processAndNumberMap = apsReportRecordsDao.selectInputAndOutputNumByProcessId(processId).stream().collect(Collectors.toMap(ProcessOutputAndInputNumber::getProcessId, ProcessOutputAndInputNumber::getNumber));

        // 具体工序作业的对象
        ScheduleGanttVo dateVo;
        int workShopIndex = 1;
        // 对数据按照设备进行分组
        LinkedHashMap<String, List<GanttVos>> processMap = apsProcessOperationProcessEquDos.stream().collect(Collectors.groupingBy(GanttVos::getProcessdeviceid,
                LinkedHashMap::new, Collectors.toList()));
        for (Map.Entry<String, List<GanttVos>> deviceEntry : processMap.entrySet()) {
            List<GanttVos>  values= deviceEntry.getValue();
            values.sort(Comparator.comparing(GanttVos::getPlanstartdate).thenComparing(GanttVos::getPlanenddate));
            // 对数据按照 计划开始时间 分组
            LinkedHashMap<String, List<GanttVos>> planDataMap = values.stream().collect(Collectors.groupingBy(info -> {
                        if (PROCESS_WAY_MERGE.equals(info.getProcessway())) {
                            return info.getPlanstartdate().toString();
                        }
                        return info.getUuid();
                    },
                    LinkedHashMap::new, Collectors.toList()));
            for (Map.Entry<String, List<GanttVos>> planDateEntry : planDataMap.entrySet()) {
                List<GanttVos> ganttVos = planDateEntry.getValue();
                ganttVos.forEach(data -> {
                    String number = processAndNumberMap.getOrDefault(data.getProcessid(), "");
                    if (StringUtils.isNotBlank(number) && number.split(DEFAULT_SPLIT).length == 2) {
                        data.setInputnumber(number.split(DEFAULT_SPLIT)[0]);
                        data.setOutputnumber(number.split(DEFAULT_SPLIT)[1]);
                    }
                });
                Date actualStartDate = null;
                Date actualFinishDate = null;
                //查询实际开工时间不为空的列表
                List<GanttVos> noNullActualDateList = ganttVos.stream()
                        .filter(g -> g.getActualstartdate() != null)
                        .collect(Collectors.toList());
                if (!noNullActualDateList.isEmpty()){
                    //取出最早实际开工时间
                    Optional<GanttVos> minDate = noNullActualDateList.stream()
                            .min(Comparator.comparing(GanttVos::getActualstartdate));
                    if(minDate.get().getActualstartdate()!= null){
                        actualStartDate = minDate.get().getActualstartdate();
                    }
                }
                //查询实际完工时间为空的列表
                List<GanttVos> nullActualFinishDateList = ganttVos.stream().filter(g -> g.getActualfinishdate() == null)
                        .collect(Collectors.toList());
                if (nullActualFinishDateList.isEmpty()){
                    //取出最晚实际完工时间
                    Optional<GanttVos> maxDate = ganttVos.stream()
                            .max(Comparator.comparing(GanttVos::getActualfinishdate));
                    if(maxDate.isPresent()&&maxDate.get().getActualfinishdate()!= null){
                        actualFinishDate = maxDate.get().getActualfinishdate();
                    }
                }
                String workstatus = "";
                Map<String, Integer> keyValueMap = new HashMap<>(16);
                // 向键值对数组中添加元素
                keyValueMap.put("待开工", 30);
                keyValueMap.put("加工中", 40);
                keyValueMap.put("已完工", 50);
                //查询出所有不为空的状态列表
                List<GanttVos> filteredWorkStatus = ganttVos.stream()
                        .filter(g -> g.getWorkstatus() != null && !g.getWorkstatus().isEmpty())
                        .collect(Collectors.toList());
                if (!filteredWorkStatus.isEmpty()){
                    GanttVos minWorkStatus = (filteredWorkStatus.stream()
                            .min(Comparator.comparingInt(p -> keyValueMap.get(p.getWorkstatus())))
                            .orElse(null));
                    //取出最早实际开工时间
                    workstatus = minWorkStatus.getWorkstatus();
                }
                String finalWorkStatus = workstatus;
                Date finalActualStartDate = actualStartDate;
                Date finalActualFinishDate = actualFinishDate;
                ganttVos.forEach(item -> {
                    if ("20".equals(item.getProcessstatus())){
                        item.setGanttprocessstatus(TO_BE_PUBLISHED);
                    }else {
                        item.setGanttprocessstatus(GANTT_PROCESS_STATUS_MAP.getOrDefault(finalWorkStatus, ""));
                    }
                    item.setActualstartdate(finalActualStartDate);
                    item.setActualfinishdate(finalActualFinishDate);
                });
//                List<String> itemNames = new ArrayList<>();
                // 按照工序作业明细ID 进行分组 并且获取 图列的 名称和描述
//                LinkedHashMap<String, List<GanttVos>> collect = ganttVos.stream().collect(Collectors.groupingBy(GanttVos::getId, LinkedHashMap::new, Collectors.toList()));

//                String itemName = collect.values().stream().map(info -> {
//                    return String.format(GANTT_ITEM_NAME, info.get(0).getInmatercondition(), info.get(0).getPlanprocessrall(),
//                            info.get(0).getCustomorderno(), info.get(0).getCustomerabbreviation(), info.get(0).getDeliverydate());
//                }).collect(Collectors.joining("</br>"));
//                itemNames.add(itemName);
                dateVo = new ScheduleGanttVo();
                dateVo.setId(String.valueOf(workShopIndex++));
                dateVo.setParent(deviceEntry.getKey());
//                dateVo.setText(StringUtils.join(itemNames, "</br>"));
                dateVo.setOpen(false);
                dateVo.setStart_date(ganttVos.get(0).getPlanstartdate());
                dateVo.setEnd_date(ganttVos.get(0).getPlanenddate());
//                dateVo.setName(StringUtils.join(itemNames, "</br>"));
                dateVo.setBlankNumber(ganttVos.stream().map(GanttVos::getBlankNumber).distinct().collect(Collectors.joining(",")));
                dateVo.setProcessdetailids(ganttVos.stream().map(GanttVos::getId).distinct().collect(Collectors.joining(",")));
                dateVo.setProcessids(ganttVos.stream().map(GanttVos::getProcessid).distinct().collect(Collectors.joining(",")));
                dateVo.setGanttVos(ganttVos);
                dateVo.setGanttprocessstatus(ganttVos.get(0).getGanttprocessstatus());
                dateVo.setWorkstatus(ganttVos.stream().map(GanttVos::getWorkstatus).distinct().collect(Collectors.joining(",")));
                dateVo.setLockmark(ganttVos.stream().map(GanttVos::getLockmark).distinct().collect(Collectors.joining(",")));
                dateVo.setProductionorderid(ganttVos.stream().map(GanttVos::getProductionorderid).collect(Collectors.joining(",")));
                dateVo.setPlanhavematerialdate( ganttVos.stream().filter(data -> data.getPlanhavematerialdate() != null)
                        .max(Comparator.comparing(GanttVos::getPlanhavematerialdate))
                        .map(GanttVos::getPlanhavematerialdate).orElse(null));
                // 冲突描述
                List<GanttVos> conflictdes = ganttVos.stream().filter(v -> StringUtils.isNotBlank(v.getConflictdes())).collect(Collectors.toList());
                if (!conflictdes.isEmpty()) {
                    String desc = conflictdes.stream().map(GanttVos::getConflictdes).distinct().collect(Collectors.joining(";"));
                    dateVo.setConflictdes(desc);
                    dateVo.setSoftconflictdes(conflictdes.stream().map(GanttVos::getSoftconflictdes).distinct().collect(Collectors.joining(";")));
                    // 有冲突描述时
                    dateVo.setConflict(StringUtils.isBlank(dateVo.getConflictdes()) && StringUtils.isBlank(dateVo.getSoftconflictdes()));
                }
                resultVo.add(dateVo);
            }
        }

        return resultVo;
        //                    dateVo.setTooltip(itemPrefix + itemDesc);
//                    dateVo.setDesc(itemPrefix + itemDesc);
//                    dateVo.setConflict(ganttVos.get(0).getConflict());
//                        String prefix = info.stream().map(data -> String.format(GANTT_ITEM_NAME_PREFIX, data.getCustomerabbreviation(), data.getProductname()))
//                                .collect(Collectors.joining(","));
//                    String itemPrefix = String.format(GANTT_DESC_PREFIX,
//                            dateFormat(ganttVos.get(0).getPlanstartdate()),
//                            dateFormat(ganttVos.get(0).getPlanenddate()),
//                            dateFormat(ganttVos.get(0).getActualstartdate()),
//                            dateFormat(ganttVos.get(0).getActualfinishdate()),
//                            ganttVos.get(0).getProcessworkshop(), ganttVos.get(0).getProcessdevice());
//                    String itemDesc = ganttVos.stream().map(info -> {
//                        return String.format(GANTT_DESC, info.getInmatercondition(), info.getPlanprocessrall(),
//                                info.getProcessname(), info.getWorkstatus(),
//                                info.getStartingroll(), info.getReportroll(),
//                                info.getCheckoutroll(), info.getUnfinishroll(),
//                                info.getCustomorderno(), info.getCustomerabbreviation(),
//                                info.getDeliverydate(), info.getOutputorderproduct());
//                    }).collect(Collectors.joining("</br>"));
//        // 对数据按照加工车间分组
//        LinkedHashMap<String, List<GanttVos>> dataMap = apsProcessOperationProcessEquDos.stream()
//                .collect(Collectors.groupingBy(GanttVos::getProcessworkshopid,
//                        LinkedHashMap::new, Collectors.toList()));
//        for (Map.Entry<String, List<GanttVos>> workShopEntry : dataMap.entrySet()) {
//            workShopVo = new ScheduleGanttVo();
//            workShopVo.setId(workShopEntry.getValue().get(0).getProcessworkshopid());
//            workShopVo.setText(workShopEntry.getValue().get(0).getProcessworkshop());
//            workShopVo.setOpen(true);
//            workShopVo.setType(DEFAULT_TYPE);
//            workShopVo.setStart_date(workShopEntry.getValue().get(0).getPlanstartdate());
//            resultVo.add(workShopVo);
//            // 对数据按照设备进行分组
//            LinkedHashMap<String, List<GanttVos>> processMap = workShopEntry.getValue().stream().collect(Collectors.groupingBy(GanttVos::getProcessdeviceid,
//                    LinkedHashMap::new, Collectors.toList()));
//            // 对数据按照 设备进行分组
//            for (Map.Entry<String, List<GanttVos>> deviceEntry : processMap.entrySet()) {
//                deviceVo = new ScheduleGanttVo();
//                deviceVo.setId(deviceEntry.getValue().get(0).getProcessdeviceid());
//                deviceVo.setText(deviceEntry.getValue().get(0).getProcessdevice());
//                deviceVo.setOpen(true);
//                deviceVo.setType(DEFAULT_TYPE);
//                deviceVo.setParent(workShopVo.getId());
////                deviceVo.setDevicetype(deviceEntry.getValue().get(0).getDevicetype());
//                deviceVo.setRender(DEFAULT_RENDER);
//                deviceVo.setStart_date(deviceEntry.getValue().get(0).getPlanstartdate());
//                deviceVo.setProductlineid(deviceEntry.getValue().get(0).getProductlineid());
//                deviceVo.setProductlinename(deviceEntry.getValue().get(0).getProductlinename());
//                resultVo.add(deviceVo);
//                // 对数据按照 计划开始时间+计划结束时间 分组
//                LinkedHashMap<String, List<GanttVos>> planDataMap = deviceEntry.getValue().stream().collect(Collectors.groupingBy(info -> {
//                            if (COMBINED_PROCESSING.equals(info.getProcessway())) {
//                                return info.getPlanstartdate().toString() + info.getPlanenddate().toString();
//                            }
//                            return info.getUuid();
//                        },
//                        LinkedHashMap::new, Collectors.toList()));
//
//            }
//
//        }
    }

}
