fix:Analysis log搜索

This commit is contained in:
nieziyan 2023-12-08 18:17:35 +08:00
parent ebf432cf9c
commit ecac7a9240
8 changed files with 92 additions and 61 deletions

View File

@ -8,17 +8,22 @@ import java.util.List;
@Data @Data
public class AnalysisLogDto extends AlarmAnalysisLog { public class AnalysisLogDto extends AlarmAnalysisLog {
private String name; private String stationCode;
private String source; private List<NuclideInfo> nuclideList;
/* 以下属性作废 */
// TODO del
private String name; // 规则名称
private String source; // 当前规则关注的数据源(逗号分隔)
private List<String> sourceList; private List<String> sourceList;
private String stations; private String stations; // 当前规则关注的台站(逗号分隔)
private List<String> stationList; private List<String> stationList;
private String nuclides; private String nuclides; // 当前规则关注的核素(逗号分隔)
private List<NuclideInfo> nuclideList;
} }

View File

@ -35,4 +35,6 @@ public interface SystemClient {
@GetMapping("/gardsStations/getCodesMap") @GetMapping("/gardsStations/getCodesMap")
Map<String,String> stationCodesMap(@RequestParam Collection<String> stationIds); Map<String,String> stationCodesMap(@RequestParam Collection<String> stationIds);
@GetMapping("/gardsStations/stationCodesMap")
Map<String,String> stationCodesMap();
} }

View File

@ -1,7 +1,9 @@
package org.jeecg.modules.mapper; package org.jeecg.modules.mapper;
import java.util.List; import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@ -10,6 +12,5 @@ import org.jeecg.modules.base.entity.postgre.AlarmAnalysisLog;
@Mapper @Mapper
public interface AlarmAnalysisLogMapper extends BaseMapper<AlarmAnalysisLog> { public interface AlarmAnalysisLogMapper extends BaseMapper<AlarmAnalysisLog> {
Page<AnalysisLogDto> findPage(Page<AnalysisLogDto> page, Map<String, Object> params);
List<AnalysisLogDto> findPage(String startDate,String endDate);
} }

View File

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.jeecg.modules.mapper.AlarmAnalysisLogMapper"> <mapper namespace="org.jeecg.modules.mapper.AlarmAnalysisLogMapper">
<select id="findPage" resultType="org.jeecg.modules.base.dto.AnalysisLogDto"> <!--<select id="findPage" resultType="org.jeecg.modules.base.dto.AnalysisLogDto">
SELECT SELECT
l.*, l.*,
r.name, r.name,
@ -21,5 +21,32 @@
</if> </if>
</where> </where>
ORDER BY l.alarm_start_date DESC ORDER BY l.alarm_start_date DESC
</select>-->
<select id="findPage" resultType="org.jeecg.modules.base.dto.AnalysisLogDto">
SELECT
*
FROM
alarm_analysis_log
<where>
<if test="params.source != null and params.source.size() > 0">
datasource IN
<foreach collection="params.source" index="index" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="params.stations != null and params.stations.size() > 0">
AND station_id IN
<foreach collection="params.stations" index="index" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="params.startDate != null and params.startDate != ''">
AND alarm_start_date &gt;= #{params.startDate}
</if>
<if test="params.endDate != null and params.endDate != ''">
AND alarm_start_date &lt;= #{params.endDate}
</if>
</where>
ORDER BY alarm_start_date DESC
</select> </select>
</mapper> </mapper>

View File

@ -1,5 +1,6 @@
package org.jeecg.modules.service.impl; package org.jeecg.modules.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -8,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.DateConstant; import org.jeecg.common.constant.DateConstant;
@ -34,6 +36,7 @@ import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j
public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMapper, AlarmAnalysisLog> implements IAlarmAnalysisLogService { public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMapper, AlarmAnalysisLog> implements IAlarmAnalysisLogService {
@Autowired @Autowired
@ -44,72 +47,44 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
String startDate = analysisLogVo.getStartDate(); String startDate = analysisLogVo.getStartDate();
String endDate = analysisLogVo.getEndDate(); String endDate = analysisLogVo.getEndDate();
if (StrUtil.isNotBlank(startDate)) if (StrUtil.isNotBlank(startDate))
startDate += DateConstant.TIME_START; analysisLogVo.setStartDate(startDate + DateConstant.TIME_START);
if (StrUtil.isNotBlank(endDate)) if (StrUtil.isNotBlank(endDate))
endDate += DateConstant.TIME_END; analysisLogVo.setEndDate(endDate + DateConstant.TIME_END);
List<AnalysisLogDto> result = baseMapper.findPage(startDate, endDate); Map<String, Object> params = BeanUtil.beanToMap(analysisLogVo);
List<String> source = analysisLogVo.getSource(); Integer pageNo = analysisLogVo.getPageNo();
List<String> stations = analysisLogVo.getStations(); Integer pageSize = analysisLogVo.getPageSize();
List<String> nuclides = analysisLogVo.getNuclides(); Page<AnalysisLogDto> page = new Page<>(pageNo, pageSize);
String comma = SymbolConstant.COMMA; page = baseMapper.findPage(page, params);
// 条件过滤 List<AnalysisLogDto> records = page.getRecords();
if (CollUtil.isNotEmpty(source)){
result = result.stream().filter(item -> {
List<String> sourceIds = ListUtil
.toList(item.getSource().split(comma));
return CollUtil.containsAny(sourceIds,source);
}).collect(Collectors.toList());
}
if (CollUtil.isNotEmpty(stations)){
result = result.stream().filter(item -> {
List<String> stationIds = ListUtil
.toList(item.getStations().split(comma));
return CollUtil.containsAny(stationIds,stations);
}).collect(Collectors.toList());
}
if (CollUtil.isNotEmpty(nuclides)){
result = result.stream().filter(item -> {
List<String> nuclideList = ListUtil
.toList(item.getNuclides().split(comma));
return CollUtil.containsAny(nuclideList,nuclides);
}).collect(Collectors.toList());
}
// 数据字典 // 数据字典
List<DictModel> sourceDict = systemClient.getItems(DictConstant.ANALYSE_SOURCE); List<DictModel> sourceDict = systemClient.getItems(DictConstant.ANALYSE_SOURCE);
// 封装Source和Station Map<String, String> sourceMap = sourceDict.stream().collect(Collectors
for (AnalysisLogDto logDto : result) { .toMap(DictModel::getValue, DictModel::getText));
Map<String, String> stationCodesMap = systemClient.stationCodesMap();
for (AnalysisLogDto logDto : records) {
// 数据源 // 数据源
String sources = logDto.getSource(); String datasource = logDto.getDatasource();
List<String> sourceList = getShow(sourceDict, sources); logDto.setDatasource(sourceMap.getOrDefault(datasource, "--"));
logDto.setSourceList(sourceList); // TODO del
logDto.setSourceList(ListUtil.toList(sourceMap.getOrDefault(datasource, "--")));
// 台站 // 台站
String stationIds = logDto.getStations(); String stationId = logDto.getStationId();
if (StrUtil.isNotBlank(stationIds)){ logDto.setStationCode(stationCodesMap.getOrDefault(stationId, "--"));
List<String> stationList = systemClient.stationCodes(stationIds); // TODO del
logDto.setStationList(stationList); logDto.setStationList(ListUtil.toList(stationCodesMap.getOrDefault(stationId, "--")));
}
// 将nuclide的json串转换为对象集合 // 将nuclide的json串转换为对象集合
String nuclideInfo = logDto.getNuclideInfo(); String nuclideInfo = logDto.getNuclideInfo();
if (StrUtil.isNotBlank(nuclideInfo)){ if (StrUtil.isNotBlank(nuclideInfo)){
try { try {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
List<NuclideInfo> nuclideInfos = mapper.readValue(nuclideInfo, List<NuclideInfo> nuclideInfos = mapper.readValue(nuclideInfo, new TypeReference<List<NuclideInfo>>() {});
new TypeReference<List<NuclideInfo>>() {
});
logDto.setNuclideList(nuclideInfos); logDto.setNuclideList(nuclideInfos);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); log.error("nuclideInfo解析异常: {}", e.getMessage());
} }
} }
} }
// 封装分页
Integer pageNo = analysisLogVo.getPageNo();
Integer pageSize = analysisLogVo.getPageSize();
int total = result.size();
List<AnalysisLogDto> records = PageUtil.page(pageNo, pageSize, result);
Page<AnalysisLogDto> page = new Page<>(pageNo,pageSize,total);
page.setRecords(records); page.setRecords(records);
return Result.OK(page); return Result.OK(page);
} }
@ -251,7 +226,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
return result; return result;
} }
private List<String> getShow(List<DictModel> dictModels,String dict){ /*private List<String> getShow(List<DictModel> dictModels,String dict){
List<String> show = new ArrayList<>(); List<String> show = new ArrayList<>();
if (StrUtil.isBlank(dict)) if (StrUtil.isBlank(dict))
return null; return null;
@ -262,7 +237,7 @@ public class AlarmAnalysisLogServiceImpl extends ServiceImpl<AlarmAnalysisLogMap
show.add(dictMap.get(key)); show.add(dictMap.get(key));
} }
return show; return show;
} }*/
private List<AlarmAnalysisLog> getLogs(String startDate,String endDate){ private List<AlarmAnalysisLog> getLogs(String startDate,String endDate){
startDate += DateConstant.TIME_START; startDate += DateConstant.TIME_START;

View File

@ -106,4 +106,10 @@ public class GardsStationsController {
public Map<String,String> getCodesMap(@RequestParam Collection<String> stationIds){ public Map<String,String> getCodesMap(@RequestParam Collection<String> stationIds){
return gardsStationsService.getCodeMap(stationIds); return gardsStationsService.getCodeMap(stationIds);
} }
@GetMapping("stationCodesMap")
@ApiOperation(value = "获取台站CodeMap", notes = "获取台站CodeMap")
public Map<String,String> getCodesMap(){
return gardsStationsService.getCodeMap();
}
} }

View File

@ -66,4 +66,6 @@ public interface IGardsStationsService extends IService<GardsStations> {
List<String> getCodeByIds(String stationIds); List<String> getCodeByIds(String stationIds);
Map<String,String> getCodeMap(Collection<String> stationIds); Map<String,String> getCodeMap(Collection<String> stationIds);
Map<String,String> getCodeMap();
} }

View File

@ -230,4 +230,17 @@ public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, G
} }
return result; return result;
} }
@Override
public Map<String, String> getCodeMap() {
String key = RedisConstant.STATION_CODE_MAP;
if (redisUtil.hasKey(key))
return (Map<String, String>) redisUtil.get(key);
List<GardsStations> gardsStations = list();
Map<String, String> stationCodeMap = gardsStations.stream().collect(Collectors.toMap(
station -> String.valueOf(station.getStationId()),
GardsStations::getStationCode));
redisUtil.set(key, stationCodeMap);
return stationCodeMap;
}
} }