package com.hfkj.service.impl;

import com.hfkj.dao.BsProductConfigMapper;
import com.hfkj.entity.BsProductConfig;
import com.hfkj.entity.BsProductConfigExample;
import com.hfkj.service.BsProductConfigService;
import org.springframework.stereotype.Service;

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

@Service("bsProductConfigService")
public class BsProductConfigServiceImpl implements BsProductConfigService {

    @Resource
    private BsProductConfigMapper bsProductConfigMapper;

    @Override
    public void create(BsProductConfig productConfig) {
        bsProductConfigMapper.insert(productConfig);
    }

    @Override
    public void update(BsProductConfig productConfig) {
        bsProductConfigMapper.updateByPrimaryKeySelective(productConfig);
    }

    @Override
    public void delete(Long id, Boolean fullDelete) {
        if (fullDelete) {
            bsProductConfigMapper.deleteByPrimaryKey(id);
        } else {
            BsProductConfig productConfig = queryDetail(id);
            productConfig.setStatus(0);
            productConfig.setUpdateTime(new Date());
            update(productConfig);
        }

    }

    @Override
    public BsProductConfig queryDetail(Long id) {
        return bsProductConfigMapper.selectByPrimaryKey(id);
    }

    @Override
    public BsProductConfig queryDetail(Integer productType) {
        BsProductConfigExample example = new BsProductConfigExample();
        example.createCriteria().andProductTypeEqualTo(productType).andStatusEqualTo(1);

        List<BsProductConfig> list = bsProductConfigMapper.selectByExample(example);

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

        return null;
    }

    @Override
    public BsProductConfig queryDetailByMap(Map<String, Object> map) {
        return null;
    }

    @Override
    public List<BsProductConfig> getList(Long merId) {
        BsProductConfigExample example = new BsProductConfigExample();
        example.createCriteria().andMerIdEqualTo(merId).andStatusEqualTo(1);
        return bsProductConfigMapper.selectByExample(example);
    }
}
