package cc.smtweb.system.bpm.test;

import cc.smtweb.system.bpm.util.CodeGenUtil;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

/**
 * Created by Akmm at 2022/3/1 9:41
 * 生成bean
 */
public class BuildJavaBean {
    @Test
    public void buildBean() {
        String str = "`trl_id` bigint(20) NOT NULL COMMENT 'null',\n" +
                "  `trl_pri_id` bigint(20) DEFAULT NULL COMMENT 'null',\n" +
                "  `trl_src_task_id` bigint(20) DEFAULT NULL COMMENT 'null',\n" +
                "  `trl_dst_task_id` bigint(20) DEFAULT NULL COMMENT 'null',\n";
        String[] ss = str.split("\n");
        for (String s: ss) {
            String[] s0 = s.trim().split(" ");
            if (StringUtils.isEmpty(s0[0])) continue;
            String tn = s0[0].substring(1, s0[0].indexOf("`", 2));
            String tnu = CodeGenUtil.underlineToUpperHump(tn.substring(tn.indexOf("_") + 1));
            String tnn = CodeGenUtil.underlineToHump(tn);

            String tt = s0[1];
            String ttj;
            if (tt.contains("(")) tt = tt.substring(0, tt.indexOf("("));
            switch (tt) {
                case "bigint":
                    tt = "long";
                    ttj = "Long";
                    break;
                case "tinyint":
                    case "smallint":
                    case "int":
                    tt = "int";
                    ttj = "Int";
                    break;
                default:
                    tt = "String";
                    ttj = "Str";
                    break;
            }
            System.out.println("public " + tt + " get" + tnu + "(){\n" +
                    "return get" + ttj + "(\"" + tn + "\");\n" +
                    "}\n" +
                    "" +
                    "public void set" + tnu + "(" + tt + " " + tnn + "){\n" +
                    "put(\"" + tn + "\", " + tnn + ");\n" +
                    "}\n");
        }
    }
}
