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> queryParkingLotUseStatisticForPage( ParkingLotUseStatisticForPageRequest request) { if (request.getBaseRequest() == null) { throw new BizException(ErrorType.PARAMM_NULL, "分页参数为空"); } PageInfo pageInfo = parkingLotUseStatisticDao.queryParkingLotUseStatisticForPage( request.getBeginTime(), request.getEndTime(), request.getQueryKind(), request.getPlNos(), request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize()); PageBean pageBean = new PageBean(); if (pageInfo != null) { PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotUseStatisticDTO.class); } return new BizResult>(pageBean); } @Override public BizResult> queryCarFlowByMonthForPage( ParkingLotUseStatisticForPageRequest request) { PageInfo pageInfo = parkingLotUseStatisticDao.queryCarFlowByMonthForPage(request); PageBean pageBean = new PageBean<>(); if (pageInfo != null) { PageBeanUtil.copyProperties(pageInfo, pageBean, ParkingLotUseStatisticDTO.class); } return new BizResult<>(pageBean); } @Override public BizResult> queryCarFlowChartByDay( ParkingLotUseStatisticForPageRequest request) { List list = parkingLotUseStatisticDao.queryCarFlowChartByDay(request); return new BizResult<>(list); } @Override public BizResult> queryCarFlowChartByMonth( ParkingLotUseStatisticForPageRequest request) { List list = parkingLotUseStatisticDao.queryCarFlowChartByMonth(request); return new BizResult<>(list); } @Override public BizResult 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(dto); } @Override public BizResult 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(dto); } @Override public BizResult 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(dto); } @Override public BizResult> 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 result = parkingLotUseStatisticDao .queryTodayVehicleFlowOccupyRateAndTurnOver(beginTime, endTime, StatisticType.PER1HOUR, request.getPlNos()); result = fixTodayVehicleFlowOccupyRateAndTurnOverData(result); return new BizResult<>(result); } private List fixTodayVehicleFlowOccupyRateAndTurnOverData( List datas) { List realDatas = new ArrayList<>(); Map 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 initTodayVehicleFlowOccupyRateAndTurnOverDTOToMap( List datas) { Map map = new HashMap<>(); for (TodayVehicleFlowOccupyRateAndTurnOverDTO dto : datas) { map.put(dto.getHour(), dto); } return map; } @Override public BizResult> queryMonthVehicleFlowAndVacancyRateAndTurnover( ParkingLotUseStatisticForPageRequest request) { if (request == null) { throw new BizException(ErrorType.PARAMM_NULL, "参数为空"); } PageInfo pageInfo = parkingLotUseStatisticDao .queryMonthVehicleFlowAndVacancyRateAndTurnover(request.getBeginTime(), request.getEndTime(), request.getPlNos(), request.getBaseRequest().getPageNum(), request.getBaseRequest().getPageSize()); PageBean pageBean = new PageBean(); if (pageInfo != null) { PageBeanUtil.copyProperties(pageInfo, pageBean, MonthVehicleFlowAndVacancyRateAndTurnoverDTO.class); } return new BizResult>(pageBean); } @Override public BizResult> 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 pageBean=new PageBean<>(); PageInfo pageInfo = parkingLotUseStatisticDao.queryTurnoverRatioNew(request); if (pageInfo != null) { PageBeanUtil.copyProperties(pageInfo, pageBean, TurnoverRatioDTO.class); } return new BizResult<>(pageBean); } @Override public BizResult> 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 pageBean=new PageBean<>(); PageInfo pageInfo = parkingLotUseStatisticDao.queryTurnoverRatioNewForChart(request); if (pageInfo == null) { return new BizResult<>(pageBean); } PageBeanUtil.copyProperties(pageInfo, pageBean, TurnoverRatioDTO.class); return new BizResult<>(pageBean); } }