Commit b356e50f authored by wanghao's avatar wanghao

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

parent 87d1d614
......@@ -2,8 +2,17 @@ package com.zehong.web.controller.supervise;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
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.model.LoginUser;
import com.zehong.common.utils.SecurityUtils;
......@@ -15,6 +24,8 @@ import com.zehong.system.domain.vo.GasUserAndSafetyDeviceVo;
import com.zehong.system.domain.vo.TDetectorUserInspectVo;
import com.zehong.system.domain.vo.UserManageSafetyDeviceExportVo;
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.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
......@@ -318,36 +329,57 @@ public class TDetectorUserController extends BaseController
file = ResourceUtils.getFile("/data/java/baseversion/importTemplate/燃气用户错误导入数据模版.xlsx");
}
// 获取文件名
String filename = file.getName();
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());
// 获取文件名
String filename = file.getName();
// 获取文件后缀名
String ext = filename.substring(filename.lastIndexOf(".") + 1).toLowerCase();
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, UserManageGasUserExportVo.class,userManageGasUserExportVos);
// 将文件写入输入流
FileInputStream fileInputStream = new FileInputStream(file);
InputStream fis = new BufferedInputStream(fileInputStream);
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
fis.close();
System.out.println("file.getPath = " + file.getPath());
System.out.println("file.getAbsolutePath = " + file.getAbsolutePath());
// 新的文件路径
String[] split = file.getPath().split("\\\\");
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) {
ex.printStackTrace();
}
......
......@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
......@@ -1199,7 +1200,6 @@ public class ExcelUtil<T>
}
}
/**
* 针对燃气用户的 多sheet导入数据
* @param file f
......
......@@ -58,6 +58,10 @@ public class UserManageGasUserExportVo {
@Excel(name = "备注", needMerge = true)
private String remarks;
/** 错误信息 */
@Excel(name = "错误信息", needMerge = true)
private String errorMsg;
public String getUserOwnId() {
return userOwnId;
}
......@@ -154,6 +158,14 @@ public class UserManageGasUserExportVo {
this.userId = userId;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public String getBeyondEnterpriseId() {
return beyondEnterpriseId;
}
......
......@@ -166,3 +166,12 @@ export function clearImportError() {
method: 'get'
})
}
// 导出从业人员信息- 错误数据
export function exportErrorData() {
return request({
url: '/supervise/user/exportErrorData',
method: 'get'
})
}
\ No newline at end of file
......@@ -65,7 +65,7 @@
@click="handleExport"
>导出</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="info"
......@@ -73,12 +73,12 @@
size="mini"
@click="handleImport">导入</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
type="danger"
icon="el-icon-download"
size="mini"
size="mini"
@click="handleImportError"
class="button-with-badge"
>
......@@ -87,7 +87,7 @@
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
......@@ -218,7 +218,7 @@
</el-option>
</el-select>
</el-form-item>
</el-col>
</el-col>
</el-row>
<el-row>
......@@ -227,8 +227,8 @@
<el-input v-model="form.address" placeholder="请输入地址" />
</el-form-item>
</el-col>
</el-row>
</el-row>
<el-row>
<el-col :span="21">
<el-form-item label="经纬度坐标" prop="longitude">
......@@ -281,7 +281,7 @@
<img :src="relationImg" style="width: 24px; height: 25px;position: relative; left: -355px; top: -12px;"/>
<span class="midText">安全装置</span>
</div>
<el-table v-loading="loadings" ref="multipleTable" :data="DetailInfoList" tooltip-effect="dark" style="width: 100%" max-height="250" @selection-change="tableDataSelectionChange">
<el-table-column label="设备名称" align="center" prop="deviceName" />
<el-table-column label="设备型号" align="center" prop="deviceModel" />
......@@ -333,7 +333,7 @@
<el-row>
<el-col :span="11">
<el-form-item label="设备类型" prop="relationDeviceType">
<el-input v-model="formDetailInfo.relationDeviceType" placeholder="请输入设备类型">
<el-input v-model="formDetailInfo.relationDeviceType" placeholder="请输入设备类型">
</el-input>
</el-form-item>
</el-col>
......@@ -343,17 +343,17 @@
<el-input v-model="formDetailInfo.fIotNo" placeholder="请输入物联网编号" />
</el-form-item>
</el-col>
</el-row>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="设备安装时间" prop="deviceInstallTime">
<el-form-item label="设备安装时间" prop="deviceInstallTime">
<el-date-picker clearable size="small"
v-model="formDetailInfo.deviceInstallTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择安装时间">
</el-date-picker>
</el-date-picker>
</el-form-item>
</el-col>
......@@ -362,12 +362,12 @@
<el-input v-model="formDetailInfo.deviceInstallPosition" placeholder="请输入安装位置" />
</el-form-item>
</el-col>
</el-row>
</el-row>
<el-row>
<el-col :span="11">
<el-form-item label="负责人" prop="head">
<el-input v-model="formDetailInfo.head" placeholder="请输入负责人">
<el-input v-model="formDetailInfo.head" placeholder="请输入负责人">
</el-input>
</el-form-item>
</el-col>
......@@ -377,9 +377,9 @@
<el-input v-model="formDetailInfo.phone" placeholder="请输入联系电话" />
</el-form-item>
</el-col>
</el-row>
</el-row>
<el-row>
<el-row>
<el-col :span="22">
<el-form-item label="探测介质" prop="detectionMedium" >
<el-input v-model="formDetailInfo.detectionMedium" placeholder="请输入探测介质" />
......@@ -393,7 +393,7 @@
</div>
</el-dialog>
<!--选择安全装置弹出框-->
<el-dialog title="选择安全装置" width="1100px" :visible.sync="dialogTableVisible" formLabelWidth="160px">
<template>
......@@ -440,7 +440,7 @@
size="mini"
@click="dialogFormVisible = true"
>新增</el-button>
</el-col>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
......@@ -450,7 +450,7 @@
:disabled="multiple"
@click="deleteListDetailInfo"
>删除</el-button>
</el-col>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getDataList"></right-toolbar>
</el-row>
<el-table v-loading="safetyDeviceManageLoadings" ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%" max-height="250" @selection-change="tableDataSelectionChange">
......@@ -463,7 +463,7 @@
<el-table-column label="设备安装时间" width="100" align="center" prop="deviceInstallTime" />
<el-table-column label="安装位置" align="center" prop="deviceInstallPosition" />
<el-table-column label="负责人" align="center" prop="head" />
<el-table-column label="联系电话" align="center" prop="phone" />
<el-table-column label="联系电话" align="center" prop="phone" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
......@@ -489,7 +489,7 @@
@close="dialogcancelFun"
@getPath="getPath"
/>
<!-- 用户导入对话框 -->
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
......@@ -521,15 +521,15 @@
</el-dialog>
<!-- 燃气用户错误数据弹出框 -->
<el-dialog :title="importErrorShowTitle" :visible.sync="importErrorShow" width="400px" append-to-body>
<el-dialog :title="importErrorShowTitle" :visible.sync="importErrorShow" width="400px" append-to-body>
<el-form>
<el-form-item>
<div style="width: 100%; text-align: center;">
<el-button type="primary" @click="downloadImportError">下载</el-button>
<el-button type="danger" @click="clearImportErrorMethod">清除错误数据</el-button>
<el-button type="danger" @click="clearImportErrorMethod">清除错误数据</el-button>
</div>
</el-form-item>
</el-form>
</el-form>
</el-dialog>
</div>
......@@ -540,7 +540,7 @@ import { listUser, getUser, delUser, addUser, updateUser,newExportUser,
getNoSelectSafetyDetailInfo,addSafetyDetailInfo,deleteSafetyDeviceInfo,
deleteSafetyDeviceListInfo,selectSafetyDeviceDetailInfo,
addUserAndSafetyDevice,updateUserAndSafetyDevice,importTemplate,downloadTemplate,
countImportError,clearImportError} from "@/api/regulation/user";
countImportError,clearImportError,exportErrorData} from "@/api/regulation/user";
import { selectTEnterprise} from "@/api/regulation/supervise";
import { noPageListVillage} from "@/api/regulation/userManagement/village";
import GetPos from '@/components/GetPos';
......@@ -565,7 +565,7 @@ export default {
headers: { Authorization: "Bearer " + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + "/supervise/user/moreSheetImportExcel" // todo
},
},
importError: null,
importErrorShow: false,
......@@ -680,7 +680,7 @@ export default {
// { min: 0, max: 30, message: "长度30位", trigger: "blur" },
],
},
//关联设备下级数据 表单校验
formDetailInfoRules:{
deviceName:[
......@@ -710,16 +710,50 @@ export default {
this.gasTypeOpers = response.data;
});
this.getNoPageListVillage();
this.countImportError();
},
methods: {
methods: {
// 下载燃气用户错误 按钮
handleImportError() {
if(this.importError === 0) {
this.$alert('暂无错误数据', '下载', {
confirmButtonText: '确定',
});
return
} else {
this.importErrorShow = true;
}
},
// 下载燃气用户错误 按钮
downloadImportError() {
// importErrorexportInfo().then(response => {
// this.download(response.msg);
// })
downloadImportError() {
// exportErrorData();
exportErrorData().then((res) =>{
let blob = new Blob([res], {type: 'data:application/vnd.ms-excel;base64;charset=utf-8'});
let downloadElement = document.createElement('a');
let href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = '燃气用户导入错误数据'+'.xlsx'; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
return true
})
this.importErrorShow = false;
},
......@@ -748,7 +782,7 @@ export default {
// 提交上传文件
submitFileForm() {
this.$refs.upload.submit();
this.$refs.upload.submit();
},
handleImport(){
......@@ -758,7 +792,7 @@ export default {
/** 下载模板操作 */
importTemplate() {
downloadTemplate().then((res) =>{
downloadTemplate().then((res) =>{
let blob = new Blob([res], {type: 'data:application/vnd.ms-excel;base64;charset=utf-8'});
......@@ -778,9 +812,9 @@ export default {
window.URL.revokeObjectURL(href); //释放掉blob对象
return true
})
},
return true
})
},
// 文件上传处理中
handleFileUploadProgress(event,file,fileList) {
......@@ -816,7 +850,7 @@ export default {
}
},
/**关联设备单条删除方法*/
deleteDetailInfo(row){
const deviceIds = row.gasUserSafetyDeviceId;
......@@ -879,12 +913,12 @@ export default {
//获取已经选中的下级设备id
const deviceIds = this.ids;
const li=this.datalist;
if (this.form.userId != null) {
if (this.form.userId != null) {
if (this.DetailInfoList) {
//修改
this.DetailInfoList=this.DetailInfoList.concat(this.datalist)
} else {
} else {
this.DetailInfoList=this.datalist;
}
//添加到数组中 以便下次使用
......@@ -905,7 +939,7 @@ export default {
this.msgSuccess("添加成功");
}
},
/**关联设备添加方法*/
addSafetyDeviceInfo(){
this.$refs["formDetailInfo"].validate(valid => {
......@@ -951,7 +985,7 @@ export default {
this.safetyDeviceManageLoadings = false;
});
},
/** 下级数据重置按钮操作 搜索框重置*/
resetQueryDate(){
this.dateQueryParams={
......@@ -1057,7 +1091,7 @@ export default {
this.open = true;
this.title = "修改燃气用户";
this.devicePos = [response.data.longitude, response.data.latitude];
});
});
//查询关联设备信息数据
selectSafetyDeviceDetailInfo(userId).then(response => {
......@@ -1074,9 +1108,9 @@ export default {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
if ( this.datalist !=null){
});
if ( this.datalist !=null){
var tDeviceInfon={
detectorUser:this.form,
gasuserSafetyDeviceInfoList:this.datalist
......@@ -1089,7 +1123,7 @@ export default {
}
} else {
var tDeviceInfon={
detectorUser:this.form,
gasuserSafetyDeviceInfoList:this.datalist
......@@ -1169,7 +1203,7 @@ export default {
font-size: 16px;
color: rgba(101, 101, 101, 1);
}
.midText {
position: absolute;
left: 3%;
......@@ -1177,4 +1211,4 @@ export default {
padding: 0 15px;
transform: translateX(-50%) translateY(-50%);
}
</style>
</style>
\ 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