package com.hzs.member.account.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.SaOrderFieldConstants;
import com.hzs.common.domain.member.account.CuMemberTradeBonus;
import com.hzs.member.account.mapper.CuMemberTradeBonusMapper;
import com.hzs.member.account.service.ICuMemberTradeBonusService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会员已发放奖金交易明细表 服务实现类
 * </p>
 *
 * @author hzs
 * @since 2023-03-24
 */
@Service
public class CuMemberTradeBonusServiceImpl extends ServiceImpl<CuMemberTradeBonusMapper, CuMemberTradeBonus> implements ICuMemberTradeBonusService {

    @Override
    public void batchInsertCuMemberTradeBonus(List<CuMemberTradeBonus> cuMemberTradeBonusList) {
        baseMapper.batchInsertCuMemberTradeBonus(cuMemberTradeBonusList);
    }

    @Override
    public List<CuMemberTradeBonus> queryCuMemberTradeBonus(List<Integer> consumeTypeList, Long pkOrder) {
        QueryWrapper<CuMemberTradeBonus> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("pk_member,pk_order,pk_trade_detail,sum(consume_money) consume_money,sum(cash_money) cash_money");
        queryWrapper.eq(SaOrderFieldConstants.PK_ORDER, pkOrder);
        queryWrapper.in(SaOrderFieldConstants.CONSUME_TYPE, consumeTypeList);
        queryWrapper.groupBy("pk_member,pk_order,pk_trade_detail");
        queryWrapper.orderByDesc("consume_money", "cash_money");
        return baseMapper.selectList(queryWrapper);
    }
}
