♻️ Refactoring code. 完善代码生成,elemenet 风格生成细节处理

This commit is contained in:
wjie 2021-08-11 18:41:34 +08:00
parent 435eae5ad0
commit 90f2d509bc
9 changed files with 63 additions and 48 deletions

View File

@ -1,5 +1,6 @@
package com.pig4cloud.pig.common.mybatis.config;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
@ -7,6 +8,7 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.util.ClassUtils;
import java.nio.charset.Charset;
import java.time.LocalDateTime;
import java.util.Optional;
@ -50,7 +52,8 @@ public class MybatisPlusMetaObjectHandler implements MetaObjectHandler {
}
// 2. 如果用户有手动设置的值
Object userSetValue = metaObject.getValue(fieldName);
if (userSetValue != null && !isCover) {
String setValueStr = StrUtil.str(userSetValue, Charset.defaultCharset());
if (StrUtil.isNotBlank(setValueStr) && !isCover) {
return;
}
// 3. field 类型相同时设置

View File

@ -147,17 +147,9 @@ public class CodeGenKits {
tableEntity.setLowerClassName(StringUtils.uncapitalize(className));
// 获取需要在swagger文档中隐藏的属性字段
List<Object> hiddenColumns = config.getList("hiddenColumn");
// 排除不需要处理的字段
List<Object> excludeColumns = config.getList("excludeColumns");
// 列信息
List<ColumnEntity> columnList = new ArrayList<>();
for (Map<String, String> column : columns) {
// 判断是否处理
String columnName = column.get("columnName");
if (excludeColumns.contains(columnName)) {
continue;
}
ColumnEntity columnEntity = new ColumnEntity();
columnEntity.setColumnName(column.get("columnName"));
columnEntity.setDataType(column.get("dataType"));

View File

@ -19,16 +19,13 @@
mainPath=com.pig4cloud.pig
#\u5305\u540D
package=com.pig4cloud.pig
moduleName=generator
moduleName=demo
#\u4F5C\u8005
author=pig code generator
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
tablePrefix=table_
#\u6392\u9664\u4E0D\u751F\u6210\u7684\u5B57\u6BB5
excludeColumns=create_time,update_time,create_by,update_by
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
tinyint=Integer
smallint=Integer

View File

@ -14,7 +14,7 @@
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
#set($excludeColumns = ["create_time","update_time","create_by","update_by"])
package ${package}.${moduleName}.entity;
import com.baomidou.mybatisplus.annotation.TableId;
@ -27,8 +27,6 @@ import lombok.EqualsAndHashCode;
#if(${hasBigDecimal})
import java.math.BigDecimal;
#end
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* ${comments}
@ -41,17 +39,20 @@ import java.time.LocalDateTime;
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "${comments}")
public class ${className} extends BaseEntity {
private static final long serialVersionUID = 1L;
#foreach ($column in $columns)
/**
#foreach ($column in $columns)
## 排除部分字段
#if(!$excludeColumns.contains($column.columnName))
/**
* $column.comments
*/
#if($column.columnName == $pk.columnName)
@TableId
#end
@ApiModelProperty(value="$column.comments"#if($column.hidden),hidden=$column.hidden#end)
#if($column.columnName == $pk.columnName)
@TableId
#end
@ApiModelProperty(value="$column.comments"#if($column.hidden),hidden=$column.hidden#end)
private $column.attrType $column.lowerAttrName;
#end
#end
#end
}

View File

@ -24,12 +24,12 @@
<mapper namespace="${package}.${moduleName}.mapper.${className}Mapper">
<resultMap id="${classname}Map" type="${package}.${moduleName}.entity.${className}">
#foreach($column in $columns)
#if($column.lowerAttrName==$pk.lowerAttrName)
<id property="${pk.lowerAttrName}" column="${pk.columnName}"/>
#else
<result property="${column.lowerAttrName}" column="${column.columnName}"/>
#end
#end
#foreach($column in $columns)
#if($column.lowerAttrName==$pk.lowerAttrName)
<id property="${pk.lowerAttrName}" column="${pk.columnName}"/>
#else
<result property="${column.lowerAttrName}" column="${column.columnName}"/>
#end
#end
</resultMap>
</mapper>

View File

@ -1,3 +1,5 @@
#set($excludeColumns = ["create_time","update_time","create_by","update_by"])
export const tableOption = {
"border": true,
"index": true,
@ -8,11 +10,22 @@ export const tableOption = {
"searchMenuSpan": 6,
"column": [
#foreach ($column in $columns)
{
## 当列是主键 或者 列是审计字段时候, 新增不显示,编辑的时候显示单不能编辑
#if($column.columnName == $pk.columnName || $excludeColumns.contains($column.columnName))
{
"type": "input",
"label": "$column.comments",
"prop": "$column.lowerAttrName",
"addDisplay": false,
"editDisabled": true
}#if($foreach.hasNext),#end
#else
{
"type": "input",
"label": "$column.comments",
"prop": "$column.lowerAttrName"
}#if($foreach.hasNext),#end
#end
#end
]
}

View File

@ -37,8 +37,8 @@
</template>
<script>
import {addObj, delObj, fetchList, putObj} from '@/api/'
import {tableOption} from '@/const/crud/'
import {fetchList, getObj, addObj, putObj, delObj} from '@/api/${pathName}'
import {tableOption} from '@/const/crud/${pathName}'
import {mapGetters} from 'vuex'
export default {

View File

@ -1,13 +1,20 @@
#set($excludeColumns = ["create_time","update_time","create_by","update_by"])
<template>
<el-dialog
:title="!dataForm.id ? '新增' : '修改'"
:close-on-click-modal="false"
@close="closeDialog()"
:visible.sync="visible">
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
## 当列是主键 新增不显示,编辑(dataForm.id 有值)的时候显示单不能编辑
#if($column.columnName == $pk.columnName || $excludeColumns.contains($column.columnName))
<el-form-item label="${column.comments}" prop="${column.lowerAttrName}" v-if="dataForm.id">
<el-input v-model="dataForm.${column.lowerAttrName}" placeholder="${column.comments}" disabled></el-input>
</el-form-item>
#else
<el-form-item label="${column.comments}" prop="${column.lowerAttrName}">
<el-input v-model="dataForm.${column.lowerAttrName}" placeholder="${column.comments}"></el-input>
<el-input v-model="dataForm.${column.lowerAttrName}" placeholder="${column.comments}"></el-input>
</el-form-item>
#end
#end
@ -20,7 +27,7 @@
</template>
<script>
import {addObj, getObj, putObj} from '@/api/'
import {getObj, addObj, putObj} from '@/api/${pathName}'
export default {
data () {
@ -39,7 +46,7 @@
},
dataRule: {
#foreach($column in $columns)
#if($column.columnName != $pk.columnName)
#if($column.columnName != $pk.columnName && !$excludeColumns.contains($column.columnName))
${column.lowerAttrName}: [
{ required: true, message: '${column.comments}不能为空', trigger: 'blur' }
]#if($velocityCount != $columns.size()),#end
@ -51,13 +58,12 @@
},
methods: {
init (id) {
this.dataForm.${pk.lowerAttrName} = id || 0;
this.visible = true;
this.canSubmit = true;
this.$nextTick(() => {
this.$refs['dataForm'].resetFields()
if (this.dataForm.${pk.lowerAttrName}) {
getObj(this.dataForm.${pk.lowerAttrName}).then(response => {
this.$refs['dataForm'].resetFields()
if (id) {
getObj(id).then(response => {
this.dataForm = response.data.data
})
}
@ -87,6 +93,10 @@
}
}
})
},
//重置表单
closeDialog() {
this.$refs["dataForm"].resetFields()
}
}
}

View File

@ -51,11 +51,10 @@
</template>
<script>
import {delObj, fetchList} from '@/api/'
import TableForm from './'
import {mapGetters} from 'vuex'
export default {
import {fetchList, delObj} from '@/api/${pathName}'
import TableForm from './${pathName}-form'
import {mapGetters} from 'vuex'
export default {
data () {
return {
dataForm: {
@ -120,7 +119,7 @@
}).then(data => {
this.$message.success('删除成功')
this.getDataList()
})
}).catch(() => {})
}
}
}