package com.ag.account.detail.impl;

import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.MultiStepUtil;
import com.ag.account.feeUtil.ReductionUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.StrUtil;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSONObject;

/**
 * 箱*天
 * Created by Administrator on 2017/6/23 0023.
 */
public class CntrStoreDetail extends AccountDetail {

    @Override
    protected void calcBefore(BizVO bizVO, SourceProperty source){
        JSONObject popMap = source.getProperty();
        if (!StrUtil.isEmpty(ICondition.TIME_ON)) {
            bizVO.setStartDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_ON)));
        }
        if (!StrUtil.isEmpty(ICondition.TIME_END)) {
            bizVO.setEndDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_END)));
        }
    }

    /**
     * 重写结算天
     */
    @Override
    protected Integer getSettleDays(BizVO bizVO){
        return TimeUtil.compareDaysLimit(bizVO.getStartDate(), bizVO.getEndDate(), true) + 1;
    }

    /**
     * 按堆存天计费
     */
    @Override
    protected void calcByUnit(BizVO bizVO, SourceProperty source, FeeDetail detail){
        detail.setSettleTimeOn(bizVO.getStartDate());
        detail.setSettleTimeEnd(bizVO.getEndDate());
        detail.setCalcDays(detail.getSettleDays());//计费天
        MultiStepUtil.calcAmount(source.getTariffVO(), detail);//计算堆存金额
        detail.setStMoney(detail.getCalcMoney());//标准金额
        detail.setFinalMoney(detail.getCalcMoney());//最终金额
    }

    /**
     * 重写优惠减免
     */
    @Override
    protected void calcByDiscount(BizVO bizVO, SourceProperty source, FeeDetail detail) {
        ReductionUtil.calcByDerateDay(source, detail);//减免天后的金额
        ReductionUtil.calcByDiscount(source.getProperty(), detail);//优惠金额和折扣
    }

}
