mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-21 05:31:54 +08:00
代码生成:增加主子表 erp 模式的示例
This commit is contained in:
@@ -8,4 +8,15 @@ ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_NOT_EXITS = new
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_ERROR = new ErrorCode(TODO 补充编号, "不能设置自己为父${table.classComment}");
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_${treeNameColumn_javaField_underlineCase.toUpperCase()}_DUPLICATE = new ErrorCode(TODO 补充编号, "已经存在该${treeNameColumn.columnComment}的${table.classComment}");
|
||||
ErrorCode ${simpleClassName_underlineCase.toUpperCase()}_PARENT_IS_CHILD = new ErrorCode(TODO 补充编号, "不能设置自己的子${table.className}为父${table.className}");
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 11 )## 特殊:ERP 情况
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
|
||||
ErrorCode ${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS = new ErrorCode(TODO 补充编号, "${subTable.classComment}不存在");
|
||||
#if ( !$subTable.subJoinMany )
|
||||
ErrorCode ${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS = new ErrorCode(TODO 补充编号, "${subTable.classComment}已存在");
|
||||
#end
|
||||
#end
|
||||
#end
|
@@ -75,7 +75,6 @@ public interface ${table.className}Service {
|
||||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
|
||||
// ==================== 子表($subTable.classComment) ====================
|
||||
|
||||
## 情况一:MASTER_ERP 时,需要分查询页子表
|
||||
|
@@ -235,6 +235,7 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||
#foreach ($subTable in $subTables)
|
||||
#set ($index = $foreach.count - 1)
|
||||
#set ($subSimpleClassName = $subSimpleClassNames.get($index))
|
||||
#set ($simpleClassNameUnderlineCase = $simpleClassNameUnderlineCases.get($index))
|
||||
#set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段
|
||||
#set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段
|
||||
#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写
|
||||
@@ -268,24 +269,44 @@ public class ${table.className}ServiceImpl implements ${table.className}Service
|
||||
#if ( $table.templateType == 11 )
|
||||
@Override
|
||||
public ${subPrimaryColumn.javaType} create${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
|
||||
## 特殊:一对一时,需要保证只有一条,不能重复插入
|
||||
#if ( !$subTable.subJoinMany)
|
||||
// 校验是否已经存在
|
||||
if (${subClassNameVars.get($index)}Mapper.selectBy${SubJoinColumnName}(${subClassNameVar}.get${SubJoinColumnName}()) != null) {
|
||||
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_EXISTS);
|
||||
}
|
||||
// 插入
|
||||
#end
|
||||
${subClassNameVars.get($index)}Mapper.insert(${subClassNameVar});
|
||||
return ${subClassNameVar}.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update${subSimpleClassName}(${subTable.className}DO ${subClassNameVar}) {
|
||||
// 校验存在
|
||||
validate${subSimpleClassName}Exists(${subClassNameVar}.getId());
|
||||
// 更新
|
||||
${subClassNameVars.get($index)}Mapper.updateById(${subClassNameVar});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||
// 校验存在
|
||||
validate${subSimpleClassName}Exists(id);
|
||||
// 删除
|
||||
${subClassNameVars.get($index)}Mapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||
@Override
|
||||
public ${subTable.className}DO get${subSimpleClassName}(${subPrimaryColumn.javaType} id) {
|
||||
return ${subClassNameVars.get($index)}Mapper.selectById(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void validate${subSimpleClassName}Exists(${subPrimaryColumn.javaType} id) {
|
||||
if (${subClassNameVar}Mapper.selectById(id) == null) {
|
||||
throw exception(${simpleClassNameUnderlineCase.toUpperCase()}_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
## 情况二:非 MASTER_ERP 时,支持批量的新增、修改操作
|
||||
#else
|
||||
|
@@ -25,7 +25,8 @@
|
||||
#elseif ($javaType == "Boolean")
|
||||
#set ($dictMethod = "getBoolDictOptions")
|
||||
#end
|
||||
#if ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 TODO 芋艿:这里要忽略下 join 字段;
|
||||
#if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写
|
||||
#elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里
|
||||
<el-form-item label="${comment}" prop="${javaField}">
|
||||
<el-input v-model="formData.${javaField}" placeholder="请输入${comment}" />
|
||||
</el-form-item>
|
||||
|
@@ -118,7 +118,7 @@
|
||||
#end
|
||||
</el-form>
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $subTables && $subTables.size() > 0 )
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
<!-- 子表的表单 -->
|
||||
<el-tabs v-model="subTabsName">
|
||||
#foreach ($subTable in $subTables)
|
||||
@@ -146,9 +146,11 @@ import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.busine
|
||||
import { defaultProps, handleTree } from '@/utils/tree'
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#foreach ($subSimpleClassName in $subSimpleClassNames)
|
||||
import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue'
|
||||
#end
|
||||
#end
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
@@ -182,6 +184,7 @@ const formRef = ref() // 表单 Ref
|
||||
const ${classNameVar}Tree = ref() // 树形结构
|
||||
#end
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#if ( $subTables && $subTables.size() > 0 )
|
||||
|
||||
/** 子表的表单 */
|
||||
@@ -190,6 +193,7 @@ const subTabsName = ref('$subClassNameVars.get(0)')
|
||||
const ${subClassNameVar}FormRef = ref()
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
@@ -219,6 +223,7 @@ const submitForm = async () => {
|
||||
// 校验表单
|
||||
await formRef.value.validate()
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#if ( $subTables && $subTables.size() > 0 )
|
||||
// 校验子表单
|
||||
#foreach ($subTable in $subTables)
|
||||
@@ -231,12 +236,14 @@ const submitForm = async () => {
|
||||
return
|
||||
}
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as ${simpleClassName}Api.${simpleClassName}VO
|
||||
## 特殊:主子表专属逻辑
|
||||
#if ( $table.templateType == 10 || $table.templateType == 12 )
|
||||
#if ( $subTables && $subTables.size() > 0 )
|
||||
// 拼接子表的数据
|
||||
#foreach ($subTable in $subTables)
|
||||
@@ -244,6 +251,7 @@ const submitForm = async () => {
|
||||
#set ($subClassNameVar = $subClassNameVars.get($index))
|
||||
data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData()
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
if (formType.value === 'create') {
|
||||
await ${simpleClassName}Api.create${simpleClassName}(data)
|
||||
|
Reference in New Issue
Block a user