|
@@ -8,6 +8,9 @@ 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;
|
|
@@ -20,6 +23,7 @@ import com.xy.config.DeviceThreadPoolConfig;
|
|
|
import com.xy.consts.DictConsts;
|
|
|
import com.xy.dto.*;
|
|
|
import com.xy.entity.*;
|
|
|
+import com.xy.enums.FileExportStatus;
|
|
|
import com.xy.error.CommRuntimeException;
|
|
|
import com.xy.mapper.DeviceInfoMapper;
|
|
|
import com.xy.mapper.entity.DeviceInfoQueryPage;
|
|
@@ -30,7 +34,9 @@ import com.xy.utils.enums.DictSonEnum;
|
|
|
import io.swagger.annotations.Api;
|
|
|
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;
|
|
@@ -40,7 +46,9 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
@@ -77,10 +85,14 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
|
|
|
private final GoodsDeviceService goodsDeviceService;
|
|
|
|
|
|
+ private final FileExportService fileExportService;
|
|
|
+
|
|
|
private final RedisService<String> redisService;
|
|
|
|
|
|
private final String keyPrefix = "device:history:";
|
|
|
|
|
|
+ private FileUtils fileUtils;
|
|
|
+
|
|
|
@Override
|
|
|
@ApiOperation("对象查询")
|
|
|
public R<DeviceInfoDto.Vo> obj(DeviceInfoDto.Obj obj) {
|
|
@@ -265,15 +277,43 @@ public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceI
|
|
|
}
|
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
@Async
|
|
|
@ApiOperation("导出设备(异步)")
|
|
|
@PostMapping("exportDevices/async")
|
|
|
- public void exportDevicesAsync(DeviceInfoDto.Page page) {
|
|
|
+ public void exportDevicesAsync(@RequestBody @Validated DeviceInfoDto.Page page) {
|
|
|
PageBean<DeviceInfoDto.Vo2> pageBean = queryPage(page);
|
|
|
List<DeviceInfoDto.Vo2> records = pageBean.getRecords();
|
|
|
List<DeviceInfoDto.DeviceExcelVO> deviceExcelVOS = BeanUtil.copyToList(records, DeviceInfoDto.DeviceExcelVO.class);
|
|
|
+
|
|
|
+ //新增导出记录
|
|
|
+ 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:
|
|
|
// 输出
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Cleanup OutputStream out = new FileOutputStream(pathName);
|
|
|
+
|
|
|
+ ExcelUtils.writeOutputStream(out, "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
|
|
|
// ExcelUtils.write(response, "设备列表.xls", "设备列表", DeviceInfoDto.DeviceExcelVO.class, deviceExcelVOS);
|
|
|
}
|
|
|
|