package com.td.boss.game.comcntorder.service;

import com.td.boss.common.service.*;
import com.td.boss.game.comcntorder.pojo.ComCntOrder;
import com.td.boss.game.comcntorder.vo.ComCntOrderPayTypeSumVo;
import com.td.boss.game.comcntorder.vo.ComCntOrderVo;
import com.td.boss.game.comcntorder.repository.ComCntOrderRepository;
import com.td.boss.util.CopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.Date;
import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class ComCntOrderServiceImpl extends CommonServiceImpl<ComCntOrderVo, ComCntOrder, String> implements ComCntOrderService{

    @PersistenceContext
    private EntityManager em;
    @Autowired
    private ComCntOrderRepository comCntOrderRepository;


    @Override
    public ComCntOrderVo findByTx(String tx) {
        Optional<ComCntOrder> comCntOrder =  comCntOrderRepository.findByTxHash(tx);
        if(comCntOrder.orElse(null) == null){
            return null;
        }else{
            return CopyUtil.copy(comCntOrder.get(), ComCntOrderVo.class);
        }
    }

    @Override
    public List<ComCntOrder> findByUserIdAndPayType(String userId, Integer payType) {
        return comCntOrderRepository.findByUserIdAndPayType(userId,payType);
    }

    @Override
    public List<ComCntOrderPayTypeSumVo> findAllCNTSumGroupByPayType() {
        return comCntOrderRepository.findCNTSumByPayType();
    }


    @Override
    public List<ComCntOrderPayTypeSumVo> findAllCNTSumGroupByPayTypeFromDate(Date startTime,Date endTime) {
        return comCntOrderRepository.findCNTSumByPayTypeFromDate(startTime, endTime);
    }

}
