package com.yihu.hos.system.dao;

import com.yihu.hos.system.model.SystemServiceFlow;
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/19.
 */
@Repository("flowDao")
public class FlowDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "flowDao";

    public Result getFlowList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from SystemServiceFlow t where 1=1 ");
        if (!StringUtils.isEmpty(params.get("valid"))) //是否有效
        {
            sb.append(" and t.valid = '" + params.get("valid") + "'");
        }
        Object name = params.get("name");
        if (!StringUtils.isEmpty(name)) {
            sb.append(" and (t.name like '%" + name + "%' or t.code like '%" + name + "%')");
        }

        return super.getDataGridResult(sb.toString(), Integer.valueOf(params.get("page").toString()), Integer.valueOf(params.get("rows").toString()));
    }

    public List<SystemServiceFlow> getFlowList(String type) throws Exception {
        List<SystemServiceFlow> list = (List<SystemServiceFlow>) super.hibernateTemplate.find("from SystemServiceFlow s where s.valid=1 and fileType=? ",  type);
        return list;
    }


}
