package com.hfkj.service.goods.impl;

import com.hfkj.dao.GoodsJumpMapper;
import com.hfkj.entity.GoodsJump;
import com.hfkj.entity.GoodsJumpExample;
import com.hfkj.service.goods.GoodsJumpService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("orderJumpService")
public class GoodsJumpServiceImpl implements GoodsJumpService {

    @Resource
    private GoodsJumpMapper goodsJumpMapper;

    @Override
    public void create(GoodsJump goodsJump) {
        goodsJumpMapper.insert(goodsJump);
    }

    @Override
    public void update(GoodsJump goodsJump) {
        goodsJumpMapper.updateByPrimaryKeySelective(goodsJump);
    }

    @Override
    public void delete(Long id) {
        goodsJumpMapper.deleteByPrimaryKey(id);
    }

    @Override
    public GoodsJump queryDetail(Long id) {
        return goodsJumpMapper.selectByPrimaryKey(id);
    }

    @Override
    public void deleteSpecsId(Long specsId) {
        GoodsJumpExample example = new GoodsJumpExample();
        example.createCriteria().andSpecsIdEqualTo(specsId);

        List<GoodsJump> list = goodsJumpMapper.selectByExample(example);

        for (GoodsJump goodsJump : list) {
            goodsJumpMapper.deleteByPrimaryKey(goodsJump.getId());
        }
    }

    @Override
    public GoodsJump queryDetailBySpecsId(Long specsId) {
        GoodsJumpExample example = new GoodsJumpExample();
        example.createCriteria().andSpecsIdEqualTo(specsId);

        List<GoodsJump> list = goodsJumpMapper.selectByExample(example);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    @Override
    public List<GoodsJump> getList(Map<String, Object> map) {
        return goodsJumpMapper.selectByExample(new GoodsJumpExample());
    }
}
