结构化数据下载功能
This commit is contained in:
parent
3f295ebd1f
commit
5eb7feffd0
|
|
@ -5,9 +5,12 @@ import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnu
|
|||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.AddImportTableDataDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.DownloadImportTableDataDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.UpdateImportTableDataDTO;
|
||||
import com.electromagnetic.industry.software.manage.service.ImportTableService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
|
@ -45,4 +48,10 @@ public class ImportTableController {
|
|||
public ElectromagneticResult<?> update(@RequestBody UpdateImportTableDataDTO updateImportTableDataDTO) {
|
||||
return importTableService.updateTableData(updateImportTableDataDTO.getId(), updateImportTableDataDTO.getTableData());
|
||||
}
|
||||
|
||||
@PostMapping("/download")
|
||||
@UserOperation(value = "下载结构化数据", modelName = UserOperationModuleEnum.STRUCT_DATA)
|
||||
public ResponseEntity<byte[]> download(@RequestBody DownloadImportTableDataDTO downloadImportTableDataDTO, HttpServletResponse response) {
|
||||
return importTableService.downloadTableData(downloadImportTableDataDTO, response);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package com.electromagnetic.industry.software.manage.pojo.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DownloadImportTableDataDTO {
|
||||
private List<String> ids;
|
||||
}
|
||||
|
|
@ -3,6 +3,10 @@ package com.electromagnetic.industry.software.manage.service;
|
|||
import com.electromagnetic.industry.software.common.pojo.RespPageVO;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportTableInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.DownloadImportTableDataDTO;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -28,5 +32,5 @@ public interface ImportTableService {
|
|||
|
||||
RespPageVO selectTableDataByTableInfoId(Integer pageNum, Integer pageSize, String tableInfoId);
|
||||
|
||||
|
||||
ResponseEntity<byte[]> downloadTableData(DownloadImportTableDataDTO downloadImportTableDataDTO, HttpServletResponse response);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,30 +1,51 @@
|
|||
package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.text.StrFormatter;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.druid.sql.visitor.functions.Char;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.electromagnetic.industry.software.common.enums.EffectFlagEnum;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
import com.electromagnetic.industry.software.common.pojo.RespPageVO;
|
||||
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
|
||||
import com.electromagnetic.industry.software.common.util.EleCommonUtil;
|
||||
import com.electromagnetic.industry.software.common.util.ElectromagneticResultUtil;
|
||||
import com.electromagnetic.industry.software.common.util.IdWorker;
|
||||
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
|
||||
import com.electromagnetic.industry.software.manage.mapper.ImportTableDataMapper;
|
||||
import com.electromagnetic.industry.software.manage.mapper.ImportTableInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportFileInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportTableData;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.ImportTableInfo;
|
||||
import com.electromagnetic.industry.software.manage.pojo.req.DownloadImportTableDataDTO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.ImportTablePageDataVO;
|
||||
import com.electromagnetic.industry.software.manage.service.ImportTableService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ImportTableServiceImpl implements ImportTableService {
|
||||
|
||||
@Resource
|
||||
|
|
@ -133,4 +154,32 @@ public class ImportTableServiceImpl implements ImportTableService {
|
|||
return new RespPageVO<>(total, pageVo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntity<byte[]> downloadTableData(DownloadImportTableDataDTO downloadImportTableDataDTO, HttpServletResponse response) {
|
||||
String nowTimeStr = EleCommonUtil.getNowTimeStr();
|
||||
String attachement = StrFormatter.format("attachement; filename={}.json", nowTimeStr);
|
||||
List<String> selectIds = downloadImportTableDataDTO.getIds();
|
||||
List<ImportTableData> importTableData = importTableDataMapper.selectList(Wrappers.<ImportTableData>lambdaQuery().select(ImportTableData::getTableInfoId, ImportTableData::getData).in(ImportTableData::getId, selectIds));
|
||||
|
||||
if (CollUtil.isEmpty(importTableData)) {
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,attachement)
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.contentLength(0)
|
||||
.body("".getBytes());
|
||||
}
|
||||
|
||||
String tableInfoId = importTableData.get(0).getTableInfoId();
|
||||
ImportTableInfo importTableInfo = importTableInfoMapper.selectById(tableInfoId);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("header", importTableInfo.getTableHeader());
|
||||
map.put("data", importTableData);
|
||||
byte[] data = JSONUtil.toJsonStr(map).getBytes(Charset.defaultCharset());
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION,attachement)
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.contentLength(data.length)
|
||||
.body(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue