21 changed files with 968 additions and 152 deletions
@ -1,86 +0,0 @@
@@ -1,86 +0,0 @@
|
||||
package com.ruoyi.swlscx.day.service.impl; |
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage; |
||||
import com.ruoyi.common.core.page.R; |
||||
import com.ruoyi.swlscx.basic.domain.vo.HyStscAVo; |
||||
import com.ruoyi.swlscx.basic.service.HyStscAService; |
||||
import com.ruoyi.swlscx.basic.service.YcExportTaskService; |
||||
import com.ruoyi.swlscx.common.PageParams; |
||||
import com.ruoyi.swlscx.day.service.HyDcsFService; |
||||
import com.ruoyi.swlscx.day.service.HyDwtCService; |
||||
import com.ruoyi.swlscx.day.service.HyZscsBService; |
||||
import com.ruoyi.swlscx.excerpt.service.HyHltdzBService; |
||||
import org.junit.jupiter.api.Test; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.mock.web.MockMultipartFile; |
||||
import org.springframework.web.multipart.MultipartFile; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
|
||||
|
||||
/** |
||||
* @Author al |
||||
* @Date 2024/10/16 9:48 |
||||
* @Description: TODO |
||||
* @Version |
||||
*/ |
||||
@SpringBootTest(classes = com.ruoyi.RuoYiApplication.class) |
||||
class HyDpCServiceImplTest { |
||||
|
||||
|
||||
@Autowired |
||||
private HyDcsFService hyDcsFService; |
||||
@Autowired |
||||
private YcExportTaskService ycExportTaskService; |
||||
|
||||
@Autowired |
||||
private HyStscAService hyStscAService; |
||||
|
||||
|
||||
@Autowired |
||||
private HyZscsBService hyZscsBService; |
||||
@Test |
||||
public void importData() throws Exception { |
||||
|
||||
// List<String> stringList = Arrays.asList("逐潮高低潮位表200501-200801"
|
||||
// , "逐潮高低潮位表200801-201001",
|
||||
// "逐潮高低潮位表201001-201301"
|
||||
// , "逐潮高低潮位表201301-201501",
|
||||
// "逐潮高低潮位表201501-201701",
|
||||
// "逐潮高低潮位表201701-202001"
|
||||
// ,"逐潮高低潮位表202001-");
|
||||
List<String> stringList = Arrays.asList("逐时潮水位表 (1)","逐时潮水位表 (2)","逐时潮水位表 (3)"); |
||||
long newTime = System.currentTimeMillis(); |
||||
System.out.println("当前时间:" + newTime); |
||||
for (String s : stringList) { |
||||
// File file = new File("C:\\Users\\12974\\Desktop\\历史查询子系统\\历史数据\\日表类\\日平均含沙量表-已完成\\" + s + ".xls");
|
||||
|
||||
File file = new File("C:\\Users\\12974\\Downloads\\" + s + ".xls"); |
||||
// 创建 FileInputStream 对象
|
||||
FileInputStream fileInputStream = new FileInputStream(file); |
||||
|
||||
// 创建 MockMultipartFile 对象
|
||||
MultipartFile multipartFile = new MockMultipartFile( |
||||
"file", |
||||
file.getName(), |
||||
"application/vnd.ms-excel", |
||||
fileInputStream |
||||
); |
||||
hyZscsBService.importHyZscsBData(multipartFile); |
||||
} |
||||
System.out.println("总耗时:" + (System.currentTimeMillis() - newTime)); |
||||
} |
||||
|
||||
@Test |
||||
public void test() { |
||||
System.out.println(hyStscAService.testSqlServer()); |
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
package com.ruoyi.swlscx.basic.domain.rowMapper; |
||||
|
||||
import com.ruoyi.swlscx.actualSurvey.domain.po.HyObqG; |
||||
import org.springframework.jdbc.core.RowMapper; |
||||
|
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Timestamp; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @Author al |
||||
* @Date 2025/7/13 14:37 |
||||
* @Description: TODO |
||||
* @Version |
||||
*/ |
||||
public class HyObqGRowMapper implements RowMapper<HyObqG> { |
||||
|
||||
@Override |
||||
public HyObqG mapRow(ResultSet rs, int rowNum) throws SQLException { |
||||
HyObqG hyObqG = new HyObqG(); |
||||
|
||||
// 1. 字符串类型字段
|
||||
hyObqG.setId(rs.getString("ID")); // 唯一标识符
|
||||
hyObqG.setStcd(rs.getString("STCD")); // 站码
|
||||
hyObqG.setXsqlc(rs.getString("XSQLC")); // 测流断面位置
|
||||
hyObqG.setMsqmt(rs.getString("MSQMT")); // 测流方法
|
||||
hyObqG.setQrcd(rs.getString("QRCD")); // 流量注解码
|
||||
hyObqG.setXsarcd(rs.getString("XSARCD")); // 断面面积注解码
|
||||
hyObqG.setObnont(rs.getString("OBNONT")); // 测次说明
|
||||
|
||||
// 2. 整数类型字段(处理可能的NULL值)
|
||||
hyObqG.setYr(rs.getObject("YR") != null ? rs.getInt("YR") : null); // 年份
|
||||
hyObqG.setMnth(rs.getObject("MNTH") != null ? rs.getInt("MNTH") : null); // 月份
|
||||
hyObqG.setQobno(rs.getObject("QOBNO") != null ? rs.getInt("QOBNO") : null); // 流量施测号数
|
||||
|
||||
// 3. 日期/时间类型字段(java.sql.Timestamp → java.util.Date)
|
||||
Timestamp msqbgtmTs = rs.getTimestamp("MSQBGTM"); |
||||
if (msqbgtmTs != null) { |
||||
hyObqG.setMsqbgtm(new Date(msqbgtmTs.getTime())); // 测流起时间
|
||||
} |
||||
Timestamp msqedtmTs = rs.getTimestamp("MSQEDTM"); |
||||
if (msqedtmTs != null) { |
||||
hyObqG.setMsqedtm(new Date(msqedtmTs.getTime())); // 测流止时间
|
||||
} |
||||
|
||||
// 4. 双精度浮点数字段(使用getDouble() + NULL检查)
|
||||
setDoubleField(rs, "BSGGZ", hyObqG::setBsggz); // 基本水尺水位
|
||||
setDoubleField(rs, "Q", hyObqG::setQ); // 流量
|
||||
setDoubleField(rs, "XSTTA", hyObqG::setXstta); // 断面总面积
|
||||
setDoubleField(rs, "XSA", hyObqG::setXsa); // 断面过水面积
|
||||
setDoubleField(rs, "XSAVV", hyObqG::setXsavv); // 断面平均流速
|
||||
setDoubleField(rs, "XSMXV", hyObqG::setXsmxv); // 断面最大流速
|
||||
setDoubleField(rs, "TPWD", hyObqG::setTpwd); // 水面宽
|
||||
setDoubleField(rs, "XSAVDP", hyObqG::setXsavdp); // 断面平均水深
|
||||
setDoubleField(rs, "XSMXDP", hyObqG::setXsmxdp); // 断面最大水深
|
||||
setDoubleField(rs, "IBWD", hyObqG::setIbwd); // 水浸冰底宽度
|
||||
setDoubleField(rs, "IBAVDP", hyObqG::setIbavdp); // 水浸冰底平均水深
|
||||
setDoubleField(rs, "IBMXDP", hyObqG::setIbmxdp); // 水浸冰底最大水深
|
||||
setDoubleField(rs, "RVSFSL", hyObqG::setRvsfsl); // 水面比降
|
||||
setDoubleField(rs, "N", hyObqG::setN); // 糙率
|
||||
|
||||
return hyObqG; |
||||
} |
||||
|
||||
// 辅助方法:安全设置Double字段(处理NULL值)
|
||||
private void setDoubleField(ResultSet rs, String columnName, java.util.function.Consumer<Double> setter) |
||||
throws SQLException { |
||||
double value = rs.getDouble(columnName); |
||||
if (!rs.wasNull()) { // 关键:检查实际值是否为NULL
|
||||
setter.accept(value); |
||||
} |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
package com.ruoyi.swlscx.basic.domain.rowMapper; |
||||
|
||||
import com.ruoyi.swlscx.actualSurvey.domain.po.HyObqG; |
||||
import com.ruoyi.swlscx.actualSurvey.domain.po.HyXsmsrsG; |
||||
import org.springframework.jdbc.core.RowMapper; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.sql.Timestamp; |
||||
import java.util.Date; |
||||
import java.util.function.Consumer; |
||||
|
||||
/** |
||||
* @Author al |
||||
* @Date 2025/7/13 14:47 |
||||
* @Description: TODO |
||||
* @Version |
||||
*/ |
||||
public class HyXsmsrsGRowMapper implements RowMapper<HyXsmsrsG> { |
||||
|
||||
@Override |
||||
public HyXsmsrsG mapRow(ResultSet rs, int rowNum) throws SQLException { |
||||
HyXsmsrsG hyXsmsrsG = new HyXsmsrsG(); |
||||
|
||||
// 1. 字符串类型字段(直接映射,数据库NULL转为Java null)
|
||||
hyXsmsrsG.setStcd(rs.getString("STCD")); // 站码
|
||||
hyXsmsrsG.setVtno(rs.getString("VTNO")); // 垂线号
|
||||
hyXsmsrsG.setRvbbelrcd(rs.getString("RVBDELRCD")); // 河底高程注解码
|
||||
hyXsmsrsG.setOdbrzrcd(rs.getString("ODBRZRCD")); // 测时水位注解码
|
||||
hyXsmsrsG.setVtaz(rs.getString("VTAZ")); // 垂线方位
|
||||
|
||||
// 2. 日期类型字段(Timestamp → java.util.Date)
|
||||
Timestamp obdtTs = rs.getTimestamp("OBDT"); |
||||
if (obdtTs != null) { |
||||
hyXsmsrsG.setObdt(new Date(obdtTs.getTime())); // 施测日期
|
||||
} |
||||
|
||||
// 3. 整数字段(处理NULL值)
|
||||
hyXsmsrsG.setObno(getNullableInt(rs, "OBNO")); // 测次号
|
||||
// nof字段若未从数据库读取则设默认值1
|
||||
Integer nofValue = getNullableInt(rs, "NOF"); |
||||
hyXsmsrsG.setNof(nofValue != null ? nofValue : 1); // 默认值逻辑[4](@ref)
|
||||
|
||||
// 4. BigDecimal字段(精确小数处理)
|
||||
setBigDecimalField(rs, "DI", hyXsmsrsG::setDi); // 起点距(米)
|
||||
setBigDecimalField(rs, "RVBDEL", hyXsmsrsG::setRvbbel); // 河底高程(米)
|
||||
setBigDecimalField(rs, "ODBRZ", hyXsmsrsG::setOdbrz); // 测时水位(米)
|
||||
|
||||
return hyXsmsrsG; |
||||
} |
||||
|
||||
// 辅助方法:安全获取可空整数字段
|
||||
private Integer getNullableInt(ResultSet rs, String columnName) throws SQLException { |
||||
int value = rs.getInt(columnName); |
||||
return rs.wasNull() ? null : value; // 检测数据库NULL值[4](@ref)
|
||||
} |
||||
|
||||
// 辅助方法:安全设置BigDecimal字段
|
||||
private void setBigDecimalField(ResultSet rs, String columnName, Consumer<BigDecimal> setter) |
||||
throws SQLException { |
||||
BigDecimal value = rs.getBigDecimal(columnName); |
||||
if (value != null) { // 直接检查BigDecimal是否为NULL
|
||||
setter.accept(value); |
||||
} |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue