mirror of https://github.com/elunez/eladmin
代码生成器优化,前后端默认添加导出功能,input时间组件自动判定
parent
6befa3771a
commit
2e3877aac3
|
@ -25,7 +25,6 @@ import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Propagation;
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import io.swagger.annotations.*;
|
import io.swagger.annotations.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
|
@ -27,10 +29,18 @@ public class ${className}Controller {
|
||||||
this.${changeClassName}Service = ${changeClassName}Service;
|
this.${changeClassName}Service = ${changeClassName}Service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Log("导出数据")
|
||||||
|
@ApiOperation("导出数据")
|
||||||
|
@GetMapping(value = "/download")
|
||||||
|
@PreAuthorize("@el.check('${changeClassName}:list')")
|
||||||
|
public void download(HttpServletResponse response, ${className}QueryCriteria criteria) throws IOException {
|
||||||
|
${changeClassName}Service.download(${changeClassName}Service.queryAll(criteria), response);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@Log("查询${className}")
|
@Log("查询${className}")
|
||||||
@ApiOperation("查询${className}")
|
@ApiOperation("查询${className}")
|
||||||
@PreAuthorize("@el.check('${changeClassName}:list'")
|
@PreAuthorize("@el.check('${changeClassName}:list')")
|
||||||
public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable){
|
public ResponseEntity get${className}s(${className}QueryCriteria criteria, Pageable pageable){
|
||||||
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
|
return new ResponseEntity<>(${changeClassName}Service.queryAll(criteria,pageable),HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@ import ${package}.service.dto.${className}QueryCriteria;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
|
@ -40,4 +42,6 @@ public interface ${className}Service {
|
||||||
void update(${className} resources);
|
void update(${className} resources);
|
||||||
|
|
||||||
void delete(${pkColumnType} ${pkChangeColName});
|
void delete(${pkColumnType} ${pkChangeColName});
|
||||||
|
|
||||||
|
void download(List<${className}DTO> all, HttpServletResponse response) throws IOException;
|
||||||
}
|
}
|
|
@ -11,6 +11,7 @@ import me.zhengjie.exception.EntityExistException;
|
||||||
</#list>
|
</#list>
|
||||||
</#if>
|
</#if>
|
||||||
import me.zhengjie.utils.ValidationUtil;
|
import me.zhengjie.utils.ValidationUtil;
|
||||||
|
import me.zhengjie.utils.FileUtil;
|
||||||
import ${package}.repository.${className}Repository;
|
import ${package}.repository.${className}Repository;
|
||||||
import ${package}.service.${className}Service;
|
import ${package}.service.${className}Service;
|
||||||
import ${package}.service.dto.${className}DTO;
|
import ${package}.service.dto.${className}DTO;
|
||||||
|
@ -35,6 +36,10 @@ import me.zhengjie.utils.PageUtil;
|
||||||
import me.zhengjie.utils.QueryHelp;
|
import me.zhengjie.utils.QueryHelp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ${author}
|
* @author ${author}
|
||||||
|
@ -127,4 +132,24 @@ public class ${className}ServiceImpl implements ${className}Service {
|
||||||
public void delete(${pkColumnType} ${pkChangeColName}) {
|
public void delete(${pkColumnType} ${pkChangeColName}) {
|
||||||
${changeClassName}Repository.deleteById(${pkChangeColName});
|
${changeClassName}Repository.deleteById(${pkChangeColName});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(List<${className}DTO> all, HttpServletResponse response) throws IOException {
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (${className}DTO ${changeClassName} : all) {
|
||||||
|
Map<String,Object> map = new LinkedHashMap<>();
|
||||||
|
<#list columns as column>
|
||||||
|
<#if column.columnKey != 'PRI'>
|
||||||
|
<#if column.columnComment != ''>
|
||||||
|
map.put("${column.columnComment}", ${changeClassName}.get${column.capitalColumnName}());
|
||||||
|
<#else>
|
||||||
|
map.put(" ${column.changeColumnName}", ${changeClassName}.get${column.capitalColumnName}());
|
||||||
|
</#if>
|
||||||
|
</#if>
|
||||||
|
</#list>
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
FileUtil.downloadExcel(list, response);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -22,3 +22,12 @@ export function edit(data) {
|
||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function download${className}(params) {
|
||||||
|
return request({
|
||||||
|
url: 'api/${changeClassName}/download',
|
||||||
|
method: 'get',
|
||||||
|
params,
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
<#list columns as column>
|
<#list columns as column>
|
||||||
<#if column.changeColumnName != '${pkChangeColName}'>
|
<#if column.changeColumnName != '${pkChangeColName}'>
|
||||||
<el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnKey = 'UNI'>prop="${column.changeColumnName}"</#if>>
|
<el-form-item label="<#if column.columnComment != ''>${column.columnComment}<#else>${column.changeColumnName}</#if>" <#if column.columnKey = 'UNI'>prop="${column.changeColumnName}"</#if>>
|
||||||
|
<#if column.columnType != 'Timestamp'>
|
||||||
<el-input v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
<el-input v-model="form.${column.changeColumnName}" style="width: 370px;"/>
|
||||||
|
<#else >
|
||||||
|
<el-date-picker v-model="form.${column.changeColumnName}" type="datetime" style="width: 370px;"/>
|
||||||
|
</#if>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
|
|
|
@ -21,6 +21,16 @@
|
||||||
icon="el-icon-plus"
|
icon="el-icon-plus"
|
||||||
@click="add">新增</el-button>
|
@click="add">新增</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- 导出 -->
|
||||||
|
<div style="display: inline-block;">
|
||||||
|
<el-button
|
||||||
|
:loading="downloadLoading"
|
||||||
|
size="mini"
|
||||||
|
class="filter-item"
|
||||||
|
type="warning"
|
||||||
|
icon="el-icon-download"
|
||||||
|
@click="download">导出</el-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--表单组件-->
|
<!--表单组件-->
|
||||||
<eForm ref="form" :is-add="isAdd"/>
|
<eForm ref="form" :is-add="isAdd"/>
|
||||||
|
@ -73,9 +83,9 @@
|
||||||
<script>
|
<script>
|
||||||
import checkPermission from '@/utils/permission'
|
import checkPermission from '@/utils/permission'
|
||||||
import initData from '@/mixins/initData'
|
import initData from '@/mixins/initData'
|
||||||
import { del } from '@/api/${changeClassName}'
|
import { del, download${className} } from '@/api/${changeClassName}'
|
||||||
<#if hasTimestamp>
|
<#if hasTimestamp>
|
||||||
import { parseTime } from '@/utils/index'
|
import { parseTime, downloadFile } from '@/utils/index'
|
||||||
</#if>
|
</#if>
|
||||||
import eForm from './form'
|
import eForm from './form'
|
||||||
export default {
|
export default {
|
||||||
|
@ -150,6 +160,17 @@ export default {
|
||||||
</#if>
|
</#if>
|
||||||
}
|
}
|
||||||
_this.dialog = true
|
_this.dialog = true
|
||||||
|
},
|
||||||
|
// 导出
|
||||||
|
download() {
|
||||||
|
this.beforeInit()
|
||||||
|
this.downloadLoading = true
|
||||||
|
download${className}(this.params).then(result => {
|
||||||
|
downloadFile(result, '${className}列表', 'xlsx')
|
||||||
|
this.downloadLoading = false
|
||||||
|
}).catch(() => {
|
||||||
|
this.downloadLoading = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue