package com.zcloud.entity.hotWorkApplication;

import com.zcloud.entity.PageData;
import org.apache.commons.lang.StringUtils;

import java.util.List;

public class Node {
    private String id;
    private String text;
    private String color;
    private String order;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public void safety_flow_text_util(PageData information){
        switch (this.order){
            case "1":
                this.text = this.text + "<br>发起人:" + information.getString("INSPECTION_ORIGINATOR_NAME") + "<br/>(" + information.getString("CREATTIME") + ")";
                break;
            case "2":
                break;
            case "3":
                if (StringUtils.isNotBlank(information.getString("INSPECTED_SITEUSER_SIGN_TIME"))) {
                    this.text = this.text + "<br>被检查人:" + information.getString("INSPECTED_SITEUSER_NAME") + "<br/>(" + information.getString("INSPECTED_SITEUSER_SIGN_TIME") + ")";
                } else {
                    this.text = this.text + "<br>被检查人:" + information.getString("INSPECTED_SITEUSER_NAME");
                }
                break;
            case "4":
                break;
        }
    }
    public void safe_flow(PageData information){
        switch (this.order){
            case "0":
                this.text = this.text + "<br>发现人:" + information.getString("CREATORNAME") + "<br/>(" + information.getString("CREATTIME") + ")";
                break;
            case "1":
                break;
        }
    }
    public void safety_creator_util(PageData safety){
        if ("-1".equals(safety.getString("INSPECTION_STATUS")) || "-2".equals(safety.getString("INSPECTION_STATUS"))) {
            safety.put("INSPECTION_STATUS", "1");
        }
        if ("0".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","2");
        }
        if ("6".equals(safety.getString("INSPECTION_STATUS")) && "".equals(safety.getString("finished_product"))){
            safety.put("INSPECTION_STATUS","5");  //finished_product为空代表是初始状态，而不是我定义的检查已验收但没有考评的状态。
        }
        if ("8".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("finished_product","2");
        }
        if ("4".equals(safety.getString("INSPECTION_STATUS")) || "3".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","4");
        }
        if ("7".equals(safety.getString("INSPECTION_STATUS")) && "".equals(safety.getString("ASSESS_SCORE"))){
            safety.put("INSPECTION_STATUS","6");  //如果是检查已验收状态，但是没有考评（考评扣分等于空视为没有考评），当前流程流转到考评框
            safety.put("finished_product","1");   //给此值代表红色的框应该是在考评框，不想让状态进行上面的其他循环
        }
        this.safety_flow_text_util(safety);
        if (Integer.parseInt(this.getOrder()) < Integer.parseInt(safety.getString("INSPECTION_STATUS"))) {
            this.setColor(Color.green.toString());
        }
        if (this.getOrder().equals(safety.getString("INSPECTION_STATUS"))) {
            this.setColor(Color.red.toString());
        }
        if (Integer.parseInt(this.getOrder()) > Integer.parseInt(safety.getString("INSPECTION_STATUS"))) {
            this.setColor(Color.blue.toString());
        }
        if("2".equals(safety.getString("finished_product")) && "6".equals(this.order)){
            this.text = "已归档";
        }
        if("6".equals(safety.getString("INSPECTION_STATUS")) && "1".equals(safety.getString("finished_product")) && "6".equals(this.order)){
            this.setColor(Color.red.toString());  //检查已验收但是没有考评的专属颜色语句
        }
    }
    public void safe_creator(PageData safe){
//        1- 未整改  3-已整改   4-已验收

        if ("100".equals(safe.getString("STATE")) || "1".equals(safe.getString("STATE"))) {
            safe.put("VSTATE", "0");
        }
        if ("3".equals(safe.getString("STATE"))) {
            safe.put("VSTATE", "1");
        }
        if ("4".equals(safe.getString("STATE")) ) {
            safe.put("VSTATE", "2");
        }
        if ("101".equals(safe.getString("STATE")) || "102".equals(safe.getString("STATE")) ) {
            safe.put("VSTATE", "2");
        }
        this.safe_flow(safe);
        if (Integer.parseInt(this.getOrder()) < Integer.parseInt(safe.getString("VSTATE"))) {
            this.setColor(Color.green.toString());
        }
        if (this.getOrder().equals(safe.getString("VSTATE"))) {
            this.setColor(Color.red.toString());
        }
        if (Integer.parseInt(this.getOrder()) > Integer.parseInt(safe.getString("VSTATE"))) {
            this.setColor(Color.blue.toString());
        }
        // 如果已验收 全节点变为绿色
        if("2".equals(safe.getString("VSTATE")) ){
            this.setColor(Color.green.toString());
        }

    }
    public void safety_inspector_util( List<PageData> inspectors){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.text);
        for (PageData inspector : inspectors) {
            if (StringUtils.isNotBlank(inspector.getString("INSPECTION_USER_SIGN_TIME"))){
                buffer.append("<br/>");
                buffer.append(inspector.getString("INSPECTION_USER_NAME"));
                buffer.append("(已签)");
                buffer.append("<br/>(");
                buffer.append(inspector.getString("OPERATTIME"));
                buffer.append(")");
            }else {
                buffer.append("<br/>");
                buffer.append(inspector.getString("INSPECTION_USER_NAME"));
                buffer.append("(未签)");
            }
        }
        this.setText(buffer.toString());
    }
    public void safety_hiddenCreator_util( List<PageData> hiddens){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData hidden : hiddens) {
            buffer.append("<br/>");
            buffer.append("验收人：");
            buffer.append(hidden.getString("HIDDEN_CREATOR_NAME"));
            if (StringUtils.isNotBlank(hidden.getString("FINAL_CHECKTIME"))){
                buffer.append("<br/>(");
                buffer.append(hidden.getString("FINAL_CHECKTIME"));
                buffer.append(")");
            }
        }
        this.setText(buffer.toString());
    }
    public void safety_assessor_util(List<PageData> assesses){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData assess:assesses) {
            buffer.append("<br/>");
            buffer.append("考评人：");
            buffer.append(assess.getString("ASSESSOR_NAME"));
            buffer.append("<br/>(");
            buffer.append(assess.getString("OPERATTIME"));
            buffer.append(")");
        }
        this.text = buffer.toString();
    }

    public void safety_hiddenz(List<PageData> hiddenz){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData hiddeny:hiddenz) {
            buffer.append("<br/>");
            buffer.append("指派人：");
            buffer.append(hiddeny.getString("YINNAME"));

        }
        this.text = buffer.toString();
    }
    public void safe_qr(List<PageData> qrs){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData qr:qrs) {

            if (StringUtils.isNotBlank(qr.getString("conUserName"))) {
                buffer.append("<br/>");
                buffer.append("确认人：");
                buffer.append(qr.getString("conUserName"));
                buffer.append("<br/>(");
                buffer.append(qr.getString("CONFIRM_TIME"));
                buffer.append(")");
            }

        }
        this.text = buffer.toString();
    }
    public void safe_ts(List<PageData> tss){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData ts:tss) {
            if (StringUtils.isNotBlank(ts.getString("tsname"))) {
                buffer.append("<br/>");
                buffer.append("审批人：");
                buffer.append(ts.getString("tsname"));
//            buffer.append("<br/>(");
//            buffer.append(ts.getString("tstiem"));
//            buffer.append(")");
            }

        }
        this.text = buffer.toString();
    }
    public void safe_zg(List<PageData> zgs){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData zg:zgs) {
            if (StringUtils.isNotBlank(zg.getString("RECTIFICATIONORNAME"))) {
                buffer.append("<br/>");
                buffer.append("整改人：");
                buffer.append(zg.getString("RECTIFICATIONORNAME"));
                if (StringUtils.isNotBlank(zg.getString("RECTIFICATIONTIME"))) {
                    buffer.append("<br/>(");
                    buffer.append(zg.getString("RECTIFICATIONTIME"));
                    buffer.append(")");
                }
            }

        }
        this.text = buffer.toString();
    }
    public void safe_ys(List<PageData> yss){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getText());
        for (PageData ys:yss) {
            if (StringUtils.isNotBlank(ys.getString("CHECKORNAME"))) {
                buffer.append("<br/>");
                buffer.append("验收人：");
                buffer.append(ys.getString("CHECKORNAME"));
                if(StringUtils.isNotBlank(ys.getString("CHECK_TIME"))){
                    buffer.append("<br/>(");
                    buffer.append(ys.getString("CHECK_TIME"));
                    buffer.append(")");
                }
            }

        }
        this.text = buffer.toString();
    }
}
