|
@@ -1,6 +1,9 @@
|
|
|
package com.usky.iot.service.impl;
|
|
|
|
|
|
+
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
@@ -13,19 +16,23 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.core.util.BeanMapperUtils;
|
|
|
+import com.usky.common.core.util.UUIDUtils;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.iot.domain.DmpDeviceInfo;
|
|
|
import com.usky.iot.mapper.DmpDeviceInfoMapper;
|
|
|
import com.usky.iot.service.DmpDeviceInfoService;
|
|
|
+import com.usky.iot.service.vo.DmpDeviceExcelVO;
|
|
|
import com.usky.iot.service.vo.DmpDeviceExportVO;
|
|
|
import com.usky.iot.service.vo.DmpDeviceInfoRequest;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.Optional;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -40,6 +47,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
|
|
|
@Override
|
|
|
public boolean add(DmpDeviceInfo dmpDeviceInfo) {
|
|
|
+ dmpDeviceInfo.setDeviceId(UUIDUtils.uuid());
|
|
|
if (checkNameUnique(dmpDeviceInfo)){
|
|
|
throw new BusinessException("新增设备信息'" + dmpDeviceInfo.getDeviceName() + "'失败,设备信息已存在");
|
|
|
}
|
|
@@ -48,6 +56,7 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
|
|
|
@Override
|
|
|
public void update(DmpDeviceInfo dmpDeviceInfo) {
|
|
|
+ dmpDeviceInfo.setUpdatedTime(new Date());
|
|
|
if (checkNameUnique(dmpDeviceInfo)){
|
|
|
throw new BusinessException("修改设备信息'" + dmpDeviceInfo.getDeviceName() + "'失败,设备信息已存在");
|
|
|
}
|
|
@@ -104,6 +113,61 @@ public class DmpDeviceInfoServiceImpl extends AbstractCrudService<DmpDeviceInfoM
|
|
|
this.saveBatch(deviceByFile);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void export(DmpDeviceInfoRequest dmpDeviceInfoRequest, HttpServletResponse response) {
|
|
|
+ Workbook workbook = null;
|
|
|
+ try {
|
|
|
+ ExportParams params = new ExportParams(null, "设备列表");
|
|
|
+ workbook = ExcelExportUtil.exportBigExcel(params, DmpDeviceExcelVO.class,
|
|
|
+ (o, i) -> {
|
|
|
+ dmpDeviceInfoRequest.setCurrent(i);
|
|
|
+ dmpDeviceInfoRequest.setSize(30);
|
|
|
+ CommonPage<DmpDeviceInfo> list = this.page(dmpDeviceInfoRequest);
|
|
|
+ return new ArrayList<>(BeanMapperUtils.mapList(list.getRecords(),DmpDeviceInfo.class,DmpDeviceExcelVO.class));
|
|
|
+ },null);
|
|
|
+ if (null != workbook) {
|
|
|
+ exportExcel(workbook,response);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("表格数据为空");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出文件失败", e);
|
|
|
+ throw new BusinessException("导出文件失败"+e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (workbook != null) {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("===export spec=== 关闭workbook失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void exportExcel(Workbook workbook, HttpServletResponse response){
|
|
|
+ //定义一个流,用作流式输出
|
|
|
+ ServletOutputStream outputStream = null;
|
|
|
+ try {
|
|
|
+ //使用流的形式传输
|
|
|
+ response.setHeader("content-type", "application/octet-stream");
|
|
|
+ //防止中文乱码
|
|
|
+ response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode("设备信息.xls", "UTF-8"));
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
+ workbook.write(outputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if(null!=outputStream){
|
|
|
+ try {
|
|
|
+ //关闭流
|
|
|
+ outputStream.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取表格数据
|