From d2142b5275ea718e042c1626b81cf930dfbb5d26 Mon Sep 17 00:00:00 2001 From: liulin <lin.liu@aliyun.com> Date: 星期三, 31 七月 2024 23:35:59 +0800 Subject: [PATCH] 处理生成代码 --- src/test/java/com/lunhan/xxx/host/GenCodeGauss.java | 51 ++++++++++++++++++++------------------------------- src/main/java/com/lunhan/xxx/repository/po/TestInfoPO.java | 5 +++-- src/main/java/com/lunhan/xxx/repository/vo/TestInfoVO.java | 1 - src/main/java/com/lunhan/xxx/service/TestInfoService.java | 1 - 4 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/lunhan/xxx/repository/po/TestInfoPO.java b/src/main/java/com/lunhan/xxx/repository/po/TestInfoPO.java index d45fed6..64394c1 100644 --- a/src/main/java/com/lunhan/xxx/repository/po/TestInfoPO.java +++ b/src/main/java/com/lunhan/xxx/repository/po/TestInfoPO.java @@ -24,6 +24,7 @@ import com.baomidou.mybatisplus.annotation.*; +import java.io.Serializable; import java.math.BigDecimal; import java.sql.Timestamp; @@ -34,11 +35,11 @@ * @date 2021/11/23 */ @TableName("test_info") -public class TestInfoPO { +public class TestInfoPO implements Serializable { /** * 主键id */ - @TableId + @TableId(type = IdType.ASSIGN_ID) @TableField("id") private Long id; /** diff --git a/src/main/java/com/lunhan/xxx/repository/vo/TestInfoVO.java b/src/main/java/com/lunhan/xxx/repository/vo/TestInfoVO.java index e60ff2b..fcde1c8 100644 --- a/src/main/java/com/lunhan/xxx/repository/vo/TestInfoVO.java +++ b/src/main/java/com/lunhan/xxx/repository/vo/TestInfoVO.java @@ -6,7 +6,6 @@ import java.util.Objects; - public class TestInfoVO extends TestInfoPO implements BasicVO { @Override public String getCreateTimeView() { diff --git a/src/main/java/com/lunhan/xxx/service/TestInfoService.java b/src/main/java/com/lunhan/xxx/service/TestInfoService.java index a6f40cb..8c282f6 100644 --- a/src/main/java/com/lunhan/xxx/service/TestInfoService.java +++ b/src/main/java/com/lunhan/xxx/service/TestInfoService.java @@ -33,7 +33,6 @@ public ExecutedResult<Long> create(ReqCreateTestInfo request) { // 转换po TestInfoPO item = TestInfoConvert.INSTANCE.toCreate(request); - item.setId(SnowFlakeUtil.getId()); // 设置状态 item.setStatus(EState.NORMAL.getValue()); // 设置记录创建时间 diff --git a/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java b/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java index bcc7534..689a93f 100644 --- a/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java +++ b/src/test/java/com/lunhan/xxx/host/GenCodeGauss.java @@ -19,7 +19,7 @@ private static final String PORT = "57654"; private static final String USER = "lunhan"; private static final String PASSWORD = "lunhan.20240330"; - private static final String DB_NAME = "water_trade_center"; + private static final String DB_NAME = "test_db1"; private static final String AUTHOR = "lin.liu"; private static Connection CONN = null; @@ -31,8 +31,8 @@ public static final String PO = "./src/main/java/com/lunhan/xxx/repository/po/"; public static final String VO = "./src/main/java/com/lunhan/xxx/repository/vo/"; public static final String CONVERT_MAPPER = "./src/main/java/com/lunhan/xxx/service/convert/"; - public static final String MAPPER_IMPL = "./src/main/java/com/lunhan/xxx/repository/mapper/"; - public static final String MAPPER = "./src/main/java/com/lunhan/xxx/repository/imapper/"; + public static final String MAPPER_IMPL = "./src/main/java/com/lunhan/xxx/repository/impl/"; + public static final String MAPPER = "./src/main/java/com/lunhan/xxx/repository/mapper/"; public static final String SERVICE = "./src/main/java/com/lunhan/xxx/service/"; public static final String Controller = "./src/main/java/com/lunhan/xxx/host/controller/"; public static final String SEARCH = "./src/main/java/com/lunhan/xxx/entity/dto/search/"; @@ -46,8 +46,8 @@ public static final String PO = "com.lunhan.xxx.repository.po"; public static final String VO = "com.lunhan.xxx.repository.vo"; public static final String CONVERT_MAPPER = "com.lunhan.xxx.service.convert"; - public static final String MAPPER_IMPL = "com.lunhan.xxx.repository.mapper"; - public static final String MAPPER = "com.lunhan.xxx.repository.imapper"; + public static final String MAPPER_IMPL = "com.lunhan.xxx.repository.impl"; + public static final String MAPPER = "com.lunhan.xxx.repository.mapper"; public static final String SERVICE = "com.lunhan.xxx.service"; public static final String Controller = "com.lunhan.xxx.host.controller"; public static final String SEARCH = "com.lunhan.xxx.entity.dto.search"; @@ -107,9 +107,8 @@ //region po类 import 内容设置 private static final String[] SET_PO_IMPORT = new String[]{ - "import com.lunhan.xxx.repository.BasicPO;", + "import com.baomidou.mybatisplus.annotation.*;", "", - "import javax.persistence.*;", "import java.io.Serializable;", "import java.sql.Timestamp;" }; @@ -129,14 +128,6 @@ "import org.mapstruct.factory.Mappers;" + "" + "import java.util.List;" - }; - //endregion - - //region 字段名枚举类 import 内容设置 - private static final String[] SET_COLUMNS_ENUM_IMPORT = new String[]{ - "import com.lunhan.xxx.common.orm2.enums.ColumnBasic;", - "import java.util.Arrays;", - "import java.util.Objects;" }; //endregion @@ -160,14 +151,14 @@ //region service类 import 内容设置 private static final String[] SET_Service_IMPORT = new String[]{ "import com.lunhan.xxx.common.*;", + "import com.lunhan.xxx.common.enums.*;", "import com.lunhan.xxx.common.model.Tuple;", "import com.lunhan.xxx.common.util.*;", "import org.apache.commons.lang3.BooleanUtils;", "import org.springframework.beans.factory.annotation.Autowired;", "import org.springframework.stereotype.Service;", - "import java.util.ArrayList;", - "import java.util.List;", - "import java.util.Objects;" + "import java.util.*;", + "import java.util.stream.Collectors;" }; //endregion @@ -332,16 +323,18 @@ listColumn.add(SET_PRO_DESC_TPL.replaceAll("\\{\\#\\=desc\\}", desc)); if (Objects.equals(isPK, 1)) { - listColumn.add("\t@Id"); + listColumn.add("\t@TableId"); + if (Objects.equals(isIdentity, 1)) { + listColumn.add("(type = IdType.AUTO)"); + } else { + listColumn.add("(type = IdType.ASSIGN_ID)"); + } } - if (Objects.equals(isIdentity, 1)) { - listColumn.add("\t@GeneratedValue(strategy = GenerationType.AUTO)"); - } - String columnAnnotation = "\t@Column(name = \"" + name + "\""; + String columnAnnotation = "\t@TableField(\"" + name + "\""; //忽略最后修改时间这一列的新增和编辑 - if (UPDATE_TIME_COLUMNS.stream().anyMatch(c -> c.equalsIgnoreCase(name))) { - columnAnnotation += ", insertable = false, updatable = false"; - } +// if (UPDATE_TIME_COLUMNS.stream().anyMatch(c -> c.equalsIgnoreCase(name))) { +// columnAnnotation += ", insertable = false, updatable = false"; +// } if ("datachange_lasttime".equalsIgnoreCase(name)) { propName = "dataChangeLastTime"; columnNameUpper = "DataChangeLastTime"; @@ -373,9 +366,7 @@ content.append("@Data"); content.append(ConstantFactory.STR_NEWLINE); } - content.append("@Entity"); - content.append(ConstantFactory.STR_NEWLINE); - content.append("@Table(name = \"" + tableName); + content.append("@TableName(\"" + tableName); content.append("\")"); content.append(ConstantFactory.STR_NEWLINE); content.append("public class "); @@ -994,8 +985,6 @@ content.append(" public ExecutedResult<Long> create(" + createDTOName + " request) {\n" + " // 转换po\n" + " " + poName + " item = CopierUtil.mapTo(request, " + poName + ".class);\n" + - " // 设置主键id\n" + - " //item.setId(SnowFlakeUtil.getId());\n" + " // 设置状态\n" + " //item.setStatus(EState.NORMAL.getValue());\n" + " // 设置记录创建时间\n" + -- Gitblit v1.9.3