package com.hfkj.service.goods.impl;

import com.hfkj.dao.GoodsVpdMapper;
import com.hfkj.entity.GoodsMsg;
import com.hfkj.entity.GoodsVpd;
import com.hfkj.entity.GoodsVpdExample;
import com.hfkj.service.goods.GoodsVpdService;
import org.springframework.stereotype.Service;

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

@Service("goodsVpdService")
public class GoodsVpdServiceImpl implements GoodsVpdService {

    @Resource
    private GoodsVpdMapper goodsVpdMapper;

    @Override
    public void create(GoodsVpd goodsVpd) {
        goodsVpdMapper.insert(goodsVpd);
    }

    @Override
    public void update(GoodsVpd goodsVpd) {
        goodsVpdMapper.updateByPrimaryKeySelective(goodsVpd);
    }

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

    @Override
    public GoodsVpd queryDetail(Long id) {
        return goodsVpdMapper.selectByPrimaryKey(id);
    }

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

        List<GoodsVpd> list = goodsVpdMapper.selectByExample(example);

        for (GoodsVpd goodsVpd : list) {
            goodsVpdMapper.deleteByPrimaryKey(goodsVpd.getId());
        }

    }

    @Override
    public GoodsVpd queryDetailBySpecsId(Long specsId) {

        GoodsVpdExample example = new GoodsVpdExample();
        example.createCriteria().andSpecsIdEqualTo(specsId);

        List<GoodsVpd> list = goodsVpdMapper.selectByExample(example);

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

        return null;
    }

    @Override
    public List<GoodsVpd> getList(Map<String, Object> map) {
        return goodsVpdMapper.selectByExample(new GoodsVpdExample());
    }
}
