• 支付方法一周年活动时间算法


    package net.joystart.order.service.impl;
    
    import java.math.BigDecimal;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.List;
    
    import javax.annotation.Resource;
    
    import org.apache.commons.lang3.StringUtils;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    import net.joystart.common.util.ConfigUtil;
    import net.joystart.common.util.HttpRequestUtil;
    import net.joystart.common.util.JSONProcesser;
    import net.joystart.common.util.date.UtilTimeFormatter;
    import net.joystart.common.util.log.Log4jTask;
    import net.joystart.enterprise.dao.CompanyCostMapper;
    import net.joystart.enterprise.entity.CompanyCost;
    import net.joystart.order.dao.CostVehiclePriceMapper;
    import net.joystart.order.dao.OrderCostItemMapper;
    import net.joystart.order.dao.OrderInsuranceMapper;
    import net.joystart.order.dao.OrderMapper;
    import net.joystart.order.entity.CostVehiclePrice;
    import net.joystart.order.entity.OrderCostItem;
    import net.joystart.order.entity.OrderDetail;
    import net.joystart.order.entity.OrderInsurance;
    import net.joystart.order.entity.OrderVehicleRuleItem;
    import net.joystart.order.entity.PriceLog;
    import net.joystart.order.entity.ResultMilage;
    import net.joystart.order.service.IOrderDetailedSerivce;
    import net.joystart.task.vehicleTask.dao.NightshiftIntervalMapper;
    import net.joystart.task.vehicleTask.entity.NightshiftInterval;
    import net.joystart.vehicle.dao.BranchMapper;
    import net.joystart.vehicle.dao.ParkinglotMapper;
    import net.joystart.vehicle.entity.Branch;
    import net.joystart.vehicle.entity.Parkinglot;
    import net.joystart.vehicle.service.IOperationService;
    import net.joystart.vehicle.service.impl.OperationServiceImpl;
    
    /***
     * 订单价格计算类
     * @author lidc
     */
    @Service(value = "orderDetailedSerivce")
    @Transactional
    public class OrderDetailedSerivceImpl implements IOrderDetailedSerivce {
    
    	@Resource
    	OrderMapper orderMapper;
    
    	@Resource
    	CostVehiclePriceMapper costVehiclePriceMapper;
    
    	@Resource
    	OrderInsuranceMapper orderInsuranceMapper;
    
    	@Resource
    	OrderCostItemMapper orderCostItemMapper;
    
    	@Resource
    	ParkinglotMapper parkinglotMapper;
    
    	@Resource
    	BranchMapper branchMapper;
    
    	@Resource
    	CompanyCostMapper companyCostMapper;
    
    	@Resource
    	NightshiftIntervalMapper nightshiftIntervalMapper;
    
    	@Resource
    	@Qualifier("ControlService")
    	IOperationService ControlService;
    
    	final Logger logger = LoggerFactory.getLogger(OperationServiceImpl.class);
    
    	private static String ControlUrl = ConfigUtil.pro.getProperty("ControlUrl");
    
    	//一周年参数配置
    
    	private static String flag = ConfigUtil.pro.getProperty("EnableFlag");
    
    	private static String startTimes = ConfigUtil.pro.getProperty("startTimes");
    
    	private static String endTimes = ConfigUtil.pro.getProperty("endTimes");
    
    	/***
    	 * 计算订单价格明细
    	 */
    	@Override
    	public List<PriceLog> getPriceLogList(Integer orderId, Long pauseTime) {
    		// 获取订单信息
    		OrderDetail oDetail = orderMapper.getOrderInfo(orderId);
    		if(oDetail!=null){
    			Integer parkId = oDetail.getRentparkid();
    			Integer branchId = oDetail.getReturnbranchid();
    			return getPriceLogList(orderId, pauseTime, parkId, branchId);
    		}
    		else
    		{
    			return getPriceLogList(orderId, pauseTime, null, null);
    		}
    	}
    
    	/***
    	 * 计算订单价格明细(带停车费)
    	 */
    	@Override
    	public List<PriceLog> getPriceLogList(Integer orderId, Long pauseTime, Integer parkId, Integer branchId) {
    
    		List<PriceLog> list = new ArrayList<>();
    
    		// 是否计算停车减免
    		boolean isStopMoney = false;
    
    
    		//还车停车费
    		double returnStopMoney = 0;
    
    		// 获取订单信息
    		OrderDetail oDetail = orderMapper.getOrderInfo(orderId);
    		if(oDetail!=null && Integer.valueOf(40).equals(oDetail.getOrderstatus()!=null)){
    			PriceLog log = new PriceLog();
    			log.setTypeText("订单已取消");
    			log.setPrice(0.0);
    			log.setType(1);
    			list.add(log);
    			return list;
    		}
    
    		//一周年活动
    		if(flag!=null && "1".equals(flag)){
    			return onePriceLog(orderId, pauseTime, parkId,branchId);
    		}
    
    		// 获取计费信息
    		CostVehiclePrice cvp = costVehiclePriceMapper.selectByVehicleModelId(oDetail);
    
    		// 获取订单包含的保险
    		List<OrderInsurance> orderInsuranceList = orderInsuranceMapper.getInsuranceByOrderId(orderId);
    
    		// 获取活动信息
    		List<OrderVehicleRuleItem> ruleItemList = orderMapper.getOrderVehicleRuleItem(orderId);
    
    		// 开始和结束时间不参与计算(算里程使用)
    		Date allStartDate = oDetail.getChargingstartdate();
    		Date allEndDate = oDetail.getReturnvehicledate();
    
    		// 取订单开始时间
    		Date startDate = oDetail.getChargingstartdate();
    		if (startDate == null)// 没有开始时间
    		{
    			return list;
    		}
    		for (OrderVehicleRuleItem ovRuleItem : ruleItemList) {
    			if (ovRuleItem != null) {
    
    				// 减去活动的开始时间
    				Date tempStartDate = new Date(startDate.getTime() + (ovRuleItem.getDuration() * 60 * 1000));
    				list.add(CreatePriceLog(
    						ovRuleItem.getName() + "(" + UtilTimeFormatter.getDatemdhm(startDate.getTime()) + "~"
    								+ UtilTimeFormatter.getDatemdhm(tempStartDate.getTime()) + ")",
    						(double) 0, startDate.getTime(), tempStartDate.getTime(), 3, (double) 0));
    				startDate = tempStartDate;
    			}
    		}
    
    		// 取订单结束时间
    		Date endDate = oDetail.getReturnvehicledate();
    		// 等于1说明是结单的时候用
    		if (pauseTime == 1 || pauseTime == 2) {
    			isStopMoney = true;
    		}
    		// 如果没有结束时间则取当前时间
    		if (endDate == null) {
    			endDate = new Date();
    		}
    		if (allEndDate == null) {
    			allEndDate = new Date();
    		}
    
    		long diff = endDate.getTime() - startDate.getTime();
    		// 减去暂停时间(最后结账时)
    		//diff = diff - pauseTime;
    		// 计算天数
    		long days = diff / (1000 * 60 * 60 * 24);
    		// 计算是否正好整天
    
    		// 计算天数
    		double dDays = (double) diff / (1000 * 60 * 60 * 24);
    
    		// 加上全日租后的开始日期
    		Date aStartDate = UtilTimeFormatter.afterNDay((int) days, startDate);
    
    		Boolean isNightSale = false; // 是否设置了夜间优惠价格
    		Boolean isNightOver = false; // 是否订单是在夜间
    
    		// 计算全日租
    		if (days != 0) {
    			list.add(CreatePriceLog(
    					"整日租" + days + "天(" + UtilTimeFormatter.getDatemdhm(startDate.getTime()) + "~"
    							+ UtilTimeFormatter.getDatemdhm(aStartDate.getTime()) + ")",
    					(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount() * days), startDate.getTime(),
    					aStartDate.getTime(), 0, (double) 0));
    		} else {
    			// 夜间特惠价格要求订单开始结束时间必须在当天18点到次日9点之间才可以
    			// 且设置的夜间特惠价格必须不能为空和大于0
    			if (null != cvp.getNightsalemoney() && cvp.getNightsalemoney().doubleValue() > 0) {
    				isNightSale = true;
    			}
    		}
    
    		if (dDays > days) { // 有小数,不是整天
    
    			Integer intStart = 17;
    			Integer intEnd = 9;
    			NightshiftInterval ns = nightshiftIntervalMapper.selectByPrimaryKeyType(2);
    			if(ns!= null){
    				Calendar calendar = Calendar.getInstance();
    				if(ns.getStarttime() != null)
    				{
    					Date date = ns.getStarttime();
    					calendar.setTime(date);
    					String strHour = new SimpleDateFormat("HH").format(calendar.getTime());
    					if(StringUtils.isNoneBlank(strHour))
    					{
    						intStart = Integer.valueOf(strHour);
    					}
    				}
    
    				if(ns.getEndtime() != null)
    				{
    					Date date = ns.getEndtime();
    					calendar.setTime(date);
    					String strHour = new SimpleDateFormat("HH").format(calendar.getTime());
    					if(StringUtils.isNoneBlank(strHour))
    					{
    						intEnd = Integer.valueOf(strHour);
    					}
    				}
    			}
    
    			//endDate = new Date(endDate.getTime() - pauseTime);
    			endDate = new Date(endDate.getTime());
    
    			// 开始时间
    			Calendar calendar_as = Calendar.getInstance();
    			calendar_as.setTime(aStartDate);
    
    			// 结束时间
    			Calendar calendar_e = Calendar.getInstance();
    			calendar_e.setTime(endDate);
    
    
    			String mushroomCarModeId = ConfigUtil.pro.getProperty("mushroomCar.ModeId");
    			int mushroomCarProvinceId = new Integer(ConfigUtil.pro.getProperty("mushroomCar.ProvinceId"));
    			String vmodeId = cvp.getVehiclemodelid().toString();
    
    			//旅游车计价2017.10.1新增
    			//根据车型和城市规则匹配
    			if(mushroomCarModeId.contains(vmodeId) && cvp.getProvinceid().intValue() == mushroomCarProvinceId){
    				// 时间价格
    				Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    				long min = mdiff / (1000 * 60);
    				//半小时为一个计价单位
    				long halfHour = (min + cvp.getPricestep() + 1) / cvp.getPricestep();
    				double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * halfHour);
    
    				// 总价格
    				double sumMoney = minMoney;
    
    				// 如果总价格大于整日租价格
    				if (sumMoney > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    					sumMoney = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					list.add(CreatePriceLog(
    							"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    									+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    							sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    				} else {// 否则显示分时记价
    					// 时间
    					list.add(CreatePriceLog(
    							UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    									+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    							minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    				}
    				//普通车计价
    			}else{
    				// 当天9点
    				Calendar calendar_9 = Calendar.getInstance();
    				calendar_9.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE), intEnd, 5, 0);
    				calendar_9.set(Calendar.MILLISECOND, 0);
    
    				// 当天18点
    				Calendar calendar_18 = Calendar.getInstance();
    				calendar_18.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE), intStart, 0, 0);
    				calendar_18.set(Calendar.MILLISECOND, 0);
    				// 隔天9点
    				Calendar calendar_Add1_9 = Calendar.getInstance();
    				calendar_Add1_9.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE) + 1, intEnd, 5, 0);
    				calendar_Add1_9.set(Calendar.MILLISECOND, 0);
    				// 隔天18点
    				Calendar calendar_Add1_18 = Calendar.getInstance();
    				calendar_Add1_18.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE) + 1, intStart, 0, 0);
    				calendar_Add1_18.set(Calendar.MILLISECOND, 0);
    				// 开始时间小于等于当天9点,结束时间小于等于当天9点 只是夜间
    				if (calendar_as.compareTo(calendar_9) <= 0 && calendar_e.compareTo(calendar_9) <= 0) {
    					isNightOver = true;
    					// 时间价格
    					Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					// 总价格
    					double sumMoney = minMoney;
    					// 如果总价格大于夜间特惠价格
    					if (sumMoney > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoney = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						list.add(CreatePriceLog(
    								"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 否则显示分时记价
    
    						// 时间
    						list.add(CreatePriceLog(
    								UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    								minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					}
    
    				}
    
    				// 开始时间小于等于当天9点,结束时间小于等于隔天9点且大于当天9点
    				if (calendar_as.compareTo(calendar_9) <= 0 && calendar_e.compareTo(calendar_Add1_9) <= 0
    						&& calendar_e.compareTo(calendar_9) > 0) {
    					// 总价格
    					double sumMoney9 = (double) 0;
    					double sumMoney18 = (double) 0;
    					double sumMoneyAdd9 = (double) 0;
    
    					// 开始时间到9点的时间(夜)
    					Long mdiff = calendar_9.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					// 9点之前的总价格
    					sumMoney9 = minMoney9;
    					// 如果总价格大于夜间特惠,夜间特惠
    					if (sumMoney9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoney9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    					}
    
    					// 9点到结束时间的时间(小于18点到结束时间)
    					double minMoney9E = (double) 0;
    
    					if (calendar_e.compareTo(calendar_18) < 0)// 小于18点,结束时间
    					{
    						// 时间
    						mdiff = calendar_e.getTimeInMillis() - calendar_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoney9E = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					} else {// 大于18点
    						// 时间
    						mdiff = calendar_18.getTimeInMillis() - calendar_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoney9E = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					// 9点-18点(结束时间)的总价格
    					sumMoney18 = minMoney9E;
    					if (sumMoney18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoney18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					}
    
    					// 18点到第二天9点的时间价格
    					double minMoney18E = (double) 0;
    
    					if (calendar_e.compareTo(calendar_18) > 0) {
    						// 时间
    						mdiff = calendar_e.getTimeInMillis() - calendar_18.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoney18E = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					sumMoneyAdd9 = minMoney18E;
    
    					if (sumMoneyAdd9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    					}
    
    					if ((cvp.getFulldaymoney() * cvp.getFulldaydiscount()) < (sumMoney9 + sumMoney18 + sumMoneyAdd9)) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {
    						// 开始时间到9点
    						if (sumMoney9 == (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoney9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    							list.add(CreatePriceLog(
    									"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()) + ")",
    									sumMoney9, calendar_as.getTimeInMillis(), calendar_9.getTimeInMillis(), 0, (double) 0));
    						} else {
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()),
    									minMoney9, calendar_as.getTimeInMillis(), calendar_9.getTimeInMillis(), 0, (double) 0));
    						}
    						// 9点到18点
    						if (calendar_e.compareTo(calendar_18) <= 0)// 小于18点,结束时间
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoney18, calendar_9.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    
    						} else { // 大于18点,到18点
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()),
    									sumMoney18, calendar_9.getTimeInMillis(), calendar_18.getTimeInMillis(), 0,
    									(double) 0));
    
    						}
    
    						// 18点到结束
    						if (calendar_e.compareTo(calendar_18) > 0) {
    							// 18点到结束
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									minMoney18E, calendar_18.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    
    						}
    					}
    				}
    
    				// 开始时间大于等于当天9点,结束时间小于等于当天18点
    				if (calendar_as.compareTo(calendar_9) > 0 && calendar_e.compareTo(calendar_18) <= 0) {
    					// 时间价格
    					Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					// 总价格
    					double sumMoney = minMoney;
    					// 如果总价格大于整日租价格
    					if (sumMoney > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoney = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 否则显示分时记价
    						// 时间
    						list.add(CreatePriceLog(
    								UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    								minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					}
    				}
    
    				// 开始时间大于等于当天9点,结束时间大于等于隔天9点,小于隔天18点
    				if (calendar_as.compareTo(calendar_9) > 0 && calendar_as.compareTo(calendar_18) < 0
    						&& calendar_e.compareTo(calendar_18) > 0 && calendar_e.compareTo(calendar_Add1_18) < 0) {
    
    					// 总价格
    					double sumMoney18 = (double) 0;
    					double sumMoneyAdd9 = (double) 0;
    					double sumMoneyAdd18 = (double) 0;
    					// 开始时间至当天18点
    					double minMoney18 = (double) 0;
    					// 当天18点至隔天9点
    					double minMoneyAdd9 = (double) 0;
    					// 隔天9点至结束时间
    					double minMoneyAdd18 = (double) 0;
    
    					// 开始时间至当天18点
    					if (calendar_e.compareTo(calendar_18) <= 0)// 小于当天18点,到结束时间(白)
    					{
    						// 开始时间到18点的时间(白)
    						Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    						long min = mdiff / (1000 * 60);
    						minMoney18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					} else {// 大于当天18点,到18点
    						Long mdiff = calendar_18.getTimeInMillis() - calendar_as.getTimeInMillis();
    						long min = mdiff / (1000 * 60);
    						minMoney18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					sumMoney18 = minMoney18;
    					if (sumMoney18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoney18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					}
    					// 当天18点至隔天9点
    					if (calendar_e.compareTo(calendar_18) > 0)// 大于18点
    					{
    						if (calendar_e.compareTo(calendar_Add1_9) <= 0)// 小于隔天9点,结束时间
    						{
    							// 18点到结束时间时间(夜)
    							Long mdiff = calendar_e.getTimeInMillis() - calendar_18.getTimeInMillis();
    							long min = mdiff / (1000 * 60);
    							minMoneyAdd9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    						} else// 大于隔天9点,隔天9点
    						{
    							// 18点到隔天9点时间(夜)
    							Long mdiff = calendar_Add1_9.getTimeInMillis() - calendar_18.getTimeInMillis();
    							long min = mdiff / (1000 * 60);
    							minMoneyAdd9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    						}
    						sumMoneyAdd9 = minMoneyAdd9;
    						if (sumMoneyAdd9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						}
    					}
    					// 隔天9点至结束时间
    					if (calendar_e.compareTo(calendar_Add1_9) > 0) {
    						// 隔天9点至结束(白)
    						Long mdiff = calendar_e.getTimeInMillis() - calendar_Add1_9.getTimeInMillis();
    						long min = mdiff / (1000 * 60);
    						minMoneyAdd18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    						sumMoneyAdd18 = minMoneyAdd18;
    						if (sumMoneyAdd18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    							sumMoneyAdd18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    						}
    					}
    					// 列出详细
    					if ((sumMoney18 + sumMoneyAdd9 + sumMoneyAdd18) > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else if ((sumMoney18 + sumMoneyAdd9) > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {
    						if (calendar_e.compareTo(calendar_18) <= 0)// 小于当天18点,到结束时间(白)
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoney18, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						} else {// 大于当天18点,到18点
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()),
    									sumMoney18, calendar_as.getTimeInMillis(), calendar_18.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						// 当天18点至隔天9点
    						if (calendar_e.compareTo(calendar_Add1_9) <= 0)// 大于隔天9点,到结束
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAdd9, calendar_18.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						} else {// 大于隔天9点,隔天9点
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()),
    									sumMoneyAdd9, calendar_18.getTimeInMillis(), calendar_Add1_9.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						// 隔天9点至结束时间
    						if (calendar_e.compareTo(calendar_Add1_9) > 0) {
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAdd18, calendar_Add1_9.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						}
    					}
    				}
    
    				// 开始时间大约18点,结束时间小于等于隔天9点
    				if (calendar_as.compareTo(calendar_18) >= 0 && calendar_e.compareTo(calendar_Add1_9) <= 0) {
    					isNightOver = true;
    					// 时间价格
    					Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					// 总价格
    					double sumMoney = minMoney;
    					// 如果总价格大于夜间特惠价格
    					if (sumMoney > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoney = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						list.add(CreatePriceLog(
    								"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 否则显示分时记价
    						// 时间
    						list.add(CreatePriceLog(
    								UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    								minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					}
    				}
    				// 开始时间大约18点,结束时间大约隔天9点
    				if (calendar_as.compareTo(calendar_18) >= 0 && calendar_e.compareTo(calendar_Add1_9) > 0) {
    
    					// 总价格
    					double sumMoneyAdd9 = (double) 0;
    					double sumMoneyAdd18 = (double) 0;
    					double sumMoneyAddE = (double) 0;
    					// 开始时间至隔天9点
    					double minMoneyAdd9 = (double) 0;
    					// 隔天9点至隔天18点
    					double minMoneyAdd18 = (double) 0;
    					// 隔天18点至结束时间
    					double minMoneyAddE = (double) 0;
    					// 开始时间至隔天9点
    
    					// 开始时间到隔天9点的时间(夜)
    					Long mdiff = calendar_Add1_9.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					minMoneyAdd9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					sumMoneyAdd9 = minMoneyAdd9;
    					if (sumMoneyAdd9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    					}
    
    					// 隔天9点至隔天18点(白)
    					if (calendar_e.compareTo(calendar_Add1_18) <= 0)// 小于等于18点,到结束时间
    					{
    						// 开始时间到隔天9点的时间(夜)
    						// mdiff = calendar_Add1_18.getTimeInMillis() -
    						// calendar_e.getTimeInMillis();
    						mdiff = calendar_e.getTimeInMillis() - calendar_Add1_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoneyAdd18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					} else { // 大于隔天18点,到隔天18点
    
    						// 开始时间到隔天9点的时间(夜)
    						mdiff = calendar_Add1_18.getTimeInMillis() - calendar_Add1_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoneyAdd18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					sumMoneyAdd18 = minMoneyAdd18;
    					if (sumMoneyAdd18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoneyAdd18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					}
    					// 隔天18点至结束时间
    					if (calendar_e.compareTo(calendar_Add1_18) > 0) {
    
    						// 开始时间到隔天9点的时间(夜)
    						mdiff = calendar_e.getTimeInMillis() - calendar_Add1_18.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoneyAddE = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    						sumMoneyAddE = minMoneyAddE;
    						if (sumMoneyAddE > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoneyAddE = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						}
    					}
    					if ((sumMoneyAdd9 + sumMoneyAdd18 + sumMoneyAddE) > (cvp.getFulldaymoney()
    							* cvp.getFulldaydiscount())) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 分段详细
    						// 开始时间至隔天9点
    						if (sumMoneyAdd9 >= (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    
    							list.add(CreatePriceLog(
    									"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + ")",
    									sumMoneyAdd9, calendar_as.getTimeInMillis(), calendar_Add1_9.getTimeInMillis(), 0,
    									(double) 0));
    						} else {
    
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()),
    									sumMoneyAdd9, calendar_as.getTimeInMillis(), calendar_Add1_9.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						// 隔天9点至隔天18点(白)
    						if (calendar_e.compareTo(calendar_Add1_18) <= 0)// 小于等于18点,到结束时间
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAdd18, calendar_Add1_9.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						} else {
    
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_18.getTimeInMillis()),
    									sumMoneyAdd18, calendar_Add1_9.getTimeInMillis(), calendar_Add1_18.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						if (calendar_e.compareTo(calendar_Add1_18) > 0) {
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAddE, calendar_Add1_18.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						}
    					}
    				}
    			}
    
    
    
    		}
    
    		// 计算里程
    		int milage = GetMilage(oDetail.getSn(), allStartDate.getTime(), allEndDate.getTime());
    		PriceLog log = new PriceLog();
    		log.setTypeText(milage + "公里");
    		BigDecimal b2 = new BigDecimal(milage * cvp.getMileagemoney() * cvp.getMileagediscount());
    		double f2 = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    		log.setPrice(f2);
    		log.setStartDate(allStartDate.getTime());
    		log.setEndDate(allEndDate.getTime());
    		log.setMilage((long) milage);
    		log.setType(1);
    		list.add(log);
    
    		Date cstartDate = oDetail.getChargingstartdate();
    		long nm = 1000*60;        //一分钟的毫秒数
    		long diff2 = new Date().getTime() - cstartDate.getTime();
    		long min = diff2/nm;      //计算差多少分钟
    
    		// 计费时间大于1分钟再计算保险费。 lidongchun@bagechuxing.cn
    		if(min>1){
    			// 记录保险消费
    			if (days == 0) {
    				for (OrderInsurance oi : orderInsuranceList) {
    					if (oi != null) {
    						list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney(), (long) 0, (long) 0,
    								4, (double) 0));
    					}
    				}
    			} else {
    				if (dDays > days) {
    					if (dDays - days >= 0.021) {
    						for (OrderInsurance oi : orderInsuranceList) {
    							if (oi != null) {
    								list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * (days + 1),
    										(long) 0, (long) 0, 4, (double) 0));
    							}
    						}
    					} else {
    						for (OrderInsurance oi : orderInsuranceList) {
    							if (oi != null) {
    								list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * (days),
    										(long) 0, (long) 0, 4, (double) 0));
    							}
    						}
    					}
    				} else {
    
    					for (OrderInsurance oi : orderInsuranceList) {
    						if (oi != null) {
    							list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * days, (long) 0,
    									(long) 0, 4, (double) 0));
    						}
    					}
    				}
    			}
    		}
    
    //		Double dMoney = ControlService.getStopVehicleMoney(Integer.valueOf(orderId));
    //		if(dMoney > 0){
    //			PriceLog logStop = new PriceLog();
    //			logStop.setTypeText("停车费减免");
    //			logStop.setPrice(-dMoney);
    //			logStop.setType(4);
    //			list.add(logStop);
    //		}
    
    		// 计算还车服务费
    		if(parkId!=null && branchId!=null){
    			PriceLog logStop = new PriceLog();
    			returnStopMoney = ControlService.getReturnStopVehicleMoney(parkId, branchId);
    			if(returnStopMoney>0){
    				logStop.setTypeText("还车服务费");
    				logStop.setPrice(returnStopMoney);
    				logStop.setType(4);
    				list.add(logStop);
    			}
    		}
    
    		if (isStopMoney) {
    			// 判断只有用户点击了开锁后,才免除区域停车费
    			if (oDetail.getIsFirstUnLock() == 1 && oDetail.getLastReturnVehicleDate() != null) {
    				// 计算合计前取是否有小区停车费用
    				double bigFreeMoney = 0; // 定义免费停车的时间
    				double FreePrice = 0;    // 设置的单价
    				long FreeTime = 0;       // 设置的时间
    				long MustTime = 0;       // 至少行驶时间
    				int MustMileage = 0;     // 至少行驶里程
    				String parkFeeAmount=""; // 停车费封顶
    				// 判断车辆是停在车场还是网点,取不同的数据
    				if (!StringUtils.isBlank(oDetail.getRentbranchid())) {
    					// 网点
    					Branch branch = this.branchMapper.selectByPrimaryKey(Integer.valueOf(oDetail.getRentbranchid()));
    					// 获取设置的价格和时间
    					if (branch != null) {
    
    						int mode = branch.getParkingmode();
    						if(mode==2){
    							//if (branch.getParkingFeeMax()!=null){
    							//	parkFeeAmount = branch.getParkingFeeMax().toString();
    							//}
    							//else
    							//{
    							parkFeeAmount = "0";
    							//}
    						}
    						else
    						{
    							// 最少行驶时间
    							if (branch.getMinimumtime() != null) {
    								MustTime = branch.getMinimumtime();
    							}
    							if (branch.getMinimummileage() != null) {
    								MustMileage = branch.getMinimummileage();
    							}
    							if (branch.getBillingunitprice() != null) {
    								FreePrice = Double.valueOf(branch.getBillingunitprice().toString());
    							}
    							if (branch.getDelaytime() != null) {
    								FreeTime = branch.getDelaytime();
    							}
    							if (branch.getParkingFeeMax()!=null){
    								parkFeeAmount = branch.getParkingFeeMax().toString();
    							}
    						}
    					}
    				} else {
    					// 车场
    					Parkinglot parkinglot = this.parkinglotMapper.selectByPrimaryKey(oDetail.getRentparkid());
    					if (parkinglot != null) {
    						int mode = parkinglot.getParkingmode();
    						//按次收费
    						if(mode==2){
    							//if (parkinglot.getParkingFeeMax()!=null){
    							//	parkFeeAmount = parkinglot.getParkingFeeMax().toString();
    							//}
    							//else
    							//{
    							parkFeeAmount = "0";
    							//}
    						}
    						else
    						{
    							if (parkinglot.getMinimumtime() != null) {
    								MustTime = parkinglot.getMinimumtime();
    							}
    							if (parkinglot.getMinimummileage() != null) {
    								MustMileage = parkinglot.getMinimummileage();
    							}
    							// 获取设置的价格和时间
    							if (parkinglot.getBillingunitprice() != null) {
    								FreePrice = Double.valueOf(parkinglot.getBillingunitprice().toString());
    							}
    							if (parkinglot.getDelaytime() != null) {
    								FreeTime = parkinglot.getDelaytime();
    							}
    							if (parkinglot.getParkingFeeMax()!=null){
    								parkFeeAmount = parkinglot.getParkingFeeMax().toString();
    							}
    						}
    					}
    				}
    				// 分钟
    				long ordertime = diff / (1000 * 60);
    
    				// 判断分钟数和里程数都达到要求才可以减免停车费
    				if (ordertime >= MustTime && milage >= MustMileage) {
    					// 计算时间
    					long minute = UtilTimeFormatter.minutes(oDetail.getChargingstartdate(),
    							oDetail.getLastReturnVehicleDate(), FreeTime);
    
    					// 计算有多少个半小时
    					long halfHour = minute / 30;
    					// 如果剩余分钟还有按半小时算
    					if ((minute - halfHour * 30) > 0) {
    						halfHour = halfHour + 1;
    					}
    
    					// 免费的钱
    					bigFreeMoney = halfHour * FreePrice;
    
    					if (bigFreeMoney > 0) {
    						if(StringUtils.isNotEmpty(parkFeeAmount)){
    							if(bigFreeMoney>Double.parseDouble(parkFeeAmount)){//如果免费钱大于停车费封顶 取封顶值
    								bigFreeMoney = Double.parseDouble(parkFeeAmount);
    							}
    						}
    						Calendar calendar_return = Calendar.getInstance();
    						calendar_return.setTime(oDetail.getChargingstartdate());
    						calendar_return.add(Calendar.MINUTE, (int) FreeTime);
    
    						if(bigFreeMoney>0){
    							// 如果是个人单计算减免
    							if (pauseTime == 1) {
    								list.add(CreatePriceLog(
    										"减免停车费(" + UtilTimeFormatter
    												.getDatemdhm(oDetail.getLastReturnVehicleDate().getTime()) + "~"
    												+ UtilTimeFormatter.getDatemdhm(calendar_return.getTimeInMillis()) + ")",
    										(Double) bigFreeMoney * -1, (long) oDetail.getLastReturnVehicleDate().getTime(),
    										(long) oDetail.getChargingstartdate().getTime(), 3, (double) 0));
    							}
    							// 如果是企业单
    							if (pauseTime == 2) {
    								try {
    									PriceLog priceLog = CreatePriceLog("减免停车费("
    													+ UtilTimeFormatter.getDatemdhm(oDetail.getLastReturnVehicleDate().getTime())
    													+ "~" + UtilTimeFormatter.getDatemdhm(calendar_return.getTimeInMillis()) + ")",
    											(Double) bigFreeMoney * -1, (long) oDetail.getLastReturnVehicleDate().getTime(),
    											(long) oDetail.getChargingstartdate().getTime(), 3, (double) 0);
    
    									//新逻辑,企业停车费减免费用要参与计算
    									list.add(priceLog);
    
    									CompanyCost companyCost = new CompanyCost();
    									companyCost.setOrderid(orderId);
    									companyCost.setMileage(priceLog.getMilage());
    									companyCost.setMoney(new BigDecimal(priceLog.getPrice()));
    									companyCost.setTypetext(priceLog.getTypeText());
    									companyCost.setCosttype(
    											priceLog.getCostType() == null ? 0 : priceLog.getCostType().intValue());
    
    									this.companyCostMapper.insertSelective(companyCost);
    								} catch (Exception ex) {
    									logger.error(ex.getMessage());
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    
    		Double sumMoneyAll = (double) 0;
    		double sumCostAll = (double) 0;
    		double stopMoney = (double)0;
    
    		// 计算合计,停车费减免单独提出来
    		for (PriceLog oi : list) {
    			if (oi.getType().intValue() != 3) {
    				BigDecimal b = new BigDecimal(oi.getPrice());
    				double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    				sumCostAll += f1;
    				sumMoneyAll += f1;
    			}
    			else{
    				BigDecimal b = new BigDecimal(oi.getPrice());
    				stopMoney = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    			}
    		}
    
    		//符合计算夜间特惠价格,判断最后的总价是否大于夜间特惠的价格
    		if(isNightSale && isNightOver){
    			if(sumMoneyAll > cvp.getNightsalemoney().doubleValue()){
    				sumMoneyAll = cvp.getNightsalemoney().doubleValue();
    			}
    		}
    
    		//计算完所有的合计之后,再减去停车费减免的金额
    		sumMoneyAll += stopMoney;
    		if (pauseTime == 2) {
    			if(sumMoneyAll < 0){
    				sumMoneyAll = 0.0;
    			}
    		}
    
    		list.add(CreatePriceLog("合计", (Double) sumMoneyAll, (long) 0, (long) 0, 2, sumCostAll));
    		return list;
    	}
    
    	/***
    	 * 计算获取行驶里程
    	 */
    	@Override
    	public  Integer GetMilage(String sn, Long startDate, Long endDate) {
    		int milage = 0;
    		try {
    			String url = ControlUrl + "GetMileageTotal.ashx?sn=" + sn + "&startTime=" + startDate + "&endTime="
    					+ endDate + "&customerFlag=" + ConfigUtil.pro.getProperty("CustomerFlag");
    
    			String str = HttpRequestUtil.sendGet(url, "");
    			if (str == null) {
    				return milage;
    			}
    			ResultMilage rm = (ResultMilage) JSONProcesser.jsonProcesser(str, ResultMilage.class);
    			if (rm == null) {
    				return milage;
    			}
    			if (rm.getResult() != 1) {
    				Log4jTask.addLog("获取里程失败:" + rm.getMessage(), System.currentTimeMillis(), Log4jTask.ERROR,
    						OrderDetailedSerivceImpl.class.getName(), new Exception());
    				return milage;
    			}
    
    			milage = rm.getCars();
    		} catch (Exception ex) {
    			Log4jTask.addLog("获取里程接口报错", System.currentTimeMillis(), Log4jTask.ERROR,
    					OrderDetailedSerivceImpl.class.getName(), ex);
    		}
    
    		//过滤行驶里程小于0的数据
    		if(milage < 0){
    			Log4jTask.addLog("车辆{"+sn+"}获取里程小于0:" + milage, System.currentTimeMillis(), Log4jTask.ERROR,
    					OrderDetailedSerivceImpl.class.getName(), new Exception());
    			milage = 1;
    		}
    
    		//如果行驶里程大于10000公里,估算里程的数据
    		int minutes = (int) ((endDate - startDate)/(1000 * 60));
    		int hours = (int) ((endDate - startDate)/(1000 * 60 * 60));
    		if(milage > 10000){
    			if(hours>0){
    				if(milage/hours>120){
    					milage = (int) (minutes * 1.5);
    				}
    			}
    			else
    			{
    				milage = (int) (minutes * 1.5);
    			}
    		}
    
    		return milage;
    	}
    
    	/***
    	 * 生成订单价格数据
    	 * @param typeText
    	 * @param price
    	 * @param startDate
    	 * @param endDate
    	 * @param type
    	 * @param cost
    	 * @return
    	 */
    	private PriceLog CreatePriceLog(String typeText, Double price, Long startDate, Long endDate, Integer type,
    									Double cost) {
    		PriceLog log = new PriceLog();
    		log.setTypeText(typeText);
    		BigDecimal b = new BigDecimal(price);
    		double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    		log.setPrice(f1);
    		log.setStartDate(startDate);
    		log.setEndDate(endDate);
    		log.setType(type);
    		log.setCost(cost);
    
    		if (typeText.contains("夜间特惠")) {
    			log.setCostType(2);
    		}
    		if (typeText.contains("整日租")) {
    			log.setCostType(1);
    		}
    
    		return log;
    	}
    
    	/***
    	 * 根据订单ID获取订单价格详情
    	 */
    	@Override
    	public List<PriceLog> getPriceDetailByOrderId(Integer orderId) {
    		List<PriceLog> result = new ArrayList<PriceLog>();
    		List<OrderCostItem> costItems = orderCostItemMapper.selectByOrderId(orderId);
    		if (costItems.isEmpty()) {
    			return new ArrayList<PriceLog>();
    		}
    		PriceLog priceLog;
    		for (OrderCostItem item : costItems) {
    			priceLog = new PriceLog();
    			priceLog.setTypeText(item.getTypetext());
    			priceLog.setPrice(item.getMoney());
    			priceLog.setMoney(item.getMoney() + "");
    			priceLog.setType(item.getCostType());
    			result.add(priceLog);
    		}
    		return result;
    	}
    
    	/***
    	 * 根据订单ID获取订单项目
    	 */
    	public List<OrderCostItem> getPriceDetailFromOrderId(Integer orderId) {
    		return orderCostItemMapper.selectByOrderId(orderId);
    	}
    
    	@Override
    	public CostVehiclePrice getCostVehiclePriceByOrderId(Integer orderId) {
    		// 获取订单信息
    		OrderDetail oDetail = orderMapper.getOrderInfo(orderId);
    		// 获取计费信息
    		CostVehiclePrice cvp = costVehiclePriceMapper.selectByVehicleModelId(oDetail);
    		return cvp;
    	}
    
    
    	/**
    	 * 一周活动使用计费方法
    	 * @param orderId
    	 * @param pauseTime
    	 * @param parkId
    	 * @param branchId
    	 * @return
    	 */
    	public List<PriceLog> onePriceLog(Integer orderId, Long pauseTime, Integer parkId, Integer branchId){
    		List<PriceLog> list = new ArrayList<>();
    
    		// 是否计算停车减免
    		boolean isStopMoney = false;
    
    
    		//还车停车费
    		double returnStopMoney = 0;
    
    		// 获取订单信息
    		OrderDetail oDetail = orderMapper.getOrderInfo(orderId);
    		if(oDetail!=null && Integer.valueOf(40).equals(oDetail.getOrderstatus()!=null)){
    			PriceLog log = new PriceLog();
    			log.setTypeText("订单已取消");
    			log.setPrice(0.0);
    			log.setType(1);
    			list.add(log);
    			return list;
    		}
    
    		// 获取订单包含的保险
    		List<OrderInsurance> orderInsuranceList = orderInsuranceMapper.getInsuranceByOrderId(orderId);
    
    		//一周年活动
    		if(flag!=null && "1".equals(flag)){
    			DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    			try {
    				Double sumMoneyAll = (double) 0;
    				double sumCostAll = (double) 0;
    				Date sdate = df.parse(startTimes);//活动开始时间
    				Date edate = df.parse(endTimes);//活动结束时间
    				Date allStartDate = oDetail.getChargingstartdate();//订单开始时间
    				if(allStartDate!=null){
    					Date allEndDate = oDetail.getReturnvehicledate();//订单结束时间
    					if (allEndDate == null) {
    						allEndDate = new Date();
    					}
    					long to = allEndDate.getTime();
    					long from = allStartDate.getTime();
    					int hours = (int) (to-from)/(1000*60*60);//结束时间减去开始时间是否小于一小时
    					if(allStartDate.getTime()>=sdate.getTime() && allStartDate.getTime()<=edate.getTime()){
    						if(hours<1){
    							Date tempStartDate = new Date(allStartDate.getTime() + (1000*60*60));
    							list.add(CreatePriceLog(
    									"限免1小时" + "(" + UtilTimeFormatter.getDatemdhm(allStartDate.getTime()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(tempStartDate.getTime()) + ")",
    									(double) 0, allStartDate.getTime(), tempStartDate.getTime(), 3, (double) 0));
    							// 计算里程
    							int milage = GetMilage(oDetail.getSn(), allStartDate.getTime(), allEndDate.getTime());
    							PriceLog log = new PriceLog();
    							log.setTypeText(milage + "公里");
    							log.setPrice(0.0);
    							log.setStartDate(allStartDate.getTime());
    							log.setEndDate(allEndDate.getTime());
    							log.setMilage((long) milage);
    							log.setType(1);
    							list.add(log);
    
    
    							long diff = allEndDate.getTime() - allStartDate.getTime();
    							long days = diff / (1000 * 60 * 60 * 24);
    
    							// 计算天数
    							double dDays = (double) diff / (1000 * 60 * 60 * 24);
    
    							long nm = 1000*60;        //一分钟的毫秒数
    							long diff2 = new Date().getTime() - allStartDate.getTime();
    							long min = diff2/nm;      //计算差多少分钟
    							double bxMoney=0.00;
    
    							// 计费时间大于1分钟再计算保险费。 lidongchun@bagechuxing.cn
    							if(min>1){
    								// 记录保险消费
    								if (days == 0) {
    									for (OrderInsurance oi : orderInsuranceList) {
    										bxMoney = (double) oi.getInsurancemoney();
    										if (oi != null) {
    											list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney(), (long) 0, (long) 0,
    													4, (double) 0));
    										}
    									}
    								} else {
    									if (dDays > days) {
    										if (dDays - days >= 0.021) {
    											for (OrderInsurance oi : orderInsuranceList) {
    												bxMoney = (double) oi.getInsurancemoney();
    												if (oi != null) {
    													list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * (days + 1),
    															(long) 0, (long) 0, 4, (double) 0));
    												}
    											}
    										} else {
    											for (OrderInsurance oi : orderInsuranceList) {
    												bxMoney = (double) oi.getInsurancemoney();
    												if (oi != null) {
    													list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * (days),
    															(long) 0, (long) 0, 4, (double) 0));
    												}
    											}
    										}
    									} else {
    
    										for (OrderInsurance oi : orderInsuranceList) {
    											bxMoney = (double) oi.getInsurancemoney();
    											if (oi != null) {
    												list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * days, (long) 0,
    														(long) 0, 4, (double) 0));
    											}
    										}
    									}
    								}
    							}
    							list.add(CreatePriceLog("合计", (Double) sumMoneyAll+bxMoney, (long) 0, (long) 0, 2, sumCostAll));
    							return list;
    						}
    					}
    				}
    
    			} catch (ParseException e) {
    				e.printStackTrace();
    			}
    		}
    		if(flag!=null && "1".equals(flag) && oDetail.getChargingstartdate()!=null){
    			Date sdate = oDetail.getChargingstartdate();
    			Calendar cal = Calendar.getInstance();
    			cal.setTime(sdate);
    			cal.add(Calendar.HOUR,-1);
    			//oDetail.setChargingstartdate(cal.getTime());
    			Date tempStartDate = new Date(sdate.getTime() + (1000*60*60));
    			list.add(CreatePriceLog(
    					"限免1小时" + "(" + UtilTimeFormatter.getDatemdhm(sdate.getTime()) + "~"
    							+ UtilTimeFormatter.getDatemdhm(tempStartDate.getTime()) + ")",
    					(double) 0, sdate.getTime(), tempStartDate.getTime(), 3, (double) 0));
    			Date now_10 = new Date(sdate.getTime() + (1000*60*60)); //10分钟前的时间
    			oDetail.setChargingstartdate(now_10);
    		}
    
    		// 获取计费信
    		CostVehiclePrice cvp = costVehiclePriceMapper.selectByVehicleModelId(oDetail);
    
    
    
    		// 获取活动信息
    		List<OrderVehicleRuleItem> ruleItemList = orderMapper.getOrderVehicleRuleItem(orderId);
    
    		// 开始和结束时间不参与计算(算里程使用)
    		Date allStartDate = oDetail.getChargingstartdate();
    		Date allEndDate = oDetail.getReturnvehicledate();
    
    		Date startDate=null;
    		// 取订单开始时间
    		startDate = oDetail.getChargingstartdate();
    
    		if (startDate == null)// 没有开始时间
    		{
    			return list;
    		}
    		for (OrderVehicleRuleItem ovRuleItem : ruleItemList) {
    			if (ovRuleItem != null) {
    
    				// 减去活动的开始时间
    				Date tempStartDate = new Date(startDate.getTime() + (ovRuleItem.getDuration() * 60 * 1000));
    				list.add(CreatePriceLog(
    						ovRuleItem.getName() + "(" + UtilTimeFormatter.getDatemdhm(startDate.getTime()) + "~"
    								+ UtilTimeFormatter.getDatemdhm(tempStartDate.getTime()) + ")",
    						(double) 0, startDate.getTime(), tempStartDate.getTime(), 3, (double) 0));
    				startDate = tempStartDate;
    			}
    		}
    
    		// 取订单结束时间
    		Date endDate = oDetail.getReturnvehicledate();
    		// 等于1说明是结单的时候用
    		if (pauseTime == 1 || pauseTime == 2) {
    			isStopMoney = true;
    		}
    		// 如果没有结束时间则取当前时间
    		if (endDate == null) {
    			endDate = new Date();
    		}
    		if (allEndDate == null) {
    			allEndDate = new Date();
    		}
    
    		long diff = endDate.getTime() - startDate.getTime();
    		// 减去暂停时间(最后结账时)
    		//diff = diff - pauseTime;
    		// 计算天数
    		long days = diff / (1000 * 60 * 60 * 24);
    		// 计算是否正好整天
    
    		// 计算天数
    		double dDays = (double) diff / (1000 * 60 * 60 * 24);
    
    		// 加上全日租后的开始日期
    		Date aStartDate = UtilTimeFormatter.afterNDay((int) days, startDate);
    
    		Boolean isNightSale = false; // 是否设置了夜间优惠价格
    		Boolean isNightOver = false; // 是否订单是在夜间
    
    		// 计算全日租
    		if (days != 0) {
    			list.add(CreatePriceLog(
    					"整日租" + days + "天(" + UtilTimeFormatter.getDatemdhm(startDate.getTime()) + "~"
    							+ UtilTimeFormatter.getDatemdhm(aStartDate.getTime()) + ")",
    					(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount() * days), startDate.getTime(),
    					aStartDate.getTime(), 0, (double) 0));
    		} else {
    			// 夜间特惠价格要求订单开始结束时间必须在当天18点到次日9点之间才可以
    			// 且设置的夜间特惠价格必须不能为空和大于0
    			if (null != cvp.getNightsalemoney() && cvp.getNightsalemoney().doubleValue() > 0) {
    				isNightSale = true;
    			}
    		}
    
    		if (dDays > days) { // 有小数,不是整天
    
    			Integer intStart = 17;
    			Integer intEnd = 9;
    			NightshiftInterval ns = nightshiftIntervalMapper.selectByPrimaryKeyType(2);
    			if(ns!= null){
    				Calendar calendar = Calendar.getInstance();
    				if(ns.getStarttime() != null)
    				{
    					Date date = ns.getStarttime();
    					calendar.setTime(date);
    					String strHour = new SimpleDateFormat("HH").format(calendar.getTime());
    					if(StringUtils.isNoneBlank(strHour))
    					{
    						intStart = Integer.valueOf(strHour);
    					}
    				}
    
    				if(ns.getEndtime() != null)
    				{
    					Date date = ns.getEndtime();
    					calendar.setTime(date);
    					String strHour = new SimpleDateFormat("HH").format(calendar.getTime());
    					if(StringUtils.isNoneBlank(strHour))
    					{
    						intEnd = Integer.valueOf(strHour);
    					}
    				}
    			}
    
    			//endDate = new Date(endDate.getTime() - pauseTime);
    			endDate = new Date(endDate.getTime());
    
    			// 开始时间
    			Calendar calendar_as = Calendar.getInstance();
    			calendar_as.setTime(aStartDate);
    
    			// 结束时间
    			Calendar calendar_e = Calendar.getInstance();
    			calendar_e.setTime(endDate);
    
    
    			String mushroomCarModeId = ConfigUtil.pro.getProperty("mushroomCar.ModeId");
    			int mushroomCarProvinceId = new Integer(ConfigUtil.pro.getProperty("mushroomCar.ProvinceId"));
    			String vmodeId = cvp.getVehiclemodelid().toString();
    
    			//旅游车计价2017.10.1新增
    			//根据车型和城市规则匹配
    			if(mushroomCarModeId.contains(vmodeId) && cvp.getProvinceid().intValue() == mushroomCarProvinceId){
    				// 时间价格
    				Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    				long min = mdiff / (1000 * 60);
    				//半小时为一个计价单位
    				long halfHour = (min + cvp.getPricestep() + 1) / cvp.getPricestep();
    				double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * halfHour);
    
    				// 总价格
    				double sumMoney = minMoney;
    
    				// 如果总价格大于整日租价格
    				if (sumMoney > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    					sumMoney = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					list.add(CreatePriceLog(
    							"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    									+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    							sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    				} else {// 否则显示分时记价
    					// 时间
    					list.add(CreatePriceLog(
    							UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    									+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    							minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    				}
    				//普通车计价
    			}else{
    				// 当天9点
    				Calendar calendar_9 = Calendar.getInstance();
    				calendar_9.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE), intEnd, 5, 0);
    				calendar_9.set(Calendar.MILLISECOND, 0);
    
    				// 当天18点
    				Calendar calendar_18 = Calendar.getInstance();
    				calendar_18.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE), intStart, 0, 0);
    				calendar_18.set(Calendar.MILLISECOND, 0);
    				// 隔天9点
    				Calendar calendar_Add1_9 = Calendar.getInstance();
    				calendar_Add1_9.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE) + 1, intEnd, 5, 0);
    				calendar_Add1_9.set(Calendar.MILLISECOND, 0);
    				// 隔天18点
    				Calendar calendar_Add1_18 = Calendar.getInstance();
    				calendar_Add1_18.set(calendar_as.get(Calendar.YEAR), calendar_as.get(Calendar.MONTH),
    						calendar_as.get(Calendar.DATE) + 1, intStart, 0, 0);
    				calendar_Add1_18.set(Calendar.MILLISECOND, 0);
    				// 开始时间小于等于当天9点,结束时间小于等于当天9点 只是夜间
    				if (calendar_as.compareTo(calendar_9) <= 0 && calendar_e.compareTo(calendar_9) <= 0) {
    					isNightOver = true;
    					// 时间价格
    					Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					// 总价格
    					double sumMoney = minMoney;
    					// 如果总价格大于夜间特惠价格
    					if (sumMoney > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoney = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						list.add(CreatePriceLog(
    								"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 否则显示分时记价
    
    						// 时间
    						list.add(CreatePriceLog(
    								UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    								minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					}
    
    				}
    
    				// 开始时间小于等于当天9点,结束时间小于等于隔天9点且大于当天9点
    				if (calendar_as.compareTo(calendar_9) <= 0 && calendar_e.compareTo(calendar_Add1_9) <= 0
    						&& calendar_e.compareTo(calendar_9) > 0) {
    					// 总价格
    					double sumMoney9 = (double) 0;
    					double sumMoney18 = (double) 0;
    					double sumMoneyAdd9 = (double) 0;
    
    					// 开始时间到9点的时间(夜)
    					Long mdiff = calendar_9.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					// 9点之前的总价格
    					sumMoney9 = minMoney9;
    					// 如果总价格大于夜间特惠,夜间特惠
    					if (sumMoney9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoney9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    					}
    
    					// 9点到结束时间的时间(小于18点到结束时间)
    					double minMoney9E = (double) 0;
    
    					if (calendar_e.compareTo(calendar_18) < 0)// 小于18点,结束时间
    					{
    						// 时间
    						mdiff = calendar_e.getTimeInMillis() - calendar_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoney9E = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					} else {// 大于18点
    						// 时间
    						mdiff = calendar_18.getTimeInMillis() - calendar_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoney9E = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					// 9点-18点(结束时间)的总价格
    					sumMoney18 = minMoney9E;
    					if (sumMoney18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoney18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					}
    
    					// 18点到第二天9点的时间价格
    					double minMoney18E = (double) 0;
    
    					if (calendar_e.compareTo(calendar_18) > 0) {
    						// 时间
    						mdiff = calendar_e.getTimeInMillis() - calendar_18.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoney18E = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					sumMoneyAdd9 = minMoney18E;
    
    					if (sumMoneyAdd9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    					}
    
    					if ((cvp.getFulldaymoney() * cvp.getFulldaydiscount()) < (sumMoney9 + sumMoney18 + sumMoneyAdd9)) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {
    						// 开始时间到9点
    						if (sumMoney9 == (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoney9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    							list.add(CreatePriceLog(
    									"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()) + ")",
    									sumMoney9, calendar_as.getTimeInMillis(), calendar_9.getTimeInMillis(), 0, (double) 0));
    						} else {
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()),
    									minMoney9, calendar_as.getTimeInMillis(), calendar_9.getTimeInMillis(), 0, (double) 0));
    						}
    						// 9点到18点
    						if (calendar_e.compareTo(calendar_18) <= 0)// 小于18点,结束时间
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoney18, calendar_9.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    
    						} else { // 大于18点,到18点
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()),
    									sumMoney18, calendar_9.getTimeInMillis(), calendar_18.getTimeInMillis(), 0,
    									(double) 0));
    
    						}
    
    						// 18点到结束
    						if (calendar_e.compareTo(calendar_18) > 0) {
    							// 18点到结束
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									minMoney18E, calendar_18.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    
    						}
    					}
    				}
    
    				// 开始时间大于等于当天9点,结束时间小于等于当天18点
    				if (calendar_as.compareTo(calendar_9) > 0 && calendar_e.compareTo(calendar_18) <= 0) {
    					// 时间价格
    					Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					// 总价格
    					double sumMoney = minMoney;
    					// 如果总价格大于整日租价格
    					if (sumMoney > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoney = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 否则显示分时记价
    						// 时间
    						list.add(CreatePriceLog(
    								UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    								minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					}
    				}
    
    				// 开始时间大于等于当天9点,结束时间大于等于隔天9点,小于隔天18点
    				if (calendar_as.compareTo(calendar_9) > 0 && calendar_as.compareTo(calendar_18) < 0
    						&& calendar_e.compareTo(calendar_18) > 0 && calendar_e.compareTo(calendar_Add1_18) < 0) {
    
    					// 总价格
    					double sumMoney18 = (double) 0;
    					double sumMoneyAdd9 = (double) 0;
    					double sumMoneyAdd18 = (double) 0;
    					// 开始时间至当天18点
    					double minMoney18 = (double) 0;
    					// 当天18点至隔天9点
    					double minMoneyAdd9 = (double) 0;
    					// 隔天9点至结束时间
    					double minMoneyAdd18 = (double) 0;
    
    					// 开始时间至当天18点
    					if (calendar_e.compareTo(calendar_18) <= 0)// 小于当天18点,到结束时间(白)
    					{
    						// 开始时间到18点的时间(白)
    						Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    						long min = mdiff / (1000 * 60);
    						minMoney18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					} else {// 大于当天18点,到18点
    						Long mdiff = calendar_18.getTimeInMillis() - calendar_as.getTimeInMillis();
    						long min = mdiff / (1000 * 60);
    						minMoney18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					sumMoney18 = minMoney18;
    					if (sumMoney18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoney18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					}
    					// 当天18点至隔天9点
    					if (calendar_e.compareTo(calendar_18) > 0)// 大于18点
    					{
    						if (calendar_e.compareTo(calendar_Add1_9) <= 0)// 小于隔天9点,结束时间
    						{
    							// 18点到结束时间时间(夜)
    							Long mdiff = calendar_e.getTimeInMillis() - calendar_18.getTimeInMillis();
    							long min = mdiff / (1000 * 60);
    							minMoneyAdd9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    						} else// 大于隔天9点,隔天9点
    						{
    							// 18点到隔天9点时间(夜)
    							Long mdiff = calendar_Add1_9.getTimeInMillis() - calendar_18.getTimeInMillis();
    							long min = mdiff / (1000 * 60);
    							minMoneyAdd9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    						}
    						sumMoneyAdd9 = minMoneyAdd9;
    						if (sumMoneyAdd9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						}
    					}
    					// 隔天9点至结束时间
    					if (calendar_e.compareTo(calendar_Add1_9) > 0) {
    						// 隔天9点至结束(白)
    						Long mdiff = calendar_e.getTimeInMillis() - calendar_Add1_9.getTimeInMillis();
    						long min = mdiff / (1000 * 60);
    						minMoneyAdd18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    						sumMoneyAdd18 = minMoneyAdd18;
    						if (sumMoneyAdd18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    							sumMoneyAdd18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    						}
    					}
    					// 列出详细
    					if ((sumMoney18 + sumMoneyAdd9 + sumMoneyAdd18) > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else if ((sumMoney18 + sumMoneyAdd9) > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {
    						if (calendar_e.compareTo(calendar_18) <= 0)// 小于当天18点,到结束时间(白)
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoney18, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						} else {// 大于当天18点,到18点
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()),
    									sumMoney18, calendar_as.getTimeInMillis(), calendar_18.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						// 当天18点至隔天9点
    						if (calendar_e.compareTo(calendar_Add1_9) <= 0)// 大于隔天9点,到结束
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAdd9, calendar_18.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						} else {// 大于隔天9点,隔天9点
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()),
    									sumMoneyAdd9, calendar_18.getTimeInMillis(), calendar_Add1_9.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						// 隔天9点至结束时间
    						if (calendar_e.compareTo(calendar_Add1_9) > 0) {
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAdd18, calendar_Add1_9.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						}
    					}
    				}
    
    				// 开始时间大约18点,结束时间小于等于隔天9点
    				if (calendar_as.compareTo(calendar_18) >= 0 && calendar_e.compareTo(calendar_Add1_9) <= 0) {
    					isNightOver = true;
    					// 时间价格
    					Long mdiff = calendar_e.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					double minMoney = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					// 总价格
    					double sumMoney = minMoney;
    					// 如果总价格大于夜间特惠价格
    					if (sumMoney > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoney = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						list.add(CreatePriceLog(
    								"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								sumMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 否则显示分时记价
    						// 时间
    						list.add(CreatePriceLog(
    								UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    								minMoney, calendar_as.getTimeInMillis(), calendar_e.getTimeInMillis(), 0, (double) 0));
    					}
    				}
    				// 开始时间大约18点,结束时间大约隔天9点
    				if (calendar_as.compareTo(calendar_18) >= 0 && calendar_e.compareTo(calendar_Add1_9) > 0) {
    
    					// 总价格
    					double sumMoneyAdd9 = (double) 0;
    					double sumMoneyAdd18 = (double) 0;
    					double sumMoneyAddE = (double) 0;
    					// 开始时间至隔天9点
    					double minMoneyAdd9 = (double) 0;
    					// 隔天9点至隔天18点
    					double minMoneyAdd18 = (double) 0;
    					// 隔天18点至结束时间
    					double minMoneyAddE = (double) 0;
    					// 开始时间至隔天9点
    
    					// 开始时间到隔天9点的时间(夜)
    					Long mdiff = calendar_Add1_9.getTimeInMillis() - calendar_as.getTimeInMillis();
    					long min = mdiff / (1000 * 60);
    					minMoneyAdd9 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    					sumMoneyAdd9 = minMoneyAdd9;
    					if (sumMoneyAdd9 > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    						sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    					}
    
    					// 隔天9点至隔天18点(白)
    					if (calendar_e.compareTo(calendar_Add1_18) <= 0)// 小于等于18点,到结束时间
    					{
    						// 开始时间到隔天9点的时间(夜)
    						// mdiff = calendar_Add1_18.getTimeInMillis() -
    						// calendar_e.getTimeInMillis();
    						mdiff = calendar_e.getTimeInMillis() - calendar_Add1_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoneyAdd18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					} else { // 大于隔天18点,到隔天18点
    
    						// 开始时间到隔天9点的时间(夜)
    						mdiff = calendar_Add1_18.getTimeInMillis() - calendar_Add1_9.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoneyAdd18 = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    					}
    					sumMoneyAdd18 = minMoneyAdd18;
    					if (sumMoneyAdd18 > (cvp.getFulldaymoney() * cvp.getFulldaydiscount())) {
    						sumMoneyAdd18 = (double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount());
    					}
    					// 隔天18点至结束时间
    					if (calendar_e.compareTo(calendar_Add1_18) > 0) {
    
    						// 开始时间到隔天9点的时间(夜)
    						mdiff = calendar_e.getTimeInMillis() - calendar_Add1_18.getTimeInMillis();
    						min = mdiff / (1000 * 60);
    						minMoneyAddE = (double) (cvp.getMinutemoney() * cvp.getMinutediscount() * min);
    
    						sumMoneyAddE = minMoneyAddE;
    						if (sumMoneyAddE > (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoneyAddE = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    						}
    					}
    					if ((sumMoneyAdd9 + sumMoneyAdd18 + sumMoneyAddE) > (cvp.getFulldaymoney()
    							* cvp.getFulldaydiscount())) {
    						list.add(CreatePriceLog(
    								"整日租(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    										+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()) + ")",
    								(double) (cvp.getFulldaymoney() * cvp.getFulldaydiscount()), calendar_as.getTimeInMillis(),
    								calendar_e.getTimeInMillis(), 0, (double) 0));
    					} else {// 分段详细
    						// 开始时间至隔天9点
    						if (sumMoneyAdd9 >= (cvp.getNightmoney() * cvp.getNightdiscount())) {
    							sumMoneyAdd9 = (double) (cvp.getNightmoney() * cvp.getNightdiscount());
    
    							list.add(CreatePriceLog(
    									"夜间特惠(" + UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + ")",
    									sumMoneyAdd9, calendar_as.getTimeInMillis(), calendar_Add1_9.getTimeInMillis(), 0,
    									(double) 0));
    						} else {
    
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_as.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()),
    									sumMoneyAdd9, calendar_as.getTimeInMillis(), calendar_Add1_9.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						// 隔天9点至隔天18点(白)
    						if (calendar_e.compareTo(calendar_Add1_18) <= 0)// 小于等于18点,到结束时间
    						{
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAdd18, calendar_Add1_9.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						} else {
    
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_9.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_Add1_18.getTimeInMillis()),
    									sumMoneyAdd18, calendar_Add1_9.getTimeInMillis(), calendar_Add1_18.getTimeInMillis(), 0,
    									(double) 0));
    						}
    						if (calendar_e.compareTo(calendar_Add1_18) > 0) {
    							// 时间
    							list.add(CreatePriceLog(
    									UtilTimeFormatter.getDatemdhm(calendar_Add1_18.getTimeInMillis()) + "~"
    											+ UtilTimeFormatter.getDatemdhm(calendar_e.getTimeInMillis()),
    									sumMoneyAddE, calendar_Add1_18.getTimeInMillis(), calendar_e.getTimeInMillis(), 0,
    									(double) 0));
    						}
    					}
    				}
    			}
    
    
    
    		}
    
    		// 计算里程
    		int milage = GetMilage(oDetail.getSn(), allStartDate.getTime(), allEndDate.getTime());
    		PriceLog log = new PriceLog();
    		log.setTypeText(milage + "公里");
    		BigDecimal b2 = new BigDecimal(milage * cvp.getMileagemoney() * cvp.getMileagediscount());
    		double f2 = b2.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    		log.setPrice(f2);
    		log.setStartDate(allStartDate.getTime());
    		log.setEndDate(allEndDate.getTime());
    		log.setMilage((long) milage);
    		log.setType(1);
    		list.add(log);
    
    		Date cstartDate = new Date(oDetail.getChargingstartdate().getTime() -(1000*60*60));
    		long nm = 1000*60;        //一分钟的毫秒数
    		long diff2 = new Date().getTime() - cstartDate.getTime();
    		long min = diff2/nm;      //计算差多少分钟
    
    		// 计费时间大于1分钟再计算保险费。 lidongchun@bagechuxing.cn
    		if(min>1){
    			// 记录保险消费
    			if (days == 0) {
    				for (OrderInsurance oi : orderInsuranceList) {
    					if (oi != null) {
    						list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney(), (long) 0, (long) 0,
    								4, (double) 0));
    					}
    				}
    			} else {
    				if (dDays > days) {
    					if (dDays - days >= 0.021) {
    						for (OrderInsurance oi : orderInsuranceList) {
    							if (oi != null) {
    								list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * (days + 1),
    										(long) 0, (long) 0, 4, (double) 0));
    							}
    						}
    					} else {
    						for (OrderInsurance oi : orderInsuranceList) {
    							if (oi != null) {
    								list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * (days),
    										(long) 0, (long) 0, 4, (double) 0));
    							}
    						}
    					}
    				} else {
    
    					for (OrderInsurance oi : orderInsuranceList) {
    						if (oi != null) {
    							list.add(CreatePriceLog(oi.getInsurancename(), (double) oi.getInsurancemoney() * days, (long) 0,
    									(long) 0, 4, (double) 0));
    						}
    					}
    				}
    			}
    		}
    
    //		Double dMoney = ControlService.getStopVehicleMoney(Integer.valueOf(orderId));
    //		if(dMoney > 0){
    //			PriceLog logStop = new PriceLog();
    //			logStop.setTypeText("停车费减免");
    //			logStop.setPrice(-dMoney);
    //			logStop.setType(4);
    //			list.add(logStop);
    //		}
    
    		// 计算还车服务费
    		if(parkId!=null && branchId!=null){
    			PriceLog logStop = new PriceLog();
    			returnStopMoney = ControlService.getReturnStopVehicleMoney(parkId, branchId);
    			if(returnStopMoney>0){
    				logStop.setTypeText("还车服务费");
    				logStop.setPrice(returnStopMoney);
    				logStop.setType(4);
    				list.add(logStop);
    			}
    		}
    
    		if (isStopMoney) {
    			// 判断只有用户点击了开锁后,才免除区域停车费
    			if (oDetail.getIsFirstUnLock() == 1 && oDetail.getLastReturnVehicleDate() != null) {
    				// 计算合计前取是否有小区停车费用
    				double bigFreeMoney = 0; // 定义免费停车的时间
    				double FreePrice = 0;    // 设置的单价
    				long FreeTime = 0;       // 设置的时间
    				long MustTime = 0;       // 至少行驶时间
    				int MustMileage = 0;     // 至少行驶里程
    				String parkFeeAmount=""; // 停车费封顶
    				// 判断车辆是停在车场还是网点,取不同的数据
    				if (!StringUtils.isBlank(oDetail.getRentbranchid())) {
    					// 网点
    					Branch branch = this.branchMapper.selectByPrimaryKey(Integer.valueOf(oDetail.getRentbranchid()));
    					// 获取设置的价格和时间
    					if (branch != null) {
    
    						int mode = branch.getParkingmode();
    						if(mode==2){
    							//if (branch.getParkingFeeMax()!=null){
    							//	parkFeeAmount = branch.getParkingFeeMax().toString();
    							//}
    							//else
    							//{
    							parkFeeAmount = "0";
    							//}
    						}
    						else
    						{
    							// 最少行驶时间
    							if (branch.getMinimumtime() != null) {
    								MustTime = branch.getMinimumtime();
    							}
    							if (branch.getMinimummileage() != null) {
    								MustMileage = branch.getMinimummileage();
    							}
    							if (branch.getBillingunitprice() != null) {
    								FreePrice = Double.valueOf(branch.getBillingunitprice().toString());
    							}
    							if (branch.getDelaytime() != null) {
    								FreeTime = branch.getDelaytime();
    							}
    							if (branch.getParkingFeeMax()!=null){
    								parkFeeAmount = branch.getParkingFeeMax().toString();
    							}
    						}
    					}
    				} else {
    					// 车场
    					Parkinglot parkinglot = this.parkinglotMapper.selectByPrimaryKey(oDetail.getRentparkid());
    					if (parkinglot != null) {
    						int mode = parkinglot.getParkingmode();
    						//按次收费
    						if(mode==2){
    							//if (parkinglot.getParkingFeeMax()!=null){
    							//	parkFeeAmount = parkinglot.getParkingFeeMax().toString();
    							//}
    							//else
    							//{
    							parkFeeAmount = "0";
    							//}
    						}
    						else
    						{
    							if (parkinglot.getMinimumtime() != null) {
    								MustTime = parkinglot.getMinimumtime();
    							}
    							if (parkinglot.getMinimummileage() != null) {
    								MustMileage = parkinglot.getMinimummileage();
    							}
    							// 获取设置的价格和时间
    							if (parkinglot.getBillingunitprice() != null) {
    								FreePrice = Double.valueOf(parkinglot.getBillingunitprice().toString());
    							}
    							if (parkinglot.getDelaytime() != null) {
    								FreeTime = parkinglot.getDelaytime();
    							}
    							if (parkinglot.getParkingFeeMax()!=null){
    								parkFeeAmount = parkinglot.getParkingFeeMax().toString();
    							}
    						}
    					}
    				}
    				// 分钟
    				long ordertime = diff / (1000 * 60);
    
    				// 判断分钟数和里程数都达到要求才可以减免停车费
    				if (ordertime >= MustTime && milage >= MustMileage) {
    					// 计算时间
    					long minute = UtilTimeFormatter.minutes(oDetail.getChargingstartdate(),
    							oDetail.getLastReturnVehicleDate(), FreeTime);
    
    					// 计算有多少个半小时
    					long halfHour = minute / 30;
    					// 如果剩余分钟还有按半小时算
    					if ((minute - halfHour * 30) > 0) {
    						halfHour = halfHour + 1;
    					}
    
    					// 免费的钱
    					bigFreeMoney = halfHour * FreePrice;
    
    					if (bigFreeMoney > 0) {
    						if(StringUtils.isNotEmpty(parkFeeAmount)){
    							if(bigFreeMoney>Double.parseDouble(parkFeeAmount)){//如果免费钱大于停车费封顶 取封顶值
    								bigFreeMoney = Double.parseDouble(parkFeeAmount);
    							}
    						}
    						Calendar calendar_return = Calendar.getInstance();
    						calendar_return.setTime(oDetail.getChargingstartdate());
    						calendar_return.add(Calendar.MINUTE, (int) FreeTime);
    
    						if(bigFreeMoney>0){
    							// 如果是个人单计算减免
    							if (pauseTime == 1) {
    								list.add(CreatePriceLog(
    										"减免停车费(" + UtilTimeFormatter
    												.getDatemdhm(oDetail.getLastReturnVehicleDate().getTime()) + "~"
    												+ UtilTimeFormatter.getDatemdhm(calendar_return.getTimeInMillis()) + ")",
    										(Double) bigFreeMoney * -1, (long) oDetail.getLastReturnVehicleDate().getTime(),
    										(long) oDetail.getChargingstartdate().getTime(), 3, (double) 0));
    							}
    							// 如果是企业单
    							if (pauseTime == 2) {
    								try {
    									PriceLog priceLog = CreatePriceLog("减免停车费("
    													+ UtilTimeFormatter.getDatemdhm(oDetail.getLastReturnVehicleDate().getTime())
    													+ "~" + UtilTimeFormatter.getDatemdhm(calendar_return.getTimeInMillis()) + ")",
    											(Double) bigFreeMoney * -1, (long) oDetail.getLastReturnVehicleDate().getTime(),
    											(long) oDetail.getChargingstartdate().getTime(), 3, (double) 0);
    
    									//新逻辑,企业停车费减免费用要参与计算
    									list.add(priceLog);
    
    									CompanyCost companyCost = new CompanyCost();
    									companyCost.setOrderid(orderId);
    									companyCost.setMileage(priceLog.getMilage());
    									companyCost.setMoney(new BigDecimal(priceLog.getPrice()));
    									companyCost.setTypetext(priceLog.getTypeText());
    									companyCost.setCosttype(
    											priceLog.getCostType() == null ? 0 : priceLog.getCostType().intValue());
    
    									this.companyCostMapper.insertSelective(companyCost);
    								} catch (Exception ex) {
    									logger.error(ex.getMessage());
    								}
    							}
    						}
    					}
    				}
    			}
    		}
    
    		Double sumMoneyAll = (double) 0;
    		double sumCostAll = (double) 0;
    		double stopMoney = (double)0;
    
    		// 计算合计,停车费减免单独提出来
    		for (PriceLog oi : list) {
    			if (oi.getType().intValue() != 3) {
    				BigDecimal b = new BigDecimal(oi.getPrice());
    				double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    				sumCostAll += f1;
    				sumMoneyAll += f1;
    			}
    			else{
    				BigDecimal b = new BigDecimal(oi.getPrice());
    				stopMoney = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    			}
    		}
    
    		//符合计算夜间特惠价格,判断最后的总价是否大于夜间特惠的价格
    		if(isNightSale && isNightOver){
    			if(sumMoneyAll > cvp.getNightsalemoney().doubleValue()){
    				sumMoneyAll = cvp.getNightsalemoney().doubleValue();
    			}
    		}
    
    		//计算完所有的合计之后,再减去停车费减免的金额
    		sumMoneyAll += stopMoney;
    		if (pauseTime == 2) {
    			if(sumMoneyAll < 0){
    				sumMoneyAll = 0.0;
    			}
    		}
    
    		list.add(CreatePriceLog("合计", (Double) sumMoneyAll, (long) 0, (long) 0, 2, sumCostAll));
    		return list;
    	}
    
    }
    
  • 相关阅读:
    android开发中如何开启用户安装的应用程序?
    丑数查找算法
    session.save_path目录大量session临时文件带来的服务器效率问题
    MOSS点滴(1):如何开发和部署feature
    如何将Excel中两个单元格或两列中的数据合并
    如何在 MOSS 2007 启用 Session
    MOSS LIST的一些属性说明
    国外广播电台
    Excel 导出 按钮
    在文档库或 Windows SharePoint Services SharePoint Portal Server 中创建一个新的文件夹或新文档时,您会收到一个"指定的文件或文件夹名太长"错误消息
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/7683201.html
Copyright © 2020-2023  润新知