!513 优化代码生成

This commit is contained in:
YunaiV 2023-06-17 12:22:12 +08:00
parent 5f8129d65b
commit eb44015b74
10 changed files with 206 additions and 107 deletions

View File

@ -34,7 +34,7 @@
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<!-- 看看咋放到 bom 里 --> <!-- 看看咋放到 bom 里 -->
<lombok.version>1.18.26</lombok.version> <lombok.version>1.18.26</lombok.version>
<spring.boot.version>2.7.11</spring.boot.version> <spring.boot.version>2.7.12</spring.boot.version>
<mapstruct.version>1.5.5.Final</mapstruct.version> <mapstruct.version>1.5.5.Final</mapstruct.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>

View File

@ -16,7 +16,7 @@
<properties> <properties>
<revision>1.7.3-snapshot</revision> <revision>1.7.3-snapshot</revision>
<!-- 统一依赖管理 --> <!-- 统一依赖管理 -->
<spring.boot.version>2.7.11</spring.boot.version> <spring.boot.version>2.7.12</spring.boot.version>
<spring.cloud.version>2021.0.5</spring.cloud.version> <spring.cloud.version>2021.0.5</spring.cloud.version>
<spring.cloud.alibaba.version>2021.0.4.0</spring.cloud.alibaba.version> <spring.cloud.alibaba.version>2021.0.4.0</spring.cloud.alibaba.version>
<!-- Web 相关 --> <!-- Web 相关 -->
@ -76,7 +76,7 @@
<minio.version>8.5.2</minio.version> <minio.version>8.5.2</minio.version>
<aliyun-java-sdk-core.version>4.6.3</aliyun-java-sdk-core.version> <aliyun-java-sdk-core.version>4.6.3</aliyun-java-sdk-core.version>
<aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version> <aliyun-java-sdk-dysmsapi.version>2.2.1</aliyun-java-sdk-dysmsapi.version>
<tencentcloud-sdk-java.version>3.1.715</tencentcloud-sdk-java.version> <tencentcloud-sdk-java.version>3.1.758</tencentcloud-sdk-java.version>
<justauth.version>1.4.0</justauth.version> <justauth.version>1.4.0</justauth.version>
<jimureport.version>1.5.6</jimureport.version> <jimureport.version>1.5.6</jimureport.version>
<xercesImpl.version>2.12.2</xercesImpl.version> <xercesImpl.version>2.12.2</xercesImpl.version>

View File

@ -3,11 +3,15 @@ package cn.iocoder.yudao.framework.captcha.config;
import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ClassUtil;
import cn.iocoder.yudao.framework.captcha.core.enums.CaptchaRedisKeyConstants; import cn.iocoder.yudao.framework.captcha.core.enums.CaptchaRedisKeyConstants;
import cn.iocoder.yudao.framework.captcha.core.service.RedisCaptchaServiceImpl; import cn.iocoder.yudao.framework.captcha.core.service.RedisCaptchaServiceImpl;
import com.xingyuv.captcha.properties.AjCaptchaProperties;
import com.xingyuv.captcha.service.CaptchaCacheService; import com.xingyuv.captcha.service.CaptchaCacheService;
import com.xingyuv.captcha.service.impl.CaptchaServiceFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import javax.annotation.Resource;
@AutoConfiguration @AutoConfiguration
public class YudaoCaptchaConfiguration { public class YudaoCaptchaConfiguration {
@ -17,9 +21,17 @@ public class YudaoCaptchaConfiguration {
ClassUtil.loadClass(CaptchaRedisKeyConstants.class.getName()); ClassUtil.loadClass(CaptchaRedisKeyConstants.class.getName());
} }
@Resource
private StringRedisTemplate stringRedisTemplate;
@Bean @Bean
public CaptchaCacheService captchaCacheService(StringRedisTemplate stringRedisTemplate) { public CaptchaCacheService captchaCacheService(AjCaptchaProperties config) {
return new RedisCaptchaServiceImpl(stringRedisTemplate); // 缓存类型 redis/local/....
CaptchaCacheService ret = CaptchaServiceFactory.getCache(config.getCacheType().name());
if (ret instanceof RedisCaptchaServiceImpl) {
((RedisCaptchaServiceImpl) ret).setStringRedisTemplate(stringRedisTemplate);
}
return ret;
} }
} }

View File

@ -20,6 +20,10 @@ public class RedisCaptchaServiceImpl implements CaptchaCacheService {
@Resource // 保证 aj-captcha SPI 创建时的注入 @Resource // 保证 aj-captcha SPI 创建时的注入
private StringRedisTemplate stringRedisTemplate; private StringRedisTemplate stringRedisTemplate;
public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
this.stringRedisTemplate = stringRedisTemplate;
}
@Override @Override
public String type() { public String type() {
return "redis"; return "redis";

View File

@ -17,7 +17,7 @@ public class ${sceneEnum.prefixClass}${table.className}RespVO extends ${sceneEnu
#foreach ($column in $columns) #foreach ($column in $columns)
#if (${column.listOperationResult} && (!${column.createOperation} || !${column.updateOperation}))##不是通用字段 #if (${column.listOperationResult} && (!${column.createOperation} || !${column.updateOperation}))##不是通用字段
@Schema(description = "${column.columnComment}"#if (!${column.nullable}), required = true#end#if ("$!column.example" != ""), example = "${column.example}"#end) @Schema(description = "${column.columnComment}"#if (!${column.nullable}), requiredMode = Schema.RequiredMode.REQUIRED#end#if ("$!column.example" != ""), example = "${column.example}"#end)
private ${column.javaType} ${column.javaField}; private ${column.javaType} ${column.javaField};
#end #end

View File

@ -16,7 +16,7 @@ export interface ${simpleClassName}VO {
} }
// 查询${table.classComment}列表 // 查询${table.classComment}列表
export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => { export const get${simpleClassName}Page = async (params) => {
return await request.get({ url: `${baseURL}/page`, params }) return await request.get({ url: `${baseURL}/page`, params })
} }

View File

@ -16,7 +16,7 @@ export interface ${simpleClassName}VO {
} }
// 查询${table.classComment}列表 // 查询${table.classComment}列表
export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => { export const get${simpleClassName}Page = async (params) => {
return await request.get({ url: '${baseURL}/page', params }) return await request.get({ url: '${baseURL}/page', params })
} }

View File

@ -1,5 +1,5 @@
import { BasicColumn, FormSchema, useRender } from '@/components/Table' import { BasicColumn, FormSchema, useRender } from '@/components/Table'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, getDictOptions } from '@/utils/dict'
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
#foreach($column in $columns) #foreach($column in $columns)
@ -53,7 +53,7 @@ export const searchFormSchema: FormSchema[] = [
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 设置了 dictType 数据字典的情况 #if ("" != $dictType)## 设置了 dictType 数据字典的情况
options: getIntDictOptions(DICT_TYPE.$dictType.toUpperCase()) options: getDictOptions(DICT_TYPE.$dictType.toUpperCase())
#else## 未设置 dictType 数据字典的情况 #else## 未设置 dictType 数据字典的情况
options: [] options: []
#end #end
@ -67,7 +67,7 @@ export const searchFormSchema: FormSchema[] = [
#end #end
] ]
export const formSchema: FormSchema[] = [ export const createFormSchema: FormSchema[] = [
{ {
label: '编号', label: '编号',
field: 'id', field: 'id',
@ -75,7 +75,7 @@ export const formSchema: FormSchema[] = [
component: 'Input' component: 'Input'
}, },
#foreach($column in $columns) #foreach($column in $columns)
#if ($column.createOperation || $column.updateOperation) #if ($column.createOperation)
#set ($dictType = $column.dictType) #set ($dictType = $column.dictType)
#set ($javaField = $column.javaField) #set ($javaField = $column.javaField)
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
@ -90,16 +90,24 @@ export const formSchema: FormSchema[] = [
#if ($column.htmlType == "input") #if ($column.htmlType == "input")
component: 'Input' component: 'Input'
#elseif($column.htmlType == "imageUpload")## 图片上传 #elseif($column.htmlType == "imageUpload")## 图片上传
component: 'Upload' component: 'FileUpload',
componentProps: {
fileType: 'file',
maxCount: 1
}
#elseif($column.htmlType == "fileUpload")## 文件上传 #elseif($column.htmlType == "fileUpload")## 文件上传
component: 'Upload' component: 'FileUpload',
componentProps: {
fileType: 'image',
maxCount: 1
}
#elseif($column.htmlType == "editor")## 文本编辑器 #elseif($column.htmlType == "editor")## 文本编辑器
component: 'InputTextArea' component: 'Editor'
#elseif($column.htmlType == "select")## 下拉框 #elseif($column.htmlType == "select")## 下拉框
component: 'Select', component: 'Select',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典 #else##没数据字典
options:[] options:[]
#end #end
@ -108,16 +116,16 @@ export const formSchema: FormSchema[] = [
component: 'Checkbox', component: 'Checkbox',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典 #else##没数据字典
options:[] options:[]
#end #end
} }
#elseif($column.htmlType == "radio")## 单选框 #elseif($column.htmlType == "radio")## 单选框
component: 'Radio', component: 'RadioButtonGroup',
componentProps: { componentProps: {
#if ("" != $dictType)## 有数据字典 #if ("" != $dictType)## 有数据字典
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典 #else##没数据字典
options:[] options:[]
#end #end
@ -132,3 +140,69 @@ export const formSchema: FormSchema[] = [
#end #end
#end #end
] ]
export const updateFormSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
show: false,
component: 'Input'
},
#foreach($column in $columns)
#if ($column.updateOperation)
#set ($dictType = $column.dictType)
#set ($javaField = $column.javaField)
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#set ($comment = $column.columnComment)
#if (!$column.primaryKey)## 忽略主键,不用在表单里
{
label: '${comment}',
field: '${javaField}',
#if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键
required: true,
#end
#if ($column.htmlType == "input")
component: 'Input'
#elseif($column.htmlType == "imageUpload")## 图片上传
component: 'Upload'
#elseif($column.htmlType == "fileUpload")## 文件上传
component: 'Upload'
#elseif($column.htmlType == "editor")## 文本编辑器
component: 'Editor'
#elseif($column.htmlType == "select")## 下拉框
component: 'Select',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "checkbox")## 多选框
component: 'Checkbox',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "radio")## 单选框
component: 'RadioButtonGroup',
componentProps: {
#if ("" != $dictType)## 有数据字典
options: getDictOptions(DICT_TYPE.$dictType.toUpperCase(), 'number')
#else##没数据字典
options:[]
#end
}
#elseif($column.htmlType == "datetime")## 时间框
component: 'DatePicker'
#elseif($column.htmlType == "textarea")## 文本域
component: 'InputTextArea'
#end
},
#end
#end
#end
]

View File

@ -1,49 +1,56 @@
<template> <template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? '编辑' : '新增'" @ok="handleSubmit"> <BasicModal v-bind="$attrs" @register="registerModal" :title="isUpdate ? t('action.edit') : t('action.create')" @ok="handleSubmit">
<BasicForm @register="registerForm" /> <BasicForm @register="registerForm" />
</BasicModal> </BasicModal>
</template> </template>
<script lang="ts" setup name="${table.className}Modal"> <script lang="ts" setup>
import { ref, unref } from 'vue' import { ref, unref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal' import { useI18n } from '@/hooks/web/useI18n'
import { BasicForm, useForm } from '@/components/Form' import { useMessage } from '@/hooks/web/useMessage'
import { formSchema } from './${classNameVar}.data' import { BasicForm, useForm } from '@/components/Form'
import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}' import { BasicModal, useModalInner } from '@/components/Modal'
import { createFormSchema, updateFormSchema } from './${classNameVar}.data'
import { create${simpleClassName}, get${simpleClassName}, update${simpleClassName} } from '@/api/${table.moduleName}/${classNameVar}'
const emit = defineEmits(['success', 'register']) defineOptions({ name: '${table.className}Modal' })
const isUpdate = ref(true)
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ const { t } = useI18n()
labelWidth: 120, const { createMessage } = useMessage()
baseColProps: { span: 24 }, const emit = defineEmits(['success', 'register'])
schemas: formSchema, const isUpdate = ref(true)
showActionButtonGroup: false,
actionColOptions: { span: 23 }
})
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
resetFields() labelWidth: 120,
setModalProps({ confirmLoading: false }) baseColProps: { span: 24 },
isUpdate.value = !!data?.isUpdate schemas: isUpdate? updateFormSchema : createFormSchema,
if (unref(isUpdate)) { showActionButtonGroup: false,
const res = await get${simpleClassName}(data.record.id) actionColOptions: { span: 23 }
setFieldsValue({ ...res }) })
}
})
async function handleSubmit() { const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
try { resetFields()
const values = await validate() setModalProps({ confirmLoading: false })
setModalProps({ confirmLoading: true }) isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) { if (unref(isUpdate)) {
await update${simpleClassName}(values) const res = await get${simpleClassName}(data.record.id)
} else { setFieldsValue({ ...res })
await create${simpleClassName}(values)
}
closeModal()
emit('success')
} finally {
setModalProps({ confirmLoading: false })
}
} }
})
async function handleSubmit() {
try {
const values = await validate()
setModalProps({ confirmLoading: true })
if (unref(isUpdate)) {
await update${simpleClassName}(values)
} else {
await create${simpleClassName}(values)
}
closeModal()
emit('success')
createMessage.success(t('common.saveSuccessText'))
} finally {
setModalProps({ confirmLoading: false })
}
}
</script> </script>

View File

@ -33,58 +33,60 @@
<${simpleClassName}Modal @register="registerModal" @success="reload()" /> <${simpleClassName}Modal @register="registerModal" @success="reload()" />
</div> </div>
</template> </template>
<script lang="ts" setup name="${table.className}"> <script lang="ts" setup>
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal' import { useModal } from '@/components/Modal'
import ${simpleClassName}Modal from './${simpleClassName}Modal.vue' import ${simpleClassName}Modal from './${simpleClassName}Modal.vue'
import { IconEnum } from '@/enums/appEnum' import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table' import { BasicTable, useTable, TableAction } from '@/components/Table'
import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${classNameVar}' import { delete${simpleClassName}, export${simpleClassName}, get${simpleClassName}Page } from '@/api/${table.moduleName}/${classNameVar}'
import { columns, searchFormSchema } from './${classNameVar}.data' import { columns, searchFormSchema } from './${classNameVar}.data'
const { t } = useI18n() defineOptions({ name: '${table.className}' })
const { createConfirm, createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerTable, { getForm, reload }] = useTable({ const { t } = useI18n()
title: '${table.classComment}列表', const { createConfirm, createMessage } = useMessage()
api: get${simpleClassName}Page, const [registerModal, { openModal }] = useModal()
columns,
formConfig: { labelWidth: 120, schemas: searchFormSchema }, const [registerTable, { getForm, reload }] = useTable({
useSearchForm: true, title: '${table.classComment}列表',
showTableSetting: true, api: get${simpleClassName}Page,
actionColumn: { columns,
width: 140, formConfig: { labelWidth: 120, schemas: searchFormSchema },
title: t('common.action'), useSearchForm: true,
dataIndex: 'action', showTableSetting: true,
fixed: 'right' actionColumn: {
width: 140,
title: t('common.action'),
dataIndex: 'action',
fixed: 'right'
}
})
function handleCreate() {
openModal(true, { isUpdate: false })
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true })
}
async function handleExport() {
createConfirm({
title: t('common.exportTitle'),
iconType: 'warning',
content: t('common.exportMessage'),
async onOk() {
await export${simpleClassName}(getForm().getFieldsValue())
createMessage.success(t('common.exportSuccessText'))
} }
}) })
}
function handleCreate() { async function handleDelete(record: Recordable) {
openModal(true, { isUpdate: false }) await delete${simpleClassName}(record.id)
} createMessage.success(t('common.delSuccessText'))
reload()
function handleEdit(record: Recordable) { }
openModal(true, { record, isUpdate: true })
}
async function handleExport() {
createConfirm({
title: t('common.exportTitle'),
iconType: 'warning',
content: t('common.exportMessage'),
async onOk() {
await export${simpleClassName}(getForm().getFieldsValue())
createMessage.success(t('common.exportSuccessText'))
}
})
}
async function handleDelete(record: Recordable) {
await delete${simpleClassName}(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
</script> </script>