【升级】代码生成模块增加批量删除及导出功能

This commit is contained in:
小诺 2021-07-18 19:02:03 +08:00 committed by 俞宝山
parent c488abdd21
commit f69b058ed0
10 changed files with 179 additions and 67 deletions

View File

@ -88,7 +88,7 @@ public class XnVelocityContext {
// sql中id的创建
List<Long> idList = new ArrayList<>();
for (int a = 0; a <= 6; a++) {
for (int a = 0; a <= 7; a++) {
idList.add(Math.abs(UUID.randomUUID().getLeastSignificantBits()));
}
velocityContext.put("sqlMenuId", idList);

View File

@ -22,21 +22,25 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点可申请商业授权获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip
*/
package ${packageName}.${modularName}.${busName}.controller;
package ${packageName}import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.core.annotion.BusinessLog;
import vip.xiaonuo.core.annotion.Permission;
import vip.xiaonuo.core.enums.LogAnnotionOpTypeEnum;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import ${packageName}.${modularName}.${busName}.param.${ClassName}Param;
import ${packageName}.${modularName}.${busName}.service.${ClassName}Service;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.util.List;
.${modularName}.${busName}.controller;
${packageName}
.${modularName}.${busName}.param.${ClassName}Param;
${packageName}
.${modularName}.${busName}.service.${ClassName}Service;
/**
* ${functionName}控制器
@ -78,7 +82,7 @@ public class ${ClassName}Controller {
}
/**
* 删除${functionName}
* 删除${functionName},可批量删除
*
* @author ${authorName}
* @date ${createDateString}
@ -86,8 +90,8 @@ public class ${ClassName}Controller {
@Permission
@PostMapping("/${className}/delete")
@BusinessLog(title = "${functionName}_删除", opType = LogAnnotionOpTypeEnum.DELETE)
public ResponseData delete(@RequestBody @Validated(${ClassName}Param.delete.class) ${ClassName}Param ${className}Param) {
${className}Service.delete(${className}Param);
public ResponseData delete(@RequestBody @Validated(${ClassName}Param.delete.class) List<${ClassName}Param> ${className}ParamList) {
${className}Service.delete(${className}ParamList);
return new SuccessResponseData();
}
@ -131,4 +135,17 @@ public class ${ClassName}Controller {
return new SuccessResponseData(${className}Service.list(${className}Param));
}
/**
* 导出系统用户
*
* @author ${authorName}
* @date ${createDateString}
*/
@Permission
@GetMapping("/${className}/export")
@BusinessLog(title = "${functionName}_导出", opType = LogAnnotionOpTypeEnum.EXPORT)
public void export(${ClassName}Param ${className}Param) {
${className}Service.export(${className}Param);
}
}

View File

@ -22,20 +22,20 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点可申请商业授权获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip
*/
package ${packageName}.${modularName}.${busName}.enums;
import vip.xiaonuo.core.annotion.ExpEnumType;
package ${packageName}import vip.xiaonuo.core.annotion.ExpEnumType;
import vip.xiaonuo.core.exception.enums.abs.AbstractBaseExceptionEnum;
import vip.xiaonuo.core.factory.ExpEnumCodeFactory;
import vip.xiaonuo.sys.core.consts.SysExpEnumConstant;
.${modularName}.${busName}.enums;
/**
* ${functionName}
*
* @author ${authorName}
* @date ${createDateString}
*/
@ExpEnumType(module = SysExpEnumConstant.SNOWY_SYS_MODULE_EXP_CODE, kind = SysExpEnumConstant.SYS_POS_EXCEPTION_ENUM)
@ExpEnumType(module = SysExpEnumConstant.SNOWY_SYS_MODULE_EXP_CODE)
public enum ${ClassName}ExceptionEnum implements AbstractBaseExceptionEnum {
/**

View File

@ -69,3 +69,18 @@ export function ${className}Delete (parameter) {
data: parameter
})
}
/**
* 导出${functionName}
*
* @author ${authorName}
* @date ${createDateString}
*/
export function ${className}Export (parameter) {
return axios({
url: '/${className}/export',
method: 'get',
params: parameter,
responseType: 'blob'
})
}

View File

@ -22,14 +22,17 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点可申请商业授权获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip
*/
package ${packageName}.${modularName}.${busName}.service;
import com.baomidou.mybatisplus.extension.service.IService;
package ${packageName}import com.baomidou.mybatisplus.extension.service.IService;
import vip.xiaonuo.core.pojo.page.PageResult;
import ${packageName}.${modularName}.${busName}.entity.${ClassName};
import ${packageName}.${modularName}.${busName}.param.${ClassName}Param;
import java.util.List;
.${modularName}.${busName}.service;
${packageName}
.${modularName}.${busName}.entity.${ClassName};
${packageName}
.${modularName}.${busName}.param.${ClassName}Param;
/**
* ${functionName}service接口
*
@ -68,7 +71,7 @@ public interface ${ClassName}Service extends IService<${ClassName}> {
* @author ${authorName}
* @date ${createDateString}
*/
void delete(${ClassName}Param ${className}Param);
void delete(List<${ClassName}Param> ${className}ParamList);
/**
* 编辑${functionName}
@ -85,4 +88,13 @@ public interface ${ClassName}Service extends IService<${ClassName}> {
* @date ${createDateString}
*/
${ClassName} detail(${ClassName}Param ${className}Param);
/**
* 导出${functionName}
*
* @author ${authorName}
* @date ${createDateString}
*/
void export(${ClassName}Param ${className}Param);
}

View File

@ -22,29 +22,30 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点可申请商业授权获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip
*/
package ${packageName}.${modularName}.${busName}.service.impl;
import cn.hutool.core.bean.BeanUtil;
package ${packageName}import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import vip.xiaonuo.core.consts.CommonConstant;
import vip.xiaonuo.core.enums.CommonStatusEnum;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.xiaonuo.core.exception.ServiceException;
import vip.xiaonuo.core.factory.PageFactory;
import vip.xiaonuo.core.pojo.page.PageResult;
import ${packageName}.${modularName}.${busName}.entity.${ClassName};
import ${packageName}.${modularName}.${busName}.enums.${ClassName}ExceptionEnum;
import ${packageName}.${modularName}.${busName}.mapper.${ClassName}Mapper;
import ${packageName}.${modularName}.${busName}.param.${ClassName}Param;
import ${packageName}.${modularName}.${busName}.service.${ClassName}Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import vip.xiaonuo.core.util.PoiUtil;
import java.util.List;
.${modularName}.${busName}.service.impl;
${packageName}
.${modularName}.${busName}.entity.${ClassName};
${packageName}
.${modularName}.${busName}.enums.${ClassName}ExceptionEnum;
${packageName}
.${modularName}.${busName}.mapper.${ClassName}Mapper;
${packageName}
.${modularName}.${busName}.param.${ClassName}Param;
${packageName}
.${modularName}.${busName}.service.${ClassName}Service;
/**
* ${functionName}service接口实现类
*
@ -85,12 +86,14 @@ public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${C
@Transactional(rollbackFor = Exception.class)
@Override
public void delete(${ClassName}Param ${className}Param) {
public void delete(List<${ClassName}Param> ${className}ParamList) {
${className}ParamList.forEach(${className}Param -> {
#foreach ($column in $tableField)
#if (${column.columnKey} == "PRI")
this.removeById(${className}Param.get${column.columnKeyName}());
this.removeById(${className}Param.get${column.columnKeyName}());
#end
#end
});
}
@Transactional(rollbackFor = Exception.class)
@ -123,4 +126,11 @@ public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${C
}
return ${className};
}
@Override
public void export(${ClassName}Param ${className}Param) {
List<${ClassName}> list = this.list(${className}Param);
PoiUtil.exportExcelWithStream("Snowy${ClassName}.xls", ${ClassName}.class, list);
}
}

View File

@ -30,5 +30,9 @@ INSERT INTO `sys_menu` VALUES
#elseif($foreach.count == 7)
INSERT INTO `sys_menu` VALUES
('$id', '$pid', '[0],[$pid],', '${functionName}列表', '${busName}_index_list', '2', null, null, null, '${className}:list', 'system_tool', '0', 'Y', null, null, '1', '100', null, '0', null, null, null, null);
#elseif($foreach.count == 8)
INSERT INTO `sys_menu` VALUES
('$id', '$pid', '[0],[$pid],', '${functionName}导出', '${busName}_index_export', '2', null, null, null, '${className}:export', 'system_tool', '0', 'Y', null, null, '1', '100', null, '0', null, null, null, null);
#end
#end

View File

@ -30,5 +30,9 @@ INSERT INTO `sys_menu` VALUES
#elseif($foreach.count == 7)
INSERT INTO "sys_menu" VALUES
("$id", "$pid", "[0],[$pid],", "${functionName}列表", "${busName}_index_list", "2", null, null, null, "${className}:list", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
#elseif($foreach.count == 7)
INSERT INTO "sys_menu" VALUES
("$id", "$pid", "[0],[$pid],", "${functionName}导出", "${busName}_index_export", "2", null, null, null, "${className}:export", "system_tool", "0", "Y", null, null, "1", "100", null, "0", null, null, null, null);
#end
#end

View File

@ -22,19 +22,16 @@ Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/xiaonuobase/snowy
6.若您的项目无法满足以上几点可申请商业授权获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip
*/
package ${packageName}.${modularName}.${busName}.entity;
import com.baomidou.mybatisplus.annotation.*;
import vip.xiaonuo.core.pojo.base.entity.BaseEntity;
package ${packageName}import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.*;
#foreach ($column in $tableField)
#if (${column.javaType} == 'BigDecimal')
import java.math.BigDecimal;
#end
#if(${column.javaType} == "Date")
import cn.afterturn.easypoi.excel.annotation.Excel;
.${modularName}.${busName}.entity;
#foreach($column in $tableField)
#if(${column.javaType}=='BigDecimal')
#end
#end
@ -64,6 +61,7 @@ public class ${ClassName} extends BaseEntity {
#if(${column.javaType} == "Date")
@Excel(name = "${column.columnComment}", databaseFormat = "yyyy-MM-dd HH:mm:ss", format = "yyyy-MM-dd", width = 20)
#end
@Excel(name = "${column.columnComment}")
private ${column.javaType} ${column.javaName};
#end
#end

View File

@ -104,16 +104,22 @@
ref="table"
:columns="columns"
:data="loadData"
:alert="true"
:alert="options.alert"
#foreach ($column in $tableField)
#if (${column.columnKey} == "PRI")
:rowKey="(record) => record.${column.javaName}"
#end
#end
:rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
:rowSelection="options.rowSelection"
>
<template class="table-operator" slot="operator" v-if="hasPerm('${className}:add')" >
<a-button type="primary" v-if="hasPerm('${className}:add')" icon="plus" @click="$refs.addForm.add()">新增${functionName}</a-button>
<a-button type="danger" :disabled="selectedRowKeys.length < 1" v-if="hasPerm('${className}:delete')" @click="batchDelete"><a-icon type="delete"/>批量删除</a-button>
<x-down
v-if="hasPerm('${className}:export')"
ref="batchExport"
@batchExport="batchExport"
/>
</template>
#foreach ($column in $tableField)
#if(${column.whetherTable} == "Y")
@ -139,7 +145,7 @@
<span slot="action" slot-scope="text, record">
<a v-if="hasPerm('${className}:edit')" @click="$refs.editForm.edit(record)">编辑</a>
<a-divider type="vertical" v-if="hasPerm('${className}:edit') & hasPerm('${className}:delete')"/>
<a-popconfirm v-if="hasPerm('${className}:delete')" placement="topRight" title="确认删除?" @confirm="() => ${className}Delete(record)">
<a-popconfirm v-if="hasPerm('${className}:delete')" placement="topRight" title="确认删除?" @confirm="() => singleDelete(record)">
<a>删除</a>
</a-popconfirm>
</span>
@ -164,25 +170,25 @@
#end
#end
#end
#if($Ellipsis == "Y")
import { STable, Ellipsis } from '@/components'
#else
import { STable } from '@/components'
#if($Ellipsis == "Y")
import {Ellipsis, STable, XDown} from '@/components'
import moment from 'moment'
import {${className}Delete, ${className}Export, ${className}Page} from '@/api/modular/main/'
import addForm from './addForm.vue'
import editForm from './editForm.vue'
#else
#end
#if($DateQuery == "Y")
import moment from 'moment'
#end
import { ${className}Page, ${className}Delete } from '@/api/modular/main/${busName}/${className}Manage'
import addForm from './addForm.vue'
import editForm from './editForm.vue'
export default {
export default {
components: {
#if($Ellipsis == "Y")
Ellipsis,
#end
STable,
addForm,
editForm
editForm,
XDown
},
data () {
return {
@ -235,7 +241,14 @@
#end
#end
selectedRowKeys: [],
selectedRows: []
selectedRows: [],
options: {
alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
rowSelection: {
selectedRowKeys: this.selectedRowKeys,
onChange: this.onSelectChange
}
}
}
},
created () {
@ -282,11 +295,35 @@
return obj
},
#end
/**
* 单个删除
*/
singleDelete (record) {
#foreach ($column in $tableField)
#if (${column.columnKey} == "PRI")
const param = [{ '${column.javaName}': record.${column.javaName} }]
#end
#end
this.${className}Delete(param)
},
/**
* 批量删除
*/
batchDelete () {
const paramIds = this.selectedRowKeys.map((d) => {
#foreach ($column in $tableField)
#if (${column.columnKey} == "PRI")
return { '${column.javaName}': d }
#end
#end
})
this.${className}Delete(paramIds)
},
${className}Delete (record) {
${className}Delete(record).then((res) => {
if (res.success) {
this.$message.success('删除成功')
this.$refs.table.refresh()
this.$refs.table.clearRefreshSelected()
} else {
this.$message.error('删除失败') // + res.message
}
@ -306,6 +343,21 @@
#end
#end
#end
/**
* 批量导出
*/
batchExport () {
const paramIds = this.selectedRowKeys.map((d) => {
#foreach ($column in $tableField)
#if (${column.columnKey} == "PRI")
return { '${column.javaName}': d }
#end
#end
})
${className}Export(paramIds).then((res) => {
this.$refs.batchExport.downloadfile(res)
})
},
handleOk () {
this.$refs.table.refresh()
},