|
@@ -1,22 +1,32 @@
|
|
|
package com.bizmatics.service.impl;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
+import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
|
|
|
+import cn.afterturn.easypoi.handler.inter.IExcelExportServer;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.bizmatics.common.core.bean.CommonPage;
|
|
|
+import com.bizmatics.common.core.exception.BusinessException;
|
|
|
+import com.bizmatics.common.core.util.BeanMapperUtils;
|
|
|
import com.bizmatics.common.core.util.DateUtils;
|
|
|
+import com.bizmatics.common.core.util.FileUtils;
|
|
|
+import com.bizmatics.common.spring.util.GlobalUtils;
|
|
|
import com.bizmatics.model.AlarmPower;
|
|
|
import com.bizmatics.persistence.mapper.AlarmPowerMapper;
|
|
|
import com.bizmatics.service.AlarmPowerService;
|
|
|
import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
import com.bizmatics.service.util.SessionLocal;
|
|
|
+import com.bizmatics.service.vo.AlarmPowerExportVO;
|
|
|
import com.bizmatics.service.vo.ApCountVO;
|
|
|
import com.bizmatics.service.vo.CommonIcoVO;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -65,7 +75,43 @@ public class AlarmPowerServiceImpl extends AbstractCrudService<AlarmPowerMapper,
|
|
|
@Override
|
|
|
public CommonPage<AlarmPower> page(Date startTime, Date endTime, Integer status, Integer siteId,Integer current,Integer size) {
|
|
|
Page<AlarmPower> page = new Page<>(current, size);
|
|
|
- baseMapper.list(page,SessionLocal.getUserId(),siteId,status,startTime,endTime);
|
|
|
+ page = baseMapper.page(page,SessionLocal.getUserId(),siteId,status,startTime,endTime);
|
|
|
return this.ToCommonPage(page);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String export(Date startTime, Date endTime, Integer status, Integer siteId){
|
|
|
+ Integer userId = SessionLocal.getUserId();
|
|
|
+ Workbook workbook = null;
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ ExportParams params = new ExportParams(null, "电力告警");
|
|
|
+ workbook = ExcelExportUtil.exportBigExcel(params, AlarmPowerExportVO.class,
|
|
|
+ (o, i) -> {
|
|
|
+ Page<AlarmPower> page = new Page<>(i, 30);
|
|
|
+ page = baseMapper.page(page, userId, siteId, status, startTime, endTime);
|
|
|
+ return new ArrayList<>(BeanMapperUtils.mapList(page.getRecords(), AlarmPower.class, AlarmPowerExportVO.class));
|
|
|
+ },null);
|
|
|
+ if (null != workbook) {
|
|
|
+ file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "电力告警", System.currentTimeMillis() + ""));
|
|
|
+ FileUtils.createFile(file.getAbsolutePath());
|
|
|
+ FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
|
|
|
+ workbook.write(allListingFileOutputStream);
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("表格数据为空");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出文件失败", e);
|
|
|
+ throw new BusinessException("导出文件失败");
|
|
|
+ } finally {
|
|
|
+ if (workbook != null) {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("===export spec=== 关闭workbook失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return GlobalUtils.getTempBaseDir()+"/"+file.getName();
|
|
|
+ }
|
|
|
}
|