RgbEnum.java 4.3 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
package com.boco.nbd.wios.flow.enums;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.boco.nbd.framework.workflow.entity.WorkTaskInfo;
import com.boco.nbd.wios.flow.entity.bo.FlowChartBO;
import com.boco.nbd.wios.flow.entity.qo.FlowChartQo;
import com.boco.nbd.wios.flow.entity.vo.FlowChartVO;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @author:cao hai
 * @date:2022/8/2 15:32
 * @version:V1.0
 * @description:RgbEnum
 * @modify:
 */
@Slf4j
public enum RgbEnum {


    /**
     * 浅绿色 rgb(0, 176, 80)=>#00B050
     * 黄色 rgb(252, 153, 8)=>#FC9908
     * 红色 rgb(192, 0, 0)=>#C00000
     * 深绿色 rgb(128, 176, 200)=>#80B0C8,
     * 0,100,0=>#006400
     * 灰色 rgb(191,191,191)=>#BFBFC0
     * 黑色 rgb(34, 42, 53)=>#222A35
     *
     * @param key
     */
    LIGHT_GREEN("#00B050"), YELLOW("#FC9908"),

    RED("#C00000"),

    DARK_GREEN("#006400"), GREY("#BFBFC0"),

    BLACK("#222A35");

    RgbEnum(String key) {
        this.key = key;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    /**
     * 忽略节点
     */
    private static final Integer[] IGNORE_NODE = {-1, 0, 199};

    /**
     * 枚举
     */
    private String key;

    /**
     * 生成流程图数据
     *
     * @param taskInfo
     * @param closeNode
     * @param tracks
     * @return
     */
    public static FlowChartVO simpleFlowChart(FlowChartQo taskInfo, Integer closeNode, List<String> tracks) {
        List<FlowChartBO> tab = new ArrayList<>(10);
        FlowChartBO priorNode = null;
        for (String track : tracks) {
            FlowNodeEnum item = FlowNodeEnum.getEnum(Convert.toInt(track));
            if (null == item) {
                log.info("nodeFlag={} is invalid data.", track);
                continue;
            }
            if (Arrays.asList(IGNORE_NODE).contains(item.getKey())) {
                continue;
            }
            RgbEnum rgbEnum = (closeNode != null && closeNode.equals(item.getKey())) ? BLACK : DARK_GREEN;
            FlowChartBO chart = new FlowChartBO(item, 1, rgbEnum.key);
            if (priorNode != null) {
                priorNode.setNext(item.getKey() + "");
                tab.add(priorNode);
            }
            priorNode = chart;
        }
        //添加当前节点
        FlowNodeEnum currentItem = FlowNodeEnum.getEnum(Convert.toInt(taskInfo.getNodeFlag()));
        if (currentItem != null) {
            if (priorNode != null) {
                priorNode.setNext(currentItem.getKey() + "");
                tab.add(priorNode);
            }
            tab.add(new FlowChartBO(currentItem, 0, getOverTimeRgb(taskInfo.getCurrentStartTime(), taskInfo.getDueDate())));
        }
        List<FlowChartBO> cell = FlowChartBO.toCellChart(tab);
        FlowChartVO flowChartVO = new FlowChartVO(tab, cell);
        flowChartVO.setElectricExpand(tracks.contains(FlowNodeEnum.NODE_115.getKey().toString()) ? 1 : 0);
        return flowChartVO;
    }

    /**
     * 获取超时对应rgb
     * 浅绿色:当前工单处于此节点(步骤)且未到超期预警,考核期内前80%的时间
     * 黄色:当前工单处于此节点(步骤),考核期内前20%的时间,渲染为黄色,
     * 红色:当前工单处于此节点(步骤)且当前时间大于等于此节点(步骤)的处理时限,渲染为红色
     * 深绿色:已经完成的节点(步骤)
     * 灰色:  还未开始的节点(步骤)
     * 黑色:  订单在此节点直接关闭(工单未实现闭环,也就是实施过程中被终止)
     *
     * @param startTime
     * @param dueDate
     * @return
     */
    public static String getOverTimeRgb(Date startTime, Date dueDate) {
        if (dueDate == null || startTime == null) {
            return LIGHT_GREEN.key;
        }
        if (DateUtil.compare(dueDate, new Date()) <= 0) {
            return RED.key;
        }
        long space = dueDate.getTime() - startTime.getTime();
        long timeSpace = System.currentTimeMillis() - startTime.getTime();
        double ratio = 0.8;
        if (timeSpace <= space * ratio) {
            return LIGHT_GREEN.key;
        }
        return YELLOW.key;
    }
}