package com.zteits.bill.biz.billing; import java.sql.Time; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; import org.apache.commons.lang3.StringUtils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.clouds.common.cache.sys.SysCodeValueCacheUtil; import com.clouds.common.constants.BillingFreeTimeTypeEnum; import com.clouds.common.constants.BillingLogEnum; import com.clouds.common.constants.CarTypeEnum; import com.clouds.common.constants.CodeValKindEnum; import com.clouds.common.constants.CodeValueEnum; import com.clouds.common.constants.WhitelistEnum; import com.clouds.common.entity.DateSpiltBean; import com.clouds.common.utils.ResultUtils; import com.clouds.common.utils.datespilt.DateSpiltUtil; import com.xiaoleilu.hutool.date.DateUnit; import com.xiaoleilu.hutool.date.DateUtil; import com.xiaoleilu.hutool.date.TimeInterval; import com.zteits.bill.biz.billing.inner.BillingInnerService; import com.zteits.bill.biz.billrule.inner.BillingRuleInnerService; import com.zteits.bill.dao.billlog.BillingLogDao; import com.zteits.bill.dao.whitelist.WhitelistDao; import com.zteits.bill.domain.WhitelistIsFreeDO; import com.zteits.bill.domain.sdomain.ParkFeeTempDO; import com.zteits.bill.util.BillingInfoUtil; import com.zteits.clouds.api.apibase.bean.BizResult; import com.zteits.clouds.api.apibase.constants.ErrorType; import com.zteits.clouds.api.apibase.constants.ParkOrderTypeEnum; import com.zteits.clouds.api.apibase.exception.BizException; import com.zteits.clouds.api.dto.bill.billing.dto.BillingResultDTO; import com.zteits.clouds.api.dto.bill.billing.param.BillingReq; import com.zteits.clouds.api.dto.bill.billinglog.dto.BillingLogDTO; import com.zteits.clouds.api.dto.bill.billinglog.dto.BillingLogDetailDTO; import com.zteits.clouds.api.dto.bill.billinglog.dto.BillingLogOfDayDTO; import com.zteits.clouds.api.dto.bill.billingrule.dto.BillingRuleCollectDTO; import com.zteits.clouds.api.dto.bill.billingrule.dto.BillingRuleDTO; import com.zteits.clouds.api.dto.bill.cloudbilling.dto.FreeSectionDTO; import com.zteits.clouds.api.dto.bill.cloudbilling.param.CloudBillingReq; import com.zteits.clouds.api.dto.bill.dto.TVipAreaCardCustInfoDTO; import com.zteits.clouds.api.dto.bill.param.TVipAreaCardCustInfoQueryRequest; import com.zteits.clouds.api.dto.bill.vipcard.VipCardCustInfoDTO; import com.zteits.clouds.api.dto.bill.vipcard.VipCardCustSubPlateInfoDTO; import com.zteits.clouds.api.dto.bill.vipcard.param.QueryIsBuyVipCardCustReq; import com.zteits.clouds.api.dto.bill.vipcard.param.VipCardInfoReq; import com.zteits.clouds.api.dto.bill.whitelist.CarNumIsFreeDTO; import com.zteits.clouds.api.dto.bill.whitelist.param.QueryCarNumIsWhitelistRequest; import com.zteits.clouds.api.service.bill.billing.BillingService; import com.zteits.clouds.api.service.bill.cloudbilling.CloudBillingService; import com.zteits.clouds.api.service.bill.viparea.TVipAreaCardCustInfoService; import com.zteits.clouds.api.service.bill.vipcard.VipCardCustInfoService; import com.zteits.clouds.api.service.bill.whitelist.WhitelistService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; /** * Copyright: Copyright (c) 2017 zteits * * @ClassName: com.zteits.billing.biz.billing * @Description: * @version: v1.0.0 * @author: atao * @date: 2017/11/1 上午11:15 Modification History: Date Author Version Description * ---------------------------------------------------------* 2017/11/1 atao v1.0.0 创建 */ @Component public class BillingServiceImpl implements BillingService { private static final Logger log = LoggerFactory.getLogger(BillingServiceImpl.class); @Autowired private BillingInnerService billingInnerService; @Autowired private BillingLogDao billingLogDao; @Autowired private BillingRuleInnerService billingRuleInnerService; @Autowired private VipCardCustInfoService vipCardCustInfoService; @Autowired private WhitelistService whitelistService; @Autowired private WhitelistDao whitelistDao; @Autowired private TVipAreaCardCustInfoService tVipAreaCardCustInfoService; @Autowired private CloudBillingService cloudBillingService; @Override public BizResult billing(BillingReq req) { validateReq(req); //调用云计费 BizResult cloudBillResult = this.billWithCloud(req); if(null != cloudBillResult){ return cloudBillResult; } TimeInterval timer = DateUtil.timer(); log.info("{}===计费处理===start==", req.getBaseRequest().getRequestId()); log.info("{}===计费处理=== req:{}", req.getBaseRequest().getRequestId(), JSONObject.toJSONString(req)); timer.start(); //真实车型 Integer realCarType = req.getCarType(); if (CarTypeEnum.OUT_LIMIT_LARGE_CAR.val().equals(req.getCarType())) { //超标大型车 req.setCarType(CarTypeEnum.LARGE_CAR.val()); } if (CarTypeEnum.OUT_LIMIT_SMALL_CAR.val().equals( req.getCarType())) { //超标小型车 req.setCarType(CarTypeEnum.SMALL_CAR.val()); } if (CarTypeEnum.TRUCK_SMALL_CAR.val().equals(req.getCarType())) { req.setCarType(CarTypeEnum.SMALL_CAR.val()); } if (CarTypeEnum.TRUCK_LARGE_CAR.val().equals(req.getCarType())) { req.setCarType(CarTypeEnum.LARGE_CAR.val()); } /** * 初始化计费日志 */ BillingLogDTO billingLogDTO = BillingInfoUtil.init(req); /** * 计算停车时长,单位为秒 */ Long parkDuration = DateUtil.between(req.getInTime(), req.getOutTime(), DateUnit.SECOND); BillingResultDTO resultDTO = new BillingResultDTO(); resultDTO.setCarNo(req.getCarNo()); resultDTO.setParkDuration(parkDuration); resultDTO.setBillingLogId(billingLogDTO.getLogId()); /** * 查询计费规则集合对象,获取免费时长 及 免费时长减免类型 */ BillingRuleCollectDTO collectDTO = billingRuleInnerService.queryBillingRuleCollectByPlNo(req.getPlNo(), req.getInTime(), req.getCarType()); if (collectDTO == null) { throw new BizException(ErrorType.BIZ_ERROR, "未查询到生效的计费规则集合"); } /** * 获取免费时长 */ Long freeTime = collectDTO.getFreeTime(); freeTime = (freeTime != null && freeTime > 0) ? freeTime : 0; billingLogDTO.setFreeTime(freeTime); billingLogDTO.setFreeTimeType(collectDTO.getFreeTimeType()); /** * 如果停车时长小于免费时长, 费用为0 */ if (parkDuration <= freeTime) { billingLogDTO.setMaxFee(collectDTO.getMaxCharge()); billingLogDTO.setRealFee(0L); billingLogDTO.setReceFee(0L); //短时停车免费 resultDTO.setFreeType(ParkOrderTypeEnum.ShortTimeParkFree.getValue()); resultDTO.setParkFee(0L); return new BizResult<>(resultDTO); } /** * 查询是否货车免费半小时白名单车辆 */ try { //获取白名单货车免费时长 String trunkFreeTimeStr = SysCodeValueCacheUtil.queryCodeNameByCodeValue( CodeValKindEnum.TRUCK_CAR_WHITE_LIST, CodeValueEnum.TRUCK_CAR_WHITE_LIST_FREE_TIME); Integer trunkFreeTime = 0; if (StringUtils.isNotEmpty(trunkFreeTimeStr)) { trunkFreeTime = Integer.valueOf(trunkFreeTimeStr); } log.info("{}===计费处理: 车牌号从缓存中获取货车白名单免费时长{}", req.getBaseRequest().getRequestId(), trunkFreeTimeStr); if (trunkFreeTime > 0) { QueryCarNumIsWhitelistRequest request = new QueryCarNumIsWhitelistRequest(); request.setCarNumber(req.getCarNo()); request.setPlNo(req.getPlNo()); request.setCurrentDate(req.getOutTime()); request.setChargerType(WhitelistEnum.CHARGE_TYPE_4.getKey()); WhitelistIsFreeDO whitelistIsFreeDO = whitelistDao.queryWhitelistByCarNumAndPlNo(request); boolean truckFlag = CarTypeEnum.TRUCK_SMALL_CAR.val().equals(realCarType) || CarTypeEnum.TRUCK_LARGE_CAR .val().equals(realCarType) || (null != whitelistIsFreeDO && WhitelistEnum.CHARGE_TYPE_4.getKey() .equals( whitelistIsFreeDO.getChargeType())); if (truckFlag) { log.info("{}===计费处理: 车牌号 {} 属于白名单货车,免费时长为:{}", req.getBaseRequest().getRequestId(), req.getCarNo(), trunkFreeTime); if (parkDuration <= trunkFreeTime) { resultDTO.setParkFee(0L); resultDTO.setFreeType(ParkOrderTypeEnum.WhiteListCarFree.getValue()); return new BizResult<>(resultDTO); } } } } catch (Exception e) { log.error("{}===计费处理: 查询处理白名单货车免费时长异常", req.getBaseRequest().getRequestId(), e); } /** * 免费时长进行减免 并且 停车时长小于等于免费时长 费用为0 if (!BillingFreeTimeTypeEnum.BILLING_FREE_TIME_NO_FREE.getVal().equals(collectDTO.getFreeTimeType()) && parkDuration <= freeTime) { log.info("停车时长小于免费时长,费用为0"); billingLogDTO.setMaxFee(collectDTO.getMaxCharge()); billingLogDTO.setRealFee(0L); billingLogDTO.setReceFee(0L); resultDTO.setParkFee(0L); return new BizResult<>(resultDTO); } */ /** * 停车时长减免 免费时长 按照进场时间减免 */ if (BillingFreeTimeTypeEnum.BILLING_FREE_TIME_FREE_IN_TIME.getVal().equals(collectDTO.getFreeTimeType())) { log.info("按照进场时间减免停车时长"); BillingInfoUtil.newDayLog(req.getInTime()); BillingLogOfDayDTO dayDTO = BillingInfoUtil.getLastBillingLogDay(); dayDTO.setShowDay(false); dayDTO.setRealFeeOfDay(0L); dayDTO.setReceFeeOfDay(0L); dayDTO.setMaxFeeOfDay(-1L); dayDTO.setFreeReason("按照进场时间减免时长"); BillingLogDetailDTO detailDTO = BillingInfoUtil.newDayLogDetail(); detailDTO.setBillingTimeLimitStart(0); detailDTO.setBillingTimeLimitEnd(0); detailDTO.setDetailFee(0L); detailDTO.setFreeReason("减免免费时长"); detailDTO.setStartTime(req.getInTime()); req.setInTime(DateUtil.offsetSecond(req.getInTime(), freeTime.intValue())); detailDTO.setEndTime(req.getInTime()); } /** * 停车时长减免 免费时长 按照出场时间减免 */ if (BillingFreeTimeTypeEnum.BILLING_FREE_TIME_FREE_OUT_TIME.getVal().equals(collectDTO.getFreeTimeType())) { log.info("按照出场时间减免停车时长"); BillingInfoUtil.newDayLog(req.getInTime()); BillingLogOfDayDTO dayDTO = BillingInfoUtil.getLastBillingLogDay(); dayDTO.setShowDay(false); dayDTO.setRealFeeOfDay(0L); dayDTO.setReceFeeOfDay(0L); dayDTO.setMaxFeeOfDay(-1L); dayDTO.setFreeReason("按照出场时间减免时长"); BillingLogDetailDTO detailDTO = BillingInfoUtil.newDayLogDetail(); detailDTO.setBillingTimeLimitStart(0); detailDTO.setBillingTimeLimitEnd(0); detailDTO.setDetailFee(0L); detailDTO.setFreeReason("减免免费时长"); detailDTO.setStartTime(req.getInTime()); req.setOutTime(DateUtil.offsetSecond(req.getOutTime(), 0 - freeTime.intValue())); detailDTO.setEndTime(req.getInTime()); } /** * 按时间切分后的日期进行计费 */ ParkFeeTempDO parkFeeBean = billingOfSpiltDay(req, collectDTO); /** * 放入计费费用 及 计费时长 */ resultDTO.setParkFee(parkFeeBean.getFee()); resultDTO.setParkFeeDuration(parkFeeBean.getParkFeeDuration()); log.info("{}===计费处理===end==", req.getBaseRequest().getRequestId()); log.info("{}===计费处理=== res:{}", req.getBaseRequest().getRequestId(), JSONObject.toJSONString(resultDTO)); log.info("{}===计费处理=== 耗费:{}毫秒", req.getBaseRequest().getRequestId(), timer.interval()); log.info("{}===计费处理=== 计费log={}", req.getBaseRequest().getRequestId(), JSONObject.toJSONString(billingLogDTO)); /** * 如果计费日志需要保存,进行日志保存 */ if (BillingLogEnum.BILLING_LOG_SAVE.getVal().equals(req.getIsShowLog())) { billingLogDao.saveBillingLog(billingLogDTO); } return new BizResult<>(resultDTO); } /** * 按照白天夜间分割时间进行计费 * * @param req 计费请求对象 * @param collectDTO 计费规则集合 * @return 费用 */ private ParkFeeTempDO billingOfSpiltDay(BillingReq req, BillingRuleCollectDTO collectDTO) { Long freeTime = collectDTO.getFreeTime(); /** * 获取进出场分隔开的时间列表 */ List spiltBeans = DateSpiltUtil.spiltTimeOfOndDay(req.getInTime(), req.getOutTime(), collectDTO.getDayStartTime(), collectDTO.getDayEndTime()); Long fee = 0L; Long parkFeeDuration = 0L; /** * 计费规则中本次最高收费 */ Integer maxCharge = 0; QueryCarNumIsWhitelistRequest request; request = new QueryCarNumIsWhitelistRequest(); request.setCarNumber(req.getCarNo()); request.setCarType(req.getCarType()); request.setPlNo(req.getPlNo()); request.setSysCode(req.getSysCode()); BizResult bizResult; BizResult isBuyVipCardResult; /** * 按照切分的日期 计算每天的费用 */ for (DateSpiltBean bean : spiltBeans) { try { /** * 查询会员卡免费信息 */ request.setCurrentDate(bean.getStartDate()); log.info("查询会员卡免费信息入参为{}" + JSONObject.toJSONString(request)); bizResult = vipCardCustInfoService.queryCarNumIsBuyVipCard(request); log.info("查询会员卡免费信息结果为{}" + JSONObject.toJSONString(bizResult)); CarNumIsFreeDTO dto = ResultUtils.getBizResultData(bizResult); /** * 车辆 会员卡用户信息 */ if (dto.getIsFree() == CarNumIsFreeDTO.FREE) { /** * 是会员卡返回0 */ fee += 0L; continue; } QueryIsBuyVipCardCustReq queryIsBuyVipCardCustReq = new QueryIsBuyVipCardCustReq(); queryIsBuyVipCardCustReq.setCarNumber(req.getCarNo()); queryIsBuyVipCardCustReq.setPlNo(req.getPlNo()); queryIsBuyVipCardCustReq.setDateTime(bean.getStartDate()); log.info("查询区域(全域)会员卡免费信息入参为{}" + JSONObject.toJSONString(queryIsBuyVipCardCustReq)); isBuyVipCardResult = tVipAreaCardCustInfoService.queryIsBuyVipCardCust( queryIsBuyVipCardCustReq); log.info("查询区域(全域)会员卡免费信息结果为{}" + JSONObject.toJSONString(isBuyVipCardResult)); Boolean isBuyFlag = ResultUtils.getBizResultData(isBuyVipCardResult); /** * 车辆 会员卡用户信息 */ if (isBuyFlag) { /** * 是会员卡返回0 */ fee += 0L; continue; } } catch (Exception e) { log.error("调用查询会员卡免费结果信息捕获了异常", e); throw new BizException(ErrorType.BIZ_ERROR, "捕获异常:" + e.getMessage()); } /** * 根据停车编码、车辆类型、进场日期获取计费规则 */ BillingRuleDTO billingRuleDTO = billingInnerService.queryRuleInfoByPlNOAndCarType(req.getPlNo(), req.getCarType(), bean.getStartDate()); /** * 新增一天的日志 */ BillingLogOfDayDTO billingLogOfDayDTO = BillingInfoUtil.newDayLog(bean.getStartDate()); billingLogOfDayDTO.setApplyDayType(billingLogOfDayDTO.getApplyDayType()); billingLogOfDayDTO.setCrossTimeRuTleType(billingLogOfDayDTO.getCrossTimeRuTleType()); billingLogOfDayDTO.setIsHoliday(billingLogOfDayDTO.getIsHoliday()); billingLogOfDayDTO.setMaxFeeOfDay(billingLogOfDayDTO.getMaxFeeOfDay()); billingLogOfDayDTO.setRuleNo(billingRuleDTO.getRuleNo()); if (null == billingRuleDTO) { /** * 根据日期查不到计费规则,则该时间段费用为0. */ billingLogOfDayDTO.setReceFeeOfDay(0L); billingLogOfDayDTO.setRealFeeOfDay(0L); billingLogOfDayDTO.setFreeReason("该段时间未查询到计费规则,默认停车费用为0元"); continue; } /** * 获取所有规则中 单次停车收费最大值 用于与最终的费用结果进行对比 */ maxCharge = maxCharge >= billingRuleDTO.getMaxCharge() ? maxCharge : billingRuleDTO.getMaxCharge(); /** * 默认夜间免费,判断白天时间 是否 小于免费时长 如果小于在免费 */ Date nightTimeOfDay = DateUtil.parse( DateUtil.formatDate(bean.getStartDate()) + " " + DateUtil.formatTime(collectDTO.getDayEndTime())); Long duration = DateUtil.between(bean.getStartDate(), nightTimeOfDay, DateUnit.SECOND); Long feeOfDay = 0L; /** * 默认夜间免费(赤峰 和 丹阳这么处理), 判断 进场时间 与白天夜间分界线 之间的停车时长是否在免费时长内,如果在的话就免费 */ boolean flag = duration <= freeTime && (Long.valueOf(10003).equals(collectDTO.getOrgId()) || Long.valueOf( 10064).equals(collectDTO.getOrgId())); if (flag) { feeOfDay = 0L; } else { ParkFeeTempDO parkFeeTempDO = billingInnerService.billingFee(bean.getStartDate(), bean.getEndDate(), billingRuleDTO); feeOfDay = parkFeeTempDO.getFee(); parkFeeDuration += parkFeeTempDO.getParkFeeDuration(); } /** *如果总费用为0,并且每天的总时长小于等于免费时长,则费用为0,不计费 */ if (fee.equals(0L) && DateUtil.between(bean.getStartDate(), bean.getEndDate(), DateUnit.SECOND) <= freeTime) { continue; } billingLogOfDayDTO.setReceFeeOfDay(feeOfDay); if (billingRuleDTO.getDayMaxCharge() > 0) { /** * 与单日最大收费进行对比 */ feeOfDay = feeOfDay <= billingRuleDTO.getDayMaxCharge() ? feeOfDay : billingRuleDTO.getDayMaxCharge(); billingLogOfDayDTO.setRealFeeOfDay(feeOfDay); } if (feeOfDay != 0) { /** * 查询白名单免费信息 */ request.setCurrentDate(bean.getEndDate()); bizResult = whitelistService.queryCarNumIsOnlyOneFeeEveryDay(request); CarNumIsFreeDTO dto = ResultUtils.getBizResultData(bizResult); if (dto.getIsFree() == CarNumIsFreeDTO.FREE) { /** * 白名单免费 */ feeOfDay = 0L; } if (dto.getIsFree() == CarNumIsFreeDTO.NO_FREE && dto.getMaxCharge() != null) { /** * 白名单按照固定费率收费 */ feeOfDay = dto.getMaxCharge(); } } /** * 当日费用叠加 */ fee += feeOfDay; } BillingLogDTO billingLogDTO = BillingInfoUtil.getBillingLog(); billingLogDTO.setReceFee(fee); if (maxCharge > 0) { /** * 与单次最高限价相比 */ fee = fee < maxCharge ? fee : maxCharge; } billingLogDTO.setMaxFee(Long.valueOf(maxCharge)); billingLogDTO.setRealFee(fee); return new ParkFeeTempDO(fee, parkFeeDuration); } private void validateReq(BillingReq req) { if (StringUtils.isBlank(req.getCarNo())) { throw new BizException(ErrorType.PARAMM_NULL, "车牌号"); } if (StringUtils.isBlank(req.getPlNo())) { throw new BizException(ErrorType.PARAMM_NULL, "停车场编号"); } if (null == req.getInTime()) { throw new BizException(ErrorType.PARAMM_NULL, "进场时间"); } if (null == req.getOutTime()) { throw new BizException(ErrorType.PARAMM_NULL, "出场时间"); } if (null == req.getCarType()) { throw new BizException(ErrorType.PARAMM_NULL, "车辆类型"); } } private BizResult billWithCloud(BillingReq req) { BizResult resultDTO = null; try { String cloudeBillPlNos = SysCodeValueCacheUtil.queryCodeNameByCodeValue( CodeValKindEnum.PL_BILLL_4_CLOUD_RULE, CodeValueEnum.PL_BILLL_4_CLOUD_RULE_PLNO); if (StringUtils.isBlank(cloudeBillPlNos)) { return null; } List plNos = Arrays.asList(cloudeBillPlNos.split(";")); if (CollectionUtils.isEmpty(plNos) || !plNos.contains(req.getPlNo())) { return null; } //获取免费时段 List freeSectionDTOList = new ArrayList<>(); VipCardInfoReq vipCardInfoReq = new VipCardInfoReq(); vipCardInfoReq.setCarNumber(req.getCarNo()); vipCardInfoReq.setPlNo(req.getPlNo()); vipCardInfoReq.setSysCode("sysCode"); // 获取该车所有的免费时段-会员车、区域卡车、子母车中的固定车 BizResult> vipBizResponse = vipCardCustInfoService.queryAllCardCustInfoByParkcodeAndCarnumber(vipCardInfoReq); BizResult> vipAreaBizResponse = tVipAreaCardCustInfoService.queryAllAreaVipCardByParkcodeAndCarnumber(vipCardInfoReq); // 会员车 List vipCardCustInfoDTOList = vipBizResponse.getData() == null ? new ArrayList<>() : vipBizResponse.getData(); log.info("{}的会员卡信息: {}", req.getCarNo(), JSON.toJSONString(vipCardCustInfoDTOList)); vipCardCustInfoDTOList.forEach(dto -> { int hourOfValidStartTime = dto.getValidStartTime().getHours(); int minOfValidStartTime = dto.getValidStartTime().getMinutes(); int secOfValidStartTime = dto.getValidStartTime().getSeconds(); int hourOfValidEndTime = dto.getValidEndTime().getHours(); int minOfValidEndTime = dto.getValidEndTime().getMinutes(); int secOfValidEndTime = dto.getValidEndTime().getSeconds(); // 如果月卡每天生效时间是00:00 到 23:59 代表全天月卡生效 if(hourOfValidStartTime == 0 && minOfValidStartTime == 0 && hourOfValidEndTime == 23 && minOfValidEndTime == 59) { FreeSectionDTO freeSectionDTO = new FreeSectionDTO(); freeSectionDTO.setStartTime(dto.getEffDate()); freeSectionDTO.setEndTime(dto.getExpDate()); freeSectionDTOList.add(freeSectionDTO); }else{ // 否则月卡每天生效时间段进行判断 提取每天没费时间加入至计费的免费时段 List list = this.genVaildDate(dto.getEffDate(), dto.getExpDate(), dto.getValidStartTime(), dto.getValidEndTime()); log.info("{}的会员卡免费时段: {}", req.getCarNo(), JSON.toJSONString(vipCardCustInfoDTOList)); freeSectionDTOList.addAll(list); } }); // 区域卡车 List tVipAreaCardCustInfoDTOList = vipAreaBizResponse.getData() == null ? new ArrayList<>() : vipAreaBizResponse.getData(); tVipAreaCardCustInfoDTOList.forEach(dto -> { FreeSectionDTO freeSectionDTO = new FreeSectionDTO(); freeSectionDTO.setStartTime(dto.getEffDate()); freeSectionDTO.setEndTime(dto.getExpDate()); freeSectionDTOList.add(freeSectionDTO); }); CloudBillingReq cloudBillingReq = new CloudBillingReq(); cloudBillingReq.setCarNo(req.getCarNo()); cloudBillingReq.setAreaId(0); cloudBillingReq.setCarType(req.getCarType()); cloudBillingReq.setFreeSectionDTOList(freeSectionDTOList); cloudBillingReq.setInTime(req.getInTime()); cloudBillingReq.setOutTime(req.getOutTime()); cloudBillingReq.setPlNo(req.getPlNo()); log.info("调用云计费 req={}", JSONObject.toJSONString(cloudBillingReq)); resultDTO = cloudBillingService.billing(cloudBillingReq); log.info("调用云计费 res={}", JSONObject.toJSONString(resultDTO)); } catch (Exception e) { log.error("查询是否云计费异常",e); } return resultDTO; } /** * 根据会员卡当天有效时间段,将用户会员卡有效期,拆成每天有效时段, * 并组成List * @param eff_date * @param exp_date * @param eff_time * @param exp_time * @return */ private List genVaildDate(Date eff_date, Date exp_date, Time eff_time, Time exp_time) { Long oneDay = 1000 * 60 * 60 * 24L; Long time = eff_date.getTime(); Long endTime = exp_date.getTime(); List freeSectionDTOList = new ArrayList<>(); DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); while (time <= endTime) { FreeSectionDTO freeSectionDTO = new FreeSectionDTO(); Date d = new Date(time); Calendar calendar=Calendar.getInstance(); calendar.setTime(d); calendar.set(Calendar.HOUR_OF_DAY, eff_time.getHours()); calendar.set(Calendar.MINUTE, eff_time.getMinutes()); calendar.set(Calendar.SECOND, eff_time.getSeconds()); Date eff_date_temp = calendar.getTime(); freeSectionDTO.setStartTime(eff_date_temp); calendar.set(Calendar.HOUR_OF_DAY, exp_time.getHours()); calendar.set(Calendar.MINUTE, exp_time.getMinutes()); calendar.set(Calendar.SECOND, exp_time.getSeconds()); Date exp_date_temp = calendar.getTime(); // 有效时段跨天 if(eff_date_temp.after(exp_date_temp)){ exp_date_temp = cn.hutool.core.date.DateUtil.offsetDay(exp_date_temp, 1); Date real_exp_date = new Date(exp_date.getTime()); real_exp_date.setHours(23); real_exp_date.setMinutes(59); real_exp_date.setSeconds(59); if(exp_date_temp.after(real_exp_date)){ exp_date_temp = new Date(exp_date.getTime()); exp_date_temp.setHours(23); exp_date_temp.setMinutes(59); exp_date_temp.setSeconds(59); } } freeSectionDTO.setEndTime(exp_date_temp); freeSectionDTOList.add(freeSectionDTO); log.info("开始时间:{},结束时间:{}", df.format(eff_date_temp), df.format(exp_date_temp)); time += oneDay; } return freeSectionDTOList; } }