浸润线导出

master
wany 2024-07-11 13:36:44 +08:00
parent a34009ac69
commit 1d52363389
4 changed files with 94 additions and 5 deletions

View File

@ -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.Operation;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -84,4 +85,10 @@ public class OsmoticPressRController {
return R.ok(service.infiltraLine(infiltraLineSo)); return R.ok(service.infiltraLine(infiltraLineSo));
} }
@Operation(summary = "浸润线导出")
@PostMapping( "/export")
public void export(@RequestBody InfiltraLineSo infiltraLineSo, HttpServletResponse response) {
service.export(infiltraLineSo,response);
}
} }

View File

@ -33,6 +33,12 @@ public class OsmoticValueVo {
@Schema(description="管水位") @Schema(description="管水位")
private BigDecimal value; private BigDecimal value;
/**
*
*/
@Schema(description="库水位")
private BigDecimal rz;
@Schema(description = "结果分析0异常 1正常") @Schema(description = "结果分析0异常 1正常")
private Integer status = 1; private Integer status = 1;
} }

View File

@ -13,8 +13,10 @@ import com.gunshi.project.xyt.model.OsmoticPressDevice;
import com.gunshi.project.xyt.model.OsmoticPressDeviceAutoDao; import com.gunshi.project.xyt.model.OsmoticPressDeviceAutoDao;
import com.gunshi.project.xyt.model.OsmoticPressR; import com.gunshi.project.xyt.model.OsmoticPressR;
import com.gunshi.project.xyt.util.DateUtil; import com.gunshi.project.xyt.util.DateUtil;
import com.gunshi.project.xyt.util.ExcelUtil;
import com.gunshi.project.xyt.util.MyBeanUtil; import com.gunshi.project.xyt.util.MyBeanUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -61,7 +63,10 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
OsmoticStationVo vo = new OsmoticStationVo(); OsmoticStationVo vo = new OsmoticStationVo();
vo.setTm(str); vo.setTm(str);
vo.setRz(rzMap.get(str)); vo.setRz(rzMap.get(str));
vo.setList(valueList.stream().filter(o->str.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); resList.add(vo);
} }
return resList; return resList;
@ -120,12 +125,11 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
public List<OsmoticStationVo> infiltraLine(InfiltraLineSo infiltraLineSo) { public List<OsmoticStationVo> infiltraLine(InfiltraLineSo infiltraLineSo) {
List<OsmoticStationVo> resList = new ArrayList<>(); List<OsmoticStationVo> resList = new ArrayList<>();
String profileCode = infiltraLineSo.getProfileCode(); String profileCode = infiltraLineSo.getProfileCode();
//通过断面查询渗压 //通过断面查询渗压设备
List<OsmoticPressDevice> pressList = pressDeviceAutoDao.list(new QueryWrapper<OsmoticPressDevice>().eq("profile_code", profileCode)); List<String> stationCodes = queryPressList(profileCode);
if(CollectionUtils.isEmpty(pressList)){ if(CollectionUtils.isEmpty(stationCodes)){
return resList; return resList;
} }
List<String> stationCodes = pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList());
//查询库水位 //查询库水位
List<StRzVo> list = mapper.queryLineRz(infiltraLineSo); List<StRzVo> list = mapper.queryLineRz(infiltraLineSo);
Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz)); Map<String, BigDecimal> rzMap = list.stream().collect(Collectors.toMap(StRzVo::getTm, StRzVo::getRz));
@ -156,6 +160,54 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
} }
return resList; return resList;
} }
private List<String> queryPressList(String profileCode){
List<OsmoticPressDevice> pressList = pressDeviceAutoDao.list(new QueryWrapper<OsmoticPressDevice>().eq("profile_code", profileCode));
return pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList());
}
public void export(InfiltraLineSo infiltraLineSo, HttpServletResponse response) {
//通过断面查询渗压设备
List<String> stationCodes = queryPressList(infiltraLineSo.getProfileCode());
//表头信息
List<String> heads = new ArrayList<>();
heads.add("时间");
heads.add("库水位(m)");
heads.addAll(stationCodes);
heads.add("结果分析");
//表格数据
List<OsmoticStationVo> resList = infiltraLine(infiltraLineSo);
List<Map<String, Object>> list = new ArrayList<>();
for (OsmoticStationVo vo : resList) {
Map<String, Object> test = new LinkedHashMap<>();
test.put("t1", vo.getTm());
test.put("t2", vo.getRz());
for(int i = 0;i<stationCodes.size();i++){
String code = stationCodes.get(i);
OsmoticValueVo valueVo = vo.getList().stream().filter(o->code.equals(o.getStationCode())).findFirst().orElse(null);
test.put(code,valueVo != null ? valueVo.getValue() : "-");
}
test.put("t4", vo.getStatus() == 0 ? "异常":"正常");
list.add(test);
}
List<List<String>> hs = new ArrayList<>();
for (String s : heads) {
hs.add(Arrays.asList(s));
}
List<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, "浸润线");
}
} }

View File

@ -52,6 +52,30 @@ public class ExcelUtil {
} }
} }
public static <T> void exportExcel(List<List<String>> head,List<T> data, String filename, Class<T> 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异常");
}
}
}
/** /**