diff --git a/dsUtils/src/main/java/com/dsideal/Tools/GenerateCode.java b/dsUtils/src/main/java/com/dsideal/Tools/GenerateCode.java index c23e89e7..ed490ded 100644 --- a/dsUtils/src/main/java/com/dsideal/Tools/GenerateCode.java +++ b/dsUtils/src/main/java/com/dsideal/Tools/GenerateCode.java @@ -131,6 +131,7 @@ public class GenerateCode { rs.close(); stmt.close(); jo.put("fields", map); + jo.put("beanName", className); return jo; } @@ -201,6 +202,10 @@ public class GenerateCode { //生成代码 autoCode(jo); } + if (StrKit.isBlank(tableNames)) { + dsKit.print("没有找到表,请检查!"); + return; + } //去掉最后的逗号 tableNames = tableNames.substring(0, tableNames.length() - 1); @@ -214,9 +219,40 @@ public class GenerateCode { /** * 功能:生成代码 + * * @param jo */ - public void autoCode(JSONObject jo){ - + public static void autoCode(JSONObject jo) { + //不带主键的其它字段,拼接成java的函数声明内容 + // 迭代map将按照插入顺序 + Map fields = (Map) jo.get("fields"); + String content = ""; + for (Map.Entry entry : fields.entrySet()) { + if (!entry.getKey().equals("create_time") && !entry.getKey().equals("b_use")) { + content += entry.getValue() + " " + entry.getKey() + ",";//这里必须是反着来的,否则数据类型会重复 + } + } + //移除最后一个逗号 + content = content.substring(0, content.length() - 1); + //后缀名称 + String beanName = jo.getStr("beanName"); + if (beanName.startsWith("T")) { + beanName = beanName.substring(1); + } + //1、增加 + StringBuilder sbAdd = new StringBuilder(); + sbAdd.append(" @Before({POST.class})\n"); + sbAdd.append(" public void add"+beanName+"(" + content + "){\n"); + + sbAdd.append(" }\n"); + + System.out.println(sbAdd); + //2、删除 + + //3、修改 + + //4、单条查询 + + //5、分页查询 } } diff --git a/dsUtils/src/main/java/com/dsideal/ZhuQue/Bean/TWxRecord.java b/dsUtils/src/main/java/com/dsideal/ZhuQue/Bean/TWxRecord.java new file mode 100644 index 00000000..a62196a6 --- /dev/null +++ b/dsUtils/src/main/java/com/dsideal/ZhuQue/Bean/TWxRecord.java @@ -0,0 +1,63 @@ +package com.dsideal.ZhuQue.Bean; + +import lombok.Setter; +import lombok.Getter; +// 维修记录表 +public class TWxRecord { + // 主键 + @Getter + @Setter + private int id; + // 场站ID + @Getter + @Setter + private int station_id; + // 场站名称 + @Getter + @Setter + private String station_name; + // 桩ID + @Getter + @Setter + private int equipmentId; + // 桩名称 + @Getter + @Setter + private String equipmentName; + // 枪ID + @Getter + @Setter + private int connectorId; + // 枪名称 + @Getter + @Setter + private String connectorNo; + // 维修人员的微信open_id + @Getter + @Setter + private String wx_openid; + // 维修单状态: 1:正在维修,2:维修完成,3:无法维修 + @Getter + @Setter + private int status_id; + // 创建时间 + @Getter + @Setter + private java.util.Date create_time; + // 故障类型id + @Getter + @Setter + private int type_id; + // 故障类型名称 + @Getter + @Setter + private String type_name; + // 维修情况说明 + @Getter + @Setter + private String memo; + + public String toString(){ + return "{ id: " + id +", station_id: " + station_id +", station_name: " + station_name +", equipmentId: " + equipmentId +", equipmentName: " + equipmentName +", connectorId: " + connectorId +", connectorNo: " + connectorNo +", wx_openid: " + wx_openid +", status_id: " + status_id +", create_time: " + create_time +", type_id: " + type_id +", type_name: " + type_name +", memo: " + memo +"}"; + } +} diff --git a/dsUtils/src/main/resources/application.properties b/dsUtils/src/main/resources/application.properties index ab9baf8f..293016c0 100644 --- a/dsUtils/src/main/resources/application.properties +++ b/dsUtils/src/main/resources/application.properties @@ -2,14 +2,14 @@ driverClassName=com.mysql.cj.jdbc.Driver user=root password=DsideaL147258369 -jdbcUrl=jdbc:mysql://10.10.14.210:22066/yltcharge?useUnicode=true&characterEncoding=UTF-8&useSSL=false +jdbcUrl=jdbc:mysql://10.10.14.210:22066/ds_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false # ???? beanPath=D:/dsWork/dsProject/dsUtils/src/main/java # ??bean??? -beanPackage=com.dsideal.base.Bean +beanPackage=com.dsideal.ZhuQue.Bean # ??????? -tableName=t_sys_loginperson +tableName=t_wx_record diff --git a/dsUtils/target/classes/application.properties b/dsUtils/target/classes/application.properties index ab9baf8f..293016c0 100644 --- a/dsUtils/target/classes/application.properties +++ b/dsUtils/target/classes/application.properties @@ -2,14 +2,14 @@ driverClassName=com.mysql.cj.jdbc.Driver user=root password=DsideaL147258369 -jdbcUrl=jdbc:mysql://10.10.14.210:22066/yltcharge?useUnicode=true&characterEncoding=UTF-8&useSSL=false +jdbcUrl=jdbc:mysql://10.10.14.210:22066/ds_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false # ???? beanPath=D:/dsWork/dsProject/dsUtils/src/main/java # ??bean??? -beanPackage=com.dsideal.base.Bean +beanPackage=com.dsideal.ZhuQue.Bean # ??????? -tableName=t_sys_loginperson +tableName=t_wx_record