瀏覽代碼

优化代码

1098226878 4 年之前
父節點
當前提交
9e4c10ea9a

+ 9 - 1
java110-generator/src/main/java/com/java110/code/TableToJson.java

@@ -34,7 +34,7 @@ public class TableToJson {
             ")";
 
     public static void main(String[] args) {
-
+        //业务名称 desc 业务编码名称生成后类名 name 主键 id  需要放到那个服务 shareName
         String newSql = createTableSql.substring(createTableSql.indexOf("(") + 1, createTableSql.lastIndexOf(")"));
         String tableName = createTableSql.substring(createTableSql.indexOf("TABLE") + 5, createTableSql.indexOf("("));
         tableName = tableName.replaceAll("`", "").trim();
@@ -73,6 +73,14 @@ public class TableToJson {
             if (rowSql.toLowerCase().contains("not null")) {
                 required.put("code", StringUtil.lineToHump(key));
                 String comment = rowSql.contains("COMMENT") ? rowSql.substring(rowSql.indexOf("COMMENT '") + 9) : StringUtil.lineToHump(key);
+                comment = comment.trim();
+                if(comment.contains(",")){
+                    comment = comment.split(",")[0];
+                }
+                if(comment.contains(" ")){
+                    comment = comment.split(" ")[0];
+                }
+
                 required.put("msg", comment + "不能为空");
                 requireds.add(required);
             }

+ 117 - 0
java110-generator/src/main/java/com/java110/code/TableToJsonWeb.java

@@ -0,0 +1,117 @@
+package com.java110.code;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.java110.utils.util.StringUtil;
+
+public class TableToJsonWeb {
+
+    //show create table c_orders  用这个语句获取
+    public static final String createTableSql = "CREATE TABLE `building_room` (\n" +
+            "  `room_id` varchar(30) NOT NULL COMMENT '房屋ID',\n" +
+            "  `b_id` varchar(30) NOT NULL COMMENT '业务Id',\n" +
+            "  `room_num` varchar(12) NOT NULL COMMENT '房屋编号',\n" +
+            "  `unit_id` varchar(30) NOT NULL COMMENT '单元ID',\n" +
+            "  `layer` int(11) NOT NULL COMMENT '层数',\n" +
+            "  `section` int(11) DEFAULT NULL COMMENT '室',\n" +
+            "  `apartment` varchar(20) NOT NULL COMMENT '户型',\n" +
+            "  `built_up_area` decimal(6,2) NOT NULL COMMENT '建筑面积',\n" +
+            "  `fee_coefficient` decimal(12,2) NOT NULL DEFAULT '1.00' COMMENT '算费系数',\n" +
+            "  `user_id` varchar(30) NOT NULL COMMENT '用户ID',\n" +
+            "  `remark` varchar(200) DEFAULT NULL COMMENT '备注',\n" +
+            "  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',\n" +
+            "  `status_cd` varchar(2) NOT NULL DEFAULT '0' COMMENT '数据状态,详细参考c_status表,S 保存,0, 在用 1失效',\n" +
+            "  `state` varchar(4) NOT NULL COMMENT '房屋状态,如房屋出售等,请查看state 表',\n" +
+            "  `community_id` varchar(30) DEFAULT NULL COMMENT '小区ID',\n" +
+            "  `room_type` varchar(12) NOT NULL DEFAULT '1010301' COMMENT '房屋类型',\n" +
+            "  `room_sub_type` varchar(12) NOT NULL DEFAULT '110' COMMENT '房屋类型 110 住宅房屋,119 办公室 120 宿舍',\n" +
+            "  `room_area` decimal(6,2) NOT NULL COMMENT '室内面积',\n" +
+            "  `room_rent` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '租金',\n" +
+            "  UNIQUE KEY `room_id` (`room_id`) USING BTREE,\n" +
+            "  UNIQUE KEY `idx_room_id` (`room_id`) USING BTREE,\n" +
+            "  KEY `idx_room_b_id` (`b_id`) USING BTREE,\n" +
+            "  KEY `i_br_unit_id` (`unit_id`)\n" +
+            ")";
+
+    public static void main(String[] args) {
+
+        // templateName 业务名称 业务编码名称生成后文件名 templateCode 主键 templateKey
+        // 业务主键名称 templateKeyName=templateName+ID 主机驼峰 searchCode 主键名称 searchName
+        // directories 放在前端那个目录下
+        String newSql = createTableSql.substring(createTableSql.indexOf("(") + 1, createTableSql.lastIndexOf(")"));
+        String tableName = createTableSql.substring(createTableSql.indexOf("TABLE") + 5, createTableSql.indexOf("("));
+        tableName = tableName.replaceAll("`", "").trim();
+        newSql = newSql.replaceAll("\n", "");
+        String[] rowSqls = newSql.split("',");
+        JSONObject param = new JSONObject();
+        param.put("templateName", "");
+        param.put("templateCode", "");
+        param.put("templateKey", "");
+        param.put("templateKeyName", "");
+        param.put("searchCode", "");
+        param.put("searchName", "");
+        param.put("directories", "");
+        JSONObject paramColumn = null;
+        JSONArray conditions = new JSONArray();
+        JSONArray paramColumns = new JSONArray();
+        JSONObject condition = null;
+        String key = "";
+        for (String rowSql : rowSqls) {
+            condition = new JSONObject();
+            paramColumn = new JSONObject();
+            key = rowSql.trim();
+            key = key.substring(0, key.indexOf(" "));
+            key = key.replaceAll("`", "");
+            if ("UNIQUE".equals(key)) {
+                continue;
+            }
+            if ("KEY".equals(key)) {
+                continue;
+            }
+            if ("b_id".equals(key)) {
+                continue;
+            }
+            if ("create_time".equals(key)) {
+                continue;
+            }
+            String comment = rowSql.contains("COMMENT") ? rowSql.substring(rowSql.indexOf("COMMENT '") + 9) : StringUtil.lineToHump(key);
+            comment = comment.trim();
+            if(comment.contains(",")){
+                comment = comment.split(",")[0];
+            }
+            if(comment.contains(" ")){
+                comment = comment.split(" ")[0];
+            }
+            paramColumn.put("desc", comment);
+            if (rowSql.toLowerCase().contains("not null")) {
+
+                condition.put("name", comment);
+                condition.put("inputType", "input");
+                condition.put("code", StringUtil.lineToHump(key));
+                condition.put("whereCondition", "equal");
+                conditions.add(condition);
+                paramColumn.put("desc", "必填,"+comment);
+            }
+            String limit = rowSql.substring(rowSql.indexOf("(") + 1,rowSql.indexOf(")"));
+            if(limit.contains(",")){
+                limit = limit.split(",")[0];
+            }
+
+            paramColumn.put("code", StringUtil.lineToHump(key));
+            paramColumn.put("cnCode", comment);
+            paramColumn.put("required", true);
+            paramColumn.put("hasDefaultValue", false);
+            paramColumn.put("inputType", "input");
+            paramColumn.put("limit", "maxLength");
+            paramColumn.put("limitParam",limit );
+            paramColumn.put("limitErrInfo", comment+"不能超过"+limit);
+            paramColumn.put("show", true);
+            paramColumns.add(paramColumn);
+        }
+        param.put("columns", paramColumns);
+        param.put("conditions", conditions);
+        System.out.println(param.toJSONString());
+
+    }
+
+}

+ 265 - 60
java110-generator/src/main/resources/web/template_1.json

@@ -1,96 +1,301 @@
 {
-  "templateName": "业务轨迹",
-  "templateCode": "businessTableHis",
-  "templateKey": "hisId",
-  "templateKeyName": "轨迹ID",
-  "searchCode": "hisId",
-  "searchName": "轨迹ID",
-  "directories": "dev",
-  "conditions": [
+  "templateKeyName": "",
+  "templateName": "",
+  "columns": [
     {
-      "name": "动作",
-      "inputType": "select",
-      "selectValue":"ADD,MOD,DEL",
-      "selectValueName":"添加,修改,删除",
-      "code": "action",
-      "whereCondition": "equal"
+      "hasDefaultValue": false,
+      "limitParam": "30",
+      "code": "roomId",
+      "limitErrInfo": "房屋ID不能超过30",
+      "cnCode": "房屋ID",
+      "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,房屋ID"
     },
     {
-      "name": "表名",
+      "hasDefaultValue": false,
+      "limitParam": "12",
+      "code": "roomNum",
+      "limitErrInfo": "房屋编号不能超过12",
+      "cnCode": "房屋编号",
+      "limit": "maxLength",
+      "show": true,
       "inputType": "input",
-      "code": "actionObj",
-      "whereCondition": "equal"
+      "required": true,
+      "desc": "必填,房屋编号"
     },
     {
-      "name": "业务类型",
+      "hasDefaultValue": false,
+      "limitParam": "30",
+      "code": "unitId",
+      "limitErrInfo": "单元ID不能超过30",
+      "cnCode": "单元ID",
+      "limit": "maxLength",
+      "show": true,
       "inputType": "input",
-      "code": "businessTypeCd",
-      "whereCondition": "equal"
-    }
-  ],
-  "columns": [
-    {
-      "code": "businessTypeCd",
-      "cnCode": "业务类型",
-      "desc": "必填,请填写业务类型",
       "required": true,
+      "desc": "必填,单元ID"
+    },
+    {
       "hasDefaultValue": false,
+      "limitParam": "11",
+      "code": "layer",
+      "limitErrInfo": "层数不能超过11",
+      "cnCode": "层数",
+      "limit": "maxLength",
+      "show": true,
       "inputType": "input",
+      "required": true,
+      "desc": "必填,层数"
+    },
+    {
+      "hasDefaultValue": false,
+      "limitParam": "11",
+      "code": "section",
+      "limitErrInfo": "室不能超过11",
+      "cnCode": "室",
       "limit": "maxLength",
-      "limitParam": "30",
-      "limitErrInfo": "业务类型超过30位",
-      "show": true
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "室"
     },
     {
-      "code": "action",
-      "cnCode": "动作",
-      "desc": "必填,请选择动作",
+      "hasDefaultValue": false,
+      "limitParam": "20",
+      "code": "apartment",
+      "limitErrInfo": "户型不能超过20",
+      "cnCode": "户型",
+      "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
       "required": true,
+      "desc": "必填,户型"
+    },
+    {
       "hasDefaultValue": false,
-      "inputType": "select",
-      "selectValue":"ADD,MOD,DEL",
-      "selectValueName":"添加,修改,删除",
+      "limitParam": "6",
+      "code": "builtUpArea",
+      "limitErrInfo": "建筑面积不能超过6",
+      "cnCode": "建筑面积",
       "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,建筑面积"
+    },
+    {
+      "hasDefaultValue": false,
       "limitParam": "12",
-      "limitErrInfo": "动作不能为空",
-      "show": true
+      "code": "feeCoefficient",
+      "limitErrInfo": "算费系数不能超过12",
+      "cnCode": "算费系数",
+      "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,算费系数"
     },
     {
-      "code": "actionObj",
-      "cnCode": "表名",
-      "desc": "必填,请填写表名",
+      "hasDefaultValue": false,
+      "limitParam": "30",
+      "code": "userId",
+      "limitErrInfo": "用户ID不能超过30",
+      "cnCode": "用户ID",
+      "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
       "required": true,
+      "desc": "必填,用户ID"
+    },
+    {
       "hasDefaultValue": false,
+      "limitParam": "200",
+      "code": "remark",
+      "limitErrInfo": "备注不能超过200",
+      "cnCode": "备注",
+      "limit": "maxLength",
+      "show": true,
       "inputType": "input",
+      "required": true,
+      "desc": "备注"
+    },
+    {
+      "hasDefaultValue": false,
+      "limitParam": "2",
+      "code": "statusCd",
+      "limitErrInfo": "数据状态不能超过2",
+      "cnCode": "数据状态",
       "limit": "maxLength",
-      "limitParam": "64",
-      "limitErrInfo": "表名超过64位",
-      "show": true
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,数据状态"
     },
     {
-      "code": "actionObjHis",
-      "cnCode": "轨迹表名",
-      "desc": "必填,请填写轨迹表名",
+      "hasDefaultValue": false,
+      "limitParam": "4",
+      "code": "state",
+      "limitErrInfo": "房屋状态不能超过4",
+      "cnCode": "房屋状态",
+      "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
       "required": true,
+      "desc": "必填,房屋状态"
+    },
+    {
       "hasDefaultValue": false,
+      "limitParam": "30",
+      "code": "communityId",
+      "limitErrInfo": "小区ID不能超过30",
+      "cnCode": "小区ID",
+      "limit": "maxLength",
+      "show": true,
       "inputType": "input",
+      "required": true,
+      "desc": "小区ID"
+    },
+    {
+      "hasDefaultValue": false,
+      "limitParam": "12",
+      "code": "roomType",
+      "limitErrInfo": "房屋类型不能超过12",
+      "cnCode": "房屋类型",
       "limit": "maxLength",
-      "limitParam": "64",
-      "limitErrInfo": "轨迹表名超过64位",
-      "show": true
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,房屋类型"
+    },
+    {
+      "hasDefaultValue": false,
+      "limitParam": "12",
+      "code": "roomSubType",
+      "limitErrInfo": "房屋类型不能超过12",
+      "cnCode": "房屋类型",
+      "limit": "maxLength",
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,房屋类型"
     },
     {
-      "code": "remark",
-      "cnCode": "备注",
-      "desc": "可填,请填写备注",
-      "required": false,
       "hasDefaultValue": false,
-      "defaultValue": "",
+      "limitParam": "6",
+      "code": "roomArea",
+      "limitErrInfo": "室内面积不能超过6",
+      "cnCode": "室内面积",
+      "limit": "maxLength",
+      "show": true,
       "inputType": "input",
+      "required": true,
+      "desc": "必填,室内面积"
+    },
+    {
+      "hasDefaultValue": false,
+      "limitParam": "10",
+      "code": "roomRent",
+      "limitErrInfo": "租金不能超过10",
+      "cnCode": "租金",
       "limit": "maxLength",
-      "limitParam": "200",
-      "limitErrInfo": "备注内容不能超过200",
-      "show": false
+      "show": true,
+      "inputType": "input",
+      "required": true,
+      "desc": "必填,租金"
     }
-  ]
-}
+  ],
+  "searchName": "",
+  "directories": "",
+  "searchCode": "",
+  "templateCode": "",
+  "conditions": [
+    {
+      "whereCondition": "equal",
+      "code": "roomId",
+      "name": "房屋ID",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "roomNum",
+      "name": "房屋编号",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "unitId",
+      "name": "单元ID",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "layer",
+      "name": "层数",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "apartment",
+      "name": "户型",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "builtUpArea",
+      "name": "建筑面积",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "feeCoefficient",
+      "name": "算费系数",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "userId",
+      "name": "用户ID",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "statusCd",
+      "name": "数据状态",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "state",
+      "name": "房屋状态",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "roomType",
+      "name": "房屋类型",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "roomSubType",
+      "name": "房屋类型",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "roomArea",
+      "name": "室内面积",
+      "inputType": "input"
+    },
+    {
+      "whereCondition": "equal",
+      "code": "roomRent",
+      "name": "租金",
+      "inputType": "input"
+    }
+  ],
+  "templateKey": ""
+}