导出文件
parent
7a19e61f8e
commit
abda441908
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="div1">
|
<div class="div1">
|
||||||
|
|
||||||
|
|
@ -216,6 +215,7 @@
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-button type="success" @click="find">查找</el-button>
|
<el-button type="success" @click="find">查找</el-button>
|
||||||
|
<el-button type="success" @click="down">导出</el-button>
|
||||||
<el-button type="success" @click="rest">重置</el-button>
|
<el-button type="success" @click="rest">重置</el-button>
|
||||||
<el-checkbox v-model="checked" @change="Allquesr">是否显示全部查询条件</el-checkbox>
|
<el-checkbox v-model="checked" @change="Allquesr">是否显示全部查询条件</el-checkbox>
|
||||||
</el-form>
|
</el-form>
|
||||||
|
|
@ -940,6 +940,78 @@ export default {
|
||||||
find(){
|
find(){
|
||||||
this.queryUser();
|
this.queryUser();
|
||||||
},
|
},
|
||||||
|
down(){
|
||||||
|
this.downExcel();
|
||||||
|
},
|
||||||
|
downExcel() {
|
||||||
|
//显示加载图
|
||||||
|
this.tableloding=true;
|
||||||
|
//发起请求:/Jianhuojiemian/download,请求方式为post,类型为 {responseType:'blob'}
|
||||||
|
//参数和搜索参数一样
|
||||||
|
this.$axios.post(this.$httpUrl + '/Jianhuojiemian/download', {
|
||||||
|
pageSize: this.pageSize,
|
||||||
|
pageNum: this.pageNum,
|
||||||
|
param: this.param,
|
||||||
|
},{responseType:'blob'}).then(res => {
|
||||||
|
this.tableloding=false;
|
||||||
|
//重命名文件
|
||||||
|
this.downloadFile(res.data,'拣货界面'+ '数据', 'xlsx')
|
||||||
|
});
|
||||||
|
//列表数据加载
|
||||||
|
|
||||||
|
},
|
||||||
|
downloadFile(obj, name, suffix) {
|
||||||
|
//解析流文件,进行下载保存
|
||||||
|
const url = window.URL.createObjectURL(new Blob([obj]))
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.style.display = 'none'
|
||||||
|
link.href = url
|
||||||
|
const fileName = this.parseTime(new Date()) + '-' + name + '.' + suffix
|
||||||
|
link.setAttribute('download', fileName)
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
},
|
||||||
|
parseTime(time, cFormat) {
|
||||||
|
//获取当前时间
|
||||||
|
if (arguments.length === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
||||||
|
let date
|
||||||
|
if (typeof time === 'undefined' || time === null || time === 'null') {
|
||||||
|
return ''
|
||||||
|
} else if (typeof time === 'object') {
|
||||||
|
date = time
|
||||||
|
} else {
|
||||||
|
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
|
||||||
|
time = parseInt(time)
|
||||||
|
}
|
||||||
|
if ((typeof time === 'number') && (time.toString().length === 10)) {
|
||||||
|
time = time * 1000
|
||||||
|
}
|
||||||
|
date = new Date(time)
|
||||||
|
}
|
||||||
|
const formatObj = {
|
||||||
|
y: date.getFullYear(),
|
||||||
|
m: date.getMonth() + 1,
|
||||||
|
d: date.getDate(),
|
||||||
|
h: date.getHours(),
|
||||||
|
i: date.getMinutes(),
|
||||||
|
s: date.getSeconds(),
|
||||||
|
a: date.getDay()
|
||||||
|
}
|
||||||
|
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
|
||||||
|
let value = formatObj[key]
|
||||||
|
// Note: getDay() returns 0 on Sunday
|
||||||
|
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
|
||||||
|
if (result.length > 0 && value < 10) {
|
||||||
|
value = '0' + value
|
||||||
|
}
|
||||||
|
return value || 0
|
||||||
|
})
|
||||||
|
return time_str
|
||||||
|
},
|
||||||
Allquesr(){
|
Allquesr(){
|
||||||
//查询按钮
|
//查询按钮
|
||||||
if(this.checked){
|
if(this.checked){
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,15 @@
|
||||||
<artifactId>jakarta.persistence-api</artifactId>
|
<artifactId>jakarta.persistence-api</artifactId>
|
||||||
<version>2.2.3</version>
|
<version>2.2.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- excel工具 -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>4.1.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,10 @@ import com.yc.wms.until.QueryPageUtil;
|
||||||
import com.yc.wms.until.Result;
|
import com.yc.wms.until.Result;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -81,4 +80,21 @@ public class JianhuojiemianController {
|
||||||
public Result Xf() {
|
public Result Xf() {
|
||||||
return jianhuojiemian.Xf();
|
return jianhuojiemian.Xf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/download")
|
||||||
|
public void exportCompany(HttpServletResponse response,@RequestBody String json) throws Exception {
|
||||||
|
|
||||||
|
QueryPageUtil query =new QueryPageUtil();
|
||||||
|
JSONObject jsonObject= JSONUtil.parseObj(json);
|
||||||
|
query.setPageSize((int)jsonObject.get("pageSize"));
|
||||||
|
query.setPageNum((int)jsonObject.get("pageNum"));
|
||||||
|
|
||||||
|
JSONObject param= (JSONObject)jsonObject.get("param");
|
||||||
|
|
||||||
|
com.yc.wms.bean.Jianhuojiemian j = JSONUtil.toBean(param.toString(), com.yc.wms.bean.Jianhuojiemian.class);
|
||||||
|
|
||||||
|
|
||||||
|
jianhuojiemian.download( (List<Map<String,Object>> )jianhuojiemian.QueryJson(query,j).getData(), response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一关于错误配置信息 异常
|
||||||
|
*
|
||||||
|
* @author: liaojinlong
|
||||||
|
* @date: 2020/6/10 18:06
|
||||||
|
*/
|
||||||
|
public class BadConfigurationException extends RuntimeException {
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with {@code null} as its
|
||||||
|
* detail message. The cause is not initialized, and may subsequently be
|
||||||
|
* initialized by a call to {@link #initCause}.
|
||||||
|
*/
|
||||||
|
public BadConfigurationException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message.
|
||||||
|
* The cause is not initialized, and may subsequently be initialized by a
|
||||||
|
* call to {@link #initCause}.
|
||||||
|
*
|
||||||
|
* @param message the detail message. The detail message is saved for
|
||||||
|
* later retrieval by the {@link #getMessage()} method.
|
||||||
|
*/
|
||||||
|
public BadConfigurationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail message and
|
||||||
|
* cause. <p>Note that the detail message associated with
|
||||||
|
* {@code cause} is <i>not</i> automatically incorporated in
|
||||||
|
* this runtime exception's detail message.
|
||||||
|
*
|
||||||
|
* @param message the detail message (which is saved for later retrieval
|
||||||
|
* by the {@link #getMessage()} method).
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
|
* {@link #getCause()} method). (A {@code null} value is
|
||||||
|
* permitted, and indicates that the cause is nonexistent or
|
||||||
|
* unknown.)
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public BadConfigurationException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified cause and a
|
||||||
|
* detail message of {@code (cause==null ? null : cause.toString())}
|
||||||
|
* (which typically contains the class and detail message of
|
||||||
|
* {@code cause}). This constructor is useful for runtime exceptions
|
||||||
|
* that are little more than wrappers for other throwables.
|
||||||
|
*
|
||||||
|
* @param cause the cause (which is saved for later retrieval by the
|
||||||
|
* {@link #getCause()} method). (A {@code null} value is
|
||||||
|
* permitted, and indicates that the cause is nonexistent or
|
||||||
|
* unknown.)
|
||||||
|
* @since 1.4
|
||||||
|
*/
|
||||||
|
public BadConfigurationException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new runtime exception with the specified detail
|
||||||
|
* message, cause, suppression enabled or disabled, and writable
|
||||||
|
* stack trace enabled or disabled.
|
||||||
|
*
|
||||||
|
* @param message the detail message.
|
||||||
|
* @param cause the cause. (A {@code null} value is permitted,
|
||||||
|
* and indicates that the cause is nonexistent or unknown.)
|
||||||
|
* @param enableSuppression whether or not suppression is enabled
|
||||||
|
* or disabled
|
||||||
|
* @param writableStackTrace whether or not the stack trace should
|
||||||
|
* be writable
|
||||||
|
* @since 1.7
|
||||||
|
*/
|
||||||
|
protected BadConfigurationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||||
|
super(message, cause, enableSuppression, writableStackTrace);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.exception;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
|
||||||
|
import static org.springframework.http.HttpStatus.BAD_REQUEST;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Liu Xue
|
||||||
|
* @date 2018-11-23
|
||||||
|
* 统一异常处理
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public class BadRequestException extends RuntimeException{
|
||||||
|
|
||||||
|
private Integer status = BAD_REQUEST.value();
|
||||||
|
|
||||||
|
public BadRequestException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BadRequestException(HttpStatus status,String msg){
|
||||||
|
super(msg);
|
||||||
|
this.status = status.value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.exception;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Liu Xue
|
||||||
|
* @date 2018-11-23
|
||||||
|
*/
|
||||||
|
public class EntityExistException extends RuntimeException {
|
||||||
|
|
||||||
|
public EntityExistException(Class clazz, String field, String val) {
|
||||||
|
super(EntityExistException.generateMessage(clazz.getSimpleName(), field, val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateMessage(String entity, String field, String val) {
|
||||||
|
return StringUtils.capitalize(entity)
|
||||||
|
+ " with " + field + " "+ val + " existed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.exception;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Liu Xue
|
||||||
|
* @date 2018-11-23
|
||||||
|
*/
|
||||||
|
public class EntityNotFoundException extends RuntimeException {
|
||||||
|
|
||||||
|
public EntityNotFoundException(Class clazz, String field, String val) {
|
||||||
|
super(EntityNotFoundException.generateMessage(clazz.getSimpleName(), field, val));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateMessage(String entity, String field, String val) {
|
||||||
|
return StringUtils.capitalize(entity)
|
||||||
|
+ " with " + field + " "+ val + " does not exist";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.exception.handler;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Liu Xue
|
||||||
|
* @date 2018-11-23
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ApiError {
|
||||||
|
|
||||||
|
private Integer status = 400;
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
private LocalDateTime timestamp;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public ApiError() {
|
||||||
|
timestamp = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiError error(String message){
|
||||||
|
ApiError apiError = new ApiError();
|
||||||
|
apiError.setMessage(message);
|
||||||
|
return apiError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiError error(Integer status, String message){
|
||||||
|
ApiError apiError = new ApiError();
|
||||||
|
apiError.setStatus(status);
|
||||||
|
apiError.setMessage(message);
|
||||||
|
return apiError;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiError errorJosn(Integer status, String message){
|
||||||
|
ApiError apiError = new ApiError();
|
||||||
|
apiError.setStatus(status);
|
||||||
|
apiError.setMessage(message);
|
||||||
|
apiError.setTimestamp(LocalDateTime.now());
|
||||||
|
return apiError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.yc.wms.exception.handler;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ApiResult {
|
||||||
|
private Object data;//数据
|
||||||
|
private String message;//内容
|
||||||
|
private int status;//编码
|
||||||
|
|
||||||
|
public static ApiResult fail() {
|
||||||
|
|
||||||
|
return result(400, "操作失败!", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiResult fail(int code, String msg, Object data) {
|
||||||
|
return result(code, msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiResult success() {
|
||||||
|
return result(200, "操作成功!", null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiResult success(Object data) {
|
||||||
|
return result(200, "操作成功!", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiResult success(String msg, Object data) {
|
||||||
|
return result(200, msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiResult success(int status, String msg, Object data) {
|
||||||
|
return result(status, msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApiResult result(int status, String message, Object data) {
|
||||||
|
ApiResult rs = new ApiResult();
|
||||||
|
rs.setStatus(status);
|
||||||
|
rs.setMessage(message);
|
||||||
|
rs.setData(data);
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,11 @@ package com.yc.wms.service;
|
||||||
import com.yc.wms.until.QueryPageUtil;
|
import com.yc.wms.until.QueryPageUtil;
|
||||||
import com.yc.wms.until.Result;
|
import com.yc.wms.until.Result;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface Jianhuojiemian {
|
public interface Jianhuojiemian {
|
||||||
|
|
||||||
// 条件查询加分页
|
// 条件查询加分页
|
||||||
|
|
@ -26,4 +31,6 @@ public interface Jianhuojiemian {
|
||||||
//下发人
|
//下发人
|
||||||
Result Xf();
|
Result Xf();
|
||||||
|
|
||||||
|
|
||||||
|
void download(List<Map<String,Object>> all, HttpServletResponse response) throws Exception;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,16 @@ package com.yc.wms.service.impl;
|
||||||
import com.yc.wms.service.Jianhuojiemian;
|
import com.yc.wms.service.Jianhuojiemian;
|
||||||
import com.yc.wms.until.QueryPageUtil;
|
import com.yc.wms.until.QueryPageUtil;
|
||||||
import com.yc.wms.until.Result;
|
import com.yc.wms.until.Result;
|
||||||
|
import com.yc.wms.utils.FileUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -315,4 +316,24 @@ public class JianhuojiemianImpl implements Jianhuojiemian {
|
||||||
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql,new HashMap<>());
|
List<Map<String,Object>> list=jdbcTemplate.queryForList(sql,new HashMap<>());
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void download(List<Map<String,Object>> all, HttpServletResponse response) throws Exception {
|
||||||
|
System.out.println(all);
|
||||||
|
System.out.println("------------------循环-------------------");
|
||||||
|
List<Map<String, Object>> list = new ArrayList<>();
|
||||||
|
for (Map<String,Object> company : all) {
|
||||||
|
Map<String,Object> map = new LinkedHashMap<>();
|
||||||
|
System.out.println(company);
|
||||||
|
map.put("id", company.get("id"));
|
||||||
|
map.put("pt_code", company.get("pt_code"));
|
||||||
|
map.put("ORDER_DATE", company.get("ORDER_DATE"));
|
||||||
|
map.put("z_name", company.get("z_name"));
|
||||||
|
map.put("sourceType", company.get("sourceType"));
|
||||||
|
list.add(map);
|
||||||
|
}
|
||||||
|
FileUtil.downloadExcel(list, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.utils;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Liu Xue
|
||||||
|
* @website https://eladmin.vip
|
||||||
|
* @description 用于关闭各种连接,缺啥补啥
|
||||||
|
* @date 2021-03-05
|
||||||
|
**/
|
||||||
|
public class CloseUtil {
|
||||||
|
|
||||||
|
public static void close(Closeable closeable) {
|
||||||
|
if (null != closeable) {
|
||||||
|
try {
|
||||||
|
closeable.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 静默关闭
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void close(AutoCloseable closeable) {
|
||||||
|
if (null != closeable) {
|
||||||
|
try {
|
||||||
|
closeable.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 静默关闭
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常用静态常量
|
||||||
|
*
|
||||||
|
* @author Liu Xue
|
||||||
|
* @date 2018-12-26
|
||||||
|
*/
|
||||||
|
public class ElAdminConstant {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于IP定位转换
|
||||||
|
*/
|
||||||
|
public static final String REGION = "内网IP|内网IP";
|
||||||
|
/**
|
||||||
|
* win 系统
|
||||||
|
*/
|
||||||
|
public static final String WIN = "win";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mac 系统
|
||||||
|
*/
|
||||||
|
public static final String MAC = "mac";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常用接口
|
||||||
|
*/
|
||||||
|
public static class Url {
|
||||||
|
// IP归属地查询
|
||||||
|
public static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.utils;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Liu Xue
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "file")
|
||||||
|
public class FileProperties {
|
||||||
|
|
||||||
|
/** 文件大小限制 */
|
||||||
|
private Long maxSize;
|
||||||
|
|
||||||
|
/** 头像大小限制 */
|
||||||
|
private Long avatarMaxSize;
|
||||||
|
|
||||||
|
private ElPath mac;
|
||||||
|
|
||||||
|
private ElPath linux;
|
||||||
|
|
||||||
|
private ElPath windows;
|
||||||
|
|
||||||
|
public ElPath getPath(){
|
||||||
|
String os = System.getProperty("os.name");
|
||||||
|
if(os.toLowerCase().startsWith(ElAdminConstant.WIN)) {
|
||||||
|
return windows;
|
||||||
|
} else if(os.toLowerCase().startsWith(ElAdminConstant.MAC)){
|
||||||
|
return mac;
|
||||||
|
}
|
||||||
|
return linux;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class ElPath{
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
|
private String avatar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,369 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.yc.wms.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.yc.wms.exception.BadRequestException;
|
||||||
|
import com.yc.wms.until.SpringContextHolder;
|
||||||
|
|
||||||
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File工具类,扩展 hutool 工具包
|
||||||
|
*
|
||||||
|
* @author Liu Xue
|
||||||
|
* @date 2018-12-27
|
||||||
|
*/
|
||||||
|
public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统临时目录
|
||||||
|
* <br>
|
||||||
|
* windows 包含路径分割符,但Linux 不包含,
|
||||||
|
* 在windows \\==\ 前提下,
|
||||||
|
* 为安全起见 同意拼装 路径分割符,
|
||||||
|
* <pre>
|
||||||
|
* java.io.tmpdir
|
||||||
|
* windows : C:\Users/xxx\AppData\Local\Temp\
|
||||||
|
* linux: /temp
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator;
|
||||||
|
/**
|
||||||
|
* 定义GB的计算常量
|
||||||
|
*/
|
||||||
|
private static final int GB = 1024 * 1024 * 1024;
|
||||||
|
/**
|
||||||
|
* 定义MB的计算常量
|
||||||
|
*/
|
||||||
|
private static final int MB = 1024 * 1024;
|
||||||
|
/**
|
||||||
|
* 定义KB的计算常量
|
||||||
|
*/
|
||||||
|
private static final int KB = 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 格式化小数
|
||||||
|
*/
|
||||||
|
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
||||||
|
|
||||||
|
public static final String IMAGE = "图片";
|
||||||
|
public static final String TXT = "文档";
|
||||||
|
public static final String MUSIC = "音乐";
|
||||||
|
public static final String VIDEO = "视频";
|
||||||
|
public static final String APK = "APK";
|
||||||
|
public static final String ZIP = "ZIP";
|
||||||
|
public static final String OTHER = "其他";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MultipartFile转File
|
||||||
|
*/
|
||||||
|
public static File toFile(MultipartFile multipartFile) {
|
||||||
|
// 获取文件名
|
||||||
|
String fileName = multipartFile.getOriginalFilename();
|
||||||
|
// 获取文件后缀
|
||||||
|
String prefix = "." + getExtensionName(fileName);
|
||||||
|
File file = null;
|
||||||
|
try {
|
||||||
|
// 用uuid作为文件名,防止生成的临时文件重复
|
||||||
|
file = new File(SYS_TEM_DIR + IdUtil.simpleUUID() + prefix);
|
||||||
|
// MultipartFile to File
|
||||||
|
multipartFile.transferTo(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件扩展名,不带 .
|
||||||
|
*/
|
||||||
|
public static String getExtensionName(String filename) {
|
||||||
|
if ((filename != null) && (filename.length() > 0)) {
|
||||||
|
int dot = filename.lastIndexOf('.');
|
||||||
|
if ((dot > -1) && (dot < (filename.length() - 1))) {
|
||||||
|
return filename.substring(dot + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java文件操作 获取不带扩展名的文件名
|
||||||
|
*/
|
||||||
|
public static String getFileNameNoEx(String filename) {
|
||||||
|
if ((filename != null) && (filename.length() > 0)) {
|
||||||
|
int dot = filename.lastIndexOf('.');
|
||||||
|
if ((dot > -1) && (dot < (filename.length()))) {
|
||||||
|
return filename.substring(0, dot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件大小转换
|
||||||
|
*/
|
||||||
|
public static String getSize(long size) {
|
||||||
|
String resultSize;
|
||||||
|
if (size / GB >= 1) {
|
||||||
|
//如果当前Byte的值大于等于1GB
|
||||||
|
resultSize = DF.format(size / (float) GB) + "GB ";
|
||||||
|
} else if (size / MB >= 1) {
|
||||||
|
//如果当前Byte的值大于等于1MB
|
||||||
|
resultSize = DF.format(size / (float) MB) + "MB ";
|
||||||
|
} else if (size / KB >= 1) {
|
||||||
|
//如果当前Byte的值大于等于1KB
|
||||||
|
resultSize = DF.format(size / (float) KB) + "KB ";
|
||||||
|
} else {
|
||||||
|
resultSize = size + "B ";
|
||||||
|
}
|
||||||
|
return resultSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inputStream 转 File
|
||||||
|
*/
|
||||||
|
static File inputStreamToFile(InputStream ins, String name){
|
||||||
|
File file = new File(SYS_TEM_DIR + name);
|
||||||
|
if (file.exists()) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
OutputStream os = null;
|
||||||
|
try {
|
||||||
|
os = new FileOutputStream(file);
|
||||||
|
int bytesRead;
|
||||||
|
int len = 8192;
|
||||||
|
byte[] buffer = new byte[len];
|
||||||
|
while ((bytesRead = ins.read(buffer, 0, len)) != -1) {
|
||||||
|
os.write(buffer, 0, bytesRead);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
CloseUtil.close(os);
|
||||||
|
CloseUtil.close(ins);
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将文件名解析成文件的上传路径
|
||||||
|
*/
|
||||||
|
public static File upload(MultipartFile file, String filePath) {
|
||||||
|
Date date = new Date();
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
|
||||||
|
String name = getFileNameNoEx(file.getOriginalFilename());
|
||||||
|
String suffix = getExtensionName(file.getOriginalFilename());
|
||||||
|
String nowStr = "-" +"ADMIN"+ "-" + format.format(date);
|
||||||
|
try {
|
||||||
|
String fileName = name + nowStr + "." + suffix;
|
||||||
|
String path = filePath + fileName;
|
||||||
|
// getCanonicalFile 可解析正确各种路径
|
||||||
|
File dest = new File(path).getCanonicalFile();
|
||||||
|
// 检测是否存在目录
|
||||||
|
if (!dest.getParentFile().exists()) {
|
||||||
|
if (!dest.getParentFile().mkdirs()) {
|
||||||
|
System.out.println("was not successful.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 文件写入
|
||||||
|
file.transferTo(dest);
|
||||||
|
return dest;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出excel
|
||||||
|
*/
|
||||||
|
public static void downloadExcel(List<Map<String, Object>> list, HttpServletResponse response) throws Exception {
|
||||||
|
log.error("list:"+list.size());
|
||||||
|
|
||||||
|
|
||||||
|
FileProperties properties= SpringContextHolder.getBean(FileProperties.class);
|
||||||
|
String tempPath=properties.getPath().getPath()+"downexcel\\"+IdUtil.fastSimpleUUID() + ".xlsx";
|
||||||
|
File file = new File(tempPath);
|
||||||
|
log.error(tempPath);
|
||||||
|
|
||||||
|
//BigExcelWriter writer = ExcelUtil.getBigWriter(file);
|
||||||
|
MyExcelWriter writer =MyExcelWriter.getBigWriter(file);
|
||||||
|
// 一次性写出内容,使用默认样式,强制输出标题
|
||||||
|
writer.write(list, true);
|
||||||
|
//列宽自适应
|
||||||
|
writer.autoSizeColumnAll();
|
||||||
|
//response为HttpServletResponse对象
|
||||||
|
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||||
|
//test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码
|
||||||
|
response.setHeader("Content-Disposition","attachment;filename=file.xls");
|
||||||
|
ServletOutputStream out = response.getOutputStream();
|
||||||
|
// 终止后删除临时文件
|
||||||
|
file.deleteOnExit();
|
||||||
|
writer.flush(out, true);
|
||||||
|
//此处记得关闭输出Servlet流
|
||||||
|
IoUtil.close(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFileType(String type) {
|
||||||
|
String documents = "txt doc pdf ppt pps xlsx xls docx";
|
||||||
|
String music = "mp3 wav wma mpa ram ra aac aif m4a";
|
||||||
|
String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg";
|
||||||
|
String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg";
|
||||||
|
String apk = "apk";
|
||||||
|
String zip = "zip rar 7z";
|
||||||
|
if (apk.contains(type)) {
|
||||||
|
return APK;
|
||||||
|
}else if (zip.contains(type)) {
|
||||||
|
return ZIP;
|
||||||
|
}else if (image.contains(type)) {
|
||||||
|
return IMAGE;
|
||||||
|
} else if (documents.contains(type)) {
|
||||||
|
return TXT;
|
||||||
|
} else if (music.contains(type)) {
|
||||||
|
return MUSIC;
|
||||||
|
} else if (video.contains(type)) {
|
||||||
|
return VIDEO;
|
||||||
|
} else {
|
||||||
|
return OTHER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkSize(long maxSize, long size) {
|
||||||
|
// 1M
|
||||||
|
int len = 1024 * 1024;
|
||||||
|
if (size > (maxSize * len)) {
|
||||||
|
throw new BadRequestException("文件超出规定大小:" + maxSize + "MB");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断两个文件是否相同
|
||||||
|
*/
|
||||||
|
public static boolean check(File file1, File file2) {
|
||||||
|
String img1Md5 = getMd5(file1);
|
||||||
|
String img2Md5 = getMd5(file2);
|
||||||
|
if(img1Md5 != null){
|
||||||
|
return img1Md5.equals(img2Md5);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断两个文件是否相同
|
||||||
|
*/
|
||||||
|
public static boolean check(String file1Md5, String file2Md5) {
|
||||||
|
return file1Md5.equals(file2Md5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] getByte(File file) {
|
||||||
|
// 得到文件长度
|
||||||
|
byte[] b = new byte[(int) file.length()];
|
||||||
|
InputStream in = null;
|
||||||
|
try {
|
||||||
|
in = new FileInputStream(file);
|
||||||
|
try {
|
||||||
|
System.out.println(in.read(b));
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
CloseUtil.close(in);
|
||||||
|
}
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getMd5(byte[] bytes) {
|
||||||
|
// 16进制字符
|
||||||
|
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||||
|
try {
|
||||||
|
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
|
||||||
|
mdTemp.update(bytes);
|
||||||
|
byte[] md = mdTemp.digest();
|
||||||
|
int j = md.length;
|
||||||
|
char[] str = new char[j * 2];
|
||||||
|
int k = 0;
|
||||||
|
// 移位 输出字符串
|
||||||
|
for (byte byte0 : md) {
|
||||||
|
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
|
||||||
|
str[k++] = hexDigits[byte0 & 0xf];
|
||||||
|
}
|
||||||
|
return new String(str);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载文件
|
||||||
|
*
|
||||||
|
* @param request /
|
||||||
|
* @param response /
|
||||||
|
* @param file /
|
||||||
|
*/
|
||||||
|
public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) {
|
||||||
|
response.setCharacterEncoding(request.getCharacterEncoding());
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
FileInputStream fis = null;
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
|
||||||
|
IOUtils.copy(fis, response.getOutputStream());
|
||||||
|
response.flushBuffer();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
} finally {
|
||||||
|
if (fis != null) {
|
||||||
|
try {
|
||||||
|
fis.close();
|
||||||
|
if (deleteOnExit) {
|
||||||
|
file.deleteOnExit();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMd5(File file) {
|
||||||
|
return getMd5(getByte(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.yc.wms.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.exceptions.DependencyException;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
|
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MyExcelWriter extends BigExcelWriter {
|
||||||
|
public static MyExcelWriter getBigWriter(File file) {
|
||||||
|
try {
|
||||||
|
return new MyExcelWriter(file);
|
||||||
|
} catch (NoClassDefFoundError var1) {
|
||||||
|
System.out.println("NoClassDefFoundError");
|
||||||
|
throw new DependencyException((Throwable) ObjectUtil.defaultIfNull(var1.getCause(), var1), "You need to add dependency of 'poi-ooxml' to your project, and version >= 4.1.2", new Object[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyExcelWriter(File file){
|
||||||
|
super(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigExcelWriter autoSizeColumnAll() {
|
||||||
|
final SXSSFSheet sheet = (SXSSFSheet)this.sheet;
|
||||||
|
sheet.trackAllColumnsForAutoSizing();
|
||||||
|
super.autoSizeColumnAll();
|
||||||
|
for (int i = 0; i <sheet.getRow(sheet.getLastRowNum()).getPhysicalNumberOfCells(); i++) {
|
||||||
|
// 解决自动设置列宽中文失效的问题
|
||||||
|
int colWidth =(sheet.getColumnWidth(i) * 17 / 8);
|
||||||
|
if(colWidth<255*256){
|
||||||
|
sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth);
|
||||||
|
}else{
|
||||||
|
sheet.setColumnWidth(i,6000 );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
sheet.untrackAllColumnsForAutoSizing();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -27,4 +27,17 @@ spring:
|
||||||
maximum-pool-size: 10
|
maximum-pool-size: 10
|
||||||
minimum-idle: 10
|
minimum-idle: 10
|
||||||
read-only: false
|
read-only: false
|
||||||
|
# 文件存储路径
|
||||||
|
file:
|
||||||
|
mac:
|
||||||
|
path: ~/file/
|
||||||
|
avatar: ~/avatar/
|
||||||
|
linux:
|
||||||
|
path: /home/eladmin/file/
|
||||||
|
avatar: /home/eladmin/avatar/
|
||||||
|
windows:
|
||||||
|
path: C:\eladmin\file\
|
||||||
|
avatar: C:\eladmin\avatar\
|
||||||
|
# 文件大小 /M
|
||||||
|
maxSize: 200
|
||||||
|
avatarMaxSize: 5
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue