package com.hai.service.impl;

import com.hai.dao.HighGoodsTypeMapper;
import com.hai.entity.HighGoodsType;
import com.hai.entity.HighGoodsTypeExample;
import com.hai.service.HighGoodsTypeService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;

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

/**
 * @serviceName HighGoodsTypeServiceImpl.java
 * @author Sum1Dream
 * @version 1.0.0
 * @Description //TODO
 * @createTime 3:36 下午 2021/11/11
 **/
@Service("highGoodsTypeService")
public class HighGoodsTypeServiceImpl implements HighGoodsTypeService {

    @Resource
    private HighGoodsTypeMapper highGoodsTypeMapper;

    @Override
    public List<HighGoodsType> getListGoodsType(Map<String, String> map) {

        HighGoodsTypeExample example  = new HighGoodsTypeExample();
        HighGoodsTypeExample.Criteria criteria = example.createCriteria();

        if (MapUtils.getString(map, "title") != null) {
            criteria.andTitleLike("%" + MapUtils.getString(map, "title") + "%");
        }
        if (MapUtils.getString(map, "userService") != null) {
            criteria.andUserServiceEqualTo(MapUtils.getString(map, "userService"));
        }

        criteria.andStatusEqualTo(1);

        example.setOrderByClause("created_time desc");

        return highGoodsTypeMapper.selectByExample(example);
    }

    @Override
    public HighGoodsType findById(Integer id) {
        return highGoodsTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public Boolean findByTitle(String title) {
        HighGoodsTypeExample example = new HighGoodsTypeExample();
        HighGoodsTypeExample.Criteria criteria = example.createCriteria();

        criteria.andTitleEqualTo(title).andStatusEqualTo(1);

        List<HighGoodsType> highGoodsTypes = highGoodsTypeMapper.selectByExample(example);

        return highGoodsTypes.size() > 0;
    }

    @Override
    public void insertGoodsType(HighGoodsType highGoodsType) {
        highGoodsTypeMapper.insert(highGoodsType);

    }

    @Override
    public void updateGoodsType(HighGoodsType highGoodsType) {
        highGoodsTypeMapper.updateByPrimaryKey(highGoodsType);

    }
}
