package com.yihu.hos.system.dao;

import com.yihu.hos.core.datatype.CollectionUtil;
import com.yihu.hos.system.model.SystemServiceFlow;
import com.yihu.hos.system.model.SystemServiceFlowProcess;
import com.yihu.hos.web.framework.dao.SQLGeneralDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("flowProcessDao")
public class FlowProcessDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "flowProcessDao";
    public List<SystemServiceFlowProcess> getFlowProcessList(String type) throws Exception {
        List<SystemServiceFlowProcess> list = (List<SystemServiceFlowProcess>) super.hibernateTemplate.find("from SystemServiceFlowProcess");
        return list;
    }

    public SystemServiceFlowProcess getFlowProcessByCode(String code) throws Exception {
        List<SystemServiceFlowProcess> list = (List<SystemServiceFlowProcess>) super.hibernateTemplate.find("from SystemServiceFlowProcess s where code=? ", code);
        if (!CollectionUtil.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

    public SystemServiceFlowProcess getFlowProcessByFlowId(Integer flowId) throws Exception {
        List<SystemServiceFlowProcess> list = (List<SystemServiceFlowProcess>) super.hibernateTemplate.find("from SystemServiceFlowProcess s where flowId=? ", flowId);
        if (!CollectionUtil.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
