diff --git a/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/datastatistic/VehicleFlowStatisticController.java b/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/datastatistic/VehicleFlowStatisticController.java index 2d4a56f..1c3f9e2 100644 --- a/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/datastatistic/VehicleFlowStatisticController.java +++ b/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/datastatistic/VehicleFlowStatisticController.java @@ -7,28 +7,15 @@ import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.apache.poi.xssf.usermodel.XSSFSheet; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - import com.alibaba.dubbo.common.utils.CollectionUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; + import com.clouds.common.entity.UserInfo; import com.clouds.common.utils.DateUtil; import com.clouds.common.utils.ResultUtils; @@ -49,367 +36,370 @@ import com.zteits.clouds.api.apibase.exception.BizException; 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.param.ParkingLotUseStatisticForPageRequest; -import com.zteits.clouds.api.dto.pay.param.TdCompanyParkQueryRequest; import com.zteits.clouds.api.service.park.ParkingLotUseStatisticService; import com.zteits.clouds.api.service.pay.TdCustCompanyService; import com.zteits.irain.portal.constant.ParkConstant; -import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.BerthsAndFlowLineChartVO; import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.LineChartVO; import com.zteits.irain.portal.vo.parkinglotcloudplatform.datastatistic.LineChartVO.SerieVO; - import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; /** - * * 停车场车流量数据统计 Copyright: Copyright (c) 2017 zteits - * + * * @ClassName: ParkingLotUseStatisticController.java * @Description: * @version: v1.0.0 * @author: langlw * @date: 2017年6月14日 下午3:02:39 Modification History: Date Author Version - * Description ---------------------------------------------------------* - * 2017年6月14日 langlw v1.0.0 创建 + * Description ---------------------------------------------------------* + * 2017年6月14日 langlw v1.0.0 创建 */ @Api(value = "停车场车流量数据统计", description = "停车场车流量数据统计") @Controller @RequestMapping(value = "/VehicleFlowStatistic") public class VehicleFlowStatisticController extends BizController { - private Logger logger = LoggerFactory.getLogger(VehicleFlowStatisticController.class); - - @Value("${project.syscode}") - private String sysCode; - - @Autowired - private ParkingLotUseStatisticService parkingLotStatisticService; - @Autowired - private HttpSession session; - @Autowired - private SessionCommUtil sessionCommUtil; - @Autowired - private TdCustCompanyService tdCustCompanyService; - - @ApiOperation("分页查询车流量数据统计车位总流量") - @PostMapping("getVehicleFlowStatisticForPage") - @ResponseBody - public BizResultVO> queryParkingLotUseStatisticForPage( - @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception { - if (null == request.getBeginTime() || null == request.getEndTime()) { - throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间"); - } - Calendar beginc = Calendar.getInstance(); - beginc.setTime(request.getBeginTime()); - int beginYear = beginc.get(Calendar.YEAR); - int beginMonth = beginc.get(Calendar.MONTH) + 1; - int beginDay = beginc.get(Calendar.DAY_OF_MONTH); - - Calendar endc = Calendar.getInstance(); - endc.setTime(request.getEndTime()); - int endYear = endc.get(Calendar.YEAR); - int endMonth = endc.get(Calendar.MONTH) + 1; - int endDay = endc.get(Calendar.DAY_OF_MONTH); - - if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) { - // 2表示按每小时统计 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); - } else { - // 3表示按每天统计 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); - } - - BizResult> bizResult = parkingLotStatisticService - .queryParkingLotUseStatisticForPage(request); - return returnJqGridData(bizResult, ParkingLotUseStatisticDTO.class); - } - - @ApiOperation("查询车流量最大值与最小值") - @PostMapping("getVehicleFlowMaxAndMin") - @ResponseBody - public BizResultVO QueryParkingLotUseStatisticMaxAndMin( - @RequestBody ParkingLotUseStatisticForPageRequest request) { - Calendar beginc = Calendar.getInstance(); - beginc.setTime(request.getBeginTime()); - int beginYear = beginc.get(Calendar.YEAR); - int beginMonth = beginc.get(Calendar.MONTH) + 1; - int beginDay = beginc.get(Calendar.DAY_OF_MONTH); - - Calendar endc = Calendar.getInstance(); - endc.setTime(request.getEndTime()); - int endYear = endc.get(Calendar.YEAR); - int endMonth = endc.get(Calendar.MONTH) + 1; - int endDay = endc.get(Calendar.DAY_OF_MONTH); - - if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) { - // 2表示按每小时统计 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); - } else { - // 3表示按每天统计 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); - } - BizResult bizResult = parkingLotStatisticService - .QueryVehicleFlowStatisticMaxAndMin(request); - return new BizResultVO<>(bizResult); - } - - @ApiOperation("导出车流量数据统计excel") - @GetMapping("exportVehicleFlowStatisticExcel") - public void excelParkingLotUseStatistic(@RequestParam String beginTime, @RequestParam String endTime, - @RequestParam String plNos, HttpServletRequest requests, HttpServletResponse response) { - ParkingLotUseStatisticForPageRequest request = new ParkingLotUseStatisticForPageRequest(); - request.setSysCode(sysCode); - request.setBeginTime(DateUtil.to_date(beginTime, DateUtil.DATETIME_FORMAT)); - request.setEndTime(DateUtil.to_date(endTime, DateUtil.DATETIME_FORMAT)); - List plNoslist = new ArrayList<>(); - plNoslist.add(plNos); - request.setPlNos(plNoslist); - request.setBaseRequest(new BaseInfo(1, 0)); - Calendar beginc = Calendar.getInstance(); - beginc.setTime(request.getBeginTime()); - int beginYear = beginc.get(Calendar.YEAR); - int beginMonth = beginc.get(Calendar.MONTH) + 1; - int beginDay = beginc.get(Calendar.DAY_OF_MONTH); - - Calendar endc = Calendar.getInstance(); - endc.setTime(request.getEndTime()); - int endYear = endc.get(Calendar.YEAR); - int endMonth = endc.get(Calendar.MONTH) + 1; - int endDay = endc.get(Calendar.DAY_OF_MONTH); - - if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) { - // 2表示按每小时统计 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); - } else { - // 3表示按每天统计 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); - } - BizResult> bizResult = parkingLotStatisticService - .queryParkingLotUseStatisticForPage(request); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); - String[] title = new String[] { "时间", "总车流量", "临时车流量", "固定车流量" }; - String sheetName = "车流量管理"; - String fileName = "车流量管理" + format2.format(new Date()); - // 1.创建excel信息 - XSSFSheet workSheet = ExcelUtil.createExcel(sheetName); - // 2.设置excel表头和表体 - Layouter.buildReport(workSheet, title, 0, 0); - // 3.填充数据 - List contentList = new ArrayList(); - List list = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(bizResult.getData().getDataList())) { - list = bizResult.getData().getDataList(); - } - for (ParkingLotUseStatisticDTO e : list) { - Object[] obj = new Object[title.length]; - int index = 0; - obj[index++] = format.format(e.getStatisticBeginTime()); - obj[index++] = e.getVehicleFlow(); - obj[index++] = e.getTmpVehicleFlow(); - obj[index++] = e.getFixVehicleFlow(); - contentList.add(obj); - } - ExcleFillDateManager fillUserManager = new ExcleFillDateManager(); - fillUserManager.fillSalesOrga(workSheet, title, contentList, 2); - // 4.excel输出配置 - ExcelUtil.write(response, workSheet, fileName); - } - - /** - * 根据时间获取车流量折线图 - * - * @param request - * @return - * @throws Exception - */ - @ApiOperation("根据时间获取车流量折线图") - @PostMapping("getVehicleFlowForLineChart") - @ResponseBody - public BizResultVO getVehicleFlowForLineChart( - @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception { - - if (null == request.getBeginTime() || null == request.getEndTime()) { - throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间"); - } - // 2.调用接口查询当前登录人管辖的停车场名称 - UserInfo userInfo = sessionCommUtil.getUserInfo(); - List plNos = new ArrayList<>(); - if (userInfo != null) { - TdCompanyParkQueryRequest tdCompanyParkQueryRequest = new TdCompanyParkQueryRequest(); - tdCompanyParkQueryRequest.setCustIdList(userInfo.getOrgIds()); - tdCompanyParkQueryRequest.setSessionId(session.getId()); - tdCompanyParkQueryRequest.setSysCode(sysCode); - BizResult> bizResult = tdCustCompanyService.queryParkNoByCustIds(tdCompanyParkQueryRequest); - // 拥有的停车场编号 - plNos = ResultUtils.getBizResultData(bizResult); - } - if (CollectionUtils.isEmpty(plNos)) { - throw new BizException(ErrorType.PARK_LOT_NOT_EXISTS, "停车场plnos不存在"); - } - request.setPlNos(plNos); - - logger.info("根据停车场编号获取该停车场今日车流量和车位折线图"); - Calendar beginTime = Calendar.getInstance(); - beginTime.setTime(request.getBeginTime()); - int year=beginTime.get(Calendar.YEAR); - Calendar endTime = Calendar.getInstance(); - endTime.setTime(request.getEndTime()); - - Long dayDifference = DateUtil.getTimeDifference(new Timestamp(request.getEndTime().getTime()), - new Timestamp(request.getBeginTime().getTime())); - List xAxisData = Lists.newArrayList(); - request.setBaseRequest(new BaseInfo(1, 0)); - String dateType = ""; - - if (dayDifference == 0L) { - // 1小时为一个时间戳 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); - int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY); - String day = ""; - String month = ""; - for (int i = 0; i < dayDifference.intValue(); i++) { - beginTime.add(Calendar.DAY_OF_MONTH, 1); - int beginMonth = beginTime.get(Calendar.MONTH) + 1; - int beginDay = beginTime.get(Calendar.DAY_OF_MONTH); - month = String.format("%02d", (beginMonth)); - day = String.format("%02d", (beginDay)); - for (int j = 0; j < totaltimestampCount; j++) { - String hour = String.format("%02d", (j)); - xAxisData.add(year+"-"+month + "-" + day + " " + hour); - } - } - dateType = "yyyy-MM-dd HH"; - LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType); - return new BizResultVO().setData(vehicleFlows); - - } else if (dayDifference <= 3L) { - // 1小时为一个时间戳 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); - int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY); - String day = ""; - String month = ""; - for (int i = 0; i < dayDifference.intValue(); i++) { - beginTime.add(Calendar.DAY_OF_MONTH, 1); - int beginMonth = beginTime.get(Calendar.MONTH) + 1; - int beginDay = beginTime.get(Calendar.DAY_OF_MONTH); - month = String.format("%02d", (beginMonth)); - day = String.format("%02d", (beginDay)); - for (int j = 0; j < totaltimestampCount; j++) { - String hour = String.format("%02d", (j)); - xAxisData.add(year+"-"+month + "-" + day + " " + hour); - } - } - dateType = "yyyy-MM-dd HH"; - LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType); - return new BizResultVO().setData(vehicleFlows); - - } else { - // 1天为一个时间戳 - request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); - for (int i = 0; i < dayDifference.intValue(); i++) { - beginTime.add(Calendar.DAY_OF_MONTH, 1); - int beginMonth = beginTime.get(Calendar.MONTH) + 1; - int beginDay = beginTime.get(Calendar.DAY_OF_MONTH); - String month = String.format("%02d", (beginMonth)); - String day = String.format("%02d", (beginDay)); - xAxisData.add(year+"-"+month + "-" + day); - - } - dateType = "yyyy-MM-dd"; - LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType); - return new BizResultVO().setData(vehicleFlows); - - } - - } - - private LineChartVO getVehicleFlows(ParkingLotUseStatisticForPageRequest request, List xAxisData, - String dateType) { - // 调用后场服务 - logger.info("调用DUBBO服务入参:" + JSON.toJSONString(request)); - BizResult> bizResult = parkingLotStatisticService - .queryParkingLotUseStatisticForPage(request); - PageBean pageBean = ResultUtils.getBizResultData(bizResult); - List useStatisticDTOs = Lists.newArrayList(); - if (pageBean != null) { - useStatisticDTOs = pageBean.getDataList(); - } - - // 保存固定车流量,时间戳和车流量对应关系 - Map fixVehicleFlowMap = Maps.newHashMap(); - // 保存临时车流量,时间戳和车流量对应关系 - Map tmpVehicleFlowMap = Maps.newHashMap(); - // 停车场编号和名称对应关系 - Map parkNameMap = Maps.newHashMap(); - // 通过停车场,和统计时间分组 - // Map> parkLotMap = Maps.newHashMap(); - if (!CollectionUtils.isEmpty(useStatisticDTOs)) { - for (ParkingLotUseStatisticDTO statisticDTO : useStatisticDTOs) { - String key = statisticDTO.getPlNo(); - parkNameMap.put(key, statisticDTO.getPlName()); - String statisBeginTime = DateUtil.getDateString(statisticDTO.getStatisticBeginTime(), dateType); - // 保存固定车流量和临时车流量 - fixVehicleFlowMap.put(statisBeginTime, - (fixVehicleFlowMap.get(statisBeginTime) == null ? 0 : fixVehicleFlowMap.get(statisBeginTime)) - + statisticDTO.getFixVehicleFlow()); - tmpVehicleFlowMap.put(statisBeginTime, - (tmpVehicleFlowMap.get(statisBeginTime) == null ? 0 : tmpVehicleFlowMap.get(statisBeginTime)) - + statisticDTO.getTmpVehicleFlow()); - } - } - - // 封装车流量统计 - LineChartVO vehicleFlows = new LineChartVO(); - List vehicleFlows_legendData = Lists.newArrayList(); - vehicleFlows_legendData.add("临时车"); - vehicleFlows_legendData.add("固定车"); - vehicleFlows.setLegendData(vehicleFlows_legendData); - vehicleFlows.setxAxisData(xAxisData); - List vehicleSeries = Lists.newArrayList(); - // 固定车 - SerieVO fixSerieVo = new SerieVO(); - fixSerieVo.setName("固定车"); - List fixSerieVoData = Lists.newArrayList(); - // 临时车 - SerieVO tmpSerieVo = new SerieVO(); - tmpSerieVo.setName("临时车"); - List tmpSerieVoData = Lists.newArrayList(); - // 保存上一次的临时车值,当某个时间点没有数据时,则保持和上次一致 - Integer lastfixFlow = 0; - Integer lasttmpFlow = 0; - for (String timestamp : xAxisData) { - - if (fixVehicleFlowMap.containsKey(timestamp)) { - lastfixFlow = fixVehicleFlowMap.get(timestamp).intValue(); - } else { - lastfixFlow = 0; - } - fixSerieVoData.add(lastfixFlow); - - if (tmpVehicleFlowMap.containsKey(timestamp)) { - lasttmpFlow = tmpVehicleFlowMap.get(timestamp).intValue(); - } else { - lasttmpFlow = 0; - } - tmpSerieVoData.add(lasttmpFlow); - } - fixSerieVo.setData(fixSerieVoData); - vehicleSeries.add(fixSerieVo); - tmpSerieVo.setData(tmpSerieVoData); - vehicleSeries.add(tmpSerieVo); - - vehicleFlows.setSeries(vehicleSeries); - return vehicleFlows; - } - - public static void main(String[] args) { - String json = "{\"id\":\"1\",\"platform\":\"android\",\"parameter\":{\"drid\":\"177277364\",\"sex\":\"1\",\"type\":\"2\",\"creatorname\":\"Mrw\",\"username\":\"jack\",\"pwd\":\"123456\",\"remark\":\"平板用户\",\"createtime\":\"2017-07-24 23:59:59\"}}"; - JSONObject object = (JSONObject) JSONObject.parse(json); - System.out.println(object.get("id")); - System.out.println(object.get("platform")); - JSONObject parameter = (JSONObject) object.get("parameter"); - System.out.println(parameter.get("drid")); - System.out.println(parameter.get("sex")); - } + private Logger logger = LoggerFactory.getLogger(VehicleFlowStatisticController.class); + + @Value("${project.syscode}") + private String sysCode; + + @Autowired + private ParkingLotUseStatisticService parkingLotStatisticService; + @Autowired + private HttpSession session; + @Autowired + private SessionCommUtil sessionCommUtil; + @Autowired + private TdCustCompanyService tdCustCompanyService; + + @ApiOperation("分页查询车流量数据统计车位总流量") + @PostMapping("getVehicleFlowStatisticForPage") + @ResponseBody + public BizResultVO> queryParkingLotUseStatisticForPage( + @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception { + if (null == request.getBeginTime() || null == request.getEndTime()) { + throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间"); + } + Calendar beginc = Calendar.getInstance(); + beginc.setTime(request.getBeginTime()); + int beginYear = beginc.get(Calendar.YEAR); + int beginMonth = beginc.get(Calendar.MONTH) + 1; + int beginDay = beginc.get(Calendar.DAY_OF_MONTH); + + Calendar endc = Calendar.getInstance(); + endc.setTime(request.getEndTime()); + int endYear = endc.get(Calendar.YEAR); + int endMonth = endc.get(Calendar.MONTH) + 1; + int endDay = endc.get(Calendar.DAY_OF_MONTH); + + if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) { + // 2表示按每小时统计 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); + } else { + // 3表示按每天统计 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); + } + + BizResult> bizResult = parkingLotStatisticService + .queryParkingLotUseStatisticForPage(request); + return returnJqGridData(bizResult, ParkingLotUseStatisticDTO.class); + } + + @ApiOperation("查询车流量最大值与最小值") + @PostMapping("getVehicleFlowMaxAndMin") + @ResponseBody + public BizResultVO QueryParkingLotUseStatisticMaxAndMin( + @RequestBody ParkingLotUseStatisticForPageRequest request) { + Calendar beginc = Calendar.getInstance(); + beginc.setTime(request.getBeginTime()); + int beginYear = beginc.get(Calendar.YEAR); + int beginMonth = beginc.get(Calendar.MONTH) + 1; + int beginDay = beginc.get(Calendar.DAY_OF_MONTH); + + Calendar endc = Calendar.getInstance(); + endc.setTime(request.getEndTime()); + int endYear = endc.get(Calendar.YEAR); + int endMonth = endc.get(Calendar.MONTH) + 1; + int endDay = endc.get(Calendar.DAY_OF_MONTH); + + if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) { + // 2表示按每小时统计 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); + } else { + // 3表示按每天统计 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); + } + BizResult bizResult = parkingLotStatisticService + .QueryVehicleFlowStatisticMaxAndMin(request); + return new BizResultVO<>(bizResult); + } + + @ApiOperation("导出车流量数据统计excel") + @GetMapping("exportVehicleFlowStatisticExcel") + public void excelParkingLotUseStatistic(@RequestParam String beginTime, @RequestParam String endTime, + @RequestParam String plNos, HttpServletRequest requests, HttpServletResponse response) { + ParkingLotUseStatisticForPageRequest request = new ParkingLotUseStatisticForPageRequest(); + request.setSysCode(sysCode); + request.setBeginTime(DateUtil.to_date(beginTime, DateUtil.DATETIME_FORMAT)); + request.setEndTime(DateUtil.to_date(endTime, DateUtil.DATETIME_FORMAT)); + List plNoslist = new ArrayList<>(); + plNoslist.add(plNos); + request.setPlNos(plNoslist); + request.setBaseRequest(new BaseInfo(1, 0)); + Calendar beginc = Calendar.getInstance(); + beginc.setTime(request.getBeginTime()); + int beginYear = beginc.get(Calendar.YEAR); + int beginMonth = beginc.get(Calendar.MONTH) + 1; + int beginDay = beginc.get(Calendar.DAY_OF_MONTH); + + Calendar endc = Calendar.getInstance(); + endc.setTime(request.getEndTime()); + int endYear = endc.get(Calendar.YEAR); + int endMonth = endc.get(Calendar.MONTH) + 1; + int endDay = endc.get(Calendar.DAY_OF_MONTH); + + if (beginYear == endYear && beginMonth == endMonth && beginDay == endDay) { + // 2表示按每小时统计 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); + } else { + // 3表示按每天统计 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); + } + BizResult> bizResult = parkingLotStatisticService + .queryParkingLotUseStatisticForPage(request); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd"); + String[] title = new String[] {"时间", "总车流量", "临时车流量", "固定车流量"}; + String sheetName = "车流量管理"; + String fileName = "车流量管理" + format2.format(new Date()); + // 1.创建excel信息 + XSSFSheet workSheet = ExcelUtil.createExcel(sheetName); + // 2.设置excel表头和表体 + Layouter.buildReport(workSheet, title, 0, 0); + // 3.填充数据 + List contentList = new ArrayList(); + List list = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(bizResult.getData().getDataList())) { + list = bizResult.getData().getDataList(); + } + for (ParkingLotUseStatisticDTO e : list) { + Object[] obj = new Object[title.length]; + int index = 0; + obj[index++] = format.format(e.getStatisticBeginTime()); + obj[index++] = e.getVehicleFlow(); + obj[index++] = e.getTmpVehicleFlow(); + obj[index++] = e.getFixVehicleFlow(); + contentList.add(obj); + } + ExcleFillDateManager fillUserManager = new ExcleFillDateManager(); + fillUserManager.fillSalesOrga(workSheet, title, contentList, 2); + // 4.excel输出配置 + ExcelUtil.write(response, workSheet, fileName); + } + + /** + * 根据时间获取车流量折线图 + * + * @param request + * @return + * @throws Exception + */ + @ApiOperation("根据时间获取车流量折线图") + @PostMapping("getVehicleFlowForLineChart") + @ResponseBody + public BizResultVO getVehicleFlowForLineChart( + @RequestBody ParkingLotUseStatisticForPageRequest request) throws Exception { + + if (null == request.getBeginTime() || null == request.getEndTime()) { + throw new BizException(ErrorType.PARAMM_NULL, "开始时间和结束时间"); + } + // 2.调用接口查询当前登录人管辖的停车场名称 + UserInfo userInfo = sessionCommUtil.getUserInfo(); + List plNos = userInfo.getOrgIds(); + if (CollectionUtils.isEmpty(plNos)) { + throw new BizException(ErrorType.PARK_LOT_NOT_EXISTS, "停车场plnos不存在"); + } + request.setPlNos(plNos); + + logger.info("根据停车场编号获取该停车场今日车流量和车位折线图"); + Calendar beginTime = Calendar.getInstance(); + beginTime.setTime(request.getBeginTime()); + int year = beginTime.get(Calendar.YEAR); + Calendar endTime = Calendar.getInstance(); + endTime.setTime(request.getEndTime()); + + Long dayDifference = DateUtil.getTimeDifference(new Timestamp(request.getEndTime().getTime()), + new Timestamp(request.getBeginTime().getTime())); + List xAxisData = Lists.newArrayList(); + request.setBaseRequest(new BaseInfo(1, 0)); + String dateType = ""; + + if (dayDifference == 0L) { + // 1小时为一个时间戳 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); + int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY); + String day = ""; + String month = ""; + + int beginMonth = beginTime.get(Calendar.MONTH) + 1; + int beginDay = beginTime.get(Calendar.DAY_OF_MONTH); + month = String.format("%02d", (beginMonth)); + day = String.format("%02d", (beginDay)); + for (int j = 0; j < totaltimestampCount; j++) { + String hour = String.format("%02d", (j)); + xAxisData.add(year + "-" + month + "-" + day + " " + hour); + } + + dateType = "yyyy-MM-dd HH"; + LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType); + return new BizResultVO().setData(vehicleFlows); + + } else if (dayDifference <= 3L) { + // 1小时为一个时间戳 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1HOUR); + int totaltimestampCount = endTime.get(Calendar.HOUR_OF_DAY); + String day = ""; + String month = ""; + for (int i = 0; i <=dayDifference.intValue(); i++) { + Calendar tempDate = Calendar.getInstance(); + tempDate .setTime(request.getBeginTime()); + tempDate.add(Calendar.DAY_OF_MONTH, i); + int beginMonth = tempDate.get(Calendar.MONTH) + 1; + int beginDay = tempDate.get(Calendar.DAY_OF_MONTH); + month = String.format("%02d", (beginMonth)); + day = String.format("%02d", (beginDay)); + for (int j = 0; j < totaltimestampCount; j++) { + String hour = String.format("%02d", (j)); + xAxisData.add(year + "-" + month + "-" + day + " " + hour); + } + } + dateType = "yyyy-MM-dd HH"; + LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType); + return new BizResultVO().setData(vehicleFlows); + + } else { + // 1天为一个时间戳 + request.setQueryKind(ParkConstant.ParkingLotUseStatistic.StatisticType.PER1DAY); + for (int i = 0; i <=dayDifference.intValue(); i++) { + Calendar tempDate = Calendar.getInstance(); + tempDate .setTime(request.getBeginTime()); + tempDate.add(Calendar.DAY_OF_MONTH, i); + int beginMonth = tempDate.get(Calendar.MONTH) + 1; + int beginDay = tempDate.get(Calendar.DAY_OF_MONTH); + String month = String.format("%02d", (beginMonth)); + String day = String.format("%02d", (beginDay)); + xAxisData.add(year + "-" + month + "-" + day); + + } + dateType = "yyyy-MM-dd"; + LineChartVO vehicleFlows = getVehicleFlows(request, xAxisData, dateType); + return new BizResultVO().setData(vehicleFlows); + + } + + } + + private LineChartVO getVehicleFlows(ParkingLotUseStatisticForPageRequest request, List xAxisData, + String dateType) { + // 调用后场服务 + logger.info("调用DUBBO服务入参:" + JSON.toJSONString(request)); + BizResult> bizResult = parkingLotStatisticService + .queryParkingLotUseStatisticForPage(request); + PageBean pageBean = ResultUtils.getBizResultData(bizResult); + List useStatisticDTOs = Lists.newArrayList(); + if (pageBean != null) { + useStatisticDTOs = pageBean.getDataList(); + } + + // 保存固定车流量,时间戳和车流量对应关系 + Map fixVehicleFlowMap = Maps.newHashMap(); + // 保存临时车流量,时间戳和车流量对应关系 + Map tmpVehicleFlowMap = Maps.newHashMap(); + // 停车场编号和名称对应关系 + Map parkNameMap = Maps.newHashMap(); + // 通过停车场,和统计时间分组 + // Map> parkLotMap = Maps.newHashMap(); + if (!CollectionUtils.isEmpty(useStatisticDTOs)) { + for (ParkingLotUseStatisticDTO statisticDTO : useStatisticDTOs) { + String key = statisticDTO.getPlNo(); + parkNameMap.put(key, statisticDTO.getPlName()); + String statisBeginTime = DateUtil.getDateString(statisticDTO.getStatisticBeginTime(), dateType); + // 保存固定车流量和临时车流量 + fixVehicleFlowMap.put(statisBeginTime, + (fixVehicleFlowMap.get(statisBeginTime) == null ? 0 : fixVehicleFlowMap.get(statisBeginTime)) + + statisticDTO.getFixVehicleFlow()); + tmpVehicleFlowMap.put(statisBeginTime, + (tmpVehicleFlowMap.get(statisBeginTime) == null ? 0 : tmpVehicleFlowMap.get(statisBeginTime)) + + statisticDTO.getTmpVehicleFlow()); + } + } + + // 封装车流量统计 + LineChartVO vehicleFlows = new LineChartVO(); + List vehicleFlows_legendData = Lists.newArrayList(); + vehicleFlows_legendData.add("临时车"); + vehicleFlows_legendData.add("固定车"); + vehicleFlows.setLegendData(vehicleFlows_legendData); + vehicleFlows.setxAxisData(xAxisData); + List vehicleSeries = Lists.newArrayList(); + // 固定车 + SerieVO fixSerieVo = new SerieVO(); + fixSerieVo.setName("固定车"); + List fixSerieVoData = Lists.newArrayList(); + // 临时车 + SerieVO tmpSerieVo = new SerieVO(); + tmpSerieVo.setName("临时车"); + List tmpSerieVoData = Lists.newArrayList(); + // 保存上一次的临时车值,当某个时间点没有数据时,则保持和上次一致 + Integer lastfixFlow = 0; + Integer lasttmpFlow = 0; + for (String timestamp : xAxisData) { + + if (fixVehicleFlowMap.containsKey(timestamp)) { + lastfixFlow = fixVehicleFlowMap.get(timestamp).intValue(); + } else { + lastfixFlow = 0; + } + fixSerieVoData.add(lastfixFlow); + + if (tmpVehicleFlowMap.containsKey(timestamp)) { + lasttmpFlow = tmpVehicleFlowMap.get(timestamp).intValue(); + } else { + lasttmpFlow = 0; + } + tmpSerieVoData.add(lasttmpFlow); + } + fixSerieVo.setData(fixSerieVoData); + vehicleSeries.add(fixSerieVo); + tmpSerieVo.setData(tmpSerieVoData); + vehicleSeries.add(tmpSerieVo); + + vehicleFlows.setSeries(vehicleSeries); + return vehicleFlows; + } + + public static void main(String[] args) { + String json + = "{\"id\":\"1\",\"platform\":\"android\",\"parameter\":{\"drid\":\"177277364\",\"sex\":\"1\",\"type\":\"2\",\"creatorname\":\"Mrw\",\"username\":\"jack\",\"pwd\":\"123456\",\"remark\":\"平板用户\",\"createtime\":\"2017-07-24 23:59:59\"}}"; + JSONObject object = (JSONObject)JSONObject.parse(json); + System.out.println(object.get("id")); + System.out.println(object.get("platform")); + JSONObject parameter = (JSONObject)object.get("parameter"); + System.out.println(parameter.get("drid")); + System.out.println(parameter.get("sex")); + } } diff --git a/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/parklotmanage/ParkLotManageController.java b/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/parklotmanage/ParkLotManageController.java index da98071..3373c73 100644 --- a/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/parklotmanage/ParkLotManageController.java +++ b/src/main/java/com/zteits/irain/portal/web/parkinglotcloudplatform/parklotmanage/ParkLotManageController.java @@ -103,19 +103,9 @@ public class ParkLotManageController{ private List GetParkLotNosByCurrUser(String sysCode) throws Exception { logger.info("根据登录人权限获取停车场列表"); - List plNos = Lists.newArrayList(); - //2.调用接口查询当前登录人管辖的停车场名称 UserInfo userInfo = sessionCommUtil.getUserInfo(); - if(userInfo!=null){ - TdCompanyParkQueryRequest tdCompanyParkQueryRequest = new TdCompanyParkQueryRequest(); - tdCompanyParkQueryRequest.setCustIdList(userInfo.getOrgIds()); - tdCompanyParkQueryRequest.setSysCode(sysCode); - tdCompanyParkQueryRequest.setSessionId(session.getId()); - BizResult> bizResult = tdCustCompanyService.queryParkNoByCustIds(tdCompanyParkQueryRequest ); - plNos = ResultUtils.getBizResultData(bizResult); - }else{ - throw new BizException(ErrorType.AUTH_TOKEN_NOT_EXISTS); - } + List plNos = userInfo.getOrgIds(); + return plNos; } }