package com.hai.order.service.impl;

import com.hai.common.utils.DateUtil;
import com.hai.dao.order.OrderMapperExt;
import com.hai.order.model.OrderCouponModel;
import com.hai.order.model.OrderIntegralRechargeModel;
import com.hai.order.service.OrderServiceExt;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @className: OrderExtServiceImpl
 * @author: HuRui
 * @date: 2022/8/26
 **/
@Service("newOrderServiceExt")
public class OrderServiceExtImpl implements OrderServiceExt {

    @Resource
    private OrderMapperExt orderMapperExt;

    @Override
    public int userBuyCouponNum(Long userId, Long couponId) {
        return orderMapperExt.userBuyCouponNum(userId,couponId);
    }

    @Override
    public List<OrderCouponModel> getOrderCouponList(Map<String, Object> param) throws Exception {

        if (MapUtils.getLong(param, "createTimeS") != null) {
            param.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "createTimeS")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "createTimeE") != null) {
            param.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "createTimeE")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "payTimeS") != null) {
            param.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "payTimeS")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "payTimeE") != null) {
            param.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "payTimeE")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "finishTimeS") != null) {
            param.put("finishTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "finishTimeS")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "finishTimeE") != null) {
            param.put("finishTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "finishTimeE")), DateUtil.Y_M_D_HMS));
        }

        return orderMapperExt.queryOrderCoupon(param);
    }

    @Override
    public List<OrderIntegralRechargeModel> getOrderIntegralRechargeList(Map<String, Object> param) throws Exception {

        if (MapUtils.getLong(param, "createTimeS") != null) {
            param.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "createTimeS")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "createTimeE") != null) {
            param.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "createTimeE")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "payTimeS") != null) {
            param.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "payTimeS")), DateUtil.Y_M_D_HMS));
        }

        if (MapUtils.getLong(param, "payTimeE") != null) {
            param.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "payTimeE")), DateUtil.Y_M_D_HMS));
        }

        return orderMapperExt.queryOrderIntegralRecharge(param);
    }

}
