package com.hzs.member.account.provider;

import com.hzs.common.core.domain.R;
import com.hzs.member.account.IBusinessCommission;
import com.hzs.member.account.dto.BusinessCommissionDTO;
import com.hzs.member.account.dto.MemberBalanceDTO;
import com.hzs.member.account.service.ICuMemberTradeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 办理业务扣费
 */
@Slf4j
@DubboService
public class IBusinessCommissionServiceProvider implements IBusinessCommission {

    @Autowired
    ICuMemberTradeService cuMemberTradeService;

    @Override
    public R businessCommissionSubmit(BusinessCommissionDTO businessCommissionDTO) {
        Integer tradeType = businessCommissionDTO.getTradeType();
        try {
            return R.ok(cuMemberTradeService.businessCommissionSubmit(businessCommissionDTO));
        } catch (Exception e) {
            log.error("业务类型编码为： {} 提交扣费失败", tradeType, e);
            return R.fail("提交扣费失败！");
        }
    }

    @Override
    public R businessCommissionReject(BusinessCommissionDTO businessCommissionDTO) {
        Integer tradeType = businessCommissionDTO.getTradeType();
        try {
            return R.ok(cuMemberTradeService.businessCommissionReject(businessCommissionDTO));
        } catch (Exception e) {
            log.error("业务类型编码为： {} 驳回扣费失败", tradeType, e);
            return R.fail("驳回扣费失败！");
        }
    }

    @Override
    public R<List<MemberBalanceDTO>> selectBalanceNotEnoughMember(BusinessCommissionDTO businessCommissionDTO) {
        return R.ok(cuMemberTradeService.selectBalanceNotEnoughMember(businessCommissionDTO));
    }


}
