新增报告导出接口
This commit is contained in:
parent
9a6cff1514
commit
834fcf7e2d
@ -1,21 +1,43 @@
|
|||||||
package com.yfd.platform.modules.algorithm.controller;
|
package com.yfd.platform.modules.algorithm.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.deepoove.poi.XWPFTemplate;
|
||||||
|
import com.deepoove.poi.config.Configure;
|
||||||
|
import com.deepoove.poi.data.Pictures;
|
||||||
|
import com.deepoove.poi.plugin.table.HackLoopTableRenderPolicy;
|
||||||
|
import com.deepoove.poi.util.PoitlIOUtils;
|
||||||
|
import com.yfd.platform.config.HttpServerConfig;
|
||||||
import com.yfd.platform.config.ResponseResult;
|
import com.yfd.platform.config.ResponseResult;
|
||||||
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange;
|
import com.yfd.platform.modules.algorithm.domain.AlgorithmArrange;
|
||||||
|
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeDeviceService;
|
||||||
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService;
|
import com.yfd.platform.modules.algorithm.service.IAlgorithmArrangeService;
|
||||||
|
import com.yfd.platform.modules.basedata.domain.Substation;
|
||||||
|
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
||||||
|
import com.yfd.platform.utils.FileUtil;
|
||||||
import com.yfd.platform.utils.SecurityUtils;
|
import com.yfd.platform.utils.SecurityUtils;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@ -28,10 +50,17 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/algorithm/algorithm-arrange")
|
@RequestMapping("/algorithm/algorithm-arrange")
|
||||||
@Api(value = "AlgorithmArrangeController", tags = "算法布点模块")
|
@Api(value = "AlgorithmArrangeController", tags = "算法布点模块")
|
||||||
|
@Slf4j
|
||||||
public class AlgorithmArrangeController {
|
public class AlgorithmArrangeController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IAlgorithmArrangeService algorithmArrangeService;
|
private IAlgorithmArrangeService algorithmArrangeService;
|
||||||
|
@Resource
|
||||||
|
private IAlgorithmArrangeDeviceService algorithmArrangeDeviceService;
|
||||||
|
@Resource
|
||||||
|
private ISysDictionaryItemsService sysDictionaryItemsService;
|
||||||
|
@Resource
|
||||||
|
private HttpServerConfig httpServerConfig;
|
||||||
|
|
||||||
@GetMapping("/getAlgorithmArrangePage")
|
@GetMapping("/getAlgorithmArrangePage")
|
||||||
@ApiOperation("查询算法布点")
|
@ApiOperation("查询算法布点")
|
||||||
@ -88,6 +117,24 @@ public class AlgorithmArrangeController {
|
|||||||
return ResponseResult.successData(algorithmArrange);
|
return ResponseResult.successData(algorithmArrange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/saveArrangeImage")
|
||||||
|
@ApiOperation("保存布点图片")
|
||||||
|
public ResponseResult saveArrangeImage(String id, MultipartFile file) {
|
||||||
|
// 文件上传逻辑
|
||||||
|
if (file != null && !file.isEmpty()) {
|
||||||
|
try {
|
||||||
|
// 上传文件
|
||||||
|
String fileUrl = algorithmArrangeService.uploadImage(file);
|
||||||
|
LambdaUpdateWrapper<AlgorithmArrange> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.eq(AlgorithmArrange::getId, id).set(AlgorithmArrange::getArrangeImageUrl, fileUrl);
|
||||||
|
algorithmArrangeService.update(updateWrapper);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return ResponseResult.error("文件上传失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ResponseResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/updateAlgorithmArrange")
|
@PostMapping("/updateAlgorithmArrange")
|
||||||
@ApiOperation("修改算法布点")
|
@ApiOperation("修改算法布点")
|
||||||
public ResponseResult updateAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) {
|
public ResponseResult updateAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) {
|
||||||
@ -129,9 +176,9 @@ public class AlgorithmArrangeController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/deleteAlgorithmArrange")
|
@PostMapping("/deleteAlgorithmArrangeByIds")
|
||||||
@ApiOperation("删除布点数据")
|
@ApiOperation("删除布点数据")
|
||||||
public ResponseResult deleteAlgorithmArrange(@RequestBody List<String> ids) {
|
public ResponseResult deleteAlgorithmArrangeByIds(@RequestBody List<String> ids) {
|
||||||
boolean b = algorithmArrangeService.removeByIds(ids);
|
boolean b = algorithmArrangeService.removeByIds(ids);
|
||||||
if (b) {
|
if (b) {
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
@ -147,4 +194,77 @@ public class AlgorithmArrangeController {
|
|||||||
return ResponseResult.successData(algorithmArrange);
|
return ResponseResult.successData(algorithmArrange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/exportArrangeById")
|
||||||
|
@ApiOperation("导出报告")
|
||||||
|
public void exportArrangeById(String id, HttpServletResponse response) throws IOException {
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
AlgorithmArrange algorithmArrange = algorithmArrangeService.getById(id);
|
||||||
|
map.put("arrangeName", algorithmArrange.getArrangeName());
|
||||||
|
map.put("stationName", algorithmArrange.getStationName());
|
||||||
|
Map<String, Object> businessTypeMap = sysDictionaryItemsService.getDeviceMapByType("businessType");
|
||||||
|
Map<String, Object> stationTypeMap = sysDictionaryItemsService.getDeviceMapByType("stationType");
|
||||||
|
JSONObject businessTypeJSON= JSONUtil.parseObj(businessTypeMap.get("resultMap"));
|
||||||
|
JSONObject stationTypeJSON= JSONUtil.parseObj(stationTypeMap.get("resultMap"));
|
||||||
|
String businessType = StrUtil.isNotBlank(algorithmArrange.getBusinessType()) ? businessTypeJSON.getStr(algorithmArrange.getBusinessType()) : "";
|
||||||
|
String stationType = StrUtil.isNotBlank(algorithmArrange.getStationType()) ? stationTypeJSON.getStr(algorithmArrange.getStationType()) : "";
|
||||||
|
map.put("stationType", stationType);
|
||||||
|
map.put("businessType",businessType);
|
||||||
|
map.put("voltLevel", algorithmArrange.getVoltLevel());
|
||||||
|
map.put("status", "完成");
|
||||||
|
map.put("date", DateUtil.now());
|
||||||
|
List<Map<String, Object>> arrangeDeviceInfo = algorithmArrangeDeviceService.getArrangeDeviceInfo(id);
|
||||||
|
arrangeDeviceInfo.forEach(a -> {
|
||||||
|
// 图片流
|
||||||
|
a.put("index", arrangeDeviceInfo.indexOf(a) + 1);
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
|
||||||
|
String arrangeImageUrl = algorithmArrange.getArrangeImageUrl();
|
||||||
|
if (StrUtil.isNotBlank(arrangeImageUrl)) {
|
||||||
|
map.put("img",
|
||||||
|
Pictures.ofStream(Files.newInputStream(new File(httpServerConfig.getPlanFilePath() + arrangeImageUrl).toPath()), FileUtil.getPictureType(arrangeImageUrl)).size(800, 200).create());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> demo = getMapData();
|
||||||
|
//创建一个列表的规则
|
||||||
|
HackLoopTableRenderPolicy policy = new HackLoopTableRenderPolicy();
|
||||||
|
//设置列表配置,如果有多个列表时需加.bind("list1", policy) 新列表配置即可
|
||||||
|
Configure config = Configure.builder().bind("list", policy).build();
|
||||||
|
if (!arrangeDeviceInfo.isEmpty()) {
|
||||||
|
map.put("list", arrangeDeviceInfo);
|
||||||
|
} else {
|
||||||
|
map.put("list", demo);
|
||||||
|
}
|
||||||
|
// 加载模板渲染数据
|
||||||
|
String path = Objects.requireNonNull(Objects.requireNonNull(ClassUtils.getDefaultClassLoader()).getResource(
|
||||||
|
"")).getPath() + "templates" + File.separator + "布点报告模板.docx";
|
||||||
|
XWPFTemplate compile = XWPFTemplate.compile(path, config);
|
||||||
|
XWPFTemplate template = compile.render(map);
|
||||||
|
response.setContentType("application/octet-stream");
|
||||||
|
response.setHeader("Content-disposition", "attachment;filename='reportTemp.docx'");
|
||||||
|
|
||||||
|
OutputStream out = response.getOutputStream();
|
||||||
|
BufferedOutputStream bos = new BufferedOutputStream(out);
|
||||||
|
template.write(bos);
|
||||||
|
bos.flush();
|
||||||
|
out.flush();
|
||||||
|
PoitlIOUtils.closeQuietlyMulti(template, bos, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Map<String, Object>> getMapData() {
|
||||||
|
List<Map<String, Object>> demo = new ArrayList<>();
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("index", "");
|
||||||
|
map.put("areaName", "");
|
||||||
|
map.put("1", "");
|
||||||
|
map.put("2", "");
|
||||||
|
map.put("3", "");
|
||||||
|
map.put("4", "");
|
||||||
|
demo.add(map);
|
||||||
|
return demo;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ public class SubstationMaindeviceController {
|
|||||||
queryWrapper.eq(StrUtil.isNotBlank(stationCode), SubstationMaindevice::getStationCode, stationCode);
|
queryWrapper.eq(StrUtil.isNotBlank(stationCode), SubstationMaindevice::getStationCode, stationCode);
|
||||||
queryWrapper.in(StrUtil.isNotBlank(deviceTypeList), SubstationMaindevice::getDeviceType, StrUtil.split(deviceTypeList
|
queryWrapper.in(StrUtil.isNotBlank(deviceTypeList), SubstationMaindevice::getDeviceType, StrUtil.split(deviceTypeList
|
||||||
, ","));
|
, ","));
|
||||||
queryWrapper.select(SubstationMaindevice::getMainDeviceId, SubstationMaindevice::getMainDeviceName,
|
queryWrapper.select(SubstationMaindevice::getMainDeviceId,SubstationMaindevice::getAreaId,SubstationMaindevice::getAreaName, SubstationMaindevice::getMainDeviceName,
|
||||||
SubstationMaindevice::getDeviceType, SubstationMaindevice::getFileUrl);
|
SubstationMaindevice::getDeviceType, SubstationMaindevice::getFileUrl);
|
||||||
queryWrapper.eq(SubstationMaindevice::getDatastatus, "1");
|
queryWrapper.eq(SubstationMaindevice::getDatastatus, "1");
|
||||||
List<Map<String, Object>> maps = substationMaindeviceService.listMaps(queryWrapper);
|
List<Map<String, Object>> maps = substationMaindeviceService.listMaps(queryWrapper);
|
||||||
|
BIN
riis-system/src/main/resources/templates/布点报告模板.docx
Normal file
BIN
riis-system/src/main/resources/templates/布点报告模板.docx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user