com.neusoft.mid.clwapi.service.statistics.StatisticsServiceImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.neusoft.mid.clwapi.service.statistics.StatisticsServiceImpl.java

Source

/**
 * @(#)StatisticsServiceImpl.java 2013-3-25
 *
 * Copyright 2013 Neusoft Group Ltd. All rights reserved.
 * Neusoft PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.neusoft.mid.clwapi.service.statistics;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.neusoft.mid.clwapi.common.ErrorConstant;
import com.neusoft.mid.clwapi.common.HttpConstant;
import com.neusoft.mid.clwapi.common.ModCommonConstant;
import com.neusoft.mid.clwapi.common.UserInfoKey;
import com.neusoft.mid.clwapi.entity.statistics.BadBehaviorPerp;
import com.neusoft.mid.clwapi.entity.statistics.CarMonthData;
import com.neusoft.mid.clwapi.entity.statistics.CarStatReport;
import com.neusoft.mid.clwapi.entity.statistics.EpCarDtl;
import com.neusoft.mid.clwapi.entity.statistics.EpDtlResp;
import com.neusoft.mid.clwapi.entity.statistics.EpMonthData;
import com.neusoft.mid.clwapi.entity.statistics.EpStatReport;
import com.neusoft.mid.clwapi.entity.statistics.MoldStatInfo;
import com.neusoft.mid.clwapi.entity.statistics.MonthStatInfo;
import com.neusoft.mid.clwapi.entity.statistics.ReportDesc;
import com.neusoft.mid.clwapi.entity.statistics.ReportDescResp;
import com.neusoft.mid.clwapi.entity.statistics.SuperviseInfo;
import com.neusoft.mid.clwapi.entity.statistics.SuperviseProcInfo;
import com.neusoft.mid.clwapi.entity.statistics.SuperviseResp;
import com.neusoft.mid.clwapi.exception.common.ApplicationException;
import com.neusoft.mid.clwapi.mapper.OauthMapper;
import com.neusoft.mid.clwapi.mapper.StatisticsMapper;
import com.neusoft.mid.clwapi.tools.BeanUtil;
import com.neusoft.mid.clwapi.tools.CheckRequestParam;
import com.neusoft.mid.clwapi.tools.JacksonUtils;
import com.neusoft.mid.clwapi.tools.TimeUtil;

/**
 * @author <a href="mailto:majch@neusoft.com">majch </a>
 * @version $Revision 1.0 $ 2013-3-25 ?9:39:25
 */
public class StatisticsServiceImpl implements StatisticsService {

    /**
     * .
     */
    private static Logger logger = LoggerFactory.getLogger(ModCommonConstant.LOGGER_NAME);

    @Autowired
    private StatisticsMapper stMapper;

    @Context
    private MessageContext context;

    @Autowired
    private OauthMapper oauthMapper;

    /**
     * ?.
     * 
     * @param token
     *            ?.
     * 
     * @param dateTime
     *            .
     * @return ??.
     */
    @Override
    public Response getSuperviseInfo(String token, String dateTime) {
        logger.info("?,:" + dateTime);

        SuperviseResp resp = new SuperviseResp();

        if ((null == dateTime) || ("".equals(dateTime)) || (dateTime.length() != 8)) {
            logger.info("??????");
            throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
        } else {
            try {
                TimeUtil.parseStringToDate(dateTime, "yyyyMMdd");
            } catch (ParseException e) {
                logger.info("" + dateTime + "?", e);
                logger.info("????");
                throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
            }
            String sysdate = new SimpleDateFormat("yyyyMMdd").format(Calendar.getInstance().getTime());
            logger.info("?:" + sysdate);
            int compareResult = dateTime.compareTo(sysdate);
            String entId = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
            if (compareResult < 0) {
                logger.info(",??");
                List<SuperviseInfo> result = stMapper.getPassSuperviseInfo(entId, dateTime);
                if (null != result && result.size() != 0) {
                    logger.info("??");
                    resp.setResultList(result);
                } else {
                    logger.error("?ID:" + entId + ",:" + dateTime
                            + "??");
                    return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                            .header("Pragma", "no-cache").build();
                }
            } else if (compareResult == 0) {
                logger.info("??");
                SuperviseProcInfo param = new SuperviseProcInfo();
                param.setDateTime(sysdate);
                stMapper.excuteProcCreatePassSuperviseInfo(param);
                if (1 == param.getResult()) {
                    logger.info("STAFF_BEHV_DAY_STAT_PROC?");
                    List<SuperviseInfo> result = stMapper.getPassSuperviseInfo(entId, sysdate);
                    if (null != result && result.size() != 0) {
                        logger.info("??");
                        resp.setResultList(result);
                    } else {
                        logger.error("?ID:" + entId + ",:" + sysdate
                                + "??");
                        return Response.status(Response.Status.NO_CONTENT)
                                .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build();
                    }
                } else {
                    logger.info("STAFF_BEHV_DAY_STAT_PROC");
                    return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                            .header("Pragma", "no-cache").build();
                }

            } else {
                logger.info("?,?");
                return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                        .header("Pragma", "no-cache").build();
            }
        }

        return Response.ok(JacksonUtils.toJsonRuntimeException(resp)).header(HttpHeaders.CACHE_CONTROL, "no-store")
                .header("Pragma", "no-cache").build();
    }

    /**
     * ??.
     * 
     * @param token
     *            ?.
     * @param VIN
     *            VIN
     * @param month
     *            ,?yyyymm  LATEST_MONTH
     * @return ??.
     */
    @Override
    public Response getCarReport(String token, String VIN, String month) {
        VIN = StringUtils.strip(VIN);
        month = StringUtils.strip(month);
        String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
        logger.info("?-?ID:" + epid + ",VIN:" + VIN + "," + month);

        if (CheckRequestParam.isEmpty(epid)) {
            logger.info("?--?ID");
            throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
        }

        Date reportMonth;
        List<CarMonthData> infos;
        //?
        if (HttpConstant.LATEST_MONTH.equals(month)) {
            infos = stMapper.getValidCarReport(VIN);
            if (CheckRequestParam.isEmpty(infos)) {
                logger.info("?-VIN:" + VIN + "???");
                return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                        .header("Pragma", "no-cache").build();
            }

            try {
                reportMonth = TimeUtil.parseStringToDate(infos.get(0).getDateTime(), HttpConstant.MONTH_FORMAT_1);
            } catch (ParseException e) {
                logger.error("?-yyyyMM?" + e.getMessage());
                throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
            }
        } else {
            //?
            try {
                reportMonth = TimeUtil.parseStringToDate(month, HttpConstant.MONTH_FORMAT);
            } catch (ParseException e) {
                logger.error("?-yyyyMM?" + e.getMessage());
                throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
            }

            if (reportMonth.after(TimeUtil.getLastMonthD())) {
                logger.info("?-??" + month + "?");
                throw new ApplicationException(ErrorConstant.ERROR10004, Response.Status.BAD_REQUEST);
            }

            infos = stMapper.getCarMonthData(month, VIN);
            if (CheckRequestParam.isEmpty(infos)) {
                logger.info("?-VIN:" + VIN + "???");
                return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                        .header("Pragma", "no-cache").build();
            }
        }

        CarStatReport statInfo = convertCarResp(infos, reportMonth);
        if (CheckRequestParam.isEmpty(statInfo)) {
            logger.info("?-VIN:" + VIN + "???");
            return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                    .header("Pragma", "no-cache").build();
        }
        return Response.ok(JacksonUtils.toJsonRuntimeException(statInfo))
                .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build();
    }

    /**
     * ??.
     * 
     * @param token
     *            ?.
     * @param month
     *            ,?yyyymm
     * @return ??.
     */
    @Override
    public Response getEntiReport(String token, String month) {
        month = StringUtils.strip(month);
        String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
        logger.info("?-?ID:" + epid + "," + month);

        Date reportMonth;
        try {
            reportMonth = TimeUtil.parseStringToDate(month, HttpConstant.MONTH_FORMAT);
        } catch (ParseException e) {
            logger.error("?-yyyyMM?" + e.getMessage());
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }

        if (reportMonth.after(TimeUtil.getLastMonthD())) {
            logger.info("?-??" + month + "?");
            throw new ApplicationException(ErrorConstant.ERROR10004, Response.Status.BAD_REQUEST);
        }

        if (CheckRequestParam.isEmpty(epid)) {
            logger.info("?--?ID");
            throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
        }

        List<EpMonthData> infos = stMapper.getEpMonthData(month, epid);
        if (CheckRequestParam.isEmpty(infos)) {
            logger.info("?-?ID:" + epid + "???");
            return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                    .header("Pragma", "no-cache").build();
        }

        EpStatReport resp = convertEpResp(infos, reportMonth);
        if (CheckRequestParam.isEmpty(resp)) {
            logger.info("?-?ID:" + epid + "???");
            return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                    .header("Pragma", "no-cache").build();
        }
        return Response.ok(JacksonUtils.toJsonRuntimeException(resp)).header(HttpHeaders.CACHE_CONTROL, "no-store")
                .header("Pragma", "no-cache").build();
    }

    /**
     * ????.
     * 
     * @param infos
     *            5????.
     * @param reportMonth
     *            ,?yyyymm
     * 
     * @return ??.
     */
    private CarStatReport convertCarResp(List<CarMonthData> infos, Date reportMonth) {
        // 
        CarStatReport statInfo = new CarStatReport();
        // ????
        MoldStatInfo speedMold = new MoldStatInfo();
        MoldStatInfo badMold = new MoldStatInfo();
        MoldStatInfo oilMold = new MoldStatInfo();
        // ?N????
        List<MonthStatInfo> speedMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> badMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> oilMonths = new ArrayList<MonthStatInfo>();
        String monthStr = "";
        String monthReport = TimeUtil.formatDateToString(reportMonth, "yyyy-MM");
        boolean reportFlag = false;
        // ???N?
        for (CarMonthData obj : infos) {
            monthStr = obj.getDateTime();
            // ???
            if (monthReport.equals(monthStr)) {
                reportFlag = true;
                // ??
                statInfo.setCarLn(obj.getCarLn());
                statInfo.setDriveName(obj.getDriverName());
                statInfo.setDateTime(monthStr);
                statInfo.setLimitNum(obj.getLimitNum());
                statInfo.setTotalMileage(obj.getTotalMileage());
                statInfo.setTotalOil(obj.getTotalOil());
                statInfo.setValidFlag(obj.getValidFlag());
                if (!HttpConstant.ZERO.equals(obj.getValidFlag())) {
                    break;
                }
                statInfo.setPreOil(obj.getOilPre());
                statInfo.setPerSpeedMileage(obj.getSpeedMileagePer());
                statInfo.setPerBadHour(obj.getBadHourPer());
                // ??
                speedMold.setStMold(HttpConstant.REPORT_SPEED_MILE);
                speedMold.setStAvg(Double.toString(obj.getSpeedMileagePerAvg()));
                speedMold.setStDesc(obj.getSpeedMileagePerDesc());
                speedMold.setStCmpPrior(obj.getSpeedMileagePerCmpPrior());
                speedMold.setStCmpAvg(obj.getSpeedMileagePerCmpAvg());
                // ???
                badMold.setStMold(HttpConstant.REPORT_BAD_TIME);
                badMold.setStAvg(Double.toString(obj.getBadHourPerAvg()));
                badMold.setStDesc(obj.getBadHourPerDesc());
                badMold.setStCmpPrior(obj.getBadHourPerCmpPrior());
                badMold.setStCmpAvg(obj.getBadHourPerCmpAvg());
                // ??
                oilMold.setStMold(HttpConstant.REPORT_OIL_MILE);
                oilMold.setStAvg(Double.toString(obj.getOilPreAvg()));
                oilMold.setStDesc(obj.getOilPreDesc());
                oilMold.setStCmpPrior(obj.getOilPerCmpPrior());
                oilMold.setStCmpAvg(obj.getOilPerCmpAvg());
            }
            // ???
            MonthStatInfo speedInfo = new MonthStatInfo();
            speedInfo.setStMonth(monthStr);
            speedInfo.setStData(obj.getSpeedMileagePer());
            speedInfo.setStOrder(obj.getSpeedMileagePerOrder());
            speedMonths.add(speedInfo);
            // ????
            MonthStatInfo badInfo = new MonthStatInfo();
            badInfo.setStMonth(monthStr);
            badInfo.setStData(obj.getBadHourPer());
            badInfo.setStOrder(obj.getBadHourPerOrder());
            badMonths.add(badInfo);
            // ???
            MonthStatInfo oilInfo = new MonthStatInfo();
            oilInfo.setStMonth(monthStr);
            oilInfo.setStData(obj.getOilPre());
            oilInfo.setStOrder(obj.getOilPreOrder());
            oilMonths.add(oilInfo);
        }

        if (!reportFlag) {
            logger.info("?-:" + monthReport + "???");
            return null;
        }
        speedMold.setStMonthInfos(speedMonths);
        badMold.setStMonthInfos(badMonths);
        oilMold.setStMonthInfos(oilMonths);

        List<MoldStatInfo> allMold = new ArrayList<MoldStatInfo>();
        allMold.add(speedMold);
        allMold.add(badMold);
        allMold.add(oilMold);

        statInfo.setDetailInfo(allMold);
        return statInfo;
    }

    /**
     * ????.
     * 
     * @param infos
     *            ?3????.
     * @param reportMonth
     *            ,?yyyymm
     * 
     * @return ??.
     */
    private EpStatReport convertEpResp(List<EpMonthData> infos, Date reportMonth) {
        // ?
        EpStatReport statInfo = new EpStatReport();
        // 01-
        MoldStatInfo speedMileMold = new MoldStatInfo();
        // 04-?
        MoldStatInfo speedPerpMold = new MoldStatInfo();
        // 02-?
        MoldStatInfo badHourMold = new MoldStatInfo();
        // 05-??
        MoldStatInfo badPerpMold = new MoldStatInfo();
        // 03-
        MoldStatInfo oilMold = new MoldStatInfo();
        // 06-?
        MoldStatInfo oilPerpMold = new MoldStatInfo();
        // 08-
        MoldStatInfo rpmHourMold = new MoldStatInfo();
        // 07-
        MoldStatInfo speedHourMold = new MoldStatInfo();
        // 09-
        MoldStatInfo longIdleHourMold = new MoldStatInfo();
        // 10-
        MoldStatInfo airIdleHourMold = new MoldStatInfo();
        // 11-???
        MoldStatInfo economicRunHourMold = new MoldStatInfo();

        // ?N????
        List<MonthStatInfo> speedMileMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> badHourMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> oilMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> speedPrepMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> badPrepMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> oilPrepMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> speedHourMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> rpmHourMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> longIdleHourMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> airIdleHourMonths = new ArrayList<MonthStatInfo>();
        List<MonthStatInfo> economicRunHourMonths = new ArrayList<MonthStatInfo>();

        // ??
        List<BadBehaviorPerp> badPerp = new ArrayList<BadBehaviorPerp>();

        String monthStr = "";
        String monthReport = TimeUtil.formatDateToString(reportMonth, "yyyy-MM");
        boolean reportFlag = false;
        // ???N?
        for (EpMonthData obj : infos) {
            monthStr = obj.getDateTime();
            // ???
            if (monthReport.equals(monthStr)) {
                reportFlag = true;
                // ??
                statInfo.setDateTime(monthStr);
                statInfo.setCarNum(obj.getCarNum());
                statInfo.setTotalMileage(obj.getTotalMileage());
                statInfo.setTotalOil(obj.getTotalOil());
                statInfo.setValidFlag(obj.getValidFlag());
                if (!HttpConstant.ZERO.equals(obj.getValidFlag())) {
                    break;
                }
                // ??
                speedMileMold.setStMold(HttpConstant.REPORT_SPEED_MILE);
                speedMileMold.setStAvg(Double.toString(obj.getSpeedMileagePerAvg()));
                speedMileMold.setStDesc(obj.getSpeedMileagePerDesc());
                speedMileMold.setStCmpPrior(obj.getSpeedMileagePerCmpPrior());
                speedMileMold.setStCmpAvg(obj.getSpeedMileagePerCmpAvg());
                // ???
                speedPerpMold.setStMold(HttpConstant.REPORT_SPEED_CAR);
                speedPerpMold.setStAvg(Double.toString(obj.getSpeedCarPerAvg()));
                speedPerpMold.setStDesc(obj.getSpeedCarPerDesc());
                speedPerpMold.setStCmpPrior(obj.getSpeedCarPerCmpPrior());
                speedPerpMold.setStCmpAvg(obj.getSpeedCarPerCmpAvg());
                // ???
                badHourMold.setStMold(HttpConstant.REPORT_BAD_TIME);
                badHourMold.setStAvg(Double.toString(obj.getBadHourPerAvg()));
                badHourMold.setStDesc(obj.getBadHourPerDesc());
                badHourMold.setStCmpPrior(obj.getBadHourPerCmpPrior());
                badHourMold.setStCmpAvg(obj.getBadHourPerCmpAvg());
                // ????
                badPerpMold.setStMold(HttpConstant.REPORT_BAD_CAR);
                // modify by majch
                badPerpMold.setStAvg(Double.toString(obj.getBadCarPerAvg()));
                badPerpMold.setStDesc(obj.getBadCarPerDesc());
                badPerpMold.setStCmpPrior(obj.getBadCarPerCmpPrior());
                badPerpMold.setStCmpAvg(obj.getBadCarPerCmpAvg());
                // ??
                oilMold.setStMold(HttpConstant.REPORT_OIL_MILE);
                oilMold.setStAvg(Double.toString(obj.getOilPreAvg()));
                oilMold.setStDesc(obj.getOilPreDesc());
                oilMold.setStCmpPrior(obj.getOilPerCmpPrior());
                oilMold.setStCmpAvg(obj.getOilPerCmpAvg());
                // ???
                oilPerpMold.setStMold(HttpConstant.REPORT_OIL_CAR);
                // modify by majch
                oilPerpMold.setStAvg(Double.toString(obj.getOilCarPerAvg()));
                oilPerpMold.setStDesc(obj.getOilCarPerDesc());
                oilPerpMold.setStCmpPrior(obj.getOilCarPerCmpPrior());
                oilPerpMold.setStCmpAvg(obj.getOilCarPerCmpAvg());
                // ?
                speedHourMold.setStMold(HttpConstant.REPORT_SPEED_TIME);
                speedHourMold.setStAvg(Double.toString(obj.getSpeedHourPerAvg()));
                // ?
                rpmHourMold.setStMold(HttpConstant.REPORT_RPM_TIME);
                rpmHourMold.setStAvg(Double.toString(obj.getRpmHourPerAvg()));
                // ?
                longIdleHourMold.setStMold(HttpConstant.REPORT_LONGIDLE_TIME);
                longIdleHourMold.setStAvg(Double.toString(obj.getLongIdleHourPerAvg()));
                // ?
                airIdleHourMold.setStMold(HttpConstant.REPORT_AIRIDLE_TIME);
                airIdleHourMold.setStAvg(Double.toString(obj.getAirIdleHourPerAvg()));
                // ???
                economicRunHourMold.setStMold(HttpConstant.REPORT_ECONOMICRUND_TIME);
                economicRunHourMold.setStAvg(Double.toString(obj.getEconomicRunHourPerAvg()));

                // ??
                BadBehaviorPerp speedPrep = new BadBehaviorPerp();
                speedPrep.setBaddriveType(HttpConstant.REPORT_QY_SPEED_CAR);
                speedPrep.setBaddrivePrecent(obj.getSpeedCarHourPer());

                BadBehaviorPerp rpmPrep = new BadBehaviorPerp();
                rpmPrep.setBaddriveType(HttpConstant.REPORT_QY_RPM_CAR);
                rpmPrep.setBaddrivePrecent(obj.getRpmCarPer());

                BadBehaviorPerp longIdlePrep = new BadBehaviorPerp();
                longIdlePrep.setBaddriveType(HttpConstant.REPORT_QY_LONGIDLE_CAR);
                longIdlePrep.setBaddrivePrecent(obj.getLongIdleCarPer());

                BadBehaviorPerp airIdlePrep = new BadBehaviorPerp();
                airIdlePrep.setBaddriveType(HttpConstant.REPORT_QY_AIRIDLE_CAR);
                airIdlePrep.setBaddrivePrecent(obj.getAirIdleCarPer());

                BadBehaviorPerp economicRunPrep = new BadBehaviorPerp();
                economicRunPrep.setBaddriveType(HttpConstant.REPORT_QY_ECONOMICRUND_CAR);
                economicRunPrep.setBaddrivePrecent(obj.getEconomicRunCarPer());

                badPerp.add(speedPrep);
                badPerp.add(rpmPrep);
                badPerp.add(longIdlePrep);
                badPerp.add(airIdlePrep);
                badPerp.add(economicRunPrep);
            }
            // ???
            MonthStatInfo speedMileInfo = new MonthStatInfo();
            speedMileInfo.setStMonth(monthStr);
            speedMileInfo.setStData(obj.getSpeedMileagePer());
            speedMileMonths.add(speedMileInfo);
            // ????
            MonthStatInfo badHourInfo = new MonthStatInfo();
            badHourInfo.setStMonth(monthStr);
            badHourInfo.setStData(obj.getBadHourPer());
            badHourMonths.add(badHourInfo);
            // ???
            MonthStatInfo oilInfo = new MonthStatInfo();
            oilInfo.setStMonth(monthStr);
            oilInfo.setStData(obj.getOilPre());
            oilMonths.add(oilInfo);
            // ????
            MonthStatInfo speedPrepInfo = new MonthStatInfo();
            speedPrepInfo.setStMonth(monthStr);
            speedPrepInfo.setStData(obj.getSpeedCarPer());
            speedPrepMonths.add(speedPrepInfo);
            // ?????
            MonthStatInfo badPrepInfo = new MonthStatInfo();
            badPrepInfo.setStMonth(monthStr);
            badPrepInfo.setStData(obj.getBadCarPer());
            badPrepMonths.add(badPrepInfo);
            // ????
            MonthStatInfo oilPrepInfo = new MonthStatInfo();
            oilPrepInfo.setStMonth(monthStr);
            oilPrepInfo.setStData(obj.getOilCarPer());
            oilPrepMonths.add(oilPrepInfo);
            // ???
            MonthStatInfo speedHourInfo = new MonthStatInfo();
            speedHourInfo.setStMonth(monthStr);
            speedHourInfo.setStData(obj.getSpeedHourPer());
            speedHourMonths.add(speedHourInfo);
            // ???
            MonthStatInfo rpmHourInfo = new MonthStatInfo();
            rpmHourInfo.setStMonth(monthStr);
            rpmHourInfo.setStData(obj.getRpmHourPer());
            rpmHourMonths.add(rpmHourInfo);
            // ???
            MonthStatInfo longIdleHourInfo = new MonthStatInfo();
            longIdleHourInfo.setStMonth(monthStr);
            longIdleHourInfo.setStData(obj.getLongIdleHourPer());
            longIdleHourMonths.add(longIdleHourInfo);
            // ???
            MonthStatInfo airIdleHourInfo = new MonthStatInfo();
            airIdleHourInfo.setStMonth(monthStr);
            airIdleHourInfo.setStData(obj.getAirIdleHourPer());
            airIdleHourMonths.add(airIdleHourInfo);
            // ??????
            MonthStatInfo economicRunHourInfo = new MonthStatInfo();
            economicRunHourInfo.setStMonth(monthStr);
            economicRunHourInfo.setStData(obj.getEconomicRunHourPer());
            economicRunHourMonths.add(economicRunHourInfo);
        }

        if (!reportFlag) {
            logger.info("?-:" + monthReport + "???");
            return null;
        }

        speedMileMold.setStMonthInfos(speedMileMonths);
        speedPerpMold.setStMonthInfos(speedPrepMonths);
        badHourMold.setStMonthInfos(badHourMonths);
        badPerpMold.setStMonthInfos(badPrepMonths);
        oilMold.setStMonthInfos(oilMonths);
        oilPerpMold.setStMonthInfos(oilPrepMonths);
        speedHourMold.setStMonthInfos(speedHourMonths);
        rpmHourMold.setStMonthInfos(rpmHourMonths);
        longIdleHourMold.setStMonthInfos(longIdleHourMonths);
        airIdleHourMold.setStMonthInfos(airIdleHourMonths);
        economicRunHourMold.setStMonthInfos(economicRunHourMonths);
        List<MoldStatInfo> allMold = new ArrayList<MoldStatInfo>();
        allMold.add(speedMileMold);
        allMold.add(speedPerpMold);
        allMold.add(badHourMold);
        allMold.add(badPerpMold);
        allMold.add(oilMold);
        allMold.add(oilPerpMold);
        allMold.add(speedHourMold);
        allMold.add(rpmHourMold);
        allMold.add(longIdleHourMold);
        allMold.add(airIdleHourMold);
        allMold.add(economicRunHourMold);
        statInfo.setDetailInfo(allMold);
        statInfo.setBadDriveInfo(badPerp);
        return statInfo;
    }

    /**
     * ??.
     * 
     * @param token
     *            ?.
     * @param month
     *            ,?yyyymm
     * @param rsType
     *            ?,01- ;02- ?;03- 
     * 
     * @return ??.
     */
    @Override
    public Response getEntiReportDetail(String token, String month, String rsType) {
        month = StringUtils.strip(month);
        rsType = StringUtils.strip(rsType);
        String epid = context.getHttpHeaders().getHeaderString(UserInfoKey.ENTERPRISE_ID);
        String orgID = context.getHttpHeaders().getHeaderString(UserInfoKey.ORGANIZATION_ID);
        logger.info("?-?ID:" + epid + ",ID" + orgID + ","
                + month + "," + rsType);

        Date reportMonth;
        try {
            reportMonth = TimeUtil.parseStringToDate(month, HttpConstant.MONTH_FORMAT);
        } catch (ParseException e) {
            logger.error("?-yyyyMM?" + e.getMessage());
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }

        if (reportMonth.after(TimeUtil.getLastMonthD())) {
            logger.info("?-??" + month + "?");
            throw new ApplicationException(ErrorConstant.ERROR10004, Response.Status.BAD_REQUEST);
        }

        if (!HttpConstant.REPORT_QY_D_SPEED.equals(rsType) && !HttpConstant.REPORT_QY_D_BAD.equals(rsType)
                && !HttpConstant.REPORT_QY_D_OIL.equals(rsType)) {
            logger.info("?-?" + rsType + "?[01,02,03]");
            throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
        }

        if (CheckRequestParam.isEmpty(epid) || CheckRequestParam.isEmpty(orgID)) {
            logger.info("?--?IDID");
            throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
        }

        List<EpCarDtl> infos = stMapper.getCarMonthDtl(month, epid, rsType, orgID);
        if (CheckRequestParam.isEmpty(infos)) {
            logger.info("?-?ID:" + epid + "ID:" + orgID + "" + month
                    + "" + rsType + "?");
            return Response.status(Response.Status.NO_CONTENT).header(HttpHeaders.CACHE_CONTROL, "no-store")
                    .header("Pragma", "no-cache").build();
        }

        EpDtlResp result = new EpDtlResp();
        result.setDetailInfo(infos);
        return Response.ok(JacksonUtils.toJsonRuntimeException(result))
                .header(HttpHeaders.CACHE_CONTROL, "no-store").header("Pragma", "no-cache").build();
    }

    /**
     * ???
     * 
     * @param token
     *            
     * @param eTag
     *            ??
     * @return ???
     */
    @Override
    public Object getAllDesc(String token, String eTag) {
        // ?Etag
        boolean checkEtagFlag = true;
        // ??ID
        String enId = context.getHttpHeaders().getHeaderString(UserInfoKey.USR_ID);
        logger.info("???");

        // ???
        List<ReportDesc> list = stMapper.getReportDesc(enId);
        logger.info("????");
        logger.debug("list = " + (list == null ? "NULL" : list.size()));

        // ???
        if (list == null || list.size() == 0) {
            logger.error("????");
            throw new ApplicationException(ErrorConstant.ERROR10010, Response.Status.NOT_FOUND);
        } else {
            logger.debug("?");
            if (logger.isDebugEnabled()) {
                Iterator<ReportDesc> it = list.iterator();
                int i = 0;
                while (it.hasNext()) {
                    ReportDesc iReportDesc = it.next();
                    logger.debug(++i + iReportDesc.toString());
                }
            }
        }

        // ??
        String plaETag = list.get(0).getUpdateTime();

        logger.info("????[" + enId + "]?");
        logger.info("?ETag:" + eTag);
        logger.info("??ETag:" + plaETag);

        // ?
        Date dateTer = new Date();
        // ??
        Date datePla = new Date();

        if (eTag == null) {
            logger.error("If-None-Match");
            throw new ApplicationException(ErrorConstant.ERROR10001, Response.Status.BAD_REQUEST);
        }

        // 
        if (!eTag.equals("0")) {
            try {
                dateTer = BeanUtil.checkTimeForm(eTag, HttpConstant.TIME_FORMAT);
            } catch (ParseException e) {
                logger.error("??", e);
                throw new ApplicationException(ErrorConstant.ERROR10002, Response.Status.BAD_REQUEST);
            }
            // ??
            if (!plaETag.equals("0")) {
                try {
                    datePla = BeanUtil.checkTimeForm(plaETag, HttpConstant.TIME_FORMAT);
                } catch (ParseException e) {
                    logger.error("???", e);
                    throw new ApplicationException(ErrorConstant.ERROR90000, Response.Status.INTERNAL_SERVER_ERROR);
                }
            }
        } else {
            checkEtagFlag = false;
        }

        // ??
        if (checkEtagFlag && dateTer.compareTo(datePla) == 0) {
            logger.info("???");
            return Response.notModified().build();
        } else if (checkEtagFlag && dateTer.compareTo(datePla) > 0) {
            logger.error("???");
            throw new ApplicationException(ErrorConstant.ERROR10103, Response.Status.BAD_REQUEST);
        }

        // ?
        List<ReportDesc> temp = new ArrayList<ReportDesc>();
        // ????
        Iterator<ReportDesc> it = list.iterator();
        while (it.hasNext()) {
            ReportDesc iReportDesc = it.next();
            // ??
            if (iReportDesc.getDel().equals("0")) {
                temp.add(iReportDesc);
            }
        }

        // ?
        ReportDescResp iReportDescResp = new ReportDescResp();
        iReportDescResp.setEtag(plaETag);
        iReportDescResp.setList(temp);
        return JacksonUtils.toJsonRuntimeException(iReportDescResp);
    }
}