RiskAssessmentConvert.java 2.43 KB
package cn.com.glsx.admin.modules.converter;

import cn.com.glsx.admin.modules.entity.Vehicle;
import cn.com.glsx.admin.modules.model.vo.StayPointListVO;
import cn.com.glsx.admin.modules.utils.DateUtil;
import cn.com.glsx.devicemonitor.api.dto.request.ResidentRequest;
import cn.com.glsx.devicemonitor.api.dto.response.GpsLocation;
import cn.com.glsx.devicemonitor.api.dto.response.StayPointRecordDTO;

import java.util.Optional;

/**
 * 风险评估转换
 */
public class RiskAssessmentConvert {

    /**
     * 风险评估转换
     */
    public static StayPointListVO buildStayPointListVO(StayPointRecordDTO stayPointRecordDTO, Vehicle vehicle, String sn, String address) {
        StayPointListVO stayPointListVO = new StayPointListVO();
        stayPointListVO.setSn(sn);
        Optional.ofNullable(vehicle).map(Vehicle::getOwnerName).ifPresent(stayPointListVO::setOwnerName);
        Optional.ofNullable(vehicle).map(Vehicle::getVin).ifPresent(stayPointListVO::setVin);
        stayPointListVO.setBeginTime(stayPointRecordDTO.getBeginTime());
        stayPointListVO.setEndTime(stayPointRecordDTO.getEndTime());
        //时长
        Optional.ofNullable(stayPointRecordDTO.getDuration()).map(e -> e * 1000).map(Integer::longValue).map(DateUtil::normalFormatDuration).ifPresent(stayPointListVO::setDuration);
        stayPointListVO.setLocationType("GPS");
        Optional.of(stayPointRecordDTO).map(StayPointRecordDTO::getStayGps).map(GpsLocation::getElat).ifPresent(stayPointListVO::setElat);
        Optional.of(stayPointRecordDTO).map(StayPointRecordDTO::getStayGps).map(GpsLocation::getElng).ifPresent(stayPointListVO::setElng);
        Optional.of(stayPointRecordDTO).map(StayPointRecordDTO::getStayGps).map(GpsLocation::getBlat).ifPresent(stayPointListVO::setBlat);
        Optional.of(stayPointRecordDTO).map(StayPointRecordDTO::getStayGps).map(GpsLocation::getBlng).ifPresent(stayPointListVO::setBlng);
        stayPointListVO.setAddress(address);
        return stayPointListVO;
    }

    public static ResidentRequest buildResidentRequest(String sn, String beginTime, String endTime, Integer locInfoType) {
        ResidentRequest residentRequest = new ResidentRequest();
        residentRequest.setSn(sn);
        residentRequest.setBeginTime(beginTime);
        residentRequest.setEndTime(endTime);
        // 4 表示为截止目前
        residentRequest.setTimes(4);
        residentRequest.setLocInfoType(locInfoType);
        return residentRequest;
    }
}