package com.zcloud.entity.hotWorkApplication;

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

import java.util.List;

public class NodeApp {
    private String title;
    private String desc;
    private String active;
    private String order;

    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getDesc() {
        return desc;
    }
    public void setDesc(String desc) {
        this.desc = desc;
    }
    public String getActive() {
        return active;
    }
    public void setActive(String active) {
        this.active = active;
    }
    public String getOrder() {return order;}
    public void setOrder(String order) {this.order = order;}

    public void safety_order(PageData safety){
        String order = "";
        if ("0".equals(safety.getString("INSPECTION_STATUS")) ||
                "-1".equals(safety.getString("INSPECTION_STATUS")) ||
                "-2".equals(safety.getString("INSPECTION_STATUS"))) {
            order = "0";
        }
        if ("1".equals(safety.getString("INSPECTION_STATUS")) ||
                "2".equals(safety.getString("INSPECTION_STATUS"))) {
            order = "1";
        }
        if ("3".equals(safety.getString("INSPECTION_STATUS"))) {
            order = "2";
        }
        if ("4".equals(safety.getString("INSPECTION_STATUS")) ||
                "5".equals(safety.getString("INSPECTION_STATUS")) ||
                "6".equals(safety.getString("INSPECTION_STATUS"))) {
            order = "3";
        }
        if ("7".equals(safety.getString("INSPECTION_STATUS"))) {
            order = "4";
        }
        if ("8".equals(safety.getString("INSPECTION_STATUS"))) {
            order = "4";
            safety.put("finished_product","2");
        }
        safety.put("order",order);
    }

    public void safety_creator_util(PageData safety){
        /*if ("-1".equals(safety.getString("INSPECTION_STATUS")) || "-2".equals(safety.getString("INSPECTION_STATUS"))) {
            safety.put("INSPECTION_STATUS", "0");
        }
        if ("0".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","1");
        }
        if ("6".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","4");
        }
        if ("8".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","5");
            safety.put("finished_product","2");
        }
        if ("5".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","4");
        }
        if ("4".equals(safety.getString("INSPECTION_STATUS")) || "3".equals(safety.getString("INSPECTION_STATUS"))){
            safety.put("INSPECTION_STATUS","3");
        }
        if ( "7".equals(safety.getString("INSPECTION_STATUS"))) {
            safety.put("INSPECTION_STATUS","4");
        }*/
        this.safety_flow_text_util(safety);
        if (this.getOrder().equals(safety.getString("order"))) {
            this.setActive(this.getOrder());
        }
        if("4".equals(this.order) && "2".equals(safety.getString("finished_product"))){
            this.setTitle("已归档");
        }
    }

    public void safety_flow_text_util(PageData information){
        switch (this.order){
            case "0":

                this.title = this.title + ":" + "\n" + information.getString("INSPECTION_ORIGINATOR_NAME") ;
                this.desc = information.getString("CREATTIME");
                break;
            case "1":
                break;
            case "2":
                this.title = this.title + ":" + "\n" + information.getString("INSPECTED_SITEUSER_NAME") ;
                this.desc = information.getString("INSPECTED_SITEUSER_SIGN_TIME");
                break;
            case "3":
                break;
            case "4":
                break;
        }
    }

    public void safety_inspector_util(List<PageData> inspectors) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.title);
        buffer.append(":");
            for (PageData inspector : inspectors) {
                buffer.append("\n");
                if (StringUtils.isNotBlank(inspector.getString("INSPECTION_USER_SIGN_TIME"))){
                    buffer.append(inspector.getString("INSPECTION_USER_NAME"));
                    buffer.append("\n");
                    buffer.append(inspector.getString("INSPECTION_USER_SIGN_TIME"));
//                buffer.append("(");
//                buffer.append(")");
                }else {
                    buffer.append(inspector.getString("INSPECTION_USER_NAME"));
                    buffer.append("(未签)");
                }
        }

        this.title = buffer.toString();

        buffer.setLength(0);
//        for (PageData inspector : inspectors) {
//            if (StringUtils.isNotBlank(inspector.getString("INSPECTION_USER_SIGN_TIME"))){
//                buffer.append(inspector.getString("INSPECTION_USER_SIGN_TIME"));
//            }
//        }

        if (buffer.length() > 0) {
            this.desc = buffer.toString();
        }
    }

    public void safety_hiddenCreator_util(List<PageData> hiddens) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.title);
        for (PageData hidden : hiddens) {
            buffer.append(":");
            buffer.append("\n");
            buffer.append(hidden.getString("HIDDEN_CREATOR_NAME"));
            buffer.append("\n");
            if (StringUtils.isNotBlank(hidden.getString("CHECK_TIME"))){
                buffer.append(hidden.getString("CHECK_TIME"));
            }
        }
        this.setTitle(buffer.toString());
    }

    public void safety_hiddenz(List<PageData> hiddenz){
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getTitle());
        buffer.append("人");
        buffer.append(":");
            for (PageData hiddeny:hiddenz) {

                buffer.append("\n");
                buffer.append(hiddeny.getString("YINNAME"));
                buffer.append("\n");
                if (StringUtils.isNotBlank(hiddeny.getString("CREATTIME"))){
                    buffer.append(hiddeny.getString("CREATTIME"));
                }

            }
        this.title = buffer.toString();

        buffer.setLength(0);
        for (PageData hiddeny : hiddenz) {
            if (StringUtils.isNotBlank(hiddeny.getString("INSPECTION_USER_SIGN_TIME"))){
                buffer.append(hiddeny.getString("INSPECTION_USER_SIGN_TIME"));
            }
        }

        if (buffer.length() > 0) {
            this.desc = buffer.toString();
        }
    }
    public void safety_assessor_util(List<PageData> assesses) {
        StringBuffer buffer = new StringBuffer();
        buffer.append(this.getTitle());
        for (PageData assess:assesses) {
            buffer.append("考评人：");
            buffer.append(assess.getString("ASSESSOR_NAME"));
            buffer.append("(");
            buffer.append(assess.getString("OPERATTIME"));
            buffer.append(")");
        }
        this.title = buffer.toString();
    }
}
