diff --git a/.gitignore b/.gitignore index ba7867f..6f161d7 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,6 @@ logs/ /.nb-gradle/ yus-water/logs/ *.vm -**/target/** \ No newline at end of file +**/target/** + +/img \ No newline at end of file diff --git a/lib/DmJdbcDriver18.jar b/lib/DmJdbcDriver18.jar new file mode 100644 index 0000000..d7f65d8 Binary files /dev/null and b/lib/DmJdbcDriver18.jar differ diff --git a/pom.xml b/pom.xml index bbaf3d8..3948f1e 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ easypoi-spring-boot-starter 4.4.0 - + @@ -91,7 +91,6 @@ - com.github.xiaoymin @@ -124,12 +123,25 @@ - + + + + + + + + com.dameng DmJdbcDriver18 - 8.1.2.79 + 8.1.2.114 + com.dameng diff --git a/src/main/java/com/whdc/zhdbaqapi/component/ScheduledTask.java b/src/main/java/com/whdc/zhdbaqapi/component/ScheduledTask.java index 45b84b9..7dc779d 100644 --- a/src/main/java/com/whdc/zhdbaqapi/component/ScheduledTask.java +++ b/src/main/java/com/whdc/zhdbaqapi/component/ScheduledTask.java @@ -18,6 +18,7 @@ public class ScheduledTask { @Scheduled(fixedDelay = 60000) public void scheduledTask() { String OS = System.getProperty("os.name").toLowerCase(); + // 简单粗暴的判断,在 linux 环境下运行时,为生成环境 if (OS.contains("linux")) { iDeviceDataService.syncData(); diff --git a/src/main/java/com/whdc/zhdbaqapi/model/entity/DeviceInfo.java b/src/main/java/com/whdc/zhdbaqapi/model/entity/DeviceInfo.java index 7e7f66e..4d61abe 100644 --- a/src/main/java/com/whdc/zhdbaqapi/model/entity/DeviceInfo.java +++ b/src/main/java/com/whdc/zhdbaqapi/model/entity/DeviceInfo.java @@ -171,8 +171,7 @@ public class DeviceInfo implements Serializable { */ @ApiParam(value = "埋设示意图") @ApiModelProperty(value = "埋设示意图", dataType = "java.lang.String") - @Excel(name = "埋设示意图说明") - @TableField("SKETCH_MAP") + @TableField(value = "SKETCH_MAP") private String sketchMap; /** @@ -180,7 +179,7 @@ public class DeviceInfo implements Serializable { */ @ApiParam(value = "日期") @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 = "日期") @TableField("CREATE_DATE") private Date createDate; @@ -263,7 +262,7 @@ public class DeviceInfo implements Serializable { @ApiParam(value = "埋设日期") @ApiModelProperty(value = "埋设日期", dataType = "java.util.Date") @Excel(name = "埋设日期") - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @TableField("EMBEDDING_DATE") private Date embeddingDate; @@ -520,4 +519,7 @@ public class DeviceInfo implements Serializable { @TableField("INSTALLATION_POSITION_X") private Double installationPositionX; + @Excel(name = "埋设示意图说明", type = 2, savePath = "img") + @TableField(exist = false) + private String picPath; } diff --git a/src/main/java/com/whdc/zhdbaqapi/service/IDeviceInfoService.java b/src/main/java/com/whdc/zhdbaqapi/service/IDeviceInfoService.java index 4af1417..3c67d13 100644 --- a/src/main/java/com/whdc/zhdbaqapi/service/IDeviceInfoService.java +++ b/src/main/java/com/whdc/zhdbaqapi/service/IDeviceInfoService.java @@ -49,4 +49,6 @@ public interface IDeviceInfoService extends IService { * @return */ DeviceInfoImpVo imp(InputStream file); + + void clearCache(); } diff --git a/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceDataServiceImpl.java b/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceDataServiceImpl.java index c08d6b1..86edcac 100644 --- a/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceDataServiceImpl.java +++ b/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceDataServiceImpl.java @@ -173,10 +173,7 @@ public class DeviceDataServiceImpl extends ServiceImpl keys = redisTemplate.keys(Constants.CACHE_NAME + "*"); - for (String k : keys) { - redisTemplate.delete(k); - } + iDeviceInfoService.clearCache(); } } } diff --git a/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceInfoServiceimpl.java b/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceInfoServiceimpl.java index d962519..af03081 100644 --- a/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceInfoServiceimpl.java +++ b/src/main/java/com/whdc/zhdbaqapi/service/impl/DeviceInfoServiceimpl.java @@ -11,9 +11,12 @@ import com.whdc.zhdbaqapi.model.dto.FindDeviceDto; import com.whdc.zhdbaqapi.model.entity.DeviceInfo; import com.whdc.zhdbaqapi.model.vo.DeviceInfoImpVo; import com.whdc.zhdbaqapi.service.IDeviceInfoService; +import com.whdc.zhdbaqapi.utils.DataUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,9 +30,14 @@ import java.util.*; */ @Service public class DeviceInfoServiceimpl extends ServiceImpl implements IDeviceInfoService { + @Autowired + private RedisTemplate redisTemplate; + @Override public DeviceInfo get(Integer id) { - return baseMapper.get(id); + DeviceInfo ret = baseMapper.get(id); + + return ret; } @Override @@ -100,6 +108,7 @@ public class DeviceInfoServiceimpl extends ServiceImpl list = ExcelImportUtil.importExcel(file, DeviceInfo.class, params); @@ -141,6 +150,12 @@ public class DeviceInfoServiceimpl extends ServiceImpl keys = redisTemplate.keys(Constants.CACHE_NAME + "*"); + for (String k : keys) { + redisTemplate.delete(k); + } + } } diff --git a/src/main/java/com/whdc/zhdbaqapi/utils/DataUtils.java b/src/main/java/com/whdc/zhdbaqapi/utils/DataUtils.java index 8bb0586..bb3d424 100644 --- a/src/main/java/com/whdc/zhdbaqapi/utils/DataUtils.java +++ b/src/main/java/com/whdc/zhdbaqapi/utils/DataUtils.java @@ -1,14 +1,31 @@ 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.MathContext; import java.math.RoundingMode; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; /** * @author 李赛 * @date 2022-07-22 8:46 */ public class DataUtils { + private static Map extension2Scheme = new HashMap(); + + 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) * 结果精度:scale @@ -31,4 +48,41 @@ public class DataUtils { deviation = deviation.setScale(scale, BigDecimal.ROUND_HALF_UP); 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() ? "成功" : "失败")); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 56d174a..6a8ab18 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -36,6 +36,12 @@ spring: port: 6379 password: Whdc_890 + + servlet: + multipart: + max-file-size: 100MB + max-request-size: 100MB + knife4j: enable: true setting: diff --git a/src/main/resources/mapper/DeviceInfoMapper.xml b/src/main/resources/mapper/DeviceInfoMapper.xml index c44b98e..05353b2 100644 --- a/src/main/resources/mapper/DeviceInfoMapper.xml +++ b/src/main/resources/mapper/DeviceInfoMapper.xml @@ -3,15 +3,7 @@ @@ -66,5 +58,6 @@ SELECT ID, STATION_CODE FROM DEVICE_INFO WHERE DEL = 0 AND STATION_CODE = #{stationCode} + LIMIT 1