package com.pj.project.tb_goods;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pj.project.relation_goods_type.RelationGoodsType;
import com.pj.project.relation_goods_type.RelationGoodsTypeService;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pj.utils.sg.*;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Service: tb_goods -- 商品管理
 *
 * @author qzy
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbGoodsService extends ServiceImpl<TbGoodsMapper, TbGoods> implements IService<TbGoods> {

    /**
     * 底层 Mapper 对象
     */
    @Autowired
    TbGoodsMapper tbGoodsMapper;
    @Resource
    private RelationGoodsTypeService relationGoodsTypeService;


    /**
     * 改
     */
    void update(TbGoods t) {
        super.updateById(t);
       List<RelationGoodsType>goodsTypes= relationGoodsTypeService.findByGoodsId(t.getId());
       goodsTypes.forEach(relationGoodsType -> {relationGoodsType.setGoodsName(t.getName());relationGoodsTypeService.updateById(relationGoodsType);});
    }


    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    List<TbGoods> getList(SoMap so) {
        return tbGoodsMapper.getList(so);
    }


}
