package com.platform.yijia.service.impl;

import com.platform.yijia.dao.CustomerGradeMapper;
import com.platform.yijia.dao.PayOrderMapper;
import com.platform.yijia.param.request.PayOrderRequest;
import com.platform.yijia.pojo.*;

import com.platform.yijia.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("payOrderService")
public class PayOrderServiceImpl implements PayOrderService {

    @Resource
    private PayOrderMapper payOrderMapper;

    //获取POS机昨天数据
    @Override
    public Map<String, Object> selectPosYesterDayData(PayOrder payOrder) {
        return payOrderMapper.selectPosYesterDayData(payOrder);
    }

    //查询POS机近七天数据
    @Override
    public List<Map<String, Object>> selectPosRecentlySevenData(PayOrder payOrder) {
        return payOrderMapper.selectPosRecentlySevenData(payOrder);
    }

    //查询订单信息
    @Override
    public List<PayOrder> getPayOrderList(String orderNo) {
        PayOrderExample example =new PayOrderExample();
        example.or().andOrderNoEqualTo(orderNo);
        return payOrderMapper.selectByExample(example);
    }

    //查询班结时间订单
    @Override
    public List<PayOrder> selectPayOrderList(PayOrder payOrder) {
        return payOrderMapper.selectPayOrderList(payOrder);
    }

    @Override
    public PayOrder getPayOrderInfoMin(PayOrder payOrder) {
        return payOrderMapper.getPayOrderInfoMin(payOrder);
    }

    /**
     * 修改订单信息
     * @param payOrder
     */
    @Override
    public int getUpdatePayOrder(PayOrder payOrder) {
//        PayOrderExample example =new PayOrderExample();
//        example.or().andOrderIdEqualTo(payOrder.getOrderId());
        return payOrderMapper.updateOrderStatus(payOrder);
    }

    @Override
    public PayOrder searchPayOrder(Integer orderId) {
        PayOrder payOrder= payOrderMapper.selectByPrimaryKey(orderId);
        return payOrder;
    }

    //根据手机号查询用户信息
    @Override
    public List<AppUserInfo> getUserInfoByOpenId(AppUserInfo appUserInfo) {
        return payOrderMapper.getUserInfoByOpenId(appUserInfo);
    }

    /*
     * 根据用户openId和用户类型userType查询用户订单
     * @param payOrder
     * @return
     */
    @Override
    public List<PayOrder> getOrderListByOpenIdAndUserType(AppUserInfo appUserInfo) {
        return payOrderMapper.getOrderListByOpenIdAndUserType(appUserInfo);
    }

    /*
     * 根据订单号查询订单信息和用户信息  注：此方法在随行付回调校验之后修改状态完成后
     * @param payOrder
     * @return
     */
    @Override
    public Map<String, Object> getOrderInfoAndUserInfoByOrderNo(PayOrder payOrder) {
        return payOrderMapper.getOrderInfoAndUserInfoByOrderNo(payOrder);
    }

    /*
     * 判断客户表是否已存在
     * @param customerManage
     * @return
     */
    @Override
    public CustomerManage isExistCustomer(CustomerManage customerManage) {
        return payOrderMapper.isExistCustomer(customerManage);
    }

    /*
     * 更新客户表 注：限用于随行付支付完成处
     * @param customerManage
     */
    @Override
    public void updateCustomer(CustomerManage customerManage) {
        payOrderMapper.updateCustomer(customerManage);
    }

    /*
     * 新增客户 注：限用于随行付支付完成处
     * @param customerManage
     */
    @Override
    public void insertCustomer(CustomerManage customerManage) {
        payOrderMapper.insertCustomer(customerManage);
    }

    /*
     *  根据手机号更新
     * @param customerManage
     */
    @Override
    public void updateCustomerByPhoneNumber(CustomerManage customerManage) {
        payOrderMapper.updateCustomerByPhoneNumber(customerManage);
    }

    //查询汇总数据
    public List<Map> selectSum(PayOrder payOrder){
        return  payOrderMapper.selectSum(payOrder);
    }
}
