package com.fzm.mall.server.front.order.service.impl;

import com.fzm.mall.server.front.goods.model.GoodSpu;
import com.fzm.mall.server.front.goods.service.IGoodSpuService;
import com.fzm.mall.server.front.order.model.OrderSpu;
import com.fzm.mall.server.front.order.mapper.OrderSpuMapper;
import com.fzm.mall.server.front.order.service.IOrderSpuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 订单快照 spu 表 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-03-03
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class OrderSpuServiceImpl extends ServiceImpl<OrderSpuMapper, OrderSpu> implements IOrderSpuService {
    private final IGoodSpuService goodSpuService;

    public boolean saveSpuSnapshot(String gid,String oid) {
        OrderSpu orderSpu = new OrderSpu();
        GoodSpu goodSpu = goodSpuService.goodSpu(gid);
        if (goodSpu != null) {
            BeanUtils.copyProperties(goodSpu, orderSpu);
        }
        orderSpu.setOid(oid);
        return saveOrUpdate(orderSpu);
    }
}
