Commit 45b9a1c9 authored by wanghao's avatar wanghao

燃气用户界面 错误数据导出 再导入功能

parent b356e50f
......@@ -2,14 +2,14 @@ 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 java.util.*;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelXorHtmlUtil;
import cn.afterturn.easypoi.excel.entity.ExcelToHtmlParams;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
......@@ -329,6 +329,8 @@ public class TDetectorUserController extends BaseController
file = ResourceUtils.getFile("/data/java/baseversion/importTemplate/燃气用户错误导入数据模版.xlsx");
}
InputStream inp = new FileInputStream(file);
// 获取文件名
String filename = file.getName();
......@@ -341,44 +343,22 @@ public class TDetectorUserController extends BaseController
userManageGasUserExportVos.add(userManageGasUserExportVo);
}
ExportParams exportParams = new ExportParams("数据列表", "数据", file.getPath());
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, UserManageGasUserExportVo.class,userManageGasUserExportVos);
TemplateExportParams params = new TemplateExportParams(file.getAbsolutePath(), true);
Map<String, Object> total = new HashMap<>();
total.put("maplist",userManageGasUserExportVos);
Workbook workbook = ExcelExportUtil.exportExcel(params, total);
System.out.println("file.getPath = " + file.getPath());
System.out.println("file.getAbsolutePath = " + file.getAbsolutePath());
String fileName = "燃气用户错误导入数据模版.xlsx";
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
// 新的文件路径
String[] split = file.getPath().split("\\\\");
StringBuilder stringBuilder = new StringBuilder();
OutputStream outputStream = response.getOutputStream();
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();
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
workbook.close();
} catch (IOException ex) {
ex.printStackTrace();
......@@ -467,11 +447,17 @@ public class TDetectorUserController extends BaseController
@PostMapping("/moreSheetImportExcel")
public AjaxResult moreSheetImportExcel(MultipartFile file,boolean updateSupport) throws Exception {
List<UserManageGasUserExportVo> userManageGasUserobjects = ExcelUtil.moreSheetImportExcel(file, 1, 2, UserManageGasUserExportVo.class, 0);
String originalFilename = file.getOriginalFilename();
if (originalFilename != null && originalFilename.contains("错误")) {
List<UserManageGasUserExportVo> userManageGasUserobjects = ExcelUtil.moreSheetImportExcel(file, 1, 2, UserManageGasUserExportVo.class, 0);
tDetectorUserService.handleCustomMoreSheetImportData(userManageGasUserobjects,null,updateSupport,true);
List<UserManageSafetyDeviceExportVo> userManageSafetyobjects = ExcelUtil.moreSheetImportExcel(file, 1, 2, UserManageSafetyDeviceExportVo.class, 1);
} else{
List<UserManageGasUserExportVo> userManageGasUserobjects = ExcelUtil.moreSheetImportExcel(file, 1, 2, UserManageGasUserExportVo.class, 0);
List<UserManageSafetyDeviceExportVo> userManageSafetyobjects = ExcelUtil.moreSheetImportExcel(file, 1, 2, UserManageSafetyDeviceExportVo.class, 1);
tDetectorUserService.handleCustomMoreSheetImportData(userManageGasUserobjects,userManageSafetyobjects,updateSupport,false);
tDetectorUserService.handleCustomMoreSheetImportData(userManageGasUserobjects,userManageSafetyobjects,updateSupport);
}
return AjaxResult.success();
}
......
......@@ -152,7 +152,16 @@
<artifactId>easypoi-base</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.2.0</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.zehong.common.utils.poi;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import com.zehong.common.annotation.Excel;
import com.zehong.common.annotation.Excel.ColumnType;
import com.zehong.common.annotation.Excel.Type;
......@@ -18,11 +21,14 @@ import com.zehong.common.utils.file.FileTypeUtils;
import com.zehong.common.utils.file.ImageUtils;
import com.zehong.common.utils.reflect.ReflectUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.omg.PortableInterceptor.USER_EXCEPTION;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
......@@ -1288,4 +1294,21 @@ public class ExcelUtil<T>
}
return result.getList();
}
//导出的时候格式很重要 .xls对应 ExcelType.HSSF .xlsx对应 ExcelType.XSSF 默认ExportParams.type= ExcelType.HSSF
public static Workbook exportExcel(ExportParams entity, Class<?> pojoClass,
Collection<?> dataSet) {
Workbook workbook = getWorkbook(entity.getType(),dataSet.size());
new ExcelExportService().createSheet(workbook, entity, pojoClass, dataSet);
return workbook;
}
private static Workbook getWorkbook(ExcelType type, int size) {
if (ExcelType.HSSF.equals(type)) {
return new HSSFWorkbook();
} else if (size < 100000) {
return new XSSFWorkbook();
} else {
return new SXSSFWorkbook();
}
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import cn.afterturn.easypoi.excel.annotation.Excel;
public class UserManageGasUserExportVo {
/** 用户账号 */
@Excel(name = "用户自有编号", needMerge = true)
@Excel(name = "用户自有编号")
private String userOwnId;
/** id */
......@@ -13,20 +13,20 @@ public class UserManageGasUserExportVo {
private Long userId;
/** 用户名称 */
@Excel(name = "用户名称", needMerge = true)
@Excel(name = "用户名称")
private String nickName;
@Excel(name = "燃气类型(0-天然气;1-液化气)", needMerge = true)
@Excel(name = "燃气类型(0-天然气;1-液化气)")
private String gasType;
/** 用户类型(1居民用户,2商业用户,3工业用户) */
@Excel(name = "用户类型(1-居民用户;2-商业用户;3-工业用户;4-餐饮单位用户)", needMerge = true)
@Excel(name = "用户类型(1-居民用户;2-商业用户;3-工业用户;4-餐饮单位用户)")
private String userType;
/**
* 所属企业名称
*/
@Excel(name = "所属企业", needMerge = true)
@Excel(name = "所属企业")
private String beyondEnterpriseName;
private String beyondEnterpriseId;
......@@ -34,7 +34,7 @@ public class UserManageGasUserExportVo {
/**
* 居住区(村、庄)
*/
@Excel(name = "居住区(村、庄)", needMerge = true)
@Excel(name = "居住区(村、庄)")
private String villageName;
/**
......@@ -43,23 +43,23 @@ public class UserManageGasUserExportVo {
private Long villageId;
/** 地址 */
@Excel(name = "地址", needMerge = true)
@Excel(name = "地址")
private String address;
/** 联系人 */
@Excel(name = "联系人", needMerge = true)
@Excel(name = "联系人")
private String linkman;
/** 电话 */
@Excel(name = "电话", needMerge = true)
@Excel(name = "电话")
private String phone;
/** 备注 */
@Excel(name = "备注", needMerge = true)
@Excel(name = "备注")
private String remarks;
/** 错误信息 */
@Excel(name = "错误信息", needMerge = true)
@Excel(name = "错误信息")
private String errorMsg;
public String getUserOwnId() {
......
......@@ -25,7 +25,7 @@ public interface TEnterpriseInfoMapper
* @param enterpriseName 企业信息名称
* @return 企业信息
*/
public TEnterpriseInfo selectTEnterpriseInfoByName(String enterpriseName);
public List<TEnterpriseInfo> selectTEnterpriseInfoByName(String enterpriseName);
/**
* 查询企业信息列表
......
......@@ -192,7 +192,7 @@ public interface ITDetectorUserService
*/
public void handleCustomMoreSheetImportData(List<UserManageGasUserExportVo> gasUserExportVos,
List<UserManageSafetyDeviceExportVo> safetyDeviceExportVos,
boolean updateSupport ) ;
boolean updateSupport ,boolean reImportOfIncorrectDataFlag) ;
/**
* 根据企业id统计错误数据
......
package com.zehong.system.service.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -20,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
* 燃气用户Service业务层处理
......@@ -47,6 +51,8 @@ public class TDetectorUserServiceImpl implements ITDetectorUserService
@Resource
private TDetectorUserErrorMapper tDetectorUserErrorMapper;
@Resource
private DataSource dataSource;
/**
* 查询探测器用户列表
*
......@@ -450,12 +456,13 @@ public class TDetectorUserServiceImpl implements ITDetectorUserService
* 处理解析好的 自定义模版的导入的数据 多sheet
* @param gasUserExportVos d 燃气用户数据
* @param safetyDeviceExportVos s 安全装置信息
* @param reImportOfIncorrectDataFlag r 错误数据重新导入标志 true 表示错误数据重新导入
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void handleCustomMoreSheetImportData(List<UserManageGasUserExportVo> gasUserExportVos,
List<UserManageSafetyDeviceExportVo> safetyDeviceExportVos,
boolean updateSupport) {
boolean updateSupport,boolean reImportOfIncorrectDataFlag) {
List<TDetectorUser> successDataList = new ArrayList<>();
......@@ -478,8 +485,11 @@ public class TDetectorUserServiceImpl implements ITDetectorUserService
String beyondEnterpriseName = gasUserExportVo.getBeyondEnterpriseName();
String villageName = gasUserExportVo.getVillageName();
if (StringUtils.isBlank(userOwnId)) {
stringBuilder.append("用户自由id为空|");
if(!reImportOfIncorrectDataFlag) {
if (StringUtils.isBlank(userOwnId)) {
stringBuilder.append("用户自由id为空|");
}
}
if (StringUtils.isNotBlank(gasType)){
......@@ -497,11 +507,11 @@ public class TDetectorUserServiceImpl implements ITDetectorUserService
if (StringUtils.isBlank(beyondEnterpriseName)) {
stringBuilder.append("所属企业为空|");
} else {
TEnterpriseInfo tEnterpriseInfo = tEnterpriseInfoMapper.selectTEnterpriseInfoByName(beyondEnterpriseName);
if (tEnterpriseInfo == null) {
stringBuilder.append("所属企业不存在|");
List<TEnterpriseInfo> tEnterpriseInfos = tEnterpriseInfoMapper.selectTEnterpriseInfoByName(beyondEnterpriseName);
if (tEnterpriseInfos != null && tEnterpriseInfos.size() > 0) {
gasUserExportVo.setBeyondEnterpriseId(tEnterpriseInfos.get(0).getEnterpriseId());
} else {
gasUserExportVo.setBeyondEnterpriseId(tEnterpriseInfo.getEnterpriseId());
stringBuilder.append("所属企业不存在|");
}
}
......@@ -578,7 +588,40 @@ public class TDetectorUserServiceImpl implements ITDetectorUserService
//是要修改的
List<TDetectorUser> updateCollect = successDataList.stream().filter(item -> item.getUserId() != null).collect(Collectors.toList());
if (updateCollect.size() > 0) {
tDetectorUserMapper.updateBatch(updateCollect);
// tDetectorUserMapper.updateBatch(updateCollect);
String sql = "UPDATE t_detector_user \n" +
"SET nick_name = ?,\n" +
"user_type = ?,\n" +
"gas_type = ?,\n" +
"f_village_id = ?,\n" +
"beyond_enterprise_id = ?,\n" +
"address = ?,\n" +
"linkman = ?,\n" +
"phone = ?,\n" +
"remarks = ?,\n" +
"error_msg = ? \n" +
"WHERE\n" +
"\tuser_id = ?";
try (Connection conn = dataSource.getConnection()) {
PreparedStatement pstmt = conn.prepareStatement(sql);
for (TDetectorUser detectorUser : updateCollect) {
pstmt.setString(1,detectorUser.getNickName());
pstmt.setString(2,detectorUser.getUserType());
pstmt.setString(3,detectorUser.getGasType());
pstmt.setLong(4,detectorUser.getVillageId());
pstmt.setString(5,detectorUser.getBeyondEnterpriseId());
pstmt.setString(6,detectorUser.getAddress());
pstmt.setString(7,detectorUser.getLinkman());
pstmt.setString(8,detectorUser.getPhone());
pstmt.setString(9,detectorUser.getRemarks());
pstmt.setString(10,null);
pstmt.setLong(11,detectorUser.getUserId());
pstmt.addBatch();
}
pstmt.executeBatch();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
......
......@@ -157,8 +157,8 @@ public class TEmployedPeopleInfoServiceImpl implements ITEmployedPeopleInfoServi
stringBuilder.append("企业信息为空|");
}
TEnterpriseInfo enterpriseInfo = enterpriseInfoMapper.selectTEnterpriseInfoByName(tEmployedPeopleInfo.getBeyondEnterpriseName());
if (enterpriseInfo == null) {
List<TEnterpriseInfo> tEnterpriseInfos = enterpriseInfoMapper.selectTEnterpriseInfoByName(tEmployedPeopleInfo.getBeyondEnterpriseName());
if (tEnterpriseInfos == null) {
stringBuilder.append("关联企业信息不存在|");
}
......
......@@ -21,9 +21,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateTime" column="update_time" />
<result property="isDel" column="is_del" />
<result property="remarks" column="remarks" />
<result property="beyondEnterpriseName" column="enterprise_name" />
<result property="beyondEnterpriseName" column="beyond_enterprise_name" />
<result property="villageId" column="f_village_id" />
<result property="villageName" column="f_village_name" />
<result property="villageName" column="village_name" />
<result property="errorMsg" column="error_msg" />
</resultMap>
......@@ -283,17 +283,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</insert>
<update id="updateBatch" parameterType="list">
<foreach collection="list" item="item" separator=";">
<foreach collection="list" item="item" index="index" separator=";">
UPDATE t_detector_user
SET nick_name = #{item.nickName},
user_type = #{item.userType},
gas_type = #{item.gasType},
f_village_id = #{item.villageId},
beyond_enterprise_id = #{item.beyondEnterpriseId},
address = #{item.address},
linkman = #{item.linkman},
phone = #{item.phone},
remarks = #{item.remarks}
<set>
nick_name = #{item.nickName},
user_type = #{item.userType},
gas_type = #{item.gasType},
f_village_id = #{item.villageId},
beyond_enterprise_id = #{item.beyondEnterpriseId},
address = #{item.address},
linkman = #{item.linkman},
phone = #{item.phone},
remarks = #{item.remarks},
error_msg = null
</set>
WHERE user_id = #{item.userId}
</foreach>
......
......@@ -172,6 +172,7 @@ export function clearImportError() {
export function exportErrorData() {
return request({
url: '/supervise/user/exportErrorData',
method: 'get'
method: 'get',
responseType: 'blob'
})
}
\ No newline at end of file
......@@ -830,6 +830,7 @@ export default {
this.getDataList();
this.countImportError();
this.getList();
// //导入后 刷新 任职岗位字典数据
// this.peopleOccupationOptions = [];
// this.queryPeopleOccupationByGroupByMethod();
......
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