提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.infra.convert.codegen; |
H |
2 |
|
|
3 |
import com.iailab.framework.common.util.collection.CollectionUtils; |
|
4 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
5 |
import com.iailab.module.infra.controller.admin.codegen.vo.CodegenDetailRespVO; |
|
6 |
import com.iailab.module.infra.controller.admin.codegen.vo.CodegenPreviewRespVO; |
|
7 |
import com.iailab.module.infra.controller.admin.codegen.vo.column.CodegenColumnRespVO; |
|
8 |
import com.iailab.module.infra.controller.admin.codegen.vo.table.CodegenTableRespVO; |
|
9 |
import com.iailab.module.infra.dal.dataobject.codegen.CodegenColumnDO; |
|
10 |
import com.iailab.module.infra.dal.dataobject.codegen.CodegenTableDO; |
|
11 |
import com.baomidou.mybatisplus.generator.config.po.TableField; |
|
12 |
import com.baomidou.mybatisplus.generator.config.po.TableInfo; |
|
13 |
import org.apache.ibatis.type.JdbcType; |
|
14 |
import org.mapstruct.Mapper; |
|
15 |
import org.mapstruct.Mapping; |
|
16 |
import org.mapstruct.Mappings; |
|
17 |
import org.mapstruct.Named; |
|
18 |
import org.mapstruct.factory.Mappers; |
|
19 |
|
|
20 |
import java.util.List; |
|
21 |
import java.util.Map; |
|
22 |
|
|
23 |
@Mapper |
|
24 |
public interface CodegenConvert { |
|
25 |
|
|
26 |
CodegenConvert INSTANCE = Mappers.getMapper(CodegenConvert.class); |
|
27 |
|
|
28 |
// ========== TableInfo 相关 ========== |
|
29 |
|
|
30 |
@Mappings({ |
|
31 |
@Mapping(source = "name", target = "tableName"), |
|
32 |
@Mapping(source = "comment", target = "tableComment"), |
|
33 |
}) |
|
34 |
CodegenTableDO convert(TableInfo bean); |
|
35 |
|
|
36 |
List<CodegenColumnDO> convertList(List<TableField> list); |
|
37 |
|
|
38 |
@Mappings({ |
|
39 |
@Mapping(source = "name", target = "columnName"), |
|
40 |
@Mapping(source = "metaInfo.jdbcType", target = "dataType", qualifiedByName = "getDataType"), |
|
41 |
@Mapping(source = "comment", target = "columnComment"), |
|
42 |
@Mapping(source = "metaInfo.nullable", target = "nullable"), |
|
43 |
@Mapping(source = "keyFlag", target = "primaryKey"), |
|
44 |
@Mapping(source = "columnType.type", target = "javaType"), |
|
45 |
@Mapping(source = "propertyName", target = "javaField"), |
|
46 |
}) |
|
47 |
CodegenColumnDO convert(TableField bean); |
|
48 |
|
|
49 |
@Named("getDataType") |
|
50 |
default String getDataType(JdbcType jdbcType) { |
|
51 |
return jdbcType.name(); |
|
52 |
} |
|
53 |
|
|
54 |
// ========== 其它 ========== |
|
55 |
|
|
56 |
default CodegenDetailRespVO convert(CodegenTableDO table, List<CodegenColumnDO> columns) { |
|
57 |
CodegenDetailRespVO respVO = new CodegenDetailRespVO(); |
|
58 |
respVO.setTable(BeanUtils.toBean(table, CodegenTableRespVO.class)); |
|
59 |
respVO.setColumns(BeanUtils.toBean(columns, CodegenColumnRespVO.class)); |
|
60 |
return respVO; |
|
61 |
} |
|
62 |
|
|
63 |
default List<CodegenPreviewRespVO> convert(Map<String, String> codes) { |
|
64 |
return CollectionUtils.convertList(codes.entrySet(), |
|
65 |
entry -> new CodegenPreviewRespVO().setFilePath(entry.getKey()).setCode(entry.getValue())); |
|
66 |
} |
|
67 |
|
|
68 |
} |