Commit 7724d6e830e267714fa046f0df7be013c2246290
Committed by
Gitee
!765 Vue2 + Element UI 代码生成器
Merge pull request !765 from 芋道源码/feature/sub-table
Showing
120 changed files
with
9990 additions
and
324 deletions
Too many changes.
To preserve performance only 100 of 120 files are displayed.
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| ... | ... | @@ -104,6 +104,18 @@ public class CodegenEngine { |
| 104 | 104 | vueFilePath("views/${table.moduleName}/${table.businessName}/index.vue")) |
| 105 | 105 | .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("api/api.js"), |
| 106 | 106 | vueFilePath("api/${table.moduleName}/${classNameVar}.js")) |
| 107 | + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/form.vue"), | |
| 108 | + vueFilePath("views/${table.moduleName}/${table.businessName}/${simpleClassName}Form.vue")) | |
| 109 | + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/form_sub_normal.vue"), // 特殊:主子表专属逻辑 | |
| 110 | + vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue")) | |
| 111 | + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/form_sub_inner.vue"), // 特殊:主子表专属逻辑 | |
| 112 | + vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue")) | |
| 113 | + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/form_sub_erp.vue"), // 特殊:主子表专属逻辑 | |
| 114 | + vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}Form.vue")) | |
| 115 | + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/list_sub_inner.vue"), // 特殊:主子表专属逻辑 | |
| 116 | + vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue")) | |
| 117 | + .put(CodegenFrontTypeEnum.VUE2.getType(), vueTemplatePath("views/components/list_sub_erp.vue"), // 特殊:主子表专属逻辑 | |
| 118 | + vueFilePath("views/${table.moduleName}/${table.businessName}/components/${subSimpleClassName}List.vue")) | |
| 107 | 119 | // Vue3 标准模版 |
| 108 | 120 | .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/index.vue"), |
| 109 | 121 | vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue")) |
| ... | ... | @@ -285,6 +297,10 @@ public class CodegenEngine { |
| 285 | 297 | if (StrUtil.count(content, "dateFormatter") == 1) { |
| 286 | 298 | content = StrUtils.removeLineContains(content, "dateFormatter"); |
| 287 | 299 | } |
| 300 | + // Vue2 界面:修正 $refs | |
| 301 | + if (StrUtil.count(content, "this.refs") >= 1) { | |
| 302 | + content = content.replace("this.refs", "this.$refs"); | |
| 303 | + } | |
| 288 | 304 | // Vue 界面:去除多的 dict 相关,只有一个的情况下,说明没使用到 |
| 289 | 305 | if (StrUtil.count(content, "getIntDictOptions") == 1) { |
| 290 | 306 | content = content.replace("getIntDictOptions, ", ""); |
| ... | ... | @@ -452,7 +468,7 @@ public class CodegenEngine { |
| 452 | 468 | } |
| 453 | 469 | |
| 454 | 470 | private static String vueFilePath(String path) { |
| 455 | - return "yudao-ui-${sceneEnum.basePackage}/" + // 顶级目录 | |
| 471 | + return "yudao-ui-${sceneEnum.basePackage}-vue2/" + // 顶级目录 | |
| 456 | 472 | "src/" + path; |
| 457 | 473 | } |
| 458 | 474 | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm
| ... | ... | @@ -35,21 +35,113 @@ export function get${simpleClassName}(id) { |
| 35 | 35 | }) |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | +#if ( $table.templateType != 2 ) | |
| 38 | 39 | // 获得${table.classComment}分页 |
| 39 | -export function get${simpleClassName}Page(query) { | |
| 40 | +export function get${simpleClassName}Page(params) { | |
| 40 | 41 | return request({ |
| 41 | 42 | url: '${baseURL}/page', |
| 42 | 43 | method: 'get', |
| 43 | - params: query | |
| 44 | + params | |
| 44 | 45 | }) |
| 45 | 46 | } |
| 46 | - | |
| 47 | +#else | |
| 48 | +// 获得${table.classComment}列表 | |
| 49 | +export function get${simpleClassName}List(params) { | |
| 50 | + return request({ | |
| 51 | + url: '${baseURL}/list', | |
| 52 | + method: 'get', | |
| 53 | + params | |
| 54 | + }) | |
| 55 | +} | |
| 56 | +#end | |
| 47 | 57 | // 导出${table.classComment} Excel |
| 48 | -export function export${simpleClassName}Excel(query) { | |
| 58 | +export function export${simpleClassName}Excel(params) { | |
| 49 | 59 | return request({ |
| 50 | 60 | url: '${baseURL}/export-excel', |
| 51 | 61 | method: 'get', |
| 52 | - params: query, | |
| 62 | + params, | |
| 53 | 63 | responseType: 'blob' |
| 54 | 64 | }) |
| 55 | 65 | } |
| 66 | +## 特殊:主子表专属逻辑 TODO @puhui999:下面方法的【空格】不太对 | |
| 67 | +#foreach ($subTable in $subTables) | |
| 68 | + #set ($index = $foreach.count - 1) | |
| 69 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 70 | + #set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段 | |
| 71 | + #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | |
| 72 | + #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 73 | + #set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index)) | |
| 74 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 75 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 76 | + | |
| 77 | +// ==================== 子表($subTable.classComment) ==================== | |
| 78 | + ## 情况一:MASTER_ERP 时,需要分查询页子表 | |
| 79 | + #if ( $table.templateType == 11 ) | |
| 80 | + | |
| 81 | + // 获得${subTable.classComment}分页 | |
| 82 | + export function get${subSimpleClassName}Page(params) { | |
| 83 | + return request({ | |
| 84 | + url: '${baseURL}/${subSimpleClassName_strikeCase}/page', | |
| 85 | + method: 'get', | |
| 86 | + params | |
| 87 | + }) | |
| 88 | + } | |
| 89 | + ## 情况二:非 MASTER_ERP 时,需要列表查询子表 | |
| 90 | + #else | |
| 91 | + #if ( $subTable.subJoinMany ) | |
| 92 | + | |
| 93 | + // 获得${subTable.classComment}列表 | |
| 94 | + export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}) { | |
| 95 | + return request({ | |
| 96 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField}, | |
| 97 | + method: 'get' | |
| 98 | + }) | |
| 99 | + } | |
| 100 | + #else | |
| 101 | + | |
| 102 | + // 获得${subTable.classComment} | |
| 103 | + export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}) { | |
| 104 | + return request({ | |
| 105 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=` + ${subJoinColumn.javaField}, | |
| 106 | + method: 'get' | |
| 107 | + }) | |
| 108 | + } | |
| 109 | + #end | |
| 110 | + #end | |
| 111 | + ## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作 | |
| 112 | + #if ( $table.templateType == 11 ) | |
| 113 | + // 新增${subTable.classComment} | |
| 114 | + export function create${subSimpleClassName}(data) { | |
| 115 | + return request({ | |
| 116 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/create`, | |
| 117 | + method: 'post', | |
| 118 | + data | |
| 119 | + }) | |
| 120 | + } | |
| 121 | + | |
| 122 | + // 修改${subTable.classComment} | |
| 123 | + export function update${subSimpleClassName}(data) { | |
| 124 | + return request({ | |
| 125 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/update`, | |
| 126 | + method: 'post', | |
| 127 | + data | |
| 128 | + }) | |
| 129 | + } | |
| 130 | + | |
| 131 | + // 删除${subTable.classComment} | |
| 132 | + export function delete${subSimpleClassName}(id) { | |
| 133 | + return request({ | |
| 134 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id, | |
| 135 | + method: 'delete' | |
| 136 | + }) | |
| 137 | + } | |
| 138 | + | |
| 139 | + // 获得${subTable.classComment} | |
| 140 | + export function get${subSimpleClassName}(id) { | |
| 141 | + return request({ | |
| 142 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id, | |
| 143 | + method: 'get' | |
| 144 | + }) | |
| 145 | + } | |
| 146 | + #end | |
| 147 | +#end | |
| 56 | 148 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_erp.vue.vm
0 → 100644
| 1 | +#set ($subTable = $subTables.get($subIndex))##当前表 | |
| 2 | +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | |
| 3 | +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | |
| 4 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 5 | +<template> | |
| 6 | + <div class="app-container"> | |
| 7 | + <!-- 对话框(添加 / 修改) --> | |
| 8 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 9 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 10 | + #foreach($column in $subColumns) | |
| 11 | + #if ($column.createOperation || $column.updateOperation) | |
| 12 | + #set ($dictType = $column.dictType) | |
| 13 | + #set ($javaField = $column.javaField) | |
| 14 | + #set ($javaType = $column.javaType) | |
| 15 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 16 | + #set ($comment = $column.columnComment) | |
| 17 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 18 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 19 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 20 | + <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 21 | + </el-form-item> | |
| 22 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 23 | + #set ($hasImageUploadColumn = true) | |
| 24 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 25 | + <ImageUpload v-model="formData.${javaField}"/> | |
| 26 | + </el-form-item> | |
| 27 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 28 | + #set ($hasFileUploadColumn = true) | |
| 29 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 30 | + <FileUpload v-model="formData.${javaField}"/> | |
| 31 | + </el-form-item> | |
| 32 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 33 | + #set ($hasEditorColumn = true) | |
| 34 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 35 | + <editor v-model="formData.${javaField}" :min-height="192"/> | |
| 36 | + </el-form-item> | |
| 37 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 38 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 39 | + <el-select v-model="formData.${javaField}" placeholder="请选择${comment}"> | |
| 40 | + #if ("" != $dictType)## 有数据字典 | |
| 41 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 42 | + :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end /> | |
| 43 | + #else##没数据字典 | |
| 44 | + <el-option label="请选择字典生成" value="" /> | |
| 45 | + #end | |
| 46 | + </el-select> | |
| 47 | + </el-form-item> | |
| 48 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 49 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 50 | + <el-checkbox-group v-model="formData.${javaField}"> | |
| 51 | + #if ("" != $dictType)## 有数据字典 | |
| 52 | + <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 53 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox> | |
| 54 | + #else##没数据字典 | |
| 55 | + <el-checkbox>请选择字典生成</el-checkbox> | |
| 56 | + #end | |
| 57 | + </el-checkbox-group> | |
| 58 | + </el-form-item> | |
| 59 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 60 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 61 | + <el-radio-group v-model="formData.${javaField}"> | |
| 62 | + #if ("" != $dictType)## 有数据字典 | |
| 63 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 64 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)" | |
| 65 | + #else:label="dict.value"#end>{{dict.label}}</el-radio> | |
| 66 | + #else##没数据字典 | |
| 67 | + <el-radio label="1">请选择字典生成</el-radio> | |
| 68 | + #end | |
| 69 | + </el-radio-group> | |
| 70 | + </el-form-item> | |
| 71 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 72 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 73 | + <el-date-picker clearable v-model="formData.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" /> | |
| 74 | + </el-form-item> | |
| 75 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 76 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 77 | + <el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入内容" /> | |
| 78 | + </el-form-item> | |
| 79 | + #end | |
| 80 | + #end | |
| 81 | + #end | |
| 82 | + </el-form> | |
| 83 | + <div slot="footer" class="dialog-footer"> | |
| 84 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 85 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 86 | + </div> | |
| 87 | + </el-dialog> | |
| 88 | + </div> | |
| 89 | +</template> | |
| 90 | + | |
| 91 | +<script> | |
| 92 | + import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'; | |
| 93 | + #if ($hasImageUploadColumn) | |
| 94 | + import ImageUpload from '@/components/ImageUpload'; | |
| 95 | + #end | |
| 96 | + #if ($hasFileUploadColumn) | |
| 97 | + import FileUpload from '@/components/FileUpload'; | |
| 98 | + #end | |
| 99 | + #if ($hasEditorColumn) | |
| 100 | + import Editor from '@/components/Editor'; | |
| 101 | + #end | |
| 102 | + export default { | |
| 103 | + name: "${subSimpleClassName}Form", | |
| 104 | + components: { | |
| 105 | + #if ($hasImageUploadColumn) | |
| 106 | + ImageUpload, | |
| 107 | + #end | |
| 108 | + #if ($hasFileUploadColumn) | |
| 109 | + FileUpload, | |
| 110 | + #end | |
| 111 | + #if ($hasEditorColumn) | |
| 112 | + Editor, | |
| 113 | + #end | |
| 114 | + }, | |
| 115 | + data() { | |
| 116 | + return { | |
| 117 | + // 弹出层标题 | |
| 118 | + dialogTitle: "", | |
| 119 | + // 是否显示弹出层 | |
| 120 | + dialogVisible: false, | |
| 121 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 122 | + formLoading: false, | |
| 123 | + // 表单参数 | |
| 124 | + formData: { | |
| 125 | + #foreach ($column in $subColumns) | |
| 126 | + #if ($column.createOperation || $column.updateOperation) | |
| 127 | + #if ($column.htmlType == "checkbox") | |
| 128 | + $column.javaField: [], | |
| 129 | + #else | |
| 130 | + $column.javaField: undefined, | |
| 131 | + #end | |
| 132 | + #end | |
| 133 | + #end | |
| 134 | + }, | |
| 135 | + // 表单校验 | |
| 136 | + formRules: { | |
| 137 | + #foreach ($column in $subColumns) | |
| 138 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 139 | + #set($comment=$column.columnComment) | |
| 140 | + $column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }], | |
| 141 | + #end | |
| 142 | + #end | |
| 143 | + }, | |
| 144 | + }; | |
| 145 | + }, | |
| 146 | + methods: { | |
| 147 | + /** 打开弹窗 */ | |
| 148 | + async open(id, ${subJoinColumn.javaField}) { | |
| 149 | + this.dialogVisible = true; | |
| 150 | + this.reset(); | |
| 151 | + this.formData.${subJoinColumn.javaField} = ${subJoinColumn.javaField}; | |
| 152 | + // 修改时,设置数据 | |
| 153 | + if (id) { | |
| 154 | + this.formLoading = true; | |
| 155 | + try { | |
| 156 | + const res = await ${simpleClassName}Api.get${subSimpleClassName}(id); | |
| 157 | + this.formData = res.data; | |
| 158 | + this.dialogTitle = "修改${subTable.classComment}"; | |
| 159 | + } finally { | |
| 160 | + this.formLoading = false; | |
| 161 | + } | |
| 162 | + } | |
| 163 | + this.dialogTitle = "新增${subTable.classComment}"; | |
| 164 | + }, | |
| 165 | + /** 提交按钮 */ | |
| 166 | + async submitForm() { | |
| 167 | + await this.#[[$]]#refs["formRef"].validate(); | |
| 168 | + this.formLoading = true; | |
| 169 | + try { | |
| 170 | + const data = this.formData; | |
| 171 | + // 修改的提交 | |
| 172 | + if (data.${primaryColumn.javaField}) { | |
| 173 | + await ${simpleClassName}Api.update${subSimpleClassName}(data); | |
| 174 | + this.#[[$modal]]#.msgSuccess("修改成功"); | |
| 175 | + this.dialogVisible = false; | |
| 176 | + this.#[[$]]#emit('success'); | |
| 177 | + return; | |
| 178 | + } | |
| 179 | + // 添加的提交 | |
| 180 | + await ${simpleClassName}Api.create${subSimpleClassName}(data); | |
| 181 | + this.#[[$modal]]#.msgSuccess("新增成功"); | |
| 182 | + this.dialogVisible = false; | |
| 183 | + this.#[[$]]#emit('success'); | |
| 184 | + }finally { | |
| 185 | + this.formLoading = false; | |
| 186 | + } | |
| 187 | + }, | |
| 188 | + /** 表单重置 */ | |
| 189 | + reset() { | |
| 190 | + this.formData = { | |
| 191 | + #foreach ($column in $subColumns) | |
| 192 | + #if ($column.createOperation || $column.updateOperation) | |
| 193 | + #if ($column.htmlType == "checkbox") | |
| 194 | + $column.javaField: [], | |
| 195 | + #else | |
| 196 | + $column.javaField: undefined, | |
| 197 | + #end | |
| 198 | + #end | |
| 199 | + #end | |
| 200 | + }; | |
| 201 | + this.resetForm("formRef"); | |
| 202 | + }, | |
| 203 | + } | |
| 204 | + }; | |
| 205 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_inner.vue.vm
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/form_sub_normal.vue.vm
0 → 100644
| 1 | +#set ($subTable = $subTables.get($subIndex))##当前表 | |
| 2 | +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | |
| 3 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 4 | +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | |
| 5 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 6 | +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 7 | +<template> | |
| 8 | + <div class="app-container"> | |
| 9 | + #if ( $subTable.subJoinMany )## 情况一:一对多,table + form | |
| 10 | + <el-form | |
| 11 | + ref="formRef" | |
| 12 | + :model="formData" | |
| 13 | + :rules="formRules" | |
| 14 | + v-loading="formLoading" | |
| 15 | + label-width="0px" | |
| 16 | + :inline-message="true" | |
| 17 | + > | |
| 18 | + <el-table :data="formData" class="-mt-10px"> | |
| 19 | + <el-table-column label="序号" type="index" width="100" /> | |
| 20 | + #foreach($column in $subColumns) | |
| 21 | + #if ($column.createOperation || $column.updateOperation) | |
| 22 | + #set ($dictType = $column.dictType) | |
| 23 | + #set ($javaField = $column.javaField) | |
| 24 | + #set ($javaType = $column.javaType) | |
| 25 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 26 | + #set ($comment = $column.columnComment) | |
| 27 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 28 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 29 | + <el-table-column label="${comment}" min-width="150"> | |
| 30 | + <template v-slot="{ row, $index }"> | |
| 31 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 32 | + <el-input v-model="row.${javaField}" placeholder="请输入${comment}" /> | |
| 33 | + </el-form-item> | |
| 34 | + </template> | |
| 35 | + </el-table-column> | |
| 36 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 37 | + #set ($hasImageUploadColumn = true) | |
| 38 | + <el-table-column label="${comment}" min-width="200"> | |
| 39 | + <template v-slot="{ row, $index }"> | |
| 40 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 41 | + <ImageUpload v-model="row.${javaField}"/> | |
| 42 | + </el-form-item> | |
| 43 | + </template> | |
| 44 | + </el-table-column> | |
| 45 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 46 | + #set ($hasFileUploadColumn = true) | |
| 47 | + <el-table-column label="${comment}" min-width="200"> | |
| 48 | + <template v-slot="{ row, $index }"> | |
| 49 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 50 | + <FileUpload v-model="row.${javaField}"/> | |
| 51 | + </el-form-item> | |
| 52 | + </template> | |
| 53 | + </el-table-column> | |
| 54 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 55 | + #set ($hasEditorColumn = true) | |
| 56 | + <el-table-column label="${comment}" min-width="400"> | |
| 57 | + <template v-slot="{ row, $index }"> | |
| 58 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 59 | + <Editor v-model="row.${javaField}" :min-height="192"/> | |
| 60 | + </el-form-item> | |
| 61 | + </template> | |
| 62 | + </el-table-column> | |
| 63 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 64 | + <el-table-column label="${comment}" min-width="150"> | |
| 65 | + <template v-slot="{ row, $index }"> | |
| 66 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 67 | + <el-select v-model="row.${javaField}" placeholder="请选择${comment}"> | |
| 68 | + #if ("" != $dictType)## 有数据字典 | |
| 69 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 70 | + :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end /> | |
| 71 | + #else##没数据字典 | |
| 72 | + <el-option label="请选择字典生成" value="" /> | |
| 73 | + #end | |
| 74 | + </el-select> | |
| 75 | + </el-form-item> | |
| 76 | + </template> | |
| 77 | + </el-table-column> | |
| 78 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 79 | + <el-table-column label="${comment}" min-width="150"> | |
| 80 | + <template v-slot="{ row, $index }"> | |
| 81 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 82 | + <el-checkbox-group v-model="row.${javaField}"> | |
| 83 | + #if ("" != $dictType)## 有数据字典 | |
| 84 | + <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 85 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox> | |
| 86 | + #else##没数据字典 | |
| 87 | + <el-checkbox>请选择字典生成</el-checkbox> | |
| 88 | + #end | |
| 89 | + </el-checkbox-group> | |
| 90 | + </el-form-item> | |
| 91 | + </template> | |
| 92 | + </el-table-column> | |
| 93 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 94 | + <el-table-column label="${comment}" min-width="150"> | |
| 95 | + <template v-slot="{ row, $index }"> | |
| 96 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 97 | + <el-radio-group v-model="row.${javaField}"> | |
| 98 | + #if ("" != $dictType)## 有数据字典 | |
| 99 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 100 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)" | |
| 101 | + #else:label="dict.value"#end>{{dict.label}}</el-radio> | |
| 102 | + #else##没数据字典 | |
| 103 | + <el-radio label="1">请选择字典生成</el-radio> | |
| 104 | + #end | |
| 105 | + </el-radio-group> | |
| 106 | + </el-form-item> | |
| 107 | + </template> | |
| 108 | + </el-table-column> | |
| 109 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 110 | + <el-table-column label="${comment}" min-width="150"> | |
| 111 | + <template v-slot="{ row, $index }"> | |
| 112 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 113 | + <el-date-picker clearable v-model="row.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" /> | |
| 114 | + </el-form-item> | |
| 115 | + </template> | |
| 116 | + </el-table-column> | |
| 117 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 118 | + <el-table-column label="${comment}" min-width="200"> | |
| 119 | + <template v-slot="{ row, $index }"> | |
| 120 | + <el-form-item :prop="`${$index}.${javaField}`" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 121 | + <el-input v-model="row.${javaField}" type="textarea" placeholder="请输入${comment}" /> | |
| 122 | + </el-form-item> | |
| 123 | + </template> | |
| 124 | + </el-table-column> | |
| 125 | + #end | |
| 126 | + #end | |
| 127 | + #end | |
| 128 | + <el-table-column align="center" fixed="right" label="操作" width="60"> | |
| 129 | + <template v-slot="{ $index }"> | |
| 130 | + <el-link @click="handleDelete($index)">—</el-link> | |
| 131 | + </template> | |
| 132 | + </el-table-column> | |
| 133 | + </el-table> | |
| 134 | + </el-form> | |
| 135 | + <el-row justify="center" class="mt-3"> | |
| 136 | + <el-button @click="handleAdd" round>+ 添加${subTable.classComment}</el-button> | |
| 137 | + </el-row> | |
| 138 | + #else## 情况二:一对一,form | |
| 139 | + <el-form | |
| 140 | + ref="formRef" | |
| 141 | + :model="formData" | |
| 142 | + :rules="formRules" | |
| 143 | + label-width="100px" | |
| 144 | + v-loading="formLoading" | |
| 145 | + > | |
| 146 | + #foreach($column in $subColumns) | |
| 147 | + #if ($column.createOperation || $column.updateOperation) | |
| 148 | + #set ($dictType = $column.dictType) | |
| 149 | + #set ($javaField = $column.javaField) | |
| 150 | + #set ($javaType = $column.javaType) | |
| 151 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 152 | + #set ($comment = $column.columnComment) | |
| 153 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 154 | + #elseif ($column.htmlType == "input" && !$column.primaryKey) | |
| 155 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 156 | + <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 157 | + </el-form-item> | |
| 158 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 159 | + #set ($hasImageUploadColumn = true) | |
| 160 | + <el-form-item label="${comment}"> | |
| 161 | + <ImageUpload v-model="formData.${javaField}"/> | |
| 162 | + </el-form-item> | |
| 163 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 164 | + #set ($hasFileUploadColumn = true) | |
| 165 | + <el-form-item label="${comment}"> | |
| 166 | + <FileUpload v-model="formData.${javaField}"/> | |
| 167 | + </el-form-item> | |
| 168 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 169 | + #set ($hasEditorColumn = true) | |
| 170 | + <el-form-item label="${comment}"> | |
| 171 | + <Editor v-model="formData.${javaField}" :min-height="192"/> | |
| 172 | + </el-form-item> | |
| 173 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 174 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 175 | + <el-select v-model="formData.${javaField}" placeholder="请选择${comment}"> | |
| 176 | + #if ("" != $dictType)## 有数据字典 | |
| 177 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 178 | + :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end /> | |
| 179 | + #else##没数据字典 | |
| 180 | + <el-option label="请选择字典生成" value="" /> | |
| 181 | + #end | |
| 182 | + </el-select> | |
| 183 | + </el-form-item> | |
| 184 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 185 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 186 | + <el-checkbox-group v-model="formData.${javaField}"> | |
| 187 | + #if ("" != $dictType)## 有数据字典 | |
| 188 | + <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 189 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox> | |
| 190 | + #else##没数据字典 | |
| 191 | + <el-checkbox>请选择字典生成</el-checkbox> | |
| 192 | + #end | |
| 193 | + </el-checkbox-group> | |
| 194 | + </el-form-item> | |
| 195 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 196 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 197 | + <el-radio-group v-model="formData.${javaField}"> | |
| 198 | + #if ("" != $dictType)## 有数据字典 | |
| 199 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 200 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)" | |
| 201 | + #else:label="dict.value"#end>{{dict.label}}</el-radio> | |
| 202 | + #else##没数据字典 | |
| 203 | + <el-radio label="1">请选择字典生成</el-radio> | |
| 204 | + #end | |
| 205 | + </el-radio-group> | |
| 206 | + </el-form-item> | |
| 207 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 208 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 209 | + <el-date-picker clearable v-model="formData.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" /> | |
| 210 | + </el-form-item> | |
| 211 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 212 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 213 | + <el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入${comment}" /> | |
| 214 | + </el-form-item> | |
| 215 | + #end | |
| 216 | + #end | |
| 217 | + #end | |
| 218 | + </el-form> | |
| 219 | + #end | |
| 220 | + </div> | |
| 221 | +</template> | |
| 222 | + | |
| 223 | +<script> | |
| 224 | + import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'; | |
| 225 | + #if ($hasImageUploadColumn) | |
| 226 | + import ImageUpload from '@/components/ImageUpload'; | |
| 227 | + #end | |
| 228 | + #if ($hasFileUploadColumn) | |
| 229 | + import FileUpload from '@/components/FileUpload'; | |
| 230 | + #end | |
| 231 | + #if ($hasEditorColumn) | |
| 232 | + import Editor from '@/components/Editor'; | |
| 233 | + #end | |
| 234 | + export default { | |
| 235 | + name: "${subSimpleClassName}Form", | |
| 236 | + components: { | |
| 237 | + #if ($hasImageUploadColumn) | |
| 238 | + ImageUpload, | |
| 239 | + #end | |
| 240 | + #if ($hasFileUploadColumn) | |
| 241 | + FileUpload, | |
| 242 | + #end | |
| 243 | + #if ($hasEditorColumn) | |
| 244 | + Editor, | |
| 245 | + #end | |
| 246 | + }, | |
| 247 | + props:[ | |
| 248 | + '${subJoinColumn.javaField}' | |
| 249 | + ],// ${subJoinColumn.columnComment}(主表的关联字段) | |
| 250 | + data() { | |
| 251 | + return { | |
| 252 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 253 | + formLoading: false, | |
| 254 | + // 表单参数 | |
| 255 | + formData: [], | |
| 256 | + // 表单校验 | |
| 257 | + formRules: { | |
| 258 | + #foreach ($column in $subColumns) | |
| 259 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 260 | + #set($comment=$column.columnComment) | |
| 261 | + $column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }], | |
| 262 | + #end | |
| 263 | + #end | |
| 264 | + }, | |
| 265 | + }; | |
| 266 | + }, | |
| 267 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 268 | + ${subJoinColumn.javaField}:{ | |
| 269 | + handler(val) { | |
| 270 | + // 1. 重置表单 | |
| 271 | + #if ( $subTable.subJoinMany ) | |
| 272 | + this.formData = [] | |
| 273 | + #else | |
| 274 | + this.formData = { | |
| 275 | + #foreach ($column in $subColumns) | |
| 276 | + #if ($column.createOperation || $column.updateOperation) | |
| 277 | + #if ($column.htmlType == "checkbox") | |
| 278 | + $column.javaField: [], | |
| 279 | + #else | |
| 280 | + $column.javaField: undefined, | |
| 281 | + #end | |
| 282 | + #end | |
| 283 | + #end | |
| 284 | + } | |
| 285 | + #end | |
| 286 | + // 2. val 非空,则加载数据 | |
| 287 | + if (!val) { | |
| 288 | + return; | |
| 289 | + } | |
| 290 | + try { | |
| 291 | + this.formLoading = true; | |
| 292 | + // 这里还是需要获取一下 this 的不然取不到 formData | |
| 293 | + const that = this; | |
| 294 | + #if ( $subTable.subJoinMany ) | |
| 295 | + ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val).then(function (res){ | |
| 296 | + that.formData = res.data; | |
| 297 | + }) | |
| 298 | + #else | |
| 299 | + ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val).then(function (res){ | |
| 300 | + const data = res.data; | |
| 301 | + if (!data) { | |
| 302 | + return | |
| 303 | + } | |
| 304 | + that.formData = data; | |
| 305 | + }) | |
| 306 | + #end | |
| 307 | + } finally { | |
| 308 | + this.formLoading = false; | |
| 309 | + } | |
| 310 | + }, | |
| 311 | + immediate: true | |
| 312 | + } | |
| 313 | + }, | |
| 314 | + methods: { | |
| 315 | + #if ( $subTable.subJoinMany ) | |
| 316 | + /** 新增按钮操作 */ | |
| 317 | + handleAdd() { | |
| 318 | + const row = { | |
| 319 | + #foreach ($column in $subColumns) | |
| 320 | + #if ($column.createOperation || $column.updateOperation) | |
| 321 | + #if ($column.htmlType == "checkbox") | |
| 322 | + $column.javaField: [], | |
| 323 | + #else | |
| 324 | + $column.javaField: undefined, | |
| 325 | + #end | |
| 326 | + #end | |
| 327 | + #end | |
| 328 | + } | |
| 329 | + row.${subJoinColumn.javaField} = this.${subJoinColumn.javaField}; | |
| 330 | + this.formData.push(row); | |
| 331 | + }, | |
| 332 | + /** 删除按钮操作 */ | |
| 333 | + handleDelete(index) { | |
| 334 | + this.formData.splice(index, 1); | |
| 335 | + }, | |
| 336 | + #end | |
| 337 | + /** 表单校验 */ | |
| 338 | + validate(){ | |
| 339 | + return this.#[[$]]#refs["formRef"].validate(); | |
| 340 | + }, | |
| 341 | + /** 表单值 */ | |
| 342 | + getData(){ | |
| 343 | + return this.formData; | |
| 344 | + } | |
| 345 | + } | |
| 346 | + }; | |
| 347 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/list_sub_erp.vue.vm
0 → 100644
| 1 | +#set ($subTable = $subTables.get($subIndex))##当前表 | |
| 2 | +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | |
| 3 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 4 | +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | |
| 5 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 6 | +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 7 | +<template> | |
| 8 | + <div class="app-container"> | |
| 9 | +#if ($table.templateType == 11) | |
| 10 | + <!-- 操作工具栏 --> | |
| 11 | + <el-row :gutter="10" class="mb8"> | |
| 12 | + <el-col :span="1.5"> | |
| 13 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 14 | + v-hasPermi="['${permissionPrefix}:create']">新增</el-button> | |
| 15 | + </el-col> | |
| 16 | + </el-row> | |
| 17 | +#end | |
| 18 | + ## 列表 | |
| 19 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 20 | + #foreach($column in $subColumns) | |
| 21 | + #if ($column.listOperationResult) | |
| 22 | + #set ($dictType=$column.dictType) | |
| 23 | + #set ($javaField = $column.javaField) | |
| 24 | + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 25 | + #set ($comment=$column.columnComment) | |
| 26 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 27 | + #elseif ($column.javaType == "LocalDateTime")## 时间类型 | |
| 28 | + <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> | |
| 29 | + <template v-slot="scope"> | |
| 30 | + <span>{{ parseTime(scope.row.${javaField}) }}</span> | |
| 31 | + </template> | |
| 32 | + </el-table-column> | |
| 33 | + #elseif($column.dictType && "" != $column.dictType)## 数据字典 | |
| 34 | + <el-table-column label="${comment}" align="center" prop="${javaField}"> | |
| 35 | + <template v-slot="scope"> | |
| 36 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" /> | |
| 37 | + </template> | |
| 38 | + </el-table-column> | |
| 39 | + #else | |
| 40 | + <el-table-column label="${comment}" align="center" prop="${javaField}" /> | |
| 41 | + #end | |
| 42 | + #end | |
| 43 | + #end | |
| 44 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 45 | + <template v-slot="scope"> | |
| 46 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})" | |
| 47 | + v-hasPermi="['${permissionPrefix}:update']">修改</el-button> | |
| 48 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 49 | + v-hasPermi="['${permissionPrefix}:delete']">删除</el-button> | |
| 50 | + </template> | |
| 51 | + </el-table-column> | |
| 52 | + </el-table> | |
| 53 | +#if ($table.templateType == 11) | |
| 54 | + <!-- 分页组件 --> | |
| 55 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 56 | + @pagination="getList"/> | |
| 57 | + <!-- 对话框(添加 / 修改) --> | |
| 58 | + <${subSimpleClassName}Form ref="formRef" @success="getList" /> | |
| 59 | +#end | |
| 60 | + </div> | |
| 61 | +</template> | |
| 62 | + | |
| 63 | +<script> | |
| 64 | + import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'; | |
| 65 | + #if ($table.templateType == 11) | |
| 66 | + import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue'; | |
| 67 | + #end | |
| 68 | + export default { | |
| 69 | + name: "${subSimpleClassName}List", | |
| 70 | +#if ($table.templateType == 11) | |
| 71 | + components: { | |
| 72 | + ${subSimpleClassName}Form | |
| 73 | + }, | |
| 74 | +#end | |
| 75 | + props:[ | |
| 76 | + '${subJoinColumn.javaField}' | |
| 77 | + ],// ${subJoinColumn.columnComment}(主表的关联字段) | |
| 78 | + data() { | |
| 79 | + return { | |
| 80 | + // 遮罩层 | |
| 81 | + loading: true, | |
| 82 | + // 列表的数据 | |
| 83 | + list: [], | |
| 84 | +#if ($table.templateType == 11) | |
| 85 | + // 列表的总页数 | |
| 86 | + total: 0, | |
| 87 | + // 查询参数 | |
| 88 | + queryParams: { | |
| 89 | + pageNo: 1, | |
| 90 | + pageSize: 10, | |
| 91 | + ${subJoinColumn.javaField}: undefined | |
| 92 | + } | |
| 93 | +#end | |
| 94 | + }; | |
| 95 | + }, | |
| 96 | +#if ($table.templateType != 11) | |
| 97 | + created() { | |
| 98 | + this.getList(); | |
| 99 | + }, | |
| 100 | +#end | |
| 101 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 102 | + ${subJoinColumn.javaField}:{ | |
| 103 | + handler(val) { | |
| 104 | + this.queryParams.${subJoinColumn.javaField} = val; | |
| 105 | + if (val){ | |
| 106 | + this.handleQuery(); | |
| 107 | + } | |
| 108 | + }, | |
| 109 | + immediate: true | |
| 110 | + } | |
| 111 | + }, | |
| 112 | + methods: { | |
| 113 | + /** 查询列表 */ | |
| 114 | + async getList() { | |
| 115 | + try { | |
| 116 | + this.loading = true; | |
| 117 | + #if ($table.templateType == 11) | |
| 118 | + const res = await ${simpleClassName}Api.get${subSimpleClassName}Page(this.queryParams); | |
| 119 | + this.list = res.data.list; | |
| 120 | + this.total = res.data.total; | |
| 121 | + #else | |
| 122 | + #if ( $subTable.subJoinMany ) | |
| 123 | + const res = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(this.${subJoinColumn.javaField}); | |
| 124 | + this.list = res.data; | |
| 125 | + #else | |
| 126 | + const res = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(this.${subJoinColumn.javaField}); | |
| 127 | + const data = res.data; | |
| 128 | + if (!data) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + this.list.push(data); | |
| 132 | + #end | |
| 133 | + #end | |
| 134 | + } finally { | |
| 135 | + this.loading = false; | |
| 136 | + } | |
| 137 | + }, | |
| 138 | + /** 搜索按钮操作 */ | |
| 139 | + handleQuery() { | |
| 140 | + this.queryParams.pageNo = 1; | |
| 141 | + this.getList(); | |
| 142 | + }, | |
| 143 | +#if ($table.templateType == 11) | |
| 144 | + /** 添加/修改操作 */ | |
| 145 | + openForm(id) { | |
| 146 | + if (!this.${subJoinColumn.javaField}) { | |
| 147 | + this.#[[$modal]]#.msgError('请选择一个${table.classComment}'); | |
| 148 | + return; | |
| 149 | + } | |
| 150 | + this.#[[$]]#refs["formRef"].open(id, this.${subJoinColumn.javaField}); | |
| 151 | + }, | |
| 152 | + /** 删除按钮操作 */ | |
| 153 | + async handleDelete(row) { | |
| 154 | + const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; | |
| 155 | + await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?'); | |
| 156 | + try { | |
| 157 | + await ${simpleClassName}Api.delete${subSimpleClassName}(${primaryColumn.javaField}); | |
| 158 | + await this.getList(); | |
| 159 | + this.#[[$modal]]#.msgSuccess("删除成功"); | |
| 160 | + } catch {} | |
| 161 | + }, | |
| 162 | +#end | |
| 163 | + } | |
| 164 | + }; | |
| 165 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/components/list_sub_inner.vue.vm
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/form.vue.vm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + #foreach($column in $columns) | |
| 7 | + #if ($column.createOperation || $column.updateOperation) | |
| 8 | + #set ($dictType = $column.dictType) | |
| 9 | + #set ($javaField = $column.javaField) | |
| 10 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 11 | + #set ($comment = $column.columnComment) | |
| 12 | + #if ( $table.templateType == 2 && $column.id == $treeParentColumn.id ) | |
| 13 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 14 | + <TreeSelect | |
| 15 | + v-model="formData.${javaField}" | |
| 16 | + :options="${classNameVar}Tree" | |
| 17 | + :normalizer="normalizer" | |
| 18 | + placeholder="请选择${comment}" | |
| 19 | + /> | |
| 20 | + </el-form-item> | |
| 21 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 22 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 23 | + <el-input v-model="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 24 | + </el-form-item> | |
| 25 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 26 | + #set ($hasImageUploadColumn = true) | |
| 27 | + <el-form-item label="${comment}"> | |
| 28 | + <ImageUpload v-model="formData.${javaField}"/> | |
| 29 | + </el-form-item> | |
| 30 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 31 | + #set ($hasFileUploadColumn = true) | |
| 32 | + <el-form-item label="${comment}"> | |
| 33 | + <FileUpload v-model="formData.${javaField}"/> | |
| 34 | + </el-form-item> | |
| 35 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 36 | + #set ($hasEditorColumn = true) | |
| 37 | + <el-form-item label="${comment}"> | |
| 38 | + <Editor v-model="formData.${javaField}" :min-height="192"/> | |
| 39 | + </el-form-item> | |
| 40 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 41 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 42 | + <el-select v-model="formData.${javaField}" placeholder="请选择${comment}"> | |
| 43 | + #if ("" != $dictType)## 有数据字典 | |
| 44 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 45 | + :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end /> | |
| 46 | + #else##没数据字典 | |
| 47 | + <el-option label="请选择字典生成" value="" /> | |
| 48 | + #end | |
| 49 | + </el-select> | |
| 50 | + </el-form-item> | |
| 51 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 52 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 53 | + <el-checkbox-group v-model="formData.${javaField}"> | |
| 54 | + #if ("" != $dictType)## 有数据字典 | |
| 55 | + <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 56 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox> | |
| 57 | + #else##没数据字典 | |
| 58 | + <el-checkbox>请选择字典生成</el-checkbox> | |
| 59 | + #end | |
| 60 | + </el-checkbox-group> | |
| 61 | + </el-form-item> | |
| 62 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 63 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 64 | + <el-radio-group v-model="formData.${javaField}"> | |
| 65 | + #if ("" != $dictType)## 有数据字典 | |
| 66 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 67 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)" | |
| 68 | + #else:label="dict.value"#end>{{dict.label}}</el-radio> | |
| 69 | + #else##没数据字典 | |
| 70 | + <el-radio label="1">请选择字典生成</el-radio> | |
| 71 | + #end | |
| 72 | + </el-radio-group> | |
| 73 | + </el-form-item> | |
| 74 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 75 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 76 | + <el-date-picker clearable v-model="formData.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" /> | |
| 77 | + </el-form-item> | |
| 78 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 79 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 80 | + <el-input v-model="formData.${javaField}" type="textarea" placeholder="请输入内容" /> | |
| 81 | + </el-form-item> | |
| 82 | + #end | |
| 83 | + #end | |
| 84 | + #end | |
| 85 | + </el-form> | |
| 86 | + ## 特殊:主子表专属逻辑 | |
| 87 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 88 | + <!-- 子表的表单 --> | |
| 89 | + <el-tabs v-model="subTabsName"> | |
| 90 | + #foreach ($subTable in $subTables) | |
| 91 | + #set ($index = $foreach.count - 1) | |
| 92 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 93 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 94 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 95 | + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar"> | |
| 96 | + <${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" /> | |
| 97 | + </el-tab-pane> | |
| 98 | + #end | |
| 99 | + </el-tabs> | |
| 100 | + #end | |
| 101 | + <div slot="footer" class="dialog-footer"> | |
| 102 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 103 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 104 | + </div> | |
| 105 | + </el-dialog> | |
| 106 | + </div> | |
| 107 | +</template> | |
| 108 | + | |
| 109 | +<script> | |
| 110 | + import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'; | |
| 111 | + #if ($hasImageUploadColumn) | |
| 112 | + import ImageUpload from '@/components/ImageUpload'; | |
| 113 | + #end | |
| 114 | + #if ($hasFileUploadColumn) | |
| 115 | + import FileUpload from '@/components/FileUpload'; | |
| 116 | + #end | |
| 117 | + #if ($hasEditorColumn) | |
| 118 | + import Editor from '@/components/Editor'; | |
| 119 | + #end | |
| 120 | + ## 特殊:树表专属逻辑 | |
| 121 | + #if ( $table.templateType == 2 ) | |
| 122 | + import TreeSelect from "@riophae/vue-treeselect"; | |
| 123 | + import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | |
| 124 | + #end | |
| 125 | + ## 特殊:主子表专属逻辑 | |
| 126 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 127 | + #foreach ($subSimpleClassName in $subSimpleClassNames) | |
| 128 | + import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue' | |
| 129 | + #end | |
| 130 | + #end | |
| 131 | + export default { | |
| 132 | + name: "${simpleClassName}Form", | |
| 133 | + components: { | |
| 134 | + #if ($hasImageUploadColumn) | |
| 135 | + ImageUpload, | |
| 136 | + #end | |
| 137 | + #if ($hasFileUploadColumn) | |
| 138 | + FileUpload, | |
| 139 | + #end | |
| 140 | + #if ($hasEditorColumn) | |
| 141 | + Editor, | |
| 142 | + #end | |
| 143 | + ## 特殊:树表专属逻辑 | |
| 144 | + #if ( $table.templateType == 2 ) | |
| 145 | + TreeSelect, | |
| 146 | + #end | |
| 147 | + ## 特殊:主子表专属逻辑 | |
| 148 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 149 | + #foreach ($subSimpleClassName in $subSimpleClassNames) | |
| 150 | + ${subSimpleClassName}Form, | |
| 151 | + #end | |
| 152 | + #end | |
| 153 | + }, | |
| 154 | + data() { | |
| 155 | + return { | |
| 156 | + // 弹出层标题 | |
| 157 | + dialogTitle: "", | |
| 158 | + // 是否显示弹出层 | |
| 159 | + dialogVisible: false, | |
| 160 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 161 | + formLoading: false, | |
| 162 | + // 表单参数 | |
| 163 | + formData: { | |
| 164 | + #foreach ($column in $columns) | |
| 165 | + #if ($column.createOperation || $column.updateOperation) | |
| 166 | + #if ($column.htmlType == "checkbox") | |
| 167 | + $column.javaField: [], | |
| 168 | + #else | |
| 169 | + $column.javaField: undefined, | |
| 170 | + #end | |
| 171 | + #end | |
| 172 | + #end | |
| 173 | + }, | |
| 174 | + // 表单校验 | |
| 175 | + formRules: { | |
| 176 | + #foreach ($column in $columns) | |
| 177 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 178 | + #set($comment=$column.columnComment) | |
| 179 | + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }], | |
| 180 | + #end | |
| 181 | + #end | |
| 182 | + }, | |
| 183 | + ## 特殊:树表专属逻辑 | |
| 184 | + #if ( $table.templateType == 2 ) | |
| 185 | + ${classNameVar}Tree: [], // 树形结构 | |
| 186 | + #end | |
| 187 | + ## 特殊:主子表专属逻辑 | |
| 188 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 189 | + #if ( $subTables && $subTables.size() > 0 ) | |
| 190 | + /** 子表的表单 */ | |
| 191 | + subTabsName: '$subClassNameVars.get(0)' | |
| 192 | + #end | |
| 193 | + #end | |
| 194 | + }; | |
| 195 | + }, | |
| 196 | + methods: { | |
| 197 | + /** 打开弹窗 */ | |
| 198 | + async open(id) { | |
| 199 | + this.dialogVisible = true; | |
| 200 | + this.reset(); | |
| 201 | + // 修改时,设置数据 | |
| 202 | + if (id) { | |
| 203 | + this.formLoading = true; | |
| 204 | + try { | |
| 205 | + const res = await ${simpleClassName}Api.get${simpleClassName}(id); | |
| 206 | + this.formData = res.data; | |
| 207 | + this.title = "修改${table.classComment}"; | |
| 208 | + } finally { | |
| 209 | + this.formLoading = false; | |
| 210 | + } | |
| 211 | + } | |
| 212 | + this.title = "新增${table.classComment}"; | |
| 213 | + ## 特殊:树表专属逻辑 | |
| 214 | + #if ( $table.templateType == 2 ) | |
| 215 | + await this.get${simpleClassName}Tree(); | |
| 216 | + #end | |
| 217 | + }, | |
| 218 | + /** 提交按钮 */ | |
| 219 | + async submitForm() { | |
| 220 | + // 校验主表 | |
| 221 | + await this.$refs["formRef"].validate(); | |
| 222 | + ## 特殊:主子表专属逻辑 | |
| 223 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 224 | + #if ( $subTables && $subTables.size() > 0 ) | |
| 225 | + // 校验子表 | |
| 226 | + #foreach ($subTable in $subTables) | |
| 227 | + #set ($index = $foreach.count - 1) | |
| 228 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 229 | + try { | |
| 230 | + ## 代码生成后会替换为正确的 refs | |
| 231 | + await this.refs['${subClassNameVar}FormRef'].validate(); | |
| 232 | + } catch (e) { | |
| 233 | + this.subTabsName = '${subClassNameVar}'; | |
| 234 | + return; | |
| 235 | + } | |
| 236 | + #end | |
| 237 | + #end | |
| 238 | + #end | |
| 239 | + this.formLoading = true; | |
| 240 | + try { | |
| 241 | + const data = this.formData; | |
| 242 | + ## 特殊:主子表专属逻辑 | |
| 243 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 244 | + #if ( $subTables && $subTables.size() > 0 ) | |
| 245 | + // 拼接子表的数据 | |
| 246 | + #foreach ($subTable in $subTables) | |
| 247 | + #set ($index = $foreach.count - 1) | |
| 248 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 249 | + data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = this.refs['${subClassNameVar}FormRef'].getData(); | |
| 250 | + #end | |
| 251 | + #end | |
| 252 | + #end | |
| 253 | + // 修改的提交 | |
| 254 | + if (data.${primaryColumn.javaField}) { | |
| 255 | + await ${simpleClassName}Api.update${simpleClassName}(data); | |
| 256 | + this.#[[$modal]]#.msgSuccess("修改成功"); | |
| 257 | + this.dialogVisible = false; | |
| 258 | + this.#[[$]]#emit('success'); | |
| 259 | + return; | |
| 260 | + } | |
| 261 | + // 添加的提交 | |
| 262 | + await ${simpleClassName}Api.create${simpleClassName}(data); | |
| 263 | + this.#[[$modal]]#.msgSuccess("新增成功"); | |
| 264 | + this.dialogVisible = false; | |
| 265 | + this.#[[$]]#emit('success'); | |
| 266 | + } finally { | |
| 267 | + this.formLoading = false; | |
| 268 | + } | |
| 269 | + }, | |
| 270 | + ## 特殊:树表专属逻辑 | |
| 271 | + #if ( $table.templateType == 2 ) | |
| 272 | + /** 获得${table.classComment}树 */ | |
| 273 | + async get${simpleClassName}Tree() { | |
| 274 | + this.${classNameVar}Tree = []; | |
| 275 | + const res = await ${simpleClassName}Api.get${simpleClassName}List(); | |
| 276 | + const root = { id: 0, name: '顶级${table.classComment}', children: [] }; | |
| 277 | + root.children = this.handleTree(res.data, 'id', '${treeParentColumn.javaField}') | |
| 278 | + this.${classNameVar}Tree.push(root) | |
| 279 | + }, | |
| 280 | + #end | |
| 281 | + ## 特殊:树表专属逻辑 | |
| 282 | + #if ( $table.templateType == 2 ) | |
| 283 | + /** 转换${table.classComment}数据结构 */ | |
| 284 | + normalizer(node) { | |
| 285 | + if (node.children && !node.children.length) { | |
| 286 | + delete node.children; | |
| 287 | + } | |
| 288 | + #if ($treeNameColumn.javaField == "name") | |
| 289 | + return { | |
| 290 | + id: node.id, | |
| 291 | + label: node.name, | |
| 292 | + children: node.children | |
| 293 | + }; | |
| 294 | + #else | |
| 295 | + return { | |
| 296 | + id: node.id, | |
| 297 | + label: node['$treeNameColumn.javaField'], | |
| 298 | + children: node.children | |
| 299 | + }; | |
| 300 | + #end | |
| 301 | + }, | |
| 302 | + #end | |
| 303 | + /** 表单重置 */ | |
| 304 | + reset() { | |
| 305 | + this.formData = { | |
| 306 | + #foreach ($column in $columns) | |
| 307 | + #if ($column.createOperation || $column.updateOperation) | |
| 308 | + #if ($column.htmlType == "checkbox") | |
| 309 | + $column.javaField: [], | |
| 310 | + #else | |
| 311 | + $column.javaField: undefined, | |
| 312 | + #end | |
| 313 | + #end | |
| 314 | + #end | |
| 315 | + }; | |
| 316 | + this.resetForm("formRef"); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + }; | |
| 320 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/views/index.vue.vm
| 1 | 1 | <template> |
| 2 | 2 | <div class="app-container"> |
| 3 | - | |
| 4 | 3 | <!-- 搜索工作栏 --> |
| 5 | 4 | <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> |
| 6 | 5 | #foreach($column in $columns) |
| ... | ... | @@ -47,18 +46,68 @@ |
| 47 | 46 | <!-- 操作工具栏 --> |
| 48 | 47 | <el-row :gutter="10" class="mb8"> |
| 49 | 48 | <el-col :span="1.5"> |
| 50 | - <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" | |
| 49 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 51 | 50 | v-hasPermi="['${permissionPrefix}:create']">新增</el-button> |
| 52 | 51 | </el-col> |
| 53 | 52 | <el-col :span="1.5"> |
| 54 | 53 | <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" |
| 55 | 54 | v-hasPermi="['${permissionPrefix}:export']">导出</el-button> |
| 56 | 55 | </el-col> |
| 56 | + ## 特殊:树表专属逻辑 | |
| 57 | + #if ( $table.templateType == 2 ) | |
| 58 | + <el-col :span="1.5"> | |
| 59 | + <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll"> | |
| 60 | + 展开/折叠 | |
| 61 | + </el-button> | |
| 62 | + </el-col> | |
| 63 | + #end | |
| 57 | 64 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 58 | 65 | </el-row> |
| 59 | 66 | |
| 60 | - <!-- 列表 --> | |
| 61 | - <el-table v-loading="loading" :data="list"> | |
| 67 | + ## 特殊:主子表专属逻辑 | |
| 68 | + #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) | |
| 69 | + <el-table | |
| 70 | + v-loading="loading" | |
| 71 | + :data="list" | |
| 72 | + :stripe="true" | |
| 73 | + :highlight-current-row="true" | |
| 74 | + :show-overflow-tooltip="true" | |
| 75 | + @current-change="handleCurrentChange" | |
| 76 | + > | |
| 77 | + ## 特殊:树表专属逻辑 | |
| 78 | + #elseif ( $table.templateType == 2 ) | |
| 79 | + <el-table | |
| 80 | + v-loading="loading" | |
| 81 | + :data="list" | |
| 82 | + :stripe="true" | |
| 83 | + :show-overflow-tooltip="true" | |
| 84 | + v-if="refreshTable" | |
| 85 | + row-key="id" | |
| 86 | + :default-expand-all="isExpandAll" | |
| 87 | + :tree-props="{children: 'children', hasChildren: 'hasChildren'}" | |
| 88 | + > | |
| 89 | + #else | |
| 90 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 91 | + #end | |
| 92 | + ## 特殊:主子表专属逻辑 | |
| 93 | + #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 ) | |
| 94 | + <!-- 子表的列表 --> | |
| 95 | + <el-table-column type="expand"> | |
| 96 | + <template #default="scope"> | |
| 97 | + <el-tabs value="$subClassNameVars.get(0)"> | |
| 98 | + #foreach ($subTable in $subTables) | |
| 99 | + #set ($index = $foreach.count - 1) | |
| 100 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 101 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 102 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 103 | + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar"> | |
| 104 | + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" /> | |
| 105 | + </el-tab-pane> | |
| 106 | + #end | |
| 107 | + </el-tabs> | |
| 108 | + </template> | |
| 109 | + </el-table-column> | |
| 110 | + #end | |
| 62 | 111 | #foreach($column in $columns) |
| 63 | 112 | #if ($column.listOperationResult) |
| 64 | 113 | #set ($dictType=$column.dictType) |
| ... | ... | @@ -84,102 +133,42 @@ |
| 84 | 133 | #end |
| 85 | 134 | <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> |
| 86 | 135 | <template v-slot="scope"> |
| 87 | - <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" | |
| 136 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})" | |
| 88 | 137 | v-hasPermi="['${permissionPrefix}:update']">修改</el-button> |
| 89 | 138 | <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" |
| 90 | 139 | v-hasPermi="['${permissionPrefix}:delete']">删除</el-button> |
| 91 | 140 | </template> |
| 92 | 141 | </el-table-column> |
| 93 | 142 | </el-table> |
| 143 | +## 特殊:树表专属逻辑(树不需要分页) | |
| 144 | +#if ( $table.templateType != 2 ) | |
| 94 | 145 | <!-- 分页组件 --> |
| 95 | 146 | <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" |
| 96 | 147 | @pagination="getList"/> |
| 97 | - | |
| 148 | +#end | |
| 98 | 149 | <!-- 对话框(添加 / 修改) --> |
| 99 | - <el-dialog :title="title" :visible.sync="open" width="500px" v-dialogDrag append-to-body> | |
| 100 | - <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 101 | -#foreach($column in $columns) | |
| 102 | -#if ($column.createOperation || $column.updateOperation) | |
| 103 | - #set ($dictType = $column.dictType) | |
| 104 | - #set ($javaField = $column.javaField) | |
| 105 | - #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 106 | - #set ($comment = $column.columnComment) | |
| 107 | -#if ($column.htmlType == "input") | |
| 108 | - #if (!$column.primaryKey)## 忽略主键,不用在表单里 | |
| 109 | - <el-form-item label="${comment}" prop="${javaField}"> | |
| 110 | - <el-input v-model="form.${javaField}" placeholder="请输入${comment}" /> | |
| 111 | - </el-form-item> | |
| 150 | + <${simpleClassName}Form ref="formRef" @success="getList" /> | |
| 151 | + ## 特殊:主子表专属逻辑 | |
| 152 | + #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) | |
| 153 | + <!-- 子表的列表 --> | |
| 154 | + <el-tabs v-model="subTabsName"> | |
| 155 | + #foreach ($subTable in $subTables) | |
| 156 | + #set ($index = $foreach.count - 1) | |
| 157 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 158 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 159 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 160 | + <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar"> | |
| 161 | + <${subSimpleClassName}List v-if="currentRow.id" :${subJoinColumn_strikeCase}="currentRow.id" /> | |
| 162 | + </el-tab-pane> | |
| 163 | + #end | |
| 164 | + </el-tabs> | |
| 112 | 165 | #end |
| 113 | -#elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 114 | - #set ($hasImageUploadColumn = true) | |
| 115 | - <el-form-item label="${comment}"> | |
| 116 | - <imageUpload v-model="form.${javaField}"/> | |
| 117 | - </el-form-item> | |
| 118 | -#elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 119 | - #set ($hasFileUploadColumn = true) | |
| 120 | - <el-form-item label="${comment}"> | |
| 121 | - <fileUpload v-model="form.${javaField}"/> | |
| 122 | - </el-form-item> | |
| 123 | -#elseif($column.htmlType == "editor")## 文本编辑器 | |
| 124 | - #set ($hasEditorColumn = true) | |
| 125 | - <el-form-item label="${comment}"> | |
| 126 | - <editor v-model="form.${javaField}" :min-height="192"/> | |
| 127 | - </el-form-item> | |
| 128 | -#elseif($column.htmlType == "select")## 下拉框 | |
| 129 | - <el-form-item label="${comment}" prop="${javaField}"> | |
| 130 | - <el-select v-model="form.${javaField}" placeholder="请选择${comment}"> | |
| 131 | - #if ("" != $dictType)## 有数据字典 | |
| 132 | - <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 133 | - :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end /> | |
| 134 | - #else##没数据字典 | |
| 135 | - <el-option label="请选择字典生成" value="" /> | |
| 136 | - #end | |
| 137 | - </el-select> | |
| 138 | - </el-form-item> | |
| 139 | -#elseif($column.htmlType == "checkbox")## 多选框 | |
| 140 | - <el-form-item label="${comment}" prop="${javaField}"> | |
| 141 | - <el-checkbox-group v-model="form.${javaField}"> | |
| 142 | - #if ("" != $dictType)## 有数据字典 | |
| 143 | - <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 144 | - :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox> | |
| 145 | - #else##没数据字典 | |
| 146 | - <el-checkbox>请选择字典生成</el-checkbox> | |
| 147 | - #end | |
| 148 | - </el-checkbox-group> | |
| 149 | - </el-form-item> | |
| 150 | -#elseif($column.htmlType == "radio")## 单选框 | |
| 151 | - <el-form-item label="${comment}" prop="${javaField}"> | |
| 152 | - <el-radio-group v-model="form.${javaField}"> | |
| 153 | - #if ("" != $dictType)## 有数据字典 | |
| 154 | - <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 155 | - :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-radio> | |
| 156 | - #else##没数据字典 | |
| 157 | - <el-radio label="1">请选择字典生成</el-radio> | |
| 158 | - #end | |
| 159 | - </el-radio-group> | |
| 160 | - </el-form-item> | |
| 161 | -#elseif($column.htmlType == "datetime")## 时间框 | |
| 162 | - <el-form-item label="${comment}" prop="${javaField}"> | |
| 163 | - <el-date-picker clearable v-model="form.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" /> | |
| 164 | - </el-form-item> | |
| 165 | -#elseif($column.htmlType == "textarea")## 文本框 | |
| 166 | - <el-form-item label="${comment}" prop="${javaField}"> | |
| 167 | - <el-input v-model="form.${javaField}" type="textarea" placeholder="请输入内容" /> | |
| 168 | - </el-form-item> | |
| 169 | -#end | |
| 170 | -#end | |
| 171 | -#end | |
| 172 | - </el-form> | |
| 173 | - <div slot="footer" class="dialog-footer"> | |
| 174 | - <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 175 | - <el-button @click="cancel">取 消</el-button> | |
| 176 | - </div> | |
| 177 | - </el-dialog> | |
| 178 | 166 | </div> |
| 179 | 167 | </template> |
| 180 | 168 | |
| 181 | 169 | <script> |
| 182 | -import { create${simpleClassName}, update${simpleClassName}, delete${simpleClassName}, get${simpleClassName}, get${simpleClassName}Page, export${simpleClassName}Excel } from "@/api/${table.moduleName}/${classNameVar}"; | |
| 170 | +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}'; | |
| 171 | +import ${simpleClassName}Form from './${simpleClassName}Form.vue'; | |
| 183 | 172 | #if ($hasImageUploadColumn) |
| 184 | 173 | import ImageUpload from '@/components/ImageUpload'; |
| 185 | 174 | #end |
| ... | ... | @@ -189,10 +178,26 @@ import FileUpload from '@/components/FileUpload'; |
| 189 | 178 | #if ($hasEditorColumn) |
| 190 | 179 | import Editor from '@/components/Editor'; |
| 191 | 180 | #end |
| 192 | - | |
| 181 | +## 特殊:主子表专属逻辑 | |
| 182 | +#if ( $table.templateType != 10 ) | |
| 183 | +#if ( $subTables && $subTables.size() > 0 ) | |
| 184 | + #foreach ($subSimpleClassName in $subSimpleClassNames) | |
| 185 | + import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'; | |
| 186 | + #end | |
| 187 | +#end | |
| 188 | +#end | |
| 193 | 189 | export default { |
| 194 | 190 | name: "${simpleClassName}", |
| 195 | 191 | components: { |
| 192 | + ${simpleClassName}Form, | |
| 193 | +## 特殊:主子表专属逻辑 | |
| 194 | +#if ( $table.templateType != 10 ) | |
| 195 | +#if ( $subTables && $subTables.size() > 0 ) | |
| 196 | + #foreach ($subSimpleClassName in $subSimpleClassNames) | |
| 197 | + ${subSimpleClassName}List, | |
| 198 | + #end | |
| 199 | +#end | |
| 200 | +#end | |
| 196 | 201 | #if ($hasImageUploadColumn) |
| 197 | 202 | ImageUpload, |
| 198 | 203 | #end |
| ... | ... | @@ -211,40 +216,44 @@ export default { |
| 211 | 216 | exportLoading: false, |
| 212 | 217 | // 显示搜索条件 |
| 213 | 218 | showSearch: true, |
| 214 | - // 总条数 | |
| 215 | - total: 0, | |
| 219 | + ## 特殊:树表专属逻辑(树不需要分页接口) | |
| 220 | + #if ( $table.templateType != 2 ) | |
| 221 | + // 总条数 | |
| 222 | + total: 0, | |
| 223 | + #end | |
| 216 | 224 | // ${table.classComment}列表 |
| 217 | 225 | list: [], |
| 218 | - // 弹出层标题 | |
| 219 | - title: "", | |
| 220 | - // 是否显示弹出层 | |
| 221 | - open: false, | |
| 226 | + // 是否展开,默认全部展开 | |
| 227 | + isExpandAll: true, | |
| 228 | + // 重新渲染表格状态 | |
| 229 | + refreshTable: true, | |
| 230 | + // 选中行 | |
| 231 | + currentRow: {}, | |
| 222 | 232 | // 查询参数 |
| 223 | 233 | queryParams: { |
| 224 | - pageNo: 1, | |
| 225 | - pageSize: 10, | |
| 234 | + ## 特殊:树表专属逻辑(树不需要分页接口) | |
| 235 | + #if ( $table.templateType != 2 ) | |
| 236 | + pageNo: 1, | |
| 237 | + pageSize: 10, | |
| 238 | + #end | |
| 226 | 239 | #foreach ($column in $columns) |
| 227 | 240 | #if ($column.listOperation) |
| 228 | 241 | #if ($column.listOperationCondition != 'BETWEEN') |
| 229 | 242 | $column.javaField: null, |
| 230 | 243 | #end |
| 231 | - #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN") | |
| 244 | + #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN") | |
| 232 | 245 | $column.javaField: [], |
| 233 | 246 | #end |
| 234 | 247 | #end |
| 235 | 248 | #end |
| 236 | 249 | }, |
| 237 | - // 表单参数 | |
| 238 | - form: {}, | |
| 239 | - // 表单校验 | |
| 240 | - rules: { | |
| 241 | - #foreach ($column in $columns) | |
| 242 | - #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 243 | - #set($comment=$column.columnComment) | |
| 244 | - $column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }], | |
| 245 | - #end | |
| 246 | - #end | |
| 247 | - } | |
| 250 | + ## 特殊:主子表专属逻辑-erp | |
| 251 | + #if ( $table.templateType == 11) | |
| 252 | + #if ( $subTables && $subTables.size() > 0 ) | |
| 253 | + /** 子表的列表 */ | |
| 254 | + subTabsName: '$subClassNameVars.get(0)' | |
| 255 | + #end | |
| 256 | + #end | |
| 248 | 257 | }; |
| 249 | 258 | }, |
| 250 | 259 | created() { |
| ... | ... | @@ -252,34 +261,21 @@ export default { |
| 252 | 261 | }, |
| 253 | 262 | methods: { |
| 254 | 263 | /** 查询列表 */ |
| 255 | - getList() { | |
| 264 | + async getList() { | |
| 265 | + try { | |
| 256 | 266 | this.loading = true; |
| 257 | - // 执行查询 | |
| 258 | - get${simpleClassName}Page(this.queryParams).then(response => { | |
| 259 | - this.list = response.data.list; | |
| 260 | - this.total = response.data.total; | |
| 267 | + ## 特殊:树表专属逻辑(树不需要分页接口) | |
| 268 | + #if ( $table.templateType == 2 ) | |
| 269 | + const res = await ${simpleClassName}Api.get${simpleClassName}List(this.queryParams); | |
| 270 | + this.list = this.handleTree(res.data, 'id', '${treeParentColumn.javaField}'); | |
| 271 | + #else | |
| 272 | + const res = await ${simpleClassName}Api.get${simpleClassName}Page(this.queryParams); | |
| 273 | + this.list = res.data.list; | |
| 274 | + this.total = res.data.total; | |
| 275 | + #end | |
| 276 | + } finally { | |
| 261 | 277 | this.loading = false; |
| 262 | - }); | |
| 263 | - }, | |
| 264 | - /** 取消按钮 */ | |
| 265 | - cancel() { | |
| 266 | - this.open = false; | |
| 267 | - this.reset(); | |
| 268 | - }, | |
| 269 | - /** 表单重置 */ | |
| 270 | - reset() { | |
| 271 | - this.form = { | |
| 272 | - #foreach ($column in $columns) | |
| 273 | - #if ($column.createOperation || $column.updateOperation) | |
| 274 | - #if ($column.htmlType == "checkbox") | |
| 275 | - $column.javaField: [], | |
| 276 | - #else | |
| 277 | - $column.javaField: undefined, | |
| 278 | - #end | |
| 279 | - #end | |
| 280 | - #end | |
| 281 | - }; | |
| 282 | - this.resetForm("form"); | |
| 278 | + } | |
| 283 | 279 | }, |
| 284 | 280 | /** 搜索按钮操作 */ |
| 285 | 281 | handleQuery() { |
| ... | ... | @@ -291,79 +287,54 @@ export default { |
| 291 | 287 | this.resetForm("queryForm"); |
| 292 | 288 | this.handleQuery(); |
| 293 | 289 | }, |
| 294 | - /** 新增按钮操作 */ | |
| 295 | - handleAdd() { | |
| 296 | - this.reset(); | |
| 297 | - this.open = true; | |
| 298 | - this.title = "添加${table.classComment}"; | |
| 299 | - }, | |
| 300 | - /** 修改按钮操作 */ | |
| 301 | - handleUpdate(row) { | |
| 302 | - this.reset(); | |
| 303 | - const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; | |
| 304 | - get${simpleClassName}(${primaryColumn.javaField}).then(response => { | |
| 305 | - this.form = response.data; | |
| 306 | - #foreach ($column in $columns) | |
| 307 | - #if($column.htmlType == "checkbox")## checkbox 特殊处理 | |
| 308 | - this.form.$column.javaField = this.form.${column.javaField}.split(","); | |
| 309 | - #end | |
| 310 | - #end | |
| 311 | - this.open = true; | |
| 312 | - this.title = "修改${table.classComment}"; | |
| 313 | - }); | |
| 314 | - }, | |
| 315 | - /** 提交按钮 */ | |
| 316 | - submitForm() { | |
| 317 | - this.#[[$]]#refs["form"].validate(valid => { | |
| 318 | - if (!valid) { | |
| 319 | - return; | |
| 320 | - } | |
| 321 | - #foreach ($column in $columns) | |
| 322 | - #if($column.htmlType == "checkbox") | |
| 323 | - this.form.$column.javaField = this.form.${column.javaField}.join(","); | |
| 324 | - #end | |
| 325 | - #end | |
| 326 | - // 修改的提交 | |
| 327 | - if (this.form.${primaryColumn.javaField} != null) { | |
| 328 | - update${simpleClassName}(this.form).then(response => { | |
| 329 | - this.#[[$modal]]#.msgSuccess("修改成功"); | |
| 330 | - this.open = false; | |
| 331 | - this.getList(); | |
| 332 | - }); | |
| 333 | - return; | |
| 334 | - } | |
| 335 | - // 添加的提交 | |
| 336 | - create${simpleClassName}(this.form).then(response => { | |
| 337 | - this.#[[$modal]]#.msgSuccess("新增成功"); | |
| 338 | - this.open = false; | |
| 339 | - this.getList(); | |
| 340 | - }); | |
| 341 | - }); | |
| 290 | + /** 添加/修改操作 */ | |
| 291 | + openForm(id) { | |
| 292 | + this.#[[$]]#refs["formRef"].open(id); | |
| 342 | 293 | }, |
| 343 | 294 | /** 删除按钮操作 */ |
| 344 | - handleDelete(row) { | |
| 295 | + async handleDelete(row) { | |
| 345 | 296 | const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; |
| 346 | - this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?').then(function() { | |
| 347 | - return delete${simpleClassName}(${primaryColumn.javaField}); | |
| 348 | - }).then(() => { | |
| 349 | - this.getList(); | |
| 350 | - this.#[[$modal]]#.msgSuccess("删除成功"); | |
| 351 | - }).catch(() => {}); | |
| 297 | + await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?') | |
| 298 | + try { | |
| 299 | + await ${simpleClassName}Api.delete${simpleClassName}(${primaryColumn.javaField}); | |
| 300 | + await this.getList(); | |
| 301 | + this.#[[$modal]]#.msgSuccess("删除成功"); | |
| 302 | + } catch {} | |
| 352 | 303 | }, |
| 353 | 304 | /** 导出按钮操作 */ |
| 354 | - handleExport() { | |
| 355 | - // 处理查询参数 | |
| 356 | - let params = {...this.queryParams}; | |
| 357 | - params.pageNo = undefined; | |
| 358 | - params.pageSize = undefined; | |
| 359 | - this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?').then(() => { | |
| 360 | - this.exportLoading = true; | |
| 361 | - return export${simpleClassName}Excel(params); | |
| 362 | - }).then(response => { | |
| 363 | - this.#[[$]]#download.excel(response, '${table.classComment}.xls'); | |
| 364 | - this.exportLoading = false; | |
| 365 | - }).catch(() => {}); | |
| 366 | - } | |
| 305 | + async handleExport() { | |
| 306 | + await this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?'); | |
| 307 | + try { | |
| 308 | + this.exportLoading = true; | |
| 309 | + const res = await ${simpleClassName}Api.export${simpleClassName}Excel(this.queryParams); | |
| 310 | + this.#[[$]]#download.excel(res.data, '${table.classComment}.xls'); | |
| 311 | + } catch { | |
| 312 | + } finally { | |
| 313 | + this.exportLoading = false; | |
| 314 | + } | |
| 315 | + }, | |
| 316 | + ## 特殊:主子表专属逻辑 | |
| 317 | + #if ( $table.templateType == 11 ) | |
| 318 | + /** 选中行操作 */ | |
| 319 | + handleCurrentChange(row) { | |
| 320 | + this.currentRow = row; | |
| 321 | + #if ( $subTables && $subTables.size() > 0 ) | |
| 322 | + /** 子表的列表 */ | |
| 323 | + this.subTabsName = '$subClassNameVars.get(0)'; | |
| 324 | + #end | |
| 325 | + }, | |
| 326 | + #end | |
| 327 | + ## 特殊:树表专属逻辑 | |
| 328 | + #if ( $table.templateType == 2 ) | |
| 329 | + /** 展开/折叠操作 */ | |
| 330 | + toggleExpandAll() { | |
| 331 | + this.refreshTable = false | |
| 332 | + this.isExpandAll = !this.isExpandAll | |
| 333 | + this.$nextTick(function () { | |
| 334 | + this.refreshTable = true | |
| 335 | + }) | |
| 336 | + } | |
| 337 | + #end | |
| 367 | 338 | } |
| 368 | 339 | }; |
| 369 | 340 | </script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.codegen.inner; | |
| 2 | + | |
| 3 | +import cn.hutool.core.io.FileUtil; | |
| 4 | +import cn.hutool.core.io.IoUtil; | |
| 5 | +import cn.hutool.core.io.resource.ResourceUtil; | |
| 6 | +import cn.hutool.core.map.MapUtil; | |
| 7 | +import cn.hutool.core.util.StrUtil; | |
| 8 | +import cn.hutool.core.util.ZipUtil; | |
| 9 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 10 | +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; | |
| 14 | +import org.junit.jupiter.api.BeforeEach; | |
| 15 | +import org.mockito.InjectMocks; | |
| 16 | +import org.mockito.Spy; | |
| 17 | + | |
| 18 | +import java.io.ByteArrayInputStream; | |
| 19 | +import java.io.ByteArrayOutputStream; | |
| 20 | +import java.util.ArrayList; | |
| 21 | +import java.util.HashMap; | |
| 22 | +import java.util.List; | |
| 23 | +import java.util.Map; | |
| 24 | + | |
| 25 | +import static org.junit.jupiter.api.Assertions.assertEquals; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * {@link CodegenEngine} 的单元测试抽象基类 | |
| 29 | + * | |
| 30 | + * @author 芋道源码 | |
| 31 | + */ | |
| 32 | +public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { | |
| 33 | + | |
| 34 | + @InjectMocks | |
| 35 | + protected CodegenEngine codegenEngine; | |
| 36 | + | |
| 37 | + @Spy | |
| 38 | + protected CodegenProperties codegenProperties = new CodegenProperties() | |
| 39 | + .setBasePackage("cn.iocoder.yudao"); | |
| 40 | + | |
| 41 | + @BeforeEach | |
| 42 | + public void setUp() { | |
| 43 | + codegenEngine.initGlobalBindingMap(); | |
| 44 | + } | |
| 45 | + | |
| 46 | + protected static CodegenTableDO getTable(String name) { | |
| 47 | + String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); | |
| 48 | + return JsonUtils.parseObject(content, "table", CodegenTableDO.class); | |
| 49 | + } | |
| 50 | + | |
| 51 | + protected static List<CodegenColumnDO> getColumnList(String name) { | |
| 52 | + String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); | |
| 53 | + List<CodegenColumnDO> list = JsonUtils.parseArray(content, "columns", CodegenColumnDO.class); | |
| 54 | + list.forEach(column -> { | |
| 55 | + if (column.getNullable() == null) { | |
| 56 | + column.setNullable(false); | |
| 57 | + } | |
| 58 | + if (column.getCreateOperation() == null) { | |
| 59 | + column.setCreateOperation(false); | |
| 60 | + } | |
| 61 | + if (column.getUpdateOperation() == null) { | |
| 62 | + column.setUpdateOperation(false); | |
| 63 | + } | |
| 64 | + if (column.getListOperation() == null) { | |
| 65 | + column.setListOperation(false); | |
| 66 | + } | |
| 67 | + if (column.getListOperationResult() == null) { | |
| 68 | + column.setListOperationResult(false); | |
| 69 | + } | |
| 70 | + }); | |
| 71 | + return list; | |
| 72 | + } | |
| 73 | + | |
| 74 | + @SuppressWarnings("rawtypes") | |
| 75 | + protected static void assertResult(Map<String, String> result, String path) { | |
| 76 | + String assertContent = ResourceUtil.readUtf8Str(path + "/assert.json"); | |
| 77 | + List<HashMap> asserts = JsonUtils.parseArray(assertContent, HashMap.class); | |
| 78 | + assertEquals(asserts.size(), result.size()); | |
| 79 | + // 校验每个文件 | |
| 80 | + asserts.forEach(assertMap -> { | |
| 81 | + String contentPath = (String) assertMap.get("contentPath"); | |
| 82 | + String filePath = (String) assertMap.get("filePath"); | |
| 83 | + String content = ResourceUtil.readUtf8Str(path + "/" + contentPath); | |
| 84 | + assertEquals(content, result.get(filePath), filePath + ":不匹配"); | |
| 85 | + }); | |
| 86 | + } | |
| 87 | + | |
| 88 | + // ==================== 调试专用 ==================== | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 【调试使用】将生成的代码,写入到文件 | |
| 92 | + * | |
| 93 | + * @param result 生成的代码 | |
| 94 | + * @param path 写入文件的路径 | |
| 95 | + */ | |
| 96 | + protected void writeFile(Map<String, String> result, String path) { | |
| 97 | + // 生成压缩包 | |
| 98 | + String[] paths = result.keySet().toArray(new String[0]); | |
| 99 | + ByteArrayInputStream[] ins = result.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); | |
| 100 | + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
| 101 | + ZipUtil.zip(outputStream, paths, ins); | |
| 102 | + // 写入文件 | |
| 103 | + FileUtil.writeBytes(outputStream.toByteArray(), path); | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * 【调试使用】将生成的结果,写入到文件 | |
| 108 | + * | |
| 109 | + * @param result 生成的代码 | |
| 110 | + * @param basePath 写入文件的路径(绝对路径) | |
| 111 | + */ | |
| 112 | + protected void writeResult(Map<String, String> result, String basePath) { | |
| 113 | + // 写入文件内容 | |
| 114 | + List<Map<String, String>> asserts = new ArrayList<>(); | |
| 115 | + result.forEach((filePath, fileContent) -> { | |
| 116 | + String lastFilePath = StrUtil.subAfter(filePath, '/', true); | |
| 117 | + String contentPath = StrUtil.subAfter(lastFilePath, '.', true) | |
| 118 | + + '/' + StrUtil.subBefore(lastFilePath, '.', true); | |
| 119 | + asserts.add(MapUtil.<String, String>builder().put("filePath", filePath) | |
| 120 | + .put("contentPath", contentPath).build()); | |
| 121 | + FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); | |
| 122 | + }); | |
| 123 | + // 写入 assert.json 文件 | |
| 124 | + FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath +"/assert.json"); | |
| 125 | + } | |
| 126 | + | |
| 127 | +} | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.codegen.inner; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; | |
| 4 | +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; | |
| 5 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; | |
| 6 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; | |
| 7 | +import org.junit.jupiter.api.Test; | |
| 8 | + | |
| 9 | +import java.util.Arrays; | |
| 10 | +import java.util.List; | |
| 11 | +import java.util.Map; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * {@link CodegenEngine} 的 Vue2 + Element UI 单元测试 | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +public class CodegenEngineVue2Test extends CodegenEngineAbstractTest { | |
| 19 | + | |
| 20 | + @Test | |
| 21 | + public void testExecute_vue2_one() { | |
| 22 | + // 准备参数 | |
| 23 | + CodegenTableDO table = getTable("student") | |
| 24 | + .setFrontType(CodegenFrontTypeEnum.VUE2.getType()) | |
| 25 | + .setTemplateType(CodegenTemplateTypeEnum.ONE.getType()); | |
| 26 | + List<CodegenColumnDO> columns = getColumnList("student"); | |
| 27 | + | |
| 28 | + // 调用 | |
| 29 | + Map<String, String> result = codegenEngine.execute(table, columns, null, null); | |
| 30 | + // 断言 | |
| 31 | + assertResult(result, "codegen/vue2_one"); | |
| 32 | +// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one"); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Test | |
| 36 | + public void testExecute_vue2_tree() { | |
| 37 | + // 准备参数 | |
| 38 | + CodegenTableDO table = getTable("category") | |
| 39 | + .setFrontType(CodegenFrontTypeEnum.VUE2.getType()) | |
| 40 | + .setTemplateType(CodegenTemplateTypeEnum.TREE.getType()); | |
| 41 | + List<CodegenColumnDO> columns = getColumnList("category"); | |
| 42 | + | |
| 43 | + // 调用 | |
| 44 | + Map<String, String> result = codegenEngine.execute(table, columns, null, null); | |
| 45 | + // 断言 | |
| 46 | + assertResult(result, "codegen/vue2_tree"); | |
| 47 | +// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_tree"); | |
| 48 | +// writeFile(result, "/Users/yunai/test/demo66.zip"); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Test | |
| 52 | + public void testExecute_vue2_master_normal() { | |
| 53 | + testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_NORMAL, "codegen/vue2_master_normal"); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @Test | |
| 57 | + public void testExecute_vue2_master_erp() { | |
| 58 | + testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_ERP, "codegen/vue2_master_erp"); | |
| 59 | + } | |
| 60 | + | |
| 61 | + @Test | |
| 62 | + public void testExecute_vue2_master_inner() { | |
| 63 | + testExecute_vue2_master(CodegenTemplateTypeEnum.MASTER_INNER, "codegen/vue2_master_inner"); | |
| 64 | + } | |
| 65 | + | |
| 66 | + private void testExecute_vue2_master(CodegenTemplateTypeEnum templateType, | |
| 67 | + String path) { | |
| 68 | + // 准备参数 | |
| 69 | + CodegenTableDO table = getTable("student") | |
| 70 | + .setFrontType(CodegenFrontTypeEnum.VUE2.getType()) | |
| 71 | + .setTemplateType(templateType.getType()); | |
| 72 | + List<CodegenColumnDO> columns = getColumnList("student"); | |
| 73 | + // 准备参数(子表) | |
| 74 | + CodegenTableDO contactTable = getTable("contact") | |
| 75 | + .setTemplateType(CodegenTemplateTypeEnum.SUB.getType()) | |
| 76 | + .setFrontType(CodegenFrontTypeEnum.VUE2.getType()) | |
| 77 | + .setSubJoinColumnId(100L).setSubJoinMany(true); | |
| 78 | + List<CodegenColumnDO> contactColumns = getColumnList("contact"); | |
| 79 | + // 准备参数(班主任) | |
| 80 | + CodegenTableDO teacherTable = getTable("teacher") | |
| 81 | + .setTemplateType(CodegenTemplateTypeEnum.SUB.getType()) | |
| 82 | + .setFrontType(CodegenFrontTypeEnum.VUE2.getType()) | |
| 83 | + .setSubJoinColumnId(200L).setSubJoinMany(false); | |
| 84 | + List<CodegenColumnDO> teacherColumns = getColumnList("teacher"); | |
| 85 | + | |
| 86 | + // 调用 | |
| 87 | + Map<String, String> result = codegenEngine.execute(table, columns, | |
| 88 | + Arrays.asList(contactTable, teacherTable), Arrays.asList(contactColumns, teacherColumns)); | |
| 89 | + // 断言 | |
| 90 | + assertResult(result, path); | |
| 91 | +// writeResult(result, "/root/ruoyi-vue-pro/yudao-module-infra/yudao-module-infra-biz/src/test/resources/" + path); | |
| 92 | +// writeFile(result, "/Users/yunai/test/demo11.zip"); | |
| 93 | + } | |
| 94 | + | |
| 95 | +} | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java renamed to yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java
| 1 | 1 | package cn.iocoder.yudao.module.infra.service.codegen.inner; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.io.FileUtil; | |
| 4 | -import cn.hutool.core.io.IoUtil; | |
| 5 | -import cn.hutool.core.io.resource.ResourceUtil; | |
| 6 | -import cn.hutool.core.map.MapUtil; | |
| 7 | -import cn.hutool.core.util.StrUtil; | |
| 8 | -import cn.hutool.core.util.ZipUtil; | |
| 9 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 10 | -import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | |
| 11 | 3 | import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; |
| 12 | 4 | import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; |
| 13 | -import cn.iocoder.yudao.module.infra.enums.codegen.*; | |
| 14 | -import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; | |
| 15 | -import org.apache.ibatis.type.JdbcType; | |
| 16 | -import org.junit.jupiter.api.BeforeEach; | |
| 5 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; | |
| 6 | +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; | |
| 17 | 7 | import org.junit.jupiter.api.Test; |
| 18 | -import org.mockito.InjectMocks; | |
| 19 | -import org.mockito.Spy; | |
| 20 | 8 | |
| 21 | -import java.io.ByteArrayInputStream; | |
| 22 | -import java.io.ByteArrayOutputStream; | |
| 23 | -import java.util.*; | |
| 24 | - | |
| 25 | -import static org.junit.jupiter.api.Assertions.assertEquals; | |
| 26 | -import static org.junit.jupiter.api.Assertions.assertTrue; | |
| 9 | +import java.util.Arrays; | |
| 10 | +import java.util.List; | |
| 11 | +import java.util.Map; | |
| 27 | 12 | |
| 28 | 13 | /** |
| 29 | - * {@link CodegenEngine} 的单元测试 | |
| 14 | + * {@link CodegenEngine} 的 Vue2 + Element Plus 单元测试 | |
| 30 | 15 | * |
| 31 | 16 | * @author 芋道源码 |
| 32 | 17 | */ |
| 33 | -public class CodegenEngineTest extends BaseMockitoUnitTest { | |
| 34 | - | |
| 35 | - @InjectMocks | |
| 36 | - private CodegenEngine codegenEngine; | |
| 37 | - | |
| 38 | - @Spy | |
| 39 | - private CodegenProperties codegenProperties = new CodegenProperties() | |
| 40 | - .setBasePackage("cn.iocoder.yudao"); | |
| 41 | - | |
| 42 | - @BeforeEach | |
| 43 | - public void setUp() { | |
| 44 | - codegenEngine.initGlobalBindingMap(); | |
| 45 | - } | |
| 18 | +public class CodegenEngineVue3Test extends CodegenEngineAbstractTest { | |
| 46 | 19 | |
| 47 | 20 | @Test |
| 48 | 21 | public void testExecute_vue3_one() { |
| ... | ... | @@ -119,85 +92,4 @@ public class CodegenEngineTest extends BaseMockitoUnitTest { |
| 119 | 92 | // writeFile(result, "/Users/yunai/test/demo11.zip"); |
| 120 | 93 | } |
| 121 | 94 | |
| 122 | - private static CodegenTableDO getTable(String name) { | |
| 123 | - String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); | |
| 124 | - return JsonUtils.parseObject(content, "table", CodegenTableDO.class); | |
| 125 | - } | |
| 126 | - | |
| 127 | - private static List<CodegenColumnDO> getColumnList(String name) { | |
| 128 | - String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); | |
| 129 | - List<CodegenColumnDO> list = JsonUtils.parseArray(content, "columns", CodegenColumnDO.class); | |
| 130 | - list.forEach(column -> { | |
| 131 | - if (column.getNullable() == null) { | |
| 132 | - column.setNullable(false); | |
| 133 | - } | |
| 134 | - if (column.getCreateOperation() == null) { | |
| 135 | - column.setCreateOperation(false); | |
| 136 | - } | |
| 137 | - if (column.getUpdateOperation() == null) { | |
| 138 | - column.setUpdateOperation(false); | |
| 139 | - } | |
| 140 | - if (column.getListOperation() == null) { | |
| 141 | - column.setListOperation(false); | |
| 142 | - } | |
| 143 | - if (column.getListOperationResult() == null) { | |
| 144 | - column.setListOperationResult(false); | |
| 145 | - } | |
| 146 | - }); | |
| 147 | - return list; | |
| 148 | - } | |
| 149 | - | |
| 150 | - @SuppressWarnings("rawtypes") | |
| 151 | - private static void assertResult(Map<String, String> result, String path) { | |
| 152 | - String assertContent = ResourceUtil.readUtf8Str(path + "/assert.json"); | |
| 153 | - List<HashMap> asserts = JsonUtils.parseArray(assertContent, HashMap.class); | |
| 154 | - assertEquals(asserts.size(), result.size()); | |
| 155 | - // 校验每个文件 | |
| 156 | - asserts.forEach(assertMap -> { | |
| 157 | - String contentPath = (String) assertMap.get("contentPath"); | |
| 158 | - String filePath = (String) assertMap.get("filePath"); | |
| 159 | - String content = ResourceUtil.readUtf8Str(path + "/" + contentPath); | |
| 160 | - assertEquals(content, result.get(filePath), filePath + ":不匹配"); | |
| 161 | - }); | |
| 162 | - } | |
| 163 | - | |
| 164 | - // ==================== 调试专用 ==================== | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * 【调试使用】将生成的代码,写入到文件 | |
| 168 | - * | |
| 169 | - * @param result 生成的代码 | |
| 170 | - * @param path 写入文件的路径 | |
| 171 | - */ | |
| 172 | - private void writeFile(Map<String, String> result, String path) { | |
| 173 | - // 生成压缩包 | |
| 174 | - String[] paths = result.keySet().toArray(new String[0]); | |
| 175 | - ByteArrayInputStream[] ins = result.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); | |
| 176 | - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
| 177 | - ZipUtil.zip(outputStream, paths, ins); | |
| 178 | - // 写入文件 | |
| 179 | - FileUtil.writeBytes(outputStream.toByteArray(), path); | |
| 180 | - } | |
| 181 | - | |
| 182 | - /** | |
| 183 | - * 【调试使用】将生成的结果,写入到文件 | |
| 184 | - * | |
| 185 | - * @param result 生成的代码 | |
| 186 | - * @param basePath 写入文件的路径(绝对路径) | |
| 187 | - */ | |
| 188 | - private void writeResult(Map<String, String> result, String basePath) { | |
| 189 | - // 写入文件内容 | |
| 190 | - List<Map<String, String>> asserts = new ArrayList<>(); | |
| 191 | - result.forEach((filePath, fileContent) -> { | |
| 192 | - String lastFilePath = StrUtil.subAfter(filePath, '/', true); | |
| 193 | - String contentPath = StrUtil.subAfter(lastFilePath, '.', true) | |
| 194 | - + '/' + StrUtil.subBefore(lastFilePath, '.', true); | |
| 195 | - asserts.add(MapUtil.<String, String>builder().put("filePath", filePath) | |
| 196 | - .put("contentPath", contentPath).build()); | |
| 197 | - FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); | |
| 198 | - }); | |
| 199 | - // 写入 assert.json 文件 | |
| 200 | - FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath +"/assert.json"); | |
| 201 | - } | |
| 202 | - | |
| 203 | 95 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentContactDO", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentContactDO.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "java/InfraStudentTeacherDO", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentTeacherDO.java" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentMapper", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentContactMapper", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentContactMapper.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentTeacherMapper", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentTeacherMapper.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "xml/InfraStudentMapper", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 36 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "java/InfraStudentService", | |
| 39 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 42 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 45 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "sql/sql", | |
| 48 | + "filePath" : "sql/sql.sql" | |
| 49 | +}, { | |
| 50 | + "contentPath" : "sql/h2", | |
| 51 | + "filePath" : "sql/h2.sql" | |
| 52 | +}, { | |
| 53 | + "contentPath" : "vue/index", | |
| 54 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 55 | +}, { | |
| 56 | + "contentPath" : "js/student", | |
| 57 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 58 | +}, { | |
| 59 | + "contentPath" : "vue/StudentForm", | |
| 60 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 61 | +}, { | |
| 62 | + "contentPath" : "vue/StudentContactForm", | |
| 63 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactForm.vue" | |
| 64 | +}, { | |
| 65 | + "contentPath" : "vue/StudentTeacherForm", | |
| 66 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherForm.vue" | |
| 67 | +}, { | |
| 68 | + "contentPath" : "vue/StudentContactList", | |
| 69 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactList.vue" | |
| 70 | +}, { | |
| 71 | + "contentPath" : "vue/StudentTeacherList", | |
| 72 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherList.vue" | |
| 73 | +} ] | |
| 0 | 74 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/ErrorCodeConstants_手动操作
0 → 100644
| 1 | +// TODO 待办:请将下面的错误码复制到 yudao-module-infra-api 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! | |
| 2 | +// ========== 学生 TODO 补充编号 ========== | |
| 3 | +ErrorCode STUDENT_NOT_EXISTS = new ErrorCode(TODO 补充编号, "学生不存在"); | |
| 4 | +ErrorCode STUDENT_CONTACT_NOT_EXISTS = new ErrorCode(TODO 补充编号, "学生联系人不存在"); | |
| 5 | +ErrorCode STUDENT_TEACHER_NOT_EXISTS = new ErrorCode(TODO 补充编号, "学生班主任不存在"); | |
| 6 | +ErrorCode STUDENT_TEACHER_EXISTS = new ErrorCode(TODO 补充编号, "学生班主任已存在"); | |
| 0 | 7 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentContactDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生联系人 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_contact") | |
| 16 | +@KeySequence("infra_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentContactDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentContactMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生联系人 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentContactMapper extends BaseMapperX<InfraStudentContactDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentContactDO> selectPage(PageParam reqVO, Long studentId) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentContactDO>() | |
| 22 | + .eq(InfraStudentContactDO::getStudentId, studentId) | |
| 23 | + .orderByDesc(InfraStudentContactDO::getId)); | |
| 24 | + } | |
| 25 | + | |
| 26 | + default int deleteByStudentId(Long studentId) { | |
| 27 | + return delete(InfraStudentContactDO::getStudentId, studentId); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 32 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 学生") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/infra/student") | |
| 37 | +@Validated | |
| 38 | +public class InfraStudentController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private InfraStudentService studentService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建学生") | |
| 45 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 46 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 47 | + return success(studentService.createStudent(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新学生") | |
| 52 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 53 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 54 | + studentService.updateStudent(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除学生") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 62 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 63 | + studentService.deleteStudent(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得学生") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 71 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 72 | + InfraStudentDO student = studentService.getStudent(id); | |
| 73 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得学生分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 79 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 80 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 81 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/export-excel") | |
| 85 | + @Operation(summary = "导出学生 Excel") | |
| 86 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 87 | + @OperateLog(type = EXPORT) | |
| 88 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 89 | + HttpServletResponse response) throws IOException { | |
| 90 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 91 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 92 | + // 导出 Excel | |
| 93 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 94 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @GetMapping("/student-contact/page") | |
| 100 | + @Operation(summary = "获得学生联系人分页") | |
| 101 | + @Parameter(name = "studentId", description = "学生编号") | |
| 102 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 103 | + public CommonResult<PageResult<InfraStudentContactDO>> getStudentContactPage(PageParam pageReqVO, | |
| 104 | + @RequestParam("studentId") Long studentId) { | |
| 105 | + return success(studentService.getStudentContactPage(pageReqVO, studentId)); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @PostMapping("/student-contact/create") | |
| 109 | + @Operation(summary = "创建学生联系人") | |
| 110 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 111 | + public CommonResult<Long> createStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) { | |
| 112 | + return success(studentService.createStudentContact(studentContact)); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @PutMapping("/student-contact/update") | |
| 116 | + @Operation(summary = "更新学生联系人") | |
| 117 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 118 | + public CommonResult<Boolean> updateStudentContact(@Valid @RequestBody InfraStudentContactDO studentContact) { | |
| 119 | + studentService.updateStudentContact(studentContact); | |
| 120 | + return success(true); | |
| 121 | + } | |
| 122 | + | |
| 123 | + @DeleteMapping("/student-contact/delete") | |
| 124 | + @Parameter(name = "id", description = "编号", required = true) | |
| 125 | + @Operation(summary = "删除学生联系人") | |
| 126 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 127 | + public CommonResult<Boolean> deleteStudentContact(@RequestParam("id") Long id) { | |
| 128 | + studentService.deleteStudentContact(id); | |
| 129 | + return success(true); | |
| 130 | + } | |
| 131 | + | |
| 132 | + @GetMapping("/student-contact/get") | |
| 133 | + @Operation(summary = "获得学生联系人") | |
| 134 | + @Parameter(name = "id", description = "编号", required = true) | |
| 135 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 136 | + public CommonResult<InfraStudentContactDO> getStudentContact(@RequestParam("id") Long id) { | |
| 137 | + return success(studentService.getStudentContact(id)); | |
| 138 | + } | |
| 139 | + | |
| 140 | + // ==================== 子表(学生班主任) ==================== | |
| 141 | + | |
| 142 | + @GetMapping("/student-teacher/page") | |
| 143 | + @Operation(summary = "获得学生班主任分页") | |
| 144 | + @Parameter(name = "studentId", description = "学生编号") | |
| 145 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 146 | + public CommonResult<PageResult<InfraStudentTeacherDO>> getStudentTeacherPage(PageParam pageReqVO, | |
| 147 | + @RequestParam("studentId") Long studentId) { | |
| 148 | + return success(studentService.getStudentTeacherPage(pageReqVO, studentId)); | |
| 149 | + } | |
| 150 | + | |
| 151 | + @PostMapping("/student-teacher/create") | |
| 152 | + @Operation(summary = "创建学生班主任") | |
| 153 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 154 | + public CommonResult<Long> createStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) { | |
| 155 | + return success(studentService.createStudentTeacher(studentTeacher)); | |
| 156 | + } | |
| 157 | + | |
| 158 | + @PutMapping("/student-teacher/update") | |
| 159 | + @Operation(summary = "更新学生班主任") | |
| 160 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 161 | + public CommonResult<Boolean> updateStudentTeacher(@Valid @RequestBody InfraStudentTeacherDO studentTeacher) { | |
| 162 | + studentService.updateStudentTeacher(studentTeacher); | |
| 163 | + return success(true); | |
| 164 | + } | |
| 165 | + | |
| 166 | + @DeleteMapping("/student-teacher/delete") | |
| 167 | + @Parameter(name = "id", description = "编号", required = true) | |
| 168 | + @Operation(summary = "删除学生班主任") | |
| 169 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 170 | + public CommonResult<Boolean> deleteStudentTeacher(@RequestParam("id") Long id) { | |
| 171 | + studentService.deleteStudentTeacher(id); | |
| 172 | + return success(true); | |
| 173 | + } | |
| 174 | + | |
| 175 | + @GetMapping("/student-teacher/get") | |
| 176 | + @Operation(summary = "获得学生班主任") | |
| 177 | + @Parameter(name = "id", description = "编号", required = true) | |
| 178 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 179 | + public CommonResult<InfraStudentTeacherDO> getStudentTeacher(@RequestParam("id") Long id) { | |
| 180 | + return success(studentService.getStudentTeacher(id)); | |
| 181 | + } | |
| 182 | + | |
| 183 | +} | |
| 0 | 184 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class InfraStudentSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 25 | + @NotEmpty(message = "简介不能为空") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "性别不能为空") | |
| 34 | + private Integer sex; | |
| 35 | + | |
| 36 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 37 | + @NotNull(message = "是否有效不能为空") | |
| 38 | + private Boolean enabled; | |
| 39 | + | |
| 40 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 41 | + @NotEmpty(message = "头像不能为空") | |
| 42 | + private String avatar; | |
| 43 | + | |
| 44 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 45 | + @NotEmpty(message = "附件不能为空") | |
| 46 | + private String video; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 49 | + @NotEmpty(message = "备注不能为空") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | +} | |
| 0 | 53 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Service 接口 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +public interface InfraStudentService { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 创建学生 | |
| 21 | + * | |
| 22 | + * @param createReqVO 创建信息 | |
| 23 | + * @return 编号 | |
| 24 | + */ | |
| 25 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 更新学生 | |
| 29 | + * | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除学生 | |
| 36 | + * | |
| 37 | + * @param id 编号 | |
| 38 | + */ | |
| 39 | + void deleteStudent(Long id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获得学生 | |
| 43 | + * | |
| 44 | + * @param id 编号 | |
| 45 | + * @return 学生 | |
| 46 | + */ | |
| 47 | + InfraStudentDO getStudent(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生分页 | |
| 51 | + * | |
| 52 | + * @param pageReqVO 分页查询 | |
| 53 | + * @return 学生分页 | |
| 54 | + */ | |
| 55 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 56 | + | |
| 57 | + // ==================== 子表(学生联系人) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生联系人分页 | |
| 61 | + * | |
| 62 | + * @param pageReqVO 分页查询 | |
| 63 | + * @param studentId 学生编号 | |
| 64 | + * @return 学生联系人分页 | |
| 65 | + */ | |
| 66 | + PageResult<InfraStudentContactDO> getStudentContactPage(PageParam pageReqVO, Long studentId); | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 创建学生联系人 | |
| 70 | + * | |
| 71 | + * @param studentContact 创建信息 | |
| 72 | + * @return 编号 | |
| 73 | + */ | |
| 74 | + Long createStudentContact(@Valid InfraStudentContactDO studentContact); | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 更新学生联系人 | |
| 78 | + * | |
| 79 | + * @param studentContact 更新信息 | |
| 80 | + */ | |
| 81 | + void updateStudentContact(@Valid InfraStudentContactDO studentContact); | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * 删除学生联系人 | |
| 85 | + * | |
| 86 | + * @param id 编号 | |
| 87 | + */ | |
| 88 | + void deleteStudentContact(Long id); | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * 获得学生联系人 | |
| 92 | + * | |
| 93 | + * @param id 编号 | |
| 94 | + * @return 学生联系人 | |
| 95 | + */ | |
| 96 | + InfraStudentContactDO getStudentContact(Long id); | |
| 97 | + | |
| 98 | + // ==================== 子表(学生班主任) ==================== | |
| 99 | + | |
| 100 | + /** | |
| 101 | + * 获得学生班主任分页 | |
| 102 | + * | |
| 103 | + * @param pageReqVO 分页查询 | |
| 104 | + * @param studentId 学生编号 | |
| 105 | + * @return 学生班主任分页 | |
| 106 | + */ | |
| 107 | + PageResult<InfraStudentTeacherDO> getStudentTeacherPage(PageParam pageReqVO, Long studentId); | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * 创建学生班主任 | |
| 111 | + * | |
| 112 | + * @param studentTeacher 创建信息 | |
| 113 | + * @return 编号 | |
| 114 | + */ | |
| 115 | + Long createStudentTeacher(@Valid InfraStudentTeacherDO studentTeacher); | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * 更新学生班主任 | |
| 119 | + * | |
| 120 | + * @param studentTeacher 更新信息 | |
| 121 | + */ | |
| 122 | + void updateStudentTeacher(@Valid InfraStudentTeacherDO studentTeacher); | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * 删除学生班主任 | |
| 126 | + * | |
| 127 | + * @param id 编号 | |
| 128 | + */ | |
| 129 | + void deleteStudentTeacher(Long id); | |
| 130 | + | |
| 131 | + /** | |
| 132 | + * 获得学生班主任 | |
| 133 | + * | |
| 134 | + * @param id 编号 | |
| 135 | + * @return 学生班主任 | |
| 136 | + */ | |
| 137 | + InfraStudentTeacherDO getStudentTeacher(Long id); | |
| 138 | + | |
| 139 | +} | |
| 0 | 140 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 15 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentContactMapper; | |
| 19 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentTeacherMapper; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private InfraStudentMapper studentMapper; | |
| 35 | + @Resource | |
| 36 | + private InfraStudentContactMapper studentContactMapper; | |
| 37 | + @Resource | |
| 38 | + private InfraStudentTeacherMapper studentTeacherMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 42 | + // 插入 | |
| 43 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 44 | + studentMapper.insert(student); | |
| 45 | + // 返回 | |
| 46 | + return student.getId(); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 51 | + // 校验存在 | |
| 52 | + validateStudentExists(updateReqVO.getId()); | |
| 53 | + // 更新 | |
| 54 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 55 | + studentMapper.updateById(updateObj); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @Override | |
| 59 | + @Transactional(rollbackFor = Exception.class) | |
| 60 | + public void deleteStudent(Long id) { | |
| 61 | + // 校验存在 | |
| 62 | + validateStudentExists(id); | |
| 63 | + // 删除 | |
| 64 | + studentMapper.deleteById(id); | |
| 65 | + | |
| 66 | + // 删除子表 | |
| 67 | + deleteStudentContactByStudentId(id); | |
| 68 | + deleteStudentTeacherByStudentId(id); | |
| 69 | + } | |
| 70 | + | |
| 71 | + private void validateStudentExists(Long id) { | |
| 72 | + if (studentMapper.selectById(id) == null) { | |
| 73 | + throw exception(STUDENT_NOT_EXISTS); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 77 | + @Override | |
| 78 | + public InfraStudentDO getStudent(Long id) { | |
| 79 | + return studentMapper.selectById(id); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Override | |
| 83 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 84 | + return studentMapper.selectPage(pageReqVO); | |
| 85 | + } | |
| 86 | + | |
| 87 | + // ==================== 子表(学生联系人) ==================== | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public PageResult<InfraStudentContactDO> getStudentContactPage(PageParam pageReqVO, Long studentId) { | |
| 91 | + return studentContactMapper.selectPage(pageReqVO, studentId); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @Override | |
| 95 | + public Long createStudentContact(InfraStudentContactDO studentContact) { | |
| 96 | + studentContactMapper.insert(studentContact); | |
| 97 | + return studentContact.getId(); | |
| 98 | + } | |
| 99 | + | |
| 100 | + @Override | |
| 101 | + public void updateStudentContact(InfraStudentContactDO studentContact) { | |
| 102 | + // 校验存在 | |
| 103 | + validateStudentContactExists(studentContact.getId()); | |
| 104 | + // 更新 | |
| 105 | + studentContactMapper.updateById(studentContact); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Override | |
| 109 | + public void deleteStudentContact(Long id) { | |
| 110 | + // 校验存在 | |
| 111 | + validateStudentContactExists(id); | |
| 112 | + // 删除 | |
| 113 | + studentContactMapper.deleteById(id); | |
| 114 | + } | |
| 115 | + | |
| 116 | + @Override | |
| 117 | + public InfraStudentContactDO getStudentContact(Long id) { | |
| 118 | + return studentContactMapper.selectById(id); | |
| 119 | + } | |
| 120 | + | |
| 121 | + private void validateStudentContactExists(Long id) { | |
| 122 | + if (studentContactMapper.selectById(id) == null) { | |
| 123 | + throw exception(STUDENT_CONTACT_NOT_EXISTS); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + private void deleteStudentContactByStudentId(Long studentId) { | |
| 128 | + studentContactMapper.deleteByStudentId(studentId); | |
| 129 | + } | |
| 130 | + | |
| 131 | + // ==================== 子表(学生班主任) ==================== | |
| 132 | + | |
| 133 | + @Override | |
| 134 | + public PageResult<InfraStudentTeacherDO> getStudentTeacherPage(PageParam pageReqVO, Long studentId) { | |
| 135 | + return studentTeacherMapper.selectPage(pageReqVO, studentId); | |
| 136 | + } | |
| 137 | + | |
| 138 | + @Override | |
| 139 | + public Long createStudentTeacher(InfraStudentTeacherDO studentTeacher) { | |
| 140 | + // 校验是否已经存在 | |
| 141 | + if (studentTeacherMapper.selectByStudentId(studentTeacher.getStudentId()) != null) { | |
| 142 | + throw exception(STUDENT_TEACHER_EXISTS); | |
| 143 | + } | |
| 144 | + // 插入 | |
| 145 | + studentTeacherMapper.insert(studentTeacher); | |
| 146 | + return studentTeacher.getId(); | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Override | |
| 150 | + public void updateStudentTeacher(InfraStudentTeacherDO studentTeacher) { | |
| 151 | + // 校验存在 | |
| 152 | + validateStudentTeacherExists(studentTeacher.getId()); | |
| 153 | + // 更新 | |
| 154 | + studentTeacherMapper.updateById(studentTeacher); | |
| 155 | + } | |
| 156 | + | |
| 157 | + @Override | |
| 158 | + public void deleteStudentTeacher(Long id) { | |
| 159 | + // 校验存在 | |
| 160 | + validateStudentTeacherExists(id); | |
| 161 | + // 删除 | |
| 162 | + studentTeacherMapper.deleteById(id); | |
| 163 | + } | |
| 164 | + | |
| 165 | + @Override | |
| 166 | + public InfraStudentTeacherDO getStudentTeacher(Long id) { | |
| 167 | + return studentTeacherMapper.selectById(id); | |
| 168 | + } | |
| 169 | + | |
| 170 | + private void validateStudentTeacherExists(Long id) { | |
| 171 | + if (studentTeacherMapper.selectById(id) == null) { | |
| 172 | + throw exception(STUDENT_TEACHER_NOT_EXISTS); | |
| 173 | + } | |
| 174 | + } | |
| 175 | + | |
| 176 | + private void deleteStudentTeacherByStudentId(Long studentId) { | |
| 177 | + studentTeacherMapper.deleteByStudentId(studentId); | |
| 178 | + } | |
| 179 | + | |
| 180 | +} | |
| 0 | 181 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentTeacherDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班主任 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_teacher") | |
| 16 | +@KeySequence("infra_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentTeacherDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/java/InfraStudentTeacherMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生班主任 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentTeacherMapper extends BaseMapperX<InfraStudentTeacherDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentTeacherDO> selectPage(PageParam reqVO, Long studentId) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentTeacherDO>() | |
| 22 | + .eq(InfraStudentTeacherDO::getStudentId, studentId) | |
| 23 | + .orderByDesc(InfraStudentTeacherDO::getId)); | |
| 24 | + } | |
| 25 | + | |
| 26 | + default int deleteByStudentId(Long studentId) { | |
| 27 | + return delete(InfraStudentTeacherDO::getStudentId, studentId); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ==================== 子表(学生联系人) ==================== | |
| 56 | + | |
| 57 | + // 获得学生联系人分页 | |
| 58 | + export function getStudentContactPage(params) { | |
| 59 | + return request({ | |
| 60 | + url: '/infra/student/student-contact/page', | |
| 61 | + method: 'get', | |
| 62 | + params | |
| 63 | + }) | |
| 64 | + } | |
| 65 | + // 新增学生联系人 | |
| 66 | + export function createStudentContact(data) { | |
| 67 | + return request({ | |
| 68 | + url: `/infra/student/student-contact/create`, | |
| 69 | + method: 'post', | |
| 70 | + data | |
| 71 | + }) | |
| 72 | + } | |
| 73 | + | |
| 74 | + // 修改学生联系人 | |
| 75 | + export function updateStudentContact(data) { | |
| 76 | + return request({ | |
| 77 | + url: `/infra/student/student-contact/update`, | |
| 78 | + method: 'post', | |
| 79 | + data | |
| 80 | + }) | |
| 81 | + } | |
| 82 | + | |
| 83 | + // 删除学生联系人 | |
| 84 | + export function deleteStudentContact(id) { | |
| 85 | + return request({ | |
| 86 | + url: `/infra/student/student-contact/delete?id=` + id, | |
| 87 | + method: 'delete' | |
| 88 | + }) | |
| 89 | + } | |
| 90 | + | |
| 91 | + // 获得学生联系人 | |
| 92 | + export function getStudentContact(id) { | |
| 93 | + return request({ | |
| 94 | + url: `/infra/student/student-contact/get?id=` + id, | |
| 95 | + method: 'get' | |
| 96 | + }) | |
| 97 | + } | |
| 98 | + | |
| 99 | +// ==================== 子表(学生班主任) ==================== | |
| 100 | + | |
| 101 | + // 获得学生班主任分页 | |
| 102 | + export function getStudentTeacherPage(params) { | |
| 103 | + return request({ | |
| 104 | + url: '/infra/student/student-teacher/page', | |
| 105 | + method: 'get', | |
| 106 | + params | |
| 107 | + }) | |
| 108 | + } | |
| 109 | + // 新增学生班主任 | |
| 110 | + export function createStudentTeacher(data) { | |
| 111 | + return request({ | |
| 112 | + url: `/infra/student/student-teacher/create`, | |
| 113 | + method: 'post', | |
| 114 | + data | |
| 115 | + }) | |
| 116 | + } | |
| 117 | + | |
| 118 | + // 修改学生班主任 | |
| 119 | + export function updateStudentTeacher(data) { | |
| 120 | + return request({ | |
| 121 | + url: `/infra/student/student-teacher/update`, | |
| 122 | + method: 'post', | |
| 123 | + data | |
| 124 | + }) | |
| 125 | + } | |
| 126 | + | |
| 127 | + // 删除学生班主任 | |
| 128 | + export function deleteStudentTeacher(id) { | |
| 129 | + return request({ | |
| 130 | + url: `/infra/student/student-teacher/delete?id=` + id, | |
| 131 | + method: 'delete' | |
| 132 | + }) | |
| 133 | + } | |
| 134 | + | |
| 135 | + // 获得学生班主任 | |
| 136 | + export function getStudentTeacher(id) { | |
| 137 | + return request({ | |
| 138 | + url: `/infra/student/student-teacher/get?id=` + id, | |
| 139 | + method: 'get' | |
| 140 | + }) | |
| 141 | + } | |
| 0 | 142 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentContactForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像" prop="avatar"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件" prop="video"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注" prop="memo"> | |
| 34 | + <editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo'; | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentContactForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + studentId: undefined, | |
| 69 | + name: undefined, | |
| 70 | + description: undefined, | |
| 71 | + birthday: undefined, | |
| 72 | + sex: undefined, | |
| 73 | + enabled: undefined, | |
| 74 | + avatar: undefined, | |
| 75 | + video: undefined, | |
| 76 | + memo: undefined, | |
| 77 | + }, | |
| 78 | + // 表单校验 | |
| 79 | + formRules: { | |
| 80 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 81 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 82 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 83 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 84 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 85 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 86 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 87 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 88 | + }, | |
| 89 | + }; | |
| 90 | + }, | |
| 91 | + methods: { | |
| 92 | + /** 打开弹窗 */ | |
| 93 | + async open(id, studentId) { | |
| 94 | + this.dialogVisible = true; | |
| 95 | + this.reset(); | |
| 96 | + this.formData.studentId = studentId; | |
| 97 | + // 修改时,设置数据 | |
| 98 | + if (id) { | |
| 99 | + this.formLoading = true; | |
| 100 | + try { | |
| 101 | + const res = await StudentApi.getStudentContact(id); | |
| 102 | + this.formData = res.data; | |
| 103 | + this.dialogTitle = "修改学生联系人"; | |
| 104 | + } finally { | |
| 105 | + this.formLoading = false; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + this.dialogTitle = "新增学生联系人"; | |
| 109 | + }, | |
| 110 | + /** 提交按钮 */ | |
| 111 | + async submitForm() { | |
| 112 | + await this.$refs["formRef"].validate(); | |
| 113 | + this.formLoading = true; | |
| 114 | + try { | |
| 115 | + const data = this.formData; | |
| 116 | + // 修改的提交 | |
| 117 | + if (data.id) { | |
| 118 | + await StudentApi.updateStudentContact(data); | |
| 119 | + this.$modal.msgSuccess("修改成功"); | |
| 120 | + this.dialogVisible = false; | |
| 121 | + this.$emit('success'); | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + // 添加的提交 | |
| 125 | + await StudentApi.createStudentContact(data); | |
| 126 | + this.$modal.msgSuccess("新增成功"); | |
| 127 | + this.dialogVisible = false; | |
| 128 | + this.$emit('success'); | |
| 129 | + }finally { | |
| 130 | + this.formLoading = false; | |
| 131 | + } | |
| 132 | + }, | |
| 133 | + /** 表单重置 */ | |
| 134 | + reset() { | |
| 135 | + this.formData = { | |
| 136 | + id: undefined, | |
| 137 | + studentId: undefined, | |
| 138 | + name: undefined, | |
| 139 | + description: undefined, | |
| 140 | + birthday: undefined, | |
| 141 | + sex: undefined, | |
| 142 | + enabled: undefined, | |
| 143 | + avatar: undefined, | |
| 144 | + video: undefined, | |
| 145 | + memo: undefined, | |
| 146 | + }; | |
| 147 | + this.resetForm("formRef"); | |
| 148 | + }, | |
| 149 | + } | |
| 150 | + }; | |
| 151 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentContactList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 操作工具栏 --> | |
| 4 | + <el-row :gutter="10" class="mb8"> | |
| 5 | + <el-col :span="1.5"> | |
| 6 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 7 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 8 | + </el-col> | |
| 9 | + </el-row> | |
| 10 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 11 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 12 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 13 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 14 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 15 | + <template v-slot="scope"> | |
| 16 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 17 | + </template> | |
| 18 | + </el-table-column> | |
| 19 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 20 | + <template v-slot="scope"> | |
| 21 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 22 | + </template> | |
| 23 | + </el-table-column> | |
| 24 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 25 | + <template v-slot="scope"> | |
| 26 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 27 | + </template> | |
| 28 | + </el-table-column> | |
| 29 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 30 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 31 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 32 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 33 | + <template v-slot="scope"> | |
| 34 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 35 | + </template> | |
| 36 | + </el-table-column> | |
| 37 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 38 | + <template v-slot="scope"> | |
| 39 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 40 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 41 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 42 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 43 | + </template> | |
| 44 | + </el-table-column> | |
| 45 | + </el-table> | |
| 46 | + <!-- 分页组件 --> | |
| 47 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 48 | + @pagination="getList"/> | |
| 49 | + <!-- 对话框(添加 / 修改) --> | |
| 50 | + <StudentContactForm ref="formRef" @success="getList" /> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo'; | |
| 56 | + import StudentContactForm from './StudentContactForm.vue'; | |
| 57 | + export default { | |
| 58 | + name: "StudentContactList", | |
| 59 | + components: { | |
| 60 | + StudentContactForm | |
| 61 | + }, | |
| 62 | + props:[ | |
| 63 | + 'studentId' | |
| 64 | + ],// 学生编号(主表的关联字段) | |
| 65 | + data() { | |
| 66 | + return { | |
| 67 | + // 遮罩层 | |
| 68 | + loading: true, | |
| 69 | + // 列表的数据 | |
| 70 | + list: [], | |
| 71 | + // 列表的总页数 | |
| 72 | + total: 0, | |
| 73 | + // 查询参数 | |
| 74 | + queryParams: { | |
| 75 | + pageNo: 1, | |
| 76 | + pageSize: 10, | |
| 77 | + studentId: undefined | |
| 78 | + } | |
| 79 | + }; | |
| 80 | + }, | |
| 81 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 82 | + studentId:{ | |
| 83 | + handler(val) { | |
| 84 | + this.queryParams.studentId = val; | |
| 85 | + if (val){ | |
| 86 | + this.handleQuery(); | |
| 87 | + } | |
| 88 | + }, | |
| 89 | + immediate: true | |
| 90 | + } | |
| 91 | + }, | |
| 92 | + methods: { | |
| 93 | + /** 查询列表 */ | |
| 94 | + async getList() { | |
| 95 | + try { | |
| 96 | + this.loading = true; | |
| 97 | + const res = await StudentApi.getStudentContactPage(this.queryParams); | |
| 98 | + this.list = res.data.list; | |
| 99 | + this.total = res.data.total; | |
| 100 | + } finally { | |
| 101 | + this.loading = false; | |
| 102 | + } | |
| 103 | + }, | |
| 104 | + /** 搜索按钮操作 */ | |
| 105 | + handleQuery() { | |
| 106 | + this.queryParams.pageNo = 1; | |
| 107 | + this.getList(); | |
| 108 | + }, | |
| 109 | + /** 添加/修改操作 */ | |
| 110 | + openForm(id) { | |
| 111 | + if (!this.studentId) { | |
| 112 | + this.$modal.msgError('请选择一个学生'); | |
| 113 | + return; | |
| 114 | + } | |
| 115 | + this.$refs["formRef"].open(id, this.studentId); | |
| 116 | + }, | |
| 117 | + /** 删除按钮操作 */ | |
| 118 | + async handleDelete(row) { | |
| 119 | + const id = row.id; | |
| 120 | + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?'); | |
| 121 | + try { | |
| 122 | + await StudentApi.deleteStudentContact(id); | |
| 123 | + await this.getList(); | |
| 124 | + this.$modal.msgSuccess("删除成功"); | |
| 125 | + } catch {} | |
| 126 | + }, | |
| 127 | + } | |
| 128 | + }; | |
| 129 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo'; | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + name: undefined, | |
| 69 | + description: undefined, | |
| 70 | + birthday: undefined, | |
| 71 | + sex: undefined, | |
| 72 | + enabled: undefined, | |
| 73 | + avatar: undefined, | |
| 74 | + video: undefined, | |
| 75 | + memo: undefined, | |
| 76 | + }, | |
| 77 | + // 表单校验 | |
| 78 | + formRules: { | |
| 79 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 80 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 81 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 82 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 83 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 84 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 85 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 86 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 87 | + }, | |
| 88 | + }; | |
| 89 | + }, | |
| 90 | + methods: { | |
| 91 | + /** 打开弹窗 */ | |
| 92 | + async open(id) { | |
| 93 | + this.dialogVisible = true; | |
| 94 | + this.reset(); | |
| 95 | + // 修改时,设置数据 | |
| 96 | + if (id) { | |
| 97 | + this.formLoading = true; | |
| 98 | + try { | |
| 99 | + const res = await StudentApi.getStudent(id); | |
| 100 | + this.formData = res.data; | |
| 101 | + this.title = "修改学生"; | |
| 102 | + } finally { | |
| 103 | + this.formLoading = false; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + this.title = "新增学生"; | |
| 107 | + }, | |
| 108 | + /** 提交按钮 */ | |
| 109 | + async submitForm() { | |
| 110 | + // 校验主表 | |
| 111 | + await this.$refs["formRef"].validate(); | |
| 112 | + this.formLoading = true; | |
| 113 | + try { | |
| 114 | + const data = this.formData; | |
| 115 | + // 修改的提交 | |
| 116 | + if (data.id) { | |
| 117 | + await StudentApi.updateStudent(data); | |
| 118 | + this.$modal.msgSuccess("修改成功"); | |
| 119 | + this.dialogVisible = false; | |
| 120 | + this.$emit('success'); | |
| 121 | + return; | |
| 122 | + } | |
| 123 | + // 添加的提交 | |
| 124 | + await StudentApi.createStudent(data); | |
| 125 | + this.$modal.msgSuccess("新增成功"); | |
| 126 | + this.dialogVisible = false; | |
| 127 | + this.$emit('success'); | |
| 128 | + } finally { | |
| 129 | + this.formLoading = false; | |
| 130 | + } | |
| 131 | + }, | |
| 132 | + /** 表单重置 */ | |
| 133 | + reset() { | |
| 134 | + this.formData = { | |
| 135 | + id: undefined, | |
| 136 | + name: undefined, | |
| 137 | + description: undefined, | |
| 138 | + birthday: undefined, | |
| 139 | + sex: undefined, | |
| 140 | + enabled: undefined, | |
| 141 | + avatar: undefined, | |
| 142 | + video: undefined, | |
| 143 | + memo: undefined, | |
| 144 | + }; | |
| 145 | + this.resetForm("formRef"); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + }; | |
| 149 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentTeacherForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像" prop="avatar"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件" prop="video"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注" prop="memo"> | |
| 34 | + <editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo'; | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentTeacherForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + studentId: undefined, | |
| 69 | + name: undefined, | |
| 70 | + description: undefined, | |
| 71 | + birthday: undefined, | |
| 72 | + sex: undefined, | |
| 73 | + enabled: undefined, | |
| 74 | + avatar: undefined, | |
| 75 | + video: undefined, | |
| 76 | + memo: undefined, | |
| 77 | + }, | |
| 78 | + // 表单校验 | |
| 79 | + formRules: { | |
| 80 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 81 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 82 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 83 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 84 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 85 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 86 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 87 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 88 | + }, | |
| 89 | + }; | |
| 90 | + }, | |
| 91 | + methods: { | |
| 92 | + /** 打开弹窗 */ | |
| 93 | + async open(id, studentId) { | |
| 94 | + this.dialogVisible = true; | |
| 95 | + this.reset(); | |
| 96 | + this.formData.studentId = studentId; | |
| 97 | + // 修改时,设置数据 | |
| 98 | + if (id) { | |
| 99 | + this.formLoading = true; | |
| 100 | + try { | |
| 101 | + const res = await StudentApi.getStudentTeacher(id); | |
| 102 | + this.formData = res.data; | |
| 103 | + this.dialogTitle = "修改学生班主任"; | |
| 104 | + } finally { | |
| 105 | + this.formLoading = false; | |
| 106 | + } | |
| 107 | + } | |
| 108 | + this.dialogTitle = "新增学生班主任"; | |
| 109 | + }, | |
| 110 | + /** 提交按钮 */ | |
| 111 | + async submitForm() { | |
| 112 | + await this.$refs["formRef"].validate(); | |
| 113 | + this.formLoading = true; | |
| 114 | + try { | |
| 115 | + const data = this.formData; | |
| 116 | + // 修改的提交 | |
| 117 | + if (data.id) { | |
| 118 | + await StudentApi.updateStudentTeacher(data); | |
| 119 | + this.$modal.msgSuccess("修改成功"); | |
| 120 | + this.dialogVisible = false; | |
| 121 | + this.$emit('success'); | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + // 添加的提交 | |
| 125 | + await StudentApi.createStudentTeacher(data); | |
| 126 | + this.$modal.msgSuccess("新增成功"); | |
| 127 | + this.dialogVisible = false; | |
| 128 | + this.$emit('success'); | |
| 129 | + }finally { | |
| 130 | + this.formLoading = false; | |
| 131 | + } | |
| 132 | + }, | |
| 133 | + /** 表单重置 */ | |
| 134 | + reset() { | |
| 135 | + this.formData = { | |
| 136 | + id: undefined, | |
| 137 | + studentId: undefined, | |
| 138 | + name: undefined, | |
| 139 | + description: undefined, | |
| 140 | + birthday: undefined, | |
| 141 | + sex: undefined, | |
| 142 | + enabled: undefined, | |
| 143 | + avatar: undefined, | |
| 144 | + video: undefined, | |
| 145 | + memo: undefined, | |
| 146 | + }; | |
| 147 | + this.resetForm("formRef"); | |
| 148 | + }, | |
| 149 | + } | |
| 150 | + }; | |
| 151 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/StudentTeacherList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 操作工具栏 --> | |
| 4 | + <el-row :gutter="10" class="mb8"> | |
| 5 | + <el-col :span="1.5"> | |
| 6 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 7 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 8 | + </el-col> | |
| 9 | + </el-row> | |
| 10 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 11 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 12 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 13 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 14 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 15 | + <template v-slot="scope"> | |
| 16 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 17 | + </template> | |
| 18 | + </el-table-column> | |
| 19 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 20 | + <template v-slot="scope"> | |
| 21 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 22 | + </template> | |
| 23 | + </el-table-column> | |
| 24 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 25 | + <template v-slot="scope"> | |
| 26 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 27 | + </template> | |
| 28 | + </el-table-column> | |
| 29 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 30 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 31 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 32 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 33 | + <template v-slot="scope"> | |
| 34 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 35 | + </template> | |
| 36 | + </el-table-column> | |
| 37 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 38 | + <template v-slot="scope"> | |
| 39 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 40 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 41 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 42 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 43 | + </template> | |
| 44 | + </el-table-column> | |
| 45 | + </el-table> | |
| 46 | + <!-- 分页组件 --> | |
| 47 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 48 | + @pagination="getList"/> | |
| 49 | + <!-- 对话框(添加 / 修改) --> | |
| 50 | + <StudentTeacherForm ref="formRef" @success="getList" /> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo'; | |
| 56 | + import StudentTeacherForm from './StudentTeacherForm.vue'; | |
| 57 | + export default { | |
| 58 | + name: "StudentTeacherList", | |
| 59 | + components: { | |
| 60 | + StudentTeacherForm | |
| 61 | + }, | |
| 62 | + props:[ | |
| 63 | + 'studentId' | |
| 64 | + ],// 学生编号(主表的关联字段) | |
| 65 | + data() { | |
| 66 | + return { | |
| 67 | + // 遮罩层 | |
| 68 | + loading: true, | |
| 69 | + // 列表的数据 | |
| 70 | + list: [], | |
| 71 | + // 列表的总页数 | |
| 72 | + total: 0, | |
| 73 | + // 查询参数 | |
| 74 | + queryParams: { | |
| 75 | + pageNo: 1, | |
| 76 | + pageSize: 10, | |
| 77 | + studentId: undefined | |
| 78 | + } | |
| 79 | + }; | |
| 80 | + }, | |
| 81 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 82 | + studentId:{ | |
| 83 | + handler(val) { | |
| 84 | + this.queryParams.studentId = val; | |
| 85 | + if (val){ | |
| 86 | + this.handleQuery(); | |
| 87 | + } | |
| 88 | + }, | |
| 89 | + immediate: true | |
| 90 | + } | |
| 91 | + }, | |
| 92 | + methods: { | |
| 93 | + /** 查询列表 */ | |
| 94 | + async getList() { | |
| 95 | + try { | |
| 96 | + this.loading = true; | |
| 97 | + const res = await StudentApi.getStudentTeacherPage(this.queryParams); | |
| 98 | + this.list = res.data.list; | |
| 99 | + this.total = res.data.total; | |
| 100 | + } finally { | |
| 101 | + this.loading = false; | |
| 102 | + } | |
| 103 | + }, | |
| 104 | + /** 搜索按钮操作 */ | |
| 105 | + handleQuery() { | |
| 106 | + this.queryParams.pageNo = 1; | |
| 107 | + this.getList(); | |
| 108 | + }, | |
| 109 | + /** 添加/修改操作 */ | |
| 110 | + openForm(id) { | |
| 111 | + if (!this.studentId) { | |
| 112 | + this.$modal.msgError('请选择一个学生'); | |
| 113 | + return; | |
| 114 | + } | |
| 115 | + this.$refs["formRef"].open(id, this.studentId); | |
| 116 | + }, | |
| 117 | + /** 删除按钮操作 */ | |
| 118 | + async handleDelete(row) { | |
| 119 | + const id = row.id; | |
| 120 | + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?'); | |
| 121 | + try { | |
| 122 | + await StudentApi.deleteStudentTeacher(id); | |
| 123 | + await this.getList(); | |
| 124 | + this.$modal.msgSuccess("删除成功"); | |
| 125 | + } catch {} | |
| 126 | + }, | |
| 127 | + } | |
| 128 | + }; | |
| 129 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 搜索工作栏 --> | |
| 4 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 5 | + <el-form-item label="名字" prop="name"> | |
| 6 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 7 | + </el-form-item> | |
| 8 | + <el-form-item label="出生日期" prop="birthday"> | |
| 9 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 10 | + </el-form-item> | |
| 11 | + <el-form-item label="性别" prop="sex"> | |
| 12 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 13 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 14 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 15 | + </el-select> | |
| 16 | + </el-form-item> | |
| 17 | + <el-form-item label="是否有效" prop="enabled"> | |
| 18 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 19 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 20 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 21 | + </el-select> | |
| 22 | + </el-form-item> | |
| 23 | + <el-form-item label="创建时间" prop="createTime"> | |
| 24 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 25 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item> | |
| 28 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 29 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 30 | + </el-form-item> | |
| 31 | + </el-form> | |
| 32 | + | |
| 33 | + <!-- 操作工具栏 --> | |
| 34 | + <el-row :gutter="10" class="mb8"> | |
| 35 | + <el-col :span="1.5"> | |
| 36 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 37 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 38 | + </el-col> | |
| 39 | + <el-col :span="1.5"> | |
| 40 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 41 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 42 | + </el-col> | |
| 43 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 44 | + </el-row> | |
| 45 | + | |
| 46 | + <el-table | |
| 47 | + v-loading="loading" | |
| 48 | + :data="list" | |
| 49 | + :stripe="true" | |
| 50 | + :highlight-current-row="true" | |
| 51 | + :show-overflow-tooltip="true" | |
| 52 | + @current-change="handleCurrentChange" | |
| 53 | + > | |
| 54 | + <el-table-column label="编号" align="center" prop="id"> | |
| 55 | + <template v-slot="scope"> | |
| 56 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 57 | + </template> | |
| 58 | + </el-table-column> | |
| 59 | + <el-table-column label="名字" align="center" prop="name"> | |
| 60 | + <template v-slot="scope"> | |
| 61 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 62 | + </template> | |
| 63 | + </el-table-column> | |
| 64 | + <el-table-column label="简介" align="center" prop="description"> | |
| 65 | + <template v-slot="scope"> | |
| 66 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 67 | + </template> | |
| 68 | + </el-table-column> | |
| 69 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 70 | + <template v-slot="scope"> | |
| 71 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 72 | + </template> | |
| 73 | + </el-table-column> | |
| 74 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 75 | + <template v-slot="scope"> | |
| 76 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 77 | + </template> | |
| 78 | + </el-table-column> | |
| 79 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 80 | + <template v-slot="scope"> | |
| 81 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 82 | + </template> | |
| 83 | + </el-table-column> | |
| 84 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 85 | + <template v-slot="scope"> | |
| 86 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 87 | + </template> | |
| 88 | + </el-table-column> | |
| 89 | + <el-table-column label="附件" align="center" prop="video"> | |
| 90 | + <template v-slot="scope"> | |
| 91 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 92 | + </template> | |
| 93 | + </el-table-column> | |
| 94 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 95 | + <template v-slot="scope"> | |
| 96 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 97 | + </template> | |
| 98 | + </el-table-column> | |
| 99 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 100 | + <template v-slot="scope"> | |
| 101 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 102 | + </template> | |
| 103 | + </el-table-column> | |
| 104 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 105 | + <template v-slot="scope"> | |
| 106 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 107 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 108 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 109 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 110 | + </template> | |
| 111 | + </el-table-column> | |
| 112 | + </el-table> | |
| 113 | + <!-- 分页组件 --> | |
| 114 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 115 | + @pagination="getList"/> | |
| 116 | + <!-- 对话框(添加 / 修改) --> | |
| 117 | + <StudentForm ref="formRef" @success="getList" /> | |
| 118 | + <!-- 子表的列表 --> | |
| 119 | + <el-tabs v-model="subTabsName"> | |
| 120 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 121 | + <StudentContactList v-if="currentRow.id" :student-id="currentRow.id" /> | |
| 122 | + </el-tab-pane> | |
| 123 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 124 | + <StudentTeacherList v-if="currentRow.id" :student-id="currentRow.id" /> | |
| 125 | + </el-tab-pane> | |
| 126 | + </el-tabs> | |
| 127 | + </div> | |
| 128 | +</template> | |
| 129 | + | |
| 130 | +<script> | |
| 131 | +import * as StudentApi from '@/api/infra/demo'; | |
| 132 | +import StudentForm from './StudentForm.vue'; | |
| 133 | + import StudentContactList from './components/StudentContactList.vue'; | |
| 134 | + import StudentTeacherList from './components/StudentTeacherList.vue'; | |
| 135 | +export default { | |
| 136 | + name: "Student", | |
| 137 | + components: { | |
| 138 | + StudentForm, | |
| 139 | + StudentContactList, | |
| 140 | + StudentTeacherList, | |
| 141 | + }, | |
| 142 | + data() { | |
| 143 | + return { | |
| 144 | + // 遮罩层 | |
| 145 | + loading: true, | |
| 146 | + // 导出遮罩层 | |
| 147 | + exportLoading: false, | |
| 148 | + // 显示搜索条件 | |
| 149 | + showSearch: true, | |
| 150 | + // 总条数 | |
| 151 | + total: 0, | |
| 152 | + // 学生列表 | |
| 153 | + list: [], | |
| 154 | + // 是否展开,默认全部展开 | |
| 155 | + isExpandAll: true, | |
| 156 | + // 重新渲染表格状态 | |
| 157 | + refreshTable: true, | |
| 158 | + // 选中行 | |
| 159 | + currentRow: {}, | |
| 160 | + // 查询参数 | |
| 161 | + queryParams: { | |
| 162 | + pageNo: 1, | |
| 163 | + pageSize: 10, | |
| 164 | + name: null, | |
| 165 | + birthday: null, | |
| 166 | + sex: null, | |
| 167 | + enabled: null, | |
| 168 | + createTime: [], | |
| 169 | + }, | |
| 170 | + /** 子表的列表 */ | |
| 171 | + subTabsName: 'studentContact' | |
| 172 | + }; | |
| 173 | + }, | |
| 174 | + created() { | |
| 175 | + this.getList(); | |
| 176 | + }, | |
| 177 | + methods: { | |
| 178 | + /** 查询列表 */ | |
| 179 | + async getList() { | |
| 180 | + try { | |
| 181 | + this.loading = true; | |
| 182 | + const res = await StudentApi.getStudentPage(this.queryParams); | |
| 183 | + this.list = res.data.list; | |
| 184 | + this.total = res.data.total; | |
| 185 | + } finally { | |
| 186 | + this.loading = false; | |
| 187 | + } | |
| 188 | + }, | |
| 189 | + /** 搜索按钮操作 */ | |
| 190 | + handleQuery() { | |
| 191 | + this.queryParams.pageNo = 1; | |
| 192 | + this.getList(); | |
| 193 | + }, | |
| 194 | + /** 重置按钮操作 */ | |
| 195 | + resetQuery() { | |
| 196 | + this.resetForm("queryForm"); | |
| 197 | + this.handleQuery(); | |
| 198 | + }, | |
| 199 | + /** 添加/修改操作 */ | |
| 200 | + openForm(id) { | |
| 201 | + this.$refs["formRef"].open(id); | |
| 202 | + }, | |
| 203 | + /** 删除按钮操作 */ | |
| 204 | + async handleDelete(row) { | |
| 205 | + const id = row.id; | |
| 206 | + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?') | |
| 207 | + try { | |
| 208 | + await StudentApi.deleteStudent(id); | |
| 209 | + await this.getList(); | |
| 210 | + this.$modal.msgSuccess("删除成功"); | |
| 211 | + } catch {} | |
| 212 | + }, | |
| 213 | + /** 导出按钮操作 */ | |
| 214 | + async handleExport() { | |
| 215 | + await this.$modal.confirm('是否确认导出所有学生数据项?'); | |
| 216 | + try { | |
| 217 | + this.exportLoading = true; | |
| 218 | + const res = await StudentApi.exportStudentExcel(this.queryParams); | |
| 219 | + this.$download.excel(res.data, '学生.xls'); | |
| 220 | + } catch { | |
| 221 | + } finally { | |
| 222 | + this.exportLoading = false; | |
| 223 | + } | |
| 224 | + }, | |
| 225 | + /** 选中行操作 */ | |
| 226 | + handleCurrentChange(row) { | |
| 227 | + this.currentRow = row; | |
| 228 | + /** 子表的列表 */ | |
| 229 | + this.subTabsName = 'studentContact'; | |
| 230 | + }, | |
| 231 | + } | |
| 232 | +}; | |
| 233 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_erp/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentContactDO", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentContactDO.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "java/InfraStudentTeacherDO", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentTeacherDO.java" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentMapper", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentContactMapper", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentContactMapper.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentTeacherMapper", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentTeacherMapper.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "xml/InfraStudentMapper", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 36 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "java/InfraStudentService", | |
| 39 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 42 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 45 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "sql/sql", | |
| 48 | + "filePath" : "sql/sql.sql" | |
| 49 | +}, { | |
| 50 | + "contentPath" : "sql/h2", | |
| 51 | + "filePath" : "sql/h2.sql" | |
| 52 | +}, { | |
| 53 | + "contentPath" : "vue/index", | |
| 54 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 55 | +}, { | |
| 56 | + "contentPath" : "js/student", | |
| 57 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 58 | +}, { | |
| 59 | + "contentPath" : "vue/StudentForm", | |
| 60 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 61 | +}, { | |
| 62 | + "contentPath" : "vue/StudentContactForm", | |
| 63 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactForm.vue" | |
| 64 | +}, { | |
| 65 | + "contentPath" : "vue/StudentTeacherForm", | |
| 66 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherForm.vue" | |
| 67 | +}, { | |
| 68 | + "contentPath" : "vue/StudentContactList", | |
| 69 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactList.vue" | |
| 70 | +}, { | |
| 71 | + "contentPath" : "vue/StudentTeacherList", | |
| 72 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherList.vue" | |
| 73 | +} ] | |
| 0 | 74 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/ErrorCodeConstants_手动操作
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentContactDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生联系人 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_contact") | |
| 16 | +@KeySequence("infra_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentContactDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentContactMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生联系人 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentContactMapper extends BaseMapperX<InfraStudentContactDO> { | |
| 19 | + | |
| 20 | + default List<InfraStudentContactDO> selectListByStudentId(Long studentId) { | |
| 21 | + return selectList(InfraStudentContactDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentContactDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 32 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 学生") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/infra/student") | |
| 37 | +@Validated | |
| 38 | +public class InfraStudentController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private InfraStudentService studentService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建学生") | |
| 45 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 46 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 47 | + return success(studentService.createStudent(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新学生") | |
| 52 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 53 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 54 | + studentService.updateStudent(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除学生") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 62 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 63 | + studentService.deleteStudent(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得学生") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 71 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 72 | + InfraStudentDO student = studentService.getStudent(id); | |
| 73 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得学生分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 79 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 80 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 81 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/export-excel") | |
| 85 | + @Operation(summary = "导出学生 Excel") | |
| 86 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 87 | + @OperateLog(type = EXPORT) | |
| 88 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 89 | + HttpServletResponse response) throws IOException { | |
| 90 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 91 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 92 | + // 导出 Excel | |
| 93 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 94 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @GetMapping("/student-contact/list-by-student-id") | |
| 100 | + @Operation(summary = "获得学生联系人列表") | |
| 101 | + @Parameter(name = "studentId", description = "学生编号") | |
| 102 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 103 | + public CommonResult<List<InfraStudentContactDO>> getStudentContactListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 104 | + return success(studentService.getStudentContactListByStudentId(studentId)); | |
| 105 | + } | |
| 106 | + | |
| 107 | + // ==================== 子表(学生班主任) ==================== | |
| 108 | + | |
| 109 | + @GetMapping("/student-teacher/get-by-student-id") | |
| 110 | + @Operation(summary = "获得学生班主任") | |
| 111 | + @Parameter(name = "studentId", description = "学生编号") | |
| 112 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 113 | + public CommonResult<InfraStudentTeacherDO> getStudentTeacherByStudentId(@RequestParam("studentId") Long studentId) { | |
| 114 | + return success(studentService.getStudentTeacherByStudentId(studentId)); | |
| 115 | + } | |
| 116 | + | |
| 117 | +} | |
| 0 | 118 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class InfraStudentSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 25 | + @NotEmpty(message = "简介不能为空") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "性别不能为空") | |
| 34 | + private Integer sex; | |
| 35 | + | |
| 36 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 37 | + @NotNull(message = "是否有效不能为空") | |
| 38 | + private Boolean enabled; | |
| 39 | + | |
| 40 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 41 | + @NotEmpty(message = "头像不能为空") | |
| 42 | + private String avatar; | |
| 43 | + | |
| 44 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 45 | + @NotEmpty(message = "附件不能为空") | |
| 46 | + private String video; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 49 | + @NotEmpty(message = "备注不能为空") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | + @Schema(description = "学生联系人列表") | |
| 53 | + private List<InfraStudentContactDO> studentContacts; | |
| 54 | + | |
| 55 | + @Schema(description = "学生班主任") | |
| 56 | + private InfraStudentTeacherDO studentTeacher; | |
| 57 | + | |
| 58 | +} | |
| 0 | 59 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Service 接口 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +public interface InfraStudentService { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 创建学生 | |
| 21 | + * | |
| 22 | + * @param createReqVO 创建信息 | |
| 23 | + * @return 编号 | |
| 24 | + */ | |
| 25 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 更新学生 | |
| 29 | + * | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除学生 | |
| 36 | + * | |
| 37 | + * @param id 编号 | |
| 38 | + */ | |
| 39 | + void deleteStudent(Long id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获得学生 | |
| 43 | + * | |
| 44 | + * @param id 编号 | |
| 45 | + * @return 学生 | |
| 46 | + */ | |
| 47 | + InfraStudentDO getStudent(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生分页 | |
| 51 | + * | |
| 52 | + * @param pageReqVO 分页查询 | |
| 53 | + * @return 学生分页 | |
| 54 | + */ | |
| 55 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 56 | + | |
| 57 | + // ==================== 子表(学生联系人) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生联系人列表 | |
| 61 | + * | |
| 62 | + * @param studentId 学生编号 | |
| 63 | + * @return 学生联系人列表 | |
| 64 | + */ | |
| 65 | + List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId); | |
| 66 | + | |
| 67 | + // ==================== 子表(学生班主任) ==================== | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 获得学生班主任 | |
| 71 | + * | |
| 72 | + * @param studentId 学生编号 | |
| 73 | + * @return 学生班主任 | |
| 74 | + */ | |
| 75 | + InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId); | |
| 76 | + | |
| 77 | +} | |
| 0 | 78 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 15 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentContactMapper; | |
| 19 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentTeacherMapper; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private InfraStudentMapper studentMapper; | |
| 35 | + @Resource | |
| 36 | + private InfraStudentContactMapper studentContactMapper; | |
| 37 | + @Resource | |
| 38 | + private InfraStudentTeacherMapper studentTeacherMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + @Transactional(rollbackFor = Exception.class) | |
| 42 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 43 | + // 插入 | |
| 44 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 45 | + studentMapper.insert(student); | |
| 46 | + | |
| 47 | + // 插入子表 | |
| 48 | + createStudentContactList(student.getId(), createReqVO.getStudentContacts()); | |
| 49 | + createStudentTeacher(student.getId(), createReqVO.getStudentTeacher()); | |
| 50 | + // 返回 | |
| 51 | + return student.getId(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + @Transactional(rollbackFor = Exception.class) | |
| 56 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 57 | + // 校验存在 | |
| 58 | + validateStudentExists(updateReqVO.getId()); | |
| 59 | + // 更新 | |
| 60 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 61 | + studentMapper.updateById(updateObj); | |
| 62 | + | |
| 63 | + // 更新子表 | |
| 64 | + updateStudentContactList(updateReqVO.getId(), updateReqVO.getStudentContacts()); | |
| 65 | + updateStudentTeacher(updateReqVO.getId(), updateReqVO.getStudentTeacher()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + @Transactional(rollbackFor = Exception.class) | |
| 70 | + public void deleteStudent(Long id) { | |
| 71 | + // 校验存在 | |
| 72 | + validateStudentExists(id); | |
| 73 | + // 删除 | |
| 74 | + studentMapper.deleteById(id); | |
| 75 | + | |
| 76 | + // 删除子表 | |
| 77 | + deleteStudentContactByStudentId(id); | |
| 78 | + deleteStudentTeacherByStudentId(id); | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void validateStudentExists(Long id) { | |
| 82 | + if (studentMapper.selectById(id) == null) { | |
| 83 | + throw exception(STUDENT_NOT_EXISTS); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + public InfraStudentDO getStudent(Long id) { | |
| 89 | + return studentMapper.selectById(id); | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 94 | + return studentMapper.selectPage(pageReqVO); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId) { | |
| 101 | + return studentContactMapper.selectListByStudentId(studentId); | |
| 102 | + } | |
| 103 | + | |
| 104 | + private void createStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 105 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 106 | + studentContactMapper.insertBatch(list); | |
| 107 | + } | |
| 108 | + | |
| 109 | + private void updateStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 110 | + deleteStudentContactByStudentId(studentId); | |
| 111 | + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 112 | + createStudentContactList(studentId, list); | |
| 113 | + } | |
| 114 | + | |
| 115 | + private void deleteStudentContactByStudentId(Long studentId) { | |
| 116 | + studentContactMapper.deleteByStudentId(studentId); | |
| 117 | + } | |
| 118 | + | |
| 119 | + // ==================== 子表(学生班主任) ==================== | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId) { | |
| 123 | + return studentTeacherMapper.selectByStudentId(studentId); | |
| 124 | + } | |
| 125 | + | |
| 126 | + private void createStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 127 | + if (studentTeacher == null) { | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + studentTeacher.setStudentId(studentId); | |
| 131 | + studentTeacherMapper.insert(studentTeacher); | |
| 132 | + } | |
| 133 | + | |
| 134 | + private void updateStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 135 | + if (studentTeacher == null) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + studentTeacher.setStudentId(studentId); | |
| 139 | + studentTeacher.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 140 | + studentTeacherMapper.insertOrUpdate(studentTeacher); | |
| 141 | + } | |
| 142 | + | |
| 143 | + private void deleteStudentTeacherByStudentId(Long studentId) { | |
| 144 | + studentTeacherMapper.deleteByStudentId(studentId); | |
| 145 | + } | |
| 146 | + | |
| 147 | +} | |
| 0 | 148 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentTeacherDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班主任 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_teacher") | |
| 16 | +@KeySequence("infra_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentTeacherDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/java/InfraStudentTeacherMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生班主任 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentTeacherMapper extends BaseMapperX<InfraStudentTeacherDO> { | |
| 19 | + | |
| 20 | + default InfraStudentTeacherDO selectByStudentId(Long studentId) { | |
| 21 | + return selectOne(InfraStudentTeacherDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentTeacherDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ==================== 子表(学生联系人) ==================== | |
| 56 | + | |
| 57 | + // 获得学生联系人列表 | |
| 58 | + export function getStudentContactListByStudentId(studentId) { | |
| 59 | + return request({ | |
| 60 | + url: `/infra/student/student-contact/list-by-student-id?studentId=` + studentId, | |
| 61 | + method: 'get' | |
| 62 | + }) | |
| 63 | + } | |
| 64 | + | |
| 65 | +// ==================== 子表(学生班主任) ==================== | |
| 66 | + | |
| 67 | + // 获得学生班主任 | |
| 68 | + export function getStudentTeacherByStudentId(studentId) { | |
| 69 | + return request({ | |
| 70 | + url: `/infra/student/student-teacher/get-by-student-id?studentId=` + studentId, | |
| 71 | + method: 'get' | |
| 72 | + }) | |
| 73 | + } | |
| 74 | + | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentContactForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + v-loading="formLoading" | |
| 8 | + label-width="0px" | |
| 9 | + :inline-message="true" | |
| 10 | + > | |
| 11 | + <el-table :data="formData" class="-mt-10px"> | |
| 12 | + <el-table-column label="序号" type="index" width="100" /> | |
| 13 | + <el-table-column label="名字" min-width="150"> | |
| 14 | + <template v-slot="{ row, $index }"> | |
| 15 | + <el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!"> | |
| 16 | + <el-input v-model="row.name" placeholder="请输入名字" /> | |
| 17 | + </el-form-item> | |
| 18 | + </template> | |
| 19 | + </el-table-column> | |
| 20 | + <el-table-column label="简介" min-width="200"> | |
| 21 | + <template v-slot="{ row, $index }"> | |
| 22 | + <el-form-item :prop="`${$index}.description`" :rules="formRules.description" class="mb-0px!"> | |
| 23 | + <el-input v-model="row.description" type="textarea" placeholder="请输入简介" /> | |
| 24 | + </el-form-item> | |
| 25 | + </template> | |
| 26 | + </el-table-column> | |
| 27 | + <el-table-column label="出生日期" min-width="150"> | |
| 28 | + <template v-slot="{ row, $index }"> | |
| 29 | + <el-form-item :prop="`${$index}.birthday`" :rules="formRules.birthday" class="mb-0px!"> | |
| 30 | + <el-date-picker clearable v-model="row.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 31 | + </el-form-item> | |
| 32 | + </template> | |
| 33 | + </el-table-column> | |
| 34 | + <el-table-column label="性别" min-width="150"> | |
| 35 | + <template v-slot="{ row, $index }"> | |
| 36 | + <el-form-item :prop="`${$index}.sex`" :rules="formRules.sex" class="mb-0px!"> | |
| 37 | + <el-select v-model="row.sex" placeholder="请选择性别"> | |
| 38 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 39 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 40 | + </el-select> | |
| 41 | + </el-form-item> | |
| 42 | + </template> | |
| 43 | + </el-table-column> | |
| 44 | + <el-table-column label="是否有效" min-width="150"> | |
| 45 | + <template v-slot="{ row, $index }"> | |
| 46 | + <el-form-item :prop="`${$index}.enabled`" :rules="formRules.enabled" class="mb-0px!"> | |
| 47 | + <el-radio-group v-model="row.enabled"> | |
| 48 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 49 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 50 | + </el-radio-group> | |
| 51 | + </el-form-item> | |
| 52 | + </template> | |
| 53 | + </el-table-column> | |
| 54 | + <el-table-column label="头像" min-width="200"> | |
| 55 | + <template v-slot="{ row, $index }"> | |
| 56 | + <el-form-item :prop="`${$index}.avatar`" :rules="formRules.avatar" class="mb-0px!"> | |
| 57 | + <ImageUpload v-model="row.avatar"/> | |
| 58 | + </el-form-item> | |
| 59 | + </template> | |
| 60 | + </el-table-column> | |
| 61 | + <el-table-column label="附件" min-width="200"> | |
| 62 | + <template v-slot="{ row, $index }"> | |
| 63 | + <el-form-item :prop="`${$index}.video`" :rules="formRules.video" class="mb-0px!"> | |
| 64 | + <FileUpload v-model="row.video"/> | |
| 65 | + </el-form-item> | |
| 66 | + </template> | |
| 67 | + </el-table-column> | |
| 68 | + <el-table-column label="备注" min-width="400"> | |
| 69 | + <template v-slot="{ row, $index }"> | |
| 70 | + <el-form-item :prop="`${$index}.memo`" :rules="formRules.memo" class="mb-0px!"> | |
| 71 | + <Editor v-model="row.memo" :min-height="192"/> | |
| 72 | + </el-form-item> | |
| 73 | + </template> | |
| 74 | + </el-table-column> | |
| 75 | + <el-table-column align="center" fixed="right" label="操作" width="60"> | |
| 76 | + <template v-slot="{ $index }"> | |
| 77 | + <el-link @click="handleDelete($index)">—</el-link> | |
| 78 | + </template> | |
| 79 | + </el-table-column> | |
| 80 | + </el-table> | |
| 81 | + </el-form> | |
| 82 | + <el-row justify="center" class="mt-3"> | |
| 83 | + <el-button @click="handleAdd" round>+ 添加学生联系人</el-button> | |
| 84 | + </el-row> | |
| 85 | + </div> | |
| 86 | +</template> | |
| 87 | + | |
| 88 | +<script> | |
| 89 | + import * as StudentApi from '@/api/infra/demo'; | |
| 90 | + import ImageUpload from '@/components/ImageUpload'; | |
| 91 | + import FileUpload from '@/components/FileUpload'; | |
| 92 | + import Editor from '@/components/Editor'; | |
| 93 | + export default { | |
| 94 | + name: "StudentContactForm", | |
| 95 | + components: { | |
| 96 | + ImageUpload, | |
| 97 | + FileUpload, | |
| 98 | + Editor, | |
| 99 | + }, | |
| 100 | + props:[ | |
| 101 | + 'studentId' | |
| 102 | + ],// 学生编号(主表的关联字段) | |
| 103 | + data() { | |
| 104 | + return { | |
| 105 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 106 | + formLoading: false, | |
| 107 | + // 表单参数 | |
| 108 | + formData: [], | |
| 109 | + // 表单校验 | |
| 110 | + formRules: { | |
| 111 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 112 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 113 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 114 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 115 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 116 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 117 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 118 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 119 | + }, | |
| 120 | + }; | |
| 121 | + }, | |
| 122 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 123 | + studentId:{ | |
| 124 | + handler(val) { | |
| 125 | + // 1. 重置表单 | |
| 126 | + this.formData = [] | |
| 127 | + // 2. val 非空,则加载数据 | |
| 128 | + if (!val) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + try { | |
| 132 | + this.formLoading = true; | |
| 133 | + // 这里还是需要获取一下 this 的不然取不到 formData | |
| 134 | + const that = this; | |
| 135 | + StudentApi.getStudentContactListByStudentId(val).then(function (res){ | |
| 136 | + that.formData = res.data; | |
| 137 | + }) | |
| 138 | + } finally { | |
| 139 | + this.formLoading = false; | |
| 140 | + } | |
| 141 | + }, | |
| 142 | + immediate: true | |
| 143 | + } | |
| 144 | + }, | |
| 145 | + methods: { | |
| 146 | + /** 新增按钮操作 */ | |
| 147 | + handleAdd() { | |
| 148 | + const row = { | |
| 149 | + id: undefined, | |
| 150 | + studentId: undefined, | |
| 151 | + name: undefined, | |
| 152 | + description: undefined, | |
| 153 | + birthday: undefined, | |
| 154 | + sex: undefined, | |
| 155 | + enabled: undefined, | |
| 156 | + avatar: undefined, | |
| 157 | + video: undefined, | |
| 158 | + memo: undefined, | |
| 159 | + } | |
| 160 | + row.studentId = this.studentId; | |
| 161 | + this.formData.push(row); | |
| 162 | + }, | |
| 163 | + /** 删除按钮操作 */ | |
| 164 | + handleDelete(index) { | |
| 165 | + this.formData.splice(index, 1); | |
| 166 | + }, | |
| 167 | + /** 表单校验 */ | |
| 168 | + validate(){ | |
| 169 | + return this.$refs["formRef"].validate(); | |
| 170 | + }, | |
| 171 | + /** 表单值 */ | |
| 172 | + getData(){ | |
| 173 | + return this.formData; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + }; | |
| 177 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentContactList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 4 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 5 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 6 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 7 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 8 | + <template v-slot="scope"> | |
| 9 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 10 | + </template> | |
| 11 | + </el-table-column> | |
| 12 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 13 | + <template v-slot="scope"> | |
| 14 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 15 | + </template> | |
| 16 | + </el-table-column> | |
| 17 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 18 | + <template v-slot="scope"> | |
| 19 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 20 | + </template> | |
| 21 | + </el-table-column> | |
| 22 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 23 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 24 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 25 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 26 | + <template v-slot="scope"> | |
| 27 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 28 | + </template> | |
| 29 | + </el-table-column> | |
| 30 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 31 | + <template v-slot="scope"> | |
| 32 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 33 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 34 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 35 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 36 | + </template> | |
| 37 | + </el-table-column> | |
| 38 | + </el-table> | |
| 39 | + </div> | |
| 40 | +</template> | |
| 41 | + | |
| 42 | +<script> | |
| 43 | + import * as StudentApi from '@/api/infra/demo'; | |
| 44 | + export default { | |
| 45 | + name: "StudentContactList", | |
| 46 | + props:[ | |
| 47 | + 'studentId' | |
| 48 | + ],// 学生编号(主表的关联字段) | |
| 49 | + data() { | |
| 50 | + return { | |
| 51 | + // 遮罩层 | |
| 52 | + loading: true, | |
| 53 | + // 列表的数据 | |
| 54 | + list: [], | |
| 55 | + }; | |
| 56 | + }, | |
| 57 | + created() { | |
| 58 | + this.getList(); | |
| 59 | + }, | |
| 60 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 61 | + studentId:{ | |
| 62 | + handler(val) { | |
| 63 | + this.queryParams.studentId = val; | |
| 64 | + if (val){ | |
| 65 | + this.handleQuery(); | |
| 66 | + } | |
| 67 | + }, | |
| 68 | + immediate: true | |
| 69 | + } | |
| 70 | + }, | |
| 71 | + methods: { | |
| 72 | + /** 查询列表 */ | |
| 73 | + async getList() { | |
| 74 | + try { | |
| 75 | + this.loading = true; | |
| 76 | + const res = await StudentApi.getStudentContactListByStudentId(this.studentId); | |
| 77 | + this.list = res.data; | |
| 78 | + } finally { | |
| 79 | + this.loading = false; | |
| 80 | + } | |
| 81 | + }, | |
| 82 | + /** 搜索按钮操作 */ | |
| 83 | + handleQuery() { | |
| 84 | + this.queryParams.pageNo = 1; | |
| 85 | + this.getList(); | |
| 86 | + }, | |
| 87 | + } | |
| 88 | + }; | |
| 89 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <!-- 子表的表单 --> | |
| 38 | + <el-tabs v-model="subTabsName"> | |
| 39 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 40 | + <StudentContactForm ref="studentContactFormRef" :student-id="formData.id" /> | |
| 41 | + </el-tab-pane> | |
| 42 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 43 | + <StudentTeacherForm ref="studentTeacherFormRef" :student-id="formData.id" /> | |
| 44 | + </el-tab-pane> | |
| 45 | + </el-tabs> | |
| 46 | + <div slot="footer" class="dialog-footer"> | |
| 47 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 48 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 49 | + </div> | |
| 50 | + </el-dialog> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo'; | |
| 56 | + import ImageUpload from '@/components/ImageUpload'; | |
| 57 | + import FileUpload from '@/components/FileUpload'; | |
| 58 | + import Editor from '@/components/Editor'; | |
| 59 | + import StudentContactForm from './components/StudentContactForm.vue' | |
| 60 | + import StudentTeacherForm from './components/StudentTeacherForm.vue' | |
| 61 | + export default { | |
| 62 | + name: "StudentForm", | |
| 63 | + components: { | |
| 64 | + ImageUpload, | |
| 65 | + FileUpload, | |
| 66 | + Editor, | |
| 67 | + StudentContactForm, | |
| 68 | + StudentTeacherForm, | |
| 69 | + }, | |
| 70 | + data() { | |
| 71 | + return { | |
| 72 | + // 弹出层标题 | |
| 73 | + dialogTitle: "", | |
| 74 | + // 是否显示弹出层 | |
| 75 | + dialogVisible: false, | |
| 76 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 77 | + formLoading: false, | |
| 78 | + // 表单参数 | |
| 79 | + formData: { | |
| 80 | + id: undefined, | |
| 81 | + name: undefined, | |
| 82 | + description: undefined, | |
| 83 | + birthday: undefined, | |
| 84 | + sex: undefined, | |
| 85 | + enabled: undefined, | |
| 86 | + avatar: undefined, | |
| 87 | + video: undefined, | |
| 88 | + memo: undefined, | |
| 89 | + }, | |
| 90 | + // 表单校验 | |
| 91 | + formRules: { | |
| 92 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 93 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 94 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 95 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 96 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 97 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 98 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 99 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 100 | + }, | |
| 101 | + /** 子表的表单 */ | |
| 102 | + subTabsName: 'studentContact' | |
| 103 | + }; | |
| 104 | + }, | |
| 105 | + methods: { | |
| 106 | + /** 打开弹窗 */ | |
| 107 | + async open(id) { | |
| 108 | + this.dialogVisible = true; | |
| 109 | + this.reset(); | |
| 110 | + // 修改时,设置数据 | |
| 111 | + if (id) { | |
| 112 | + this.formLoading = true; | |
| 113 | + try { | |
| 114 | + const res = await StudentApi.getStudent(id); | |
| 115 | + this.formData = res.data; | |
| 116 | + this.title = "修改学生"; | |
| 117 | + } finally { | |
| 118 | + this.formLoading = false; | |
| 119 | + } | |
| 120 | + } | |
| 121 | + this.title = "新增学生"; | |
| 122 | + }, | |
| 123 | + /** 提交按钮 */ | |
| 124 | + async submitForm() { | |
| 125 | + // 校验主表 | |
| 126 | + await this.$refs["formRef"].validate(); | |
| 127 | + // 校验子表 | |
| 128 | + try { | |
| 129 | + await this.$refs['studentContactFormRef'].validate(); | |
| 130 | + } catch (e) { | |
| 131 | + this.subTabsName = 'studentContact'; | |
| 132 | + return; | |
| 133 | + } | |
| 134 | + try { | |
| 135 | + await this.$refs['studentTeacherFormRef'].validate(); | |
| 136 | + } catch (e) { | |
| 137 | + this.subTabsName = 'studentTeacher'; | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + this.formLoading = true; | |
| 141 | + try { | |
| 142 | + const data = this.formData; | |
| 143 | + // 拼接子表的数据 | |
| 144 | + data.studentContacts = this.$refs['studentContactFormRef'].getData(); | |
| 145 | + data.studentTeacher = this.$refs['studentTeacherFormRef'].getData(); | |
| 146 | + // 修改的提交 | |
| 147 | + if (data.id) { | |
| 148 | + await StudentApi.updateStudent(data); | |
| 149 | + this.$modal.msgSuccess("修改成功"); | |
| 150 | + this.dialogVisible = false; | |
| 151 | + this.$emit('success'); | |
| 152 | + return; | |
| 153 | + } | |
| 154 | + // 添加的提交 | |
| 155 | + await StudentApi.createStudent(data); | |
| 156 | + this.$modal.msgSuccess("新增成功"); | |
| 157 | + this.dialogVisible = false; | |
| 158 | + this.$emit('success'); | |
| 159 | + } finally { | |
| 160 | + this.formLoading = false; | |
| 161 | + } | |
| 162 | + }, | |
| 163 | + /** 表单重置 */ | |
| 164 | + reset() { | |
| 165 | + this.formData = { | |
| 166 | + id: undefined, | |
| 167 | + name: undefined, | |
| 168 | + description: undefined, | |
| 169 | + birthday: undefined, | |
| 170 | + sex: undefined, | |
| 171 | + enabled: undefined, | |
| 172 | + avatar: undefined, | |
| 173 | + video: undefined, | |
| 174 | + memo: undefined, | |
| 175 | + }; | |
| 176 | + this.resetForm("formRef"); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + }; | |
| 180 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentTeacherForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + label-width="100px" | |
| 8 | + v-loading="formLoading" | |
| 9 | + > | |
| 10 | + <el-form-item label="名字" prop="name"> | |
| 11 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 12 | + </el-form-item> | |
| 13 | + <el-form-item label="简介" prop="description"> | |
| 14 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入简介" /> | |
| 15 | + </el-form-item> | |
| 16 | + <el-form-item label="出生日期" prop="birthday"> | |
| 17 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 18 | + </el-form-item> | |
| 19 | + <el-form-item label="性别" prop="sex"> | |
| 20 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 21 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 22 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 23 | + </el-select> | |
| 24 | + </el-form-item> | |
| 25 | + <el-form-item label="是否有效" prop="enabled"> | |
| 26 | + <el-radio-group v-model="formData.enabled"> | |
| 27 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 28 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 29 | + </el-radio-group> | |
| 30 | + </el-form-item> | |
| 31 | + <el-form-item label="头像"> | |
| 32 | + <ImageUpload v-model="formData.avatar"/> | |
| 33 | + </el-form-item> | |
| 34 | + <el-form-item label="附件"> | |
| 35 | + <FileUpload v-model="formData.video"/> | |
| 36 | + </el-form-item> | |
| 37 | + <el-form-item label="备注"> | |
| 38 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 39 | + </el-form-item> | |
| 40 | + </el-form> | |
| 41 | + </div> | |
| 42 | +</template> | |
| 43 | + | |
| 44 | +<script> | |
| 45 | + import * as StudentApi from '@/api/infra/demo'; | |
| 46 | + import ImageUpload from '@/components/ImageUpload'; | |
| 47 | + import FileUpload from '@/components/FileUpload'; | |
| 48 | + import Editor from '@/components/Editor'; | |
| 49 | + export default { | |
| 50 | + name: "StudentTeacherForm", | |
| 51 | + components: { | |
| 52 | + ImageUpload, | |
| 53 | + FileUpload, | |
| 54 | + Editor, | |
| 55 | + }, | |
| 56 | + props:[ | |
| 57 | + 'studentId' | |
| 58 | + ],// 学生编号(主表的关联字段) | |
| 59 | + data() { | |
| 60 | + return { | |
| 61 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 62 | + formLoading: false, | |
| 63 | + // 表单参数 | |
| 64 | + formData: [], | |
| 65 | + // 表单校验 | |
| 66 | + formRules: { | |
| 67 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 68 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 69 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 70 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 71 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 72 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 73 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 74 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 75 | + }, | |
| 76 | + }; | |
| 77 | + }, | |
| 78 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 79 | + studentId:{ | |
| 80 | + handler(val) { | |
| 81 | + // 1. 重置表单 | |
| 82 | + this.formData = { | |
| 83 | + id: undefined, | |
| 84 | + studentId: undefined, | |
| 85 | + name: undefined, | |
| 86 | + description: undefined, | |
| 87 | + birthday: undefined, | |
| 88 | + sex: undefined, | |
| 89 | + enabled: undefined, | |
| 90 | + avatar: undefined, | |
| 91 | + video: undefined, | |
| 92 | + memo: undefined, | |
| 93 | + } | |
| 94 | + // 2. val 非空,则加载数据 | |
| 95 | + if (!val) { | |
| 96 | + return; | |
| 97 | + } | |
| 98 | + try { | |
| 99 | + this.formLoading = true; | |
| 100 | + // 这里还是需要获取一下 this 的不然取不到 formData | |
| 101 | + const that = this; | |
| 102 | + StudentApi.getStudentTeacherByStudentId(val).then(function (res){ | |
| 103 | + const data = res.data; | |
| 104 | + if (!data) { | |
| 105 | + return | |
| 106 | + } | |
| 107 | + that.formData = data; | |
| 108 | + }) | |
| 109 | + } finally { | |
| 110 | + this.formLoading = false; | |
| 111 | + } | |
| 112 | + }, | |
| 113 | + immediate: true | |
| 114 | + } | |
| 115 | + }, | |
| 116 | + methods: { | |
| 117 | + /** 表单校验 */ | |
| 118 | + validate(){ | |
| 119 | + return this.$refs["formRef"].validate(); | |
| 120 | + }, | |
| 121 | + /** 表单值 */ | |
| 122 | + getData(){ | |
| 123 | + return this.formData; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + }; | |
| 127 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/StudentTeacherList
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 4 | + <el-table-column label="编号" align="center" prop="id" /> | |
| 5 | + <el-table-column label="名字" align="center" prop="name" /> | |
| 6 | + <el-table-column label="简介" align="center" prop="description" /> | |
| 7 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 8 | + <template v-slot="scope"> | |
| 9 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 10 | + </template> | |
| 11 | + </el-table-column> | |
| 12 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 13 | + <template v-slot="scope"> | |
| 14 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 15 | + </template> | |
| 16 | + </el-table-column> | |
| 17 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 18 | + <template v-slot="scope"> | |
| 19 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 20 | + </template> | |
| 21 | + </el-table-column> | |
| 22 | + <el-table-column label="头像" align="center" prop="avatar" /> | |
| 23 | + <el-table-column label="附件" align="center" prop="video" /> | |
| 24 | + <el-table-column label="备注" align="center" prop="memo" /> | |
| 25 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 26 | + <template v-slot="scope"> | |
| 27 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 28 | + </template> | |
| 29 | + </el-table-column> | |
| 30 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 31 | + <template v-slot="scope"> | |
| 32 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 33 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 34 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 35 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 36 | + </template> | |
| 37 | + </el-table-column> | |
| 38 | + </el-table> | |
| 39 | + </div> | |
| 40 | +</template> | |
| 41 | + | |
| 42 | +<script> | |
| 43 | + import * as StudentApi from '@/api/infra/demo'; | |
| 44 | + export default { | |
| 45 | + name: "StudentTeacherList", | |
| 46 | + props:[ | |
| 47 | + 'studentId' | |
| 48 | + ],// 学生编号(主表的关联字段) | |
| 49 | + data() { | |
| 50 | + return { | |
| 51 | + // 遮罩层 | |
| 52 | + loading: true, | |
| 53 | + // 列表的数据 | |
| 54 | + list: [], | |
| 55 | + }; | |
| 56 | + }, | |
| 57 | + created() { | |
| 58 | + this.getList(); | |
| 59 | + }, | |
| 60 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 61 | + studentId:{ | |
| 62 | + handler(val) { | |
| 63 | + this.queryParams.studentId = val; | |
| 64 | + if (val){ | |
| 65 | + this.handleQuery(); | |
| 66 | + } | |
| 67 | + }, | |
| 68 | + immediate: true | |
| 69 | + } | |
| 70 | + }, | |
| 71 | + methods: { | |
| 72 | + /** 查询列表 */ | |
| 73 | + async getList() { | |
| 74 | + try { | |
| 75 | + this.loading = true; | |
| 76 | + const res = await StudentApi.getStudentTeacherByStudentId(this.studentId); | |
| 77 | + const data = res.data; | |
| 78 | + if (!data) { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + this.list.push(data); | |
| 82 | + } finally { | |
| 83 | + this.loading = false; | |
| 84 | + } | |
| 85 | + }, | |
| 86 | + /** 搜索按钮操作 */ | |
| 87 | + handleQuery() { | |
| 88 | + this.queryParams.pageNo = 1; | |
| 89 | + this.getList(); | |
| 90 | + }, | |
| 91 | + } | |
| 92 | + }; | |
| 93 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 搜索工作栏 --> | |
| 4 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 5 | + <el-form-item label="名字" prop="name"> | |
| 6 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 7 | + </el-form-item> | |
| 8 | + <el-form-item label="出生日期" prop="birthday"> | |
| 9 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 10 | + </el-form-item> | |
| 11 | + <el-form-item label="性别" prop="sex"> | |
| 12 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 13 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 14 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 15 | + </el-select> | |
| 16 | + </el-form-item> | |
| 17 | + <el-form-item label="是否有效" prop="enabled"> | |
| 18 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 19 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 20 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 21 | + </el-select> | |
| 22 | + </el-form-item> | |
| 23 | + <el-form-item label="创建时间" prop="createTime"> | |
| 24 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 25 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item> | |
| 28 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 29 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 30 | + </el-form-item> | |
| 31 | + </el-form> | |
| 32 | + | |
| 33 | + <!-- 操作工具栏 --> | |
| 34 | + <el-row :gutter="10" class="mb8"> | |
| 35 | + <el-col :span="1.5"> | |
| 36 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 37 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 38 | + </el-col> | |
| 39 | + <el-col :span="1.5"> | |
| 40 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 41 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 42 | + </el-col> | |
| 43 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 44 | + </el-row> | |
| 45 | + | |
| 46 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 47 | + <!-- 子表的列表 --> | |
| 48 | + <el-table-column type="expand"> | |
| 49 | + <template #default="scope"> | |
| 50 | + <el-tabs value="studentContact"> | |
| 51 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 52 | + <StudentContactList :student-id="scope.row.id" /> | |
| 53 | + </el-tab-pane> | |
| 54 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 55 | + <StudentTeacherList :student-id="scope.row.id" /> | |
| 56 | + </el-tab-pane> | |
| 57 | + </el-tabs> | |
| 58 | + </template> | |
| 59 | + </el-table-column> | |
| 60 | + <el-table-column label="编号" align="center" prop="id"> | |
| 61 | + <template v-slot="scope"> | |
| 62 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 63 | + </template> | |
| 64 | + </el-table-column> | |
| 65 | + <el-table-column label="名字" align="center" prop="name"> | |
| 66 | + <template v-slot="scope"> | |
| 67 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 68 | + </template> | |
| 69 | + </el-table-column> | |
| 70 | + <el-table-column label="简介" align="center" prop="description"> | |
| 71 | + <template v-slot="scope"> | |
| 72 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 73 | + </template> | |
| 74 | + </el-table-column> | |
| 75 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 76 | + <template v-slot="scope"> | |
| 77 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 78 | + </template> | |
| 79 | + </el-table-column> | |
| 80 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 81 | + <template v-slot="scope"> | |
| 82 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 83 | + </template> | |
| 84 | + </el-table-column> | |
| 85 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 86 | + <template v-slot="scope"> | |
| 87 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 88 | + </template> | |
| 89 | + </el-table-column> | |
| 90 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 91 | + <template v-slot="scope"> | |
| 92 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 93 | + </template> | |
| 94 | + </el-table-column> | |
| 95 | + <el-table-column label="附件" align="center" prop="video"> | |
| 96 | + <template v-slot="scope"> | |
| 97 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 98 | + </template> | |
| 99 | + </el-table-column> | |
| 100 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 101 | + <template v-slot="scope"> | |
| 102 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 103 | + </template> | |
| 104 | + </el-table-column> | |
| 105 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 106 | + <template v-slot="scope"> | |
| 107 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 108 | + </template> | |
| 109 | + </el-table-column> | |
| 110 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 111 | + <template v-slot="scope"> | |
| 112 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 113 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 114 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 115 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 116 | + </template> | |
| 117 | + </el-table-column> | |
| 118 | + </el-table> | |
| 119 | + <!-- 分页组件 --> | |
| 120 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 121 | + @pagination="getList"/> | |
| 122 | + <!-- 对话框(添加 / 修改) --> | |
| 123 | + <StudentForm ref="formRef" @success="getList" /> | |
| 124 | + </div> | |
| 125 | +</template> | |
| 126 | + | |
| 127 | +<script> | |
| 128 | +import * as StudentApi from '@/api/infra/demo'; | |
| 129 | +import StudentForm from './StudentForm.vue'; | |
| 130 | + import StudentContactList from './components/StudentContactList.vue'; | |
| 131 | + import StudentTeacherList from './components/StudentTeacherList.vue'; | |
| 132 | +export default { | |
| 133 | + name: "Student", | |
| 134 | + components: { | |
| 135 | + StudentForm, | |
| 136 | + StudentContactList, | |
| 137 | + StudentTeacherList, | |
| 138 | + }, | |
| 139 | + data() { | |
| 140 | + return { | |
| 141 | + // 遮罩层 | |
| 142 | + loading: true, | |
| 143 | + // 导出遮罩层 | |
| 144 | + exportLoading: false, | |
| 145 | + // 显示搜索条件 | |
| 146 | + showSearch: true, | |
| 147 | + // 总条数 | |
| 148 | + total: 0, | |
| 149 | + // 学生列表 | |
| 150 | + list: [], | |
| 151 | + // 是否展开,默认全部展开 | |
| 152 | + isExpandAll: true, | |
| 153 | + // 重新渲染表格状态 | |
| 154 | + refreshTable: true, | |
| 155 | + // 选中行 | |
| 156 | + currentRow: {}, | |
| 157 | + // 查询参数 | |
| 158 | + queryParams: { | |
| 159 | + pageNo: 1, | |
| 160 | + pageSize: 10, | |
| 161 | + name: null, | |
| 162 | + birthday: null, | |
| 163 | + sex: null, | |
| 164 | + enabled: null, | |
| 165 | + createTime: [], | |
| 166 | + }, | |
| 167 | + }; | |
| 168 | + }, | |
| 169 | + created() { | |
| 170 | + this.getList(); | |
| 171 | + }, | |
| 172 | + methods: { | |
| 173 | + /** 查询列表 */ | |
| 174 | + async getList() { | |
| 175 | + try { | |
| 176 | + this.loading = true; | |
| 177 | + const res = await StudentApi.getStudentPage(this.queryParams); | |
| 178 | + this.list = res.data.list; | |
| 179 | + this.total = res.data.total; | |
| 180 | + } finally { | |
| 181 | + this.loading = false; | |
| 182 | + } | |
| 183 | + }, | |
| 184 | + /** 搜索按钮操作 */ | |
| 185 | + handleQuery() { | |
| 186 | + this.queryParams.pageNo = 1; | |
| 187 | + this.getList(); | |
| 188 | + }, | |
| 189 | + /** 重置按钮操作 */ | |
| 190 | + resetQuery() { | |
| 191 | + this.resetForm("queryForm"); | |
| 192 | + this.handleQuery(); | |
| 193 | + }, | |
| 194 | + /** 添加/修改操作 */ | |
| 195 | + openForm(id) { | |
| 196 | + this.$refs["formRef"].open(id); | |
| 197 | + }, | |
| 198 | + /** 删除按钮操作 */ | |
| 199 | + async handleDelete(row) { | |
| 200 | + const id = row.id; | |
| 201 | + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?') | |
| 202 | + try { | |
| 203 | + await StudentApi.deleteStudent(id); | |
| 204 | + await this.getList(); | |
| 205 | + this.$modal.msgSuccess("删除成功"); | |
| 206 | + } catch {} | |
| 207 | + }, | |
| 208 | + /** 导出按钮操作 */ | |
| 209 | + async handleExport() { | |
| 210 | + await this.$modal.confirm('是否确认导出所有学生数据项?'); | |
| 211 | + try { | |
| 212 | + this.exportLoading = true; | |
| 213 | + const res = await StudentApi.exportStudentExcel(this.queryParams); | |
| 214 | + this.$download.excel(res.data, '学生.xls'); | |
| 215 | + } catch { | |
| 216 | + } finally { | |
| 217 | + this.exportLoading = false; | |
| 218 | + } | |
| 219 | + }, | |
| 220 | + } | |
| 221 | +}; | |
| 222 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_inner/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentContactDO", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentContactDO.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "java/InfraStudentTeacherDO", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentTeacherDO.java" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentMapper", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentContactMapper", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentContactMapper.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentTeacherMapper", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentTeacherMapper.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "xml/InfraStudentMapper", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 36 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "java/InfraStudentService", | |
| 39 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 42 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 45 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "sql/sql", | |
| 48 | + "filePath" : "sql/sql.sql" | |
| 49 | +}, { | |
| 50 | + "contentPath" : "sql/h2", | |
| 51 | + "filePath" : "sql/h2.sql" | |
| 52 | +}, { | |
| 53 | + "contentPath" : "vue/index", | |
| 54 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 55 | +}, { | |
| 56 | + "contentPath" : "js/student", | |
| 57 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 58 | +}, { | |
| 59 | + "contentPath" : "vue/StudentForm", | |
| 60 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 61 | +}, { | |
| 62 | + "contentPath" : "vue/StudentContactForm", | |
| 63 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentContactForm.vue" | |
| 64 | +}, { | |
| 65 | + "contentPath" : "vue/StudentTeacherForm", | |
| 66 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/components/StudentTeacherForm.vue" | |
| 67 | +} ] | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/ErrorCodeConstants_手动操作
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentContactDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生联系人 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_contact") | |
| 16 | +@KeySequence("infra_student_contact_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentContactDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentContactMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生联系人 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentContactMapper extends BaseMapperX<InfraStudentContactDO> { | |
| 19 | + | |
| 20 | + default List<InfraStudentContactDO> selectListByStudentId(Long studentId) { | |
| 21 | + return selectList(InfraStudentContactDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentContactDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 31 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 32 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 33 | + | |
| 34 | +@Tag(name = "管理后台 - 学生") | |
| 35 | +@RestController | |
| 36 | +@RequestMapping("/infra/student") | |
| 37 | +@Validated | |
| 38 | +public class InfraStudentController { | |
| 39 | + | |
| 40 | + @Resource | |
| 41 | + private InfraStudentService studentService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建学生") | |
| 45 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 46 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 47 | + return success(studentService.createStudent(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新学生") | |
| 52 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 53 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 54 | + studentService.updateStudent(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除学生") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 62 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 63 | + studentService.deleteStudent(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得学生") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 71 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 72 | + InfraStudentDO student = studentService.getStudent(id); | |
| 73 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得学生分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 79 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 80 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 81 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/export-excel") | |
| 85 | + @Operation(summary = "导出学生 Excel") | |
| 86 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 87 | + @OperateLog(type = EXPORT) | |
| 88 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 89 | + HttpServletResponse response) throws IOException { | |
| 90 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 91 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 92 | + // 导出 Excel | |
| 93 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 94 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @GetMapping("/student-contact/list-by-student-id") | |
| 100 | + @Operation(summary = "获得学生联系人列表") | |
| 101 | + @Parameter(name = "studentId", description = "学生编号") | |
| 102 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 103 | + public CommonResult<List<InfraStudentContactDO>> getStudentContactListByStudentId(@RequestParam("studentId") Long studentId) { | |
| 104 | + return success(studentService.getStudentContactListByStudentId(studentId)); | |
| 105 | + } | |
| 106 | + | |
| 107 | + // ==================== 子表(学生班主任) ==================== | |
| 108 | + | |
| 109 | + @GetMapping("/student-teacher/get-by-student-id") | |
| 110 | + @Operation(summary = "获得学生班主任") | |
| 111 | + @Parameter(name = "studentId", description = "学生编号") | |
| 112 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 113 | + public CommonResult<InfraStudentTeacherDO> getStudentTeacherByStudentId(@RequestParam("studentId") Long studentId) { | |
| 114 | + return success(studentService.getStudentTeacherByStudentId(studentId)); | |
| 115 | + } | |
| 116 | + | |
| 117 | +} | |
| 0 | 118 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class InfraStudentSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 21 | + @NotEmpty(message = "名字不能为空") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 25 | + @NotEmpty(message = "简介不能为空") | |
| 26 | + private String description; | |
| 27 | + | |
| 28 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 29 | + @NotNull(message = "出生日期不能为空") | |
| 30 | + private LocalDateTime birthday; | |
| 31 | + | |
| 32 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 33 | + @NotNull(message = "性别不能为空") | |
| 34 | + private Integer sex; | |
| 35 | + | |
| 36 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 37 | + @NotNull(message = "是否有效不能为空") | |
| 38 | + private Boolean enabled; | |
| 39 | + | |
| 40 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 41 | + @NotEmpty(message = "头像不能为空") | |
| 42 | + private String avatar; | |
| 43 | + | |
| 44 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 45 | + @NotEmpty(message = "附件不能为空") | |
| 46 | + private String video; | |
| 47 | + | |
| 48 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 49 | + @NotEmpty(message = "备注不能为空") | |
| 50 | + private String memo; | |
| 51 | + | |
| 52 | + @Schema(description = "学生联系人列表") | |
| 53 | + private List<InfraStudentContactDO> studentContacts; | |
| 54 | + | |
| 55 | + @Schema(description = "学生班主任") | |
| 56 | + private InfraStudentTeacherDO studentTeacher; | |
| 57 | + | |
| 58 | +} | |
| 0 | 59 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 9 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 10 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Service 接口 | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +public interface InfraStudentService { | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * 创建学生 | |
| 21 | + * | |
| 22 | + * @param createReqVO 创建信息 | |
| 23 | + * @return 编号 | |
| 24 | + */ | |
| 25 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 更新学生 | |
| 29 | + * | |
| 30 | + * @param updateReqVO 更新信息 | |
| 31 | + */ | |
| 32 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * 删除学生 | |
| 36 | + * | |
| 37 | + * @param id 编号 | |
| 38 | + */ | |
| 39 | + void deleteStudent(Long id); | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * 获得学生 | |
| 43 | + * | |
| 44 | + * @param id 编号 | |
| 45 | + * @return 学生 | |
| 46 | + */ | |
| 47 | + InfraStudentDO getStudent(Long id); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得学生分页 | |
| 51 | + * | |
| 52 | + * @param pageReqVO 分页查询 | |
| 53 | + * @return 学生分页 | |
| 54 | + */ | |
| 55 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 56 | + | |
| 57 | + // ==================== 子表(学生联系人) ==================== | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * 获得学生联系人列表 | |
| 61 | + * | |
| 62 | + * @param studentId 学生编号 | |
| 63 | + * @return 学生联系人列表 | |
| 64 | + */ | |
| 65 | + List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId); | |
| 66 | + | |
| 67 | + // ==================== 子表(学生班主任) ==================== | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * 获得学生班主任 | |
| 71 | + * | |
| 72 | + * @param studentId 学生编号 | |
| 73 | + * @return 学生班主任 | |
| 74 | + */ | |
| 75 | + InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId); | |
| 76 | + | |
| 77 | +} | |
| 0 | 78 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentContactDO; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 13 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 15 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 18 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentContactMapper; | |
| 19 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentTeacherMapper; | |
| 20 | + | |
| 21 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * 学生 Service 实现类 | |
| 26 | + * | |
| 27 | + * @author 芋道源码 | |
| 28 | + */ | |
| 29 | +@Service | |
| 30 | +@Validated | |
| 31 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 32 | + | |
| 33 | + @Resource | |
| 34 | + private InfraStudentMapper studentMapper; | |
| 35 | + @Resource | |
| 36 | + private InfraStudentContactMapper studentContactMapper; | |
| 37 | + @Resource | |
| 38 | + private InfraStudentTeacherMapper studentTeacherMapper; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + @Transactional(rollbackFor = Exception.class) | |
| 42 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 43 | + // 插入 | |
| 44 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 45 | + studentMapper.insert(student); | |
| 46 | + | |
| 47 | + // 插入子表 | |
| 48 | + createStudentContactList(student.getId(), createReqVO.getStudentContacts()); | |
| 49 | + createStudentTeacher(student.getId(), createReqVO.getStudentTeacher()); | |
| 50 | + // 返回 | |
| 51 | + return student.getId(); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + @Transactional(rollbackFor = Exception.class) | |
| 56 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 57 | + // 校验存在 | |
| 58 | + validateStudentExists(updateReqVO.getId()); | |
| 59 | + // 更新 | |
| 60 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 61 | + studentMapper.updateById(updateObj); | |
| 62 | + | |
| 63 | + // 更新子表 | |
| 64 | + updateStudentContactList(updateReqVO.getId(), updateReqVO.getStudentContacts()); | |
| 65 | + updateStudentTeacher(updateReqVO.getId(), updateReqVO.getStudentTeacher()); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @Override | |
| 69 | + @Transactional(rollbackFor = Exception.class) | |
| 70 | + public void deleteStudent(Long id) { | |
| 71 | + // 校验存在 | |
| 72 | + validateStudentExists(id); | |
| 73 | + // 删除 | |
| 74 | + studentMapper.deleteById(id); | |
| 75 | + | |
| 76 | + // 删除子表 | |
| 77 | + deleteStudentContactByStudentId(id); | |
| 78 | + deleteStudentTeacherByStudentId(id); | |
| 79 | + } | |
| 80 | + | |
| 81 | + private void validateStudentExists(Long id) { | |
| 82 | + if (studentMapper.selectById(id) == null) { | |
| 83 | + throw exception(STUDENT_NOT_EXISTS); | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + @Override | |
| 88 | + public InfraStudentDO getStudent(Long id) { | |
| 89 | + return studentMapper.selectById(id); | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 94 | + return studentMapper.selectPage(pageReqVO); | |
| 95 | + } | |
| 96 | + | |
| 97 | + // ==================== 子表(学生联系人) ==================== | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public List<InfraStudentContactDO> getStudentContactListByStudentId(Long studentId) { | |
| 101 | + return studentContactMapper.selectListByStudentId(studentId); | |
| 102 | + } | |
| 103 | + | |
| 104 | + private void createStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 105 | + list.forEach(o -> o.setStudentId(studentId)); | |
| 106 | + studentContactMapper.insertBatch(list); | |
| 107 | + } | |
| 108 | + | |
| 109 | + private void updateStudentContactList(Long studentId, List<InfraStudentContactDO> list) { | |
| 110 | + deleteStudentContactByStudentId(studentId); | |
| 111 | + list.forEach(o -> o.setId(null).setUpdater(null).setUpdateTime(null)); // 解决更新情况下:1)id 冲突;2)updateTime 不更新 | |
| 112 | + createStudentContactList(studentId, list); | |
| 113 | + } | |
| 114 | + | |
| 115 | + private void deleteStudentContactByStudentId(Long studentId) { | |
| 116 | + studentContactMapper.deleteByStudentId(studentId); | |
| 117 | + } | |
| 118 | + | |
| 119 | + // ==================== 子表(学生班主任) ==================== | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public InfraStudentTeacherDO getStudentTeacherByStudentId(Long studentId) { | |
| 123 | + return studentTeacherMapper.selectByStudentId(studentId); | |
| 124 | + } | |
| 125 | + | |
| 126 | + private void createStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 127 | + if (studentTeacher == null) { | |
| 128 | + return; | |
| 129 | + } | |
| 130 | + studentTeacher.setStudentId(studentId); | |
| 131 | + studentTeacherMapper.insert(studentTeacher); | |
| 132 | + } | |
| 133 | + | |
| 134 | + private void updateStudentTeacher(Long studentId, InfraStudentTeacherDO studentTeacher) { | |
| 135 | + if (studentTeacher == null) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + studentTeacher.setStudentId(studentId); | |
| 139 | + studentTeacher.setUpdater(null).setUpdateTime(null); // 解决更新情况下:updateTime 不更新 | |
| 140 | + studentTeacherMapper.insertOrUpdate(studentTeacher); | |
| 141 | + } | |
| 142 | + | |
| 143 | + private void deleteStudentTeacherByStudentId(Long studentId) { | |
| 144 | + studentTeacherMapper.deleteByStudentId(studentId); | |
| 145 | + } | |
| 146 | + | |
| 147 | +} | |
| 0 | 148 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentTeacherDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生班主任 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student_teacher") | |
| 16 | +@KeySequence("infra_student_teacher_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentTeacherDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 学生编号 | |
| 32 | + */ | |
| 33 | + private Long studentId; | |
| 34 | + /** | |
| 35 | + * 名字 | |
| 36 | + */ | |
| 37 | + private String name; | |
| 38 | + /** | |
| 39 | + * 简介 | |
| 40 | + */ | |
| 41 | + private String description; | |
| 42 | + /** | |
| 43 | + * 出生日期 | |
| 44 | + */ | |
| 45 | + private LocalDateTime birthday; | |
| 46 | + /** | |
| 47 | + * 性别 | |
| 48 | + * | |
| 49 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 50 | + */ | |
| 51 | + private Integer sex; | |
| 52 | + /** | |
| 53 | + * 是否有效 | |
| 54 | + * | |
| 55 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 56 | + */ | |
| 57 | + private Boolean enabled; | |
| 58 | + /** | |
| 59 | + * 头像 | |
| 60 | + */ | |
| 61 | + private String avatar; | |
| 62 | + /** | |
| 63 | + * 附件 | |
| 64 | + */ | |
| 65 | + private String video; | |
| 66 | + /** | |
| 67 | + * 备注 | |
| 68 | + */ | |
| 69 | + private String memo; | |
| 70 | + | |
| 71 | +} | |
| 0 | 72 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/java/InfraStudentTeacherMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 9 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentTeacherDO; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生班主任 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentTeacherMapper extends BaseMapperX<InfraStudentTeacherDO> { | |
| 19 | + | |
| 20 | + default InfraStudentTeacherDO selectByStudentId(Long studentId) { | |
| 21 | + return selectOne(InfraStudentTeacherDO::getStudentId, studentId); | |
| 22 | + } | |
| 23 | + | |
| 24 | + default int deleteByStudentId(Long studentId) { | |
| 25 | + return delete(InfraStudentTeacherDO::getStudentId, studentId); | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | |
| 0 | 29 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 54 | + | |
| 55 | +// ==================== 子表(学生联系人) ==================== | |
| 56 | + | |
| 57 | + // 获得学生联系人列表 | |
| 58 | + export function getStudentContactListByStudentId(studentId) { | |
| 59 | + return request({ | |
| 60 | + url: `/infra/student/student-contact/list-by-student-id?studentId=` + studentId, | |
| 61 | + method: 'get' | |
| 62 | + }) | |
| 63 | + } | |
| 64 | + | |
| 65 | +// ==================== 子表(学生班主任) ==================== | |
| 66 | + | |
| 67 | + // 获得学生班主任 | |
| 68 | + export function getStudentTeacherByStudentId(studentId) { | |
| 69 | + return request({ | |
| 70 | + url: `/infra/student/student-teacher/get-by-student-id?studentId=` + studentId, | |
| 71 | + method: 'get' | |
| 72 | + }) | |
| 73 | + } | |
| 74 | + | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/StudentContactForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + v-loading="formLoading" | |
| 8 | + label-width="0px" | |
| 9 | + :inline-message="true" | |
| 10 | + > | |
| 11 | + <el-table :data="formData" class="-mt-10px"> | |
| 12 | + <el-table-column label="序号" type="index" width="100" /> | |
| 13 | + <el-table-column label="名字" min-width="150"> | |
| 14 | + <template v-slot="{ row, $index }"> | |
| 15 | + <el-form-item :prop="`${$index}.name`" :rules="formRules.name" class="mb-0px!"> | |
| 16 | + <el-input v-model="row.name" placeholder="请输入名字" /> | |
| 17 | + </el-form-item> | |
| 18 | + </template> | |
| 19 | + </el-table-column> | |
| 20 | + <el-table-column label="简介" min-width="200"> | |
| 21 | + <template v-slot="{ row, $index }"> | |
| 22 | + <el-form-item :prop="`${$index}.description`" :rules="formRules.description" class="mb-0px!"> | |
| 23 | + <el-input v-model="row.description" type="textarea" placeholder="请输入简介" /> | |
| 24 | + </el-form-item> | |
| 25 | + </template> | |
| 26 | + </el-table-column> | |
| 27 | + <el-table-column label="出生日期" min-width="150"> | |
| 28 | + <template v-slot="{ row, $index }"> | |
| 29 | + <el-form-item :prop="`${$index}.birthday`" :rules="formRules.birthday" class="mb-0px!"> | |
| 30 | + <el-date-picker clearable v-model="row.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 31 | + </el-form-item> | |
| 32 | + </template> | |
| 33 | + </el-table-column> | |
| 34 | + <el-table-column label="性别" min-width="150"> | |
| 35 | + <template v-slot="{ row, $index }"> | |
| 36 | + <el-form-item :prop="`${$index}.sex`" :rules="formRules.sex" class="mb-0px!"> | |
| 37 | + <el-select v-model="row.sex" placeholder="请选择性别"> | |
| 38 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 39 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 40 | + </el-select> | |
| 41 | + </el-form-item> | |
| 42 | + </template> | |
| 43 | + </el-table-column> | |
| 44 | + <el-table-column label="是否有效" min-width="150"> | |
| 45 | + <template v-slot="{ row, $index }"> | |
| 46 | + <el-form-item :prop="`${$index}.enabled`" :rules="formRules.enabled" class="mb-0px!"> | |
| 47 | + <el-radio-group v-model="row.enabled"> | |
| 48 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 49 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 50 | + </el-radio-group> | |
| 51 | + </el-form-item> | |
| 52 | + </template> | |
| 53 | + </el-table-column> | |
| 54 | + <el-table-column label="头像" min-width="200"> | |
| 55 | + <template v-slot="{ row, $index }"> | |
| 56 | + <el-form-item :prop="`${$index}.avatar`" :rules="formRules.avatar" class="mb-0px!"> | |
| 57 | + <ImageUpload v-model="row.avatar"/> | |
| 58 | + </el-form-item> | |
| 59 | + </template> | |
| 60 | + </el-table-column> | |
| 61 | + <el-table-column label="附件" min-width="200"> | |
| 62 | + <template v-slot="{ row, $index }"> | |
| 63 | + <el-form-item :prop="`${$index}.video`" :rules="formRules.video" class="mb-0px!"> | |
| 64 | + <FileUpload v-model="row.video"/> | |
| 65 | + </el-form-item> | |
| 66 | + </template> | |
| 67 | + </el-table-column> | |
| 68 | + <el-table-column label="备注" min-width="400"> | |
| 69 | + <template v-slot="{ row, $index }"> | |
| 70 | + <el-form-item :prop="`${$index}.memo`" :rules="formRules.memo" class="mb-0px!"> | |
| 71 | + <Editor v-model="row.memo" :min-height="192"/> | |
| 72 | + </el-form-item> | |
| 73 | + </template> | |
| 74 | + </el-table-column> | |
| 75 | + <el-table-column align="center" fixed="right" label="操作" width="60"> | |
| 76 | + <template v-slot="{ $index }"> | |
| 77 | + <el-link @click="handleDelete($index)">—</el-link> | |
| 78 | + </template> | |
| 79 | + </el-table-column> | |
| 80 | + </el-table> | |
| 81 | + </el-form> | |
| 82 | + <el-row justify="center" class="mt-3"> | |
| 83 | + <el-button @click="handleAdd" round>+ 添加学生联系人</el-button> | |
| 84 | + </el-row> | |
| 85 | + </div> | |
| 86 | +</template> | |
| 87 | + | |
| 88 | +<script> | |
| 89 | + import * as StudentApi from '@/api/infra/demo'; | |
| 90 | + import ImageUpload from '@/components/ImageUpload'; | |
| 91 | + import FileUpload from '@/components/FileUpload'; | |
| 92 | + import Editor from '@/components/Editor'; | |
| 93 | + export default { | |
| 94 | + name: "StudentContactForm", | |
| 95 | + components: { | |
| 96 | + ImageUpload, | |
| 97 | + FileUpload, | |
| 98 | + Editor, | |
| 99 | + }, | |
| 100 | + props:[ | |
| 101 | + 'studentId' | |
| 102 | + ],// 学生编号(主表的关联字段) | |
| 103 | + data() { | |
| 104 | + return { | |
| 105 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 106 | + formLoading: false, | |
| 107 | + // 表单参数 | |
| 108 | + formData: [], | |
| 109 | + // 表单校验 | |
| 110 | + formRules: { | |
| 111 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 112 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 113 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 114 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 115 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 116 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 117 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 118 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 119 | + }, | |
| 120 | + }; | |
| 121 | + }, | |
| 122 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 123 | + studentId:{ | |
| 124 | + handler(val) { | |
| 125 | + // 1. 重置表单 | |
| 126 | + this.formData = [] | |
| 127 | + // 2. val 非空,则加载数据 | |
| 128 | + if (!val) { | |
| 129 | + return; | |
| 130 | + } | |
| 131 | + try { | |
| 132 | + this.formLoading = true; | |
| 133 | + // 这里还是需要获取一下 this 的不然取不到 formData | |
| 134 | + const that = this; | |
| 135 | + StudentApi.getStudentContactListByStudentId(val).then(function (res){ | |
| 136 | + that.formData = res.data; | |
| 137 | + }) | |
| 138 | + } finally { | |
| 139 | + this.formLoading = false; | |
| 140 | + } | |
| 141 | + }, | |
| 142 | + immediate: true | |
| 143 | + } | |
| 144 | + }, | |
| 145 | + methods: { | |
| 146 | + /** 新增按钮操作 */ | |
| 147 | + handleAdd() { | |
| 148 | + const row = { | |
| 149 | + id: undefined, | |
| 150 | + studentId: undefined, | |
| 151 | + name: undefined, | |
| 152 | + description: undefined, | |
| 153 | + birthday: undefined, | |
| 154 | + sex: undefined, | |
| 155 | + enabled: undefined, | |
| 156 | + avatar: undefined, | |
| 157 | + video: undefined, | |
| 158 | + memo: undefined, | |
| 159 | + } | |
| 160 | + row.studentId = this.studentId; | |
| 161 | + this.formData.push(row); | |
| 162 | + }, | |
| 163 | + /** 删除按钮操作 */ | |
| 164 | + handleDelete(index) { | |
| 165 | + this.formData.splice(index, 1); | |
| 166 | + }, | |
| 167 | + /** 表单校验 */ | |
| 168 | + validate(){ | |
| 169 | + return this.$refs["formRef"].validate(); | |
| 170 | + }, | |
| 171 | + /** 表单值 */ | |
| 172 | + getData(){ | |
| 173 | + return this.formData; | |
| 174 | + } | |
| 175 | + } | |
| 176 | + }; | |
| 177 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <!-- 子表的表单 --> | |
| 38 | + <el-tabs v-model="subTabsName"> | |
| 39 | + <el-tab-pane label="学生联系人" name="studentContact"> | |
| 40 | + <StudentContactForm ref="studentContactFormRef" :student-id="formData.id" /> | |
| 41 | + </el-tab-pane> | |
| 42 | + <el-tab-pane label="学生班主任" name="studentTeacher"> | |
| 43 | + <StudentTeacherForm ref="studentTeacherFormRef" :student-id="formData.id" /> | |
| 44 | + </el-tab-pane> | |
| 45 | + </el-tabs> | |
| 46 | + <div slot="footer" class="dialog-footer"> | |
| 47 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 48 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 49 | + </div> | |
| 50 | + </el-dialog> | |
| 51 | + </div> | |
| 52 | +</template> | |
| 53 | + | |
| 54 | +<script> | |
| 55 | + import * as StudentApi from '@/api/infra/demo'; | |
| 56 | + import ImageUpload from '@/components/ImageUpload'; | |
| 57 | + import FileUpload from '@/components/FileUpload'; | |
| 58 | + import Editor from '@/components/Editor'; | |
| 59 | + import StudentContactForm from './components/StudentContactForm.vue' | |
| 60 | + import StudentTeacherForm from './components/StudentTeacherForm.vue' | |
| 61 | + export default { | |
| 62 | + name: "StudentForm", | |
| 63 | + components: { | |
| 64 | + ImageUpload, | |
| 65 | + FileUpload, | |
| 66 | + Editor, | |
| 67 | + StudentContactForm, | |
| 68 | + StudentTeacherForm, | |
| 69 | + }, | |
| 70 | + data() { | |
| 71 | + return { | |
| 72 | + // 弹出层标题 | |
| 73 | + dialogTitle: "", | |
| 74 | + // 是否显示弹出层 | |
| 75 | + dialogVisible: false, | |
| 76 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 77 | + formLoading: false, | |
| 78 | + // 表单参数 | |
| 79 | + formData: { | |
| 80 | + id: undefined, | |
| 81 | + name: undefined, | |
| 82 | + description: undefined, | |
| 83 | + birthday: undefined, | |
| 84 | + sex: undefined, | |
| 85 | + enabled: undefined, | |
| 86 | + avatar: undefined, | |
| 87 | + video: undefined, | |
| 88 | + memo: undefined, | |
| 89 | + }, | |
| 90 | + // 表单校验 | |
| 91 | + formRules: { | |
| 92 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 93 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 94 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 95 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 96 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 97 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 98 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 99 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 100 | + }, | |
| 101 | + /** 子表的表单 */ | |
| 102 | + subTabsName: 'studentContact' | |
| 103 | + }; | |
| 104 | + }, | |
| 105 | + methods: { | |
| 106 | + /** 打开弹窗 */ | |
| 107 | + async open(id) { | |
| 108 | + this.dialogVisible = true; | |
| 109 | + this.reset(); | |
| 110 | + // 修改时,设置数据 | |
| 111 | + if (id) { | |
| 112 | + this.formLoading = true; | |
| 113 | + try { | |
| 114 | + const res = await StudentApi.getStudent(id); | |
| 115 | + this.formData = res.data; | |
| 116 | + this.title = "修改学生"; | |
| 117 | + } finally { | |
| 118 | + this.formLoading = false; | |
| 119 | + } | |
| 120 | + } | |
| 121 | + this.title = "新增学生"; | |
| 122 | + }, | |
| 123 | + /** 提交按钮 */ | |
| 124 | + async submitForm() { | |
| 125 | + // 校验主表 | |
| 126 | + await this.$refs["formRef"].validate(); | |
| 127 | + // 校验子表 | |
| 128 | + try { | |
| 129 | + await this.$refs['studentContactFormRef'].validate(); | |
| 130 | + } catch (e) { | |
| 131 | + this.subTabsName = 'studentContact'; | |
| 132 | + return; | |
| 133 | + } | |
| 134 | + try { | |
| 135 | + await this.$refs['studentTeacherFormRef'].validate(); | |
| 136 | + } catch (e) { | |
| 137 | + this.subTabsName = 'studentTeacher'; | |
| 138 | + return; | |
| 139 | + } | |
| 140 | + this.formLoading = true; | |
| 141 | + try { | |
| 142 | + const data = this.formData; | |
| 143 | + // 拼接子表的数据 | |
| 144 | + data.studentContacts = this.$refs['studentContactFormRef'].getData(); | |
| 145 | + data.studentTeacher = this.$refs['studentTeacherFormRef'].getData(); | |
| 146 | + // 修改的提交 | |
| 147 | + if (data.id) { | |
| 148 | + await StudentApi.updateStudent(data); | |
| 149 | + this.$modal.msgSuccess("修改成功"); | |
| 150 | + this.dialogVisible = false; | |
| 151 | + this.$emit('success'); | |
| 152 | + return; | |
| 153 | + } | |
| 154 | + // 添加的提交 | |
| 155 | + await StudentApi.createStudent(data); | |
| 156 | + this.$modal.msgSuccess("新增成功"); | |
| 157 | + this.dialogVisible = false; | |
| 158 | + this.$emit('success'); | |
| 159 | + } finally { | |
| 160 | + this.formLoading = false; | |
| 161 | + } | |
| 162 | + }, | |
| 163 | + /** 表单重置 */ | |
| 164 | + reset() { | |
| 165 | + this.formData = { | |
| 166 | + id: undefined, | |
| 167 | + name: undefined, | |
| 168 | + description: undefined, | |
| 169 | + birthday: undefined, | |
| 170 | + sex: undefined, | |
| 171 | + enabled: undefined, | |
| 172 | + avatar: undefined, | |
| 173 | + video: undefined, | |
| 174 | + memo: undefined, | |
| 175 | + }; | |
| 176 | + this.resetForm("formRef"); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + }; | |
| 180 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/StudentTeacherForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <el-form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + label-width="100px" | |
| 8 | + v-loading="formLoading" | |
| 9 | + > | |
| 10 | + <el-form-item label="名字" prop="name"> | |
| 11 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 12 | + </el-form-item> | |
| 13 | + <el-form-item label="简介" prop="description"> | |
| 14 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入简介" /> | |
| 15 | + </el-form-item> | |
| 16 | + <el-form-item label="出生日期" prop="birthday"> | |
| 17 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 18 | + </el-form-item> | |
| 19 | + <el-form-item label="性别" prop="sex"> | |
| 20 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 21 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 22 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 23 | + </el-select> | |
| 24 | + </el-form-item> | |
| 25 | + <el-form-item label="是否有效" prop="enabled"> | |
| 26 | + <el-radio-group v-model="formData.enabled"> | |
| 27 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 28 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 29 | + </el-radio-group> | |
| 30 | + </el-form-item> | |
| 31 | + <el-form-item label="头像"> | |
| 32 | + <ImageUpload v-model="formData.avatar"/> | |
| 33 | + </el-form-item> | |
| 34 | + <el-form-item label="附件"> | |
| 35 | + <FileUpload v-model="formData.video"/> | |
| 36 | + </el-form-item> | |
| 37 | + <el-form-item label="备注"> | |
| 38 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 39 | + </el-form-item> | |
| 40 | + </el-form> | |
| 41 | + </div> | |
| 42 | +</template> | |
| 43 | + | |
| 44 | +<script> | |
| 45 | + import * as StudentApi from '@/api/infra/demo'; | |
| 46 | + import ImageUpload from '@/components/ImageUpload'; | |
| 47 | + import FileUpload from '@/components/FileUpload'; | |
| 48 | + import Editor from '@/components/Editor'; | |
| 49 | + export default { | |
| 50 | + name: "StudentTeacherForm", | |
| 51 | + components: { | |
| 52 | + ImageUpload, | |
| 53 | + FileUpload, | |
| 54 | + Editor, | |
| 55 | + }, | |
| 56 | + props:[ | |
| 57 | + 'studentId' | |
| 58 | + ],// 学生编号(主表的关联字段) | |
| 59 | + data() { | |
| 60 | + return { | |
| 61 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 62 | + formLoading: false, | |
| 63 | + // 表单参数 | |
| 64 | + formData: [], | |
| 65 | + // 表单校验 | |
| 66 | + formRules: { | |
| 67 | + studentId: [{ required: true, message: "学生编号不能为空", trigger: "blur" }], | |
| 68 | + name: [{ required: true, message: "名字不能为空", trigger: "blur" }], | |
| 69 | + description: [{ required: true, message: "简介不能为空", trigger: "blur" }], | |
| 70 | + birthday: [{ required: true, message: "出生日期不能为空", trigger: "blur" }], | |
| 71 | + sex: [{ required: true, message: "性别不能为空", trigger: "change" }], | |
| 72 | + enabled: [{ required: true, message: "是否有效不能为空", trigger: "blur" }], | |
| 73 | + avatar: [{ required: true, message: "头像不能为空", trigger: "blur" }], | |
| 74 | + memo: [{ required: true, message: "备注不能为空", trigger: "blur" }], | |
| 75 | + }, | |
| 76 | + }; | |
| 77 | + }, | |
| 78 | + watch:{/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 79 | + studentId:{ | |
| 80 | + handler(val) { | |
| 81 | + // 1. 重置表单 | |
| 82 | + this.formData = { | |
| 83 | + id: undefined, | |
| 84 | + studentId: undefined, | |
| 85 | + name: undefined, | |
| 86 | + description: undefined, | |
| 87 | + birthday: undefined, | |
| 88 | + sex: undefined, | |
| 89 | + enabled: undefined, | |
| 90 | + avatar: undefined, | |
| 91 | + video: undefined, | |
| 92 | + memo: undefined, | |
| 93 | + } | |
| 94 | + // 2. val 非空,则加载数据 | |
| 95 | + if (!val) { | |
| 96 | + return; | |
| 97 | + } | |
| 98 | + try { | |
| 99 | + this.formLoading = true; | |
| 100 | + // 这里还是需要获取一下 this 的不然取不到 formData | |
| 101 | + const that = this; | |
| 102 | + StudentApi.getStudentTeacherByStudentId(val).then(function (res){ | |
| 103 | + const data = res.data; | |
| 104 | + if (!data) { | |
| 105 | + return | |
| 106 | + } | |
| 107 | + that.formData = data; | |
| 108 | + }) | |
| 109 | + } finally { | |
| 110 | + this.formLoading = false; | |
| 111 | + } | |
| 112 | + }, | |
| 113 | + immediate: true | |
| 114 | + } | |
| 115 | + }, | |
| 116 | + methods: { | |
| 117 | + /** 表单校验 */ | |
| 118 | + validate(){ | |
| 119 | + return this.$refs["formRef"].validate(); | |
| 120 | + }, | |
| 121 | + /** 表单值 */ | |
| 122 | + getData(){ | |
| 123 | + return this.formData; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + }; | |
| 127 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/vue/index
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 搜索工作栏 --> | |
| 4 | + <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> | |
| 5 | + <el-form-item label="名字" prop="name"> | |
| 6 | + <el-input v-model="queryParams.name" placeholder="请输入名字" clearable @keyup.enter.native="handleQuery"/> | |
| 7 | + </el-form-item> | |
| 8 | + <el-form-item label="出生日期" prop="birthday"> | |
| 9 | + <el-date-picker clearable v-model="queryParams.birthday" type="date" value-format="yyyy-MM-dd" placeholder="选择出生日期" /> | |
| 10 | + </el-form-item> | |
| 11 | + <el-form-item label="性别" prop="sex"> | |
| 12 | + <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small"> | |
| 13 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 14 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 15 | + </el-select> | |
| 16 | + </el-form-item> | |
| 17 | + <el-form-item label="是否有效" prop="enabled"> | |
| 18 | + <el-select v-model="queryParams.enabled" placeholder="请选择是否有效" clearable size="small"> | |
| 19 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 20 | + :key="dict.value" :label="dict.label" :value="dict.value"/> | |
| 21 | + </el-select> | |
| 22 | + </el-form-item> | |
| 23 | + <el-form-item label="创建时间" prop="createTime"> | |
| 24 | + <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" | |
| 25 | + range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" /> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item> | |
| 28 | + <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> | |
| 29 | + <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> | |
| 30 | + </el-form-item> | |
| 31 | + </el-form> | |
| 32 | + | |
| 33 | + <!-- 操作工具栏 --> | |
| 34 | + <el-row :gutter="10" class="mb8"> | |
| 35 | + <el-col :span="1.5"> | |
| 36 | + <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | |
| 37 | + v-hasPermi="['infra:student:create']">新增</el-button> | |
| 38 | + </el-col> | |
| 39 | + <el-col :span="1.5"> | |
| 40 | + <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | |
| 41 | + v-hasPermi="['infra:student:export']">导出</el-button> | |
| 42 | + </el-col> | |
| 43 | + <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | |
| 44 | + </el-row> | |
| 45 | + | |
| 46 | + <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 47 | + <el-table-column label="编号" align="center" prop="id"> | |
| 48 | + <template v-slot="scope"> | |
| 49 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.id" /> | |
| 50 | + </template> | |
| 51 | + </el-table-column> | |
| 52 | + <el-table-column label="名字" align="center" prop="name"> | |
| 53 | + <template v-slot="scope"> | |
| 54 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.name" /> | |
| 55 | + </template> | |
| 56 | + </el-table-column> | |
| 57 | + <el-table-column label="简介" align="center" prop="description"> | |
| 58 | + <template v-slot="scope"> | |
| 59 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.description" /> | |
| 60 | + </template> | |
| 61 | + </el-table-column> | |
| 62 | + <el-table-column label="出生日期" align="center" prop="birthday" width="180"> | |
| 63 | + <template v-slot="scope"> | |
| 64 | + <span>{{ parseTime(scope.row.birthday) }}</span> | |
| 65 | + </template> | |
| 66 | + </el-table-column> | |
| 67 | + <el-table-column label="性别" align="center" prop="sex"> | |
| 68 | + <template v-slot="scope"> | |
| 69 | + <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.sex" /> | |
| 70 | + </template> | |
| 71 | + </el-table-column> | |
| 72 | + <el-table-column label="是否有效" align="center" prop="enabled"> | |
| 73 | + <template v-slot="scope"> | |
| 74 | + <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.enabled" /> | |
| 75 | + </template> | |
| 76 | + </el-table-column> | |
| 77 | + <el-table-column label="头像" align="center" prop="avatar"> | |
| 78 | + <template v-slot="scope"> | |
| 79 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.avatar" /> | |
| 80 | + </template> | |
| 81 | + </el-table-column> | |
| 82 | + <el-table-column label="附件" align="center" prop="video"> | |
| 83 | + <template v-slot="scope"> | |
| 84 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.video" /> | |
| 85 | + </template> | |
| 86 | + </el-table-column> | |
| 87 | + <el-table-column label="备注" align="center" prop="memo"> | |
| 88 | + <template v-slot="scope"> | |
| 89 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.memo" /> | |
| 90 | + </template> | |
| 91 | + </el-table-column> | |
| 92 | + <el-table-column label="创建时间" align="center" prop="createTime" width="180"> | |
| 93 | + <template v-slot="scope"> | |
| 94 | + <span>{{ parseTime(scope.row.createTime) }}</span> | |
| 95 | + </template> | |
| 96 | + </el-table-column> | |
| 97 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | |
| 98 | + <template v-slot="scope"> | |
| 99 | + <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.id)" | |
| 100 | + v-hasPermi="['infra:student:update']">修改</el-button> | |
| 101 | + <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" | |
| 102 | + v-hasPermi="['infra:student:delete']">删除</el-button> | |
| 103 | + </template> | |
| 104 | + </el-table-column> | |
| 105 | + </el-table> | |
| 106 | + <!-- 分页组件 --> | |
| 107 | + <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" | |
| 108 | + @pagination="getList"/> | |
| 109 | + <!-- 对话框(添加 / 修改) --> | |
| 110 | + <StudentForm ref="formRef" @success="getList" /> | |
| 111 | + </div> | |
| 112 | +</template> | |
| 113 | + | |
| 114 | +<script> | |
| 115 | +import * as StudentApi from '@/api/infra/demo'; | |
| 116 | +import StudentForm from './StudentForm.vue'; | |
| 117 | +export default { | |
| 118 | + name: "Student", | |
| 119 | + components: { | |
| 120 | + StudentForm, | |
| 121 | + }, | |
| 122 | + data() { | |
| 123 | + return { | |
| 124 | + // 遮罩层 | |
| 125 | + loading: true, | |
| 126 | + // 导出遮罩层 | |
| 127 | + exportLoading: false, | |
| 128 | + // 显示搜索条件 | |
| 129 | + showSearch: true, | |
| 130 | + // 总条数 | |
| 131 | + total: 0, | |
| 132 | + // 学生列表 | |
| 133 | + list: [], | |
| 134 | + // 是否展开,默认全部展开 | |
| 135 | + isExpandAll: true, | |
| 136 | + // 重新渲染表格状态 | |
| 137 | + refreshTable: true, | |
| 138 | + // 选中行 | |
| 139 | + currentRow: {}, | |
| 140 | + // 查询参数 | |
| 141 | + queryParams: { | |
| 142 | + pageNo: 1, | |
| 143 | + pageSize: 10, | |
| 144 | + name: null, | |
| 145 | + birthday: null, | |
| 146 | + sex: null, | |
| 147 | + enabled: null, | |
| 148 | + createTime: [], | |
| 149 | + }, | |
| 150 | + }; | |
| 151 | + }, | |
| 152 | + created() { | |
| 153 | + this.getList(); | |
| 154 | + }, | |
| 155 | + methods: { | |
| 156 | + /** 查询列表 */ | |
| 157 | + async getList() { | |
| 158 | + try { | |
| 159 | + this.loading = true; | |
| 160 | + const res = await StudentApi.getStudentPage(this.queryParams); | |
| 161 | + this.list = res.data.list; | |
| 162 | + this.total = res.data.total; | |
| 163 | + } finally { | |
| 164 | + this.loading = false; | |
| 165 | + } | |
| 166 | + }, | |
| 167 | + /** 搜索按钮操作 */ | |
| 168 | + handleQuery() { | |
| 169 | + this.queryParams.pageNo = 1; | |
| 170 | + this.getList(); | |
| 171 | + }, | |
| 172 | + /** 重置按钮操作 */ | |
| 173 | + resetQuery() { | |
| 174 | + this.resetForm("queryForm"); | |
| 175 | + this.handleQuery(); | |
| 176 | + }, | |
| 177 | + /** 添加/修改操作 */ | |
| 178 | + openForm(id) { | |
| 179 | + this.$refs["formRef"].open(id); | |
| 180 | + }, | |
| 181 | + /** 删除按钮操作 */ | |
| 182 | + async handleDelete(row) { | |
| 183 | + const id = row.id; | |
| 184 | + await this.$modal.confirm('是否确认删除学生编号为"' + id + '"的数据项?') | |
| 185 | + try { | |
| 186 | + await StudentApi.deleteStudent(id); | |
| 187 | + await this.getList(); | |
| 188 | + this.$modal.msgSuccess("删除成功"); | |
| 189 | + } catch {} | |
| 190 | + }, | |
| 191 | + /** 导出按钮操作 */ | |
| 192 | + async handleExport() { | |
| 193 | + await this.$modal.confirm('是否确认导出所有学生数据项?'); | |
| 194 | + try { | |
| 195 | + this.exportLoading = true; | |
| 196 | + const res = await StudentApi.exportStudentExcel(this.queryParams); | |
| 197 | + this.$download.excel(res.data, '学生.xls'); | |
| 198 | + } catch { | |
| 199 | + } finally { | |
| 200 | + this.exportLoading = false; | |
| 201 | + } | |
| 202 | + }, | |
| 203 | + } | |
| 204 | +}; | |
| 205 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_master_normal/xml/InfraStudentMapper
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
| 3 | +<mapper namespace="cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper"> | |
| 4 | + | |
| 5 | + <!-- | |
| 6 | + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 | |
| 7 | + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 | |
| 8 | + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 | |
| 9 | + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ | |
| 10 | + --> | |
| 11 | + | |
| 12 | +</mapper> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/assert.json
0 → 100644
| 1 | +[ { | |
| 2 | + "contentPath" : "java/InfraStudentPageReqVO", | |
| 3 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentPageReqVO.java" | |
| 4 | +}, { | |
| 5 | + "contentPath" : "java/InfraStudentRespVO", | |
| 6 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentRespVO.java" | |
| 7 | +}, { | |
| 8 | + "contentPath" : "java/InfraStudentSaveReqVO", | |
| 9 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/vo/InfraStudentSaveReqVO.java" | |
| 10 | +}, { | |
| 11 | + "contentPath" : "java/InfraStudentController", | |
| 12 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/demo/InfraStudentController.java" | |
| 13 | +}, { | |
| 14 | + "contentPath" : "java/InfraStudentDO", | |
| 15 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/dataobject/demo/InfraStudentDO.java" | |
| 16 | +}, { | |
| 17 | + "contentPath" : "java/InfraStudentMapper", | |
| 18 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/demo/InfraStudentMapper.java" | |
| 19 | +}, { | |
| 20 | + "contentPath" : "xml/InfraStudentMapper", | |
| 21 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/resources/mapper/demo/InfraStudentMapper.xml" | |
| 22 | +}, { | |
| 23 | + "contentPath" : "java/InfraStudentServiceImpl", | |
| 24 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImpl.java" | |
| 25 | +}, { | |
| 26 | + "contentPath" : "java/InfraStudentService", | |
| 27 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentService.java" | |
| 28 | +}, { | |
| 29 | + "contentPath" : "java/InfraStudentServiceImplTest", | |
| 30 | + "filePath" : "yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/demo/InfraStudentServiceImplTest.java" | |
| 31 | +}, { | |
| 32 | + "contentPath" : "java/ErrorCodeConstants_手动操作", | |
| 33 | + "filePath" : "yudao-module-infra/yudao-module-infra-api/src/main/java/cn/iocoder/yudao/module/infra/enums/ErrorCodeConstants_手动操作.java" | |
| 34 | +}, { | |
| 35 | + "contentPath" : "sql/sql", | |
| 36 | + "filePath" : "sql/sql.sql" | |
| 37 | +}, { | |
| 38 | + "contentPath" : "sql/h2", | |
| 39 | + "filePath" : "sql/h2.sql" | |
| 40 | +}, { | |
| 41 | + "contentPath" : "vue/index", | |
| 42 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/index.vue" | |
| 43 | +}, { | |
| 44 | + "contentPath" : "js/student", | |
| 45 | + "filePath" : "yudao-ui-admin-vue2/src/api/infra/student.js" | |
| 46 | +}, { | |
| 47 | + "contentPath" : "vue/StudentForm", | |
| 48 | + "filePath" : "yudao-ui-admin-vue2/src/views/infra/demo/StudentForm.vue" | |
| 49 | +} ] | |
| 0 | 50 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/ErrorCodeConstants_手动操作
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentController
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo; | |
| 2 | + | |
| 3 | +import org.springframework.web.bind.annotation.*; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 7 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 8 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | + | |
| 11 | +import javax.validation.constraints.*; | |
| 12 | +import javax.validation.*; | |
| 13 | +import javax.servlet.http.*; | |
| 14 | +import java.util.*; | |
| 15 | +import java.io.IOException; | |
| 16 | + | |
| 17 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 18 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 19 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 20 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 21 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 22 | + | |
| 23 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 24 | + | |
| 25 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 26 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*; | |
| 27 | + | |
| 28 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 29 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 30 | +import cn.iocoder.yudao.module.infra.service.demo.InfraStudentService; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - 学生") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/infra/student") | |
| 35 | +@Validated | |
| 36 | +public class InfraStudentController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private InfraStudentService studentService; | |
| 40 | + | |
| 41 | + @PostMapping("/create") | |
| 42 | + @Operation(summary = "创建学生") | |
| 43 | + @PreAuthorize("@ss.hasPermission('infra:student:create')") | |
| 44 | + public CommonResult<Long> createStudent(@Valid @RequestBody InfraStudentSaveReqVO createReqVO) { | |
| 45 | + return success(studentService.createStudent(createReqVO)); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @PutMapping("/update") | |
| 49 | + @Operation(summary = "更新学生") | |
| 50 | + @PreAuthorize("@ss.hasPermission('infra:student:update')") | |
| 51 | + public CommonResult<Boolean> updateStudent(@Valid @RequestBody InfraStudentSaveReqVO updateReqVO) { | |
| 52 | + studentService.updateStudent(updateReqVO); | |
| 53 | + return success(true); | |
| 54 | + } | |
| 55 | + | |
| 56 | + @DeleteMapping("/delete") | |
| 57 | + @Operation(summary = "删除学生") | |
| 58 | + @Parameter(name = "id", description = "编号", required = true) | |
| 59 | + @PreAuthorize("@ss.hasPermission('infra:student:delete')") | |
| 60 | + public CommonResult<Boolean> deleteStudent(@RequestParam("id") Long id) { | |
| 61 | + studentService.deleteStudent(id); | |
| 62 | + return success(true); | |
| 63 | + } | |
| 64 | + | |
| 65 | + @GetMapping("/get") | |
| 66 | + @Operation(summary = "获得学生") | |
| 67 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 68 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 69 | + public CommonResult<InfraStudentRespVO> getStudent(@RequestParam("id") Long id) { | |
| 70 | + InfraStudentDO student = studentService.getStudent(id); | |
| 71 | + return success(BeanUtils.toBean(student, InfraStudentRespVO.class)); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/page") | |
| 75 | + @Operation(summary = "获得学生分页") | |
| 76 | + @PreAuthorize("@ss.hasPermission('infra:student:query')") | |
| 77 | + public CommonResult<PageResult<InfraStudentRespVO>> getStudentPage(@Valid InfraStudentPageReqVO pageReqVO) { | |
| 78 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(pageReqVO); | |
| 79 | + return success(BeanUtils.toBean(pageResult, InfraStudentRespVO.class)); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @GetMapping("/export-excel") | |
| 83 | + @Operation(summary = "导出学生 Excel") | |
| 84 | + @PreAuthorize("@ss.hasPermission('infra:student:export')") | |
| 85 | + @OperateLog(type = EXPORT) | |
| 86 | + public void exportStudentExcel(@Valid InfraStudentPageReqVO pageReqVO, | |
| 87 | + HttpServletResponse response) throws IOException { | |
| 88 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 89 | + List<InfraStudentDO> list = studentService.getStudentPage(pageReqVO).getList(); | |
| 90 | + // 导出 Excel | |
| 91 | + ExcelUtils.write(response, "学生.xls", "数据", InfraStudentRespVO.class, | |
| 92 | + BeanUtils.toBean(list, InfraStudentRespVO.class)); | |
| 93 | + } | |
| 94 | + | |
| 95 | +} | |
| 0 | 96 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentDO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.dataobject.demo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import java.time.LocalDateTime; | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | +import com.baomidou.mybatisplus.annotation.*; | |
| 8 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 DO | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@TableName("infra_student") | |
| 16 | +@KeySequence("infra_student_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +@Builder | |
| 21 | +@NoArgsConstructor | |
| 22 | +@AllArgsConstructor | |
| 23 | +public class InfraStudentDO extends BaseDO { | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 编号 | |
| 27 | + */ | |
| 28 | + @TableId | |
| 29 | + private Long id; | |
| 30 | + /** | |
| 31 | + * 名字 | |
| 32 | + */ | |
| 33 | + private String name; | |
| 34 | + /** | |
| 35 | + * 简介 | |
| 36 | + */ | |
| 37 | + private String description; | |
| 38 | + /** | |
| 39 | + * 出生日期 | |
| 40 | + */ | |
| 41 | + private LocalDateTime birthday; | |
| 42 | + /** | |
| 43 | + * 性别 | |
| 44 | + * | |
| 45 | + * 枚举 {@link TODO system_user_sex 对应的类} | |
| 46 | + */ | |
| 47 | + private Integer sex; | |
| 48 | + /** | |
| 49 | + * 是否有效 | |
| 50 | + * | |
| 51 | + * 枚举 {@link TODO infra_boolean_string 对应的类} | |
| 52 | + */ | |
| 53 | + private Boolean enabled; | |
| 54 | + /** | |
| 55 | + * 头像 | |
| 56 | + */ | |
| 57 | + private String avatar; | |
| 58 | + /** | |
| 59 | + * 附件 | |
| 60 | + */ | |
| 61 | + private String video; | |
| 62 | + /** | |
| 63 | + * 备注 | |
| 64 | + */ | |
| 65 | + private String memo; | |
| 66 | + | |
| 67 | +} | |
| 0 | 68 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentMapper
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.dal.mysql.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | + | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 8 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 9 | +import org.apache.ibatis.annotations.Mapper; | |
| 10 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * 学生 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface InfraStudentMapper extends BaseMapperX<InfraStudentDO> { | |
| 19 | + | |
| 20 | + default PageResult<InfraStudentDO> selectPage(InfraStudentPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<InfraStudentDO>() | |
| 22 | + .likeIfPresent(InfraStudentDO::getName, reqVO.getName()) | |
| 23 | + .eqIfPresent(InfraStudentDO::getBirthday, reqVO.getBirthday()) | |
| 24 | + .eqIfPresent(InfraStudentDO::getSex, reqVO.getSex()) | |
| 25 | + .eqIfPresent(InfraStudentDO::getEnabled, reqVO.getEnabled()) | |
| 26 | + .betweenIfPresent(InfraStudentDO::getCreateTime, reqVO.getCreateTime()) | |
| 27 | + .orderByDesc(InfraStudentDO::getId)); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentPageReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import lombok.*; | |
| 4 | +import java.util.*; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 11 | + | |
| 12 | +@Schema(description = "管理后台 - 学生分页 Request VO") | |
| 13 | +@Data | |
| 14 | +@EqualsAndHashCode(callSuper = true) | |
| 15 | +@ToString(callSuper = true) | |
| 16 | +public class InfraStudentPageReqVO extends PageParam { | |
| 17 | + | |
| 18 | + @Schema(description = "名字", example = "芋头") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "出生日期") | |
| 22 | + private LocalDateTime birthday; | |
| 23 | + | |
| 24 | + @Schema(description = "性别", example = "1") | |
| 25 | + private Integer sex; | |
| 26 | + | |
| 27 | + @Schema(description = "是否有效", example = "true") | |
| 28 | + private Boolean enabled; | |
| 29 | + | |
| 30 | + @Schema(description = "创建时间") | |
| 31 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 32 | + private LocalDateTime[] createTime; | |
| 33 | + | |
| 34 | +} | |
| 0 | 35 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentRespVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import java.util.*; | |
| 7 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | +import com.alibaba.excel.annotation.*; | |
| 10 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 11 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - 学生 Response VO") | |
| 14 | +@Data | |
| 15 | +@ExcelIgnoreUnannotated | |
| 16 | +public class InfraStudentRespVO { | |
| 17 | + | |
| 18 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 19 | + @ExcelProperty("编号") | |
| 20 | + private Long id; | |
| 21 | + | |
| 22 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 23 | + @ExcelProperty("名字") | |
| 24 | + private String name; | |
| 25 | + | |
| 26 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 27 | + @ExcelProperty("简介") | |
| 28 | + private String description; | |
| 29 | + | |
| 30 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 31 | + @ExcelProperty("出生日期") | |
| 32 | + private LocalDateTime birthday; | |
| 33 | + | |
| 34 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 35 | + @ExcelProperty(value = "性别", converter = DictConvert.class) | |
| 36 | + @DictFormat("system_user_sex") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 37 | + private Integer sex; | |
| 38 | + | |
| 39 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 40 | + @ExcelProperty(value = "是否有效", converter = DictConvert.class) | |
| 41 | + @DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中 | |
| 42 | + private Boolean enabled; | |
| 43 | + | |
| 44 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 45 | + @ExcelProperty("头像") | |
| 46 | + private String avatar; | |
| 47 | + | |
| 48 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 49 | + @ExcelProperty("附件") | |
| 50 | + private String video; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String memo; | |
| 55 | + | |
| 56 | + @Schema(description = "创建时间") | |
| 57 | + @ExcelProperty("创建时间") | |
| 58 | + private LocalDateTime createTime; | |
| 59 | + | |
| 60 | +} | |
| 0 | 61 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentSaveReqVO
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.controller.admin.demo.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.*; | |
| 5 | +import java.util.*; | |
| 6 | +import javax.validation.constraints.*; | |
| 7 | +import java.util.*; | |
| 8 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | + | |
| 11 | +@Schema(description = "管理后台 - 学生新增/修改 Request VO") | |
| 12 | +@Data | |
| 13 | +public class InfraStudentSaveReqVO { | |
| 14 | + | |
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 16 | + private Long id; | |
| 17 | + | |
| 18 | + @Schema(description = "名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋头") | |
| 19 | + @NotEmpty(message = "名字不能为空") | |
| 20 | + private String name; | |
| 21 | + | |
| 22 | + @Schema(description = "简介", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是介绍") | |
| 23 | + @NotEmpty(message = "简介不能为空") | |
| 24 | + private String description; | |
| 25 | + | |
| 26 | + @Schema(description = "出生日期", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 27 | + @NotNull(message = "出生日期不能为空") | |
| 28 | + private LocalDateTime birthday; | |
| 29 | + | |
| 30 | + @Schema(description = "性别", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 31 | + @NotNull(message = "性别不能为空") | |
| 32 | + private Integer sex; | |
| 33 | + | |
| 34 | + @Schema(description = "是否有效", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") | |
| 35 | + @NotNull(message = "是否有效不能为空") | |
| 36 | + private Boolean enabled; | |
| 37 | + | |
| 38 | + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png") | |
| 39 | + @NotEmpty(message = "头像不能为空") | |
| 40 | + private String avatar; | |
| 41 | + | |
| 42 | + @Schema(description = "附件", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.mp4") | |
| 43 | + @NotEmpty(message = "附件不能为空") | |
| 44 | + private String video; | |
| 45 | + | |
| 46 | + @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "我是备注") | |
| 47 | + @NotEmpty(message = "备注不能为空") | |
| 48 | + private String memo; | |
| 49 | + | |
| 50 | +} | |
| 0 | 51 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentService
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import java.util.*; | |
| 4 | +import javax.validation.*; | |
| 5 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 6 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 7 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 8 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 学生 Service 接口 | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +public interface InfraStudentService { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 创建学生 | |
| 19 | + * | |
| 20 | + * @param createReqVO 创建信息 | |
| 21 | + * @return 编号 | |
| 22 | + */ | |
| 23 | + Long createStudent(@Valid InfraStudentSaveReqVO createReqVO); | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 更新学生 | |
| 27 | + * | |
| 28 | + * @param updateReqVO 更新信息 | |
| 29 | + */ | |
| 30 | + void updateStudent(@Valid InfraStudentSaveReqVO updateReqVO); | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 删除学生 | |
| 34 | + * | |
| 35 | + * @param id 编号 | |
| 36 | + */ | |
| 37 | + void deleteStudent(Long id); | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 获得学生 | |
| 41 | + * | |
| 42 | + * @param id 编号 | |
| 43 | + * @return 学生 | |
| 44 | + */ | |
| 45 | + InfraStudentDO getStudent(Long id); | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * 获得学生分页 | |
| 49 | + * | |
| 50 | + * @param pageReqVO 分页查询 | |
| 51 | + * @return 学生分页 | |
| 52 | + */ | |
| 53 | + PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO); | |
| 54 | + | |
| 55 | +} | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentServiceImpl
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.springframework.stereotype.Service; | |
| 4 | +import javax.annotation.Resource; | |
| 5 | +import org.springframework.validation.annotation.Validated; | |
| 6 | +import org.springframework.transaction.annotation.Transactional; | |
| 7 | + | |
| 8 | +import java.util.*; | |
| 9 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 10 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 11 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 13 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 14 | + | |
| 15 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 18 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * 学生 Service 实现类 | |
| 22 | + * | |
| 23 | + * @author 芋道源码 | |
| 24 | + */ | |
| 25 | +@Service | |
| 26 | +@Validated | |
| 27 | +public class InfraStudentServiceImpl implements InfraStudentService { | |
| 28 | + | |
| 29 | + @Resource | |
| 30 | + private InfraStudentMapper studentMapper; | |
| 31 | + | |
| 32 | + @Override | |
| 33 | + public Long createStudent(InfraStudentSaveReqVO createReqVO) { | |
| 34 | + // 插入 | |
| 35 | + InfraStudentDO student = BeanUtils.toBean(createReqVO, InfraStudentDO.class); | |
| 36 | + studentMapper.insert(student); | |
| 37 | + // 返回 | |
| 38 | + return student.getId(); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public void updateStudent(InfraStudentSaveReqVO updateReqVO) { | |
| 43 | + // 校验存在 | |
| 44 | + validateStudentExists(updateReqVO.getId()); | |
| 45 | + // 更新 | |
| 46 | + InfraStudentDO updateObj = BeanUtils.toBean(updateReqVO, InfraStudentDO.class); | |
| 47 | + studentMapper.updateById(updateObj); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void deleteStudent(Long id) { | |
| 52 | + // 校验存在 | |
| 53 | + validateStudentExists(id); | |
| 54 | + // 删除 | |
| 55 | + studentMapper.deleteById(id); | |
| 56 | + } | |
| 57 | + | |
| 58 | + private void validateStudentExists(Long id) { | |
| 59 | + if (studentMapper.selectById(id) == null) { | |
| 60 | + throw exception(STUDENT_NOT_EXISTS); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Override | |
| 65 | + public InfraStudentDO getStudent(Long id) { | |
| 66 | + return studentMapper.selectById(id); | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public PageResult<InfraStudentDO> getStudentPage(InfraStudentPageReqVO pageReqVO) { | |
| 71 | + return studentMapper.selectPage(pageReqVO); | |
| 72 | + } | |
| 73 | + | |
| 74 | +} | |
| 0 | 75 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/java/InfraStudentServiceImplTest
0 → 100644
| 1 | +package cn.iocoder.yudao.module.infra.service.demo; | |
| 2 | + | |
| 3 | +import org.junit.jupiter.api.Disabled; | |
| 4 | +import org.junit.jupiter.api.Test; | |
| 5 | +import org.springframework.boot.test.mock.mockito.MockBean; | |
| 6 | + | |
| 7 | +import javax.annotation.Resource; | |
| 8 | + | |
| 9 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 10 | + | |
| 11 | +import cn.iocoder.yudao.module.infra.controller.admin.demo.vo.*; | |
| 12 | +import cn.iocoder.yudao.module.infra.dal.dataobject.demo.InfraStudentDO; | |
| 13 | +import cn.iocoder.yudao.module.infra.dal.mysql.demo.InfraStudentMapper; | |
| 14 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import org.springframework.context.annotation.Import; | |
| 18 | +import java.util.*; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | + | |
| 21 | +import static cn.hutool.core.util.RandomUtil.*; | |
| 22 | +import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.*; | |
| 23 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*; | |
| 24 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | |
| 25 | +import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.*; | |
| 26 | +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*; | |
| 27 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*; | |
| 28 | +import static org.junit.jupiter.api.Assertions.*; | |
| 29 | +import static org.mockito.Mockito.*; | |
| 30 | + | |
| 31 | +/** | |
| 32 | + * {@link InfraStudentServiceImpl} 的单元测试类 | |
| 33 | + * | |
| 34 | + * @author 芋道源码 | |
| 35 | + */ | |
| 36 | +@Import(InfraStudentServiceImpl.class) | |
| 37 | +public class InfraStudentServiceImplTest extends BaseDbUnitTest { | |
| 38 | + | |
| 39 | + @Resource | |
| 40 | + private InfraStudentServiceImpl studentService; | |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + private InfraStudentMapper studentMapper; | |
| 44 | + | |
| 45 | + @Test | |
| 46 | + public void testCreateStudent_success() { | |
| 47 | + // 准备参数 | |
| 48 | + InfraStudentSaveReqVO createReqVO = randomPojo(InfraStudentSaveReqVO.class).setId(null); | |
| 49 | + | |
| 50 | + // 调用 | |
| 51 | + Long studentId = studentService.createStudent(createReqVO); | |
| 52 | + // 断言 | |
| 53 | + assertNotNull(studentId); | |
| 54 | + // 校验记录的属性是否正确 | |
| 55 | + InfraStudentDO student = studentMapper.selectById(studentId); | |
| 56 | + assertPojoEquals(createReqVO, student, "id"); | |
| 57 | + } | |
| 58 | + | |
| 59 | + @Test | |
| 60 | + public void testUpdateStudent_success() { | |
| 61 | + // mock 数据 | |
| 62 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 63 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 64 | + // 准备参数 | |
| 65 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class, o -> { | |
| 66 | + o.setId(dbStudent.getId()); // 设置更新的 ID | |
| 67 | + }); | |
| 68 | + | |
| 69 | + // 调用 | |
| 70 | + studentService.updateStudent(updateReqVO); | |
| 71 | + // 校验是否更新正确 | |
| 72 | + InfraStudentDO student = studentMapper.selectById(updateReqVO.getId()); // 获取最新的 | |
| 73 | + assertPojoEquals(updateReqVO, student); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @Test | |
| 77 | + public void testUpdateStudent_notExists() { | |
| 78 | + // 准备参数 | |
| 79 | + InfraStudentSaveReqVO updateReqVO = randomPojo(InfraStudentSaveReqVO.class); | |
| 80 | + | |
| 81 | + // 调用, 并断言异常 | |
| 82 | + assertServiceException(() -> studentService.updateStudent(updateReqVO), STUDENT_NOT_EXISTS); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @Test | |
| 86 | + public void testDeleteStudent_success() { | |
| 87 | + // mock 数据 | |
| 88 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class); | |
| 89 | + studentMapper.insert(dbStudent);// @Sql: 先插入出一条存在的数据 | |
| 90 | + // 准备参数 | |
| 91 | + Long id = dbStudent.getId(); | |
| 92 | + | |
| 93 | + // 调用 | |
| 94 | + studentService.deleteStudent(id); | |
| 95 | + // 校验数据不存在了 | |
| 96 | + assertNull(studentMapper.selectById(id)); | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testDeleteStudent_notExists() { | |
| 101 | + // 准备参数 | |
| 102 | + Long id = randomLongId(); | |
| 103 | + | |
| 104 | + // 调用, 并断言异常 | |
| 105 | + assertServiceException(() -> studentService.deleteStudent(id), STUDENT_NOT_EXISTS); | |
| 106 | + } | |
| 107 | + | |
| 108 | + @Test | |
| 109 | + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 | |
| 110 | + public void testGetStudentPage() { | |
| 111 | + // mock 数据 | |
| 112 | + InfraStudentDO dbStudent = randomPojo(InfraStudentDO.class, o -> { // 等会查询到 | |
| 113 | + o.setName(null); | |
| 114 | + o.setBirthday(null); | |
| 115 | + o.setSex(null); | |
| 116 | + o.setEnabled(null); | |
| 117 | + o.setCreateTime(null); | |
| 118 | + }); | |
| 119 | + studentMapper.insert(dbStudent); | |
| 120 | + // 测试 name 不匹配 | |
| 121 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setName(null))); | |
| 122 | + // 测试 birthday 不匹配 | |
| 123 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setBirthday(null))); | |
| 124 | + // 测试 sex 不匹配 | |
| 125 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setSex(null))); | |
| 126 | + // 测试 enabled 不匹配 | |
| 127 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setEnabled(null))); | |
| 128 | + // 测试 createTime 不匹配 | |
| 129 | + studentMapper.insert(cloneIgnoreId(dbStudent, o -> o.setCreateTime(null))); | |
| 130 | + // 准备参数 | |
| 131 | + InfraStudentPageReqVO reqVO = new InfraStudentPageReqVO(); | |
| 132 | + reqVO.setName(null); | |
| 133 | + reqVO.setBirthday(null); | |
| 134 | + reqVO.setSex(null); | |
| 135 | + reqVO.setEnabled(null); | |
| 136 | + reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); | |
| 137 | + | |
| 138 | + // 调用 | |
| 139 | + PageResult<InfraStudentDO> pageResult = studentService.getStudentPage(reqVO); | |
| 140 | + // 断言 | |
| 141 | + assertEquals(1, pageResult.getTotal()); | |
| 142 | + assertEquals(1, pageResult.getList().size()); | |
| 143 | + assertPojoEquals(dbStudent, pageResult.getList().get(0)); | |
| 144 | + } | |
| 145 | + | |
| 146 | +} | |
| 0 | 147 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/js/student
0 → 100644
| 1 | +import request from '@/utils/request' | |
| 2 | + | |
| 3 | +// 创建学生 | |
| 4 | +export function createStudent(data) { | |
| 5 | + return request({ | |
| 6 | + url: '/infra/student/create', | |
| 7 | + method: 'post', | |
| 8 | + data: data | |
| 9 | + }) | |
| 10 | +} | |
| 11 | + | |
| 12 | +// 更新学生 | |
| 13 | +export function updateStudent(data) { | |
| 14 | + return request({ | |
| 15 | + url: '/infra/student/update', | |
| 16 | + method: 'put', | |
| 17 | + data: data | |
| 18 | + }) | |
| 19 | +} | |
| 20 | + | |
| 21 | +// 删除学生 | |
| 22 | +export function deleteStudent(id) { | |
| 23 | + return request({ | |
| 24 | + url: '/infra/student/delete?id=' + id, | |
| 25 | + method: 'delete' | |
| 26 | + }) | |
| 27 | +} | |
| 28 | + | |
| 29 | +// 获得学生 | |
| 30 | +export function getStudent(id) { | |
| 31 | + return request({ | |
| 32 | + url: '/infra/student/get?id=' + id, | |
| 33 | + method: 'get' | |
| 34 | + }) | |
| 35 | +} | |
| 36 | + | |
| 37 | +// 获得学生分页 | |
| 38 | +export function getStudentPage(params) { | |
| 39 | + return request({ | |
| 40 | + url: '/infra/student/page', | |
| 41 | + method: 'get', | |
| 42 | + params | |
| 43 | + }) | |
| 44 | +} | |
| 45 | +// 导出学生 Excel | |
| 46 | +export function exportStudentExcel(params) { | |
| 47 | + return request({ | |
| 48 | + url: '/infra/student/export-excel', | |
| 49 | + method: 'get', | |
| 50 | + params, | |
| 51 | + responseType: 'blob' | |
| 52 | + }) | |
| 53 | +} | |
| 0 | 54 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/sql/h2
0 → 100644
| 1 | +-- 将该建表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/create_tables.sql 文件里 | |
| 2 | +CREATE TABLE IF NOT EXISTS "infra_student" ( | |
| 3 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 4 | + "name" varchar NOT NULL, | |
| 5 | + "description" varchar NOT NULL, | |
| 6 | + "birthday" varchar NOT NULL, | |
| 7 | + "sex" int NOT NULL, | |
| 8 | + "enabled" bit NOT NULL, | |
| 9 | + "avatar" varchar NOT NULL, | |
| 10 | + "video" varchar NOT NULL, | |
| 11 | + "memo" varchar NOT NULL, | |
| 12 | + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 13 | + PRIMARY KEY ("id") | |
| 14 | +) COMMENT '学生表'; | |
| 15 | + | |
| 16 | +-- 将该删表 SQL 语句,添加到 yudao-module-infra-biz 模块的 test/resources/sql/clean.sql 文件里 | |
| 17 | +DELETE FROM "infra_student"; | |
| 0 | 18 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/sql/sql
0 → 100644
| 1 | +-- 菜单 SQL | |
| 2 | +INSERT INTO system_menu( | |
| 3 | + name, permission, type, sort, parent_id, | |
| 4 | + path, icon, component, status, component_name | |
| 5 | +) | |
| 6 | +VALUES ( | |
| 7 | + '学生管理', '', 2, 0, 888, | |
| 8 | + 'student', '', 'infra/demo/index', 0, 'InfraStudent' | |
| 9 | +); | |
| 10 | + | |
| 11 | +-- 按钮父菜单ID | |
| 12 | +-- 暂时只支持 MySQL。如果你是 Oracle、PostgreSQL、SQLServer 的话,需要手动修改 @parentId 的部分的代码 | |
| 13 | +SELECT @parentId := LAST_INSERT_ID(); | |
| 14 | + | |
| 15 | +-- 按钮 SQL | |
| 16 | +INSERT INTO system_menu( | |
| 17 | + name, permission, type, sort, parent_id, | |
| 18 | + path, icon, component, status | |
| 19 | +) | |
| 20 | +VALUES ( | |
| 21 | + '学生查询', 'infra:student:query', 3, 1, @parentId, | |
| 22 | + '', '', '', 0 | |
| 23 | +); | |
| 24 | +INSERT INTO system_menu( | |
| 25 | + name, permission, type, sort, parent_id, | |
| 26 | + path, icon, component, status | |
| 27 | +) | |
| 28 | +VALUES ( | |
| 29 | + '学生创建', 'infra:student:create', 3, 2, @parentId, | |
| 30 | + '', '', '', 0 | |
| 31 | +); | |
| 32 | +INSERT INTO system_menu( | |
| 33 | + name, permission, type, sort, parent_id, | |
| 34 | + path, icon, component, status | |
| 35 | +) | |
| 36 | +VALUES ( | |
| 37 | + '学生更新', 'infra:student:update', 3, 3, @parentId, | |
| 38 | + '', '', '', 0 | |
| 39 | +); | |
| 40 | +INSERT INTO system_menu( | |
| 41 | + name, permission, type, sort, parent_id, | |
| 42 | + path, icon, component, status | |
| 43 | +) | |
| 44 | +VALUES ( | |
| 45 | + '学生删除', 'infra:student:delete', 3, 4, @parentId, | |
| 46 | + '', '', '', 0 | |
| 47 | +); | |
| 48 | +INSERT INTO system_menu( | |
| 49 | + name, permission, type, sort, parent_id, | |
| 50 | + path, icon, component, status | |
| 51 | +) | |
| 52 | +VALUES ( | |
| 53 | + '学生导出', 'infra:student:export', 3, 5, @parentId, | |
| 54 | + '', '', '', 0 | |
| 55 | +); | |
| 0 | 56 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/test/resources/codegen/vue2_one/vue/StudentForm
0 → 100644
| 1 | +<template> | |
| 2 | + <div class="app-container"> | |
| 3 | + <!-- 对话框(添加 / 修改) --> | |
| 4 | + <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body> | |
| 5 | + <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px"> | |
| 6 | + <el-form-item label="名字" prop="name"> | |
| 7 | + <el-input v-model="formData.name" placeholder="请输入名字" /> | |
| 8 | + </el-form-item> | |
| 9 | + <el-form-item label="简介" prop="description"> | |
| 10 | + <el-input v-model="formData.description" type="textarea" placeholder="请输入内容" /> | |
| 11 | + </el-form-item> | |
| 12 | + <el-form-item label="出生日期" prop="birthday"> | |
| 13 | + <el-date-picker clearable v-model="formData.birthday" type="date" value-format="timestamp" placeholder="选择出生日期" /> | |
| 14 | + </el-form-item> | |
| 15 | + <el-form-item label="性别" prop="sex"> | |
| 16 | + <el-select v-model="formData.sex" placeholder="请选择性别"> | |
| 17 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_SEX)" | |
| 18 | + :key="dict.value" :label="dict.label" :value="parseInt(dict.value)" /> | |
| 19 | + </el-select> | |
| 20 | + </el-form-item> | |
| 21 | + <el-form-item label="是否有效" prop="enabled"> | |
| 22 | + <el-radio-group v-model="formData.enabled"> | |
| 23 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_BOOLEAN_STRING)" | |
| 24 | + :key="dict.value" :label="dict.value">{{dict.label}}</el-radio> | |
| 25 | + </el-radio-group> | |
| 26 | + </el-form-item> | |
| 27 | + <el-form-item label="头像"> | |
| 28 | + <ImageUpload v-model="formData.avatar"/> | |
| 29 | + </el-form-item> | |
| 30 | + <el-form-item label="附件"> | |
| 31 | + <FileUpload v-model="formData.video"/> | |
| 32 | + </el-form-item> | |
| 33 | + <el-form-item label="备注"> | |
| 34 | + <Editor v-model="formData.memo" :min-height="192"/> | |
| 35 | + </el-form-item> | |
| 36 | + </el-form> | |
| 37 | + <div slot="footer" class="dialog-footer"> | |
| 38 | + <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button> | |
| 39 | + <el-button @click="dialogVisible = false">取 消</el-button> | |
| 40 | + </div> | |
| 41 | + </el-dialog> | |
| 42 | + </div> | |
| 43 | +</template> | |
| 44 | + | |
| 45 | +<script> | |
| 46 | + import * as StudentApi from '@/api/infra/demo'; | |
| 47 | + import ImageUpload from '@/components/ImageUpload'; | |
| 48 | + import FileUpload from '@/components/FileUpload'; | |
| 49 | + import Editor from '@/components/Editor'; | |
| 50 | + export default { | |
| 51 | + name: "StudentForm", | |
| 52 | + components: { | |
| 53 | + ImageUpload, | |
| 54 | + FileUpload, | |
| 55 | + Editor, | |
| 56 | + }, | |
| 57 | + data() { | |
| 58 | + return { | |
| 59 | + // 弹出层标题 | |
| 60 | + dialogTitle: "", | |
| 61 | + // 是否显示弹出层 | |
| 62 | + dialogVisible: false, | |
| 63 | + // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 64 | + formLoading: false, | |
| 65 | + // 表单参数 | |
| 66 | + formData: { | |
| 67 | + id: undefined, | |
| 68 | + name: undefined, | |
| 69 | + description: undefined, | |
| 70 | + birthday: undefined, | |
| 71 | + sex: undefined, | |
| 72 | + enabled: undefined, | |
| 73 | + avatar: undefined, | |
| 74 | + video: undefined, | |
| 75 | + memo: undefined, | |
| 76 | + }, | |
| 77 | + // 表单校验 | |
| 78 | + formRules: { | |
| 79 | + name: [{ required: true, message: '名字不能为空', trigger: 'blur' }], | |
| 80 | + description: [{ required: true, message: '简介不能为空', trigger: 'blur' }], | |
| 81 | + birthday: [{ required: true, message: '出生日期不能为空', trigger: 'blur' }], | |
| 82 | + sex: [{ required: true, message: '性别不能为空', trigger: 'change' }], | |
| 83 | + enabled: [{ required: true, message: '是否有效不能为空', trigger: 'blur' }], | |
| 84 | + avatar: [{ required: true, message: '头像不能为空', trigger: 'blur' }], | |
| 85 | + video: [{ required: true, message: '附件不能为空', trigger: 'blur' }], | |
| 86 | + memo: [{ required: true, message: '备注不能为空', trigger: 'blur' }], | |
| 87 | + }, | |
| 88 | + }; | |
| 89 | + }, | |
| 90 | + methods: { | |
| 91 | + /** 打开弹窗 */ | |
| 92 | + async open(id) { | |
| 93 | + this.dialogVisible = true; | |
| 94 | + this.reset(); | |
| 95 | + // 修改时,设置数据 | |
| 96 | + if (id) { | |
| 97 | + this.formLoading = true; | |
| 98 | + try { | |
| 99 | + const res = await StudentApi.getStudent(id); | |
| 100 | + this.formData = res.data; | |
| 101 | + this.title = "修改学生"; | |
| 102 | + } finally { | |
| 103 | + this.formLoading = false; | |
| 104 | + } | |
| 105 | + } | |
| 106 | + this.title = "新增学生"; | |
| 107 | + }, | |
| 108 | + /** 提交按钮 */ | |
| 109 | + async submitForm() { | |
| 110 | + // 校验主表 | |
| 111 | + await this.$refs["formRef"].validate(); | |
| 112 | + this.formLoading = true; | |
| 113 | + try { | |
| 114 | + const data = this.formData; | |
| 115 | + // 修改的提交 | |
| 116 | + if (data.id) { | |
| 117 | + await StudentApi.updateStudent(data); | |
| 118 | + this.$modal.msgSuccess("修改成功"); | |
| 119 | + this.dialogVisible = false; | |
| 120 | + this.$emit('success'); | |
| 121 | + return; | |
| 122 | + } | |
| 123 | + // 添加的提交 | |
| 124 | + await StudentApi.createStudent(data); | |
| 125 | + this.$modal.msgSuccess("新增成功"); | |
| 126 | + this.dialogVisible = false; | |
| 127 | + this.$emit('success'); | |
| 128 | + } finally { | |
| 129 | + this.formLoading = false; | |
| 130 | + } | |
| 131 | + }, | |
| 132 | + /** 表单重置 */ | |
| 133 | + reset() { | |
| 134 | + this.formData = { | |
| 135 | + id: undefined, | |
| 136 | + name: undefined, | |
| 137 | + description: undefined, | |
| 138 | + birthday: undefined, | |
| 139 | + sex: undefined, | |
| 140 | + enabled: undefined, | |
| 141 | + avatar: undefined, | |
| 142 | + video: undefined, | |
| 143 | + memo: undefined, | |
| 144 | + }; | |
| 145 | + this.resetForm("formRef"); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + }; | |
| 149 | +</script> | ... | ... |