diff --git a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java index f8e0bd6..4ace801 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/algorithm/controller/AlgorithmArrangeController.java @@ -1,21 +1,43 @@ package com.yfd.platform.modules.algorithm.controller; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; 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.update.LambdaUpdateWrapper; 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.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.basedata.domain.Substation; +import com.yfd.platform.system.service.ISysDictionaryItemsService; +import com.yfd.platform.utils.FileUtil; import com.yfd.platform.utils.SecurityUtils; import io.swagger.annotations.Api; 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.multipart.MultipartFile; 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.util.List; +import java.util.*; +import java.util.stream.Collectors; /** *

@@ -28,10 +50,17 @@ import java.util.List; @RestController @RequestMapping("/algorithm/algorithm-arrange") @Api(value = "AlgorithmArrangeController", tags = "算法布点模块") +@Slf4j public class AlgorithmArrangeController { @Resource private IAlgorithmArrangeService algorithmArrangeService; + @Resource + private IAlgorithmArrangeDeviceService algorithmArrangeDeviceService; + @Resource + private ISysDictionaryItemsService sysDictionaryItemsService; + @Resource + private HttpServerConfig httpServerConfig; @GetMapping("/getAlgorithmArrangePage") @ApiOperation("查询算法布点") @@ -88,6 +117,24 @@ public class AlgorithmArrangeController { 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 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") @ApiOperation("修改算法布点") public ResponseResult updateAlgorithmArrange(AlgorithmArrange algorithmArrange, MultipartFile file) { @@ -129,9 +176,9 @@ public class AlgorithmArrangeController { } } - @PostMapping("/deleteAlgorithmArrange") + @PostMapping("/deleteAlgorithmArrangeByIds") @ApiOperation("删除布点数据") - public ResponseResult deleteAlgorithmArrange(@RequestBody List ids) { + public ResponseResult deleteAlgorithmArrangeByIds(@RequestBody List ids) { boolean b = algorithmArrangeService.removeByIds(ids); if (b) { return ResponseResult.success(); @@ -147,4 +194,77 @@ public class AlgorithmArrangeController { return ResponseResult.successData(algorithmArrange); } + @GetMapping("/exportArrangeById") + @ApiOperation("导出报告") + public void exportArrangeById(String id, HttpServletResponse response) throws IOException { + Map map = new HashMap<>(); + AlgorithmArrange algorithmArrange = algorithmArrangeService.getById(id); + map.put("arrangeName", algorithmArrange.getArrangeName()); + map.put("stationName", algorithmArrange.getStationName()); + Map businessTypeMap = sysDictionaryItemsService.getDeviceMapByType("businessType"); + Map 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> 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> 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> getMapData() { + List> demo = new ArrayList<>(); + Map 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; + } + } diff --git a/riis-system/src/main/java/com/yfd/platform/modules/basedata/controller/SubstationMaindeviceController.java b/riis-system/src/main/java/com/yfd/platform/modules/basedata/controller/SubstationMaindeviceController.java index 3ae1cf0..a74a942 100644 --- a/riis-system/src/main/java/com/yfd/platform/modules/basedata/controller/SubstationMaindeviceController.java +++ b/riis-system/src/main/java/com/yfd/platform/modules/basedata/controller/SubstationMaindeviceController.java @@ -117,7 +117,7 @@ public class SubstationMaindeviceController { queryWrapper.eq(StrUtil.isNotBlank(stationCode), SubstationMaindevice::getStationCode, stationCode); 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); queryWrapper.eq(SubstationMaindevice::getDatastatus, "1"); List> maps = substationMaindeviceService.listMaps(queryWrapper); diff --git a/riis-system/src/main/resources/templates/布点报告模板.docx b/riis-system/src/main/resources/templates/布点报告模板.docx new file mode 100644 index 0000000..4e1fa97 Binary files /dev/null and b/riis-system/src/main/resources/templates/布点报告模板.docx differ