完善导入功能

master
lisai 2022-07-26 21:40:58 +08:00
parent 38befe0401
commit 6f54eb3e85
11 changed files with 116 additions and 23 deletions

4
.gitignore vendored
View File

@ -41,4 +41,6 @@ logs/
/.nb-gradle/ /.nb-gradle/
yus-water/logs/ yus-water/logs/
*.vm *.vm
**/target/** **/target/**
/img

BIN
lib/DmJdbcDriver18.jar Normal file

Binary file not shown.

20
pom.xml
View File

@ -70,7 +70,7 @@
<artifactId>easypoi-spring-boot-starter</artifactId> <artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.4.0</version> <version>4.4.0</version>
</dependency> </dependency>
<!-- Sa-Token 权限认证, 在线文档http://sa-token.dev33.cn/ --> <!-- Sa-Token 权限认证, 在线文档http://sa-token.dev33.cn/ -->
<dependency> <dependency>
@ -91,7 +91,6 @@
<!-- Sa-Token 权限认证 end --> <!-- Sa-Token 权限认证 end -->
<!-- knife4j swagger start--> <!-- knife4j swagger start-->
<dependency> <dependency>
<groupId>com.github.xiaoymin</groupId> <groupId>com.github.xiaoymin</groupId>
@ -124,12 +123,25 @@
</dependency> </dependency>
<!-- fastjson end--> <!-- fastjson end-->
<!-- dameng start --> <!-- dameng start mvn 库中的 8.1.2.79 不是最新的。达梦安装包内带的 jar 才是最新的
2022年7月25日发现安装包中带的版本号是 2022.05.07 编译的 version 8.1.2.114
-->
<!-- <dependency>-->
<!-- <groupId>com.dameng</groupId>-->
<!-- <artifactId>DmJdbcDriver18</artifactId>-->
<!-- <version>8.1.2.79</version>-->
<!-- </dependency>-->
<!--
将 jar 安装到本地库仓库,方便下面的打包插件统一处理
mvn install:install-file -Dfile=C:/lisai/workspase/zhsk/zhdbaq-service/lib/DmJdbcDriver18.jar -DgroupId="com.dameng" -DartifactId=DmJdbcDriver18 -Dversion="8.1.2.114" -Dpackaging=jar
-->
<dependency> <dependency>
<groupId>com.dameng</groupId> <groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId> <artifactId>DmJdbcDriver18</artifactId>
<version>8.1.2.79</version> <version>8.1.2.114</version>
</dependency> </dependency>
<!--达梦数据库方言--> <!--达梦数据库方言-->
<dependency> <dependency>
<groupId>com.dameng</groupId> <groupId>com.dameng</groupId>

View File

@ -18,6 +18,7 @@ public class ScheduledTask {
@Scheduled(fixedDelay = 60000) @Scheduled(fixedDelay = 60000)
public void scheduledTask() { public void scheduledTask() {
String OS = System.getProperty("os.name").toLowerCase(); String OS = System.getProperty("os.name").toLowerCase();
// 简单粗暴的判断,在 linux 环境下运行时,为生成环境 // 简单粗暴的判断,在 linux 环境下运行时,为生成环境
if (OS.contains("linux")) { if (OS.contains("linux")) {
iDeviceDataService.syncData(); iDeviceDataService.syncData();

View File

@ -171,8 +171,7 @@ public class DeviceInfo implements Serializable {
*/ */
@ApiParam(value = "埋设示意图") @ApiParam(value = "埋设示意图")
@ApiModelProperty(value = "埋设示意图", dataType = "java.lang.String") @ApiModelProperty(value = "埋设示意图", dataType = "java.lang.String")
@Excel(name = "埋设示意图说明") @TableField(value = "SKETCH_MAP")
@TableField("SKETCH_MAP")
private String sketchMap; private String sketchMap;
/** /**
@ -180,7 +179,7 @@ public class DeviceInfo implements Serializable {
*/ */
@ApiParam(value = "日期") @ApiParam(value = "日期")
@ApiModelProperty(value = "日期", dataType = "java.util.Date") @ApiModelProperty(value = "日期", dataType = "java.util.Date")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Excel(name = "日期") @Excel(name = "日期")
@TableField("CREATE_DATE") @TableField("CREATE_DATE")
private Date createDate; private Date createDate;
@ -263,7 +262,7 @@ public class DeviceInfo implements Serializable {
@ApiParam(value = "埋设日期") @ApiParam(value = "埋设日期")
@ApiModelProperty(value = "埋设日期", dataType = "java.util.Date") @ApiModelProperty(value = "埋设日期", dataType = "java.util.Date")
@Excel(name = "埋设日期") @Excel(name = "埋设日期")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@TableField("EMBEDDING_DATE") @TableField("EMBEDDING_DATE")
private Date embeddingDate; private Date embeddingDate;
@ -520,4 +519,7 @@ public class DeviceInfo implements Serializable {
@TableField("INSTALLATION_POSITION_X") @TableField("INSTALLATION_POSITION_X")
private Double installationPositionX; private Double installationPositionX;
@Excel(name = "埋设示意图说明", type = 2, savePath = "img")
@TableField(exist = false)
private String picPath;
} }

View File

@ -49,4 +49,6 @@ public interface IDeviceInfoService extends IService<DeviceInfo> {
* @return * @return
*/ */
DeviceInfoImpVo imp(InputStream file); DeviceInfoImpVo imp(InputStream file);
void clearCache();
} }

View File

@ -173,10 +173,7 @@ public class DeviceDataServiceImpl extends ServiceImpl<DeviceDataMapper, DeviceD
} }
if (changeDi) { if (changeDi) {
Set<String> keys = redisTemplate.keys(Constants.CACHE_NAME + "*"); iDeviceInfoService.clearCache();
for (String k : keys) {
redisTemplate.delete(k);
}
} }
} }
} }

View File

@ -11,9 +11,12 @@ import com.whdc.zhdbaqapi.model.dto.FindDeviceDto;
import com.whdc.zhdbaqapi.model.entity.DeviceInfo; import com.whdc.zhdbaqapi.model.entity.DeviceInfo;
import com.whdc.zhdbaqapi.model.vo.DeviceInfoImpVo; import com.whdc.zhdbaqapi.model.vo.DeviceInfoImpVo;
import com.whdc.zhdbaqapi.service.IDeviceInfoService; import com.whdc.zhdbaqapi.service.IDeviceInfoService;
import com.whdc.zhdbaqapi.utils.DataUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -27,9 +30,14 @@ import java.util.*;
*/ */
@Service @Service
public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements IDeviceInfoService { public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements IDeviceInfoService {
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Override @Override
public DeviceInfo get(Integer id) { public DeviceInfo get(Integer id) {
return baseMapper.get(id); DeviceInfo ret = baseMapper.get(id);
return ret;
} }
@Override @Override
@ -100,6 +108,7 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
public DeviceInfoImpVo imp(InputStream file) { public DeviceInfoImpVo imp(InputStream file) {
ImportParams params = new ImportParams(); ImportParams params = new ImportParams();
params.setHeadRows(1); params.setHeadRows(1);
params.setNeedSave(false);
try { try {
List<DeviceInfo> list = ExcelImportUtil.importExcel(file, DeviceInfo.class, params); List<DeviceInfo> list = ExcelImportUtil.importExcel(file, DeviceInfo.class, params);
@ -141,6 +150,12 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
if (chkMap.containsKey(di.getStationCode())) { if (chkMap.containsKey(di.getStationCode())) {
err.add(di); err.add(di);
} else { } else {
if (StringUtils.isNotBlank(di.getPicPath())) {
String filepath = System.getProperty("user.dir") + "/" + di.getPicPath();
di.setSketchMap(DataUtils.File2Base64(filepath));
DataUtils.DelFile(filepath);
}
impList.add(di); impList.add(di);
} }
} }
@ -150,6 +165,7 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
} }
if (super.saveBatch(impList)) { if (super.saveBatch(impList)) {
return new DeviceInfoImpVo().setLoad(list.size()).setSuccess(impList.size()).setFail(err.size()).setErr(err).setMsg("成功"); return new DeviceInfoImpVo().setLoad(list.size()).setSuccess(impList.size()).setFail(err.size()).setErr(err).setMsg("成功");
} else { } else {
return new DeviceInfoImpVo().setLoad(list.size()).setSuccess(0).setFail(err.size()).setErr(err).setMsg("失败"); return new DeviceInfoImpVo().setLoad(list.size()).setSuccess(0).setFail(err.size()).setErr(err).setMsg("失败");
@ -159,4 +175,12 @@ public class DeviceInfoServiceimpl extends ServiceImpl<DeviceInfoMapper, DeviceI
throw new MyException("导入异常!" + e.getMessage()); throw new MyException("导入异常!" + e.getMessage());
} }
} }
@Override
public void clearCache() {
Set<String> keys = redisTemplate.keys(Constants.CACHE_NAME + "*");
for (String k : keys) {
redisTemplate.delete(k);
}
}
} }

View File

@ -1,14 +1,31 @@
package com.whdc.zhdbaqapi.utils; package com.whdc.zhdbaqapi.utils;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author * @author
* @date 2022-07-22 8:46 * @date 2022-07-22 8:46
*/ */
public class DataUtils { public class DataUtils {
private static Map<String, String> extension2Scheme = new HashMap<String, String>();
static {
extension2Scheme.put("jpg", "data:image/jpg;base64,");
extension2Scheme.put("jpeg", "data:image/jpeg;base64,");
extension2Scheme.put("png", "data:image/png;base64,");
extension2Scheme.put("gif", "data:image/gif;base64,");
extension2Scheme.put("icon", "data:image/x-icon;base64,");
}
/** /**
* σ=sqrt(s^2) * σ=sqrt(s^2)
* scale * scale
@ -31,4 +48,41 @@ public class DataUtils {
deviation = deviation.setScale(scale, BigDecimal.ROUND_HALF_UP); deviation = deviation.setScale(scale, BigDecimal.ROUND_HALF_UP);
return deviation; return deviation;
} }
public static String File2Base64(String filepath) {
if (StringUtils.isBlank(filepath)) {
return null;
}
File file1 = new File(filepath);
if (!file1.exists()) {
return null;
}
int lastPointIndex = filepath.lastIndexOf(".");
String type = filepath.substring(lastPointIndex + 1);
if (!extension2Scheme.containsKey(type.toLowerCase())) {
System.out.println("文件类型错误 " + type);
return null;
}
try (FileInputStream inputStream = new FileInputStream(file1)) {
byte[] buffer = new byte[inputStream.available()];
if (inputStream.read(buffer) == -1) {
inputStream.close();
}
return extension2Scheme.get(type.toLowerCase()) + Base64.getEncoder().encodeToString(buffer);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void DelFile(String filepath) {
File file1 = new File(filepath);
System.out.println("清理图片缓存:" + filepath + (file1.delete() ? "成功" : "失败"));
}
} }

View File

@ -36,6 +36,12 @@ spring:
port: 6379 port: 6379
password: Whdc_890 password: Whdc_890
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
knife4j: knife4j:
enable: true enable: true
setting: setting:

View File

@ -3,15 +3,7 @@
<mapper namespace="com.whdc.zhdbaqapi.mapper.DeviceInfoMapper"> <mapper namespace="com.whdc.zhdbaqapi.mapper.DeviceInfoMapper">
<select id="get" resultType="com.whdc.zhdbaqapi.model.entity.DeviceInfo"> <select id="get" resultType="com.whdc.zhdbaqapi.model.entity.DeviceInfo">
SELECT SELECT *
ID,STATION_CODE,DEVICE_ID,CHANNEL_NUM,TEMPERATURE_K,START_TEMPERATURE,CALIBRATION_COEFFICIENT,INITIAL_READING,
PROJECT_NAME,REMARK,SUPERVISOR,CREATION_TIME,MODIFICATION_TIME,DEL,IFNULL(SKETCH_MAP, '') SKETCH_MAP,CREATE_DATE,BURIED_PERSONNEL,
CHECK_PERSONNEL,TECHNICAL_DIRECTOR,TAILWATER_LEVEL,HEADWATER_LEVEL,WEATHER,AIR_PRESSURE,AIR_TEMPERATURE,
EMBEDDING_DATE,EMBEDDING_FINISH_READING,ZERO_PRESSURE_READINGS,END_READINGS,START_READINGS,DRAFT,READINGS,
DAM_WHEELBASE,COLUMN_NO,EMBEDDING_ELEVATION,CABLE_LENGTH_MARK,CABLE_LENGTH,RESISTANCE,RANGE,SENSOR_COEFFICIENT,
MANUFACTURER,MEASURING_PROBE_NO,STEADY_WATER_LEVEL,INITIAL_WATER_LEVEL,DRILLING_SIZE,DRILLING_NO,PRESSURE,
RECENT_DATA,LATEST_REPORTING_TIME,CROSS_SECTION,DAM,MOUNTING_HEIGHT,
INSTALLATION_POSITION_Z,INSTALLATION_POSITION_Y,INSTALLATION_POSITION_X
FROM DEVICE_INFO WHERE ID=#{id} FROM DEVICE_INFO WHERE ID=#{id}
</select> </select>
@ -66,5 +58,6 @@
SELECT ID, STATION_CODE FROM DEVICE_INFO SELECT ID, STATION_CODE FROM DEVICE_INFO
WHERE DEL = 0 WHERE DEL = 0
AND STATION_CODE = #{stationCode} AND STATION_CODE = #{stationCode}
LIMIT 1
</select> </select>
</mapper> </mapper>