Skip to content

Commit

Permalink
feat: 代码生成支持导入功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lltx authored Jul 21, 2024
1 parent 17e5214 commit c4d425e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
16 changes: 16 additions & 0 deletions multiple/主子Contoller.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,20 @@ public R removeChild(@RequestBody ${pk.attrType}[] ids) {
#end public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {
return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));
}

/**
* 导入excel 表
* @param ${className}List 对象实体列表
* @param bindingResult 错误信息列表
* @return ok fail
*/
@PostMapping("/import")
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_export")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_export')" )
#end
public R import(@RequestExcel List<DemoEntity> ${className}List, BindingResult bindingResult) {
return R.ok( ${className}Service.saveBatch(${className}List));
}
}
16 changes: 16 additions & 0 deletions single/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,20 @@ public R removeById(@RequestBody ${pk.attrType}[] ids) {
public List<${ClassName}Entity> export(${ClassName}Entity ${className},${pk.attrType}[] ids) {
return ${className}Service.list(Wrappers.lambdaQuery(${className}).in(ArrayUtil.isNotEmpty(ids), ${ClassName}Entity::$str.getProperty($pk.attrName), ids));
}

/**
* 导入excel 表
* @param ${className}List 对象实体列表
* @param bindingResult 错误信息列表
* @return ok fail
*/
@PostMapping("/import")
#if($isSpringBoot3)
@HasPermission("${moduleName}_${functionName}_export")
#else
@PreAuthorize("@pms.hasPermission('${moduleName}_${functionName}_export')" )
#end
public R import(@RequestExcel List<DemoEntity> ${className}List, BindingResult bindingResult) {
return R.ok( ${className}Service.saveBatch(${className}List));
}
}
18 changes: 15 additions & 3 deletions single/表格.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
#end
<el-form-item>
<el-button icon="search" type="primary" @click="getDataList">
查询
查 询
</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
<el-button icon="Refresh" @click="resetQuery">重 置</el-button>
</el-form-item>
</el-form>
</el-row>
Expand All @@ -55,9 +55,12 @@
v-auth="'${moduleName}_${functionName}_add'">
新 增
</el-button>
<el-button plain icon="upload-filled" type="primary" class="ml10" @click="excelUploadRef.show()" v-auth="'sys_user_add'">
导 入
</el-button>
<el-button plain :disabled="multiple" icon="Delete" type="primary"
v-auth="'${moduleName}_${functionName}_del'" @click="handleDelete(selectObjs)">
删除
删 除
</el-button>
<right-toolbar v-model:showSearch="showSearch" :export="'${moduleName}_${functionName}_export'"
@exportExcel="exportExcel" class="ml10 mr20" style="float: right;"
Expand Down Expand Up @@ -95,6 +98,14 @@
<!-- 编辑、新增 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" />

<!-- 导入excel -->
<upload-excel
ref="excelUploadRef"
title="导入"
url="/${moduleName}/${functionName}/import"
temp-url="/${moduleName}/${functionName}/export.xlsx?$pk.attrName=-1"
@refreshDataList="getDataList"
/>
</div>
</template>

Expand Down Expand Up @@ -124,6 +135,7 @@ const { $dict.format($fieldDict) } = useDict($dict.quotation($fieldDict))
#end
// 定义变量内容
const formDialogRef = ref()
const excelUploadRef = ref();
// 搜索变量
const queryRef = ref()
const showSearch = ref(true)
Expand Down

0 comments on commit c4d425e

Please sign in to comment.