Commit b6911640 authored by wanghao's avatar wanghao

1 燃气用户界面 加入 导入功能 ,实现 两个sheet的导入,目前已经能拿到两个sheet的数据, 入库逻辑实现中。

parent 3e469472
......@@ -2,7 +2,6 @@ package com.zehong.web.controller.supervise;
import java.io.*;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.List;
import com.zehong.common.core.domain.entity.SysUser;
......@@ -11,9 +10,10 @@ import com.zehong.common.utils.SecurityUtils;
import com.zehong.common.utils.ServletUtils;
import com.zehong.framework.web.service.TokenService;
import com.zehong.system.domain.TDetectorUserCount;
import com.zehong.system.domain.vo.GasUserAndSafetyDeviceExportVo;
import com.zehong.system.domain.vo.UserManageGasUserExportVo;
import com.zehong.system.domain.vo.GasUserAndSafetyDeviceVo;
import com.zehong.system.domain.vo.TDetectorUserInspectVo;
import com.zehong.system.domain.vo.UserManageSafetyDeviceExportVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
......@@ -267,7 +267,7 @@ public class TDetectorUserController extends BaseController
@GetMapping("/importTemplate")
public AjaxResult importTemplate()
{
ExcelUtil<GasUserAndSafetyDeviceExportVo> util = new ExcelUtil<>(GasUserAndSafetyDeviceExportVo.class);
ExcelUtil<UserManageGasUserExportVo> util = new ExcelUtil<>(UserManageGasUserExportVo.class);
return util.importTemplateExcel("燃气用户数据");
}
......@@ -281,8 +281,8 @@ public class TDetectorUserController extends BaseController
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport, HttpServletResponse response) throws Exception
{
ExcelUtil<GasUserAndSafetyDeviceExportVo> util = new ExcelUtil<>(GasUserAndSafetyDeviceExportVo.class);
List<GasUserAndSafetyDeviceExportVo> XmbhList = util.importExcel(file.getInputStream());
ExcelUtil<UserManageGasUserExportVo> util = new ExcelUtil<>(UserManageGasUserExportVo.class);
List<UserManageGasUserExportVo> XmbhList = util.importExcel(file.getInputStream());
String operName = SecurityUtils.getLoginUser().getUsername();
String message = tDetectorUserService.importEmployedPeopleInfo(XmbhList, updateSupport, operName,response);
return AjaxResult.success(message);
......@@ -354,12 +354,27 @@ public class TDetectorUserController extends BaseController
*/
@PostMapping("/importCustom")
public AjaxResult importData(MultipartFile file,boolean updateSupport) throws Exception {
List<GasUserAndSafetyDeviceExportVo> dataInfos = ExcelUtil.importExcel(file, 1, 2, GasUserAndSafetyDeviceExportVo.class);
for (GasUserAndSafetyDeviceExportVo dataInfo : dataInfos) {
System.out.println(dataInfo.getLinkman());
List<UserManageGasUserExportVo> dataInfos = ExcelUtil.importExcel(file, 1, 2, UserManageGasUserExportVo.class);
if(dataInfos != null && dataInfos.size() > 0) {
tDetectorUserService.handleCustomImportData(dataInfos,updateSupport);
}
return AjaxResult.success();
}
/**
* 自定义模版的多sheet导入
* @param file
* @return
* @throws Exception
*/
@PostMapping("/moreSheetImportExcel")
public AjaxResult moreSheetImportExcel(MultipartFile file,boolean updateSupport) throws Exception {
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);
return AjaxResult.success();
}
}
......@@ -1200,14 +1200,62 @@ public class ExcelUtil<T>
}
/**
* 针对燃气用户的 多sheet导入数据
* @param file f
* @param titleRows 标题在第几行
* @param headerRows 表头在第几行
* @param <T> t
* @return r
*/
public static <T> List<T> moreSheetImportExcel(MultipartFile file,
Integer titleRows,
Integer headerRows,
Class<T> Clazz,
Integer sheetIndex) {
Map<String,List<T>> map = new HashMap<>();
if (file == null) {
return null;
}
ImportParams params = new ImportParams();
params.setTitleRows(titleRows);
params.setHeadRows(headerRows);
params.setNeedVerify(true);
ExcelImportResult<T> result = null;
try {
ImportParams param = new ImportParams();
//标题行数
param.setTitleRows(titleRows);
//表头行数
param.setHeadRows(headerRows);
//0 是燃气用户数据
param.setStartSheetIndex(sheetIndex);
result= ExcelImportUtil.importExcelMore(file.getInputStream(), Clazz, param);
} catch (NoSuchElementException e) {
// 日志记录错误
log.error(String.format("导入数据为空: %s", ExceptionUtils.getStackTrace(e)));
throw new RuntimeException("导入数据为空");
} catch (Exception e) {
// 日志记录错误
log.error(String.format("导入失败: %s", ExceptionUtils.getStackTrace(e)));
throw new RuntimeException("导入失败");
}
if (result.isVerifyFail()) {
// 如有需要,可以根据result.getFailWorkbook();获取到有错误的数据
throw new RuntimeException("校验出错");
}
return result.getList();
}
/**
* 导入数据
* @param file
* @param file f
* @param titleRows 标题在第几行
* @param headerRows 表头在第几行
* @param clazz
* @param <T>
* @return
* @param clazz c
* @param <T> t
* @return r
*/
public static <T> List<T> importExcel(MultipartFile file, Integer titleRows, Integer headerRows,
Class<T> clazz) {
......
package com.zehong.system.domain.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
import com.zehong.system.domain.TGasuserSafetyDeviceInfo;
import java.util.List;
public class GasUserAndSafetyDeviceExportVo {
public class UserManageGasUserExportVo {
/** 用户账号 */
@Excel(name = "用户号", needMerge = true)
private String username;
@Excel(name = "用户自有编号", needMerge = true)
private String userOwnId;
/** 用户名称 */
@Excel(name = "用户名称", needMerge = true)
private String nickName;
@Excel(name = "燃气类型", needMerge = true)
@Excel(name = "燃气类型(0-天然气;1-液化气)", needMerge = true)
private String gasType;
/** 用户类型(1居民用户,2商业用户,3工业用户) */
@Excel(name = "用户类型", needMerge = true)
@Excel(name = "用户类型(1-居民用户;2-商业用户;3-工业用户;4-餐饮单位用户)", needMerge = true)
private String userType;
/**
......@@ -47,24 +43,16 @@ public class GasUserAndSafetyDeviceExportVo {
@Excel(name = "电话", needMerge = true)
private String phone;
/** 邮箱 */
@Excel(name = "邮箱", needMerge = true)
private String email;
/** 备注 */
@Excel(name = "备注", needMerge = true)
private String remarks;
/** 安全装置信息 */
@ExcelCollection(name = "安全装置信息")
private List<TGasuserSafetyDeviceInfo> gasuserSafetyDeviceInfoList;
public String getUsername() {
return username;
public String getUserOwnId() {
return userOwnId;
}
public void setUsername(String username) {
this.username = username;
public void setUserOwnId(String userOwnId) {
this.userOwnId = userOwnId;
}
public String getNickName() {
......@@ -131,14 +119,6 @@ public class GasUserAndSafetyDeviceExportVo {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getRemarks() {
return remarks;
}
......@@ -146,12 +126,4 @@ public class GasUserAndSafetyDeviceExportVo {
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public List<TGasuserSafetyDeviceInfo> getGasuserSafetyDeviceInfoList() {
return gasuserSafetyDeviceInfoList;
}
public void setGasuserSafetyDeviceInfoList(List<TGasuserSafetyDeviceInfo> gasuserSafetyDeviceInfoList) {
this.gasuserSafetyDeviceInfoList = gasuserSafetyDeviceInfoList;
}
}
package com.zehong.system.domain.vo;
import cn.afterturn.easypoi.excel.annotation.Excel;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Date;
public class UserManageSafetyDeviceExportVo {
/** 用户账号 */
@Excel(name = "用户自有编号")
private String userOwnId;
/** 关联设备类型 */
@Excel(name = "设备类型")
private String relationDeviceType;
/** 设备名称 */
@Excel(name = "设备名称")
private String deviceName;
/** 设备型号 */
@Excel(name = "设备型号")
private String deviceModel;
/** 物联网编号 */
@Excel(name = "物联网编号")
private String fIotNo;
/** 探测介质 */
@Excel(name = "探测介质")
private String detectionMedium;
/** 设备安装时间 */
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "设备安装时间(yyyy-mm-dd)", width = 30,format="yyyy-MM-dd")
private Date deviceInstallTime;
/** 安装位置 */
@Excel(name = "安装位置")
private String deviceInstallPosition;
/** 负责人 */
@Excel(name = "负责人")
private String head;
/** 联系电话 */
@Excel(name = "联系电话")
private String phone;
public String getUserOwnId() {
return userOwnId;
}
public void setUserOwnId(String userOwnId) {
this.userOwnId = userOwnId;
}
public String getRelationDeviceType() {
return relationDeviceType;
}
public void setRelationDeviceType(String relationDeviceType) {
this.relationDeviceType = relationDeviceType;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getDeviceModel() {
return deviceModel;
}
public void setDeviceModel(String deviceModel) {
this.deviceModel = deviceModel;
}
public String getfIotNo() {
return fIotNo;
}
public void setfIotNo(String fIotNo) {
this.fIotNo = fIotNo;
}
public String getDetectionMedium() {
return detectionMedium;
}
public void setDetectionMedium(String detectionMedium) {
this.detectionMedium = detectionMedium;
}
public Date getDeviceInstallTime() {
return deviceInstallTime;
}
public void setDeviceInstallTime(Date deviceInstallTime) {
this.deviceInstallTime = deviceInstallTime;
}
public String getDeviceInstallPosition() {
return deviceInstallPosition;
}
public void setDeviceInstallPosition(String deviceInstallPosition) {
this.deviceInstallPosition = deviceInstallPosition;
}
public String getHead() {
return head;
}
public void setHead(String head) {
this.head = head;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
......@@ -5,7 +5,6 @@ import java.util.Map;
import com.zehong.system.domain.TDetectorUser;
import com.zehong.system.domain.TDetectorUserCount;
import com.zehong.system.domain.TEmployedPeopleInfoError;
import com.zehong.system.domain.vo.*;
import javax.servlet.http.HttpServletResponse;
......@@ -171,6 +170,21 @@ public interface ITDetectorUserService
* @param operName 操作用户
* @return 结果
*/
public String importEmployedPeopleInfo(List<GasUserAndSafetyDeviceExportVo> XmbhList, Boolean isUpdateSupport, String operName, HttpServletResponse response);
public String importEmployedPeopleInfo(List<UserManageGasUserExportVo> XmbhList, Boolean isUpdateSupport, String operName, HttpServletResponse response);
/**
* 处理 解析好的 导入的数据
* @param dataInfos d
*/
public void handleCustomImportData(List<UserManageGasUserExportVo> dataInfos, boolean updateSupport ) ;
/**
* 处理 解析好的 多sheet 导入的数据
* @param gasUserExportVos g
* @param safetyDeviceExportVos s
*/
public void handleCustomMoreSheetImportData(List<UserManageGasUserExportVo> gasUserExportVos,
List<UserManageSafetyDeviceExportVo> safetyDeviceExportVos,
boolean updateSupport ) ;
}
......@@ -9,10 +9,7 @@ import java.util.stream.Collectors;
import com.zehong.common.utils.DateUtils;
import com.zehong.system.domain.TDetectorUserCount;
import com.zehong.system.domain.TGasuserSafetyDeviceInfo;
import com.zehong.system.domain.vo.GasUserAndSafetyDeviceExportVo;
import com.zehong.system.domain.vo.GasUserAndSafetyDeviceVo;
import com.zehong.system.domain.vo.TDetectorUserInspectVo;
import com.zehong.system.domain.vo.TDetectorUserVO;
import com.zehong.system.domain.vo.*;
import com.zehong.system.mapper.TDeviceInfoMapper;
import com.zehong.system.mapper.TGasuserSafetyDeviceInfoMapper;
import com.zehong.system.mapper.TSiteStationInfoMapper;
......@@ -411,13 +408,41 @@ public class TDetectorUserServiceImpl implements ITDetectorUserService
* @return
*/
@Override
public String importEmployedPeopleInfo(List<GasUserAndSafetyDeviceExportVo> XmbhList, Boolean isUpdateSupport, String operName, HttpServletResponse response) {
public String importEmployedPeopleInfo(List<UserManageGasUserExportVo> XmbhList, Boolean isUpdateSupport, String operName, HttpServletResponse response) {
if(XmbhList.size() > 0) {
for (GasUserAndSafetyDeviceExportVo gasUserAndSafetyDeviceExportVo : XmbhList) {
System.out.println(gasUserAndSafetyDeviceExportVo.getLinkman());
for (UserManageGasUserExportVo userManageGasUserExportVo : XmbhList) {
System.out.println(userManageGasUserExportVo.getLinkman());
}
}
return null;
}
/**
* 处理解析好的 自定义模版的导入的数据
* @param dataInfos d
*/
@Override
public void handleCustomImportData(List<UserManageGasUserExportVo> dataInfos, boolean updateSupport) {
}
/**
* 处理解析好的 自定义模版的导入的数据 多sheet
* @param gasUserExportVos d
* @param safetyDeviceExportVos s
*/
@Override
public void handleCustomMoreSheetImportData(List<UserManageGasUserExportVo> gasUserExportVos,
List<UserManageSafetyDeviceExportVo> safetyDeviceExportVos,
boolean updateSupport) {
for (UserManageGasUserExportVo gasUserExportVo : gasUserExportVos) {
System.out.println(gasUserExportVo.getAddress());
}
for (UserManageSafetyDeviceExportVo safetyDeviceExportVo : safetyDeviceExportVos) {
System.out.println(safetyDeviceExportVo.getDeviceModel());
}
}
}
......@@ -538,7 +538,7 @@ export default {
// 设置上传的请求头部
headers: { Authorization: "Bearer " + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + "/supervise/user/importCustom" // todo
url: process.env.VUE_APP_BASE_API + "/supervise/user/moreSheetImportExcel" // todo
},
relationImg: require('@/assets/project/relation.png'),
......
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