package com.yihu.hos.system.dao;

import com.yihu.hos.system.model.SystemDictList;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by chenweida on 2016/1/20.
 */
@Repository("dictListDao")
public class DictListDao extends SQLGeneralDAO  {

    public static final String BEAN_ID = "dictListDao";

    public Result getDictList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from SystemDictList s where 1=1 ");
        if (!StringUtils.isEmpty(params.get("name"))) {
            sb.append(" and  s.chineseName like '%" + params.get("name") + "%' ");
        }
        sb.append(" order by dictName desc");
        return super.getDataGridResult(sb.toString(), Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
    }

  
    public SystemDictList getDitcByName(String dictName) throws Exception {
        List<SystemDictList> sdl = (List<SystemDictList>) super.hibernateTemplate.find("from SystemDictList s where s.dictName=?", dictName);
        if (sdl != null && sdl.size() > 0) {
            return sdl.get(0);
        }
        return null;
    }

  
    public SystemDictList getDitcByNameWithOutId(String dictName, String id) throws Exception {
        List<SystemDictList> sdl = (List<SystemDictList>) super.hibernateTemplate.find("from SystemDictList s where s.dictName=? and s.id!=?", dictName, id);
        if (sdl != null && sdl.size() > 0) {
            return sdl.get(0);
        }
        return null;
    }
}
