package com.yami.shop.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.RefundAddr;
import com.yami.shop.dao.RefundAddrMapper;
import com.yami.shop.service.RefundAddrService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

/**
 * @author LGH
 * @date 2019-06-28 10:19:21
 */
@Service
@AllArgsConstructor
public class RefundAddrServiceImpl extends ServiceImpl<RefundAddrMapper, RefundAddr> implements RefundAddrService {

    private RefundAddrMapper refundAddrMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addRefundAddr(RefundAddr refundAddr) {
//        if (Objects.equals(refundAddr.getDefaultAddr(), 1)) {
//            refundAddrMapper.cancelDefaultAddr(refundAddr.getShopId());
//        }
        refundAddrMapper.insert(refundAddr);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateRefundAddr(Long shopId, RefundAddr refundAddr) {
        if (Objects.equals(refundAddr.getDefaultAddr(), 1)) {
            refundAddrMapper.cancelDefaultAddr(shopId);
        }
        refundAddrMapper.updateById(refundAddr);
    }
}
