package com.xmomen.module.system.service;

import com.xmomen.framework.mybatis.dao.MybatisDao;
import com.xmomen.framework.mybatis.page.Page;
import com.xmomen.framework.utils.StringUtilsExt;
import com.xmomen.module.system.entity.SysDictionary;
import com.xmomen.module.system.entity.SysDictionaryExample;
import com.xmomen.module.system.entity.SysDictionaryParameter;
import com.xmomen.module.system.entity.SysDictionaryParameterExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Jeng on 16/4/2.
 */
@Service
public class DictionaryService {

    // 注入MybatisDao
    @Autowired
    MybatisDao mybatisDao;

    // 创建字典
    @Transactional
    public SysDictionaryParameter createDictionary(SysDictionaryParameter sysDictionaryParameter){
        // 调用MybatisDao的insertByModel方法插入字典
        return mybatisDao.insertByModel(sysDictionaryParameter);
    }

    // 获取字典列表
    public Page<SysDictionary> getDictionaryList(Integer groupId, Integer limit, Integer offset){
        // 创建SysDictionaryParameterExample对象
        SysDictionaryParameterExample sysDictionaryExample = new SysDictionaryParameterExample();
        // 设置查询条件
        sysDictionaryExample.createCriteria().andSysDictionaryIdEqualTo(groupId);
        // 调用MybatisDao的selectPageByExample方法查询字典列表
        return mybatisDao.selectPageByExample(sysDictionaryExample, limit, offset);
    }

    // 获取字典
    public SysDictionaryParameter getDictionary(Integer id){
        // 调用MybatisDao的selectByPrimaryKey方法查询字典
    // 更新字典
        return mybatisDao.selectByPrimaryKey(SysDictionaryParameter.class, id);
        // 调用mybatisDao的update方法，更新字典
    }

    // 删除字典
        // 调用mybatisDao的deleteByPrimaryKey方法，根据id删除字典
    public void updateDictionary(SysDictionaryParameter sysDictionary){
        mybatisDao.update(sysDictionary);
    }

    public void deleteDictionary(Integer id){
        mybatisDao.deleteByPrimaryKey(SysDictionaryParameter.class, id);
    }


}
