package com.yihu.hos.system.dao;

import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.system.model.SystemServiceFlowProcessor;
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;

/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2016/8/16.
 */
@Repository("processorDao")
public class ProcessorDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "processorDao";
   
    public Result getProcessorList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from SystemServiceFlowProcessor t where 1=1 ");
        Object name = params.get("name");
        if (!StringUtils.isEmpty(name)) {
            sb.append(" and (t.name like '%" + name + "%'')");
        }
        return super.getDataGridResult(sb.toString(), Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
    }

    public List<SystemServiceFlowProcessor> getListByName(String processorName) throws Exception {
        String hql = "from SystemServiceFlowProcessor";
        if (!StringUtil.isEmpty(processorName)) {
            hql += " where name = "+processorName+"";
        }
        return getEntityList(SystemServiceFlowProcessor.class, hql);
    }
}
