package com.yihu.hos.system.dao;

import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.system.model.SystemServiceEndpoint;
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("appServiceDao")
public class AppServiceDao extends SQLGeneralDAO {
    public static final String BEAN_ID = "appServiceDao";
   
    public Result getAppServiceList(Map<String, Object> params) throws Exception {
        StringBuilder sb = new StringBuilder("from SystemServiceEndpoint t where 1=1 ");
        if (!StringUtils.isEmpty(params.get("valid"))) //是否有效
        {
            sb.append(" and t.valid = '" + params.get("valid") + "'");
        }
        Object name = params.get("name");
        Object appId = params.get("appId");
        if (!StringUtils.isEmpty(appId)) {
            sb.append(" and t.appId='"+ appId+ "'");
        }
        if (!StringUtils.isEmpty(name)) {
            sb.append(" and (t.name like '%" + name + "%' or t.code like '%" + name + "%')");
        }
        sb.append(" order by t.createDate desc");

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

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