浸润线导出
parent
a34009ac69
commit
1d52363389
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ServiceImpl<OsmoticPressRMapper, Osmot
|
|||
OsmoticStationVo vo = new OsmoticStationVo();
|
||||
vo.setTm(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);
|
||||
}
|
||||
return resList;
|
||||
|
|
@ -120,12 +125,11 @@ public class OsmoticPressRService extends ServiceImpl<OsmoticPressRMapper, Osmot
|
|||
public List<OsmoticStationVo> infiltraLine(InfiltraLineSo infiltraLineSo) {
|
||||
List<OsmoticStationVo> resList = new ArrayList<>();
|
||||
String profileCode = infiltraLineSo.getProfileCode();
|
||||
//通过断面查询渗压
|
||||
List<OsmoticPressDevice> pressList = pressDeviceAutoDao.list(new QueryWrapper<OsmoticPressDevice>().eq("profile_code", profileCode));
|
||||
if(CollectionUtils.isEmpty(pressList)){
|
||||
//通过断面查询渗压设备
|
||||
List<String> stationCodes = queryPressList(profileCode);
|
||||
if(CollectionUtils.isEmpty(stationCodes)){
|
||||
return resList;
|
||||
}
|
||||
List<String> stationCodes = pressList.stream().map(OsmoticPressDevice::getStationCode).collect(Collectors.toList());
|
||||
//查询库水位
|
||||
List<StRzVo> list = mapper.queryLineRz(infiltraLineSo);
|
||||
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;
|
||||
}
|
||||
|
||||
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, "浸润线");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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异常");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue