package com.bonus.canteen.core.account.v3.service;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.canteen.core.account.v3.mapper.AccTradeUseAmountHistMapper;
import com.bonus.canteen.core.account.v3.model.AccTradeUseAmountHist;
import com.bonus.canteen.core.common.utils.JacksonUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class AccTradeUseAmountHistService extends ServiceImpl<AccTradeUseAmountHistMapper, AccTradeUseAmountHist> {
   private static final Logger log = LoggerFactory.getLogger(AccTradeUseAmountHistService.class);

   public List<AccTradeUseAmountHist> canRefundTradeHist(Long useTradeId) {
      return ((AccTradeUseAmountHistMapper)this.baseMapper).canRefundTradeHist(useTradeId);
   }

   public void updateRefundAmount(Long id, BigDecimal refundAmount) {
      ((AccTradeUseAmountHistMapper)this.baseMapper).update(null, Wrappers.<AccTradeUseAmountHist>lambdaUpdate()
              .setSql("refund_amount = refund_amount + " + refundAmount)
              .eq(AccTradeUseAmountHist::getId, id));
   }

   public void insertUseAmountHist(AccTradeUseAmountHist accTradeUseAmountHist) {
      log.info("[补贴变动]写入使用关联记录,入参={}", JacksonUtil.writeValueAsString(accTradeUseAmountHist));
      ((AccTradeUseAmountHistMapper)this.baseMapper).insert(accTradeUseAmountHist);
   }
}


