package cn.cslg.pas.common.utils.handler;

import cn.cslg.pas.common.utils.StringUtils;

import java.util.List;

public class PatSnapPatentAffairHandler implements IProcessData {
    public PatSnapPatentAffairHandler() {
    }

    @Override
    public Object processData(Object data, Object code) {
        List<String> splitStr = StringUtils.changeStringToString(data.toString(), "\\|");
        if (splitStr.size() % 3 != 0) {
            return null;
        }
        StringBuilder all = new StringBuilder();
        StringBuilder one = new StringBuilder();
        for (int i = 0; i < splitStr.size(); i += 3) {
            if (one.toString().equals("")) {
                one = new StringBuilder("\"inpadocData\"" + ":[" + "{" + "\"name\"" + ":" + "\"发生日期\"" + "," + "\"content\"" + ":" + "\"" + splitStr.get(i).trim() + "\"" + "}");
            } else {
                one.append("," + "{" + "\"name\"" + ":" + "\"发生日期\"" + "," + "\"content\"" + ":" + "\"").append(splitStr.get(i).trim()).append("\"").append("}");
            }
            one.append(",{").append("\"name\":\"国家\"").append(",").append("\"content\":").append("\"").append(splitStr.get(i + 2).trim()).append("\"").append("}");
            one.append("," + "{" + "\"name\"" + ":" + "\"内容\"" + "," + "\"content\"" + ":" + "\"").append(splitStr.get(i + 1).trim()).append("\"").append("}]");

            if (!one.toString().equals("")) {
                if (!all.toString().equals("")) {
                    all.append(",{").append(one).append("}");
                } else {
                    all = new StringBuilder("{" + one + "}");
                }
            }
            one = new StringBuilder();
        }

        all = new StringBuilder("[" + all + "]");
        return all.toString();
    }
}
