ParkingLotUseStatisticServiceImpl.java 11.1 KB
package com.zteits.park.biz;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;
import com.xiaoleilu.hutool.date.DateField;
import com.xiaoleilu.hutool.date.DateTime;
import com.xiaoleilu.hutool.util.CollectionUtil;
import com.zteits.clouds.api.apibase.bean.BizResult;
import com.zteits.clouds.api.apibase.bean.PageBean;
import com.zteits.clouds.api.apibase.constants.ErrorType;
import com.zteits.clouds.api.apibase.exception.BizException;
import com.zteits.clouds.api.dto.clouds.dto.TurnoverRatioDTO;
import com.zteits.clouds.api.dto.park.dto.MonthVehicleFlowAndVacancyRateAndTurnoverDTO;
import com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticDTO;
import com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticMaxAndMinDTO;
import com.zteits.clouds.api.dto.park.dto.ParkingLotUseStatisticSumDTO;
import com.zteits.clouds.api.dto.park.dto.TodayVehicleFlowOccupyRateAndTurnOverDTO;
import com.zteits.clouds.api.dto.park.param.CommonPlnosQueryRequest;
import com.zteits.clouds.api.dto.park.param.ParkingLotUseStatisticForPageRequest;
import com.zteits.clouds.api.service.park.ParkingLotUseStatisticService;
import com.zteits.park.constant.ParkConstant.ParkingLotUseStatistic.StatisticType;
import com.zteits.park.dao.ParkingLotDao;
import com.zteits.park.dao.ParkingLotUseStatisticDao;
import com.zteits.park.domain.ParkingLotUseStatistic;
import com.zteits.park.domain.ParkingLotUseStatisticMaxAndMin;
import com.zteits.park.domain.ParkingLotUseStatisticSum;
import com.zteits.park.pagepager.PageBeanUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.zteits.park.biz.ParkingLotUseStatisticServiceImpl")
public class ParkingLotUseStatisticServiceImpl implements ParkingLotUseStatisticService {
    @Autowired
    private ParkingLotUseStatisticDao parkingLotUseStatisticDao;
    @Autowired
    private ParkingLotDao parkingLotDao;

    @Override
    public BizResult<PageBean<ParkingLotUseStatisticDTO>> queryParkingLotUseStatisticForPage(
        ParkingLotUseStatisticForPageRequest request) {
        if (request.getBaseRequest() == null) {
            throw new BizException(ErrorType.PARAMM_NULL, "分页参数为空");
        }
        PageInfo<ParkingLotUseStatistic> pageInfo = parkingLotUseStatisticDao.queryParkingLotUseStatisticForPage(
            request.getBeginTime(), request.getEndTime(), request.getQueryKind(), request.getPlNos(),
            request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize());
        PageBean<ParkingLotUseStatisticDTO> pageBean = new PageBean<ParkingLotUseStatisticDTO>();
        if (pageInfo != null) {
            PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotUseStatisticDTO.class);
        }
        return new BizResult<PageBean<ParkingLotUseStatisticDTO>>(pageBean);
    }

    @Override
    public BizResult<PageBean<ParkingLotUseStatisticDTO>> queryCarFlowByMonthForPage(
        ParkingLotUseStatisticForPageRequest request) {
        PageInfo<ParkingLotUseStatisticDTO> pageInfo = parkingLotUseStatisticDao.queryCarFlowByMonthForPage(request);
        PageBean<ParkingLotUseStatisticDTO> pageBean = new PageBean<>();
        if (pageInfo != null) {
            PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotUseStatisticDTO.class);
        }
        return new BizResult<>(pageBean);
    }

    @Override
    public BizResult<List<ParkingLotUseStatisticDTO>> queryCarFlowChartByDay(
        ParkingLotUseStatisticForPageRequest request) {

        List<ParkingLotUseStatisticDTO> list = parkingLotUseStatisticDao.queryCarFlowChartByDay(request);
        return new BizResult<>(list);
    }

    @Override
    public BizResult<List<ParkingLotUseStatisticDTO>> queryCarFlowChartByMonth(
        ParkingLotUseStatisticForPageRequest request) {


        List<ParkingLotUseStatisticDTO> list = parkingLotUseStatisticDao.queryCarFlowChartByMonth(request);
        return new BizResult<>(list);
    }

    @Override
    public BizResult<ParkingLotUseStatisticMaxAndMinDTO> QueryVehicleFlowStatisticMaxAndMin(
        ParkingLotUseStatisticForPageRequest request) {
        ParkingLotUseStatisticMaxAndMin parkingLotUseStatisticMaxAndMin = parkingLotUseStatisticDao
            .QueryVehicleFlowStatisticMaxAndMin(request.getBeginTime(), request.getEndTime(),
                request.getQueryKind(), request.getPlNos());

        ParkingLotUseStatisticMaxAndMinDTO dto = new ParkingLotUseStatisticMaxAndMinDTO();
        if (null != parkingLotUseStatisticMaxAndMin) {
            BeanUtils.copyProperties(parkingLotUseStatisticMaxAndMin, dto);
        }
        return new BizResult<ParkingLotUseStatisticMaxAndMinDTO>(dto);
    }

    @Override
    public BizResult<ParkingLotUseStatisticMaxAndMinDTO> QueryBerthUseStatisticMaxAndMin(
        ParkingLotUseStatisticForPageRequest request) {
        ParkingLotUseStatisticMaxAndMin parkingLotUseStatisticMaxAndMin = parkingLotUseStatisticDao
            .QueryBerthUseStatisticMaxAndMin(request.getBeginTime(), request.getEndTime(), request.getQueryKind(),
                request.getPlNos());
        ParkingLotUseStatisticMaxAndMinDTO dto = new ParkingLotUseStatisticMaxAndMinDTO();
        if (null != parkingLotUseStatisticMaxAndMin) {
            BeanUtils.copyProperties(parkingLotUseStatisticMaxAndMin, dto);
        }
        return new BizResult<ParkingLotUseStatisticMaxAndMinDTO>(dto);
    }

    @Override
    public BizResult<ParkingLotUseStatisticSumDTO> QueryInOutParkStatisticSum(
        ParkingLotUseStatisticForPageRequest request) {
        ParkingLotUseStatisticSum parkingLotUseStatisticSum = parkingLotUseStatisticDao.QueryInOutParkStatisticSum(
            request.getBeginTime(), request.getEndTime(), request.getQueryKind(), request.getPlNos());
        ParkingLotUseStatisticSumDTO dto = new ParkingLotUseStatisticSumDTO();
        if (null != parkingLotUseStatisticSum) {
            BeanUtils.copyProperties(parkingLotUseStatisticSum, dto);
        }
        return new BizResult<ParkingLotUseStatisticSumDTO>(dto);
    }

    @Override
    public BizResult<List<TodayVehicleFlowOccupyRateAndTurnOverDTO>> queryTodayVehicleFlowOccupyRateAndTurnOver(
        CommonPlnosQueryRequest request) {
        DateTime beginTime = new DateTime().setField(DateField.HOUR_OF_DAY, 0).setField(DateField.MINUTE, 0)
            .setField(DateField.SECOND, 0);
        DateTime endTime = new DateTime().setField(DateField.HOUR_OF_DAY, 23).setField(DateField.MINUTE, 59)
            .setField(DateField.SECOND, 59);

        List<TodayVehicleFlowOccupyRateAndTurnOverDTO> result = parkingLotUseStatisticDao
            .queryTodayVehicleFlowOccupyRateAndTurnOver(beginTime, endTime, StatisticType.PER1HOUR,
                request.getPlNos());
        result = fixTodayVehicleFlowOccupyRateAndTurnOverData(result);
        return new BizResult<>(result);
    }

    private List<TodayVehicleFlowOccupyRateAndTurnOverDTO> fixTodayVehicleFlowOccupyRateAndTurnOverData(
        List<TodayVehicleFlowOccupyRateAndTurnOverDTO> datas) {
        List<TodayVehicleFlowOccupyRateAndTurnOverDTO> realDatas = new ArrayList<>();
        Map<Integer, TodayVehicleFlowOccupyRateAndTurnOverDTO> dataMap
            = initTodayVehicleFlowOccupyRateAndTurnOverDTOToMap(
            datas);
        for (int i = 0; i <= 23; i++) {
            TodayVehicleFlowOccupyRateAndTurnOverDTO realDTO = null;

            if (dataMap.containsKey(i)) {
                realDTO = dataMap.get(i);
            } else {
                realDTO = new TodayVehicleFlowOccupyRateAndTurnOverDTO();
                realDTO.setHour(i);
                realDTO.setAvgOccupyRate(0.0);
                realDTO.setAvgTurnoverRate(0.0);
                realDTO.setInCount(0);
                realDTO.setOutCount(0);
            }
            realDatas.add(realDTO);
        }
        return realDatas;
    }

    private Map<Integer, TodayVehicleFlowOccupyRateAndTurnOverDTO> initTodayVehicleFlowOccupyRateAndTurnOverDTOToMap(
        List<TodayVehicleFlowOccupyRateAndTurnOverDTO> datas) {
        Map<Integer, TodayVehicleFlowOccupyRateAndTurnOverDTO> map = new HashMap<>();
        for (TodayVehicleFlowOccupyRateAndTurnOverDTO dto : datas) {
            map.put(dto.getHour(), dto);
        }
        return map;
    }

    @Override
    public BizResult<PageBean<MonthVehicleFlowAndVacancyRateAndTurnoverDTO>>
    queryMonthVehicleFlowAndVacancyRateAndTurnover(
        ParkingLotUseStatisticForPageRequest request) {
        if (request == null) {
            throw new BizException(ErrorType.PARAMM_NULL, "参数为空");
        }
        PageInfo<MonthVehicleFlowAndVacancyRateAndTurnoverDTO> pageInfo = parkingLotUseStatisticDao
            .queryMonthVehicleFlowAndVacancyRateAndTurnover(request.getBeginTime(), request.getEndTime(),
                request.getPlNos(), request.getBaseRequest().getPageNum(),
                request.getBaseRequest().getPageSize());
        PageBean<MonthVehicleFlowAndVacancyRateAndTurnoverDTO> pageBean
            = new PageBean<MonthVehicleFlowAndVacancyRateAndTurnoverDTO>();
        if (pageInfo != null) {
            PageBeanUtil.copyProperties(pageInfo, pageBean, MonthVehicleFlowAndVacancyRateAndTurnoverDTO.class);
        }
        return new BizResult<PageBean<MonthVehicleFlowAndVacancyRateAndTurnoverDTO>>(pageBean);
    }

    @Override
    public BizResult<PageBean<TurnoverRatioDTO>> queryTurnoverRatioNew(ParkingLotUseStatisticForPageRequest request) {
        if(null ==request.getBeginTime() ){
            throw new BizException(ErrorType.PARAMM_NULL, "开始时间参数为空");
        }
        if(null ==request.getEndTime() ){
            throw new BizException(ErrorType.PARAMM_NULL, "结束时间参数为空");
        }
        if(CollectionUtil.isEmpty(request.getPlNos())){
            throw new BizException(ErrorType.PARAMM_NULL, "停车场编号参数为空");
        }
        PageBean<TurnoverRatioDTO> pageBean=new PageBean<>();
        PageInfo<TurnoverRatioDTO> pageInfo = parkingLotUseStatisticDao.queryTurnoverRatioNew(request);
        if (pageInfo != null) {
            PageBeanUtil.copyProperties(pageInfo, pageBean, TurnoverRatioDTO.class);
        }
        return new BizResult<>(pageBean);
    }

    @Override
    public BizResult<PageBean<TurnoverRatioDTO>> queryTurnoverRatioNewForChart(ParkingLotUseStatisticForPageRequest request) {
        if(null ==request.getBeginTime() ){
            throw new BizException(ErrorType.PARAMM_NULL, "开始时间参数为空");
        }
        if(null ==request.getEndTime() ){
            throw new BizException(ErrorType.PARAMM_NULL, "结束时间参数为空");
        }
        if(CollectionUtil.isEmpty(request.getPlNos())){
            throw new BizException(ErrorType.PARAMM_NULL, "停车场编号参数为空");
        }
        PageBean<TurnoverRatioDTO> pageBean=new PageBean<>();
        PageInfo<TurnoverRatioDTO> pageInfo = parkingLotUseStatisticDao.queryTurnoverRatioNewForChart(request);
        if (pageInfo == null) {
            return new BizResult<>(pageBean);
        }
        PageBeanUtil.copyProperties(pageInfo, pageBean, TurnoverRatioDTO.class);
        return new BizResult<>(pageBean);
    }

}