JudgmentService.java 7.53 KB
package cn.com.glsx.admin.modules.service;

import cn.com.glsx.admin.common.enums.TypeConverseEunm;
import cn.com.glsx.admin.modules.mapper.VehicleMapper;
import cn.com.glsx.admin.modules.model.export.JudgmentExport;
import cn.com.glsx.admin.modules.model.param.JudgmentSearch;
import cn.com.glsx.admin.modules.remote.RemoteStuJudgeAlarmService;
import cn.com.glsx.alarm.services.model.StuJudgeAlarmDto;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.glsx.plat.common.utils.StringUtils;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 大数据研判 service
 *
 * @author yll
 */
@Slf4j
@Service
public class JudgmentService extends AbstractCommonService {

    @Autowired
    private RemoteStuJudgeAlarmService remoteStuJudgeAlarmService;

    @Autowired
    private VehicleMapper vehicleMapper;

    /**
     * 查询大数据研判数据列表
     *
     * @param search
     * @return
     */
    public PageInfo findJudgmentList(JudgmentSearch search) {
        setOrgCheckedAuth(search);

        List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search);
        if (CollectionUtil.isEmpty(judgmentList)) {
            return new PageInfo<>();
        }
        log.info("查询大数据研判数据列表的条数" + judgmentList.size());
        List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList());
        PageInfo stuJudgeAlarmListByPage = remoteStuJudgeAlarmService.searchStuJudgeAlarmListByPage(snList, search);
        List<StuJudgeAlarmDto> stuJudgeAlarmList = JSON.parseArray(JSON.toJSONString(stuJudgeAlarmListByPage.getList()), StuJudgeAlarmDto.class);
        if (CollectionUtil.isEmpty(stuJudgeAlarmList)) {
            return new PageInfo<>();
        }

        Map<String, JudgmentExport> judgmentExportMap = judgmentList.stream().filter(judExport -> StringUtils.isNotBlank(judExport.getSn())).collect(Collectors.toMap(JudgmentExport::getSn, Function.identity(), (v1, v2) -> v1));
        List<JudgmentExport> judgmentExportList = Lists.newArrayList();
        stuJudgeAlarmList.forEach(stuJudgeAlarm -> {
            if (StringUtils.isBlank(stuJudgeAlarm.getSn())) {
                return;
            }
            JudgmentExport judgmentExportTemp = judgmentExportMap.get(stuJudgeAlarm.getSn());
            if (judgmentExportTemp != null) {
                JudgmentExport judgmentExport = new JudgmentExport();
                BeanUtils.copyProperties(judgmentExportTemp, judgmentExport);
                judgmentExport.setSourceStr(TypeConverseEunm.SourceEnum.getStrBySourceType(judgmentExport.getSource()));
                judgmentExport.setAlarmType(stuJudgeAlarm.getAlarmType());
                judgmentExport.setAlarmTypeStr(TypeConverseEunm.AlarmTypeEnum.getStrByAlarmType(stuJudgeAlarm.getAlarmType()));
                judgmentExport.setAlarmStatus(stuJudgeAlarm.getAlarmStatus());
                judgmentExport.setAlarmStatusStr(TypeConverseEunm.AlarmStatusEnum.getStrByAlarmStatus(stuJudgeAlarm.getAlarmStatus()));
                judgmentExport.setGeoCode(stuJudgeAlarm.getGeoCode());
                judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
                judgmentExport.setAlarmBeginTime(stuJudgeAlarm.getAlarmBeginTime());
                judgmentExport.setAlarmEndTime(stuJudgeAlarm.getAlarmEndTime());
                if (TypeConverseEunm.AlarmStatusEnum.TAKE_EFFECT.getAlarmStatus().equals(stuJudgeAlarm.getAlarmStatus())) {
                    // 如果警情为生效警情 则将失效时间设备为 --
                    judgmentExport.setAlarmEndTime("--");
                }
                judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng());
                judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat());
                judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
                judgmentExport.setAlarmCount(stuJudgeAlarm.getAlarmCount());
                judgmentExport.setAlarmLevel(stuJudgeAlarm.getAlarmLevel());
                judgmentExportList.add(judgmentExport);
            }
        });
        stuJudgeAlarmListByPage.setList(judgmentExportList);
        return stuJudgeAlarmListByPage;
    }

    public List<JudgmentExport> exportJudgmentList(JudgmentSearch search) {
        setOrgCheckedAuth(search);

        List<JudgmentExport> judgmentList = vehicleMapper.findJudgmentList(search);
        if (ObjectUtil.isNull(judgmentList)) {
            return null;
        }
        log.info("查询大数据研判数据列表的条数" + judgmentList.size());
        List<String> snList = judgmentList.stream().map(JudgmentExport::getSn).collect(Collectors.toList());
        List<StuJudgeAlarmDto> stuJudgeAlarmDtoList = remoteStuJudgeAlarmService.searchStuJudgeAlarmDataList(snList, search);
        if (CollectionUtil.isEmpty(stuJudgeAlarmDtoList)) {
            return null;
        }

        Map<String, JudgmentExport> judgmentExportMap = judgmentList.stream().filter(judgement -> StringUtils.isNotBlank(judgement.getSn())).collect(Collectors.toMap(JudgmentExport::getSn, Function.identity(), (v1, v2) -> v1));
        List<JudgmentExport> judgmentExportList = Lists.newArrayList();
        stuJudgeAlarmDtoList.forEach(stuJudgeAlarm -> {
            if (StringUtils.isBlank(stuJudgeAlarm.getSn())) {
                return;
            }

            JudgmentExport judgmentExportTemp = judgmentExportMap.get(stuJudgeAlarm.getSn());
            if (judgmentExportTemp != null) {
                JudgmentExport judgmentExport = new JudgmentExport();
                BeanUtils.copyProperties(judgmentExportTemp, judgmentExport);
                judgmentExport.setSourceStr(TypeConverseEunm.SourceEnum.getStrBySourceType(judgmentExport.getSource()));
                judgmentExport.setAlarmType(stuJudgeAlarm.getAlarmType());
                judgmentExport.setAlarmTypeStr(TypeConverseEunm.AlarmTypeEnum.getStrByAlarmType(stuJudgeAlarm.getAlarmType()));
                judgmentExport.setAlarmStatus(stuJudgeAlarm.getAlarmStatus());
                judgmentExport.setAlarmStatusStr(TypeConverseEunm.AlarmStatusEnum.getStrByAlarmStatus(stuJudgeAlarm.getAlarmStatus()));
                judgmentExport.setGeoCode(stuJudgeAlarm.getGeoCode());
                judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
                judgmentExport.setAlarmBeginTime(stuJudgeAlarm.getAlarmBeginTime());
                judgmentExport.setAlarmEndTime(stuJudgeAlarm.getAlarmEndTime());
                if (TypeConverseEunm.AlarmStatusEnum.TAKE_EFFECT.getAlarmStatus().equals(stuJudgeAlarm.getAlarmStatus())) {
                    // 如果警情为生效警情 则将失效时间设备为 --
                    judgmentExport.setAlarmEndTime("--");
                }
                judgmentExport.setAlarmLng(stuJudgeAlarm.getAlarmLng());
                judgmentExport.setAlarmLat(stuJudgeAlarm.getAlarmLat());
                judgmentExport.setAlarmAddress(stuJudgeAlarm.getAlarmAddress());
                judgmentExport.setAlarmCount(stuJudgeAlarm.getAlarmCount());
                judgmentExport.setAlarmLevel(stuJudgeAlarm.getAlarmLevel());
                judgmentExportList.add(judgmentExport);
            }
        });
        return judgmentExportList;
    }
}