package com.yonge.cooleshow.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.yonge.cooleshow.admin.dao.PmsProductAttributeCategoryDao;
import com.yonge.cooleshow.admin.dto.PmsProductAttributeCategoryItem;
import com.yonge.cooleshow.mbg.mapper.PmsProductAttributeCategoryMapper;
import com.yonge.cooleshow.mbg.model.PmsProductAttributeCategory;
import com.yonge.cooleshow.mbg.model.PmsProductAttributeCategoryExample;
import com.yonge.cooleshow.admin.service.PmsProductAttributeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品属性分类管理Service实现类
 * Created by macro on 2018/4/26.
 */
@Service
public class PmsProductAttributeCategoryServiceImpl implements PmsProductAttributeCategoryService {
    @Autowired
    private PmsProductAttributeCategoryMapper productAttributeCategoryMapper;
    @Autowired
    private PmsProductAttributeCategoryDao productAttributeCategoryDao;

    @Override
    public int create(String name, Integer sort) {
        PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
        productAttributeCategory.setName(name);
        productAttributeCategory.setSort(sort);
        return productAttributeCategoryMapper.insertSelective(productAttributeCategory);
    }

    @Override
    public int update(Long id, String name, Integer sort) {
        PmsProductAttributeCategory productAttributeCategory = new PmsProductAttributeCategory();
        productAttributeCategory.setName(name);
        productAttributeCategory.setId(id);
        productAttributeCategory.setSort(sort);
        return productAttributeCategoryMapper.updateByPrimaryKeySelective(productAttributeCategory);
    }

    @Override
    public int delete(Long id) {
        return productAttributeCategoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PmsProductAttributeCategory getItem(Long id) {
        return productAttributeCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PmsProductAttributeCategory> getList(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        PmsProductAttributeCategoryExample pmsProductAttributeCategoryExample = new PmsProductAttributeCategoryExample();
        pmsProductAttributeCategoryExample.setOrderByClause("sort desc");
        return productAttributeCategoryMapper.selectByExample(pmsProductAttributeCategoryExample);
    }

    @Override
    public List<PmsProductAttributeCategoryItem> getListWithAttr() {
        return productAttributeCategoryDao.getListWithAttr();
    }
}
