package com.fzm.mall.server.admin.goods_center.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzm.mall.server.admin.goods_center.entity.dto.ExternalTokenTradeDTO;
import com.fzm.mall.server.admin.goods_center.model.ExternalTokenTrade;
import com.fzm.mall.server.admin.goods_center.mapper.ExternalTokenTradeMapper;
import com.fzm.mall.server.admin.goods_center.service.IExternalTokenTradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.admin.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * <p>
 * 外部商品通证 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-08-10
 */
@Service
@Transactional
public class ExternalTokenTradeServiceImpl extends ServiceImpl<ExternalTokenTradeMapper, ExternalTokenTrade> implements IExternalTokenTradeService {

    @Autowired
    private ExternalTokenTradeMapper externalTokenTradeMapper;

    @Override
    public IPage<ExternalTokenTradeDTO> page(Page<ExternalTokenTradeDTO> page, String commodityPassId, String oppositeAddress, Integer tradeType, Long startTime, Long endTime) {
        return externalTokenTradeMapper.page(page, commodityPassId, oppositeAddress, tradeType, startTime, endTime);
    }

    @Override
    public void addTrade(String commodityPassId, String address, BigDecimal amount) {
        ExternalTokenTrade trade = new ExternalTokenTrade();
        trade.setCommodityPassId(commodityPassId);
        trade.setTradeId(UUIDUtil.getUUID());
        trade.setOppositeAddress(address);
        trade.setTradeNumber(amount);
        trade.setTradeType(1);
        save(trade);
    }
}
