Commit b356e50f authored by wanghao's avatar wanghao

1 燃气用户界面 错误数据导出 再导入功能实现中。

parent 87d1d614
...@@ -2,8 +2,17 @@ package com.zehong.web.controller.supervise; ...@@ -2,8 +2,17 @@ package com.zehong.web.controller.supervise;
import java.io.*; import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.zehong.common.core.domain.entity.SysUser; import com.zehong.common.core.domain.entity.SysUser;
import com.zehong.common.core.domain.model.LoginUser; import com.zehong.common.core.domain.model.LoginUser;
import com.zehong.common.utils.SecurityUtils; import com.zehong.common.utils.SecurityUtils;
...@@ -15,6 +24,8 @@ import com.zehong.system.domain.vo.GasUserAndSafetyDeviceVo; ...@@ -15,6 +24,8 @@ import com.zehong.system.domain.vo.GasUserAndSafetyDeviceVo;
import com.zehong.system.domain.vo.TDetectorUserInspectVo; import com.zehong.system.domain.vo.TDetectorUserInspectVo;
import com.zehong.system.domain.vo.UserManageSafetyDeviceExportVo; import com.zehong.system.domain.vo.UserManageSafetyDeviceExportVo;
import com.zehong.system.service.ITDetectorUserErrorService; import com.zehong.system.service.ITDetectorUserErrorService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
...@@ -318,36 +329,57 @@ public class TDetectorUserController extends BaseController ...@@ -318,36 +329,57 @@ public class TDetectorUserController extends BaseController
file = ResourceUtils.getFile("/data/java/baseversion/importTemplate/燃气用户错误导入数据模版.xlsx"); file = ResourceUtils.getFile("/data/java/baseversion/importTemplate/燃气用户错误导入数据模版.xlsx");
} }
// 获取文件名
String filename = file.getName();
List<TDetectorUser> tDetectorUsers = tDetectorUserService.queryErrorDetectorUserList(); List<TDetectorUser> tDetectorUsers = tDetectorUserService.queryErrorDetectorUserList();
List<UserManageGasUserExportVo> userManageGasUserExportVos = new ArrayList<>();
for (TDetectorUser tDetectorUser : tDetectorUsers) {
UserManageGasUserExportVo userManageGasUserExportVo = new UserManageGasUserExportVo();
BeanUtils.copyProperties(tDetectorUser,userManageGasUserExportVo);
userManageGasUserExportVos.add(userManageGasUserExportVo);
}
ExportParams exportParams = new ExportParams("数据列表", "数据", file.getPath());
// 获取文件名 Workbook workbook = ExcelExportUtil.exportExcel(exportParams, UserManageGasUserExportVo.class,userManageGasUserExportVos);
String filename = file.getName();
// 获取文件后缀名
String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
// 将文件写入输入流 System.out.println("file.getPath = " + file.getPath());
FileInputStream fileInputStream = new FileInputStream(file); System.out.println("file.getAbsolutePath = " + file.getAbsolutePath());
InputStream fis = new BufferedInputStream(fileInputStream);
byte[] buffer = new byte[fis.available()]; // 新的文件路径
fis.read(buffer); String[] split = file.getPath().split("\\\\");
fis.close(); StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < split.length - 1; i++) {
stringBuilder.append(split[i] + "\\");
}
stringBuilder.append("错误数据.xlsx");
System.out.println("filepaht = " + stringBuilder);
// 将 Excel 写入文件系统
FileOutputStream fos = new FileOutputStream(stringBuilder.toString());
workbook.write(fos);
fos.close();
// // 清空response
// response.reset();
// // 设置response的Header
// response.setCharacterEncoding("UTF-8");
// //Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
// //attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
// // filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
// response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
// // 告知浏览器文件的大小
// response.addHeader("Content-Length", "" + file.length());
// OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
// response.setContentType("application/octet-stream");
// outputStream.write(workbook);
// outputStream.flush();
// 清空response
response.reset();
// 设置response的Header
response.setCharacterEncoding("UTF-8");
//Content-Disposition的作用:告知浏览器以何种方式显示响应返回的文件,用浏览器打开还是以附件的形式下载到本地保存
//attachment表示以附件方式下载 inline表示在线打开 "Content-Disposition: inline; filename=文件名.mp3"
// filename表示文件的默认名称,因为网络传输只支持URL编码的相关支付,因此需要将文件名URL编码后进行传输,前端收到后需要反编码才能获取到真正的名称
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
// 告知浏览器文件的大小
response.addHeader("Content-Length", "" + file.length());
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
outputStream.write(buffer);
outputStream.flush();
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
......
...@@ -27,6 +27,7 @@ import org.slf4j.Logger; ...@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
...@@ -1199,7 +1200,6 @@ public class ExcelUtil<T> ...@@ -1199,7 +1200,6 @@ public class ExcelUtil<T>
} }
} }
/** /**
* 针对燃气用户的 多sheet导入数据 * 针对燃气用户的 多sheet导入数据
* @param file f * @param file f
......
...@@ -58,6 +58,10 @@ public class UserManageGasUserExportVo { ...@@ -58,6 +58,10 @@ public class UserManageGasUserExportVo {
@Excel(name = "备注", needMerge = true) @Excel(name = "备注", needMerge = true)
private String remarks; private String remarks;
/** 错误信息 */
@Excel(name = "错误信息", needMerge = true)
private String errorMsg;
public String getUserOwnId() { public String getUserOwnId() {
return userOwnId; return userOwnId;
} }
...@@ -154,6 +158,14 @@ public class UserManageGasUserExportVo { ...@@ -154,6 +158,14 @@ public class UserManageGasUserExportVo {
this.userId = userId; this.userId = userId;
} }
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public String getBeyondEnterpriseId() { public String getBeyondEnterpriseId() {
return beyondEnterpriseId; return beyondEnterpriseId;
} }
......
...@@ -166,3 +166,12 @@ export function clearImportError() { ...@@ -166,3 +166,12 @@ export function clearImportError() {
method: 'get' method: 'get'
}) })
} }
// 导出从业人员信息- 错误数据
export function exportErrorData() {
return request({
url: '/supervise/user/exportErrorData',
method: 'get'
})
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment