|
@@ -8,15 +8,13 @@ import cn.hutool.core.text.StrBuilder;
|
|
|
import cn.hutool.core.util.BooleanUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.alibaba.excel.EasyExcel;
|
|
|
-import com.alibaba.excel.ExcelWriter;
|
|
|
-import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.yitter.idgen.YitIdHelper;
|
|
|
import com.xy.collections.list.JArrayList;
|
|
|
import com.xy.collections.list.JList;
|
|
|
import com.xy.config.DeviceThreadPoolConfig;
|
|
@@ -24,10 +22,12 @@ import com.xy.consts.DictConsts;
|
|
|
import com.xy.dto.*;
|
|
|
import com.xy.entity.*;
|
|
|
import com.xy.enums.FileExportStatus;
|
|
|
+import com.xy.enums.FileExportType;
|
|
|
import com.xy.error.CommRuntimeException;
|
|
|
import com.xy.mapper.DeviceInfoMapper;
|
|
|
import com.xy.mapper.entity.DeviceInfoQueryPage;
|
|
|
import com.xy.util.ExcelUtils;
|
|
|
+import com.xy.util.FileUtils;
|
|
|
import com.xy.utils.*;
|
|
|
import com.xy.utils.enums.DictEnum;
|
|
|
import com.xy.utils.enums.DictSonEnum;
|
|
@@ -36,7 +36,6 @@ import io.swagger.annotations.ApiOperation;
|
|
|
import jodd.introspector.MapperFunction;
|
|
|
import lombok.Cleanup;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import lombok.SneakyThrows;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -46,6 +45,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
@@ -91,7 +91,7 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
|
|
|
private final String keyPrefix = "device:history:";
|
|
|
|
|
|
- private FileUtils fileUtils;
|
|
|
+ private final FileUtils fileUtils;
|
|
|
|
|
|
@Override
|
|
|
@ApiOperation("对象查询")
|
|
@@ -277,7 +277,6 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
}
|
|
|
|
|
|
|
|
|
- @SneakyThrows
|
|
|
@Async
|
|
|
@ApiOperation("导出设备(异步)")
|
|
|
@PostMapping("exportDevices/async")
|
|
@@ -285,36 +284,34 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
|
|
|
List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
|
|
|
List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
|
|
|
-
|
|
|
+ //TODO:以下逻辑迁移到SDK公用
|
|
|
//新增导出记录
|
|
|
- FileExportDto.Save fileExport = new FileExportDto.Save();
|
|
|
- fileExport.setExportStatus(FileExportStatus.EXPORT_ING.getCode());
|
|
|
- R<FileExportDto.Vo> r = R.feignCheck(fileExportService.save(fileExport));
|
|
|
- FileExportDto.Vo fileExportDtoVO = r.getData();
|
|
|
- Long id = fileExportDtoVO.getId();
|
|
|
- //TODO:
|
|
|
- // 输出
|
|
|
+ long id = YitIdHelper.nextId();
|
|
|
String fileName = fileUtils.getFileName(id);
|
|
|
String pathName = fileUtils.getPathName(fileName);
|
|
|
-
|
|
|
- ExcelWriter excelWriter = null;
|
|
|
try {
|
|
|
- excelWriter = EasyExcel.write(pathName, DeviceInfoDto.DeviceExcelVO.class).build();
|
|
|
- WriteSheet writeSheet = EasyExcel.writerSheet("商品").build();
|
|
|
- excelWriter.write(deviceExcelVOS, writeSheet);
|
|
|
-
|
|
|
- } catch (Exception ex) {
|
|
|
-
|
|
|
- } finally {
|
|
|
- if (excelWriter != null) {
|
|
|
- excelWriter.finish();
|
|
|
+ FileExportDto.Save fileExport = new FileExportDto.Save().setId(id)
|
|
|
+ .setExportStatus(FileExportStatus.EXPORT_ING.getCode())
|
|
|
+ .setFileType(FileExportType.DEVICE_INFO.getCode()).setFileName(fileName);
|
|
|
+ R.feignCheck(fileExportService.save(fileExport));
|
|
|
+ @Cleanup OutputStream out = new FileOutputStream(pathName);
|
|
|
+ ExcelUtils.writeOutputStream(out, "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
|
|
|
+ fileExportService.updateExportStatus(id, FileExportStatus.EXPORT_LOCAL_SUCESS.getCode());
|
|
|
+
|
|
|
+ FileInputStream fis = new FileInputStream(pathName);
|
|
|
+ String cloudUrl = AliOssUtil.upload(fis, ExcelUtils.EXCEL_PREFIX + fileName);
|
|
|
+ if (StrUtil.isEmpty(cloudUrl)) {
|
|
|
+ fileExportService.updateExportStatus(id, FileExportStatus.EXPORT_FAILED.getCode());
|
|
|
+ return;
|
|
|
}
|
|
|
- }
|
|
|
+ //更新状态与文件地址
|
|
|
+ fileExportService.updateExportStatus(id, FileExportStatus.EXPORT_CLOUD_SUCESS.getCode(), cloudUrl);
|
|
|
+ //删除本地文件
|
|
|
+ fileUtils.deleteFile(pathName);
|
|
|
|
|
|
- @Cleanup OutputStream out = new FileOutputStream(pathName);
|
|
|
-
|
|
|
- ExcelUtils.writeOutputStream(out, "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
|
|
|
-// ExcelUtils.write(response, "设备列表.xls", "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ fileExportService.updateExportStatus(id, FileExportStatus.EXPORT_FAILED.getCode());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PostMapping("nearbyPage")
|