From 1d52363389bf2098fd348bb4eb51e682f0f03e63 Mon Sep 17 00:00:00 2001 From: wany <13995595726@qq.com> Date: Thu, 11 Jul 2024 13:36:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=B8=E6=B6=A6=E7=BA=BF=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OsmoticPressRController.java | 7 +++ .../project/xyt/entity/vo/OsmoticValueVo.java | 6 ++ .../xyt/service/OsmoticPressRService.java | 62 +++++++++++++++++-- .../gunshi/project/xyt/util/ExcelUtil.java | 24 +++++++ 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java b/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java index 6f2b98d..d486470 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/OsmoticPressRController.java @@ -14,6 +14,7 @@ import com.gunshi.project.xyt.validate.markers.Update; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -84,4 +85,10 @@ public class OsmoticPressRController { return R.ok(service.infiltraLine(infiltraLineSo)); } + @Operation(summary = "浸润线导出") + @PostMapping( "/export") + public void export(@RequestBody InfiltraLineSo infiltraLineSo, HttpServletResponse response) { + service.export(infiltraLineSo,response); + } + } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java index 5cad3cb..d626e11 100644 --- a/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/OsmoticValueVo.java @@ -33,6 +33,12 @@ public class OsmoticValueVo { @Schema(description="管水位") private BigDecimal value; + /** + * 库水位 + */ + @Schema(description="库水位") + private BigDecimal rz; + @Schema(description = "结果分析(0异常 1正常)") private Integer status = 1; } diff --git a/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java b/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java index b631c0d..5b3a8e5 100644 --- a/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java +++ b/src/main/java/com/gunshi/project/xyt/service/OsmoticPressRService.java @@ -13,8 +13,10 @@ import com.gunshi.project.xyt.model.OsmoticPressDevice; import com.gunshi.project.xyt.model.OsmoticPressDeviceAutoDao; import com.gunshi.project.xyt.model.OsmoticPressR; import com.gunshi.project.xyt.util.DateUtil; +import com.gunshi.project.xyt.util.ExcelUtil; import com.gunshi.project.xyt.util.MyBeanUtil; import jakarta.annotation.Resource; +import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -61,7 +63,10 @@ public class OsmoticPressRService extends ServiceImplstr.equals(o.getTm())).collect(Collectors.toList())); + vo.setList(valueList.stream().filter(o->str.equals(o.getTm())).map(t->{ + t.setRz(vo.getRz()); + return t; + }).collect(Collectors.toList())); resList.add(vo); } return resList; @@ -120,12 +125,11 @@ public class OsmoticPressRService extends ServiceImpl infiltraLine(InfiltraLineSo infiltraLineSo) { List resList = new ArrayList<>(); String profileCode = infiltraLineSo.getProfileCode(); - //通过断面查询渗压 - List pressList = pressDeviceAutoDao.list(new QueryWrapper().eq("profile_code", profileCode)); - if(CollectionUtils.isEmpty(pressList)){ + //通过断面查询渗压设备 + List stationCodes = queryPressList(profileCode); + if(CollectionUtils.isEmpty(stationCodes)){ return resList; } - List stationCodes = pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList()); //查询库水位 List list = mapper.queryLineRz(infiltraLineSo); Map rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); @@ -156,6 +160,54 @@ public class OsmoticPressRService extends ServiceImpl queryPressList(String profileCode){ + List pressList = pressDeviceAutoDao.list(new QueryWrapper().eq("profile_code", profileCode)); + return pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList()); + } + + public void export(InfiltraLineSo infiltraLineSo, HttpServletResponse response) { + //通过断面查询渗压设备 + List stationCodes = queryPressList(infiltraLineSo.getProfileCode()); + //表头信息 + List heads = new ArrayList<>(); + heads.add("时间"); + heads.add("库水位(m)"); + heads.addAll(stationCodes); + heads.add("结果分析"); + + //表格数据 + List resList = infiltraLine(infiltraLineSo); + List> list = new ArrayList<>(); + for (OsmoticStationVo vo : resList) { + Map test = new LinkedHashMap<>(); + test.put("t1", vo.getTm()); + test.put("t2", vo.getRz()); + for(int i = 0;icode.equals(o.getStationCode())).findFirst().orElse(null); + test.put(code,valueVo != null ? valueVo.getValue() : "-"); + } + test.put("t4", vo.getStatus() == 0 ? "异常":"正常"); + list.add(test); + } + List> hs = new ArrayList<>(); + for (String s : heads) { + hs.add(Arrays.asList(s)); + } + + List list2 = new ArrayList<>(); + Collection values; + for (int i = 0; i < list.size(); i++) { + values = list.get(i).values(); + List objects = new ArrayList<>(); + for (Object value : values) { + objects.add(value.toString()); + } + list2.add(objects); + } + ExcelUtil.exportExcel(hs, list2, "浸润线", null, response, "浸润线"); + } } diff --git a/src/main/java/com/gunshi/project/xyt/util/ExcelUtil.java b/src/main/java/com/gunshi/project/xyt/util/ExcelUtil.java index 46e54ec..782ebe0 100644 --- a/src/main/java/com/gunshi/project/xyt/util/ExcelUtil.java +++ b/src/main/java/com/gunshi/project/xyt/util/ExcelUtil.java @@ -52,6 +52,30 @@ public class ExcelUtil { } } + public static void exportExcel(List> head,List data, String filename, Class clazz, HttpServletResponse response,String sheetName) { + OutputStream out = null; + try { + out = getOutputStream(filename,response); + ExcelWriterSheetBuilder builder = EasyExcel.write(out, clazz) + //是否自动关闭流 + .autoCloseStream(Boolean.FALSE) + //自动列宽(不太精确) + .registerWriteHandler(new VoteTitleHandler(filename)) + .head(head) + .sheet(sheetName); + builder.doWrite(data); + } finally { + try { + if (out != null){ + out.flush(); + out.close(); + } + } catch (IOException e) { + throw new RuntimeException("导出Excel异常"); + } + } + } + /**