修改LocalDateTime改为使用Date类型

This commit is contained in:
duwenyuan 2026-05-23 11:06:52 +08:00
parent 5b920b4935
commit f72f4d7a7a
19 changed files with 655 additions and 467 deletions

View File

@ -4,10 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.jeecg.modules.base.enums.SourceType;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.Set;
@ -29,7 +27,7 @@ public class Info implements Serializable {
private String sampleName;
// 采样时间
private LocalDateTime collectionDate;
private Date collectionDate;
//采集停止时间
private Date collectStop;
// 数据源类型(ARMDARR=1|ARMDRRR=2|IDCARR=3|IDCRRR=4)

View File

@ -3,7 +3,7 @@ package org.jeecg.modules.base.entity;
import lombok.Data;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;
@Data
public class GardsNuclThresholds implements Serializable {
@ -12,6 +12,6 @@ public class GardsNuclThresholds implements Serializable {
private String stationId;
private Double thresholdValue;
private String nuclideName;
private LocalDateTime calculationTime;
private Date calculationTime;
}

View File

@ -7,6 +7,7 @@ import org.jeecg.modules.base.entity.ThresholdMetric;
import org.jeecg.modules.base.entity.rnauto.GardsThresholdResult;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
@Mapper
@ -20,5 +21,5 @@ public interface ThresholdRnAutoResultMapper extends BaseMapper<GardsThresholdRe
List<ThresholdMetric> selectByRnAutoStationIds(@Param("stationIds") List<String> stationIds,
@Param("oneYearAgo")
Timestamp oneYearAgo);
Date oneYearAgo);
}

View File

@ -7,6 +7,7 @@ import org.jeecg.modules.base.entity.ThresholdMetric;
import org.jeecg.modules.base.entity.rnman.GardsThresholdResult;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
@Mapper
@ -19,5 +20,5 @@ public interface ThresholdRnManResultMapper extends BaseMapper<GardsThresholdRes
List<GardsThresholdResult> selectByStationId(String stationId);
List<ThresholdMetric> selectByRnManStationIds(@Param("stationIds") List<String> stationIds,
@Param("oneYearAgo") Timestamp oneYearAgo);
@Param("oneYearAgo") Date oneYearAgo);
}

View File

@ -26,7 +26,8 @@ import java.util.stream.Collectors;
@Service
@Slf4j
@DS("ora")
public class RnAutoThresholdServiceImpl extends ThresholdCalculationBaseService<ThresholdRnAutoResultMapper, GardsThresholdResult> {
public class RnAutoThresholdServiceImpl
extends ThresholdCalculationBaseService<ThresholdRnAutoResultMapper, GardsThresholdResult> {
@Autowired
@ -118,7 +119,8 @@ public class RnAutoThresholdServiceImpl extends ThresholdCalculationBaseService<
/**
* 构建ThresholdResult列表
*/
private List<GardsThresholdResult> buildThresholdResultList(Info info, Map<String, Double> thresholds,
private List<GardsThresholdResult> buildThresholdResultList(Info info,
Map<String, Double> thresholds,
Map<String, StatisticsResult> statistics) {
List<GardsThresholdResult> results = new ArrayList<>(thresholds.size());
@ -137,7 +139,8 @@ public class RnAutoThresholdServiceImpl extends ThresholdCalculationBaseService<
String concStr = info.getNuclides().get(nuclideName);
if (StringUtils.hasText(concStr)) {
try {
double concValue = Double.parseDouble(NumberFormatUtil.numberFormat(concStr));
double concValue =
Double.parseDouble(NumberFormatUtil.numberFormat(concStr));
category = concValue < thresholdValue ? "B" : "C";
} catch (Exception ignored) {
// 解析失败保持 A
@ -146,7 +149,7 @@ public class RnAutoThresholdServiceImpl extends ThresholdCalculationBaseService<
}
GardsThresholdResult result = new GardsThresholdResult();
result.setId(UUID.randomUUID().toString());
result.setStationId(Integer.parseInt(info.getStationId()) );
result.setStationId(Integer.parseInt(info.getStationId()));
result.setNuclideName(nuclideName);
result.setCategory(category);
result.setThresholdValue(thresholdValue);
@ -208,11 +211,9 @@ public class RnAutoThresholdServiceImpl extends ThresholdCalculationBaseService<
* @param startDate 开始时间
* @return List<ThresholdMetric> ThresholdMetric
*/
public List<ThresholdMetric> queryMetricsByDataType(List<String> stationIds, String startDate) {
public List<ThresholdMetric> queryMetricsByDataType(List<String> stationIds, Date startDate) {
try {
Timestamp timestamp = Timestamp.valueOf(startDate);
return this.baseMapper.selectByRnAutoStationIds(stationIds, timestamp);
return this.baseMapper.selectByRnAutoStationIds(stationIds, startDate);
} catch (Exception e) {
log.error("查询核素度量数据失败:,台站{}", stationIds, e);
return Collections.emptyList();

View File

@ -177,10 +177,9 @@ public class RnManThresholdServiceImpl extends ThresholdCalculationBaseService<T
* @param startDate 开始时间
* @return List<ThresholdMetric> ThresholdMetric
*/
public List<ThresholdMetric> queryMetricsByDataType(List<String> stationIds, String startDate) {
public List<ThresholdMetric> queryMetricsByDataType(List<String> stationIds, Date startDate) {
try {
Timestamp timestamp = Timestamp.valueOf(startDate);
return this.baseMapper.selectByRnManStationIds(stationIds, timestamp);
return this.baseMapper.selectByRnManStationIds(stationIds, startDate);
} catch (Exception e) {
log.error("查询核素度量数据失败:,台站{}", stationIds, e);

View File

@ -25,6 +25,8 @@ import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@ -280,9 +282,8 @@ public abstract class ThresholdCalculationBaseService<M extends BaseMapper<T>, T
}
//查询核素浓度
// 计算查询时间范围近1年
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, -getDayValue());
String startDate = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
Date startDate = Date.from(LocalDateTime.now().minusDays(getDayValue())
.atZone(ZoneId.systemDefault()).toInstant());
log.debug("查询核素度量数据:台站{}个,时间范围{}至今",
stationIds.size(), startDate);
@ -345,9 +346,8 @@ public abstract class ThresholdCalculationBaseService<M extends BaseMapper<T>, T
throw new IllegalArgumentException("台站ID列表不可为空");
}
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_YEAR, -getDayValue());
String startDate = DateUtils.formatDate(calendar.getTime(), "yyyy-MM-dd HH:mm:ss");
Date startDate = Date.from(LocalDateTime.now().minusDays(getDayValue())
.atZone(ZoneId.systemDefault()).toInstant());
log.debug("查询核素度量数据:台站{}个,时间范围{}至今",
stationIds.size(), startDate);
@ -391,7 +391,7 @@ public abstract class ThresholdCalculationBaseService<M extends BaseMapper<T>, T
* @param startDate 开始时间
* @return 度量数据列表
*/
protected abstract List<ThresholdMetric> queryMetricsByDataType(List<String> stationIds, String startDate);
protected abstract List<ThresholdMetric> queryMetricsByDataType(List<String> stationIds, Date startDate);
/**
* 解析度量数据到分层映射

View File

@ -38,10 +38,11 @@ import org.springframework.stereotype.Component;
import static org.jeecg.common.constant.enums.MessageTypeEnum.*;
import static org.jeecg.common.util.TokenUtils.getTempToken;
import static org.jeecg.modules.base.enums.Template.ANALYSIS_NUCLIDE;
import static org.jeecg.modules.base.enums.Template.ANALYSIS_NUCLIDE;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@ -94,56 +95,70 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
// 手动删除已消费消息
redisStreamUtil.del(streamKey, recordId.getValue());
}
}catch (Exception e){
} catch (Exception e) {
log.error("AnalysisConsumer消费异常: ", e);
}finally {
} finally {
destroy();
}
}
private void consume(Info info){
private void consume(Info info) {
String stationId = info.getStationId();
String sampleId = info.getSampleId();
String fullOrPrel = info.getFullOrPrel();
String datasource = info.getDatasource();
Map<String, String> infoNuclideMap = info.getNuclides();
if (StrUtil.isBlank(stationId)) return;
if (StrUtil.isBlank(sampleId)) return;
if (MapUtil.isEmpty(infoNuclideMap)) return;
if (StrUtil.isBlank(stationId)) {
return;
}
if (StrUtil.isBlank(sampleId)) {
return;
}
if (MapUtil.isEmpty(infoNuclideMap)) {
return;
}
List<AlarmAnalysisRule> rules = ruleService.allAnalysisRule();
for (AlarmAnalysisRule rule : rules) {
// 当前规则是否有报警条件
String conditionStr = rule.getConditions();
if (StrUtil.isBlank(conditionStr))
if (StrUtil.isBlank(conditionStr)) {
continue;
}
// 是否在当前规则关注的台站列表内
String stations = rule.getStations();
if (!StrUtil.contains(stations, stationId))
if (!StrUtil.contains(stations, stationId)) {
continue;
}
// 是否在当前规则关注的数据源内
String source = rule.getSource();
if (!StrUtil.contains(source,datasource))
if (!StrUtil.contains(source, datasource)) {
continue;
}
// 是否在当前规则关注的谱类型内
String spectralQualifier = rule.getSpectralQualifier();
if (!StrUtil.contains(spectralQualifier,fullOrPrel))
if (!StrUtil.contains(spectralQualifier, fullOrPrel)) {
continue;
}
// 是否有当前规则关注的核素
String nuclidesStr = rule.getNuclides();
if (StrUtil.isBlank(nuclidesStr)) continue;
if (StrUtil.isBlank(nuclidesStr)) {
continue;
}
Set<String> names = infoNuclideMap.keySet();
List<String> follow = ListUtil.toList(nuclidesStr.split(COMMA));
// 因数据库 Xe核素名称 M大小写不统一先统一大小写再进行比较
Collection<String> follows = follow.stream().map(f -> {
if(f.toLowerCase().contains("xe")){
return f.replace("M", "m");
if (f.toLowerCase().contains("xe")) {
return f.replace("M", "m");
}
return f;
}).collect(Collectors.toList());
// 推送过来的核素集合与所关注核素集合取交集
Collection<String> cross = CollectionUtil.intersection(names, follows);
if (CollUtil.isEmpty(cross)) continue;
if (CollUtil.isEmpty(cross)) {
continue;
}
Map<String, String> nuclidesCross = infoNuclideMap.entrySet().stream()
.filter(entry -> cross.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
@ -155,7 +170,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
String[] inSplit = rule.getIdentifyNuclides().split(",");
if (inSplit.length >= 1) {
info.setIdentifyNuclideSet(Arrays.stream(inSplit).map(f -> {
if(f.toLowerCase().contains("xe")){
if (f.toLowerCase().contains("xe")) {
return f.replace("M", "m");
}
return f;
@ -166,20 +181,24 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
}
}
private void judge(Info info, Map<String,String> nuclidesCross){
private void judge(Info info, Map<String, String> nuclidesCross) {
Set<String> nuclideNames = nuclidesCross.keySet();
String conditionStr = info.getConditions();
String betaOrGamma = info.getBetaOrGamma();
String datasource = info.getDatasource();
String stationId = info.getStationId();
String stationCode="";
HashMap<String, Object> stationMap = (HashMap<String, Object>)redisUtil.get(RedisConstant.STATION_CODE_MAP);
String stationCode = "";
HashMap<String, Object> stationMap =
(HashMap<String, Object>) redisUtil.get(RedisConstant.STATION_CODE_MAP);
String sampleId = info.getSampleId();
String sampleName = info.getSampleName();
Set<String> identifyNuclideSet = info.getIdentifyNuclideSet();
// 获取谱文件采样日期 如果为null 则默认为LocalDate.now()
LocalDate collDate = ObjectUtil.isNull(info.getCollectionDate()) ? LocalDate.now() :
info.getCollectionDate().toLocalDate();
LocalDate localDate = info.getCollectionDate().toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate();
LocalDate collDate =
ObjectUtil.isNull(info.getCollectionDate()) ? LocalDate.now() : localDate;
List<String> conditions = ListUtil.toList(conditionStr.split(COMMA));
List<NuclideInfo> firstDetected = new ArrayList<>(); // 首次发现
@ -189,20 +208,26 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
List<NuclideInfo> identifyNuclideResult = new ArrayList<>();
for (String con : conditions) {
Condition condition = Condition.valueOf1(con);
if (ObjectUtil.isNull(condition)) continue;
switch (condition){
if (ObjectUtil.isNull(condition)) {
continue;
}
switch (condition) {
case FIRST_FOUND: // 首次发现该元素
firstDetected = this.firstDetected(betaOrGamma, datasource, stationId, sampleId, nuclidesCross);
firstDetected = this.firstDetected(betaOrGamma, datasource, stationId, sampleId,
nuclidesCross);
break;
case ABOVE_AVERAGE: // 元素浓度高于均值
moreThanAvg = this.moreThanAvg(datasource, stationId, collDate, nuclidesCross);
break;
case MEANWHILE: // 同时出现两种及以上核素
meanWhile = this.meanWhile(betaOrGamma, datasource, sampleId, nuclidesCross);
if (meanWhile.size() < 2) meanWhile = ListUtil.empty();
if (meanWhile.size() < 2) {
meanWhile = ListUtil.empty();
}
break;
case IDENTIFY_NUCLIDES: // 识别到某个核素
identifyNuclideResult = this.meanWhile(info.getNuclides(), datasource, identifyNuclideSet);
identifyNuclideResult =
this.meanWhile(info.getNuclides(), datasource, identifyNuclideSet);
break;
default:
break;
@ -219,7 +244,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
nuclideInfoMap.put(nuclideInfo.getNuclide(), nuclideInfo);
}
}
if (CollUtil.isNotEmpty(meanWhile)){
if (CollUtil.isNotEmpty(meanWhile)) {
String above = meanWhile.stream()
.map(NuclideInfo::getNuclide)
.collect(Collectors.joining(StrUtil.COMMA + StrUtil.SPACE));
@ -228,7 +253,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
nuclideInfoMap.put(nuclideInfo.getNuclide(), nuclideInfo);
}
}
if (CollUtil.isNotEmpty(identifyNuclideResult)){
if (CollUtil.isNotEmpty(identifyNuclideResult)) {
String above = identifyNuclideResult.stream()
.map(NuclideInfo::getNuclide)
.collect(Collectors.joining(StrUtil.COMMA + StrUtil.SPACE));
@ -237,9 +262,10 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
nuclideInfoMap.put(nuclideInfo.getNuclide(), nuclideInfo);
}
}
if (CollUtil.isNotEmpty(moreThanAvg)){
if (CollUtil.isNotEmpty(moreThanAvg)) {
String above = moreThanAvg.stream()
.map(item -> item.getNuclide() + "(" + item.getValue() + ")" + " > " + item.getThreshold())
.map(item -> item.getNuclide() + "(" + item.getValue() + ")" + " > " +
item.getThreshold())
.collect(Collectors.joining(StrUtil.COMMA + StrUtil.SPACE));
dataTool.put("moreThanAvg", above);
for (NuclideInfo nuclideInfo : moreThanAvg) {
@ -247,23 +273,26 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
}
}
// 如果报警数据为空 则不需要发送报警信息和生成报警日志
if (MapUtil.isEmpty(dataTool.get())) return;
if (MapUtil.isEmpty(dataTool.get())) {
return;
}
// 产生报警信息的Sample信息
if (CollUtil.isNotEmpty(stationMap))
{
stationCode=stationMap.get(stationId).toString();
if (CollUtil.isNotEmpty(stationMap)) {
stationCode = stationMap.get(stationId).toString();
}
dataTool.put("sampleId", sampleId).put("sampleName", sampleName);
DataTool titleData = DataTool.getInstance();
titleData.put("stationCode",stationCode);
titleData.put("stationCode", stationCode);
// 构建预警信息实例 准备发送预警信息,20250327--修改模版
MessageDTO messageDTO = TemplateUtil.parse1(ANALYSIS_NUCLIDE.getCode(), dataTool.get(),titleData.get());
MessageDTO messageDTO =
TemplateUtil.parse1(ANALYSIS_NUCLIDE.getCode(), dataTool.get(), titleData.get());
// 保存报警日志
AlarmAnalysisLog logInfo = new AlarmAnalysisLog();
BeanUtil.copyProperties(info, logInfo);
SampleType sampleType = SampleType.typeOf(betaOrGamma);
if (ObjectUtil.isNotNull(sampleType))
if (ObjectUtil.isNotNull(sampleType)) {
logInfo.setSampleType(sampleType.getValue());
}
logInfo.setAlarmInfo(messageDTO.getContent());
// 报警信息中核素列表
@ -283,7 +312,8 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
* 首次发现该核素
*/
private List<NuclideInfo> firstDetected(String betaOrGamma, String dataSourceType,
String stationId, String sampleId, Map<String,String> nuclidesCross){
String stationId, String sampleId,
Map<String, String> nuclidesCross) {
List<NuclideInfo> result = Lists.newArrayList();
/* 查询用户关注的核素是否存在 如果不存在则为首次发现该核素
判断核素是否存在的条件: 该核素的Conc值是否大于MDC值
@ -293,11 +323,12 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
throw new RuntimeException("detectorId is null or empty");
}
Set<String> nuclideNames = nuclidesCross.keySet();
List<String> list = analysisResultService.nuclideFirst(betaOrGamma, dataSourceType, stationId,
detectorId, sampleId, nuclideNames);
if(CollUtil.isNotEmpty(list)){
List<String> list =
analysisResultService.nuclideFirst(betaOrGamma, dataSourceType, stationId,
detectorId, sampleId, nuclideNames);
if (CollUtil.isNotEmpty(list)) {
for (Map.Entry<String, String> f : nuclidesCross.entrySet()) {
if(list.contains(f.getKey())){
if (list.contains(f.getKey())) {
NuclideInfo nuclideInfo = new NuclideInfo();
nuclideInfo.setNuclide(f.getKey());
nuclideInfo.setDatasource(DSType.typeOf(dataSourceType));
@ -325,13 +356,15 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
String nuclideName = nuclide.getKey();
String concValue = nuclide.getValue();// 浓度值
String avgValue = nuclideAvgs.get(nuclideName);// 浓度均值
if (!NumberUtil.isNumber(concValue) || !NumberUtil.isNumber(avgValue))
if (!NumberUtil.isNumber(concValue) || !NumberUtil.isNumber(avgValue)) {
continue;
}
BigDecimal conc = new BigDecimal(concValue);
BigDecimal avg = new BigDecimal(avgValue);
// 如果核素浓度值小于均值,继续判断下一个核素
if (NumberUtil.isLessOrEqual(conc, avg))
if (NumberUtil.isLessOrEqual(conc, avg)) {
continue;
}
NuclideInfo nuclideInfo = new NuclideInfo();
nuclideInfo.setNuclide(nuclideName);
nuclideInfo.setThreshold(avg.toString());
@ -344,19 +377,21 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
}
/*
* 是否同时存在两种及以上核素
* */
* 是否同时存在两种及以上核素
* */
private List<NuclideInfo> meanWhile(String betaOrGamma, String dataSourceType,
String sampleId, Map<String,String> nuclidesCross){
String sampleId, Map<String, String> nuclidesCross) {
List<NuclideInfo> result = Lists.newArrayList();
/* 查询用户关注的核素中 该谱中是否存在两种及以上核素
判断核素是否存在的条件: 该核素的Conc值是否大于MDC值
*/
Set<String> nuclideNames = nuclidesCross.keySet();
List<String> list = analysisResultService.nuclideExist(betaOrGamma, dataSourceType, sampleId, nuclideNames);
if(CollUtil.isNotEmpty(list)){
List<String> list =
analysisResultService.nuclideExist(betaOrGamma, dataSourceType, sampleId,
nuclideNames);
if (CollUtil.isNotEmpty(list)) {
for (Map.Entry<String, String> f : nuclidesCross.entrySet()) {
if(list.contains(f.getKey())){
if (list.contains(f.getKey())) {
NuclideInfo nuclideInfo = new NuclideInfo();
nuclideInfo.setNuclide(f.getKey());
nuclideInfo.setDatasource(DSType.typeOf(dataSourceType));
@ -368,16 +403,18 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
}
return result;
}
/*
* 是否同时存在两种及以上核素
* */
private List<NuclideInfo> meanWhile(Map<String,String> nuclideMap, String dataSourceType, Set<String> nuclideNames){
* 是否同时存在两种及以上核素
* */
private List<NuclideInfo> meanWhile(Map<String, String> nuclideMap, String dataSourceType,
Set<String> nuclideNames) {
List<NuclideInfo> result = Lists.newArrayList();
/* 查询用户关注的核素中 该谱中是否存在两种及以上核素
判断核素是否存在的条件: 该核素的Conc值是否大于MDC值
*/
for (String name : nuclideNames) {
if(nuclideMap.containsKey(name)){
if (nuclideMap.containsKey(name)) {
NuclideInfo nuclideInfo = new NuclideInfo();
nuclideInfo.setNuclide(name);
nuclideInfo.setDatasource(DSType.typeOf(dataSourceType));
@ -401,7 +438,7 @@ public class AnalysisConsumer implements StreamListener<String, ObjectRecord<Str
redisUtil = SpringContextUtils.getBean(RedisUtil.class);
}
private void destroy(){
private void destroy() {
// end 删除临时Token
UserTokenContext.remove();
}

View File

@ -446,9 +446,7 @@ public class Sample_B_Analysis implements BlockConstant {
info.setIdAnalysis(this.analyses.getIdAnalysis().toString());
info.setSampleType(this.sampleData.getSampleType());
info.setSampleName(this.phdFileName);
final Instant instant = this.sampleData.getCollectStart().toInstant();
final LocalDateTime collectTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
info.setCollectionDate(collectTime);
info.setCollectionDate(this.sampleData.getCollectStart());
info.setCollectStop(this.sampleData.getCollectStop());
info.setDatasource(DSType.ARMDARR.getType());
info.setFullOrPrel(this.sampleData.getSpectralQualifie());

View File

@ -45,9 +45,6 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.ParseException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
@ -238,8 +235,7 @@ public class Sample_G_Analysis {
info.setSampleType(middleData.getSample_Type());
info.setIdAnalysis(middleData.getIdAnalysis());
info.setSampleName(middleData.analyses_save_filePath.substring(middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH) + 1));
final Instant instant = DateUtils.parseDate(middleData.sample_collection_start).toInstant();
final LocalDateTime collectTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
Date collectTime = DateUtils.parseDate(middleData.sample_collection_start);
info.setCollectionDate(collectTime);
info.setCollectStop(this.sampleData.getCollectStop());
info.setDatasource(DSType.ARMDARR.getType());

View File

@ -6,7 +6,7 @@ import org.jeecg.modules.entity.*;
import org.jeecg.modules.entity.vo.TableNuclideActivity;
import org.jeecg.modules.entity.vo.TablePeak;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Mapper
@ -16,8 +16,8 @@ public interface IDCDataMapper {
List<Integer> getGardsSampleData(@Param("siteDetCode") String siteDetCode,
@Param("stationId") Integer stationId,
@Param("spectralQualifier") String spectralQualifier,
@Param("collectStart") LocalDateTime collectStart,
@Param("acquisitionStop") LocalDateTime acquisitionStop);
@Param("collectStart") Date collectStart,
@Param("acquisitionStop") Date acquisitionStop);
List<TablePeak> getGardsPeaksSpectrum(@Param("sampleId") Integer sampleId);

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@ -20,13 +21,16 @@ import org.springframework.stereotype.Service;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import java.util.Date;
import java.util.stream.Collectors;
@Service
@Slf4j
@DS("ora")
public class DataServiceImpl implements IDataService {
// 日期格式常量
private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
@ -47,9 +51,9 @@ public class DataServiceImpl implements IDataService {
Integer sampleId = null;
List<TablePeak> peakInfoList = new LinkedList<>();
try {
// 字符串转 LocalDateTime
LocalDateTime collectStartDate = parseToLocalDateTime(collectStart);
LocalDateTime acquisitionStopDate = parseToLocalDateTime(acquisitionStop);
// 字符串转 Date
Date collectStartDate = parseToDateTime(collectStart);
Date acquisitionStopDate = parseToDateTime(acquisitionStop);
//根据探测器编码台站id采样开始时间采集结束时间 查询 sampleId
List<Integer> sampleIds =
@ -101,9 +105,9 @@ public class DataServiceImpl implements IDataService {
Integer sampleId = null;
List<TableNuclideActivity> nuclideActivityList = new LinkedList<>();
try {
// 字符串转 LocalDateTime
LocalDateTime collectStartDate = parseToLocalDateTime(collectStart);
LocalDateTime acquisitionStopDate = parseToLocalDateTime(acquisitionStop);
// 字符串转 Date
Date collectStartDate = parseToDateTime(collectStart);
Date acquisitionStopDate = parseToDateTime(acquisitionStop);
List<Integer> sampleIds =
idcDataMapper.getGardsSampleData(siteDetCode, stationId, spectralQualifier,
@ -159,9 +163,9 @@ public class DataServiceImpl implements IDataService {
List<GardsXeResultsView> xeResultsViewList = new LinkedList<>();
try {
//根据探测器编码台站id采样开始时间采集结束时间 查询 sampleId
// 字符串转 LocalDateTime
LocalDateTime collectStartDate = parseToLocalDateTime(collectStart);
LocalDateTime acquisitionStopDate = parseToLocalDateTime(acquisitionStop);
// 字符串转 DateTime
Date collectStartDate = parseToDateTime(collectStart);
Date acquisitionStopDate = parseToDateTime(acquisitionStop);
List<Integer> sampleIds =
idcDataMapper.getGardsSampleData(siteDetCode, stationId, spectralQualifier,
collectStartDate, acquisitionStopDate);
@ -225,12 +229,14 @@ public class DataServiceImpl implements IDataService {
}
/**
* 字符串转 LocalDateTime
* 字符串转 Date
*/
private LocalDateTime parseToLocalDateTime(String dateTimeStr) {
private Date parseToDateTime(String dateTimeStr) {
String normalizedStr = dateTimeStr.replace('/', '-');
try {
return LocalDateTime.parse(normalizedStr, DATE_TIME_FORMATTER);
LocalDateTime localDateTime= LocalDateTime.parse(normalizedStr, DATE_TIME_FORMATTER);
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
} catch (DateTimeParseException e) {
throw new IllegalArgumentException("日期时间格式解析错误: " + dateTimeStr, e);
}

View File

@ -803,17 +803,20 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
result.error500("The end time cannot be empty");
return result;
}
LocalDateTime startTime = startDate
.toInstant()
.atZone(ZoneId.systemDefault())
// 开始时间当天零点
LocalDateTime startLdt = startDate.toInstant()
.atZone(ZoneId.of("Asia/Shanghai")) // 北京时间
.toLocalDate()
.atStartOfDay();
Date startTime = Date.from(startLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
LocalDateTime endTime = endDate
.toInstant()
.atZone(ZoneId.systemDefault())
// 结束时间23:59:59.999
LocalDateTime endLdt = endDate.toInstant()
.atZone(ZoneId.of("Asia/Shanghai"))
.toLocalDate()
.atTime(LocalTime.MAX);
.atTime(LocalTime.of(23, 59, 59, 999_000_000));
Date endTime = Date.from(endLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
List<String> menuTypeList = Arrays.asList(menuTypes);
if (CollectionUtils.isEmpty(menuTypeList)) {
result.error500("The spectrum type cannot be empty");
@ -5395,14 +5398,10 @@ public class GammaServiceImpl extends AbstractLogOrReport implements IGammaServi
info.setSampleType(middleData.sample_Type);
info.setSampleName(middleData.analyses_save_filePath.substring(
middleData.analyses_save_filePath.lastIndexOf(StringPool.SLASH) + 1));
final Instant instant =
DateUtils.parseDate(middleData.sample_collection_start).toInstant();
final LocalDateTime collectTime =
instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
Date collectTime = DateUtils.parseDate(middleData.sample_collection_start);
info.setCollectionDate(collectTime);
final Instant instantStop =
DateUtils.parseDate(middleData.sample_collection_stop).toInstant();
info.setCollectStop(Date.from(instantStop));
Date collectStopTime = DateUtils.parseDate(middleData.sample_collection_stop);
info.setCollectStop(collectStopTime);
info.setDatasource(DSType.ARMDRRR.getType());
info.setFullOrPrel(phd.getHeader().getSpectrum_quantity());
info.setBetaOrGamma(SpectrumType.GAMMA.getType());

View File

@ -7,9 +7,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@ -57,11 +55,9 @@ import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
import javax.annotation.PostConstruct;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.*;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -285,17 +281,19 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
result.error500("The end time cannot be empty");
return result;
}
LocalDateTime startTime = startDate
.toInstant()
.atZone(ZoneId.systemDefault())
// 开始时间当天零点
LocalDateTime startLdt = startDate.toInstant()
.atZone(ZoneId.of("Asia/Shanghai")) // 北京时间
.toLocalDate()
.atStartOfDay();
Date startTime = Date.from(startLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
LocalDateTime endTime = endDate
.toInstant()
.atZone(ZoneId.systemDefault())
// 结束时间23:59:59.999
LocalDateTime endLdt = endDate.toInstant()
.atZone(ZoneId.of("Asia/Shanghai"))
.toLocalDate()
.atTime(LocalTime.MAX);
.atTime(LocalTime.of(23, 59, 59, 999_000_000));
Date endTime = Date.from(endLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
List<String> menuTypeList = Arrays.asList(menuTypes);
if (CollectionUtils.isEmpty(menuTypeList)) {
@ -524,13 +522,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
String qcFileName = "";
if (Objects.nonNull(dbSpectrumFilePath.getCollectStart()) &&
StringUtils.isNotBlank(dbSpectrumFilePath.getSiteDetCode())) {
LocalDateTime collectStart = dbSpectrumFilePath
.getCollectStart()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
String collectStartStr =
DateUtils.formatDate(dbSpectrumFilePath.getCollectStart(),
"yyyy/MM/dd HH:mm:ss");
dbQcFilePath = spectrumAnalysisMapper.getQCFilePath(
dbSpectrumFilePath.getSiteDetCode(), collectStart);
dbSpectrumFilePath.getSiteDetCode(),
collectStartStr);
if (StringUtils.isNotBlank(dbQcFilePath)) {
qc = spectrumAnalysisMapper.findSampleByFilePath(dbQcFilePath);
qcFileName = dbQcFilePath.substring(
@ -964,16 +961,13 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
detBgMap.put("fileName", betaDataFile.getDetFileName());
resultMap.put("detBg", detBgMap);
}
LocalDateTime collectStart = sampleData
.getCollectStart()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
// 查询Qc谱
String collectStartStr =
DateUtils.formatDate(sampleData.getCollectStart(),
"yyyy/MM/dd HH:mm:ss");
String qcFilePath =
spectrumAnalysisMapper.getQCFilePath(sampleData.getSiteDetCode(),
collectStart);
collectStartStr);
if (StringUtils.isNotBlank(qcFilePath)) {
GardsSampleData qcSampleData =
spectrumAnalysisMapper.findSampleByFilePath(qcFilePath);
@ -2878,8 +2872,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
spectrumAnalysisMapper.selectThresholdDataBySampleId(schemaName,
rrrLogInfo.getSampleId().toString());
//获取阈值历史信息
LocalDateTime startTime = LocalDateTime.now().minusYears(1);
LocalDateTime endTime = LocalDateTime.now();
Date startTime = Date.from(
LocalDateTime.now().minusYears(1).atZone(ZoneId.systemDefault())
.toInstant());
Date endTime =
Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
List<ThresholdResultHistory> thresholdHistoryValues =
spectrumAnalysisMapper.selectThresholdHistoryBySampleId(schemaName,
rrrLogInfo.getSampleId().toString(), startTime);
@ -4791,10 +4789,14 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
.toLocalDate()
.atStartOfDay();
Date startDate = Date.from(start.atZone(ZoneId.systemDefault()).toInstant());
LocalDateTime end = endTime.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDate()
.atTime(23, 59, 59);
Date endDate = Date.from(end.atZone(ZoneId.systemDefault()).toInstant());
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@ -4811,7 +4813,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
}
if (statisticsType.equals("Colloc_Time")) {
List<StatisticsData> statisticsData =
spectrumAnalysisMapper.statisticsQueryCollection(start, end,
spectrumAnalysisMapper.statisticsQueryCollection(startDate, endDate,
detectorIdList);
StcGraph stcGraph = new StcGraph();
stcGraph.setM_strGraphName("Colloction Time");
@ -4840,7 +4842,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
result.setResult(stcGraph);
} else if (statisticsType.equals("Acq_Time")) {
List<StatisticsData> statisticsData =
spectrumAnalysisMapper.statisticsQueryAcquisition(start, end,
spectrumAnalysisMapper.statisticsQueryAcquisition(startDate, endDate,
detectorIdList);
StcGraph stcGraph = new StcGraph();
@ -4872,7 +4874,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
result.setResult(stcGraph);
} else if (statisticsType.equals("Xe_volumn")) {
List<StatisticsData> statisticsData =
spectrumAnalysisMapper.statisticsQueryXeVolumn(start, end,
spectrumAnalysisMapper.statisticsQueryXeVolumn(startDate, endDate,
detectorIdList);
StcGraph stcGraph = new StcGraph();
stcGraph.setM_strGraphName("Xe Volumn");
@ -4890,7 +4892,7 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
result.setResult(stcGraph);
} else if (statisticsType.equals("Sample_Volumn")) {
List<StatisticsData> statisticsData =
spectrumAnalysisMapper.statisticsQuerySampleVolumn(start, end,
spectrumAnalysisMapper.statisticsQuerySampleVolumn(startDate, endDate,
detectorIdList);
StcGraph stcGraph = new StcGraph();
stcGraph.setM_strGraphName("Sample Volumn");
@ -6665,17 +6667,14 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
info.setSampleId(betaDataFile.getSampleId());
info.setSampleType(betaDataFile.getSampleStruct().system_type);
info.setSampleName(betaDataFile.getSampleFileName());
final Instant instant = DateUtils.parseDate(
Date collectTime = DateUtils.parseDate(
betaDataFile.getSampleStruct().collection_start_date + StringPool.SPACE +
betaDataFile.getSampleStruct().collection_start_time).toInstant();
final LocalDateTime collectTime =
instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
betaDataFile.getSampleStruct().collection_start_time);
info.setCollectionDate(collectTime);
final Instant instantStop = DateUtils.parseDate(
Date collectStopTime = DateUtils.parseDate(
betaDataFile.getSampleStruct().collection_stop_date + StringPool.SPACE +
betaDataFile.getSampleStruct().collection_stop_time).toInstant();
info.setCollectStop(Date.from(instantStop));
betaDataFile.getSampleStruct().collection_stop_time);
info.setCollectStop(collectStopTime);
info.setDatasource(DSType.ARMDRRR.getType());
info.setFullOrPrel(betaDataFile.getSampleStruct().spectrum_quantity);
info.setBetaOrGamma(SpectrumType.BETA.getType());
@ -8976,8 +8975,12 @@ public class SpectrumAnalysisServiceImpl extends AbstractLogOrReport
List<Map<String, Object>> thresholdValues =
spectrumAnalysisMapper.selectThresholdDataBySampleId(schemaName, sampleId);
//获取阈值历史信息
LocalDateTime startTime = LocalDateTime.now().minusYears(1);
LocalDateTime endTime = LocalDateTime.now();
Date startTime = Date.from(
LocalDateTime.now().minusYears(1).atZone(ZoneId.systemDefault())
.toInstant());
Date endTime =
Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant());
List<ThresholdResultHistory> thresholdHistoryValues =
spectrumAnalysisMapper.selectThresholdHistoryBySampleId(schemaName,
sampleId, startTime);

View File

@ -7,26 +7,33 @@ import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.entity.GardsSampleDataWeb;
import org.jeecg.modules.entity.vo.SpectrumFileRecord;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Mapper
public interface GardsSampleDataWebMapper extends BaseMapper<GardsSampleDataWeb> {
Page<GardsSampleDataWeb> findAutoPage(String startDate, String endDate, List<Integer> stationIdList, String qualifie, String sampleType, Page<GardsSampleDataWeb> page);
Page<GardsSampleDataWeb> findAutoPage(@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
List<Integer> stationIdList, String qualifie,
String sampleType, Page<GardsSampleDataWeb> page);
Page<GardsSampleDataWeb> findReviewedPage(String startDate, String endDate, List<Integer> stationIdList, String qualifie, Page<GardsSampleDataWeb> page);
Page<GardsSampleDataWeb> findParticulatePage(String dataType, String spectralQualifie, String startDate, String endDate, List<Integer> stationIdList, Page<GardsSampleDataWeb> page);
Page<GardsSampleDataWeb> findReviewedPage(@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
List<Integer> stationIdList, String qualifie,
Page<GardsSampleDataWeb> page);
Integer getAnalysisID(@Param(value = "sampleId") Integer sampleId);
SpectrumFileRecord getDBSpectrumFilePath(Integer sampleId, Integer analysisID);
String getQCFilePath(String siteDetCode, String collectStartStr);
String getQCFilePath(@Param("siteDetCode") String siteDetCode,
@Param("startTime") Date startTime);
Integer getSampleId(@Param(value = "filePathName") String filePathName);
List<Map<String, Object>> findNuclideStatistics(@Param(value = "stationId") String stationId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "nuclideSql") String nuclideSql);
List<Map<String, Object>> findNuclideStatistics(@Param(value = "stationId") String stationId,
@Param(value = "startTime") Date startTime,
@Param(value = "endTime") Date endTime,
@Param(value = "nuclideSql") String nuclideSql);
}

View File

@ -28,12 +28,12 @@
ORIGINAL.GARDS_SAMPLE_DATA sam
INNER JOIN RNAUTO.GARDS_ANALYSES ana on ana.SAMPLE_ID = sam.SAMPLE_ID
<where>
sam.COLLECT_START >= TO_DATE(#{startDate}, 'yyyy-mm-dd hh24:mi:ss')
and sam.COLLECT_STOP &lt;= TO_DATE(#{endDate}, 'yyyy-mm-dd hh24:mi:ss')
<if test="stationIdList.size==0 and stationIdList != null">
and sam.STATION_ID in ('')
sam.COLLECT_START >= #{startDate}
AND sam.COLLECT_STOP &lt;= #{endDate}
<if test="stationIdList != null and stationIdList.size == 0">
AND 1 = 0
</if>
<if test="stationIdList.size>0 and stationIdList != null">
<if test="stationIdList != null and stationIdList.size > 0">
and sam.STATION_ID in
<foreach collection="stationIdList" item="stationId" open="(" close=")" separator=",">
#{stationId}
@ -75,13 +75,13 @@
ORIGINAL.GARDS_SAMPLE_DATA sam
INNER JOIN RNMAN.GARDS_ANALYSES ana on ana.SAMPLE_ID = sam.SAMPLE_ID
<where>
sam.COLLECT_START >= TO_DATE(#{startDate}, 'yyyy-mm-dd hh24:mi:ss')
AND sam.COLLECT_STOP &lt;= TO_DATE(#{endDate}, 'yyyy-mm-dd hh24:mi:ss')
sam.COLLECT_START >= #{startDate}
AND sam.COLLECT_STOP &lt;= #{endDate}
AND ana.REPORT_PAHT IS NOT NULL
<if test="stationIdList.size ==0 and stationIdList != null">
and sam.STATION_ID in ('')
<if test="stationIdList != null and stationIdList.size == 0">
AND 1 = 0
</if>
<if test="stationIdList.size>0 and stationIdList != null">
<if test="stationIdList != null and stationIdList.size > 0">
and sam.STATION_ID in
<foreach collection="stationIdList" item="stationId" open="(" close=")" separator=",">
#{stationId}
@ -166,11 +166,11 @@
FROM ORIGINAL.GARDS_SAMPLE_DATA org_sample_data
<where>
org_sample_data.ACQUISITION_START=
(SELECT MAX(qc_samples.ACQUISITION_START) FROM ORIGINAL.GARDS_SAMPLE_DATA qc_samples WHERE qc_samples.SITE_DET_CODE= '${siteDetCode}'
(SELECT MAX(qc_samples.ACQUISITION_START) FROM ORIGINAL.GARDS_SAMPLE_DATA qc_samples WHERE qc_samples.SITE_DET_CODE= #{siteDetCode}
AND qc_samples.DATA_TYPE='Q'
AND qc_samples.SPECTRAL_QUALIFIE='FULL'
AND qc_samples.ACQUISITION_START &lt;= TO_DATE('${collectStartStr}', 'YYYY-MM-DD hh24:mi:ss'))
AND org_sample_data.SITE_DET_CODE= '${siteDetCode}'
AND qc_samples.ACQUISITION_START &lt;= #{startTime})
AND org_sample_data.SITE_DET_CODE= #{siteDetCode}
</where>
</select>

View File

@ -2,10 +2,7 @@ package org.jeecg.modules.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -14,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.ExportUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.entity.rnauto.GardsAnalyses;
@ -22,7 +18,6 @@ import org.jeecg.modules.entity.GardsSampleDataWeb;
import org.jeecg.modules.entity.dto.SampleDataDto;
import org.jeecg.modules.mapper.GardsAnalysesAutoMapper;
import org.jeecg.modules.mapper.GardsSampleDataWebMapper;
import org.jeecg.modules.mapper.GardsSampleDataWebPostgresMapper;
import org.jeecg.modules.service.IAutoService;
import org.jeecg.modules.service.IGardsSampleDataWebService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
@ -30,12 +25,12 @@ import org.jeecgframework.poi.excel.entity.ExportParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@ -49,23 +44,8 @@ public class AutoServiceImpl extends ServiceImpl<GardsAnalysesAutoMapper, GardsA
@Autowired
private GardsSampleDataWebMapper gardsSampleDataWebMapper;
@Autowired
private GardsSampleDataWebPostgresMapper gardsSampleDataWebPostgresMapper;
@Autowired
private RedisUtil redisUtil;
@Autowired
private DataSource dataSource;
private DbType databaseType;
@PostConstruct
public void initDbType() throws SQLException {
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
String databaseProductName =
ds.getDataSource("ora").getConnection().getMetaData().getDatabaseProductName();
databaseType = DbType.getDbType(databaseProductName);
}
@Override
public Result findAutoPage(QueryRequest queryRequest, Integer[] stationIds, String qualifie,
String sampleType, Date startTime, Date endTime) {
@ -76,12 +56,23 @@ public class AutoServiceImpl extends ServiceImpl<GardsAnalysesAutoMapper, GardsA
result.error500("The start time cannot be empty");
return result;
}
String startDate = DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00";
if (Objects.isNull(endTime)) {
result.error500("The end time cannot be empty");
return result;
}
String endDate = DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59";
// 开始时间当天零点
LocalDateTime startLdt = startTime.toInstant()
.atZone(ZoneId.of("Asia/Shanghai")) // 北京时间
.toLocalDate()
.atStartOfDay();
Date startDate = Date.from(startLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
// 结束时间23:59:59.999
LocalDateTime endLdt = endTime.toInstant()
.atZone(ZoneId.of("Asia/Shanghai"))
.toLocalDate()
.atTime(LocalTime.of(23, 59, 59, 999_000_000));
Date endDate = Date.from(endLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
List<Integer> stationIdList;
if (Objects.isNull(stationIds)) {
stationIdList = new LinkedList<>();
@ -91,16 +82,8 @@ public class AutoServiceImpl extends ServiceImpl<GardsAnalysesAutoMapper, GardsA
Page<GardsSampleDataWeb> page =
new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
Page<GardsSampleDataWeb> sampleDataPage =
new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
if (databaseType == DbType.POSTGRE_SQL) {
sampleDataPage =
gardsSampleDataWebPostgresMapper.findAutoPage(startDate, endDate, stationIdList,
qualifie, sampleType, page);
} else if (databaseType == DbType.ORACLE) {
sampleDataPage =
gardsSampleDataWebMapper.findAutoPage(startDate, endDate, stationIdList,
qualifie, sampleType, page);
}
gardsSampleDataWebMapper.findAutoPage(startDate, endDate, stationIdList,
qualifie, sampleType, page);
sampleDataPage.getRecords().forEach(item -> {
item.setSiteDetCode(StringUtils.trim(item.getSiteDetCode()));

View File

@ -13,7 +13,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.ExportUtil;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.base.entity.rnman.GardsAnalyses;
@ -21,7 +20,6 @@ import org.jeecg.modules.entity.GardsSampleDataWeb;
import org.jeecg.modules.entity.dto.SampleDataDto;
import org.jeecg.modules.mapper.GardsAnalysesManMapper;
import org.jeecg.modules.mapper.GardsSampleDataWebMapper;
import org.jeecg.modules.mapper.GardsSampleDataWebPostgresMapper;
import org.jeecg.modules.service.IGardsSampleDataWebService;
import org.jeecg.modules.service.IReviewedService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
@ -35,12 +33,16 @@ import javax.sql.DataSource;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;
import java.util.stream.Collectors;
@Service("reviewedService")
@DS("ora")
public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, GardsAnalyses> implements IReviewedService {
public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, GardsAnalyses>
implements IReviewedService {
@Autowired
private IGardsSampleDataWebService gardsSampleDataService;
@ -49,8 +51,6 @@ public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, Gar
@Autowired
private RedisUtil redisUtil;
@Autowired
private GardsSampleDataWebPostgresMapper postgresMapper;
@Autowired
private DataSource dataSource;
private DbType databaseType;
@ -65,31 +65,48 @@ public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, Gar
}
@Override
public Result findReviewedPage(QueryRequest queryRequest, Integer[] stationIds, String qualifie, Date startTime, Date endTime) {
public Result findReviewedPage(QueryRequest queryRequest, Integer[] stationIds, String qualifie,
Date startTime, Date endTime) {
Result result = new Result();
//获取redis中缓存的台站信息
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
if (Objects.isNull(startTime)){
Map<String, String> stationMap = (Map<String, String>) redisUtil.get("stationMap");
if (Objects.isNull(startTime)) {
result.error500("The start time cannot be empty");
return result;
}
String startDate = DateUtils.formatDate(startTime, "yyyy-MM-dd") + " 00:00:00";
if (Objects.isNull(endTime)){
if (Objects.isNull(endTime)) {
result.error500("The end time cannot be empty");
return result;
}
String endDate = DateUtils.formatDate(endTime, "yyyy-MM-dd") + " 23:59:59";
// 开始时间当天零点
LocalDateTime startLdt = startTime.toInstant()
.atZone(ZoneId.of("Asia/Shanghai")) // 北京时间
.toLocalDate()
.atStartOfDay();
Date startDate = Date.from(startLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
// 结束时间23:59:59.999
LocalDateTime endLdt = endTime.toInstant()
.atZone(ZoneId.of("Asia/Shanghai"))
.toLocalDate()
.atTime(LocalTime.of(23, 59, 59, 999_000_000));
Date endDate = Date.from(endLdt.atZone(ZoneId.of("Asia/Shanghai")).toInstant());
List<Integer> stationIdList;
if (Objects.isNull(stationIds)){
if (Objects.isNull(stationIds)) {
stationIdList = new LinkedList<>();
}else {
} else {
stationIdList = Arrays.asList(stationIds);
}
Page<GardsSampleDataWeb> page = new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
Page<GardsSampleDataWeb> sampleDataPage =databaseType==DbType.POSTGRE_SQL?postgresMapper.findReviewedPage(startDate, endDate, stationIdList, qualifie, page): gardsSampleDataWebMapper.findReviewedPage(startDate, endDate, stationIdList, qualifie, page);
sampleDataPage.getRecords().forEach(item->{
Page<GardsSampleDataWeb> page =
new Page<>(queryRequest.getPageNo(), queryRequest.getPageSize());
Page<GardsSampleDataWeb> sampleDataPage =
gardsSampleDataWebMapper.findReviewedPage(startDate, endDate, stationIdList,
qualifie, page);
sampleDataPage.getRecords().forEach(item -> {
item.setSiteDetCode(StringUtils.trim(item.getSiteDetCode()));
if (stationMap.containsKey(item.getStationId().toString()) && CollectionUtils.isNotEmpty(stationMap)){
if (stationMap.containsKey(item.getStationId().toString()) &&
CollectionUtils.isNotEmpty(stationMap)) {
String stationName = stationMap.get(item.getStationId().toString());
item.setStationName(stationName);
}
@ -102,7 +119,7 @@ public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, Gar
@Override
public GardsAnalyses getOne(Integer sampleId) {
LambdaQueryWrapper<GardsAnalyses> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAnalyses::getSampleId,sampleId);
wrapper.eq(GardsAnalyses::getSampleId, sampleId);
GardsAnalyses gardsAnalyses = getOne(wrapper);
return Optional.ofNullable(gardsAnalyses)
.orElse(new GardsAnalyses());
@ -121,7 +138,9 @@ public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, Gar
.stream()
.map(GardsAnalyses::getSampleId)
.collect(Collectors.toList());
if (CollUtil.isEmpty(sampleIds)) return;
if (CollUtil.isEmpty(sampleIds)) {
return;
}
// 查询全部样品基础数据
List<GardsSampleDataWeb> sampleData = gardsSampleDataService.listBySampleIds(stationIds,
@ -138,18 +157,20 @@ public class ReviewedServiceImpl extends ServiceImpl<GardsAnalysesManMapper, Gar
OutputStream outputStream = null;
try {
// 设置文件名Excel类型(xls|xlsx)
outputStream = ExportUtil.xls(response,"RRR.xls");
outputStream = ExportUtil.xls(response, "RRR.xls");
workbook = ExcelExportUtil.
exportExcel(params, SampleDataDto.class, sampleDataDtos);
workbook.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}finally {
} finally {
try {
if (ObjectUtil.isNotNull(outputStream))
if (ObjectUtil.isNotNull(outputStream)) {
outputStream.close();
if (ObjectUtil.isNotNull(workbook))
}
if (ObjectUtil.isNotNull(workbook)) {
workbook.close();
}
} catch (IOException e) {
e.printStackTrace();
}