|
@@ -1,20 +1,34 @@
|
|
|
package com.bizmatics.service.impl;
|
|
|
|
|
|
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.afterturn.easypoi.excel.entity.ExportParams;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
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.FileUtils;
|
|
|
import com.bizmatics.common.mvc.base.AbstractCrudService;
|
|
|
+import com.bizmatics.common.spring.util.GlobalUtils;
|
|
|
+import com.bizmatics.model.AlarmPower;
|
|
|
import com.bizmatics.model.DeviceAnalogVariableList;
|
|
|
+import com.bizmatics.model.DeviceAttribute;
|
|
|
import com.bizmatics.model.system.SysUser;
|
|
|
import com.bizmatics.model.vo.DeviceAnalogVariableListOneVo;
|
|
|
import com.bizmatics.model.vo.DeviceAnalogVariableListVo;
|
|
|
import com.bizmatics.persistence.mapper.DeviceAnalogVariableListMapper;
|
|
|
import com.bizmatics.service.DeviceAnalogVariableListService;
|
|
|
import com.bizmatics.service.util.SecurityUtils;
|
|
|
+import com.bizmatics.service.vo.DeviceAttributeExportVO;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -100,5 +114,40 @@ public class DeviceAnalogVariableListServiceImpl extends AbstractCrudService<Dev
|
|
|
return DeviceAnalogVariableListDroplist;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String variableListExport( Integer siteId,String variableName,Integer dataArea) {
|
|
|
+ Workbook workbook = null;
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ ExportParams params = new ExportParams(null, "变量列表");
|
|
|
+ workbook = ExcelExportUtil.exportBigExcel(params, DeviceAttributeExportVO.class,
|
|
|
+ (o, i) -> {
|
|
|
+ Page<DeviceAnalogVariableListOneVo> page = new Page<>(i, 30);
|
|
|
+ page = baseMapper.variableListExport(page,siteId, variableName, dataArea);
|
|
|
+ return new ArrayList<>(BeanMapperUtils.mapList(page.getRecords(), DeviceAnalogVariableListOneVo.class, DeviceAttributeExportVO.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 file.getName();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|